File indexing completed on 2025-01-19 03:53:46
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-05-29 0007 * Description : Thumbnails database interface. 0008 * 0009 * SPDX-FileCopyrightText: 2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2009-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_THUMBS_DB_H 0017 #define DIGIKAM_THUMBS_DB_H 0018 0019 // Qt includes 0020 0021 #include <QDateTime> 0022 #include <QString> 0023 #include <QHash> 0024 #include <QList> 0025 0026 // Local includes 0027 0028 #include "dbenginesqlquery.h" 0029 #include "thumbsdbbackend.h" 0030 #include "thumbsdbaccess.h" 0031 #include "digikam_export.h" 0032 0033 namespace Digikam 0034 { 0035 0036 namespace DatabaseThumbnail 0037 { 0038 0039 enum Type 0040 { 0041 UndefinedType = 0, 0042 NoThumbnail, 0043 PGF, 0044 JPEG, // Warning : no alpha channel support. Cannot be used as well. 0045 JPEG2000, 0046 PNG 0047 //FreeDesktopHash 0048 }; 0049 0050 } // namespace DatabaseThumbnail 0051 0052 class DIGIKAM_EXPORT ThumbsDbInfo 0053 { 0054 0055 public: 0056 0057 explicit ThumbsDbInfo() 0058 : id (-1), 0059 type (DatabaseThumbnail::UndefinedType), 0060 orientationHint(0) 0061 { 0062 } 0063 0064 int id; 0065 DatabaseThumbnail::Type type; 0066 QDateTime modificationDate; 0067 int orientationHint; 0068 QByteArray data; 0069 }; 0070 0071 // ------------------------------------------------------------------------------------------ 0072 0073 class DIGIKAM_EXPORT ThumbsDb 0074 { 0075 0076 public: 0077 0078 bool setSetting(const QString& keyword, const QString& value); 0079 QString getSetting(const QString& keyword); 0080 QString getLegacySetting(const QString& keyword); 0081 0082 ThumbsDbInfo findByHash(const QString& uniqueHash, qlonglong fileSize); 0083 ThumbsDbInfo findByFilePath(const QString& path); 0084 ThumbsDbInfo findByCustomIdentifier(const QString& id); 0085 0086 /** 0087 * This is findByFilePath with extra security: Pass the uniqueHash which you have. 0088 * If an entry is found by file path, and the entry is referenced by any uniqueHash, 0089 * which is different from the given hash, a null info is returned. 0090 * If uniqueHash is null, equivalent to the simple findByFilePath. 0091 */ 0092 ThumbsDbInfo findByFilePath(const QString& path, const QString& uniqueHash); 0093 0094 /** 0095 * Returns the thumbnail ids of all thumbnails in the database. 0096 */ 0097 QList<int> findAll(); 0098 0099 BdEngineBackend::QueryState insertUniqueHash(const QString& uniqueHash, qlonglong fileSize, int thumbId); 0100 BdEngineBackend::QueryState insertFilePath(const QString& path, int thumbId); 0101 BdEngineBackend::QueryState insertCustomIdentifier(const QString& id, int thumbId); 0102 0103 BdEngineBackend::QueryState remove(int thumbId); 0104 0105 /** 0106 * Removes thumbnail data associated to the given uniqueHash/fileSize 0107 */ 0108 BdEngineBackend::QueryState removeByUniqueHash(const QString& uniqueHash, qlonglong fileSize); 0109 0110 /** 0111 * Removes thumbnail data associated to the given file path 0112 */ 0113 BdEngineBackend::QueryState removeByFilePath(const QString& path); 0114 BdEngineBackend::QueryState removeByCustomIdentifier(const QString& id); 0115 0116 BdEngineBackend::QueryState renameByFilePath(const QString& oldPath, const QString& newPath); 0117 0118 BdEngineBackend::QueryState insertThumbnail(const ThumbsDbInfo& info, QVariant* const lastInsertId = nullptr); 0119 BdEngineBackend::QueryState replaceThumbnail(const ThumbsDbInfo& info); 0120 0121 QHash<QString, int> getFilePathsWithThumbnail(); 0122 0123 void replaceUniqueHash(const QString& oldUniqueHash, int oldFileSize, const QString& newUniqueHash, int newFileSize); 0124 BdEngineBackend::QueryState updateModificationDate(int thumbId, const QDateTime& modificationDate); 0125 0126 // ----------- Database shrinking methods ---------- 0127 0128 /** 0129 * Returns true if the integrity of the database is preserved. 0130 */ 0131 bool integrityCheck(); 0132 0133 /** 0134 * Shrinks the database. 0135 */ 0136 void vacuum(); 0137 0138 private: 0139 0140 explicit ThumbsDb(ThumbsDbBackend* const backend); 0141 ~ThumbsDb(); 0142 0143 ThumbsDbInfo fillThumbnailInfo(const QList<QVariant>& values); 0144 0145 private: 0146 0147 // Disable 0148 ThumbsDb(const ThumbsDb&) = delete; 0149 ThumbsDb& operator=(const ThumbsDb&) = delete; 0150 0151 class Private; 0152 Private* const d; 0153 0154 friend class ThumbsDbAccess; 0155 }; 0156 0157 } // namespace Digikam 0158 0159 #endif // DIGIKAM_THUMBS_DB_H