diff --git a/app/main.cpp b/app/main.cpp index 5fcd4dd..05c03b2 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -40,13 +40,20 @@ int main(int argc, char *argv[]) a.setApplicationName("Pineapple Pictures"); a.setApplicationDisplayName(QCoreApplication::translate("main", "Pineapple Pictures")); + // commandline options + QCommandLineOption supportedImageFormats(QStringLiteral("supported-image-formats"), QCoreApplication::translate("main", "List supported image format suffixes, and quit program.")); // parse commandline arguments QCommandLineParser parser; + parser.addOption(supportedImageFormats); parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list.")); parser.addHelpOption(); - parser.process(a); + if (parser.isSet(supportedImageFormats)) { + fputs(qPrintable(MainWindow::supportedImageFormats().join(QChar('\n'))), stdout); + ::exit(EXIT_SUCCESS); + } + MainWindow w; w.show(); diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp index 80ac900..363d5b6 100644 --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -57,12 +57,7 @@ MainWindow::MainWindow(QWidget *parent) this->setWindowIcon(QIcon(":/icons/app-icon.svg")); this->setMouseTracking(true); - // related to jfif: https://codereview.qt-project.org/c/qt/qtbase/+/577730 - QStringList formatFilters{ QStringLiteral("*.jfif") }; - for (const QByteArray &item : QImageReader::supportedImageFormats()) { - formatFilters.append(QStringLiteral("*.") % QString::fromLocal8Bit(item)); - } - m_pm->setAutoLoadFilterSuffixes(formatFilters); + m_pm->setAutoLoadFilterSuffixes(supportedImageFormats()); m_fadeOutAnimation = new QPropertyAnimation(this, "windowOpacity"); m_fadeOutAnimation->setDuration(300); @@ -278,6 +273,19 @@ void MainWindow::galleryCurrent() } } +QStringList MainWindow::supportedImageFormats() +{ + QStringList formatFilters { +#if QT_VERSION < QT_VERSION_CHECK(6, 8, 0) + QStringLiteral("*.jfif") +#endif // QT_VERSION < QT_VERSION_CHECK(6, 8, 0) + }; + for (const QByteArray &item : QImageReader::supportedImageFormats()) { + formatFilters.append(QStringLiteral("*.") % QString::fromLocal8Bit(item)); + } + return formatFilters; +} + void MainWindow::showEvent(QShowEvent *event) { updateWidgetsPosition(); diff --git a/app/mainwindow.h b/app/mainwindow.h index 528f929..7a0c842 100644 --- a/app/mainwindow.h +++ b/app/mainwindow.h @@ -47,6 +47,8 @@ public: void galleryNext(); void galleryCurrent(); + static QStringList supportedImageFormats(); + protected slots: void showEvent(QShowEvent *event) override; void enterEvent(QT_ENTER_EVENT *event) override;