2022-06-19 16:17:38 +08:00
// SPDX-FileCopyrightText: 2022 Gary Wang <wzc782970009@gmail.com>
//
// SPDX-License-Identifier: MIT
2019-09-28 01:18:08 +08:00
# include "mainwindow.h"
2021-02-09 14:19:09 +08:00
# include "playlistmanager.h"
2023-07-10 01:07:01 +08:00
# include "settings.h"
2021-02-09 14:19:09 +08:00
2019-09-28 01:18:08 +08:00
# include <QApplication>
2019-10-01 10:37:14 +08:00
# include <QCommandLineParser>
2020-01-05 14:30:33 +08:00
# include <QDir>
2019-10-06 17:31:27 +08:00
# include <QTranslator>
2019-10-01 10:37:14 +08:00
# 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 [ ] )
{
2023-07-10 01:07:01 +08:00
QGuiApplication : : setHighDpiScaleFactorRoundingPolicy ( Settings : : instance ( ) - > hiDpiScaleFactorBehavior ( ) ) ;
2019-09-28 01:18:08 +08:00
QApplication a ( argc , argv ) ;
2022-09-29 13:11:21 +08:00
# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
a . setAttribute ( Qt : : ApplicationAttribute : : AA_UseHighDpiPixmaps ) ;
# endif
2019-09-29 23:53:29 +08:00
2019-10-06 17:31:27 +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
2023-08-26 23:39:34 +08:00
if ( translator . load ( QLocale ( ) , QLatin1String ( " PineapplePictures " ) , QLatin1String ( " _ " ) , qmDir ) ) {
2020-12-25 13:36:34 +08:00
a . installTranslator ( & translator ) ;
}
2020-07-21 20:47:06 +08:00
a . setApplicationName ( " Pineapple Pictures " ) ;
a . setApplicationDisplayName ( QCoreApplication : : translate ( " main " , " Pineapple Pictures " ) ) ;
2019-10-06 17:31:27 +08:00
2024-07-28 16:16:20 +08:00
// commandline options
QCommandLineOption supportedImageFormats ( QStringLiteral ( " supported-image-formats " ) , QCoreApplication : : translate ( " main " , " List supported image format suffixes, and quit program. " ) ) ;
2019-10-01 10:37:14 +08:00
// parse commandline arguments
QCommandLineParser parser ;
2024-07-28 16:16:20 +08:00
parser . addOption ( supportedImageFormats ) ;
2019-10-01 10:37:14 +08:00
parser . addPositionalArgument ( " File list " , QCoreApplication : : translate ( " main " , " File list. " ) ) ;
2019-10-06 17:31:27 +08:00
parser . addHelpOption ( ) ;
2019-10-01 10:37:14 +08:00
parser . process ( a ) ;
2024-07-28 16:16:20 +08:00
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 ( ) ;
2021-02-26 00:57:12 +08:00
QStringList urlStrList = parser . positionalArguments ( ) ;
QList < QUrl > & & urlList = PlaylistManager : : convertToUrlList ( urlStrList ) ;
2019-10-01 10:37:14 +08:00
if ( ! urlList . isEmpty ( ) ) {
w . showUrls ( urlList ) ;
}
2022-03-11 16:21:56 +08:00
w . initWindowSize ( ) ;
2019-09-28 01:18:08 +08:00
return a . exec ( ) ;
}