[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:34 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-list.git;a=commitdiff;h=b224b3e
The following commit has been merged in the master branch:
commit b224b3e47b8b5207c2a1bb93762888b2e974c378
Author: George Goldberg <grundleborg at googlemail.com>
Date: Sat Mar 6 20:42:03 2010 +0000
Hackish implementation for listening to changes on Nepomuk Resources.
At the moment, this is implemented by a signleton that listens to all statementAdded() and statementDeleted() calls on Nepomuk, which
can then call back to registered objects if the statement effects an interesting resource.
NB This is only a temporary measure until the Nepomuk folks implement listening for changes better on their side.
svn path=/trunk/playground/network/telepathy-contactlist/; revision=1100114
---
CMakeLists.txt | 1 +
contact-item.cpp | 10 ++++++
contact-item.h | 6 +++-
main.cpp | 1 +
nepomuk-signal-watcher.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++
nepomuk-signal-watcher.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++
6 files changed, 188 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c74b9aa..de4baf1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -74,6 +74,7 @@ set (contactlist_SRCS
contacts-list-model.cpp
contact-item.cpp
main-widget.cpp
+ nepomuk-signal-watcher.cpp
)
kde4_add_ui_files (contactlist_SRCS
diff --git a/contact-item.cpp b/contact-item.cpp
index decba3c..b5074c2 100644
--- a/contact-item.cpp
+++ b/contact-item.cpp
@@ -33,6 +33,11 @@ ContactItem::ContactItem(Nepomuk::PersonContact personContact,
{
kDebug() << this << ": New ContactItem: " << personContact.resourceType().toString() << imAccount.resourceType().toString();
+ // Subscribe to Nepomuk change signals for our Nepomuk Resources.
+ NepomukSignalWatcher *watcher = NepomukSignalWatcher::instance();
+ watcher->registerCallbackOnSubject(m_imAccount, this);
+ watcher->registerCallbackOnSubject(m_personContact, this);
+
updatePresenceIcon();
}
@@ -95,6 +100,11 @@ const KIcon& ContactItem::presenceIcon() const
return *m_presenceIcon;
}
+void ContactItem::onStatementAdded(const Soprano::Statement &statement)
+{
+ kDebug() << "Statement added called.";
+}
+
#include "contact-item.moc"
diff --git a/contact-item.h b/contact-item.h
index 36befca..8431184 100644
--- a/contact-item.h
+++ b/contact-item.h
@@ -22,6 +22,8 @@
#ifndef TELEPATHY_CONTACTSLIST_PROTOTYPE_CONTACT_ITEM_H
#define TELEPATHY_CONTACTSLIST_PROTOTYPE_CONTACT_ITEM_H
+#include "nepomuk-signal-watcher.h"
+
#include "imaccount.h"
#include "personcontact.h"
@@ -29,7 +31,7 @@
#include <QObject>
-class ContactItem : public QObject {
+class ContactItem : public QObject, NepomukSignalWatcher::Watcher {
Q_OBJECT
@@ -42,6 +44,8 @@ public:
QString displayName() const;
const KIcon& presenceIcon() const;
+ virtual void onStatementAdded(const Soprano::Statement &statement);
+
private Q_SLOTS:
void updatePresenceIcon();
diff --git a/main.cpp b/main.cpp
index 2d4198e..bba0e41 100644
--- a/main.cpp
+++ b/main.cpp
@@ -40,6 +40,7 @@ namespace
if ((signal == SIGTERM) || (signal == SIGINT)) {
QCoreApplication * const app(QCoreApplication::instance());
if (app != 0) {
+ kDebug() << "Signal Handler Called. Exiting...";
app->quit();
}
}
diff --git a/nepomuk-signal-watcher.cpp b/nepomuk-signal-watcher.cpp
new file mode 100644
index 0000000..c0d3f7f
--- /dev/null
+++ b/nepomuk-signal-watcher.cpp
@@ -0,0 +1,85 @@
+/*
+ * 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 "nepomuk-signal-watcher.h"
+
+#include <KDebug>
+
+#include <Nepomuk/ResourceManager>
+
+#include <Soprano/Node>
+#include <Soprano/Statement>
+
+NepomukSignalWatcher* NepomukSignalWatcher::s_self = 0;
+
+NepomukSignalWatcher::NepomukSignalWatcher()
+ : m_sopranoModel(new Soprano::Util::SignalCacheModel(
+ Nepomuk::ResourceManager::instance()->mainModel()))
+{
+ kDebug();
+
+ // Set up the singleton instance
+ s_self = this;
+
+ // Connect to the slots we need to monitor from the Soprano Model.
+ connect(m_sopranoModel,
+ SIGNAL(statementAdded(Soprano::Statement)),
+ SLOT(onStatementAdded(Soprano::Statement)));
+}
+
+NepomukSignalWatcher::~NepomukSignalWatcher()
+{
+ kDebug();
+
+ delete m_sopranoModel;
+
+ // Delete the singleton instance of this class
+ s_self = 0;
+}
+
+NepomukSignalWatcher *NepomukSignalWatcher::instance()
+{
+ // Construct the singleton if hasn't been already
+ if (!s_self) {
+ s_self = new NepomukSignalWatcher;
+ }
+
+ // Return the singleton instance of this class
+ return s_self;
+}
+
+void NepomukSignalWatcher::onStatementAdded(const Soprano::Statement &statement)
+{
+ foreach (NepomukSignalWatcher::Watcher *callback,
+ m_subjectCallbacks.values(statement.subject().toString())) {
+ // Call the callback
+ callback->onStatementAdded(statement);
+ }
+}
+
+void NepomukSignalWatcher::registerCallbackOnSubject(const Nepomuk::Resource &resource,
+ NepomukSignalWatcher::Watcher *callback)
+{
+ // Add this subject to the list.
+ m_subjectCallbacks.insertMulti(resource.resourceUri().toString(), callback);
+ kDebug() << "Registering callback:" << resource.resourceUri() << callback;
+}
+
diff --git a/nepomuk-signal-watcher.h b/nepomuk-signal-watcher.h
new file mode 100644
index 0000000..18d4287
--- /dev/null
+++ b/nepomuk-signal-watcher.h
@@ -0,0 +1,86 @@
+/*
+ * 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 NEPOMUK_SIGNAL_WATCHER_H
+#define NEPOMUK_SIGNAL_WATCHER_H
+
+#include <Nepomuk/Resource>
+
+#include <QtCore/QMap>
+#include <QtCore/QObject>
+#include <QtCore/QPair>
+
+#include <Soprano/Util/SignalCacheModel>
+
+/**
+ * This class allows you to register an interest in a specific Nepomuk resource
+ * and be notified whenever that resource is either the subject or object of a statement
+ * added or removed from the Nepomuk database. It calls the appropriate callback that is
+ * registered with it, when something happens concerning a specific resource.
+ *
+ * The purpose of all this is to improve performance and code readability (hopefully) by
+ * not needing to have Soprano::SignalCachedModels doing stuff all over the place in our
+ * source code.
+ *
+ * Really, the purpose of this class should be fulfilled by Nepomuk or Soprano in some better
+ * way, but until that day arrives, we need this temporary solution.
+ *
+ * To use this class, the object must inherit from NepomukSignalWatcher::Watcher, and reimplement
+ * onStatementAdded() and/or onStatementRemoved(). It must then registerCallbackOnSubject()
+ * etc for all the resource it is interested in.
+ */
+class NepomukSignalWatcher : public QObject
+{
+ Q_OBJECT
+
+public:
+ class Watcher {
+ public:
+ Watcher() { }
+ virtual ~Watcher() { }
+ virtual void onStatementAdded(const Soprano::Statement &statement) { Q_UNUSED(statement); }
+ virtual void onStatementRemoved(const Soprano::Statement &statement) { Q_UNUSED(statement); }
+ };
+
+ static NepomukSignalWatcher *instance();
+
+ virtual ~NepomukSignalWatcher();
+
+ void registerCallbackOnSubject(const Nepomuk::Resource &resource,
+ NepomukSignalWatcher::Watcher *callback);
+
+private Q_SLOTS:
+ void onStatementAdded(const Soprano::Statement &statement);
+
+private:
+ Q_DISABLE_COPY(NepomukSignalWatcher);
+
+ NepomukSignalWatcher();
+ static NepomukSignalWatcher *s_self;
+
+ Soprano::Util::SignalCacheModel *m_sopranoModel;
+
+ QMap<QString, NepomukSignalWatcher::Watcher*> m_subjectCallbacks;
+};
+
+
+#endif // Header guard
+
--
ktp-contact-list packaging
More information about the pkg-kde-commits
mailing list