digiKam
itemscanner.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 : 2007-09-19
7  * Description : Scanning a single item.
8  *
9  * Copyright (C) 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2013-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_ITEM_SCANNER_H
26 #define DIGIKAM_ITEM_SCANNER_H
27 
28 // Qt includes
29 
30 #include <QFileInfo>
31 
32 // Local includes
33 
34 #include "dimg.h"
35 #include "iteminfo.h"
36 #include "dmetadata.h"
37 #include "coredbalbuminfo.h"
38 #include "coredbinfocontainers.h"
39 
40 namespace Digikam
41 {
42 
43 class DIGIKAM_DATABASE_EXPORT ItemScanner
44 {
45 
46 public:
47 
48  enum ScanMode
49  {
52  Rescan
53  };
54 
55 public:
56 
62  ItemScanner(const QFileInfo& info, const ItemScanInfo& Iteminfo);
63 
68  explicit ItemScanner(const QFileInfo& info);
69 
74  explicit ItemScanner(qlonglong imageid);
75 
76  ~ItemScanner();
77 
83  void setCategory(DatabaseItem::Category category);
84 
89  const ItemScanInfo& itemScanInfo() const;
90 
97  void loadFromDisk();
98 
102  static QString formatToString(const QString& format);
103 
104 private:
105 
106  static bool hasValidField(const QVariantList& list);
107  static bool lessThanForIdentity(const ItemScanInfo& a, const ItemScanInfo& b);
108 
109  // -----------------------------------------------------------------------------
110 
115 
116 public:
117 
122  void newFile(int albumId);
123 
130  void newFileFullScan(int albumId);
131 
137  void rescan();
138 
144  void commit();
145 
149  qlonglong id() const;
150 
158  void copiedFrom(int albumId, qlonglong srcId);
159 
165  static void sortByProximity(QList<ItemInfo>& infos, const ItemInfo& subject);
166 
167 protected:
168 
169  bool copyFromSource(qlonglong src);
170  void commitCopyImageAttributes();
171 
172  void prepareAddImage(int albumId);
173  bool commitAddImage();
174 
176 
177  // -----------------------------------------------------------------------------
178 
183 
184 public:
185 
194  void fileModified();
195 
200  static void fillCommonContainer(qlonglong imageid, ImageCommonContainer* const container);
201 
206  static QDateTime creationDateFromFilesystem(const QFileInfo& info);
207 
208 protected:
209 
210  void prepareUpdateImage();
211  void commitUpdateImage();
212 
213  bool scanFromIdenticalFile();
214  void scanFile(ScanMode mode);
215 
216  void scanItemInformation();
217  void commitItemInformation();
218 
220 
221  // -----------------------------------------------------------------------------
222 
227 
228 public:
229 
235  static QString iptcCorePropertyName(MetadataInfo::Field field);
236 
237  static MetadataFields allImageMetadataFields();
238 
239 protected:
240 
241  QString detectImageFormat() const;
242 
243  void scanImageMetadata();
244  void commitImageMetadata();
245  void scanItemPosition();
246  void commitItemPosition();
247  void scanItemComments();
248  void commitItemComments();
249  void scanItemCopyright();
250  void commitItemCopyright();
251  void scanIPTCCore();
252  void commitIPTCCore();
253  void scanTags();
254  void commitTags();
255  void scanFaces();
256  void commitFaces();
257 
258  bool checkRatingFromMetadata(const QVariant& ratingFromMetadata) const;
259  void checkCreationDateFromMetadata(QVariant& dateFromMetadata) const;
260 
262 
263  // -----------------------------------------------------------------------------
264 
269 
270 public:
271 
276  static void fillVideoMetadataContainer(qlonglong imageid, VideoMetadataContainer* const container);
277 
278 protected:
279 
280  void scanVideoInformation();
281  void scanVideoMetadata();
282  void commitVideoMetadata();
283  QString detectVideoFormat() const;
284  QString detectAudioFormat() const;
285  static MetadataFields allVideoMetadataFields();
286 
288 
289  // -----------------------------------------------------------------------------
290 
295 
296 public:
297 
301  bool hasHistoryToResolve() const;
302 
304 
309  static bool resolveImageHistory(qlonglong id, QList<qlonglong>* needTaggingIds = nullptr);
310  static bool resolveImageHistory(qlonglong imageId, const QString& historyXml, QList<qlonglong>* needTaggingIds = nullptr);
312 
317  static void tagItemHistoryGraph(qlonglong id);
318 
329  static DImageHistory resolvedImageHistory(const DImageHistory& history, bool mustBeAvailable = false);
330 
335  static bool sameReferredImage(const HistoryImageId& id1, const HistoryImageId& id2);
336 
340  static QList<qlonglong> resolveHistoryImageId(const HistoryImageId& historyId);
341 
342 protected:
343 
344  void scanImageHistory();
345  void commitImageHistory();
346  void scanImageHistoryIfModified();
347 
348  QString uniqueHash() const;
349 
351 
352 public:
353 
357  void scanBalooInfo();
358 
359 private:
360 
361  // Disable
362  ItemScanner(const ItemScanner&) = delete;
363  ItemScanner& operator=(const ItemScanner&) = delete;
364 
365 private:
366 
367  class Private;
368  Private* const d;
369 };
370 
371 } // namespace Digikam
372 
373 #endif // DIGIKAM_ITEM_SCANNER_H
Definition: dimagehistory.h:49
Definition: historyimageid.h:42
Definition: coredbinfocontainers.h:36
Definition: iteminfo.h:78
Definition: coredbalbuminfo.h:277
Definition: itemscanner.h:44
ScanMode
Definition: itemscanner.h:49
@ ModifiedScan
Definition: itemscanner.h:51
@ NewScan
Definition: itemscanner.h:50
Definition: coredbinfocontainers.h:97
Category
Definition: coredbconstants.h:95
Field
Definition: metadatainfo.h:91
Definition: datefolderview.cpp:43