[Xfce4-commits] <xfce4-panel:devel> Use hard-coded paths for loading modules (bug #5455).

Nick Schermer nick at xfce.org
Tue Aug 11 20:35:18 CEST 2009


Updating branch refs/heads/devel
         to 8c7ed2a793e3c61717908c8a0094480126e643b2 (commit)
       from a891d551965de229b820227e151f42f32b651261 (commit)

commit 8c7ed2a793e3c61717908c8a0094480126e643b2
Author: Nick Schermer <nick at xfce.org>
Date:   Tue Aug 4 20:47:41 2009 +0200

    Use hard-coded paths for loading modules (bug #5455).

 panel/Makefile.am            |    2 +-
 panel/panel-module-factory.c |  153 +++++++++++++++++-------------------------
 panel/panel-module.c         |    7 +-
 panel/panel-module.h         |    1 +
 4 files changed, 67 insertions(+), 96 deletions(-)

diff --git a/panel/Makefile.am b/panel/Makefile.am
index 760700e..b38d2e8 100644
--- a/panel/Makefile.am
+++ b/panel/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES = \
 	-I$(top_builddir) \
 	-DG_LOG_DOMAIN=\"xfce4-panel\" \
 	-DDATADIR=\"$(datadir)\" \
-	-DLIBDIR=\"$(libdir)/xfce4\" \
+	-DLIBDIR=\"$(libdir)\" \
 	-DLIBEXECDIR=\"$(libexecdir)\" \
 	-DSYSCONFDIR=\"$(sysconfdir)\" \
 	-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
diff --git a/panel/panel-module-factory.c b/panel/panel-module-factory.c
index 835d06b..4a1ce69 100644
--- a/panel/panel-module-factory.c
+++ b/panel/panel-module-factory.c
@@ -36,6 +36,9 @@
 #include <panel/panel-module.h>
 #include <panel/panel-module-factory.h>
 
+#define DESKTOP_FILES_DIR (DATADIR G_DIR_SEPARATOR_S "xfce4" G_DIR_SEPARATOR_S "panel-plugins")
+#define LIBRARY_FILES_DIR (LIBDIR  G_DIR_SEPARATOR_S "xfce4" G_DIR_SEPARATOR_S "panel-plugins")
+
 
 
 static void     panel_module_factory_finalize        (GObject                  *object);
@@ -141,107 +144,75 @@ panel_module_factory_finalize (GObject *object)
 static void
 panel_module_factory_load_modules (PanelModuleFactory *factory)
 {
-  gchar       **dirs;
-  gint          n;
-  gchar        *path;
-  GDir         *dir;
-  const gchar  *name, *p;
-  gchar        *filename;
-  PanelModule  *module;
-  gchar        *internal_name;
-
-  /* get all resource directories */
-  dirs = xfce_resource_dirs (XFCE_RESOURCE_DATA);
-
-  /* check if the installation datadir is part of this list */
-  for (n = 0; dirs[n] != NULL; n++)
-    if (exo_str_is_equal (dirs[n], DATADIR))
-      break;
-
-  if (G_UNLIKELY (dirs[n] == NULL))
-    {
-      /* add the installation datadir */
-      dirs = g_realloc (dirs, (n + 2) * sizeof (gchar *));
-      dirs[n] = g_strdup (DATADIR);
-      dirs[n+1] = NULL;
-    }
+  GDir        *dir;
+  const gchar *name, *p;
+  gchar       *filename;
+  PanelModule *module;
+  gchar       *internal_name;
 
-  /* search the directories for plugin .desktop files */
-  for (n = 0; dirs[n] != NULL; n++)
+  /* try to open the directory */
+  dir = g_dir_open (DESKTOP_FILES_DIR, 0, NULL);
+  if (G_UNLIKELY (dir == NULL))
+    return;
+
+  /* walk the directory */
+  for (;;)
     {
-      /* build path */
-      path = g_build_filename (dirs[n], "xfce4", "panel-plugins", NULL);
+      /* get name of the next file */
+      name = g_dir_read_name (dir);
+
+      /* break when we reached the last file */
+      if (G_UNLIKELY (name == NULL))
+        break;
+
+      /* continue if it's not a desktop file */
+      if (G_UNLIKELY (g_str_has_suffix (name, ".desktop") == FALSE))
+        continue;
+
+      /* create the full .desktop filename */
+      filename = g_build_filename (DESKTOP_FILES_DIR, name, NULL);
 
-      /* try to open the directory */
-      dir = g_dir_open (path, 0, NULL);
+      /* find the dot in the name, this cannot
+       * fail since it pasted the .desktop suffix check */
+      p = strrchr (name, '.');
 
-      if (G_LIKELY (dir))
+      /* get the new module internal name */
+      internal_name = g_strndup (name, p - name);
+
+      /* check if the modules name is already loaded */
+      if (G_UNLIKELY (g_hash_table_lookup (factory->modules, internal_name) != NULL))
+        goto already_loaded;
+
+      /* try to load the module */
+      module = panel_module_new_from_desktop_file (filename,
+                                                   internal_name,
+                                                   LIBRARY_FILES_DIR,
+                                                   force_all_external);
+
+      if (G_LIKELY (module != NULL))
         {
-          /* walk the directory */
-          for (;;)
-            {
-              /* get name of the next file */
-              name = g_dir_read_name (dir);
-
-              /* break when we reached the last file */
-              if (G_UNLIKELY (name == NULL))
-                break;
-
-              /* continue if it's not a desktop file */
-              if (G_UNLIKELY (g_str_has_suffix (name, ".desktop") == FALSE))
-                continue;
-
-              /* create the full .desktop filename */
-              filename = g_build_filename (path, name, NULL);
-
-              /* find the dot in the name, this cannot
-               * fail since it pasted the .desktop suffix check */
-              p = strrchr (name, '.');
-
-              /* get the new module internal name */
-              internal_name = g_strndup (name, p - name);
-
-              /* check if the modules name is already loaded */
-              if (G_UNLIKELY (g_hash_table_lookup (factory->modules, internal_name) != NULL))
-                goto already_loaded;
-
-              /* try to load the module */
-              module = panel_module_new_from_desktop_file (filename,
-                                                           internal_name,
-                                                           force_all_external);
-
-              if (G_LIKELY (module != NULL))
-                {
-                  /* add the module to the internal list */
-                  g_hash_table_insert (factory->modules, internal_name, module);
-
-                  /* check if this is the launcher */
-                  if (factory->has_launcher == FALSE
-                      && exo_str_is_equal (LAUNCHER_PLUGIN_NAME, internal_name))
-                    factory->has_launcher = TRUE;
-                }
-              else
-                {
-                  already_loaded:
-
-                  /* cleanup */
-                  g_free (internal_name);
-                }
-
-              /* cleanup */
-              g_free (filename);
-            }
-
-          /* close directory */
-          g_dir_close (dir);
+          /* add the module to the internal list */
+          g_hash_table_insert (factory->modules, internal_name, module);
+
+          /* check if this is the launcher */
+          if (factory->has_launcher == FALSE
+              && exo_str_is_equal (LAUNCHER_PLUGIN_NAME, internal_name))
+            factory->has_launcher = TRUE;
+        }
+      else
+        {
+          already_loaded:
+
+          /* cleanup */
+          g_free (internal_name);
         }
 
       /* cleanup */
-      g_free (path);
+      g_free (filename);
     }
 
-  /* cleanup */
-  g_strfreev (dirs);
+  /* close directory */
+  g_dir_close (dir);
 }
 
 
diff --git a/panel/panel-module.c b/panel/panel-module.c
index 5a350ea..3dc2acf 100644
--- a/panel/panel-module.c
+++ b/panel/panel-module.c
@@ -272,12 +272,12 @@ panel_module_plugin_destroyed (gpointer  user_data,
 PanelModule *
 panel_module_new_from_desktop_file (const gchar *filename,
                                     const gchar *name,
+                                    const gchar *lib_directory,
                                     gboolean     force_external)
 {
   PanelModule *module = NULL;
   XfceRc      *rc;
   const gchar *module_name;
-  const gchar *directory;
   const gchar *value;
   gchar       *path;
 
@@ -292,12 +292,11 @@ panel_module_new_from_desktop_file (const gchar *filename,
 
       /* read library location from the desktop file */
       module_name = xfce_rc_read_entry (rc, "X-XFCE-Module", NULL);
-      directory = xfce_rc_read_entry (rc, "X-XFCE-Module-Path", NULL);
 
-      if (G_LIKELY (module_name != NULL && directory != NULL))
+      if (G_LIKELY (module_name != NULL))
         {
           /* build the module path */
-          path = g_module_build_path (directory, module_name);
+          path = g_module_build_path (lib_directory, module_name);
 
           /* test if the library exists */
           if (G_LIKELY (g_file_test (path, G_FILE_TEST_EXISTS)))
diff --git a/panel/panel-module.h b/panel/panel-module.h
index fe9a17b..f84fee3 100644
--- a/panel/panel-module.h
+++ b/panel/panel-module.h
@@ -42,6 +42,7 @@ GType        panel_module_get_type                 (void) G_GNUC_CONST;
 
 PanelModule *panel_module_new_from_desktop_file    (const gchar             *filename,
                                                     const gchar             *name,
+                                                    const gchar             *lib_directory,
                                                     gboolean                 force_external) G_GNUC_MALLOC;
 
 GtkWidget   *panel_module_new_plugin               (PanelModule             *module,



More information about the Xfce4-commits mailing list