[Goodies-commits] r1446 - in xfce4-weather-plugin/trunk: icons/liquid panel-plugin

Nick Schermer nick at xfce.org
Wed Jun 14 22:14:46 CEST 2006


Author: nick
Date: 2006-06-14 20:14:45 +0000 (Wed, 14 Jun 2006)
New Revision: 1446

Removed:
   xfce4-weather-plugin/trunk/icons/liquid/0.png
Modified:
   xfce4-weather-plugin/trunk/icons/liquid/Makefile.am
   xfce4-weather-plugin/trunk/panel-plugin/icon.c
   xfce4-weather-plugin/trunk/panel-plugin/icon.h
   xfce4-weather-plugin/trunk/panel-plugin/parsers.c
   xfce4-weather-plugin/trunk/panel-plugin/plugin.c
   xfce4-weather-plugin/trunk/panel-plugin/scrollbox.c
   xfce4-weather-plugin/trunk/panel-plugin/summary_window.c
Log:
* Fix huge memory leak in the weather plugin (1,2 MB each startup).
  This happend while creating the icon factory, the pixmaps where loaded
  and unrefed but the icon factory also raised the ref_count by 1, so
  all the 47 pixmaps where never freed.
  I've fixed this by removing the factory and load the pixmaps manually.
* Remove the 0.png and use 25.png instead.
* Fixed icon in summary window if no weather data was available
* Fixed panel resizing, this also seems to fix the "no update back from 
  laptop suspend", duno why, but it works :).
* The previous commit also added some more usefull default labels


Deleted: xfce4-weather-plugin/trunk/icons/liquid/0.png

Modified: xfce4-weather-plugin/trunk/icons/liquid/Makefile.am
===================================================================
--- xfce4-weather-plugin/trunk/icons/liquid/Makefile.am	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/icons/liquid/Makefile.am	2006-06-14 20:14:45 UTC (rev 1446)
@@ -1,7 +1,6 @@
 liquiddir = $(datadir)/xfce4/weather/icons/liquid
 
-liquid_DATA =	0.png	\
-		1.png	\
+liquid_DATA =	1.png	\
 		2.png	\
 		3.png	\
 		4.png	\

Modified: xfce4-weather-plugin/trunk/panel-plugin/icon.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/icon.c	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/icon.c	2006-06-14 20:14:45 UTC (rev 1446)
@@ -24,60 +24,31 @@
 
 #include "icon.h"
 
-GtkIconFactory *cfactory = NULL;
+#define DEFAULT_W_THEME "liquid"
 
-void
-register_icons (gchar *path)
-{
-    GtkIconSet *iconset;
-    guint       i;
-    GdkPixbuf  *pixbuf; 
-    gchar      *filename, *name;
-
-    if (cfactory)
-        return;
-
-    cfactory = gtk_icon_factory_new ();
-
-    for (i = 0; i <= 47; i++) 
-    {
-        filename = g_strdup_printf ("%s%d.png", path, i);
-        name = g_strdup_printf ("xfceweather_%d", i);
-        pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
-
-        if (!pixbuf) 
-            continue;
-
-        iconset = gtk_icon_set_new_from_pixbuf (pixbuf);
-        g_object_unref (pixbuf);
-
-        gtk_icon_factory_add (cfactory, name, iconset);
-
-        g_free (filename);
-        g_free (name);
-    }
-
-    if (iconset)
-        gtk_icon_factory_add (cfactory, "xfceweather_-", iconset);
-
-    gtk_icon_factory_add_default (cfactory);
-}
-
 GdkPixbuf *
-get_icon (GtkWidget   *widget,
-           const gchar *number,
-           GtkIconSize  size)
+get_icon (const gchar *number,
+          GtkIconSize  size)
 {
     GdkPixbuf *image = NULL;
-    gchar     *str;
-
-    str = g_strdup_printf ("xfceweather_%s", number);
-    image = gtk_widget_render_icon (widget, str, size, "none");
+    gchar     *filename;
+    gint       width, height;
     
-    g_free (str);
+    gtk_icon_size_lookup (size, &width, &height);
+    
+    filename = g_strdup_printf ("%s%s%s%s%s.png",
+            THEMESDIR, G_DIR_SEPARATOR_S,
+            DEFAULT_W_THEME, G_DIR_SEPARATOR_S,
+            number);
+    
+    image = gdk_pixbuf_new_from_file_at_scale (filename,
+	    width, height,
+            TRUE, NULL);
+    
+    g_free (filename);
 
     if (!image)
-        g_warning ("weather plugin: No image found");
+        g_warning ("Weather Plugin: No image found");
     
     return image;
 }

Modified: xfce4-weather-plugin/trunk/panel-plugin/icon.h
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/icon.h	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/icon.h	2006-06-14 20:14:45 UTC (rev 1446)
@@ -20,11 +20,8 @@
 
 G_BEGIN_DECLS
 
-void
-register_icons   (gchar *path);
-
 GdkPixbuf *
-get_icon         (GtkWidget *widget, const gchar *icon, GtkIconSize size);
+get_icon         (const gchar *icon, GtkIconSize size);
 
 G_END_DECLS
 

Modified: xfce4-weather-plugin/trunk/panel-plugin/parsers.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/parsers.c	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/parsers.c	2006-06-14 20:14:45 UTC (rev 1446)
@@ -139,7 +139,7 @@
 {
     xml_wind *ret;
     
-    if ((ret = g_new0(xml_wind, 1)) == NULL)
+    if ((ret = g_new (xml_wind, 1)) == NULL)
         return NULL;
     
     for (cur_node = cur_node->children; cur_node; cur_node = cur_node->next)
@@ -275,7 +275,7 @@
 }
 
 #define CHK_FREE(this) if (this)\
-              free(this);
+              g_free(this);
 
 static void
 xml_uv_free (xml_uv *data)

Modified: xfce4-weather-plugin/trunk/panel-plugin/plugin.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/plugin.c	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/plugin.c	2006-06-14 20:14:45 UTC (rev 1446)
@@ -37,7 +37,6 @@
 #include "scrollbox.h"
 
 #define XFCEWEATHER_ROOT "weather"
-#define DEFAULT_W_THEME "liquid"
 #define UPDATE_TIME 1600
 #define BORDER 8
 
