summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2012-03-01 08:03:50 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-03 09:00:30 (GMT)
commitfde71bd59b1412ae475c06f2d4100ce088e86af6 (patch)
tree4f3d85c700942d666c5ac5d032c757bc45bb1593
parent5271144cb6c0ecf3dc237af25197fa72a8737c09 (diff)
downloadswift-contrib-fde71bd59b1412ae475c06f2d4100ce088e86af6.zip
swift-contrib-fde71bd59b1412ae475c06f2d4100ce088e86af6.tar.bz2
Unit tests for SettingsProviderHierachy
Also fixing up errors they found and an uninitialised read left-over from the original patch.
-rw-r--r--Swift/Controllers/Chat/ChatsManager.cpp2
-rw-r--r--Swift/Controllers/SConscript1
-rw-r--r--Swift/Controllers/Settings/DummySettingsProvider.h9
-rw-r--r--Swift/Controllers/Settings/SettingsProvider.h1
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.cpp39
-rw-r--r--Swift/Controllers/Settings/SettingsProviderHierachy.h1
-rw-r--r--Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp91
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.cpp5
-rw-r--r--Swift/Controllers/Settings/XMLSettingsProvider.h2
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp5
-rw-r--r--Swift/QtUI/QtSettingsProvider.h1
-rw-r--r--Swiften/Client/CoreClient.h2
12 files changed, 147 insertions, 12 deletions
diff --git a/Swift/Controllers/Chat/ChatsManager.cpp b/Swift/Controllers/Chat/ChatsManager.cpp
index dcbba34..aedee4c 100644
--- a/Swift/Controllers/Chat/ChatsManager.cpp
+++ b/Swift/Controllers/Chat/ChatsManager.cpp
@@ -81,70 +81,72 @@ ChatsManager::ChatsManager(
roster_(roster),
eagleMode_(eagleMode),
settings_(settings) {
timerFactory_ = timerFactory;
eventController_ = eventController;
stanzaChannel_ = stanzaChannel;
iqRouter_ = iqRouter;
chatWindowFactory_ = chatWindowFactory;
nickResolver_ = nickResolver;
presenceOracle_ = presenceOracle;
avatarManager_ = NULL;
serverDiscoInfo_ = boost::shared_ptr<DiscoInfo>(new DiscoInfo());
presenceSender_ = presenceSender;
uiEventStream_ = uiEventStream;
mucBookmarkManager_ = NULL;
profileSettings_ = profileSettings;
presenceOracle_->onPresenceChange.connect(boost::bind(&ChatsManager::handlePresenceChange, this, _1));
uiEventConnection_ = uiEventStream_->onUIEvent.connect(boost::bind(&ChatsManager::handleUIEvent, this, _1));
chatListWindow_ = chatListWindowFactory->createChatListWindow(uiEventStream_);
chatListWindow_->onMUCBookmarkActivated.connect(boost::bind(&ChatsManager::handleMUCBookmarkActivated, this, _1));
chatListWindow_->onRecentActivated.connect(boost::bind(&ChatsManager::handleRecentActivated, this, _1));
chatListWindow_->onClearRecentsRequested.connect(boost::bind(&ChatsManager::handleClearRecentsRequested, this));
joinMUCWindow_ = NULL;
mucSearchController_ = new MUCSearchController(jid_, mucSearchWindowFactory, iqRouter, profileSettings_);
mucSearchController_->onMUCSelected.connect(boost::bind(&ChatsManager::handleMUCSelectedAfterSearch, this, _1));
ftOverview_->onNewFileTransferController.connect(boost::bind(&ChatsManager::handleNewFileTransferController, this, _1));
roster_->onJIDAdded.connect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
roster_->onJIDRemoved.connect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
roster_->onJIDUpdated.connect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
roster_->onRosterCleared.connect(boost::bind(&ChatsManager::handleRosterCleared, this));
settings_->onSettingChanged.connect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
+ userWantsReceipts_ = settings_->getSetting(SettingConstants::REQUEST_DELIVERYRECEIPTS);
+
setupBookmarks();
loadRecents();
}
ChatsManager::~ChatsManager() {
settings_->onSettingChanged.disconnect(boost::bind(&ChatsManager::handleSettingChanged, this, _1));
roster_->onJIDAdded.disconnect(boost::bind(&ChatsManager::handleJIDAddedToRoster, this, _1));
roster_->onJIDRemoved.disconnect(boost::bind(&ChatsManager::handleJIDRemovedFromRoster, this, _1));
roster_->onJIDUpdated.disconnect(boost::bind(&ChatsManager::handleJIDUpdatedInRoster, this, _1));
roster_->onRosterCleared.disconnect(boost::bind(&ChatsManager::handleRosterCleared, this));
delete joinMUCWindow_;
foreach (JIDChatControllerPair controllerPair, chatControllers_) {
delete controllerPair.second;
}
foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
delete controllerPair.second;
}
delete mucBookmarkManager_;
delete mucSearchController_;
}
void ChatsManager::saveRecents() {
std::string recents;
int i = 1;
foreach (ChatListWindow::Chat chat, recentChats_) {
std::vector<std::string> activity;
boost::split(activity, chat.activity, boost::is_any_of("\t\n"));
if (activity.empty()) {
/* Work around Boost bug https://svn.boost.org/trac/boost/ticket/4751 */
activity.push_back("");
}
std::string recent = chat.jid.toString() + "\t" + (eagleMode_ ? "" : activity[0]) + "\t" + (chat.isMUC ? "true" : "false") + "\t" + chat.nick;
recents += recent + "\n";
if (i++ > 25) {
break;
diff --git a/Swift/Controllers/SConscript b/Swift/Controllers/SConscript
index 02e212b..70085a6 100644
--- a/Swift/Controllers/SConscript
+++ b/Swift/Controllers/SConscript
@@ -52,36 +52,37 @@ if env["SCONS_STAGE"] == "build" :
"XMPPEvents/EventController.cpp",
"UIEvents/UIEvent.cpp",
"UIInterfaces/XMLConsoleWidget.cpp",
"UIInterfaces/ChatListWindow.cpp",
"PreviousStatusStore.cpp",
"ProfileSettingsProvider.cpp",
"Settings/SettingsProviderHierachy.cpp",
"Settings/XMLSettingsProvider.cpp",
"Storages/CertificateStorageFactory.cpp",
"Storages/CertificateStorage.cpp",
"Storages/CertificateFileStorage.cpp",
"Storages/CertificateMemoryStorage.cpp",
"Storages/AvatarFileStorage.cpp",
"Storages/FileStorages.cpp",
"Storages/RosterFileStorage.cpp",
"Storages/CapsFileStorage.cpp",
"Storages/VCardFileStorage.cpp",
"StatusUtil.cpp",
"Translator.cpp",
"XMPPURIController.cpp",
"ChatMessageSummarizer.cpp",
"SettingConstants.cpp"
])
env.Append(UNITTEST_SOURCES = [
File("Roster/UnitTest/RosterControllerTest.cpp"),
File("Roster/UnitTest/RosterTest.cpp"),
File("Roster/UnitTest/LeastCommonSubsequenceTest.cpp"),
File("Roster/UnitTest/TableRosterTest.cpp"),
File("UnitTest/PreviousStatusStoreTest.cpp"),
File("UnitTest/PresenceNotifierTest.cpp"),
File("Chat/UnitTest/ChatsManagerTest.cpp"),
File("Chat/UnitTest/MUCControllerTest.cpp"),
File("UnitTest/MockChatWindow.cpp"),
File("UnitTest/ChatMessageSummarizerTest.cpp"),
+ File("Settings/UnitTest/SettingsProviderHierachyTest.cpp"),
])
diff --git a/Swift/Controllers/Settings/DummySettingsProvider.h b/Swift/Controllers/Settings/DummySettingsProvider.h
index bb7d2e6..1d6059f 100644
--- a/Swift/Controllers/Settings/DummySettingsProvider.h
+++ b/Swift/Controllers/Settings/DummySettingsProvider.h
@@ -7,46 +7,53 @@
#pragma once
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <map>
namespace Swift {
class DummySettingsProvider : public SettingsProvider {
public:
virtual ~DummySettingsProvider() {}
virtual std::string getSetting(const Setting<std::string>& setting) {
return stringValues.find(setting.getKey()) != stringValues.end() ? stringValues[setting.getKey()] : setting.getDefaultValue();
};
virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) {
stringValues[setting.getKey()] = value;
onSettingChanged(setting.getKey());
};
virtual bool getSetting(const Setting<bool>& setting) {
return boolValues.find(setting.getKey()) != boolValues.end() ? boolValues[setting.getKey()] : setting.getDefaultValue();
};
virtual void storeSetting(const Setting<bool>& setting, const bool& value) {
boolValues[setting.getKey()] = value;
onSettingChanged(setting.getKey());
};
virtual int getSetting(const Setting<int>& setting) {
return intValues.find(setting.getKey()) != intValues.end() ? intValues[setting.getKey()] : setting.getDefaultValue();
};
virtual void storeSetting(const Setting<int>& setting, const int& value) {
intValues[setting.getKey()] = value;
onSettingChanged(setting.getKey());
};
virtual std::vector<std::string> getAvailableProfiles() {return std::vector<std::string>();}
virtual void createProfile(const std::string& ) {}
virtual void removeProfile(const std::string& ) {}
- virtual bool getIsSettingFinal(const std::string& ) {return false;}
+ virtual bool getIsSettingFinal(const std::string& settingPath) {return finals.count(settingPath);}
+ void setFinal(const std::string& settingPath) {
+ finals.insert(settingPath);
+ }
+ virtual bool hasSetting(const std::string& key) {
+ return stringValues.find(key) != stringValues.end() || intValues.find(key) != intValues.end() || boolValues.find(key) != boolValues.end();
+ }
private:
std::map<std::string, std::string> stringValues;
std::map<std::string, int> intValues;
std::map<std::string, bool> boolValues;
+ std::set<std::string> finals;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProvider.h b/Swift/Controllers/Settings/SettingsProvider.h
index e884add..458653b 100644
--- a/Swift/Controllers/Settings/SettingsProvider.h
+++ b/Swift/Controllers/Settings/SettingsProvider.h
@@ -23,51 +23,52 @@ class SettingsProvider {
}
const std::string& getKey() const {
return key;
}
const T& getDefaultValue() const {
return defaultValue;
}
private:
std::string key;
T defaultValue;
};
public:
virtual ~SettingsProvider() {}
virtual std::string getSetting(const Setting<std::string>& setting) = 0;
virtual void storeSetting(const Setting<std::string>& setting, const std::string& value) = 0;
virtual bool getSetting(const Setting<bool>& setting) = 0;
virtual void storeSetting(const Setting<bool>& setting, const bool& value) = 0;
virtual int getSetting(const Setting<int>& setting) = 0;
virtual void storeSetting(const Setting<int>& setting, const int& value) = 0;
virtual std::vector<std::string> getAvailableProfiles() = 0;
virtual void createProfile(const std::string& profile) = 0;
virtual void removeProfile(const std::string& profile) = 0;
/** A final setting is one that this settings provider says may not be overriden by lower priority profiles.
* e.g. An Administrator-set configuration to disallow saving user passwords could not be overridden by the user.
*/
template<typename T>
bool getIsSettingFinal(const Setting<T>& setting) {
return getIsSettingFinal(setting.getKey());
}
+ virtual bool hasSetting(const std::string& key) = 0;
friend class SettingsProviderHierachy;
protected:
virtual bool getIsSettingFinal(const std::string& settingPath) = 0;
public:
/**
* Emitted when a setting is changed.
*/
boost::signal<void (const std::string& /*Setting's Path*/)> onSettingChanged;
};
}
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
index 3b7d13c..40a9025 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.cpp
@@ -1,90 +1,111 @@
/*
* Copyright (c) 2012 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
#include <Swiften/Base/foreach.h>
#include <Swiften/Base/Log.h>
namespace Swift {
SettingsProviderHierachy::~SettingsProviderHierachy() {
}
+bool SettingsProviderHierachy::hasSetting(const std::string& key) {
+ foreach (SettingsProvider* provider, providers_) {
+ if (provider->hasSetting(key)) {
+ return true;
+ }
+ }
+ return false;
+}
+
std::string SettingsProviderHierachy::getSetting(const Setting<std::string>& setting) {
+ std::string value = setting.getDefaultValue();
foreach (SettingsProvider* provider, providers_) {
std::string providerSetting = provider->getSetting(setting);
- if (providerSetting != setting.getDefaultValue()) {
- return providerSetting;
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ }
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return value;
}
}
- return setting.getDefaultValue();
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<std::string>& setting, const std::string& settingValue) {
if (!getIsSettingFinal(setting.getKey())) {
getWritableProvider()->storeSetting(setting, settingValue);
}
}
bool SettingsProviderHierachy::getSetting(const Setting<bool>& setting) {
+ bool value = setting.getDefaultValue();
foreach (SettingsProvider* provider, providers_) {
bool providerSetting = provider->getSetting(setting);
- if (providerSetting != setting.getDefaultValue()) {
- return providerSetting;
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
}
}
- return setting.getDefaultValue();
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<bool>& setting, const bool& settingValue) {
if (!getIsSettingFinal(setting.getKey())) {
getWritableProvider()->storeSetting(setting, settingValue);
}
}
int SettingsProviderHierachy::getSetting(const Setting<int>& setting) {
+ int value = setting.getDefaultValue();
foreach (SettingsProvider* provider, providers_) {
int providerSetting = provider->getSetting(setting);
- if (providerSetting != setting.getDefaultValue()) {
- return providerSetting;
+ if (provider->hasSetting(setting.getKey())) {
+ value = providerSetting;
+ if (provider->getIsSettingFinal(setting.getKey())) {
+ return providerSetting;
+ }
}
}
- return setting.getDefaultValue();
+ return value;
}
void SettingsProviderHierachy::storeSetting(const Setting<int>& setting, const int& settingValue) {
if (!getIsSettingFinal(setting.getKey())) {
getWritableProvider()->storeSetting(setting, settingValue);
}
}
std::vector<std::string> SettingsProviderHierachy::getAvailableProfiles() {
/* Always pull profiles from the topmost */
return getWritableProvider()->getAvailableProfiles();
}
void SettingsProviderHierachy::createProfile(const std::string& profile) {
return getWritableProvider()->createProfile(profile);
}
void SettingsProviderHierachy::removeProfile(const std::string& profile) {
return getWritableProvider()->removeProfile(profile);
}
bool SettingsProviderHierachy::getIsSettingFinal(const std::string& settingPath) {
bool isFinal = false;
foreach (SettingsProvider* provider, providers_) {
isFinal |= provider->getIsSettingFinal(settingPath);
}
return isFinal;
}
SettingsProvider* SettingsProviderHierachy::getWritableProvider() {
return providers_.back();
}
void SettingsProviderHierachy::addProviderToTopOfStack(SettingsProvider* provider) {
providers_.push_back(provider);
diff --git a/Swift/Controllers/Settings/SettingsProviderHierachy.h b/Swift/Controllers/Settings/SettingsProviderHierachy.h
index b7f6961..b16b33e 100644
--- a/Swift/Controllers/Settings/SettingsProviderHierachy.h
+++ b/Swift/Controllers/Settings/SettingsProviderHierachy.h
@@ -1,46 +1,47 @@
/*
* Copyright (c) 2012 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
class SettingsProviderHierachy : public SettingsProvider {
public:
virtual ~SettingsProviderHierachy();
virtual std::string getSetting(const Setting<std::string>& setting);
virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
virtual bool getSetting(const Setting<bool>& setting);
virtual void storeSetting(const Setting<bool>& setting, const bool& value);
virtual int getSetting(const Setting<int>& setting);
virtual void storeSetting(const Setting<int>& setting, const int& value);
virtual std::vector<std::string> getAvailableProfiles();
virtual void createProfile(const std::string& profile);
virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
protected:
virtual bool getIsSettingFinal(const std::string& settingPath);
public:
/**
* Adds a provider less significant than any already added.
* This means that if an existing provider has a setting, this provider won't be asked.
* Any settings will be pushed into the topmost (least significant) provider.
* Does not take ownership of provider.
*/
void addProviderToTopOfStack(SettingsProvider* provider);
private:
SettingsProvider* getWritableProvider();
private:
/* Start/Left is most significant (lowest), left overrides right.*/
std::vector<SettingsProvider*> providers_;
};
}
diff --git a/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
new file mode 100644
index 0000000..aa4d14f
--- /dev/null
+++ b/Swift/Controllers/Settings/UnitTest/SettingsProviderHierachyTest.cpp
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2012 Kevin Smith
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swift/Controllers/Settings/SettingsProviderHierachy.h>
+#include <Swift/Controllers/Settings/DummySettingsProvider.h>
+#include <Swift/Controllers/Settings/XMLSettingsProvider.h>
+
+using namespace Swift;
+using namespace std;
+
+class SettingsProviderHierachyTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(SettingsProviderHierachyTest);
+ CPPUNIT_TEST(testEmpty);
+ CPPUNIT_TEST(testTop);
+ CPPUNIT_TEST(testBottom);
+ CPPUNIT_TEST(testBoth);
+ CPPUNIT_TEST(testTopDefault);
+ CPPUNIT_TEST(testBottomOverrides);
+ CPPUNIT_TEST(testFinal);
+ CPPUNIT_TEST_SUITE_END();
+
+public:
+ SettingsProviderHierachyTest() : setting1("somekey", 42) {};
+
+ void setUp() {
+ bottom = new DummySettingsProvider();
+ top = new DummySettingsProvider();
+ testling = new SettingsProviderHierachy();
+ testling->addProviderToTopOfStack(bottom);
+ testling->addProviderToTopOfStack(top);
+ }
+
+ void tearDown() {
+ delete testling;
+ delete top;
+ delete bottom;
+ }
+
+ void testEmpty() {
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
+
+ void testTop() {
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
+
+ void testBottom() {
+ bottom->storeSetting(setting1, 17);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
+
+ void testBoth() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 37);
+ CPPUNIT_ASSERT_EQUAL(37, testling->getSetting(setting1));
+ }
+
+ void testTopDefault() {
+ bottom->storeSetting(setting1, 17);
+ top->storeSetting(setting1, 42);
+ CPPUNIT_ASSERT_EQUAL(42, testling->getSetting(setting1));
+ }
+
+ void testBottomOverrides() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ top->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
+
+ void testFinal() {
+ bottom->storeSetting(setting1, 17);
+ bottom->setFinal(setting1.getKey());
+ testling->storeSetting(setting1, 5);
+ CPPUNIT_ASSERT_EQUAL(17, testling->getSetting(setting1));
+ }
+private:
+ SettingsProviderHierachy* testling;
+ DummySettingsProvider* bottom;
+ DummySettingsProvider* top;
+ SettingsProvider::Setting<int> setting1;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SettingsProviderHierachyTest);
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.cpp b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
index 3710072..e83ed24 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.cpp
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.cpp
@@ -4,70 +4,75 @@
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <Swift/Controllers/Settings/XMLSettingsProvider.h>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <Swiften/Parser/PlatformXMLParserFactory.h>
#include <Swiften/Parser/XMLParser.h>
#include <Swiften/Base/Log.h>
namespace Swift {
XMLSettingsProvider::XMLSettingsProvider(const std::string& xmlConfig) : level_(0) {
if (!xmlConfig.empty()) {
PlatformXMLParserFactory factory;
XMLParser* parser = factory.createXMLParser(this);
if (parser->parse(xmlConfig)) {
SWIFT_LOG(debug) << "Found and parsed system config" << std::endl;
}
else {
SWIFT_LOG(debug) << "Found invalid system config" << std::endl;
}
delete parser;
}
else {
SWIFT_LOG(debug) << "No system config found" << std::endl;
}
}
XMLSettingsProvider::~XMLSettingsProvider() {
}
+bool XMLSettingsProvider::hasSetting(const std::string& key) {
+ return (values_.find(key) != values_.end());
+}
+
+
std::string XMLSettingsProvider::getSetting(const Setting<std::string>& setting) {
if (values_.find(setting.getKey()) != values_.end()) {
std::string value = values_[setting.getKey()];
return value;
}
return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<std::string>& /*settingPath*/, const std::string& /*settingValue*/) {
assert(false);
}
bool XMLSettingsProvider::getSetting(const Setting<bool>& setting) {
if (values_.find(setting.getKey()) != values_.end()) {
std::string value = values_[setting.getKey()];
return boost::iequals(value, "true") || value == "1";
}
return setting.getDefaultValue();
}
void XMLSettingsProvider::storeSetting(const Setting<bool>& /*settingPath*/, const bool& /*settingValue*/) {
assert(false);
}
int XMLSettingsProvider::getSetting(const Setting<int>& setting) {
if (values_.find(setting.getKey()) != values_.end()) {
std::string value = values_[setting.getKey()];
try {
return value.empty() ? setting.getDefaultValue() : boost::lexical_cast<int>(value);;
}
catch(boost::bad_lexical_cast &) {}
}
return setting.getDefaultValue();
}
diff --git a/Swift/Controllers/Settings/XMLSettingsProvider.h b/Swift/Controllers/Settings/XMLSettingsProvider.h
index 61abd11..e03d3c1 100644
--- a/Swift/Controllers/Settings/XMLSettingsProvider.h
+++ b/Swift/Controllers/Settings/XMLSettingsProvider.h
@@ -1,56 +1,58 @@
/*
* Copyright (c) 2012 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <Swiften/Parser/XMLParserClient.h>
#include <map>
#include <set>
namespace Swift {
class XMLSettingsProvider : public SettingsProvider, public XMLParserClient {
public:
XMLSettingsProvider(const std::string& xmlConfig);
virtual ~XMLSettingsProvider();
virtual std::string getSetting(const Setting<std::string>& setting);
virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
virtual bool getSetting(const Setting<bool>& setting);
virtual void storeSetting(const Setting<bool>& setting, const bool& value);
virtual int getSetting(const Setting<int>& setting);
virtual void storeSetting(const Setting<int>& setting, const int& value);
virtual std::vector<std::string> getAvailableProfiles();
virtual void createProfile(const std::string& profile);
virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
+
virtual void handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes);
virtual void handleEndElement(const std::string& element, const std::string& ns);
virtual void handleCharacterData(const std::string& data);
protected:
virtual bool getIsSettingFinal(const std::string& settingPath);
private:
std::map<std::string /*settingPath*/, std::string /*settingValue*/> values_;
/* Settings that are final*/
std::set<std::string /*settingPath*/> finals_;
enum Level {
TopLevel = 0,
SettingLevel = 2
};
int level_;
std::string currentElement_;
std::string currentText_;
};
}
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index 0c4d49b..64e88d4 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -1,55 +1,60 @@
/*
* 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 <QStringList>
#include <QFile>
namespace Swift {
QtSettingsProvider::QtSettingsProvider() {
}
QtSettingsProvider::~QtSettingsProvider() {
}
+bool QtSettingsProvider::hasSetting(const std::string& key) {
+ return !settings_.value(key.c_str()).isNull();
+}
+
+
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::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::getSetting(const Setting<bool>& setting) {
QVariant variant = settings_.value(setting.getKey().c_str());
return variant.isNull() ? setting.getDefaultValue() : variant.toBool();
}
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::getSetting(const Setting<int>& setting) {
diff --git a/Swift/QtUI/QtSettingsProvider.h b/Swift/QtUI/QtSettingsProvider.h
index ececa6e..e85bfb5 100644
--- a/Swift/QtUI/QtSettingsProvider.h
+++ b/Swift/QtUI/QtSettingsProvider.h
@@ -1,43 +1,44 @@
/*
* Copyright (c) 2010-2012 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <Swift/Controllers/Settings/SettingsProvider.h>
#include <QSettings>
namespace Swift {
class QtSettingsProvider : public SettingsProvider {
public:
QtSettingsProvider();
virtual ~QtSettingsProvider();
virtual std::string getSetting(const Setting<std::string>& setting);
virtual void storeSetting(const Setting<std::string>& setting, const std::string& value);
virtual bool getSetting(const Setting<bool>& setting);
virtual void storeSetting(const Setting<bool>& setting, const bool& value);
virtual int getSetting(const Setting<int>& setting);
virtual void storeSetting(const Setting<int>& setting, const int& value);
virtual std::vector<std::string> getAvailableProfiles();
virtual void createProfile(const std::string& profile);
virtual void removeProfile(const std::string& profile);
+ virtual bool hasSetting(const std::string& key);
QSettings* getQSettings();
protected:
virtual bool getIsSettingFinal(const std::string& settingPath);
private:
void updatePermissions();
private:
QSettings settings_;
};
}
diff --git a/Swiften/Client/CoreClient.h b/Swiften/Client/CoreClient.h
index 1b875d2..c9a6f30 100644
--- a/Swiften/Client/CoreClient.h
+++ b/Swiften/Client/CoreClient.h
@@ -170,71 +170,69 @@ namespace Swift {
*/
boost::signal<void (const SafeByteArray&)> onDataWritten;
/**
* Emitted when a message is received.
*/
boost::signal<void (boost::shared_ptr<Message>)> onMessageReceived;
/**
* Emitted when a presence stanza is received.
*/
boost::signal<void (boost::shared_ptr<Presence>) > onPresenceReceived;
/**
* Emitted when the server acknowledges receipt of a
* stanza (if acknowledgements are available).
*
* \see getStreamManagementEnabled()
*/
boost::signal<void (boost::shared_ptr<Stanza>)> onStanzaAcked;
protected:
boost::shared_ptr<ClientSession> getSession() const {
return session_;
}
NetworkFactories* getNetworkFactories() const {
return networkFactories;
}
/**
* Called before onConnected signal is emmitted.
*/
virtual void handleConnected() {};
- bool isCAPIURI();
-
private:
void handleConnectorFinished(boost::shared_ptr<Connection>);
void handleStanzaChannelAvailableChanged(bool available);
void handleSessionFinished(boost::shared_ptr<Error>);
void handleNeedCredentials();
void handleDataRead(const SafeByteArray&);
void handleDataWritten(const SafeByteArray&);
void handlePresenceReceived(boost::shared_ptr<Presence>);
void handleMessageReceived(boost::shared_ptr<Message>);
void handleStanzaAcked(boost::shared_ptr<Stanza>);
void purgePassword();
void bindSessionToStream();
void resetConnector();
void resetSession();
void forceReset();
private:
JID jid_;
SafeByteArray password_;
NetworkFactories* networkFactories;
ClientSessionStanzaChannel* stanzaChannel_;
IQRouter* iqRouter_;
ClientOptions options;
boost::shared_ptr<ChainedConnector> connector_;
std::vector<ConnectionFactory*> proxyConnectionFactories;
boost::shared_ptr<Connection> connection_;
boost::shared_ptr<SessionStream> sessionStream_;
boost::shared_ptr<ClientSession> session_;
CertificateWithKey::ref certificate_;
bool disconnectRequested_;
CertificateTrustChecker* certificateTrustChecker;
};
}