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


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

The following commit has been merged in the master branch:
commit 19cd91ea71d4306912d421c34351fe26dc9ff1b2
Author: Dario Freddi <drf at kde.org>
Date:   Sat Mar 27 13:20:39 2010 +0000

    Add avatar support to tp-integration-daemon (MR #3408)
    
    svn path=/trunk/playground/network/telepathy-integration-daemon/; revision=1107995
---
 kpeople/nepomuk-feeder/telepathy.trig       |   7 ++
 kpeople/nepomuk-feeder/telepathyaccount.cpp | 115 ++++++++++++++++++++++++++--
 kpeople/nepomuk-feeder/telepathyaccount.h   |   8 ++
 kpeople/nepomuk-feeder/telepathycontact.cpp |  32 ++++++++
 kpeople/nepomuk-feeder/telepathycontact.h   |   3 +
 5 files changed, 160 insertions(+), 5 deletions(-)

diff --git a/kpeople/nepomuk-feeder/telepathy.trig b/kpeople/nepomuk-feeder/telepathy.trig
index db4d327..e001b1a 100644
--- a/kpeople/nepomuk-feeder/telepathy.trig
+++ b/kpeople/nepomuk-feeder/telepathy.trig
@@ -27,6 +27,13 @@ telepathy: {telepathy:accountIdentifier
           rdfs:domain nco:IMAccount ;
           rdfs:label "isBuddyOf" ;
           rdfs:range nco:IMAccount .
+
+          telepathy:avatarToken
+     a rdf:Property ;
+          rdfs:comment "The current avatar token for the nco:photo of this contact";
+          rdfs:domain nco:Contact ;
+          rdfs:label "avatarToken" ;
+          rdfs:range xsd:string .
 }
 
 <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 4990651..094d14c 100644
--- a/kpeople/nepomuk-feeder/telepathyaccount.cpp
+++ b/kpeople/nepomuk-feeder/telepathyaccount.cpp
@@ -28,10 +28,14 @@
 #include "nco.h"
 #include "telepathy.h"
 
+#include <informationelement.h>
+#include <dataobject.h>
+
 #include <KDebug>
 
 #include <Nepomuk/ResourceManager>
 #include <Nepomuk/Variant>
+#include <Nepomuk/Resource>
 
 #include <Soprano/Model>
 #include <Soprano/QueryResultIterator>
@@ -53,7 +57,8 @@ TelepathyAccount::TelepathyAccount(const QString &path, TelepathyAccountMonitor
 
     Tp::Features features;
     features << Tp::Account::FeatureCore
-             << Tp::Account::FeatureProtocolInfo;
+             << Tp::Account::FeatureProtocolInfo
+             << Tp::Account::FeatureAvatar;
 
     connect(m_account->becomeReady(features),
             SIGNAL(finished(Tp::PendingOperation*)),
@@ -66,6 +71,9 @@ TelepathyAccount::TelepathyAccount(const QString &path, TelepathyAccountMonitor
     connect(m_account.data(),
             SIGNAL(currentPresenceChanged(Tp::SimplePresence)),
             SLOT(onCurrentPresenceChanged(Tp::SimplePresence)));
+    connect(m_account.data(),
+            SIGNAL(avatarChanged(Tp::Avatar)),
+            SLOT(onAvatarChanged(Tp::Avatar)));
             // ...... and any other properties we want to sync...
 }
 
@@ -168,8 +176,15 @@ void TelepathyAccount::doNepomukSetup()
         m_accountResource.addProperty(Nepomuk::Vocabulary::Telepathy::accountIdentifier(),
                                       m_path);
 
+        Nepomuk::InformationElement photo;
+        photo.setPlainTextContents(QStringList() << m_account->avatar().avatarData.toBase64());
+        Nepomuk::DataObject dataObject(m_accountResource);
+        dataObject.addInterpretedAs(photo);
+        m_accountResource.addProperty(Nepomuk::Vocabulary::NCO::photo(),
+                                      dataObject);
+
         mePersonContact.addProperty(Nepomuk::Vocabulary::NCO::hasIMAccount(),
-                                    m_accountResource);
+                                     m_accountResource);
     }
 
     // Check if the account already has a connection, and
@@ -227,8 +242,18 @@ void TelepathyAccount::onConnectionReady(Tp::PendingOperation *op)
 
     QSet<Tp::Contact::Feature> features;
     features << Tp::Contact::FeatureAlias
-             << Tp::Contact::FeatureSimplePresence;
-
+             << Tp::Contact::FeatureSimplePresence
+             << Tp::Contact::FeatureAvatarToken;
+
+    // Handle contact avatars here, by using AvatarsInterface
+    connect(m_connection.data()->avatarsInterface(),
+            SIGNAL(AvatarRetrieved(uint,QString,QByteArray,QString)),
+            SLOT(onContactAvatarRetrieved(uint,QString,QByteArray,QString)));
+    connect(m_connection.data()->avatarsInterface(),
+            SIGNAL(AvatarUpdated(uint,QString)),
+            SLOT(onContactAvatarUpdated(uint,QString)));
+
+    // Retrieve contacts
     connect(m_connection->contactManager()->upgradeContacts(contacts.toList(), features),
             SIGNAL(finished(Tp::PendingOperation*)),
             SLOT(onContactsUpgraded(Tp::PendingOperation*)));
@@ -252,8 +277,34 @@ void TelepathyAccount::onContactsUpgraded(Tp::PendingOperation* op)
 
     // We have an upgraded contact list. Now we can create a TelepathyContact instance for
     // each contact.
+    // We also keep tracks of handles to do avatar retrieval (if needed)
+    Tp::UIntList avatarsToRetrieve;
     foreach (Tp::ContactPtr contact, pc->contacts()) {
-        new TelepathyContact(contact, m_connection, m_accountResource, this);
+        TelepathyContact *tpcontact = new TelepathyContact(contact, m_connection, m_accountResource, this);
+        m_contacts.insert(contact, tpcontact);
+        if (tpcontact->avatarToken().isEmpty()) {
+            // We totally need to retrieve the avatar
+            avatarsToRetrieve << contact->handle().toList();
+        } else {
+            kDebug() << "Our contact already has the avatar " << tpcontact->avatarToken();
+        }
+    }
+
+    if (!avatarsToRetrieve.isEmpty()) {
+        kDebug() << "Pulling avatars";
+        // Ok, pull the avatars here
+        QDBusPendingReply< Tp::AvatarTokenMap > reply =
+            m_connection.data()->avatarsInterface()->GetKnownAvatarTokens(avatarsToRetrieve);
+
+        reply.waitForFinished();
+        if (!reply.value().isEmpty()) {
+            Tp::AvatarTokenMap result = reply.value();
+            for (Tp::AvatarTokenMap::const_iterator i = result.constBegin(); i != result.constEnd(); ++i) {
+                if (!i.value().isEmpty()) {
+                    onContactAvatarUpdated(i.key(), i.value());
+                }
+            }
+        }
     }
 }
 
