enabling away on detach
authorMarcus Eggenberger <egs@quassel-irc.org>
Tue, 28 Oct 2008 12:34:35 +0000 (13:34 +0100)
committerMarcus Eggenberger <egs@quassel-irc.org>
Tue, 28 Oct 2008 12:34:35 +0000 (13:34 +0100)
src/core/coresession.cpp
src/core/coresession.h
src/qtui/settingspages/identitiessettingspage.cpp

index 020950f..0dd3358 100644 (file)
@@ -57,6 +57,9 @@ CoreSession::CoreSession(UserId uid, bool restoreState, QObject *parent)
   SignalProxy *p = signalProxy();
   connect(p, SIGNAL(peerRemoved(QIODevice *)), this, SLOT(removeClient(QIODevice *)));
 
+  connect(p, SIGNAL(connected()), this, SLOT(clientsConnected()));
+  connect(p, SIGNAL(disconnected()), this, SLOT(clientsDisconnected()));
+
   //p->attachSlot(SIGNAL(disconnectFromNetwork(NetworkId)), this, SLOT(disconnectFromNetwork(NetworkId))); // FIXME
   p->attachSlot(SIGNAL(sendInput(BufferInfo, QString)), this, SLOT(msgFromClient(BufferInfo, QString)));
   p->attachSignal(this, SIGNAL(displayMsg(Message)));
@@ -116,10 +119,6 @@ CoreSession::~CoreSession() {
   }
 }
 
-UserId CoreSession::user() const {
-  return _user;
-}
-
 CoreNetwork *CoreSession::network(NetworkId id) const {
   if(_networks.contains(id)) return _networks[id];
   return 0;
@@ -503,3 +502,65 @@ void CoreSession::renameBuffer(const NetworkId &networkId, const QString &newNam
     emit bufferRenamed(bufferId, newName);
   }
 }
+
+void CoreSession::clientsConnected() {
+  QHash<NetworkId, NetworkConnection *>::iterator conIter = _connections.begin();
+  Identity *identity = 0;
+  NetworkConnection *con = 0;
+  Network *network = 0;
+  IrcUser *me = 0;
+  QString awayReason;
+  while(conIter != _connections.end()) {
+    con = *conIter;
+    conIter++;
+
+    if(!con->isConnected())
+      continue;
+    identity = con->identity();
+    if(!identity)
+      continue;
+    network = con->network();
+    if(!network)
+      continue;
+    me = network->me();
+    if(!me)
+      continue;
+
+    if(identity->detachAwayEnabled() && me->isAway()) {
+      con->userInputHandler()->handleAway(BufferInfo(), QString());
+    }
+  }
+}
+
+void CoreSession::clientsDisconnected() {
+  QHash<NetworkId, NetworkConnection *>::iterator conIter = _connections.begin();
+  Identity *identity = 0;
+  NetworkConnection *con = 0;
+  Network *network = 0;
+  IrcUser *me = 0;
+  QString awayReason;
+  while(conIter != _connections.end()) {
+    con = *conIter;
+    conIter++;
+
+    if(!con->isConnected())
+      continue;
+    identity = con->identity();
+    if(!identity)
+      continue;
+    network = con->network();
+    if(!network)
+      continue;
+    me = network->me();
+    if(!me)
+      continue;
+
+    if(identity->detachAwayEnabled() && !me->isAway()) {
+      if(identity->detachAwayReasonEnabled())
+       awayReason = identity->detachAwayReason();
+      else
+       awayReason = identity->awayReason();
+      con->userInputHandler()->handleAway(BufferInfo(), awayReason);
+    }
+  }
+}
index d032187..91ad27e 100644 (file)
@@ -48,7 +48,7 @@ public:
   ~CoreSession();
 
   QList<BufferInfo> buffers() const;
-  UserId user() const;
+  inline UserId user() const { return _user; }
   CoreNetwork *network(NetworkId) const;
   NetworkConnection *networkConnection(NetworkId) const;
   Identity *identity(IdentityId) const;
@@ -172,6 +172,9 @@ private slots:
 
   void scriptRequest(QString script);
 
+  void clientsConnected();
+  void clientsDisconnected();
+
 private:
   void loadSettings();
   void initScriptEngine();
index a5ec4f9..8dd9c0d 100644 (file)
@@ -72,7 +72,6 @@ IdentitiesSettingsPage::IdentitiesSettingsPage(QWidget *parent)
   // we would need this if we enabled drag and drop in the nicklist...
   //connect(ui.nicknameList, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(setWidgetStates()));
   //connect(ui.nicknameList->model(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(nicklistHasChanged()));
-
 }
 
 void IdentitiesSettingsPage::setWidgetStates() {
@@ -86,9 +85,6 @@ void IdentitiesSettingsPage::setWidgetStates() {
     ui.nickDown->setDisabled(true);
   }
   ui.deleteNick->setEnabled(ui.nicknameList->count() > 1);
-
-  // FIXME this is until stuff has been implemented
-  ui.detachAwayEnabled->setEnabled(false);
 }
 
 void IdentitiesSettingsPage::coreConnectionStateChanged(bool state) {