File indexing completed on 2025-04-27 03:58:10

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2007-06-05
0007  * Description : Thumbnail loading - private containers
0008  *
0009  * SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
0010  * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  * SPDX-FileCopyrightText: 2015      by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_THUMB_NAIL_LOAD_THREAD_P_H
0018 #define DIGIKAM_THUMB_NAIL_LOAD_THREAD_P_H
0019 
0020 #include "thumbnailloadthread.h"
0021 
0022 // Qt includes
0023 
0024 #include <QApplication>
0025 #include <QMessageBox>
0026 #include <QEventLoop>
0027 #include <QPainter>
0028 #include <QHash>
0029 #include <QIcon>
0030 #include <QMimeType>
0031 #include <QMimeDatabase>
0032 
0033 // KDE includes
0034 
0035 #include <klocalizedstring.h>
0036 
0037 // Local includes
0038 
0039 #include "digikam_debug.h"
0040 #include "iccmanager.h"
0041 #include "iccprofile.h"
0042 #include "loadingcache.h"
0043 #include "thumbsdbaccess.h"
0044 #include "thumbnailsize.h"
0045 #include "thumbnailcreator.h"
0046 
0047 namespace Digikam
0048 {
0049 
0050 class Q_DECL_HIDDEN ThumbnailResult
0051 {
0052 
0053 public:
0054 
0055     explicit ThumbnailResult(const LoadingDescription& description, const QImage& image)
0056         : loadingDescription(description),
0057           image             (image)
0058     {
0059     }
0060 
0061     LoadingDescription loadingDescription;
0062     QImage             image;
0063 };
0064 
0065 // -------------------------------------------------------------------
0066 
0067 class Q_DECL_HIDDEN ThumbnailLoadThreadStaticPriv
0068 {
0069 public:
0070 
0071     explicit ThumbnailLoadThreadStaticPriv()
0072       : firstThreadCreated  (false),
0073         storageMethod       (ThumbnailCreator::FreeDesktopStandard),
0074         provider            (nullptr),
0075         profile             (IccProfile::sRGB())
0076     {
0077     }
0078 
0079     ~ThumbnailLoadThreadStaticPriv()
0080     {
0081         delete provider;
0082     }
0083 
0084 public:
0085 
0086     bool                            firstThreadCreated;
0087 
0088     ThumbnailCreator::StorageMethod storageMethod;
0089     ThumbnailInfoProvider*          provider;
0090     IccProfile                      profile;
0091 };
0092 
0093 // -------------------------------------------------------------------
0094 
0095 class Q_DECL_HIDDEN ThumbnailLoadThread::Private
0096 {
0097 
0098 public:
0099 
0100     explicit Private()
0101       : wantPixmap          (true),
0102         highlight           (true),
0103         sendSurrogate       (true),
0104         notifiedForResults  (false),
0105         size                (ThumbnailSize::maxThumbsSize()),
0106         creator             (nullptr)
0107     {
0108     }
0109 
0110     bool                               wantPixmap;
0111     bool                               highlight;
0112     bool                               sendSurrogate;
0113     bool                               notifiedForResults;
0114 
0115     int                                size;
0116 
0117     ThumbnailCreator*                  creator;
0118 
0119     QHash<QString, ThumbnailResult>    collectedResults;
0120     QMutex                             resultsMutex;
0121 
0122     QList<LoadingDescription>          lastDescriptions;
0123 
0124 public:
0125 
0126     LoadingDescription        createLoadingDescription(const ThumbnailIdentifier& identifier, int size, bool setLastDescription = true);
0127     LoadingDescription        createLoadingDescription(const ThumbnailIdentifier& identifier, int size,
0128                                                        const QRect& detailRect, bool setLastDescription = true);
0129     bool                      checkDescription(const LoadingDescription& description);
0130     QList<LoadingDescription> makeDescriptions(const QList<ThumbnailIdentifier>& identifiers, int size);
0131     QList<LoadingDescription> makeDescriptions(const QList<QPair<ThumbnailIdentifier, QRect> >& idsAndRects, int size);
0132     bool                      hasHighlightingBorder()                       const;
0133     int                       pixmapSizeForThumbnailSize(int thumbnailSize) const;
0134     int                       thumbnailSizeForPixmapSize(int pixmapSize)    const;
0135 };
0136 
0137 // --- ThumbnailImageCatcher ---------------------------------------------------------
0138 
0139 class Q_DECL_HIDDEN ThumbnailImageCatcher::Private
0140 {
0141 
0142 public:
0143 
0144     enum CatcherState
0145     {
0146         Inactive,
0147         Accepting,
0148         Waiting,
0149         Quitting
0150     };
0151 
0152 public:
0153 
0154     class Q_DECL_HIDDEN CatcherResult
0155     {
0156     public:
0157 
0158         explicit CatcherResult(const LoadingDescription& d)
0159             : description(d),
0160               received   (false)
0161         {
0162         }
0163 
0164         CatcherResult(const LoadingDescription& d, const QImage& image)
0165             : image      (image),
0166               description(d),
0167               received   (true)
0168         {
0169         }
0170 
0171     public:
0172 
0173         QImage             image;
0174         LoadingDescription description;
0175         bool               received;
0176     };
0177 
0178 public:
0179 
0180     explicit Private()
0181       : state (Inactive),
0182         active(true),
0183         thread(nullptr)
0184     {
0185     }
0186 
0187     void reset();
0188     void harvest(const LoadingDescription& description, const QImage& image);
0189 
0190 public:
0191 
0192     CatcherState                  state;
0193 
0194     bool                          active;
0195     ThumbnailLoadThread*          thread;
0196     QList<Private::CatcherResult> tasks;
0197     QList<Private::CatcherResult> intermediate;
0198 
0199     QMutex                        mutex;
0200     QWaitCondition                condVar;
0201 };
0202 
0203 } // namespace Digikam
0204 
0205 #endif // DIGIKAM_THUMB_NAIL_LOAD_THREAD_P_H