1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2011-08-12
7 * Description : advanced settings for camera interface.
8 *
9 * Copyright (C) 2011-2021 by Gilles Caulier <caulier dot gilles at gmail dot com>
10 *
11 * This program is free software; you can redistribute it
12 * and/or modify it under the terms of the GNU General
13 * Public License as published by the Free Software Foundation;
14 * either version 2, or (at your option)
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * ============================================================ */
23
24 #include "advancedsettings.h"
25
26 // Qt includes
27
28 #include <QVBoxLayout>
29 #include <QLabel>
30 #include <QCheckBox>
31 #include <QToolButton>
32 #include <QApplication>
33 #include <QStyle>
34 #include <QComboBox>
35
36 // KDE includes
37
38 #include <kconfiggroup.h>
39 #include <klocalizedstring.h>
40
41 // Local includes
42
43 #include "digikam_debug.h"
44 #include "digikam_config.h"
45 #include "templateselector.h"
46 #include "ddatetimeedit.h"
47 #include "template.h"
48
49 namespace Digikam
50 {
51
52 class Q_DECL_HIDDEN AdvancedSettings::Private
53 {
54 public:
55
Private()56 explicit Private()
57 : formatLabel (nullptr),
58 autoRotateCheck (nullptr),
59 convertJpegCheck (nullptr),
60 fixDateTimeCheck (nullptr),
61 documentNameCheck (nullptr),
62 losslessFormat (nullptr),
63 dateTimeEdit (nullptr),
64 templateSelector (nullptr)
65 {
66 }
67
68 QLabel* formatLabel;
69
70 QCheckBox* autoRotateCheck;
71 QCheckBox* convertJpegCheck;
72 QCheckBox* fixDateTimeCheck;
73 QCheckBox* documentNameCheck;
74
75 QComboBox* losslessFormat;
76
77 DDateTimeEdit* dateTimeEdit;
78
79 TemplateSelector* templateSelector;
80 };
81
AdvancedSettings(QWidget * const parent)82 AdvancedSettings::AdvancedSettings(QWidget* const parent)
83 : QWidget(parent),
84 d (new Private)
85 {
86 const int spacing = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
87
88 QVBoxLayout* const onFlyVlay = new QVBoxLayout(this);
89 d->templateSelector = new TemplateSelector(this);
90 d->documentNameCheck = new QCheckBox(i18nc("@option:check", "Write the document name to EXIF"), this);
91 d->fixDateTimeCheck = new QCheckBox(i18nc("@option:check", "Fix internal date && time"), this);
92 d->dateTimeEdit = new DDateTimeEdit(this, QLatin1String("datepicker"));
93 d->autoRotateCheck = new QCheckBox(i18nc("@option:check", "Auto-rotate/flip image"), this);
94 d->convertJpegCheck = new QCheckBox(i18nc("@option:check", "Convert to lossless file format"), this);
95 DHBox* const hbox2 = new DHBox(this);
96 d->formatLabel = new QLabel(i18nc("@label", "New image format:"), hbox2);
97 d->losslessFormat = new QComboBox(hbox2);
98 d->losslessFormat->insertItem(0, QLatin1String("PNG"));
99 d->losslessFormat->insertItem(1, QLatin1String("TIF"));
100 d->losslessFormat->insertItem(2, QLatin1String("PGF"));
101
102 #ifdef HAVE_JASPER
103
104 d->losslessFormat->insertItem(3, QLatin1String("JP2"));
105
106 #endif // HAVE_JASPER
107
108 #ifdef HAVE_X265
109
110 d->losslessFormat->insertItem(4, QLatin1String("HEIC"));
111
112 #endif // HAVE_X265
113
114 onFlyVlay->addWidget(d->templateSelector);
115 onFlyVlay->addWidget(d->documentNameCheck);
116 onFlyVlay->addWidget(d->fixDateTimeCheck);
117 onFlyVlay->addWidget(d->dateTimeEdit);
118 onFlyVlay->addWidget(d->autoRotateCheck);
119 onFlyVlay->addWidget(d->convertJpegCheck);
120 onFlyVlay->addWidget(hbox2);
121 onFlyVlay->addStretch();
122 onFlyVlay->setContentsMargins(spacing, spacing, spacing, spacing);
123 onFlyVlay->setSpacing(spacing);
124
125 setWhatsThis(i18nc("@info", "Set here all options to fix/transform JPEG files automatically "
126 "as they are downloaded."));
127 d->autoRotateCheck->setWhatsThis(i18nc("@info", "Enable this option if you want images automatically "
128 "rotated or flipped using Exif information provided by the camera."));
129 d->templateSelector->setWhatsThis(i18nc("@info", "Select here which metadata template you want to apply "
130 "to images."));
131 d->documentNameCheck->setWhatsThis(i18nc("@info", "Enable this option to write the document name to the Exif metadata. "
132 "The document name is the original file name of the imported file."));
133 d->fixDateTimeCheck->setWhatsThis(i18nc("@info", "Enable this option to set date and time metadata "
134 "tags to the right values if your camera does not set "
135 "these tags correctly when pictures are taken. The values will "
136 "be saved in the DateTimeDigitized and DateTimeCreated EXIF, XMP, and IPTC tags."));
137 d->convertJpegCheck->setWhatsThis(i18nc("@info", "Enable this option to automatically convert "
138 "all JPEG files to a lossless image format. Note: Image conversion can take a "
139 "while on a slow computer."));
140 d->losslessFormat->setWhatsThis(i18nc("@info", "Select your preferred lossless image file format to "
141 "convert to. Note: All metadata will be preserved during the conversion."));
142
143 // ---------------------------------------------------------------------------------------
144
145 connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
146 d->losslessFormat, SLOT(setEnabled(bool)));
147
148 connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
149 d->formatLabel, SLOT(setEnabled(bool)));
150
151 connect(d->convertJpegCheck, SIGNAL(toggled(bool)),
152 this, SIGNAL(signalDownloadNameChanged()));
153
154 connect(d->losslessFormat, SIGNAL(activated(int)),
155 this, SIGNAL(signalDownloadNameChanged()));
156
157 connect(d->fixDateTimeCheck, SIGNAL(toggled(bool)),
158 d->dateTimeEdit, SLOT(setEnabled(bool)));
159 }
160
~AdvancedSettings()161 AdvancedSettings::~AdvancedSettings()
162 {
163 delete d;
164 }
165
readSettings(KConfigGroup & group)166 void AdvancedSettings::readSettings(KConfigGroup& group)
167 {
168 d->autoRotateCheck->setChecked(group.readEntry(QLatin1String("AutoRotate"), true));
169 d->fixDateTimeCheck->setChecked(group.readEntry(QLatin1String("FixDateTime"), false));
170 d->documentNameCheck->setChecked(group.readEntry(QLatin1String("DocumentName"), false));
171 d->templateSelector->setTemplateIndex(group.readEntry(QLatin1String("Template"), 0));
172 d->convertJpegCheck->setChecked(group.readEntry(QLatin1String("ConvertJpeg"), false));
173 d->losslessFormat->setCurrentIndex(group.readEntry(QLatin1String("LossLessFormat"), 0)); // PNG by default
174
175 d->dateTimeEdit->setEnabled(d->fixDateTimeCheck->isChecked());
176 d->losslessFormat->setEnabled(d->convertJpegCheck->isChecked());
177 d->formatLabel->setEnabled(d->convertJpegCheck->isChecked());
178 }
179
saveSettings(KConfigGroup & group)180 void AdvancedSettings::saveSettings(KConfigGroup& group)
181 {
182 group.writeEntry(QLatin1String("AutoRotate"), d->autoRotateCheck->isChecked());
183 group.writeEntry(QLatin1String("FixDateTime"), d->fixDateTimeCheck->isChecked());
184 group.writeEntry(QLatin1String("DocumentName"), d->documentNameCheck->isChecked());
185 group.writeEntry(QLatin1String("Template"), d->templateSelector->getTemplateIndex());
186 group.writeEntry(QLatin1String("ConvertJpeg"), d->convertJpegCheck->isChecked());
187 group.writeEntry(QLatin1String("LossLessFormat"), d->losslessFormat->currentIndex());
188 }
189
settings() const190 DownloadSettings AdvancedSettings::settings() const
191 {
192 DownloadSettings settings;
193
194 settings.autoRotate = d->autoRotateCheck->isChecked();
195 settings.fixDateTime = d->fixDateTimeCheck->isChecked();
196 settings.convertJpeg = d->convertJpegCheck->isChecked();
197 settings.newDateTime = d->dateTimeEdit->dateTime();
198 settings.documentName = d->documentNameCheck->isChecked();
199 settings.losslessFormat = d->losslessFormat->currentText();
200 settings.templateTitle = d->templateSelector->getTemplate().templateTitle();
201
202 return settings;
203 }
204
205 } // namespace Digikam
206