pineapple-pictures/app/main.cpp

73 lines
2.3 KiB
C++
Raw Normal View History

// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
//
// SPDX-License-Identifier: MIT
2019-09-28 01:18:08 +08:00
#include "mainwindow.h"
#include "playlistmanager.h"
#include "settings.h"
2019-09-28 01:18:08 +08:00
#include <QApplication>
#include <QCommandLineParser>
2020-01-05 14:30:33 +08:00
#include <QDir>
#include <QTranslator>
#include <QUrl>
2019-09-28 01:18:08 +08:00
2020-01-05 15:22:47 +08:00
// QM_FILE_INSTALL_DIR should be defined from the CMakeLists file.
#ifndef QM_FILE_INSTALL_DIR
#define QM_FILE_INSTALL_DIR ":/i18n/"
#endif // QM_FILE_INSTALL_DIR
2019-09-28 01:18:08 +08:00
int main(int argc, char *argv[])
{
2024-10-22 21:35:50 +08:00
QCoreApplication::setApplicationName("Pineapple Pictures");
QCoreApplication::setApplicationVersion(PPIC_VERSION_STRING);
2024-10-27 13:49:24 +08:00
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Settings::instance()->hiDpiScaleFactorBehavior());
QApplication a(argc, argv);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
a.setAttribute(Qt::ApplicationAttribute::AA_UseHighDpiPixmaps);
#endif
2019-09-29 23:53:29 +08:00
QTranslator translator;
2020-01-05 14:30:33 +08:00
QString qmDir;
#ifdef _WIN32
qmDir = QDir(QCoreApplication::applicationDirPath()).absoluteFilePath("translations");
#else
2020-01-05 15:22:47 +08:00
qmDir = QT_STRINGIFY(QM_FILE_INSTALL_DIR);
2020-01-05 14:30:33 +08:00
#endif
if (translator.load(QLocale(), QLatin1String("PineapplePictures"), QLatin1String("_"), qmDir)) {
2024-10-22 21:35:50 +08:00
QCoreApplication::installTranslator(&translator);
}
2024-10-22 21:35:50 +08:00
QGuiApplication::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);
}
2019-09-28 01:18:08 +08:00
MainWindow w;
w.show();
QStringList urlStrList = parser.positionalArguments();
QList<QUrl> && urlList = PlaylistManager::convertToUrlList(urlStrList);
if (!urlList.isEmpty()) {
w.showUrls(urlList);
}
w.initWindowSize();
2024-10-22 21:35:50 +08:00
return QApplication::exec();
2019-09-28 01:18:08 +08:00
}