/soc/2013/ankitkv/gobjectification: 7a5cb79a8243: Refactored gtk...

Ankit Vani a at nevitus.org
Fri Aug 2 13:05:15 EDT 2013


Changeset: 7a5cb79a8243cf70dab7249a9addac92dc65e9b6
Author:	 Ankit Vani <a at nevitus.org>
Date:	 2013-08-02 22:34 +0530
Branch:	 soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/7a5cb79a8243

Description:

Refactored gtkplugin to use the new API. Handling of dependent plugins on unload is left till GPlugin implements it.

diffstat:

 pidgin/gtkplugin.c |  224 ++++++++++++++++++++++++++++------------------------
 1 files changed, 121 insertions(+), 103 deletions(-)

diffs (truncated from 501 to 300 lines):

diff --git a/pidgin/gtkplugin.c b/pidgin/gtkplugin.c
--- a/pidgin/gtkplugin.c
+++ b/pidgin/gtkplugin.c
@@ -44,9 +44,10 @@
 
 typedef struct
 {
+	PidginPluginConfigFrame get_config_frame;
 } PidginPluginInfoPrivate;
 
-static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model,
+static void plugin_toggled_stage_two(GPluginPlugin *plug, GtkTreeModel *model,
                                   GtkTreeIter *iter, gboolean unload);
 
 static GtkWidget *expander = NULL;
@@ -89,46 +90,66 @@ pidgin_plugin_info_get_type(void)
 }
 
 GtkWidget *
-pidgin_plugin_get_config_frame(PurplePlugin *plugin)
+pidgin_plugin_get_config_frame(GPluginPlugin *plugin)
 {
 	GtkWidget *config = NULL;
+	PurplePluginInfo *info;
+	PidginPluginInfoPrivate *priv = NULL;
 
 	g_return_val_if_fail(plugin != NULL, NULL);
 
-	if (PIDGIN_IS_PIDGIN_PLUGIN(plugin) && plugin->info->ui_info
-		&& PIDGIN_PLUGIN_UI_INFO(plugin)->get_config_frame)
+	info = PURPLE_PLUGIN_INFO(gplugin_plugin_get_info(plugin));
+	if (PIDGIN_IS_PLUGIN_INFO(info))
+		priv = PIDGIN_PLUGIN_INFO_GET_PRIVATE(info);
+
+	if (priv && priv->get_config_frame)
 	{
-		PidginPluginUiInfo *ui_info;
+		config = priv->get_config_frame(plugin);
 
-		ui_info = PIDGIN_PLUGIN_UI_INFO(plugin);
-
-		config = ui_info->get_config_frame(plugin);
-
-		if (plugin->info->prefs_info
-			&& plugin->info->prefs_info->get_plugin_pref_frame)
+		if (purple_plugin_info_get_pref_frame_callback(info))
 		{
 			purple_debug_warning("gtkplugin",
 				"Plugin %s contains both, ui_info and "
 				"prefs_info preferences; prefs_info will be "
-				"ignored.", plugin->info->name);
+				"ignored.",
+				gplugin_plugin_info_get_name(GPLUGIN_PLUGIN_INFO(info)));
 		}
 	}
-
-	if (config == NULL && plugin->info->prefs_info
-		&& plugin->info->prefs_info->get_plugin_pref_frame)
+	else if (purple_plugin_info_get_pref_frame_callback(info))
 	{
 		PurplePluginPrefFrame *frame;
+		PurplePluginPrefFrameCallback get_pref_frame =
+				purple_plugin_info_get_pref_frame_callback(info);
 
-		frame = plugin->info->prefs_info->get_plugin_pref_frame(plugin);
+		frame = get_pref_frame(plugin);
 
 		config = pidgin_plugin_pref_create_frame(frame);
-
-		plugin->info->prefs_info->frame = frame;
 	}
 
+	g_object_unref(info);
+
 	return config;
 }
 