@@ -279,6 +330,60 @@ void TelepathyAccount::onCurrentPresenceChanged(Tp::SimplePresence presence)
     }
 }
 
+void TelepathyAccount::onAvatarChanged(const Tp::Avatar& avatar)
+{
+    // Do not update any property on the account resource if it hasn't yet been created.
+    if (!m_accountResource.uri().isEmpty()) {
+        // Store avatarData only. QImage will take care of determining the mimetype.
+        Nepomuk::InformationElement photo;
+        photo.setPlainTextContents(QStringList() << avatar.avatarData.toBase64());
+        Nepomuk::DataObject dataObject(m_accountResource);
+        dataObject.addInterpretedAs(photo);
+        m_accountResource.setProperty(Nepomuk::Vocabulary::NCO::photo(),
+                                      dataObject);
+    }
+}
+void TelepathyAccount::onContactAvatarRetrieved(uint contact, const QString& token, const QByteArray& avatar, const QString&)
+{
+    kDebug() << "Avatar retrieved" << contact << token;
+    // Retrieve the contact
+    Tp::ContactPtr tpContact = m_connection.data()->contactManager()->lookupContactByHandle(contact);
+
+    // Set the avatar
+    TelepathyContact *telepathyContact = m_contacts[tpContact];
+    if (telepathyContact) {
+        // Match. Let's set the avatar then
+        telepathyContact->setAvatar(token, avatar);
+    }
+}
+
+void TelepathyAccount::onContactAvatarUpdated(uint contact, const QString& token)
+{
+    kDebug() << "Avatar updated" << token << contact;
+    Tp::ContactPtr tpContact = m_connection.data()->contactManager()->lookupContactByHandle(contact);
+
+    // Now we need to check if we need to update the avatar
+    TelepathyContact *telepathyContact = m_contacts[tpContact];
+    if (telepathyContact) {
+        kDebug() << "match";
+        // Match. Now check if we need to retrieve the avatar
+        if (telepathyContact->avatarToken() != token) {
+            kDebug() << "retrieve";
+            // We do
+            QDBusPendingReply<void> reply = m_connection.data()->avatarsInterface()->RequestAvatars(tpContact->handle().toList());
+            if (reply.error().type() != QDBusError::NoError) {
+                // TODO: What to do in case of error?
+            }
+        }
+    }
+}
+
+void TelepathyAccount::removeContact(const Tp::ContactPtr &contact)
+{
+    if (!contact.isNull()) {
+        m_contacts.remove(contact);
+    }
+}
 
 #include "telepathyaccount.moc"
 
