1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* ============================================================
 *
 * This file is a part of digiKam project
 * https://www.digikam.org
 *
 * Date        : 2006-04-04
 * Description : a tool to generate HTML image galleries
 *
 * SPDX-FileCopyrightText: 2006-2010 by Aurelien Gateau <aurelien dot gateau at free dot fr>
 * SPDX-FileCopyrightText: 2012-2025 by Gilles Caulier <caulier dot gilles at gmail dot com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 *
 * ============================================================ */

#include "htmlwizard.h"

// Qt includes

#include <QCheckBox>
#include <QLabel>
#include <QMenu>
#include <QApplication>
#include <QComboBox>
#include <QListWidget>
#include <QTextBrowser>

// KDE includes

#include <klocalizedstring.h>

// Local includes

#include "dwizardpage.h"
#include "dconfigdlgmngr.h"
#include "digikam_debug.h"
#include "abstractthemeparameter.h"
#include "galleryinfo.h"
#include "invisiblebuttongroup.h"
#include "htmlintropage.h"
#include "htmloutputpage.h"
#include "htmlselectionpage.h"
#include "htmlthemepage.h"
#include "htmlparameterspage.h"
#include "htmlimagesettingspage.h"
#include "htmlfinalpage.h"

namespace DigikamGenericHtmlGalleryPlugin
{

class Q_DECL_HIDDEN HTMLWizard::Private
{
public:

    Private() = default;

    GalleryInfo*           info                 = nullptr;
    DConfigDlgMngr*        configManager        = nullptr;

    HTMLIntroPage*         introPage            = nullptr;
    HTMLSelectionPage*     selectionPage        = nullptr;
    HTMLThemePage*         themePage            = nullptr;
    HTMLParametersPage*    parametersPage       = nullptr;
    HTMLImageSettingsPage* imageSettingsPage    = nullptr;
    HTMLOutputPage*        outputPage           = nullptr;
    HTMLFinalPage*         finalPage            = nullptr;
};

HTMLWizard::HTMLWizard(QWidget* const parent, DInfoInterface* const iface)
    : DWizardDlg(parent, QLatin1String("HTML Gallery Dialog")),
      d         (new Private)
{
    setOption(QWizard::NoCancelButtonOnLastPage);
    setWindowTitle(i18nc("@title:window", "Create HTML Gallery"));

    d->info = new GalleryInfo(iface);
    d->info->load();

    d->introPage         = new HTMLIntroPage(this,         i18n("Welcome to HTML Gallery Tool"));
    d->selectionPage     = new HTMLSelectionPage(this,     i18n("Items Selection"));
    d->themePage         = new HTMLThemePage(this,         i18n("Theme Selection"));
    d->parametersPage    = new HTMLParametersPage(this,    i18n("Theme Parameters"));
    d->imageSettingsPage = new HTMLImageSettingsPage(this, i18n("Image Settings"));
    d->outputPage        = new HTMLOutputPage(this,        i18n("Output Settings"));
    d->finalPage         = new HTMLFinalPage(this,         i18n("Generating Gallery"));
    d->configManager     = new DConfigDlgMngr(this, d->info);
    d->configManager->updateWidgets();
}

HTMLWizard::~HTMLWizard()
{
    delete d;
}

void HTMLWizard::setItemsList(const QList<QUrl>& urls)
{
    d->selectionPage->setItemsList(urls);
}

bool HTMLWizard::validateCurrentPage()
{
    if (!DWizardDlg::validateCurrentPage())
    {
        return false;
    }

    if (currentPage() == d->outputPage)
    {
        GalleryTheme::Ptr curtheme                     = galleryTheme();
        QString themeInternalName                      = curtheme->internalName();
        d->info->setTheme(themeInternalName);

        GalleryTheme::ParameterList parameterList      = curtheme->parameterList();
        GalleryTheme::ParameterList::ConstIterator it  = parameterList.constBegin();
        GalleryTheme::ParameterList::ConstIterator end = parameterList.constEnd();

        for ( ; it != end ; ++it)
        {
            AbstractThemeParameter* const themeParameter = *it;<--- Variable 'themeParameter' can be declared as pointer to const
            QByteArray parameterInternalName             = themeParameter->internalName();
            QWidget* const widget                        = d->parametersPage->themeParameterWidgetFromName(parameterInternalName);
            QString value                                = themeParameter->valueFromWidget(widget);

            d->info->setThemeParameterValue(themeInternalName,
                                             QString::fromLatin1(parameterInternalName),
                                             value);
        }

        d->configManager->updateSettings();
        d->info->save();
    }

    return true;
}

int HTMLWizard::nextId() const
{
    if (currentPage() == d->themePage)
    {
        GalleryTheme::Ptr theme = galleryTheme();

        if (theme && (theme->parameterList().size() > 0))
        {
            // Enable theme parameters page as next page if there is any parameter.

            return d->parametersPage->id();
        }

        return d->imageSettingsPage->id();
    }

    return DWizardDlg::nextId();
}

GalleryInfo* HTMLWizard::galleryInfo() const
{
    return d->info;
}

GalleryTheme::Ptr HTMLWizard::galleryTheme() const
{
    return d->themePage->currentTheme();
}

} // namespace DigikamGenericHtmlGalleryPlugin

#include "moc_htmlwizard.cpp"