Warning, file /multimedia/kid3/src/app/qt/mainqt.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /** 0002 * \file mainqt.cpp 0003 * Main program. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 9 Jan 2003 0008 * 0009 * Copyright (C) 2003-2018 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #include <QFile> 0028 #include <QApplication> 0029 #include <QLibraryInfo> 0030 #include <QLocale> 0031 #include <QTranslator> 0032 #include <QDir> 0033 #include <QSettings> 0034 #include "fileconfig.h" 0035 #include "loadtranslation.h" 0036 #include "kid3mainwindow.h" 0037 #include "platformtools.h" 0038 #include "kid3application.h" 0039 #include "kid3qtapplication.h" 0040 0041 /** 0042 * Main program. 0043 * 0044 * @param argc number of arguments including command name 0045 * @param argv arguments, argv[0] is command name 0046 * 0047 * @return exit code of application. 0048 */ 0049 0050 int main(int argc, char* argv[]) 0051 { 0052 Q_INIT_RESOURCE(kid3); 0053 0054 #if QT_VERSION < 0x060000 0055 // Enable support for high resolution "@2x" images 0056 QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); 0057 #if QT_VERSION >= 0x050600 0058 QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 0059 #endif 0060 #endif 0061 Kid3QtApplication app(argc, argv); 0062 QCoreApplication::setApplicationName(QLatin1String("Kid3")); 0063 0064 #if defined Q_OS_LINUX && QT_VERSION >= 0x050700 0065 app.setDesktopFileName(QLatin1String("org.kde.kid3-qt.desktop")); 0066 #endif 0067 0068 #ifdef Q_OS_MAC 0069 QDir dir(QApplication::applicationDirPath()); 0070 dir.cdUp(); 0071 dir.cd(QLatin1String("PlugIns")); 0072 QApplication::setLibraryPaths(QStringList(dir.absolutePath())); 0073 #endif 0074 0075 QStringList args = QApplication::arguments(); 0076 if (args.size() > 1 && args.at(1) == QLatin1String("--portable")) { 0077 args.removeAt(1); 0078 qputenv("KID3_CONFIG_FILE", 0079 QCoreApplication::applicationDirPath().toLatin1() + "/kid3.ini"); 0080 } 0081 0082 // The Language setting has to be read bypassing the regular 0083 // configuration object because the language must be set before 0084 // the application is created. 0085 QByteArray configPath = qgetenv("KID3_CONFIG_FILE"); 0086 auto configuredLanguage = configPath.isNull() 0087 ? QSettings(QSettings::UserScope, QLatin1String("Kid3"), 0088 QLatin1String("Kid3")) 0089 .value(QLatin1String("MainWindow/Language")).toString() 0090 : QSettings(QFile::decodeName(configPath), QSettings::IniFormat) 0091 .value(QLatin1String("MainWindow/Language")).toString(); 0092 Utils::loadTranslation(configuredLanguage); 0093 0094 IPlatformTools* platformTools = new PlatformTools; 0095 auto kid3App = new Kid3Application(platformTools); 0096 #ifdef HAVE_QTDBUS 0097 kid3App->activateDbusInterface(); 0098 #endif 0099 auto kid3 = new Kid3MainWindow(platformTools, kid3App); 0100 kid3->setAttribute(Qt::WA_DeleteOnClose); 0101 QObject::connect(&app, &Kid3QtApplication::openFileRequested, 0102 kid3App, &Kid3Application::openDrop); 0103 kid3->show(); 0104 if (args.size() > 1) { 0105 kid3App->openDirectory(args.mid(1)); 0106 } else if ((FileConfig::instance().loadLastOpenedFile() || 0107 app.isSessionRestored()) && 0108 !FileConfig::instance().lastOpenedFile().isEmpty()) { 0109 kid3App->openDirectory(QStringList() 0110 << FileConfig::instance().lastOpenedFile()); 0111 } 0112 int rc = QApplication::exec(); 0113 delete kid3App; 0114 delete platformTools; 0115 return rc; 0116 }