File indexing completed on 2025-01-05 03:52:07

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2006-04-04
0007  * Description : a tool to generate HTML image galleries
0008  *
0009  * SPDX-FileCopyrightText: 2006-2010 by Aurelien Gateau <aurelien dot gateau at free dot fr>
0010  * SPDX-FileCopyrightText: 2012-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0011  *
0012  * SPDX-License-Identifier: GPL-2.0-or-later
0013  *
0014  * ============================================================ */
0015 
0016 #include "htmlwizard.h"
0017 
0018 // Qt includes
0019 
0020 #include <QCheckBox>
0021 #include <QLabel>
0022 #include <QMenu>
0023 #include <QApplication>
0024 #include <QComboBox>
0025 #include <QListWidget>
0026 #include <QTextBrowser>
0027 
0028 // KDE includes
0029 
0030 #include <klocalizedstring.h>
0031 
0032 // Local includes
0033 
0034 #include "dwizardpage.h"
0035 #include "dconfigdlgmngr.h"
0036 #include "digikam_debug.h"
0037 #include "abstractthemeparameter.h"
0038 #include "galleryinfo.h"
0039 #include "invisiblebuttongroup.h"
0040 #include "htmlintropage.h"
0041 #include "htmloutputpage.h"
0042 #include "htmlselectionpage.h"
0043 #include "htmlthemepage.h"
0044 #include "htmlparameterspage.h"
0045 #include "htmlimagesettingspage.h"
0046 #include "htmlfinalpage.h"
0047 
0048 namespace DigikamGenericHtmlGalleryPlugin
0049 {
0050 
0051 class Q_DECL_HIDDEN HTMLWizard::Private
0052 {
0053 public:
0054 
0055     explicit Private()
0056       : info                (nullptr),
0057         configManager       (nullptr),
0058         introPage           (nullptr),
0059         selectionPage       (nullptr),
0060         themePage           (nullptr),
0061         parametersPage      (nullptr),
0062         imageSettingsPage   (nullptr),
0063         outputPage          (nullptr),
0064         finalPage           (nullptr)
0065     {
0066     }
0067 
0068     GalleryInfo*           info;
0069     DConfigDlgMngr*        configManager;
0070 
0071     HTMLIntroPage*         introPage;
0072     HTMLSelectionPage*     selectionPage;
0073     HTMLThemePage*         themePage;
0074     HTMLParametersPage*    parametersPage;
0075     HTMLImageSettingsPage* imageSettingsPage;
0076     HTMLOutputPage*        outputPage;
0077     HTMLFinalPage*         finalPage;
0078 };
0079 
0080 HTMLWizard::HTMLWizard(QWidget* const parent, DInfoInterface* const iface)
0081     : DWizardDlg(parent, QLatin1String("HTML Gallery Dialog")),
0082       d         (new Private)
0083 {
0084     setOption(QWizard::NoCancelButtonOnLastPage);
0085     setWindowTitle(i18nc("@title:window", "Create HTML Gallery"));
0086 
0087     d->info = new GalleryInfo(iface);
0088     d->info->load();
0089 
0090     d->introPage         = new HTMLIntroPage(this,         i18n("Welcome to HTML Gallery Tool"));
0091     d->selectionPage     = new HTMLSelectionPage(this,     i18n("Items Selection"));
0092     d->themePage         = new HTMLThemePage(this,         i18n("Theme Selection"));
0093     d->parametersPage    = new HTMLParametersPage(this,    i18n("Theme Parameters"));
0094     d->imageSettingsPage = new HTMLImageSettingsPage(this, i18n("Image Settings"));
0095     d->outputPage        = new HTMLOutputPage(this,        i18n("Output Settings"));
0096     d->finalPage         = new HTMLFinalPage(this,         i18n("Generating Gallery"));
0097     d->configManager     = new DConfigDlgMngr(this, d->info);
0098     d->configManager->updateWidgets();
0099 }
0100 
0101 HTMLWizard::~HTMLWizard()
0102 {
0103     delete d;
0104 }
0105 
0106 void HTMLWizard::setItemsList(const QList<QUrl>& urls)
0107 {
0108     d->selectionPage->setItemsList(urls);
0109 }
0110 
0111 bool HTMLWizard::validateCurrentPage()
0112 {
0113     if (!DWizardDlg::validateCurrentPage())
0114     {
0115         return false;
0116     }
0117 
0118     if (currentPage() == d->outputPage)
0119     {
0120         GalleryTheme::Ptr curtheme                     = galleryTheme();
0121         QString themeInternalName                      = curtheme->internalName();
0122         d->info->setTheme(themeInternalName);
0123 
0124         GalleryTheme::ParameterList parameterList      = curtheme->parameterList();
0125         GalleryTheme::ParameterList::ConstIterator it  = parameterList.constBegin();
0126         GalleryTheme::ParameterList::ConstIterator end = parameterList.constEnd();
0127 
0128         for (; it != end ; ++it)
0129         {
0130             AbstractThemeParameter* const themeParameter = *it;
0131             QByteArray parameterInternalName             = themeParameter->internalName();
0132             QWidget* const widget                        = d->parametersPage->themeParameterWidgetFromName(parameterInternalName);
0133             QString value                                = themeParameter->valueFromWidget(widget);
0134 
0135             d->info->setThemeParameterValue(themeInternalName,
0136                                              QString::fromLatin1(parameterInternalName),
0137                                              value);
0138         }
0139 
0140         d->configManager->updateSettings();
0141         d->info->save();
0142     }
0143 
0144     return true;
0145 }
0146 
0147 int HTMLWizard::nextId() const
0148 {
0149     if (currentPage() == d->themePage)
0150     {
0151         GalleryTheme::Ptr theme = galleryTheme();
0152 
0153         if (theme && theme->parameterList().size() > 0)
0154         {
0155             // Enable theme parameters page as next page if there is any parameter.
0156 
0157             return d->parametersPage->id();
0158         }
0159 
0160         return d->imageSettingsPage->id();
0161     }
0162 
0163     return DWizardDlg::nextId();
0164 }
0165 
0166 GalleryInfo* HTMLWizard::galleryInfo() const
0167 {
0168     return d->info;
0169 }
0170 
0171 GalleryTheme::Ptr HTMLWizard::galleryTheme() const
0172 {
0173     return d->themePage->currentTheme();
0174 }
0175 
0176 } // namespace DigikamGenericHtmlGalleryPlugin
0177 
0178 #include "moc_htmlwizard.cpp"