Skip to content

Commit

Permalink
feat: cli argument to list supported image formats
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Jul 28, 2024
1 parent cd01a05 commit a6e31a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
9 changes: 8 additions & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
20 changes: 14 additions & 6 deletions app/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions app/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class MainWindow : public FramelessWindow
void galleryNext();
void galleryCurrent();

static QStringList supportedImageFormats();

protected slots:
void showEvent(QShowEvent *event) override;
void enterEvent(QT_ENTER_EVENT *event) override;
Expand Down

0 comments on commit a6e31a2

Please sign in to comment.