Mercurial > pidgin
changeset 13476:465c368366f8
[gaim-migrate @ 15852]
Add GAIM_MESSAGE_ACTIVE_ONLY:
This allows core plugins to hint to the UI that it should not show a message if a conversation is "inactive". For the GTK+ UI, this means conversations that aren't the active conversation in a contact-aware conversation.
With the GTK+ UI, to avoid having such a message logged, you need to either call gaim_conv_im_write() (which will drop the message before logging, or allow it through for both logging and displaying) or set the GAIM_MESSAGE_NO_LOG flag (which obviously suppresses all logging). Look at the Buddy State Notification and Psychic plugins for the examples of each of these techniques, respectively.
This fixes a ShowStopperBug.
Also, rearrange some stuff in gtkconv.c to make things more clear and remove unused code.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Thu, 09 Mar 2006 04:02:09 +0000 |
parents | d6912eee114e |
children | d18f5962d454 |
files | plugins/ChangeLog.API plugins/psychic.c plugins/statenotify.c src/conversation.h src/gtkconv.c |
diffstat | 5 files changed, 85 insertions(+), 74 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/ChangeLog.API Thu Mar 09 03:11:50 2006 +0000 +++ b/plugins/ChangeLog.API Thu Mar 09 04:02:09 2006 +0000 @@ -169,6 +169,7 @@ * gaim_date() * gaim_date_full(): See gaim_date_format_full() * gaim_strftime(): See gaim_utf8_strftime() + * GAIM_MESSAGE_COLORIZE Added: * gaim_prefs_disconnect_by_handle() @@ -279,6 +280,7 @@ * gaim_gtk_setup_screenname_autocomplete() * gaim_gtk_set_cursor() * gaim_gtk_clear_cursor() + * GAIM_MESSAGE_ACTIVE_ONLY Signals - Changed: (See the Doxygen docs for details on all signals.) * Signal propagation now stops after a handler returns a non-NULL value.
--- a/plugins/psychic.c Thu Mar 09 03:11:50 2006 +0000 +++ b/plugins/psychic.c Thu Mar 09 04:02:09 2006 +0000 @@ -58,7 +58,7 @@ if(gaim_prefs_get_bool(PREF_NOTICE)) { gaim_conversation_write(gconv, NULL, _("You feel a disturbance in the force..."), - GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG, + GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_NO_LOG | GAIM_MESSAGE_ACTIVE_ONLY, time(NULL)); }
--- a/plugins/statenotify.c Thu Mar 09 03:11:50 2006 +0000 +++ b/plugins/statenotify.c Thu Mar 09 04:02:09 2006 +0000 @@ -25,6 +25,7 @@ if (conv == NULL) return; + g_return_if_fail(conv->type == GAIM_CONV_TYPE_IM); who = gaim_buddy_get_alias(buddy); escaped = g_markup_escape_text(who, -1); @@ -32,7 +33,7 @@ g_snprintf(buf, sizeof(buf), message, escaped); g_free(escaped); - gaim_conversation_write(conv, NULL, buf, GAIM_MESSAGE_SYSTEM, time(NULL)); + gaim_conv_im_write(conv->u.im, NULL, buf, GAIM_MESSAGE_SYSTEM | GAIM_MESSAGE_ACTIVE_ONLY, time(NULL)); } static void
--- a/src/conversation.h Thu Mar 09 03:11:50 2006 +0000 +++ b/src/conversation.h Thu Mar 09 04:02:09 2006 +0000 @@ -97,18 +97,25 @@ */ typedef enum { - GAIM_MESSAGE_SEND = 0x0001, /**< Outgoing message. */ - GAIM_MESSAGE_RECV = 0x0002, /**< Incoming message. */ - GAIM_MESSAGE_SYSTEM = 0x0004, /**< System message. */ - GAIM_MESSAGE_AUTO_RESP = 0x0008, /**< Auto response. */ - GAIM_MESSAGE_COLORIZE = 0x0010, /**< Colorize nicks. */ - GAIM_MESSAGE_NICK = 0x0020, /**< Contains your nick. */ - GAIM_MESSAGE_NO_LOG = 0x0040, /**< Do not log. */ - GAIM_MESSAGE_WHISPER = 0x0080, /**< Whispered message. */ - GAIM_MESSAGE_ERROR = 0x0200, /**< Error message. */ - GAIM_MESSAGE_DELAYED = 0x0400, /**< Delayed message. */ - GAIM_MESSAGE_RAW = 0x0800, /**< "Raw" message - don't apply formatting */ - GAIM_MESSAGE_IMAGES = 0x1000 /**< Message contains images */ + GAIM_MESSAGE_SEND = 0x0001, /**< Outgoing message. */ + GAIM_MESSAGE_RECV = 0x0002, /**< Incoming message. */ + GAIM_MESSAGE_SYSTEM = 0x0004, /**< System message. */ + GAIM_MESSAGE_AUTO_RESP = 0x0008, /**< Auto response. */ + GAIM_MESSAGE_ACTIVE_ONLY = 0x0010, /**< Hint to the UI that this + message should not be + shown in conversations + which are only open for + internal UI purposes + (e.g. for contact-aware + conversions). */ + GAIM_MESSAGE_NICK = 0x0020, /**< Contains your nick. */ + GAIM_MESSAGE_NO_LOG = 0x0040, /**< Do not log. */ + GAIM_MESSAGE_WHISPER = 0x0080, /**< Whispered message. */ + GAIM_MESSAGE_ERROR = 0x0200, /**< Error message. */ + GAIM_MESSAGE_DELAYED = 0x0400, /**< Delayed message. */ + GAIM_MESSAGE_RAW = 0x0800, /**< "Raw" message - don't + apply formatting */ + GAIM_MESSAGE_IMAGES = 0x1000 /**< Message contains images */ } GaimMessageFlags; @@ -124,7 +131,6 @@ GAIM_CBFLAGS_FOUNDER = 0x0008, /**< Channel Founder */ GAIM_CBFLAGS_TYPING = 0x0010, /**< Currently typing */ - } GaimConvChatBuddyFlags; #include "account.h"
--- a/src/gtkconv.c Thu Mar 09 03:11:50 2006 +0000 +++ b/src/gtkconv.c Thu Mar 09 04:02:09 2006 +0000 @@ -2002,8 +2002,8 @@ return TRUE; } -static void -gaim_gtkconv_set_active_conversation(GaimConversation *conv) +void +gaim_gtkconv_switch_active_conversation(GaimConversation *conv) { GaimGtkConversation *gtkconv; GaimConversation *old_conv; @@ -2099,18 +2099,6 @@ } gaim_signal_emit(gaim_gtk_conversations_get_handle(), "conversation-switched", conv); -} - -void -gaim_gtkconv_switch_active_conversation(GaimConversation *conv) -{ - GaimGtkConversation *gtkconv; - - g_return_if_fail(conv != NULL); - - gtkconv = GAIM_GTK_CONVERSATION(conv); - - gaim_gtkconv_set_active_conversation(conv); gray_stuff_out(gtkconv); update_typing_icon(gtkconv); @@ -2516,7 +2504,7 @@ gaim_gtkconv_placement_place(gtkconv); } - gaim_gtkconv_set_active_conversation(conv); + gaim_gtkconv_switch_active_conversation(conv); gaim_gtk_conv_window_switch_gtkconv(gtkconv->win, gtkconv); gaim_gtk_conv_window_raise(gtkconv->win); gtk_window_present(GTK_WINDOW(gtkconv->win->window)); @@ -4466,6 +4454,7 @@ g_free(gtkconv); } + static void gaim_gtkconv_write_im(GaimConversation *conv, const char *who, const char *message, GaimMessageFlags flags, @@ -4474,21 +4463,17 @@ GaimGtkConversation *gtkconv; gtkconv = GAIM_GTK_CONVERSATION(conv); - gaim_gtkconv_set_active_conversation(conv); - - gaim_conversation_write(conv, who, message, flags, mtime); -} - -static void -gaim_gtkconv_write_chat(GaimConversation *conv, const char *who, - const char *message, GaimMessageFlags flags, time_t mtime) -{ - GaimGtkConversation *gtkconv; - - gtkconv = GAIM_GTK_CONVERSATION(conv); - gaim_gtkconv_set_active_conversation(conv); - - flags |= GAIM_MESSAGE_COLORIZE; + + if (conv != gtkconv->active_conv && + flags & GAIM_MESSAGE_ACTIVE_ONLY) + { + /* Plugins that want these messages suppressed should be + * calling gaim_conv_im_write(), so they get suppressed here, + * before being written to the log. */ + gaim_debug_info("gtkconv", + "Suppressing message for an inactive conversation in gaim_gtkconv_write_im()\n"); + return; + } gaim_conversation_write(conv, who, message, flags, mtime); } @@ -4584,8 +4569,7 @@ GaimPluginProtocolInfo *prpl_info; int gtk_font_options = 0; int gtk_font_options_all = 0; - int max_scrollback_lines = gaim_prefs_get_int( - "/gaim/gtk/conversations/scrollback_lines"); + int max_scrollback_lines; int line_count; char buf2[BUF_LONG]; char *mdate; @@ -4597,19 +4581,32 @@ GaimConversationType type; char *displaying; gboolean plugin_return; - struct tm tm = *(localtime(&mtime)); - + struct tm tm; + + g_return_if_fail(conv != NULL); gtkconv = GAIM_GTK_CONVERSATION(conv); - - if(gaim_prefs_get_bool("/gaim/gtk/conversations/use_smooth_scrolling")) - gtk_font_options_all |= GTK_IMHTML_USE_SMOOTHSCROLLING; - - /* Set the active conversation to the one that just messaged us. */ - /* TODO: consider not doing this if the account is offline or something */ - if (flags & (GAIM_MESSAGE_SEND | GAIM_MESSAGE_RECV)) - gaim_gtkconv_set_active_conversation(conv); + g_return_if_fail(gtkconv != NULL); + + if (conv != gtkconv->active_conv) + { + if (flags & GAIM_MESSAGE_ACTIVE_ONLY) + { + /* Unless this had GAIM_MESSAGE_NO_LOG, this message + * was logged. Plugin writers: if this isn't what + * you wanted, call gaim_conv_im_write() instead of + * gaim_conversation_write(). */ + gaim_debug_info("gtkconv", + "Suppressing message for an inactive conversation in gaim_gtkconv_write_conv()\n"); + return; + } + + /* Set the active conversation to the one that just messaged us. */ + /* TODO: consider not doing this if the account is offline or something */ + if (flags & (GAIM_MESSAGE_SEND | GAIM_MESSAGE_RECV)) + gaim_gtkconv_switch_active_conversation(conv); + } + type = gaim_conversation_get_type(conv); - account = gaim_conversation_get_account(conv); g_return_if_fail(account != NULL); gc = gaim_account_get_connection(account); @@ -4635,6 +4632,8 @@ gtk_text_view_get_buffer(GTK_TEXT_VIEW( gtkconv->imhtml))); + max_scrollback_lines = gaim_prefs_get_int( + "/gaim/gtk/conversations/scrollback_lines"); /* If we're sitting at more than 100 lines more than the max scrollback, trim down to max scrollback */ if (max_scrollback_lines > 0 @@ -4661,9 +4660,13 @@ g_free(tmp); } + if (gaim_prefs_get_bool("/gaim/gtk/conversations/use_smooth_scrolling")) + gtk_font_options_all |= GTK_IMHTML_USE_SMOOTHSCROLLING; + if (gtk_text_buffer_get_char_count(gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->imhtml)))) gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR>", gtk_font_options_all); + tm = *(localtime(&mtime)); mdate = gaim_signal_emit_return_1(gaim_gtk_conversations_get_handle(), "conversation-timestamp", conv, &tm); @@ -4675,8 +4678,7 @@ mdate = g_strdup(gaim_time_format(&tm)); } - sml_attrib = g_strdup_printf("sml=\"%s\"", - gaim_account_get_protocol_name(account)); + sml_attrib = g_strdup_printf("sml=\"%s\"", gaim_account_get_protocol_name(account)); gtk_font_options |= GTK_IMHTML_NO_COMMENTS; @@ -4783,7 +4785,7 @@ if (flags & GAIM_MESSAGE_NICK) strcpy(color, HIGHLIGHT_COLOR); else if (flags & GAIM_MESSAGE_RECV) { - if (flags & GAIM_MESSAGE_COLORIZE) { + if (type == GAIM_CONV_TYPE_CHAT) { GdkColor *col = get_nick_color(gtkconv, name); g_snprintf(color, sizeof(color), "#%02X%02X%02X", @@ -5698,19 +5700,19 @@ static GaimConversationUiOps conversation_ui_ops = { gaim_gtkconv_new, - gaim_gtkconv_destroy, /* destroy_conversation */ - gaim_gtkconv_write_chat, /* write_chat */ - gaim_gtkconv_write_im, /* write_im */ - gaim_gtkconv_write_conv, /* write_conv */ - gaim_gtkconv_chat_add_users, /* chat_add_users */ - gaim_gtkconv_chat_rename_user, /* chat_rename_user */ - gaim_gtkconv_chat_remove_users, /* chat_remove_users */ - gaim_gtkconv_chat_update_user, /* chat_update_user */ - gaim_gtkconv_present_conversation, /* present */ - gaim_gtkconv_has_focus, /* has_focus */ - gaim_gtkconv_custom_smiley_add, /* custom_smiley_add */ - gaim_gtkconv_custom_smiley_write, /* custom_smiley_write */ - gaim_gtkconv_custom_smiley_close /* custom_smiley_close */ + gaim_gtkconv_destroy, /* destroy_conversation */ + NULL, /* write_chat */ + gaim_gtkconv_write_im, /* write_im */ + gaim_gtkconv_write_conv, /* write_conv */ + gaim_gtkconv_chat_add_users, /* chat_add_users */ + gaim_gtkconv_chat_rename_user, /* chat_rename_user */ + gaim_gtkconv_chat_remove_users, /* chat_remove_users */ + gaim_gtkconv_chat_update_user, /* chat_update_user */ + gaim_gtkconv_present_conversation, /* present */ + gaim_gtkconv_has_focus, /* has_focus */ + gaim_gtkconv_custom_smiley_add, /* custom_smiley_add */ + gaim_gtkconv_custom_smiley_write, /* custom_smiley_write */ + gaim_gtkconv_custom_smiley_close /* custom_smiley_close */ }; GaimConversationUiOps *