[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:24:38 UTC 2016


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

The following commit has been merged in the master branch:
commit 5506ceed15fdd88b47a6f2715587bfcba8c532fa
Author: Dan Vrátil <dvratil at redhat.com>
Date:   Tue Apr 29 16:51:52 2014 +0200

    Don't leave group chat room when window is closed
    
    When "Don't leave chat room when window is closed" settings is enabled, the
    channel is not closed when user closes the tab or window, but is maintained
    by TelepathyChatUi. The channel can be left via Conversation -> Leave room
    action.
    
    REVIEW: 117543
---
 app/chat-tab.cpp           |   1 +
 app/chat-tab.h             |   3 +
 app/chat-window.cpp        |  27 +++++++
 app/chat-window.h          |   2 +
 app/telepathy-chat-ui.cpp  | 181 ++++++++++++++++++++++++++++++++++++++++++---
 app/telepathy-chat-ui.h    |  24 +++++-
 config/behavior-config.cpp |  11 +++
 config/behavior-config.h   |   2 +
 config/behavior-config.ui  |  22 ++++++
 lib/chat-widget.cpp        |   1 -
 lib/notify-filter.cpp      |   8 +-
 lib/notify-filter.h        |   5 +-
 lib/text-chat-config.cpp   |  17 +++++
 lib/text-chat-config.h     |   3 +
 14 files changed, 290 insertions(+), 17 deletions(-)

diff --git a/app/chat-tab.cpp b/app/chat-tab.cpp
index 5c9308a..6426f6c 100644
--- a/app/chat-tab.cpp
+++ b/app/chat-tab.cpp
@@ -45,6 +45,7 @@ ChatTab::ChatTab(const Tp::TextChannelPtr& channel, const Tp::AccountPtr& accoun
 
 ChatTab::~ChatTab()
 {
+    Q_EMIT aboutToClose(this);
 }
 
 void ChatTab::setChatWindow(ChatWindow* window)
diff --git a/app/chat-tab.h b/app/chat-tab.h
index 0bb9dcf..c4b2e78 100644
--- a/app/chat-tab.h
+++ b/app/chat-tab.h
@@ -50,6 +50,9 @@ public:
 public Q_SLOTS:
     void showOnTop();
 
+Q_SIGNALS:
+    void aboutToClose(ChatTab *tab);
+
 private Q_SLOTS:
     /** connect account's connection status.
      * This re-enables open chats if user goes offline and then back online */
diff --git a/app/chat-window.cpp b/app/chat-window.cpp
index 67059c8..1125496 100644
--- a/app/chat-window.cpp
+++ b/app/chat-window.cpp
@@ -217,6 +217,17 @@ ChatTab* ChatWindow::getTab(const Tp::AccountPtr &account, const Tp::TextChannel
 ChatTab *ChatWindow::getCurrentTab()
 {
     return qobject_cast<ChatTab*>(m_tabWidget->currentWidget());
+
+}
+
+QList<ChatTab*> ChatWindow::tabs() const
+{
+    QList<ChatTab*> tabs;
+    tabs.reserve(m_tabWidget->count());
+    for (int i = 0; i < m_tabWidget->count(); ++i) {
+        tabs << qobject_cast<ChatTab*>(m_tabWidget->widget(i));
+    }
+    return tabs;
 }
 
 void ChatWindow::removeTab(ChatTab *tab)
@@ -381,6 +392,11 @@ void ChatWindow::onCurrentIndexChanged(int index)
         setShowInfoEnabled(false);
     }
 
+    // Allow "Leaving" rooms only in group chat, and when persistent rooms are enabled
+    actionCollection()->action(QLatin1String("leave-chat"))->setEnabled(currentChatTab->isGroupChat() && TextChatConfig::instance()->dontLeaveGroupChats());
+    // No point having "Close" action with only one tab, it behaves exactly like "Quit"
+    actionCollection()->action(QLatin1String("file_close"))->setVisible(m_tabWidget->count() > 1);
+
     if ( currentChatTab->account()->connection() ) {
         const QString collab(QLatin1String("infinote"));
         bool selfCanShare = currentChatTab->account()->connection()->selfContact()->capabilities().streamTubes(collab);
@@ -802,6 +818,9 @@ void ChatWindow::setupCustomActions()
     KAction* showInfoAction = new KAction(KIcon(QLatin1String("view-pim-contacts")), i18n("&Contact info"), this);
     connect(showInfoAction, SIGNAL(triggered()), this, SLOT(onShowInfoTriggered()));
 
+    KAction* leaveAction = new KAction(KIcon(QLatin1String("irc-close-channel")), i18n("&Leave room"), this);
+    connect(leaveAction, SIGNAL(triggered()), this, SLOT(onLeaveChannelTriggered()));
+
     m_spellDictCombo = new Sonnet::DictionaryComboBox();
     connect(m_spellDictCombo, SIGNAL(dictionaryChanged(QString)),
             this, SLOT(setTabSpellDictionary(QString)));
@@ -855,6 +874,7 @@ void ChatWindow::setupCustomActions()
     actionCollection()->addAction(QLatin1String("send-message"), m_sendMessage);
     actionCollection()->addAction(QLatin1String("collaborate-document"), collaborateDocumentAction);
     actionCollection()->addAction(QLatin1String("contact-info"), showInfoAction);
+    actionCollection()->addAction(QLatin1String("leave-chat"), leaveAction);
 }
 
 void ChatWindow::setCollaborateDocumentEnabled(bool enable)
@@ -1133,4 +1153,11 @@ void ChatWindow::onReloadTheme()
     }
 }
 
