summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/Controllers')
-rw-r--r--Swift/Controllers/IdleDetector.h16
-rw-r--r--Swift/Controllers/MainController.cpp45
-rw-r--r--Swift/Controllers/MainController.h21
3 files changed, 34 insertions, 48 deletions
diff --git a/Swift/Controllers/IdleDetector.h b/Swift/Controllers/IdleDetector.h
deleted file mode 100644
index 72fe07c..0000000
--- a/Swift/Controllers/IdleDetector.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#pragma once
-
-#include <boost/signals.hpp>
-#include <boost/shared_ptr.hpp>
-
-namespace Swift {
-class IdleDetector {
- public:
- virtual ~IdleDetector() {};
- virtual void forceNotIdle() = 0;
- boost::signal<void ()> onInputIdle;
- boost::signal<void ()> onInputNotIdle;
-};
-}
-
-
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index f05d42d..f54e0a2 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -7,13 +7,12 @@
#include "Swiften/Application/Application.h"
#include "Swiften/Application/ApplicationMessageDisplay.h"
#include "Swift/Controllers/ChatController.h"
#include "Swift/Controllers/ChatWindowFactory.h"
#include "Swift/Controllers/EventController.h"
-#include "Swift/Controllers/IdleDetector.h"
#include "Swift/Controllers/LoginWindow.h"
#include "Swift/Controllers/LoginWindowFactory.h"
#include "Swift/Controllers/MainWindow.h"
#include "Swift/Controllers/MainWindowFactory.h"
#include "Swift/Controllers/MUCController.h"
#include "Swift/Controllers/NickResolver.h"
@@ -57,16 +56,14 @@ static const String CLIENT_NAME = "Swift";
static const String CLIENT_VERSION = "0.3";
static const String CLIENT_NODE = "http://swift.im";
typedef std::pair<JID, ChatController*> JIDChatControllerPair;
typedef std::pair<JID, MUCController*> JIDMUCControllerPair;
-MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, IdleDetector* idleDetector)
- : client_(NULL), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), treeWidgetFactory_(treeWidgetFactory), settings_(settings),
- xmppRosterController_(NULL), rosterController_(NULL), loginWindow_(NULL), clientVersionResponder_(NULL), nickResolver_(NULL), discoResponder_(NULL) {
- idleDetector_ = idleDetector;
+MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory *treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer)
+ : timerFactory_(&boostIOServiceThread_.getIOService()), idleDetector_(&idleQuerier_, &timerFactory_, 100), client_(NULL), chatWindowFactory_(chatWindowFactory), mainWindowFactory_(mainWindowFactory), loginWindowFactory_(loginWindowFactory), treeWidgetFactory_(treeWidgetFactory), settings_(settings), xmppRosterController_(NULL), rosterController_(NULL), loginWindow_(NULL), clientVersionResponder_(NULL), nickResolver_(NULL), discoResponder_(NULL) {
application_ = application;
presenceOracle_ = NULL;
avatarManager_ = NULL;
avatarStorage_ = new AvatarFileStorage(application_->getAvatarDir());
@@ -79,12 +76,15 @@ MainController::MainController(ChatWindowFactory* chatWindowFactory, MainWindowF
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));
loginWindow_->onCancelLoginRequest.connect(boost::bind(&MainController::handleCancelLoginRequest, this));
+
+ idleDetector_.setIdleTimeSeconds(600);
+ idleDetector_.onIdleChanged.connect(boost::bind(&MainController::handleInputIdleChanged, this, _1));
}
MainController::~MainController() {
foreach (JIDChatControllerPair controllerPair, chatControllers_) {
delete controllerPair.second;
}
@@ -162,15 +162,12 @@ void MainController::handleConnected() {
discoInfoRequest->send();
boost::shared_ptr<GetVCardRequest> vCardRequest(new GetVCardRequest(JID(), client_));
vCardRequest->onResponse.connect(boost::bind(&MainController::handleOwnVCardReceived, this, _1, _2));
vCardRequest->send();
- idleDetector_->onInputIdle.connect(boost::bind(&MainController::handleInputIdle, this));
- idleDetector_->onInputNotIdle.connect(boost::bind(&MainController::handleInputNotIdle, this));
-
//Send presence last to catch all the incoming presences.
boost::shared_ptr<Presence> initialPresence;
if (queuedPresence_.get() != NULL) {
initialPresence = queuedPresence_;
} else {
initialPresence = boost::shared_ptr<Presence>(new Presence());
@@ -216,25 +213,29 @@ void MainController::sendPresence(boost::shared_ptr<Presence> presence) {
client_->sendPresence(presence);
if (presence->getType() == Presence::Unavailable) {
logout();
}
}
-void MainController::handleInputIdle() {
- preIdlePresence_ = lastSentPresence_;
- boost::shared_ptr<Presence> presence(new Presence());
- presence->setShow(StatusShow::Away);
- presence->setStatus("Auto-away");
- sendPresence(presence);
-}
-
-void MainController::handleInputNotIdle() {
- if (client_) {
- sendPresence(preIdlePresence_);
- } else {
- queuedPresence_ = preIdlePresence_;
+void MainController::handleInputIdleChanged(bool idle) {
+ if (!client_ || !client_->isAvailable()) {
+ return;
+ }
+ if (idle) {
+ preIdlePresence_ = lastSentPresence_;
+ boost::shared_ptr<Presence> presence(new Presence());
+ presence->setShow(StatusShow::Away);
+ presence->setStatus("Auto-away");
+ sendPresence(presence);
+ }
+ else {
+ if (client_) {
+ sendPresence(preIdlePresence_);
+ } else {
+ queuedPresence_ = preIdlePresence_;
+ }
}
}
void MainController::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
//FIXME: subscribe, subscribed
rosterController_->handleIncomingPresence(presence);
@@ -301,14 +302,12 @@ void MainController::handleError(const ClientError& error) {
void MainController::handleCancelLoginRequest() {
signOut();
}
void MainController::signOut() {
logout();
- idleDetector_->onInputIdle.connect(boost::bind(&MainController::handleInputIdle, this));
- idleDetector_->onInputNotIdle.connect(boost::bind(&MainController::handleInputNotIdle, this));
loginWindow_->loggedOut();
foreach (JIDChatControllerPair controllerPair, chatControllers_) {
delete controllerPair.second;
}
chatControllers_.clear();
foreach (JIDMUCControllerPair controllerPair, mucControllers_) {
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index df6901d..270b131 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -1,13 +1,16 @@
-#ifndef SWIFTEN_MainController_H
-#define SWIFTEN_MainController_H
+#pragma once
#include <boost/signals.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
+#include "Swiften/Network/BoostIOServiceThread.h"
+#include "Swiften/Network/BoostTimerFactory.h"
+#include "SwifTools/Idle/PlatformIdleQuerier.h"
+#include "SwifTools/Idle/ActualIdleDetector.h"
#include "Swiften/Base/String.h"
#include "Swiften/Client/ClientError.h"
#include "Swiften/JID/JID.h"
#include "Swiften/Elements/VCard.h"
#include "Swiften/Elements/DiscoInfo.h"
#include "Swiften/Elements/ErrorPayload.h"
@@ -22,13 +25,12 @@ namespace Swift {
class AvatarStorage;
class Application;
class Client;
class ChatWindowFactory;
class ChatController;
class EventController;
- class IdleDetector;
class MainWindowFactory;
class MainWindow;
class NickResolver;
class RosterController;
class XMPPRosterController;
class DiscoInfoResponder;
@@ -44,13 +46,13 @@ namespace Swift {
class SystemTrayController;
class SoundEventController;
class SoundPlayer;
class MainController : public MUCRegistry {
public:
- MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer, IdleDetector* idleDetector);
+ MainController(ChatWindowFactory* chatWindowFactory, MainWindowFactory *mainWindowFactory, LoginWindowFactory *loginWindowFactory, TreeWidgetFactory* treeWidgetFactory, SettingsProvider *settings, Application* application, SystemTray* systemTray, SoundPlayer* soundPlayer);
~MainController();
private:
void resetClient();
@@ -66,22 +68,26 @@ namespace Swift {
void handleError(const ClientError& error);
void handleServerDiscoInfoResponse(boost::shared_ptr<DiscoInfo>, const boost::optional<ErrorPayload>&);
void handleEventQueueLengthChange(int count);
void handleOwnVCardReceived(boost::shared_ptr<VCard> vCard, const boost::optional<ErrorPayload>& error);
ChatController* getChatController(const JID &contact);
void sendPresence(boost::shared_ptr<Presence> presence);
- void handleInputIdle();
- void handleInputNotIdle();
+ void handleInputIdleChanged(bool);
void logout();
void signOut();
virtual bool isMUC(const JID& muc) const;
void performLoginFromCachedCredentials();
void reconnectAfterError();
void setManagersEnabled(bool enabled);
+
+ BoostIOServiceThread boostIOServiceThread_;
+ BoostTimerFactory timerFactory_;
+ PlatformIdleQuerier idleQuerier_;
+ ActualIdleDetector idleDetector_;
Client* client_;
ChatWindowFactory* chatWindowFactory_;
MainWindowFactory* mainWindowFactory_;
LoginWindowFactory* loginWindowFactory_;
TreeWidgetFactory* treeWidgetFactory_;
SettingsProvider *settings_;
@@ -92,13 +98,12 @@ namespace Swift {
RosterController* rosterController_;
EventController* eventController_;
LoginWindow* loginWindow_;
SoftwareVersionResponder* clientVersionResponder_;
NickResolver* nickResolver_;
DiscoInfoResponder* discoResponder_;
- IdleDetector* idleDetector_;
boost::shared_ptr<CapsInfo> capsInfo_;
std::map<JID, MUCController*> mucControllers_;
std::map<JID, ChatController*> chatControllers_;
boost::shared_ptr<DiscoInfo> serverDiscoInfo_;
boost::shared_ptr<XMPPRoster> xmppRoster_;;
JID jid_;
@@ -111,8 +116,6 @@ namespace Swift {
String vCardPhotoHash_;
boost::shared_ptr<Presence> queuedPresence_;
String password_;
String certificateFile_;
};
}
-#endif
-