/soc/2013/ankitkv/gobjectification: eed15b8d51a1: Merged soc.201...
Ankit Vani
a at nevitus.org
Thu Oct 24 14:27:10 EDT 2013
Changeset: eed15b8d51a11de5923fe6eb79a21601a282bb79
Author: Ankit Vani <a at nevitus.org>
Date: 2013-10-24 23:56 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/eed15b8d51a1
Description:
Merged soc.2013.gobjectification branch
diffstat:
ChangeLog.API | 1 +
finch/gntplugin.c | 136 +++++++++++++++-----
libpurple/plugins.c | 27 ++++
libpurple/plugins.h | 68 ++++++----
libpurple/plugins/perl/perl.c | 2 +
libpurple/util.c | 9 +
libpurple/util.h | 9 +
pidgin/gtkplugin.c | 271 ++++++++++++++++++++++++++++-------------
pidgin/gtkplugin.h | 11 -
9 files changed, 373 insertions(+), 161 deletions(-)
diffs (truncated from 855 to 300 lines):
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -86,6 +86,7 @@ version 3.0.0 (??/??/????):
* purple_plugin_info_get_license_text
* purple_plugin_info_get_license_url
* purple_plugin_info_get_pref_frame_callback
+ * purple_plugin_info_get_pref_request_callback
* purple_plugin_info_get_ui_data
* purple_plugin_info_set_ui_data
* purple_plugin_register_type
diff --git a/finch/gntplugin.c b/finch/gntplugin.c
--- a/finch/gntplugin.c
+++ b/finch/gntplugin.c
@@ -65,7 +65,20 @@ static struct
GntWidget *conf;
} plugins;
-static GHashTable *confwins;
+typedef struct
+{
+ enum
+ {
+ FINCH_PLUGIN_UI_DATA_TYPE_WINDOW,
+ FINCH_PLUGIN_UI_DATA_TYPE_REQUEST
+ } type;
+
+ union
+ {
+ GntWidget *window;
+ gpointer request_handle;
+ } u;
+} FinchPluginUiData;
static GntWidget *process_pref_frame(PurplePluginPrefFrame *frame);
@@ -167,26 +180,66 @@ free_stringlist(GList *list)
g_list_free(list);
}
+static gboolean
+has_prefs(PurplePlugin *plugin)
+{
+ PurplePluginInfo *info = purple_plugin_get_info(plugin);
+ FinchPluginInfoPrivate *priv = NULL;
+ gboolean ret;
+
+ g_return_val_if_fail(plugin != NULL, FALSE);
+
+ if (!purple_plugin_is_loaded(plugin))
+ return FALSE;
+
+ if (FINCH_IS_PLUGIN_INFO(info))
+ priv = FINCH_PLUGIN_INFO_GET_PRIVATE(info);
+
+ ret = ((priv && priv->get_pref_frame) ||
+ purple_plugin_info_get_pref_frame_callback(info) ||
+ purple_plugin_info_get_pref_request_callback(info));
+
+ return ret;
+}
+
static void
decide_conf_button(PurplePlugin *plugin)
{
- gboolean visible = FALSE;
- PurplePluginInfo *info = purple_plugin_get_info(plugin);
+ if (has_prefs(plugin))
+ gnt_widget_set_visible(plugins.conf, TRUE);
+ else
+ gnt_widget_set_visible(plugins.conf, FALSE);
- if (purple_plugin_is_loaded(plugin)) {
- FinchPluginInfoPrivate *priv = NULL;
- if (FINCH_IS_PLUGIN_INFO(info))
- priv = FINCH_PLUGIN_INFO_GET_PRIVATE(info);
+ gnt_box_readjust(GNT_BOX(plugins.window));
+ gnt_widget_draw(plugins.window);
+}
- if ((priv && priv->get_pref_frame) ||
- (purple_plugin_info_get_pref_frame_callback(info))) {
- visible = TRUE;
- }
+static void
+finch_plugin_pref_close(PurplePlugin *plugin)
+{
+ PurplePluginInfo *info;
+ FinchPluginUiData *ui_data;
+
+ g_return_if_fail(plugin != NULL);
+
+ info = purple_plugin_get_info(plugin);
+ ui_data = purple_plugin_info_get_ui_data(info);
+
+ if (!ui_data)
+ return;
+
+ if (ui_data->type == FINCH_PLUGIN_UI_DATA_TYPE_REQUEST) {
+ purple_request_close(PURPLE_REQUEST_FIELDS,
+ ui_data->u.request_handle);
+ return;
}
- gnt_widget_set_visible(plugins.conf, visible);
- gnt_box_readjust(GNT_BOX(plugins.window));
- gnt_widget_draw(plugins.window);
+ g_return_if_fail(ui_data->type == FINCH_PLUGIN_UI_DATA_TYPE_WINDOW);
+
+ gnt_widget_destroy(ui_data->u.window);
+
+ g_free(ui_data);
+ purple_plugin_info_set_ui_data(info, NULL);
}
static void
@@ -204,8 +257,6 @@ plugin_toggled_cb(GntWidget *tree, Purpl
}
else
{
- GntWidget *win;
-
if (!purple_plugin_unload(plugin, &error)) {
purple_notify_error(NULL, _("ERROR"), _("unloading plugin failed"), error->message, NULL);
purple_plugin_disable(plugin);
@@ -213,10 +264,7 @@ plugin_toggled_cb(GntWidget *tree, Purpl
g_error_free(error);
}
- if (confwins && (win = g_hash_table_lookup(confwins, plugin)) != NULL)
- {
- gnt_widget_destroy(win);
- }
+ finch_plugin_pref_close(plugin);
}
decide_conf_button(plugin);
finch_plugins_save_loaded();
@@ -309,15 +357,13 @@ plugin_compare(PurplePlugin *p1, PurpleP
}
static void
-confwin_init(void)
+remove_confwin(GntWidget *window, gpointer _plugin)
{
- confwins = g_hash_table_new(g_direct_hash, g_direct_equal);
-}
+ PurplePlugin *plugin = _plugin;
+ PurplePluginInfo *info = purple_plugin_get_info(plugin);
-static void
-remove_confwin(GntWidget *window, gpointer plugin)
-{
- g_hash_table_remove(confwins, plugin);
+ g_free(info->ui_data);
+ purple_plugin_info_set_ui_data(info, NULL);
}
static void
@@ -326,6 +372,7 @@ configure_plugin_cb(GntWidget *button, g
PurplePlugin *plugin;
PurplePluginInfo *info;
FinchPluginInfoPrivate *priv = NULL;
+ FinchPluginUiData *ui_data;
g_return_if_fail(plugins.tree != NULL);
@@ -337,10 +384,13 @@ configure_plugin_cb(GntWidget *button, g
return;
}
- if (confwins && g_hash_table_lookup(confwins, plugin))
+ info = purple_plugin_get_info(plugin);
+
+ if (purple_plugin_info_get_ui_data(info))
return;
+ ui_data = g_new0(FinchPluginUiData, 1);
+ purple_plugin_info_set_ui_data(info, ui_data);
- info = purple_plugin_get_info(plugin);
if (FINCH_IS_PLUGIN_INFO(info))
priv = FINCH_PLUGIN_INFO_GET_PRIVATE(info);
@@ -368,23 +418,35 @@ configure_plugin_cb(GntWidget *button, g
gnt_widget_show(window);
- if (confwins == NULL)
- confwin_init();
- g_hash_table_insert(confwins, plugin, window);
+ ui_data->type = FINCH_PLUGIN_UI_DATA_TYPE_WINDOW;
+ ui_data->u.window = window;
+ }
+ else if (purple_plugin_info_get_pref_request_callback(info))
+ {
+ PurplePluginPrefRequestCallback get_pref_request = purple_plugin_info_get_pref_request_callback(info);
+ gpointer handle;
+
+ ui_data->type = FINCH_PLUGIN_UI_DATA_TYPE_REQUEST;
+ ui_data->u.request_handle = handle = get_pref_request(plugin);
+ purple_request_add_close_notify(handle,
+ purple_callback_set_zero, &info->ui_data);
+ purple_request_add_close_notify(handle, g_free, ui_data);
}
else if (purple_plugin_info_get_pref_frame_callback(info))
{
PurplePluginPrefFrameCallback get_pref_frame = purple_plugin_info_get_pref_frame_callback(info);
GntWidget *win = process_pref_frame(get_pref_frame(plugin));
- if (confwins == NULL)
- confwin_init();
g_signal_connect(G_OBJECT(win), "destroy", G_CALLBACK(remove_confwin), plugin);
- g_hash_table_insert(confwins, plugin, win);
+
+ ui_data->type = FINCH_PLUGIN_UI_DATA_TYPE_WINDOW;
+ ui_data->u.window = win;
}
else
{
- purple_notify_info(plugin, _("Error"),
- _("No configuration options for this plugin."), NULL, NULL);
+ purple_notify_info(plugin, _("Error"), _("No configuration "
+ "options for this plugin."), NULL, NULL);
+ g_free(ui_data);
+ purple_plugin_info_set_ui_data(info, NULL);
}
}
diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -48,6 +48,9 @@ struct _PurplePluginInfoPrivate {
/** Callback that returns a preferences frame for a plugin */
PurplePluginPrefFrameCallback get_pref_frame;
+ /** Callback that returns a preferences request handle for a plugin */
+ PurplePluginPrefRequestCallback get_pref_request;
+
/** TRUE if a plugin has been unloaded at least once. Auto-load
* plugins that have been unloaded once will not be auto-loaded again. */
gboolean unloaded;
@@ -59,6 +62,7 @@ enum
PROP_UI_REQUIREMENT,
PROP_GET_ACTIONS,
PROP_PREFERENCES_FRAME,
+ PROP_PREFERENCES_REQUEST,
PROP_FLAGS,
PROP_LAST
};
@@ -377,6 +381,9 @@ purple_plugin_info_set_property(GObject
case PROP_PREFERENCES_FRAME:
priv->get_pref_frame = g_value_get_pointer(value);
break;
+ case PROP_PREFERENCES_REQUEST:
+ priv->get_pref_request = g_value_get_pointer(value);
+ break;
case PROP_FLAGS:
priv->flags = g_value_get_flags(value);
break;
@@ -402,6 +409,10 @@ purple_plugin_info_get_property(GObject
g_value_set_pointer(value,
purple_plugin_info_get_pref_frame_callback(info));
break;
+ case PROP_PREFERENCES_REQUEST:
+ g_value_set_pointer(value,
+ purple_plugin_info_get_pref_request_callback(info));
+ break;
case PROP_FLAGS:
g_value_set_flags(value, purple_plugin_info_get_flags(info));
break;
@@ -496,6 +507,12 @@ static void purple_plugin_info_class_ini
_("The callback that returns the preferences frame"),
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property(obj_class, PROP_PREFERENCES_REQUEST,
+ g_param_spec_pointer("preferences-request",
+ _("Preferences request callback"),
+ _("Callback that returns preferences request handle"),
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
g_object_class_install_property(obj_class, PROP_FLAGS,
g_param_spec_flags("flags",
_("Plugin flags"),
@@ -752,6 +769,16 @@ purple_plugin_info_get_pref_frame_callba
return priv->get_pref_frame;
}
+PurplePluginPrefRequestCallback
+purple_plugin_info_get_pref_request_callback(const PurplePluginInfo *info)
+{
+ PurplePluginInfoPrivate *priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(info);
+
+ g_return_val_if_fail(priv != NULL, NULL);
+
+ return priv->get_pref_request;
+}
+
PurplePluginInfoFlags
purple_plugin_info_get_flags(const PurplePluginInfo *info)
{
diff --git a/libpurple/plugins.h b/libpurple/plugins.h
--- a/libpurple/plugins.h
More information about the Commits
mailing list