File indexing completed on 2025-01-05 03:57:56

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2005-04-02
0007  * Description : showFoto setup dialog.
0008  *
0009  * SPDX-FileCopyrightText: 2005-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "showfotosetup.h"
0016 
0017 // Qt includes
0018 
0019 #include <QPointer>
0020 #include <QPushButton>
0021 #include <QApplication>
0022 
0023 // KDE includes
0024 
0025 #include <kconfiggroup.h>
0026 #include <ksharedconfig.h>
0027 #include <klocalizedstring.h>
0028 
0029 // Local includes
0030 
0031 #include "digikam_globals.h"
0032 #include "setupeditoriface.h"
0033 #include "setupicc.h"
0034 #include "setupiofiles.h"
0035 #include "showfotosettings.h"
0036 #include "showfotosetupraw.h"
0037 #include "showfotosetupmisc.h"
0038 #include "showfotosetupmetadata.h"
0039 #include "showfotosetuptooltip.h"
0040 #include "showfotosetupplugins.h"
0041 #include "dxmlguiwindow.h"
0042 #include "onlineversiondlg.h"
0043 
0044 #ifdef HAVE_GEOLOCATION
0045 #   include "setupgeolocation.h"
0046 #endif
0047 
0048 namespace ShowFoto
0049 {
0050 
0051 class Q_DECL_HIDDEN ShowfotoSetup::Private
0052 {
0053 public:
0054 
0055     explicit Private()
0056       : page_editorIface(nullptr),
0057         page_metadata   (nullptr),
0058         page_tooltip    (nullptr),
0059         page_raw        (nullptr),
0060         page_iofiles    (nullptr),
0061         page_icc        (nullptr),
0062 
0063 #ifdef HAVE_GEOLOCATION
0064 
0065         page_geolocation(nullptr),
0066 
0067 #endif
0068 
0069         page_plugins    (nullptr),
0070         page_misc       (nullptr),
0071         metadataPage    (nullptr),
0072         toolTipPage     (nullptr),
0073         miscPage        (nullptr),
0074         rawPage         (nullptr),
0075         pluginsPage     (nullptr),
0076 
0077 #ifdef HAVE_GEOLOCATION
0078 
0079         geolocationPage (nullptr),
0080 
0081 #endif
0082 
0083         editorIfacePage (nullptr),
0084         iofilesPage     (nullptr),
0085         iccPage         (nullptr)
0086     {
0087     }
0088 
0089     DConfigDlgWdgItem*            page_editorIface;
0090     DConfigDlgWdgItem*            page_metadata;
0091     DConfigDlgWdgItem*            page_tooltip;
0092     DConfigDlgWdgItem*            page_raw;
0093     DConfigDlgWdgItem*            page_iofiles;
0094     DConfigDlgWdgItem*            page_icc;
0095 
0096 #ifdef HAVE_GEOLOCATION
0097 
0098     DConfigDlgWdgItem*            page_geolocation;
0099 
0100 #endif
0101 
0102     DConfigDlgWdgItem*            page_plugins;
0103     DConfigDlgWdgItem*            page_misc;
0104 
0105     ShowfotoSetupMetadata*        metadataPage;
0106     ShowfotoSetupToolTip*         toolTipPage;
0107     ShowfotoSetupMisc*            miscPage;
0108     ShowfotoSetupRaw*             rawPage;
0109     ShowfotoSetupPlugins*         pluginsPage;
0110 
0111 #ifdef HAVE_GEOLOCATION
0112 
0113     Digikam::SetupGeolocation*    geolocationPage;
0114 
0115 #endif
0116 
0117     Digikam::SetupEditorIface*    editorIfacePage;
0118     Digikam::SetupIOFiles*        iofilesPage;
0119     Digikam::SetupICC*            iccPage;
0120 
0121 public:
0122 
0123     DConfigDlgWdgItem* pageItem(ShowfotoSetup::Page page) const;
0124 };
0125 
0126 ShowfotoSetup::ShowfotoSetup(QWidget* const parent, ShowfotoSetup::Page page)
0127     : DConfigDlg(parent),
0128       d         (new Private)
0129 {
0130     setWindowTitle(i18nc("@title:window", "Configure"));
0131     setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0132     button(QDialogButtonBox::Ok)->setDefault(true);
0133     setFaceType(DConfigDlg::List);
0134     setModal(true);
0135 
0136     d->editorIfacePage  = new Digikam::SetupEditorIface();
0137     d->page_editorIface = addPage(d->editorIfacePage, i18n("Editor Window"));
0138     d->page_editorIface->setHeader(i18n("<qt>Editor Window Settings<br/>"
0139                                    "<i>Customize editor window behavior</i></qt>"));
0140     d->page_editorIface->setIcon(QIcon::fromTheme(QLatin1String("document-edit")));
0141 
0142     d->metadataPage   = new ShowfotoSetupMetadata();
0143     d->page_metadata  = addPage(d->metadataPage, i18n("Metadata"));
0144     d->page_metadata->setHeader(i18n("<qt>Embedded Image Information Management<br/>"
0145                                      "<i>Setup relations between images and metadata</i></qt>"));
0146     d->page_metadata->setIcon(QIcon::fromTheme(QLatin1String("format-text-code"))); // krazy:exclude=iconnames
0147 
0148     d->toolTipPage    = new ShowfotoSetupToolTip();
0149     d->page_tooltip   = addPage(d->toolTipPage, i18n("Tool Tip"));
0150     d->page_tooltip->setHeader(i18n("<qt>Thumbbar and Folder-View Items Tool-Tip Settings<br/>"
0151                                     "<i>Customize information in tool-tips</i></qt>"));
0152     d->page_tooltip->setIcon(QIcon::fromTheme(QLatin1String("dialog-information")));
0153 
0154     d->rawPage        = new ShowfotoSetupRaw();
0155     d->page_raw       = addPage(d->rawPage, i18n("RAW Decoding"));
0156     d->page_raw->setHeader(i18n("<qt>RAW Files Decoding Settings<br/>"
0157                                   "<i>Customize default RAW decoding settings</i></qt>"));
0158     d->page_raw->setIcon(QIcon::fromTheme(QLatin1String("image-x-adobe-dng")));
0159 
0160     d->iccPage        = new Digikam::SetupICC(buttonBox());
0161     d->page_icc       = addPage(d->iccPage, i18n("Color Management"));
0162     d->page_icc->setHeader(i18n("<qt>Settings for Color Management<br/>"
0163                                 "<i>Customize color management settings</i></qt>"));
0164     d->page_icc->setIcon(QIcon::fromTheme(QLatin1String("preferences-desktop-display-color")));
0165 
0166     d->iofilesPage    = new Digikam::SetupIOFiles();
0167     d->page_iofiles   = addPage(d->iofilesPage, i18n("Save Images"));
0168     d->page_iofiles->setHeader(i18n("<qt>Settings for Saving Image Files<br/>"
0169                                     "<i>Set default configuration used to save images</i></qt>"));
0170     d->page_iofiles->setIcon(QIcon::fromTheme(QLatin1String("document-save-all")));
0171 
0172 #ifdef HAVE_GEOLOCATION
0173 
0174     d->geolocationPage  = new SetupGeolocation();
0175     d->page_geolocation = addPage(d->geolocationPage, i18nc("@title: settings section", "Geolocation"));
0176     d->page_geolocation->setHeader(i18nc("@title", "Geolocation Settings\nCustomize view to geolocalize items"));
0177     d->page_geolocation->setIcon(QIcon::fromTheme(QLatin1String("map-globe")));
0178 
0179 #endif
0180 
0181     d->pluginsPage    = new ShowfotoSetupPlugins();
0182     d->page_plugins   = addPage(d->pluginsPage, i18n("Plugins"));
0183     d->page_plugins->setHeader(i18n("<qt>Main Interface Plug-in Settings<br/>"
0184                                     "<i>Set which plugins will be accessible from application</i></qt>"));
0185     d->page_plugins->setIcon(QIcon::fromTheme(QLatin1String("preferences-plugin")));
0186 
0187     d->miscPage       = new ShowfotoSetupMisc(this);
0188     d->page_misc      = addPage(d->miscPage, i18nc("@title: misc setup options page", "Miscellaneous"));
0189     d->page_misc->setHeader(i18n("<qt>Miscellaneous Settings<br/>"
0190                                  "<i>Customize behavior of the other parts of Showfoto</i></qt>"));
0191     d->page_misc->setIcon(QIcon::fromTheme(QLatin1String("preferences-other")));
0192 
0193     for (int i = 0 ; i != SetupPageEnumLast ; ++i)
0194     {
0195         DConfigDlgWdgItem* const item = d->pageItem((Page)i);
0196 
0197         if (!item)
0198         {
0199             continue;
0200         }
0201 
0202         QWidget* const wgt            = item->widget();
0203         QScrollArea* const scrollArea = qobject_cast<QScrollArea*>(wgt);
0204 
0205         if (scrollArea)
0206         {
0207             scrollArea->setFrameShape(QFrame::NoFrame);
0208         }
0209     }
0210 
0211     connect(buttonBox()->button(QDialogButtonBox::Ok), &QPushButton::clicked,
0212             this, &ShowfotoSetup::slotOkClicked);
0213 
0214     connect(buttonBox()->button(QDialogButtonBox::Cancel), &QPushButton::clicked,
0215             this, &ShowfotoSetup::slotCancelClicked);
0216 
0217     connect(buttonBox(), SIGNAL(helpRequested()),
0218             this, SLOT(slotHelp()));
0219 
0220     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0221     KConfigGroup group        = config->group(QLatin1String("Setup Dialog"));
0222 
0223     if (page != LastPageUsed)
0224     {
0225         showPage(page);
0226         d->metadataPage->setActiveTab((ShowfotoSetupMetadata::MetadataTab)group.readEntry(QLatin1String("Metadata Tab"), (int)ShowfotoSetupMetadata::Behavior));
0227         d->rawPage->setActiveTab((ShowfotoSetupRaw::RAWTab)group.readEntry(QLatin1String("RAW Tab"), (int)ShowfotoSetupRaw::RAWBehavior));
0228         d->iccPage->setActiveTab((Digikam::SetupICC::ICCTab)group.readEntry(QLatin1String("ICC Tab"), (int)Digikam::SetupICC::Behavior));
0229         d->pluginsPage->setActiveTab((ShowfotoSetupPlugins::PluginTab)group.readEntry(QLatin1String("Plugin Tab"), (int)ShowfotoSetupPlugins::Generic));
0230 
0231 #ifdef HAVE_GEOLOCATION
0232 
0233         d->geolocationPage->setActiveTab((SetupGeolocation::GeolocationTab)group.readEntry(QLatin1String("Geolocation Tab"), (int)SetupGeolocation::MarbleView));
0234 
0235 #endif
0236 
0237         d->miscPage->setActiveTab((ShowfotoSetupMisc::MiscTab)group.readEntry(QLatin1String("Misc Tab"), (int)ShowfotoSetupMisc::Behaviour));
0238     }
0239     else
0240     {
0241         showPage((Page)group.readEntry(QLatin1String("Setup Page"), (int)EditorPage));
0242     }
0243 
0244     winId();
0245     DXmlGuiWindow::setGoodDefaultWindowSize(windowHandle());
0246     DXmlGuiWindow::restoreWindowSize(windowHandle(), group);
0247     resize(windowHandle()->size());
0248 }
0249 
0250 ShowfotoSetup::~ShowfotoSetup()
0251 {
0252     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0253     KConfigGroup group        = config->group(QLatin1String("Setup Dialog"));
0254     group.writeEntry(QLatin1String("Setup Page"),      (int)activePageIndex());
0255     group.writeEntry(QLatin1String("Metadata Tab"),    (int)d->metadataPage->activeTab());
0256     group.writeEntry(QLatin1String("RAW Tab"),         (int)d->rawPage->activeTab());
0257     group.writeEntry(QLatin1String("ICC Tab"),         (int)d->iccPage->activeTab());
0258     group.writeEntry(QLatin1String("Plugin Tab"),      (int)d->pluginsPage->activeTab());
0259 
0260 #ifdef HAVE_GEOLOCATION
0261 
0262     group.writeEntry(QLatin1String("Geolocation Tab"), (int)d->geolocationPage->activeTab());
0263 
0264 #endif
0265 
0266     group.writeEntry(QLatin1String("Misc Tab"),        (int)d->miscPage->activeTab());
0267     Digikam::DXmlGuiWindow::saveWindowSize(windowHandle(), group);
0268     config->sync();
0269 
0270     delete d;
0271 }
0272 
0273 void ShowfotoSetup::slotHelp()
0274 {
0275     Digikam::openOnlineDocumentation(QLatin1String("showfoto_editor"), QLatin1String("showfoto_setup"));
0276 }
0277 
0278 void ShowfotoSetup::slotCancelClicked()
0279 {
0280 
0281 #ifdef HAVE_GEOLOCATION
0282 
0283     d->geolocationPage->cancel();
0284 
0285 #endif
0286 
0287 }
0288 
0289 void ShowfotoSetup::slotOkClicked()
0290 {
0291     if (!d->miscPage->checkSettings())
0292     {
0293         showPage(MiscellaneousPage);
0294         return;
0295     }
0296 
0297     qApp->setOverrideCursor(Qt::WaitCursor);
0298 
0299     d->editorIfacePage->applySettings();
0300     d->metadataPage->applySettings();
0301     d->toolTipPage->applySettings();
0302     d->rawPage->applySettings();
0303     d->iofilesPage->applySettings();
0304     d->iccPage->applySettings();
0305     d->pluginsPage->applySettings();
0306 
0307 #ifdef HAVE_GEOLOCATION
0308 
0309     d->geolocationPage->applySettings();
0310 
0311 #endif
0312 
0313     d->miscPage->applySettings();
0314 
0315     qApp->restoreOverrideCursor();
0316 
0317     accept();
0318 }
0319 
0320 void ShowfotoSetup::showPage(ShowfotoSetup::Page page)
0321 {
0322     switch (page)
0323     {
0324         case ToolTipPage:
0325         {
0326             setCurrentPage(d->page_tooltip);
0327             break;
0328         }
0329 
0330         case RawPage:
0331         {
0332             setCurrentPage(d->page_raw);
0333             break;
0334         }
0335 
0336         case IOFilesPage:
0337         {
0338             setCurrentPage(d->page_iofiles);
0339             break;
0340         }
0341 
0342         case ICCPage:
0343         {
0344             setCurrentPage(d->page_icc);
0345             break;
0346         }
0347 
0348         case MetadataPage:
0349         {
0350             setCurrentPage(d->page_metadata);
0351             break;
0352         }
0353 
0354         case PluginsPage:
0355         {
0356             setCurrentPage(d->page_plugins);
0357             break;
0358         }
0359 
0360 #ifdef HAVE_GEOLOCATION
0361 
0362         case GeolocationPage:
0363         {
0364             setCurrentPage(d->page_geolocation);
0365             break;
0366         }
0367 
0368 #endif
0369 
0370         case MiscellaneousPage:
0371         {
0372             setCurrentPage(d->page_misc);
0373             break;
0374         }
0375 
0376         default:
0377         {
0378             setCurrentPage(d->page_editorIface);
0379             break;
0380         }
0381     }
0382 }
0383 
0384 ShowfotoSetup::Page ShowfotoSetup::activePageIndex()
0385 {
0386     DConfigDlgWdgItem* const cur = currentPage();
0387 
0388     if (cur == d->page_tooltip)
0389     {
0390         return ToolTipPage;
0391     }
0392 
0393     if (cur == d->page_raw)
0394     {
0395         return RawPage;
0396     }
0397 
0398     if (cur == d->page_iofiles)
0399     {
0400         return IOFilesPage;
0401     }
0402 
0403     if (cur == d->page_icc)
0404     {
0405         return ICCPage;
0406     }
0407 
0408     if (cur == d->page_metadata)
0409     {
0410         return MetadataPage;
0411     }
0412 
0413     if (cur == d->page_plugins)
0414     {
0415         return PluginsPage;
0416     }
0417 
0418 #ifdef HAVE_GEOLOCATION
0419 
0420     if (cur == d->page_geolocation)
0421     {
0422         return GeolocationPage;
0423     }
0424 
0425 #endif
0426 
0427     if (cur == d->page_misc)
0428     {
0429         return MiscellaneousPage;
0430     }
0431 
0432     return EditorPage;
0433 }
0434 
0435 DConfigDlgWdgItem* ShowfotoSetup::Private::pageItem(ShowfotoSetup::Page page) const
0436 {
0437     switch (page)
0438     {
0439         case ShowfotoSetup::EditorPage:
0440         {
0441             return page_editorIface;
0442         }
0443 
0444         case ShowfotoSetup::MetadataPage:
0445         {
0446             return page_metadata;
0447         }
0448 
0449         case ShowfotoSetup::ToolTipPage:
0450         {
0451             return page_tooltip;
0452         }
0453 
0454         case ShowfotoSetup::RawPage:
0455         {
0456             return page_raw;
0457         }
0458 
0459         case ShowfotoSetup::IOFilesPage:
0460         {
0461             return page_iofiles;
0462         }
0463 
0464         case ShowfotoSetup::ICCPage:
0465         {
0466             return page_icc;
0467         }
0468 
0469         case ShowfotoSetup::PluginsPage:
0470         {
0471             return page_plugins;
0472         }
0473 
0474 #ifdef HAVE_GEOLOCATION
0475 
0476         case ShowfotoSetup::GeolocationPage:
0477         {
0478             return page_geolocation;
0479         }
0480 
0481 #endif
0482 
0483         case ShowfotoSetup::MiscellaneousPage:
0484         {
0485             return page_misc;
0486         }
0487 
0488         default:
0489         {
0490             return nullptr;
0491         }
0492     }
0493 }
0494 
0495 bool ShowfotoSetup::execSinglePage(Page page)
0496 {
0497     return (execSinglePage(nullptr, page));
0498 }
0499 
0500 bool ShowfotoSetup::execSinglePage(QWidget* const parent, Page page)
0501 {
0502     QPointer<ShowfotoSetup> setup = new ShowfotoSetup(parent);
0503     setup->showPage(page);
0504     setup->setFaceType(Plain);
0505 
0506     bool success                  = (setup->DConfigDlg::exec() == QDialog::Accepted);
0507     delete setup;
0508 
0509     return success;
0510 }
0511 
0512 #ifdef HAVE_GEOLOCATION
0513 
0514 bool ShowfotoSetup::execGeolocation(QWidget* const parent, int tab)
0515 {
0516     QPointer<ShowfotoSetup> setup  = new ShowfotoSetup(parent);
0517     setup->showPage(GeolocationPage);
0518     setup->setFaceType(Plain);
0519 
0520     DConfigDlgWdgItem* const cur   = setup->currentPage();
0521 
0522     if (!cur)
0523     {
0524         return false;
0525     }
0526 
0527     Digikam::SetupGeolocation* const widget = dynamic_cast<Digikam::SetupGeolocation*>(cur->widget());
0528 
0529     if (!widget)
0530     {
0531         return false;
0532     }
0533 
0534     widget->setActiveTab((Digikam::SetupGeolocation::GeolocationTab)tab);
0535 
0536     bool success                   = (setup->DConfigDlg::exec() == QDialog::Accepted);
0537     delete setup;
0538 
0539     return success;
0540 }
0541 
0542 #endif
0543 
0544 bool ShowfotoSetup::execMetadataFilters(QWidget* const parent, int tab)
0545 {
0546     QPointer<ShowfotoSetup> setup = new ShowfotoSetup(parent);
0547     setup->showPage(MetadataPage);
0548     setup->setFaceType(Plain);
0549 
0550     DConfigDlgWdgItem* const cur  = setup->currentPage();
0551 
0552     if (!cur)
0553     {
0554         return false;
0555     }
0556 
0557     ShowfotoSetupMetadata* const widget = dynamic_cast<ShowfotoSetupMetadata*>(cur->widget());
0558 
0559     if (!widget)
0560     {
0561         return false;
0562     }
0563 
0564     widget->setActiveTab((ShowfotoSetupMetadata::MetadataTab)tab);
0565 
0566     bool success                        = (setup->DConfigDlg::exec() == QDialog::Accepted);
0567     delete setup;
0568 
0569     return success;
0570 }
0571 
0572 bool ShowfotoSetup::execExifTool(QWidget* const parent)
0573 {
0574     QPointer<ShowfotoSetup> setup        = new ShowfotoSetup(parent);
0575     setup->showPage(MetadataPage);
0576     setup->setFaceType(Plain);
0577 
0578     DConfigDlgWdgItem* const cur         = setup->currentPage();
0579 
0580     if (!cur)
0581     {
0582         return false;
0583     }
0584 
0585     ShowfotoSetupMetadata* const widget  = dynamic_cast<ShowfotoSetupMetadata*>(cur->widget());
0586 
0587     if (!widget)
0588     {
0589         return false;
0590     }
0591 
0592     widget->setActiveTab(ShowfotoSetupMetadata::ExifTool);
0593 
0594     bool success                         = (setup->DConfigDlg::exec() == QDialog::Accepted);
0595     delete setup;
0596 
0597     return success;
0598 }
0599 
0600 bool ShowfotoSetup::execLocalize(QWidget* const parent)
0601 {
0602     QPointer<ShowfotoSetup> setup        = new ShowfotoSetup(parent);
0603     setup->showPage(MiscellaneousPage);
0604     setup->setFaceType(Plain);
0605 
0606     DConfigDlgWdgItem* const cur         = setup->currentPage();
0607 
0608     if (!cur)
0609     {
0610         return false;
0611     }
0612 
0613     ShowfotoSetupMisc* const widget  = dynamic_cast<ShowfotoSetupMisc*>(cur->widget());
0614 
0615     if (!widget)
0616     {
0617         return false;
0618     }
0619 
0620     widget->setActiveTab(ShowfotoSetupMisc::Localize);
0621 
0622     bool success                         = (setup->DConfigDlg::exec() == QDialog::Accepted);
0623     delete setup;
0624 
0625     return success;
0626 }
0627 
0628 void ShowfotoSetup::onlineVersionCheck()
0629 {
0630     OnlineVersionDlg* const dlg = new OnlineVersionDlg(qApp->activeWindow(),
0631                                                        QLatin1String(digikam_version_short),
0632                                                        digiKamBuildDate(),
0633                                                        ShowfotoSettings::instance()->getUpdateType(),
0634                                                        ShowfotoSettings::instance()->getUpdateWithDebug());
0635 
0636     connect(dlg, &OnlineVersionDlg::signalSetupUpdate,
0637             [=]()
0638         {
0639             ShowfotoSetup::execSinglePage(nullptr, ShowfotoSetup::MiscellaneousPage);
0640         }
0641     );
0642 
0643     dlg->exec();
0644 }
0645 
0646 } // namespace ShowFoto
0647 
0648 #include "moc_showfotosetup.cpp"