digiKam
collectionscanner.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-03-21
7  * Description : Collection scanning to database.
8  *
9  * Copyright (C) 2005 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2005-2006 by Tom Albers <tomalbers at kde dot nl>
11  * Copyright (C) 2007-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  * Copyright (C) 2009-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_COLLECTION_SCANNER_H
28 #define DIGIKAM_COLLECTION_SCANNER_H
29 
30 // Qt includes
31 
32 #include <QString>
33 #include <QObject>
34 #include <QList>
35 
36 // Local includes
37 
38 #include "iteminfo.h"
39 #include "digikam_export.h"
40 #include "coredbaccess.h"
41 #include "coredbalbuminfo.h"
42 #include "collectionscannerhints.h"
43 
44 class QFileInfo;
45 
46 namespace Digikam
47 {
48 
49 class DIGIKAM_DATABASE_EXPORT CollectionScanner : public QObject
50 {
51  Q_OBJECT
52 
53 public:
54 
56  {
64 
72 
78  Rescan
79  };
80 
81 public:
82 
83  explicit CollectionScanner();
84  ~CollectionScanner() override;
85 
87 
94  static CollectionScannerHintContainer* createHintContainer();
95  void setHintContainer(CollectionScannerHintContainer* const container);
96  void setUpdateHashHint(bool hint = true);
98 
103  void setSignalsEnabled(bool on);
104 
110  void setNeedFileCount(bool on);
111 
116  void setPerformFastScan(bool on);
117 
121  void setObserver(CollectionScannerObserver* const observer);
122 
123  void setDeferredFileScanning(bool defer);
124  QStringList deferredAlbumPaths() const;
125 
129  QList<qlonglong> getNewIdsList() const;
130 
131  // -----------------------------------------------------------------------------
132 
137 
138 public:
139 
146  void completeScan();
147 
155  void finishCompleteScan(const QStringList& albumPaths);
156 
162  static bool databaseInitialScanDone();
163 
170  void partialScan(const QString& filePath);
171 
175  void partialScan(const QString& albumRoot, const QString& album);
176 
181  qlonglong scanFile(const QString& filePath, FileScanMode mode = ModifiedScan);
182 
188  qlonglong scanFile(const QString& albumRoot,
189  const QString& album,
190  const QString& fileName,
191  FileScanMode mode = ModifiedScan);
192 
196  void scanFile(const ItemInfo& info, FileScanMode mode = ModifiedScan);
197 
198 protected:
199 
200  void scanForStaleAlbums(const QList<CollectionLocation>& locations);
201  void scanForStaleAlbums(const QList<int>& locationIdsToScan);
202  void scanAlbumRoot(const CollectionLocation& location);
203  void scanAlbum(const CollectionLocation& location, const QString& album, bool checkDate = false);
204  void scanExistingFile(const QFileInfo& fi, qlonglong id);
205  void scanFileNormal(const QFileInfo& info, const ItemScanInfo& scanInfo, bool checkSidecar = true);
206  void scanModifiedFile(const QFileInfo& info, const ItemScanInfo& scanInfo);
207  void scanFileUpdateHashReuseThumbnail(const QFileInfo& fi, const ItemScanInfo& scanInfo, bool fileWasEdited);
208  void rescanFile(const QFileInfo& info, const ItemScanInfo& scanInfo);
209  void completeScanCleanupPart();
210  void completeHistoryScanning();
211  void finishHistoryScanning();
212  void historyScanningStage2(const QList<qlonglong>& ids);
213  void historyScanningStage3(const QList<qlonglong>& ids);
214 
215  qlonglong scanFile(const QFileInfo& fi, int albumId, qlonglong id, FileScanMode mode);
216  qlonglong scanNewFile(const QFileInfo& info, int albumId);
217  qlonglong scanNewFileFullScan(const QFileInfo& info, int albumId);
218 
220 
221  // -----------------------------------------------------------------------------
222 
227 
228 public:
229 
235  void safelyRemoveAlbums(const QList<int>& albumIds);
236 
241  static void copyFileProperties(const ItemInfo& source, const ItemInfo& dest);
242 
243 protected:
244 
245  void markDatabaseAsScanned();
246  void mainEntryPoint(bool complete);
247  int checkAlbum(const CollectionLocation& location, const QString& album);
248  void itemsWereRemoved(const QList<qlonglong>& removedIds);
249  void updateRemovedItemsTime();
250  void incrementDeleteRemovedCompleteScanCount();
251  void resetDeleteRemovedSettings();
252  bool checkDeleteRemoved();
253  void loadNameFilters();
254  int countItemsInFolder(const QString& path);
255  DatabaseItem::Category category(const QFileInfo& info);
256 
258 
259 Q_SIGNALS:
260 
265  void totalFilesToScan(int count);
266 
268 
272  void startScanningAlbumRoot(const QString& albumRoot);
273  void startScanningAlbum(const QString& albumRoot, const QString& album);
277  void signalScannedNewImage(const QFileInfo& info);
279 
281 
285  void finishedScanningAlbumRoot(const QString& albumRoot);
286  void finishedScanningAlbum(const QString& albumRoot, const QString& album, int filesScanned);
290 
296  void scannedFiles(int filesScanned);
297 
301  void cancelled();
302 
303 private:
304 
305  // Disable
306  CollectionScanner(QObject*) = delete;
307 
308  class Private;
309  Private* const d;
310 };
311 
312 } // namespace Digikam
313 
314 #endif // DIGIKAM_COLLECTION_SCANNER_H
Definition: collectionlocation.h:41
Definition: collectionscannerhints.h:56
Definition: collectionscannerobserver.h:41
Definition: collectionscanner_p.h:138
Definition: collectionscanner.h:50
void scannedFiles(int filesScanned)
void scanExistingFile(const QFileInfo &fi, qlonglong id)
void finishedScanningAlbumRoot(const QString &albumRoot)
void signalScannedNewImage(const QFileInfo &info)
void totalFilesToScan(int count)
void startScanningAlbum(const QString &albumRoot, const QString &album)
FileScanMode
Definition: collectionscanner.h:56
@ ModifiedScan
Definition: collectionscanner.h:71
@ NormalScan
Definition: collectionscanner.h:63
void startScanningAlbumRoot(const QString &albumRoot)
void finishedScanningAlbum(const QString &albumRoot, const QString &album, int filesScanned)
Definition: iteminfo.h:78
Definition: coredbalbuminfo.h:277
Category
Definition: coredbconstants.h:95
std::vector< T > location(const std::vector< T > &shape, unsigned long idx)
Definition: shapepredictor.h:109
Definition: datefolderview.cpp:43