1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2011-12-28
* Description : test for implementation of thread manager api
*
* SPDX-FileCopyrightText: 2011-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
* SPDX-FileCopyrightText: 2014 by Veaceslav Munteanu <veaceslav dot munteanu90 at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "processordlg.h"
// Qt includes
#include <QCoreApplication>
#include <QVBoxLayout>
#include <QLabel>
#include <QProgressBar>
#include <QThreadPool>
#include <QFileInfo>
#include <QDialogButtonBox>
#include <QPushButton>
#include <QHBoxLayout>
#include <QScrollArea>
#include <QSpinBox>
// Local includes
#include "digikam_debug.h"
#include "rawtopngconverterthread.h"
class Q_DECL_HIDDEN ProcessorDlg::Private
{
public:
explicit Private()
: count (0),
page (nullptr),
items (nullptr),
buttons (nullptr),
progressView (nullptr),
usedCore (nullptr),
thread (nullptr)
{
}
int count;
QWidget* page;
QLabel* items;
QDialogButtonBox* buttons;
QScrollArea* progressView;
QList<QUrl> list;
QSpinBox* usedCore;
RAWToPNGConverterThread* thread;
};
ProcessorDlg::ProcessorDlg(const QList<QUrl>& list, QWidget* const parent)
: QDialog(parent),
d (new Private)
{
setModal(false);
setWindowTitle(QString::fromUtf8("Convert RAW Files to PNG"));
d->buttons = new QDialogButtonBox(QDialogButtonBox::Apply | QDialogButtonBox::Close, this);
d->thread = new RAWToPNGConverterThread(this);
d->list = list;
d->count = d->list.count();
qCDebug(DIGIKAM_TESTS_LOG) << d->list;
d->page = new QWidget(this);
QVBoxLayout* const vbx = new QVBoxLayout(this);
vbx->addWidget(d->page);
vbx->addWidget(d->buttons);
setLayout(vbx);
int cpu = d->thread->maximumNumberOfThreads();
QGridLayout* const grid = new QGridLayout(d->page);
QLabel* const pid = new QLabel(QString::fromUtf8("Main PID: %1").arg(QCoreApplication::applicationPid()), this);
QLabel* const core = new QLabel(QString::fromUtf8("CPU cores available: %1").arg(cpu), this);
QWidget* const hbox = new QWidget(this);
d->items = new QLabel(this);
QHBoxLayout* const hlay = new QHBoxLayout(hbox);
QLabel* const coresLabel = new QLabel(QString::fromUtf8("Cores to use: "), this);<--- Variable 'coresLabel' can be declared as pointer to const
d->usedCore = new QSpinBox(this);
d->usedCore->setRange(1, cpu);
d->usedCore->setSingleStep(1);
d->usedCore->setValue(cpu);
hlay->addWidget(coresLabel);
hlay->addWidget(d->usedCore);
hlay->setContentsMargins(QMargins());
d->progressView = new QScrollArea(this);
QWidget* const progressbox = new QWidget(d->progressView->viewport());
QVBoxLayout* const progressLay = new QVBoxLayout(progressbox);
d->progressView->setWidget(progressbox);
d->progressView->setWidgetResizable(true);
grid->addWidget(pid, 0, 0, 1, 1);
grid->addWidget(core, 1, 0, 1, 1);
grid->addWidget(hbox, 2, 0, 1, 1);
grid->addWidget(d->items, 3, 0, 1, 1);
grid->addWidget(d->progressView, 4, 0, 1, 1);
for (const QUrl& url : std::as_const(d->list))
{
QProgressBar* const bar = new QProgressBar(progressbox);
QString file = url.toLocalFile();
QFileInfo fi(file);
bar->setMaximum(100);
bar->setMinimum(0);
bar->setValue(100);
bar->setObjectName(file);
bar->setFormat(fi.fileName());
progressLay->addWidget(bar);
}
progressLay->addStretch();
QPushButton* const applyBtn = d->buttons->button(QDialogButtonBox::Apply);<--- Variable 'applyBtn' can be declared as pointer to const
QPushButton* const cancelBtn = d->buttons->button(QDialogButtonBox::Close);<--- Variable 'cancelBtn' can be declared as pointer to const
connect(applyBtn, SIGNAL(clicked()),
this, SLOT(slotStart()));
connect(cancelBtn, SIGNAL(clicked()),
this, SLOT(slotStop()));
connect(d->thread, SIGNAL(starting(QUrl)),
this, SLOT(slotStarting(QUrl)));
connect(d->thread, SIGNAL(finished(QUrl)),
this, SLOT(slotFinished(QUrl)));
connect(d->thread, SIGNAL(failed(QUrl,QString)),
this, SLOT(slotFailed(QUrl,QString)));
connect(d->thread, SIGNAL(progress(QUrl,int)),
this, SLOT(slotProgress(QUrl,int)));
updateCount();
resize(500, 400);
}
ProcessorDlg::~ProcessorDlg()
{
delete d;
}
void ProcessorDlg::updateCount()
{
d->items->setText(QString::fromUtf8("Files to process : %1").arg(d->count));
}
void ProcessorDlg::slotStart()
{
if (d->list.isEmpty()) return;
d->buttons->button(QDialogButtonBox::Apply)->setDisabled(true);
d->usedCore->setDisabled(true);
d->thread->setMaximumNumberOfThreads(d->usedCore->value());
d->thread->convertRAWtoPNG(d->list, DRawDecoderSettings());
d->thread->start();
}
void ProcessorDlg::slotStop()
{
d->thread->cancel();
reject();
}
QProgressBar* ProcessorDlg::findProgressBar(const QUrl& url) const
{
QList<QProgressBar*> bars = findChildren<QProgressBar*>();
for (QProgressBar* const b : std::as_const(bars))
{
if (b->objectName() == url.toLocalFile())
{ // cppcheck-suppress useStlAlgorithm
return b;
}
}
qCWarning(DIGIKAM_TESTS_LOG) << "Cannot found relevant progress bar for " << url.toLocalFile();
return nullptr;
}
void ProcessorDlg::slotStarting(const QUrl& url)
{
qCDebug(DIGIKAM_TESTS_LOG) << "Start to process item " << url.toLocalFile();
QProgressBar* const b = findProgressBar(url);
if (b)
{
d->progressView->ensureWidgetVisible(b);
b->setMinimum(0);
b->setMaximum(100);
b->setValue(0);
}
}
void ProcessorDlg::slotProgress(const QUrl& url,int p)
{
qCDebug(DIGIKAM_TESTS_LOG) << "Processing item " << url.toLocalFile() << " : " << p << " %";;
QProgressBar* const b = findProgressBar(url);
if (b)
{
b->setMinimum(0);
b->setMaximum(100);
b->setValue(p);
}
}
void ProcessorDlg::slotFinished(const QUrl& url)
{
qCDebug(DIGIKAM_TESTS_LOG) << "Completed item " << url.toLocalFile();
QProgressBar* const b = findProgressBar(url);
if (b)
{
b->setMinimum(0);
b->setMaximum(100);
b->setValue(100);
b->setFormat(QString::fromUtf8("Done"));
d->count--;
updateCount();
}
}
void ProcessorDlg::slotFailed(const QUrl& url, const QString& err)
{
qCDebug(DIGIKAM_TESTS_LOG) << "Failed to complete item " << url.toLocalFile();
QProgressBar* const b = findProgressBar(url);
if (b)
{
b->setMinimum(0);
b->setMaximum(100);
b->setValue(100);
b->setFormat(err);
d->count--;
updateCount();
}
}
#include "moc_processordlg.cpp"
|