optimize a bit the code related to obtaining current icon theme
authormishas <mikhail.sobolev@gmail.com>
Wed, 6 Dec 2006 22:20:46 +0000 (22:20 +0000)
committermishas <mikhail.sobolev@gmail.com>
Wed, 6 Dec 2006 22:20:46 +0000 (22:20 +0000)
git-svn-id: file:///svnroot/simple-launcher/trunk@50 3ba93dab-e023-0410-b42a-de7732cf370a

launcher-item.cc
launcher-item.h

index 9785ba2..8863fc0 100644 (file)
 #include <glib/gmem.h>
 #include <glib/gkeyfile.h>
 
-#include <gtk/gtkicontheme.h>
-
 #include "launcher-item.h"
 
+GtkIconTheme *LauncherItem::ourTheme = 0;
+
 static const char *DESKTOP_ENTRY_GROUP = "Desktop Entry",
                   *DESKTOP_ENTRY_TYPE_FIELD = "Type",
                   *DESKTOP_ENTRY_ICON_FIELD = "Icon",
@@ -104,11 +104,13 @@ GdkPixbuf *LauncherItem::getIcon(int icon_size) const {
   GdkPixbuf *pixbuf = 0;
 
   if (!myIcon.empty()) {
-    GtkIconTheme *theme;
+    if (ourTheme == 0) {
+      ourTheme = gtk_icon_theme_get_default();
+    }
+
     GError *error = 0;
 
-    theme = gtk_icon_theme_get_default();
-    pixbuf = gtk_icon_theme_load_icon(theme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error);
+    pixbuf = gtk_icon_theme_load_icon(ourTheme, myIcon.c_str(), icon_size, GTK_ICON_LOOKUP_NO_SVG, &error);
 
     if (error != 0) {
       g_error_free(error);
index 09da256..395bf27 100644 (file)
@@ -21,6 +21,7 @@
 #include <string>
 
 #include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtkicontheme.h>
 
 #include <libosso.h>
 
@@ -40,6 +41,8 @@ public:
   const std::string& getService() const { return myService; }
 private:
   std::string myName, myComment, myIcon, myService;
+
+  static GtkIconTheme *ourTheme;
 };
 
 #endif