[Pkg-owncloud-commits] [owncloud-client] 33/159: Themes: Cache icons instead of rebuilding a lot.

Sandro Knauß hefee-guest at moszumanska.debian.org
Fri May 1 13:05:19 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit a9a24c96fc0195ef8017284bf729b8554464501a
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Wed Mar 25 14:57:23 2015 +0100

    Themes: Cache icons instead of rebuilding a lot.
---
 src/libsync/theme.cpp | 18 +++++++++++-------
 src/libsync/theme.h   |  2 +-
 2 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/libsync/theme.cpp b/src/libsync/theme.cpp
index 6483e90..3a78497 100644
--- a/src/libsync/theme.cpp
+++ b/src/libsync/theme.cpp
@@ -122,11 +122,14 @@ QIcon Theme::themeIcon( const QString& name, bool sysTray ) const
         flavor = QLatin1String("colored");
     }
 
-    QIcon icon;
     if( QIcon::hasThemeIcon( name )) {
         // use from theme
-        icon = QIcon::fromTheme( name );
-    } else {
+        return QIcon::fromTheme( name );
+    }
+
+    QString key = name + "," + flavor;
+    QIcon & cached = _iconCache[key];
+    if (cached.isNull()) {
         QList<int> sizes;
         sizes <<16 << 22 << 32 << 48 << 64 << 128 << 256;
         foreach (int size, sizes) {
@@ -140,19 +143,20 @@ QIcon Theme::themeIcon( const QString& name, bool sysTray ) const
                     p.setPen(QColor("#dfdbd2"));
                     p.drawPixmap(px.rect(), mask, mask.rect());
                 }
-                icon.addPixmap(px);
+                cached.addPixmap(px);
             }
         }
-        if (icon.isNull()) {
+        if (cached.isNull()) {
             foreach (int size, sizes) {
                 QString pixmapName = QString::fromLatin1(":/client/resources/%1-%2.png").arg(name).arg(size);
                 if (QFile::exists(pixmapName)) {
-                    icon.addFile(pixmapName);
+                    cached.addFile(pixmapName);
                 }
             }
         }
     }
-    return icon;
+
+    return cached;
 }
 
 QString Theme::hidpiFileName(const QString &fileName, QPaintDevice *dev)
diff --git a/src/libsync/theme.h b/src/libsync/theme.h
index 061060e..7974b76 100644
--- a/src/libsync/theme.h
+++ b/src/libsync/theme.h
@@ -208,7 +208,7 @@ private:
 
     static Theme* _instance;
     bool _mono;
-
+    mutable QHash<QString, QIcon> _iconCache;
 };
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list