]> Pileus Git - grits/commitdiff
Allow applications to specify plugin and config paths
authorAndy Spencer <andy753421@gmail.com>
Sun, 25 Oct 2009 17:15:10 +0000 (17:15 +0000)
committerAndy Spencer <andy753421@gmail.com>
Sun, 25 Oct 2009 17:15:10 +0000 (17:15 +0000)
Makefile.am
gen.sh
src/Makefile.am
src/gis [new symlink]
src/gis-plugin.c
src/gis-plugin.h
src/gis-prefs.c
src/gis-prefs.h
src/gis_test.c
src/libgis.pc.in

index 3373886299d0ab260fa9bebe67b0ed9ced6e2473..3f414104cc0318965ff77dc9b6c2675fbaee7b14 100644 (file)
@@ -24,12 +24,12 @@ depscan:
                --book=atk         \
                --book=gdk         \
                --book=gdk-pixbuf  \
-               --book=glib        \
                --book=gio         \
+               --book=glib        \
                --book=gobject     \
                --book=gtk         \
-               --book=pango       \
                --book=libsoup-2.4 \
+               --book=pango       \
                --list-unknown     \
                "$@"               \
                src/*.c
diff --git a/gen.sh b/gen.sh
index 8c2b18f7c70c19c66b9964f34dd380ac8652c69b..a6e66e34dcad3b6df8124aabba807c05ee13a986 100755 (executable)
--- a/gen.sh
+++ b/gen.sh
@@ -1,8 +1,8 @@
 #!/bin/bash
 dir=$(dirname $(readlink -f $0))
 ./autogen.sh \
-       "--libdir=$dir/src/plugins" \
-       "--datadir=$dir/data" \
-       --enable-gtk-doc \
+       "--enable-gtk-doc" \
+       "--libdir=$dir/src/.libs" \
+       "--includedir=$dir/src" \
        CFLAGS="-g -Werror -Wno-unused $CFLAGS" \
        LDFLAGS="-Wl,-z,defs"
index bb6a37c7409867e56f8ff887200b80b0e6c2b708..aba03b776b2918b86a241e15c79ab8658bde6469 100644 (file)
@@ -29,7 +29,7 @@ libgis_la_SOURCES = \
        wms.c         wms.h         \
        gpqueue.c     gpqueue.h
 libgis_la_CPPFLAGS = $(AM_CPPFLAGS) \
-       -DDATADIR="\"$(datadir)\"" -DPLUGINDIR="\"$(libdir)/gis\""
+       -DPKGDATADIR="\"$(datadir)/gis\"" -DPLUGINSDIR="\"$(libdir)/gis\""
 libgis_la_LIBADD = $(AM_LDADD)
 
 pkgconfigdir = $(libdir)/pkgconfig
diff --git a/src/gis b/src/gis
new file mode 120000 (symlink)
index 0000000..945c9b4
--- /dev/null
+++ b/src/gis
@@ -0,0 +1 @@
+.
\ No newline at end of file
index 4bfab58d71afb8d634ebd7b6d7a5957b180eb01e..c874095bd41795ac4381ca4a2ac97e728fd819a3 100644 (file)
@@ -68,35 +68,49 @@ typedef struct {
        GisPlugin *plugin;
 } GisPluginStore;
 
-GisPlugins *gis_plugins_new()
+GisPlugins *gis_plugins_new(gchar *dir)
 {
-       return g_ptr_array_new();
+       g_debug("GisPlugins: new - dir=%s", dir);
+       GisPlugins *plugins = g_new0(GisPlugins, 1);
+       if (dir)
+               plugins->dir = g_strdup(dir);
+       plugins->plugins = g_ptr_array_new();
+       return plugins;
 }
 
 void gis_plugins_free(GisPlugins *self)
 {
-       for (int i = 0; i < self->len; i++) {
-               GisPluginStore *store = g_ptr_array_index(self, i);
+       g_debug("GisPlugins: free");
+       for (int i = 0; i < self->plugins->len; i++) {
+               GisPluginStore *store = g_ptr_array_index(self->plugins, i);
                g_object_unref(store->plugin);
                g_free(store->name);
                g_free(store);
-               g_ptr_array_remove_index(self, i);
+               g_ptr_array_remove_index(self->plugins, i);
        }
-       g_ptr_array_free(self, TRUE);
+       g_ptr_array_free(self->plugins, TRUE);
+       if (self->dir)
+               g_free(self->dir);
+       g_free(self);
 }
 
-GList *gis_plugins_available()
+GList *gis_plugins_available(GisPlugins *self)
 {
-       GDir *dir = g_dir_open(PLUGINDIR, 0, NULL);
-       if (dir == NULL)
-               return NULL;
+       g_debug("GisPlugins: available");
        GList *list = NULL;
-       const gchar *name;
-       while ((name = g_dir_read_name(dir))) {
-               if (g_pattern_match_simple("*.so", name)) {
-                       gchar **parts = g_strsplit(name, ".", 2);
-                       list = g_list_prepend(list, g_strdup(parts[0]));
-                       g_strfreev(parts);
+       gchar *dirs[] = {self->dir, PLUGINSDIR};
+       for (int i = 0; i<2; i++) {
+               GDir *dir = g_dir_open(dirs[i], 0, NULL);
+               if (dir == NULL)
+                       continue;
+               g_debug("            checking %s", dirs[i]);
+               const gchar *name;
+               while ((name = g_dir_read_name(dir))) {
+                       if (g_pattern_match_simple("*.so", name)) {
+                               gchar **parts = g_strsplit(name, ".", 2);
+                               list = g_list_prepend(list, g_strdup(parts[0]));
+                               g_strfreev(parts);
+                       }
                }
        }
        return list;
@@ -105,7 +119,14 @@ GList *gis_plugins_available()
 GisPlugin *gis_plugins_load(GisPlugins *self, const char *name,
                GisWorld *world, GisView *view, GisOpenGL *opengl, GisPrefs *prefs)
 {
-       gchar *path = g_strdup_printf("%s/%s.%s", PLUGINDIR, name, G_MODULE_SUFFIX);
+       g_debug("GisPlugins: load %s", name);
+       gchar *path = g_strdup_printf("%s/%s.%s", self->dir, name, G_MODULE_SUFFIX);
+       if (!g_file_test(path, G_FILE_TEST_EXISTS))
+               path = g_strdup_printf("%s/%s.%s", PLUGINSDIR, name, G_MODULE_SUFFIX);
+       if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+               g_warning("Module %s not found", name);
+               return NULL;
+       }
        GModule *module = g_module_open(path, 0);
        g_free(path);
        if (module == NULL) {
@@ -128,29 +149,31 @@ GisPlugin *gis_plugins_load(GisPlugins *self, const char *name,
        GisPluginStore *store = g_malloc(sizeof(GisPluginStore));
        store->name = g_strdup(name);
        store->plugin = constructor(world, view, opengl, prefs);
-       g_ptr_array_add(self, store);
+       g_ptr_array_add(self->plugins, store);
        return store->plugin;
 }
 
 gboolean gis_plugins_unload(GisPlugins *self, const char *name)
 {
-       for (int i = 0; i < self->len; i++) {
-               GisPluginStore *store = g_ptr_array_index(self, i);
+       g_debug("GisPlugins: unload %s", name);
+       for (int i = 0; i < self->plugins->len; i++) {
+               GisPluginStore *store = g_ptr_array_index(self->plugins, i);
                if (g_str_equal(store->name, name)) {
                        g_object_unref(store->plugin);
                        g_free(store->name);
                        g_free(store);
-                       g_ptr_array_remove_index(self, i);
+                       g_ptr_array_remove_index(self->plugins, i);
                }
        }
        return FALSE;
 }
 void gis_plugins_foreach(GisPlugins *self, GCallback _callback, gpointer user_data)
 {
+       g_debug("GisPlugins: foreach");
        typedef void (*CBFunc)(GisPlugin *, const gchar *, gpointer);
        CBFunc callback = (CBFunc)_callback;
-       for (int i = 0; i < self->len; i++) {
-               GisPluginStore *store = g_ptr_array_index(self, i);
+       for (int i = 0; i < self->plugins->len; i++) {
+               GisPluginStore *store = g_ptr_array_index(self->plugins, i);
                callback(store->plugin, store->name, user_data);
        }
 }
index a667fba8919dcf5ca1dcb0ede0896e6d8513686f..6390f473fdd62f7f6f51bb2a093226fa8b40eb5c 100644 (file)
@@ -28,7 +28,7 @@
 
 typedef struct _GisPlugin          GisPlugin;
 typedef struct _GisPluginInterface GisPluginInterface;
-typedef GPtrArray                  GisPlugins;
+typedef struct _GisPlugins         GisPlugins;
 
 struct _GisPluginInterface
 {
@@ -51,14 +51,19 @@ GtkWidget *gis_plugin_get_config(GisPlugin *self);
 #include "gis-opengl.h"
 #include "gis-prefs.h"
 
+struct _GisPlugins {
+       gchar     *dir;
+       GPtrArray *plugins;
+};
+
 typedef GisPlugin *(*GisPluginConstructor)(GisWorld *world, GisView *view, GisOpenGL *opengl, GisPrefs *prefs);
 
-GisPlugins *gis_plugins_new();
+GisPlugins *gis_plugins_new(gchar *dir);
 void        gis_plugins_free();
-GList      *gis_plugins_available();
-GisPlugin  *gis_plugins_load(GisPlugins *self, const char *name,
+GList      *gis_plugins_available(GisPlugins *plugins);
+GisPlugin  *gis_plugins_load(GisPlugins *plugins, const char *name,
                GisWorld *world, GisView *view, GisOpenGL *opengl, GisPrefs *prefs);
-gboolean    gis_plugins_unload(GisPlugins *self, const char *name);
-void        gis_plugins_foreach(GisPlugins *self, GCallback callback, gpointer user_data);
+gboolean    gis_plugins_unload(GisPlugins *plugins, const char *name);
+void        gis_plugins_foreach(GisPlugins *plugins, GCallback callback, gpointer user_data);
 
 #endif
index abae1a2a1c6f97d5d83d2fabc33a5e1e62022fc4..4a1ee0d885bf977858df7ef77a46cc21053ea014 100644 (file)
@@ -30,27 +30,28 @@ static guint signals[NUM_SIGNALS];
 /***********
  * Methods *
  ***********/
