summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/MainController.cpp14
-rw-r--r--Swift/Controllers/MainController.h1
-rw-r--r--Swift/QtUI/QtIdleDetector.cpp22
-rw-r--r--Swift/QtUI/QtIdleDetector.h17
4 files changed, 48 insertions, 6 deletions
diff --git a/Swift/Controllers/MainController.cpp b/Swift/Controllers/MainController.cpp
index 5495ec0..15947b6 100644
--- a/Swift/Controllers/MainController.cpp
+++ b/Swift/Controllers/MainController.cpp
@@ -185,7 +185,6 @@ void MainController::handleEventQueueLengthChange(int count) {
void MainController::handleChangeStatusRequest(StatusShow::Type show, const String &statusText) {
boost::shared_ptr<Presence> presence(new Presence());
- presence->addPayload(capsInfo_);
if (show == StatusShow::None) {
// FIXME: This is wrong. None doesn't mean unavailable
presence->setType(Presence::Unavailable);
@@ -206,6 +205,7 @@ void MainController::sendPresence(boost::shared_ptr<Presence> presence) {
if (!vCardPhotoHash_.isEmpty()) {
presence->addPayload(boost::shared_ptr<VCardUpdate>(new VCardUpdate(vCardPhotoHash_)));
}
+ presence->addPayload(capsInfo_);
lastSentPresence_ = presence;
client_->sendPresence(presence);
if (presence->getType() == Presence::Unavailable) {
@@ -214,11 +214,19 @@ void MainController::sendPresence(boost::shared_ptr<Presence> presence) {
}
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::handleIncomingPresence(boost::shared_ptr<Presence> presence) {
diff --git a/Swift/Controllers/MainController.h b/Swift/Controllers/MainController.h
index 5cdd9fa..3179df9 100644
--- a/Swift/Controllers/MainController.h
+++ b/Swift/Controllers/MainController.h
@@ -106,6 +106,7 @@ namespace Swift {
SoundEventController* soundEventController_;
AvatarManager* avatarManager_;
boost::shared_ptr<Presence> lastSentPresence_;
+ boost::shared_ptr<Presence> preIdlePresence_;
String vCardPhotoHash_;
boost::shared_ptr<Presence> queuedPresence_;
String password_;
diff --git a/Swift/QtUI/QtIdleDetector.cpp b/Swift/QtUI/QtIdleDetector.cpp
index e947854..783cc14 100644
--- a/Swift/QtUI/QtIdleDetector.cpp
+++ b/Swift/QtUI/QtIdleDetector.cpp
@@ -1,8 +1,15 @@
#include "QtIdleDetector.h"
+#include <QCursor>
+
namespace Swift {
QtIdleDetector::QtIdleDetector() {
+ signalled_ = false;
+ lastMoveTime_ = QDateTime::currentDateTime();
+ lastPosition_ = QCursor::pos();
+ connect(&timer_, SIGNAL(timeout()), this, SLOT(handleTimerTick()));
+ timer_.start(1000);
}
QtIdleDetector::~QtIdleDetector() {
@@ -12,5 +19,20 @@ void QtIdleDetector::forceNotIdle() {
}
+void QtIdleDetector::handleTimerTick() {
+ QPoint position = QCursor::pos();
+ QDateTime now = QDateTime::currentDateTime();
+ if (position != lastPosition_) {
+ if (signalled_) {
+ onInputNotIdle();
+ }
+ lastPosition_ = position;
+ lastMoveTime_ = now;
+ signalled_ = false;
+ } else if (!signalled_ && now > lastMoveTime_.addSecs(600) && position == lastPosition_) {
+ signalled_ = true;
+ onInputIdle();
+ }
+}
}
diff --git a/Swift/QtUI/QtIdleDetector.h b/Swift/QtUI/QtIdleDetector.h
index e21e4a8..444fb15 100644
--- a/Swift/QtUI/QtIdleDetector.h
+++ b/Swift/QtUI/QtIdleDetector.h
@@ -2,13 +2,24 @@
#include "Swift/Controllers/IdleDetector.h"
+#include <QObject>
+#include <QPoint>
+#include <QTimer>
+#include <QDateTime>
+
namespace Swift {
-class QtIdleDetector : public IdleDetector {
+class QtIdleDetector : public QObject, public IdleDetector {
+ Q_OBJECT
public:
QtIdleDetector();
virtual ~QtIdleDetector();
virtual void forceNotIdle();
-
-
+ private slots:
+ void handleTimerTick();
+ private:
+ QPoint lastPosition_;
+ QDateTime lastMoveTime_;
+ QTimer timer_;
+ bool signalled_;
};
}