File indexing completed on 2024-04-28 15:52:01

0001 /*
0002     SPDX-FileCopyrightText: 2002 Wilco Greven <greven@kde.org>
0003     SPDX-FileCopyrightText: 2003 Christophe Devriese <Christophe.Devriese@student.kuleuven.ac.be>
0004     SPDX-FileCopyrightText: 2003 Laurent Montel <montel@kde.org>
0005     SPDX-FileCopyrightText: 2003-2007 Albert Astals Cid <aacid@kde.org>
0006     SPDX-FileCopyrightText: 2004 Andy Goossens <andygoossens@telenet.be>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #include "shell.h"
0012 
0013 #include "aboutdata.h"
0014 #include "okular_main.h"
0015 #include "shellutils.h"
0016 #include <KAboutData>
0017 #include <KCrash>
0018 #include <KLocalizedString>
0019 #include <KMessageBox>
0020 #include <KWindowSystem>
0021 #include <QApplication>
0022 #include <QCommandLineOption>
0023 #include <QCommandLineParser>
0024 #include <QStringList>
0025 #include <QTextStream>
0026 #include <QtGlobal>
0027 
0028 int main(int argc, char **argv)
0029 {
0030     /**
0031      * enable dark mode for title bar on Windows
0032      */
0033 #if defined(Q_OS_WIN)
0034     if (!qEnvironmentVariableIsSet("QT_QPA_PLATFORM")) {
0035         qputenv("QT_QPA_PLATFORM", "windows:darkmode=1");
0036     }
0037 #endif
0038 
0039     /**
0040      * allow fractional scaling
0041      */
0042     QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
0043 
0044     QCoreApplication::setAttribute(Qt::AA_CompressTabletEvents);
0045 
0046     QApplication app(argc, argv);
0047     KLocalizedString::setApplicationDomain("okular");
0048 
0049     /**
0050      * For Windows and macOS: use Breeze if available
0051      * Of all tested styles that works the best for us
0052      */
0053 #if defined(Q_OS_MACOS) || defined(Q_OS_WIN)
0054     QApplication::setStyle(QStringLiteral("breeze"));
0055 #endif
0056 
0057     KAboutData aboutData = okularAboutData();
0058     KAboutData::setApplicationData(aboutData);
0059     // set icon for shells which do not use desktop file metadata
0060     QApplication::setWindowIcon(QIcon::fromTheme(QStringLiteral("okular")));
0061 
0062     KCrash::initialize();
0063 
0064     QCommandLineParser parser;
0065     // The KDE4 version accepted flags such as -unique with a single dash -> preserve compatibility
0066     parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
0067     aboutData.setupCommandLine(&parser);
0068 
0069     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("p") << QStringLiteral("page"), i18n("Page of the document to be shown"), QStringLiteral("number")));
0070     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("presentation"), i18n("Start the document in presentation mode")));
0071     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("print"), i18n("Start with print dialog")));
0072     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("print-and-exit"), i18n("Start with print dialog and exit after printing")));
0073     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("unique"), i18n("\"Unique instance\" control")));
0074     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("noraise"), i18n("Not raise window")));
0075     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("find"), i18n("Find a string on the text"), QStringLiteral("string")));
0076     parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("editor-cmd"), i18n("Sets the external editor command"), QStringLiteral("string")));
0077     parser.addPositionalArgument(QStringLiteral("urls"), i18n("Documents to open. Specify '-' to read from stdin."));
0078 
0079     parser.process(app);
0080     aboutData.processCommandLine(&parser);
0081 
0082     // see if we are starting with session management
0083     if (app.isSessionRestored()) {
0084         kRestoreMainWindows<Shell>();
0085     } else {
0086         // no session.. just start up normally
0087         QStringList paths;
0088         for (int i = 0; i < parser.positionalArguments().count(); ++i) {
0089             paths << parser.positionalArguments().at(i);
0090         }
0091         Okular::Status status = Okular::main(paths, ShellUtils::serializeOptions(parser));
0092         switch (status) {
0093         case Okular::Error:
0094             return -1;
0095         case Okular::AttachedOtherProcess:
0096             return 0;
0097         case Okular::Success:
0098             // Do nothing
0099             break;
0100         }
0101     }
0102 
0103     return app.exec();
0104 }
0105 
0106 /* kate: replace-tabs on; indent-width 4; */