-GisPrefs *gis_prefs_new(const gchar *prog)
+GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults)
 {
-       g_debug("GisPrefs: new - %s", prog);
+       g_debug("GisPrefs: new - %s, %s", config, defaults);
        GisPrefs *self = g_object_new(GIS_TYPE_PREFS, NULL);
-       self->key_path = g_build_filename(g_get_user_config_dir(),
-                       prog, "config.ini", NULL);
+       if (config)
+               self->key_path = g_strdup(config);
+       else
+               self->key_path = g_build_filename(g_get_user_config_dir(),
+                               "gis", "config.ini", NULL);
        GError *error = NULL;
        g_key_file_load_from_file(self->key_file, self->key_path,
                        G_KEY_FILE_KEEP_COMMENTS, &error);
-       if (error) {
-               g_debug("GisPrefs: new - Trying %s defaults", prog);
+       if (error && defaults) {
+               g_debug("GisPrefs: new - Trying %s defaults", defaults);
                g_clear_error(&error);
-               gchar *tmp = g_build_filename(DATADIR, prog, "defaults.ini", NULL);
-               g_key_file_load_from_file(self->key_file, tmp,
+               g_key_file_load_from_file(self->key_file, defaults,
                                G_KEY_FILE_KEEP_COMMENTS, &error);
-               g_free(tmp);
        }
        if (error) {
                g_debug("GisPrefs: new - Trying GIS defaults");
                g_clear_error(&error);
-               gchar *tmp = g_build_filename(DATADIR, "gis", "defaults.ini", NULL);
+               gchar *tmp = g_build_filename(PKGDATADIR, "defaults.ini", NULL);
                g_key_file_load_from_file(self->key_file, tmp,
                                G_KEY_FILE_KEEP_COMMENTS, &error);
                g_free(tmp);
@@ -116,7 +117,7 @@ static void gis_prefs_init(GisPrefs *self)
 static GObject *gis_prefs_constructor(GType gtype, guint n_properties,
                GObjectConstructParam *properties)
 {
-       g_debug("gis_prefs: constructor");
+       g_debug("GisPrefs: constructor");
        GObjectClass *parent_class = G_OBJECT_CLASS(gis_prefs_parent_class);
        return  parent_class->constructor(gtype, n_properties, properties);
 }
index 164573492ee4a23e97873720d2702f5ccbc68d13..ac9cde620904dd3e95bf7e41a81a0d7bc4155b46 100644 (file)
@@ -48,7 +48,7 @@ struct _GisPrefsClass {
 GType gis_prefs_get_type(void);
 
 /* Methods */
-GisPrefs *gis_prefs_new(const gchar *prog);
+GisPrefs *gis_prefs_new(const gchar *config, const gchar *defaults);
 
 gchar    *gis_prefs_get_string   (GisPrefs *prefs, const gchar *key);
 gboolean  gis_prefs_get_boolean  (GisPrefs *prefs, const gchar *key);
index fbe46a9354cbde30f732da0227e6e1d2547593c1..d587936a4a82f92833ab372d8e7566dff5a1cafe 100644 (file)
@@ -44,8 +44,8 @@ int main(int argc, char **argv)
        gtk_init(&argc, &argv);
        g_thread_init(NULL);
 
-       GisPrefs   *prefs   = gis_prefs_new("aweather");
-       GisPlugins *plugins = gis_plugins_new();
+       GisPrefs   *prefs   = gis_prefs_new(NULL, NULL);
+       GisPlugins *plugins = gis_plugins_new(NULL);
        GisWorld   *world   = gis_world_new();
        GisView    *view    = gis_view_new();
        GisOpenGL  *opengl  = gis_opengl_new(world, view, plugins);
index 859289e4df0dce289dc49e87f5b66c0f41751bd8..031cb4a76b82a9dca2de9c907cdad66ca43a9446 100644 (file)
@@ -8,4 +8,4 @@ Description: GIS Library for Gtk+ applications
 Version: @VERSION@
 Requires: gmodule-2.0 gtk+-2.0 gtkglext-1.0 libsoup-2.4
 Libs: -L${libdir} -lgis
-Cflags: -I${includedir}/gis
+Cflags: -I${includedir}