/soc/2013/ankitkv/gobjectification: b1ce7f2998e4: Added purple_p...

Ankit Vani a at nevitus.org
Wed Aug 7 06:10:48 EDT 2013


Changeset: b1ce7f2998e4c1187d6bff828599d3e525f74f38
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-07 15:18 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/b1ce7f2998e4

Description:

Added purple_plugin_loads_on_query()

diffstat:

 libpurple/plugins.c                 |  39 ++++++++++++++++++++++++++++++++++++-
 libpurple/plugins.h                 |  16 ++++++++++++++-
 libpurple/protocols/null/nullprpl.c |   6 ++--
 3 files changed, 56 insertions(+), 5 deletions(-)

diffs (143 lines):

diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -102,7 +102,7 @@ purple_plugin_load(PurplePlugin *plugin)
 	loaded_plugins = g_list_append(loaded_plugins, plugin);
 
 	purple_debug_info("plugins", "Loaded plugin %s\n",
-			purple_plugin_get_filename(plugin));
+	                  purple_plugin_get_filename(plugin));
 
 	purple_signal_emit(purple_plugins_get_handle(), "plugin-load", plugin);
 
@@ -286,6 +286,23 @@ purple_plugin_is_loadable(const PurplePl
 	return priv->loadable;
 }
 
+gboolean
+purple_plugin_loads_on_query(const PurplePlugin *plugin)
+{
+#ifdef PURPLE_PLUGINS
+	GPluginPluginInfo *info;
+
+	g_return_val_if_fail(plugin != NULL, FALSE);
+
+	info = GPLUGIN_PLUGIN_INFO(purple_plugin_get_info(plugin));
+	return (gplugin_plugin_info_get_flags(info) &
+	        GPLUGIN_PLUGIN_INFO_FLAGS_LOAD_ON_QUERY);
+
+#else
+	return FALSE;
+#endif
+}
+
 gchar *
 purple_plugin_get_error(const PurplePlugin *plugin)
 {
@@ -766,7 +783,24 @@ void
 purple_plugins_refresh(void)
 {
 #ifdef PURPLE_PLUGINS
+	GList *plugins, *l;
+
 	gplugin_plugin_manager_refresh();
+
+	plugins = purple_plugins_find_all();
+	for (l = plugins; l != NULL; l = l->next) {
+		PurplePlugin *plugin = PURPLE_PLUGIN(l->data);
+		if (purple_plugin_is_loaded(plugin))
+			continue;
+
+		if (purple_plugin_loads_on_query(plugin)) {
+			purple_debug_info("plugins", "Auto-loading plugin %s\n",
+			                  purple_plugin_get_filename(plugin));
+			purple_plugin_load(plugin);
+		}
+	}
+
+	g_list_free(plugins);
 #endif
 }
 
@@ -821,6 +855,9 @@ purple_plugins_save_loaded(const char *k
 
 	for (pl = purple_plugins_get_loaded(); pl != NULL; pl = pl->next) {
 		PurplePlugin *plugin = PURPLE_PLUGIN(pl->data);
+		if (purple_plugin_loads_on_query(plugin))
+			continue;
+
 		if (!g_list_find(plugins_to_disable, plugin))
 			files = g_list_append(files, (gchar *)purple_plugin_get_filename(plugin));
 	}
diff --git a/libpurple/plugins.h b/libpurple/plugins.h
--- a/libpurple/plugins.h
+++ b/libpurple/plugins.h
@@ -69,6 +69,8 @@ typedef GPluginPluginClass PurplePluginC
 #define PURPLE_IS_PLUGIN_CLASS(klass)  G_IS_OBJECT_CLASS(klass)
 #define PURPLE_PLUGIN_GET_CLASS(obj)   G_OBJECT_GET_CLASS(obj)
 
+#define GPLUGIN_PLUGIN_INFO_FLAGS_LOAD_ON_QUERY 0
+
 typedef GObject PurplePlugin;
 typedef GObjectClass PurplePluginClass;
 
@@ -321,6 +323,16 @@ GList *purple_plugin_get_actions(const P
 gboolean purple_plugin_is_loadable(const PurplePlugin *plugin);
 
 /**
+ * Returns whether a plugin auto-loads on query or not. Plugins that auto-loaded
+ * on query are not saved by purple_plugins_save_loaded().
+ *
+ * @param plugin The plugin.
+ *
+ * @return @c TRUE if the plugin auto-loads on query, @c FALSE if it doesn't.
+ */
+gboolean purple_plugin_loads_on_query(const PurplePlugin *plugin);
+
+/**
  * If a plugin is not loadable, this returns the reason.
  *
  * @param plugin The plugin.
@@ -543,9 +555,11 @@ GList *purple_plugins_get_loaded(void);
 void purple_plugins_add_search_path(const gchar *path);
 
 /**
- * Forces a refresh of all plugins found in the search paths.
+ * Forces a refresh of all plugins found in the search paths, and loads plugins
+ * that are to be loaded on query.
  *
  * @see purple_plugins_add_search_path()
+ * @see purple_plugin_loads_on_query()
  */
 void purple_plugins_refresh(void);
 
diff --git a/libpurple/protocols/null/nullprpl.c b/libpurple/protocols/null/nullprpl.c
--- a/libpurple/protocols/null/nullprpl.c
+++ b/libpurple/protocols/null/nullprpl.c
@@ -69,7 +69,7 @@
 
 #define NULLPRPL_ID "prpl-null"
 static PurplePluginProtocolInfo *_null_protocol = NULL;
-static PurpleCmdId msg_cmd;
+static PurpleCmdId _msg_cmd;
 
 #define NULL_STATUS_ONLINE   "online"
 #define NULL_STATUS_AWAY     "away"
@@ -1169,7 +1169,7 @@ plugin_load(PurplePlugin *plugin)
   prpl_info.protocol_options = g_list_append(NULL, option);
 
   /* register whisper chat command, /msg */
-  msg_cmd = purple_cmd_register("msg",
+  _msg_cmd = purple_cmd_register("msg",
                     "ws",                  /* args: recipient and message */
                     PURPLE_CMD_P_DEFAULT,  /* priority */
                     PURPLE_CMD_FLAG_CHAT,
@@ -1197,7 +1197,7 @@ plugin_unload(PurplePlugin *plugin)
 {
   purple_debug_info("nullprpl", "shutting down\n");
 
-  purple_cmd_unregister(msg_cmd);
+  purple_cmd_unregister(_msg_cmd);
   purple_protocols_remove(_null_protocol);
 
   return TRUE;



More information about the Commits mailing list