/pidgin/main: 7d4651f1035e: Plugins API: add an option to provid...
Tomasz Wasilczyk
twasilczyk at pidgin.im
Thu Oct 24 09:54:33 EDT 2013
Changeset: 7d4651f1035ef723448f45deacc6db9174bee650
Author: Tomasz Wasilczyk <twasilczyk at pidgin.im>
Date: 2013-10-24 15:54 +0200
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/7d4651f1035e
Description:
Plugins API: add an option to provide plugin configuration using Request API
diffstat:
finch/gntplugin.c | 120 +++++++++++---
finch/plugins/gnttinyurl.c | 1 +
libpurple/plugin.h | 1 +
libpurple/plugins/autoaccept.c | 1 +
libpurple/plugins/joinpart.c | 1 +
libpurple/plugins/log_reader.c | 1 +
libpurple/plugins/newline.c | 2 +
libpurple/plugins/offlinemsg.c | 1 +
libpurple/plugins/perl/perl.c | 2 +
libpurple/plugins/pluginpref_example.c | 2 +
libpurple/plugins/psychic.c | 1 +
libpurple/plugins/statenotify.c | 1 +
libpurple/util.c | 9 +
libpurple/util.h | 9 +
pidgin/gtkplugin.c | 266 ++++++++++++++++++++++----------
pidgin/gtkplugin.h | 11 -
pidgin/plugins/extplacement.c | 1 +
pidgin/plugins/markerline.c | 1 +
18 files changed, 307 insertions(+), 124 deletions(-)
diffs (truncated from 774 to 300 lines):
diff --git a/finch/gntplugin.c b/finch/gntplugin.c
--- a/finch/gntplugin.c
+++ b/finch/gntplugin.c
@@ -50,7 +50,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);
@@ -61,14 +74,31 @@ free_stringlist(GList *list)
g_list_free(list);
}
+static gboolean
+has_prefs(PurplePlugin *plugin)
+{
+ PurplePluginUiInfo *pinfo;
+
+ if (!purple_plugin_is_loaded(plugin))
+ return FALSE;
+
+ if (PURPLE_IS_GNT_PLUGIN(plugin) &&
+ FINCH_PLUGIN_UI_INFO(plugin) != NULL)
+ {
+ return TRUE;
+ }
+
+ pinfo = plugin->info->prefs_info;
+ if (!pinfo)
+ return FALSE;
+
+ return (pinfo->get_plugin_pref_frame || pinfo->get_plugin_pref_request);
+}
+
static void
decide_conf_button(PurplePlugin *plugin)
{
- if (purple_plugin_is_loaded(plugin) &&
- ((PURPLE_IS_GNT_PLUGIN(plugin) &&
- FINCH_PLUGIN_UI_INFO(plugin) != NULL) ||
- (plugin->info->prefs_info &&
- plugin->info->prefs_info->get_plugin_pref_frame)))
+ if (has_prefs(plugin))
gnt_widget_set_visible(plugins.conf, TRUE);
else
gnt_widget_set_visible(plugins.conf, FALSE);
@@ -78,6 +108,31 @@ decide_conf_button(PurplePlugin *plugin)
}
static void
+finch_plugin_pref_close(PurplePlugin *plugin)
+{
+ FinchPluginUiData *ui_data;
+
+ g_return_if_fail(plugin != NULL);
+
+ if (plugin->ui_data == NULL)
+ return;
+ ui_data = plugin->ui_data;
+
+ if (ui_data->type == FINCH_PLUGIN_UI_DATA_TYPE_REQUEST) {
+ purple_request_close(PURPLE_REQUEST_FIELDS,
+ ui_data->u.request_handle);
+ return;
+ }
+
+ g_return_if_fail(ui_data->type == FINCH_PLUGIN_UI_DATA_TYPE_WINDOW);
+
+ gnt_widget_destroy(ui_data->u.window);
+
+ g_free(ui_data);
+ plugin->ui_data = NULL;
+}
+
+static void
plugin_toggled_cb(GntWidget *tree, PurplePlugin *plugin, gpointer null)
{
if (gnt_tree_get_choice(GNT_TREE(tree), plugin))
@@ -89,18 +144,13 @@ plugin_toggled_cb(GntWidget *tree, Purpl
}
else
{
- GntWidget *win;
-
if (!purple_plugin_unload(plugin)) {
purple_notify_error(NULL, _("ERROR"), _("unloading plugin failed"), NULL, NULL);
purple_plugin_disable(plugin);
gnt_tree_set_choice(GNT_TREE(tree), plugin, TRUE);
}
- 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();
@@ -173,15 +223,12 @@ 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;
-static void
-remove_confwin(GntWidget *window, gpointer plugin)
-{
- g_hash_table_remove(confwins, plugin);
+ g_free(plugin->ui_data);
+ plugin->ui_data = NULL;
}
static void
@@ -189,6 +236,7 @@ configure_plugin_cb(GntWidget *button, g
{
PurplePlugin *plugin;
FinchPluginFrame callback;
+ FinchPluginUiData *ui_data;
g_return_if_fail(plugins.tree != NULL);
@@ -200,8 +248,9 @@ configure_plugin_cb(GntWidget *button, g
return;
}
- if (confwins && g_hash_table_lookup(confwins, plugin))
+ if (plugin->ui_data != NULL)
return;
+ plugin->ui_data = ui_data = g_new0(FinchPluginUiData, 1);
if (PURPLE_IS_GNT_PLUGIN(plugin) &&
(callback = FINCH_PLUGIN_UI_INFO(plugin)) != NULL)
@@ -227,25 +276,36 @@ 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 (plugin->info->prefs_info &&
+ plugin->info->prefs_info->get_plugin_pref_request)
+ {
+ gpointer handle;
+
+ ui_data->type = FINCH_PLUGIN_UI_DATA_TYPE_REQUEST;
+ ui_data->u.request_handle = handle = plugin->info->prefs_info->
+ get_plugin_pref_request(plugin);
+ purple_request_add_close_notify(handle,
+ purple_callback_set_zero, &plugin->ui_data);
+ purple_request_add_close_notify(handle, g_free, ui_data);
}
else if (plugin->info->prefs_info &&
plugin->info->prefs_info->get_plugin_pref_frame)
{
GntWidget *win = process_pref_frame(plugin->info->prefs_info->get_plugin_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);
- return;
+
+ 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);
- return;
+ purple_notify_info(plugin, _("Error"), _("No configuration "
+ "options for this plugin."), NULL, NULL);
+ g_free(ui_data);
+ plugin->ui_data = NULL;
}
}
diff --git a/finch/plugins/gnttinyurl.c b/finch/plugins/gnttinyurl.c
--- a/finch/plugins/gnttinyurl.c
+++ b/finch/plugins/gnttinyurl.c
@@ -465,6 +465,7 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
/* padding */
NULL,
diff --git a/libpurple/plugin.h b/libpurple/plugin.h
--- a/libpurple/plugin.h
+++ b/libpurple/plugin.h
@@ -173,6 +173,7 @@ struct _PurplePlugin
struct _PurplePluginUiInfo {
PurplePluginPrefFrame *(*get_plugin_pref_frame)(PurplePlugin *plugin);
+ gpointer (*get_plugin_pref_request)(PurplePlugin *plugin);
void (*_purple_reserved1)(void);
void (*_purple_reserved2)(void);
diff --git a/libpurple/plugins/autoaccept.c b/libpurple/plugins/autoaccept.c
--- a/libpurple/plugins/autoaccept.c
+++ b/libpurple/plugins/autoaccept.c
@@ -298,6 +298,7 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
/* padding */
NULL,
diff --git a/libpurple/plugins/joinpart.c b/libpurple/plugins/joinpart.c
--- a/libpurple/plugins/joinpart.c
+++ b/libpurple/plugins/joinpart.c
@@ -252,6 +252,7 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
/* padding */
NULL,
diff --git a/libpurple/plugins/log_reader.c b/libpurple/plugins/log_reader.c
--- a/libpurple/plugins/log_reader.c
+++ b/libpurple/plugins/log_reader.c
@@ -2909,6 +2909,7 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
/* padding */
NULL,
diff --git a/libpurple/plugins/newline.c b/libpurple/plugins/newline.c
--- a/libpurple/plugins/newline.c
+++ b/libpurple/plugins/newline.c
@@ -80,6 +80,8 @@ plugin_load(PurplePlugin *plugin)
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
+
/* Padding */
NULL,
NULL,
diff --git a/libpurple/plugins/offlinemsg.c b/libpurple/plugins/offlinemsg.c
--- a/libpurple/plugins/offlinemsg.c
+++ b/libpurple/plugins/offlinemsg.c
@@ -207,6 +207,7 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
/* padding */
NULL,
diff --git a/libpurple/plugins/perl/perl.c b/libpurple/plugins/perl/perl.c
--- a/libpurple/plugins/perl/perl.c
+++ b/libpurple/plugins/perl/perl.c
@@ -117,6 +117,8 @@ struct _PurplePerlInfoStrings
static PurplePluginUiInfo ui_info =
{
purple_perl_get_plugin_frame,
+ NULL,
+
/* Padding */
NULL,
NULL,
diff --git a/libpurple/plugins/pluginpref_example.c b/libpurple/plugins/pluginpref_example.c
--- a/libpurple/plugins/pluginpref_example.c
+++ b/libpurple/plugins/pluginpref_example.c
@@ -109,6 +109,8 @@ get_plugin_pref_frame(PurplePlugin *plug
static PurplePluginUiInfo prefs_info = {
get_plugin_pref_frame,
+ NULL,
+
/* Padding */
More information about the Commits
mailing list