digiKam
scancontroller.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 : 2005-10-28
7  * Description : scan item controller.
8  *
9  * Copyright (C) 2005-2006 by Tom Albers <tomalbers at kde dot nl>
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_SCAN_CONTROLLER_H
27 #define DIGIKAM_SCAN_CONTROLLER_H
28 
29 // Qt includes
30 
31 #include <QThread>
32 #include <QString>
33 #include <QList>
34 
35 // Local includes
36 
37 #include "digikam_export.h"
39 #include "collectionscannerhints.h"
40 #include "iteminfo.h"
41 #include "loadingcache.h"
42 #include "coredbchangesets.h"
43 
44 namespace Digikam
45 {
46 
47 class CollectionScanner;
48 class PAlbum;
49 
50 class DIGIKAM_GUI_EXPORT ScanController : public QThread,
52 {
53  Q_OBJECT
54 
55 public:
56 
57  enum Advice
58  {
61  AbortImmediately
62  };
63 
64 public:
65 
75  {
76  public:
77 
78  explicit FileMetadataWrite(const ItemInfo& info);
80 
81  void changed(bool wasChanged);
82 
83  protected:
84 
86  bool m_changed;
87  };
88 
89 public:
90 
91  static ScanController* instance();
92 
99  void updateUniqueHash();
100 
101  void allowToScanDeferredFiles();
102 
107  ItemInfo scannedInfo(const QString& filePath);
108 
112  QList<qlonglong> getNewIdsList() const;
113 
114 protected:
115 
116  void run() override;
117 
118 private:
119 
120  explicit ScanController();
121  ~ScanController() override;
122 
123  void setInitializationMessage();
124  void createProgressDialog();
125 
126  bool continueQuery() override;
127  void connectCollectionScanner(CollectionScanner* const scanner) override;
128 
129  // -----------------------------------------------------------------------------
130 
135 
136 public:
137 
143  Advice databaseInitialization();
144 
154  void completeCollectionScan(bool defer = false);
155  void completeCollectionScanDeferFiles();
156 
161  void completeCollectionScanInBackground(bool defer, bool fastScan = true);
162 
167  void scheduleCollectionScan(const QString& path);
168 
176  void scheduleCollectionScanRelaxed(const QString& path);
177 
186  void scheduleCollectionScanExternal(const QString& path);
187 
191  void beginFileMetadataWrite(const ItemInfo& info);
192 
201  void resumeCollectionScan();
202 
203 Q_SIGNALS:
204 
205  void databaseInitialized(bool success);
206  void collectionScanStarted(const QString& message);
207 
208 private Q_SLOTS:
209 
210  void slotStartCompleteScan();
211  void slotStartScanningAlbum(const QString& albumRoot, const QString& album);
212  void slotStartScanningAlbumRoot(const QString& albumRoot);
213  void slotStartScanningForStaleAlbums();
214  void slotStartScanningAlbumRoots();
215 
216 private:
217 
222  void scanFileDirectly(const QString& filePath);
223  void scanFileDirectlyNormal(const ItemInfo& info);
224  void completeCollectionScanCore(bool needTotalFiles, bool defer, bool fastScan);
225 
227 
228  // -----------------------------------------------------------------------------
229 
234 
235 public:
236 
245  void hintAtMoveOrCopyOfAlbum(const PAlbum* const album,
246  const PAlbum* const dstAlbum,
247  const QString& newAlbumName = QString());
248  void hintAtMoveOrCopyOfAlbum(const PAlbum* const album,
249  const QString& dstPath,
250  const QString& newAlbumName = QString());
251 
259  void hintAtMoveOrCopyOfItems(const QList<qlonglong>& ids,
260  const PAlbum* const dstAlbum,
261  const QStringList& itemNames);
262  void hintAtMoveOrCopyOfItem(qlonglong id,
263  const PAlbum* const dstAlbum,
264  const QString& itemName);
265 
270  void hintAtModificationOfItems(const QList<qlonglong>& ids);
271  void hintAtModificationOfItem(qlonglong id);
272 
273 Q_SIGNALS:
274 
275  void totalFilesToScan(int);
276  void filesScanned(int);
277  void scanningProgress(float progress);
280  void progressFromInitialization(const QString&, int);
281 
282 private Q_SLOTS:
283 
284  void slotTotalFilesToScan(int count);
285  void slotScannedFiles(int scanned);
286  void slotShowProgressDialog();
287  void slotTriggerShowProgressDialog();
288  void slotProgressFromInitialization(const QString& message, int numberOfSteps);
289  void slotErrorFromInitialization(const QString& errorMessage);
290 
291 private:
292 
293  void moreSchemaUpdateSteps(int numberOfSteps) override;
294  void schemaUpdateProgress(const QString& message, int numberOfSteps) override;
295  void error(const QString& errorMessage) override;
296 
297  AlbumCopyMoveHint hintForAlbum(const PAlbum* const album,
298  int dstAlbumRootId,
299  const QString& relativeDstPath,
300  const QString& albumName);
301 
302  QList<AlbumCopyMoveHint> hintsForAlbum(const PAlbum* const album,
303  int dstAlbumRootId,
304  const QString& relativeDstPath,
305  const QString& albumName);
307 
308  // -----------------------------------------------------------------------------
309 
314 
315 public:
316 
320  void shutDown();
321 
327  void abortInitialization();
328 
334  void cancelCompleteScan();
335 
342  void cancelAllAndSuspendCollectionScan();
343 
352  void suspendCollectionScan();
353 
357  void finishFileMetadataWrite(const ItemInfo& info, bool changed);
358 
359 Q_SIGNALS:
360 
362  void newImages(const ItemInfoList&);
363  void partialScanDone(const QString& path);
366  void errorFromInitialization(const QString&);
367 
368 private Q_SLOTS:
369 
370  void slotCancelPressed();
371  void slotRelaxedScanning();
372 
373 private:
374 
375  void finishedSchemaUpdate(UpdateResult result) override;
376 
378 
379 private:
380 
381  // Disable
382  ScanController(QObject*) = delete;
383  ScanController(const ScanController&) = delete;
384  ScanController& operator=(const ScanController&) = delete;
385 
386 private:
387 
388  friend class ScanControllerCreator;
389 
390  class Private;
391  Private* const d;
392 };
393 
394 } // namespace Digikam
395 
396 #endif // DIGIKAM_SCAN_CONTROLLER_H
Definition: collectionscannerhints.h:155
Definition: collectionscanner.h:50
Definition: collectionscannerobserver.h:57
UpdateResult
Definition: collectionscannerobserver.h:61
Definition: iteminfolist.h:47
Definition: iteminfo.h:78
Definition: album.h:357
Definition: scancontroller_p.h:179
Definition: scancontroller.h:75
bool m_changed
Definition: scancontroller.h:86
ItemInfo m_info
Definition: scancontroller.h:85
Definition: scancontroller_p.h:111
Definition: scancontroller.h:52
void incrementProgressDialog(int)
void scanningProgress(float progress)
void progressFromInitialization(const QString &, int)
Advice
Definition: scancontroller.h:58
@ Success
Definition: scancontroller.h:59
@ ContinueWithoutDatabase
Definition: scancontroller.h:60
void collectionScanStarted(const QString &message)
void databaseInitialized(bool success)
void newImages(const ItemInfoList &)
void partialScanDone(const QString &path)
void errorFromInitialization(const QString &)
Definition: datefolderview.cpp:43