+void ChatWindow::onLeaveChannelTriggered()
+{
+    ChatTab *tab = getCurrentTab();
+    tab->textChannel()->requestLeave();
+    closeCurrentTab();
+}
+
 #include "chat-window.moc"
diff --git a/app/chat-window.h b/app/chat-window.h
index 72bbd1d..bfd6db5 100644
--- a/app/chat-window.h
+++ b/app/chat-window.h
@@ -59,6 +59,7 @@ public:
      */
     ChatTab* getTab(const Tp::AccountPtr &account, const Tp::TextChannelPtr &incomingTextChannel);
     ChatTab* getCurrentTab();
+    QList<ChatTab*> tabs() const;
 
     void focusChat(ChatTab *tab);
 
@@ -115,6 +116,7 @@ private Q_SLOTS:
     void updateSendMessageShortcuts();
     void onReloadTheme();
     void onCollaborateDocumentTriggered();
+    void onLeaveChannelTriggered();
 
 protected Q_SLOTS:
     void showSettingsDialog();
diff --git a/app/telepathy-chat-ui.cpp b/app/telepathy-chat-ui.cpp
index 33150b8..d27c6f2 100644
--- a/app/telepathy-chat-ui.cpp
+++ b/app/telepathy-chat-ui.cpp
@@ -2,6 +2,7 @@
     Copyright (C) 2010  David Edmundson    <kde at davidedmundson.co.uk>
     Copyright (C) 2011  Dominik Schmidt    <dev at dominik-schmidt.de>
     Copyright (C) 2011  Francesco Nwokeka  <francesco.nwokeka at gmail.com>
+    Copyright (C) 2014  Daniel Vrátil      <dvratil at redhat.com>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -21,16 +22,22 @@
 #include "chat-tab.h"
 #include "chat-window.h"
 #include "text-chat-config.h"
+#include "notify-filter.h"
+#include "text-chat-config.h"
+#include "defines.h"
 
 #include <KDebug>
 #include <KConfigGroup>
 #include <KWindowSystem>
+#include <KGlobal>
 
 #include <TelepathyQt/ChannelClassSpec>
 #include <TelepathyQt/TextChannel>
 #include <TelepathyQt/ChannelRequest>
 #include <TelepathyQt/ChannelRequestHints>
 
