diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-30 17:46:24 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-30 17:51:32 (GMT) |
commit | ba333999576d89f3340c271b2a3331d6a3e64ac7 (patch) | |
tree | 7f2d0dd20d6d6a302a26c904468a90c22150b481 /Swift/Controllers | |
parent | 59be74ec6fc7bc495f2a261b8f274b8555aee306 (diff) | |
download | swift-ba333999576d89f3340c271b2a3331d6a3e64ac7.zip swift-ba333999576d89f3340c271b2a3331d6a3e64ac7.tar.bz2 |
Disconnect client cleanly before quitting.
Resolves: #671, #420
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/MainController.cpp | 18 | ||||
-rw-r--r-- | Swift/Controllers/MainController.h | 2 | ||||
-rw-r--r-- | Swift/Controllers/UIInterfaces/LoginWindow.h | 3 |
3 files changed, 22 insertions, 1 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp index eb03e50..92a3f2a 100644 --- a/Swift/Controllers/MainController.cpp +++ b/Swift/Controllers/MainController.cpp @@ -100,6 +100,7 @@ MainController::MainController( eventWindowController_ = NULL; discoResponder_ = NULL; mucSearchController_ = NULL; + quitRequested_ = false; timeBeforeNextReconnect_ = -1; mucSearchWindowFactory_ = mucSearchWindowFactory; @@ -136,6 +137,7 @@ MainController::MainController( loginWindow_->setLoginAutomatically(loginAutomatically); loginWindow_->onLoginRequest.connect(boost::bind(&MainController::handleLoginRequest, this, _1, _2, _3, _4, _5)); loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this)); + loginWindow_->onQuitRequest.connect(boost::bind(&MainController::handleQuitRequest, this)); idleDetector_.setIdleTimeSeconds(600); idleDetector_.onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1)); @@ -401,7 +403,11 @@ void MainController::performLoginFromCachedCredentials() { } void MainController::handleDisconnected(const boost::optional<ClientError>& error) { - if (error) { + if (quitRequested_) { + resetClient(); + loginWindow_->quit(); + } + else if (error) { String message; switch(error->getType()) { case ClientError::UnknownError: message = "Unknown Error"; break; @@ -506,5 +512,15 @@ void MainController::handleNotificationClicked(const JID& jid) { uiEventStream_->send(boost::shared_ptr<UIEvent>(new RequestChatUIEvent(jid))); } +void MainController::handleQuitRequest() { + if (client_ && client_->isActive()) { + quitRequested_ = true; + client_->disconnect(); + } + else { + resetClient(); + loginWindow_->quit(); + } +} } diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h index da65567..c36c136 100644 --- a/Swift/Controllers/MainController.h +++ b/Swift/Controllers/MainController.h @@ -89,6 +89,7 @@ namespace Swift { void handleConnected(); void handleLoginRequest(const String& username, const String& password, const String& certificateFile, bool remember, bool loginAutomatically); void handleCancelLoginRequest(); + void handleQuitRequest(); void handleChangeStatusRequest(StatusShow::Type show, const String &statusText); void handleDisconnected(const boost::optional<ClientError>& error); void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, const boost::optional<ErrorPayload>&); @@ -152,5 +153,6 @@ namespace Swift { Timer::ref reconnectTimer_; StatusTracker* statusTracker_; bool myStatusLooksOnline_; + bool quitRequested_; }; } diff --git a/Swift/Controllers/UIInterfaces/LoginWindow.h b/Swift/Controllers/UIInterfaces/LoginWindow.h index c752d0a..54d8099 100644 --- a/Swift/Controllers/UIInterfaces/LoginWindow.h +++ b/Swift/Controllers/UIInterfaces/LoginWindow.h @@ -25,7 +25,10 @@ namespace Swift { virtual void addAvailableAccount(const String& defaultJID, const String& defaultPassword, const String& defaultCertificate) = 0; boost::signal<void (const String&, const String&, const String& /* certificateFile */, bool /* remember password*/, bool /* login automatically */)> onLoginRequest; virtual void setLoginAutomatically(bool loginAutomatically) = 0; + virtual void quit() = 0; + boost::signal<void ()> onCancelLoginRequest; + boost::signal<void ()> onQuitRequest; }; } #endif |