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 "htmlfinalpage.h"
0016 
0017 // Qt includes
0018 
0019 #include <QIcon>
0020 #include <QSpacerItem>
0021 #include <QVBoxLayout>
0022 #include <QDesktopServices>
0023 #include <QUrl>
0024 #include <QApplication>
0025 #include <QStyle>
0026 #include <QTimer>
0027 #include <QDir>
0028 
0029 // KDE includes
0030 
0031 #include <klocalizedstring.h>
0032 
0033 // Local includes
0034 
0035 #include "digikam_debug.h"
0036 #include "abstractthemeparameter.h"
0037 #include "gallerygenerator.h"
0038 #include "webbrowserdlg.h"
0039 #include "dprogresswdg.h"
0040 #include "dhistoryview.h"
0041 #include "galleryinfo.h"
0042 #include "htmlwizard.h"
0043 #include "dlayoutbox.h"
0044 
0045 namespace DigikamGenericHtmlGalleryPlugin
0046 {
0047 
0048 class Q_DECL_HIDDEN HTMLFinalPage::Private
0049 {
0050 public:
0051 
0052     explicit Private()
0053       : progressView(nullptr),
0054         progressBar (nullptr),
0055         complete    (false)
0056     {
0057     }
0058 
0059     DHistoryView* progressView;
0060     DProgressWdg* progressBar;
0061     bool          complete;
0062 };
0063 
0064 HTMLFinalPage::HTMLFinalPage(QWizard* const dialog, const QString& title)
0065     : DWizardPage(dialog, title),
0066       d          (new Private)
0067 {
0068     setObjectName(QLatin1String("FinalPage"));
0069 
0070     DVBox* const vbox = new DVBox(this);
0071     d->progressView   = new DHistoryView(vbox);
0072     d->progressBar    = new DProgressWdg(vbox);
0073 
0074     vbox->setStretchFactor(d->progressBar, 10);
0075     vbox->setContentsMargins(QMargins());
0076     vbox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0077                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0078 
0079     setPageWidget(vbox);
0080     setLeftBottomPix(QIcon::fromTheme(QLatin1String("system-run")));
0081 }
0082 
0083 HTMLFinalPage::~HTMLFinalPage()
0084 {
0085     delete d;
0086 }
0087 
0088 void HTMLFinalPage::initializePage()
0089 {
0090     d->complete = false;
0091     Q_EMIT completeChanged();
0092     QTimer::singleShot(0, this, SLOT(slotProcess()));
0093 }
0094 
0095 void HTMLFinalPage::slotProcess()
0096 {
0097     HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant());
0098 
0099     if (!wizard)
0100     {
0101         d->progressView->addEntry(i18n("Internal Error"),
0102                                   DHistoryView::ErrorEntry);
0103         return;
0104     }
0105 
0106     d->progressView->clear();
0107     d->progressBar->reset();
0108 
0109     GalleryInfo* const info  = wizard->galleryInfo();
0110 
0111     // Generate GalleryInfo
0112 
0113     qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << info;
0114 
0115     d->progressView->addEntry(i18n("Starting to generate gallery..."),
0116                               DHistoryView::ProgressEntry);
0117 
0118     if (info->m_getOption == GalleryInfo::ALBUMS)
0119     {
0120         if (!info->m_iface)
0121         {
0122             return;
0123         }
0124 
0125         d->progressView->addEntry(i18n("%1 albums to process:", info->m_albumList.count()),
0126                                   DHistoryView::ProgressEntry);
0127 
0128         Q_FOREACH (const QUrl& url, info->m_iface->albumsItems(info->m_albumList))
0129         {
0130             d->progressView->addEntry(QDir::toNativeSeparators(url.toLocalFile()),
0131                                       DHistoryView::ProgressEntry);
0132         }
0133     }
0134     else
0135     {
0136         d->progressView->addEntry(i18n("%1 items to process", info->m_imageList.count()),
0137                                   DHistoryView::ProgressEntry);
0138     }
0139 
0140     d->progressView->addEntry(i18n("Output directory: %1",
0141                               QDir::toNativeSeparators(info->destUrl().toLocalFile())),
0142                               DHistoryView::ProgressEntry);
0143 
0144     GalleryGenerator generator(info);
0145     generator.setProgressWidgets(d->progressView, d->progressBar);
0146 
0147     if (!generator.run())
0148     {
0149         return;
0150     }
0151 
0152     if (generator.warnings())
0153     {
0154         d->progressView->addEntry(i18n("Gallery is completed, but some warnings occurred."),
0155                                   DHistoryView::WarningEntry);
0156     }
0157     else
0158     {
0159         d->progressView->addEntry(i18n("Gallery completed."),
0160                                   DHistoryView::ProgressEntry);
0161     }
0162 
0163     QUrl url = info->destUrl().adjusted(QUrl::StripTrailingSlash);
0164     url.setPath(url.path() + QLatin1String("/index.html"));
0165 
0166     switch (info->openInBrowser())
0167     {
0168         case GalleryConfig::DESKTOP:
0169         {
0170             QDesktopServices::openUrl(url);
0171             d->progressView->addEntry(i18n("Opening gallery with default desktop browser..."),
0172                                       DHistoryView::ProgressEntry);
0173             break;
0174         }
0175 
0176         case GalleryConfig::INTERNAL:
0177         {
0178             WebBrowserDlg* const browser = new WebBrowserDlg(url, this);
0179             browser->show();
0180             d->progressView->addEntry(i18n("Opening gallery with internal browser..."),
0181                                       DHistoryView::ProgressEntry);
0182             break;
0183         }
0184 
0185         default:
0186         {
0187             break;
0188         }
0189     }
0190 
0191     d->complete = true;
0192     Q_EMIT completeChanged();
0193 }
0194 
0195 bool HTMLFinalPage::isComplete() const
0196 {
0197     return d->complete;
0198 }
0199 
0200 } // namespace DigikamGenericHtmlGalleryPlugin
0201 
0202 #include "moc_htmlfinalpage.cpp"