comparison src/gtkconv.c @ 7887:4b43a3f9de73

[gaim-migrate @ 8545] Change the New Instant Message shortcut to CTRL+M. Apparently CTRL+I is used for "italics." Also reworked how stuff in conv windows is hidden and grayed out when changing tabs and when accounts sign on and off. I had some problems with signing off and still being able to click the warn button and stuff, but that was probably caused by my changes from a few days ago. Anyway, this makes a lot more sense to me. I added a function that takes a conversation and updates all the buttons and menu items to be what they should be based on whether the conversation is an IM or a chat, and if the account is connected or not. It still has a few minor problems (tab icons don't become active after signing back in an account that was signed out), but I'll get to that in a day or 3. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Tue, 16 Dec 2003 05:29:37 +0000
parents c5a4d1863425
children d12b234959d5
comparison
equal deleted inserted replaced
7886:818835fb55cc 7887:4b43a3f9de73
2059 } 2059 }
2060 } 2060 }
2061 return status; 2061 return status;
2062 } 2062 }
2063 2063
2064 /*
2065 * Makes sure all the menu items and all the buttons are hidden/shown and
2066 * sensitive/insensitve. This is called after changing tabs and when an
2067 * account signs on or off.
2068 */
2069 static void
2070 gray_stuff_out(GaimConversation *conv)
2071 {
2072 GaimConvWindow *win;
2073 GaimGtkWindow *gtkwin;
2074 GaimGtkConversation *gtkconv;
2075 GaimConnection *gc;
2076 GaimPluginProtocolInfo *prpl_info = NULL;
2077 GdkPixbuf *window_icon = NULL;
2078
2079 win = gaim_conversation_get_window(conv);
2080 gtkwin = GAIM_GTK_WINDOW(win);
2081 gtkconv = GAIM_GTK_CONVERSATION(conv);
2082 gc = gaim_conversation_get_gc(conv);
2083
2084 if (gc != NULL)
2085 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
2086
2087 if (gtkwin->menu.send_as != NULL)
2088 g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
2089
2090 /*
2091 * Handle hiding and showing stuff based on what type of conv this is.
2092 */
2093 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
2094 /* Show stuff that applies to IMs, hide stuff that applies to chats */
2095
2096 /* Deal with buttons */
2097 gtk_widget_show(gtkconv->info);
2098 gtk_widget_show(gtkconv->send);
2099 gtk_widget_show(gtkconv->u.im->warn);
2100 gtk_widget_show(gtkconv->u.im->block);
2101 gtk_widget_show(gtkconv->u.im->add);
2102
2103 /* Deal with the toolbar */
2104 gtk_widget_show(gtkconv->toolbar.image);
2105
2106 /* Deal with menu items */
2107 gtk_widget_show(gtkwin->menu.view_log);
2108 gtk_widget_show(gtkwin->menu.add_pounce);
2109 gtk_widget_show(gtkwin->menu.get_info);
2110 gtk_widget_show(gtkwin->menu.warn);
2111 gtk_widget_hide(gtkwin->menu.invite);
2112 gtk_widget_show(gtkwin->menu.alias);
2113 gtk_widget_show(gtkwin->menu.block);
2114
2115 if (gaim_find_buddy(gaim_conversation_get_account(conv),
2116 gaim_conversation_get_name(conv)) == NULL) {
2117 gtk_widget_show(gtkwin->menu.add);
2118 gtk_widget_hide(gtkwin->menu.remove);
2119 } else {
2120 gtk_widget_show(gtkwin->menu.remove);
2121 gtk_widget_hide(gtkwin->menu.add);
2122 }
2123
2124 gtk_widget_show(gtkwin->menu.insert_link);
2125 gtk_widget_show(gtkwin->menu.insert_image);
2126 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
2127 /* Show stuff that applies to IMs, hide stuff that applies to chats */
2128
2129 /* Deal with buttons */
2130 gtk_widget_hide(gtkconv->info);
2131 gtk_widget_show(gtkconv->send);
2132 gtk_widget_show(gtkconv->u.chat->invite);
2133
2134 /* Deal with the toolbar */
2135 gtk_widget_hide(gtkconv->toolbar.image);
2136
2137 /* Deal with menu items */
2138 gtk_widget_hide(gtkwin->menu.view_log);
2139 gtk_widget_hide(gtkwin->menu.add_pounce);
2140 gtk_widget_hide(gtkwin->menu.get_info);
2141 gtk_widget_hide(gtkwin->menu.warn);
2142 gtk_widget_show(gtkwin->menu.invite);
2143 gtk_widget_show(gtkwin->menu.alias);
2144 gtk_widget_hide(gtkwin->menu.block);
2145
2146 if (gaim_blist_find_chat(gaim_conversation_get_account(conv),
2147 gaim_conversation_get_name(conv)) == NULL) {
2148 gtk_widget_show(gtkwin->menu.add);
2149 gtk_widget_hide(gtkwin->menu.remove);
2150 } else {
2151 gtk_widget_show(gtkwin->menu.remove);
2152 gtk_widget_hide(gtkwin->menu.add);
2153 }
2154
2155 gtk_widget_show(gtkwin->menu.insert_link);
2156 gtk_widget_hide(gtkwin->menu.insert_image);
2157 }
2158
2159 /*
2160 * Handle graying stuff out based on whether an account is connected
2161 * and what features that account supports.
2162 */
2163 if (gc != NULL) {
2164 /* Account is online */
2165
2166 /* Deal with buttons */
2167 gtk_widget_set_sensitive(gtkconv->info, (prpl_info->get_info != NULL));
2168 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
2169 gtk_widget_set_sensitive(gtkconv->send, TRUE);
2170 gtk_widget_set_sensitive(gtkconv->u.im->warn,
2171 (prpl_info->warn != NULL));
2172 gtk_widget_set_sensitive(gtkconv->u.im->block,
2173 (prpl_info->add_deny != NULL));
2174 gtk_widget_set_sensitive(gtkconv->u.im->add, TRUE);
2175 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
2176 gtk_widget_set_sensitive(gtkconv->send, (prpl_info->chat_send != NULL));
2177 gtk_widget_set_sensitive(gtkconv->u.chat->invite,
2178 (prpl_info->chat_invite != NULL));
2179 }
2180
2181 /* Deal with the toolbar */
2182 gtk_widget_set_sensitive(gtkconv->toolbar.image,
2183 (prpl_info->options & OPT_PROTO_IM_IMAGE));
2184
2185 /* Deal with menu items */
2186 gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE);
2187 gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE);
2188 gtk_widget_set_sensitive(gtkwin->menu.get_info, (prpl_info->get_info != NULL));
2189 gtk_widget_set_sensitive(gtkwin->menu.warn, (prpl_info->warn != NULL));
2190 gtk_widget_set_sensitive(gtkwin->menu.invite,
2191 (prpl_info->chat_invite != NULL));
2192
2193 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
2194 if (gaim_find_buddy(gaim_conversation_get_account(conv),
2195 gaim_conversation_get_name(conv)) == NULL)
2196 gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
2197 else
2198 gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
2199 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
2200 if (gaim_blist_find_chat(gaim_conversation_get_account(conv),
2201 gaim_conversation_get_name(conv)) == NULL)
2202 gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
2203 else
2204 gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
2205 }
2206
2207 gtk_widget_set_sensitive(gtkwin->menu.block, TRUE);
2208 gtk_widget_set_sensitive(gtkwin->menu.add, TRUE);
2209 gtk_widget_set_sensitive(gtkwin->menu.remove, TRUE);
2210 gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE);
2211 gtk_widget_set_sensitive(gtkwin->menu.insert_image,
2212 (prpl_info->options & OPT_PROTO_IM_IMAGE));
2213 } else {
2214 /* Account is offline */
2215
2216 /* Deal with buttons */
2217 gtk_widget_set_sensitive(gtkconv->info, FALSE);
2218 gtk_widget_set_sensitive(gtkconv->send, FALSE);
2219 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
2220 gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE);
2221 gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE);
2222 gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE);
2223 } else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
2224 gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE);
2225 }
2226
2227 /* Deal with the toolbar */
2228 gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
2229
2230 /* Then deal with menu items */
2231 gtk_widget_set_sensitive(gtkwin->menu.view_log, TRUE);
2232 gtk_widget_set_sensitive(gtkwin->menu.add_pounce, TRUE);
2233 gtk_widget_set_sensitive(gtkwin->menu.get_info, FALSE);
2234 gtk_widget_set_sensitive(gtkwin->menu.warn, FALSE);
2235 gtk_widget_set_sensitive(gtkwin->menu.invite, FALSE);
2236 gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
2237 gtk_widget_set_sensitive(gtkwin->menu.block, FALSE);
2238 gtk_widget_set_sensitive(gtkwin->menu.add, FALSE);
2239 gtk_widget_set_sensitive(gtkwin->menu.remove, FALSE);
2240 gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE);
2241 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
2242 }
2243
2244 /*
2245 * Update the window's icon
2246 */
2247 if ((gaim_conversation_get_type(conv) == GAIM_CONV_IM) && (gtkconv->u.im->anim)) {
2248 window_icon = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
2249 g_object_ref(window_icon);
2250 } else {
2251 window_icon = get_tab_icon(conv);
2252 }
2253 gtk_window_set_icon(GTK_WINDOW(gtkwin->window), window_icon);
2254 g_object_unref(G_OBJECT(window_icon));
2255 }
2256
2064 static void 2257 static void
2065 switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num, 2258 switch_conv_cb(GtkNotebook *notebook, GtkWidget *page, gint page_num,
2066 gpointer user_data) 2259 gpointer user_data)
2067 { 2260 {
2068 GaimPluginProtocolInfo *prpl_info = NULL;
2069 GaimConvWindow *win; 2261 GaimConvWindow *win;
2070 GaimConversation *conv; 2262 GaimConversation *conv;
2071 GaimGtkConversation *gtkconv; 2263 GaimGtkConversation *gtkconv;
2072 GaimGtkWindow *gtkwin; 2264 GaimGtkWindow *gtkwin;
2073 GaimConnection *gc;
2074 GdkPixbuf *window_icon = NULL;
2075 2265
2076 win = (GaimConvWindow *)user_data; 2266 win = (GaimConvWindow *)user_data;
2077
2078 conv = gaim_conv_window_get_conversation_at(win, page_num); 2267 conv = gaim_conv_window_get_conversation_at(win, page_num);
2079 2268
2080 g_return_if_fail(conv != NULL); 2269 g_return_if_fail(conv != NULL);
2081 2270
2082 gc = gaim_conversation_get_gc(conv);
2083 gtkwin = GAIM_GTK_WINDOW(win); 2271 gtkwin = GAIM_GTK_WINDOW(win);
2084 gtkconv = GAIM_GTK_CONVERSATION(conv); 2272 gtkconv = GAIM_GTK_CONVERSATION(conv);
2085 2273
2086 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); 2274 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE);
2087 2275
2088 if (gc != NULL)
2089 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
2090
2091 /* Update the menubar */ 2276 /* Update the menubar */
2092 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) { 2277 gray_stuff_out(conv);
2093 gtk_widget_show(gtkwin->menu.view_log);
2094 gtk_widget_show(gtkwin->menu.add_pounce);
2095 gtk_widget_show(gtkwin->menu.get_info);
2096 gtk_widget_hide(gtkwin->menu.invite);
2097
2098 gtk_widget_show(gtkwin->menu.insert_link);
2099
2100 gtk_widget_show(gtkwin->menu.insert_image);
2101 if (gc && prpl_info->options & OPT_PROTO_IM_IMAGE)
2102 gtk_widget_set_sensitive(gtkwin->menu.insert_image, TRUE);
2103 else
2104 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
2105
2106 gtk_widget_show(gtkwin->menu.warn);
2107 if (gc && prpl_info->warn != NULL)
2108 gtk_widget_set_sensitive(gtkwin->menu.warn, TRUE);
2109 else
2110 gtk_widget_set_sensitive(gtkwin->menu.warn, FALSE);
2111
2112 gtk_widget_show(gtkwin->menu.block);
2113
2114 if (gaim_find_buddy(gaim_conversation_get_account(conv),
2115 gaim_conversation_get_name(conv)) == NULL) {
2116 gtk_widget_show(gtkwin->menu.add);
2117 gtk_widget_hide(gtkwin->menu.remove);
2118 gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
2119 } else {
2120 gtk_widget_show(gtkwin->menu.remove);
2121 gtk_widget_hide(gtkwin->menu.add);
2122 gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
2123 }
2124 gtk_widget_set_sensitive(gtkwin->menu.add, TRUE);
2125 gtk_widget_set_sensitive(gtkwin->menu.remove, TRUE);
2126
2127 if (gtkwin->menu.send_as != NULL)
2128 g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
2129
2130 if (gtkconv->u.im->anim) {
2131 window_icon = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
2132 g_object_ref(window_icon);
2133 } else {
2134 window_icon = get_tab_icon(conv);
2135 }
2136 }
2137 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
2138 gtk_widget_hide(gtkwin->menu.view_log);
2139 gtk_widget_hide(gtkwin->menu.add_pounce);
2140 gtk_widget_hide(gtkwin->menu.get_info);
2141 gtk_widget_show(gtkwin->menu.invite);
2142
2143 gtk_widget_show(gtkwin->menu.insert_link);
2144
2145 gtk_widget_hide(gtkwin->menu.insert_image);
2146 gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
2147
2148 gtk_widget_hide(gtkwin->menu.warn);
2149 gtk_widget_hide(gtkwin->menu.block);
2150
2151 if (gaim_blist_find_chat(gaim_conversation_get_account(conv),
2152 gaim_conversation_get_name(conv)) == NULL) {
2153 gtk_widget_show(gtkwin->menu.add);
2154 gtk_widget_hide(gtkwin->menu.remove);
2155 gtk_widget_set_sensitive(gtkwin->menu.alias, FALSE);
2156 } else {
2157 gtk_widget_show(gtkwin->menu.remove);
2158 gtk_widget_hide(gtkwin->menu.add);
2159 gtk_widget_set_sensitive(gtkwin->menu.alias, TRUE);
2160 }
2161 gtk_widget_set_sensitive(gtkwin->menu.add, TRUE);
2162 gtk_widget_set_sensitive(gtkwin->menu.remove, TRUE);
2163
2164 if (gtkwin->menu.send_as != NULL)
2165 g_timeout_add(0, (GSourceFunc)update_send_as_selection, win);
2166 window_icon = get_tab_icon(conv);
2167 }
2168 2278
2169 update_typing_icon(conv); 2279 update_typing_icon(conv);
2170 2280
2171 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.logging), 2281 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkwin->menu.logging),
2172 gaim_conversation_is_logging(conv)); 2282 gaim_conversation_is_logging(conv));
2178 GTK_CHECK_MENU_ITEM(gtkwin->menu.show_formatting_toolbar), 2288 GTK_CHECK_MENU_ITEM(gtkwin->menu.show_formatting_toolbar),
2179 gtkconv->show_formatting_toolbar); 2289 gtkconv->show_formatting_toolbar);
2180 2290
2181 gtk_widget_grab_focus(gtkconv->entry); 2291 gtk_widget_grab_focus(gtkconv->entry);
2182 2292
2183 gtk_window_set_icon(GTK_WINDOW(gtkwin->window), window_icon);
2184 g_object_unref(G_OBJECT(window_icon));
2185 gtk_window_set_title(GTK_WINDOW(gtkwin->window), 2293 gtk_window_set_title(GTK_WINDOW(gtkwin->window),
2186 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label))); 2294 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
2187 } 2295 }
2188 2296
2189 /************************************************************************** 2297 /**************************************************************************
2889 static GtkItemFactoryEntry menu_items[] = 2997 static GtkItemFactoryEntry menu_items[] =
2890 { 2998 {
2891 /* Conversation menu */ 2999 /* Conversation menu */
2892 { N_("/_Conversation"), NULL, NULL, 0, "<Branch>" }, 3000 { N_("/_Conversation"), NULL, NULL, 0, "<Branch>" },
2893 3001
2894 { N_("/Conversation/New _Instant Message..."), "<CTL>I", menu_new_conv_cb, 3002 { N_("/Conversation/New Instant _Message..."), "<CTL>M", menu_new_conv_cb,
2895 0, "<StockItem>", GAIM_STOCK_IM }, 3003 0, "<StockItem>", GAIM_STOCK_IM },
2896 3004
2897 { "/Conversation/sep0", NULL, NULL, 0, "<Separator>" }, 3005 { "/Conversation/sep0", NULL, NULL, 0, "<Separator>" },
2898 3006
2899 { N_("/Conversation/_Find..."), NULL, menu_find_cb, 0, "<StockItem>", GTK_STOCK_FIND }, 3007 { N_("/Conversation/_Find..."), NULL, menu_find_cb, 0, "<StockItem>", GTK_STOCK_FIND },
5464 } 5572 }
5465 5573
5466 void 5574 void
5467 gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv) 5575 gaim_gtkconv_update_buttons_by_protocol(GaimConversation *conv)
5468 { 5576 {
5469 GaimPluginProtocolInfo *prpl_info = NULL;
5470 GaimConvWindow *win; 5577 GaimConvWindow *win;
5471 GaimGtkWindow *gtkwin = NULL;
5472 GaimGtkConversation *gtkconv;
5473 GaimConnection *gc;
5474 5578
5475 if (!GAIM_IS_GTK_CONVERSATION(conv)) 5579 if (!GAIM_IS_GTK_CONVERSATION(conv))
5476 return; 5580 return;
5477 5581
5478 gc = gaim_conversation_get_gc(conv); 5582 win = gaim_conversation_get_window(conv);
5479 win = gaim_conversation_get_window(conv); 5583
5480 gtkconv = GAIM_GTK_CONVERSATION(conv); 5584 if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv)
5481 5585 gray_stuff_out(conv);
5482 if (win != NULL)
5483 gtkwin = GAIM_GTK_WINDOW(win);
5484
5485 if (gc == NULL) {
5486 gtk_widget_set_sensitive(gtkconv->send, FALSE);
5487
5488 if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv) {
5489 gtk_widget_set_sensitive(gtkwin->menu.insert_link, FALSE);
5490 }
5491 }
5492 else {
5493 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
5494
5495 gtk_widget_set_sensitive(gtkconv->send, TRUE);
5496
5497 if (win != NULL)
5498 gtk_widget_set_sensitive(gtkwin->menu.insert_link, TRUE);
5499
5500 gtk_widget_set_sensitive(gtkconv->toolbar.bgcolor,
5501 !(gc->flags & GAIM_CONNECTION_NO_BGCOLOR));
5502 }
5503
5504 if (gaim_conversation_get_type(conv) == GAIM_CONV_IM) {
5505 if (gc == NULL) {
5506 gtk_widget_set_sensitive(gtkconv->info, FALSE);
5507 gtk_widget_set_sensitive(gtkconv->u.im->warn, FALSE);
5508 gtk_widget_set_sensitive(gtkconv->u.im->block, FALSE);
5509 gtk_widget_set_sensitive(gtkconv->u.im->add, FALSE);
5510
5511 if (win != NULL &&
5512 gaim_conv_window_get_active_conversation(win) == conv) {
5513
5514 gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE);
5515 }
5516
5517 return;
5518 }
5519
5520 gtk_widget_set_sensitive(gtkconv->info,
5521 (prpl_info->get_info != NULL));
5522
5523 gtk_widget_set_sensitive(gtkconv->toolbar.image,
5524 (prpl_info->options & OPT_PROTO_IM_IMAGE));
5525
5526 if (win != NULL && gaim_conv_window_get_active_conversation(win) == conv) {
5527 gtk_widget_set_sensitive(gtkwin->menu.insert_image,
5528 (prpl_info->options & OPT_PROTO_IM_IMAGE));
5529 }
5530
5531 gtk_widget_set_sensitive(gtkconv->u.im->warn,
5532 (prpl_info->warn != NULL));
5533
5534 gtk_widget_set_sensitive(gtkconv->u.im->block,
5535 (prpl_info->add_deny != NULL));
5536
5537 update_convo_add_button(conv);
5538 }
5539 else if (gaim_conversation_get_type(conv) == GAIM_CONV_CHAT) {
5540 if (gc == NULL) {
5541 if (gtkconv->u.chat->whisper != NULL)
5542 gtk_widget_set_sensitive(gtkconv->u.chat->whisper, FALSE);
5543
5544 gtk_widget_set_sensitive(gtkconv->u.chat->invite, FALSE);
5545
5546 return;
5547 }
5548
5549 gtk_widget_set_sensitive(gtkconv->send, (prpl_info->chat_send != NULL));
5550
5551 gtk_widget_set_sensitive(gtkconv->toolbar.image, FALSE);
5552 /* gtk_widget_set_sensitive(gtkwin->menu.insert_image, FALSE); */
5553
5554 if (gtkconv->u.chat->whisper != NULL)
5555 gtk_widget_set_sensitive(gtkconv->u.chat->whisper,
5556 (prpl_info->chat_whisper != NULL));
5557
5558 gtk_widget_set_sensitive(gtkconv->u.chat->invite,
5559 (prpl_info->chat_invite != NULL));
5560 }
5561 } 5586 }
5562 5587
5563 GaimConvWindow * 5588 GaimConvWindow *
5564 gaim_gtkwin_get_at_xy(int x, int y) 5589 gaim_gtkwin_get_at_xy(int x, int y)
5565 { 5590 {