gtkstock fixes and other comments



Hi.
I think there is a bug in the gtkstock implementation:
the stock label is translated at each lookup of the stock
item (unnecessary, IMHO, and could well get called on the
already translated string) and later the result of dgettext()
is passed to g_free() (while managing to leak some memory:-).

With the attached patch the call to dgettext() happens
once when the item is added to the hash table and the
associated memory is properly handled/freed.

There is still one problem, though: the default items
are added to the hash table and if you want to override them
later, they are g_free()ed. We have two options: copy them
(bleah) or add a flag telling they are really static entries.

I'd go for the second option. And while we are changing the 
GtkStockItem structure, why not add a GtkIconSet* as well?
Right now we have two hash tables (one static in gtkstock.c
and another in the default instance of GtkIconFactory): both
of them have stock_ids as keys and need to be kept in sync.
Keeping the icon source and the stock label in the same
structure will also allow to set a standard 'property'
on GtkImage widgets created from stock ids that holds
a description of the image (a screen reader such as gspeech
could make use of that info).
What is the reason for having different GtkIconFactory objects,
anyway? I see no reason for an application to have different
stock items in different windows, for example (and if you
need that you'd need also different stock labels).
So my plan would be to remove the GtkItemFactory stuff and
move the functionality for stock icons in gtkstock.c.
Comments?

Thanks,
	lupus

-- 
Paolo Molaro, Open Source Developer, Linuxcare, Inc.
+39.049.8043411 tel, +39.049.8043412 fax
lupus linuxcare com, http://www.linuxcare.com/
Linuxcare. Support for the revolution.
--- gtkstock.c.old	Thu Oct 26 15:51:17 2000
+++ gtkstock.c	Thu Oct 26 17:14:25 2000
@@ -58,6 +58,17 @@
           gtk_stock_item_free (old_value);
         }
       
+      if (copy)
+	{
+	  gchar* old_label = item->label;
+          item->label = g_strdup (dgettext (item->translation_domain, item->label));
+	  g_free (old_label);
+	}
+      else if (item->label)
+	{
+          item->label = dgettext (item->translation_domain, item->label);
+	}
+
       g_hash_table_insert (stock_hash,
                            (gchar*)item->stock_id, (GtkStockItem*)item);
 
@@ -97,11 +108,7 @@
   found = g_hash_table_lookup (stock_hash, stock_id);
 
   if (found)
-    {
-      *item = *found;
-      if (item->label)
-        item->label = dgettext (item->translation_domain, item->label);
-    }
+    *item = *found;
 
   return found != NULL;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]