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
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) {
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<linphone::Config> &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;
......
......@@ -102,7 +102,7 @@ private:
void setTrayIcon ();
void createNotifier ();
void initLocale ();
void initLocale (const std::shared_ptr<linphone::Config> &config);
QString getConfigLocale () const;
void setConfigLocale (const QString &locale);
......
......@@ -20,10 +20,10 @@
* Author: Ronan Abhamon
*/
#include <linphone++/linphone.hh>
#include <QMetaProperty>
#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<linphone::Config> &config) {
overrideColors(config);
}
// -----------------------------------------------------------------------------
void Colors::overrideColors () {
shared_ptr<linphone::Config> config = CoreManager::getInstance()->getCore()->getConfig();
void Colors::overrideColors (const shared_ptr<linphone::Config> &config) {
const QMetaObject *info = metaObject();
for (int i = info->propertyOffset(); i < info->propertyCount(); ++i) {
......
......@@ -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<linphone::Config> &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<linphone::Config> &config);
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