[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9

Maximiliano Curia maxy at moszumanska.debian.org
Mon May 9 09:06:23 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=a357ec8

The following commit has been merged in the master branch:
commit a357ec8543aaef77ebd22f20ba4aab1aff5fc5b6
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Sat Feb 9 02:39:46 2013 +0000

    Add HasTextChannel and UnreadMessageCount roles to contact list
    
    Model acts as an QIdentityModel and Tp::AbstractClientObserver for text channels
    on top of contact-list-model.
    
    REVIEW: 108871
---
 KTp/Models/CMakeLists.txt                       |   2 +
 KTp/Models/text-channel-watcher-proxy-model.cpp | 187 ++++++++++++++++++++++++
 KTp/Models/text-channel-watcher-proxy-model.h   |  61 ++++++++
 3 files changed, 250 insertions(+)

diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index 0d305e6..560747c 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -11,6 +11,7 @@ set (ktp_models_private_SRCS
     contacts-list-model.cpp
     contacts-model.cpp
     groups-tree-proxy-model.cpp
+    text-channel-watcher-proxy-model.cpp
     rooms-model.cpp
 )
 
@@ -22,6 +23,7 @@ set (ktp_models_private_HDRS
     contacts-list-model.h
     contacts-model.h
     groups-tree-proxy-model.h
+    text-channel-watcher-proxy-model.h
     rooms-model.h
 )
 
diff --git a/KTp/Models/text-channel-watcher-proxy-model.cpp b/KTp/Models/text-channel-watcher-proxy-model.cpp
new file mode 100644
index 0000000..0cf0956
--- /dev/null
+++ b/KTp/Models/text-channel-watcher-proxy-model.cpp
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2013 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "text-channel-watcher-proxy-model.h"
+
+#include <TelepathyQt/TextChannel>
+#include <TelepathyQt/ChannelClassSpecList>
+#include <TelepathyQt/MethodInvocationContext>
+#include <TelepathyQt/Types>
+#include <TelepathyQt/ReceivedMessage>
+
+#include <KTp/types.h>
+#include <KTp/contact.h>
+
+
+inline Tp::ChannelClassSpecList channelClasses() {
+    return Tp::ChannelClassSpecList() << Tp::ChannelClassSpec::textChat();
+}
+
+class ChannelWatcher : public QObject, public Tp::RefCounted
+{
+    Q_OBJECT
+public:
+    ChannelWatcher(const QPersistentModelIndex &index, const Tp::TextChannelPtr &channel, QObject *parent=0);
+    int unreadMessageCount() const;
+    QPersistentModelIndex modelIndex() const;
+Q_SIGNALS:
+    void messagesChanged();
+    void invalidated();
+private:
+    QPersistentModelIndex m_index;
+    Tp::TextChannelPtr m_channel;
+};
+
+typedef Tp::SharedPtr<ChannelWatcher> ChannelWatcherPtr;
+
+ChannelWatcher::ChannelWatcher(const QPersistentModelIndex &index, const Tp::TextChannelPtr &channel, QObject *parent):
+    QObject(parent),
+    m_index(index),
+    m_channel(channel)
+{
+    connect(channel.data(), SIGNAL(pendingMessageRemoved(Tp::ReceivedMessage)), SIGNAL(messagesChanged()));
+    connect(channel.data(), SIGNAL(messageReceived(Tp::ReceivedMessage)), SIGNAL(messagesChanged()));
+    connect(channel.data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), SIGNAL(invalidated()));
+
+    //trigger an update to the contact straight away
+    QTimer::singleShot(0, this, SIGNAL(messagesChanged()));
+}
+
+QPersistentModelIndex ChannelWatcher::modelIndex() const
+{
+    return m_index;
+}
+
+int ChannelWatcher::unreadMessageCount() const
+{
+    return m_channel->messageQueue().size();
+}
+
+
+
+
+namespace KTp {
+
+class TextChannelWatcherProxyModel::Private {
+public:
+    QHash<KTp::ContactPtr, ChannelWatcherPtr> currentChannels;
+};
+
+} //namespace
+
+
+
+
+KTp::TextChannelWatcherProxyModel::TextChannelWatcherProxyModel(QObject *parent) :
+    QIdentityProxyModel(parent),
+    Tp::AbstractClientObserver(channelClasses(), true),
+    d(new TextChannelWatcherProxyModel::Private)
+{
+}
+
+KTp::TextChannelWatcherProxyModel::~TextChannelWatcherProxyModel()
+{
+    delete d;
+}
+
+void KTp::TextChannelWatcherProxyModel::observeChannels(const Tp::MethodInvocationContextPtr<> &context, const Tp::AccountPtr &account, const Tp::ConnectionPtr &connection, const QList<Tp::ChannelPtr> &channels, const Tp::ChannelDispatchOperationPtr &dispatchOperation, const QList<Tp::ChannelRequestPtr> &requestsSatisfied, const Tp::AbstractClientObserver::ObserverInfo &observerInfo)
+{
+    Q_UNUSED(context)
+    Q_UNUSED(account)
+    Q_UNUSED(connection)
+    Q_UNUSED(dispatchOperation)
+    Q_UNUSED(requestsSatisfied)
+    Q_UNUSED(observerInfo)
+
+    if (!sourceModel()) {
+        return;
+    }
+
+    Q_FOREACH(const Tp::ChannelPtr & channel, channels) {
+        Tp::TextChannelPtr textChannel = Tp::TextChannelPtr::dynamicCast(channel);
+        if (textChannel) {
+            KTp::ContactPtr targetContact = KTp::ContactPtr::qObjectCast(textChannel->targetContact());
+
+            //skip group chats and situations where we don't have a single contact to mark messages for
+            if (targetContact.isNull()) {
+                continue;
+            }
+
+            //if it's not in our source model, ignore the channel
+            QModelIndexList matchedContacts = sourceModel()->match(QModelIndex(sourceModel()->index(0,0)), KTp::ContactRole, QVariant::fromValue(targetContact));
+            if (matchedContacts.size() !=1) {
+                continue;
+            }
+
+            QPersistentModelIndex contactIndex(matchedContacts[0]);
+
+            ChannelWatcherPtr watcher = ChannelWatcherPtr(new ChannelWatcher(contactIndex, textChannel));
+            d->currentChannels[targetContact] = watcher;
+
+            connect(watcher.data(), SIGNAL(messagesChanged()), SLOT(onChannelMessagesChanged()));
+        }
+    }
+}
+
+QVariant KTp::TextChannelWatcherProxyModel::data(const QModelIndex &proxyIndex, int role) const
+{
+    QModelIndex sourceIndex = mapToSource(proxyIndex);
+    if (role == KTp::ContactHasTextChannelRole) {
+        KTp::ContactPtr contact = sourceIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
+        if (contact) {
+            if (d->currentChannels.contains(contact)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    if (role == KTp::ContactUnreadMessageCountRole) {
+        KTp::ContactPtr contact = sourceIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
+        if (contact) {
+            if (d->currentChannels.contains(contact)) {
+                return d->currentChannels[contact]->unreadMessageCount();
+            }
+        }
+        return 0;
+    }
+
+    return sourceIndex.data(role);
+}
+
+void KTp::TextChannelWatcherProxyModel::onChannelMessagesChanged()
+{
+    ChannelWatcher* watcher = qobject_cast<ChannelWatcher*>(sender());
+    Q_ASSERT(watcher);
+    QModelIndex index = watcher->modelIndex();
+    dataChanged(index, index);
+}
+
+void KTp::TextChannelWatcherProxyModel::onChannelInvalidated()
+{
+    ChannelWatcher* watcher = qobject_cast<ChannelWatcher*>(sender());
+    Q_ASSERT(watcher);
+    QModelIndex index = watcher->modelIndex();
+    KTp::ContactPtr contact = index.data(KTp::ContactRole).value<KTp::ContactPtr>();
+
+    d->currentChannels.remove(contact);
+    dataChanged(index, index);
+}
+
+#include "text-channel-watcher-proxy-model.moc"
+#include "moc_text-channel-watcher-proxy-model.cpp"
diff --git a/KTp/Models/text-channel-watcher-proxy-model.h b/KTp/Models/text-channel-watcher-proxy-model.h
new file mode 100644
index 0000000..803211d
--- /dev/null
+++ b/KTp/Models/text-channel-watcher-proxy-model.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2013 David Edmundson <kde at davidedmundson.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef KTP_TEXT_CHANNEL_WATCHER_PROXY_MODEL_H
+#define KTP_TEXT_CHANNEL_WATCHER_PROXY_MODEL_H
+
+#include <TelepathyQt/AbstractClientObserver>
+#include <TelepathyQt/TextChannel>
+
+#include <QIdentityProxyModel>
+
+#include <ktp-export.h>
+
+namespace KTp
+{
+
+/** This class proxies the ContactsListModel, adding a role for ongoing chats*/
+class KTP_EXPORT TextChannelWatcherProxyModel : public QIdentityProxyModel, public Tp::AbstractClientObserver
+{
+    Q_OBJECT
+public:
+    explicit TextChannelWatcherProxyModel(QObject *parent=0);
+    virtual ~TextChannelWatcherProxyModel();
+
+    virtual void observeChannels(const Tp::MethodInvocationContextPtr<> &context,
+                                 const Tp::AccountPtr &account,
+                                 const Tp::ConnectionPtr &connection,
+                                 const QList<Tp::ChannelPtr> &channels,
+                                 const Tp::ChannelDispatchOperationPtr &dispatchOperation,
+                                 const QList<Tp::ChannelRequestPtr> &requestsSatisfied,
+                                 const Tp::AbstractClientObserver::ObserverInfo &observerInfo);
+
+    QVariant data(const QModelIndex &proxyIndex, int role) const;
+
+private Q_SLOTS:
+    void onChannelMessagesChanged();
+    void onChannelInvalidated();
+
+private:
+    class Private;
+    Private *d;
+};
+
+}
+
+#endif // KTP_TEXT_CHANNEL_WATCHER_PROXY_MODEL_H

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list