+#include <KTp/message-processor.h>
+
 
 inline Tp::ChannelClassSpecList channelClassList()
 {
@@ -41,17 +48,21 @@ inline Tp::ChannelClassSpecList channelClassList()
 
 
 TelepathyChatUi::TelepathyChatUi()
-    : KTp::TelepathyHandlerApplication(true, -1, -1), AbstractClientHandler(channelClassList())
+    : KTp::TelepathyHandlerApplication(true, -1, -1),
+      AbstractClientHandler(channelClassList())
 {
     kDebug();
+    m_notifyFilter = new NotifyFilter;
     ChatWindow *window = createWindow();
     window->show();
 }
 
-void TelepathyChatUi::removeWindow(ChatWindow *window)
+TelepathyChatUi::~TelepathyChatUi()
 {
-    Q_ASSERT(window);
-    m_chatWindows.removeOne(window);
+    Q_FOREACH (const Tp::TextChannelPtr &channel, m_channelAccountMap.keys()) {
+        channel->requestClose();
+    }
+    delete m_notifyFilter;
 }
 
 ChatWindow* TelepathyChatUi::createWindow()
@@ -59,13 +70,35 @@ ChatWindow* TelepathyChatUi::createWindow()
     ChatWindow* window = new ChatWindow();
 
     connect(window, SIGNAL(detachRequested(ChatTab*)), this, SLOT(dettachTab(ChatTab*)));
-    connect(window, SIGNAL(aboutToClose(ChatWindow*)), this, SLOT(removeWindow(ChatWindow*)));
+    connect(window, SIGNAL(aboutToClose(ChatWindow*)), this, SLOT(onWindowAboutToClose(ChatWindow*)));
 
     m_chatWindows.push_back(window);
 
     return window;
 }
 
+bool TelepathyChatUi::isHiddenChannel(const Tp::AccountPtr &account,
+                                      const Tp::TextChannelPtr& channel,
+                                      Tp::TextChannelPtr *oldChannel) const
+{
+    if (channel->targetHandleType() != Tp::HandleTypeRoom) {
+        return false;
+    }
+
+    QHash<Tp::TextChannelPtr,Tp::AccountPtr>::const_iterator it = m_channelAccountMap.constBegin();
+    for ( ; it != m_channelAccountMap.constEnd(); ++it) {
+        if (channel->targetId() == it.key()->targetId()
+            && channel->targetHandleType() == it.key()->targetHandleType()
+            && account == it.value())
+        {
+            *oldChannel = it.key();
+            return true;
+        }
+    }
+
+    return false;
+}
+
 void TelepathyChatUi::dettachTab(ChatTab* tab)
 {
     ChatWindow* window = createWindow();
@@ -73,10 +106,6 @@ void TelepathyChatUi::dettachTab(ChatTab* tab)
     window->show();
 }
 
-TelepathyChatUi::~TelepathyChatUi()
-{
-}
-
 void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & context,
         const Tp::AccountPtr &account,
         const Tp::ConnectionPtr &connection,
@@ -113,8 +142,21 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
         windowRaise = !channelRequest->hints().hint(QLatin1String("org.kde.telepathy"), QLatin1String("suppressWindowRaise")).toBool();
     }
 
+    kDebug() << "Incomming channel" << textChannel->targetId();
     kDebug() << "raise window hint set to: " << windowRaise;
 
+    Tp::TextChannelPtr oldTextChannel;
+    const bool isKnown = isHiddenChannel(account, textChannel, &oldTextChannel);
+    if (isKnown) {
+        // windowRaise is false, this is just an update after reconnect, so update
+        // cache, but don't create window
+        if (!windowRaise) {
+            releaseChannel(oldTextChannel, account, false);
+            takeChannel(textChannel, account, false);
+            return;
+        }
+    }
+
     bool tabFound = false;
 
     //search for any tabs which are already handling this channel.
@@ -144,7 +186,6 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
     }
 
     //if there is currently no tab containing the incoming channel.
-
     if (!tabFound) {
         ChatWindow* window = 0;
         switch (TextChatConfig::instance()->openMode()) {
@@ -166,6 +207,8 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
 
         ChatTab* tab = new ChatTab(textChannel, account);
         tab->setChatWindow(window);
+        connect(tab, SIGNAL(aboutToClose(ChatTab*)),
+                this, SLOT(onTabAboutToClose(ChatTab*)));
         window->show();
 
         if (windowRaise) {
@@ -173,6 +216,11 @@ void TelepathyChatUi::handleChannels(const Tp::MethodInvocationContextPtr<> & co
         }
     }
 
+    // the channel now has a tab and a window that owns it, so we can release it
+    if (!oldTextChannel.isNull()) {
+        releaseChannel(oldTextChannel, account);
+    }
+
     context->setFinished();
 }
 
@@ -181,3 +229,116 @@ bool TelepathyChatUi::bypassApproval() const
     return false;
 }
 
