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


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

The following commit has been merged in the master branch:
commit 1ba100f2e72f598110316514cbfbad06a832a129
Author: Vishesh Handa <me at vhanda.in>
Date:   Wed Aug 29 02:19:40 2012 +0530

    Contacts query - Use a simpler sparql query
    
    Insted of the earlier complex query. Also, do not request for the
    pimo:Person, we have no need for it.
    
    The telepathy-nepomuk-service will just deal with contacts.
---
 kpeople/nepomuk-feeder/nepomuk-storage.cpp | 154 ++++++-----------------------
 kpeople/nepomuk-feeder/nepomuk-storage.h   |   9 +-
 2 files changed, 29 insertions(+), 134 deletions(-)

diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.cpp b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
index 4472003..d6466e7 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.cpp
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.cpp
@@ -201,9 +201,8 @@ bool ContactIdentifier::operator!=(const ContactIdentifier& other) const
 
 class ContactResources::Data : public QSharedData {
 public:
-    Data(const QUrl &p, const QUrl &pc,  const QUrl &ia)
-      : person(p),
-        personContact(pc),
+    Data(const QUrl &pc,  const QUrl &ia)
+      : personContact(pc),
         imAccount(ia)
     { }
 
@@ -212,7 +211,6 @@ public:
 
     Data(const Data &other)
       : QSharedData(other),
-        person(other.person),
         personContact(other.personContact),
         imAccount(other.imAccount)
     { }
@@ -220,15 +218,13 @@ public:
     ~Data()
     { }
 
-    QUrl person;
     QUrl personContact;
     QUrl imAccount;
 };
 
