File indexing completed on 2025-01-19 03:53:38
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2007-05-01 0007 * Description : ItemInfo common data 0008 * 0009 * SPDX-FileCopyrightText: 2007-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0011 * 0012 * SPDX-License-Identifier: GPL-2.0-or-later 0013 * 0014 * ============================================================ */ 0015 0016 #ifndef DIGIKAM_ITEM_INFO_CACHE_H 0017 #define DIGIKAM_ITEM_INFO_CACHE_H 0018 0019 // Qt includes 0020 0021 #include <QHash> 0022 #include <QObject> 0023 #include <QMultiHash> 0024 #include <QExplicitlySharedDataPointer> 0025 0026 // Local includes 0027 0028 #include "coredbwatch.h" 0029 0030 namespace Digikam 0031 { 0032 0033 class AlbumShortInfo; 0034 class ItemInfoData; 0035 0036 // NOTE: No need to EXPORT this class 0037 class ItemInfoCache : public QObject 0038 { 0039 Q_OBJECT 0040 0041 public: 0042 0043 ItemInfoCache(); 0044 ~ItemInfoCache() override; 0045 0046 /** 0047 * Return an ItemInfoData object for the given image id. 0048 * A new object is created, or an existing object is returned. 0049 * If a new object is created, the id field will be initialized. 0050 */ 0051 QExplicitlySharedDataPointer<ItemInfoData> infoForId(qlonglong id); 0052 0053 /** 0054 * Call this when the data has been dereferenced, 0055 * before deletion. 0056 */ 0057 void dropInfo(const QExplicitlySharedDataPointer<ItemInfoData>& infoPtr); 0058 0059 /** 0060 * Call this to put data in the hash by file name if you have newly created data 0061 * and the name is filled. 0062 * Call under write lock. 0063 */ 0064 void cacheByName(const QExplicitlySharedDataPointer<ItemInfoData>& infoPtr); 0065 0066 /** 0067 * Return an ItemInfoData object for the given album root, relativePath and file name triple. 0068 * Works if previously cached with cacheByName. 0069 * Returns 0 if not found. 0070 */ 0071 QExplicitlySharedDataPointer<ItemInfoData> infoForPath(int albumRootId, 0072 const QString& relativePath, 0073 const QString& name); 0074 0075 /** 0076 * Returns the cached relativePath for the given album id. 0077 */ 0078 QString albumRelativePath(int albumId); 0079 0080 /** 0081 * Returns the cached grouped count for the given image id. 0082 */ 0083 int getImageGroupedCount(qlonglong id); 0084 0085 /** 0086 * Invalidate the cache and all its cached data 0087 */ 0088 void invalidate(); 0089 0090 private Q_SLOTS: 0091 0092 void slotImageChanged(const ImageChangeset& changeset); 0093 void slotImageTagChanged(const ImageTagChangeset& changeset); 0094 void slotAlbumChange(const AlbumChangeset&); 0095 0096 private: 0097 0098 // Disable 0099 explicit ItemInfoCache(QObject*) = delete; 0100 0101 QList<AlbumShortInfo>::const_iterator findAlbum(int id); 0102 void checkAlbums(); 0103 0104 private: 0105 0106 QMultiHash<QString, QExplicitlySharedDataPointer<ItemInfoData> > m_nameHash; 0107 QHash<qlonglong, QExplicitlySharedDataPointer<ItemInfoData> > m_infoHash; 0108 QHash<qlonglong, QString> m_dataHash; 0109 volatile bool m_needUpdateAlbums; 0110 volatile bool m_needUpdateGrouped; 0111 QList<qlonglong> m_grouped; 0112 QList<AlbumShortInfo> m_albums; 0113 }; 0114 0115 } // namespace Digikam 0116 0117 #endif // DIGIKAM_ITEM_INFO_CACHE_H