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


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

The following commit has been merged in the master branch:
commit 334b4d53361fd8bdc529305d754c4bf738dd2915
Author: Dario Freddi <drf at kde.org>
Date:   Sun Apr 18 15:28:44 2010 +0000

    Make telepathy-integration-daemon pick up the changes done at a subscription/publication level to telepathy contacts.
    This makes it possible to keep Nepomuk in sync with local changes done.
    
    This also updates the Telepathy ontology.
    
    Signed-off-by: Dario Freddi <dario.freddi at collabora.co.uk>
    
    svn path=/trunk/playground/network/telepathy-integration-daemon/; revision=1116071
---
 kpeople/nepomuk-feeder/telepathy.trig       |  23 ++++-
 kpeople/nepomuk-feeder/telepathyaccount.cpp |  66 ++++++++++--
 kpeople/nepomuk-feeder/telepathyaccount.h   |   1 +
 kpeople/nepomuk-feeder/telepathycontact.cpp | 154 +++++++++++++++++++++++++++-
 kpeople/nepomuk-feeder/telepathycontact.h   |   4 +
 5 files changed, 239 insertions(+), 9 deletions(-)

diff --git a/kpeople/nepomuk-feeder/telepathy.trig b/kpeople/nepomuk-feeder/telepathy.trig
index e001b1a..1a7875c 100644
--- a/kpeople/nepomuk-feeder/telepathy.trig
+++ b/kpeople/nepomuk-feeder/telepathy.trig
@@ -22,7 +22,7 @@ telepathy: {telepathy:accountIdentifier
           rdfs:range xsd:integer .
 
             telepathy:isBuddyOf
-        a       rdf:Property ;
+     a rdf:Property ;
           rdfs:comment "Indicates the local IM Account on whose buddy list this IM Account appears." ;
           rdfs:domain nco:IMAccount ;
           rdfs:label "isBuddyOf" ;
@@ -34,6 +34,27 @@ telepathy: {telepathy:accountIdentifier
           rdfs:domain nco:Contact ;
           rdfs:label "avatarToken" ;
           rdfs:range xsd:string .
+
+          telepathy:isBlocked
+     a rdf:Property ;
+          rdfs:comment "Indicates whether this account has been blocked by the user or not, if the protocol supports it." ;
+          rdfs:domain nco:IMAccount ;
+          rdfs:label "isBlocked" ;
+          rdfs:range xsd:boolean .
+
+          telepathy:publishesPresenceTo
+     a rdf:Property ;
+          rdfs:comment "Indicates to which local IM Accounts this IMAccount publishes presence to" ;
+          rdfs:domain nco:IMAccount ;
+          rdfs:label "publishesPresenceTo" ;
+          rdfs:range nco:IMAccount .
+
+          telepathy:requestedSubscriptionTo
+     a rdf:Property ;
+          rdfs:comment "Indicates to which local IM Accounts this IMAccount requested subscription to" ;
+          rdfs:domain nco:IMAccount ;
+          rdfs:label "requestedSubscriptionTo" ;
+          rdfs:range nco:IMAccount .
 }
 
 <http://nepomuk.kde.org/ontologies/2009/06/20/telepathy/metadata>
diff --git a/kpeople/nepomuk-feeder/telepathyaccount.cpp b/kpeople/nepomuk-feeder/telepathyaccount.cpp
index 1a0e093..a6a084b 100644
--- a/kpeople/nepomuk-feeder/telepathyaccount.cpp
+++ b/kpeople/nepomuk-feeder/telepathyaccount.cpp
@@ -246,12 +246,15 @@ void TelepathyAccount::onConnectionReady(Tp::PendingOperation *op)
              << Tp::Contact::FeatureAvatarToken;
 
     // Handle contact avatars here, by using AvatarsInterface
-    connect(m_connection.data()->avatarsInterface(),
+    connect(m_connection->avatarsInterface(),
             SIGNAL(AvatarRetrieved(uint,QString,QByteArray,QString)),
             SLOT(onContactAvatarRetrieved(uint,QString,QByteArray,QString)));
-    connect(m_connection.data()->avatarsInterface(),
+    connect(m_connection->avatarsInterface(),
             SIGNAL(AvatarUpdated(uint,QString)),
             SLOT(onContactAvatarUpdated(uint,QString)));
+    connect(m_connection->contactManager(),
+            SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts)),
+            SLOT(onAllKnownContactsChanged(Tp::Contacts,Tp::Contacts)));
 
     // Retrieve contacts
     connect(m_connection->contactManager()->upgradeContacts(contacts.toList(), features),
@@ -301,7 +304,7 @@ void TelepathyAccount::onContactsUpgraded(Tp::PendingOperation* op)
         kDebug() << "Pulling avatars";
         // Ok, pull the avatars here
         QDBusPendingReply< Tp::AvatarTokenMap > reply =
-            m_connection.data()->avatarsInterface()->GetKnownAvatarTokens(avatarsToRetrieve);
+            m_connection->avatarsInterface()->GetKnownAvatarTokens(avatarsToRetrieve);
 
         reply.waitForFinished();
         if (!reply.value().isEmpty()) {
@@ -354,7 +357,7 @@ void TelepathyAccount::onContactAvatarRetrieved(uint contact, const QString& tok
 {
     kDebug() << "Avatar retrieved" << contact << token;
     // Retrieve the contact
-    Tp::ContactPtr tpContact = m_connection.data()->contactManager()->lookupContactByHandle(contact);
+    Tp::ContactPtr tpContact = m_connection->contactManager()->lookupContactByHandle(contact);
 
     // Set the avatar
     TelepathyContact *telepathyContact = m_contacts[tpContact];
@@ -367,7 +370,7 @@ void TelepathyAccount::onContactAvatarRetrieved(uint contact, const QString& tok
 void TelepathyAccount::onContactAvatarUpdated(uint contact, const QString& token)
 {
     kDebug() << "Avatar updated" << token << contact;
-    Tp::ContactPtr tpContact = m_connection.data()->contactManager()->lookupContactByHandle(contact);
+    Tp::ContactPtr tpContact = m_connection->contactManager()->lookupContactByHandle(contact);
 
     // Now we need to check if we need to update the avatar
     TelepathyContact *telepathyContact = m_contacts[tpContact];
@@ -377,7 +380,8 @@ void TelepathyAccount::onContactAvatarUpdated(uint contact, const QString& token
         if (telepathyContact->avatarToken() != token) {
             kDebug() << "retrieve";
             // We do
-            QDBusPendingReply<void> reply = m_connection.data()->avatarsInterface()->RequestAvatars(tpContact->handle().toList());
+            QDBusPendingReply< void > reply =
+                m_connection->avatarsInterface()->RequestAvatars(tpContact->handle().toList());
             if (reply.error().type() != QDBusError::NoError) {
                 // TODO: What to do in case of error?
             }
@@ -392,6 +396,56 @@ void TelepathyAccount::onContactDestroyed(const Tp::ContactPtr &contact)
     }
 }
 
+void TelepathyAccount::onAllKnownContactsChanged(const Tp::Contacts& added, const Tp::Contacts& removed)
+{
+    // For each added contact, let's check if we need to add it to our roster.
+    Tp::Contacts realAdded;
+    foreach (const Tp::ContactPtr &contact, added) {
+        if (!m_contacts.contains(contact)) {
+            // It's a brand new one
+            realAdded << contact;
+        }
+    }
+
+    // Any contacts to actually add?
+    if (!realAdded.isEmpty()) {
+        kDebug() << "Some contacts have been added for real";
+        // Yes: let's upgrade them and let our usual handler handle the creation and everything else
+        QSet<Tp::Contact::Feature> features;
+        features << Tp::Contact::FeatureAlias
+                 << Tp::Contact::FeatureSimplePresence
+                 << Tp::Contact::FeatureAvatarToken;
+
+        // Retrieve contacts
+        connect(m_connection->contactManager()->upgradeContacts(realAdded.toList(), features),
+                SIGNAL(finished(Tp::PendingOperation*)),
+                SLOT(onContactsUpgraded(Tp::PendingOperation*)));
+    }
+
+    // Ok, now removals. Let's check again what we have and what we do not have
+    Tp::Contacts realRemoved;
+    foreach (const Tp::ContactPtr &contact, removed) {
+        if (m_contacts.contains(contact)) {
+            // It's been removed for real
+            realRemoved << contact;
+        }
+    }
+
+    // So, any real removals?
+    if (!realRemoved.isEmpty()) {
+        // Yes: take action.
+        kDebug() << "Some contacts have been removed for real";
+        foreach (const Tp::ContactPtr &contact, realRemoved) {
+            // The subscription state changed signal triggered in the contact should have already updated
+            // buddy properties. Here, instead:
+            // Remove it from our "cache" hash
+            m_contacts.remove(contact);
+            // Free the contact itself
+            contact->deleteLater();
+        }
+    }
+}
+
 
 #include "telepathyaccount.moc"
 
diff --git a/kpeople/nepomuk-feeder/telepathyaccount.h b/kpeople/nepomuk-feeder/telepathyaccount.h
index 29f39f4..9e331b6 100644
--- a/kpeople/nepomuk-feeder/telepathyaccount.h
+++ b/kpeople/nepomuk-feeder/telepathyaccount.h
@@ -64,6 +64,7 @@ private Q_SLOTS:
     void onContactAvatarRetrieved(uint contact, const QString &token, const QByteArray &avatar, const QString &mimetype);
     void onContactAvatarUpdated(uint contact, const QString &token);
     void onContactDestroyed(const Tp::ContactPtr &contact);
+    void onAllKnownContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed);
 
 private:
     Q_DISABLE_COPY(TelepathyAccount);
diff --git a/kpeople/nepomuk-feeder/telepathycontact.cpp b/kpeople/nepomuk-feeder/telepathycontact.cpp
index 8c9d16e..ed52e11 100644
--- a/kpeople/nepomuk-feeder/telepathycontact.cpp
+++ b/kpeople/nepomuk-feeder/telepathycontact.cpp
@@ -72,10 +72,25 @@ TelepathyContact::TelepathyContact(Tp::ContactPtr contact,
     connect(m_contact.data(),
             SIGNAL(removedFromGroup(QString)),
             SLOT(onRemovedFromGroup(QString)));
+    // Watch over his subscription, publication and block status
+    connect(m_contact.data(),
+            SIGNAL(subscriptionStateChanged(Tp::Contact::PresenceState)),
+            SLOT(onSubscriptionStateChanged(Tp::Contact::PresenceState)));
+    connect(m_contact.data(),
+            SIGNAL(publishStateChanged(Tp::Contact::PresenceState)),
+            SLOT(onPublishStateChanged(Tp::Contact::PresenceState)));
+    connect(m_contact.data(),
+            SIGNAL(blockStatusChanged(bool)),
+            SLOT(onBlockStatusChanged(bool)));
     // FIXME: Connect to any other signals of sync-worthy properties here.
 
     // Find the Nepomuk resource for this contact, or create a new one if necessary.
     doNepomukSetup();
+
+    // Take the needed action for the current presence/subscription/block state
+    onPublishStateChanged(m_contact->publishState());
+    onSubscriptionStateChanged(m_contact->subscriptionState());
+    onBlockStatusChanged(m_contact->isBlocked());
 }
 
 TelepathyContact::~TelepathyContact()
@@ -155,8 +170,6 @@ void TelepathyContact::doNepomukSetup()
 
         m_contactIMAccountResource.addProperty(Nepomuk::Vocabulary::NCO::imID(),
                                                m_contact->id());
-        m_contactIMAccountResource.addProperty(Nepomuk::Vocabulary::Telepathy::isBuddyOf(),
-                                               m_accountResource);
         m_contactIMAccountResource.addProperty(Nepomuk::Vocabulary::NCO::imNickname(),
                                                m_contact->alias());
         m_contactIMAccountResource.addProperty(Nepomuk::Vocabulary::NCO::imStatus(),
@@ -196,6 +209,7 @@ void TelepathyContact::onPresenceChanged(const QString& status, uint type, const
 
 void TelepathyContact::onAddedToGroup(const QString &group)
 {
+    kDebug() << "On added to group " << group;
     // Only update the properties if we already have the contactIMAccountResource.
     if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
 
@@ -203,6 +217,7 @@ void TelepathyContact::onAddedToGroup(const QString &group)
         foreach(Nepomuk::ContactGroup g, m_contactPersonContactResource.belongsToGroups()) {
             if (g.contactGroupName() == group) {
                 // Already in that group
+                kDebug() << "Already in that group " << group;
                 return;
             }
         }
@@ -227,12 +242,14 @@ void TelepathyContact::onAddedToGroup(const QString &group)
         }
 
         // Add the contact to the group.
+        kDebug() << "Added to " << group;
         m_contactPersonContactResource.addBelongsToGroup(groupResource);
     }
 }
 
 void TelepathyContact::onRemovedFromGroup(const QString &group)
 {
+    kDebug() << "On removed from group " << group;
     // Only update the properties if we already have the contactIMAccountResource.
     if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
 
@@ -247,6 +264,8 @@ void TelepathyContact::onRemovedFromGroup(const QString &group)
             }
         }
 
+        kDebug() << "Setting groups to " << newGroups;
+
         m_contactPersonContactResource.setBelongsToGroups(newGroups);
     }
 }
@@ -279,7 +298,138 @@ void TelepathyContact::setAvatar(const QString& token, const QByteArray& data)
     }
 }
 
+void TelepathyContact::onBlockStatusChanged(bool blocked)
+{
+    // Only update the properties if we already have the contactIMAccountResource.
+    if (!m_contactPersonContactResource.resourceUri().isEmpty()) {
+        if (m_contactIMAccountResource.isBlockeds().isEmpty()) {
+            // Add the property
+            m_contactIMAccountResource.setProperty(Nepomuk::Vocabulary::Telepathy::isBlocked(),
+                                                   blocked);
+        }
+
+        if (blocked != m_contactIMAccountResource.isBlockeds().first()) {
+            m_contactIMAccountResource.setProperty(Nepomuk::Vocabulary::Telepathy::isBlocked(),
+                                                   blocked);
+        }
+    }
+}
 
+void TelepathyContact::onPublishStateChanged(Tp::Contact::PresenceState state)
+{
+    Q_UNUSED(state)
+    kDebug() << "Publication changed!";
+    switch (state) {
+        case Tp::Contact::PresenceStateYes:
+            // We can now see the contact's presence
+
+            // Only update the properties if we already have the contactIMAccountResource.
+            if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
+                // If we're not yet isBuddyOf, let's become one.
+                if (!m_contactIMAccountResource.publishesPresenceTos().contains(m_accountResource)) {
+                    kDebug() << "We're not yet publishing presence to the account";
+                    m_contactIMAccountResource.addPublishesPresenceTo(m_accountResource);
+                }
+            }
+            kDebug() << "State yes, now it publishes to " << m_contactIMAccountResource.publishesPresenceTos();
+
+            break;
+        case Tp::Contact::PresenceStateNo:
+            // We can no longer see his presence
+
+            // Only update the properties if we already have the contactIMAccountResource.
+            if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
+                // Remove the publishesPresenceTo property
+                if (m_contactIMAccountResource.publishesPresenceTos().contains(m_accountResource)) {
+                    // FIXME: The correct code should be:
+                    // m_contactIMAccountResource.removeProperty(Nepomuk::Vocabulary::Telepathy::publishesPresenceTo(),
+                    //                                           m_accountResource);
+                    // but it does not work
+                    m_contactIMAccountResource.removeProperty(Nepomuk::Vocabulary::Telepathy::publishesPresenceTo());
+                }
+            }
+            kDebug() << "State no, now it publishes to " << m_contactIMAccountResource.publishesPresenceTos();
+
+            break;
+        case Tp::Contact::PresenceStateAsk:
+            // Do nothing here
+            break;
+    }
+}
+
+void TelepathyContact::onSubscriptionStateChanged(Tp::Contact::PresenceState state)
+{
+    kDebug() << "Subscription changed!";
+    using namespace Nepomuk::Vocabulary;
+    switch (state) {
+        case Tp::Contact::PresenceStateYes:
+            // We are now subscribed.
+
+            // Only update the properties if we already have the contactIMAccountResource.
+            if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
+                // If we're not yet isBuddyOf, let's become one.
+                if (!m_contactIMAccountResource.isBuddyOfs().contains(m_accountResource)) {
+                    kDebug() << "We're not yet buddies with the account";
+                    m_contactIMAccountResource.addIsBuddyOf(m_accountResource);
+                }
+                // If there was a request, clear it
+                if (m_contactIMAccountResource.requestedSubscriptionTos().contains(m_accountResource)) {
+                    // Remove the publishesPresenceTo property
+                    // FIXME: The correct code should be:
+                    // m_contactIMAccountResource.removeProperty(Telepathy::requestedSubscriptionTo(),
+                    //                                           m_accountResource);
+                    // but it does not work
+                    m_contactIMAccountResource.removeProperty(Telepathy::requestedSubscriptionTo());
+                }
+            }
+            kDebug() << "State yes, now it's buddy of " << m_contactIMAccountResource.isBuddyOfs();
+
+            break;
+        case Tp::Contact::PresenceStateNo:
+            // We are no longer subscribed. This means the user explicitely requested to clear
+            // the contact from his buddy list. Let's do it then.
+
+            // Only update the properties if we already have the contactIMAccountResource.
+            if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
+                // Remove the isBuddyOf property, which will magically clear out the contact from our list
+                if (m_contactIMAccountResource.isBuddyOfs().contains(m_accountResource)) {
+                    // FIXME: The correct code should be:
+                    // m_contactIMAccountResource.removeProperty(Telepathy::isBuddyOf(),
+                    //                                           m_accountResource);
+                    // but it does not work
+                    m_contactIMAccountResource.removeProperty(Telepathy::isBuddyOf());
+                }
+
+                // If there was a request, clear it
+                if (m_contactIMAccountResource.requestedSubscriptionTos().contains(m_accountResource)) {
+                    // Remove the publishesPresenceTo property
+                    // FIXME: The correct code should be:
+                    // m_contactIMAccountResource.removeProperty(Telepathy::requestedSubscriptionTo(),
+                    //                                           m_accountResource);
+                    // but it does not work
+                    m_contactIMAccountResource.removeProperty(Telepathy::requestedSubscriptionTo());
+                }
+            }
+            kDebug() << "State no, now it's buddy of " << m_contactIMAccountResource.isBuddyOfs();
+
+            break;
+        case Tp::Contact::PresenceStateAsk:
+            // The contact asked to subscribe to us
+
+             // Only update the properties if we already have the contactIMAccountResource.
+            if (!m_contactIMAccountResource.resourceUri().isEmpty()) {
+                // If there was a request, clear it
+                if (!m_contactIMAccountResource.requestedSubscriptionTos().contains(m_accountResource)) {
+                    // Add the request
+                    m_contactIMAccountResource.addRequestedSubscriptionTo(m_accountResource);
+                }
+            }
+            kDebug() << "State ask, now it has requests towards "
+                     << m_contactIMAccountResource.requestedSubscriptionTos();
+
+            break;
+    }
+}
 
 #include "telepathycontact.moc"
 
diff --git a/kpeople/nepomuk-feeder/telepathycontact.h b/kpeople/nepomuk-feeder/telepathycontact.h
index 6d5ec52..2fa5725 100644
--- a/kpeople/nepomuk-feeder/telepathycontact.h
+++ b/kpeople/nepomuk-feeder/telepathycontact.h
@@ -57,6 +57,9 @@ private Q_SLOTS:
     void onPresenceChanged(const QString &status, uint type, const QString &message);
     void onAddedToGroup(const QString &group);
     void onRemovedFromGroup(const QString &group);
+    void onBlockStatusChanged(bool blocked);
+    void onPublishStateChanged(Tp::Contact::PresenceState state);
+    void onSubscriptionStateChanged(Tp::Contact::PresenceState state);
 
 private:
     Q_DISABLE_COPY(TelepathyContact);
@@ -66,6 +69,7 @@ private:
     TelepathyAccount *m_parent;
     Tp::ContactPtr m_contact;
     Tp::ConnectionPtr m_connection;
+
     Nepomuk::IMAccount m_accountResource;
     Nepomuk::IMAccount m_contactIMAccountResource;
     Nepomuk::PersonContact m_contactPersonContactResource;

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list