1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date        : 2006-01-23
7  * Description : setup image editor output files settings.
8  *
9  * Copyright (C) 2006-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 "setupiofiles.h"
25 
26 // Qt includes
27 
28 #include <QCheckBox>
29 #include <QGroupBox>
30 #include <QVBoxLayout>
31 
32 // KDE includes
33 
34 #include <kconfiggroup.h>
35 #include <ksharedconfig.h>
36 #include <klocalizedstring.h>
37 
38 // Local includes
39 
40 #include "digikam_config.h"
41 #include "jpegsettings.h"
42 #include "pgfsettings.h"
43 #include "pngsettings.h"
44 #include "tiffsettings.h"
45 
46 #ifdef HAVE_JASPER
47 #   include "jp2ksettings.h"
48 #endif // HAVE_JASPER
49 
50 #ifdef HAVE_X265
51 #   include "heifsettings.h"
52 #endif // HAVE_X265
53 
54 namespace Digikam
55 {
56 
57 class Q_DECL_HIDDEN SetupIOFiles::Private
58 {
59 public:
60 
Private()61     explicit Private()
62       : JPEGOptions             (nullptr),
63         PNGOptions              (nullptr),
64         TIFFOptions             (nullptr),
65 
66 #ifdef HAVE_JASPER
67 
68         JPEG2000Options         (nullptr),
69 
70 #endif // HAVE_JASPER
71 
72         PGFOptions              (nullptr),
73 
74 #ifdef HAVE_X265
75 
76         HEIFOptions             (nullptr),
77 
78 #endif // HAVE_X265
79 
80         showImageSettingsDialog (nullptr)
81     {
82     }
83 
createGroupBox(QWidget * const w) const84     QWidget* createGroupBox(QWidget* const w) const
85     {
86         QGroupBox* const  box     = new QGroupBox;
87         QVBoxLayout* const layout = new QVBoxLayout;
88         layout->addWidget(w);
89         box->setLayout(layout);
90 
91         return box;
92     }
93 
94 public:
95 
96     static const QString configGroupName;
97     static const QString configJPEGCompressionEntry;
98     static const QString configJPEGSubSamplingEntry;
99     static const QString configPNGCompressionEntry;
100     static const QString configTIFFCompressionEntry;
101     static const QString configJPEG2000CompressionEntry;
102     static const QString configJPEG2000LossLessEntry;
103     static const QString configPGFCompressionEntry;
104     static const QString configPGFLossLessEntry;
105     static const QString configHEIFCompressionEntry;
106     static const QString configHEIFLossLessEntry;
107     static const QString configShowImageSettingsDialog;
108 
109     JPEGSettings*        JPEGOptions;
110     PNGSettings*         PNGOptions;
111     TIFFSettings*        TIFFOptions;
112 
113 #ifdef HAVE_JASPER
114 
115     JP2KSettings*        JPEG2000Options;
116 
117 #endif // HAVE_JASPER
118 
119     PGFSettings*         PGFOptions;
120 
121 #ifdef HAVE_X265
122 
123     HEIFSettings*        HEIFOptions;
124 
125 #endif // HAVE_X265
126 
127     QCheckBox*           showImageSettingsDialog;
128 };
129 
130 const QString SetupIOFiles::Private::configGroupName(QLatin1String("ImageViewer Settings"));
131 const QString SetupIOFiles::Private::configJPEGCompressionEntry(QLatin1String("JPEGCompression"));
132 const QString SetupIOFiles::Private::configJPEGSubSamplingEntry(QLatin1String("JPEGSubSampling"));
133 const QString SetupIOFiles::Private::configPNGCompressionEntry(QLatin1String("PNGCompression"));
134 const QString SetupIOFiles::Private::configTIFFCompressionEntry(QLatin1String("TIFFCompression"));
135 const QString SetupIOFiles::Private::configJPEG2000CompressionEntry(QLatin1String("JPEG2000Compression"));
136 const QString SetupIOFiles::Private::configJPEG2000LossLessEntry(QLatin1String("JPEG2000LossLess"));
137 const QString SetupIOFiles::Private::configPGFCompressionEntry(QLatin1String("PGFCompression"));
138 const QString SetupIOFiles::Private::configPGFLossLessEntry(QLatin1String("PGFLossLess"));
139 const QString SetupIOFiles::Private::configHEIFCompressionEntry(QLatin1String("HEIFCompression"));
140 const QString SetupIOFiles::Private::configHEIFLossLessEntry(QLatin1String("HEIFLossLess"));
141 const QString SetupIOFiles::Private::configShowImageSettingsDialog(QLatin1String("ShowImageSettingsDialog"));
142 
143 // --------------------------------------------------------
144 
SetupIOFiles(QWidget * const parent)145 SetupIOFiles::SetupIOFiles(QWidget* const parent)
146     : QScrollArea(parent),
147       d          (new Private)
148 {
149     QWidget* const panel    = new QWidget;
150     QVBoxLayout* const vbox = new QVBoxLayout;
151     d->JPEGOptions          = new JPEGSettings;
152     d->PNGOptions           = new PNGSettings;
153     d->TIFFOptions          = new TIFFSettings;
154 
155 #ifdef HAVE_JASPER
156 
157     d->JPEG2000Options      = new JP2KSettings;
158 
159 #endif // HAVE_JASPER
160 
161     d->PGFOptions           = new PGFSettings;
162 
163 #ifdef HAVE_X265
164 
165     d->HEIFOptions          = new HEIFSettings;
166 
167 #endif // HAVE_X265
168 
169     // Show Settings Dialog Option
170 
171     d->showImageSettingsDialog = new QCheckBox(panel);
172     d->showImageSettingsDialog->setText(i18n("Show Settings Dialog when Saving Image Files"));
173     d->showImageSettingsDialog->setWhatsThis(i18n("<ul><li>Checked: A dialog where settings can be changed when saving image files</li>"
174                                                   "<li>Unchecked: Default settings are used when saving image files</li></ul>"));
175 
176     vbox->addWidget(d->createGroupBox(d->JPEGOptions));
177     vbox->addWidget(d->createGroupBox(d->PNGOptions));
178     vbox->addWidget(d->createGroupBox(d->TIFFOptions));
179 
180 #ifdef HAVE_JASPER
181 
182     vbox->addWidget(d->createGroupBox(d->JPEG2000Options));
183 
184 #endif // HAVE_JASPER
185 
186     vbox->addWidget(d->createGroupBox(d->PGFOptions));
187 
188 #ifdef HAVE_X265
189 
190     vbox->addWidget(d->createGroupBox(d->HEIFOptions));
191 
192 #endif // HAVE_265
193 
194     vbox->addWidget(d->createGroupBox(d->showImageSettingsDialog));
195     vbox->addStretch();
196 
197     panel->setLayout(vbox);
198     setWidget(panel);
199     setWidgetResizable(true);
200 
201     // --------------------------------------------------------
202 
203     readSettings();
204 }
205 
~SetupIOFiles()206 SetupIOFiles::~SetupIOFiles()
207 {
208     delete d;
209 }
210 
applySettings()211 void SetupIOFiles::applySettings()
212 {
213     KSharedConfig::Ptr config = KSharedConfig::openConfig();
214     KConfigGroup group        = config->group(d->configGroupName);
215     group.writeEntry(d->configJPEGCompressionEntry,     d->JPEGOptions->getCompressionValue());
216     group.writeEntry(d->configJPEGSubSamplingEntry,     d->JPEGOptions->getSubSamplingValue());
217     group.writeEntry(d->configPNGCompressionEntry,      d->PNGOptions->getCompressionValue());
218     group.writeEntry(d->configTIFFCompressionEntry,     d->TIFFOptions->getCompression());
219 
220 #ifdef HAVE_JASPER
221 
222     group.writeEntry(d->configJPEG2000CompressionEntry, d->JPEG2000Options->getCompressionValue());
223     group.writeEntry(d->configJPEG2000LossLessEntry,    d->JPEG2000Options->getLossLessCompression());
224 
225 #endif // HAVE_JASPER
226 
227     group.writeEntry(d->configPGFCompressionEntry,      d->PGFOptions->getCompressionValue());
228     group.writeEntry(d->configPGFLossLessEntry,         d->PGFOptions->getLossLessCompression());
229 
230 #ifdef HAVE_X265
231 
232     group.writeEntry(d->configHEIFCompressionEntry,     d->HEIFOptions->getCompressionValue());
233     group.writeEntry(d->configHEIFLossLessEntry,        d->HEIFOptions->getLossLessCompression());
234 
235 #endif // HAVE_X265
236 
237     group.writeEntry(d->configShowImageSettingsDialog,  d->showImageSettingsDialog->isChecked());
238     config->sync();
239 }
240 
readSettings()241 void SetupIOFiles::readSettings()
242 {
243     KSharedConfig::Ptr config = KSharedConfig::openConfig();
244     KConfigGroup group        = config->group(d->configGroupName);
245     d->JPEGOptions->setCompressionValue(group.readEntry(d->configJPEGCompressionEntry,         75));
246     d->JPEGOptions->setSubSamplingValue(group.readEntry(d->configJPEGSubSamplingEntry,         1));  // Medium sub-sampling
247     d->PNGOptions->setCompressionValue(group.readEntry(d->configPNGCompressionEntry,           9));
248     d->TIFFOptions->setCompression(group.readEntry(d->configTIFFCompressionEntry,              false));
249 
250 #ifdef HAVE_JASPER
251 
252     d->JPEG2000Options->setCompressionValue(group.readEntry(d->configJPEG2000CompressionEntry, 75));
253     d->JPEG2000Options->setLossLessCompression(group.readEntry(d->configJPEG2000LossLessEntry, true));
254 
255 #endif // HAVE_JASPER
256 
257     d->PGFOptions->setCompressionValue(group.readEntry(d->configPGFCompressionEntry,           3));
258     d->PGFOptions->setLossLessCompression(group.readEntry(d->configPGFLossLessEntry,           true));
259 
260 #ifdef HAVE_X265
261 
262     d->HEIFOptions->setCompressionValue(group.readEntry(d->configHEIFCompressionEntry,         75));
263     d->HEIFOptions->setLossLessCompression(group.readEntry(d->configHEIFLossLessEntry,         true));
264 
265 #endif // HAVE_X265
266 
267     d->showImageSettingsDialog->setChecked(group.readEntry(d->configShowImageSettingsDialog,   true));
268 }
269 
270 } // namespace Digikam
271