[SCM] ktp-contact-list packaging branch, master, updated. debian/15.12.1-2-1070-g6c56f91

Maximiliano Curia maxy at moszumanska.debian.org
Sat May 28 00:04:38 UTC 2016


Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=3378267

The following commit has been merged in the master branch:
commit 33782672f0fb7e64a6369fe77c6fdaa33f5ce5b2
Author: George Goldberg <grundleborg at googlemail.com>
Date:   Wed Mar 10 18:16:17 2010 +0000

    Start to introduce meta contacts, by creating Fake metacontacts for the all PersonContacts found.
    
    svn path=/trunk/playground/network/telepathy-contactlist/; revision=1101723
---
 CMakeLists.txt                        |   2 +
 contact-item.cpp                      |   2 +-
 contact-item.h                        |   3 +-
 contacts-list-model.cpp               | 247 ++++++++++++++++++++++++++++------
 contacts-list-model.h                 |  25 +++-
 main-widget.cpp                       |   6 +-
 meta-contact-item.cpp                 | 102 ++++++++++++++
 contact-item.h => meta-contact-item.h |  40 +++---
 8 files changed, 363 insertions(+), 64 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 61fe7f9..323aadf 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -121,6 +121,7 @@ nepomuk_add_ontology_classes (nie_SRCS
                               ${NFO_TRIG_SOURCE}
                               ${NCO_TRIG_SOURCE}
                               ${NMO_TRIG_SOURCE}
+                              ${PIMO_TRIG_SOURCE}
                               ${TELEPATHY_TRIG_SOURCE}
 )
 
@@ -144,6 +145,7 @@ set (contactlist_SRCS
      main-widget.cpp
      nepomuk-signal-watcher.cpp
      grouped-contacts-proxy-model.cpp
+     meta-contact-item.cpp
 )
 
 kde4_add_ui_files (contactlist_SRCS
diff --git a/contact-item.cpp b/contact-item.cpp
index fcc92fb..0c78910 100644
--- a/contact-item.cpp
+++ b/contact-item.cpp
@@ -28,7 +28,7 @@
 ContactItem::ContactItem(Nepomuk::PersonContact personContact,
                          Nepomuk::IMAccount imAccount,
                          QObject *parent)
-  : QObject(parent),
+  : ContactsListModelItem(parent),
     m_personContact(personContact),
     m_imAccount(imAccount),
     m_presenceIcon(new KIcon)
diff --git a/contact-item.h b/contact-item.h
index a80490a..c278af0 100644
--- a/contact-item.h
+++ b/contact-item.h
@@ -23,6 +23,7 @@
 #define TELEPATHY_CONTACTSLIST_PROTOTYPE_CONTACT_ITEM_H
 
 #include "nepomuk-signal-watcher.h"
+#include "contacts-list-model.h"
 
 #include "imaccount.h"
 #include "personcontact.h"
@@ -31,7 +32,7 @@
 
 #include <QObject>
 
-class ContactItem : public QObject, NepomukSignalWatcher::Watcher {
+class ContactItem : public ContactsListModelItem, NepomukSignalWatcher::Watcher {
 
     Q_OBJECT
 
diff --git a/contacts-list-model.cpp b/contacts-list-model.cpp
index 2be7236..22d0362 100644
--- a/contacts-list-model.cpp
+++ b/contacts-list-model.cpp
@@ -22,6 +22,7 @@
 #include "contacts-list-model.h"
 
 #include "contact-item.h"
+#include "meta-contact-item.h"
 
 // Nepomuk Vocabulary URIs
 #include "nepomuk/pimo.h"
@@ -30,6 +31,7 @@
 
 // Nepomuk Resources
 #include "imaccount.h"
+#include "person.h"
 #include "personcontact.h"
 
 #include <KDebug>
@@ -40,14 +42,65 @@
 #include <Soprano/Model>
 #include <Soprano/QueryResultIterator>
 
+#include <unistd.h>
+
+ContactsListModelItem::ContactsListModelItem(QObject *parent)
+ : QObject(parent),
+   m_parent(0)
+{
+
+}
+
+ContactsListModelItem::~ContactsListModelItem()
+{
+
+}
+
+QList<ContactsListModelItem*> ContactsListModelItem::childItems() const
+{
+    return m_children;
+}
+
+ContactsListModelItem *ContactsListModelItem::parentItem() const
+{
+    return m_parent;
+}
+
+void ContactsListModelItem::appendChildItem(ContactsListModelItem *child)
+{
+    m_children.append(child);
+}
+
+void ContactsListModelItem::removeChildItem(ContactsListModelItem *child)
+{
+    m_children.removeOne(child);
+}
+
+void ContactsListModelItem::setParentItem(ContactsListModelItem *parent)
+{
+    m_parent = parent;
+}
+
+
+// -------------------------------------------------------------------------------------------------
+
+
 ContactsListModel::ContactsListModel(QObject *parent)
- : QAbstractItemModel(parent)
+ : QAbstractItemModel(parent),
+   m_rootItem(0)
 {
     kDebug();
 
+    // Create the root Item.
+    m_rootItem = new ContactsListModelItem;
+
     // FIXME: Get the Nepomuk Resource for myself in the standardised way, once it is standardised.
     Nepomuk::Resource me(QUrl::fromEncoded("nepomuk:/myself"));
 
+    // Get ALL THE METACONTACT!!!!11!!111!!11one111!!!!eleven!!!1!
+    QString metaContactquery = QString("select distinct ?a where { ?a a %7 . }")
+            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::Person()));
+
     QString query = QString("select distinct ?a ?b where { ?a a %1 . ?a %2 ?b . ?b a %3 . ?b %4 ?r . ?r a %3 . ?s %2 ?r . ?s a %1 . %5 %6 ?s }")
             .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::PersonContact()))
             .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
