[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:37 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=9ebcdbc
The following commit has been merged in the master branch:
commit 9ebcdbc2eb1c9ab22cf46a17c732a6daf33be780
Author: George Goldberg <grundleborg at googlemail.com>
Date: Sun Mar 7 21:29:41 2010 +0000
Provide a ProxyModel allowing us to view contacts by group.
This is still quite messy and will be tidied up and generalised when I implement other contact views, such as by presence state.
svn path=/trunk/playground/network/telepathy-contactlist/; revision=1100577
---
CMakeLists.txt | 1 +
contact-item.cpp | 6 +-
contacts-list-model.cpp | 2 +-
grouped-contacts-proxy-model.cpp | 279 +++++++++++++++++++++++++++++++++++++++
grouped-contacts-proxy-model.h | 73 ++++++++++
main-widget.cpp | 11 +-
main-widget.h | 2 +
nepomuk-signal-watcher.cpp | 2 +-
8 files changed, 371 insertions(+), 5 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 644de46..61fe7f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -143,6 +143,7 @@ set (contactlist_SRCS
contact-item.cpp
main-widget.cpp
nepomuk-signal-watcher.cpp
+ grouped-contacts-proxy-model.cpp
)
kde4_add_ui_files (contactlist_SRCS
diff --git a/contact-item.cpp b/contact-item.cpp
index 247a36e..fcc92fb 100644
--- a/contact-item.cpp
+++ b/contact-item.cpp
@@ -33,7 +33,7 @@ ContactItem::ContactItem(Nepomuk::PersonContact personContact,
m_imAccount(imAccount),
m_presenceIcon(new KIcon)
{
- kDebug() << this << ": New ContactItem: " << personContact.resourceType().toString() << imAccount.resourceType().toString();
+ // kDebug() << this << ": New ContactItem: " << personContact.resourceType().toString() << imAccount.resourceType().toString();
// Subscribe to Nepomuk change signals for our Nepomuk Resources.
NepomukSignalWatcher *watcher = NepomukSignalWatcher::instance();
@@ -119,6 +119,10 @@ QStringList ContactItem::groups() const
QStringList groupNames;
+ if (groups.isEmpty()) {
+ return QStringList() << "No Group";
+ }
+
foreach (const Nepomuk::ContactGroup &group, groups) {
groupNames << group.contactGroupName();
}
diff --git a/contacts-list-model.cpp b/contacts-list-model.cpp
index a556f20..3601ab5 100644
--- a/contacts-list-model.cpp
+++ b/contacts-list-model.cpp
@@ -65,7 +65,7 @@ ContactsListModel::ContactsListModel(QObject *parent)
while(it.next()) {
Nepomuk::PersonContact foundPersonContact(it.binding("a").uri());
Nepomuk::IMAccount foundIMAccount(it.binding("b").uri());
- kDebug() << this << ": Found Contact:" << foundIMAccount.imIDs().first();
+ // kDebug() << this << ": Found Contact:" << foundIMAccount.imIDs().first();
// And create a ContactItem for each one.
ContactItem *item = new ContactItem(foundPersonContact, foundIMAccount, this);
diff --git a/grouped-contacts-proxy-model.cpp b/grouped-contacts-proxy-model.cpp
new file mode 100644
index 0000000..2ff30c2
--- /dev/null
+++ b/grouped-contacts-proxy-model.cpp
@@ -0,0 +1,279 @@
+/*
+ * 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 "grouped-contacts-proxy-model.h"
+
+#include "contact-item.h"
+#include "contacts-list-model.h"
+
+#include <KDebug>
+
+#include <QtGui/QItemSelection>
+
+GroupedContactsProxyModel::GroupedContactsProxyModel(QObject* parent)
+ : QAbstractProxyModel(parent),
+ m_sourceModel(0),
+ m_rootItem(0)
+{
+
+}
+
+GroupedContactsProxyModel::~GroupedContactsProxyModel()
+{
+
+}
+
+Qt::ItemFlags GroupedContactsProxyModel::flags(const QModelIndex &index) const
+{
+ return QAbstractItemModel::flags(index);
+}
+
+QVariant GroupedContactsProxyModel::data(const QModelIndex &index, int role) const
+{
+ // If the model-index parent is invalid, then we have a group
+ if (!index.parent().isValid()) {
+ // Data only exists in Column 0.
+ if (index.column() != 0) {
+ return QVariant();
+ }
+
+ // Return the group data.
+ QVariant data;
+ Item *item = m_rootItem->children.at(index.row());
+
+ Q_ASSERT(item);
+ if (!item) {
+ kWarning() << "NO ITEM!";
+ return QVariant();
+ }
+
+ switch(role) {
+ case Qt::DisplayRole:
+ data.setValue<QString>(item->name);
+ break;
+ }
+
+ return data;
+ }
+
+ // Return the data from the original model.
+ return m_sourceModel->data(mapToSource(index), role);
+}
+
+QModelIndex GroupedContactsProxyModel::index(int row, int column, const QModelIndex &parent) const
+{
+// kWarning() << "index called";
+ if (parent.isValid() && parent.parent().isValid()) {
+ return QModelIndex();
+ }
+
+ // Only 1 column
+ if (column != 0) {
+ return QModelIndex();
+ }
+
+ if (parent.isValid()) {
+ if (row >= m_rootItem->children.at(parent.row())->children.length()) {
+ return QModelIndex();
+ }
+
+ return createIndex(row, column, m_rootItem->children.at(parent.row())->children.at(row));
+ }
+
+ // Return the index to the item.
+ if (row >= m_rootItem->children.length()) {
+ return QModelIndex();
+ }
+
+ return createIndex(row, column, m_rootItem->children.at(row));
+}
+
+QModelIndex GroupedContactsProxyModel::parent(const QModelIndex &index) const
+{
+// kWarning() << "Parent called. Argh";
+
+ Item *item = static_cast<Item*>(index.internalPointer());
+
+ Q_ASSERT(item);
+ if (!item) {
+ kWarning() << "Not a valid internal pointer. Argh :/";
+ return QModelIndex();
+ }
+
+ if (item->parent == m_rootItem) {
+ return QModelIndex();
+ }
+
+ return this->index(m_rootItem->children.lastIndexOf(item->parent), 0, QModelIndex());
+}
+
+int GroupedContactsProxyModel::rowCount(const QModelIndex &parent) const
+{
+ if (parent == QModelIndex()) {
+ return m_rootItem->children.length();
+ }
+
+ if (parent.parent() == QModelIndex()) {
+ Item *item = static_cast<Item*>(parent.internalPointer());
+
+ Q_ASSERT(item);
+ if (!item) {
+ kWarning() << "Not a valid internal pointer. Argh :/";
+ return 0;
+ }
+
+ return item->children.length();
+ }
+
+ return 0;
+}
+
+int GroupedContactsProxyModel::columnCount(const QModelIndex &parent) const
+{
+ Q_UNUSED(parent);
+
+ return 1;
+}
+
+QModelIndex GroupedContactsProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
+{
+ kWarning() << "Map From Source Called. Argh";
+
+ Q_ASSERT(false);
+
+ return sourceIndex;
+}
+
+QItemSelection GroupedContactsProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
+{
+ return QAbstractProxyModel::mapSelectionFromSource(sourceSelection);
+}
+
+QItemSelection GroupedContactsProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const
+{
+ return QAbstractProxyModel::mapSelectionToSource(proxySelection);
+}
+
+QModelIndex GroupedContactsProxyModel::mapToSource(const QModelIndex &proxyIndex) const
+{
+ // Work out the appropriate index on the source model
+ Item *item = static_cast<Item*>(proxyIndex.internalPointer());
+
+ Q_ASSERT(item);
+ if (!item) {
+ kWarning() << "Invalid internal pointer :/";
+ return QModelIndex();
+ }
+
+ return item->sourceIndex;
+}
+
+void GroupedContactsProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
+{
+ m_sourceModel = qobject_cast<ContactsListModel*>(sourceModel);
+
+ Q_ASSERT(m_sourceModel);
+ if (!m_sourceModel) {
+ kWarning() << "Invalid model supplied";
+ return;
+ }
+
+ QAbstractProxyModel::setSourceModel(sourceModel);
+
+ connect(sourceModel,
+ SIGNAL(rowsInserted(QModelIndex,int,int)),
+ SLOT(onSourceRowsInserted(QModelIndex,int,int)));
+ connect(sourceModel,
+ SIGNAL(rowsRemoved(QModelIndex,int,int)),
+ SLOT(onSourceRowsRemoved(QModelIndex,int,int)));
+ connect(sourceModel,
+ SIGNAL(modelReset()),
+ SLOT(onSourceReset()));
+
+ // Synthesise invalidating all mappings and repopulating this proxy model.
+ onSourceReset();
+}
+
+void GroupedContactsProxyModel::onSourceReset()
+{
+ kDebug() << "Source Reset";
+
+ // Reset the internal data-layout of this model.
+ if (m_rootItem) {
+ foreach (Item *item, m_rootItem->children) {
+ foreach (Item *i, item->children) {
+ delete i;
+ }
+ delete item;
+ }
+ delete m_rootItem;
+ m_rootItem = 0;
+ }
+
+ // Repopulate the proxy model data.
+ m_rootItem = new Item;
+ for (int i=0; i < m_sourceModel->rowCount(); ++i) {
+ QModelIndex index = m_sourceModel->index(i, 0, QModelIndex());
+
+ QStringList groups = m_sourceModel->data(index, ContactsListModel::GroupsRole).toStringList();
+
+ foreach (const QString &group, groups) {
+ Item *item = 0;
+ foreach (Item *i, m_rootItem->children) {
+ if (i->name == group) {
+ item = i;
+ break;
+ }
+ }
+
+ if (!item) {
+ item = new Item;
+ item->parent = m_rootItem;
+ m_rootItem->children.append(item);
+ item->name = group;
+ }
+
+ Item *childItem = new Item;
+ childItem->sourceIndex = index;
+ item->children.append(childItem);
+ childItem->parent = item;
+ }
+ }
+
+ // Invalidate this model, so that the view re-queries it for stuff.
+ reset();
+}
+
+void GroupedContactsProxyModel::onSourceRowsInserted(const QModelIndex &parent, int start, int end)
+{
+ kDebug() << "Rows Inserted";
+ // TODO: Invalidate All Mappings
+}
+
+void GroupedContactsProxyModel::onSourceRowsRemoved(const QModelIndex &parent, int start, int end)
+{
+ kDebug() << "Rows Removed";
+ // TODO: Invalidate All Mappings
+}
+
+
+#include "grouped-contacts-proxy-model.moc"
+
diff --git a/grouped-contacts-proxy-model.h b/grouped-contacts-proxy-model.h
new file mode 100644
index 0000000..3a4388e
--- /dev/null
+++ b/grouped-contacts-proxy-model.h
@@ -0,0 +1,73 @@
+/*
+ * 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
+ */
+
+#ifndef TELEPATHY_CONTACTSLIST_PROTOTYPE_GROUPED_CONTACTS_PROXY_MODEL_H
+#define TELEPATHY_CONTACTSLIST_PROTOTYPE_GROUPED_CONTACTS_PROXY_MODEL_H
+
+#include <QtGui/QAbstractProxyModel>
+
+class ContactsListModel;
+
+class GroupedContactsProxyModel : public QAbstractProxyModel
+{
+ Q_OBJECT
+
+public:
+ GroupedContactsProxyModel(QObject* parent = 0);
+ virtual ~GroupedContactsProxyModel();
+
+ virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+ virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+ virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+ virtual QModelIndex parent(const QModelIndex &index) const;
+ virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+ virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+
+ virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
+ virtual QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const;
+ virtual QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const;
+ virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
+
+ virtual void setSourceModel(QAbstractItemModel *sourceModel);
+
+private Q_SLOTS:
+ void onSourceRowsInserted(const QModelIndex &parent, int start, int end);
+ void onSourceRowsRemoved(const QModelIndex &parent, int start, int end);
+ void onSourceReset();
+
+private:
+ struct Item {
+ Item *parent;
+ QList<Item*> children;
+ QString name;
+ QModelIndex sourceIndex;
+
+ Item() : parent(0) { }
+ };
+
+ ContactsListModel *m_sourceModel;
+ Item *m_rootItem;
+
+};
+
+
+#endif // header guard
+
diff --git a/main-widget.cpp b/main-widget.cpp
index 02745fb..19567f8 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -22,13 +22,16 @@
#include "main-widget.h"
#include "contacts-list-model.h"
+#include "grouped-contacts-proxy-model.h"
#include <KDebug>
#include <QtGui/QSortFilterProxyModel>
MainWidget::MainWidget(QWidget *parent)
: QWidget(parent),
- m_model(0)
+ m_model(0),
+ m_groupedContactsProxyModel(0),
+ m_sortFilterProxyModel(0)
{
kDebug();
@@ -37,8 +40,12 @@ MainWidget::MainWidget(QWidget *parent)
m_model = new ContactsListModel(this);
m_sortFilterProxyModel = new QSortFilterProxyModel(this);
m_sortFilterProxyModel->setSourceModel(m_model);
+
+ m_groupedContactsProxyModel = new GroupedContactsProxyModel(this);
+ m_groupedContactsProxyModel->setSourceModel(m_model);
+
m_contactsListView->setSortingEnabled(true);
- m_contactsListView->setModel(m_sortFilterProxyModel);
+ m_contactsListView->setModel(m_groupedContactsProxyModel);
}
MainWidget::~MainWidget()
diff --git a/main-widget.h b/main-widget.h
index a6ae326..d11901e 100644
--- a/main-widget.h
+++ b/main-widget.h
@@ -27,6 +27,7 @@
#include <QtGui/QWidget>
class ContactsListModel;
+class GroupedContactsProxyModel;
class QSortFilterProxyModel;
class MainWidget : public QWidget, Ui::MainWidget
@@ -39,6 +40,7 @@ public:
private:
ContactsListModel *m_model;
+ GroupedContactsProxyModel *m_groupedContactsProxyModel;
QSortFilterProxyModel *m_sortFilterProxyModel;
};
diff --git a/nepomuk-signal-watcher.cpp b/nepomuk-signal-watcher.cpp
index c0d3f7f..b350b38 100644
--- a/nepomuk-signal-watcher.cpp
+++ b/nepomuk-signal-watcher.cpp
@@ -80,6 +80,6 @@ void NepomukSignalWatcher::registerCallbackOnSubject(const Nepomuk::Resource &re
{
// Add this subject to the list.
m_subjectCallbacks.insertMulti(resource.resourceUri().toString(), callback);
- kDebug() << "Registering callback:" << resource.resourceUri() << callback;
+ // kDebug() << "Registering callback:" << resource.resourceUri() << callback;
}
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list