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


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

The following commit has been merged in the master branch:
commit e9d7007f184bba5cd37e06edac59d7dffdbf93b4
Author: Martin Klapetek <martin.klapetek at gmail.com>
Date:   Wed Mar 20 20:54:51 2013 +0100

    Rewrite avatarPixmap() to use pixmap cache, simplifies code
    
    The previous code stored things in pixmap cache but didn't really load
    them. This stores all avatars in pixmap cache and first checks if the
    cache has avatar for us, only if not proceeds to actually load things.
    
    REVIEW: 109563
    BUG: 316743
---
 KTp/contact.cpp | 55 ++++++++++++++++++++++++++++++++++---------------------
 KTp/contact.h   |  7 +++++--
 2 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/KTp/contact.cpp b/KTp/contact.cpp
index 33ab04f..4fa37d5 100644
--- a/KTp/contact.cpp
+++ b/KTp/contact.cpp
@@ -39,6 +39,8 @@ KTp::Contact::Contact(Tp::ContactManager *manager, const Tp::ReferencedHandles &
 {
     connect(manager->connection().data(), SIGNAL(destroyed()), SIGNAL(invalidated()));
     connect(manager->connection().data(), SIGNAL(invalidated(Tp::DBusProxy*,QString,QString)), SIGNAL(invalidated()));
+    connect(this, SIGNAL(avatarTokenChanged(QString)), SLOT(invalidateAvatarCache()));
+    connect(this, SIGNAL(avatarDataChanged(Tp::AvatarData)), SLOT(invalidateAvatarCache()));
 }
 
 KTp::Presence KTp::Contact::presence() const
@@ -107,31 +109,36 @@ QStringList KTp::Contact::clientTypes() const
 QPixmap KTp::Contact::avatarPixmap()
 {
     QPixmap avatar;
-    QString file = avatarData().fileName;
-    QString avatarToken;
 
-    //if the user is offline, look into the cache for avatar
-    if (file.isEmpty() && presence().type() == Tp::ConnectionPresenceTypeOffline) {
-        KConfig config(QLatin1String("ktelepathy-avatarsrc"));
-        KConfigGroup avatarTokenGroup = config.group(id());
-        avatarToken = avatarTokenGroup.readEntry(QLatin1String("avatarToken"));
-
-        if (!avatarToken.isEmpty()) {
-            avatar.load(buildAvatarPath(avatarToken));
+    //check pixmap cache for the avatar, if not present, load the avatar
+    if (!QPixmapCache::find(keyCache(), avatar)){
+        QString file = avatarData().fileName;
+
+        //if contact does not provide path, let's see if we have avatar for the stored token
+        if (file.isEmpty()) {
+            KConfig config(QLatin1String("ktelepathy-avatarsrc"));
+            KConfigGroup avatarTokenGroup = config.group(id());
+            QString avatarToken = avatarTokenGroup.readEntry(QLatin1String("avatarToken"));
+            //only bother loading the pixmap if the token is not empty
+            if (!avatarToken.isEmpty()) {
+                avatar.load(buildAvatarPath(avatarToken));
+            }
+        } else {
+            avatar.load(file);
         }
-    } else {
-        avatar.load(file);
-    }
 
-    if (avatar.isNull()) {
-        avatar = KIconLoader::global()->loadIcon(QLatin1String("im-user"), KIconLoader::NoGroup, 96);
-    }
+        //if neither above succeeded, we need to load the icon
+        if (avatar.isNull()) {
+            avatar = KIconLoader::global()->loadIcon(QLatin1String("im-user"), KIconLoader::NoGroup, 96);
+        }
 
-    if (presence().type() == Tp::ConnectionPresenceTypeOffline) {
-        if (!QPixmapCache::find(keyCache(avatarToken),avatar)){
+        //if the contact is offline, gray it out
+        if (presence().type() == Tp::ConnectionPresenceTypeOffline) {
             avatarToGray(avatar);
-            QPixmapCache::insert(keyCache(avatarToken), avatar);
         }
+
+        //insert the contact into pixmap cache for faster lookup
+        QPixmapCache::insert(keyCache(), avatar);
     }
 
     return avatar;
@@ -151,9 +158,9 @@ void KTp::Contact::avatarToGray(QPixmap &avatar)
     avatar.setAlphaChannel(alpha);
 }
 
-QString KTp::Contact::keyCache(const QString &avatarToken) const
+QString KTp::Contact::keyCache() const
 {
-    return avatarToken+QLatin1String("-offline");
+    return id() + (presence().type() == Tp::ConnectionPresenceTypeOffline ? QLatin1String("-offline") : QLatin1String("-online"));
 }
 
 QString KTp::Contact::buildAvatarPath(const QString &avatarToken)
@@ -179,3 +186,9 @@ QString KTp::Contact::buildAvatarPath(const QString &avatarToken)
 
     return avatarFileName;
 }
+
+void KTp::Contact::invalidateAvatarCache()
+{
+    QPixmapCache::remove(id() + QLatin1String("-offline"));
+    QPixmapCache::remove(id() + QLatin1String("-online"));
+}
diff --git a/KTp/contact.h b/KTp/contact.h
index 5eea8c1..7173686 100644
--- a/KTp/contact.h
+++ b/KTp/contact.h
@@ -48,11 +48,14 @@ public:
      QPixmap avatarPixmap();
 
 Q_SIGNALS:
-     void invalidated();
+    void invalidated();
+
+private Q_SLOTS:
+    void invalidateAvatarCache();
 
 private:
     void avatarToGray(QPixmap &avatar);
-    QString keyCache(const QString &avatarHash) const;
+    QString keyCache() const;
     QString buildAvatarPath(const QString &avatarToken);
 
 };

-- 
ktp-common-internals packaging



More information about the pkg-kde-commits mailing list