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


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

The following commit has been merged in the master branch:
commit 9c002a1cf63bd5c56e3f49e074db6026d06fca1b
Author: David Edmundson <kde at davidedmundson.co.uk>
Date:   Mon Feb 25 01:03:46 2013 +0000

    Add a small application to show contact-list-model
    
    REVIEW: 109132
---
 CMakeLists.txt                               |   2 +
 tests/CMakeLists.txt                         |  31 +++++
 tests/contact-list-model-view-main.cpp       |  99 ++++++++++++++++
 KTp/pending-wallet.h => tests/model-view.cpp |  36 +++---
 KTp/pending-wallet.h => tests/model-view.h   |  37 +++---
 tests/model-view.ui                          |  24 ++++
 tests/roles-proxy-model.cpp                  | 168 +++++++++++++++++++++++++++
 tests/roles-proxy-model.h                    |  59 ++++++++++
 8 files changed, 417 insertions(+), 39 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index de94874..6b7cf7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -40,3 +40,5 @@ configure_file(version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h @ONLY)
 add_subdirectory(KTp)
 add_subdirectory(tools)
 add_subdirectory(data)
+add_subdirectory(tests)
+
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..4694b75
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1,31 @@
+set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} )
+
+include_directories(
+  ${CMAKE_SOURCE_DIR}
+  ${CMAKE_CURRENT_BINARY_DIR}/..
+  ${CMAKE_CURRENT_SOURCE_DIR}/..
+  )
+
+
+
+set(ktp_contact_list_model_view_SRCS
+    contact-list-model-view-main.cpp
+    model-view.cpp
+    roles-proxy-model.cpp
+)
+
+kde4_add_ui_files(ktp_contact_list_model_view_SRCS model-view.ui)
+
+kde4_add_executable(ktp_contact_list_model_view
+    ${ktp_contact_list_model_view_SRCS}
+)
+
+target_link_libraries(ktp_contact_list_model_view
+  ${QT_QTTEST_LIBRARY}
+  ${KDE4_KDECORE_LIBS}
+  ${KDE4_KDEUI_LIBS}
+  ${TELEPATHY_QT4_LIBRARIES}
+  ktpcommoninternalsprivate
+  ktpmodelsprivate
+)
+
diff --git a/tests/contact-list-model-view-main.cpp b/tests/contact-list-model-view-main.cpp
new file mode 100644
index 0000000..ca7cab1
--- /dev/null
+++ b/tests/contact-list-model-view-main.cpp
@@ -0,0 +1,99 @@
+/*
+ * This file is part of telepathy-kde-models-test-ui
+ *
+ * Copyright (C) 2011 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 "model-view.h"
+
+#include <KAboutData>
+#include <KCmdLineArgs>
+#include <KDebug>
+#include <KApplication>
+
+#include <TelepathyQt/Types>
+#include <TelepathyQt/Debug>
+
+#include <TelepathyQt/AccountManager>
+#include <TelepathyQt/AccountFactory>
+#include <TelepathyQt/ConnectionFactory>
+#include <TelepathyQt/TextChannel>
+
+#include <QDBusConnection>
+
+#include "KTp/Models/contacts-list-model.h"
+#include "KTp/contact-factory.h"
+
+int main(int argc, char *argv[])
+{
+    KAboutData aboutData("telepathy-kde-models-test-ui",
+                         0,
+                         ki18n("Telepathy KDE Models Test UI"),
+                         "0.1",
+                         ki18n("Telepathy KDE Models Test UI"),
+                         KAboutData::License_LGPL,
+                         ki18n("(C) 2011 Collabora Ltd"));
+
+    KCmdLineArgs::init(argc, argv, &aboutData);
+
+    KApplication app;
+
+    Tp::registerTypes();
+    Tp::enableDebug(false);
+    Tp::enableWarnings(true);
+
+    
+        Tp::AccountFactoryPtr  accountFactory = Tp::AccountFactory::create(QDBusConnection::sessionBus(),
+                                                                       Tp::Features() << Tp::Account::FeatureCore
+                                                                       << Tp::Account::FeatureAvatar
+                                                                       << Tp::Account::FeatureCapabilities
+                                                                       << Tp::Account::FeatureProtocolInfo
+                                                                       << Tp::Account::FeatureProfile);
+
+    Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(QDBusConnection::sessionBus(),
+                                                                               Tp::Features() << Tp::Connection::FeatureCore
+                                                                               << Tp::Connection::FeatureRosterGroups
+                                                                               << Tp::Connection::FeatureRoster
+                                                                               << Tp::Connection::FeatureSelfContact);
+
+    Tp::ContactFactoryPtr contactFactory = KTp::ContactFactory::create(Tp::Features()  << Tp::Contact::FeatureAlias
+                                                                      << Tp::Contact::FeatureAvatarData
+                                                                      << Tp::Contact::FeatureSimplePresence
+                                                                      << Tp::Contact::FeatureCapabilities
+                                                                      << Tp::Contact::FeatureClientTypes);
+
+    Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(QDBusConnection::sessionBus());
+    channelFactory->addFeaturesForTextChats(Tp::Features() << Tp::Channel::FeatureCore << Tp::TextChannel::FeatureMessageQueue);
+
+    Tp::AccountManagerPtr accountManager = Tp::AccountManager::create(QDBusConnection::sessionBus(),
+                                                  accountFactory,
+                                                  connectionFactory,
+                                                  channelFactory,
+                                                  contactFactory);
+
+    KTp::ContactsListModel *model = new KTp::ContactsListModel(&app);
+    model->setAccountManager(accountManager);
+    
+    // Set up and show the main widget
+    ModelView *mainWidget = new ModelView(model, 0);
+    mainWidget->show();
+
+    // Start event loop.
+    app.exec();
+}
+
diff --git a/KTp/pending-wallet.h b/tests/model-view.cpp
similarity index 56%
copy from KTp/pending-wallet.h
copy to tests/model-view.cpp
index 9ef86d7..25ed46b 100644
--- a/KTp/pending-wallet.h
+++ b/tests/model-view.cpp
@@ -1,5 +1,8 @@
 /*
- * Copyright (C) 2012 David Edmundson <kde at davidedmundson.co.uk>
+ * This file is part of telepathy-kde-models-test-ui
+ *
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2013 David Edmundson <davidedmundson at kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,30 +19,25 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#include "model-view.h"
 
-#ifndef PENDINGWALLETOPERATION_H
-#define PENDINGWALLETOPERATION_H
+#include "roles-proxy-model.h"
 
-#include <TelepathyQt/PendingOperation>
 
-#include "wallet-interface.h"
-#include <KTp/ktp-export.h>
 
-namespace KTp
+ModelView::ModelView(QAbstractItemModel *model, QWidget *parent)
+  : QWidget(parent)
 {
-class PendingWalletPrivate;
+    setupUi(this);
+
+    RolesProxyModel *proxyModel = new RolesProxyModel(this);
+    proxyModel->setSourceModel(model);
 
-class KTP_EXPORT PendingWallet : public Tp::PendingOperation
+    TreeView->setModel(proxyModel);
+}
+
+ModelView::~ModelView()
 {
-    Q_OBJECT
-public:
-    friend class WalletInterface;
-    KTp::WalletInterface *walletInterface() const;
-private:
-    PendingWallet(KTp::WalletInterface *wallet);
-    virtual ~PendingWallet();
-    KTp::PendingWalletPrivate *d;
-};
 
 }
-#endif // PENDINGWALLETOPERATION_H
+
diff --git a/KTp/pending-wallet.h b/tests/model-view.h
similarity index 57%
copy from KTp/pending-wallet.h
copy to tests/model-view.h
index 9ef86d7..f0ad9f7 100644
--- a/KTp/pending-wallet.h
+++ b/tests/model-view.h
@@ -1,5 +1,8 @@
 /*
- * Copyright (C) 2012 David Edmundson <kde at davidedmundson.co.uk>
+ * This file is part of telepathy-kde-models-test-ui
+ *
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2013 David Edmundson <davidedmundson at kde.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -16,30 +19,24 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+#ifndef MAIN_WIDGET_H
+#define MAIN_WIDGET_H
 
-#ifndef PENDINGWALLETOPERATION_H
-#define PENDINGWALLETOPERATION_H
-
-#include <TelepathyQt/PendingOperation>
+#include "ui_model-view.h"
 
-#include "wallet-interface.h"
-#include <KTp/ktp-export.h>
+#include <QWidget>
+#include <QAbstractItemModel>
 
-namespace KTp
-{
-class PendingWalletPrivate;
+class ModelView : public QWidget, protected Ui::MainWidget {
 
-class KTP_EXPORT PendingWallet : public Tp::PendingOperation
-{
     Q_OBJECT
+
 public:
-    friend class WalletInterface;
-    KTp::WalletInterface *walletInterface() const;
-private:
-    PendingWallet(KTp::WalletInterface *wallet);
-    virtual ~PendingWallet();
-    KTp::PendingWalletPrivate *d;
+    ModelView(QAbstractItemModel *model, QWidget *parent = 0);
+    ~ModelView();
+
 };
 
-}
-#endif // PENDINGWALLETOPERATION_H
+
+#endif
+
diff --git a/tests/model-view.ui b/tests/model-view.ui
new file mode 100644
index 0000000..75450e1
--- /dev/null
+++ b/tests/model-view.ui
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWidget</class>
+ <widget class="QWidget" name="MainWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Telepathy-KDE Models Testing UI</string>
+  </property>
+  <layout class="QHBoxLayout" name="horizontalLayout">
+   <item>
+    <widget class="QTreeView" name="TreeView"/>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/tests/roles-proxy-model.cpp b/tests/roles-proxy-model.cpp
new file mode 100644
index 0000000..6a0c3e1
--- /dev/null
+++ b/tests/roles-proxy-model.cpp
@@ -0,0 +1,168 @@
+/*
+ * This file is part of telepathy-kde-models-test-ui
+ *
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2013 David Edmundson <davidedmundson at kde.org>
+ *
+ * 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 "roles-proxy-model.h"
+
+#include <KDebug>
+
+RolesProxyModel::RolesProxyModel(QObject *parent)
+  : QAbstractProxyModel(parent)
+{
+    kDebug();
+}
+
+RolesProxyModel::~RolesProxyModel()
+{
+    kDebug();
+}
+
+void RolesProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
+{
+    connect(sourceModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
+            this, SLOT(onSourceRowsInserted(QModelIndex,int,int)));
+    connect(sourceModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+            this, SLOT(onSourceRowsRemoved(QModelIndex,int,int)));
+    connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
+            this, SLOT(onSourceDataChanged(QModelIndex,QModelIndex)));
+    connect(sourceModel, SIGNAL(layoutChanged()),
+            this, SLOT(onSourceLayoutChanged()));
+
+    QAbstractProxyModel::setSourceModel(sourceModel);
+}
+
+int RolesProxyModel::columnCount(const QModelIndex &parent) const
+{
+    // Number of columns is number of roles available to QML
+    return sourceModel()->roleNames().size();
+}
+
+int RolesProxyModel::rowCount(const QModelIndex &parent) const
+{
+    return sourceModel()->rowCount(mapToSource(parent));
+}
+
+QModelIndex RolesProxyModel::index(int row, int column, const QModelIndex &parent) const
+{
+    // this is a list, not a tree, so parent must be invalid (root item)
+    if (parent.isValid()) {
+        return QModelIndex();
+    }
+
+    if (column >= columnCount() || column < 0) {
+        return QModelIndex();
+    }
+
+    // Check the row is within the bounds of the list
+    if (row >= rowCount() || row < 0) {
+        return QModelIndex();
+    }
+
+    // Return the index to the item.
+    return createIndex(row, column, 0);
+}
+
+QModelIndex RolesProxyModel::parent(const QModelIndex &index) const
+{
+    Q_UNUSED(index);
+
+    // Not a tree model, so all items have root-item as parent.
+    return QModelIndex();
+}
+
+QVariant RolesProxyModel::data(const QModelIndex &index, int role) const
+{
+    if (!index.isValid()) {
+        return QVariant();
+    }
+
+    if (index.column() >= columnCount() || index.column() < 0) {
+        return QVariant();
+    }
+
+    if (index.row() >= rowCount() || index.row() < 0) {
+        return QVariant();
+    }
+
+    if (role == Qt::DisplayRole) {
+        return sourceModel()->data(mapToSource(index), sourceModel()->roleNames().keys().at(index.column()));
+    }
+
+    return sourceModel()->data(mapToSource(index), role);
+}
+
+Qt::ItemFlags RolesProxyModel::flags(const QModelIndex &index) const
+{
+    // Pass through from source model
+    return sourceModel()->flags(mapToSource(index));
+}
+
+QVariant RolesProxyModel::headerData(int section, Qt::Orientation orientation, int role) const
+{
+    if (role == Qt::DisplayRole) {
+        return sourceModel()->roleNames().values().at(section);
+    }
+
+    return QVariant();
+}
+
+QModelIndex RolesProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
+{
+    if (!sourceIndex.isValid()) {
+        return QModelIndex();
+    }
+
+    return index(sourceIndex.row(), sourceIndex.column(), mapFromSource(sourceIndex.parent()));
+}
+
+QModelIndex RolesProxyModel::mapToSource(const QModelIndex &proxyIndex) const
+{
+    if (!proxyIndex.isValid()) {
+        return QModelIndex();
+    }
+
+    return sourceModel()->index(proxyIndex.row(), 0, mapToSource(proxyIndex.parent()));
+}
+
+void RolesProxyModel::onSourceRowsInserted(const QModelIndex &parent, int start, int end)
+{
+    beginInsertRows(mapFromSource(parent), start, end);
+    endInsertRows();
+}
+
+void RolesProxyModel::onSourceRowsRemoved(const QModelIndex &parent, int start, int end)
+{
+    beginRemoveRows(mapFromSource(parent), start, end);
+    endRemoveRows();
+}
+
+void RolesProxyModel::onSourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
+{
+    // Assume that since the data is layed out in the same way in the proxy model that we can just
+    // translate the ranges to relay the signal
+    dataChanged(mapFromSource(topLeft), mapFromSource(bottomRight));
+}
+
+void RolesProxyModel::onSourceLayoutChanged()
+{
+    layoutAboutToBeChanged();
+    layoutChanged();
+}
+
diff --git a/tests/roles-proxy-model.h b/tests/roles-proxy-model.h
new file mode 100644
index 0000000..4766110
--- /dev/null
+++ b/tests/roles-proxy-model.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of telepathy-kde-models-test-ui
+ *
+ * Copyright (C) 2011 Collabora Ltd. <info at collabora.co.uk>
+ * Copyright (C) 2013 David Edmundson <davidedmundson at kde.org>
+ *
+ * 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 ROLES_PROXY_MODEL_H
+#define ROLES_PROXY_MODEL_H
+
+#include <QAbstractProxyModel>
+
+class RolesProxyModel : public QAbstractProxyModel {
+
+    Q_OBJECT
+
+public:
+    RolesProxyModel(QObject *parent = 0);
+    virtual ~RolesProxyModel();
+
+    virtual void setSourceModel(QAbstractItemModel *sourceModel);
+
+    virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
+    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
+    virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
+    virtual QModelIndex parent(const QModelIndex &index) const;
+
+    virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
+    virtual Qt::ItemFlags flags(const QModelIndex &index) const;
+    virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
+
+    virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const;
+    virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const;
+
+protected Q_SLOTS:
+    virtual void onSourceRowsInserted(const QModelIndex &parent, int start, int end);
+    virtual void onSourceRowsRemoved(const QModelIndex &parent, int start, int end);
+    virtual void onSourceDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
+    virtual void onSourceLayoutChanged();
+
+};
+
+
+#endif
+

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list