File indexing completed on 2024-05-12 04:21:06

0001 /*
0002  * SPDX-FileCopyrightText: 2012-2015 Vishesh Handa <vhanda@kde.org>
0003  * SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0004  *
0005  * SPDX-License-Identifier: LGPL-2.1-or-later
0006  */
0007 
0008 #ifndef EXIV2EXTRACTOR_H
0009 #define EXIV2EXTRACTOR_H
0010 
0011 #include <exiv2/exiv2.hpp>
0012 
0013 #include "koko_export.h"
0014 #include <QDateTime>
0015 #include <QObject>
0016 #include <QString>
0017 #include <QUrl>
0018 
0019 class KOKO_EXPORT Exiv2Extractor : public QObject
0020 {
0021     Q_OBJECT
0022 
0023     Q_PROPERTY(QUrl filePath READ filePath WRITE setFilePath NOTIFY filePathChanged)
0024     Q_PROPERTY(double gpsLatitude READ gpsLatitude NOTIFY filePathChanged)
0025     Q_PROPERTY(double gpsLongitude READ gpsLongitude NOTIFY filePathChanged)
0026     Q_PROPERTY(QDateTime dateTime READ dateTime NOTIFY filePathChanged)
0027     Q_PROPERTY(QString simplifiedPath READ simplifiedPath NOTIFY filePathChanged)
0028     Q_PROPERTY(int height READ height NOTIFY filePathChanged)
0029     Q_PROPERTY(int width READ width NOTIFY filePathChanged)
0030     Q_PROPERTY(int size READ size NOTIFY filePathChanged)
0031     Q_PROPERTY(QString model READ model NOTIFY filePathChanged)
0032     Q_PROPERTY(QString time READ time NOTIFY filePathChanged)
0033     Q_PROPERTY(bool favorite READ favorite NOTIFY favoriteChanged)
0034     Q_PROPERTY(int rating READ rating WRITE setRating NOTIFY filePathChanged)
0035     Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY filePathChanged)
0036     Q_PROPERTY(QStringList tags READ tags WRITE setTags NOTIFY filePathChanged)
0037 
0038 public:
0039     explicit Exiv2Extractor(QObject *parent = nullptr);
0040     ~Exiv2Extractor();
0041 
0042     void extract(const QString &filePath);
0043     Q_INVOKABLE void updateFavorite(const QString &filePath);
0044     Q_INVOKABLE void toggleFavorite(const QString &filePath);
0045 
0046     QUrl filePath() const;
0047     void setFilePath(const QUrl &filePath)
0048     {
0049         extract(filePath.toLocalFile());
0050     }
0051 
0052     double gpsLatitude() const
0053     {
0054         return m_latitude;
0055     }
0056     double gpsLongitude() const
0057     {
0058         return m_longitude;
0059     }
0060 
0061     QDateTime dateTime() const
0062     {
0063         return m_dateTime;
0064     }
0065 
0066     QString simplifiedPath() const;
0067 
0068     int height() const
0069     {
0070         return m_height;
0071     }
0072     int width() const
0073     {
0074         return m_width;
0075     }
0076 
0077     int size() const
0078     {
0079         return m_size;
0080     }
0081 
0082     QString model() const
0083     {
0084         return m_model;
0085     }
0086 
0087     QString time() const
0088     {
0089         return m_time;
0090     }
0091 
0092     bool favorite() const
0093     {
0094         return m_favorite;
0095     }
0096 
0097     int rating() const
0098     {
0099         return m_rating;
0100     }
0101 
0102     QString description() const
0103     {
0104         return m_description;
0105     }
0106 
0107     QStringList tags() const
0108     {
0109         return m_tags;
0110     }
0111 
0112     void setRating(const int &rating);
0113     void setDescription(const QString &description);
0114     void setTags(const QStringList &tags);
0115 
0116     bool error() const;
0117 
0118 Q_SIGNALS:
0119     void filePathChanged();
0120     void favoriteChanged();
0121 
0122 private:
0123     double fetchGpsDouble(const Exiv2::ExifData &data, const char *name);
0124     QByteArray fetchByteArray(const Exiv2::ExifData &data, const char *name);
0125 
0126     QString m_filePath;
0127     double m_latitude;
0128     double m_longitude;
0129     QDateTime m_dateTime;
0130     int m_height;
0131     int m_width;
0132     int m_size;
0133     QString m_model;
0134     QString m_time;
0135     bool m_favorite;
0136     int m_rating;
0137     QString m_description;
0138     QStringList m_tags;
0139 
0140     bool m_error;
0141 };
0142 
0143 #endif // EXIV2EXTRACTOR_H