changeset 19172:069c036d9b72

propagate from branch 'tmpbranch' (head fd482c25cc81ccebcc993d06cad489169e942c22) to branch 'im.pidgin.soc.2007.finchfeat' (head 627c3377bc204d06f54462d88bd59d01fbb753a1)
author Eric Polino <aluink@pidgin.im>
date Tue, 24 Jul 2007 19:39:58 +0000
parents 9f7587b86b0d (diff) cf9dfbbe8cd6 (current diff)
children e9151f52a4f1
files finch/gntblist.c pidgin/sounds/Makefile.am pidgin/sounds/Makefile.mingw pidgin/sounds/alert.wav pidgin/sounds/login.wav pidgin/sounds/logout.wav pidgin/sounds/receive.wav pidgin/sounds/send.wav
diffstat 40 files changed, 1630 insertions(+), 100 deletions(-) [+]
line wrap: on
line diff
--- a/COPYRIGHT	Tue Jul 24 19:39:37 2007 +0000
+++ b/COPYRIGHT	Tue Jul 24 19:39:58 2007 +0000
@@ -276,6 +276,7 @@
 Joao Luís Marques Pinto
 Aleksander Piotrowski
 Julien Pivotto
+Eric Polino <aluink@gmail.com>
 Ari Pollak
 Robey Pointer
 Eric Polino
--- a/Makefile.am	Tue Jul 24 19:39:37 2007 +0000
+++ b/Makefile.am	Tue Jul 24 19:39:58 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
--- a/configure.ac	Tue Jul 24 19:39:37 2007 +0000
+++ b/configure.ac	Tue Jul 24 19:39:58 2007 +0000
@@ -2038,6 +2038,8 @@
 	AC_DEFINE(DEBUG, 1, [Define if debugging is enabled.])
 fi
 
