[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    =?utf-8?q?=5Btelepathy-chat-handler=5D_/=3A_Re-establish_chat_af?=
From:       Francesco Nwokeka <francesco.nwokeka () gmail ! com>
Date:       2011-04-30 2:20:04
Message-ID: 20110430022004.F0AD2A60A4 () git ! kde ! org
[Download RAW message or body]

Git commit 660964f634f0bb85bf166f5fa8579d83291db7a9 by Francesco Nwokeka.
Committed on 30/04/2011 at 04:24.
Pushed by nwokeka into branch 'master'.

Re-establish chat after going offline and back online PART 2 of 3

If a textChannel is invaldiated by the user going offline and then, once back online, \
requests a chat with the same person, the channel is re-established.

Reviewed by: David Edmundson
REVIEW: 101255

M  +8    -1    app/chat-window.cpp     
M  +27   -9    lib/chat-widget.cpp     
M  +8    -0    lib/chat-widget.h     

http://commits.kde.org/telepathy-chat-handler/660964f634f0bb85bf166f5fa8579d83291db7a9


diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 3d14909..7d82066 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -101,6 +101,13 @@ void ChatWindow::startChat(Tp::TextChannelPtr \
                incomingTextChannel)
         && auxChatTab->textChannel()->targetHandleType() == \
incomingTextChannel->targetHandleType()) {  duplicateTab = true;
             m_tabWidget->setCurrentIndex(index);    // set focus on selected tab
+
+            // check if channel is invalid. Replace only if invalid
+            // You get this status if user goes offline and then back on without \
closing the chat +            if (!auxChatTab->textChannel()->isValid()) {
+                auxChatTab->setTextChannel(incomingTextChannel);    // replace with \
new one +                auxChatTab->setChatEnabled(true);                   // \
re-enable chat +            }
         } else if (auxChatTab->textChannel()->targetId() == \
                incomingTextChannel->targetId()
           && auxChatTab->textChannel()->targetHandleType() == Tp::HandleTypeContact) \
                {
             // got duplicate group chat. Wait for group handling to be sorted out
@@ -110,7 +117,7 @@ void ChatWindow::startChat(Tp::TextChannelPtr \
incomingTextChannel)  }
 
     // got new chat, create it
-    if(!duplicateTab) {
+    if (!duplicateTab) {
         createNewChat(incomingTextChannel);
     }
 }
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index ef4927c..148f4e4 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -282,6 +282,32 @@ ChatSearchBar* ChatWidget::chatSearchBar() const
     return d->ui.searchBar;
 }
 
+void ChatWidget::setChatEnabled(bool enable)
+{
+    d->ui.sendMessageBox->setEnabled(enable);
+    d->ui.sendButton->setEnabled(enable);
+
+    // show a message informing the user
+    AdiumThemeStatusInfo statusMessage;
+
+    if (!enable) {
+        statusMessage.setMessage(i18n("Connection closed"));
+    } else {
+        statusMessage.setMessage(i18n("Connected"));
+    }
+    statusMessage.setService(d->channel->connection()->protocolName());
+    statusMessage.setTime(QDateTime::currentDateTime());
+    d->ui.chatArea->addStatusMessage(statusMessage);
+}
+
+void ChatWidget::setTextChannel(const Tp::TextChannelPtr &newTextChannelPtr)
+{
+    d->channel = newTextChannelPtr;     // set the new channel
+
+    // connect signals for the new textchannel
+    setupChannelSignals();
+}
+
 Tp::TextChannelPtr ChatWidget::textChannel() const
 {
     return d->channel;
@@ -697,15 +723,7 @@ void ChatWidget::onContactAliasChanged(const Tp::ContactPtr & \
contact, const QSt  
 void ChatWidget::onChannelInvalidated()
 {
-    d->ui.sendMessageBox->setDisabled(true);
-    d->ui.sendButton->setDisabled(true);
-
-    // show a message informing the user
-    AdiumThemeStatusInfo statusMessage;
-    statusMessage.setMessage(i18n("Connection closed"));
-    statusMessage.setService(d->channel->connection()->protocolName());
-    statusMessage.setTime(QDateTime::currentDateTime());
-    d->ui.chatArea->addStatusMessage(statusMessage);
+    setChatEnabled(false);
 }
 
 void ChatWidget::onInputBoxChanged()
diff --git a/lib/chat-widget.h b/lib/chat-widget.h
index f7d08d3..0a4cb1a 100644
--- a/lib/chat-widget.h
+++ b/lib/chat-widget.h
@@ -50,6 +50,14 @@ public:
     /** Returns a pointer to the Chatwidget's search bar */
     ChatSearchBar *chatSearchBar() const;
 
+    /** invalidates the use of the chat.
+     * @param enable flag to validate/invalidate chatWidget
+     */
+    void setChatEnabled(bool enable);
+
+    /** Sets textchannel to given one */
+    void setTextChannel(const Tp::TextChannelPtr &newTextChannelPtr);
+
     /** Returns the text channel pointer of the chatWidget */
     Tp::TextChannelPtr textChannel() const;
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic