digiKam
thumbsdb.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-05-29
7  * Description : Thumbnails database interface.
8  *
9  * Copyright (C) 2009 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_THUMBS_DB_H
26 #define DIGIKAM_THUMBS_DB_H
27 
28 // Qt includes
29 
30 #include <QDateTime>
31 #include <QString>
32 #include <QHash>
33 #include <QList>
34 
35 // Local includes
36 
37 #include "dbenginesqlquery.h"
38 #include "thumbsdbbackend.h"
39 #include "thumbsdbaccess.h"
40 #include "digikam_export.h"
41 
42 namespace Digikam
43 {
44 
45 namespace DatabaseThumbnail
46 {
47 
48 enum Type
49 {
52  PGF,
53  JPEG, // Warning : no alpha channel support. Cannot be used as well.
55  PNG
56  //FreeDesktopHash
57 };
58 
59 } // namespace DatabaseThumbnail
60 
61 class DIGIKAM_EXPORT ThumbsDbInfo
62 {
63 
64 public:
65 
66  explicit ThumbsDbInfo()
67  : id (-1),
68  type (DatabaseThumbnail::UndefinedType),
69  orientationHint(0)
70  {
71  }
72 
73  int id;
75  QDateTime modificationDate;
77  QByteArray data;
78 };
79 
80 // ------------------------------------------------------------------------------------------
81 
82 class DIGIKAM_EXPORT ThumbsDb
83 {
84 
85 public:
86 
87  bool setSetting(const QString& keyword, const QString& value);
88  QString getSetting(const QString& keyword);
89  QString getLegacySetting(const QString& keyword);
90 
91  ThumbsDbInfo findByHash(const QString& uniqueHash, qlonglong fileSize);
92  ThumbsDbInfo findByFilePath(const QString& path);
93  ThumbsDbInfo findByCustomIdentifier(const QString& id);
94 
101  ThumbsDbInfo findByFilePath(const QString& path, const QString& uniqueHash);
102 
106  QList<int> findAll();
107 
108  BdEngineBackend::QueryState insertUniqueHash(const QString& uniqueHash, qlonglong fileSize, int thumbId);
109  BdEngineBackend::QueryState insertFilePath(const QString& path, int thumbId);
110  BdEngineBackend::QueryState insertCustomIdentifier(const QString& id, int thumbId);
111 
112  BdEngineBackend::QueryState remove(int thumbId);
113 
117  BdEngineBackend::QueryState removeByUniqueHash(const QString& uniqueHash, qlonglong fileSize);
118 
122  BdEngineBackend::QueryState removeByFilePath(const QString& path);
123  BdEngineBackend::QueryState removeByCustomIdentifier(const QString& id);
124 
125  BdEngineBackend::QueryState renameByFilePath(const QString& oldPath, const QString& newPath);
126 
127  BdEngineBackend::QueryState insertThumbnail(const ThumbsDbInfo& info, QVariant* const lastInsertId = nullptr);
128  BdEngineBackend::QueryState replaceThumbnail(const ThumbsDbInfo& info);
129 
130  QHash<QString, int> getFilePathsWithThumbnail();
131 
132  void replaceUniqueHash(const QString& oldUniqueHash, int oldFileSize, const QString& newUniqueHash, int newFileSize);
133  BdEngineBackend::QueryState updateModificationDate(int thumbId, const QDateTime& modificationDate);
134 
135  // ----------- Database shrinking methods ----------
136 
140  bool integrityCheck();
141 
145  void vacuum();
146 
147 private:
148 
149  explicit ThumbsDb(ThumbsDbBackend* const backend);
150  ~ThumbsDb();
151 
152  ThumbsDbInfo fillThumbnailInfo(const QList<QVariant>& values);
153 
154 private:
155 
156  // Disable
157  ThumbsDb(const ThumbsDb&) = delete;
158  ThumbsDb& operator=(const ThumbsDb&) = delete;
159 
160  class Private;
161  Private* const d;
162 
163  friend class ThumbsDbAccess;
164 };
165 
166 } // namespace Digikam
167 
168 #endif // DIGIKAM_THUMBS_DB_H
Definition: dbenginebackend.h:157
Definition: thumbsdbaccess.h:43
Definition: thumbsdbbackend.h:39
Definition: thumbsdb.h:62
int id
Definition: thumbsdb.h:73
QByteArray data
Definition: thumbsdb.h:77
DatabaseThumbnail::Type type
Definition: thumbsdb.h:74
QDateTime modificationDate
Definition: thumbsdb.h:75
int orientationHint
Definition: thumbsdb.h:76
ThumbsDbInfo()
Definition: thumbsdb.h:66
Definition: thumbsdb.h:83
qulonglong value
Definition: itemviewutilities.cpp:592
Type
Definition: thumbsdb.h:49
@ JPEG
Definition: thumbsdb.h:53
@ PNG
Definition: thumbsdb.h:55
@ PGF
Definition: thumbsdb.h:52
@ UndefinedType
Definition: thumbsdb.h:50
@ JPEG2000
Definition: thumbsdb.h:54
@ NoThumbnail
Definition: thumbsdb.h:51
Definition: datefolderview.cpp:43