+void TelepathyChatUi::onTabAboutToClose(ChatTab *tab)
+{
+    kDebug() << tab;
+    const Tp::TextChannelPtr channel = tab->textChannel();
+
+    // Close 1-on-1 chats, but keep group chats opened if user has configured so
+    if (channel->targetHandleType() == Tp::HandleTypeContact || !TextChatConfig::instance()->dontLeaveGroupChats()) {
+        channel->requestClose();
+    } else {
+        takeChannel(channel, tab->account());
+    }
+}
+
+void TelepathyChatUi::onWindowAboutToClose(ChatWindow* window)
+{
+    Q_ASSERT(window);
+    m_chatWindows.removeOne(window);
+
+    // Take all tabs now. When tab emits aboutToClose, it's too late to call KGlobal::ref(),
+    Q_FOREACH (ChatTab *tab, window->tabs()) {
+        disconnect(tab, SIGNAL(aboutToClose(ChatTab*)),
+                   this, SLOT(onTabAboutToClose(ChatTab*)));
+        onTabAboutToClose(tab);
+    }
+}
+
+void TelepathyChatUi::takeChannel(const Tp::TextChannelPtr& channel, const Tp::AccountPtr& account, bool ref)
+{
+    kDebug() << channel->targetId();
+    m_channelAccountMap.insert(channel, account);
+    connectChannelNotifications(channel, true);
+    connectAccountNotifications(account, true);
+
+    if (ref) {
+        KGlobal::ref();
+    }
+}
+
+void TelepathyChatUi::releaseChannel(const Tp::TextChannelPtr& channel, const Tp::AccountPtr& account, bool unref)
+{
+    kDebug() << channel->targetId();
+    m_channelAccountMap.remove(channel);
+    connectChannelNotifications(channel, false);
+    if (m_channelAccountMap.keys(account).count() == 0) {
+        connectAccountNotifications(account, false);
+    }
+
+    if (unref) {
+        KGlobal::deref();
+    }
+}
+
+void TelepathyChatUi::connectAccountNotifications(const Tp::AccountPtr& account, bool enable)
+{
+    if (enable) {
+        connect(account.constData(), SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
+                this, SLOT(onConnectionStatusChanged(Tp::ConnectionStatus)),
+                Qt::UniqueConnection);
+    } else {
+        disconnect(account.constData(), SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)),
+                   this, SLOT(onConnectionStatusChanged(Tp::ConnectionStatus)));
+    }
+}
+
+
+void TelepathyChatUi::connectChannelNotifications(const Tp::TextChannelPtr &textChannel, bool enable)
+{
+    if (enable) {
+        connect(textChannel.constData(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
+                this, SLOT(onGroupChatMessageReceived(Tp::ReceivedMessage)));
+        connect(textChannel.constData(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
+                this, SLOT(onChannelInvalidated()));
+    } else {
+        disconnect(textChannel.constData(), SIGNAL(messageReceived(Tp::ReceivedMessage)),
+                this, SLOT(onGroupChatMessageReceived(Tp::ReceivedMessage)));
+        disconnect(textChannel.constData(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)),
+                this, SLOT(onChannelInvalidated()));
+    }
+}
+
+
+void TelepathyChatUi::onGroupChatMessageReceived(const Tp::ReceivedMessage& message)
+{
+    const Tp::TextChannelPtr channel(qobject_cast<Tp::TextChannel*>(sender()));
+    Tp::AccountPtr account = m_channelAccountMap.value(channel);
+
+    KTp::Message processedMessage(KTp::MessageProcessor::instance()->processIncomingMessage(message, account, channel));
+    m_notifyFilter->filterMessage(processedMessage, KTp::MessageContext(account, channel));
+}
+
+void TelepathyChatUi::onChannelInvalidated()
+{
+    const Tp::TextChannelPtr channel(qobject_cast<Tp::TextChannel*>(sender()));
+    releaseChannel(channel, m_channelAccountMap.value(channel));
+}
+
+void TelepathyChatUi::onConnectionStatusChanged(Tp::ConnectionStatus status)
+{
+    if (status != Tp::ConnectionStatusConnected) {
+        return;
+    }
+
+    Tp::ChannelRequestHints hints;
+    hints.setHint(QLatin1String("org.kde.telepathy"),QLatin1String("suppressWindowRaise"), QVariant(true));
+
+    const Tp::AccountPtr account(qobject_cast<Tp::Account*>(sender()));
+    Q_FOREACH (const Tp::TextChannelPtr &channel, m_channelAccountMap.keys(account)) {
+        account->ensureTextChatroom(channel->targetId(),
+                                    QDateTime::currentDateTime(),
+                                    QLatin1String(KTP_TEXTUI_CLIENT_PATH),
+                                    hints);
+    }
+}
diff --git a/app/telepathy-chat-ui.h b/app/telepathy-chat-ui.h
index 97bc4b7..9bb2440 100644
--- a/app/telepathy-chat-ui.h
+++ b/app/telepathy-chat-ui.h
@@ -26,6 +26,14 @@
 
 #include <KTp/telepathy-handler-application.h>
 
+namespace KTp {
+class AbstractMessageFilter;
+}
+
+namespace Tp {
+class ReceivedMessage;
+}
+
 class ChatTab;
 class ChatWindow;
 
@@ -47,14 +55,28 @@ public:
     virtual bool bypassApproval() const;
 
 private Q_SLOTS:
-    void removeWindow(ChatWindow *window);
     void dettachTab(ChatTab *tab);
 
+    void onTabAboutToClose(ChatTab *tab);
+    void onWindowAboutToClose(ChatWindow *window);
+    void onGroupChatMessageReceived(const Tp::ReceivedMessage &msg);
+    void onChannelInvalidated();
+    void onConnectionStatusChanged(Tp::ConnectionStatus);
+
 private:
+    void takeChannel(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account, bool ref = true);
+    void releaseChannel(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account, bool unref = true);
+    void connectChannelNotifications(const Tp::TextChannelPtr &textChannel, bool enable);
+    void connectAccountNotifications(const Tp::AccountPtr &account, bool enable);
+    bool isHiddenChannel(const Tp::AccountPtr &account, const Tp::TextChannelPtr &channel,
+                         Tp::TextChannelPtr *oldChannel) const;
     ChatWindow* createWindow();
 
     Tp::AccountManagerPtr m_accountManager;
     QList<ChatWindow*> m_chatWindows;
+
+    QHash<Tp::TextChannelPtr, Tp::AccountPtr> m_channelAccountMap;
+    KTp::AbstractMessageFilter *m_notifyFilter;
 };
 
 #endif // TELEPATHYCHATUI_H
