From 0f667b4d2fb9a34b8ebbfe1d07b47407ce54468a Mon Sep 17 00:00:00 2001 From: Marcus Eggenberger Date: Wed, 12 May 2010 22:00:03 +0200 Subject: [PATCH] Introducing global away - "/away -all " marks you away on all connected networks - "/away -all" removes away state on all connected networks --- src/core/coresession.cpp | 16 ++++++++++++++++ src/core/coresession.h | 3 +++ src/core/coreuserinputhandler.cpp | 21 +++++++++++++++++++-- src/core/coreuserinputhandler.h | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/core/coresession.cpp b/src/core/coresession.cpp index e327f63a..1c38a87a 100644 --- a/src/core/coresession.cpp +++ b/src/core/coresession.cpp @@ -515,6 +515,7 @@ void CoreSession::clientsDisconnected() { if(!net->isConnected()) continue; + identity = net->identityPtr(); if(!identity) continue; @@ -530,3 +531,18 @@ void CoreSession::clientsDisconnected() { } } } + + +void CoreSession::globalAway(const QString &msg) { + QHash::iterator netIter = _networks.begin(); + CoreNetwork *net = 0; + while(netIter != _networks.end()) { + net = *netIter; + netIter++; + + if(!net->isConnected()) + continue; + + net->userInputHandler()->issueAway(msg, false /* no force away */); + } +} diff --git a/src/core/coresession.h b/src/core/coresession.h index 4f341ee5..772e7dc3 100644 --- a/src/core/coresession.h +++ b/src/core/coresession.h @@ -109,6 +109,9 @@ public slots: QHash persistentChannels(NetworkId) const; + //! Marks us away (or unaway) on all networks + void globalAway(const QString &msg = QString()); + signals: void initialized(); void sessionState(const QVariant &); diff --git a/src/core/coreuserinputhandler.cpp b/src/core/coreuserinputhandler.cpp index ecff7ef8..3184f253 100644 --- a/src/core/coreuserinputhandler.cpp +++ b/src/core/coreuserinputhandler.cpp @@ -51,14 +51,31 @@ void CoreUserInputHandler::handleUserInput(const BufferInfo &bufferInfo, const Q // ==================== void CoreUserInputHandler::handleAway(const BufferInfo &bufferInfo, const QString &msg) { Q_UNUSED(bufferInfo) + if(msg.startsWith("-all")) { + if(msg.length() == 4) { + coreSession()->globalAway(); + return; + } + Q_ASSERT(msg.length() > 4); + if(msg[4] == ' ') { + coreSession()->globalAway(msg.mid(5)); + return; + } + } + issueAway(msg); +} +void CoreUserInputHandler::issueAway(const QString &msg, bool autoCheck) { QString awayMsg = msg; IrcUser *me = network()->me(); // if there is no message supplied we have to check if we are already away or not - if(msg.isEmpty()) { + if(autoCheck && msg.isEmpty()) { if(me && !me->isAway()) { - awayMsg = network()->identityPtr()->awayReason(); + Identity *identity = network()->identityPtr(); + if(identity) { + awayMsg = identity->awayReason(); + } if(awayMsg.isEmpty()) { awayMsg = tr("away"); } diff --git a/src/core/coreuserinputhandler.h b/src/core/coreuserinputhandler.h index 40490bea..f98fb740 100644 --- a/src/core/coreuserinputhandler.h +++ b/src/core/coreuserinputhandler.h @@ -68,6 +68,7 @@ public slots: void defaultHandler(QString cmd, const BufferInfo &bufferInfo, const QString &text); void issueQuit(const QString &reason); + void issueAway(const QString &msg, bool autoCheck = true); protected: void timerEvent(QTimerEvent *event); -- 2.20.1