From f26865e394b69b46fded45abd1b2e63230564f2e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Wed, 6 Apr 2011 20:37:11 +0200
Subject: Force settings permissions to be group and world unreadable.


diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index b563af1..a5642d7 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -7,6 +7,7 @@
 #include "QtSettingsProvider.h"
 
 #include <QStringList>
+#include <QFile>
 
 namespace Swift {
 
@@ -24,6 +25,7 @@ std::string QtSettingsProvider::getStringSetting(const std::string &settingPath)
 
 void QtSettingsProvider::storeString(const std::string &settingPath, const std::string &settingValue) {
 	settings_.setValue(settingPath.c_str(), settingValue.c_str());
+	updatePermissions();
 }
 
 bool QtSettingsProvider::getBoolSetting(const std::string &settingPath, bool defaultValue) {
@@ -33,6 +35,7 @@ bool QtSettingsProvider::getBoolSetting(const std::string &settingPath, bool def
 
 void QtSettingsProvider::storeBool(const std::string &settingPath, bool settingValue) {
 	settings_.setValue(settingPath.c_str(), settingValue);
+	updatePermissions();
 }
 
 int QtSettingsProvider::getIntSetting(const std::string &settingPath, int defaultValue) {
@@ -42,6 +45,7 @@ int QtSettingsProvider::getIntSetting(const std::string &settingPath, int defaul
 
 void QtSettingsProvider::storeInt(const std::string &settingPath, int settingValue) {
 	settings_.setValue(settingPath.c_str(), settingValue);
+	updatePermissions();
 }
 
 std::vector<std::string> QtSettingsProvider::getAvailableProfiles() {
@@ -57,6 +61,7 @@ void QtSettingsProvider::createProfile(const std::string& profile) {
 	QStringList stringList = settings_.value("profileList").toStringList();
 	stringList.append(profile.c_str());
 	settings_.setValue("profileList", stringList);
+	updatePermissions();
 }
 
 void QtSettingsProvider::removeProfile(const std::string& profile) {
@@ -69,11 +74,19 @@ void QtSettingsProvider::removeProfile(const std::string& profile) {
 	QStringList stringList = settings_.value("profileList").toStringList();
 	stringList.removeAll(profile.c_str());
 	settings_.setValue("profileList", stringList);
+	updatePermissions();
 }
 
 QSettings* QtSettingsProvider::getQSettings() {
 	return &settings_;
 }
 
+void QtSettingsProvider::updatePermissions() {
+	QFile file(settings_.fileName());
+	if (file.exists()) {
+		file.setPermissions(QFile::ReadOwner|QFile::WriteOwner);
+	}
+}
+
 }
 
diff --git a/Swift/QtUI/QtSettingsProvider.h b/Swift/QtUI/QtSettingsProvider.h
index ca05fe1..8eeb854 100644
--- a/Swift/QtUI/QtSettingsProvider.h
+++ b/Swift/QtUI/QtSettingsProvider.h
@@ -27,6 +27,10 @@ class QtSettingsProvider : public SettingsProvider {
 		virtual void createProfile(const std::string& profile);
 		virtual void removeProfile(const std::string& profile);
 		QSettings* getQSettings();
+	
+	private:
+		void updatePermissions();
+
 	private:
 		QSettings settings_;
 };
-- 
cgit v0.10.2-6-g49f6