diff --git a/kpeople/nepomuk-feeder/telepathyaccount.h b/kpeople/nepomuk-feeder/telepathyaccount.h
index cb577f7..dd73b18 100644
--- a/kpeople/nepomuk-feeder/telepathyaccount.h
+++ b/kpeople/nepomuk-feeder/telepathyaccount.h
@@ -31,6 +31,7 @@
 #include <TelepathyQt4/Account>
 #include <TelepathyQt4/Connection>
 
+class TelepathyContact;
 class KJob;
 class TelepathyAccountMonitor;
 
@@ -52,6 +53,8 @@ public:
     explicit TelepathyAccount(const QString &path, TelepathyAccountMonitor *parent = 0);
     ~TelepathyAccount();
 
+    void removeContact(const Tp::ContactPtr &contact);
+
 private Q_SLOTS:
     void onAccountReady(Tp::PendingOperation *op);
     void onHaveConnectionChanged(bool haveConnection);
@@ -59,6 +62,9 @@ private Q_SLOTS:
     void onNicknameChanged(const QString &nickname);
     void onCurrentPresenceChanged(Tp::SimplePresence presence);
     void onContactsUpgraded(Tp::PendingOperation *op);
+    void onAvatarChanged(const Tp::Avatar &avatar);
+    void onContactAvatarRetrieved(uint contact, const QString &token, const QByteArray &avatar, const QString &mimetype);
+    void onContactAvatarUpdated(uint contact, const QString &token);
 
 private:
     Q_DISABLE_COPY(TelepathyAccount);
@@ -72,6 +78,8 @@ private:
     Nepomuk::IMAccount m_accountResource;
     Tp::ConnectionPtr m_connection;
     QString m_path;
+
+    QHash< Tp::ContactPtr, TelepathyContact* > m_contacts;
 };
 
 
diff --git a/kpeople/nepomuk-feeder/telepathycontact.cpp b/kpeople/nepomuk-feeder/telepathycontact.cpp
index 82ba734..0a36aaf 100644
--- a/kpeople/nepomuk-feeder/telepathycontact.cpp
+++ b/kpeople/nepomuk-feeder/telepathycontact.cpp
@@ -29,6 +29,7 @@
 
 // Full Resource Classes
 #include "contactgroup.h"
+#include "dataobject.h"
 
 #include <KDebug>
 
@@ -79,6 +80,8 @@ TelepathyContact::TelepathyContact(Tp::ContactPtr contact,
 
 TelepathyContact::~TelepathyContact()
 {
+    // Remove from cache
+    m_parent->removeContact(m_contact);
     kDebug();
 }
 
@@ -240,6 +243,35 @@ void TelepathyContact::onRemovedFromGroup(const QString &group)
     }
 }
 
+QString TelepathyContact::avatarToken() const
+{
+    // Only check the properties if we already have the contactPersonAccountResource.
+    if (!m_contactPersonContactResource.resourceUri().isEmpty()) {
+        // Return the stored token
+        return m_contactPersonContactResource.property(Nepomuk::Vocabulary::Telepathy::avatarToken()).toString();
+    }
+
+    kDebug() << "Resource URI empty";
+    return QString::null;
+}
+
+void TelepathyContact::setAvatar(const QString& token, const QByteArray& data)
+{
+    kDebug() << "Storing avatar for " << token << m_contact.data();
+    // Only update the properties if we already have the contactIMAccountResource.
+    if (!m_contactPersonContactResource.resourceUri().isEmpty()) {
+        // Add token...
+        m_contactPersonContactResource.setAvatarTokens(QStringList() << token);
+        // .. and the data itself
+        Nepomuk::InformationElement photo;
+        photo.setPlainTextContents(QStringList() << data.toBase64());
+        Nepomuk::DataObject dataObject(m_contactPersonContactResource);
+        dataObject.addInterpretedAs(photo);
+        m_contactPersonContactResource.setPhotos(QList<Nepomuk::DataObject>() << dataObject);
+    }
+}
+
+
 
 #include "telepathycontact.moc"
 
diff --git a/kpeople/nepomuk-feeder/telepathycontact.h b/kpeople/nepomuk-feeder/telepathycontact.h
index 383cb49..9710754 100644
--- a/kpeople/nepomuk-feeder/telepathycontact.h
+++ b/kpeople/nepomuk-feeder/telepathycontact.h
@@ -46,6 +46,9 @@ public:
                               TelepathyAccount *parent = 0);
     ~TelepathyContact();
 
+    QString avatarToken() const;
+    void setAvatar(const QString &token, const QByteArray &data);
+
 private Q_SLOTS:
     void onAliasChanged(const QString &alias);
     void onPresenceChanged(const QString &status, uint type, const QString &message);

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list