+AM_CONDITIONAL(PURPLE_AVAILABLE, true)
+
 AC_OUTPUT([Makefile
 		   Doxyfile
 		   doc/Makefile
@@ -2116,7 +2118,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
@@ -2149,6 +2150,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
--- a/finch/Makefile.am	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/Makefile.am	Tue Jul 24 19:39:58 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)
--- a/finch/finch.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/finch.h	Tue Jul 24 19:39:58 2007 +0000
@@ -27,3 +27,4 @@
 
 #define FINCH_UI "gnt-purple"
 
+#define FINCH_PREFS_ROOT "/finch"
--- a/finch/gntconv.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/gntconv.h	Tue Jul 24 19:39:58 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
  ***************************************************************************/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/gntsound.c	Tue Jul 24 19:39:58 2007 +0000
@@ -0,0 +1,1059 @@
+/**
+ * @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 <windows.h>
+#include <mmsystem.h>
+#endif
+
+#ifdef USE_GSTREAMER
+#include <gst/gst.h>
+#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 {
+	PurpleSoundEventID id;
+	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;
+	GntWidget *selector;
+
+	GntWidget *profiles;
+	GntWidget *new_profile;
+	gchar * original_profile;
+} SoundPrefDialog;
+
+#define DEFAULT_PROFILE "default"
+
+static 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] = {
+	{PURPLE_SOUND_BUDDY_ARRIVE, N_("Buddy logs in"), "login", "login.wav", NULL},
+	{PURPLE_SOUND_BUDDY_LEAVE,  N_("Buddy logs out"), "logout", "logout.wav", NULL},
+	{PURPLE_SOUND_RECEIVE,      N_("Message received"), "im_recv", "receive.wav", NULL},
+	{PURPLE_SOUND_FIRST_RECEIVE, N_("Message received begins conversation"), "first_im_recv", "receive.wav", NULL},
+	{PURPLE_SOUND_SEND,         N_("Message sent"), "send_im", "send.wav", NULL},
+	{PURPLE_SOUND_CHAT_JOIN,    N_("Person enters chat"), "join_chat", "login.wav", NULL},
+	{PURPLE_SOUND_CHAT_LEAVE,   N_("Person leaves chat"), "left_chat", "logout.wav", NULL},
+	{PURPLE_SOUND_CHAT_YOU_SAY, N_("You talk in chat"), "send_chat_msg", "send.wav", NULL},
+	{PURPLE_SOUND_CHAT_SAY,     N_("Others talk in chat"), "chat_msg_recv", "receive.wav", NULL},
+	{PURPLE_SOUND_POUNCE_DEFAULT, NULL, "pounce_default", "alert.wav", NULL},
+	{PURPLE_SOUND_CHAT_NICK,    N_("Someone says your screen name in chat"), "nick_said", "alert.wav", NULL}
+};
+
+const char *
+finch_sound_get_active_profile()
+{
+	return purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/actprofile");
+}
+
+/* This method creates a pref name based on the current active profile.
+ * So if "Home" is the current active profile the pref name
+ * [FINCH_PREFS_ROOT "/sound/profiles/Home/$NAME"] is created.
+ */
+static gchar *
+make_pref(const char *name)
+{
+	static char pref_string[512];
+	g_snprintf(pref_string, sizeof(pref_string),
+			FINCH_PREFS_ROOT "/sound/profiles/%s%s", finch_sound_get_active_profile(), name);
+	return pref_string;
+}
+
+
+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(make_pref("/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_seconds(10, unmute_login_sounds_cb, NULL);
+}
+
+void *
+finch_sound_get_handle()
+{
+	static int handle;
+
+	return &handle;
+}
+
+
+/* This gets called when the active profile changes */
+static void
+initialize_profile(const char *name, PurplePrefType type, gconstpointer val, gpointer null)
+{
+	if (purple_prefs_exists(make_pref("")))
+		return;
+
+	purple_prefs_add_none(make_pref(""));
+	purple_prefs_add_none(make_pref("/enabled"));
+	purple_prefs_add_none(make_pref("/file"));
+	purple_prefs_add_bool(make_pref("/enabled/login"), TRUE);
+	purple_prefs_add_path(make_pref("/file/login"), "");
+	purple_prefs_add_bool(make_pref("/enabled/logout"), TRUE);
+	purple_prefs_add_path(make_pref("/file/logout"), "");
+	purple_prefs_add_bool(make_pref("/enabled/im_recv"), TRUE);
+	purple_prefs_add_path(make_pref("/file/im_recv"), "");
+	purple_prefs_add_bool(make_pref("/enabled/first_im_recv"), FALSE);
+	purple_prefs_add_path(make_pref("/file/first_im_recv"), "");
+	purple_prefs_add_bool(make_pref("/enabled/send_im"), TRUE);
+	purple_prefs_add_path(make_pref("/file/send_im"), "");
+	purple_prefs_add_bool(make_pref("/enabled/join_chat"), FALSE);
+	purple_prefs_add_path(make_pref("/file/join_chat"), "");
+	purple_prefs_add_bool(make_pref("/enabled/left_chat"), FALSE);
+	purple_prefs_add_path(make_pref("/file/left_chat"), "");
+	purple_prefs_add_bool(make_pref("/enabled/send_chat_msg"), FALSE);
+	purple_prefs_add_path(make_pref("/file/send_chat_msg"), "");
+	purple_prefs_add_bool(make_pref("/enabled/chat_msg_recv"), FALSE);
+	purple_prefs_add_path(make_pref("/file/chat_msg_recv"), "");
+	purple_prefs_add_bool(make_pref("/enabled/nick_said"), FALSE);
+	purple_prefs_add_path(make_pref("/file/nick_said"), "");
+	purple_prefs_add_bool(make_pref("/enabled/pounce_default"), TRUE);
+	purple_prefs_add_path(make_pref("/file/pounce_default"), "");
+	purple_prefs_add_bool(make_pref("/conv_focus"), TRUE);
+	purple_prefs_add_bool(make_pref("/mute"), FALSE);
+	purple_prefs_add_path(make_pref("/command"), "");
+	purple_prefs_add_string(make_pref("/method"), "automatic");
+	purple_prefs_add_int(make_pref("/volume"), 50);
+}
+
+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_string(FINCH_PREFS_ROOT "/sound/actprofile", DEFAULT_PROFILE);
+	purple_prefs_add_none(FINCH_PREFS_ROOT "/sound/profiles");
+
+	purple_prefs_connect_callback(gnt_sound_handle, FINCH_PREFS_ROOT "/sound/actprofile", initialize_profile, NULL);
+	purple_prefs_trigger_callback(FINCH_PREFS_ROOT "/sound/actprofile");
+
+	
+#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(make_pref("/mute")))
+		return;
+
+	method = purple_prefs_get_string(make_pref("/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(make_pref("/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(make_pref("/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/profiles/%s/enabled/%s",
+			finch_sound_get_active_profile(),
+			sounds[event].pref);
+	file_pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), 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);
+}
+
+GList *
+finch_sound_get_profiles()
+{
+	GList *list = NULL, *iter;
+	iter = purple_prefs_get_children_names(FINCH_PREFS_ROOT "/sound/profiles");
+	while (iter) {
+		list = g_list_append(list, g_strdup(strrchr(iter->data, '/') + 1));
+		g_free(iter->data);
+		iter = g_list_delete_link(iter, iter);
+	}
+	return list;
+}
+
+/* This will also create it if it doesn't exist */
+void
+finch_sound_set_active_profile(const char *name)
+{
+	purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile", name);
+}
+
+gboolean
+finch_sound_profile_exists(const char *name)
+{
+	gchar * tmp;
+	gboolean ret = purple_prefs_exists(tmp = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", name));
+	g_free(tmp);
+	return ret;
+}
+
+static void
+save_cb(GntWidget *button, gpointer win)
+{
+	GList * itr;
+
+	purple_prefs_set_string(make_pref("/method"), gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->method)));
+	purple_prefs_set_path(make_pref("/command"), gnt_entry_get_text(GNT_ENTRY(pref_dialog->command)));
+	purple_prefs_set_bool(make_pref("/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(make_pref("/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(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", finch_sound_get_active_profile(), event->pref);
+		char * boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", finch_sound_get_active_profile(), 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(GntFileSel *w, const char *path, const char *file, gpointer data)
+{
+	FinchSoundEvent *event = data;
+
+	g_free(event->file);
+	event->file = g_strdup(path);
+
+	gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(event->id), 1, file);
+	
+	gnt_widget_destroy(GNT_WIDGET(w));
+}
+
+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/profiles/%s/enabled/%s", finch_sound_get_active_profile(),
+			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);
+	PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)));
+	FinchSoundEvent * event = &sounds[id];
+	char *path = NULL;
+
+	gnt_file_sel_set_current_location(sel,
+			(event && event->file) ? (path = g_path_get_dirname(event->file))
+				: purple_home_dir());
+
+	g_signal_connect_swapped(G_OBJECT(sel->cancel), "activate", G_CALLBACK(gnt_widget_destroy), sel);
+	g_signal_connect(G_OBJECT(sel), "file_selected", G_CALLBACK(file_cb), event);
+	g_signal_connect_swapped(G_OBJECT(sel), "destroy", G_CALLBACK(g_nullify_pointer), &pref_dialog->selector);
+
+	/* If there's an already open file-selector, close that one. */
+	if (pref_dialog->selector)
+		gnt_widget_destroy(pref_dialog->selector);
+
+	pref_dialog->selector = w;
+
+	gnt_widget_show(w);
+	g_free(path);
+}
+
+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);
+	}
+	if (pref_dialog->selector)
+		gnt_widget_destroy(pref_dialog->selector);
+	g_free(pref_dialog);
+	pref_dialog = NULL;
+}
+
+static void
+load_pref_window(const char * profile)
+{
+	gint i;
+
+	finch_sound_set_active_profile(profile);
+
+	gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->method), (gchar *)purple_prefs_get_string(make_pref("/method")));
+
+	gnt_entry_set_text(GNT_ENTRY(pref_dialog->command), purple_prefs_get_path(make_pref("/command")));
+
+	gnt_check_box_set_checked(GNT_CHECK_BOX(pref_dialog->conv_focus), purple_prefs_get_bool(make_pref("/conv_focus")));
+
+	gnt_combo_box_set_selected(GNT_COMBO_BOX(pref_dialog->while_status), GINT_TO_POINTER(purple_prefs_get_int("/purple" "/sound/while_status")));
+
+	gnt_slider_set_value(GNT_SLIDER(pref_dialog->volume), CLAMP(purple_prefs_get_int(make_pref("/volume")), 0, 100));
+
+	for (i = 0; i < PURPLE_NUM_SOUNDS; i++) {
+		FinchSoundEvent * event = &sounds[i];
+		gchar *boolpref;
+		gchar *filepref;
+		const char * profile = finch_sound_get_active_profile();
+
+		filepref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/file/%s", profile, event->pref);
+
+		event->file = g_strdup(purple_prefs_get_path(filepref));
+
+		g_free(filepref);
+		if (event->label == NULL) {
+			continue;
+		}
+
+		boolpref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s/enabled/%s", profile, event->pref);
+
+		gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 0, event->label);
+		gnt_tree_change_text(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), 1, event->file[0] ? g_path_get_basename(event->file) : "(default)");
+
+		gnt_tree_set_choice(GNT_TREE(pref_dialog->events), GINT_TO_POINTER(i), purple_prefs_get_bool(boolpref));
+
+		g_free(boolpref);
+	}
+
+	gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), (gchar *)finch_sound_get_active_profile());
+
+	gnt_widget_draw(pref_dialog->window);
+}
+
+static void
+reload_pref_window(const char *profile)
+{
+	if (!strcmp(profile, finch_sound_get_active_profile()))
+		return;
+	load_pref_window(profile);
+}
+
+static void
+prof_del_cb(GntWidget *button, gpointer null)
+{
+	const char * profile = gnt_entry_get_text(GNT_ENTRY(pref_dialog->new_profile));
+	gchar * pref;
+
+	if (!strcmp(profile, DEFAULT_PROFILE))
+		return;
+
+	pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s", profile);
+	purple_prefs_remove(pref);
+	g_free(pref);
+
+	if (!strcmp(pref_dialog->original_profile, profile)) {
+		g_free(pref_dialog->original_profile);
+		pref_dialog->original_profile = g_strdup(DEFAULT_PROFILE);
+	}
+
+	if(!strcmp(profile, finch_sound_get_active_profile()))
+		reload_pref_window(DEFAULT_PROFILE);
+
+	gnt_tree_remove(GNT_TREE(pref_dialog->profiles), (gchar *) profile);
+}
+
+static void
+prof_add_cb(GntButton *button, GntEntry * entry)
+{
+	const char * profile = gnt_entry_get_text(entry);
+	GntTreeRow * row;
+	if (!finch_sound_profile_exists(profile)) {
+		gpointer key = g_strdup(profile);
+		row = gnt_tree_create_row(GNT_TREE(pref_dialog->profiles), profile);
+		gnt_tree_add_row_after(GNT_TREE(pref_dialog->profiles), key,
+				row,
+				NULL, NULL);
+		gnt_entry_set_text(entry, "");
+		gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles), key);
+		finch_sound_set_active_profile(key);
+	} else 
+		reload_pref_window(profile);
+}
+
+static void
+prof_load_cb(GntTree *tree, gpointer oldkey, gpointer newkey, gpointer null)
+{
+	reload_pref_window(newkey);
+}
+
+static void
+cancel_cb(GntButton *button, gpointer win)
+{
+	finch_sound_set_active_profile(pref_dialog->original_profile);
+	gnt_widget_destroy(GNT_WIDGET(win));
+}
+
+void
+finch_sounds_show_all(void)
+{
+	GntWidget *box, *tmpbox, *splitbox, *cmbox, *slider;
+	GntWidget *entry;
+	GntWidget *chkbox;
+	GntWidget *button;
+	GntWidget *label;
+	GntWidget *tree;
+	GntWidget *win;
+
+	gint i;
+	GList *itr, *list;
+
+	if (pref_dialog) {
+		gnt_window_present(pref_dialog->window);
+		return;
+	}
+
+	pref_dialog = g_new0(SoundPrefDialog, 1);
+
+	pref_dialog->original_profile = g_strdup(finch_sound_get_active_profile());
+
+	pref_dialog->window = win = gnt_window_box_new(FALSE, TRUE);
+	gnt_box_set_pad(GNT_BOX(win), 0);
+	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_MID);
+
+	/* Profiles */
+	splitbox = gnt_hbox_new(FALSE);
+	gnt_box_set_pad(GNT_BOX(splitbox), 0);
+	gnt_box_set_alignment(GNT_BOX(splitbox), GNT_ALIGN_TOP);
+
+	box = gnt_vbox_new(FALSE);
+	gnt_box_set_pad(GNT_BOX(box), 0);
+	gnt_box_add_widget(GNT_BOX(box), gnt_label_new_with_format(_("Profiles"), GNT_TEXT_FLAG_BOLD));
+	pref_dialog->profiles = tree = gnt_tree_new();
+	gnt_tree_set_hash_fns(GNT_TREE(tree), g_str_hash, g_str_equal, g_free);
+	gnt_tree_set_compare_func(GNT_TREE(tree), (GCompareFunc)g_ascii_strcasecmp);
+	g_signal_connect(G_OBJECT(tree), "selection-changed", G_CALLBACK(prof_load_cb), NULL);
+
+	itr = list = finch_sound_get_profiles();
+	for (; itr; itr = itr->next) {
+		gnt_tree_add_row_after(GNT_TREE(tree), itr->data, gnt_tree_create_row(GNT_TREE(tree), itr->data), NULL, NULL);
+	}
+	g_list_free(list);
+
+	gnt_box_add_widget(GNT_BOX(box), tree);
+
+	pref_dialog->new_profile = entry = gnt_entry_new("");
+	gnt_box_add_widget(GNT_BOX(box), entry);
+
+	tmpbox = gnt_hbox_new(FALSE);
+	button = gnt_button_new("Add");
+	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(prof_add_cb), entry);
+	gnt_box_add_widget(GNT_BOX(tmpbox), button);
+	button = gnt_button_new("Delete");
+	g_signal_connect(G_OBJECT(button), "activate", G_CALLBACK(prof_del_cb), NULL);
+	gnt_box_add_widget(GNT_BOX(tmpbox), button);
+	gnt_box_add_widget(GNT_BOX(box), tmpbox);
+	gnt_box_add_widget(GNT_BOX(splitbox), box);
+
+	gnt_box_add_widget(GNT_BOX(splitbox), gnt_vline_new());
+
+	/* Sound method */
+
+	box = gnt_vbox_new(FALSE);
+	gnt_box_set_pad(GNT_BOX(box), 0);
+
+	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"));
+
+	label = gnt_label_new_with_format(_("Sound Method"), GNT_TEXT_FLAG_BOLD);
+	gnt_box_add_widget(GNT_BOX(box), label); 
+	tmpbox = gnt_hbox_new(TRUE);
+	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
+	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
+	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new(_("Method: ")));
+	gnt_box_add_widget(GNT_BOX(tmpbox), cmbox);
+	gnt_box_add_widget(GNT_BOX(box), tmpbox); 
+
+	tmpbox = gnt_hbox_new(TRUE);
+	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
+	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
+	gnt_box_add_widget(GNT_BOX(tmpbox), gnt_label_new(_("Sound Command\n(%s for filename)")));
+	pref_dialog->command = entry = gnt_entry_new("");
+	gnt_box_add_widget(GNT_BOX(tmpbox), entry);
+	gnt_box_add_widget(GNT_BOX(box), tmpbox);
+
+	gnt_box_add_widget(GNT_BOX(box), gnt_line_new(FALSE));
+
+	/* Sound options */
+	gnt_box_add_widget(GNT_BOX(box), 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_box_add_widget(GNT_BOX(box), chkbox);
+
+	tmpbox = gnt_hbox_new(TRUE);
+	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
+	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
+	gnt_box_add_widget(GNT_BOX(tmpbox), 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_box_add_widget(GNT_BOX(tmpbox), cmbox);
+	gnt_box_add_widget(GNT_BOX(box), tmpbox);
+
+	tmpbox = gnt_hbox_new(TRUE);
+	gnt_box_set_pad(GNT_BOX(tmpbox), 0);
+	gnt_box_set_fill(GNT_BOX(tmpbox), FALSE);
+	gnt_box_add_widget(GNT_BOX(tmpbox), 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_box_set_pad(GNT_BOX(tmpbox), 1);
+	gnt_box_add_widget(GNT_BOX(tmpbox), slider);
+	gnt_box_add_widget(GNT_BOX(tmpbox), label);
+	gnt_box_add_widget(GNT_BOX(box), tmpbox);
+	gnt_box_add_widget(GNT_BOX(splitbox), box);
+
+	gnt_box_add_widget(GNT_BOX(win), splitbox);
+
+	gnt_box_add_widget(GNT_BOX(win), gnt_hline_new());
+
+	/* Sound events */
+	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];
+		
+		if (event->label == NULL) {
+			continue;
+		}
+
+		gnt_tree_add_choice(GNT_TREE(tree), GINT_TO_POINTER(i),
+			gnt_tree_create_row(GNT_TREE(tree), "", ""),
+			NULL, NULL);
+	}
+
+	gnt_tree_adjust_columns(GNT_TREE(tree));
+	gnt_box_add_widget(GNT_BOX(win), tree);
+
+	box = gnt_hbox_new(FALSE);
+	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);
+
+	gnt_box_add_widget(GNT_BOX(win), gnt_line_new(FALSE));
+
+	/* Add new stuff before this */
+	box = gnt_hbox_new(FALSE);
+	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(G_OBJECT(button), "activate", G_CALLBACK(cancel_cb), 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);
+
+	load_pref_window(finch_sound_get_active_profile());
+
+	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;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/finch/gntsound.h	Tue Jul 24 19:39:58 2007 +0000
@@ -0,0 +1,103 @@
+/**
+ * @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);
+
+/*
+ * Get the name of the active sound profile.
+ *
+ * @return the name
+ */
+const char *finch_sound_get_active_profile(void);
+
+/**
+ * Set the active profile.  If the profile doesn't exist, nothing is changed.
+ * 
+ * 
+ */
+void finch_sound_set_active_profile(const char *name);
+
+/**
+ * Returns whether a profile exists or not.
+ *
+ * @parame name The name of the profile to check for
+ * return Existance value
+ *
+ */
+gboolean finch_sound_profile_exists(const char *name);
+
+
+/**
+ * Get a list of available sound profiles.
+ *
+ * @return A list of strings denoting sound profile names.  Free this list when you're done with it.
+ */
+GList *finch_sound_get_profiles(void);
+
+/**
+* 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
--- a/finch/gntui.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/gntui.c	Tue Jul 24 19:39:58 2007 +0000
@@ -35,6 +35,7 @@
 #include "gntprefs.h"
 #include "gntrequest.h"
 #include "gntstatus.h"
+#include "gntsound.h"
 
 #include <prefs.h>
 
@@ -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);
 
--- a/finch/libgnt/configure.ac	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/configure.ac	Tue Jul 24 19:39:58 2007 +0000
@@ -314,6 +314,8 @@
 	AC_DEFINE(NO_LIBXML, 1, [Do not have libxml2.])
 fi
 
+AM_CONDITIONAL(PURPLE_AVAILABLE, false)
+
 AC_OUTPUT([Makefile
            gnt.pc
            wms/Makefile
--- a/finch/libgnt/gnt.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gnt.h	Tue Jul 24 19:39:58 2007 +0000
@@ -157,4 +157,3 @@
 		void (*callback)(int status, gpointer data), gpointer data);
 
 gboolean gnt_is_refugee(void);
-
--- a/finch/libgnt/gntbindable.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntbindable.c	Tue Jul 24 19:39:58 2007 +0000
@@ -20,13 +20,198 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
+#include <string.h>
+
 #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;
+}
+
--- a/finch/libgnt/gntbindable.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntbindable.h	Tue Jul 24 19:39:58 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 */
--- a/finch/libgnt/gntbox.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntbox.c	Tue Jul 24 19:39:58 2007 +0000
@@ -316,10 +316,6 @@
 		{
 			find_next_focus(box);
 		}
