On Fri, 2004-01-09 at 16:51, ext Joaquin Cuenca Abela wrote:
> 
> That makes perfect sense to me.  If none else
> disagrees, feel free to commit a patch with your
> suggested changes, which should equal to your earliest
> patch + this change.

I'll rather attach a followup patch to be applied after the previous
one.  They are solving slightly different issues.  The first one simply
fixed the library loading.  This one makes it more general and
convenient (unfortunately library="gnomeui-2" is pretty useless without
wrappers)


-- 
Tommi Komulainen <[EMAIL PROTECTED]>
diff -u ChangeLog ChangeLog
--- ChangeLog	2004-01-08 18:14:27.000000000 +0200
+++ ChangeLog	2004-01-09 17:27:54.000000000 +0200
@@ -1,3 +1,13 @@
+2004-01-09  Tommi Komulainen  <[EMAIL PROTECTED]>
+
+	* src/glade-catalog.c
+	* src/glade-widget-class.c
+	* widgets/gtk-additional.xml
+	* widgets/gtk-base.xml: Instead of playing tricks with the library
+	filename, use the given name verbatim and let GModule handle platform
+	specifics.  Load the library from Glade modules directory, or failing
+	that from standard library paths.
+
 2004-01-08  Tommi Komulainen  <[EMAIL PROTECTED]>
 
 	* src/glade-widget-class.c: load the library module before attempting
diff -u src/glade-widget-class.c src/glade-widget-class.c
--- src/glade-widget-class.c	2004-01-08 16:34:05.000000000 +0200
+++ src/glade-widget-class.c	2004-01-09 17:43:23.000000000 +0200
@@ -472,6 +472,55 @@
 }
 
 /**
+ * glade_widget_class_load_library:
+ * @library_name: name of the library .
+ *
+ * Loads the named library from the Glade modules directory, or failing that
+ * from the standard platform specific directories.
+ *
+ * The @library_name should not include any platform specifix prefix or suffix,
+ * those are automatically added, if needed, by g_module_build_path()
+ *
+ * @returns: a #GModule on success, or %NULL on failure.
+ */
+static GModule *
+glade_widget_class_load_library (const gchar *library_name)
+{
+	gchar   *path;
+	GModule *module;
+
+	path = g_module_build_path (MODULES_DIR, library_name);
+	if (!path)
+	{
+		g_warning (_("Not enough memory."));
+		return NULL;
+	}
+
+	module = g_module_open (path, G_MODULE_BIND_LAZY);
+	g_free (path);
+
+	if (!module)
+	{
+		path = g_module_build_path (NULL, library_name);
+		if (!path)
+		{
+			g_warning (_("Not enough memory."));
+			return NULL;
+		}
+
+		module = g_module_open (path, G_MODULE_BIND_LAZY);
+		g_free (path);
+	}
+
+	if (!module)
+	{
+		g_warning (_("Unable to open the module %s."), library_name);
+	}
+
+	return module;
+}
+
+/**
  * glade_widget_class_new:
  * @name: name of the widget class (for instance: GtkButton)
  * @generic_name: base of the name for the widgets of this class (for instance: button).
@@ -496,7 +545,6 @@
 {
 	GladeWidgetClass *widget_class = NULL;
 	char *filename = NULL;
-	char *library = NULL;
 	char *init_function_name = NULL;
 	GModule *module = NULL;
 	GType parent_type;
@@ -521,19 +569,9 @@
 
 	if (base_library != NULL)
 	{
-		library = g_strconcat (MODULES_DIR G_DIR_SEPARATOR_S, base_library, NULL);
-		if (library == NULL)
-		{
-			g_warning (_("Not enough memory."));
-			goto lblError;
-		}
-
-		module = g_module_open (library, G_MODULE_BIND_LAZY);
+		module = glade_widget_class_load_library (base_library);
 		if (!module)
-		{
-			g_warning (_("Unable to open the module %s."), library);
 			goto lblError;
-		}
 	}
 
 	widget_class = g_new0 (GladeWidgetClass, 1);
@@ -606,7 +644,6 @@
 
 lblError:
 	g_free (filename);
-	g_free (library);
 	g_free (init_function_name);
 	glade_widget_class_free (widget_class);
 	return NULL;
only in patch2:
unchanged:
--- widgets/gtk-base.xml	2003-11-29 15:44:45.000000000 +0200
+++ widgets/gtk-base.xml	2004-01-09 17:00:30.000000000 +0200
@@ -1,4 +1,4 @@
-<GladeCatalog Title="Gtk+ Basic" library="gtk">
+<GladeCatalog Title="Gtk+ Basic" library="gladegtk">
 
   <GladeWidget name="GtkWidget" filename="gtkwidget.xml"/>
   <GladeWidget name="GtkContainer" filename="gtkcontainer.xml"/>
only in patch2:
unchanged:
--- widgets/gtk-additional.xml	2003-10-04 13:36:31.000000000 +0300
+++ widgets/gtk-additional.xml	2004-01-09 17:00:57.000000000 +0200
@@ -1,4 +1,4 @@
-<GladeCatalog Title="Gtk+ Additional" library="gtk">
+<GladeCatalog Title="Gtk+ Additional" library="gladegtk">
 
   <GladeWidget name="GtkHScale" generic_name="hscale"/>
   <GladeWidget name="GtkVScale" generic_name="vscale"/>
only in patch2:
unchanged:
--- src/glade-catalog.c	2003-11-09 17:16:41.000000000 +0200
+++ src/glade-catalog.c	2004-01-09 15:34:47.000000000 +0200
@@ -66,7 +66,6 @@
 	char *generic_name = NULL;
 	char *catalog_filename = NULL;
 	char *base_filename = NULL;
-	char *partial_library = NULL;
 	char *base_library = NULL;
 	GList *last_widget_class = NULL;
 
@@ -102,22 +101,12 @@
 	}
 
 	/* get the library to be used by this catalog (if any) */