-ContactResources::ContactResources(const QUrl &person,
-                                   const QUrl &personContact,
+ContactResources::ContactResources(const QUrl &personContact,
                                    const QUrl &imAccount)
-  : d(new Data(person, personContact, imAccount))
+  : d(new Data(personContact, imAccount))
 { }
 
 ContactResources::ContactResources()
@@ -242,11 +238,6 @@ ContactResources::ContactResources(const ContactResources &other)
 ContactResources::~ContactResources()
 { }
 
-const QUrl &ContactResources::person() const
-{
-    return d->person;
-}
-
 const QUrl &ContactResources::personContact() const
 {
     return d->personContact;
@@ -259,8 +250,7 @@ const QUrl &ContactResources::imAccount() const
 
 bool ContactResources::operator==(const ContactResources& other) const
 {
-    return ((other.person() == person()) &&
-            (other.personContact() == personContact()) &&
+    return ((other.personContact() == personContact()) &&
             (other.imAccount() == imAccount()));
 }
 
@@ -271,7 +261,7 @@ bool ContactResources::operator!=(const ContactResources& other) const
 
 bool ContactResources::isEmpty() const
 {
-    return d->person.isEmpty() && d->personContact.isEmpty() && d->imAccount.isEmpty();
+    return d->personContact.isEmpty() && d->imAccount.isEmpty();
 }
 
 
@@ -411,124 +401,38 @@ void NepomukStorage::init()
 void NepomukStorage::onAccountsQueryFinishedListing()
 {
     kDebug() << "Accounts Query Finished Successfully.";
+    Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
     // Got all the accounts, now move on to the contacts.
 
-    // Query Nepomuk for all know Contacts.
-    {
-        using namespace Nepomuk2::Query;
-
-        // Get the PIMO Person owning that PersonContact
-        ComparisonTerm pterm(Nepomuk2::Vocabulary::PIMO::groundingOccurrence(),
-                             ResourceTypeTerm(Nepomuk2::Vocabulary::PIMO::Person()));
-        pterm.setVariableName("person");
-        pterm.setInverted(true);
-
-        // Get the person contact owning this IMAccount
-        ComparisonTerm pcterm(Nepomuk2::Vocabulary::NCO::hasIMAccount(),
-                            AndTerm(ResourceTypeTerm(Nepomuk2::Vocabulary::NCO::PersonContact()),
-                                    pterm));
-        pcterm.setVariableName("personContact");
-        pcterm.setInverted(true);
-
-        // Special case: if we're buddy of an account we do own, we want to create a new
-        // resource for that.
-        // This avoids race conditions and a lot of bad things.
-        ComparisonTerm accountTerm(Nepomuk2::Vocabulary::NCO::hasIMAccount(),
-                                ResourceTerm(m_mePersonContact));
-        accountTerm.setInverted(true);
-
-        ComparisonTerm hasTelepathyIdTerm(Nepomuk2::Vocabulary::Telepathy::accountIdentifier(), LiteralTerm());
-        hasTelepathyIdTerm.setVariableName("accountIdentifier");
-
-        ComparisonTerm accessedByTerm(Nepomuk2::Vocabulary::NCO::isAccessedBy(),
-                                     AndTerm(ResourceTypeTerm(Nepomuk2::Vocabulary::NCO::IMAccount()),
-                                             hasTelepathyIdTerm));
-        accessedByTerm.setVariableName("accessedBy");
-
-        ComparisonTerm imIdsTerm(Nepomuk2::Vocabulary::NCO::imID(), LiteralTerm());
-        imIdsTerm.setVariableName("imIds");
-
-        Query query(AndTerm(pcterm, NegationTerm::negateTerm(accountTerm), accessedByTerm,
-                            ResourceTypeTerm(Nepomuk2::Vocabulary::NCO::IMAccount()), imIdsTerm));
-
-        QueryServiceClient *client = new QueryServiceClient(this);
-        connect(client,
-                SIGNAL(newEntries(QList<Nepomuk2::Query::Result>)),
-                SLOT(onContactsQueryNewEntries(QList<Nepomuk2::Query::Result>)));
-        connect(client,
-                SIGNAL(entriesRemoved(QList<QUrl>)),
-                SLOT(onContactsQueryEntriesRemoved(QList<QUrl>)));
-        connect(client,
-                SIGNAL(error(QString)),
-                SLOT(onContactsQueryError(QString)));
-        connect(client,
-                SIGNAL(finishedListing()),
-                SLOT(onContactsQueryFinishedListing()));
-        connect(client, SIGNAL(finishedListing()),
-                client, SLOT(deleteLater()));
-        client->query(query);
-    }
-}
-
-void NepomukStorage::onContactsQueryNewEntries(const QList< Nepomuk2::Query::Result > &entries)
-{
-    // Iterate over all the IMAccounts found.
-    foreach (const Nepomuk2::Query::Result &result, entries) {
-
-        QUrl foundImAccount(result.resource().uri());
-        QUrl foundPersonContact(result.additionalBinding("personContact").toUrl());
-        QUrl foundPerson(result.additionalBinding("person").toUrl());
-        QUrl foundImAccountAccessedBy(result.additionalBinding("accessedBy").toUrl());
-        QString foundImAccountIdentifier(result.additionalBinding("accountIdentifier").toString());
+    QHashIterator<QString, AccountResources> iter( m_accounts );
+    while( iter.hasNext() ) {
+        iter.next();
 
-        //kDebug() << "Account Identifier: " << foundImAccountIdentifier;
-        //kDebug() << "PIMO:Person" << foundPerson;
+        const QString& accountId = iter.key();
+        const AccountResources& accRes = iter.value();
 
-        // Check that the IM account only has one ID.
-        QStringList accountIDs = result.additionalBinding("imIds").toStringList();
+        QString query = QString::fromLatin1("select distinct ?r ?id ?contact where { ?r a nco:IMAccount . "
+                                            " ?r nco:imID ?id ; nco:accessedBy %1 . "
+                                            " ?contact nco:hasIMAccount ?r . }")
+                        .arg( Soprano::Node::resourceToN3(accRes.account()) );
 
-        if (accountIDs.size() != 1) {
-            kWarning() << "Account does not have 1 ID. Oops. Ignoring."
-                       << "Number of Identifiers: "
-                       << accountIDs.size();
-            continue;
-        }
+        Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
+        while( it.next() ) {
 
-        //kDebug() << "IM ID:" << accountIDs.first();
+            QUrl imAccount = it["r"].uri();
+            QUrl contact = it["contact"].uri();
+            QString id = it["id"].literal().toString();
 
-        // Cache the contact
-        m_contacts.insert(ContactIdentifier(foundImAccountIdentifier,
-                                            accountIDs.first()),
-                            ContactResources(foundPerson, foundPersonContact, foundImAccount));
-        //kDebug() << "Contact found in Nepomuk. Caching.";
-    }
-}
+            ContactIdentifier ci( accountId, id );
+            ContactResources cr( contact, imAccount );
 
-void NepomukStorage::onContactsQueryEntriesRemoved(const QList<QUrl> &entries)
-{
-    foreach (const QUrl &entry, entries) {
-        foreach (const ContactResources &resources, m_contacts.values()) {
-            if (resources.personContact() == entry) {
-                m_contacts.remove(m_contacts.key(resources));
-                break;
-            }
+            m_contacts.insert( ci, cr );
         }
     }
-}
-
-void NepomukStorage::onContactsQueryError(const QString &errorMessage)
-{
-    kWarning() << "A Nepomuk Error occurred:" << errorMessage;
 
-    emit initialised(false);
+    emit initialised( true );
 }
 
-void NepomukStorage::onContactsQueryFinishedListing()
-{
-    kDebug() << "Contacts Query Finished Successfully.";
-
-    emit initialised(true);
-}
 
 void NepomukStorage::cleanupAccounts(const QList<QString> &paths)
 {
@@ -750,8 +654,7 @@ void NepomukStorage::createContact(const QString &path, const QString &id)
     newPimoPerson.addProperty(Nepomuk2::Vocabulary::PIMO::groundingOccurrence(), newPersonContact);
 
     m_graph << newPersonContact << newImAccount << newPimoPerson;
-    m_contacts.insert( identifier, ContactResources(newPimoPerson.uri(),
-                                                    newPersonContact.uri(),
+    m_contacts.insert( identifier, ContactResources(newPersonContact.uri(),
                                                     newImAccount.uri()) );
 
     // Insert into a list so that their real uri can be set later on
@@ -1082,16 +985,15 @@ void NepomukStorage::onContactGraphJob(KJob* job)
     QList<ContactIdentifier> unresolvedContacts;
     foreach( const ContactIdentifier& identifier, m_unresolvedContacts ) {
         const ContactResources& res = m_contacts[identifier];
-        QUrl personUri = mappings.value( res.person() );
         QUrl contactUri = mappings.value( res.personContact() );
         QUrl accountUri = mappings.value( res.imAccount() );
 
-        if( personUri.isEmpty() || contactUri.isEmpty() || accountUri.isEmpty() ) {
+        if( contactUri.isEmpty() || accountUri.isEmpty() ) {
             unresolvedContacts << identifier;
             continue;
         }
 
-        m_contacts[identifier] = ContactResources(personUri, contactUri, accountUri);
+        m_contacts[identifier] = ContactResources(contactUri, accountUri);
     }
 
     m_unresolvedContacts = unresolvedContacts;
diff --git a/kpeople/nepomuk-feeder/nepomuk-storage.h b/kpeople/nepomuk-feeder/nepomuk-storage.h
index 0774886..7c22faa 100644
--- a/kpeople/nepomuk-feeder/nepomuk-storage.h
+++ b/kpeople/nepomuk-feeder/nepomuk-storage.h
@@ -90,14 +90,12 @@ int qHash(ContactIdentifier c);
 
 class ContactResources {
 public:
-    ContactResources(const QUrl &person,
-                     const QUrl &personContact,
+    ContactResources(const QUrl &personContact,
                      const QUrl &imAccount);
     ContactResources(const ContactResources &other);
     ContactResources();
     ~ContactResources();
 
-    const QUrl &person() const;
     const QUrl &personContact() const;
     const QUrl &imAccount() const;
 
@@ -150,11 +148,6 @@ private Q_SLOTS:
 
     void onAccountsQueryFinishedListing();
 
-    void onContactsQueryNewEntries(const QList<Nepomuk2::Query::Result> &entries);
-    void onContactsQueryEntriesRemoved(const QList<QUrl> &entries);
-    void onContactsQueryError(const QString &errorMessage);
-    void onContactsQueryFinishedListing();
-
     void onContactTimer();
     void onContactGraphJob(KJob *job);
     void onRemovePropertiesJob(KJob *job);

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list