Mercurial > pidgin
changeset 2170:c24595d3c364
[gaim-migrate @ 2180]
buddy_menu
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 27 Aug 2001 07:11:50 +0000 |
parents | b7807144bf44 |
children | b51cd9350d65 |
files | TODO src/buddy.c src/multi.h src/protocols/icq/gaim_icq.c src/protocols/irc/irc.c src/protocols/jabber/jabber.c src/protocols/msn/msn.c src/protocols/napster/napster.c src/protocols/oscar/oscar.c src/protocols/toc/toc.c src/protocols/yahoo/yay.c src/protocols/zephyr/zephyr.c src/prpl.h |
diffstat | 13 files changed, 180 insertions(+), 155 deletions(-) [+] |
line wrap: on
line diff
--- a/TODO Mon Aug 27 04:53:19 2001 +0000 +++ b/TODO Mon Aug 27 07:11:50 2001 +0000 @@ -4,8 +4,6 @@ GPG Encryption of messages Better way of showing away state - and possibly in main window Moving GTK/GDK and related things out of the prpls - All: buddy_menu: pass connection/name, get back glist of char* and - callback, which takes connection and name. easy enough. All: draw_join_chat (haven't thought about this yet) ICQ and Yahoo: checkbox in convo window (haven't though about it) Jabber: user registration (this is buggy anyway and should probably
--- a/src/buddy.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/buddy.c Mon Aug 27 07:11:50 2001 +0000 @@ -618,6 +618,17 @@ alias_dialog_bud(b); } +static void menu_click(GtkObject *obj, char *who) +{ + GList *list = gtk_object_get_user_data(obj); + GList *first = g_list_first(list); + struct proto_buddy_menu *pbm = list->data; + if (pbm->callback) + pbm->callback(pbm->gc, who); + g_list_foreach(first, (GFunc)g_free, NULL); + g_list_free(first); +} + void handle_click_buddy(GtkWidget *widget, GdkEventButton *event, struct buddy_show *b) { if (!b->connlist) return; @@ -673,6 +684,8 @@ while (cn) { g = (struct gaim_connection *)cn->data; if (g->prpl->buddy_menu) { + GList *mo = (*g->prpl->buddy_menu)(g, b->name); + menuitem = gtk_menu_item_new_with_label(g->username); gtk_menu_append(GTK_MENU(menu), menuitem); gtk_widget_show(menuitem); @@ -681,14 +694,41 @@ gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), conmenu); gtk_widget_show(conmenu); - (*g->prpl->buddy_menu)(conmenu, g, b->name); + while (mo) { + struct proto_buddy_menu *pbm = mo->data; + GtkWidget *button; + + button = gtk_menu_item_new_with_label(pbm->label); + gtk_signal_connect(GTK_OBJECT(button), "activate", + GTK_SIGNAL_FUNC(menu_click), b->name); + gtk_object_set_user_data(GTK_OBJECT(button), mo); + gtk_menu_append(GTK_MENU(conmenu), button); + gtk_widget_show(button); + + mo = mo->next; + } } cn = g_slist_next(cn); } } else { g = (struct gaim_connection *)cn->data; - if (g->prpl->buddy_menu) - (*g->prpl->buddy_menu)(menu, g, b->name); + if (g->prpl->buddy_menu) { + GList *mo = (*g->prpl->buddy_menu)(g, b->name); + + while (mo) { + struct proto_buddy_menu *pbm = mo->data; + GtkWidget *button; + + button = gtk_menu_item_new_with_label(pbm->label); + gtk_signal_connect(GTK_OBJECT(button), "activate", + GTK_SIGNAL_FUNC(menu_click), b->name); + gtk_object_set_user_data(GTK_OBJECT(button), mo); + gtk_menu_append(GTK_MENU(menu), button); + gtk_widget_show(button); + + mo = mo->next; + } + } } /* we send the menu widget so we can add menuitems within a plugin */
--- a/src/multi.h Mon Aug 27 04:53:19 2001 +0000 +++ b/src/multi.h Mon Aug 27 07:11:50 2001 +0000 @@ -85,6 +85,12 @@ int pos; }; +struct proto_buddy_menu { + char *label; + void (*callback)(struct gaim_connection *, char *); + struct gaim_connection *gc; +}; + /* now that we have our struct, we're going to need lots of them. Maybe even a list of them. */ extern GSList *connections;
--- a/src/protocols/icq/gaim_icq.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/icq/gaim_icq.c Mon Aug 27 07:11:50 2001 +0000 @@ -430,19 +430,21 @@ icq_SendInfoReq(id->link, atol(who)); } -static void icq_info(GtkObject *obj, char *who) { - serv_get_info(gtk_object_get_user_data(obj), who); +static void icq_info(struct gaim_connection *gc, char *who) { + serv_get_info(gc, who); } -static void icq_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { - GtkWidget *button; +static GList *icq_buddy_menu(struct gaim_connection *gc, char *who) { + GList *m = NULL; + struct proto_buddy_menu *pbm; - button = gtk_menu_item_new_with_label(_("Get Info")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(icq_info), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Info"); + pbm->callback = icq_info; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static GList *icq_user_opts() {
--- a/src/protocols/irc/irc.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/irc/irc.c Mon Aug 27 07:11:50 2001 +0000 @@ -24,7 +24,6 @@ #include <netdb.h> -#include <gtk/gtk.h> #include <unistd.h> #include <errno.h> #include <netinet/in.h> @@ -1978,9 +1977,8 @@ } /* Send out a ping request to the specified user */ -static void irc_send_ping(GtkObject *w, char *who) +static void irc_send_ping(struct gaim_connection *gc, char *who) { - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); struct irc_data *idata = (struct irc_data *)gc->proto_data; char buf[BUF_LEN]; @@ -2003,27 +2001,24 @@ write(idata->fd, buf, strlen(buf)); } -static void irc_send_whois(GtkObject *w, char *who) -{ - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); - irc_get_info(gc, who); -} - -static void irc_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) +static GList *irc_buddy_menu(struct gaim_connection *gc, char *who) { - GtkWidget *button; - - button = gtk_menu_item_new_with_label("Ping"); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_ping), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); - - button = gtk_menu_item_new_with_label("Whois"); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(irc_send_whois), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + GList *m = NULL; + struct proto_buddy_menu *pbm; + + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Ping"); + pbm->callback = irc_send_ping; + pbm->gc = gc; + m = g_list_append(m, pbm); + + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Whois"); + pbm->callback = irc_get_info; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; }
--- a/src/protocols/jabber/jabber.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/jabber/jabber.c Mon Aug 27 07:11:50 2001 +0000 @@ -1871,19 +1871,17 @@ } -static void jabber_info(GtkObject *obj, char *who) { - serv_get_info(gtk_object_get_user_data(obj), who); -} +static GList *jabber_buddy_menu(struct gaim_connection *gc, char *who) { + GList *m = NULL; + struct proto_buddy_menu *pbm; -static void jabber_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { - GtkWidget *button; - - button = gtk_menu_item_new_with_label(_("Get Info")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(jabber_info), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Info"); + pbm->callback = jabber_get_info; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static GList *jabber_away_states() {
--- a/src/protocols/msn/msn.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/msn/msn.c Mon Aug 27 07:11:50 2001 +0000 @@ -1,7 +1,6 @@ #include "config.h" #include <stdlib.h> -#include <gtk/gtk.h> #include <string.h> #include <errno.h> #include <stdio.h> @@ -1321,20 +1320,24 @@ } } -static void msn_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) +static GList *msn_buddy_menu(struct gaim_connection *gc, char *who) { + GList *m = NULL; + struct proto_buddy_menu *pbm; struct buddy *b = find_buddy(gc, who); - char buf[MSN_BUF_LEN]; - GtkWidget *button; + static char buf[MSN_BUF_LEN]; if (!b || !(b->uc >> 5)) - return; - - g_snprintf(buf, sizeof(buf), "Status: %s", msn_get_away_text(b->uc >> 5)); + return m; - button = gtk_menu_item_new_with_label(buf); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + g_snprintf(buf, sizeof(buf), "Status: %s", msn_get_away_text(b->uc >> 5)); + pbm->label = buf; + pbm->callback = NULL; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static void msn_add_buddy(struct gaim_connection *gc, char *who)
--- a/src/protocols/napster/napster.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/napster/napster.c Mon Aug 27 07:11:50 2001 +0000 @@ -1039,9 +1039,8 @@ } -static void nap_send_browse(GtkObject *w, char *who) +static void nap_send_browse(struct gaim_connection *gc, char *who) { - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); gchar buf[NAP_BUF_LEN]; g_snprintf(buf, NAP_BUF_LEN, "%s", who); @@ -1065,10 +1064,8 @@ gtk_widget_destroy(win); } -static void nap_show_search(GtkObject *w, void *omit) +static void nap_show_search(struct gaim_connection *gc, char *omit) { - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(w); - if (!search_dialog) { GtkWidget *window; @@ -1149,21 +1146,24 @@ gtk_widget_show(search_dialog->window); } -static void nap_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) +static GList *nap_buddy_menu(struct gaim_connection *gc, char *who) { - GtkWidget *button; + GList *m = NULL; + struct proto_buddy_menu *pbm; - button = gtk_menu_item_new_with_label("Browse Files"); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_send_browse), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Browse Files"); + pbm->callback = nap_send_browse; + pbm->gc = gc; + m = g_list_append(m, pbm); - button = gtk_menu_item_new_with_label("Search Napster"); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(nap_show_search), NULL); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Search Napster"); + pbm->callback = nap_show_search; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static char** nap_list_icon(int uc)
--- a/src/protocols/oscar/oscar.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/oscar/oscar.c Mon Aug 27 07:11:50 2001 +0000 @@ -2891,16 +2891,6 @@ return NULL; } -static void oscar_info(GtkObject *obj, char *who) { - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); - serv_get_info(gc, who); -} - -static void oscar_away_msg(GtkObject *obj, char *who) { - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); - serv_get_away_msg(gc, who); -} - static int gaim_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...) { va_list ap; struct gaim_connection *gc = sess->aux_data; @@ -3048,44 +3038,44 @@ } } -static void oscar_ask_direct_im(GtkObject *m, gchar *who) { +static void oscar_ask_direct_im(struct gaim_connection *gc, gchar *who) { char buf[BUF_LONG]; struct ask_do_dir_im *data = g_new0(struct ask_do_dir_im, 1); data->who = who; - data->gc = gtk_object_get_user_data(m); + data->gc = gc; g_snprintf(buf, sizeof(buf), _("You have selected to open a Direct IM connection with %s." " Doing this will let them see your IP address, and may be" " a security risk. Do you wish to continue?"), who); do_ask_dialog(buf, data, oscar_direct_im, oscar_cancel_direct_im); } -static void oscar_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { - GtkWidget *button; +static GList *oscar_buddy_menu(struct gaim_connection *gc, char *who) { + GList *m = NULL; + struct proto_buddy_menu *pbm; char *n = g_strdup(normalize(gc->username)); - button = gtk_menu_item_new_with_label(_("Get Info")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(oscar_info), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); - - button = gtk_menu_item_new_with_label(_("Get Away Msg")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(oscar_away_msg), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Info"); + pbm->callback = oscar_get_info; + pbm->gc = gc; + m = g_list_append(m, pbm); + + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Away Msg"); + pbm->callback = oscar_get_away_msg; + pbm->gc = gc; + m = g_list_append(m, pbm); if (strcmp(n, normalize(who))) { - button = gtk_menu_item_new_with_label(_("Direct IM")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(oscar_ask_direct_im), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Direct IM"); + pbm->callback = oscar_ask_direct_im; + pbm->gc = gc; + m = g_list_append(m, pbm); } g_free(n); + + return m; } static GList *oscar_user_opts()
--- a/src/protocols/toc/toc.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/toc/toc.c Mon Aug 27 07:11:50 2001 +0000 @@ -976,18 +976,6 @@ return NULL; } -static void toc_info(GtkObject * obj, char *who) -{ - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); - serv_get_info(gc, who); -} - -static void toc_dir_info(GtkObject * obj, char *who) -{ - struct gaim_connection *gc = (struct gaim_connection *)gtk_object_get_user_data(obj); - serv_get_dir(gc, who); -} - static void des_jc() { join_chat_entry = NULL; @@ -1029,21 +1017,24 @@ gtk_widget_show(join_chat_spin); } -static void toc_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) +static GList *toc_buddy_menu(struct gaim_connection *gc, char *who) { - GtkWidget *button; + GList *m = NULL; + struct proto_buddy_menu *pbm; - button = gtk_menu_item_new_with_label(_("Get Info")); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(toc_info), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Info"); + pbm->callback = toc_get_info; + pbm->gc = gc; + m = g_list_append(m, pbm); - button = gtk_menu_item_new_with_label(_("Get Dir Info")); - gtk_signal_connect(GTK_OBJECT(button), "activate", GTK_SIGNAL_FUNC(toc_dir_info), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("Get Dir Info"); + pbm->callback = toc_get_dir; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static GList *toc_user_opts()
--- a/src/protocols/yahoo/yay.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/yahoo/yay.c Mon Aug 27 07:11:50 2001 +0000 @@ -592,24 +592,29 @@ } } -static void yahoo_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { +static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) { + GList *m = NULL; + struct proto_buddy_menu *pbm; struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; - GtkWidget *button; struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, segfault and get the bug report. */ - char buf[1024]; + static char buf[1024]; if (b->uc & UC_NORMAL) - return; + return NULL; + pbm = g_new0(struct proto_buddy_menu, 1); if ((b->uc >> 5) != YAHOO_STATUS_CUSTOM) g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 5)); else g_snprintf(buf, sizeof buf, "Custom Status: %s", (char *)g_hash_table_lookup(yd->hash, b->name)); - button = gtk_menu_item_new_with_label(buf); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm->label = buf; + pbm->callback = NULL; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static GList *yahoo_away_states() {
--- a/src/protocols/zephyr/zephyr.c Mon Aug 27 04:53:19 2001 +0000 +++ b/src/protocols/zephyr/zephyr.c Mon Aug 27 07:11:50 2001 +0000 @@ -781,21 +781,18 @@ g_strdup(zephyr_normalize(who))); } -static void info_callback(GtkObject *obj, char *who) -{ - zephyr_zloc(gtk_object_get_user_data(obj), who); -} - -static void zephyr_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) +static GList *zephyr_buddy_menu(struct gaim_connection *gc, char *who) { - GtkWidget *button; + GList *m = NULL; + struct proto_buddy_menu *pbm; - button = gtk_menu_item_new_with_label(_("ZLocate")); - gtk_signal_connect(GTK_OBJECT(button), "activate", - GTK_SIGNAL_FUNC(info_callback), who); - gtk_object_set_user_data(GTK_OBJECT(button), gc); - gtk_menu_append(GTK_MENU(menu), button); - gtk_widget_show(button); + pbm = g_new0(struct proto_buddy_menu, 1); + pbm->label = _("ZLocate"); + pbm->callback = zephyr_zloc; + pbm->gc = gc; + m = g_list_append(m, pbm); + + return m; } static void zephyr_set_away(struct gaim_connection *gc, char *state, char *msg)
--- a/src/prpl.h Mon Aug 27 04:53:19 2001 +0000 +++ b/src/prpl.h Mon Aug 27 07:11:50 2001 +0000 @@ -80,6 +80,7 @@ void (* do_action)(struct gaim_connection *, char *); /* user_opts returns a GList* of g_malloc'd struct proto_user_opts */ GList *(* user_opts)(); + GList *(* buddy_menu)(struct gaim_connection *, char *); /* when UI plugins come, these will have to be reconciled by returning * structs indicating what kinds of information they want displayed. */ @@ -87,7 +88,6 @@ * have different src- dirs in src: src-common, src-gtk, src-cli, etc. * then have a prpl-base and prpl-UI stuff. people don't need to change * their UIs all that often anyway. */ - void (* buddy_menu)(GtkWidget *, struct gaim_connection *, char *); void (* draw_new_user)(GtkWidget *); void (* do_new_user)(); void (* draw_join_chat)(struct gaim_connection *, GtkWidget *);