-		else if (strcmp(text, GNT_KEY_BACK_TAB) == 0)
-		{
-			find_prev_focus(box);
-		}
 	}
 	else if (text[0] == '\t')
 	{
--- a/finch/libgnt/gntcombobox.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntcombobox.h	Tue Jul 24 19:39:58 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);
 
--- a/finch/libgnt/gntkeys.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntkeys.c	Tue Jul 24 19:39:58 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++;
 	}
 
--- a/finch/libgnt/gntmain.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntmain.c	Tue Jul 24 19:39:58 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;
--- a/finch/libgnt/gntmenu.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntmenu.c	Tue Jul 24 19:39:58 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;
 }
--- a/finch/libgnt/gntstyle.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntstyle.c	Tue Jul 24 19:39:58 2007 +0000
@@ -22,6 +22,7 @@
 
 #include "gntstyle.h"
 #include "gntcolors.h"
+
 #include "gntws.h"
 
 #include <glib.h>
--- a/finch/libgnt/gntutils.h	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntutils.h	Tue Jul 24 19:39:58 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.
  *
--- a/finch/libgnt/gntwm.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/gntwm.c	Tue Jul 24 19:39:58 2007 +0000
@@ -34,7 +34,9 @@
 #include <string.h>
 #include <time.h>
 