diff --git a/config/behavior-config.cpp b/config/behavior-config.cpp
index 3c21ee9..f973378 100644
--- a/config/behavior-config.cpp
+++ b/config/behavior-config.cpp
@@ -57,6 +57,9 @@ BehaviorConfig::BehaviorConfig(QWidget *parent, const QVariantList& args)
     ui->checkBoxShowOthersTyping->setChecked(m_showOthersTyping);
     connect(ui->checkBoxShowOthersTyping, SIGNAL(toggled(bool)), this, SLOT(onShowOthersTypingChanged(bool)));
 
+    ui->dontLeaveGroupChats->setChecked(m_dontLeaveGroupChats);
+    connect(ui->dontLeaveGroupChats, SIGNAL(toggled(bool)), this, SLOT(onDontLeaveGroupChatsChanged(bool)));
+
     QStringList nicknameCompletionStyles;
     const QString namePlaceholder = ki18nc("Placeholder for contact name in completion suffix selector", "Nickname").toString();
     Q_FOREACH(const QString &suffix, BehaviorConfig::nicknameCompletionSuffixes) {
@@ -92,6 +95,7 @@ void BehaviorConfig::load()
     m_showOthersTyping = TextChatConfig::instance()->showOthersTyping();
     m_nicknameCompletionSuffix = TextChatConfig::instance()->nicknameCompletionSuffix();
     m_imageShareServiceType = TextChatConfig::instance()->imageShareServiceType();
+    m_dontLeaveGroupChats = TextChatConfig::instance()->dontLeaveGroupChats();
 }
 
 void BehaviorConfig::save()
