summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-02-17 16:57:01 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-02-21 14:34:55 (GMT)
commit3605b6622bc8b4abb810fac6b53f7f71be0fa7de (patch)
tree638a8fd6449dd235931fe307e50119adf9c9fe22 /Swift/QtUI/QtSettingsProvider.cpp
parentb05f8fcb285d2d13d2be50a3eb1062048fbe30f5 (diff)
downloadswift-contrib-3605b6622bc8b4abb810fac6b53f7f71be0fa7de.zip
swift-contrib-3605b6622bc8b4abb810fac6b53f7f71be0fa7de.tar.bz2
Introduce system settings policies.
Release-Notes: It is now possible for sysadmins to deploy files with policies for configuration options, such as making it impossible for users to save passwords or to force sound notifications off, or to set defaults. Also allow changing an option so that Swift disconnects on idle timeout, instead of going away.
Diffstat (limited to 'Swift/QtUI/QtSettingsProvider.cpp')
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp59
1 files changed, 42 insertions, 17 deletions
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index b8ef9bb..0c4d49b 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -1,10 +1,10 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2012 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
-#include "QtSettingsProvider.h"
+#include <QtSettingsProvider.h>
#include <QStringList>
#include <QFile>
@@ -18,33 +18,54 @@ QtSettingsProvider::~QtSettingsProvider() {
}
-std::string QtSettingsProvider::getStringSetting(const std::string &settingPath) {
- QVariant setting = settings_.value(settingPath.c_str());
- return setting.isNull() ? "" : std::string(setting.toString().toUtf8());
+std::string QtSettingsProvider::getSetting(const Setting<std::string>& setting) {
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : std::string(variant.toString().toUtf8());
}
-void QtSettingsProvider::storeString(const std::string &settingPath, const std::string &settingValue) {
- settings_.setValue(settingPath.c_str(), settingValue.c_str());
+void QtSettingsProvider::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) {
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue.c_str());
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
updatePermissions();
}
-bool QtSettingsProvider::getBoolSetting(const std::string &settingPath, bool defaultValue) {
- QVariant setting = settings_.value(settingPath.c_str());
- return setting.isNull() ? defaultValue : setting.toBool();
+bool QtSettingsProvider::getSetting(const Setting<bool>& setting) {
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : variant.toBool();
}
-void QtSettingsProvider::storeBool(const std::string &settingPath, bool settingValue) {
- settings_.setValue(settingPath.c_str(), settingValue);
+void QtSettingsProvider::storeSetting(const Setting<bool>& setting, const bool& settingValue) {
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue);
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
updatePermissions();
}
-int QtSettingsProvider::getIntSetting(const std::string &settingPath, int defaultValue) {
- QVariant setting = settings_.value(settingPath.c_str());
- return setting.isNull() ? defaultValue : setting.toInt();
+int QtSettingsProvider::getSetting(const Setting<int>& setting) {
+ QVariant variant = settings_.value(setting.getKey().c_str());
+ return variant.isNull() ? setting.getDefaultValue() : variant.toInt();
}
-void QtSettingsProvider::storeInt(const std::string &settingPath, int settingValue) {
- settings_.setValue(settingPath.c_str(), settingValue);
+void QtSettingsProvider::storeSetting(const Setting<int>& setting, const int& settingValue) {
+ bool changed = false;
+ if (getSetting(setting) != settingValue) {
+ changed = true;
+ }
+ settings_.setValue(setting.getKey().c_str(), settingValue);
+ if (changed) {
+ onSettingChanged(setting.getKey());
+ }
updatePermissions();
}
@@ -90,5 +111,9 @@ void QtSettingsProvider::updatePermissions() {
#endif
}
+bool QtSettingsProvider::getIsSettingFinal(const std::string& /*settingPath*/) {
+ return false;
+}
+
}