+static gboolean
+pidgin_plugin_has_config_frame(GPluginPlugin *plugin)
+{
+	PurplePluginInfo *info = PURPLE_PLUGIN_INFO(gplugin_plugin_get_info(plugin));
+	PidginPluginInfoPrivate *priv = NULL;
+	gboolean ret;
+
+	g_return_val_if_fail(plugin != NULL, FALSE);
+
+	if (PIDGIN_IS_PLUGIN_INFO(info))
+		priv = PIDGIN_PLUGIN_INFO_GET_PRIVATE(info);
+
+	ret = ((priv && priv->get_config_frame) ||
+			purple_plugin_info_get_pref_frame_callback(info));
+
+	g_object_unref(info);
+	return ret;
+}
+
 void
 pidgin_plugins_save(void)
 {
@@ -140,44 +161,35 @@ update_plugin_list(void *data)
 {
 	GtkListStore *ls = GTK_LIST_STORE(data);
 	GtkTreeIter iter;
-	GList *probes;
-	PurplePlugin *plug;
+	GList *plugins, *l;
+	GPluginPlugin *plug;
+	GPluginPluginInfo *info;
 
 	gtk_list_store_clear(ls);
 	gplugin_plugin_manager_refresh();
 
-	for (probes = purple_plugins_get_all();
-		 probes != NULL;
-		 probes = probes->next)
+	plugins = purple_plugins_find_all();
+
+	for (l = plugins; l != NULL; l = l->next)
 	{
 		char *name;
 		char *version;
 		char *summary;
 		char *desc;
-		plug = probes->data;
-
-		if (plug->info->type == PURPLE_PLUGIN_LOADER) {
-			GList *cur;
-			for (cur = PURPLE_PLUGIN_LOADER_INFO(plug)->exts; cur != NULL;
-					 cur = cur->next)
-				purple_plugins_probe(cur->data);
-			continue;
-		} else if (plug->info->type != PURPLE_PLUGIN_STANDARD ||
-			(plug->info->flags & PURPLE_PLUGIN_FLAG_INVISIBLE)) {
-			continue;
-		}
+		plug = GPLUGIN_PLUGIN(l->data);
+		info = gplugin_plugin_get_info(plug);
 
 		gtk_list_store_append (ls, &iter);
 
-		if (plug->info->name) {
-			name = g_markup_escape_text(_(plug->info->name), -1);
+		if (gplugin_plugin_info_get_name(info)) {
+			name = g_markup_escape_text(_(gplugin_plugin_info_get_name(info)), -1);
 		} else {
-			char *tmp = g_path_get_basename(plug->path);
+			char *tmp = g_path_get_basename(gplugin_plugin_get_filename(plug));
 			name = g_markup_escape_text(tmp, -1);
 			g_free(tmp);
 		}
-		version = g_markup_escape_text(purple_plugin_get_version(plug), -1);
-		summary = g_markup_escape_text(purple_plugin_get_summary(plug), -1);
+		version = g_markup_escape_text(gplugin_plugin_info_get_version(info), -1);
+		summary = g_markup_escape_text(gplugin_plugin_info_get_summary(info), -1);
 
 		desc = g_strdup_printf("<b>%s</b> %s\n%s", name,
 				       version,
@@ -190,20 +202,24 @@ update_plugin_list(void *data)
 				   0, purple_plugin_is_loaded(plug),
 				   1, desc,
 				   2, plug,
-				   3, purple_plugin_is_unloadable(plug),
+				   3, !purple_plugin_info_is_loadable(PURPLE_PLUGIN_INFO(info)),
 				   -1);
 		g_free(desc);
+
+		g_object_unref(info);
 	}
+
+	purple_plugins_free_found_list(plugins);
 }
 
-static void plugin_loading_common(PurplePlugin *plugin, GtkTreeView *view, gboolean loaded)
+static void plugin_loading_common(GPluginPlugin *plugin, GtkTreeView *view, gboolean loaded)
 {
 	GtkTreeIter iter;
 	GtkTreeModel *model = gtk_tree_view_get_model(view);
 
 	if (gtk_tree_model_get_iter_first(model, &iter)) {
 		do {
-			PurplePlugin *plug;
+			GPluginPlugin *plug;
 			GtkTreeSelection *sel;
 
 			gtk_tree_model_get(model, &iter, 2, &plug, -1);
@@ -222,11 +238,7 @@ static void plugin_loading_common(Purple
 				if (plug == plugin)
 				{
 					gtk_widget_set_sensitive(pref_button,
-						loaded
-						&& ((PIDGIN_IS_PIDGIN_PLUGIN(plug) && plug->info->ui_info
-							&& PIDGIN_PLUGIN_UI_INFO(plug)->get_config_frame)
-						 || (plug->info->prefs_info
-							&& plug->info->prefs_info->get_plugin_pref_frame)));
+							loaded && pidgin_plugin_has_config_frame(plug));
 				}
 			}
 
@@ -235,19 +247,19 @@ static void plugin_loading_common(Purple
 	}
 }
 
-static void plugin_load_cb(PurplePlugin *plugin, gpointer data)
+static void plugin_load_cb(GPluginPlugin *plugin, gpointer data)
 {
 	GtkTreeView *view = (GtkTreeView *)data;
 	plugin_loading_common(plugin, view, TRUE);
 }
 
-static void plugin_unload_cb(PurplePlugin *plugin, gpointer data)
+static void plugin_unload_cb(GPluginPlugin *plugin, gpointer data)
 {
 	GtkTreeView *view = (GtkTreeView *)data;
 	plugin_loading_common(plugin, view, FALSE);
 }
 
-static void pref_dialog_response_cb(GtkWidget *d, int response, PurplePlugin *plug)
+static void pref_dialog_response_cb(GtkWidget *d, int response, GPluginPlugin *plug)
 {
 	switch (response) {
 	case GTK_RESPONSE_CLOSE:
@@ -259,18 +271,13 @@ static void pref_dialog_response_cb(GtkW
 		}
 		gtk_widget_destroy(d);
 
-		if (plug->info->prefs_info && plug->info->prefs_info->frame) {
-			purple_plugin_pref_frame_destroy(plug->info->prefs_info->frame);
-			plug->info->prefs_info->frame = NULL;
-		}
-
 		break;
 	}
 }
 
 static void plugin_unload_confirm_cb(gpointer *data)
 {
-	PurplePlugin *plugin = (PurplePlugin *)data[0];
+	GPluginPlugin *plugin = (GPluginPlugin *)data[0];
 	GtkTreeModel *model = (GtkTreeModel *)data[1];
 	GtkTreeIter *iter = (GtkTreeIter *)data[2];
 
@@ -284,17 +291,21 @@ static void plugin_toggled(GtkCellRender
 	GtkTreeModel *model = (GtkTreeModel *)data;
 	GtkTreeIter *iter = g_new(GtkTreeIter, 1);
 	GtkTreePath *path = gtk_tree_path_new_from_string(pth);
-	PurplePlugin *plug;
+	GPluginPlugin *plug;
+	PurplePluginInfo *info;
 	GtkWidget *dialog = NULL;
 
 	gtk_tree_model_get_iter(model, iter, path);
 	gtk_tree_path_free(path);
 	gtk_tree_model_get(model, iter, 2, &plug, -1);
 
+	info = PURPLE_PLUGIN_INFO(gplugin_plugin_get_info(plug));
+
 	/* Apparently, GTK+ won't honor the sensitive flag on cell renderers for booleans. */
-	if (purple_plugin_is_unloadable(plug))
+	if (!purple_plugin_info_is_loadable(info))
 	{
 		g_free(iter);
+		g_object_unref(info);
 		return;
 	}
 
@@ -322,10 +333,16 @@ static void plugin_toggled(GtkCellRender
 			for (l = plug->dependent_plugins ; l != NULL ; l = l->next)
 			{
 				const char *dep_name = (const char *)l->data;
-				PurplePlugin *dep_plugin = purple_plugins_find_with_id(dep_name);
+				GPluginPlugin *dep_plugin = gplugin_plugin_manager_find_plugin(dep_name);
+				GPluginPluginInfo *dep_info;
+
 				g_return_if_fail(dep_plugin != NULL);
 
-				g_string_append_printf(tmp, "\n\t%s\n", purple_plugin_get_name(dep_plugin));
+				dep_info = gplugin_plugin_get_info(dep_plugin);
+				g_string_append_printf(tmp, "\n\t%s\n", gplugin_plugin_info_get_name(dep_info));
+
+				g_object_unref(dep_info);
+				g_object_unref(dep_plugin);
 			}
 
 			cb_data = g_new(gpointer, 3);
@@ -345,10 +362,14 @@ static void plugin_toggled(GtkCellRender
 		else
 			plugin_toggled_stage_two(plug, model, iter, TRUE);
 	}
+
+	g_object_unref(info);
 }
 
-static void plugin_toggled_stage_two(PurplePlugin *plug, GtkTreeModel *model, GtkTreeIter *iter, gboolean unload)
+static void plugin_toggled_stage_two(GPluginPlugin *plug, GtkTreeModel *model, GtkTreeIter *iter, gboolean unload)
 {
+	PurplePluginInfo *info = PURPLE_PLUGIN_INFO(gplugin_plugin_get_info(plug));
+
 	if (unload)
 	{
 		pidgin_set_cursor(plugin_dialog, GDK_WATCH);



More information about the Commits mailing list