File indexing completed on 2024-05-12 15:55:36
0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team 0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0003 // 0004 // SPDX-License-Identifier: GPL-2.0-or-later 0005 0006 #ifndef EXIFDATABASE_H 0007 #define EXIFDATABASE_H 0008 0009 #include <kpabase/FileNameList.h> 0010 0011 #include <QList> 0012 #include <QPair> 0013 #include <QString> 0014 0015 namespace DB 0016 { 0017 class UIDelegate; 0018 class AbstractProgressIndicator; 0019 } 0020 namespace Exiv2 0021 { 0022 class ExifData; 0023 } 0024 0025 typedef QPair<int, int> Rational; 0026 typedef QList<Rational> RationalList; 0027 typedef QPair<DB::FileName, Exiv2::ExifData> DBExifInfo; 0028 0029 namespace Exif 0030 { 0031 class DatabaseElement; 0032 0033 // ============================================================================ 0034 // IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT 0035 // ============================================================================ 0036 // 0037 // It is the resposibility of the methods in here to bail out in case database 0038 // support is not available ( !isAvailable() ). This is to simplify client code. 0039 class Database 0040 { 0041 public: 0042 typedef QList<DatabaseElement *> ElementList; 0043 typedef QPair<QString, QString> Camera; 0044 typedef QList<Camera> CameraList; 0045 typedef QString Lens; 0046 typedef QList<Lens> LensList; 0047 0048 Database(const QString &sqliteFileName, DB::UIDelegate &uiDelegate); 0049 Database(const Database &) = delete; 0050 ~Database(); 0051 0052 Database &operator=(const Database &) = delete; 0053 0054 static bool isAvailable(); 0055 /** 0056 * @brief DBVersion is the exif search database schema version currently supported by KPhotoAlbum. 0057 * @return the Exif Database version 0058 */ 0059 static int DBVersion(); 0060 0061 /** 0062 * @brief isUsable 0063 * @return \c true, if the Exif database is available, open, and not in a failure state. \c false otherwise 0064 */ 0065 bool isUsable() const; 0066 /** 0067 * @brief DBFileVersion is the database schema version used in the exif-info.db file. 0068 * @return the database schema version used by the database file, or 0 on error. 0069 */ 0070 int DBFileVersion() const; 0071 /** 0072 * @brief DBFileVersionGuaranteed reflects DBVersion of the last time the exif db has been built. 0073 * It is just like the DBFileVersion() but concerning the data. 0074 * The schema version is automatically updated to a newer schema, but normally the 0075 * data in the exif database is not. 0076 * In this situation, only newly added pictures are populated with the new fields, whereas 0077 * existing pictures have empty values. 0078 * However, once the user rebuilds the exif database, we can guarantee all entries in the 0079 * database to conform to the new schema, and DBFileVersionGuaranteed() will be updated to the new value. 0080 * @return 0 <= DBFileVersionGuaranteed() <= DBFileVersion() 0081 */ 0082 int DBFileVersionGuaranteed() const; 0083 /** 0084 * @brief Adds a file and its exif data to the exif database. 0085 * If the file already exists in the database, the new data replaces the existing data. 0086 * @param filename 0087 * @param data the exif data 0088 * @return \c true, if the operation succeeded, \c false otherwise 0089 */ 0090 bool add(const DB::FileName &filename, Exiv2::ExifData data); 0091 /** 0092 * @brief Adds a file to the exif database, reading its exif data from the file. 0093 * @param fileName 0094 * @return \c true, if the operation succeeded, \c false otherwise 0095 */ 0096 bool add(const DB::FileName &fileName); 0097 /** 0098 * @brief Adds a list of files to the exif database, reading the exif data from the files. 0099 * @param list 0100 * @return \c true, if the operation succeeded, \c false otherwise 0101 */ 0102 bool add(const DB::FileNameList &list); 0103 /** 0104 * @brief Removes a single file from the exif database. 0105 * Removing a file that is not in the database is allowed. 0106 * @param fileName 0107 */ 0108 void remove(const DB::FileName &fileName); 0109 /** 0110 * @brief Removes a list of files from the exif database. 0111 * Passing an empty list or a list that contains files that are not actually in the exif database is allowed. 0112 * @param list 0113 */ 0114 void remove(const DB::FileNameList &list); 0115 /** 0116 * @brief readFields searches the exif database for a given file and fills the element list with values. 0117 * If the query fails or has no result, the ElementList is not changed. 0118 * @param fileName 0119 * @param fields a list of the DatabaseElements that you want to read. 0120 * @return true, if the fileName is found in the database, false otherwise. 0121 */ 0122 bool readFields(const DB::FileName &fileName, ElementList &fields) const; 0123 DB::FileNameSet filesMatchingQuery(const QString &query) const; 0124 CameraList cameras() const; 0125 LensList lenses() const; 0126 0127 /** 0128 * @brief size 0129 * @return The number of entries in the Exif database 0130 */ 0131 int size() const; 0132 0133 /** 0134 * @brief Discards the current exif database and recreates it from the given files. 0135 * 0136 * Exiv2 seems to accept both image and movie files without ill effects 0137 * (but does not actually return any usable metadata). 0138 * 0139 * Recreating the exif database can take a lot of time. To get a decent user experience in spite of that, 0140 * the method updates the given AbstractProgressIndicator and calls QCoreApplication::processEvents() 0141 * in regular intervals (if a QCoreApplication instance is available). 0142 * 0143 * To be on the safe side though, you should still filter out non-image files as long as there is no official support for movie files in exiv2. 0144 * @param allImageFiles a list of all image files 0145 * @param progressIndicator for quick usage from a GUI application, use a DB::ProgressIndicator<QProgressDialog> 0146 */ 0147 void recreate(const DB::FileNameList &allImageFiles, DB::AbstractProgressIndicator &progressIndicator); 0148 bool startInsertTransaction(); 0149 bool commitInsertTransaction(); 0150 bool abortInsertTransaction(); 0151 0152 private: 0153 class DatabasePrivate; 0154 DatabasePrivate *d_ptr; 0155 Q_DECLARE_PRIVATE(Database) 0156 }; 0157 } 0158 0159 #endif /* EXIFDATABASE_H */ 0160 0161 // vi:expandtab:tabstop=4 shiftwidth=4: