2018-12-13 15:42:28 +00:00
|
|
|
#include "appconfig.h"
|
|
|
|
|
|
|
|
#include <QLoggingCategory>
|
|
|
|
|
2018-12-18 17:30:26 +00:00
|
|
|
#include <QSettings>
|
2018-12-13 15:42:28 +00:00
|
|
|
|
|
|
|
const QStringList loggingCategories =
|
|
|
|
{"UIManager",
|
|
|
|
"Flexbox",
|
|
|
|
"WebSocketModule",
|
|
|
|
"Networking",
|
|
|
|
"ViewManager",
|
|
|
|
"RCTNotification",
|
|
|
|
"default",
|
|
|
|
"RCTStatus",
|
|
|
|
"jsserver",
|
|
|
|
"status"};
|
2018-12-18 17:30:26 +00:00
|
|
|
|
|
|
|
const QString SETTINGS_GROUP_NAME = "im/status";
|
|
|
|
const QString AppConfig::LOGGING_ENABLED = "logging_enabled";
|
|
|
|
|
2018-12-13 15:42:28 +00:00
|
|
|
Q_LOGGING_CATEGORY(APPCONFIG, "AppConfig")
|
|
|
|
|
|
|
|
AppConfig AppConfig::appConfig;
|
|
|
|
|
2018-12-18 17:30:26 +00:00
|
|
|
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]));
|
|
|
|
}
|
2018-12-13 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AppConfig& AppConfig::inst() {
|
|
|
|
return appConfig;
|
|
|
|
}
|
|
|
|
|
2018-12-18 17:30:26 +00:00
|
|
|
QVariant AppConfig::getValue(const QString& name) const {
|
|
|
|
return settings.value(name);
|
2018-12-13 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 17:30:26 +00:00
|
|
|
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));
|
|
|
|
}
|
2018-12-13 15:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2018-12-18 17:30:26 +00:00
|
|
|
|