summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2009-09-12 21:13:01 (GMT)
committerKevin Smith <git@kismith.co.uk>2009-09-12 21:13:01 (GMT)
commit6bc9ff75b3971cc8d1c610bc348279be89c95d9d (patch)
treecea1010530fb6c0fbc4235f926d5effc8235f023 /Swift/Controllers
parent7dafb815ca404f1e15c9cdf6b26817c941dae4ec (diff)
downloadswift-contrib-6bc9ff75b3971cc8d1c610bc348279be89c95d9d.zip
swift-contrib-6bc9ff75b3971cc8d1c610bc348279be89c95d9d.tar.bz2
Allow storing of settings for multiple profiles.
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/LoginWindow.h2
-rw-r--r--Swift/Controllers/LoginWindowFactory.h2
-rw-r--r--Swift/Controllers/MainController.cpp17
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.h33
4 files changed, 47 insertions, 7 deletions
diff --git a/Swift/Controllers/LoginWindow.h b/Swift/Controllers/LoginWindow.h
index 44855c0..bab505b 100644
--- a/Swift/Controllers/LoginWindow.h
+++ b/Swift/Controllers/LoginWindow.h
@@ -14,7 +14,7 @@ namespace Swift {
virtual void morphInto(MainWindow *mainWindow) = 0;
virtual void loggedOut() = 0;
virtual void setMessage(const String&) = 0;
-
+ virtual void addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) = 0;
boost::signal<void (const String&, const String&, const String& /* certificateFile */, bool)> onLoginRequest;
};
}
diff --git a/Swift/Controllers/LoginWindowFactory.h b/Swift/Controllers/LoginWindowFactory.h
index 3edd200..79ad5c0 100644
--- a/Swift/Controllers/LoginWindowFactory.h
+++ b/Swift/Controllers/LoginWindowFactory.h
@@ -14,7 +14,7 @@ namespace Swift {
/**
* Transfers ownership of result.
*/
- virtual LoginWindow* createLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) = 0;
+ virtual LoginWindow* createLoginWindow() = 0;
};
}
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 6bed7da..15ca5f4 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -16,6 +16,7 @@
#include "Swift/Controllers/MainWindowFactory.h"
#include "Swift/Controllers/MUCController.h"
#include "Swift/Controllers/NickResolver.h"
+#include "Swift/Controllers/ProfileSettingsProvider.h"
#include "Swift/Controllers/RosterController.h"
#include "Swift/Controllers/SoundEventController.h"
#include "Swift/Controllers/SoundPlayer.h"
@@ -71,7 +72,12 @@ MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowF
eventController_->onEventQueueLengthChange.connect(boost::bind(&MainController::handleEventQueueLengthChange, this, _1));
systemTrayController_ = new SystemTrayController(eventController_, systemTray);
soundEventController_ = new SoundEventController(eventController_, soundPlayer, settings->getBoolSetting("playSounds", true));
- loginWindow_ = loginWindowFactory_->createLoginWindow(settings->getStringSetting("jid"), settings->getStringSetting("pass"), settings->getStringSetting("certificate"));
+ loginWindow_ = loginWindowFactory_->createLoginWindow();
+ foreach (String profile, settings->getAvailableProfiles()) {
+ ProfileSettingsProvider* profileSettings = new ProfileSettingsProvider(profile, settings);
+ loginWindow_->addAvailableAccount(profileSettings->getStringSetting("jid"), profileSettings->getStringSetting("pass"), profileSettings->getStringSetting("certificate"));
+ delete profileSettings;
+ }
loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4));
}
@@ -190,10 +196,11 @@ void MainController::handleIncomingPresence(boost::shared_ptr<Presence> presence
void MainController::handleLoginRequest(const String &username, const String &password, const String& certificateFile, bool remember) {
loginWindow_->setMessage("");
-
- settings_->storeString("jid", username);
- settings_->storeString("certificate", certificateFile);
- settings_->storeString("pass", remember ? password : "");
+ ProfileSettingsProvider* profileSettings = new ProfileSettingsProvider(username, settings_);
+ profileSettings->storeString("jid", username);
+ profileSettings->storeString("certificate", certificateFile);
+ profileSettings->storeString("pass", remember ? password : "");
+ delete profileSettings;
resetClient();
diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h
new file mode 100644
index 0000000..c485418
--- /dev/null
+++ b/Swift/Controllers/ProfileSettingsProvider.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "Swiften/Settings/SettingsProvider.h"
+
+namespace Swift {
+
+class ProfileSettingsProvider {
+ public:
+ ProfileSettingsProvider(const String& profile, SettingsProvider* provider) : profile_(profile) {
+ provider_ = provider;
+ bool found = false;
+ foreach (String existingProfile, provider->getAvailableProfiles()) {
+ if (existingProfile == profile) {
+ found = true;
+ }
+ }
+ if (!found) {
+ provider_->createProfile(profile);
+ }
+ };
+ virtual ~ProfileSettingsProvider() {};
+ virtual String getStringSetting(const String &settingPath) {return provider_->getStringSetting(profileSettingPath(settingPath));};
+ virtual void storeString(const String &settingPath, const String &settingValue) {provider_->storeString(profileSettingPath(settingPath), settingValue);};
+
+ private:
+ String profileSettingPath(const String &settingPath) {return profile_ + ":" + settingPath;};
+ SettingsProvider* provider_;
+ String profile_;
+};
+
+}
+
+