[evolution] Allow to load modules from custom prefixes



commit c3f774af4d8929e1c6a247ed24431bb284309832
Author: Milan Crha <mcrha redhat com>
Date:   Thu Feb 25 08:04:55 2021 +0100

    Allow to load modules from custom prefixes
    
    This change loads modules not only from the install prefix,
    but tries to read it also from the ~/.local/share/evolution/modules
    and from the directories listed in the EDS_EXTRA_PREFIXES, which
    is a list of paths separated by colon (':').

 src/e-util/e-alert.c     | 58 ++++++++++++++++++++++++++++++----------------
 src/e-util/e-plugin.c    | 60 +++++++++++++++++++++++++++++++++---------------
 src/shell/CMakeLists.txt |  1 +
 src/shell/main.c         |  2 +-
 4 files changed, 81 insertions(+), 40 deletions(-)
---
diff --git a/src/e-util/e-alert.c b/src/e-util/e-alert.c
index c8823b80a1..3cc0936eac 100644
--- a/src/e-util/e-alert.c
+++ b/src/e-util/e-alert.c
@@ -308,13 +308,37 @@ e_alert_load (const gchar *path)
 }
 
 static void
-e_alert_load_tables (void)
+e_alert_load_directory (const gchar *dirname)
 {
        GDir *dir;
        const gchar *d;
+
+       dir = g_dir_open (dirname, 0, NULL);
+       if (dir == NULL) {
+               return;
+       }
+
+       while ((d = g_dir_read_name (dir))) {
+               gchar *path;
+
+               if (d[0] == '.')
+                       continue;
+
+               path = g_build_filename (dirname, d, NULL);
+               e_alert_load (path);
+               g_free (path);
+       }
+
+       g_dir_close (dir);
+}
+
+static void
+e_alert_load_tables (void)
+{
+       GPtrArray *variants;
        gchar *base;
        struct _e_alert_table *table;
-       gint i;
+       guint ii;
 
        if (alert_table != NULL)
                return;
@@ -325,32 +349,26 @@ e_alert_load_tables (void)
        table = g_malloc0 (sizeof (*table));
        table->domain = "builtin";
        table->alerts = g_hash_table_new (g_str_hash, g_str_equal);
-       for (i = 0; i < G_N_ELEMENTS (default_alerts); i++)
+       for (ii = 0; ii < G_N_ELEMENTS (default_alerts); ii++)
                g_hash_table_insert (
                        table->alerts, (gpointer)
-                       default_alerts[i].id, &default_alerts[i]);
+                       default_alerts[ii].id, &default_alerts[ii]);
        g_hash_table_insert (alert_table, (gpointer) table->domain, table);
 
        /* look for installed alert tables */
        base = g_build_filename (EVOLUTION_PRIVDATADIR, "errors", NULL);
-       dir = g_dir_open (base, 0, NULL);
-       if (dir == NULL) {
-               g_free (base);
-               return;
-       }
-
-       while ((d = g_dir_read_name (dir))) {
-               gchar *path;
+       variants = e_util_get_directory_variants (base, EVOLUTION_PREFIX, TRUE);
+       if (variants) {
+               for (ii = 0; ii < variants->len; ii++) {
+                       const gchar *dirname = g_ptr_array_index (variants, ii);
 
-               if (d[0] == '.')
-                       continue;
-
-               path = g_build_filename (base, d, NULL);
-               e_alert_load (path);
-               g_free (path);
+                       if (dirname && *dirname)
+                               e_alert_load_directory (dirname);
+               }
+               g_ptr_array_unref (variants);
+       } else {
+               e_alert_load_directory (base);
        }
-
-       g_dir_close (dir);
        g_free (base);
 }
 
diff --git a/src/e-util/e-plugin.c b/src/e-util/e-plugin.c
index 386233e4b9..21dc1d3d34 100644
--- a/src/e-util/e-plugin.c
+++ b/src/e-util/e-plugin.c
@@ -472,6 +472,33 @@ plugin_hook_load_subclass (GType type,
        g_hash_table_insert (hash_table, key, hook_class);
 }
 
