/soc/2013/ankitkv/gobjectification: 48c3419844f0: Undo action-re...
Ankit Vani
a at nevitus.org
Sat Aug 10 14:42:05 EDT 2013
Changeset: 48c3419844f09643b7b882bc4f9fa6210d9cd996
Author: Ankit Vani <a at nevitus.org>
Date: 2013-08-10 23:51 +0530
Branch: soc.2013.gobjectification.plugins
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/48c3419844f0
Description:
Undo action-related changes in UI
diffstat:
finch/gntblist.c | 71 ++++++++++++++++------------------------------------
libpurple/plugins.c | 12 +--------
libpurple/prpl.c | 2 +-
pidgin/gtkblist.c | 61 +++++++++++++++++++++++++++-----------------
pidgin/gtkdocklet.c | 26 ++++++++++++------
5 files changed, 78 insertions(+), 94 deletions(-)
diffs (truncated from 392 to 300 lines):
diff --git a/finch/gntblist.c b/finch/gntblist.c
--- a/finch/gntblist.c
+++ b/finch/gntblist.c
@@ -2450,53 +2450,25 @@ plugin_action(GntMenuItem *item, gpointe
}
static void
-build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin)
+build_plugin_actions(GntMenuItem *item, PurplePlugin *plugin, gpointer context)
{
GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP);
- GList *actions, *l;
+ GList *actions;
GntMenuItem *menuitem;
- actions = purple_plugin_get_actions(plugin);
-
gnt_menuitem_set_submenu(item, GNT_MENU(sub));
- for (l = actions; l; l = l->next) {
- if (l->data) {
- PurplePluginAction *action = l->data;
+ for (actions = PURPLE_PLUGIN_ACTIONS(plugin, context); actions;
+ actions = g_list_delete_link(actions, actions)) {
+ if (actions->data) {
+ PurplePluginAction *action = actions->data;
+ action->plugin = plugin;
+ action->context = context;
menuitem = gnt_menuitem_new(action->label);
gnt_menu_add_item(GNT_MENU(sub), menuitem);
gnt_menuitem_set_callback(menuitem, plugin_action, action);
- g_object_set_data(G_OBJECT(menuitem), "plugin_action", action);
- }
- }
-}
-
-static void
-protocol_action(GntMenuItem *item, gpointer data)
-{
- PurpleProtocolAction *action = data;
- if (action && action->callback)
- action->callback(action);
-}
-
-static void
-build_protocol_actions(GntMenuItem *item, PurplePluginProtocolInfo *prpl_info,
- PurpleConnection *gc)
-{
- GntWidget *sub = gnt_menu_new(GNT_MENU_POPUP);
- GList *l;
- GntMenuItem *menuitem;
-
- gnt_menuitem_set_submenu(item, GNT_MENU(sub));
- for (l = prpl_info->actions; l; l = l->next) {
- if (l->data) {
- PurpleProtocolAction *action = l->data;
- action->connection = gc;
- menuitem = gnt_menuitem_new(action->label);
- gnt_menu_add_item(GNT_MENU(sub), menuitem);
-
- gnt_menuitem_set_callback(menuitem, protocol_action, action);
- g_object_set_data(G_OBJECT(menuitem), "protocol_action", action);
+ g_object_set_data_full(G_OBJECT(menuitem), "plugin_action",
+ action, (GDestroyNotify)purple_plugin_action_free);
}
}
}
@@ -2565,16 +2537,17 @@ reconstruct_plugins_menu(void)
gnt_menuitem_set_submenu(plg, GNT_MENU(sub));
for (iter = purple_plugins_get_loaded(); iter; iter = iter->next) {
- PurplePlugin *plugin = PURPLE_PLUGIN(iter->data);
- PurplePluginInfo *plugin_info = purple_plugin_get_info(plugin);
+ PurplePlugin *plugin = iter->data;
GntMenuItem *item;
-
- if (!purple_plugin_get_actions(plugin))
+ if (PURPLE_IS_PROTOCOL_PLUGIN(plugin))
continue;
- item = gnt_menuitem_new(_(purple_plugin_info_get_name(plugin_info)));
+ if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin))
+ continue;
+
+ item = gnt_menuitem_new(_(plugin->info->name));
gnt_menu_add_item(GNT_MENU(sub), item);
- build_plugin_actions(item, plugin);
+ build_plugin_actions(item, plugin, NULL);
}
}
@@ -2599,16 +2572,16 @@ reconstruct_accounts_menu(void)
iter = g_list_delete_link(iter, iter)) {
PurpleAccount *account = iter->data;
PurpleConnection *gc = purple_account_get_connection(account);
- PurplePluginProtocolInfo *prpl_info;
+ PurplePlugin *prpl;
if (!gc || !PURPLE_CONNECTION_IS_CONNECTED(gc))
continue;
- prpl_info = purple_connection_get_protocol_info(gc);
-
- if (prpl_info->actions != NULL) {
+ prpl = purple_connection_get_prpl(gc);
+
+ if (PURPLE_PLUGIN_HAS_ACTIONS(prpl)) {
item = gnt_menuitem_new(purple_account_get_username(account));
gnt_menu_add_item(GNT_MENU(sub), item);
- build_protocol_actions(item, prpl_info, gc);
+ build_plugin_actions(item, prpl, gc);
}
}
}
diff --git a/libpurple/plugins.c b/libpurple/plugins.c
--- a/libpurple/plugins.c
+++ b/libpurple/plugins.c
@@ -151,10 +151,6 @@ purple_plugin_unload(PurplePlugin *plugi
purple_signals_disconnect_by_handle(plugin);
- while (priv->actions) {
- g_boxed_free(PURPLE_TYPE_PLUGIN_ACTION, priv->actions->data);
- priv->actions = g_list_delete_link(priv->actions, priv->actions);
- }
priv->unloaded = TRUE;
loaded_plugins = g_list_remove(loaded_plugins, plugin);
@@ -434,11 +430,6 @@ purple_plugin_info_finalize(GObject *obj
{
PurplePluginInfoPrivate *priv = PURPLE_PLUGIN_INFO_GET_PRIVATE(object);
- while (priv->actions) {
- g_boxed_free(PURPLE_TYPE_PLUGIN_ACTION, priv->actions->data);
- priv->actions = g_list_delete_link(priv->actions, priv->actions);
- }
-
g_free(priv->category);
g_free(priv->ui_requirement);
g_free(priv->error);
@@ -743,13 +734,12 @@ purple_plugin_action_new(const char* lab
{
PurplePluginAction *action;
- g_return_if_fail(label != NULL && callback != NULL);
+ g_return_val_if_fail(label != NULL && callback != NULL, NULL);
action = g_new0(PurplePluginAction, 1);
action->label = g_strdup(label);
action->callback = callback;
- action->plugin = plugin;
return action;
}
diff --git a/libpurple/prpl.c b/libpurple/prpl.c
--- a/libpurple/prpl.c
+++ b/libpurple/prpl.c
@@ -626,7 +626,7 @@ purple_protocol_action_new(const char* l
{
PurpleProtocolAction *action;
- g_return_if_fail(label != NULL && callback != NULL);
+ g_return_val_if_fail(label != NULL && callback != NULL, NULL);
action = g_new0(PurpleProtocolAction, 1);
diff --git a/pidgin/gtkblist.c b/pidgin/gtkblist.c
--- a/pidgin/gtkblist.c
+++ b/pidgin/gtkblist.c
@@ -8108,7 +8108,7 @@ plugin_act(GtkWidget *obj, PurplePluginA
static void
build_plugin_actions(GtkActionGroup *action_group, GString *ui, char *parent,
- PurplePlugin *plugin)
+ PurplePlugin *plugin, gpointer context)
{
GtkAction *menuaction;
PurplePluginAction *action = NULL;
@@ -8116,11 +8116,13 @@ build_plugin_actions(GtkActionGroup *act
char *name;
int count = 0;
- actions = purple_plugin_get_actions(plugin);
+ actions = PURPLE_PLUGIN_ACTIONS(plugin, context);
for (l = actions; l != NULL; l = l->next) {
if (l->data) {
action = (PurplePluginAction *)l->data;
+ action->plugin = plugin;
+ action->context = context;
name = g_strdup_printf("%s-action-%d", parent, count++);
menuaction = gtk_action_new(name, action->label, NULL, NULL);
@@ -8129,13 +8131,16 @@ build_plugin_actions(GtkActionGroup *act
g_signal_connect(G_OBJECT(menuaction), "activate",
G_CALLBACK(plugin_act), action);
- g_object_set_data(G_OBJECT(menuaction), "plugin_action",
- action);
+ g_object_set_data_full(G_OBJECT(menuaction), "plugin_action",
+ action,
+ (GDestroyNotify)purple_plugin_action_free);
g_free(name);
}
else
g_string_append(ui, "<separator/>");
}
+
+ g_list_free(actions);
}
@@ -8246,6 +8251,7 @@ pidgin_blist_update_accounts_menu(void)
PurpleConnection *gc = NULL;
PurpleAccount *account = NULL;
GdkPixbuf *pixbuf = NULL;
+ PurplePlugin *plugin = NULL;
PurplePluginProtocolInfo *prpl_info;
account = accounts->data;
@@ -8286,11 +8292,12 @@ pidgin_blist_update_accounts_menu(void)
pidgin_separator(submenu);
gc = purple_account_get_connection(account);
- prpl_info = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? purple_connection_get_protocol_info(gc) : NULL;
+ plugin = gc && PURPLE_CONNECTION_IS_CONNECTED(gc) ? purple_connection_get_prpl(gc) : NULL;
+ prpl_info = plugin ? PURPLE_PLUGIN_PROTOCOL_INFO(plugin) : NULL;
if (prpl_info &&
(PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) ||
- prpl_info->actions)) {
+ PURPLE_PLUGIN_HAS_ACTIONS(plugin))) {
if (PURPLE_PROTOCOL_PLUGIN_HAS_FUNC(prpl_info, get_moods) &&
(purple_connection_get_flags(gc) & PURPLE_CONNECTION_FLAG_SUPPORT_MOODS)) {
@@ -8302,30 +8309,36 @@ pidgin_blist_update_accounts_menu(void)
}
}
- if (prpl_info->actions) {
+ if (PURPLE_PLUGIN_HAS_ACTIONS(plugin)) {
GtkWidget *menuitem;
- PurpleProtocolAction *action = NULL;
- GList *l;
-
- for (l = prpl_info->actions; l != NULL; l = l->next)
+ PurplePluginAction *action = NULL;
+ GList *actions, *l;
+
+ actions = PURPLE_PLUGIN_ACTIONS(plugin, gc);
+
+ for (l = actions; l != NULL; l = l->next)
{
if (l->data)
{
- action = (PurpleProtocolAction *) l->data;
- action->connection = gc;
+ action = (PurplePluginAction *) l->data;
+ action->plugin = plugin;
+ action->context = gc;
menuitem = gtk_menu_item_new_with_label(action->label);
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem);
g_signal_connect(G_OBJECT(menuitem), "activate",
G_CALLBACK(plugin_act), action);
- g_object_set_data(G_OBJECT(menuitem), "protocol_action",
- action);
+ g_object_set_data_full(G_OBJECT(menuitem), "plugin_action",
+ action,
+ (GDestroyNotify)purple_plugin_action_free);
gtk_widget_show(menuitem);
}
else
pidgin_separator(submenu);
}
+
+ g_list_free(actions);
}
} else {
menuitem = gtk_menu_item_new_with_label(_("No actions available"));
@@ -8377,21 +8390,21 @@ pidgin_blist_update_plugin_actions(void)
/* Add a submenu for each plugin with custom actions */
for (l = purple_plugins_get_loaded(); l; l = l->next) {
char *name;
- PurplePluginInfo *info;
-
- plugin = PURPLE_PLUGIN(l->data);
- info = purple_plugin_get_info(plugin);
-
- if (!purple_plugin_get_actions(plugin))
+
+ plugin = (PurplePlugin *)l->data;
+
+ if (PURPLE_IS_PROTOCOL_PLUGIN(plugin))
continue;
+ if (!PURPLE_PLUGIN_HAS_ACTIONS(plugin))
+ continue;
+
More information about the Commits
mailing list