# HG changeset patch # User Sadrul Habib Chowdhury # Date 1183768863 0 # Node ID 7a5025b8698c6671efbb7fff95db363c5648f802 # Parent 7122bcebf7c93ef173a1177f41dbf26b6a4c6d4a# Parent 2d0925800d72265c8030262ff200050a7c6e0775 propagate from branch 'im.pidgin.pidgin' (head 007693114b23cd2711c1cb9030a148e2f63de8c8) to branch 'im.pidgin.soc.2007.finchfeat' (head e338ac75e7034d8253e0e6b928940c27c2dcf5f0) diff -r 7122bcebf7c9 -r 7a5025b8698c COPYRIGHT --- a/COPYRIGHT Sat Jul 07 00:30:45 2007 +0000 +++ b/COPYRIGHT Sat Jul 07 00:41:03 2007 +0000 @@ -274,6 +274,7 @@ Joao Luís Marques Pinto Aleksander Piotrowski Julien Pivotto +Eric Polino Ari Pollak Robey Pointer Eric Polino diff -r 7122bcebf7c9 -r 7a5025b8698c Makefile.am --- a/Makefile.am Sat Jul 07 00:30:45 2007 +0000 +++ b/Makefile.am Sat Jul 07 00:41:03 2007 +0000 @@ -42,7 +42,7 @@ GNT_DIR=finch endif -SUBDIRS = libpurple doc $(GNT_DIR) $(GTK_DIR) m4macros po +SUBDIRS = libpurple doc $(GNT_DIR) $(GTK_DIR) m4macros po share docs: Doxyfile if HAVE_DOXYGEN diff -r 7122bcebf7c9 -r 7a5025b8698c configure.ac --- a/configure.ac Sat Jul 07 00:30:45 2007 +0000 +++ b/configure.ac Sat Jul 07 00:41:03 2007 +0000 @@ -2114,7 +2114,6 @@ pidgin/plugins/perl/Makefile pidgin/plugins/perl/common/Makefile.PL pidgin/plugins/ticker/Makefile - pidgin/sounds/Makefile libpurple/example/Makefile libpurple/gconf/Makefile libpurple/purple.pc @@ -2147,6 +2146,8 @@ libpurple/protocols/zephyr/Makefile libpurple/tests/Makefile libpurple/version.h + share/Makefile + share/sounds/Makefile finch/Makefile finch/libgnt/Makefile finch/libgnt/gnt.pc diff -r 7122bcebf7c9 -r 7a5025b8698c finch/Makefile.am --- a/finch/Makefile.am Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/Makefile.am Sat Jul 07 00:41:03 2007 +0000 @@ -25,6 +25,7 @@ gntpounce.c \ gntprefs.c \ gntrequest.c \ + gntsound.c \ gntstatus.c \ gntui.c @@ -42,6 +43,7 @@ gntpounce.h \ gntprefs.h \ gntrequest.h \ + gntsound.h \ gntstatus.h \ gntui.h @@ -58,6 +60,7 @@ $(GLIB_LIBS) \ $(LIBXML_LIBS) \ $(GNT_LIBS) \ + $(GSTREAMER_LIBS) \ ./libgnt/libgnt.la \ $(top_builddir)/libpurple/libpurple.la @@ -75,4 +78,5 @@ $(GLIB_CFLAGS) \ $(DBUS_CFLAGS) \ $(LIBXML_CFLAGS) \ + $(GSTREAMER_CFLAGS) \ $(GNT_CFLAGS) diff -r 7122bcebf7c9 -r 7a5025b8698c finch/finch.h --- a/finch/finch.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/finch.h Sat Jul 07 00:41:03 2007 +0000 @@ -27,3 +27,4 @@ #define FINCH_UI "gnt-purple" +#define FINCH_PREFS_ROOT "/finch" diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntblist.c diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntconv.h --- a/finch/gntconv.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/gntconv.h Sat Jul 07 00:41:03 2007 +0000 @@ -30,6 +30,9 @@ #include "conversation.h" +/* Grabs the conv out of a PurpleConverstation */ +#define FINCH_CONV(conv) ((FinchConv *)(conv)->ui_data) + /*************************************************************************** * @name GNT Conversations API ***************************************************************************/ diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntdebug.c --- a/finch/gntdebug.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/gntdebug.c Sat Jul 07 00:41:03 2007 +0000 @@ -302,7 +302,7 @@ REGISTER_G_LOG_HANDLER("GThread"); g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */ - g_set_printerr_handler(suppress_error_messages); +// g_set_printerr_handler(suppress_error_messages); purple_prefs_add_none(PREF_ROOT); purple_prefs_add_string(PREF_ROOT "/filter", ""); diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntsound.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/finch/gntsound.c Sat Jul 07 00:41:03 2007 +0000 @@ -0,0 +1,844 @@ +/** +* @file gntsound.c GNT Sound API +* @ingroup finch +* +* finch +* +* Finch is the legal property of its developers, whose names are too numerous +* to list here. Please refer to the COPYRIGHT file distributed with this +* source distribution. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "internal.h" +#include "finch.h" + +#ifdef _WIN32 +#include +#include +#endif + +#ifdef USE_GSTREAMER +#include +#endif /* USE_GSTREAMER */ + +#include "debug.h" +#include "notify.h" +#include "prefs.h" +#include "sound.h" +#include "util.h" + +#include "gntbox.h" +#include "gntwindow.h" +#include "gntcombobox.h" +#include "gntlabel.h" +#include "gntconv.h" +#include "gntsound.h" +#include "gntwidget.h" +#include "gntentry.h" +#include "gntcheckbox.h" +#include "gntline.h" +#include "gntslider.h" +#include "gnttree.h" +#include "gntfilesel.h" + +typedef struct { + char *label; + char *pref; + char *def; + char *file; +} FinchSoundEvent; + +typedef struct { + GntWidget *method; + GntWidget *command; + GntWidget *conv_focus; + GntWidget *while_status; + GntWidget *volume; + GntWidget *events; + GntWidget *window; +} SoundPrefDialog; + +SoundPrefDialog *pref_dialog; + +#define PLAY_SOUND_TIMEOUT 15000 + +static guint mute_login_sounds_timeout = 0; +static gboolean mute_login_sounds = FALSE; + +#ifdef USE_GSTREAMER +static gboolean gst_init_failed; +#endif /* USE_GSTREAMER */ + +static FinchSoundEvent sounds[PURPLE_NUM_SOUNDS] = { + {N_("Buddy logs in"), "login", "login.wav",NULL}, + {N_("Buddy logs out"), "logout", "logout.wav",NULL}, + {N_("Message received"), "im_recv", "receive.wav",NULL}, + {N_("Message received begins conversation"), "first_im_recv", "receive.wav",NULL}, + {N_("Message sent"), "send_im", "send.wav",NULL}, + {N_("Person enters chat"), "join_chat", "login.wav",NULL}, + {N_("Person leaves chat"), "left_chat", "logout.wav",NULL}, + {N_("You talk in chat"), "send_chat_msg", "send.wav",NULL}, + {N_("Others talk in chat"), "chat_msg_recv", "receive.wav",NULL}, + /* this isn't a terminator, it's the buddy pounce default sound event ;-) */ + {NULL, "pounce_default", "alert.wav",NULL}, + {N_("Someone says your screen name in chat"), "nick_said", "alert.wav",NULL} +}; + +static gboolean +unmute_login_sounds_cb(gpointer data) +{ + mute_login_sounds = FALSE; + mute_login_sounds_timeout = 0; + return FALSE; +} + +static gboolean +chat_nick_matches_name(PurpleConversation *conv, const char *aname) +{ + PurpleConvChat *chat = NULL; + char *nick = NULL; + char *name = NULL; + gboolean ret = FALSE; + chat = purple_conversation_get_chat_data(conv); + + if (chat==NULL) + return ret; + + nick = g_strdup(purple_normalize(conv->account, chat->nick)); + name = g_strdup(purple_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(PurpleConversation *conv, PurpleSoundEventID event) +{ + /* If we should not play the sound for some reason, then exit early */ + if (conv != NULL) + { + FinchConv *gntconv; + gboolean has_focus; + + gntconv = FINCH_CONV(conv); + + has_focus = purple_conversation_has_focus(conv); + + if (has_focus && !purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus")) + { + return; + } + } + + purple_sound_play_event(event, conv ? purple_conversation_get_account(conv) : NULL); +} + +static void +buddy_state_cb(PurpleBuddy *buddy, PurpleSoundEventID event) +{ + purple_sound_play_event(event, purple_buddy_get_account(buddy)); +} + +static void +im_msg_received_cb(PurpleAccount *account, char *sender, + char *message, PurpleConversation *conv, + PurpleMessageFlags flags, PurpleSoundEventID event) +{ + if (flags & PURPLE_MESSAGE_DELAYED) + return; + + if (conv==NULL){ + purple_sound_play_event(PURPLE_SOUND_FIRST_RECEIVE, account); + } + else{ + play_conv_event(conv, event); + } +} + +static void +im_msg_sent_cb(PurpleAccount *account, const char *receiver, + const char *message, PurpleSoundEventID event) +{ + PurpleConversation *conv = purple_find_conversation_with_account( + PURPLE_CONV_TYPE_ANY, receiver, account); + play_conv_event(conv, event); +} + +static void +chat_buddy_join_cb(PurpleConversation *conv, const char *name, + PurpleConvChatBuddyFlags flags, gboolean new_arrival, + PurpleSoundEventID event) +{ + if (new_arrival && !chat_nick_matches_name(conv, name)) + play_conv_event(conv, event); +} + +static void +chat_buddy_left_cb(PurpleConversation *conv, const char *name, + const char *reason, PurpleSoundEventID event) +{ + if (!chat_nick_matches_name(conv, name)) + play_conv_event(conv, event); +} + +static void +chat_msg_sent_cb(PurpleAccount *account, const char *message, + int id, PurpleSoundEventID event) +{ + PurpleConnection *conn = purple_account_get_connection(account); + PurpleConversation *conv = NULL; + + if (conn!=NULL) + conv = purple_find_chat(conn,id); + + play_conv_event(conv, event); +} + +static void +chat_msg_received_cb(PurpleAccount *account, char *sender, + char *message, PurpleConversation *conv, + PurpleMessageFlags flags, PurpleSoundEventID event) +{ + PurpleConvChat *chat; + + if (flags & PURPLE_MESSAGE_DELAYED) + return; + + chat = purple_conversation_get_chat_data(conv); + g_return_if_fail(chat != NULL); + + if (purple_conv_chat_is_user_ignored(chat, sender)) + return; + + if (chat_nick_matches_name(conv, sender)) + return; + + if (flags & PURPLE_MESSAGE_NICK || purple_utf8_has_word(message, chat->nick)) + play_conv_event(conv, PURPLE_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 + * your buddies logging in. + */ +static void +account_signon_cb(PurpleConnection *gc, gpointer data) +{ + if (mute_login_sounds_timeout != 0) + g_source_remove(mute_login_sounds_timeout); + mute_login_sounds = TRUE; + mute_login_sounds_timeout = purple_timeout_add(10000, unmute_login_sounds_cb, NULL); +} + +const char * +finch_sound_get_event_option(PurpleSoundEventID event) +{ + if(event >= PURPLE_NUM_SOUNDS) + return 0; + + return sounds[event].pref; +} + +const char * +finch_sound_get_event_label(PurpleSoundEventID event) +{ + if(event >= PURPLE_NUM_SOUNDS) + return NULL; + + return sounds[event].label; +} + +void * +finch_sound_get_handle() +{ + static int handle; + + return &handle; +} + +static void +finch_sound_init(void) +{ + void *gnt_sound_handle = finch_sound_get_handle(); + void *blist_handle = purple_blist_get_handle(); + void *conv_handle = purple_conversations_get_handle(); +#ifdef USE_GSTREAMER + GError *error = NULL; +#endif + + purple_signal_connect(purple_connections_get_handle(), "signed-on", + gnt_sound_handle, PURPLE_CALLBACK(account_signon_cb), + NULL); + + purple_prefs_add_none(FINCH_PREFS_ROOT "/sound"); + purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/enabled"); + purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/file"); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/login", TRUE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/login", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/logout", TRUE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/logout", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/im_recv", TRUE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/im_recv", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/first_im_recv", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/first_im_recv", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_im", TRUE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_im", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/join_chat", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/join_chat", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/left_chat", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/left_chat", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/send_chat_msg", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/send_chat_msg", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/chat_msg_recv", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/chat_msg_recv", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/nick_said", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/nick_said", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/enabled/pounce_default", TRUE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/file/pounce_default", ""); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/conv_focus", TRUE); + purple_prefs_add_bool(FINCH_PREFS_ROOT "/sound/mute", FALSE); + purple_prefs_add_path(FINCH_PREFS_ROOT "/sound/command", ""); + purple_prefs_add_string(FINCH_PREFS_ROOT "/sound/method", "automatic"); + purple_prefs_add_int(FINCH_PREFS_ROOT "/sound/volume", 50); + +#ifdef USE_GSTREAMER + purple_debug_info("sound", "Initializing sound output drivers.\n"); + if ((gst_init_failed = !gst_init_check(NULL, NULL, &error))) { + purple_notify_error(NULL, _("GStreamer Failure"), + _("GStreamer failed to initialize."), + error ? error->message : ""); + if (error) { + g_error_free(error); + error = NULL; + } + } +#endif /* USE_GSTREAMER */ + + purple_signal_connect(blist_handle, "buddy-signed-on", + gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb), + GINT_TO_POINTER(PURPLE_SOUND_BUDDY_ARRIVE)); + purple_signal_connect(blist_handle, "buddy-signed-off", + gnt_sound_handle, PURPLE_CALLBACK(buddy_state_cb), + GINT_TO_POINTER(PURPLE_SOUND_BUDDY_LEAVE)); + purple_signal_connect(conv_handle, "received-im-msg", + gnt_sound_handle, PURPLE_CALLBACK(im_msg_received_cb), + GINT_TO_POINTER(PURPLE_SOUND_RECEIVE)); + purple_signal_connect(conv_handle, "sent-im-msg", + gnt_sound_handle, PURPLE_CALLBACK(im_msg_sent_cb), + GINT_TO_POINTER(PURPLE_SOUND_SEND)); + purple_signal_connect(conv_handle, "chat-buddy-joined", + gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_join_cb), + GINT_TO_POINTER(PURPLE_SOUND_CHAT_JOIN)); + purple_signal_connect(conv_handle, "chat-buddy-left", + gnt_sound_handle, PURPLE_CALLBACK(chat_buddy_left_cb), + GINT_TO_POINTER(PURPLE_SOUND_CHAT_LEAVE)); + purple_signal_connect(conv_handle, "sent-chat-msg", + gnt_sound_handle, PURPLE_CALLBACK(chat_msg_sent_cb), + GINT_TO_POINTER(PURPLE_SOUND_CHAT_YOU_SAY)); + purple_signal_connect(conv_handle, "received-chat-msg", + gnt_sound_handle, PURPLE_CALLBACK(chat_msg_received_cb), + GINT_TO_POINTER(PURPLE_SOUND_CHAT_SAY)); +} + +static void +finch_sound_uninit(void) +{ +#ifdef USE_GSTREAMER + if (!gst_init_failed) + gst_deinit(); +#endif + + purple_signals_disconnect_by_handle(finch_sound_get_handle()); +} + +#ifdef USE_GSTREAMER +static gboolean +bus_call (GstBus *bus, GstMessage *msg, gpointer data) +{ + GstElement *play = data; + GError *err = NULL; + + switch (GST_MESSAGE_TYPE (msg)) { + case GST_MESSAGE_EOS: + gst_element_set_state(play, GST_STATE_NULL); + gst_object_unref(GST_OBJECT(play)); + break; + case GST_MESSAGE_ERROR: + gst_message_parse_error(msg, &err, NULL); + purple_debug_error("gstreamer", err->message); + g_error_free(err); + break; + case GST_MESSAGE_WARNING: + gst_message_parse_warning(msg, &err, NULL); + purple_debug_warning("gstreamer", err->message); + g_error_free(err); + break; + default: + break; + } + return TRUE; +} +#endif + +static void +finch_sound_play_file(const char *filename) +{ + const char *method; +#ifdef USE_GSTREAMER + float volume; + char *uri; + GstElement *sink = NULL; + GstElement *play = NULL; + GstBus *bus = NULL; +#endif + if (purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/mute")) + return; + + method = purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method"); + + if (!strcmp(method, "none")) { + return; + } else if (!strcmp(method, "beep")) { + beep(); + return; + } + + if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { + purple_debug_error("gntsound", "sound file (%s) does not exist.\n", filename); + return; + } + +#ifndef _WIN32 + if (!strcmp(method, "custom")) { + const char *sound_cmd; + char *command; + char *esc_filename; + GError *error = NULL; + + sound_cmd = purple_prefs_get_path(FINCH_PREFS_ROOT "/sound/command"); + + if (!sound_cmd || *sound_cmd == '\0') { + purple_debug_error("gntsound", + "'Command' sound method has been chosen, " + "but no command has been set."); + return; + } + + esc_filename = g_shell_quote(filename); + + if(strstr(sound_cmd, "%s")) + command = purple_strreplace(sound_cmd, "%s", esc_filename); + else + command = g_strdup_printf("%s %s", sound_cmd, esc_filename); + + if(!g_spawn_command_line_async(command, &error)) { + purple_debug_error("gntsound", "sound command could not be launched: %s\n", error->message); + g_error_free(error); + } + + g_free(esc_filename); + g_free(command); + return; + } +#ifdef USE_GSTREAMER + if (gst_init_failed) /* Perhaps do beep instead? */ + return; + volume = (float)(CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100)) / 50; + if (!strcmp(method, "automatic")) { + if (purple_running_gnome()) { + sink = gst_element_factory_make("gconfaudiosink", "sink"); + } + if (!sink) + sink = gst_element_factory_make("autoaudiosink", "sink"); + if (!sink) { + purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); + return; + } + } else if (!strcmp(method, "esd")) { + sink = gst_element_factory_make("esdsink", "sink"); + if (!sink) { + purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); + return; + } + } else if (!strcmp(method, "alsa")) { + sink = gst_element_factory_make("alsasink", "sink"); + if (!sink) { + purple_debug_error("sound", "Unable to create GStreamer audiosink.\n"); + return; + } + } else { + purple_debug_error("sound", "Unknown sound method '%s'\n", method); + return; + } + + play = gst_element_factory_make("playbin", "play"); + + if (play == NULL) { + return; + } + + uri = g_strdup_printf("file://%s", filename); + + g_object_set(G_OBJECT(play), "uri", uri, + "volume", volume, + "audio-sink", sink, NULL); + + bus = gst_pipeline_get_bus(GST_PIPELINE(play)); + gst_bus_add_watch(bus, bus_call, play); + + gst_element_set_state(play, GST_STATE_PLAYING); + + gst_object_unref(bus); + g_free(uri); + +#else /* USE_GSTREAMER */ + beep(); + return; +#endif /* USE_GSTREAMER */ +#else /* _WIN32 */ + purple_debug_info("sound", "Playing %s\n", filename); + + if (G_WIN32_HAVE_WIDECHAR_API ()) { + wchar_t *wc_filename = g_utf8_to_utf16(filename, + -1, NULL, NULL, NULL); + if (!PlaySoundW(wc_filename, NULL, SND_ASYNC | SND_FILENAME)) + purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n"); + g_free(wc_filename); + } else { + char *l_filename = g_locale_from_utf8(filename, + -1, NULL, NULL, NULL); + if (!PlaySoundA(l_filename, NULL, SND_ASYNC | SND_FILENAME)) + purple_debug(PURPLE_DEBUG_ERROR, "sound", "Error playing sound.\n"); + g_free(l_filename); + } +#endif /* _WIN32 */ +} + +static void +finch_sound_play_event(PurpleSoundEventID event) +{ + char *enable_pref; + char *file_pref; + if ((event == PURPLE_SOUND_BUDDY_ARRIVE) && mute_login_sounds) + return; + + if (event >= PURPLE_NUM_SOUNDS) { + purple_debug_error("sound", "got request for unknown sound: %d\n", event); + return; + } + + enable_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", + sounds[event].pref); + file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/file/%s", sounds[event].pref); + + /* check NULL for sounds that don't have an option, ie buddy pounce */ + if (purple_prefs_get_bool(enable_pref)) { + char *filename = g_strdup(purple_prefs_get_path(file_pref)); + if(!filename || !strlen(filename)) { + g_free(filename); + /* XXX Consider creating a constant for "sounds/purple" to be shared with Pidgin */ + filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); + } + + purple_sound_play_file(filename, NULL); + g_free(filename); + } + + g_free(enable_pref); + g_free(file_pref); +} + +static void +save_cb(GntWidget *button, gpointer win) +{ + GList * itr; + + purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/method", gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->method))); + purple_prefs_set_path(FINCH_PREFS_ROOT "/sound/command", gnt_entry_get_text(GNT_ENTRY(pref_dialog->command))); + purple_prefs_set_bool(FINCH_PREFS_ROOT "/sound/conv_focus",gnt_check_box_get_checked(GNT_CHECK_BOX(pref_dialog->conv_focus))); + purple_prefs_set_int("/purple/sound/while_status",GPOINTER_TO_INT(gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->while_status)))); + purple_prefs_set_int(FINCH_PREFS_ROOT "/sound/volume",gnt_slider_get_value(GNT_SLIDER(pref_dialog->volume))); + + for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ + FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(itr->data)]; + char * filepref = g_strdup_printf("%s/sound/file/%s",FINCH_PREFS_ROOT,event->pref); + char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s",event->pref); + purple_prefs_set_bool(boolpref,gnt_tree_get_choice(GNT_TREE(pref_dialog->events),itr->data)); + purple_prefs_set_path(filepref,event->file ? event->file : ""); + g_free(filepref); + g_free(boolpref); + } + gnt_widget_destroy(GNT_WIDGET(win)); +} +static void +file_cb(GntWidget *w, gpointer data) +{ + GntFileSel *sel = GNT_FILE_SEL(data); + const char * file = gnt_file_sel_get_selected_file(sel); + gpointer key = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)); + FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(key)]; + + g_free(event->file); + event->file = g_strdup(file); + + gnt_tree_change_text(GNT_TREE(pref_dialog->events),key,1,g_path_get_basename(file)); + + gnt_widget_destroy(GNT_WIDGET(data)); +} + +static void +test_cb(GntWidget *button, gpointer null) +{ + PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events))); + FinchSoundEvent * event = &sounds[id]; + char *pref; + gboolean temp_value; + + pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", + event->pref); + + temp_value = purple_prefs_get_bool(pref); + + if (!temp_value) purple_prefs_set_bool(pref, TRUE); + + purple_sound_play_event(id, NULL); + + if (!temp_value) purple_prefs_set_bool(pref, FALSE); + + g_free(pref); +} + +static void +reset_cb(GntWidget *button,gpointer null) +{ + /* Don't dereference this pointer ! */ + gpointer key = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)); + + FinchSoundEvent * event = &sounds[GPOINTER_TO_INT(key)]; + g_free(event->file); + event->file = NULL; + gnt_tree_change_text(GNT_TREE(pref_dialog->events),key,1,"(default)"); +} + +static void +choose_cb(GntWidget *button, gpointer null) +{ + GntWidget *w = gnt_file_sel_new(); + + GntFileSel *sel = GNT_FILE_SEL(w); + gnt_file_sel_set_current_location(sel,purple_home_dir()); + + g_signal_connect_swapped(G_OBJECT(sel->cancel),"activate",G_CALLBACK(gnt_widget_destroy),sel); + g_signal_connect(G_OBJECT(sel->select),"activate",G_CALLBACK(file_cb),sel); + + gnt_widget_show(w); +} + +static void +release_pref_dialog(GntBindable *data, gpointer null) +{ + GList * itr; + for(itr = gnt_tree_get_rows(GNT_TREE(pref_dialog->events));itr;itr = itr->next){ + PurpleSoundEventID id = GPOINTER_TO_INT(itr->data); + FinchSoundEvent * e = &sounds[id]; + g_free(e->file); + } + g_free(pref_dialog); + pref_dialog = NULL; +} + +void +finch_sounds_show_all(void) +{ + GntWidget *box; + GntWidget *cmbox; + GntWidget *slider; + GntWidget *entry; + GntWidget *chkbox; + GntWidget *button; + GntWidget *label; + GntWidget *tree; + GntWidget *win; + + gint i; + + if(pref_dialog){ + gnt_window_present(pref_dialog->window); + return; + } + + + pref_dialog = g_new0(SoundPrefDialog,1); + + pref_dialog->window = win = gnt_window_box_new(FALSE,TRUE); + gnt_box_set_pad(GNT_BOX(win),0); + gnt_box_set_fill(GNT_BOX(win),FALSE); + gnt_box_set_toplevel(GNT_BOX(win), TRUE); + gnt_box_set_title(GNT_BOX(win),_("Sound Preferences")); + gnt_box_set_fill(GNT_BOX(win),TRUE); + gnt_box_set_alignment(GNT_BOX(win),GNT_ALIGN_LEFT); + + pref_dialog->method = cmbox = gnt_combo_box_new(); + gnt_tree_set_hash_fns(GNT_TREE(GNT_COMBO_BOX(cmbox)->dropdown), g_str_hash, g_str_equal, NULL); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"automatic",_("Automatic")); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"alsa","ALSA"); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"esd","ESD"); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"beep",_("Console Beep")); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"custom",_("Command")); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"nosound",_("No Sound")); + gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),(gchar *)purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method")); + + label = gnt_label_new_with_format(_("Sound Method"),GNT_TEXT_FLAG_BOLD); + gnt_box_add_widget(GNT_BOX(win),label); + box = gnt_hbox_new(TRUE); + gnt_box_set_fill(GNT_BOX(box),FALSE); + gnt_box_set_pad(GNT_BOX(box),0); + gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Method: "))); + gnt_box_add_widget(GNT_BOX(box),cmbox); + gnt_box_add_widget(GNT_BOX(win),box); + + box = gnt_hbox_new(TRUE); + gnt_box_set_pad(GNT_BOX(box),0); + gnt_box_set_fill(GNT_BOX(box),FALSE); + gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Sound Command\n(%s for filename)"))); + pref_dialog->command = entry = gnt_entry_new(purple_prefs_get_path(FINCH_PREFS_ROOT "/sound/command")); + gnt_box_add_widget(GNT_BOX(box),entry); + gnt_box_add_widget(GNT_BOX(win),box); + + gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); + + gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Options"),GNT_TEXT_FLAG_BOLD)); + pref_dialog->conv_focus = chkbox = gnt_check_box_new(_("Sounds when conversation has focus")); + gnt_check_box_set_checked(GNT_CHECK_BOX(chkbox),purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus")); + gnt_box_add_widget(GNT_BOX(win),chkbox); + + box = gnt_hbox_new(TRUE); + gnt_box_set_pad(GNT_BOX(box),0); + gnt_box_set_fill(GNT_BOX(box),FALSE); + gnt_box_add_widget(GNT_BOX(box),gnt_label_new("Enable Sounds:")); + pref_dialog->while_status = cmbox = gnt_combo_box_new(); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(3),_("Always")); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(1),_("Only when available")); + gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(2),_("Only when not available")); + gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status"))); + gnt_box_add_widget(GNT_BOX(box),cmbox); + gnt_box_add_widget(GNT_BOX(win),box); + + box = gnt_hbox_new(TRUE); + gnt_box_set_pad(GNT_BOX(box),0); + gnt_box_set_fill(GNT_BOX(box),FALSE); + gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Volume(0-100):"))); + + pref_dialog->volume = slider = gnt_slider_new(FALSE,100,0); + gnt_slider_set_step(GNT_SLIDER(slider),5); + label = gnt_label_new(""); + gnt_slider_reflect_label(GNT_SLIDER(slider),GNT_LABEL(label)); + gnt_slider_set_value(GNT_SLIDER(slider),CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100)); + gnt_box_set_pad(GNT_BOX(box),1); + gnt_box_add_widget(GNT_BOX(box),slider); + gnt_box_add_widget(GNT_BOX(box),label); + gnt_box_add_widget(GNT_BOX(win),box); + + gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE)); + + gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); + pref_dialog->events = tree = gnt_tree_new_with_columns(2); + gnt_tree_set_column_titles(GNT_TREE(tree),_("Event"),_("File")); + gnt_tree_set_show_title(GNT_TREE(tree),TRUE); + + for(i = 0;i < PURPLE_NUM_SOUNDS;i++){ + FinchSoundEvent * event = &sounds[i]; + gchar *boolpref; + gchar *filepref; + + boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/enabled/%s", event->pref); + + filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/file/%s", event->pref); + event->file = g_strdup(purple_prefs_get_path(filepref)); + if(event->label == NULL){ + continue; + } + + gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i), + gnt_tree_create_row(GNT_TREE(tree),event->label,event->file[0] ? g_path_get_basename(event->file) : "(default)"), + NULL, NULL); + gnt_tree_set_choice(GNT_TREE(tree),GINT_TO_POINTER(i),purple_prefs_get_bool(boolpref)); + g_free(boolpref); + g_free(filepref); + } + + gnt_tree_adjust_columns(GNT_TREE(tree)); + gnt_box_add_widget(GNT_BOX(win),tree); + + box = gnt_hbox_new(TRUE); + button = gnt_button_new("Test"); + g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(test_cb),NULL); + gnt_box_add_widget(GNT_BOX(box),button); + button = gnt_button_new("Reset"); + g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(reset_cb),NULL); + gnt_box_add_widget(GNT_BOX(box),button); + button = gnt_button_new("Choose..."); + g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(choose_cb),NULL); + gnt_box_add_widget(GNT_BOX(box),button); + gnt_box_add_widget(GNT_BOX(win),box); + + box = gnt_hbox_new(TRUE); + gnt_box_set_pad(GNT_BOX(box),0); + gnt_box_set_fill(GNT_BOX(box),TRUE); + button = gnt_button_new("Save"); + g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(save_cb),win); + gnt_box_add_widget(GNT_BOX(box),button); + button = gnt_button_new("Cancel"); + g_signal_connect_swapped(G_OBJECT(button),"activate",G_CALLBACK(gnt_widget_destroy),win); + gnt_box_add_widget(GNT_BOX(box),button); + gnt_box_add_widget(GNT_BOX(win),box); + + + g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL); + + gnt_widget_show(win); + +} + +static PurpleSoundUiOps sound_ui_ops = +{ + finch_sound_init, + finch_sound_uninit, + finch_sound_play_file, + finch_sound_play_event, + NULL, + NULL, + NULL, + NULL +}; + +PurpleSoundUiOps * +finch_sound_get_ui_ops(void) +{ + return &sound_ui_ops; +} diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntsound.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/finch/gntsound.h Sat Jul 07 00:41:03 2007 +0000 @@ -0,0 +1,72 @@ +/** + * @file gntsound.h GNT Sound API + * @ingroup finch + * + * finch + * + * Finch is the legal property of its developers, whose names are too numerous + * to list here. Please refer to the COPYRIGHT file distributed with this + * source distribution. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GNT_SOUND_H +#define _GNT_SOUND_H + +#include "sound.h" + +/**********************************************************************/ +/** @name GNT Sound API */ +/**********************************************************************/ +/*@{*/ + +/** +* Get the prefs option for an event. +* +* @param event The event. +* @return The option. +*/ +const char *finch_sound_get_event_option(PurpleSoundEventID event); + +/** +* Get the label for an event. +* +* @param event The event. +* @return The label. +*/ +const char *finch_sound_get_event_label(PurpleSoundEventID event); + +/** +* Gets GNT sound UI ops. +* +* @return The UI operations structure. +*/ +PurpleSoundUiOps *finch_sound_get_ui_ops(void); + +/** + * Show the sound settings dialog. + */ +void finch_sounds_show_all(void); + +/** +* Get the handle for the GNT sound system. +* +* @return The handle to the sound system +*/ +void *finch_sound_get_handle(void); + +/*@}*/ + +#endif diff -r 7122bcebf7c9 -r 7a5025b8698c finch/gntui.c --- a/finch/gntui.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/gntui.c Sat Jul 07 00:41:03 2007 +0000 @@ -35,6 +35,7 @@ #include "gntprefs.h" #include "gntrequest.h" #include "gntstatus.h" +#include "gntsound.h" #include @@ -58,6 +59,9 @@ finch_blist_init(); purple_blist_set_ui_ops(finch_blist_get_ui_ops()); + /* Initialize sound */ + purple_sound_set_ui_ops(finch_sound_get_ui_ops()); + /* Now the conversations */ finch_conversation_init(); purple_conversations_set_ui_ops(finch_conv_get_ui_ops()); @@ -80,6 +84,7 @@ gnt_register_action(_("Debug Window"), finch_debug_window_show); gnt_register_action(_("File Transfers"), finch_xfer_dialog_show); gnt_register_action(_("Plugins"), finch_plugins_show_all); + gnt_register_action(_("Sounds"), finch_sounds_show_all); gnt_register_action(_("Preferences"), finch_prefs_show_all); gnt_register_action(_("Statuses"), finch_savedstatus_show_all); diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gnt.h --- a/finch/libgnt/gnt.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gnt.h Sat Jul 07 00:41:03 2007 +0000 @@ -156,4 +156,3 @@ gint *stin, gint *stout, gint *sterr); gboolean gnt_is_refugee(void); - diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntbindable.c --- a/finch/libgnt/gntbindable.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntbindable.c Sat Jul 07 00:41:03 2007 +0000 @@ -20,13 +20,198 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "gntbindable.h" #include "gntstyle.h" #include "gnt.h" #include "gntutils.h" +#include "gnttextview.h" +#include "gnttree.h" +#include "gntbox.h" +#include "gntbutton.h" +#include "gntwindow.h" +#include "gntlabel.h" static GObjectClass *parent_class = NULL; +static struct +{ + char * okeys; /* Old keystrokes */ + char * keys; /* New Keystrokes being bound to the action */ + GntBindableClass * klass; /* Class of the object that's getting keys rebound */ + char * name; /* The name of the action */ + GList * params; /* The list of paramaters */ + +} rebind_info = {NULL,NULL,NULL,NULL,NULL}; + +static void +gnt_bindable_free_rebind_info() +{ + g_free(rebind_info.name); + g_free(rebind_info.keys); + g_free(rebind_info.okeys); +} + +static void +gnt_bindable_rebinding_cancel(GntWidget *button, gpointer data) +{ + gnt_bindable_free_rebind_info(); + gnt_widget_destroy(GNT_WIDGET(data)); +} + +static void +gnt_bindable_rebinding_rebind(GntWidget *button, gpointer data) +{ + + if(rebind_info.keys) { + gnt_bindable_register_binding(rebind_info.klass, + NULL, + rebind_info.okeys, + rebind_info.params); + gnt_bindable_register_binding(rebind_info.klass, + rebind_info.name, + rebind_info.keys, + rebind_info.params); + } + gnt_bindable_free_rebind_info(); + + gnt_widget_destroy(GNT_WIDGET(data)); +} + +static gboolean +gnt_bindable_rebinding_grab_key(GntBindable *bindable, const char *text, gpointer *data) +{ + + GntTextView *textview= GNT_TEXT_VIEW(data); + char *new_text; + const char *tmp; + + if(text && *text){ + + if(!strcmp(text, GNT_KEY_CTRL_I) || !strcmp(text, GNT_KEY_ENTER)){ + return FALSE; + } + + tmp = gnt_key_lookup(text); + new_text = g_strdup_printf("KEY: \"%s\"",tmp); + gnt_text_view_clear(textview); + gnt_text_view_append_text_with_flags(textview,new_text,GNT_TEXT_FLAG_NORMAL); + g_free(new_text); + + g_free(rebind_info.keys); + rebind_info.keys = g_strdup(text); + + + return TRUE; + } + return FALSE; +} +static void +gnt_bindable_rebinding_activate(GntBindable *data, gpointer bindable) +{ + + GntTree * tree = GNT_TREE(data); + + GntWidget *vbox = gnt_box_new(FALSE,TRUE); + + GntWidget *label; + const char * widget_name = g_type_name(G_OBJECT_TYPE(bindable)); + char * keys; + + GntWidget *key_textview; + + GntWidget *bind_button, *cancel_button; + GntWidget *button_box; + + GntWidget *win = gnt_window_new(); + GList * current_row_data,*itr; + char * tmp; + + rebind_info.klass = GNT_BINDABLE_GET_CLASS(bindable); + + current_row_data = gnt_tree_get_selection_text_list(tree); + rebind_info.name = g_strdup(g_list_nth_data(current_row_data,1)); + + keys = gnt_tree_get_selection_data(tree); + rebind_info.okeys = g_strdup(gnt_key_translate(keys)); + + rebind_info.params = NULL; + + itr = current_row_data; + while(itr){ + g_free(itr->data); + itr = itr->next; + } + g_list_free(current_row_data); + + gnt_box_set_alignment(GNT_BOX(vbox), GNT_ALIGN_MID); + + gnt_box_set_title(GNT_BOX(win),"Key Capture"); + + tmp = g_strdup_printf("Type the new bindings for %s in a %s.",rebind_info.name,widget_name); + label = gnt_label_new(tmp); + g_free(tmp); + gnt_box_add_widget(GNT_BOX(vbox),label); + + tmp = g_strdup_printf("KEY: \"%s\"",keys); + key_textview = gnt_text_view_new(); + gnt_widget_set_size(key_textview,key_textview->priv.x,2); + gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(key_textview),tmp,GNT_TEXT_FLAG_NORMAL); + g_free(tmp); + gnt_widget_set_name(key_textview,"keystroke"); + gnt_box_add_widget(GNT_BOX(vbox),key_textview); + + g_signal_connect(G_OBJECT(win), "key_pressed", G_CALLBACK(gnt_bindable_rebinding_grab_key),key_textview); + + button_box = gnt_box_new(FALSE,FALSE); + + bind_button = gnt_button_new("BIND"); + gnt_widget_set_name(bind_button,"bind"); + gnt_box_add_widget(GNT_BOX(button_box), bind_button); + + cancel_button = gnt_button_new("Cancel"); + gnt_widget_set_name(cancel_button,"cancel"); + gnt_box_add_widget(GNT_BOX(button_box),cancel_button); + + g_signal_connect(G_OBJECT(bind_button), "activate", G_CALLBACK(gnt_bindable_rebinding_rebind),win); + g_signal_connect(G_OBJECT(cancel_button), "activate", G_CALLBACK(gnt_bindable_rebinding_cancel),win); + + + gnt_box_add_widget(GNT_BOX(vbox),button_box); + + gnt_box_add_widget(GNT_BOX(win),vbox); + gnt_widget_show(win); + +} + +typedef struct { + GHashTable *hash; + GntTree *tree; +} BindingView; + +static void +add_binding(gpointer key, gpointer value, gpointer data) +{ + BindingView *bv = data; + GntBindableActionParam *act = value; + const char *name = g_hash_table_lookup(bv->hash, act->action); + if (name && *name) { + const char *k = gnt_key_lookup(key); + if (!k) + k = key; + gnt_tree_add_row_after(bv->tree, (gpointer)k, + gnt_tree_create_row(bv->tree, k, name), NULL, NULL); + } +} + +static void +add_action(gpointer key, gpointer value, gpointer data) +{ + BindingView *bv = data; + g_hash_table_insert(bv->hash, value, key); +} + static void gnt_bindable_class_init(GntBindableClass *klass) { @@ -251,4 +436,56 @@ g_free(param); } +GntBindable * gnt_bindable_bindings_view(GntBindable *bind) +{ + GntBindable *tree = GNT_BINDABLE(gnt_tree_new_with_columns(2)); + GntBindableClass *klass = GNT_BINDABLE_CLASS(GNT_BINDABLE_GET_CLASS(bind)); + GHashTable *hash = g_hash_table_new(g_direct_hash, g_direct_equal); + BindingView bv = {hash, GNT_TREE(tree)}; + gnt_tree_set_compare_func(bv.tree, (GCompareFunc)g_utf8_collate); + g_hash_table_foreach(klass->actions, add_action, &bv); + g_hash_table_foreach(klass->bindings, add_binding, &bv); + if (GNT_TREE(tree)->list == NULL) { + gnt_widget_destroy(GNT_WIDGET(tree)); + tree = NULL; + } else + gnt_tree_adjust_columns(bv.tree); + g_hash_table_destroy(hash); + + return tree; +} + +static void +reset_binding_window(GntBindableClass *window, gpointer k) +{ + GntBindableClass *klass = GNT_BINDABLE_CLASS(k); + klass->help_window = NULL; +} + +gboolean +gnt_bindable_build_help_window(GntBindable *bindable) +{ + + GntWidget *tree; + GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable); + char *title; + + tree = GNT_WIDGET(gnt_bindable_bindings_view(bindable)); + + klass->help_window = GNT_BINDABLE(gnt_window_new()); + title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(bindable))); + gnt_box_set_title(GNT_BOX(klass->help_window), title); + if (tree) { + g_signal_connect(G_OBJECT(tree), "activate", G_CALLBACK(gnt_bindable_rebinding_activate), bindable); + gnt_box_add_widget(GNT_BOX(klass->help_window), tree); + } else + gnt_box_add_widget(GNT_BOX(klass->help_window), gnt_label_new("This widget has no customizable bindings.")); + + g_signal_connect(G_OBJECT(klass->help_window), "destroy", G_CALLBACK(reset_binding_window), klass); + gnt_widget_show(GNT_WIDGET(klass->help_window)); + g_free(title); + + return TRUE; +} + diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntbindable.h --- a/finch/libgnt/gntbindable.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntbindable.h Sat Jul 07 00:41:03 2007 +0000 @@ -57,7 +57,8 @@ GHashTable *actions; /* name -> Action */ GHashTable *bindings; /* key -> ActionParam */ - void (*gnt_reserved1)(void); + GntBindable * help_window; + void (*gnt_reserved2)(void); void (*gnt_reserved3)(void); void (*gnt_reserved4)(void); @@ -150,6 +151,31 @@ */ gboolean gnt_bindable_perform_action_named(GntBindable *bindable, const char *name, ...); +/** +* Returns a GntTree populated with "key" -> "binding" for the widget. +*/ +/** +* +* @param widget +* +* @return +*/ +GntBindable * gnt_bindable_bindings_view(GntBindable *bind); + +/** + * + * Builds a window that list the key bindings for a GntBindable object. From this window a user can select a listing to rebind a new key for the given action. + * + */ +/** + * + * @param bindable + * + * @return + */ + +gboolean gnt_bindable_build_help_window(GntBindable *bindable); + G_END_DECLS #endif /* GNT_BINDABLE_H */ diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntbox.c --- a/finch/libgnt/gntbox.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntbox.c Sat Jul 07 00:41:03 2007 +0000 @@ -315,10 +315,6 @@ { find_next_focus(box); } - else if (strcmp(text, GNT_KEY_BACK_TAB) == 0) - { - find_prev_focus(box); - } } else if (text[0] == '\t') { diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntcombobox.h --- a/finch/libgnt/gntcombobox.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntcombobox.h Sat Jul 07 00:41:03 2007 +0000 @@ -69,7 +69,8 @@ G_BEGIN_DECLS /** - * + * + * Get the GType for GntComboBox * * @return */ @@ -77,44 +78,55 @@ /** * + * Create a new GntComboBox * - * @return + * @return A new GntComboBox */ GntWidget * gnt_combo_box_new(void); /** * - * @param box - * @param key - * @param text + * Add an entry + * + * @param box The GntComboBox + * @param key The data + * @param text The text to display */ void gnt_combo_box_add_data(GntComboBox *box, gpointer key, const char *text); /** + * + * Remove an entry * - * @param box - * @param key + * @param box The GntComboBox + * @param key The data to be removed */ void gnt_combo_box_remove(GntComboBox *box, gpointer key); /** * - * @param box + * Remove all entries + * + * @param box The GntComboBox */ void gnt_combo_box_remove_all(GntComboBox *box); /** * - * @param box + * Get the data that is currently selected * - * @return + * @param box The GntComboBox + * + * @return The data of the currently selected entry */ gpointer gnt_combo_box_get_selected_data(GntComboBox *box); /** * - * @param box - * @param key + * Set the current selection to a specific entry + * + * @param box The GntComboBox + * @param key The data to be set to */ void gnt_combo_box_set_selected(GntComboBox *box, gpointer key); diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntkeys.c --- a/finch/libgnt/gntkeys.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntkeys.c Sat Jul 07 00:41:03 2007 +0000 @@ -72,7 +72,6 @@ INSERT_KEY("pagedown", GNT_KEY_PGDOWN); INSERT_KEY("insert", GNT_KEY_INS); INSERT_KEY("delete", GNT_KEY_DEL); - INSERT_KEY("back_tab", GNT_KEY_BACK_TAB); INSERT_KEY("left", GNT_KEY_LEFT); INSERT_KEY("right", GNT_KEY_RIGHT); @@ -206,8 +205,8 @@ node->flags |= IS_END; return; } - while (*path && node->next[(unsigned char)*path]) { - node = node->next[(unsigned char)*path]; + while (*path && node->next[*path]) { + node = node->next[*path]; node->ref++; path++; } @@ -215,7 +214,7 @@ return; n = g_new0(struct _node, 1); n->ref = 1; - node->next[(unsigned char)*path++] = n; + node->next[*path++] = n; add_path(n, path); } @@ -230,13 +229,13 @@ if (!*path) return; - next = node->next[(unsigned char)*path]; + next = node->next[*path]; if (!next) return; del_path(next, path + 1); next->ref--; if (next->ref == 0) { - node->next[(unsigned char)*path] = NULL; + node->next[*path] = NULL; g_free(next); } } @@ -252,12 +251,12 @@ struct _node *n = &root; root.flags &= ~IS_END; - while (*path && n->next[(unsigned char)*path] && !(n->flags & IS_END)) { + while (*path && n->next[*path] && !(n->flags & IS_END)) { if (!g_ascii_isspace(*path) && !g_ascii_iscntrl(*path) && !g_ascii_isgraph(*path)) return 0; - n = n->next[(unsigned char)*path++]; + n = n->next[*path++]; depth++; } diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntmain.c --- a/finch/libgnt/gntmain.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntmain.c Sat Jul 07 00:41:03 2007 +0000 @@ -252,6 +252,12 @@ if (HOLDING_ESCAPE) keys[0] = '\033'; k = keys; + if(*k < 0){ /* Alt not sending ESC* */ + *(k + 1) = 128 - *k; + *k = 27; + *(k + 2) = 0; + rd++; + } while (rd) { char back; int p; diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntmenu.c --- a/finch/libgnt/gntmenu.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntmenu.c Sat Jul 07 00:41:03 2007 +0000 @@ -337,10 +337,7 @@ static void gnt_menu_hide(GntWidget *widget) { - GntMenu *sub, *menu = GNT_MENU(widget); - - while ((sub = menu->submenu)) - gnt_widget_hide(GNT_WIDGET(sub)); + GntMenu *menu = GNT_MENU(widget); if (menu->parentmenu) menu->parentmenu->submenu = NULL; } diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntslider.c --- a/finch/libgnt/gntslider.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntslider.c Sat Jul 07 00:41:03 2007 +0000 @@ -241,6 +241,11 @@ slider_value_changed(slider); } +int gnt_slider_get_value(GntSlider *slider) +{ + return slider->current; +} + int gnt_slider_advance_step(GntSlider *slider, int steps) { slider->current += steps * slider->step; diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntslider.h --- a/finch/libgnt/gntslider.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntslider.h Sat Jul 07 00:41:03 2007 +0000 @@ -127,6 +127,14 @@ void gnt_slider_set_value(GntSlider *slider, int value); /** + * Get the current value for the slider. + * + * @param slider The slider + * + */ +int gnt_slider_get_value(GntSlider *slider); + +/** * Update a label with the value of the slider whenever the value changes. * * @param slider The slider @@ -134,6 +142,7 @@ */ void gnt_slider_reflect_label(GntSlider *slider, GntLabel *label); + G_END_DECLS #endif /* GNT_SLIDER_H */ diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntstyle.c --- a/finch/libgnt/gntstyle.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntstyle.c Sat Jul 07 00:41:03 2007 +0000 @@ -22,6 +22,7 @@ #include "gntstyle.h" #include "gntcolors.h" + #include "gntws.h" #include diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntutils.h --- a/finch/libgnt/gntutils.h Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntutils.h Sat Jul 07 00:41:03 2007 +0000 @@ -40,6 +40,7 @@ */ void gnt_util_get_text_bound(const char *text, int *width, int *height); +/* excluding *end */ /** * Get the onscreen width of a string, or a substring. * diff -r 7122bcebf7c9 -r 7a5025b8698c finch/libgnt/gntwm.c --- a/finch/libgnt/gntwm.c Sat Jul 07 00:30:45 2007 +0000 +++ b/finch/libgnt/gntwm.c Sat Jul 07 00:41:03 2007 +0000 @@ -34,7 +34,9 @@ #include #include +#include "gntbutton.h" #include "gntwm.h" +#include "gntentry.h" #include "gntstyle.h" #include "gntmarshal.h" #include "gnt.h" @@ -84,6 +86,7 @@ static time_t last_active_time; static gboolean idle_update; static GList *act = NULL; /* list of WS with unseen activitiy */ +static gboolean ignore_keys = FALSE; static GList * g_list_bring_to_front(GList *list, gpointer data) @@ -485,35 +488,6 @@ return TRUE; } -static gboolean -help_for_widget(GntBindable *bindable, GList *null) -{ - GntWM *wm = GNT_WM(bindable); - GntWidget *widget, *tree, *win, *active; - char *title; - - if (!wm->cws->ordered) - return TRUE; - - widget = wm->cws->ordered->data; - if (!GNT_IS_BOX(widget)) - return TRUE; - active = GNT_BOX(widget)->active; - - tree = gnt_widget_bindings_view(active); - win = gnt_window_new(); - title = g_strdup_printf("Bindings for %s", g_type_name(G_OBJECT_TYPE(active))); - gnt_box_set_title(GNT_BOX(win), title); - if (tree) - gnt_box_add_widget(GNT_BOX(win), tree); - else - gnt_box_add_widget(GNT_BOX(win), gnt_label_new("This widget has no customizable bindings.")); - - gnt_widget_show(win); - - return TRUE; -} - static void destroy__list(GntWidget *widget, GntWM *wm) { @@ -1129,6 +1103,71 @@ return TRUE; } +static gboolean +ignore_keys_start(GntBindable *bindable, GList *n) +{ + GntWM *wm = GNT_WM(bindable); + + if(!wm->menu && !wm->_list.window && wm->mode == GNT_KP_MODE_NORMAL){ + ignore_keys = TRUE; + return TRUE; + } + return FALSE; +} + +static gboolean +ignore_keys_end(GntBindable *bindable, GList *n) +{ + return ignore_keys ? !(ignore_keys = FALSE) : FALSE; +} + +static gboolean +help_for_bindable(GntWM *wm, GntBindable *bindable) +{ + gboolean ret = TRUE; + GntBindableClass *klass = GNT_BINDABLE_GET_CLASS(bindable); + + if (klass->help_window) { + gnt_wm_raise_window(wm, GNT_WIDGET(klass->help_window)); + } else { + ret = gnt_bindable_build_help_window(bindable); + } + return ret; + +} + +static gboolean +help_for_wm(GntBindable *bindable, GList *null) +{ + return help_for_bindable(GNT_WM(bindable),bindable); +} + +static gboolean +help_for_window(GntBindable *bindable, GList *null) +{ + GntWM *wm = GNT_WM(bindable); + GntWidget *widget = wm->cws->ordered->data; + + return help_for_bindable(wm,GNT_BINDABLE(widget)); +} + +static gboolean +help_for_widget(GntBindable *bindable, GList *null) +{ + GntWM *wm = GNT_WM(bindable); + GntWidget *widget; + + if (!wm->cws->ordered) + return TRUE; + + widget = wm->cws->ordered->data; + if (!GNT_IS_BOX(widget)) + return TRUE; + + return help_for_bindable(wm, GNT_BINDABLE(GNT_BOX(widget)->active)); + +} + static void gnt_wm_class_init(GntWMClass *klass) { @@ -1286,6 +1325,16 @@ "\033" "s", NULL); gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", toggle_clipboard, "\033" "C", NULL); + gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-wm", help_for_wm, + "\033" "\\", NULL); + gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "help-for-window", help_for_window, + "\033" "|", NULL); + gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "toggle-clipboard", toggle_clipboard, + "\033" "C", NULL); + gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-start", ignore_keys_start, + GNT_KEY_CTRL_G, NULL); + gnt_bindable_class_register_action(GNT_BINDABLE_CLASS(klass), "ignore-keys-end", ignore_keys_end, + "\033" GNT_KEY_CTRL_G, NULL); gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass)); @@ -1672,6 +1721,14 @@ keys = gnt_bindable_remap_keys(GNT_BINDABLE(wm), keys); idle_update = TRUE; + if(ignore_keys){ + if(keys && !strcmp(keys, "\033" GNT_KEY_CTRL_G)){ + if(gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)){ + return TRUE; + } + } + return wm->cws->ordered ? gnt_widget_key_pressed(GNT_WIDGET(wm->cws->ordered->data), keys) : FALSE; + } if (gnt_bindable_perform_action_key(GNT_BINDABLE(wm), keys)) { return TRUE; diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/Makefile.am --- a/pidgin/Makefile.am Sat Jul 07 00:30:45 2007 +0000 +++ b/pidgin/Makefile.am Sat Jul 07 00:41:03 2007 +0000 @@ -65,7 +65,7 @@ pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = pidgin.pc -SUBDIRS = pixmaps plugins sounds +SUBDIRS = pixmaps plugins bin_PROGRAMS = pidgin diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/gtksound.c --- a/pidgin/gtksound.c Sat Jul 07 00:30:45 2007 +0000 +++ b/pidgin/gtksound.c Sat Jul 07 00:41:03 2007 +0000 @@ -543,7 +543,8 @@ char *filename = g_strdup(purple_prefs_get_path(file_pref)); if(!filename || !strlen(filename)) { g_free(filename); - filename = g_build_filename(DATADIR, "sounds", "pidgin", sounds[event].def, NULL); + /* XXX Consider creating a constant for "sounds/purple" to be shared with Finch */ + filename = g_build_filename(DATADIR, "sounds", "purple", sounds[event].def, NULL); } purple_sound_play_file(filename, NULL); diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/Makefile.am --- a/pidgin/sounds/Makefile.am Sat Jul 07 00:30:45 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -soundsdir = $(datadir)/sounds/pidgin -sounds_DATA = \ - alert.wav \ - login.wav \ - logout.wav \ - receive.wav \ - send.wav - -EXTRA_DIST = \ - Makefile.mingw \ - $(sounds_DATA) - diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/Makefile.mingw --- a/pidgin/sounds/Makefile.mingw Sat Jul 07 00:30:45 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -# -# Makefile.mingw -# -# Description: Makefile for win32 (mingw) version of Pidgin sounds -# - -PIDGIN_TREE_TOP := ../.. -include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak - -datadir := $(PIDGIN_INSTALL_DIR) -include ./Makefile.am - -.PHONY: install - -install: - if test '$(sounds_DATA)'; then \ - mkdir -p $(soundsdir); \ - cp $(sounds_DATA) $(soundsdir); \ - fi; - diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/alert.wav Binary file pidgin/sounds/alert.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/login.wav Binary file pidgin/sounds/login.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/logout.wav Binary file pidgin/sounds/logout.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/receive.wav Binary file pidgin/sounds/receive.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c pidgin/sounds/send.wav Binary file pidgin/sounds/send.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c share/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/share/Makefile.am Sat Jul 07 00:41:03 2007 +0000 @@ -0,0 +1,2 @@ + +SUBDIRS = sounds diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/share/sounds/Makefile.am Sat Jul 07 00:41:03 2007 +0000 @@ -0,0 +1,12 @@ +soundsdir = $(datadir)/sounds/purple +sounds_DATA = \ + alert.wav \ + login.wav \ + logout.wav \ + receive.wav \ + send.wav + +EXTRA_DIST = \ + Makefile.mingw \ + $(sounds_DATA) + diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/Makefile.mingw --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/share/sounds/Makefile.mingw Sat Jul 07 00:41:03 2007 +0000 @@ -0,0 +1,20 @@ +# +# Makefile.mingw +# +# Description: Makefile for win32 (mingw) version of Pidgin sounds +# + +PIDGIN_TREE_TOP := ../.. +include $(PIDGIN_TREE_TOP)/libpurple/win32/global.mak + +datadir := $(PIDGIN_INSTALL_DIR) +include ./Makefile.am + +.PHONY: install + +install: + if test '$(sounds_DATA)'; then \ + mkdir -p $(soundsdir); \ + cp $(sounds_DATA) $(soundsdir); \ + fi; + diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/alert.wav Binary file share/sounds/alert.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/login.wav Binary file share/sounds/login.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/logout.wav Binary file share/sounds/logout.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/receive.wav Binary file share/sounds/receive.wav has changed diff -r 7122bcebf7c9 -r 7a5025b8698c share/sounds/send.wav Binary file share/sounds/send.wav has changed