@@ -58,6 +111,18 @@ ContactsListModel::ContactsListModel(QObject *parent)
 
     Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
 
+    Soprano::QueryResultIterator metaIt = model->executeQuery(metaContactquery, Soprano::Query::QueryLanguageSparql);
+
+    while(metaIt.next()) {
+        Nepomuk::Person foundPimoPerson(metaIt.binding("a").uri());
+
+        kDebug() << "Found a PIMO Person.";
+   //     MetaContactItem *item = new MetaContactItem(foundPimoPerson, 0);
+   //     item->setParentItem(m_rootItem);
+   //     m_rootItem->appendChildItem(item);
+   //     connect(item, SIGNAL(dirty()), SLOT(onItemDirty()));
+    }
+
     Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
 
     // Iterate over all the IMAccounts/PersonContacts found.
@@ -67,8 +132,14 @@ ContactsListModel::ContactsListModel(QObject *parent)
       //  kDebug() << this << ": Found Contact:" << foundIMAccount.imIDs().first();
 
         // And create a ContactItem for each one.
-        ContactItem *item = new ContactItem(foundPersonContact, foundIMAccount, this);
-        m_contactItems.append(item);
+        MetaContactItem *metaContactItem = new MetaContactItem(MetaContactItem::FakeMetaContact, 0);
+        metaContactItem->setParentItem(m_rootItem);
+        m_rootItem->appendChildItem(metaContactItem);
+        connect(metaContactItem, SIGNAL(dirty()), SLOT(onItemDirty()));
+
+        ContactItem *item = new ContactItem(foundPersonContact, foundIMAccount, 0);
+        item->setParentItem(metaContactItem);
+        metaContactItem->appendChildItem(item);
         connect(item, SIGNAL(dirty()), SLOT(onItemDirty()));
     }
 }
