Commit 2f833894 authored by Ronan's avatar Ronan
Browse files

fix(src/app/App): use preferred locale at startup

parent 3ce3a5cc
......@@ -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<TYPE>( \
"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();
......
......@@ -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 ();
......
......@@ -70,7 +70,6 @@ int main (int argc, char *argv[]) {
// ---------------------------------------------------------------------------
App app(argc, argv);
app.parseArgs();
if (app.isSecondary()) {
QString command = app.getCommandArgument();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment