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


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

The following commit has been merged in the master branch:
commit 713ea815e0f5e19d7eebf418dc003a2953a1e26d
Author: Dario Freddi <drf at kde.org>
Date:   Mon May 10 20:24:52 2010 +0000

    CCMAIL: kde-telepathy at kde.org
    
    Switch all SPARQL queries to the new Nepomuk::Query framework. This grants a more readable and maintainable code,
    some optimizations in the queries for free, and overall a nice improvement.
    
    Please note: this also increases the dependency to KDE 4.5. Also, you need some fixes in trunk since yesterday.
    
    Signed-off-by: Dario Freddi <dario.freddi at collabora.co.uk>
    
    svn path=/trunk/playground/network/telepathy-contactlist/; revision=1125158
---
 CMakeLists.txt           |   3 +-
 add-meta-contact-job.cpp |   1 -
 contacts-list-model.cpp  | 113 ++++++++++++++++++++++++++++++++---------------
 main-widget.cpp          |  81 ++++++++++++++++++++++-----------
 meta-contact-item.cpp    |  88 ++++++++++++++++++++++++++----------
 remove-contacts-job.cpp  |  50 +++++++++++++--------
 telepathy-bridge.cpp     |  81 ++++++++++++++++++++++++---------
 7 files changed, 290 insertions(+), 127 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 85d52a2..94fea6e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -5,7 +5,8 @@ set (CMAKE_MODULE_PATH
      ${CMAKE_MODULE_PATH}
 )
 
-find_package (KDE4 REQUIRED)
+set(KDE_MIN_VERSION "4.4.75")
+find_package (KDE4 4.4.75 REQUIRED)
 find_package (TelepathyQt4 REQUIRED)
 find_package(Nepomuk REQUIRED)
 
diff --git a/add-meta-contact-job.cpp b/add-meta-contact-job.cpp
index e4796e0..2df3d02 100644
--- a/add-meta-contact-job.cpp
+++ b/add-meta-contact-job.cpp
@@ -23,7 +23,6 @@
 
 #include "telepathy-base-job_p.h"
 #include <QTimer>
-#include <Soprano/Node>
 #include <pimo.h>
 #include <person.h>
 #include <nco.h>
diff --git a/contacts-list-model.cpp b/contacts-list-model.cpp
index 12e4071..4083de2 100644
--- a/contacts-list-model.cpp
+++ b/contacts-list-model.cpp
@@ -41,11 +41,14 @@
 #include <Nepomuk/Variant>
 
 #include <Nepomuk/Query/QueryServiceClient>
+#include <Nepomuk/Query/Query>
+#include <Nepomuk/Query/ResourceTypeTerm>
+#include <Nepomuk/Query/ResourceTerm>
+#include <Nepomuk/Query/ComparisonTerm>
+#include <Nepomuk/Query/AndTerm>
+#include <Nepomuk/Query/NegationTerm>
 #include <Nepomuk/Query/Result>
 
-#include <Soprano/Model>
-#include <Soprano/QueryResultIterator>
-
 #include <unistd.h>
 #include <KMessageBox>
 
@@ -61,35 +64,26 @@ ContactsListModel::ContactsListModel(QObject *parent)
     // 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 %1 }")
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::Person()));
-
     m_metaContactsQuery = new Nepomuk::Query::QueryServiceClient(this);
     connect(m_metaContactsQuery, SIGNAL(newEntries(QList<Nepomuk::Query::Result>)),
             this, SLOT(onMetaContactsQueryNewEntries(QList<Nepomuk::Query::Result>)));
     connect(m_metaContactsQuery, SIGNAL(entriesRemoved(QList<QUrl>)),
             this, SLOT(onMetaContactsEntriesRemoved(QList<QUrl>)));
 
-    bool queryResult = m_metaContactsQuery->sparqlQuery(metaContactQuery);
-    kDebug() << "Metacontact query result " << queryResult;
-    if (!queryResult) {
-        KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
-                                   "installation and make sure Nepomuk is running."));
-    }
+    // Get all metacontacts
+    {
+        using namespace Nepomuk::Query;
+
+        Query query(ResourceTypeTerm(Nepomuk::Vocabulary::PIMO::Person()));
 
-    // Get all the Telepathy PersonContacts which do not belong to any metacontact
-    QString query = QString("select distinct ?r ?account where { ?r a %1 . ?r %2 ?account . "
-                            "?acccount a %3 . ?account %4 ?t . ?account %5 ?t . ?t a %3 . ?s %2 ?t . "
-                            "?s a %1 . %6 %7 ?s . optional { ?u a %8 . ?u %7 ?r } . filter(!bound(?u))  }")
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::PersonContact()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::Telepathy::isBuddyOf()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::Telepathy::publishesPresenceTo()))
-            .arg(Soprano::Node::resourceToN3(me.resourceUri()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::groundingOccurrence()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::Person()));
+        bool queryResult = m_metaContactsQuery->query(query);
+        kDebug() << "Metacontact query result " << queryResult;
+
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                       "installation and make sure Nepomuk is running."));
+        }
+    }
 
     m_contactsQuery = new Nepomuk::Query::QueryServiceClient(this);
     connect(m_contactsQuery, SIGNAL(newEntries(QList<Nepomuk::Query::Result>)),
@@ -97,13 +91,60 @@ ContactsListModel::ContactsListModel(QObject *parent)
     connect(m_contactsQuery, SIGNAL(entriesRemoved(QList<QUrl>)),
             this, SLOT(onContactsQueryEntriesRemoved(QList<QUrl>)));
 
-    Nepomuk::Query::RequestPropertyMap rpm;
-    rpm.insert("account", Nepomuk::Vocabulary::NCO::IMAccount());
-    queryResult = m_contactsQuery->sparqlQuery(query, rpm);
-    kDebug() << "Contact query result " << queryResult;
-    if (!queryResult) {
-        KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
-                                   "installation and make sure Nepomuk is running."));
+    // Get all Telepathy PersonContacts which do not belong to any metacontact
+    {
+        using namespace Nepomuk::Query;
+        using namespace Nepomuk::Vocabulary;
+        // subquery to match grouding occurrences of me
+        ComparisonTerm goterm(PIMO::groundingOccurrence(),
+                              ResourceTerm(me));
+        goterm.setInverted(true);
+
+        // combine that with only nco:PersonContacts
+        AndTerm pcgoterm(ResourceTypeTerm(NCO::PersonContact()),
+                         goterm);
+
+        // now look for im accounts of those grounding occurrences (pcgoterm will become the subject of this comparison,
+        // thus the comparison will match the im accounts)
+        ComparisonTerm impcgoterm(NCO::hasIMAccount(),
+                                  pcgoterm);
+        impcgoterm.setInverted(true);
+
+        // now look for all buddies of the accounts
+        ComparisonTerm buddyTerm(Telepathy::isBuddyOf(),
+                                 impcgoterm);
+        // set the name of the variable (i.e. the buddies) to be able to match it later
+        buddyTerm.setVariableName("t");
+
+        // same comparison, other property, but use the same variable name to match them
+        ComparisonTerm ppterm(Telepathy::publishesPresenceTo(),
+                              ResourceTypeTerm(NCO::IMAccount()));
+        ppterm.setVariableName("t");
+
+        // combine both to complete the matching of the im account ?account
+        AndTerm accountTerm(ResourceTypeTerm(NCO::IMAccount()),
+                            buddyTerm, ppterm);
+
+        // match the account and select it for the results
+        ComparisonTerm imaccountTerm(NCO::hasIMAccount(), accountTerm);
+        imaccountTerm.setVariableName("account");
+
+        // and finally the exclusion of those person contacts that already have a pimo person attached
+        ComparisonTerm personTerm(PIMO::groundingOccurrence(),
+                                  ResourceTypeTerm(PIMO::Person()));
+        personTerm.setInverted(true);
+
+        // and all combined
+        Query query(AndTerm(ResourceTypeTerm(Nepomuk::Vocabulary::NCO::PersonContact()),
+                            imaccountTerm, NegationTerm::negateTerm(personTerm)));
+
+        bool queryResult = m_contactsQuery->query(query);
+
+        kDebug() << "Contact query result " << queryResult;
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                       "installation and make sure Nepomuk is running."));
+        }
     }
 }
 
@@ -112,8 +153,8 @@ void ContactsListModel::onContactsQueryNewEntries(const QList<Nepomuk::Query::Re
     kDebug();
     // Iterate over all the IMAccounts/PersonContacts found.
     foreach (const Nepomuk::Query::Result &result, entries) {
-        Nepomuk::PersonContact foundPersonContact(result.resource().resourceUri());
-        Nepomuk::IMAccount foundIMAccount(result.requestProperty(Nepomuk::Vocabulary::NCO::IMAccount()).uri());
+        Nepomuk::PersonContact foundPersonContact(result.resource());
+        Nepomuk::IMAccount foundIMAccount(result.additionalBinding("account").uri());
         kDebug() << "New resource added: " << foundPersonContact << foundIMAccount;
 
         // Create a fake metacontact to hold this item.
@@ -178,8 +219,8 @@ void ContactsListModel::onMetaContactsQueryNewEntries(const QList< Nepomuk::Quer
     kDebug();
     // Iterate over all the IMAccounts/PersonContacts found.
     foreach (const Nepomuk::Query::Result &result, entries) {
-        kDebug()<<result.resource();
-        Nepomuk::Person foundPimoPerson(result.resource().resourceUri());
+        kDebug() << result.resource();
+        Nepomuk::Person foundPimoPerson(result.resource());
         kDebug() << "Found a PIMO Person "<< foundPimoPerson;
         MetaContactItem *item = new MetaContactItem(MetaContactItem::RealMetaContact, 0);
         item->setParentItem(m_rootItem);
diff --git a/main-widget.cpp b/main-widget.cpp
index 4275e95..b5f2ada 100644
--- a/main-widget.cpp
+++ b/main-widget.cpp
@@ -47,11 +47,12 @@
 #include <Nepomuk/Variant>
 #include <Nepomuk/Query/QueryServiceClient>
 #include <Nepomuk/Query/ComparisonTerm>
+#include <Nepomuk/Query/ResourceTerm>
 #include <Nepomuk/Query/ResourceTypeTerm>
 #include <Nepomuk/Query/LiteralTerm>
 #include <Nepomuk/Query/AndTerm>
+#include <Nepomuk/Query/Result>
 
-#include <Soprano/QueryResultIterator>
 #include <pimo.h>
 #include <nao.h>
 
@@ -262,18 +263,27 @@ void MainWidget::onCustomContextMenuRequested(const QPoint& point)
         }
 
         if (canAddToMetaContact) {
-            // Let's list available metacontacts here
-            QString metaContactQuery = QString("select distinct ?a where { ?a a %7 . }")
-                .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::Person()));
-            Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-            Soprano::QueryResultIterator it = model->executeQuery(metaContactQuery,
-                                                                  Soprano::Query::QueryLanguageSparql);
+            // List available metacontacts
+            QList<Nepomuk::Query::Result> results;
+            {
+                using namespace Nepomuk::Query;
+
+                Query query(ResourceTypeTerm(Nepomuk::Vocabulary::PIMO::Person()));
+
+                bool queryResult = true;
+                results = QueryServiceClient::syncQuery(query, &queryResult);
+
+                if (!queryResult) {
+                    KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                               "installation and make sure Nepomuk is running."));
+                }
+            }
 
             QMenu *parentAction = new QMenu(i18n("Add to metacontact"));
             menu->addMenu(parentAction);
             // Iterate over all the IMAccounts found.
-            while(it.next()) {
-                Nepomuk::Person foundPerson(it.binding("a").uri());
+            foreach (const Nepomuk::Query::Result &result, results) {
+                Nepomuk::Person foundPerson(result.resource());
                 kDebug() << foundPerson;
                 QAction *action = parentAction->addAction(foundPerson.genericLabel());
                 connect(action, SIGNAL(triggered(bool)),
@@ -574,23 +584,35 @@ void MainWidget::onAddContactRequest(bool )
     lay->addWidget(account);
     lay->addWidget(contactId);
 
-    // Get all valid TP accounts through a sparql query
-    QString query = QString("select distinct ?a where { %1 %2 ?a . ?a a %3 }")
-                            .arg(Soprano::Node::resourceToN3(m_mePersonContact.resourceUri()))
-                            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
-                            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()));
+    // Get all valid Telepathy accounts
+    QList<Nepomuk::Query::Result> results;
+    {
+        using namespace Nepomuk::Query;
+
+        // me must have an IMAccount
+        ComparisonTerm imterm(Nepomuk::Vocabulary::NCO::hasIMAccount(),
+                              ResourceTerm(m_mePersonContact));
+        imterm.setInverted(true);
 
-    // Get the Nepomuk model to query.
-    Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
+        // Which must be an IMAccount of course
+        Query query(AndTerm(ResourceTypeTerm(Nepomuk::Vocabulary::NCO::IMAccount()),
+                            imterm));
 
-    Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
+        bool queryResult = true;
+        results = QueryServiceClient::syncQuery(query, &queryResult);
+
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                        "installation and make sure Nepomuk is running."));
+        }
+    }
 
     // Iterate over all the IMAccounts/PersonContacts found.
-    while(it.next()) {
-        Nepomuk::IMAccount foundIMAccount(it.binding("a").uri());
+    foreach (const Nepomuk::Query::Result &result, results) {
+        Nepomuk::IMAccount foundIMAccount(result.resource());
 
         foreach (const QString &id, foundIMAccount.imIDs()) {
-            account->addItem(id, it.binding("a").uri());
+            account->addItem(id, foundIMAccount.resourceUri());
         }
     }
 
@@ -667,21 +689,28 @@ void MainWidget::onAddToMetaContact(bool )
     }
 
     // Ok, now let's add the contact
-    Soprano::QueryResultIterator it;
+    QList< Nepomuk::Query::Result > results;
     {
         using namespace Nepomuk::Query;
         using namespace Nepomuk::Vocabulary;
+
         ResourceTypeTerm rtterm(PIMO::Person());
         ComparisonTerm cmpterm(NAO::prefLabel(), LiteralTerm(metaContactName));
+
         Query query(AndTerm(cmpterm, rtterm));
-        Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-        it = model->executeQuery(query.toSparqlQuery(), Soprano::Query::QueryLanguageSparql);
-        kDebug() << query.toSparqlQuery();
+
+        bool queryResult = true;
+        results = QueryServiceClient::syncQuery(query, &queryResult);
+
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                       "installation and make sure Nepomuk is running."));
+        }
     }
 
     // Iterate over all the IMAccounts found.
-    while(it.next()) {
-        Nepomuk::Person foundPerson(it.binding("r").uri());
+    foreach (const Nepomuk::Query::Result &result, results) {
+        Nepomuk::Person foundPerson(result.resource());
         foundPerson.addGroundingOccurrence(contactItem->personContact());
     }
 }
diff --git a/meta-contact-item.cpp b/meta-contact-item.cpp
index 13a6202..9b2e1f0 100644
--- a/meta-contact-item.cpp
+++ b/meta-contact-item.cpp
@@ -30,8 +30,16 @@
 #include <telepathy.h>
 #include <pimo.h>
 #include <Nepomuk/Variant>
-#include <Nepomuk/Query/Result>
+
 #include <Nepomuk/Query/QueryServiceClient>
+#include <Nepomuk/Query/Query>
+#include <Nepomuk/Query/ResourceTypeTerm>
+#include <Nepomuk/Query/ResourceTerm>
+#include <Nepomuk/Query/ComparisonTerm>
+#include <Nepomuk/Query/AndTerm>
+#include <Nepomuk/Query/NegationTerm>
+#include <Nepomuk/Query/Result>
+
 #include <KMessageBox>
 
 MetaContactItem::MetaContactItem(MetaContactType type, QObject *parent)
@@ -81,33 +89,65 @@ void MetaContactItem::setPimoPerson(const Nepomuk::Person& pimoPerson)
     // FIXME: Get the Nepomuk Resource for myself in the standardised way, once it is standardised.
     Nepomuk::Resource me(QUrl::fromEncoded("nepomuk:/myself"));
 