+#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)
 {
@@ -762,6 +736,7 @@
 			print = ch;
 #ifndef NO_WIDECHAR
 			if (wch.chars[0] > 255) {
+				/* XXX This lines throws a warning, can we quiet it? */
 				snprintf(unicode, sizeof(unicode), "&#x%x;", wch.chars[0]);
 				print = unicode;
 			}
@@ -841,6 +816,7 @@
 shift_right(GntBindable *bindable, GList *null)
 {
 	GntWM *wm = GNT_WM(bindable);
+	
 	if (wm->_list.window)
 		return TRUE;
 
@@ -1136,6 +1112,77 @@
 	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;
+	
+	
+	if(!wm->cws->ordered)
+		return FALSE;
+	
+	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)
 {
@@ -1293,6 +1340,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));
 
@@ -1679,6 +1736,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;
@@ -1897,7 +1962,8 @@
 
 	if (!node)
 		return;
-	
+
+	/* XXX Should there be a check before access to 'data' to make sure 'ordered' isn't NULL? */
 	if (widget != wm->_list.window && !GNT_IS_MENU(widget) &&
 				wm->cws->ordered->data != widget) {
 		GntWidget *w = wm->cws->ordered->data;
@@ -1962,6 +2028,7 @@
 	GntWS *ws = gnt_wm_widget_find_workspace(wm, widget);
 	if (wm->cws != ws)
 		gnt_wm_switch_workspace(wm, g_list_index(wm->workspaces, ws));
+	/* XXX Should there be a check before access to 'data' to make sure 'ordered' isn't NULL? */
 	if (widget != wm->cws->ordered->data) {
 		GntWidget *wid = wm->cws->ordered->data;
 		wm->cws->ordered = g_list_bring_to_front(wm->cws->ordered, widget);
--- a/finch/libgnt/wms/Makefile.am	Tue Jul 24 19:39:37 2007 +0000
+++ b/finch/libgnt/wms/Makefile.am	Tue Jul 24 19:39:58 2007 +0000
@@ -1,10 +1,16 @@
+if PURPLE_AVAILABLE
+# These custom wms depend on libpurple
+purple_wms = s.la irssi.la
+else
+purple_wms =
+endif
+
 s_la_LDFLAGS             = -module -avoid-version
 irssi_la_LDFLAGS         = -module -avoid-version
 
 plugin_LTLIBRARIES = \
-	s.la \
-	irssi.la
-
+	$(purple_wms)
+ 
 plugindir = $(libdir)/gnt
 
 irssi_la_SOURCES = irssi.c
--- a/libpurple/prefs.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/libpurple/prefs.c	Tue Jul 24 19:39:58 2007 +0000
@@ -1341,7 +1341,6 @@
 		list = g_list_append(list, g_strdup_printf("%s%s%s", name, sep, child->name));
 	}
 	return list;
-
 }
 
 void
