Move initSettings to SettingManager

Fixes #205
This commit is contained in:
Rasmus Karlsson 2018-01-05 01:55:21 +01:00
parent 947589358b
commit d1458a0db3
4 changed files with 35 additions and 49 deletions

View file

@ -19,7 +19,6 @@ Application::Application()
singletons::WindowManager::getInstance(); singletons::WindowManager::getInstance();
logging::init(); logging::init();
singletons::SettingManager::getInstance().load();
singletons::WindowManager::getInstance().initMainWindow(); singletons::WindowManager::getInstance().initMainWindow();

View file

@ -1,11 +1,9 @@
#include "application.hpp" #include "application.hpp"
#include "singletons/settingsmanager.hpp"
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <QApplication> #include <QApplication>
#include <QDir>
#include <QLibrary> #include <QLibrary>
#include <QStandardPaths>
#include <pajlada/settings/settingmanager.hpp>
#include "util/networkmanager.hpp" #include "util/networkmanager.hpp"
@ -13,37 +11,6 @@
#include "util/nativeeventhelper.hpp" #include "util/nativeeventhelper.hpp"
#endif #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[]) int main(int argc, char *argv[])
{ {
QApplication::setAttribute(Qt::AA_Use96Dpi, true); QApplication::setAttribute(Qt::AA_Use96Dpi, true);
@ -56,17 +23,9 @@ int main(int argc, char *argv[])
a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter); a.installNativeEventFilter(new chatterino::util::DpiNativeEventFilter);
#endif #endif
// Options
bool portable = false;
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "portable") == 0) {
portable = true;
}
}
// Initialize settings // Initialize settings
if (!initSettings(portable)) { bool success = chatterino::singletons::SettingManager::getInstance().init(argc, argv);
if (!success) {
printf("Error initializing settings\n"); printf("Error initializing settings\n");
return 1; return 1;
} }

View file

@ -42,10 +42,38 @@ bool SettingManager::isIgnoredEmote(const QString &)
return false; return false;
} }
void SettingManager::load() bool SettingManager::init(int argc, char **argv)
{ {
// Just to make sure the singleton is initialized // Options
debug::Log("."); 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() void SettingManager::updateWordTypeMask()

View file

@ -25,7 +25,7 @@ public:
messages::Word::Flags getWordTypeMask(); messages::Word::Flags getWordTypeMask();
bool isIgnoredEmote(const QString &emote); bool isIgnoredEmote(const QString &emote);
void load(); bool init(int argc, char **argv);
/// Appearance /// Appearance
BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true}; BoolSetting showTimestamps = {"/appearance/messages/showTimestamps", true};