forked from status-im/status-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathappconfig.cpp
More file actions
76 lines (61 loc) · 1.96 KB
/
appconfig.cpp
File metadata and controls
76 lines (61 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "appconfig.h"
#include <QLoggingCategory>
#include <QSettings>
const QStringList loggingCategories =
{"UIManager",
"Flexbox",
"WebSocketModule",
"Networking",
"ViewManager",
"RCTNotification",
"default",
"RCTStatus",
"jsserver",
"status"};
const QString SETTINGS_GROUP_NAME = "im/status";
const QString AppConfig::LOGGING_ENABLED = "logging_enabled";
Q_LOGGING_CATEGORY(APPCONFIG, "AppConfig")
AppConfig AppConfig::appConfig;
AppConfig::AppConfig()
: settings("Status.im", "StatusDesktop") {
settings.beginGroup(SETTINGS_GROUP_NAME);
// Set default values
if (settings.value(LOGGING_ENABLED).isNull()) {
settings.setValue(LOGGING_ENABLED, false);
}
QStringList keys = settings.allKeys();
for (int i = 0; i < keys.size(); ++i) {
processFx(keys[i], settings.value(keys[i]));
}
}
AppConfig& AppConfig::inst() {
return appConfig;
}
QVariant AppConfig::getValue(const QString& name) const {
return settings.value(name);
}
void AppConfig::setValue(const QString& name, const QVariant& value) {
processFx(name, value);
settings.setValue(name, value);
}
// This fn is for processing side-effects of a particular value
void AppConfig::processFx(const QString& name, const QVariant& value) const {
//qCDebug(APPCONFIG) << "### processFx group" << settings.group() << " " << name << ": " << value;
if (name == LOGGING_ENABLED) {
bool enabled = value.toBool();
//qCDebug(APPCONFIG) << "### processFx" << name << ": " << value << ": " << enabled;
QLoggingCategory::setFilterRules(getLoggingFilterRules(enabled));
}
}
QString AppConfig::getLoggingFilterRules(bool enabled) const {
if (enabled) {
return "UIManager=false\nFlexbox=false\nViewManager=false\nNetworking=false\nWebSocketModule=false";
}
else {
QString filterRules;
for (int i = 0; i < loggingCategories.size(); ++i) {
filterRules += (loggingCategories.at(i) + "=false\n");
}
return filterRules;
}
}