@@ -102,6 +106,7 @@ void BehaviorConfig::save()
     TextChatConfig::instance()->setShowOthersTyping(m_showOthersTyping);
     TextChatConfig::instance()->setNicknameCompletionSuffix(m_nicknameCompletionSuffix);
     TextChatConfig::instance()->setImageShareServiceName(m_imageShareServiceType);
+    TextChatConfig::instance()->setDontLeaveGroupChats(m_dontLeaveGroupChats);
     TextChatConfig::instance()->sync();
 }
 
@@ -158,3 +163,9 @@ void BehaviorConfig::onImageSharingServiceChanged(int index)
     m_imageShareServiceType = ShareProvider::availableShareServices()[imageShareServiceName];
     Q_EMIT changed(true);
 }
+
+void BehaviorConfig::onDontLeaveGroupChatsChanged(bool state)
+{
+    m_dontLeaveGroupChats = state;
+    Q_EMIT changed(true);
+}
diff --git a/config/behavior-config.h b/config/behavior-config.h
index a9c378d..389d3c8 100644
--- a/config/behavior-config.h
+++ b/config/behavior-config.h
@@ -52,12 +52,14 @@ private Q_SLOTS:
     void onShowOthersTypingChanged(bool state);
     void onNicknameCompletionStyleChanged(int index);
     void onImageSharingServiceChanged(int index);
+    void onDontLeaveGroupChatsChanged(bool state);
 
 private:
     TextChatConfig::TabOpenMode m_openMode;
     int m_scrollbackLength;
     bool m_showMeTyping; // show others I am typing
     bool m_showOthersTyping; // show me others are typing
+    bool m_dontLeaveGroupChats;
     QString m_nicknameCompletionSuffix;
     ShareProvider::ShareService m_imageShareServiceType;
     Ui::BehaviorConfigUi *ui;
diff --git a/config/behavior-config.ui b/config/behavior-config.ui
index 11f7030..60836a3 100644
--- a/config/behavior-config.ui
+++ b/config/behavior-config.ui
@@ -190,6 +190,28 @@
     </widget>
    </item>
    <item>
