channelDestroyed hadling, TPSESSION_DEBUG env
[tpsession] / tpsession-0.1 / tpsession / tpsessionaccount.cpp
index 657e4ba..ab8d8fe 100644 (file)
@@ -234,7 +234,7 @@ void TpSessionAccount::sendMessageToAddress(QString address,QString message)
     Tp::ContactPtr p;
     TpSessionChannel* channel=getChannelFromPeerAddress(address);
     if(channel) {
-      //  qDebug() << "TpSessionAccount::sendMessageToAddress peer:" << channel->peerId() << "queuing:" << message;
+        if(TpSession::tpsDebug()) qDebug() << "TpSessionAccount::sendMessageToAddress peer:" << channel->peerId() << "queuing:" << message;
         channel->sendMessage(message); // We have already channel
         emit messageQueued(this,true);
     }
@@ -252,7 +252,7 @@ void TpSessionAccount::addOutgoingChannel(const Tp::ContactPtr &contact)
 {
 
 
-  //    qDebug() << "TpSessionAccount::addOutgoingChannel";
+  if(TpSession::tpsDebug()) qDebug() << "TpSessionAccount::addOutgoingChannel";
 
      TpSessionChannel* newChannel=new TpSessionChannel(contact->manager()->connection(),contact);
      connect(newChannel,SIGNAL(messageReceived(const Tp::ReceivedMessage &,TpSessionChannel *)),
@@ -261,16 +261,18 @@ void TpSessionAccount::addOutgoingChannel(const Tp::ContactPtr &contact)
              SLOT(onMessageSent(const Tp::Message &,Tp::MessageSendingFlags, const QString &,TpSessionChannel *)));
      connect(newChannel,SIGNAL(channelReady(TpSessionChannel *)),
             SLOT(onOutgoingChannelReady(TpSessionChannel*)));
+     connect(newChannel,SIGNAL(channelDestroyed(TpSessionChannel *)),
+            SLOT(onChannelDestroyed(TpSessionChannel*)));
      myChannels+=newChannel;
 
 }
 
 void TpSessionAccount::onOutgoingChannelReady(TpSessionChannel *ch)
 {
-  // qDebug() << "TpSessionAccount::onOutgoingChannelReady";
+ if(TpSession::tpsDebug()) qDebug() << "TpSessionAccount::onOutgoingChannelReady";
  emit channelReady(this);
  if(!reqMessage.isEmpty()) {
-   //  qDebug() << "TpSessionAccount::onOutgoingChannelReady peer:" << ch->peerId() << "queuing:" << reqMessage;
+   if(TpSession::tpsDebug())  qDebug() << "TpSessionAccount::onOutgoingChannelReady peer:" << ch->peerId() << "queuing:" << reqMessage;
    ch->sendMessage(reqMessage);
    emit messageQueued(this,true);
  };
@@ -281,7 +283,7 @@ void TpSessionAccount::onOutgoingChannelReady(TpSessionChannel *ch)
 void TpSessionAccount::onMessageSent(const Tp::Message &msg,Tp::MessageSendingFlags, const QString &flags,TpSessionChannel *ch)
 {
     Q_UNUSED(flags);
-    // qDebug() << "TpSessionAccount::onMessageSent peer:" << ch->peerId() <<"txt:" << msg.text();
+    if(TpSession::tpsDebug()) qDebug() << "TpSessionAccount::onMessageSent peer:" << ch->peerId() <<"txt:" << msg.text();
     emit messageSent(msg,this);
 };
 
@@ -314,6 +316,8 @@ void TpSessionAccount::onNewChannels(const Tp::ChannelDetailsList &channels)
              SLOT(onMessageReceived(const Tp::ReceivedMessage &,TpSessionChannel *)));
             connect(newChannel,SIGNAL(messageSent(const Tp::Message &,Tp::MessageSendingFlags, const QString &,TpSessionChannel *)),
                     SLOT(onMessageSent(const Tp::Message &,Tp::MessageSendingFlags, const QString &,TpSessionChannel *)));
+            connect(newChannel,SIGNAL(channelDestroyed(TpSessionChannel *)),
+                   SLOT(onChannelDestroyed(TpSessionChannel*)));
             myChannels+=newChannel;
         }
         if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA && !requested) {
@@ -321,3 +325,9 @@ void TpSessionAccount::onNewChannels(const Tp::ChannelDetailsList &channels)
         }
     }
 }
+
+void TpSessionAccount::onChannelDestroyed(TpSessionChannel *ch)
+{
+   if(TpSession::tpsDebug()) qDebug() << "TpSessionAccount::onMessageSent peer:" << ch->peerId();
+   myChannels.remove(ch);
+};