digiKam
albummanager.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 : 2004-06-15
7  * Description : Albums manager interface.
8  *
9  * Copyright (C) 2004 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2006-2011 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_ALBUM_MANAGER_H
27 #define DIGIKAM_ALBUM_MANAGER_H
28 
29 // Qt includes
30 
31 #include <QList>
32 #include <QObject>
33 #include <QString>
34 #include <QMap>
35 #include <QUrl>
36 #include <QDate>
37 #include <QFileInfo>
38 
39 // Local includes
40 
41 #include "album.h"
42 #include "coredbalbuminfo.h"
43 #include "dbengineparameters.h"
44 #include "digikam_export.h"
45 #include "itemlisterrecord.h"
46 
47 namespace Digikam
48 {
49 
50 class FAlbum;
51 class CollectionLocation;
52 class AlbumChangeset;
53 class TagChangeset;
54 class SearchChangeset;
55 class CollectionImageChangeset;
56 class ImageTagChangeset;
57 
72 class DIGIKAM_GUI_EXPORT AlbumManager : public QObject
73 {
74  Q_OBJECT
75 
76 public:
77 
81  static AlbumManager* instance();
82 
89  void startScan();
90 
94  void cleanUp();
95 
103  void refresh();
104 
108  void prepareItemCounts();
109 
110  bool isShowingOnlyAvailableAlbums() const;
111  void setShowOnlyAvailableAlbums(bool onlyAvailable);
112 
113 private Q_SLOTS:
114 
115  void slotImagesDeleted(const QList<qlonglong>& imageIds);
116 
117  // -----------------------------------------------------------------------------
118 
124 
125 public:
126 
133  bool setDatabase(const DbEngineParameters& params, bool priority,
134  const QString& suggestedAlbumRoot = QString());
135 
141  void changeDatabase(const DbEngineParameters& params);
142 
146  bool databaseEqual(const DbEngineParameters& parameters) const;
147 
148  void addFakeConnection();
149  void removeFakeConnection();
150 
154  static void checkDatabaseDirsAfterFirstRun(const QString& dbPath, const QString& albumPath);
155 
156 private:
157 
158  static bool moveToBackup(const QFileInfo& info);
159  static bool copyToNewLocation(const QFileInfo& oldFile,
160  const QFileInfo& newFile,
161  const QString& otherMessage = QString());
162 
164 
165  // -----------------------------------------------------------------------------
166 
172 
173 private:
174 
178  bool handleCollectionStatusChange(const CollectionLocation& location, int oldStatus);
179 
180  void addAlbumRoot(const CollectionLocation& location);
181  void removeAlbumRoot(const CollectionLocation& location);
182 
183 private Q_SLOTS:
184 
185  void slotCollectionLocationStatusChanged(const CollectionLocation&, int);
186  void slotCollectionLocationPropertiesChanged(const CollectionLocation& location);
187  void slotCollectionImageChange(const CollectionImageChangeset& changeset);
188 
190 
191  // -----------------------------------------------------------------------------
192 
198 
199 public:
200 
204  void setCurrentAlbums(const QList<Album*>& albums);
205 
209  AlbumList currentAlbums() const;
210 
214  void clearCurrentAlbums();
215 
220  Album* findAlbum(int gid) const;
221 
226  Album* findAlbum(Album::Type type, int id) const;
227 
231  QHash<int, QString> albumTitles() const;
232 
240  bool isMovingAlbum(Album* album) const;
241 
249  qlonglong getItemFromAlbum(Album* const album, const QString& fileName);
250 
251 private:
252 
253  bool hasDirectChildAlbumWithTitle(Album* parent, const QString& title);
254  void notifyAlbumDeletion(Album* album);
255  void updateAlbumPathHash();
256  void addGuardedPointer(Album* a, Album** pointer);
257  void removeGuardedPointer(Album* a, Album** pointer);
258  void changeGuardedPointer(Album* oldAlbum, Album* a, Album** pointer);
259  void invalidateGuardedPointers(Album* album);
260 
261 private Q_SLOTS:
262 
263  void slotAlbumsJobResult();
264  void slotAlbumsJobData(const QMap<int, int>& albumsStatMap);
265  void slotAlbumChange(const AlbumChangeset& changeset);
266  void getAlbumItemsCount();
267 
268 Q_SIGNALS:
269 
274  void signalAlbumAboutToBeAdded(Album* album, Album* parent, Album* prev);
275 
279  void signalAlbumAdded(Album* album);
280 
285 
289  void signalAlbumDeleted(Album* album);
290 
296 
300 
302  void signalAlbumRenamed(Album* album);
303  void signalAlbumNewPath(Album* album);
304 
310 
315  void signalAlbumMoved(Album* album);
316  void signalAlbumsUpdated(int type);
317 
322  void signalShowOnlyAvailableAlbumsChanged(bool showsOnlyAvailableAlbums);
323 
325 
326  // -----------------------------------------------------------------------------
327 
333 
334 public:
335 
339  AlbumList allDAlbums() const;
340 
345  DAlbum* findDAlbum(int id) const;
346 
353  QMap<YearMonth, int> getDAlbumsCount() const;
354 
355 private Q_SLOTS:
356 
357  void slotDatesJobResult();
358  void slotDatesJobData(const QHash<QDateTime, int>& datesStatMap);
359 
363  void scanDAlbumsScheduled();
364  void scanDAlbums();
365 
366 Q_SIGNALS:
367 
368  void signalDAlbumsDirty(const QMap<YearMonth, int>&);
369  void signalDatesHashDirty(const QHash<QDateTime, int>&);
371 
373 
374  // -----------------------------------------------------------------------------
375 
381 
382 public:
383 
387  AlbumList allPAlbums() const;
388 
392  PAlbum* currentPAlbum() const;
393 
401  PAlbum* findPAlbum(const QUrl& url) const;
402 
407  PAlbum* findPAlbum(int id) const;
408 
415  QMap<int, int> getPAlbumsCount() const;
416 
417  void removeWatchedPAlbums(const PAlbum* const album);
418 
436  PAlbum* createPAlbum(PAlbum* parent, const QString& name,
437  const QString& caption, const QDate& date,
438  const QString& category,
439  QString& errMsg);
440 
445  PAlbum* createPAlbum(const QString& albumRootPath, const QString& name,
446  const QString& caption, const QDate& date,
447  const QString& category,
448  QString& errMsg);
449 
456  PAlbum* createPAlbum(const CollectionLocation& location, const QString& name,
457  const QString& caption, const QDate& date,
458  const QString& category,
459  QString& errMsg);
460 
470  bool renamePAlbum(PAlbum* album, const QString& newName,
471  QString& errMsg);
472 
482  bool updatePAlbumIcon(PAlbum* album, qlonglong iconID, QString& errMsg);
483 
484 private:
485 
486  bool showDatabaseSetupPage(const QString& error, bool priority, const QString& suggestedAlbumRoot);
487  void insertPAlbum(PAlbum* album, PAlbum* parent);
488  void removePAlbum(PAlbum* album);
489 
490 private Q_SLOTS:
491 
497  void scanPAlbums();
498  void updateChangedPAlbums();
499 
500 Q_SIGNALS:
501 
502  void signalPAlbumsDirty(const QMap<int, int>&);
503 
505 
506  // -----------------------------------------------------------------------------
507 
513 
514 public:
515 
519  AlbumList allTAlbums() const;
520 
524  QList<TAlbum*> currentTAlbums() const;
525 
530  TAlbum* findTAlbum(int id) const;
531 
536  TAlbum* findTAlbum(const QString& tagPath) const;
537 
544  QMap<int, int> getTAlbumsCount() const;
545 
559  TAlbum* createTAlbum(TAlbum* parent, const QString& name,
560  const QString& iconkde, QString& errMsg);
561 
568  AlbumList findOrCreateTAlbums(const QStringList& tagPaths);
569 
581  bool deleteTAlbum(TAlbum* album, QString& errMsg, bool askUser = true);
582 
592  bool renameTAlbum(TAlbum* album, const QString& name, QString& errMsg);
593 
603  bool moveTAlbum(TAlbum* album, TAlbum* newParent, QString& errMsg);
604 
616  bool mergeTAlbum(TAlbum* album, TAlbum* destAlbum, bool dialog, QString& errMsg);
617 
630  bool updateTAlbumIcon(TAlbum* album, const QString& iconKDE,
631  qlonglong iconID, QString& errMsg);
632 
638  AlbumList getRecentlyAssignedTags(bool includeInternal = false) const;
639 
646  QStringList tagPaths(const QList<int>& tagIDs, bool leadingSlash=true, bool includeInternal = false) const;
647 
652  QStringList tagNames(const QList<int>& tagIDs, bool includeInternal = false) const;
653 
657  QHash<int, QString> tagPaths(bool leadingSlash=true, bool includeInternal = false) const;
658 
662  QHash<int, QString> tagNames(bool includeInternal = false) const;
663 
668  AlbumList findTagsWithProperty(const QString& property);
669  AlbumList findTagsWithProperty(const QString& property, const QString& value);
670 
674  QList<int> subTags(int tagId, bool recursive = false);
675 
676 private:
677 
686  void askUserForWriteChangedTAlbumToFiles(TAlbum* const album);
687  void askUserForWriteChangedTAlbumToFiles(const QList<qlonglong>& imageIds);
688 
689  void insertTAlbum(TAlbum* album, TAlbum* parent);
690  void removeTAlbum(TAlbum* album);
691 
692 private Q_SLOTS:
693 
699  void scanTAlbums();
700 
701  void slotTagsJobResult();
702  void slotTagsJobData(const QMap<int, int>& tagsStatMap);
703  void slotTagChange(const TagChangeset& changeset);
704  void slotImageTagChange(const ImageTagChangeset& changeset);
705 
706  void getTagItemsCount();
707  void tagItemsCount();
708 
709 Q_SIGNALS:
710 
711  void signalTAlbumsDirty(const QMap<int, int>&);
713 
715 
716  // -----------------------------------------------------------------------------
717 
723 
724 public:
725 
729  AlbumList allSAlbums() const;
730 
735  SAlbum* findSAlbum(int id) const;
736 
741  SAlbum* findSAlbum(const QString& name) const;
742 
747  QList<SAlbum*> findSAlbumsBySearchType(int searchType) const;
748 
761  SAlbum* createSAlbum(const QString& name,
763  const QString& query);
764 
773  bool updateSAlbum(SAlbum* album,
774  const QString& changedQuery,
775  const QString& changedName = QString(),
777 
785  bool deleteSAlbum(SAlbum* album);
786 
787 private Q_SLOTS:
788 
794  void scanSAlbums();
795 
796  void slotSearchChange(const SearchChangeset& changeset);
797 
798 Q_SIGNALS:
799 
800  void signalUpdateDuplicatesAlbums(const QList<SAlbum*>& modifiedAlbums,
801  const QList<qlonglong>& deletedImages);
803 
805 
806  // -----------------------------------------------------------------------------
807 
813 
814 public:
815 
822  QMap<int, int> getFaceCount() const;
823 
830  QMap<int, int> getUnconfirmedFaceCount() const;
831 
832 private Q_SLOTS:
833 
834  void slotPeopleJobResult();
835  void slotPeopleJobData(const QMap<QString,
836  QMap<int, int> >& facesStatMap);
837  void personItemsCount();
838 
839 Q_SIGNALS:
840 
841  void signalFaceCountsDirty(const QMap<int, int>& faceCount,
842  const QMap<int, int>& uFaceCount,
843  const QList<int>& toUpdatedFaces);
844 
846 
847 private:
848 
849  // Disable
850  AlbumManager();
851  explicit AlbumManager(QObject*) = delete;
852  ~AlbumManager() override;
853 
854  friend class AlbumManagerCreator;
855 
856  static AlbumManager* internalInstance;
857 
858 public:
859 
860  // Declared public because it used in ChangingDB class.
861  class Private;
862 
863 private:
864 
865  Private* const d;
866 
867  template <class T> friend class AlbumPointer;
868  friend class Album;
869 };
870 
871 } // namespace Digikam
872 
873 #endif // DIGIKAM_ALBUM_MANAGER_H
Definition: coredbchangesets.h:262
Definition: albummanager_p.h:227
Definition: albummanager_p.h:149
Definition: albummanager.h:73
void signalAlbumAboutToBeMoved(Album *album)
void signalAlbumHasBeenDeleted(quintptr)
void signalTAlbumsDirty(const QMap< int, int > &)
void signalAlbumAboutToBeAdded(Album *album, Album *parent, Album *prev)
void signalUpdateDuplicatesAlbums(const QList< SAlbum * > &modifiedAlbums, const QList< qlonglong > &deletedImages)
void signalAlbumDeleted(Album *album)
void signalPAlbumsDirty(const QMap< int, int > &)
void signalDAlbumsDirty(const QMap< YearMonth, int > &)
void signalDatesHashDirty(const QHash< QDateTime, int > &)
void signalFaceCountsDirty(const QMap< int, int > &faceCount, const QMap< int, int > &uFaceCount, const QList< int > &toUpdatedFaces)
void signalShowOnlyAvailableAlbumsChanged(bool showsOnlyAvailableAlbums)
void signalAlbumCurrentChanged(const QList< Album * > &albums)
void signalTagPropertiesChanged(TAlbum *album)
void signalAlbumMoved(Album *album)
void signalAlbumIconChanged(Album *album)
void signalAlbumRenamed(Album *album)
void signalAlbumNewPath(Album *album)
void signalAlbumsUpdated(int type)
void signalAlbumAdded(Album *album)
void signalSearchUpdated(SAlbum *album)
void signalAlbumAboutToBeDeleted(Album *album)
Definition: albumpointer.h:48
Abstract base class for all album types.
Definition: album.h:67
Type
Definition: album.h:71
Definition: coredbchangesets.h:152
Definition: collectionlocation.h:41
Definition: album.h:460
Definition: dbengineparameters.h:49
Definition: coredbchangesets.h:80
Definition: album.h:357
Definition: album.h:493
Definition: coredbchangesets.h:372
Definition: album.h:420
Definition: coredbchangesets.h:298
qulonglong value
Definition: itemviewutilities.cpp:592
Type
Definition: coredbconstants.h:60
@ UndefinedType
Definition: coredbconstants.h:61
std::vector< T > location(const std::vector< T > &shape, unsigned long idx)
Definition: shapepredictor.h:109
Definition: datefolderview.cpp:43