File indexing completed on 2024-04-28 15:40:12

0001 // SPDX-FileCopyrightText: 2003-2020 The KPhotoAlbum Development Team
0002 // SPDX-FileCopyrightText: 2021 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0003 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0004 //
0005 // SPDX-License-Identifier: GPL-2.0-or-later
0006 
0007 #include "FeatureDialog.h"
0008 #include <config-kpa-videobackends.h>
0009 
0010 #include <kpabase/config-kpa-marble.h>
0011 #include <kpabase/config-kpa-plugins.h>
0012 #include <kpaexif/Database.h>
0013 
0014 #include <KLocalizedString>
0015 #include <QDialogButtonBox>
0016 #include <QLayout>
0017 #include <QList>
0018 #include <QProcess>
0019 #include <QPushButton>
0020 #include <QStandardPaths>
0021 #include <QTextBrowser>
0022 #include <QVBoxLayout>
0023 
0024 using namespace MainWindow;
0025 
0026 FeatureDialog::FeatureDialog(QWidget *parent)
0027     : QDialog(parent)
0028 {
0029     setWindowTitle(i18nc("@title:window", "Feature Status"));
0030 
0031     QTextBrowser *browser = new QTextBrowser(this);
0032 
0033     QString text = i18n("<h1>Overview</h1>"
0034                         "<p>Below you may see the list of compile- and runtime features KPhotoAlbum has, and their status:</p>"
0035                         "%1",
0036                         featureString());
0037     text += i18n("<h1>What can I do if I miss a feature?</h1>"
0038 
0039                  "<p>If you compiled KPhotoAlbum yourself, then please review the sections below to learn what to install "
0040                  "to get the feature in question. If on the other hand you installed KPhotoAlbum from a binary package, please tell "
0041                  "whoever made the package about this defect, eventually including the information from the section below.</p>"
0042 
0043                  "<p>In case you are missing a feature and you did not compile KPhotoAlbum yourself, please do consider doing so. "
0044                  "It really is not that hard. If you need help compiling KPhotoAlbum, feel free to ask on the "
0045                  "<a href=\"https://mail.kde.org/cgi-bin/mailman/listinfo/kphotoalbum\">KPhotoAlbum mailing list</a></p>"
0046 
0047                  "<p>The steps to compile KPhotoAlbum can be seen on <a href=\"https://community.kde.org/KPhotoAlbum/build_instructions\">"
0048                  "the KPhotoAlbum home page</a>. If you have never compiled a KDE application, then please ensure that "
0049                  "you have the developer packages installed, in most distributions they go under names like kdelibs<i>-devel</i></p>");
0050 
0051     text += i18n("<h1><a name=\"purpose\">Plugin support</a></h1>"
0052                  "<p>KPhotoAlbum supports the <em>Purpose</em> plugin system.</p>");
0053 
0054     text += i18n("<h1><a name=\"database\">SQLite database support</a></h1>"
0055                  "<p>KPhotoAlbum allows you to search using a certain number of Exif tags. For this KPhotoAlbum "
0056                  "needs an SQLite database. "
0057                  "In addition the Qt package for SQLite (e.g. qt-sql-sqlite) must be installed.</p>");
0058 
0059     text += i18n("<h1><a name=\"geomap\">Map view for geotagged images</a></h1>"
0060                  "<p>If KPhotoAlbum has been built with support for Marble, "
0061                  "KPhotoAlbum can show images with GPS information on a map."
0062                  "</p>");
0063 
0064     text += i18n("<h1><a name=\"video\">Video support</a></h1>"
0065                  "<p>KPhotoAlbum relies on QtAv for displaying videos; this in turn relies on ffmpeg</p>");
0066 
0067     text += i18n("<h1><a name=\"videoPreview\">Video thumbnail support</a></h1>"
0068                  "<p>KPhotoAlbum can use <tt>ffmpeg</tt> to extract thumbnails from videos. These thumbnails are used to preview "
0069                  "videos in the thumbnail viewer.</p>");
0070 
0071     text += i18n("<h1><a name=\"videoInfo\">Video metadata support</a></h1>"
0072                  "<p>KPhotoAlbum can use <tt>ffprobe</tt> to extract length information from videos."
0073                  "</p>"
0074                  "<p>Correct length information is necessary for correct rendering of video thumbnails.</p>");
0075 
0076     browser->setText(text);
0077 
0078     QVBoxLayout *layout = new QVBoxLayout;
0079     layout->addWidget(browser);
0080     this->setLayout(layout);
0081 
0082     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok);
0083     buttonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::CTRL | Qt::Key_Return);
0084     layout->addWidget(buttonBox);
0085 
0086     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0087 }
0088 
0089 QSize FeatureDialog::sizeHint() const
0090 {
0091     return QSize(800, 600);
0092 }
0093 
0094 bool MainWindow::FeatureDialog::hasPurposeSupport()
0095 {
0096 #ifdef KF5Purpose_FOUND
0097     return true;
0098 #else
0099     return false;
0100 #endif
0101 }
0102 
0103 bool MainWindow::FeatureDialog::hasEXIV2DBSupport()
0104 {
0105     return Exif::Database::isAvailable();
0106 }
0107 
0108 bool MainWindow::FeatureDialog::hasGeoMapSupport()
0109 {
0110 #ifdef HAVE_MARBLE
0111     return true;
0112 #else
0113     return false;
0114 #endif
0115 }
0116 
0117 QString FeatureDialog::ffmpegBinary()
0118 {
0119     QString ffmpeg = QStandardPaths::findExecutable(QString::fromLatin1("ffmpeg"));
0120     return ffmpeg;
0121 }
0122 
0123 QString FeatureDialog::ffprobeBinary()
0124 {
0125     QString ffprobe = QStandardPaths::findExecutable(QString::fromLatin1("ffprobe"));
0126     return ffprobe;
0127 }
0128 
0129 bool FeatureDialog::hasVideoThumbnailer()
0130 {
0131     return !ffmpegBinary().isEmpty();
0132 }
0133 
0134 bool FeatureDialog::hasVideoProber()
0135 {
0136     return !ffprobeBinary().isEmpty();
0137 }
0138 
0139 bool MainWindow::FeatureDialog::hasAllFeaturesAvailable()
0140 {
0141     // Only answer those that are compile time tests, otherwise we will pay a penalty each time we start up.
0142     return hasPurposeSupport() && hasEXIV2DBSupport() && hasGeoMapSupport() && hasVideoThumbnailer() && hasVideoProber();
0143 }
0144 
0145 struct Data {
0146     Data() { }
0147     Data(const QString &title, const QString &tag, bool featureFound)
0148         : title(title)
0149         , tag(tag)
0150         , featureFound(featureFound)
0151     {
0152     }
0153     QString title;
0154     QString tag;
0155     bool featureFound = false;
0156 };
0157 
0158 QString MainWindow::FeatureDialog::featureString()
0159 {
0160     QList<Data> features;
0161     features << Data(i18n("Plug-ins available"), QString::fromLatin1("#purpose"), hasPurposeSupport());
0162     features << Data(i18n("SQLite database support (used for Exif searches)"), QString::fromLatin1("#database"), hasEXIV2DBSupport());
0163     features << Data(i18n("Map view for geotagged images."), QString::fromLatin1("#geomap"), hasGeoMapSupport());
0164     features << Data(i18n("Video thumbnail support"), QString::fromLatin1("#videoPreview"), hasVideoThumbnailer());
0165     features << Data(i18n("Video metadata support"), QString::fromLatin1("#videoInfo"), hasVideoProber());
0166 
0167     QString result = QString::fromLatin1("<p><table>");
0168     const QString red = QString::fromLatin1("<font color=\"red\">%1</font>");
0169     const QString yes = i18nc("Feature available", "Yes");
0170     const QString no = red.arg(i18nc("Feature not available", "No"));
0171     const QString formatString = QString::fromLatin1("<tr><td><a href=\"%1\">%2</a></td><td><b>%3</b></td></tr>");
0172     for (QList<Data>::ConstIterator featureIt = features.constBegin(); featureIt != features.constEnd(); ++featureIt) {
0173         result += formatString.arg((*featureIt).tag, (*featureIt).title, (*featureIt).featureFound ? yes : no);
0174     }
0175     result += QString::fromLatin1("</table></p>");
0176 
0177     return result;
0178 }
0179 
0180 // vi:expandtab:tabstop=4 shiftwidth=4:
0181 
0182 #include "moc_FeatureDialog.cpp"