changeset 19121:bd44f661f4c8

merge of '7229e4b74f5d355cabe59ecbbe84f35f1d9cdca9' and 'd415e1047f1286523321e03ed1bca413f396edac'
author Eric Polino <aluink@pidgin.im>
date Fri, 29 Jun 2007 01:54:45 +0000
parents b25cb0775be3 (current diff) 086cfcb71b01 (diff)
children 6dded98d1c80
files
diffstat 1 files changed, 130 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntsound.c	Thu Jun 28 03:09:03 2007 +0000
+++ b/finch/gntsound.c	Fri Jun 29 01:54:45 2007 +0000
@@ -49,6 +49,7 @@
 #include "gntwidget.h"
 #include "gntentry.h"
 #include "gntcheckbox.h"
+#include "gntline.h"
 
 struct finch_sound_event {
 	char *label;
@@ -56,6 +57,25 @@
 	char *def;
 };
 
+typedef struct {
+	GntWidget *method;
+	GntWidget *command;
+	GntWidget *conv_focus;
+	GntWidget *while_status;
+	GntWidget *volume;
+	GntWidget *window;
+} SoundPrefDialog;
+
+static struct {
+	const gchar *method;
+	const gchar *command;
+	gboolean conv_focus;
+	gint while_status;
+	gint volume;
+	GntTree *events;
+	SoundPrefDialog *dialog;
+} sound_pref_data;
+
 #define PLAY_SOUND_TIMEOUT 15000
 
 static guint mute_login_sounds_timeout = 0;
@@ -556,58 +576,155 @@
 	g_free(file_pref);
 }
 
+static void init_pref_data()
+{
+	GntTree *events = NULL;
+
+	if(sound_pref_data.method){
+		return;
+	}
+
+	/* TODO Setup the events tree */
+
+	sound_pref_data.method = purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/method");
+	sound_pref_data.command = purple_prefs_get_string(FINCH_PREFS_ROOT "/sound/command");
+	sound_pref_data.conv_focus = purple_prefs_get_bool(FINCH_PREFS_ROOT "/sound/conv_focus");
+	sound_pref_data.while_status = purple_prefs_get_int(FINCH_PREFS_ROOT "/purple/sound/while_status");
+	sound_pref_data.volume = CLAMP(purple_prefs_get_int(FINCH_PREFS_ROOT "/sound/volume"),0,100);
+	sound_pref_data.events = events;
+
+	return;
+}	
+
+static gboolean
+save_cb(GntBindable *data, gpointer *win)
+{
+	gnt_widget_destroy(GNT_WIDGET(win));
+	return TRUE;
+}
+
+static gboolean
+cancel_cb(GntBindable *data, gpointer win)
+{
+	gnt_widget_destroy(GNT_WIDGET(win));
+	return TRUE;
+}
+
+static void release_pref_window(GntBindable *data, gpointer null) {
+	g_free(sound_pref_data.dialog);
+	sound_pref_data.dialog = NULL;
+}
+
 void
-finch_sounds_show_all(void){
-	GntWidget *win;
-
+finch_sounds_show_all(void)
+{
 	GntWidget *box;
 	GntWidget *cmbox;
 	GntWidget *entry;
-	
-	win = gnt_window_box_new(TRUE,TRUE);
+	GntWidget *chkbox;
+	GntWidget *button;
+	GntWidget *label;
+	GntWidget *win;
+	gchar *buf;
+
+	if(sound_pref_data.dialog){
+		gnt_window_present(sound_pref_data.dialog->window);
+		return;
+	}
+
+	init_pref_data();
 
-	cmbox = gnt_combo_box_new();
+	sound_pref_data.dialog = g_new0(SoundPrefDialog,1);
+
+	sound_pref_data.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_MID);
+	gnt_widget_set_name(win, "sounds");
+
+	sound_pref_data.dialog->method = cmbox = gnt_combo_box_new();
 	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),sound_pref_data.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")));
-	entry = gnt_entry_new("cat %s > /dev/dsp");
+	gnt_box_add_widget(GNT_BOX(box),gnt_label_new(_("Sound Command\n(%s for filename)")));
+	sound_pref_data.dialog->command = entry = gnt_entry_new(sound_pref_data.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_check_box_new("Sounds when conversation has focus"));
+	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)); 
+	sound_pref_data.dialog->conv_focus = chkbox = gnt_check_box_new("Sounds when conversation has focus");
+	gnt_check_box_set_checked(GNT_CHECK_BOX(chkbox),sound_pref_data.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:"));
-	cmbox = gnt_combo_box_new();
+	sound_pref_data.dialog->while_status = cmbox = gnt_combo_box_new();
 	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"always","Always");
 	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"available","Only when available");
-	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"navailable","Only when not available");
+	gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),"away","Only when not available");
+	switch(sound_pref_data.while_status){
+		case 1:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"available");break;
+		case 2:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"away");break;
+		default:gnt_combo_box_set_selected(GNT_COMBO_BOX(cmbox),"always");break;
+	}
 	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):"));
-	entry = gnt_entry_new("50");
+
+	buf = g_strdup_printf("%d",sound_pref_data.volume);
+	sound_pref_data.dialog->volume = entry = gnt_entry_new(buf);
+	g_free(buf);
+	gnt_widget_set_name(entry,"volume");
 	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_set_title(GNT_BOX(win),"Sound Preferences");
+	gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Sound Events"),GNT_TEXT_FLAG_BOLD)); 
+	/* Put events tree here */
+
+	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),NULL);
+	gnt_box_add_widget(GNT_BOX(box),button);
+	button = gnt_button_new("Cancel");
+	g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(cancel_cb),NULL);
+	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_window),NULL);
+
 	gnt_widget_show(win);
 
 }