-    // Ok, now we need a decent query to find out our children.
-    // Get all the Telepathy PersonContacts which belong to this metacontact, and match our criteria
-    QString query = QString("select distinct ?r ?account where { %8 %7 ?r . ?r a %1 . ?r %2 ?account . "
-                            "?acccount a %3 . ?account %4 ?t . ?account %5 ?t . ?t a %3 . ?s %2 ?t . "
-                            "?s a %1 . %6 %7 ?s }")
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::PersonContact()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::Telepathy::isBuddyOf()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::Telepathy::publishesPresenceTo()))
-            .arg(Soprano::Node::resourceToN3(me.resourceUri()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::groundingOccurrence()))
-            .arg(Soprano::Node::resourceToN3(pimoPerson.resourceUri()));
-
     m_queryClient = new Nepomuk::Query::QueryServiceClient(this);
     connect(m_queryClient, SIGNAL(newEntries(QList<Nepomuk::Query::Result>)),
             this, SLOT(onNewEntries(QList<Nepomuk::Query::Result>)));
     connect(m_queryClient, SIGNAL(entriesRemoved(QList<QUrl>)),
             this, SLOT(onEntriesRemoved(QList<QUrl>)));
 
-    Nepomuk::Query::RequestPropertyMap rpm;
-    rpm.insert("account", Nepomuk::Vocabulary::NCO::IMAccount());
-    bool queryResult = m_queryClient->sparqlQuery(query, rpm);
-    kDebug() << "Query result for " << pimoPerson << queryResult;
-    if (!queryResult) {
-        KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
-                                   "installation and make sure Nepomuk is running."));
+    // Get all Telepathy PersonContacts which belong to this metacontact, and match our criteria
+    {
+        using namespace Nepomuk::Query;
+        using namespace Nepomuk::Vocabulary;
+        // subquery to match grouding occurrences of me
+        ComparisonTerm goterm(PIMO::groundingOccurrence(),
+                              ResourceTerm(me));
+        goterm.setInverted(true);
+
+        // combine that with only nco:PersonContacts
+        AndTerm pcgoterm(ResourceTypeTerm(NCO::PersonContact()),
+                         goterm);
+
+        // now look for im accounts of those grounding occurrences (pcgoterm will become the subject of this comparison,
+        // thus the comparison will match the im accounts)
+        ComparisonTerm impcgoterm(NCO::hasIMAccount(),
+                                  pcgoterm);
+        impcgoterm.setInverted(true);
+
+        // now look for all buddies of the accounts
+        ComparisonTerm buddyTerm(Telepathy::isBuddyOf(),
+                                 impcgoterm);
+        // set the name of the variable (i.e. the buddies) to be able to match it later
+        buddyTerm.setVariableName("t");
+
+        // same comparison, other property, but use the same variable name to match them
+        ComparisonTerm ppterm(Telepathy::publishesPresenceTo(),
+                              ResourceTypeTerm(NCO::IMAccount()));
+        ppterm.setVariableName("t");
+
+        // combine both to complete the matching of the im account ?account
+        AndTerm accountTerm(ResourceTypeTerm(NCO::IMAccount()),
+                            buddyTerm, ppterm);
+
+        // match the account and select it for the results
+        ComparisonTerm imaccountTerm(NCO::hasIMAccount(), accountTerm);
+        imaccountTerm.setVariableName("account");
+
+        // the result must be a groundingOccurrence of pimoPerson
+        ComparisonTerm personTerm(PIMO::groundingOccurrence(),
+                                  ResourceTerm(pimoPerson));
+        personTerm.setInverted(true);
+
+        // and all combined
+        Query query(AndTerm(ResourceTypeTerm(Nepomuk::Vocabulary::NCO::PersonContact()),
+                            imaccountTerm, personTerm));
+
+        bool queryResult = m_queryClient->query(query);
+        kDebug() << "Query result for " << pimoPerson << queryResult;
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                    "installation and make sure Nepomuk is running."));
+        }
     }
 }
 
