diff --git a/linphone-desktop/src/app/App.cpp b/linphone-desktop/src/app/App.cpp index 4c0894a43..fd64b83ef 100644 --- a/linphone-desktop/src/app/App.cpp +++ b/linphone-desktop/src/app/App.cpp @@ -33,11 +33,12 @@ #include "../components/Components.hpp" #include "../Utils.hpp" +#include "cli/Cli.hpp" #include "logger/Logger.hpp" +#include "paths/Paths.hpp" #include "providers/AvatarProvider.hpp" #include "providers/ThumbnailProvider.hpp" #include "translator/DefaultTranslator.hpp" -#include "cli/Cli.hpp" #include "App.hpp" @@ -71,12 +72,28 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true) { setApplicationVersion(LINPHONE_QT_GIT_VERSION); setWindowIcon(QIcon(WINDOW_ICON_PATH)); + parseArgs(); + // List available locales. for (const auto &locale : QDir(LANGUAGES_PATH).entryList()) mAvailableLocales << QLocale(locale); mTranslator = new DefaultTranslator(this); + // Try to use preferred locale. + QString locale = ::Utils::coreStringToAppString( + linphone::Config::newWithFactory( + Paths::getConfigFilePath(mParser.value("config")), "")->getString( + SettingsModel::UI_SECTION, "locale", "" + ) + ); + + if (!locale.isEmpty() && installLocale(*this, *mTranslator, QLocale(locale))) { + mLocale = locale; + qInfo() << QStringLiteral("Use preferred locale: %1").arg(locale); + return; + } + // Try to use system locale. QLocale sysLocale = QLocale::system(); if (installLocale(*this, *mTranslator, sysLocale)) { @@ -200,33 +217,6 @@ void App::initContentApp () { // ----------------------------------------------------------------------------- -void App::parseArgs () { - mParser.setApplicationDescription(tr("applicationDescription")); - mParser.addHelpOption(); - mParser.addVersionOption(); - mParser.addOptions({ - { "config", tr("commandLineOptionConfig"), tr("commandLineOptionConfigArg") }, - #ifndef Q_OS_MACOS - { "iconified", tr("commandLineOptionIconified") }, - #endif // ifndef Q_OS_MACOS - { "self-test", tr("commandLineOptionSelfTest") }, - { { "V", "verbose" }, tr("commandLineOptionVerbose") }, - { { "c", "cmd" }, tr("commandLineOptionCmd"), tr("commandLineOptionCmdArg") } - }); - - mParser.process(*this); - - // Initialize logger. (Do not do this before this point because the - // application has to be created for the logs to be put in the correct - // directory.) - Logger::init(); - if (mParser.isSet("verbose")) { - Logger::getInstance()->setVerbose(true); - } -} - -// ----------------------------------------------------------------------------- - QString App::getCommandArgument () { return mParser.value("cmd"); } @@ -239,29 +229,6 @@ void App::executeCommand (const QString &command) { // ----------------------------------------------------------------------------- -void App::tryToUsePreferredLocale () { - QString locale = getConfigLocale(); - - if (!locale.isEmpty()) { - DefaultTranslator *translator = new DefaultTranslator(this); - - if (installLocale(*this, *translator, QLocale(locale))) { - // Use config. - mTranslator->deleteLater(); - mTranslator = translator; - mLocale = locale; - - qInfo() << QStringLiteral("Use preferred locale: %1").arg(locale); - } else { - // Reset config. - setConfigLocale(""); - translator->deleteLater(); - } - } -} - -// ----------------------------------------------------------------------------- - QQuickWindow *App::getCallsWindow () { if (!mCallsWindow) mCallsWindow = createSubWindow(this, QML_VIEW_CALLS_WINDOW); @@ -318,6 +285,33 @@ bool App::hasFocus () const { // ----------------------------------------------------------------------------- +void App::parseArgs () { + mParser.setApplicationDescription(tr("applicationDescription")); + mParser.addHelpOption(); + mParser.addVersionOption(); + mParser.addOptions({ + { "config", tr("commandLineOptionConfig"), tr("commandLineOptionConfigArg") }, + #ifndef Q_OS_MACOS + { "iconified", tr("commandLineOptionIconified") }, + #endif // ifndef Q_OS_MACOS + { "self-test", tr("commandLineOptionSelfTest") }, + { { "V", "verbose" }, tr("commandLineOptionVerbose") }, + { { "c", "cmd" }, tr("commandLineOptionCmd"), tr("commandLineOptionCmdArg") } + }); + + mParser.process(*this); + + // Initialize logger. (Do not do this before this point because the + // application has to be created for the logs to be put in the correct + // directory.) + Logger::init(); + if (mParser.isSet("verbose")) { + Logger::getInstance()->setVerbose(true); + } +} + +// ----------------------------------------------------------------------------- + #define registerSharedSingletonType(TYPE, NAME, METHOD) qmlRegisterSingletonType( \ "Linphone", 1, 0, NAME, \ [](QQmlEngine *, QJSEngine *) -> QObject *{ \ @@ -468,8 +462,6 @@ QString App::getLocale () const { // ----------------------------------------------------------------------------- void App::openAppAfterInit () { - tryToUsePreferredLocale(); - qInfo() << QStringLiteral("Open linphone app."); QQuickWindow *mainWindow = getMainWindow(); diff --git a/linphone-desktop/src/app/App.hpp b/linphone-desktop/src/app/App.hpp index 5278000ab..b817fc75e 100644 --- a/linphone-desktop/src/app/App.hpp +++ b/linphone-desktop/src/app/App.hpp @@ -50,13 +50,10 @@ public: ~App (); void initContentApp (); - void parseArgs (); QString getCommandArgument (); void executeCommand (const QString &command); - void tryToUsePreferredLocale (); - QQmlEngine *getEngine () { return mEngine; } @@ -91,6 +88,8 @@ signals: void configLocaleChanged (const QString &locale); private: + void parseArgs (); + void registerTypes (); void registerSharedTypes (); void setTrayIcon (); diff --git a/linphone-desktop/src/main.cpp b/linphone-desktop/src/main.cpp index 0d7929f94..929025341 100644 --- a/linphone-desktop/src/main.cpp +++ b/linphone-desktop/src/main.cpp @@ -70,7 +70,6 @@ int main (int argc, char *argv[]) { // --------------------------------------------------------------------------- App app(argc, argv); - app.parseArgs(); if (app.isSecondary()) { QString command = app.getCommandArgument();