Introducing global away
authorMarcus Eggenberger <egs@quassel-irc.org>
Wed, 12 May 2010 20:00:03 +0000 (22:00 +0200)
committerMarcus Eggenberger <egs@quassel-irc.org>
Wed, 12 May 2010 20:00:03 +0000 (22:00 +0200)
 - "/away -all <msg>" marks you away on all connected networks
 - "/away -all" removes away state on all connected networks

src/core/coresession.cpp
src/core/coresession.h
src/core/coreuserinputhandler.cpp
src/core/coreuserinputhandler.h

index e327f63..1c38a87 100644 (file)
@@ -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<NetworkId, CoreNetwork *>::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 */);
+  }
+}
index 4f341ee..772e7dc 100644 (file)
@@ -109,6 +109,9 @@ public slots:
 
   QHash<QString, QString> persistentChannels(NetworkId) const;
 
+  //! Marks us away (or unaway) on all networks
+  void globalAway(const QString &msg = QString());
+
 signals:
   void initialized();
   void sessionState(const QVariant &);
index ecff7ef..3184f25 100644 (file)
@@ -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");
       }
index 40490be..f98fb74 100644 (file)
@@ -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);