@@ -138,8 +178,8 @@ void MetaContactItem::onNewEntries(const QList< Nepomuk::Query::Result > &entrie
     kDebug();
     // Iterate over all the IMAccounts/PersonContacts found.
     foreach (const Nepomuk::Query::Result &result, entries) {
-        Nepomuk::PersonContact foundPersonContact(result.resource().resourceUri());
-        Nepomuk::IMAccount foundIMAccount(result.requestProperty(Nepomuk::Vocabulary::NCO::IMAccount()).uri());
+        Nepomuk::PersonContact foundPersonContact(result.resource());
+        Nepomuk::IMAccount foundIMAccount(result.additionalBinding("account").uri());
         kDebug() << "New resource added";
 
         // Create the contact item itself, parenting it to this metacontact.
diff --git a/remove-contacts-job.cpp b/remove-contacts-job.cpp
index 380ae00..a08c2f1 100644
--- a/remove-contacts-job.cpp
+++ b/remove-contacts-job.cpp
@@ -24,6 +24,8 @@
 #include <person.h>
 #include <personcontact.h>
 #include <imaccount.h>
+#include <pimo.h>
+#include <informationelement.h>
 
 #include <QTimer>
 
@@ -34,16 +36,20 @@
 #include <KLocalizedString>
 #include <KDebug>
 
+#include <KMessageBox>
+
 #include <TelepathyQt4/Account>
 #include <TelepathyQt4/AccountManager>
 #include <TelepathyQt4/ContactManager>
 #include <TelepathyQt4/PendingOperation>
-#include <Soprano/Node>
-#include <pimo.h>
-#include <Soprano/Model>
-#include <Nepomuk/ResourceManager>
-#include <Soprano/QueryResultIterator>
-#include <informationelement.h>
+
+#include <Nepomuk/Query/Query>
+#include <Nepomuk/Query/QueryServiceClient>
+#include <Nepomuk/Query/AndTerm>
+#include <Nepomuk/Query/ResourceTerm>
+#include <Nepomuk/Query/ResourceTypeTerm>
+#include <Nepomuk/Query/ComparisonTerm>
+#include <Nepomuk/Query/Result>
 
 class RemoveContactsJobPrivate : public TelepathyBaseJobPrivate
 {
@@ -204,24 +210,32 @@ void RemoveContactsJobPrivate::__k__removeContacts()
             }
         }
         if (removalModes & TelepathyBridge::RemoveFromMetacontactMode) {
-            // Check if this contact is associated to a metacontact
-            Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-
             // FIXME: Port to new OSCAF standard for accessing "me" as soon as it
             // becomes available.
             Nepomuk::Thing me(QUrl::fromEncoded("nepomuk:/myself"));
 
             foreach (const Nepomuk::PersonContact &contact, proxyToContacts[i.key()]) {
-                QString query = QString("select distinct ?r where { ?r a %1 . ?r %2 %3 }")
-                                .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::Person()))
-                                .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::groundingOccurrence()))
-                                .arg(Soprano::Node::resourceToN3(contact.resourceUri()));
-
-
-                Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
+                QList< Nepomuk::Query::Result > results;
+                // Get metacontacts for a specific contact
+                {
+                    using namespace Nepomuk::Query;
+
+                    ResourceTypeTerm rterm(Nepomuk::Vocabulary::PIMO::Person());
+                    ComparisonTerm cterm(Nepomuk::Vocabulary::PIMO::groundingOccurrence(),
+                                         ResourceTerm(contact));
+                    Query query(AndTerm(rterm, cterm));
+
+                    bool queryResult = true;
+                    results = QueryServiceClient::syncQuery(query, &queryResult);
+
+                    if (!queryResult) {
+                        KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                                   "installation and make sure Nepomuk is running."));
+                    }
+                }
 
