1 /**
2 * \file mainqt.cpp
3 * Main program.
4 *
5 * \b Project: Kid3
6 * \author Urs Fleisch
7 * \date 9 Jan 2003
8 *
9 * Copyright (C) 2003-2018 Urs Fleisch
10 *
11 * This file is part of Kid3.
12 *
13 * Kid3 is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * Kid3 is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 */
26
27 #include <QFile>
28 #include <QApplication>
29 #include <QLibraryInfo>
30 #include <QLocale>
31 #include <QTranslator>
32 #include <QDir>
33 #include <QSettings>
34 #include "fileconfig.h"
35 #include "loadtranslation.h"
36 #include "kid3mainwindow.h"
37 #include "platformtools.h"
38 #include "kid3application.h"
39 #include "kid3qtapplication.h"
40
41 /**
42 * Main program.
43 *
44 * @param argc number of arguments including command name
45 * @param argv arguments, argv[0] is command name
46 *
47 * @return exit code of application.
48 */
49
main(int argc,char * argv[])50 int main(int argc, char* argv[])
51 {
52 Q_INIT_RESOURCE(kid3);
53
54 #if QT_VERSION < 0x060000
55 // Enable support for high resolution "@2x" images
56 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
57 #if QT_VERSION >= 0x050600
58 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
59 #endif
60 #endif
61 Kid3QtApplication app(argc, argv);
62 QCoreApplication::setApplicationName(QLatin1String("Kid3"));
63
64 #ifdef Q_OS_MAC
65 QDir dir(QApplication::applicationDirPath());
66 dir.cdUp();
67 dir.cd(QLatin1String("PlugIns"));
68 QApplication::setLibraryPaths(QStringList(dir.absolutePath()));
69 #endif
70
71 QStringList args = QApplication::arguments();
72 if (args.size() > 1 && args.at(1) == QLatin1String("--portable")) {
73 args.removeAt(1);
74 qputenv("KID3_CONFIG_FILE",
75 QCoreApplication::applicationDirPath().toLatin1() + "/kid3.ini");
76 }
77
78 // The Language setting has to be read bypassing the regular
79 // configuration object because the language must be set before
80 // the application is created.
81 QByteArray configPath = qgetenv("KID3_CONFIG_FILE");
82 auto configuredLanguage = configPath.isNull()
83 ? QSettings(QSettings::UserScope, QLatin1String("Kid3"),
84 QLatin1String("Kid3"))
85 .value(QLatin1String("MainWindow/Language")).toString()
86 : QSettings(QFile::decodeName(configPath), QSettings::IniFormat)
87 .value(QLatin1String("MainWindow/Language")).toString();
88 Utils::loadTranslation(configuredLanguage);
89
90 IPlatformTools* platformTools = new PlatformTools;
91 auto kid3App = new Kid3Application(platformTools);
92 #ifdef HAVE_QTDBUS
93 kid3App->activateDbusInterface();
94 #endif
95 auto kid3 = new Kid3MainWindow(platformTools, kid3App);
96 kid3->setAttribute(Qt::WA_DeleteOnClose);
97 QObject::connect(&app, &Kid3QtApplication::openFileRequested,
98 kid3App, &Kid3Application::openDrop);
99 kid3->show();
100 if (args.size() > 1) {
101 kid3App->openDirectory(args.mid(1));
102 } else if ((FileConfig::instance().loadLastOpenedFile() ||
103 app.isSessionRestored()) &&
104 !FileConfig::instance().lastOpenedFile().isEmpty()) {
105 kid3App->openDirectory(QStringList()
106 << FileConfig::instance().lastOpenedFile());
107 }
108 int rc = QApplication::exec();
109 delete kid3App;
110 delete platformTools;
111 return rc;
112 }
113