@@ -176,10 +175,9 @@
 static void
 set_icon_error (xfceweather_data *data)
 {
-
-    GdkPixbuf *icon = get_icon (data->iconimage, "25", data->iconsize);
+    GdkPixbuf *icon = get_icon ("25", data->iconsize);
     gtk_image_set_from_pixbuf (GTK_IMAGE(data->iconimage), icon);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
 
     if (data->weatherdata)
     {
@@ -196,9 +194,8 @@
 static void
 set_icon_current (xfceweather_data *data)
 {
-
     guint      i;
-    GdkPixbuf *icon;
+    GdkPixbuf *icon = NULL;
 
     for (i = 0; i < data->labels->len; i++)
     {
@@ -216,11 +213,11 @@
         g_free (str);
     }
 
-    gtk_scrollbox_enablecb(GTK_SCROLLBOX(data->scrollbox), TRUE);       
-        
-    icon = get_icon (data->iconimage, get_data(data->weatherdata, WICON), data->iconsize);
+    gtk_scrollbox_enablecb(GTK_SCROLLBOX(data->scrollbox), TRUE);
+    
+    icon = get_icon (get_data(data->weatherdata, WICON), data->iconsize);
     gtk_image_set_from_pixbuf (GTK_IMAGE(data->iconimage), icon);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
        
     gtk_tooltips_set_tip (data->tooltips, data->tooltipbox, 
         translate_desc(get_data(data->weatherdata, TRANS)), NULL);
@@ -248,10 +245,10 @@
         return;
 
     cur_node = xmlDocGetRootElement (doc);
-
+    
     if (cur_node)
         weather = parse_weather (cur_node);
-
+    
     xmlFreeDoc (doc);
 
     gtk_scrollbox_clear (GTK_SCROLLBOX(data->scrollbox));
@@ -279,9 +276,8 @@
 {
 
     struct stat attrs; 
-    /*gchar *fullfilename = xfce_resource_save_location (XFCE_RESOURCE_CACHE, 
-            filename, TRUE);*/
     gchar *fullfilename;
+    gchar *url;
 
     if (!data->location_code)
         return -1;
@@ -297,21 +293,23 @@
     if (force || (stat (fullfilename, &attrs) == -1) || 
             ((time (NULL) - attrs.st_mtime) > (UPDATE_TIME)))
     {
-        gchar *url = g_strdup_printf ("/weather/local/%s?cc=*&dayf=%d&unit=%c",
+        url = g_strdup_printf ("/weather/local/%s?cc=*&dayf=%d&unit=%c",
                 data->location_code, XML_WEATHER_DAYF_N,
                 data->unit == METRIC ? 'm' : 'i');
-           
 
         gboolean status = http_get_file (url, "xoap.weather.com", fullfilename, 
                 data->proxy_host, data->proxy_port, cb_update,
                 (gpointer) data);
+	
         g_free (url);
         g_free (fullfilename);
 
         return status ? 1 : -1;
     }
     else if (data->weatherdata)
-        return 0;
+    {
+	return 0;
+    }
     else
     {
         cb_update (TRUE, data);
@@ -622,7 +620,7 @@
     xfceweather_data *data = g_new0 (xfceweather_data, 1);
     GtkWidget    *vbox, *refresh;
     datas         lbl;
-    GdkPixbuf    *icon;
+    GdkPixbuf    *icon = NULL;
 
     if (!GTK_ICON_SIZE_SMALL)
         GTK_ICON_SIZE_SMALL = gtk_icon_size_register ("iconsize_small", 16, 16);
@@ -634,11 +632,11 @@
     gtk_object_sink (GTK_OBJECT (data->tooltips));
 
     data->scrollbox = gtk_scrollbox_new ();
-       
-    icon = get_icon (GTK_WIDGET (plugin), "0", GTK_ICON_SIZE_SMALL);
+  
+    icon = get_icon ("25", GTK_ICON_SIZE_SMALL);
     data->iconimage = gtk_image_new_from_pixbuf (icon);
     gtk_misc_set_alignment (GTK_MISC(data->iconimage), 0.5, 1);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
 
     data->labels = g_array_new (FALSE, TRUE, sizeof (datas));
        
@@ -703,7 +701,7 @@
     
     /* Free Tooltip */
     gtk_tooltips_set_tip (data->tooltips, data->tooltipbox, NULL, NULL);
-    g_object_unref (data->tooltips);
+    g_object_unref (G_OBJECT (data->tooltips));
     
     /* Free chars */
     g_free (data->location_code);
@@ -733,7 +731,12 @@
     else
         data->iconsize = GTK_ICON_SIZE_DND;
 
-    update_plugin (data, FALSE);
+    gtk_scrollbox_clear (GTK_SCROLLBOX(data->scrollbox));
+    
+    if (data->weatherdata)
+        set_icon_current (data);
+    else
+	set_icon_error (data);
 
     return TRUE;
 }
@@ -741,16 +744,9 @@
 static void
 weather_construct (XfcePanelPlugin *plugin)
 {
-
-    gchar *path;
     xfceweather_data *data;
 
     xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
-    
-    path = g_strdup_printf ("%s%s%s%s", THEMESDIR, G_DIR_SEPARATOR_S,
-            DEFAULT_W_THEME, G_DIR_SEPARATOR_S);
-    register_icons (path);
-    g_free (path);
 
     data = xfceweather_create_control (plugin);
     
@@ -773,7 +769,8 @@
     xfce_panel_plugin_menu_show_configure (plugin);
     g_signal_connect (plugin, "configure-plugin", 
               G_CALLBACK (xfceweather_create_options), data);
+	      
+    update_plugin (data, TRUE);
 }
 
 XFCE_PANEL_PLUGIN_REGISTER_EXTERNAL (weather_construct);
-

Modified: xfce4-weather-plugin/trunk/panel-plugin/scrollbox.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/scrollbox.c	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/scrollbox.c	2006-06-14 20:14:45 UTC (rev 1446)
@@ -51,9 +51,9 @@
 free_label (struct label *lbl)
 {
     if (lbl->pixmap)
-        g_object_unref (lbl->pixmap);
+        g_object_unref (G_OBJECT (lbl->pixmap));
     if (lbl->msg)
-        g_free(lbl->msg);
+        g_free (lbl->msg);
 }
 
 static gboolean
@@ -207,7 +207,7 @@
 
     gdk_draw_layout(GDK_DRAWABLE(pixmap), widget->style->fg_gc[0], 0, 0, pl);
 
-    g_object_unref(pl);
+    g_object_unref(G_OBJECT (pl));
 
     gtk_widget_size_request(widget, &widgsize);
 
@@ -319,7 +319,7 @@
         {
             struct label *lbl = (struct label*)g_ptr_array_index(self->labels, i); 
 
-            g_object_unref (lbl->pixmap);
+            g_object_unref (G_OBJECT (lbl->pixmap));
             g_free(lbl->msg);
         }
         g_ptr_array_free(self->labels, TRUE);
@@ -353,7 +353,7 @@
         newpixmap = make_pixmap(self, lbl->msg);
 
         if (lbl->pixmap)
-            g_object_unref (lbl->pixmap);
+            g_object_unref (G_OBJECT (lbl->pixmap));
 
         lbl->pixmap = newpixmap;
     }

Modified: xfce4-weather-plugin/trunk/panel-plugin/summary_window.c
===================================================================
--- xfce4-weather-plugin/trunk/panel-plugin/summary_window.c	2006-06-14 08:05:58 UTC (rev 1445)
+++ xfce4-weather-plugin/trunk/panel-plugin/summary_window.c	2006-06-14 20:14:45 UTC (rev 1446)
@@ -191,15 +191,15 @@
 
     icon_hbox = gtk_hbox_new(FALSE, 0);
     
-    icon = get_icon(item_vbox, get_data_f(weatherdata, ICON_D), GTK_ICON_SIZE_DIALOG);
+    icon = get_icon(get_data_f(weatherdata, ICON_D), GTK_ICON_SIZE_DIALOG);
     icon_d = gtk_image_new_from_pixbuf(icon);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
     box_d = gtk_event_box_new();
     gtk_container_add(GTK_CONTAINER(box_d), icon_d);
     
-    icon = get_icon(item_vbox, get_data_f(weatherdata, ICON_N), GTK_ICON_SIZE_DIALOG);
+    icon = get_icon(get_data_f(weatherdata, ICON_N), GTK_ICON_SIZE_DIALOG);
     icon_n = gtk_image_new_from_pixbuf(icon);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
     box_n = gtk_event_box_new();
     gtk_container_add(GTK_CONTAINER(box_n), icon_n);
 
@@ -368,9 +368,13 @@
     vbox = gtk_vbox_new(FALSE, 0);
     gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), vbox, TRUE, TRUE, 0); 
 
-    icon = get_icon (window, get_data(data, WICON), GTK_ICON_SIZE_DIALOG);
+    icon = get_icon (get_data(data, WICON), GTK_ICON_SIZE_DIALOG);
+    
+    if (!icon)
+	icon = get_icon ("25", GTK_ICON_SIZE_DIALOG);
+    
     gtk_window_set_icon (GTK_WINDOW (window), icon);
-    g_object_unref (icon);
+    g_object_unref (G_OBJECT (icon));
 
     notebook = gtk_notebook_new();
     gtk_container_set_border_width(GTK_CONTAINER(notebook), BORDER);




More information about the Goodies-commits mailing list