Mercurial > pidgin
changeset 8986:8cf32769ba1b
[gaim-migrate @ 9761]
" This patch adds a Plugin Actions menu item after the
Account Actions menu. The Plugin Actions menu is
populated from the added 'actions' slot in
GaimPluginInfo. As a demonstration, the Idle Maker
plugin has been converted to no longer require GTK code
and the Preferences interface just to perform its
actions. Instead, it uses a Plugin Action to spawn a
Fields Request.
There's also a minor fix for consistency in the menu
building for buddy actions. The pre-existing method for
instructing a menu list to display a separator was to
insert a NULL rather than a proto_buddy_menu into the
GList of actions. The code for the buddy menus was
instead checking for a proto_buddy_menu with a '-'
label. This has been fixed, and it now correctly uses
NULL to indicate a separator."
"Date: 2004-05-16 02:25
Sender: taliesein
Logged In: YES
user_id=77326
I need to add a callback to this patch to watch for
loading/unloading of plugins (to determine when to rebuild
the menu). Since the appropriate way to handle Plugin
Actions is still mildly up for debate, I'm holding of on
correcting the patch until I know for sure whether I should
fix this patch, or scrap it and write a new one using a
different method."
"Date: 2004-05-18 12:26
Sender: taliesein
Logged In: YES
user_id=77326
I've completed changes to this patch to also add plugin load
and unload signals (it looks like plugin.c actually had
pre-signal callbacks in place, but they were never used or
converted to signals)
This patch now will correctly update the Plugin Action menu
as plugins load and unload."
I'm not entirely sure i like the ui of a plugins actions menu, but i think
that having some way for plugins to add actions on an account is a good
thing, and i'm not sure that every viable action fits under the accounts
actions menu. we may want to merge the two (the existing accounts actions
and this plugins actions), but both times it came up in #gaim no one seemed
to want to comment, and on one commented to the gaim-devel post either.
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Thu, 20 May 2004 05:11:44 +0000 |
parents | 8abc99ed5d93 |
children | bac11276893c |
files | plugins/idle.c src/gtkblist.c src/gtkblist.h src/multi.h src/plugin.c src/plugin.h |
diffstat | 6 files changed, 238 insertions(+), 82 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/idle.c Thu May 20 03:11:52 2004 +0000 +++ b/plugins/idle.c Thu May 20 05:11:44 2004 +0000 @@ -7,28 +7,29 @@ #include "connection.h" #include "debug.h" +#include "multi.h" +#include "plugin.h" +#include "request.h" #include "server.h" -#include "gtkplugin.h" -#include "gtkutils.h" - #define IDLE_PLUGIN_ID "gtk-idle" -static GaimConnection *gc = NULL; -static void set_idle(GtkWidget *button, GtkWidget *spinner) { +static void +idle_action_ok(void *ignored, GaimRequestFields *fields) +{ time_t t; - int tm = CLAMP(gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spinner)), 0, G_MAXUSHORT); - GaimAccount *account; + int tm; + GaimAccount *acct; + GaimConnection *gc; - if (!gc) - return; - - account = gaim_connection_get_account(gc); + tm = gaim_request_fields_get_integer(fields, "mins"); + acct = gaim_request_fields_get_account(fields, "acct"); + gc = gaim_account_get_connection(acct); gaim_debug(GAIM_DEBUG_INFO, "idle", - "setting idle time for %s to %d\n", - gaim_account_get_username(account), tm); + "setting idle time for %s to %d\n", + gaim_account_get_username(acct), tm); time(&t); t -= 60 * tm; gc->last_sent_time = t; @@ -36,82 +37,60 @@ gc->is_idle = 0; } -static void select_account_cb(GtkWidget *opt, GaimAccount *account) + +static void +idle_action(GaimPlugin *plugin) { - gc = gaim_account_get_connection(account); -} + /* Use the super fancy request API */ -static void make_connect_menu(GtkWidget *box) { - GtkWidget *optmenu; + GaimRequestFields *request; + GaimRequestFieldGroup *group; + GaimRequestField *field; + + group = gaim_request_field_group_new(NULL); - optmenu = gaim_gtk_account_option_menu_new(NULL, FALSE, - G_CALLBACK(select_account_cb), NULL, NULL); - - gtk_box_pack_start(GTK_BOX(box), optmenu, FALSE, FALSE, 5); + field = gaim_request_field_account_new("acct", "Account", NULL); + gaim_request_field_account_set_show_all(field, FALSE); + gaim_request_field_group_add_field(group, field); + + field = gaim_request_field_int_new("mins", "Minutes", 10); + gaim_request_field_group_add_field(group, field); - if (gaim_connections_get_all()) - gc = gaim_connections_get_all()->data; - else - gc = NULL; + request = gaim_request_fields_new(); + gaim_request_fields_add_group(request, group); + + gaim_request_fields(plugin, + N_("I'dle Mak'er"), + _("Set Account Idle Time"), + NULL, + request, + _("_Set"), G_CALLBACK(idle_action_ok), + _("_Cancel"), NULL, + NULL); } -static GtkWidget * -get_config_frame(GaimPlugin *plugin) + +static GList * +actions(GaimPlugin *plugin) { - GtkWidget *ret; - GtkWidget *frame, *label; - GtkWidget *vbox, *hbox; - GtkAdjustment *adj; - GtkWidget *spinner, *button; - - ret = gtk_vbox_new(FALSE, 18); - gtk_container_set_border_width(GTK_CONTAINER(ret), 12); - - frame = gaim_gtk_make_frame(ret, _("Idle Time")); - - vbox = gtk_vbox_new(FALSE, 5); - gtk_container_add(GTK_CONTAINER(frame), vbox); - - hbox = gtk_hbox_new(FALSE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); - - label = gtk_label_new(_("Set")); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); + GList *l = NULL; + struct plugin_actions_menu *pam; - make_connect_menu(hbox); - - label = gtk_label_new(_("idle for")); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); - - adj = (GtkAdjustment *)gtk_adjustment_new(10, 0, G_MAXUSHORT, 1, 0, 0); - spinner = gtk_spin_button_new(adj, 0, 0); - gtk_box_pack_start(GTK_BOX(hbox), spinner, TRUE, TRUE, 0); + pam = g_new0(struct plugin_actions_menu, 1); + pam->label = _("Set Account Idle Time"); + pam->callback = idle_action; + pam->plugin = plugin; + l = g_list_append(l, pam); - label = gtk_label_new(_("minutes.")); - gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 5); - - hbox = gtk_hbox_new(TRUE, 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); - - button = gtk_button_new_with_mnemonic(_("_Set")); - gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 5); - g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(set_idle), spinner); - - gtk_widget_show_all(ret); - - return ret; + return l; } -static GaimGtkPluginUiInfo ui_info = -{ - get_config_frame -}; static GaimPluginInfo info = { GAIM_PLUGIN_API_VERSION, GAIM_PLUGIN_STANDARD, - GAIM_GTK_PLUGIN_TYPE, + NULL, 0, NULL, GAIM_PRIORITY_DEFAULT, @@ -125,13 +104,18 @@ NULL, NULL, NULL, - &ui_info, - NULL + NULL, + NULL, + NULL, + actions }; + static void init_plugin(GaimPlugin *plugin) { } + GAIM_INIT_PLUGIN(idle, init_plugin, info) +
--- a/src/gtkblist.c Thu May 20 03:11:52 2004 +0000 +++ b/src/gtkblist.c Thu May 20 05:11:44 2004 +0000 @@ -29,6 +29,7 @@ #include "notify.h" #include "prpl.h" #include "prefs.h" +#include "plugin.h" #include "request.h" #include "signals.h" #include "sound.h" @@ -99,7 +100,7 @@ } GaimGtkJoinChatData; -static GtkWidget *protomenu = NULL; +static GtkWidget *protomenu = NULL, *pluginmenu = NULL; GSList *gaim_gtk_blist_sort_methods = NULL; static struct gaim_gtk_blist_sort_method *current_sort_method = NULL; @@ -1094,16 +1095,15 @@ for(l = list; l; l = l->next) { struct proto_buddy_menu *pbm = l->data; - /* draw "-" titled menu items as a separator. Since the + /* draw NULL menu items as a separator. Since the pbm is not being used in a callback, it needs to be freed. Also, do some simple checking to prevent doubled-up separators */ - if('-' == *pbm->label) { + if(pbm == NULL) { if(! dup_separator) { gaim_separator(menu); dup_separator = TRUE; } - g_free(pbm); continue; } else { dup_separator = FALSE; @@ -1124,9 +1124,9 @@ for(l = list; l; l = l->next) { struct proto_buddy_menu *pbm = l->data; - /* draw "-" titled menu items as a separator. see previous, + /* draw NULL menu items as a separator. see previous, identical-looking code. */ - if('-' == *pbm->label) { + if(pbm == NULL) { if(! dup_separator) { gaim_separator(menu); dup_separator = TRUE; @@ -1213,7 +1213,7 @@ for(l = list; l; l = l->next) { struct proto_group_menu *pgm = l->data; - /* draw "-" titled menu items as a separator. see previous, + /* draw NULL menu items as a separator. see previous, identical-looking code. (in make_buddy_menu)*/ if(pgm == NULL) { if(! dup_separator) { @@ -2355,6 +2355,7 @@ { N_("/Tools/_Away"), NULL, NULL, 0, "<Branch>" }, { N_("/Tools/Buddy _Pounce"), NULL, NULL, 0, "<Branch>" }, { N_("/Tools/Account Ac_tions"), NULL, NULL, 0, "<Branch>" }, + { N_("/Tools/Pl_ugin Actions"), NULL, NULL, 0, "<Branch>" }, { "/Tools/sep1", NULL, NULL, 0, "<Separator>" }, { N_("/Tools/A_ccounts"), "<CTL>A", gaim_gtk_accounts_window_show, 0, "<StockItem>", GAIM_STOCK_ACCOUNTS }, { N_("/Tools/_File Transfers"), NULL, gaim_show_xfer_dialog, 0, "<StockItem>", GAIM_STOCK_FILE_TRANSFER }, @@ -2927,6 +2928,14 @@ gtk_widget_set_sensitive(widget, gaim_gtk_privacy_is_showable()); } + +static void +plugin_changed_cb(GaimPlugin *p, gpointer *data) +{ + gaim_gtk_blist_update_plugin_actions(); +} + + /* this is called on all sorts of signals, and we have no reason to pass * it anything, so it remains without arguments. If you need anything * more specific, do as below, and create another callback that calls @@ -3068,6 +3077,9 @@ protomenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Account Actions")); gaim_gtk_blist_update_protocol_actions(); + + pluginmenu = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Plugin Actions")); + gaim_gtk_blist_update_plugin_actions(); /****************************** GtkTreeView **********************************/ sw = gtk_scrolled_window_new(NULL,NULL); gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN); @@ -3282,6 +3294,11 @@ gaim_signal_connect(gaim_connections_get_handle(), "signed-off", gtkblist, GAIM_CALLBACK(sign_on_off_cb), list); + gaim_signal_connect(gaim_plugins_get_handle(), "plugin-load", + gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); + gaim_signal_connect(gaim_plugins_get_handle(), "plugin-unload", + gtkblist, GAIM_CALLBACK(plugin_changed_cb), NULL); + /* emit our created signal */ gaim_signal_emit(gaim_gtk_blist_get_handle(), "gtkblist-created", list); } @@ -3793,6 +3810,7 @@ gtkblist->bbox = NULL; g_object_unref(G_OBJECT(gtkblist->ift)); protomenu = NULL; + pluginmenu = NULL; awaymenu = NULL; gtkblist = NULL; @@ -4878,6 +4896,15 @@ pam->callback(pam->gc); } + +static void +plugin_act(GtkObject *obk, struct plugin_actions_menu *pam) +{ + if (pam->callback && pam->plugin) + pam->callback(pam->plugin); +} + + void gaim_gtk_blist_update_protocol_actions(void) { @@ -5008,3 +5035,104 @@ } } } + + + +void +gaim_gtk_blist_update_plugin_actions(void) +{ + GtkWidget *menuitem; + GtkWidget *submenu; + GaimPluginInfo *plugin_info = NULL; + GList *l; + GList *c; + struct plugin_actions_menu *pam; + int count = 0; + + if (pluginmenu == NULL) + return; + + for (l = gtk_container_get_children(GTK_CONTAINER(pluginmenu)); + l != NULL; + l = l->next) { + + menuitem = l->data; + pam = g_object_get_data(G_OBJECT(menuitem), "plugin_actions_menu"); + g_free(pam); + + gtk_container_remove(GTK_CONTAINER(pluginmenu), GTK_WIDGET(menuitem)); + } + + for (c = gaim_plugins_get_loaded(); c != NULL; c = c->next) { + plugin_info = ((GaimPlugin *)c->data)->info; + if (plugin_info->actions) + count++; + } + + if (count == 0) { + menuitem = gtk_menu_item_new_with_label(_("No actions available")); + gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); + gtk_widget_show(menuitem); + + } + else if (count == 1) { + GList *act; + GaimPlugin *plugin = NULL; + + for (c = gaim_plugins_get_loaded(); c != NULL; c = c->next) { + plugin = (GaimPlugin *) c->data; + plugin_info = plugin->info; + if (plugin_info->actions != NULL) + break; + } + + for (act = plugin_info->actions(plugin); act != NULL; act = act->next) { + if (act->data) { + struct plugin_actions_menu *pam = act->data; + menuitem = gtk_menu_item_new_with_label(pam->label); + gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); + g_signal_connect(G_OBJECT(menuitem), "activate", + G_CALLBACK(plugin_act), pam); + g_object_set_data(G_OBJECT(menuitem), "plugin_actions_menu", pam); + gtk_widget_show(menuitem); + } + else + gaim_separator(pluginmenu); + } + } + else { + for (c = gaim_plugins_get_loaded(); c != NULL; c = c->next) { + GList *act; + GaimPlugin *plugin; + + plugin = (GaimPlugin *) c->data; + plugin_info = plugin->info; + if (plugin_info->actions == NULL) + continue; + + menuitem = gtk_image_menu_item_new_with_label(plugin_info->name); + gtk_menu_shell_append(GTK_MENU_SHELL(pluginmenu), menuitem); + gtk_widget_show(menuitem); + + submenu = gtk_menu_new(); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); + gtk_widget_show(submenu); + + for (act = plugin_info->actions(plugin); act != NULL; act = act->next) { + if (act->data) { + struct plugin_actions_menu *pam = act->data; + menuitem = gtk_menu_item_new_with_label(pam->label); + gtk_menu_shell_append(GTK_MENU_SHELL(submenu), menuitem); + g_signal_connect(G_OBJECT(menuitem), "activate", + G_CALLBACK(plugin_act), pam); + g_object_set_data(G_OBJECT(menuitem), "plugin_actions_menu", pam); + gtk_widget_show(menuitem); + } + else { + gaim_separator(submenu); + } + } + } + } +} +
--- a/src/gtkblist.h Thu May 20 03:11:52 2004 +0000 +++ b/src/gtkblist.h Thu May 20 05:11:44 2004 +0000 @@ -209,6 +209,11 @@ void gaim_gtk_blist_update_protocol_actions(); /** + * Updates the plugin actions menu on the GTK+ buddy list window. + */ +void gaim_gtk_blist_update_plugin_actions(); + +/** * Determines if showing the join chat dialog is a valid action. * * @return Returns TRUE if there are accounts online capable of
--- a/src/multi.h Thu May 20 03:11:52 2004 +0000 +++ b/src/multi.h Thu May 20 05:11:44 2004 +0000 @@ -33,6 +33,12 @@ GaimConnection *gc; }; +struct plugin_actions_menu { + char *label; + void (*callback)(GaimPlugin *); + GaimPlugin *plugin; +}; + struct proto_buddy_menu { char *label; void (*callback)(GaimConnection *, const char *);
--- a/src/plugin.c Thu May 20 03:11:52 2004 +0000 +++ b/src/plugin.c Thu May 20 05:11:44 2004 +0000 @@ -73,6 +73,15 @@ static void (*unload_cb)(GaimPlugin *, void *) = NULL; static void *unload_cb_data = NULL; + +void * +gaim_plugins_get_handle(void) +{ + static int handle; + return &handle; +} + + #ifdef GAIM_PLUGINS static int is_so_file(const char *filename, const char *ext) @@ -355,6 +364,8 @@ if (load_cb != NULL) load_cb(plugin, load_cb_data); + gaim_signal_emit(gaim_plugins_get_handle(), "plugin-unload", plugin); + return TRUE; #else @@ -426,6 +437,9 @@ if (unload_cb != NULL) unload_cb(plugin, unload_cb_data); + /* I suppose this is the right place to call this... */ + gaim_signal_emit(gaim_plugins_get_handle(), "plugin-unload", plugin); + return TRUE; #else return TRUE; @@ -836,9 +850,22 @@ GaimPlugin *plugin; size_t i; + void *handle; + if (!g_module_supported()) return; + handle = gaim_plugins_get_handle(); + + gaim_debug_info("plugins", "registering plugin-load signal\n"); + gaim_signal_register(handle, "plugin-load", gaim_marshal_VOID__POINTER, NULL, + 1, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_PLUGIN)); + + gaim_debug_info("plugins", "registering plugin-unload signal\n"); + gaim_signal_register(handle, "plugin-unload", gaim_marshal_VOID__POINTER, NULL, + 1, gaim_value_new(GAIM_TYPE_SUBTYPE, GAIM_SUBTYPE_PLUGIN)); + + for (i = 0; i < search_path_count; i++) { if (search_paths[i] == NULL) continue;
--- a/src/plugin.h Thu May 20 03:11:52 2004 +0000 +++ b/src/plugin.h Thu May 20 05:11:44 2004 +0000 @@ -25,6 +25,7 @@ #ifndef _GAIM_PLUGIN_H_ #define _GAIM_PLUGIN_H_ +#include <glib/glist.h> #include <gmodule.h> #include "signals.h" #include "value.h" @@ -88,6 +89,7 @@ void *ui_info; void *extra_info; GaimPluginUiInfo *prefs_info; + GList *(*actions)(GaimPlugin *plugin); }; /** @@ -160,6 +162,10 @@ extern "C" { #endif + +void *gaim_plugins_get_handle(void); + + /**************************************************************************/ /** @name Plugin API */ /**************************************************************************/