# HG changeset patch
# Node ID 9157b255ee95
# Parent  ef6d6a257756
diff --git a/finch/libfinch.c b/finch/libfinch.c
--- a/finch/libfinch.c
+++ b/finch/libfinch.c
@@ -72,17 +72,37 @@
 	return FALSE;
 }
 
+static void
+finch_plugins_init(void) {
+	GPluginManager *manager = NULL;
+	gchar *path = NULL;
+
+	manager = gplugin_manager_get_default();
+
+	gplugin_manager_append_paths_from_environment(manager,
+	                                              "FINCH_PLUGIN_PATH");
+
+	path = g_build_filename(purple_data_dir(), "plugins", NULL);
+	if(g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0 && errno != EEXIST) {
+		fprintf(stderr, "Couldn't create plugins dir\n");
+	}
+	gplugin_manager_append_path(manager, path);
+	g_free(path);
+
+	gplugin_manager_append_path(manager, FINCH_LIBDIR);
+
+	purple_plugins_refresh();
+}
+
 static int
 init_libpurple(int argc, char **argv)
 {
-	char *path;
 	gboolean opt_nologin = FALSE;
 	gboolean opt_version = FALSE;
 	gboolean opt_debug = FALSE;
 	char *opt_config_dir_arg = NULL;
 	GOptionContext *context;
 	gchar **args;
-	const gchar *plugin_path = NULL;
 	GError *error = NULL;
 
 	GOptionEntry option_entries[] = {
@@ -177,27 +197,7 @@
 		abort();
 	}
 
-	plugin_path = g_getenv("FINCH_PLUGIN_PATH");
-	if (plugin_path) {
-		gchar **paths;
-		gint i;
-
-		paths = g_strsplit(plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
-		for (i = 0; paths[i]; ++i) {
-			purple_plugins_add_search_path(paths[i]);
-		}
-
-		g_strfreev(paths);
-	}
-
-	path = g_build_filename(purple_data_dir(), "plugins", NULL);
-	if (g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR) != 0 && errno != EEXIST)
-		fprintf(stderr, "Couldn't create plugins dir\n");
-	purple_plugins_add_search_path(path);
-	g_free(path);
-
-	purple_plugins_add_search_path(FINCH_LIBDIR);
-	purple_plugins_refresh();
+	finch_plugins_init();
 
 	/* TODO: should this be moved into finch_prefs_init() ? */
 	finch_prefs_update_old();
diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -486,24 +486,13 @@
 purple_plugins_init(void)
 {
 	GPluginManager *manager = NULL;
-	const gchar *search_path;
 
 	gplugin_init(GPLUGIN_CORE_FLAGS_NONE);
 
 	manager = gplugin_manager_get_default();
 
-	search_path = g_getenv("PURPLE_PLUGIN_PATH");
-	if (search_path) {
-		gchar **paths;
-		gint i;
-
-		paths = g_strsplit(search_path, G_SEARCHPATH_SEPARATOR_S, 0);
-		for (i = 0; paths[i]; ++i) {
-			gplugin_manager_append_path(manager, paths[i]);
-		}
-
-		g_strfreev(paths);
-	}
+	gplugin_manager_append_paths_from_environment(manager,
+	                                              "PURPLE_PLUGIN_PATH");
 
 	gplugin_manager_add_default_paths(manager);
 
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -560,12 +560,12 @@
 # Check for GPlugin
 #######################################################################
 gplugin_dep = dependency('gplugin',
-	version : ['>=0.36.0', '<0.37.0'],
+	version : ['>=0.37.0', '<0.38.0'],
 	fallback : ['gplugin', 'gplugin_dep'])
 
 if get_option('gtkui')
 	gplugin_gtk_dep = dependency('gplugin-gtk3',
-		version : ['>=0.36.0', '<0.37.0'],
+		version : ['>=0.37.0', '<0.38.0'],
 		fallback : ['gplugin-gtk', 'gplugin_gtk3_dep'])
 endif
 
diff --git a/pidgin/pidginapplication.c b/pidgin/pidginapplication.c
--- a/pidgin/pidginapplication.c
+++ b/pidgin/pidginapplication.c
@@ -95,6 +95,35 @@
 G_DEFINE_TYPE(PidginApplication, pidgin_application, GTK_TYPE_APPLICATION)
 
 /******************************************************************************
+ * Helpers
+ *****************************************************************************/
+static void
+pidgin_application_init_plugins(void) {
+	GPluginManager *manager = gplugin_manager_get_default();
+
+	gplugin_manager_append_paths_from_environment(manager,
+	                                              "PIDGIN_PLUGIN_PATH");
+
+	if(g_getenv("PURPLE_PLUGINS_SKIP")) {
+		g_message("PURPLE_PLUGINS_SKIP environment variable set, skipping "
+		          "normal Pidgin plugin paths");
+	} else {
+		gchar *path = g_build_filename(purple_data_dir(), "plugins", NULL);
+
+		if(!g_file_test(path, G_FILE_TEST_IS_DIR)) {
+			g_mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
+		}
+
+		gplugin_manager_append_path(manager, path);
+		g_free(path);
+
+		gplugin_manager_append_path(manager, PIDGIN_LIBDIR);
+	}
+
+	purple_plugins_refresh();
+}
+
+/******************************************************************************
  * Actions
  *****************************************************************************/
 /**< private >
@@ -477,7 +506,6 @@
 	GError *error = NULL;
 	GList *active_accounts = NULL;
 	gchar *search_path = NULL;
-	const gchar *plugin_path = NULL;
 	gpointer handle = NULL;
 
 	G_APPLICATION_CLASS(pidgin_application_parent_class)->startup(application);
@@ -534,37 +562,7 @@
 		g_abort();
 	}
 
-	plugin_path = g_getenv("PIDGIN_PLUGIN_PATH");
-	if (plugin_path) {
-		gchar **paths;
-		gint i;
-
-		paths = g_strsplit(plugin_path, G_SEARCHPATH_SEPARATOR_S, 0);
-		for (i = 0; paths[i]; ++i) {
-			purple_plugins_add_search_path(paths[i]);
-		}
-
-		g_strfreev(paths);
-	}
-
-	if(g_getenv("PURPLE_PLUGINS_SKIP")) {
-		purple_debug_info("gtk",
-				"PURPLE_PLUGINS_SKIP environment variable "
-				"set, skipping normal Pidgin plugin paths");
-	} else {
-		search_path = g_build_filename(purple_data_dir(), "plugins", NULL);
-
-		if(!g_file_test(search_path, G_FILE_TEST_IS_DIR)) {
-			g_mkdir(search_path, S_IRUSR | S_IWUSR | S_IXUSR);
-		}
-
-		purple_plugins_add_search_path(search_path);
-		g_free(search_path);
-
-		purple_plugins_add_search_path(PIDGIN_LIBDIR);
-	}
-
-	purple_plugins_refresh();
+	pidgin_application_init_plugins();
 
 	/* load plugins we had when we quit */
 	purple_plugins_load_saved(PIDGIN_PREFS_ROOT "/plugins/loaded");
diff --git a/subprojects/gplugin.wrap b/subprojects/gplugin.wrap
--- a/subprojects/gplugin.wrap
+++ b/subprojects/gplugin.wrap
@@ -1,4 +1,4 @@
 [wrap-hg]
 directory = gplugin
 url = https://keep.imfreedom.org/gplugin/gplugin
-revision = v0.36.0
+revision = v0.37.0
