diff options
author | Tristan Van Berkom <tvb@src.gnome.org> | 2007-07-25 20:04:56 +0000 |
---|---|---|
committer | Tristan Van Berkom <tvb@src.gnome.org> | 2007-07-25 20:04:56 +0000 |
commit | c9edd8b01a189dad489aff46d1f13dadade99c0d (patch) | |
tree | 8c09de5d5baa78c1927cd81d23e3f6924853efa1 | |
parent | 123cb31e815838553897957a5aaeb62bee0fe3c5 (diff) | |
download | glade-c9edd8b01a189dad489aff46d1f13dadade99c0d.tar.gz |
Loop through user defined search paths and load catalogs from there first.
* gladeui/glade-catalog.c: Loop through user defined search paths and load
catalogs from there first.
* gladeui/glade-utils.c: Loop through user defined search paths for modules,
then fallback on the compile time default, then fallback on default system
library paths.
* gladeui/glade-app.h: Define env variables GLADE_MODULE_PATH & GLADE_CATALOG_PATH
svn path=/trunk/; revision=1516
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | gladeui/glade-app.h | 9 | ||||
-rw-r--r-- | gladeui/glade-catalog.c | 91 | ||||
-rw-r--r-- | gladeui/glade-utils.c | 47 |
4 files changed, 112 insertions, 44 deletions
@@ -8,6 +8,15 @@ (to counter the evil effects of gtk+ bug 460272, which made it impossible to set the label-xalign to 0.5). + * gladeui/glade-catalog.c: Loop through user defined search paths and load + catalogs from there first. + + * gladeui/glade-utils.c: Loop through user defined search paths for modules, + then fallback on the compile time default, then fallback on default system + library paths. + + * gladeui/glade-app.h: Define env variables GLADE_MODULE_PATH & GLADE_CATALOG_PATH + 2006-06-24 Tristan Van Berkom <tvb@gnome.org> * src/glade-window.c: Set custom label on the property editor sensitive/insensitive diff --git a/gladeui/glade-app.h b/gladeui/glade-app.h index f516267a..28fa2c8d 100644 --- a/gladeui/glade-app.h +++ b/gladeui/glade-app.h @@ -38,6 +38,9 @@ G_BEGIN_DECLS #define GLADE_TYPE_POINTER_MODE (glade_pointer_mode_get_type()) +#define GLADE_ENV_CATALOG_PATH "GLADE_CATALOG_PATH" +#define GLADE_ENV_MODULE_PATH "GLADE_MODULE_PATH" + typedef struct _GladeApp GladeApp; typedef struct _GladeAppPrivate GladeAppPrivate; typedef struct _GladeAppClass GladeAppClass; @@ -155,12 +158,12 @@ void glade_app_set_accel_group (GtkAccelGroup *accel_group); void glade_app_update_instance_count (GladeProject *project); -GtkWidget *glade_app_undo_button_new (void); +GtkWidget *glade_app_undo_button_new (void); -GtkWidget *glade_app_redo_button_new (void); +GtkWidget *glade_app_redo_button_new (void); -GList *glade_app_get_selection (void); +GList *glade_app_get_selection (void); /* These handle selection on a global scope and take care diff --git a/gladeui/glade-catalog.c b/gladeui/glade-catalog.c index 7d22a66a..92924bbf 100644 --- a/gladeui/glade-catalog.c +++ b/gladeui/glade-catalog.c @@ -438,52 +438,79 @@ catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node) return TRUE; } -const GList * -glade_catalog_load_all (void) +static GList * +catalogs_from_path (GList *catalogs, const gchar *path) { + GladeCatalog *catalog; GDir *dir; GError *error = NULL; const gchar *filename; - GList *catalogs, *l; - GladeCatalog *catalog; + + if ((dir = g_dir_open (path, 0, &error)) != NULL) + { + while ((filename = g_dir_read_name (dir))) + { + gchar *catalog_filename; + + if (!g_str_has_suffix (filename, ".xml")) + continue; + + catalog_filename = g_build_filename (path, filename, NULL); + catalog = catalog_open (catalog_filename); + g_free (catalog_filename); + + if (catalog) + { + /* Verify that we are not loading the same catalog twice ! + */ + if (!g_list_find_custom (catalogs, catalog->name, + (GCompareFunc)catalog_find_by_name)) + catalogs = g_list_prepend (catalogs, catalog); + else + catalog_destroy (catalog); + } + else + g_warning ("Unable to open the catalog file %s.\n", filename); + } + } + else + g_warning ("Failed to open catalog directory '%s': %s", path, error->message); - /* Read all files in catalog dir */ - dir = g_dir_open (glade_app_get_catalogs_dir (), 0, &error); - if (!dir) + + return catalogs; +} + +const GList * +glade_catalog_load_all (void) +{ + GList *catalogs = NULL, *l; + GladeCatalog *catalog; + const gchar *search_path; + gchar **split; + gint i; + + /* First load catalogs from user specified directories ... */ + if ((search_path = g_getenv (GLADE_ENV_CATALOG_PATH)) != NULL) { - g_warning ("Failed to open catalog directory: %s", - error->message); - return NULL; + if ((split = g_strsplit (search_path, ":", 0)) != NULL) + { + for (i = 0; split[i] != NULL; i++) + catalogs = catalogs_from_path (catalogs, split[i]); + + g_strfreev (split); + } } + /* ... Then load catalogs from standard install directory */ + catalogs = catalogs_from_path (catalogs, glade_app_get_catalogs_dir ()); + /* Catalogs need dependancies, most catalogs depend on * the gtk+ catalog, but some custom toolkits may depend * on the gnome catalog for instance. */ - catalogs = NULL; - while ((filename = g_dir_read_name (dir))) - { - gchar *catalog_filename; - - if (!g_str_has_suffix (filename, ".xml")) - continue; - - catalog_filename = g_build_filename (glade_app_get_catalogs_dir (), - filename, NULL); - catalog = catalog_open (catalog_filename); - g_free (catalog_filename); - - if (catalog) - catalogs = g_list_prepend (catalogs, catalog); - else - g_warning ("Unable to open the catalog file %s.\n", - filename); - } - g_dir_close (dir); - - /* After sorting, execute init function and then load */ catalogs = catalog_sort (catalogs); + /* After sorting, execute init function and then load */ for (l = catalogs; l; l = l->next) { catalog = l->data; diff --git a/gladeui/glade-utils.c b/gladeui/glade-utils.c index 6b4c9b6d..5f968585 100644 --- a/gladeui/glade-utils.c +++ b/gladeui/glade-utils.c @@ -667,7 +667,7 @@ glade_util_get_window_positioned_in (GtkWidget *widget) return widget->window; } -void +static void glade_util_draw_nodes (GdkWindow *window, GdkGC *gc, gint x, gint y, gint width, gint height) @@ -1376,6 +1376,20 @@ glade_util_class_implements_interface (GType class_type, } +static GModule * +try_load_library (const gchar *library_path, + const gchar *library_name) +{ + GModule *module; + gchar *path; + + path = g_module_build_path (library_path, library_name); + module = g_module_open (path, G_MODULE_BIND_LAZY); + g_free (path); + + return module; +} + /** * glade_util_load_library: * @library_name: name of the library @@ -1391,19 +1405,34 @@ glade_util_class_implements_interface (GType class_type, GModule * glade_util_load_library (const gchar *library_name) { - gchar *path; - GModule *module; + GModule *module = NULL; + const gchar *default_paths[] = { glade_app_get_modules_dir (), "/lib", "/usr/lib", "/usr/local/lib", NULL }; + const gchar *search_path; + gchar **split; + gint i; + + if ((search_path = g_getenv (GLADE_ENV_MODULE_PATH)) != NULL) + { + if ((split = g_strsplit (search_path, ":", 0)) != NULL) + { + for (i = 0; split[i] != NULL; i++) + if ((module = try_load_library (split[i], library_name)) != NULL) + break; - path = g_module_build_path (glade_app_get_modules_dir (), library_name); + g_strfreev (split); + } + } - if ((module = g_module_open (path, G_MODULE_BIND_LAZY)) == NULL) + if (!module) { - g_warning (_("Unable to open the module %s (%s)."), - path, g_module_error()); + for (i = 0; default_paths[i] != NULL; i++) + if ((module = try_load_library (default_paths[i], library_name)) != NULL) + break; } - g_free (path); - + if (!module) + g_critical ("Unable to load module '%s' from any search paths", library_name); + return module; } |