diff --git a/src/app/App.cpp b/src/app/App.cpp index 164fa7b48..283cbcae4 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -68,6 +68,16 @@ inline bool installLocale (App &app, QTranslator &translator, const QLocale &loc return translator.load(locale, LANGUAGES_PATH) && app.installTranslator(&translator); } +inline shared_ptr getConfigIfExists (const QCommandLineParser &parser) { + string configPath = Paths::getConfigFilePath(parser.value("config"), false); + if (Paths::filePathExists(configPath)) + return linphone::Config::newWithFactory(configPath, ""); + + return nullptr; +} + +// ----------------------------------------------------------------------------- + App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::User | Mode::ExcludeAppPath | Mode::ExcludeAppVersion) { setWindowIcon(QIcon(WINDOW_ICON_PATH)); @@ -87,7 +97,7 @@ App::App (int &argc, char *argv[]) : SingleApplication(argc, argv, true, Mode::U // Init locale. mTranslator = new DefaultTranslator(this); - initLocale(); + initLocale(::getConfigIfExists(*mParser)); if (mParser->isSet("help")) { createParser(); @@ -175,6 +185,7 @@ void App::initContentApp () { mEngine->addImageProvider(ThumbnailProvider::PROVIDER_ID, new ThumbnailProvider()); mColors = new Colors(this); + mColors->useConfig(::getConfigIfExists(*mParser)); registerTypes(); registerSharedTypes(); @@ -452,16 +463,11 @@ void App::setTrayIcon () { // ----------------------------------------------------------------------------- -void App::initLocale () { +void App::initLocale (const shared_ptr &config) { // Try to use preferred locale. QString locale; - string configPath = Paths::getConfigFilePath(mParser->value("config"), false); - if (Paths::filePathExists(configPath)) - locale = ::Utils::coreStringToAppString( - linphone::Config::newWithFactory(configPath, "")->getString( - SettingsModel::UI_SECTION, "locale", "" - ) - ); + if (config) + locale = ::Utils::coreStringToAppString(config->getString(SettingsModel::UI_SECTION, "locale", "")); if (!locale.isEmpty() && ::installLocale(*this, *mTranslator, QLocale(locale))) { mLocale = locale; diff --git a/src/app/App.hpp b/src/app/App.hpp index ca93868f0..9c0c04e8d 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -102,7 +102,7 @@ private: void setTrayIcon (); void createNotifier (); - void initLocale (); + void initLocale (const std::shared_ptr &config); QString getConfigLocale () const; void setConfigLocale (const QString &locale); diff --git a/src/components/other/colors/Colors.cpp b/src/components/other/colors/Colors.cpp index f0bbaf71b..fc62c1408 100644 --- a/src/components/other/colors/Colors.cpp +++ b/src/components/other/colors/Colors.cpp @@ -20,10 +20,10 @@ * Author: Ronan Abhamon */ +#include #include #include "../../../utils/Utils.hpp" -#include "../../core/CoreManager.hpp" #include "Colors.hpp" @@ -33,14 +33,15 @@ using namespace std; // ============================================================================= -Colors::Colors (QObject *parent) : QObject(parent) { - QObject::connect(CoreManager::getInstance(), &CoreManager::coreCreated, this, &Colors::overrideColors); +Colors::Colors (QObject *parent) : QObject(parent) {} + +void Colors::useConfig (const std::shared_ptr &config) { + overrideColors(config); } // ----------------------------------------------------------------------------- -void Colors::overrideColors () { - shared_ptr config = CoreManager::getInstance()->getCore()->getConfig(); +void Colors::overrideColors (const shared_ptr &config) { const QMetaObject *info = metaObject(); for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) { diff --git a/src/components/other/colors/Colors.hpp b/src/components/other/colors/Colors.hpp index f7d3c3395..e2aadc138 100644 --- a/src/components/other/colors/Colors.hpp +++ b/src/components/other/colors/Colors.hpp @@ -47,6 +47,10 @@ // ----------------------------------------------------------------------------- +namespace linphone { + class Config; +} + class Colors : public QObject { Q_OBJECT; @@ -94,6 +98,8 @@ public: Colors (QObject *parent = Q_NULLPTR); ~Colors () = default; + void useConfig (const std::shared_ptr &config); + signals: void colorTaChanged (const QColor &color); void colorTbChanged (const QColor &color); @@ -125,7 +131,7 @@ signals: void colorTerrorChanged (const QColor &color); private: - void overrideColors (); + void overrideColors (const std::shared_ptr &config); QStringList getColorNames () const; };