Mercurial > pidgin.yaz
changeset 11552:11d30825c1bb
[gaim-migrate @ 13812]
Source Forge patch 1273590 from Casey Harkins to move all sound playing events into gtksound.[ch] as well as a few other clean ups to make sure that all sounds are being played by the ui.
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sat, 17 Sep 2005 03:00:12 +0000 |
parents | 78aad676fdb2 |
children | 5c8210f7cbe2 |
files | COPYRIGHT src/conversation.c src/gtkconv.c src/gtksound.c src/sound.c src/util.c src/util.h |
diffstat | 7 files changed, 199 insertions(+), 89 deletions(-) [+] |
line wrap: on
line diff
--- a/COPYRIGHT Thu Sep 15 14:54:23 2005 +0000 +++ b/COPYRIGHT Sat Sep 17 03:00:12 2005 +0000 @@ -92,6 +92,7 @@ Christian Hammond Erick Hamness Fred Hampton +Casey Harkins Andy Harrison Andrew Hart (arhart) G. Sumner Hayes
--- a/src/conversation.c Thu Sep 15 14:54:23 2005 +0000 +++ b/src/conversation.c Sat Sep 17 03:00:12 2005 +0000 @@ -54,30 +54,6 @@ static void conv_placement_last_created_win(GaimConversation *conv); static gboolean -find_nick(const char *nick, const char *message) -{ - char *msg, *who, *p; - int n; - gboolean ret = FALSE; - - msg = g_utf8_strdown(message, -1); - - who = g_utf8_strdown(nick, -1); - n = strlen(who); - - if ((p = strstr(msg, who)) != NULL) { - if ((p == msg || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { - ret = TRUE; - } - } - - g_free(who); - g_free(msg); - - return ret; -} - -static gboolean reset_typing(gpointer data) { GaimConversation *c = (GaimConversation *)data; @@ -1907,7 +1883,7 @@ } else { flags |= GAIM_MESSAGE_RECV; - if (find_nick(chat->nick, message)) + if (gaim_utf8_has_word(message, chat->nick)) flags |= GAIM_MESSAGE_NICK; }
--- a/src/gtkconv.c Thu Sep 15 14:54:23 2005 +0000 +++ b/src/gtkconv.c Sat Sep 17 03:00:12 2005 +0000 @@ -5036,33 +5036,9 @@ time_t mtime) { GaimGtkConversation *gtkconv; - GaimConvWindow *gaimwin; - GaimGtkWindow *gtkwin; - gboolean has_focus; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkconv->active_conv = conv; - gaimwin = gaim_conversation_get_window(conv); - gtkwin = GAIM_GTK_WINDOW(gaimwin); - - g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); - - /* Play a sound, if specified in prefs. */ - if (gtkconv->make_sound && !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && - !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) { - if (flags & GAIM_MESSAGE_RECV) { - if (gtkconv->u.im->a_virgin && - gaim_prefs_get_bool("/gaim/gtk/sound/enabled/first_im_recv")) { - - gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE); - } - else - gaim_sound_play_event(GAIM_SOUND_RECEIVE); - } - else { - gaim_sound_play_event(GAIM_SOUND_SEND); - } - } gtkconv->u.im->a_virgin = FALSE; @@ -5074,35 +5050,9 @@ const char *message, GaimMessageFlags flags, time_t mtime) { GaimGtkConversation *gtkconv; - GaimConvWindow *gaimwin; - GaimGtkWindow *gtkwin; - gboolean has_focus; gtkconv = GAIM_GTK_CONVERSATION(conv); gtkconv->active_conv = conv; - gaimwin = gaim_conversation_get_window(conv); - gtkwin = GAIM_GTK_WINDOW(gaimwin); - - g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", &has_focus, NULL); - - /* Play a sound, if specified in prefs. */ - if (gtkconv->make_sound && !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && - !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus) && - !(flags & GAIM_MESSAGE_DELAYED) && - !(flags & GAIM_MESSAGE_SYSTEM)) { - - if (!(flags & GAIM_MESSAGE_WHISPER) && (flags & GAIM_MESSAGE_SEND)) - gaim_sound_play_event(GAIM_SOUND_CHAT_YOU_SAY); - else if (flags & GAIM_MESSAGE_RECV) { - if ((flags & GAIM_MESSAGE_NICK) && - gaim_prefs_get_bool("/gaim/gtk/sound/enabled/nick_said")) { - - gaim_sound_play_event(GAIM_SOUND_CHAT_NICK); - } - else - gaim_sound_play_event(GAIM_SOUND_CHAT_SAY); - } - } flags |= GAIM_MESSAGE_COLORIZE; @@ -5564,8 +5514,6 @@ gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); - if (gtkconv->make_sound) - gaim_sound_play_event(GAIM_SOUND_CHAT_LEAVE); } static void
--- a/src/gtksound.c Thu Sep 15 14:54:23 2005 +0000 +++ b/src/gtksound.c Sat Sep 17 03:00:12 2005 +0000 @@ -42,6 +42,7 @@ #include "sound.h" #include "util.h" +#include "gtkconv.h" #include "gtksound.h" struct gaim_sound_event { @@ -83,6 +84,136 @@ return FALSE; } +static gboolean +chat_nick_matches_name(GaimConversation *conv, const char *aname) +{ + GaimConvChat *chat = NULL; + char *nick = NULL; + char *name = NULL; + gboolean ret = FALSE; + chat = gaim_conversation_get_chat_data(conv); + + if (chat==NULL) + return ret; + + nick = g_strdup(gaim_normalize(conv->account, chat->nick)); + name = g_strdup(gaim_normalize(conv->account, aname)); + + if (g_utf8_collate(nick, name) == 0) + ret = TRUE; + + g_free(nick); + g_free(name); + + return ret; +} + +/* + * play a sound event for a conversation, honoring make_sound flag + * of conversation and checking for focus if conv_focus pref is set + */ +static void +play_conv_event(GaimConversation *conv, GaimSoundEventID event) +{ + GaimGtkConversation *gtkconv; + GaimConvWindow *gaimwin; + GaimGtkWindow *gtkwin; + gboolean has_focus; + + if (conv==NULL) + gaim_sound_play_event(event); + + gtkconv = GAIM_GTK_CONVERSATION(conv); + gaimwin = gaim_conversation_get_window(conv); + gtkwin = GAIM_GTK_WINDOW(gaimwin); + + g_object_get(G_OBJECT(gtkwin->window), "has-toplevel-focus", + &has_focus, NULL); + + if (gtkconv->make_sound && + !((gaim_conv_window_get_active_conversation(gaimwin) == conv) && + !gaim_prefs_get_bool("/gaim/gtk/sound/conv_focus") && has_focus)) { + + gaim_sound_play_event(event); + } +} + +static void +buddy_state_cb(GaimBuddy *buddy, GaimSoundEventID event) +{ + gaim_sound_play_event(event); +} + +static void +im_msg_received_cb(GaimAccount *account, char *sender, + char *message, GaimConversation *conv, + int flags, GaimSoundEventID event) +{ + if (conv==NULL) + gaim_sound_play_event(GAIM_SOUND_FIRST_RECEIVE); + else + play_conv_event(conv, event); +} + +static void +im_msg_sent_cb(GaimAccount *account, const char *receiver, + const char *message, GaimSoundEventID event) +{ + GaimConversation *conv = gaim_find_conversation_with_account( + GAIM_CONV_TYPE_ANY, receiver, account); + play_conv_event(conv, event); +} + +static void +chat_buddy_join_cb(GaimConversation *conv, const char *name, + GaimConvChatBuddyFlags flags, GaimSoundEventID event) +{ + if (!chat_nick_matches_name(conv, name)) + play_conv_event(conv, event); +} + +static void +chat_buddy_left_cb(GaimConversation *conv, const char *name, + const char *reason, GaimSoundEventID event) +{ + if (!chat_nick_matches_name(conv, name)) + play_conv_event(conv, event); +} + +static void +chat_msg_sent_cb(GaimAccount *account, const char *message, + int id, GaimSoundEventID event) +{ + GaimConnection *conn = gaim_account_get_connection(account); + GaimConversation *conv = NULL; + + if (conn!=NULL) + conv = gaim_find_chat(conn,id); + + play_conv_event(conv, event); +} + +static void +chat_msg_received_cb(GaimAccount *account, char *sender, + char *message, GaimConversation *conv, + int flags, GaimSoundEventID event) +{ + GaimConvChat *chat; + + chat = gaim_conversation_get_chat_data(conv); + + if (chat!=NULL && gaim_conv_chat_is_user_ignored(chat, sender)) + return; + + if (chat_nick_matches_name(conv, sender)) + return; + + if (flags & GAIM_CONV_CHAT_ALERT || gaim_utf8_has_word(message, chat->nick)) + play_conv_event(conv, GAIM_SOUND_CHAT_NICK); + else + play_conv_event(conv, event); +} + /* * We mute sounds for the 10 seconds after you log in so that * you don't get flooded with sounds when the blist shows all @@ -155,6 +286,8 @@ gaim_gtk_sound_init(void) { void *gtk_sound_handle = gaim_gtk_sound_get_handle(); + void *blist_handle = gaim_blist_get_handle(); + void *conv_handle = gaim_conversations_get_handle(); gaim_signal_connect(gaim_connections_get_handle(), "signed-on", gtk_sound_handle, GAIM_CALLBACK(account_signon_cb), @@ -197,6 +330,31 @@ gaim_prefs_connect_callback(gaim_gtk_sound_get_handle(), "/gaim/gtk/sound/method", _pref_sound_method_changed, NULL); + + gaim_signal_connect(blist_handle, "buddy-signed-on", + gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), + GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE)); + gaim_signal_connect(blist_handle, "buddy-signed-off", + gtk_sound_handle, GAIM_CALLBACK(buddy_state_cb), + GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE)); + gaim_signal_connect(conv_handle, "received-im-msg", + gtk_sound_handle, GAIM_CALLBACK(im_msg_received_cb), + GINT_TO_POINTER(GAIM_SOUND_RECEIVE)); + gaim_signal_connect(conv_handle, "sent-im-msg", + gtk_sound_handle, GAIM_CALLBACK(im_msg_sent_cb), + GINT_TO_POINTER(GAIM_SOUND_SEND)); + gaim_signal_connect(conv_handle, "chat-buddy-joined", + gtk_sound_handle, GAIM_CALLBACK(chat_buddy_join_cb), + GINT_TO_POINTER(GAIM_SOUND_CHAT_JOIN)); + gaim_signal_connect(conv_handle, "chat-buddy-left", + gtk_sound_handle, GAIM_CALLBACK(chat_buddy_left_cb), + GINT_TO_POINTER(GAIM_SOUND_CHAT_LEAVE)); + gaim_signal_connect(conv_handle, "sent-chat-msg", + gtk_sound_handle, GAIM_CALLBACK(chat_msg_sent_cb), + GINT_TO_POINTER(GAIM_SOUND_CHAT_YOU_SAY)); + gaim_signal_connect(conv_handle, "received-chat-msg", + gtk_sound_handle, GAIM_CALLBACK(chat_msg_received_cb), + GINT_TO_POINTER(GAIM_SOUND_CHAT_SAY)); } static void @@ -206,6 +364,8 @@ ao_shutdown(); #endif sound_initialized = FALSE; + + gaim_signals_disconnect_by_handle(gaim_gtk_sound_get_handle()); } #ifdef USE_AO
--- a/src/sound.c Thu Sep 15 14:54:23 2005 +0000 +++ b/src/sound.c Sat Sep 17 03:00:12 2005 +0000 @@ -54,12 +54,6 @@ sound_ui_ops->play_event(event); } -static void -sound_triggered_cb(GaimBuddy *buddy, GaimSoundEventID event) -{ - gaim_sound_play_event(event); -} - void gaim_sound_set_ui_ops(GaimSoundUiOps *ops) { @@ -94,12 +88,6 @@ gaim_prefs_add_none("/core/sound"); gaim_prefs_add_bool("/core/sound/while_away", FALSE); - gaim_signal_connect(blist_handle, "buddy-signed-on", - handle, GAIM_CALLBACK(sound_triggered_cb), - GINT_TO_POINTER(GAIM_SOUND_BUDDY_ARRIVE)); - gaim_signal_connect(blist_handle, "buddy-signed-off", - handle, GAIM_CALLBACK(sound_triggered_cb), - GINT_TO_POINTER(GAIM_SOUND_BUDDY_LEAVE)); } void
--- a/src/util.c Thu Sep 15 14:54:23 2005 +0000 +++ b/src/util.c Sat Sep 17 03:00:12 2005 +0000 @@ -3373,6 +3373,31 @@ return ret; } +/* previously conversation::find_nick() */ +gboolean +gaim_utf8_has_word(const char *haystack, const char *needle) +{ + char *hay, *pin, *p; + int n; + gboolean ret = FALSE; + + hay = g_utf8_strdown(haystack, -1); + + pin = g_utf8_strdown(needle, -1); + n = strlen(pin); + + if ((p = strstr(hay, pin)) != NULL) { + if ((p == hay || !isalnum(*(p - 1))) && !isalnum(*(p + n))) { + ret = TRUE; + } + } + + g_free(pin); + g_free(hay); + + return ret; +} + gboolean gaim_message_meify(char *message, size_t len) { char *c;
--- a/src/util.h Thu Sep 15 14:54:23 2005 +0000 +++ b/src/util.h Sat Sep 17 03:00:12 2005 +0000 @@ -796,6 +796,18 @@ int gaim_utf8_strcasecmp(const char *a, const char *b); /** + * Case insensitive search for a word in a string. The needle string + * must be contained in the haystack string and not be immediately + * preceded or immediately followed by another alpha-numeric character. + * + * @param haystack The string to search in. + * @param needle The substring to find. + * + * @return TRUE if haystack has the word, otherwise FALSE + */ +gboolean gaim_utf8_has_word(const char *haystack, const char *needle); + +/** * Checks for messages starting with "/me " * * @param message The message to check