From d1458a0db397a3802b30c9e1d8ae64e3cd8d6946 Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Fri, 5 Jan 2018 01:55:21 +0100 Subject: [PATCH] Move initSettings to SettingManager Fixes #205 --- src/application.cpp | 1 - src/main.cpp | 47 ++---------------------------- src/singletons/settingsmanager.cpp | 34 +++++++++++++++++++-- src/singletons/settingsmanager.hpp | 2 +- 4 files changed, 35 insertions(+), 49 deletions(-) diff --git a/src/application.cpp b/src/application.cpp index 33f2c85be..b92f4bbfe 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -19,7 +19,6 @@ Application::Application() singletons::WindowManager::getInstance(); logging::init(); - singletons::SettingManager::getInstance().load(); singletons::WindowManager::getInstance().initMainWindow(); diff --git a/src/main.cpp b/src/main.cpp index 0240179be..6d9ba5702 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,11 +1,9 @@ #include "application.hpp" +#include "singletons/settingsmanager.hpp" #include #include -#include #include -#include -#include #include "util/networkmanager.hpp" @@ -13,37 +11,6 @@ #include "util/nativeeventhelper.hpp" #endif -namespace { - -inline bool initSettings(bool portable) -{ - QString settingsPath; - if (portable) { - settingsPath.append(QDir::currentPath()); - } else { - // Get settings path - settingsPath.append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); - if (settingsPath.isEmpty()) { - printf("Error finding writable location for settings\n"); - return false; - } - } - - qDebug() << settingsPath; - - if (!QDir().mkpath(settingsPath)) { - printf("Error creating directories for settings: %s\n", qPrintable(settingsPath)); - return false; - } - settingsPath.append("/settings.json"); - - pajlada::Settings::SettingManager::load(qPrintable(settingsPath)); - - return true; -} - -} // namespace - int main(int argc, char *argv[]) { QApplication::setAttribute(Qt::AA_Use96Dpi, true); @@ -56,17 +23,9 @@ int main(int argc, char *argv[]) a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter); #endif - // Options - bool portable = false; - - for (int i = 1; i < argc; ++i) { - if (strcmp(argv[i], "portable") == 0) { - portable = true; - } - } - // Initialize settings - if (!initSettings(portable)) { + bool success = chatterino::singletons::SettingManager::getInstance().init(argc, argv); + if (!success) { printf("Error initializing settings\n"); return 1; } diff --git a/src/singletons/settingsmanager.cpp b/src/singletons/settingsmanager.cpp index b5f939e7b..d118bb88a 100644 --- a/src/singletons/settingsmanager.cpp +++ b/src/singletons/settingsmanager.cpp @@ -42,10 +42,38 @@ bool SettingManager::isIgnoredEmote(const QString &) return false; } -void SettingManager::load() +bool SettingManager::init(int argc, char **argv) { - // Just to make sure the singleton is initialized - debug::Log("."); + // Options + bool portable = false; + + for (int i = 1; i < argc; ++i) { + if (strcmp(argv[i], "portable") == 0) { + portable = true; + } + } + + QString settingsPath; + if (portable) { + settingsPath.append(QDir::currentPath()); + } else { + // Get settings path + settingsPath.append(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); + if (settingsPath.isEmpty()) { + printf("Error finding writable location for settings\n"); + return false; + } + } + + if (!QDir().mkpath(settingsPath)) { + printf("Error creating directories for settings: %s\n", qPrintable(settingsPath)); + return false; + } + settingsPath.append("/settings.json"); + + pajlada::Settings::SettingManager::load(qPrintable(settingsPath)); + + return true; } void SettingManager::updateWordTypeMask() diff --git a/src/singletons/settingsmanager.hpp b/src/singletons/settingsmanager.hpp index 7120469cb..67233409d 100644 --- a/src/singletons/settingsmanager.hpp +++ b/src/singletons/settingsmanager.hpp @@ -25,7 +25,7 @@ public: messages::Word::Flags getWordTypeMask(); bool isIgnoredEmote(const QString &emote); - void load(); + bool init(int argc, char **argv); /// Appearance BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};