From: Gary K. <amc...@us...> - 2005-09-17 03:00:24
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26128/src Modified Files: conversation.c gtkconv.c gtksound.c sound.c util.c util.h Log Message: 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. Index: conversation.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/conversation.c,v retrieving revision 1.670 retrieving revision 1.671 diff -u -d -p -r1.670 -r1.671 --- conversation.c 11 Sep 2005 02:58:02 -0000 1.670 +++ conversation.c 17 Sep 2005 03:00:12 -0000 1.671 @@ -54,30 +54,6 @@ static void ensure_default_funcs(void); 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 @@ gaim_conv_chat_write(GaimConvChat *chat, } else { flags |= GAIM_MESSAGE_RECV; - if (find_nick(chat->nick, message)) + if (gaim_utf8_has_word(message, chat->nick)) flags |= GAIM_MESSAGE_NICK; } Index: gtkconv.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtkconv.c,v retrieving revision 1.601 retrieving revision 1.602 diff -u -d -p -r1.601 -r1.602 --- gtkconv.c 15 Sep 2005 04:54:26 -0000 1.601 +++ gtkconv.c 17 Sep 2005 03:00:12 -0000 1.602 @@ -5036,33 +5036,9 @@ gaim_gtkconv_write_im(GaimConversation * 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 @@ gaim_gtkconv_write_chat(GaimConversation 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 @@ gaim_gtkconv_chat_remove_user(GaimConver gtk_label_set_text(GTK_LABEL(gtkchat->count), tmp); - if (gtkconv->make_sound) - gaim_sound_play_event(GAIM_SOUND_CHAT_LEAVE); } static void Index: gtksound.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/gtksound.c,v retrieving revision 1.29 retrieving revision 1.30 diff -u -d -p -r1.29 -r1.30 --- gtksound.c 7 Sep 2005 04:00:11 -0000 1.29 +++ gtksound.c 17 Sep 2005 03:00:12 -0000 1.30 @@ -42,6 +42,7 @@ #include "sound.h" #include "util.h" +#include "gtkconv.h" #include "gtksound.h" struct gaim_sound_event { @@ -83,6 +84,136 @@ unmute_login_sounds_cb(gpointer data) 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 @@ static void 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_gtk_sound_init(void) 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 @@ gaim_gtk_sound_uninit(void) ao_shutdown(); #endif sound_initialized = FALSE; + + gaim_signals_disconnect_by_handle(gaim_gtk_sound_get_handle()); } #ifdef USE_AO Index: sound.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/sound.c,v retrieving revision 1.97 retrieving revision 1.98 diff -u -d -p -r1.97 -r1.98 --- sound.c 5 Dec 2004 23:19:16 -0000 1.97 +++ sound.c 17 Sep 2005 03:00:12 -0000 1.98 @@ -54,12 +54,6 @@ gaim_sound_play_event(GaimSoundEventID e 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_sound_init() 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 Index: util.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.c,v retrieving revision 1.364 retrieving revision 1.365 diff -u -d -p -r1.364 -r1.365 --- util.c 10 Sep 2005 19:19:20 -0000 1.364 +++ util.c 17 Sep 2005 03:00:12 -0000 1.365 @@ -3373,6 +3373,31 @@ gaim_utf8_strcasecmp(const char *a, cons 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; Index: util.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/util.h,v retrieving revision 1.81 retrieving revision 1.82 diff -u -d -p -r1.81 -r1.82 --- util.h 11 Sep 2005 03:58:13 -0000 1.81 +++ util.h 17 Sep 2005 03:00:12 -0000 1.82 @@ -796,6 +796,18 @@ gchar *gaim_utf8_salvage(const char *str 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 |