Warning, file /multimedia/kid3/src/app/cli/maincli.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 maincli.cpp
0003  * Main program for command line interface.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 10 Aug 2013
0008  *
0009  * Copyright (C) 2013-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 <QCoreApplication>
0028 #include <QLibraryInfo>
0029 #include <QDir>
0030 #include <QTimer>
0031 #include <QSettings>
0032 #include "kid3cli.h"
0033 #include "loadtranslation.h"
0034 #include "standardiohandler.h"
0035 #include "coreplatformtools.h"
0036 #include "kid3application.h"
0037 
0038 #if defined Q_OS_WIN32 && defined Q_CC_MINGW
0039 // Disable command line globbing to avoid crash in QCoreApplication::arguments()
0040 // QTBUG-30330
0041 int _CRT_glob = 0;
0042 #endif
0043 
0044 /**
0045  * Main program for command line interface.
0046  *
0047  * @param argc number of arguments including command name
0048  * @param argv arguments, argv[0] is command name
0049  *
0050  * @return exit code of application.
0051  */
0052 int main(int argc, char* argv[])
0053 {
0054   QCoreApplication app(argc, argv);
0055   QCoreApplication::setApplicationName(QLatin1String("Kid3"));
0056 
0057 #ifdef Q_OS_MAC
0058   QDir dir(QCoreApplication::applicationDirPath());
0059   dir.cdUp();
0060   dir.cd(QLatin1String("PlugIns"));
0061   QCoreApplication::setLibraryPaths(QStringList(dir.absolutePath()));
0062 #endif
0063 
0064   QStringList args = QCoreApplication::arguments();
0065   if (args.size() > 1 && args.at(1) == QLatin1String("--portable")) {
0066     args.removeAt(1);
0067     qputenv("KID3_CONFIG_FILE",
0068             QCoreApplication::applicationDirPath().toLatin1() + "/kid3.ini");
0069   }
0070 
0071   // The Language setting has to be read bypassing the regular
0072   // configuration object because the language must be set before
0073   // the application is created.
0074   QByteArray configPath = qgetenv("KID3_CONFIG_FILE");
0075   auto configuredLanguage = configPath.isNull()
0076       ? QSettings(QSettings::UserScope, QLatin1String("Kid3"),
0077                   QLatin1String("Kid3"))
0078         .value(QLatin1String("MainWindow/Language")).toString()
0079       : QSettings(QFile::decodeName(configPath), QSettings::IniFormat)
0080         .value(QLatin1String("MainWindow/Language")).toString();
0081   Utils::loadTranslation(configuredLanguage);
0082 
0083   ICorePlatformTools* platformTools = new CorePlatformTools;
0084   auto kid3App = new Kid3Application(platformTools);
0085 #ifdef HAVE_QTDBUS
0086   if (args.size() > 1 && args.at(1) == QLatin1String("--dbus")) {
0087     args.removeAt(1);
0088     kid3App->activateDbusInterface();
0089   }
0090 #endif
0091   Kid3Cli kid3cli(kid3App, new StandardIOHandler("kid3-cli> "), args);
0092   QTimer::singleShot(0, &kid3cli, &Kid3Cli::execute);
0093   int rc = QCoreApplication::exec();
0094   delete kid3App;
0095   delete platformTools;
0096   return rc;
0097 }