-	partial_library = glade_xml_get_property_string (root, "library");
-	if (partial_library && *partial_library)
-	{
-		base_library = g_strdup_printf ("libglade%s", partial_library);
-		if (!base_library)
-		{
-			g_critical (_("Not enough memory."));
-			goto lblError;
-		}
-	}
+	base_library = glade_xml_get_property_string (root, "library");
 
 	/* build all the GladeWidgetClass'es associated with this catalog */
 	widget_node = glade_xml_node_get_children (root);
 	for (; widget_node; widget_node = glade_xml_node_next (widget_node))
 	{
-		char *partial_widget_class_library = NULL;
 		char *base_widget_class_library = NULL;
 
 		if (!glade_xml_node_verify (widget_node, GLADE_TAG_GLADE_WIDGET))
@@ -128,16 +117,7 @@
 			continue;
 
 		/* get the specific library to the widget class, if any */
-		partial_widget_class_library = glade_xml_get_property_string (widget_node, "library");
-		if (partial_widget_class_library && *partial_widget_class_library)
-		{
-			base_widget_class_library = g_strdup_printf ("libglade%s", partial_widget_class_library);
-			if (!base_widget_class_library)
-			{
-				g_critical (_("Not enough memory."));
-				continue;
-			}
-		}
+		base_widget_class_library = glade_xml_get_property_string (widget_node, "library");
 
 		generic_name = glade_xml_get_property_string (widget_node, "generic_name");
 		base_filename = glade_xml_get_property_string (widget_node, "filename");
@@ -157,7 +137,6 @@
 		g_free (name);
 		g_free (generic_name);
 		g_free (base_filename);
-		g_free (partial_widget_class_library);
 		g_free (base_widget_class_library);
 	}
 
@@ -169,7 +148,6 @@
 	glade_xml_context_free (context);
 	g_free (catalog_filename);
 	g_free (catalog);
-	g_free (partial_library);
 	g_free (base_library);
 	return NULL;
 }

Reply via email to