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


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

The following commit has been merged in the master branch:
commit 8585a5efdc2b629e38376f255e7eca75f77cd94d
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Wed Dec 19 13:06:18 2012 +0000

    Add a new list model of Contacts
---
 KTp/Models/CMakeLists.txt                          |  34 ++--
 KTp/Models/contacts-list-model.cpp                 | 197 +++++++++++++++++++++
 .../contacts-list-model.h}                         |  42 +++--
 KTp/contact-factory.h                              |   4 +-
 KTp/contact.h                                      |   5 +-
 5 files changed, 250 insertions(+), 32 deletions(-)

diff --git a/KTp/Models/CMakeLists.txt b/KTp/Models/CMakeLists.txt
index b83512e..18ceaee 100644
--- a/KTp/Models/CMakeLists.txt
+++ b/KTp/Models/CMakeLists.txt
@@ -6,30 +6,32 @@ include_directories (${CMAKE_CURRENT_BINARY_DIR}
 set (ktp_models_private_SRCS
     accounts-list-model.cpp
     accounts-filter-model.cpp
-    accounts-model-item.cpp
+    accounts-model-item.cpp #Deprecated
     ../capabilities-hack-private.cpp #HACK, COPY INTO BOTH LIBRARIES UNTIL ContactModels IS REPLACED
     ../service-availability-checker.cpp #
-    contact-model-item.cpp
-    contacts-model.cpp
-    groups-model-item.cpp
-    groups-model.cpp
-    proxy-tree-node.cpp
-    tree-node.cpp
-    flat-model-proxy.cpp
+    contacts-list-model.cpp
+    contact-model-item.cpp #Deprecated
+    contacts-model.cpp #Deprecated
+    groups-model-item.cpp #Deprecated
+    groups-model.cpp #Deprecated
+    proxy-tree-node.cpp #Deprecated
+    tree-node.cpp #Deprecated
+    flat-model-proxy.cpp #Deprecated
     rooms-model.cpp
 )
 
 set (ktp_models_private_HDRS
     accounts-list-model.h
     accounts-filter-model.h
-    accounts-model-item.h
-    contact-model-item.h
-    contacts-model.h
-    groups-model-item.h
-    groups-model.h
-    proxy-tree-node.h
-    tree-node.h
-    flat-model-proxy.h
+    accounts-model-item.h #Deprecated
+    contact-model-item.h #Deprecated
+    contacts-model.h #Deprecated
+    contacts-list-model.h
+    groups-model-item.h #Deprecated
+    groups-model.h #Deprecated
+    proxy-tree-node.h #Deprecated
+    tree-node.h #Deprecated
+    flat-model-proxy.h #Deprecated
     rooms-model.h
 )
 
diff --git a/KTp/Models/contacts-list-model.cpp b/KTp/Models/contacts-list-model.cpp
new file mode 100644
index 0000000..b048f76
--- /dev/null
+++ b/KTp/Models/contacts-list-model.cpp
@@ -0,0 +1,197 @@
+/*
+* Copyright (C) 2012 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 "contacts-list-model.h"
+#include "contact.h"
+
+#include <TelepathyQt/Account>
+#include <TelepathyQt/Contact>
+#include <TelepathyQt/ContactCapabilities>
+#include <TelepathyQt/Connection>
+#include <TelepathyQt/ContactManager>
+
+#include <KTp/Models/contacts-model.h>
+#include <KTp/presence.h>
+
+class KTp::ContactsListModel::Private
+{
+public:
+    QList<Tp::ContactPtr> contacts;
+    KTp::GlobalContactManager *contactManager;
+};
+
+
+KTp::ContactsListModel::ContactsListModel(QObject *parent) :
+    QAbstractListModel(parent),
+    d(new KTp::ContactsListModel::Private())
+{
+    d->contactManager = 0;
+}
+
+KTp::ContactsListModel::~ContactsListModel()
+{
+    delete d;
+}
+
+void KTp::ContactsListModel::setAccountManager(const Tp::AccountManagerPtr &accountManager)
+{
+    d->contactManager = new KTp::GlobalContactManager(accountManager, this);
+    onContactsChanged(d->contactManager->allKnownContacts(), Tp::Contacts());
+    connect(d->contactManager, SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts)), SLOT(onContactsChanged(Tp::Contacts,Tp::Contacts)));
+}
+
+int KTp::ContactsListModel::rowCount(const QModelIndex &parent) const
+{
+    Q_UNUSED (parent);
+    return d->contacts.size();
+}
+
+QVariant KTp::ContactsListModel::data(const QModelIndex &index, int role) const
+{
+    int row = index.row();
+
+    if (row >=0 && row < d->contacts.size()) {
+        const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(d->contacts[row]);
+
+        switch (role) {
+        case ContactsModel::IdRole:
+            return contact->id();
+        case ContactsModel::TypeRole:
+            return ContactsModel::ContactRowType;
+        case ContactsModel::ContactRole:
+            return QVariant::fromValue(contact);
+        case ContactsModel::AccountRole:
+            return QVariant::fromValue(d->contactManager->accountForContact(contact));
+        case Qt::DisplayRole:
+            return contact->alias();
+        case ContactsModel::AliasRole:
+            return contact->alias();
+        case ContactsModel::PresenceRole:
+            return QVariant::fromValue(contact->presence());
+        case ContactsModel::PresenceIconRole:
+            return QIcon(contact->presence().icon());
+        case ContactsModel::PresenceStatusRole:
+            return contact->presence().status();
+        case ContactsModel::PresenceTypeRole:
+            return contact->presence().type();
+        case ContactsModel::PresenceMessageRole:
+            return contact->presence().statusMessage();
+        case ContactsModel::SubscriptionStateRole:
+            return contact->subscriptionState();
+        case ContactsModel::PublishStateRole:
+            return contact->publishState();
+        case ContactsModel::BlockedRole:
+            return contact->isBlocked();
+        case ContactsModel::GroupsRole:
+            return contact->groups();
+        case ContactsModel::AvatarRole:
+            return contact->avatarData().fileName;
+        case Qt::DecorationRole:
+            return QImage(contact->avatarData().fileName);
+        case ContactsModel::TextChatCapabilityRole:
+            return contact->capabilities().textChats();
+        case ContactsModel::ClientTypesRole:
+            return contact->clientTypes();
+        default:
+            break;
+        }
+
+    }
+    return QVariant();
+}
+
+void KTp::ContactsListModel::onContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed)
+{
+    //add contacts.
+
+    Q_FOREACH(const Tp::ContactPtr &contact_uncasted, added) {
+        KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(contact_uncasted);
+
+        connect(contact.data(),
+                    SIGNAL(aliasChanged(QString)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(avatarTokenChanged(QString)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(avatarDataChanged(Tp::AvatarData)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(presenceChanged(Tp::Presence)),
+                    SLOT(onChanged()));
+            connect(contact->manager()->connection()->selfContact().data(),
+                    SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(capabilitiesChanged(Tp::ContactCapabilities)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(locationUpdated(Tp::LocationInfo)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(infoFieldsChanged(Tp::Contact::InfoFields)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(publishStateChanged(Tp::Contact::PresenceState,QString)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(blockStatusChanged(bool)),
+                    SLOT(onChanged()));
+            connect(contact.data(),
+                    SIGNAL(clientTypesChanged(QStringList)),
+                    SLOT(onChanged()));
+
+            connect(contact.data(), SIGNAL(invalidated()), SLOT(onConnectionDropped()));
+    }
+
+    if (added.size() > 0) {
+        beginInsertRows(QModelIndex(), d->contacts.size(), d->contacts.size() + added.size() -1);
+        d->contacts.append(added.toList());
+        endInsertRows();
+    }
+
+    //remove contacts
+    Q_FOREACH(const Tp::ContactPtr &contact, removed) {
+        int row = d->contacts.indexOf(contact);
+        if (row >= 0) { //if contact found in list
+            beginRemoveRows(QModelIndex(), row, row);
+            d->contacts.removeOne(contact);
+            endInsertRows();
+        }
+    }
+}
+
+void KTp::ContactsListModel::onChanged()
+{
+    KTp::ContactPtr contact(qobject_cast<KTp::Contact*>(sender()));
+    int row = d->contacts.indexOf(contact);
+    if (row > 0) {
+        QModelIndex index = createIndex(row, 0);
+        dataChanged(index, index);
+    }
+}
+
+void KTp::ContactsListModel::onConnectionDropped()
+{
+    KTp::ContactPtr contact(qobject_cast<KTp::Contact*>(sender()));
+    onContactsChanged(Tp::Contacts(), Tp::Contacts() << contact);
+}
+
diff --git a/KTp/contact-factory.h b/KTp/Models/contacts-list-model.h
similarity index 53%
copy from KTp/contact-factory.h
copy to KTp/Models/contacts-list-model.h
index 203b761..a2d5821 100644
--- a/KTp/contact-factory.h
+++ b/KTp/Models/contacts-list-model.h
@@ -16,22 +16,40 @@
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
 
-#ifndef KTP_CONTACT_FACTORY_H
-#define KTP_CONTACT_FACTORY_H
+#ifndef KTP_CONTACTS_LIST_MODEL_H
+#define KTP_CONTACTS_LIST_MODEL_H
 
-#include <TelepathyQt/ContactFactory>
+#include <QAbstractListModel>
 #include <TelepathyQt/Types>
 
-namespace KTp {
-class ContactFactory : public Tp::ContactFactory
+#include <KTp/global-contact-manager.h>
+
+namespace KTp
+{
+
+class ContactsListModel : public QAbstractListModel
 {
+    Q_OBJECT
 public:
-    static Tp::ContactFactoryPtr create(const Tp::Features &features=Tp::Features());
-protected:
-    ContactFactory(const Tp::Features &features);
-    virtual Tp::ContactPtr construct(Tp::ContactManager *manager, const Tp::ReferencedHandles &handle, const Tp::Features &features, const QVariantMap &attributes) const;
-};
-}
+    explicit ContactsListModel(QObject *parent = 0);
+    virtual ~ContactsListModel();
+
+    void setAccountManager(const Tp::AccountManagerPtr &accountManager);
 
+    int rowCount(const QModelIndex &parent) const;
+    QVariant data(const QModelIndex &index, int role) const;
 
-#endif // CONTACTFACTORY_H
+private Q_SLOTS:
+    void onContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed);
+    void onChanged();
+    void onConnectionDropped();
+
+private:
+    //FIXME d_ptr
+    class Private;
+    Private *d;
+
+};
+
+}
+#endif // CONTACTSLISTMODEL_H
diff --git a/KTp/contact-factory.h b/KTp/contact-factory.h
index 203b761..5881451 100644
--- a/KTp/contact-factory.h
+++ b/KTp/contact-factory.h
@@ -22,8 +22,10 @@
 #include <TelepathyQt/ContactFactory>
 #include <TelepathyQt/Types>
 
+#include <KTp/ktp-export.h>
+
 namespace KTp {
-class ContactFactory : public Tp::ContactFactory
+class KTP_EXPORT ContactFactory : public Tp::ContactFactory
 {
 public:
     static Tp::ContactFactoryPtr create(const Tp::Features &features=Tp::Features());
diff --git a/KTp/contact.h b/KTp/contact.h
index 1763162..2d803b7 100644
--- a/KTp/contact.h
+++ b/KTp/contact.h
@@ -22,12 +22,11 @@
 #include <QVariant>
 #include <TelepathyQt/Contact>
 #include <KTp/presence.h>
+#include <KTp/ktp-export.h>
 
-//K_GLOBAL_STATIC_WITH_ARGS(KTp::ServiceAvailabilityChecker, s_krfbAvailableChecker,
-//                          (QLatin1String("org.freedesktop.Telepathy.Client.krfb_rfb_handler")));
 
 namespace KTp{
-class Contact : public Tp::Contact
+class KTP_EXPORT Contact : public Tp::Contact
 {
     Q_OBJECT
 public:

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list