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

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: 2012-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 "htmloutputpage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QIcon>
0020 #include <QLabel>
0021 #include <QUrl>
0022 #include <QWidget>
0023 #include <QApplication>
0024 #include <QStyle>
0025 #include <QComboBox>
0026 #include <QGridLayout>
0027 
0028 // KDE includes
0029 
0030 #include <klocalizedstring.h>
0031 
0032 // Local includes
0033 
0034 #include "dtextedit.h"
0035 #include "htmlwizard.h"
0036 #include "galleryinfo.h"
0037 #include "dfileselector.h"
0038 
0039 namespace DigikamGenericHtmlGalleryPlugin
0040 {
0041 
0042 class Q_DECL_HIDDEN HTMLOutputPage::Private
0043 {
0044 public:
0045 
0046     explicit Private()
0047       : destUrl             (nullptr),
0048         openInBrowser       (nullptr),
0049         titleLabel          (nullptr),
0050         imageSelectionTitle (nullptr)
0051     {
0052     }
0053 
0054     DFileSelector* destUrl;
0055     QComboBox*     openInBrowser;
0056     QLabel*        titleLabel;
0057     DTextEdit*     imageSelectionTitle;
0058 };
0059 
0060 HTMLOutputPage::HTMLOutputPage(QWizard* const dialog, const QString& title)
0061     : DWizardPage(dialog, title),
0062       d          (new Private)
0063 {
0064     setObjectName(QLatin1String("OutputPage"));
0065 
0066     QWidget* const main      = new QWidget(this);
0067 
0068     // --------------------
0069 
0070     d->titleLabel = new QLabel(main);
0071     d->titleLabel->setWordWrap(false);
0072     d->titleLabel->setText(i18nc("@label", "Gallery Title:"));
0073 
0074     d->imageSelectionTitle   = new DTextEdit(main);
0075     d->imageSelectionTitle->setLinesVisible(1);
0076     d->titleLabel->setBuddy(d->imageSelectionTitle);
0077 
0078     // --------------------
0079 
0080     QLabel* const textLabel1 = new QLabel(main);
0081     textLabel1->setWordWrap(false);
0082     textLabel1->setText(i18nc("@label", "Destination folder:"));
0083 
0084     d->destUrl = new DFileSelector(main);
0085     d->destUrl->setFileDlgTitle(i18nc("@title:window", "Destination Folder"));
0086     d->destUrl->setFileDlgMode(QFileDialog::Directory);
0087     d->destUrl->setFileDlgOptions(QFileDialog::ShowDirsOnly);
0088     textLabel1->setBuddy(d->destUrl);
0089 
0090     // --------------------
0091 
0092     QLabel* const browserLabel = new QLabel(main);
0093     browserLabel->setWordWrap(false);
0094     browserLabel->setText(i18nc("@label", "Open in Browser:"));
0095     d->openInBrowser           = new QComboBox(main);
0096     d->openInBrowser->addItem(i18nc("@item: open in browser", "None"),                 GalleryConfig::NOBROWSER);
0097     d->openInBrowser->addItem(i18nc("@item: open in browser", "Internal"),             GalleryConfig::INTERNAL);
0098     d->openInBrowser->addItem(i18nc("@item: open in browser", "Default from Desktop"), GalleryConfig::DESKTOP);
0099     d->openInBrowser->setEditable(false);
0100     browserLabel->setBuddy(d->openInBrowser);
0101 
0102     // --------------------
0103 
0104     QGridLayout* const grid = new QGridLayout(main);
0105     grid->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0106                           QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0107     grid->addWidget(d->titleLabel,          0, 0, 1, 1);
0108     grid->addWidget(d->imageSelectionTitle, 0, 1, 1, 1);
0109     grid->addWidget(textLabel1,             1, 0, 1, 1);
0110     grid->addWidget(d->destUrl,             1, 1, 1, 1);
0111     grid->addWidget(browserLabel,           2, 0, 1, 1);
0112     grid->addWidget(d->openInBrowser,       2, 1, 1, 1);
0113     grid->setRowStretch(3, 10);
0114 
0115     // --------------------
0116 
0117     setPageWidget(main);
0118     setLeftBottomPix(QIcon::fromTheme(QLatin1String("folder-html")));
0119 
0120     connect(d->destUrl->lineEdit(), SIGNAL(textEdited(QString)),
0121             this, SIGNAL(completeChanged()));
0122 
0123     connect(d->destUrl, SIGNAL(signalUrlSelected(QUrl)),
0124             this, SIGNAL(completeChanged()));
0125 
0126     connect(d->imageSelectionTitle, SIGNAL(textEdited(QString)),
0127             this, SIGNAL(completeChanged()));
0128 }
0129 
0130 HTMLOutputPage::~HTMLOutputPage()
0131 {
0132     delete d;
0133 }
0134 
0135 void HTMLOutputPage::initializePage()
0136 {
0137     HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant());
0138 
0139     if (!wizard)
0140     {
0141         return;
0142     }
0143 
0144     GalleryInfo* const info  = wizard->galleryInfo();
0145 
0146     d->destUrl->setFileDlgPath(info->destUrl().toLocalFile());
0147     d->openInBrowser->setCurrentIndex(info->openInBrowser());
0148     d->imageSelectionTitle->setText(info->imageSelectionTitle());
0149 
0150     d->titleLabel->setVisible(info->m_getOption == GalleryInfo::IMAGES);
0151     d->imageSelectionTitle->setVisible(info->m_getOption == GalleryInfo::IMAGES);
0152 }
0153 
0154 bool HTMLOutputPage::validatePage()
0155 {
0156     if (d->destUrl->fileDlgPath().isEmpty())
0157     {
0158         return false;
0159     }
0160 
0161     HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant());
0162 
0163     if (!wizard)
0164     {
0165         return false;
0166     }
0167 
0168     GalleryInfo* const info  = wizard->galleryInfo();
0169 
0170     if (info->m_getOption == GalleryInfo::IMAGES && d->imageSelectionTitle->text().isEmpty())
0171     {
0172         return false;
0173     }
0174 
0175     info->setDestUrl(QUrl::fromLocalFile(d->destUrl->fileDlgPath()));
0176     info->setOpenInBrowser(d->openInBrowser->currentIndex());
0177     info->setImageSelectionTitle(d->imageSelectionTitle->text());
0178 
0179     return true;
0180 }
0181 
0182 bool HTMLOutputPage::isComplete() const
0183 {
0184     HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant());
0185 
0186     if (!wizard)
0187     {
0188         return false;
0189     }
0190 
0191     GalleryInfo* const info  = wizard->galleryInfo();
0192 
0193     bool b                   = !d->destUrl->fileDlgPath().isEmpty();
0194 
0195     if (info->m_getOption == GalleryInfo::IMAGES)
0196     {
0197         b = (b && !d->imageSelectionTitle->text().isEmpty());
0198     }
0199 
0200     return b;
0201 }
0202 
0203 } // namespace DigikamGenericHtmlGalleryPlugin
0204 
0205 #include "moc_htmloutputpage.cpp"