-                while (it.next()) {
-                    Nepomuk::Person foundPerson(it.binding("r").uri());
+                foreach (const Nepomuk::Query::Result &result, results) {
+                    Nepomuk::Person foundPerson(result.resource());
 
                     if (foundPerson.resourceUri() == me.resourceUri()) {
                         kDebug() << "Skipping myself resource for removing from metacontact";
diff --git a/telepathy-bridge.cpp b/telepathy-bridge.cpp
index 1b18323..7d9962b 100644
--- a/telepathy-bridge.cpp
+++ b/telepathy-bridge.cpp
@@ -46,11 +46,15 @@
 #include <KDebug>
 #include <KGlobal>
 
-#include <Nepomuk/ResourceManager>
-
-#include <Soprano/Node>
-#include <Soprano/QueryResultIterator>
-#include <Soprano/Model>
+#include <Nepomuk/Query/QueryServiceClient>
+#include <Nepomuk/Query/Query>
+#include <Nepomuk/Query/ResourceTypeTerm>
+#include <Nepomuk/Query/ResourceTerm>
+#include <Nepomuk/Query/ComparisonTerm>
+#include <Nepomuk/Query/AndTerm>
+#include <Nepomuk/Query/NegationTerm>
+#include <Nepomuk/Query/Result>
+#include <KMessageBox>
 
 class TelepathyBridgeHelper
 {
@@ -195,24 +199,59 @@ QList< Nepomuk::PersonContact > TelepathyBridgePrivate::contactsForMetaContact(c
 {
     QList< Nepomuk::PersonContact > retlist;
 
-    // We need a query here, go sparql!
-    QString query = QString("select distinct ?a where { ?a a %1 . %2 %3 ?a . ?a %4 ?r . ?r a %5 . ?r %6 ?s . "
-                            "?s a %5 . ?t a %1 . ?t %4 ?s . %7 %3 ?t }")
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::PersonContact()))
-            .arg(Soprano::Node::resourceToN3(metacontact.resourceUri()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::PIMO::groundingOccurrence()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::hasIMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::NCO::IMAccount()))
-            .arg(Soprano::Node::resourceToN3(Nepomuk::Vocabulary::Telepathy::isBuddyOf()))
-            .arg(Soprano::Node::resourceToN3(mePimoURI));
-
-    // Get the Nepomuk model to query.
-    Soprano::Model *model = Nepomuk::ResourceManager::instance()->mainModel();
-    Soprano::QueryResultIterator it = model->executeQuery(query, Soprano::Query::QueryLanguageSparql);
+    // Get all Telepathy PersonContacts which belong to this metacontact, and match our criteria
+    QList< Nepomuk::Query::Result > results;
+    {
+        using namespace Nepomuk::Query;
+        using namespace Nepomuk::Vocabulary;
+        // subquery to match grouding occurrences of mePimoURI
+        ComparisonTerm goterm(PIMO::groundingOccurrence(),
+                              ResourceTerm(mePimoURI));
+        goterm.setInverted(true);
+
+        // combine that with only nco:PersonContacts
+        AndTerm pcgoterm(ResourceTypeTerm(NCO::PersonContact()),
+                         goterm);
+
+        // now look for im accounts of those grounding occurrences (pcgoterm will become the subject of this comparison,
+        // thus the comparison will match the im accounts)
+        ComparisonTerm impcgoterm(NCO::hasIMAccount(),
+                                  pcgoterm);
+        impcgoterm.setInverted(true);
+
+        // now look for all buddies of the accounts
+        ComparisonTerm buddyTerm(Telepathy::isBuddyOf(),
+                                 impcgoterm);
+
+        // combine that with only IMAccounts
+        AndTerm imbuddyTerm(ResourceTypeTerm(NCO::IMAccount()),
+                            buddyTerm);
+
+        // ensure the result has this IMAccount
+        ComparisonTerm retAccountTerm(NCO::hasIMAccount(),
+                                      imbuddyTerm);
+
+        // match grouding occurrences of metacontact
+        ComparisonTerm retgoterm(PIMO::groundingOccurrence(),
+                                 ResourceTerm(metacontact));
+        goterm.setInverted(true);
+
+        // and all combined
+        Query query(AndTerm(ResourceTypeTerm(Nepomuk::Vocabulary::NCO::PersonContact()),
+                            retAccountTerm, retgoterm));
+
+        bool queryResult = true;
+        results = QueryServiceClient::syncQuery(query, &queryResult);
+
+        if (!queryResult) {
+            KMessageBox::error(0, i18n("It was not possible to query Nepomuk database. Please check your "
+                                       "installation and make sure Nepomuk is running."));
+        }
+    }
 
     // Iterate over all the IMAccounts/PersonContacts found.
-    while(it.next()) {
-        Nepomuk::PersonContact foundPersonContact(it.binding("a").uri());
+    foreach (const Nepomuk::Query::Result &result, results) {
+        Nepomuk::PersonContact foundPersonContact(result.resource());
 
         retlist << foundPersonContact;
     }

-- 
ktp-contact-list packaging



More information about the pkg-kde-commits mailing list