summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/MainController.cpp28
-rw-r--r--Swift/Controllers/MainController.h2
-rw-r--r--Swift/Controllers/ProfileSettingsProvider.h2
3 files changed, 23 insertions, 9 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 5502640..b267dd2 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -28,7 +28,6 @@
#include "Swift/Controllers/UIInterfaces/MainWindow.h"
#include "Swift/Controllers/Chat/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"
@@ -122,8 +121,8 @@ MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowF
idleDetector_.onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
xmlConsoleController_ = new XMLConsoleController(uiEventStream_, xmlConsoleWidgetFactory);
-
if (loginAutomatically) {
+ profileSettings_ = new ProfileSettingsProvider(selectedLoginJID, settings_);
handleLoginRequest(selectedLoginJID, cachedPassword, cachedCertificate, true, true);
}
}
@@ -169,6 +168,8 @@ void MainController::resetClient() {
mucSearchController_ = NULL;
delete statusTracker_;
statusTracker_ = NULL;
+ delete profileSettings_;
+ profileSettings_ = NULL;
}
void MainController::resetPendingReconnects() {
@@ -231,7 +232,6 @@ void MainController::handleConnected() {
serverDiscoInfo_ = boost::shared_ptr<DiscoInfo>(new DiscoInfo());
mucSearchController_ = new MUCSearchController(jid_, uiEventStream_, mucSearchWindowFactory_, client_);
- statusTracker_ = new StatusTracker();
}
boost::shared_ptr<GetDiscoInfoRequest> discoInfoRequest(new GetDiscoInfoRequest(JID(), client_));
@@ -271,6 +271,10 @@ void MainController::handleChangeStatusRequest(StatusShow::Type show, const Stri
}
presence->setStatus(statusText);
statusTracker_->setRequestedPresence(presence);
+ if (presence->getType() != Presence::Unavailable) {
+ profileSettings_->storeInt("lastShow", presence->getShow());
+ profileSettings_->storeString("lastStatus", presence->getStatus());
+ }
if (presence->getType() != Presence::Unavailable && !client_->isAvailable()) {
performLoginFromCachedCredentials();
} else {
@@ -317,14 +321,13 @@ void MainController::handleInputIdleChanged(bool idle) {
void MainController::handleLoginRequest(const String &username, const String &password, const String& certificateFile, bool remember, bool loginAutomatically) {
loginWindow_->setMessage("");
loginWindow_->setIsLoggingIn(true);
- ProfileSettingsProvider* profileSettings = new ProfileSettingsProvider(username, settings_);
- profileSettings->storeString("jid", username);
- profileSettings->storeString("certificate", certificateFile);
- profileSettings->storeString("pass", (remember || loginAutomatically) ? password : "");
+ profileSettings_ = new ProfileSettingsProvider(username, settings_);
+ profileSettings_->storeString("jid", username);
+ profileSettings_->storeString("certificate", certificateFile);
+ profileSettings_->storeString("pass", (remember || loginAutomatically) ? password : "");
settings_->storeString("lastLoginJID", username);
settings_->storeBool("loginAutomatically", loginAutomatically);
- loginWindow_->addAvailableAccount(profileSettings->getStringSetting("jid"), profileSettings->getStringSetting("pass"), profileSettings->getStringSetting("certificate"));
- delete profileSettings;
+ loginWindow_->addAvailableAccount(profileSettings_->getStringSetting("jid"), profileSettings_->getStringSetting("pass"), profileSettings_->getStringSetting("certificate"));
jid_ = JID(username);
password_ = password;
certificateFile_ = certificateFile;
@@ -332,6 +335,9 @@ void MainController::handleLoginRequest(const String &username, const String &pa
}
void MainController::performLoginFromCachedCredentials() {
+ if (!statusTracker_) {
+ statusTracker_ = new StatusTracker();
+ }
if (!client_) {
client_ = new Swift::Client(jid_, password_);
presenceSender_ = new PresenceSender(client_);
@@ -344,6 +350,10 @@ void MainController::performLoginFromCachedCredentials() {
}
client_->onError.connect(boost::bind(&MainController::handleError, this, _1));
client_->onConnected.connect(boost::bind(&MainController::handleConnected, this));
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setShow(static_cast<StatusShow::Type>(profileSettings_->getIntSetting("lastShow", StatusShow::Online)));
+ presence->setStatus(profileSettings_->getStringSetting("lastStatus"));
+ statusTracker_->setRequestedPresence(presence);
} else {
/* In case we're in the middle of another login, make sure they don't overlap */
client_->disconnect();
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index 36fe59d..e220211 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -22,6 +22,7 @@
#include "Swiften/Elements/ErrorPayload.h"
#include "Swiften/Elements/Presence.h"
#include "Swiften/Settings/SettingsProvider.h"
+#include "Swift/Controllers/ProfileSettingsProvider.h"
#include "Swiften/Elements/CapsInfo.h"
#include "Swiften/Events/ErrorEvent.h"
#include "Swiften/Roster/XMPPRoster.h"
@@ -102,6 +103,7 @@ namespace Swift {
LoginWindowFactory* loginWindowFactory_;
EventWindowFactory* eventWindowFactory_;
SettingsProvider *settings_;
+ ProfileSettingsProvider* profileSettings_;
AvatarStorage* avatarStorage_;
ApplicationMessageDisplay* applicationMessageDisplay_;
ChatController* chatController_;
diff --git a/Swift/Controllers/ProfileSettingsProvider.h b/Swift/Controllers/ProfileSettingsProvider.h
index 62878df..76d20e6 100644
--- a/Swift/Controllers/ProfileSettingsProvider.h
+++ b/Swift/Controllers/ProfileSettingsProvider.h
@@ -27,6 +27,8 @@ class ProfileSettingsProvider {
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);};
+ virtual int getIntSetting(const String& settingPath, int defaultValue) {return provider_->getIntSetting(settingPath, defaultValue);}
+ virtual void storeInt(const String& settingPath, int settingValue) {provider_->storeInt(settingPath, settingValue);}
private:
String profileSettingPath(const String &settingPath) {return profile_ + ":" + settingPath;};