+static void
+e_plugin_traverse_directory (const gchar *dirname,
+                            gint index)
+{
+       GDir *dir;
+       const gchar *d;
+
+       pd (printf ("scanning plugin dir '%s'\n", dirname));
+
+       dir = g_dir_open (dirname, 0, NULL);
+
+       if (!dir)
+               return;
+
+       while ((d = g_dir_read_name (dir))) {
+               if (g_str_has_suffix  (d, ".eplug")) {
+                       gchar *name;
+
+                       name = g_build_filename (dirname, d, NULL);
+                       ep_load (name, index);
+                       g_free (name);
+               }
+       }
+
+       g_dir_close (dir);
+}
+
 /**
  * e_plugin_load_plugins:
  *
@@ -484,6 +511,7 @@ gint
 e_plugin_load_plugins (void)
 {
        GSettings *settings;
+       GPtrArray *variants;
        gchar **strv;
        gint i;
 
@@ -511,32 +539,26 @@ e_plugin_load_plugins (void)
        g_strfreev (strv);
        g_object_unref (settings);
 
-       for (i = 0; i < 3; i++) {
-               GDir *dir;
-               const gchar *d;
-               const gchar *path = EVOLUTION_PLUGINDIR;
-
-               pd (printf ("scanning plugin dir '%s'\n", path));
+       variants = e_util_get_directory_variants (EVOLUTION_PLUGINDIR, EVOLUTION_PREFIX, TRUE);
 
-               dir = g_dir_open (path, 0, NULL);
-               if (dir == NULL) {
-                       /*g_warning("Could not find plugin path: %s", path);*/
-                       continue;
-               }
+       for (i = 0; i < 3; i++) {
+               if (variants) {
+                       guint jj;
 
-               while ((d = g_dir_read_name (dir))) {
-                       if (g_str_has_suffix  (d, ".eplug")) {
-                               gchar *name;
+                       for (jj = 0; jj < variants->len; jj++) {
+                               const gchar *dirname = g_ptr_array_index (variants, jj);
 
-                               name = g_build_filename (path, d, NULL);
-                               ep_load (name, i);
-                               g_free (name);
+                               if (dirname && *dirname)
+                                       e_plugin_traverse_directory (dirname, i);
                        }
+               } else {
+                       e_plugin_traverse_directory (EVOLUTION_PLUGINDIR, i);
                }
-
-               g_dir_close (dir);
        }
 
+       if (variants)
+               g_ptr_array_unref (variants);
+
        return 0;
 }
 
diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt
index 0fbf96e5b1..55d066966d 100644
--- a/src/shell/CMakeLists.txt
+++ b/src/shell/CMakeLists.txt
@@ -133,6 +133,7 @@ target_compile_definitions(evolution PRIVATE
        -DEVOLUTION_ICONDIR=\"${icondir}\"
        -DEVOLUTION_ICONDIR_IN_PREFIX=\"${SHARE_INSTALL_PREFIX}/icons\"
        -DEVOLUTION_MODULEDIR=\"${moduledir}\"
+       -DEVOLUTION_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
        -DEVOLUTION_RULEDIR=\"${privdatadir}\"
        -DEVOLUTION_TOOLSDIR=\"${privlibexecdir}\"
 )
diff --git a/src/shell/main.c b/src/shell/main.c
index 2f797ca9ca..e0d0f53dfe 100644
--- a/src/shell/main.c
+++ b/src/shell/main.c
@@ -407,7 +407,7 @@ create_default_shell (void)
        }
 
        /* Load all shared library modules. */
-       module_types = e_module_load_all_in_directory (EVOLUTION_MODULEDIR);
+       module_types = e_module_load_all_in_directory_and_prefixes (EVOLUTION_MODULEDIR, EVOLUTION_PREFIX);
        g_list_free_full (module_types, (GDestroyNotify) g_type_module_unuse);
 
        flags = G_APPLICATION_HANDLES_OPEN |


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