summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--Swift/QtUI/QtLoginWindow.cpp23
-rw-r--r--Swift/QtUI/QtLoginWindow.h4
-rw-r--r--Swift/QtUI/QtLoginWindowFactory.cpp4
-rw-r--r--Swift/QtUI/QtLoginWindowFactory.h2
-rw-r--r--Swift/QtUI/QtSettingsProvider.cpp17
-rw-r--r--Swift/QtUI/QtSettingsProvider.h2
-rw-r--r--Swiften/Settings/SettingsProvider.h4
11 files changed, 87 insertions, 23 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_;
+};
+
+}
+
+
diff --git a/Swift/QtUI/QtLoginWindow.cpp b/Swift/QtUI/QtLoginWindow.cpp
index 62e0484..d25f732 100644
--- a/Swift/QtUI/QtLoginWindow.cpp
+++ b/Swift/QtUI/QtLoginWindow.cpp
@@ -16,7 +16,7 @@
namespace Swift{
-QtLoginWindow::QtLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) : QMainWindow() {
+QtLoginWindow::QtLoginWindow() : QMainWindow() {
setWindowTitle("Swift");
resize(200, 500);
setContentsMargins(0,0,0,0);
@@ -58,10 +58,7 @@ QtLoginWindow::QtLoginWindow(const String& defaultJID, const String& defaultPass
certificateButton_ = new QToolButton(this);
certificateButton_->setCheckable(true);
certificateButton_->setIcon(QIcon(":/icons/certificate.png"));
- certificateFile_ = P2QSTRING(defaultCertificate);
- if (!certificateFile_.isEmpty()) {
- certificateButton_->setChecked(true);
- }
+
credentialsLayout->addWidget(certificateButton_);
connect(certificateButton_, SIGNAL(clicked(bool)), SLOT(handleCertficateChecked(bool)));
@@ -71,9 +68,6 @@ QtLoginWindow::QtLoginWindow(const String& defaultJID, const String& defaultPass
loginButton_->setDefault(true);
layout->addWidget(loginButton_);
- username_->setText(P2QSTRING(defaultJID));
- password_->setText(P2QSTRING(defaultPassword));
-
message_ = new QLabel(this);
message_->setTextFormat(Qt::RichText);
message_->setWordWrap(true);
@@ -81,7 +75,6 @@ QtLoginWindow::QtLoginWindow(const String& defaultJID, const String& defaultPass
layout->addStretch();
remember_ = new QCheckBox(tr("Remember Password?"), this);
- remember_->setChecked(defaultPassword != "");
layout->addWidget(remember_);
connect(loginButton_, SIGNAL(clicked()), SLOT(loginClicked()));
stack_->addWidget(wrapperWidget);
@@ -102,12 +95,20 @@ QtLoginWindow::QtLoginWindow(const String& defaultJID, const String& defaultPass
connect(quitAction, SIGNAL(activated()), SLOT(handleQuit()));
swiftMenu_->addAction(quitAction);
-
-
setInitialMenus();
this->show();
}
+void QtLoginWindow::addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) {
+ username_->setText(P2QSTRING(defaultJID));
+ password_->setText(P2QSTRING(defaultPassword));
+ certificateFile_ = P2QSTRING(defaultCertificate);
+ if (!certificateFile_.isEmpty()) {
+ certificateButton_->setChecked(true);
+ }
+ remember_->setChecked(defaultPassword != "");
+}
+
void QtLoginWindow::loggedOut() {
if (stack_->count() > 1) {
QWidget* current = stack_->currentWidget();
diff --git a/Swift/QtUI/QtLoginWindow.h b/Swift/QtUI/QtLoginWindow.h
index 153f757..a4ec606 100644
--- a/Swift/QtUI/QtLoginWindow.h
+++ b/Swift/QtUI/QtLoginWindow.h
@@ -20,12 +20,12 @@ namespace Swift {
class QtLoginWindow : public QMainWindow, public LoginWindow {
Q_OBJECT
public:
- QtLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate);
+ QtLoginWindow();
void morphInto(MainWindow *mainWindow);
virtual void loggedOut();
virtual void setMessage(const String& message);
-
+ virtual void addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate);
private slots:
void loginClicked();
void handleCertficateChecked(bool);
diff --git a/Swift/QtUI/QtLoginWindowFactory.cpp b/Swift/QtUI/QtLoginWindowFactory.cpp
index 2405dd6..e351f43 100644
--- a/Swift/QtUI/QtLoginWindowFactory.cpp
+++ b/Swift/QtUI/QtLoginWindowFactory.cpp
@@ -8,8 +8,8 @@ QtLoginWindowFactory::QtLoginWindowFactory(QSplitter* splitter, QtSystemTray* sy
systemTray_ = systemTray;
}
-LoginWindow* QtLoginWindowFactory::createLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) {
- QtLoginWindow* window = new QtLoginWindow(defaultJID, defaultPassword, defaultCertificate);
+LoginWindow* QtLoginWindowFactory::createLoginWindow() {
+ QtLoginWindow* window = new QtLoginWindow();
if (splitter_) {
splitter_->insertWidget(0, window);
}
diff --git a/Swift/QtUI/QtLoginWindowFactory.h b/Swift/QtUI/QtLoginWindowFactory.h
index 7513ab6..0ae8284 100644
--- a/Swift/QtUI/QtLoginWindowFactory.h
+++ b/Swift/QtUI/QtLoginWindowFactory.h
@@ -11,7 +11,7 @@ namespace Swift {
Q_OBJECT
public:
QtLoginWindowFactory(QSplitter* splitter, QtSystemTray* systemTray);
- LoginWindow* createLoginWindow(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate);
+ LoginWindow* createLoginWindow();
private:
QSplitter* splitter_;
QtSystemTray* systemTray_;
diff --git a/Swift/QtUI/QtSettingsProvider.cpp b/Swift/QtUI/QtSettingsProvider.cpp
index cf02d83..7012288 100644
--- a/Swift/QtUI/QtSettingsProvider.cpp
+++ b/Swift/QtUI/QtSettingsProvider.cpp
@@ -1,6 +1,8 @@
#include "QtSettingsProvider.h"
#include "QtSwiftUtil.h"
+#include <QStringList>
+
namespace Swift {
QtSettingsProvider::QtSettingsProvider() {
@@ -28,5 +30,20 @@ void QtSettingsProvider::storeBool(const String &settingPath, bool settingValue)
settings_.setValue(P2QSTRING(settingPath), settingValue);
}
+std::vector<String> QtSettingsProvider::getAvailableProfiles() {
+ std::vector<String> profiles;
+ QVariant profilesVariant = settings_.value("profileList");
+ foreach(QString profileQString, profilesVariant.toStringList()) {
+ profiles.push_back(Q2PSTRING(profileQString));
+ }
+ return profiles;
+}
+
+void QtSettingsProvider::createProfile(const String& profile) {
+ QStringList stringList = settings_.value("profileList").toStringList();
+ stringList.append(P2QSTRING(profile));
+ settings_.setValue("profileList", stringList);
+}
+
}
diff --git a/Swift/QtUI/QtSettingsProvider.h b/Swift/QtUI/QtSettingsProvider.h
index fec4101..a8d5bcc 100644
--- a/Swift/QtUI/QtSettingsProvider.h
+++ b/Swift/QtUI/QtSettingsProvider.h
@@ -15,6 +15,8 @@ class QtSettingsProvider : public SettingsProvider {
virtual void storeString(const String &settingPath, const String &settingValue);
virtual bool getBoolSetting(const String &settingPath, bool defaultValue);
virtual void storeBool(const String &settingPath, bool settingValue);
+ virtual std::vector<String> getAvailableProfiles();
+ virtual void createProfile(const String& profile);
private:
QSettings settings_;
};
diff --git a/Swiften/Settings/SettingsProvider.h b/Swiften/Settings/SettingsProvider.h
index e311911..d07e790 100644
--- a/Swiften/Settings/SettingsProvider.h
+++ b/Swiften/Settings/SettingsProvider.h
@@ -3,6 +3,8 @@
#include "Swiften/Base/String.h"
+#include <vector>
+
namespace Swift {
class SettingsProvider {
@@ -12,6 +14,8 @@ class SettingsProvider {
virtual void storeString(const String &settingPath, const String &settingValue) = 0;
virtual bool getBoolSetting(const String &settingPath, bool defaultValue) = 0;
virtual void storeBool(const String &settingPath, bool settingValue) = 0;
+ virtual std::vector<String> getAvailableProfiles() = 0;
+ virtual void createProfile(const String& profile) = 0;
};
}