[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:19:33 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=670271d

The following commit has been merged in the master branch:
commit 670271d73d74d3f5aa00d31e1c2ed47168dd05ba
Author: Lasath Fernando <kde at lasath.org>
Date:   Wed Jul 6 05:51:11 2011 +0530

    Refractored tabs in ChatTab, ChatWindow and TelepathyChatUi.
    
    Now tabs can be dettached from window via a context menu
---
 app/chat-tab.cpp          |  27 +++++++---
 app/chat-tab.h            |   8 +--
 app/chat-window.cpp       | 126 ++++++++++++++++++++++++++++++++--------------
 app/chat-window.h         |  31 +++++++++---
 app/telepathy-chat-ui.cpp |  52 +++++++++++++++++--
 app/telepathy-chat-ui.h   |  10 +++-
 6 files changed, 191 insertions(+), 63 deletions(-)

diff --git a/app/chat-tab.cpp b/app/chat-tab.cpp
index 23c912e..d347602 100644
--- a/app/chat-tab.cpp
+++ b/app/chat-tab.cpp
@@ -28,10 +28,11 @@
 
 #include <TelepathyQt4/Account>
 #include <TelepathyQt4/TextChannel>
+#include "chat-window.h"
 
 ChatTab::ChatTab(const Tp::TextChannelPtr& channel, const Tp::AccountPtr& account, QWidget* parent)
     : ChatWidget(channel, account, parent)
-    , m_tabWidget(0)
+    , m_chatWindow(0)
 {
     connect(this, SIGNAL(notificationClicked()), SLOT(showOnTop()));
 
@@ -43,21 +44,33 @@ ChatTab::~ChatTab()
 {
 }
 
-void ChatTab::setTabWidget(KTabWidget* tabWidget)
+void ChatTab::setWindow(ChatWindow* window)
 {
-    m_tabWidget = tabWidget;
+    kDebug();
+
+    if(m_chatWindow) {
+        m_chatWindow->removeTab(this);
+    }
+    
+    m_chatWindow = window;
+    
+    if(window) {
+        window->addTab(this);
+    }
 }
 
-KTabWidget* ChatTab::tabWidget() const
+ChatWindow* ChatTab::window() const
 {
-    return m_tabWidget;
+    return m_chatWindow;
 }
 
 void ChatTab::showOnTop()
 {
     kDebug() << "Show this widget on top" << title();
-    if(m_tabWidget) {
-        m_tabWidget->setCurrentWidget(this);
+    if(m_chatWindow) {
+        m_chatWindow->focusChat(this);
+    } else {
+        kError() << "Attempting to focus chatTab without chatWindow being set!";
     }
 
     activateWindow();
diff --git a/app/chat-tab.h b/app/chat-tab.h
index 2175fe2..408bb91 100644
--- a/app/chat-tab.h
+++ b/app/chat-tab.h
@@ -27,8 +27,8 @@
 #include <KIcon>
 #include <KColorScheme>
 
+class ChatWindow;
 
-class KTabWidget;
 class ChatWidgetPrivate;
 class QShowEvent;
 
@@ -40,8 +40,8 @@ public:
     explicit ChatTab(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account, QWidget *parent = 0);
     virtual ~ChatTab();
 
-    void setTabWidget(KTabWidget *tabWidget);
-    KTabWidget* tabWidget() const;
+    void setWindow(ChatWindow* tab);
+    ChatWindow* window() const;
 
 public slots:
     void showOnTop();
@@ -52,7 +52,7 @@ private slots:
     void onConnectionStatusChanged(Tp::ConnectionStatus);
 
 private:
-    KTabWidget *m_tabWidget;
+    ChatWindow *m_chatWindow;
 };
 
 #endif // CHATWIDGET_H
diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 517b694..86e2cf6 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -44,6 +44,7 @@
 #include <TelepathyQt4/ContactCapabilities>
 #include <TelepathyQt4/PendingChannelRequest>
 #include <TelepathyQt4/TextChannel>
+#include <KMenu>
 
 #define PREFERRED_TEXTCHAT_HANDLER "org.freedesktop.Telepathy.Client.KDE.TextUi"
 #define PREFERRED_FILETRANSFER_HANDLER "org.freedesktop.Telepathy.Client.KDE.FileTransfer"
@@ -74,10 +75,11 @@ ChatWindow::ChatWindow()
     m_tabWidget->setCloseButtonEnabled(true);
     m_tabWidget->setHoverCloseButtonDelayed(true);
     m_tabWidget->setTabBarHidden(true);
-    connect(m_tabWidget, SIGNAL(closeRequest(QWidget*)), this, SLOT(removeTab(QWidget*)));
+    connect(m_tabWidget, SIGNAL(closeRequest(QWidget*)), this, SLOT( destroyTab(QWidget*)));
     connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
     connect(qobject_cast<KTabBar*>(m_tabWidget->tabBar()), SIGNAL(mouseMiddleClick(int)),
                 m_tabWidget, SLOT(removeTab(int)));
+    connect(qobject_cast<KTabBar*>(m_tabWidget->tabBar()), SIGNAL(contextMenu(int,QPoint)), SLOT(tabBarContextMenu(int,QPoint)));
 
     setCentralWidget(m_tabWidget);
 
@@ -86,51 +88,102 @@ ChatWindow::ChatWindow()
 
 ChatWindow::~ChatWindow()
 {
+    emit aboutToClose();
 }
 
-void ChatWindow::startChat(const Tp::TextChannelPtr &incomingTextChannel, const Tp::AccountPtr &account)
+void ChatWindow::tabBarContextMenu(int index, const QPoint& globalPos)
 {
-    // if targetHandle is None, targetId is also "", so create new chat
-    if (incomingTextChannel->targetHandleType() == Tp::HandleTypeNone) {
-        kDebug() << "ChatWindow::startChat target handle type is HandleTypeNone";
-        createNewChat(incomingTextChannel, account);
-        return;
+    KAction close("Close", this);
+    KAction dettach("Dettach Tab", this);
+
+    KAction moveLeft("Move Tab Left", this), moveRight("Move Tab Right", this);
+
+    KMenu* menu = new KMenu(this);
+    menu->addAction(&moveLeft);
+    menu->addAction(&moveRight);
+    menu->addAction(&dettach);
+    menu->addAction(&close);
+
+    KAction* result = qobject_cast<KAction*>(menu->exec(globalPos));
+
+    if(result == &close) {
+        destroyTab(m_tabWidget->widget(index));
+    } else if (result == &dettach) {
+        emit dettachRequested(qobject_cast<ChatTab*>(m_tabWidget->widget(index)));
+    } else if (result == &moveLeft) {
+        m_tabWidget->moveTab(index, index - 1);
+    } else if (result == &moveRight) {
+        m_tabWidget->moveTab(index, index + 1);
     }
+}
 
-    bool duplicateTab = false;
+void ChatWindow::focusChat ( ChatTab* tab )
+{
+    kDebug();
+    m_tabWidget->setCurrentWidget(tab);
+}
 
-    // check that the tab requested isn't already open
-    for (int index = 0; index < m_tabWidget->count() && !duplicateTab; ++index) {
+ChatTab* ChatWindow::getTab ( const Tp::TextChannelPtr& incomingTextChannel )
+{
+    ChatTab* match = NULL;
 
-        // get chatWidget object
-        ChatTab *auxChatTab = qobject_cast<ChatTab*>(m_tabWidget->widget(index));
+    // if targetHandle is None, targetId is also ""
+    if (!incomingTextChannel->targetHandleType() == Tp::HandleTypeNone) {
+        kDebug() << "ChatWindow::startChat target handle type is NOT HandleTypeNone";
 
-        Q_ASSERT(auxChatTab);
+        // check that the tab requested isn't already open
+        for (int index = 0; index < m_tabWidget->count()/* && !match*/; ++index) {
 
-        // check for 1on1 duplicate chat
-        if (auxChatTab->textChannel()->targetId() == incomingTextChannel->targetId()
-        && auxChatTab->textChannel()->targetHandleType() == incomingTextChannel->targetHandleType()) {
-            duplicateTab = true;
-            m_tabWidget->setCurrentIndex(index);    // set focus on selected tab
+            // get chatWidget object
+            ChatTab *auxChatTab = qobject_cast<ChatTab*>(m_tabWidget->widget(index));
+
+            Q_ASSERT(auxChatTab);
+
+            // check for 1on1 duplicate chat
+            if (auxChatTab->textChannel()->targetId() == incomingTextChannel->targetId()
+            && auxChatTab->textChannel()->targetHandleType() == incomingTextChannel->targetHandleType()) {
+                match = auxChatTab;
 
-            // 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
             }
-        } 
+        }
     }
 
-    // got new chat, create it
-    if (!duplicateTab) {
-        createNewChat(incomingTextChannel, account);
+    return match;
+}
+
+void ChatWindow::removeTab ( ChatTab* tab )
+{
+    m_tabWidget->removePage(tab);
+
+    if (!m_tabWidget->isTabBarHidden()){
+        if (m_tabWidget->count() <= 1) {
+            m_tabWidget->setTabBarHidden(true);
+        }
     }
 }
 
-void ChatWindow::removeTab(QWidget* chatWidget)
+void ChatWindow::addTab ( ChatTab* tab )
 {
-    m_tabWidget->removePage(chatWidget);
+    kDebug();
+
+    m_tabWidget->addTab(tab, tab->icon(), tab->title());
+    m_tabWidget->setCurrentWidget(tab);
+
+    if (m_tabWidget->isTabBarHidden()) {
+        if (m_tabWidget->count() > 1) {
+            m_tabWidget->setTabBarHidden(false);
+        }
+    }
+}
+
+void ChatWindow::destroyTab(QWidget* chatWidget)
+{
+    kDebug();
+    
+    ChatTab* tab = qobject_cast<ChatTab*>(chatWidget);
+    Q_ASSERT(tab);
+    
+    tab->setWindow(NULL);
     delete chatWidget;
 }
 
@@ -161,7 +214,7 @@ void ChatWindow::setTabTextColor(int index, const QColor& color)
 
 void ChatWindow::closeCurrentTab()
 {
-    removeTab(m_tabWidget->currentWidget());
+    destroyTab(m_tabWidget->currentWidget());
 }
 
 void ChatWindow::onAudioCallTriggered()
@@ -363,17 +416,12 @@ void ChatWindow::showNotificationsDialog()
 
 void ChatWindow::createNewChat(const Tp::TextChannelPtr &channelPtr, const Tp::AccountPtr &accountPtr)
 {
+    kDebug();
+    
     ChatTab *chatTab = new ChatTab(channelPtr, accountPtr, m_tabWidget);
     setupChatTabSignals(chatTab);
-    chatTab->setTabWidget(m_tabWidget);
-    m_tabWidget->addTab(chatTab, chatTab->icon(), chatTab->title());
-    m_tabWidget->setCurrentWidget(chatTab);
-
-    if (m_tabWidget->isTabBarHidden()) {
-        if (m_tabWidget->count() > 1) {
-            m_tabWidget->setTabBarHidden(false);
-        }
-    }
+    
+    chatTab->setWindow(this);
 }
 
 void ChatWindow::sendNotificationToUser(ChatWindow::NotificationType type, const QString& errorMsg)
diff --git a/app/chat-window.h b/app/chat-window.h
index 2b2b70d..5499101 100644
--- a/app/chat-window.h
+++ b/app/chat-window.h
@@ -25,6 +25,7 @@
 #include <KXmlGuiWindow>
 #include <KTabWidget>
 
+class TelepathyChatUi;
 class KIcon;
 class ChatTab;
 
@@ -46,16 +47,31 @@ public:
      * chat doesn't already exist
      * @param incomingTextChannel new text channel
      */
-    void startChat(const Tp::TextChannelPtr &incomingTextChannel, const Tp::AccountPtr &account);
-    void removeTab(ChatTab *chatWidget);
+//     void startChat(const Tp::TextChannelPtr &incomingTextChannel, const Tp::AccountPtr &account);
+    void destroyTab(ChatTab *chatWidget);
     void setTabText(int index, const QString &newTitle);
     void setTabIcon(int index, const KIcon &newIcon);
     void setTabTextColor(int index,const QColor &color);
-
+	ChatTab* getTab(const Tp::TextChannelPtr &incomingTextChannel);
+	void focusChat(ChatTab* tab);
+	/** creats a new chat and adds it to the tab widget
+     * @param channelPtr pointer to textChannel to use
+     */
+    void createNewChat(const Tp::TextChannelPtr &channelPtr, const Tp::AccountPtr &account);
+    void addTab(ChatTab* tab);
+    void removeTab(ChatTab* tab);
+
+	TelepathyChatUi* ui();
+	void setUi(TelepathyChatUi* ui);
+signals:
+    void aboutToClose();
+    void dettachRequested(ChatTab*);
+    
 public slots:
-    void removeTab(QWidget *chatWidget);
+    void destroyTab(QWidget *chatWidget);
 
 private slots:
+    void tabBarContextMenu(int  index, const QPoint &  globalPos);
     void closeCurrentTab();
     void onAudioCallTriggered();                                /** start an audio call */
     void onCurrentIndexChanged(int index);
@@ -78,10 +94,7 @@ protected slots:
     void showNotificationsDialog();
 
 private:
-    /** creats a new chat and adds it to the tab widget
-     * @param channelPtr pointer to textChannel to use
-     */
-    void createNewChat(const Tp::TextChannelPtr &channelPtr, const Tp::AccountPtr &account);
+    
 
     /** sends notification to the user via plasma desktop notification system
      * @param type notification type
@@ -122,6 +135,8 @@ private:
     void startVideoCall(const Tp::AccountPtr &account, const Tp::ContactPtr &contact);
 
     KTabWidget *m_tabWidget;
+	
+	TelepathyChatUi* m_chatUi;
 };
 
 #endif // CHATWINDOW_H
diff --git a/app/telepathy-chat-ui.cpp b/app/telepathy-chat-ui.cpp
index 1654a9d..819f0ff 100644
--- a/app/telepathy-chat-ui.cpp
+++ b/app/telepathy-chat-ui.cpp
@@ -36,8 +36,33 @@ TelepathyChatUi::TelepathyChatUi()
     : KApplication(), AbstractClientHandler(channelClassList())
 {
     kDebug();
+    createWindow();
+}
+
+void TelepathyChatUi::removeWindow()
+{
+    ChatWindow* window = qobject_cast<ChatWindow*>(sender());
+    Q_ASSERT(window);
+    m_chatWindows.removeOne(window);
+}
+
+ChatWindow* TelepathyChatUi::createWindow()
+{
+    kDebug();
 
-    m_chatWindow = new ChatWindow();
+    ChatWindow* window = new ChatWindow();
+    connect(window, SIGNAL(aboutToClose()), SLOT(removeWindow()));
+    connect(window, SIGNAL(dettachRequested(ChatTab*)), SLOT(dettachTab(ChatTab*)));
+    m_chatWindows.push_back(window);
+    
+    return window;
+}
+
+void TelepathyChatUi::dettachTab(ChatTab* tab)
+{
+    ChatWindow* window = createWindow();
+    tab->setWindow(window);
+    window->show();
 }
 
 TelepathyChatUi::~TelepathyChatUi()
@@ -69,9 +94,28 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
 
     Q_ASSERT(textChannel);
 
-    // create new chat
-    m_chatWindow->startChat(textChannel, account);
-    m_chatWindow->show();
+    bool tabFound = false;
+    foreach(ChatWindow* window, m_chatWindows) {
+        ChatTab* tab = window->getTab(textChannel);
+        if(tab){
+            tabFound = true;
+            
+            tab->showOnTop();                                       // 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 (!tab->textChannel()->isValid()) {
+                tab->setTextChannel(textChannel);    // replace with new one
+                tab->setChatEnabled(true);                   // re-enable chat
+            }
+        }
+    }
+
+    if(!tabFound) {
+        ChatWindow* window = m_chatWindows[0];
+        window->createNewChat(textChannel, account);
+        window->show();
+    }
     context->setFinished();
 }
 
diff --git a/app/telepathy-chat-ui.h b/app/telepathy-chat-ui.h
index 306912d..819e10e 100644
--- a/app/telepathy-chat-ui.h
+++ b/app/telepathy-chat-ui.h
@@ -28,6 +28,8 @@
 
 class TelepathyChatUi : public KApplication, public Tp::AbstractClientHandler
 {
+    Q_OBJECT
+
 public:
     TelepathyChatUi();
     ~TelepathyChatUi();
@@ -41,9 +43,15 @@ public:
             const Tp::AbstractClientHandler::HandlerInfo & handlerInfo);
 
     virtual bool bypassApproval() const;
+    
+private slots:
+	void removeWindow();
+    void dettachTab(ChatTab*);
 
 private:
-    ChatWindow *m_chatWindow;
+    ChatWindow* createWindow();
+    
+    QList<ChatWindow*> m_chatWindows;
 };
 
 #endif // TELEPATHYCHATUI_H

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list