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: 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 "htmlselectionpage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QIcon>
0020 #include <QPixmap>
0021 #include <QStackedWidget>
0022 
0023 // Local includes
0024 
0025 #include "htmlwizard.h"
0026 #include "galleryinfo.h"
0027 #include "ditemslist.h"
0028 
0029 namespace DigikamGenericHtmlGalleryPlugin
0030 {
0031 
0032 class Q_DECL_HIDDEN HTMLSelectionPage::Private
0033 {
0034 public:
0035 
0036     explicit Private(QWizard* const dialog)
0037       : albumSupport    (false),
0038         albumSelector   (nullptr),
0039         imageList       (nullptr),
0040         stack           (nullptr),
0041         wizard          (nullptr),
0042         info            (nullptr),
0043         iface           (nullptr)
0044     {
0045         wizard = dynamic_cast<HTMLWizard*>(dialog);
0046 
0047         if (wizard)
0048         {
0049             info  = wizard->galleryInfo();
0050             iface = info->m_iface;
0051         }
0052     }
0053 
0054     bool             albumSupport;
0055     QWidget*         albumSelector;
0056     DItemsList*      imageList;
0057     QStackedWidget*  stack;
0058     HTMLWizard*      wizard;
0059     GalleryInfo*     info;
0060     DInfoInterface*  iface;
0061 };
0062 
0063 HTMLSelectionPage::HTMLSelectionPage(QWizard* const dialog, const QString& title)
0064     : DWizardPage(dialog, title),
0065       d          (new Private(dialog))
0066 {
0067     setObjectName(QLatin1String("AlbumSelectorPage"));
0068 
0069     d->stack              = new QStackedWidget(this);
0070     d->albumSupport       = (d->iface && d->iface->supportAlbums());
0071 
0072     if (d->albumSupport)
0073     {
0074         d->albumSelector = d->iface->albumChooser(this);
0075     }
0076     else
0077     {
0078         d->albumSelector = new QWidget(this);
0079     }
0080 
0081     d->stack->insertWidget(GalleryInfo::ALBUMS, d->albumSelector);
0082 
0083     d->imageList          = new DItemsList(this);
0084     d->imageList->setObjectName(QLatin1String("HTMLGalleries ImagesList"));
0085     d->imageList->setControlButtonsPlacement(DItemsList::ControlButtonsBelow);
0086     d->stack->insertWidget(GalleryInfo::IMAGES, d->imageList);
0087 
0088     setPageWidget(d->stack);
0089     setLeftBottomPix(QIcon::fromTheme(QLatin1String("folder-pictures")));
0090 
0091     if (d->albumSupport)
0092     {
0093         connect(d->iface, SIGNAL(signalAlbumChooserSelectionChanged()),
0094                 this, SIGNAL(completeChanged()));
0095     }
0096 
0097     connect(d->imageList, SIGNAL(signalImageListChanged()),
0098             this, SIGNAL(completeChanged()));
0099 }
0100 
0101 HTMLSelectionPage::~HTMLSelectionPage()
0102 {
0103     delete d;
0104 }
0105 
0106 
0107 void HTMLSelectionPage::setItemsList(const QList<QUrl>& urls)
0108 {
0109     d->imageList->slotAddImages(urls);
0110 }
0111 
0112 void HTMLSelectionPage::initializePage()
0113 {
0114     d->imageList->setIface(d->iface);
0115 
0116     if (d->info->m_getOption == GalleryInfo::IMAGES)
0117     {
0118         d->imageList->loadImagesFromCurrentSelection();
0119     }
0120 
0121     d->stack->setCurrentIndex(d->info->m_getOption);
0122 }
0123 
0124 bool HTMLSelectionPage::validatePage()
0125 {
0126     if (d->stack->currentIndex() == GalleryInfo::ALBUMS)
0127     {
0128         if (d->albumSupport)
0129         {
0130             if (d->iface->albumChooserItems().isEmpty())
0131                 return false;
0132 
0133             d->info->m_albumList = d->iface->albumChooserItems();
0134         }
0135         else
0136         {
0137             return false;
0138         }
0139     }
0140     else
0141     {
0142         if (d->imageList->imageUrls().isEmpty())
0143         {
0144             return false;
0145         }
0146 
0147         d->info->m_imageList = d->imageList->imageUrls();
0148     }
0149 
0150     return true;
0151 }
0152 
0153 bool HTMLSelectionPage::isComplete() const
0154 {
0155     if (d->stack->currentIndex() == GalleryInfo::ALBUMS)
0156     {
0157         if (!d->albumSupport)
0158         {
0159             return false;
0160         }
0161 
0162         return (!d->iface->albumChooserItems().isEmpty());
0163     }
0164 
0165     return (!d->imageList->imageUrls().isEmpty());
0166 }
0167 
0168 } // namespace DigikamGenericHtmlGalleryPlugin
0169 
0170 #include "moc_htmlselectionpage.cpp"