Debian Codegraph @

core/libs/album/engine/albumthumbnailloader.h

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2006-04-14
7 * Description : Load and cache tag thumbnails
8 *
9 * SPDX-FileCopyrightText: 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 *
14 * ============================================================ */
15
16 #pragma once
17
18 // Qt includes
19
20 #include <QObject>
21 #include <QPixmap>
22
23 // Local includes
24
25 #include "digikam_export.h"
26
27 namespace Digikam
28 {
29 class Album;
30 class TAlbum;
31 class PAlbum;
32 class LoadingDescription;
33
34 class DIGIKAM_GUI_EXPORT AlbumThumbnailLoader : public QObject
35 {
36 Q_OBJECT
37
38 public:
39
40 /**
41 * Album thumbnail size is configurable via the settings menu.
42 * Some widgets use smaller icons than other widgets.
43 * These widgets do not need to know the currently set icon size from
44 * the setup and calculate a smaller size, but can simply request
45 * a relatively smaller icon.
46 * Depending on the user-chosen icon size, this size may in fact not
47 * be smaller than the normal size.
48 */
49 enum RelativeSize
50 {
51 NormalSize,
52 SmallerSize
53 };
54
55 public:
56
57 AlbumThumbnailLoader();
58 ~AlbumThumbnailLoader() override;
59
60 static AlbumThumbnailLoader* instance();
61
62 void cleanUp();
63
64 /**
65 * Change the size of the thumbnails.
66 * If the size differs from the current size,
67 * signalReloadThumbnails will be emitted.
68 */
69 void setThumbnailSize(int size, int face);
70
71 /**
72 * Get the current default icon size
73 */
74 int thumbnailSize() const;
75
76 /**
77 * Request thumbnail for given album.
78 * The thumbnail will be loaded
79 * and returned asynchronously by the signals.
80 * If no thumbnail is associated with given album,
81 * no action will be taken, and false is returned.
82 */
83 bool getAlbumThumbnail(PAlbum* const album);
84
85 /**
86 * Request thumbnail for given album,
87 * with slightly different behavior than the above method:
88 * If the thumbnail is already available in the cache,
89 * it is returned.
90 * If the icon is not yet loaded, it will be returned asynchronously
91 * by the signals, and a default icon is returned here.
92 * If no icon is associated, the default icon is returned.
93 */
94 QPixmap getAlbumThumbnailDirectly(PAlbum* const album);
95
96 /**
97 * Behaves similar to the above method.
98 * Tag thumbnails will be processed as appropriate.
99 * Tags may have associated an icon that is loaded
100 * synchronously by the system icon loader.
101 * In this case, icon is set to this icon, and false is returned.
102 * If no icon is associated with the tag, icon is set to null,
103 * and false is returned.
104 * If a custom icon is associated with the tag,
105 * it is loaded asynchronously, icon is set to null,
106 * and true is returned.
107 * Tag thumbnails are always smaller than album thumbnails -
108 * as small as an album thumbnail with SmallerSize.
109 * They are supposed to be blended into the standard tag icon
110 * obtained below, or used as is when SmallerSize is requested anyway.
111 * @return Returns true if icon is loaded asynchronously.
112 */
113 bool getTagThumbnail(TAlbum* const album, QPixmap& icon);
114
115 /**
116 * Loads tag thumbnail,
117 * with slightly different behavior than the above method:
118 * If the thumbnail is already available in the cache,
119 * it is returned, already blended with the standard icon, if requested.
120 * If the icon is not yet loaded, it will be returned asynchronously
121 * by the signals (unblended), and a default icon is returned here.
122 * If no icon is associated, the default icon is returned.
123 */
124 QPixmap getTagThumbnailDirectly(TAlbum* const album);
125
126 /**
127 * Loads face tag thumbnail,
128 * like getTagThumbnailDirectly() but
129 * loads thumbnails in the size for faces
130 */
131 QPixmap getFaceThumbnailDirectly(TAlbum* const album);
132
133 /**
134 * Return standard tag and album icons.
135 * The third methods check if album is the root,
136 * and returns the standard icon or the root standard icon.
137 */
138 QPixmap getStandardTagIcon(RelativeSize size = NormalSize);
139 QPixmap getStandardTagRootIcon(RelativeSize size = NormalSize);
140 QPixmap getStandardTagIcon(TAlbum* const album, RelativeSize size = NormalSize);
141 QPixmap getStandardFaceIcon(TAlbum* const album, RelativeSize size = NormalSize);
142 QPixmap getNewTagIcon(RelativeSize size = NormalSize);
143
144 QPixmap getStandardAlbumIcon(PAlbum* const album, RelativeSize size = NormalSize);
145 QPixmap getStandardEmptyTrashIcon(RelativeSize size = NormalSize);
146 QPixmap getStandardFullTrashIcon(RelativeSize size = NormalSize);
147 QPixmap getStandardAlbumRootIcon(RelativeSize size = NormalSize);
148 QPixmap getStandardOfflineIcon(RelativeSize size = NormalSize);
149 QPixmap getStandardAlbumIcon(RelativeSize size = NormalSize);
150
151 /**
152 * Return a preview of physical album directly without to use cache.
153 * Size of image can be passed as argument.
154 */
155 /*
156 QImage getAlbumPreviewDirectly(PAlbum* const album, int size);
157 */
158
159 Q_SIGNALS:
160
161 /**
162 * This signal is emitted as soon as a thumbnail has become available
163 * for given album.
164 * This class is a singleton, so any object connected to this
165 * signal might not actually have requested a thumbnail for given url
166 */
167 void signalThumbnail(Album* album, const QPixmap&);
168
169 /** This signal is emitted if thumbnail generation for given album failed.
170 * Same considerations as above.
171 */
172 void signalFailed(Album* album);
173
174 /**
175 * Indicates that all album and tag thumbnails need to be reloaded.
176 * This is usually because the icon size has changed in the setup.
177 */
178 void signalReloadThumbnails();
179
180 /**
181 * Internal signal to dispatch Album thumbnail change.
182 */
183 void signalDispatchThumbnailInternal(int albumID, const QPixmap& thumbnail);
184
185 protected Q_SLOTS:
186
187 void slotGotThumbnailFromIcon(const LoadingDescription& loadingDescription, const QPixmap& pixmap);
188 void slotIconChanged(Album* album);
189 void slotDispatchThumbnailInternal(int albumID, const QPixmap& thumbnail);
190
191 private:
192
193 /// @note disabled
194 explicit AlbumThumbnailLoader(QObject*) = delete;
195
196 void addUrl(Album* const album, qlonglong id);
197 QPixmap loadIcon(const QString& name, int size = 0) const;
198 int computeIconSize(RelativeSize size) const;
199 int computeFaceSize(RelativeSize size) const;
200
201 private:
202
203 class Private;
204 Private* const d = nullptr;
205 };
206
207 } // namespace Digikam