Mercurial > pidgin
changeset 8940:b875f5d57b81
[gaim-migrate @ 9710]
Gray out the Join a Chat menu item when no online accounts support chats.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 16 May 2004 00:06:25 +0000 |
parents | 19885cb8a24c |
children | 71fddf3f340d |
files | plugins/docklet/docklet.c src/gtkblist.c src/gtkblist.h src/gtkprivacy.c src/gtkroomlist.c src/gtkutils.c src/gtkutils.h |
diffstat | 7 files changed, 85 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/docklet/docklet.c Sat May 15 23:04:08 2004 +0000 +++ b/plugins/docklet/docklet.c Sun May 16 00:06:25 2004 +0000 @@ -115,7 +115,7 @@ break; default: gaim_new_item_from_stock(menu, _("New Message..."), GAIM_STOCK_IM, G_CALLBACK(show_im_dialog), NULL, 0, 0, NULL); - gaim_new_item_from_stock(menu, _("Join A Chat..."), GAIM_STOCK_CHAT, G_CALLBACK(gaim_gtk_blist_show_join_chat), NULL, 0, 0, NULL); + gaim_new_item_from_stock(menu, _("Join A Chat..."), GAIM_STOCK_CHAT, G_CALLBACK(gaim_gtk_blist_joinchat_show), NULL, 0, 0, NULL); break; }
--- a/src/gtkblist.c Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkblist.c Sun May 16 00:06:25 2004 +0000 @@ -647,6 +647,22 @@ } static void +do_joinchat(GtkWidget *dialog, int id, GaimGtkJoinChatData *info) +{ + switch(id) + { + case GTK_RESPONSE_OK: + do_join_chat(info); + + break; + } + + gtk_widget_destroy(GTK_WIDGET(dialog)); + g_list_free(info->entries); + g_free(info); +} + +static void rebuild_joinchat_entries(GaimGtkJoinChatData *data) { GaimConnection *gc; @@ -734,7 +750,7 @@ } static void -join_chat_select_account_cb(GObject *w, GaimAccount *account, +joinchat_select_account_cb(GObject *w, GaimAccount *account, GaimGtkJoinChatData *data) { if (gaim_account_get_protocol(data->account) == @@ -750,60 +766,41 @@ } static gboolean -join_chat_check_account_func(GaimAccount *account) +joinchat_account_filter_func(GaimAccount *account) { GaimConnection *gc = gaim_account_get_connection(account); - - return (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->chat_info != NULL); + GaimPluginProtocolInfo *prpl_info = NULL; + + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); + + return (prpl_info->chat_info != NULL); } -static void -do_joinchat(GtkWidget *dialog, int id, GaimGtkJoinChatData *info) +gboolean +gaim_gtk_blist_joinchat_is_showable() { - switch(id) - { - case GTK_RESPONSE_OK: - do_join_chat(info); - - break; + GList *c; + GaimConnection *gc; + + for (c = gaim_connections_get_all(); c != NULL; c = c->next) { + gc = c->data; + + if (joinchat_account_filter_func(gaim_connection_get_account(gc))) + return TRUE; } - gtk_widget_destroy(GTK_WIDGET(dialog)); - g_list_free(info->entries); - g_free(info); + return FALSE; } void -gaim_gtk_blist_show_join_chat(void) +gaim_gtk_blist_joinchat_show(void) { GtkWidget *hbox, *vbox; GtkWidget *rowbox; GtkWidget *label; - GList *c; GaimGtkBuddyList *gtkblist; GtkWidget *img = NULL; - GaimConnection *gc = NULL; GaimGtkJoinChatData *data = NULL; - int numaccounts = 0; - - /* Count how many protocols support chat */ - for (c = gaim_connections_get_all(); c != NULL; c = c->next) - { - gc = c->data; - - if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat) - numaccounts++; - } - - if (numaccounts <= 0) - { - gaim_notify_error(NULL, NULL, - _("You are not currently signed on with any " - "protocols that have the ability to chat."), - NULL); - - return; - } gtkblist = GAIM_GTK_BLIST(gaim_get_blist()); img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, @@ -843,34 +840,25 @@ data->sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); - if (numaccounts > 1) - { - label = gtk_label_new_with_mnemonic(_("_Account:")); - gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); - gtk_size_group_add_widget(data->sg, label); - - data->account_menu = gaim_gtk_account_option_menu_new(NULL, FALSE, - G_CALLBACK(join_chat_select_account_cb), - join_chat_check_account_func, data); - gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); - gtk_label_set_mnemonic_widget(GTK_LABEL(label), - GTK_WIDGET(data->account_menu)); - gaim_set_accessible_label (data->account_menu, label); - } + label = gtk_label_new_with_mnemonic(_("_Account:")); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(rowbox), label, FALSE, FALSE, 0); + gtk_size_group_add_widget(data->sg, label); + + data->account_menu = gaim_gtk_account_option_menu_new(NULL, FALSE, + G_CALLBACK(joinchat_select_account_cb), + joinchat_account_filter_func, data); + gtk_box_pack_start(GTK_BOX(rowbox), data->account_menu, TRUE, TRUE, 0); + gtk_label_set_mnemonic_widget(GTK_LABEL(label), + GTK_WIDGET(data->account_menu)); + gaim_set_accessible_label (data->account_menu, label); data->entries_box = gtk_vbox_new(FALSE, 5); gtk_container_add(GTK_CONTAINER(vbox), data->entries_box); gtk_container_set_border_width(GTK_CONTAINER(data->entries_box), 0); - for (c = gaim_connections_get_all(); c != NULL; c = c->next) - { - gc = c->data; - - if (GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl)->join_chat) - break; - } - data->account = gaim_connection_get_account(gc); + data->account = gaim_gtk_account_option_menu_get_selected(data->account_menu); + rebuild_joinchat_entries(data); g_signal_connect(G_OBJECT(data->window), "response", @@ -896,7 +884,7 @@ return; } } - gaim_gtk_blist_show_join_chat(); + gaim_gtk_blist_joinchat_show(); } static void gtk_blist_button_away_cb(GtkWidget *w, gpointer data) @@ -2311,7 +2299,7 @@ /* Buddies menu */ { N_("/_Buddies"), NULL, NULL, 0, "<Branch>" }, { N_("/Buddies/New Instant _Message..."), "<CTL>M", show_im_dialog, 0, "<StockItem>", GAIM_STOCK_IM }, - { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_show_join_chat, 0, "<StockItem>", GAIM_STOCK_CHAT }, + { N_("/Buddies/Join a _Chat..."), "<CTL>C", gaim_gtk_blist_joinchat_show, 0, "<StockItem>", GAIM_STOCK_CHAT }, { N_("/Buddies/Get User _Info..."), "<CTL>I", show_info_dialog, 0, "<StockItem>", GAIM_STOCK_INFO }, { N_("/Buddies/View User _Log..."), "<CTL>L", show_log_dialog, 0, "<StockItem>" }, { "/Buddies/sep1", NULL, NULL, 0, "<Separator>" }, @@ -2890,6 +2878,10 @@ gaim_gtk_blist_update_protocol_actions(); gaim_gtkpounce_menu_build(gtkblist->bpmenu); + /* Make menu items sensitive/insensitive where appropriate */ + widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Buddies/Join a Chat...")); + gtk_widget_set_sensitive(widget, gaim_gtk_blist_joinchat_is_showable()); + widget = gtk_item_factory_get_widget(gtkblist->ift, N_("/Tools/Room List")); gtk_widget_set_sensitive(widget, gaim_gtk_roomlist_is_showable());
--- a/src/gtkblist.h Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkblist.h Sun May 16 00:06:25 2004 +0000 @@ -209,8 +209,16 @@ void gaim_gtk_blist_update_protocol_actions(); /** - * Shows the join chat dialog + * Determines if showing the join chat dialog is a valid action. + * + * @return Returns TRUE if there are accounts online capable of + * joining chat rooms. Otherwise returns FALSE. */ -void gaim_gtk_blist_show_join_chat(void); +gboolean gaim_gtk_blist_joinchat_is_showable(void); + +/** + * Shows the join chat dialog. + */ +void gaim_gtk_blist_joinchat_show(void); #endif /* _GAIM_GTK_LIST_H_ */
--- a/src/gtkprivacy.c Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkprivacy.c Sun May 16 00:06:25 2004 +0000 @@ -367,7 +367,6 @@ privacy_dialog_new(void) { GaimGtkPrivacyDialog *dialog; - GaimConnection *gc; GtkWidget *bbox; GtkWidget *hbox; GtkWidget *vbox; @@ -381,9 +380,6 @@ dialog = g_new0(GaimGtkPrivacyDialog, 1); - gc = (GaimConnection *)gaim_connections_get_all()->data; - dialog->account = gaim_connection_get_account(gc); - dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE); gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy"); @@ -419,12 +415,13 @@ gtk_widget_show(label); /* Accounts drop-down */ - dropdown = gaim_gtk_account_option_menu_new(dialog->account, FALSE, + dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE, G_CALLBACK(select_account_cb), check_account_func, dialog); gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0); gtk_widget_show(dropdown); gaim_set_accessible_label (dropdown, label); + dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown); /* Add the drop-down list with the allow/block types. */ dialog->type_menu = gtk_option_menu_new();
--- a/src/gtkroomlist.c Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkroomlist.c Sun May 16 00:06:25 2004 +0000 @@ -288,9 +288,6 @@ GaimConnection *gc = gaim_account_get_connection(account); GaimPluginProtocolInfo *prpl_info = NULL; -// if (!gc) -// return FALSE; - prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl); return (prpl_info->roomlist_get_list != NULL);
--- a/src/gtkutils.c Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkutils.c Sun May 16 00:06:25 2004 +0000 @@ -594,6 +594,14 @@ return optmenu; } +GaimAccount * +gaim_gtk_account_option_menu_get_selected(GtkWidget *optmenu) +{ + GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)); + GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu)); + return g_object_get_data(G_OBJECT(item), "account"); +} + static void account_menu_cb(GtkWidget *optmenu, GCallback cb) {
--- a/src/gtkutils.h Sat May 15 23:04:08 2004 +0000 +++ b/src/gtkutils.h Sun May 16 00:06:25 2004 +0000 @@ -248,6 +248,15 @@ GaimFilterAccountFunc filter_func, gpointer user_data); /** + * Gets the currently selected account from an account drop down box. + * + * @param optmenu The GtkOptionMenu created by + * gaim_gtk_account_option_menu_new. + * @return Returns the GaimAccount that is currently selected. + */ +GaimAccount *gaim_gtk_account_option_menu_get_selected(GtkWidget *optmenu); + +/** * Check if the given path is a directory or not. If it is, then modify * the given GtkFileSelection dialog so that it displays the given path. * If the given path is not a directory, then do nothing.