+    <widget class="QGroupBox" name="groupChatsGroup">
+     <property name="title">
+      <string>Group Chats</string>
+     </property>
+     <layout class="QFormLayout" name="formLayout">
+      <property name="fieldGrowthPolicy">
+       <enum>QFormLayout::ExpandingFieldsGrow</enum>
+      </property>
+      <item row="0" column="0">
+       <widget class="QCheckBox" name="dontLeaveGroupChats">
+        <property name="toolTip">
+         <string extracomment="When enabled, you will remain connected to a chat room even when you close the chat window and you will still receive notifications, for example when someone highlights your name."/>
+        </property>
+        <property name="text">
+         <string>Stay connected to group chat even when tab is closed</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
diff --git a/lib/chat-widget.cpp b/lib/chat-widget.cpp
index c4f2ea5..d186cc7 100644
--- a/lib/chat-widget.cpp
+++ b/lib/chat-widget.cpp
@@ -246,7 +246,6 @@ ChatWidget::ChatWidget(const Tp::TextChannelPtr & channel, const Tp::AccountPtr
 ChatWidget::~ChatWidget()
 {
     saveSpellCheckingOption();
-    d->channel->requestClose(); // ensure closing; does nothing, if already closed
     delete d;
 }
 
diff --git a/lib/notify-filter.cpp b/lib/notify-filter.cpp
index 6807dac..5060618 100644
--- a/lib/notify-filter.cpp
+++ b/lib/notify-filter.cpp
@@ -57,7 +57,7 @@ void NotifyFilter::filterMessage(KTp::Message &message, const KTp::MessageContex
     if(message.type() == Tp::ChannelTextMessageTypeNotice) {
         notificationType = QLatin1String("kde_telepathy_info_event");
     } else {
-        if (m_widget->isGroupChat()) {
+        if (context.channel()->targetHandleType() == Tp::HandleTypeRoom) {
             if(message.property("highlight").toBool()) {
                 notificationType = QLatin1String("kde_telepathy_group_chat_highlight");
             } else {
@@ -67,7 +67,7 @@ void NotifyFilter::filterMessage(KTp::Message &message, const KTp::MessageContex
             notificationType = QLatin1String("kde_telepathy_contact_incoming");
         }
 
-        if (m_widget->isOnTop()) {
+        if (m_widget && m_widget->isOnTop()) {
             notificationType += QLatin1String("_active_window");
         }
     }
@@ -93,7 +93,9 @@ void NotifyFilter::filterMessage(KTp::Message &message, const KTp::MessageContex
     notification->setText(message.mainMessagePart().simplified());
 
     notification->setActions(QStringList(i18n("View")));
-    connect(notification, SIGNAL(activated(uint)), m_widget, SIGNAL(notificationClicked()));
+    if (m_widget) {
+        connect(notification, SIGNAL(activated(uint)), m_widget, SIGNAL(notificationClicked()));
+    }
 
     notification->sendEvent();
 }
diff --git a/lib/notify-filter.h b/lib/notify-filter.h
index f929ce3..30fb064 100644
--- a/lib/notify-filter.h
+++ b/lib/notify-filter.h
@@ -20,14 +20,15 @@
 #define NOTIFYFILTER_H
 
 #include "chat-widget.h"
+#include "ktpchat_export.h"
 
 #include <KTp/abstract-message-filter.h>
 
-class NotifyFilter : public KTp::AbstractMessageFilter
+class KDE_TELEPATHY_CHAT_EXPORT NotifyFilter : public KTp::AbstractMessageFilter
 {
     Q_OBJECT
 public:
-    explicit NotifyFilter(ChatWidget *widget);
+    explicit NotifyFilter(ChatWidget *widget = 0);
     void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
 
 private:
diff --git a/lib/text-chat-config.cpp b/lib/text-chat-config.cpp
index c268451..8f0b538 100644
--- a/lib/text-chat-config.cpp
+++ b/lib/text-chat-config.cpp
@@ -37,6 +37,7 @@ public:
     int m_scrollbackLength;
     bool m_showMeTyping;
     bool m_showOthersTyping;
+    bool m_dontLeaveGroupChats;
     QString m_nicknameCompletionSuffix;
     ShareProvider::ShareService m_imageShareServiceType;
 };
@@ -87,6 +88,8 @@ void TextChatConfig::sync()
 
     behaviorConfig.writeEntry("imageShareServiceType", static_cast<int>(d->m_imageShareServiceType));
 
+    behaviorConfig.writeEntry("dontLeaveGroupChats", d->m_dontLeaveGroupChats);
+
     behaviorConfig.sync();
 
     mutex.unlock();
@@ -196,6 +199,18 @@ void TextChatConfig::setImageShareServiceName(ShareProvider::ShareService servic
 }
 
 
+bool TextChatConfig::dontLeaveGroupChats() const
+{
+    return d->m_dontLeaveGroupChats;
+}
+
+void TextChatConfig::setDontLeaveGroupChats(bool dontLeaveGroupChats)
+{
+    mutex.lock();
+    d->m_dontLeaveGroupChats = dontLeaveGroupChats;
+    mutex.unlock();
+}
+
 TextChatConfig::TextChatConfig() :
     d(new TextChatConfigPrivate())
 {
@@ -220,6 +235,8 @@ TextChatConfig::TextChatConfig() :
 
     d->m_nicknameCompletionSuffix = behaviorConfig.readEntry("nicknameCompletionSuffix", ", ");
 
+    d->m_dontLeaveGroupChats = behaviorConfig.readEntry("dontLeaveGroupChats", false);
+
     // Imgur is the default image sharing service
     int shareServiceType = behaviorConfig.readEntry("imageShareServiceType", static_cast<int>(ShareProvider::Imgur));
     d->m_imageShareServiceType = static_cast<ShareProvider::ShareService>(shareServiceType);
diff --git a/lib/text-chat-config.h b/lib/text-chat-config.h
index e784708..fd90932 100644
--- a/lib/text-chat-config.h
+++ b/lib/text-chat-config.h
@@ -63,6 +63,9 @@ class KDE_TELEPATHY_CHAT_EXPORT TextChatConfig : QObject
     ShareProvider::ShareService imageShareServiceType() const;
     void setImageShareServiceName(ShareProvider::ShareService serviceType);
 
+    bool dontLeaveGroupChats() const;
+    void setDontLeaveGroupChats(bool dontLeaveGroupChats);
+
 private:
     TextChatConfig();
 

-- 
ktp-text-ui packaging



More information about the pkg-kde-commits mailing list