File indexing completed on 2025-03-09 03:52:03

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2017-05-25
0007  * Description : a tool to generate video slideshow from images.
0008  *
0009  * SPDX-FileCopyrightText: 2017-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 "vidslidefinalpage.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 #include <QTextBrowser>
0029 
0030 // KDE includes
0031 
0032 #include <klocalizedstring.h>
0033 
0034 // Local includes
0035 
0036 #include "vidslidewizard.h"
0037 #include "dlayoutbox.h"
0038 #include "digikam_debug.h"
0039 #include "dprogresswdg.h"
0040 #include "dhistoryview.h"
0041 #include "vidslidethread.h"
0042 
0043 #ifdef HAVE_MEDIAPLAYER
0044 
0045 #   include "vidplayerdlg.h"
0046 
0047 #endif
0048 
0049 namespace DigikamGenericVideoSlideShowPlugin
0050 {
0051 
0052 class Q_DECL_HIDDEN VidSlideFinalPage::Private
0053 {
0054 public:
0055 
0056     explicit Private(QWizard* const dialog)
0057     {
0058         wizard = dynamic_cast<VidSlideWizard*>(dialog);
0059 
0060         if (wizard)
0061         {
0062             settings = wizard->settings();
0063         }
0064     }
0065 
0066     DHistoryView*     progressView = nullptr;
0067     DProgressWdg*     progressBar  = nullptr;
0068     bool              complete     = false;
0069     VidSlideThread*   encoder      = nullptr;
0070     VidSlideWizard*   wizard       = nullptr;
0071     VidSlideSettings* settings     = nullptr;
0072     QTextBrowser*     detailsText  = nullptr;
0073 };
0074 
0075 VidSlideFinalPage::VidSlideFinalPage(QWizard* const dialog, const QString& title)
0076     : DWizardPage(dialog, title),
0077       d          (new Private(dialog))
0078 {
0079     setObjectName(QLatin1String("FinalPage"));
0080 
0081     DVBox* const vbox = new DVBox(this);
0082     d->progressView   = new DHistoryView(vbox);
0083     d->detailsText    = new QTextBrowser(vbox);
0084     d->detailsText->hide();
0085     d->progressBar    = new DProgressWdg(vbox);
0086 
0087     vbox->setStretchFactor(d->progressBar, 10);
0088     vbox->setContentsMargins(QMargins());
0089     vbox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0090                           QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing)));
0091 
0092     setPageWidget(vbox);
0093     setLeftBottomPix(QIcon::fromTheme(QLatin1String("system-run")));
0094 }
0095 
0096 VidSlideFinalPage::~VidSlideFinalPage()
0097 {
0098     if (d->encoder)
0099     {
0100         d->encoder->cancel();
0101     }
0102 
0103     delete d;
0104 }
0105 
0106 void VidSlideFinalPage::initializePage()
0107 {
0108     d->complete = false;
0109     d->detailsText->hide();
0110 
0111     Q_EMIT completeChanged();
0112 
0113     QTimer::singleShot(0, this, SLOT(slotProcess()));
0114 }
0115 
0116 void VidSlideFinalPage::slotProcess()
0117 {
0118     if (!d->wizard)
0119     {
0120         d->progressView->addEntry(i18n("Internal Error"),
0121                                   DHistoryView::ErrorEntry);
0122         return;
0123     }
0124 
0125     d->progressView->clear();
0126     d->progressBar->reset();
0127 
0128     d->progressView->addEntry(i18n("Starting to generate video slideshow..."),
0129                               DHistoryView::ProgressEntry);
0130 
0131     d->progressView->addEntry(i18n("%1 input images to process", d->settings->inputImages.count()),
0132                                   DHistoryView::ProgressEntry);
0133 
0134     d->progressBar->setMinimum(0);
0135 
0136     // NOTE: last stage is FFmpeg encoding.
0137     d->progressBar->setMaximum(d->settings->inputImages.count() + 1);
0138 
0139     d->encoder = new VidSlideThread(this);
0140 
0141     connect(d->encoder, SIGNAL(signalProgress(int)),
0142             d->progressBar, SLOT(setValue(int)));
0143 
0144     connect(d->encoder, SIGNAL(signalMessage(QString,bool)),
0145             this, SLOT(slotMessage(QString,bool)));
0146 
0147     connect(d->encoder, SIGNAL(signalDone(bool)),
0148             this, SLOT(slotDone(bool)));
0149 
0150     d->encoder->prepareFrames(d->settings);
0151     d->encoder->start();
0152 }
0153 
0154 void VidSlideFinalPage::cleanupPage()
0155 {
0156     d->detailsText->clear();
0157     d->detailsText->hide();
0158 
0159     if (d->encoder)
0160     {
0161         d->encoder->cancel();
0162     }
0163 }
0164 
0165 void VidSlideFinalPage::slotMessage(const QString& mess, bool err)
0166 {
0167     d->progressView->addEntry(mess, err ? DHistoryView::ErrorEntry
0168                                         : DHistoryView::ProgressEntry);
0169 }
0170 
0171 void VidSlideFinalPage::slotDone(bool completed)
0172 {
0173     d->progressBar->setValue(d->progressBar->maximum());
0174     d->progressBar->progressCompleted();
0175     d->complete = completed;
0176 
0177     if (!d->complete)
0178     {
0179         d->progressView->addEntry(i18n("Video Slideshow is not completed"),
0180                                   DHistoryView::WarningEntry);
0181 
0182         d->detailsText->show();
0183         d->detailsText->setText(d->encoder->encodingTraces());
0184         d->progressView->addEntry(i18n("See the video encoding trace below"),
0185                                   DHistoryView::WarningEntry);
0186     }
0187     else
0188     {
0189         d->progressView->addEntry(i18n("Video Slideshow completed."),
0190                                   DHistoryView::ProgressEntry);
0191 
0192         if (d->settings->outputPlayer != VidSlideSettings::NOPLAYER)
0193         {
0194             d->progressView->addEntry(i18n("Opening video stream in player..."),
0195                                       DHistoryView::ProgressEntry);
0196 
0197 #ifdef HAVE_MEDIAPLAYER
0198 
0199             if (d->settings->outputPlayer == VidSlideSettings::INTERNAL)
0200             {
0201 
0202 
0203                 VidPlayerDlg* const player = new VidPlayerDlg(d->settings->outputFile, this);
0204                 player->show();
0205                 player->resize(800, 600);
0206 
0207 
0208             }
0209             else
0210 
0211 #endif
0212             {
0213                 QDesktopServices::openUrl(QUrl::fromLocalFile(d->settings->outputFile));
0214             }
0215         }
0216     }
0217 
0218     Q_EMIT completeChanged();
0219 }
0220 
0221 bool VidSlideFinalPage::isComplete() const
0222 {
0223     return d->complete;
0224 }
0225 
0226 } // namespace DigikamGenericVideoSlideShowPlugin
0227 
0228 #include "moc_vidslidefinalpage.cpp"