comparison pidgin/gtkconv.c @ 32730:29f1a6b07b9b

Try not to call purple_conversation_get_features a million times.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sat, 08 Oct 2011 07:35:35 +0000
parents 512d781a5849
children 599f8901a5e0
comparison
equal deleted inserted replaced
32729:512d781a5849 32730:29f1a6b07b9b
2278 { 2278 {
2279 PidginConversation *gtkconv; 2279 PidginConversation *gtkconv;
2280 PurpleConversation *old_conv; 2280 PurpleConversation *old_conv;
2281 GtkIMHtml *entry; 2281 GtkIMHtml *entry;
2282 const char *protocol_name; 2282 const char *protocol_name;
2283 PurpleConnectionFlags features;
2283 2284
2284 g_return_if_fail(conv != NULL); 2285 g_return_if_fail(conv != NULL);
2285 2286
2286 gtkconv = PIDGIN_CONVERSATION(conv); 2287 gtkconv = PIDGIN_CONVERSATION(conv);
2287 old_conv = gtkconv->active_conv; 2288 old_conv = gtkconv->active_conv;
2303 entry = GTK_IMHTML(gtkconv->entry); 2304 entry = GTK_IMHTML(gtkconv->entry);
2304 protocol_name = purple_account_get_protocol_name(purple_conversation_get_account(conv)); 2305 protocol_name = purple_account_get_protocol_name(purple_conversation_get_account(conv));
2305 gtk_imhtml_set_protocol_name(entry, protocol_name); 2306 gtk_imhtml_set_protocol_name(entry, protocol_name);
2306 /* TODO WEBKIT: gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol_name); */ 2307 /* TODO WEBKIT: gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->imhtml), protocol_name); */
2307 2308
2308 if (!(purple_conversation_get_features(conv) & PURPLE_CONNECTION_HTML)) 2309 features = purple_conversation_get_features(conv);
2310 if (!(features & PURPLE_CONNECTION_HTML))
2309 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry)); 2311 gtk_imhtml_clear_formatting(GTK_IMHTML(gtkconv->entry));
2310 else if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_FORMATTING_WBFO && 2312 else if (features & PURPLE_CONNECTION_FORMATTING_WBFO &&
2311 !(purple_conversation_get_features(old_conv) & PURPLE_CONNECTION_FORMATTING_WBFO)) 2313 !(purple_conversation_get_features(old_conv) & PURPLE_CONNECTION_FORMATTING_WBFO))
2312 { 2314 {
2313 /* The old conversation allowed formatting on parts of the 2315 /* The old conversation allowed formatting on parts of the
2314 * buffer, but the new one only allows it on the whole 2316 * buffer, but the new one only allows it on the whole
2315 * buffer. This code saves the formatting from the current 2317 * buffer. This code saves the formatting from the current
2346 if (underline != underline2) 2348 if (underline != underline2)
2347 gtk_imhtml_toggle_underline(entry); 2349 gtk_imhtml_toggle_underline(entry);
2348 2350
2349 gtk_imhtml_toggle_fontface(entry, fontface); 2351 gtk_imhtml_toggle_fontface(entry, fontface);
2350 2352
2351 if (!(purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_FONTSIZE)) 2353 if (!(features & PURPLE_CONNECTION_NO_FONTSIZE))
2352 gtk_imhtml_font_set_size(entry, fontsize); 2354 gtk_imhtml_font_set_size(entry, fontsize);
2353 2355
2354 gtk_imhtml_toggle_forecolor(entry, forecolor); 2356 gtk_imhtml_toggle_forecolor(entry, forecolor);
2355 2357
2356 if (!(purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_BGCOLOR)) 2358 if (!(features & PURPLE_CONNECTION_NO_BGCOLOR))
2357 { 2359 {
2358 gtk_imhtml_toggle_backcolor(entry, backcolor); 2360 gtk_imhtml_toggle_backcolor(entry, backcolor);
2359 gtk_imhtml_toggle_background(entry, background); 2361 gtk_imhtml_toggle_background(entry, background);
2360 } 2362 }
2361 2363
2369 /* This is done in default_formatize, which is called from clear_formatting_cb, 2371 /* This is done in default_formatize, which is called from clear_formatting_cb,
2370 * which is (obviously) a clear_formatting signal handler. However, if we're 2372 * which is (obviously) a clear_formatting signal handler. However, if we're
2371 * here, we didn't call gtk_imhtml_clear_formatting() (because we want to 2373 * here, we didn't call gtk_imhtml_clear_formatting() (because we want to
2372 * preserve the formatting exactly as it is), so we have to do this now. */ 2374 * preserve the formatting exactly as it is), so we have to do this now. */
2373 gtk_imhtml_set_whole_buffer_formatting_only(entry, 2375 gtk_imhtml_set_whole_buffer_formatting_only(entry,
2374 (purple_conversation_get_features(conv) & PURPLE_CONNECTION_FORMATTING_WBFO)); 2376 (features & PURPLE_CONNECTION_FORMATTING_WBFO));
2375 } 2377 }
2376 2378
2377 purple_signal_emit(pidgin_conversations_get_handle(), "conversation-switched", conv); 2379 purple_signal_emit(pidgin_conversations_get_handle(), "conversation-switched", conv);
2378 2380
2379 gray_stuff_out(gtkconv); 2381 gray_stuff_out(gtkconv);
6939 */ 6941 */
6940 if ((gc != NULL) && 6942 if ((gc != NULL) &&
6941 ((purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_CHAT) || 6943 ((purple_conversation_get_type(conv) != PURPLE_CONV_TYPE_CHAT) ||
6942 !purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv)) )) 6944 !purple_conv_chat_has_left(PURPLE_CONV_CHAT(conv)) ))
6943 { 6945 {
6946 PurpleConnectionFlags features = purple_conversation_get_features(conv);
6944 /* Account is online */ 6947 /* Account is online */
6945 /* Deal with the toolbar */ 6948 /* Deal with the toolbar */
6946 if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_HTML) 6949 if (features & PURPLE_CONNECTION_HTML)
6947 { 6950 {
6948 buttons = GTK_IMHTML_ALL; /* Everything on */ 6951 buttons = GTK_IMHTML_ALL; /* Everything on */
6949 if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_BGCOLOR) 6952 if (features & PURPLE_CONNECTION_NO_BGCOLOR)
6950 buttons &= ~GTK_IMHTML_BACKCOLOR; 6953 buttons &= ~GTK_IMHTML_BACKCOLOR;
6951 if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_FONTSIZE) 6954 if (features & PURPLE_CONNECTION_NO_FONTSIZE)
6952 { 6955 {
6953 buttons &= ~GTK_IMHTML_GROW; 6956 buttons &= ~GTK_IMHTML_GROW;
6954 buttons &= ~GTK_IMHTML_SHRINK; 6957 buttons &= ~GTK_IMHTML_SHRINK;
6955 } 6958 }
6956 if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_URLDESC) 6959 if (features & PURPLE_CONNECTION_NO_URLDESC)
6957 buttons &= ~GTK_IMHTML_LINKDESC; 6960 buttons &= ~GTK_IMHTML_LINKDESC;
6958 } else { 6961 } else {
6959 buttons = GTK_IMHTML_SMILEY | GTK_IMHTML_IMAGE; 6962 buttons = GTK_IMHTML_SMILEY | GTK_IMHTML_IMAGE;
6960 } 6963 }
6961 6964
6962 if (!(prpl_info->options & OPT_PROTO_IM_IMAGE)) 6965 if (!(prpl_info->options & OPT_PROTO_IM_IMAGE)) {
6963 purple_conversation_set_features(conv, purple_conversation_get_features(conv) | PURPLE_CONNECTION_NO_IMAGES); 6966 features |= PURPLE_CONNECTION_NO_IMAGES;
6964 6967 purple_conversation_set_features(conv, features);
6965 if(purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_IMAGES) 6968 }
6969
6970 if (features & PURPLE_CONNECTION_NO_IMAGES)
6966 buttons &= ~GTK_IMHTML_IMAGE; 6971 buttons &= ~GTK_IMHTML_IMAGE;
6967 6972
6968 if (purple_conversation_get_features(conv) & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY) 6973 if (features & PURPLE_CONNECTION_ALLOW_CUSTOM_SMILEY)
6969 buttons |= GTK_IMHTML_CUSTOM_SMILEY; 6974 buttons |= GTK_IMHTML_CUSTOM_SMILEY;
6970 else 6975 else
6971 buttons &= ~GTK_IMHTML_CUSTOM_SMILEY; 6976 buttons &= ~GTK_IMHTML_CUSTOM_SMILEY;
6972 6977
6973 gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->entry), buttons); 6978 gtk_imhtml_set_format_functions(GTK_IMHTML(gtkconv->entry), buttons);
6977 /* Deal with menu items */ 6982 /* Deal with menu items */
6978 gtk_widget_set_sensitive(win->menu.view_log, TRUE); 6983 gtk_widget_set_sensitive(win->menu.view_log, TRUE);
6979 gtk_widget_set_sensitive(win->menu.add_pounce, TRUE); 6984 gtk_widget_set_sensitive(win->menu.add_pounce, TRUE);
6980 gtk_widget_set_sensitive(win->menu.get_info, (prpl_info->get_info != NULL)); 6985 gtk_widget_set_sensitive(win->menu.get_info, (prpl_info->get_info != NULL));
6981 gtk_widget_set_sensitive(win->menu.invite, (prpl_info->chat_invite != NULL)); 6986 gtk_widget_set_sensitive(win->menu.invite, (prpl_info->chat_invite != NULL));
6982 gtk_widget_set_sensitive(win->menu.insert_link, (purple_conversation_get_features(conv) & PURPLE_CONNECTION_HTML)); 6987 gtk_widget_set_sensitive(win->menu.insert_link, (features & PURPLE_CONNECTION_HTML));
6983 gtk_widget_set_sensitive(win->menu.insert_image, !(purple_conversation_get_features(conv) & PURPLE_CONNECTION_NO_IMAGES)); 6988 gtk_widget_set_sensitive(win->menu.insert_image, !(features & PURPLE_CONNECTION_NO_IMAGES));
6984 6989
6985 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) 6990 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
6986 { 6991 {
6987 gtk_widget_set_sensitive(win->menu.add, (prpl_info->add_buddy != NULL)); 6992 gtk_widget_set_sensitive(win->menu.add, (prpl_info->add_buddy != NULL));
6988 gtk_widget_set_sensitive(win->menu.remove, (prpl_info->remove_buddy != NULL)); 6993 gtk_widget_set_sensitive(win->menu.remove, (prpl_info->remove_buddy != NULL));