@@ -88,42 +159,97 @@ int ContactsListModel::columnCount(const QModelIndex &parent) const
 
 int ContactsListModel::rowCount(const QModelIndex &parent) const
 {
-    // If the index is the root item, then return the row count.
-    if (parent == QModelIndex()) {
-       return m_contactItems.size();
+    kDebug();
+
+    // If the parent is invalid, then this request is for the root item.
+    if (!parent.isValid()) {
+        return m_rootItem->childItems().length();
+    }
+
+    // Get the item from the internal pointer of the ModelIndex.
+    ContactsListModelItem *item = static_cast<ContactsListModelItem*>(parent.internalPointer());
+
+    // If the item is valid, return the number of children it has.
+    if (item) {
+        kDebug() << item->childItems().length();
+        return item->childItems().length();
     }
 
-    // Otherwise, return 0 (as this is a list model, so all items
-    // are children of the root item).
+    // Otherwise, return 0
     return 0;
 }
 
 QVariant ContactsListModel::data(const QModelIndex &index, int role) const
 {
+    kDebug() << "index:" << index << "parent:" << index.parent();
+    // Only column 0 is valid.
     if (index.column() != 0) {
         return QVariant();
     }
 
-    QVariant data;
-    switch(role)
-    {
-    case Qt::DisplayRole:
-        data.setValue<QString>(m_contactItems.at(index.row())->displayName());
-        break;
-    case Qt::DecorationRole:
-        data.setValue<QIcon>(m_contactItems.at(index.row())->presenceIcon());
-        break;
-    case ContactsListModel::PresenceTypeRole:
-        data.setValue<qint64>(m_contactItems.at(index.row())->presenceType());
-        break;
-    case ContactsListModel::GroupsRole:
-        data.setValue<QStringList>(m_contactItems.at(index.row())->groups());
-        break;
-    default:
-        break;
+    if (index.internalPointer() == m_rootItem) {
+        kDebug() << "Internal root item pointe rwtf?";
     }
 
-    return data;
+    // Check what type of item we have here.
+    ContactsListModelItem *clmItem = static_cast<ContactItem*>(index.internalPointer());
+    ContactItem *contactItem = qobject_cast<ContactItem*>(clmItem);
+
+    kDebug() << contactItem;
+
+    if (contactItem) {
+        kDebug() << "Is a contact Item." << contactItem;
+        QVariant data;
+        switch(role)
+        {
+        case Qt::DisplayRole:
+            data.setValue<QString>(contactItem->displayName());
+            break;
+        case Qt::DecorationRole:
+            data.setValue<QIcon>(contactItem->presenceIcon());
+            break;
+        case ContactsListModel::PresenceTypeRole:
+            data.setValue<qint64>(contactItem->presenceType());
+            break;
+        case ContactsListModel::GroupsRole:
+            data.setValue<QStringList>(contactItem->groups());
+            break;
+        default:
+            break;
+        }
+
+        return data;
+    }
+
+    MetaContactItem *metaContactItem = qobject_cast<MetaContactItem*>(clmItem);
+
+    if (metaContactItem) {
+        QVariant data;
+        switch(role)
+        {
+        case Qt::DisplayRole:
+            data.setValue<QString>(metaContactItem->displayName());
+            break;
+        case Qt::DecorationRole:
+//            data.setValue<QIcon>(contactItem->presenceIcon());
+            break;
+        case ContactsListModel::PresenceTypeRole:
+//            data.setValue<qint64>(contactItem->presenceType());
+            break;
+        case ContactsListModel::GroupsRole:
+//            data.setValue<QStringList>(contactItem->groups());
+            break;
+        default:
+            break;
+        }
+
+        return data;
+    }
+
+    Q_ASSERT(false);
+    kWarning() << "Model Index pointer is of invalid type.";
+
+    return QVariant();
 }
 
 Qt::ItemFlags ContactsListModel::flags(const QModelIndex &index) const
@@ -133,31 +259,71 @@ Qt::ItemFlags ContactsListModel::flags(const QModelIndex &index) const
 
 QModelIndex ContactsListModel::parent(const QModelIndex &index) const
 {
-    Q_UNUSED(index);
+    // If the index is invalid, return an invalid parent index.
+    if (!index.isValid()) {
+        return QModelIndex();
+    }
+
+    // Get the item we have been passed, and it's parent
+    ContactsListModelItem *childItem = item(index);
+    ContactsListModelItem *parentItem = childItem->parentItem();
+
+    // If the parent is the root item, then the parent index of the index we were passed is
+    // by definition an invalid index.
+    if (parentItem == m_rootItem) {
+        return QModelIndex();
+    }
+
+    // The parent of the item is not the root item, meaning that the parent must have a parent too.
+    ContactsListModelItem *parentOfParentItem = parentItem->parentItem();
+
+    // As stated in the previous comment, something is really wrong if it doesn't have a parent.
+    Q_ASSERT(parentOfParentItem);
+    if (!parentOfParentItem) {
+        kWarning() << "Impossible parent situation occurred!";
+        return createIndex(0, 0, parentItem);
+    }
 
-    // This is a list model, so all items are children of the root item.
-    return QModelIndex();
+    // Return the model index of the parent item.
+    return createIndex(parentOfParentItem->childItems().lastIndexOf(parentItem), 0, parentItem);
 }
 
 QModelIndex ContactsListModel::index(int row, int column, const QModelIndex &parent) const
 {
-    // List view, so all items are children of the root item.
-    if (parent.isValid()) {
+    kDebug();
+    // 1 column list, so invalid index if the column is not 1.
+    if (parent.isValid() && parent.column() != 0) {
+        kDebug() << "Wrong column";
         return QModelIndex();
     }
 
-    // Only 1 column
-    if (column != 0) {
-        return QModelIndex();
-    }
+    // Get the parent item.
+    ContactsListModelItem *parentItem = item(parent);
+
+    // Get all the parent's children.
+    QList<ContactsListModelItem*> children = parentItem->childItems();
 
-    // Check the row is within the range of the list.
-    if (row >= m_contactItems.size()) {
+    // Check the row doesn't go beyond the end of the list of children.
+    if (row >= children.length()) {
+        kDebug() << "Bounds error";
         return QModelIndex();
     }
 
     // Return the index to the item.
-    return createIndex(row, column, 0);
+    kDebug() << "AOK:" << row << column << children.at(row);
+    return createIndex(row, column, children.at(row));
+}
+
+ContactsListModelItem* ContactsListModel::item(const QModelIndex &index) const
+{
+    if (index.isValid()) {
+        ContactsListModelItem *item = static_cast<ContactsListModelItem*>(index.internalPointer());
+         if (item) {
+             return item;
+         }
+     }
+
+     return m_rootItem;
 }
 
 QVariant ContactsListModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -180,8 +346,9 @@ void ContactsListModel::onItemDirty()
         kWarning() << "Invalid sender.";
     }
 
-    QModelIndex itemIndex = index(m_contactItems.indexOf(item), 0, QModelIndex());
-    Q_EMIT dataChanged(itemIndex, itemIndex);
+    // FIXME: Port this stuff to new tree structure.
+   // QModelIndex itemIndex = index(m_contactItems.indexOf(item), 0, QModelIndex());
+   // Q_EMIT dataChanged(itemIndex, itemIndex);
 }
 
 #include "contacts-list-model.moc"
diff --git a/contacts-list-model.h b/contacts-list-model.h
index f0ba973..fcdf531 100644
--- a/contacts-list-model.h
+++ b/contacts-list-model.h
@@ -26,6 +26,27 @@
 
 class ContactItem;
 
+class ContactsListModelItem : public QObject
+{
+    Q_OBJECT
+
+public:
+    ContactsListModelItem(QObject *parent = 0);
+    virtual ~ContactsListModelItem();
+
+    virtual void appendChildItem(ContactsListModelItem *child);
+    virtual void removeChildItem(ContactsListModelItem *child);
+
+    virtual void setParentItem(ContactsListModelItem *parent);
+
+    virtual QList<ContactsListModelItem*> childItems() const;
+    virtual ContactsListModelItem *parentItem() const;
+
+private:
+    QList<ContactsListModelItem*> m_children;
+    ContactsListModelItem *m_parent;
+};
+
 class ContactsListModel : public QAbstractItemModel
 {
     Q_OBJECT
@@ -57,7 +78,9 @@ private Q_SLOTS:
 private:
     Q_DISABLE_COPY(ContactsListModel);
 
-    QList<ContactItem*> m_contactItems;
+    ContactsListModelItem *item(const QModelIndex &index) const;
+
+    ContactsListModelItem *m_rootItem;
 };
 
 
diff --git a/main-widget.cpp b/main-widget.cpp
index 19567f8..325af61 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -41,11 +41,11 @@ MainWidget::MainWidget(QWidget *parent)
     m_sortFilterProxyModel = new QSortFilterProxyModel(this);
     m_sortFilterProxyModel->setSourceModel(m_model);
 
-    m_groupedContactsProxyModel = new GroupedContactsProxyModel(this);
-    m_groupedContactsProxyModel->setSourceModel(m_model);
+   // m_groupedContactsProxyModel = new GroupedContactsProxyModel(this);
+   // m_groupedContactsProxyModel->setSourceModel(m_model);
 
     m_contactsListView->setSortingEnabled(true);
-    m_contactsListView->setModel(m_groupedContactsProxyModel);
+    m_contactsListView->setModel(m_sortFilterProxyModel);
 }
 
 MainWidget::~MainWidget()
diff --git a/meta-contact-item.cpp b/meta-contact-item.cpp
new file mode 100644
index 0000000..a450868
--- /dev/null
+++ b/meta-contact-item.cpp
@@ -0,0 +1,102 @@
+/*
+ * This file is part of telepathy-contactslist-prototype
+ *
+ * Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
+ *   @Author George Goldberg <george.goldberg at collabora.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 "meta-contact-item.h"
+
+#include "contact-item.h"
+
+#include <KDebug>
+
+MetaContactItem::MetaContactItem(MetaContactType type, QObject *parent)
+  : ContactsListModelItem(parent),
+    m_type(type)
+{
+    if (type == RealMetaContact) {
+        // A Real metacontact. Wait for the setPimoPerson to be called before
+        // setting everything up.
+        kDebug() << "Constructing new Real MetaContact.";
+    } else if (type == FakeMetaContact) {
+        // A fake Meta-Contact. There is no PIMO:Person, so wait for setPersonContact()
+        // to be called before doing the setup.
+        kDebug() << "Constructing new Fake MetaContact.";
+    }
+}
+
+MetaContactItem::~MetaContactItem()
+{
+    kDebug();
+}
+
+void MetaContactItem::onStatementAdded(const Soprano::Statement &statement)
+{
+    Q_UNUSED(statement);
+
+    kDebug() << "Statement added called.";
+
+    Q_EMIT dirty();
+}
+
+void MetaContactItem::setPimoPerson(const Nepomuk::Person& pimoPerson)
+{
+    m_pimoPerson = pimoPerson;
+
+    // Subscribe to Nepomuk change signals for our Nepomuk Resources.
+    NepomukSignalWatcher *watcher = NepomukSignalWatcher::instance();
+    watcher->registerCallbackOnSubject(m_pimoPerson, this);
+}
+
+QString MetaContactItem::displayName() const
+{
+    if (childItems().isEmpty()) {
+        return QString();
+    }
+
+    ContactItem *item = qobject_cast<ContactItem*>(childItems().first());
+
+    if (!item) {
+        return QString();
+    }
+
+    return item->displayName();
+}
+/*
+void MetaContactItem::setPersonContact(const Nepomuk::PersonContact &personContact)
+{
+    // This should only be called if the meta contact is fake.
+    Q_ASSERT(m_type == FakeMetaContact);
+    if (m_type != FakeMetaContact) {
+        kWarning() << "setPersonContact called on real meta contact. This should not happen.";
+        return;
+    }
+
+    // The list of personContacts should be empty when this is called.
+    Q_ASSERT(!m_personContacts.isEmpty());
+    if (!m_personContacts.isEmpty()) {
+        kWarning() << "We already have a person contact set for this fake meta contact.";
+        return;
+    }
+
+    m_personContacts.insert(personContact);
+}
+*/
+
+#include "meta-contact-item.moc"
+
diff --git a/contact-item.h b/meta-contact-item.h
similarity index 62%
copy from contact-item.h
copy to meta-contact-item.h
index a80490a..f75b0fb 100644
--- a/contact-item.h
+++ b/meta-contact-item.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of telepathy-contactslist-prototype
  *
- * Copyright (C) 2009-2010 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2010 Collabora Ltd. <info at collabora.co.uk>
  *   @Author George Goldberg <george.goldberg at collabora.co.uk>
  *
  * This library is free software; you can redistribute it and/or
@@ -19,32 +19,37 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifndef TELEPATHY_CONTACTSLIST_PROTOTYPE_CONTACT_ITEM_H
-#define TELEPATHY_CONTACTSLIST_PROTOTYPE_CONTACT_ITEM_H
+#ifndef TELEPATHY_CONTACTSLIST_PROTOTYPE_META_CONTACT_ITEM_H
+#define TELEPATHY_CONTACTSLIST_PROTOTYPE_META_CONTACT_ITEM_H
 
 #include "nepomuk-signal-watcher.h"
+#include "contacts-list-model.h"
 
-#include "imaccount.h"
+#include "person.h"
 #include "personcontact.h"
 
-#include <KIcon>
-
 #include <QObject>
 
-class ContactItem : public QObject, NepomukSignalWatcher::Watcher {
+class MetaContactItem : public ContactsListModelItem, NepomukSignalWatcher::Watcher {
 
     Q_OBJECT
 
 public:
-    ContactItem(Nepomuk::PersonContact personContact,
-                Nepomuk::IMAccount imAccount,
-                QObject *parent = 0);
-    ~ContactItem();
+    enum MetaContactType {
+        RealMetaContact = 0,
+        FakeMetaContact = 1
+    };
+
+    MetaContactItem(MetaContactType type, QObject *parent = 0);
+    ~MetaContactItem();
 
     QString displayName() const;
-    const KIcon& presenceIcon() const;
+/*    const KIcon& presenceIcon() const;
     qint64 presenceType() const;
     QStringList groups() const;
+*/
+
+    void setPimoPerson(const Nepomuk::Person &pimoPerson);
 
     virtual void onStatementAdded(const Soprano::Statement &statement);
 
@@ -52,16 +57,15 @@ Q_SIGNALS:
     void dirty();
 
 private Q_SLOTS:
-    void updatePresenceIcon();
+//    void updatePresenceIcon();
 
 private:
-    Q_DISABLE_COPY(ContactItem);
+    Q_DISABLE_COPY(MetaContactItem);
 
-    Nepomuk::PersonContact m_personContact;
-    Nepomuk::IMAccount m_imAccount;
-
-    KIcon *m_presenceIcon;
+    MetaContactType m_type;
+    Nepomuk::Person m_pimoPerson;
 };
 
+
 #endif // Header guard
 

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list