--- a/pidgin/Makefile.am	Tue Jul 24 19:39:37 2007 +0000
+++ b/pidgin/Makefile.am	Tue Jul 24 19:39:58 2007 +0000
@@ -65,7 +65,7 @@
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = pidgin.pc
 
-SUBDIRS = pixmaps plugins sounds
+SUBDIRS = pixmaps plugins
 
 bin_PROGRAMS = pidgin
 
--- a/pidgin/gtksound.c	Tue Jul 24 19:39:37 2007 +0000
+++ b/pidgin/gtksound.c	Tue Jul 24 19:39:58 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);
--- a/pidgin/sounds/Makefile.am	Tue Jul 24 19:39:37 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)
-
--- a/pidgin/sounds/Makefile.mingw	Tue Jul 24 19:39:37 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;
-
Binary file pidgin/sounds/alert.wav has changed
Binary file pidgin/sounds/login.wav has changed
Binary file pidgin/sounds/logout.wav has changed
Binary file pidgin/sounds/receive.wav has changed
Binary file pidgin/sounds/send.wav has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/Makefile.am	Tue Jul 24 19:39:58 2007 +0000
@@ -0,0 +1,2 @@
+
+SUBDIRS = sounds
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/sounds/Makefile.am	Tue Jul 24 19:39:58 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)
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/sounds/Makefile.mingw	Tue Jul 24 19:39:58 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;
+
Binary file share/sounds/alert.wav has changed
Binary file share/sounds/login.wav has changed
Binary file share/sounds/logout.wav has changed
Binary file share/sounds/receive.wav has changed
Binary file share/sounds/send.wav has changed