File indexing completed on 2025-01-05 03:53:48

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-04-14
0007  * Description : Load and cache tag thumbnails
0008  *
0009  * SPDX-FileCopyrightText: 2006-2010 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2015      by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #ifndef DIGIKAM_ALBUM_THUMBNAIL_LOADER_H
0017 #define DIGIKAM_ALBUM_THUMBNAIL_LOADER_H
0018 
0019 // Qt includes
0020 
0021 #include <QObject>
0022 #include <QPixmap>
0023 
0024 // Local includes
0025 
0026 #include "digikam_export.h"
0027 
0028 namespace Digikam
0029 {
0030 class Album;
0031 class TAlbum;
0032 class PAlbum;
0033 class LoadingDescription;
0034 
0035 class DIGIKAM_GUI_EXPORT AlbumThumbnailLoader : public QObject
0036 {
0037     Q_OBJECT
0038 
0039 public:
0040 
0041     /**
0042      * Album thumbnail size is configurable via the settings menu.
0043      * Some widgets use smaller icons than other widgets.
0044      * These widgets do not need to know the currently set icon size from
0045      * the setup and calculate a smaller size, but can simply request
0046      * a relatively smaller icon.
0047      * Depending on the user-chosen icon size, this size may in fact not
0048      * be smaller than the normal size.
0049      */
0050     enum RelativeSize
0051     {
0052         NormalSize,
0053         SmallerSize
0054     };
0055 
0056 public:
0057 
0058     void cleanUp();
0059 
0060     /**
0061      * Change the size of the thumbnails.
0062      * If the size differs from the current size,
0063      * signalReloadThumbnails will be emitted.
0064      */
0065     void setThumbnailSize(int size, int face);
0066 
0067     /**
0068      * Get the current default icon size
0069      */
0070     int  thumbnailSize() const;
0071 
0072     /**
0073      * Request thumbnail for given album.
0074      * The thumbnail will be loaded
0075      * and returned asynchronously by the signals.
0076      * If no thumbnail is associated with given album,
0077      * no action will be taken, and false is returned.
0078      */
0079     bool getAlbumThumbnail(PAlbum* const album);
0080 
0081     /**
0082      * Request thumbnail for given album,
0083      * with slightly different behavior than the above method:
0084      * If the thumbnail is already available in the cache,
0085      * it is returned.
0086      * If the icon is not yet loaded, it will be returned asynchronously
0087      * by the signals, and a default icon is returned here.
0088      * If no icon is associated, the default icon is returned.
0089      */
0090     QPixmap getAlbumThumbnailDirectly(PAlbum* const album);
0091 
0092     /**
0093      * Behaves similar to the above method.
0094      * Tag thumbnails will be processed as appropriate.
0095      * Tags may have associated an icon that is loaded
0096      * synchronously by the system icon loader.
0097      * In this case, icon is set to this icon, and false is returned.
0098      * If no icon is associated with the tag, icon is set to null,
0099      * and false is returned.
0100      * If a custom icon is associated with the tag,
0101      * it is loaded asynchronously, icon is set to null,
0102      * and true is returned.
0103      * Tag thumbnails are always smaller than album thumbnails -
0104      * as small as an album thumbnail with SmallerSize.
0105      * They are supposed to be blended into the standard tag icon
0106      * obtained below, or used as is when SmallerSize is requested anyway.
0107      * @return Returns true if icon is loaded asynchronously.
0108      */
0109     bool getTagThumbnail(TAlbum* const album, QPixmap& icon);
0110 
0111     /**
0112      * Loads tag thumbnail,
0113      * with slightly different behavior than the above method:
0114      * If the thumbnail is already available in the cache,
0115      * it is returned, already blended with the standard icon, if requested.
0116      * If the icon is not yet loaded, it will be returned asynchronously
0117      * by the signals (unblended), and a default icon is returned here.
0118      * If no icon is associated, the default icon is returned.
0119      */
0120     QPixmap getTagThumbnailDirectly(TAlbum* const album);
0121 
0122     /**
0123      * Loads face tag thumbnail,
0124      * like getTagThumbnailDirectly() but
0125      * loads thumbnails in the size for faces
0126      */
0127     QPixmap getFaceThumbnailDirectly(TAlbum* const album);
0128 
0129     /**
0130      * Return standard tag and album icons.
0131      * The third methods check if album is the root,
0132      * and returns the standard icon or the root standard icon.
0133      */
0134     QPixmap getStandardTagIcon(RelativeSize size = NormalSize);
0135     QPixmap getStandardTagRootIcon(RelativeSize size = NormalSize);
0136     QPixmap getStandardTagIcon(TAlbum* const album, RelativeSize size = NormalSize);
0137     QPixmap getStandardFaceIcon(TAlbum* const album, RelativeSize size = NormalSize);
0138     QPixmap getNewTagIcon(RelativeSize size = NormalSize);
0139 
0140     QPixmap getStandardAlbumIcon(PAlbum* const album, RelativeSize size = NormalSize);
0141     QPixmap getStandardEmptyTrashIcon(RelativeSize size = NormalSize);
0142     QPixmap getStandardFullTrashIcon(RelativeSize size = NormalSize);
0143     QPixmap getStandardAlbumRootIcon(RelativeSize size = NormalSize);
0144     QPixmap getStandardAlbumIcon(RelativeSize size = NormalSize);
0145 
0146     /**
0147      * Return a preview of physical album directly without to use cache.
0148      * Size of image can be passed as argument.
0149      */
0150 /*
0151     QImage getAlbumPreviewDirectly(PAlbum* const album, int size);
0152 */
0153 
0154 public:
0155 
0156     static AlbumThumbnailLoader* instance();
0157 
0158 Q_SIGNALS:
0159 
0160     /**
0161      * This signal is emitted as soon as a thumbnail has become available
0162      * for given album.
0163      * This class is a singleton, so any object connected to this
0164      * signal might not actually have requested a thumbnail for given url
0165      */
0166     void signalThumbnail(Album* album, const QPixmap&);
0167 
0168     /** This signal is emitted if thumbnail generation for given album failed.
0169      *  Same considerations as above.
0170      */
0171     void signalFailed(Album* album);
0172 
0173     /**
0174      * Indicates that all album and tag thumbnails need to be reloaded.
0175      * This is usually because the icon size has changed in the setup.
0176      */
0177     void signalReloadThumbnails();
0178 
0179     /**
0180      * Internal signal to dispatch Album thumbnail change.
0181      */
0182     void signalDispatchThumbnailInternal(int albumID, const QPixmap& thumbnail);
0183 
0184 protected Q_SLOTS:
0185 
0186     void slotGotThumbnailFromIcon(const LoadingDescription& loadingDescription, const QPixmap& pixmap);
0187     void slotIconChanged(Album* album);
0188     void slotDispatchThumbnailInternal(int albumID, const QPixmap& thumbnail);
0189 
0190 private:
0191 
0192     // Disable
0193     AlbumThumbnailLoader();
0194     explicit AlbumThumbnailLoader(QObject*) = delete;
0195     ~AlbumThumbnailLoader() override;
0196 
0197     void    addUrl(Album* const album, qlonglong id);
0198     QPixmap loadIcon(const QString& name, int size = 0) const;
0199     int     computeIconSize(RelativeSize size)          const;
0200     int     computeFaceSize(RelativeSize size)          const;
0201 
0202 private:
0203 
0204     friend class AlbumThumbnailLoaderCreator;
0205 
0206     class Private;
0207     Private* const d;
0208 };
0209 
0210 } // namespace Digikam
0211 
0212 #endif // DIGIKAM_ALBUM_THUMBNAIL_LOADER_H