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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334 | /* ============================================================
*
* This file is a part of digiKam project
* https://www.digikam.org
*
* Date : 2019-03-27
* Description : a tool to export items to a local storage
*
* SPDX-FileCopyrightText: 2006-2009 by Johannes Wienke <languitar at semipol dot de>
* SPDX-FileCopyrightText: 2011-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
* SPDX-FileCopyrightText: 2019-2020 by Maik Qualmann <metzpinguin at gmail dot com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
* ============================================================ */
#include "fcexportwidget.h"
// Qt includes
#include <QApplication>
#include <QRadioButton>
#include <QButtonGroup>
#include <QVBoxLayout>
#include <QCheckBox>
#include <QGroupBox>
#include <QComboBox>
#include <QSpinBox>
#include <QLabel>
// KDE includes
#include <klocalizedstring.h>
// Local includes
#include "digikam_debug.h"
#include "dfileselector.h"
#include "wstoolutils.h"
#include "dlayoutbox.h"
#include "fctask.h"
#include "metaenginesettings.h"
namespace DigikamGenericFileCopyPlugin
{
class Q_DECL_HIDDEN FCExportWidget::Private
{
public:
Private() = default;
DInfoInterface* iface = nullptr;
DFileSelector* selector = nullptr;
DItemsList* imageList = nullptr;
QCheckBox* sidecars = nullptr;
QCheckBox* writeMetadataToFile = nullptr;
QCheckBox* overwrite = nullptr;
QCheckBox* albumPath = nullptr;
QButtonGroup* targetButtonGroup = nullptr;
QRadioButton* fileCopyButton = nullptr;
QRadioButton* symLinkButton = nullptr;
QRadioButton* relativeButton = nullptr;
QUrl targetUrl;
QGroupBox* imageChangeGroupBox = nullptr;
QCheckBox* changeImagesProp = nullptr;
QCheckBox* removeMetadataProp = nullptr;
QSpinBox* imageCompression = nullptr;
QSpinBox* imageResize = nullptr;
QComboBox* imageFormat = nullptr;
};
FCExportWidget::FCExportWidget(DInfoInterface* const iface, QWidget* const parent)
: QWidget(parent),
d (new Private)
{
d->iface = iface;
// setup local target selection
const int spacing = layoutSpacing();
DHBox* const hbox = new DHBox(this);
QLabel* const locationLabel = new QLabel(hbox);
locationLabel->setText(i18n("Target location: "));
d->selector = new DFileSelector(hbox);
d->selector->setFileDlgMode(QFileDialog::Directory);
d->selector->setFileDlgOptions(QFileDialog::ShowDirsOnly);
d->selector->setFileDlgTitle(i18nc("@title:window", "Target Folder"));
d->selector->setWhatsThis(i18n("Sets the target address to copy the items to."));
QLabel* const targetLabel = new QLabel(i18n("Target file behavior:"), this);<--- Variable 'targetLabel' can be declared as pointer to const
d->targetButtonGroup = new QButtonGroup(this);
d->fileCopyButton = new QRadioButton(i18n("Copy files"), this);
d->symLinkButton = new QRadioButton(i18n("Create symlinks"), this);
d->relativeButton = new QRadioButton(i18n("Create relative symlinks"), this);
d->sidecars = new QCheckBox(i18n("Include the sidecar of the items"), this);
d->writeMetadataToFile = new QCheckBox(i18n("Write sidecar metadata to the items"), this);
d->overwrite = new QCheckBox(i18n("Overwrite existing items in the target"), this);
d->albumPath = new QCheckBox(i18n("Use the album path of the items in the target"), this);
if (!d->iface->supportAlbums())
{
d->albumPath->hide();
}
if (MetaEngineSettings::instance()->settings().metadataWritingMode != MetaEngine::WRITE_TO_SIDECAR_ONLY)
{
d->writeMetadataToFile->hide();
}
d->targetButtonGroup->addButton(d->fileCopyButton, FCContainer::CopyFile);
d->targetButtonGroup->addButton(d->symLinkButton, FCContainer::FullSymLink);
d->targetButtonGroup->addButton(d->relativeButton, FCContainer::RelativeSymLink);
d->targetButtonGroup->setExclusive(true);
d->fileCopyButton->setChecked(true);
//---------------------------------------------
d->changeImagesProp = new QCheckBox(i18n("Adjust image properties"), this);
d->changeImagesProp->setChecked(false);
d->changeImagesProp->setWhatsThis(i18n("If you enable this option, "
"all images to be sent can be "
"resized and recompressed."));
//---------------------------------------------
d->imageChangeGroupBox = new QGroupBox(i18n("Image Properties"), this);
d->imageResize = new QSpinBox(d->imageChangeGroupBox);
d->imageResize->setRange(300, 6000);
d->imageResize->setSingleStep(1);
d->imageResize->setValue(1024);
d->imageResize->setSuffix(i18n(" px"));
d->imageResize->setWhatsThis(i18n("Select the length of the images that are to be sent. "
"The aspect ratio is preserved."));
d->imageChangeGroupBox->setEnabled(false);
QLabel* const labelImageResize = new QLabel(i18n("Image Length:"), d->imageChangeGroupBox);
labelImageResize->setBuddy(d->imageResize);
//---------------------------------------------
QLabel* const labelImageFormat = new QLabel(d->imageChangeGroupBox);
labelImageFormat->setWordWrap(false);
labelImageFormat->setText(i18n("Image Format:"));
d->imageFormat = new QComboBox(d->imageChangeGroupBox);
d->imageFormat->setEditable(false);
d->imageFormat->setWhatsThis(i18n("Select your preferred format to convert image."));
d->imageFormat->addItem(i18nc("Image format: JPEG", "Jpeg"), FCContainer::JPEG);
d->imageFormat->addItem(i18nc("Image format: PNG", "Png"), FCContainer::PNG);
labelImageFormat->setBuddy(d->imageFormat);
//---------------------------------------------
d->imageCompression = new QSpinBox(d->imageChangeGroupBox);
d->imageCompression->setRange(1, 100);
d->imageCompression->setSingleStep(1);
d->imageCompression->setValue(75);
d->imageCompression->setWhatsThis(i18n("<p>The new compression value of JPEG images to be sent:</p>"
"<p><b>1</b>: very high compression<br/>"
"<b>25</b>: high compression<br/>"
"<b>50</b>: medium compression<br/>"
"<b>75</b>: low compression (default value)<br/>"
"<b>100</b>: no compression</p>"));
QLabel* const labelImageCompression = new QLabel(i18n("Image quality:"), d->imageChangeGroupBox);
labelImageCompression->setBuddy(d->imageCompression);
//---------------------------------------------
d->removeMetadataProp = new QCheckBox(i18n("Remove all metadata"), d->imageChangeGroupBox);
d->removeMetadataProp->setWhatsThis(i18n("If you enable this option, all metadata "
"as Exif, Iptc, and Xmp will be removed."));
//---------------------------------------------
QGridLayout* const grid2 = new QGridLayout(d->imageChangeGroupBox);
grid2->addWidget(labelImageResize, 0, 0, 1, 1);
grid2->addWidget(d->imageResize, 0, 1, 1, 2);
grid2->addWidget(labelImageFormat, 1, 0, 1, 1);
grid2->addWidget(d->imageFormat, 1, 1, 1, 2);
grid2->addWidget(labelImageCompression, 2, 0, 1, 1);
grid2->addWidget(d->imageCompression, 2, 1, 1, 2);
grid2->addWidget(d->removeMetadataProp, 3, 0, 1, 2);
grid2->setColumnStretch(2, 10);
grid2->setSpacing(spacing);
grid2->setAlignment(Qt::AlignTop);
//---------------------------------------------
// setup image list
d->imageList = new DItemsList(this);
d->imageList->setObjectName(QLatin1String("FCExport ImagesList"));
d->imageList->listView()->setWhatsThis(i18n("This is the list of items to copy "
"to the specified target."));
d->imageList->setAllowRAW(true);
d->imageList->setIface(d->iface);
if (d->iface->forceAlbumSelection)
{
d->iface->forceAlbumSelection = false;
d->imageList->loadImagesFromCurrentAlbum();
}
else
{
d->imageList->loadImagesFromCurrentSelection();
}
// layout dialog
QVBoxLayout* const layout = new QVBoxLayout(this);
layout->addWidget(hbox);
layout->addWidget(targetLabel);
layout->addWidget(d->fileCopyButton);
layout->addWidget(d->symLinkButton);
layout->addWidget(d->relativeButton);
layout->addWidget(d->sidecars);
layout->addWidget(d->writeMetadataToFile);
layout->addWidget(d->overwrite);
layout->addWidget(d->albumPath);
layout->addWidget(d->imageList);
layout->addWidget(d->changeImagesProp);
layout->addWidget(d->imageChangeGroupBox);
layout->setSpacing(spacing);
layout->setContentsMargins(QMargins());
// ------------------------------------------------------------------------
connect(d->selector->lineEdit(), SIGNAL(textEdited(QString)),
this, SLOT(slotLabelUrlChanged()));
connect(d->selector, SIGNAL(signalUrlSelected(QUrl)),
this, SLOT(slotLabelUrlChanged()));
connect(d->fileCopyButton, SIGNAL(toggled(bool)),
this, SLOT(slotFileCopyButtonChanged(bool)));
connect(d->changeImagesProp, SIGNAL(toggled(bool)),
d->imageChangeGroupBox, SLOT(setEnabled(bool)));
}
FCExportWidget::~FCExportWidget()
{
delete d;
}
DItemsList* FCExportWidget::imagesList() const
{
return d->imageList;
}
QUrl FCExportWidget::targetUrl() const
{
return d->targetUrl;
}
FCContainer FCExportWidget::getSettings() const
{
FCContainer settings;
settings.iface = d->iface;
settings.destUrl = d->targetUrl;
settings.behavior = d->targetButtonGroup->checkedId();
settings.imageFormat = d->imageFormat->currentIndex();
settings.imageResize = d->imageResize->value();
settings.imageCompression = d->imageCompression->value();
settings.sidecars = d->sidecars->isChecked();
settings.writeMetadataToFile = d->writeMetadataToFile->isChecked();
settings.overwrite = d->overwrite->isChecked();
settings.albumPath = d->albumPath->isChecked();
settings.removeMetadata = d->removeMetadataProp->isChecked();
settings.changeImageProperties = d->changeImagesProp->isChecked();
return settings;
}
void FCExportWidget::setSettings(const FCContainer& settings)
{
d->targetUrl = settings.destUrl;
d->selector->setFileDlgPath(d->targetUrl.toLocalFile());
QAbstractButton* const button = d->targetButtonGroup->button(settings.behavior);
if (button)
{
button->setChecked(true);
}
d->imageFormat->setCurrentIndex(settings.imageFormat);
d->imageResize->setValue(settings.imageResize);
d->imageCompression->setValue(settings.imageCompression);
d->sidecars->setChecked(settings.sidecars);
d->writeMetadataToFile->setChecked(settings.writeMetadataToFile);
d->overwrite->setChecked(settings.overwrite);
d->albumPath->setChecked(settings.albumPath);
d->removeMetadataProp->setChecked(settings.removeMetadata);
d->changeImagesProp->setChecked(settings.changeImageProperties);
}
void FCExportWidget::slotLabelUrlChanged()
{
d->targetUrl = QUrl::fromLocalFile(d->selector->fileDlgPath());
Q_EMIT signalTargetUrlChanged(d->targetUrl);
}
void FCExportWidget::slotFileCopyButtonChanged(bool enabled)
{
if (!enabled)
{
d->changeImagesProp->setChecked(false);
}
d->changeImagesProp->setEnabled(enabled);
// The changeImagesProp is by default and on each change unchecked
d->imageChangeGroupBox->setEnabled(false);
}
} // namespace DigikamGenericFileCopyPlugin
#include "moc_fcexportwidget.cpp"
|