File indexing completed on 2022-09-27 16:29:36

0001 /*
0002     SPDX-FileCopyrightText: 2016 ROSA, 2022 Jonathan Esk-Riddell <jr@jriddell.org>
0003     SPDX-License-Identifier: GPL-3.0-or-later
0004 */
0005 
0006 #include "mainapplication.h"
0007 
0008 #include <QStandardPaths>
0009 #include <QIcon>
0010 #include <QUrl>
0011 #include <KAboutData>
0012 #include <KLocalizedString>
0013 
0014 #include "common.h"
0015 #include "isoimagewriter_version.h"
0016 
0017 // in one source file
0018 Q_LOGGING_CATEGORY(IMAGEWRITER, "org.kde.isoimagewriter");
0019 
0020 MainApplication::MainApplication(int& argc, char** argv) :
0021     QApplication(argc, argv)
0022 {
0023     setWindowIcon(QIcon::fromTheme("drive-removable-media"));
0024     KLocalizedString::setApplicationDomain("isoimagewriter");
0025     KAboutData aboutData( QStringLiteral("isoimagewriter"),
0026                           i18n("ISO Image Writer"),
0027                           QStringLiteral(ISOIMAGEWRITER_VERSION_STRING),
0028                           i18n("Write an ISO Image to a USB Disk"),
0029                           KAboutLicense::GPL,
0030                           i18n("Copyright (c) 2016 ROSA, Copyright (c) 2022 Jonathan Esk-Riddell <jr@jriddell.org>"));
0031 
0032     aboutData.addAuthor(i18n("Konstantin Vlasov"), i18n("Author"), QStringLiteral("konstantin.vlasov@rosalab.ru"));
0033     aboutData.addAuthor(i18n("Jonathan Riddell"), i18n("Author"), QStringLiteral("jr@jriddell.org"));
0034     m_Options.addVersionOption();
0035     m_Options.addOption(QCommandLineOption("lang", "", "language"));
0036     m_Options.addOption(QCommandLineOption("dir", "", "path"));
0037     m_Options.addPositionalArgument("[File]", i18n("ISO file to open"));
0038     aboutData.setupCommandLine(&m_Options);
0039     m_Options.process(arguments());
0040     aboutData.processCommandLine(&m_Options);
0041     KAboutData::setApplicationData(aboutData);
0042 
0043     QLoggingCategory::setFilterRules(QStringLiteral("org.kde.isoimagewriter = true"));
0044 }
0045 
0046 // Returns the language id to be used by the application (specified by --lang, or system locale otherwise)
0047 QString MainApplication::getLocale()
0048 {
0049     return (m_Options.isSet("lang") ? m_Options.value("lang") : QLocale::system().name());
0050 }
0051 
0052 // Returns the start-up directory that will be shown by default in the Open File dialog
0053 QString MainApplication::getInitialDir()
0054 {
0055     // TODO: Check for elevation
0056     // win:restricted
0057     // win:admin
0058     // mac:restricted
0059     // linux:restricted
0060     // linux:root
0061     // linux: translated dir names
0062     // win: redefined paths
0063     if (m_Options.isSet("dir"))
0064         return m_Options.value("dir");
0065 
0066     // Otherwise get the standard system Downloads location
0067     QStringList downloadDirs = QStandardPaths::standardLocations(QStandardPaths::DownloadLocation);
0068     if (downloadDirs.size() > 0)
0069         return downloadDirs.at(0);
0070     else
0071         return "";
0072 }
0073 
0074 // Returns the fila path passed to the application as command-line parameter
0075 QUrl MainApplication::getInitialImage()
0076 {
0077     const QStringList args = m_Options.positionalArguments();
0078     if (!args.isEmpty())
0079         return QUrl::fromUserInput(args.first(), getInitialDir(), QUrl::AssumeLocalFile);
0080     else
0081         return {};
0082 }