Commit 3e5cee9c authored by Ronan Abhamon's avatar Ronan Abhamon

fix(App): override colors at app creation, not at core started signal

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