File indexing completed on 2025-03-09 03:52:04
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 "vidslideintropage.h" 0016 0017 // Qt includes 0018 0019 #include <QLabel> 0020 #include <QPixmap> 0021 #include <QComboBox> 0022 #include <QGroupBox> 0023 #include <QIcon> 0024 #include <QStandardPaths> 0025 #include <QFileInfo> 0026 0027 // KDE includes 0028 0029 #include <klocalizedstring.h> 0030 0031 // Local includes 0032 0033 #include "digikam_debug.h" 0034 #include "dlayoutbox.h" 0035 #include "vidslidewizard.h" 0036 #include "vidslidesettings.h" 0037 #include "ffmpegbinary.h" 0038 #include "ffmpeglauncher.h" 0039 #include "dbinarysearch.h" 0040 0041 namespace DigikamGenericVideoSlideShowPlugin 0042 { 0043 0044 class Q_DECL_HIDDEN VidSlideIntroPage::Private 0045 { 0046 public: 0047 0048 explicit Private(QWizard* const dialog) 0049 { 0050 wizard = dynamic_cast<VidSlideWizard*>(dialog); 0051 0052 if (wizard) 0053 { 0054 settings = wizard->settings(); 0055 } 0056 } 0057 0058 QComboBox* imageGetOption = nullptr; 0059 DHBox* hbox = nullptr; 0060 VidSlideWizard* wizard = nullptr; 0061 VidSlideSettings* settings = nullptr; 0062 FFmpegBinary ffmpegBin; 0063 DBinarySearch* binSearch = nullptr; 0064 }; 0065 0066 VidSlideIntroPage::VidSlideIntroPage(QWizard* const dialog, const QString& title) 0067 : DWizardPage(dialog, title), 0068 d (new Private(dialog)) 0069 { 0070 DVBox* const vbox = new DVBox(this); 0071 QLabel* const desc = new QLabel(vbox); 0072 0073 desc->setWordWrap(true); 0074 desc->setOpenExternalLinks(true); 0075 desc->setText(i18n("<qt>" 0076 "<p><h1><b>Welcome to Video Slideshow tool</b></h1></p>" 0077 "<p>This assistant will guide you to export</p>" 0078 "<p>your images as a video stream.</p>" 0079 "<p>You can generate quickly a " 0080 "<a href='https://en.wikipedia.org/wiki/Time-lapse_photography'>Time-lapse</a> " 0081 "movie from images</p>" 0082 "<p>captured with a tripod mounted camera controlled with an " 0083 "<a href='https://en.wikipedia.org/wiki/Intervalometer#Photography'>intervalometer</a>.</p>" 0084 "<p></p><p>You can also create a video presentation with transition</p>" 0085 "<p>effects and audio tracks to show on a TV screen.</p>" 0086 "</qt>")); 0087 0088 // ComboBox for image selection method 0089 0090 d->hbox = new DHBox(vbox); 0091 QLabel* const getImageLabel = new QLabel(i18n("&Choose image selection method:"), d->hbox); 0092 d->imageGetOption = new QComboBox(d->hbox); 0093 d->imageGetOption->insertItem(VidSlideSettings::ALBUMS, i18n("Albums")); 0094 d->imageGetOption->insertItem(VidSlideSettings::IMAGES, i18n("Images")); 0095 getImageLabel->setBuddy(d->imageGetOption); 0096 0097 // --------------------- 0098 0099 QGroupBox* const binaryBox = new QGroupBox(vbox); 0100 QGridLayout* const binaryLayout = new QGridLayout; 0101 binaryBox->setLayout(binaryLayout); 0102 binaryBox->setTitle(i18nc("@title:group", "FFmpeg Binary")); 0103 d->binSearch = new DBinarySearch(binaryBox); 0104 d->binSearch->addBinary(d->ffmpegBin); 0105 0106 Q_FOREACH (const QString& path, d->wizard->settings()->defaultFFmpegSearchPaths()) 0107 { 0108 d->binSearch->addDirectory(path); 0109 } 0110 0111 vbox->setStretchFactor(desc, 2); 0112 vbox->setStretchFactor(d->hbox, 1); 0113 vbox->setStretchFactor(binaryBox, 3); 0114 0115 setPageWidget(vbox); 0116 setLeftBottomPix(QIcon::fromTheme(QLatin1String("view-presentation"))); 0117 } 0118 0119 VidSlideIntroPage::~VidSlideIntroPage() 0120 { 0121 delete d; 0122 } 0123 0124 void VidSlideIntroPage::initializePage() 0125 { 0126 bool albumSupport = (d->settings->iface && d->settings->iface->supportAlbums()); 0127 0128 if (!albumSupport) 0129 { 0130 d->imageGetOption->setCurrentIndex(VidSlideSettings::IMAGES); 0131 d->hbox->setEnabled(false); 0132 } 0133 else 0134 { 0135 d->imageGetOption->setCurrentIndex(d->wizard->settings()->selMode); 0136 } 0137 0138 d->binSearch->allBinariesFound(); 0139 } 0140 0141 bool VidSlideIntroPage::validatePage() 0142 { 0143 d->wizard->settings()->selMode = (VidSlideSettings::Selection)d->imageGetOption->currentIndex(); 0144 0145 if (d->ffmpegBin.isValid()) 0146 { 0147 QString path = d->ffmpegBin.path(); 0148 0149 if (path.isEmpty() || (path == FFmpegBinary::ffmpegToolBin())) 0150 { 0151 0152 #ifdef Q_OS_WIN 0153 0154 QStringList possiblePaths({QLatin1String("C:/Program Files/digiKam"), 0155 QLatin1String("C:/Program Files/digiKam/bin")}); 0156 0157 path = QStandardPaths::findExecutable(FFmpegBinary::ffmpegToolBin(), possiblePaths); 0158 0159 #else 0160 0161 path = QStandardPaths::findExecutable(FFmpegBinary::ffmpegToolBin()); 0162 0163 #endif 0164 0165 } 0166 else if (QFileInfo(path).isDir()) 0167 { 0168 if (!path.endsWith(QLatin1Char('/'))) 0169 { 0170 path.append(QLatin1Char('/')); 0171 } 0172 0173 path.append(FFmpegBinary::ffmpegToolBin()); 0174 } 0175 0176 d->wizard->settings()->ffmpegPath = path; 0177 qCDebug(DIGIKAM_DPLUGIN_GENERIC_LOG) << d->ffmpegBin.directory() << d->ffmpegBin.path(); 0178 0179 FFmpegLauncher ffmpeg(this); 0180 ffmpeg.setSettings(d->wizard->settings()); 0181 d->wizard->settings()->ffmpegCodecs = ffmpeg.supportedCodecs(); 0182 d->wizard->settings()->ffmpegFormats = ffmpeg.supportedFormats(); 0183 0184 return true; 0185 } 0186 0187 return false; 0188 } 0189 0190 } // namespace DigikamGenericVideoSlideShowPlugin 0191 0192 #include "moc_vidslideintropage.cpp"