Debian Codegraph @

core/libs/threadimageio/thumb/thumbnailloadthread_p.h

raw
1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2007-06-05
7 * Description : Thumbnail loading - private containers
8 *
9 * SPDX-FileCopyrightText: 2006-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10 * SPDX-FileCopyrightText: 2005-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
11 * SPDX-FileCopyrightText: 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
12 *
13 * SPDX-License-Identifier: GPL-2.0-or-later
14 *
15 * ============================================================ */
16
17 #pragma once
18
19 #include "thumbnailloadthread.h"
20
21 // Qt includes
22
23 #include <QApplication>
24 #include <QMessageBox>
25 #include <QEventLoop>
26 #include <QPainter>
27 #include <QHash>
28 #include <QIcon>
29 #include <QMimeType>
30 #include <QMimeDatabase>
31
32 // KDE includes
33
34 #include <klocalizedstring.h>
35
36 // Local includes
37
38 #include "digikam_debug.h"
39 #include "iccmanager.h"
40 #include "iccprofile.h"
41 #include "loadingcache.h"
42 #include "thumbsdbaccess.h"
43 #include "thumbnailsize.h"
44 #include "thumbnailcreator.h"
45
46 namespace Digikam
47 {
48
49 class Q_DECL_HIDDEN ThumbnailResult
50 {
51
52 public:
53
54 explicit ThumbnailResult(const LoadingDescription& description, const QImage& image)
55 : loadingDescription(description),
56 image (image)
57 {
58 }
59
60 LoadingDescription loadingDescription;
61 QImage image;
62 };
63
64 // -------------------------------------------------------------------
65
66 class Q_DECL_HIDDEN ThumbnailLoadThreadStaticPriv
67 {
68 public:
69
70 ThumbnailLoadThreadStaticPriv() = default;
71
72 ~ThumbnailLoadThreadStaticPriv()
73 {
74 delete provider;
75 }
76
77 public:
78
79 /// @note disabled
80 ThumbnailLoadThreadStaticPriv(const ThumbnailLoadThreadStaticPriv&) = delete;
81 ThumbnailLoadThreadStaticPriv& operator=(const ThumbnailLoadThreadStaticPriv&) = delete;
82
83 bool firstThreadCreated = false;
84
85 ThumbnailCreator::StorageMethod storageMethod = ThumbnailCreator::FreeDesktopStandard;
86 ThumbnailInfoProvider* provider = nullptr;
87 IccProfile profile = IccProfile::sRGB();
88 };
89
90 // -------------------------------------------------------------------
91
92 class Q_DECL_HIDDEN ThumbnailLoadThread::Private
93 {
94
95 public:
96
97 Private() = default;
98
99 bool wantPixmap = true;
100 bool highlight = true;
101 bool sendSurrogate = true;
102 bool notifiedForResults = false;
103
104 int size = ThumbnailSize::maxThumbsSize();
105
106 ThumbnailCreator* creator = nullptr;
107
108 QHash<QString, ThumbnailResult> collectedResults;
109 QMutex resultsMutex;
110
111 QList<LoadingDescription> lastDescriptions;
112
113 public:
114
115 LoadingDescription createLoadingDescription(const ThumbnailIdentifier& identifier, int size, bool setLastDescription = true);
116 LoadingDescription createLoadingDescription(const ThumbnailIdentifier& identifier, int size,
117 const QRect& detailRect, bool setLastDescription = true);
118 bool checkDescription(const LoadingDescription& description);
119 QList<LoadingDescription> makeDescriptions(const QList<ThumbnailIdentifier>& identifiers, int size);
120 QList<LoadingDescription> makeDescriptions(const QList<QPair<ThumbnailIdentifier, QRect> >& idsAndRects, int size);
121 bool hasHighlightingBorder() const;
122 int pixmapSizeForThumbnailSize(int thumbnailSize) const;
123 int thumbnailSizeForPixmapSize(int pixmapSize) const;
124 };
125
126 // --- ThumbnailImageCatcher ---------------------------------------------------------
127
128 class Q_DECL_HIDDEN ThumbnailImageCatcher::Private
129 {
130
131 public:
132
133 enum CatcherState
134 {
135 Inactive,
136 Accepting,
137 Waiting,
138 Quitting
139 };
140
141 public:
142
143 class Q_DECL_HIDDEN CatcherResult
144 {
145 public:
146
147 explicit CatcherResult(const LoadingDescription& d)
148 : description(d)
149 {
150 }
151
152 CatcherResult(const LoadingDescription& d, const QImage& image)
153 : image (image),
154 description(d),
155 received (true)
156 {
157 }
158
159 public:
160
161 QImage image;
162 LoadingDescription description;
163 bool received = false;
164 };
165
166 public:
167
168 Private() = default;
169
170 void reset();
171 void harvest(const LoadingDescription& description, const QImage& image);
172
173 public:
174
175 CatcherState state = Inactive;
176
177 bool active = true;
178 ThumbnailLoadThread* thread = nullptr;
179 QList<Private::CatcherResult> tasks;
180 QList<Private::CatcherResult> intermediate;
181
182 QMutex mutex;
183 QWaitCondition condVar;
184 };
185
186 } // namespace Digikam