1 /* ============================================================
2 *
3 * This file is a part of digiKam project
4 * https://www.digikam.org
5 *
6 * Date : 2005-04-02
7 * Description : showFoto setup dialog.
8 *
9 * Copyright (C) 2005-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 "showfotosetup.h"
25
26 // Qt includes
27
28 #include <QPointer>
29 #include <QPushButton>
30 #include <QApplication>
31
32 // KDE includes
33
34 #include <kconfiggroup.h>
35 #include <ksharedconfig.h>
36 #include <klocalizedstring.h>
37
38 // Local includes
39
40 #include "setupeditoriface.h"
41 #include "setupicc.h"
42 #include "setupiofiles.h"
43 #include "showfotosettings.h"
44 #include "showfotosetupraw.h"
45 #include "showfotosetupmisc.h"
46 #include "showfotosetupmetadata.h"
47 #include "showfotosetuptooltip.h"
48 #include "showfotosetupplugins.h"
49 #include "dxmlguiwindow.h"
50 #include "onlineversiondlg.h"
51
52 namespace ShowFoto
53 {
54
55 class Q_DECL_HIDDEN ShowfotoSetup::Private
56 {
57 public:
58
Private()59 explicit Private()
60 : page_editorIface(nullptr),
61 page_metadata (nullptr),
62 page_tooltip (nullptr),
63 page_raw (nullptr),
64 page_iofiles (nullptr),
65 page_icc (nullptr),
66 page_plugins (nullptr),
67 page_misc (nullptr),
68 metadataPage (nullptr),
69 toolTipPage (nullptr),
70 miscPage (nullptr),
71 rawPage (nullptr),
72 pluginsPage (nullptr),
73 editorIfacePage (nullptr),
74 iofilesPage (nullptr),
75 iccPage (nullptr)
76 {
77 }
78
79 DConfigDlgWdgItem* page_editorIface;
80 DConfigDlgWdgItem* page_metadata;
81 DConfigDlgWdgItem* page_tooltip;
82 DConfigDlgWdgItem* page_raw;
83 DConfigDlgWdgItem* page_iofiles;
84 DConfigDlgWdgItem* page_icc;
85 DConfigDlgWdgItem* page_plugins;
86 DConfigDlgWdgItem* page_misc;
87
88 ShowfotoSetupMetadata* metadataPage;
89 ShowfotoSetupToolTip* toolTipPage;
90 ShowfotoSetupMisc* miscPage;
91 ShowfotoSetupRaw* rawPage;
92 ShowfotoSetupPlugins* pluginsPage;
93
94 Digikam::SetupEditorIface* editorIfacePage;
95 Digikam::SetupIOFiles* iofilesPage;
96 Digikam::SetupICC* iccPage;
97
98 public:
99
100 DConfigDlgWdgItem* pageItem(ShowfotoSetup::Page page) const;
101 };
102
ShowfotoSetup(QWidget * const parent,ShowfotoSetup::Page page)103 ShowfotoSetup::ShowfotoSetup(QWidget* const parent, ShowfotoSetup::Page page)
104 : DConfigDlg(parent),
105 d (new Private)
106 {
107 setWindowTitle(i18n("Configure"));
108 setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
109 button(QDialogButtonBox::Ok)->setDefault(true);
110 setFaceType(DConfigDlg::List);
111 setModal(true);
112
113 d->editorIfacePage = new Digikam::SetupEditorIface();
114 d->page_editorIface = addPage(d->editorIfacePage, i18n("Editor Window"));
115 d->page_editorIface->setHeader(i18n("<qt>Editor Window Settings<br/>"
116 "<i>Customize editor window behavior</i></qt>"));
117 d->page_editorIface->setIcon(QIcon::fromTheme(QLatin1String("document-edit")));
118
119 d->metadataPage = new ShowfotoSetupMetadata();
120 d->page_metadata = addPage(d->metadataPage, i18n("Metadata"));
121 d->page_metadata->setHeader(i18n("<qt>Embedded Image Information Management<br/>"
122 "<i>Setup relations between images and metadata</i></qt>"));
123 d->page_metadata->setIcon(QIcon::fromTheme(QLatin1String("format-text-code"))); // krazy:exclude=iconnames
124
125 d->toolTipPage = new ShowfotoSetupToolTip();
126 d->page_tooltip = addPage(d->toolTipPage, i18n("Tool Tip"));
127 d->page_tooltip->setHeader(i18n("<qt>Thumbbar and Folder-View Items Tool-Tip Settings<br/>"
128 "<i>Customize information in tool-tips</i></qt>"));
129 d->page_tooltip->setIcon(QIcon::fromTheme(QLatin1String("dialog-information")));
130
131 d->rawPage = new ShowfotoSetupRaw();
132 d->page_raw = addPage(d->rawPage, i18n("RAW Decoding"));
133 d->page_raw->setHeader(i18n("<qt>RAW Files Decoding Settings<br/>"
134 "<i>Customize default RAW decoding settings</i></qt>"));
135 d->page_raw->setIcon(QIcon::fromTheme(QLatin1String("image-x-adobe-dng")));
136
137 d->iccPage = new Digikam::SetupICC(buttonBox());
138 d->page_icc = addPage(d->iccPage, i18n("Color Management"));
139 d->page_icc->setHeader(i18n("<qt>Settings for Color Management<br/>"
140 "<i>Customize color management settings</i></qt>"));
141 d->page_icc->setIcon(QIcon::fromTheme(QLatin1String("preferences-desktop-display-color")));
142
143 d->iofilesPage = new Digikam::SetupIOFiles();
144 d->page_iofiles = addPage(d->iofilesPage, i18n("Save Images"));
145 d->page_iofiles->setHeader(i18n("<qt>Settings for Saving Image Files<br/>"
146 "<i>Set default configuration used to save images</i></qt>"));
147 d->page_iofiles->setIcon(QIcon::fromTheme(QLatin1String("document-save-all")));
148
149 d->pluginsPage = new ShowfotoSetupPlugins();
150 d->page_plugins = addPage(d->pluginsPage, i18n("Plugins"));
151 d->page_plugins->setHeader(i18n("<qt>Main Interface Plug-in Settings<br/>"
152 "<i>Set which plugins will be accessible from application</i></qt>"));
153 d->page_plugins->setIcon(QIcon::fromTheme(QLatin1String("preferences-plugin")));
154
155 d->miscPage = new ShowfotoSetupMisc(this);
156 d->page_misc = addPage(d->miscPage, i18nc("@title: misc setup options page", "Miscellaneous"));
157 d->page_misc->setHeader(i18n("<qt>Miscellaneous Settings<br/>"
158 "<i>Customize behavior of the other parts of Showfoto</i></qt>"));
159 d->page_misc->setIcon(QIcon::fromTheme(QLatin1String("preferences-other")));
160
161 for (int i = 0 ; i != SetupPageEnumLast ; ++i)
162 {
163 DConfigDlgWdgItem* const item = d->pageItem((Page)i);
164
165 if (!item)
166 {
167 continue;
168 }
169
170 QWidget* const wgt = item->widget();
171 QScrollArea* const scrollArea = qobject_cast<QScrollArea*>(wgt);
172
173 if (scrollArea)
174 {
175 scrollArea->setFrameShape(QFrame::NoFrame);
176 }
177 }
178
179 connect(buttonBox()->button(QDialogButtonBox::Ok),
180 &QPushButton::clicked, this, &ShowfotoSetup::slotOkClicked);
181
182 connect(buttonBox(), SIGNAL(helpRequested()),
183 this, SLOT(slotHelp()));
184
185 KSharedConfig::Ptr config = KSharedConfig::openConfig();
186 KConfigGroup group = config->group(QLatin1String("Setup Dialog"));
187
188 if (page != LastPageUsed)
189 {
190 showPage(page);
191 }
192 else
193 {
194 showPage((Page)group.readEntry(QLatin1String("Setup Page"), (int)EditorPage));
195 }
196
197 winId();
198 Digikam::DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
199 resize(windowHandle()->size());
200 }
201
~ShowfotoSetup()202 ShowfotoSetup::~ShowfotoSetup()
203 {
204 KSharedConfig::Ptr config = KSharedConfig::openConfig();
205 KConfigGroup group = config->group(QLatin1String("Setup Dialog"));
206 group.writeEntry(QLatin1String("Setup Page"), (int)activePageIndex());
207 Digikam::DXmlGuiWindow::saveWindowSize(windowHandle(), group);
208 config->sync();
209
210 delete d;
211 }
212
slotHelp()213 void ShowfotoSetup::slotHelp()
214 {
215 Digikam::DXmlGuiWindow::openHandbook();
216 }
217
slotOkClicked()218 void ShowfotoSetup::slotOkClicked()
219 {
220 if (!d->miscPage->checkSettings())
221 {
222 showPage(MiscellaneousPage);
223 return;
224 }
225
226 qApp->setOverrideCursor(Qt::WaitCursor);
227
228 d->editorIfacePage->applySettings();
229 d->metadataPage->applySettings();
230 d->toolTipPage->applySettings();
231 d->rawPage->applySettings();
232 d->iofilesPage->applySettings();
233 d->iccPage->applySettings();
234 d->pluginsPage->applySettings();
235 d->miscPage->applySettings();
236
237 qApp->restoreOverrideCursor();
238
239 accept();
240 }
241
showPage(ShowfotoSetup::Page page)242 void ShowfotoSetup::showPage(ShowfotoSetup::Page page)
243 {
244 switch (page)
245 {
246 case ToolTipPage:
247 {
248 setCurrentPage(d->page_tooltip);
249 break;
250 }
251
252 case RawPage:
253 {
254 setCurrentPage(d->page_raw);
255 break;
256 }
257
258 case IOFilesPage:
259 {
260 setCurrentPage(d->page_iofiles);
261 break;
262 }
263
264 case ICCPage:
265 {
266 setCurrentPage(d->page_icc);
267 break;
268 }
269
270 case MetadataPage:
271 {
272 setCurrentPage(d->page_metadata);
273 break;
274 }
275
276 case PluginsPage:
277 {
278 setCurrentPage(d->page_plugins);
279 break;
280 }
281
282 case MiscellaneousPage:
283 {
284 setCurrentPage(d->page_misc);
285 break;
286 }
287
288 default:
289 {
290 setCurrentPage(d->page_editorIface);
291 break;
292 }
293 }
294 }
295
activePageIndex()296 ShowfotoSetup::Page ShowfotoSetup::activePageIndex()
297 {
298 DConfigDlgWdgItem* const cur = currentPage();
299
300 if (cur == d->page_tooltip)
301 {
302 return ToolTipPage;
303 }
304
305 if (cur == d->page_raw)
306 {
307 return RawPage;
308 }
309
310 if (cur == d->page_iofiles)
311 {
312 return IOFilesPage;
313 }
314
315 if (cur == d->page_icc)
316 {
317 return ICCPage;
318 }
319
320 if (cur == d->page_metadata)
321 {
322 return MetadataPage;
323 }
324
325 if (cur == d->page_plugins)
326 {
327 return PluginsPage;
328 }
329
330 if (cur == d->page_misc)
331 {
332 return MiscellaneousPage;
333 }
334
335 return EditorPage;
336 }
337
pageItem(ShowfotoSetup::Page page) const338 DConfigDlgWdgItem* ShowfotoSetup::Private::pageItem(ShowfotoSetup::Page page) const
339 {
340 switch (page)
341 {
342 case ShowfotoSetup::EditorPage:
343 {
344 return page_editorIface;
345 }
346
347 case ShowfotoSetup::MetadataPage:
348 {
349 return page_metadata;
350 }
351
352 case ShowfotoSetup::ToolTipPage:
353 {
354 return page_tooltip;
355 }
356
357 case ShowfotoSetup::RawPage:
358 {
359 return page_raw;
360 }
361
362 case ShowfotoSetup::IOFilesPage:
363 {
364 return page_iofiles;
365 }
366
367 case ShowfotoSetup::ICCPage:
368 {
369 return page_icc;
370 }
371
372 case ShowfotoSetup::PluginsPage:
373 {
374 return page_plugins;
375 }
376
377 case ShowfotoSetup::MiscellaneousPage:
378 {
379 return page_misc;
380 }
381
382 default:
383 {
384 return nullptr;
385 }
386 }
387 }
388
execSinglePage(Page page)389 bool ShowfotoSetup::execSinglePage(Page page)
390 {
391 return (execSinglePage(nullptr, page));
392 }
393
execSinglePage(QWidget * const parent,Page page)394 bool ShowfotoSetup::execSinglePage(QWidget* const parent, Page page)
395 {
396 QPointer<ShowfotoSetup> setup = new ShowfotoSetup(parent);
397 setup->showPage(page);
398 setup->setFaceType(Plain);
399
400 bool success = (setup->DConfigDlg::exec() == QDialog::Accepted);
401 delete setup;
402
403 return success;
404 }
405
execMetadataFilters(QWidget * const parent,int tab)406 bool ShowfotoSetup::execMetadataFilters(QWidget* const parent, int tab)
407 {
408 QPointer<ShowfotoSetup> setup = new ShowfotoSetup(parent);
409 setup->showPage(MetadataPage);
410 setup->setFaceType(Plain);
411
412 DConfigDlgWdgItem* const cur = setup->currentPage();
413
414 if (!cur)
415 {
416 return false;
417 }
418
419 ShowfotoSetupMetadata* const widget = dynamic_cast<ShowfotoSetupMetadata*>(cur->widget());
420
421 if (!widget)
422 {
423 return false;
424 }
425
426 widget->setActiveTab((ShowfotoSetupMetadata::MetadataTab)tab);
427
428 bool success = (setup->DConfigDlg::exec() == QDialog::Accepted);
429 delete setup;
430
431 return success;
432 }
433
execExifTool(QWidget * const parent)434 bool ShowfotoSetup::execExifTool(QWidget* const parent)
435 {
436 QPointer<ShowfotoSetup> setup = new ShowfotoSetup(parent);
437 setup->showPage(MetadataPage);
438 setup->setFaceType(Plain);
439
440 DConfigDlgWdgItem* const cur = setup->currentPage();
441
442 if (!cur)
443 {
444 return false;
445 }
446
447 ShowfotoSetupMetadata* const widget = dynamic_cast<ShowfotoSetupMetadata*>(cur->widget());
448
449 if (!widget)
450 {
451 return false;
452 }
453
454 widget->setActiveTab(ShowfotoSetupMetadata::ExifTool);
455
456 bool success = (setup->DConfigDlg::exec() == QDialog::Accepted);
457 delete setup;
458
459 return success;
460 }
461
onlineVersionCheck()462 void ShowfotoSetup::onlineVersionCheck()
463 {
464 OnlineVersionDlg* const dlg = new OnlineVersionDlg(qApp->activeWindow(),
465 QLatin1String(digikam_version_short),
466 digiKamBuildDate(),
467 ShowfotoSettings::instance()->getUpdateType(),
468 ShowfotoSettings::instance()->getUpdateWithDebug());
469
470 connect(dlg, &OnlineVersionDlg::signalSetupUpdate,
471 [=]()
472 {
473 ShowfotoSetup::execSinglePage(nullptr, ShowfotoSetup::MiscellaneousPage);
474 }
475 );
476
477 dlg->exec();
478 }
479
480 } // namespace ShowFoto
481