changeset 19160:fbecc35c23bb

Profiles now work with the new layout
author Eric Polino <aluink@pidgin.im>
date Thu, 12 Jul 2007 23:37:35 +0000
parents 67fc276e5332
children 4521c558796e
files finch/gntsound.c finch/gntsound.h
diffstat 2 files changed, 90 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntsound.c	Thu Jul 12 21:49:27 2007 +0000
+++ b/finch/gntsound.c	Thu Jul 12 23:37:35 2007 +0000
@@ -281,7 +281,7 @@
 	mute_login_sounds_timeout = purple_timeout_add_seconds(10, unmute_login_sounds_cb, NULL);
 }
 
-static void *
+void *
 finch_sound_get_handle()
 {
 	static int handle;
@@ -619,6 +619,13 @@
 	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)
@@ -775,9 +782,8 @@
 		g_free(boolpref);
 	}
 
-	/* Can someone double check to make sure there isn't a leak in the way I'm keeping
-	 * track of thest profile suggests in the entry.  Thanks!
-	 */
+	gnt_tree_set_selected(GNT_TREE(pref_dialog->profiles),(gchar *)finch_sound_get_active_profile());
+
 	gnt_widget_draw(pref_dialog->window);
 }
 
@@ -794,31 +800,52 @@
 prof_del_cb(GntWidget *button, gpointer null)
 {
 
-	const gchar * profile = gnt_entry_get_text(GNT_ENTRY(pref_dialog->profiles));
-	gchar * pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s",profile);
+	gchar * profile = gnt_tree_get_selection_data(GNT_TREE(pref_dialog->profiles));
+	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);
 
-	g_free(pref_dialog->original_profile);
-	pref_dialog->original_profile = g_strdup(DEFAULT_PROFILE);
+	if(!strcmp(pref_dialog->original_profile,profile)){
+		g_free(pref_dialog->original_profile);
+		pref_dialog->original_profile = g_strdup(DEFAULT_PROFILE);
+	}
+
+	gnt_tree_remove(GNT_TREE(pref_dialog->profiles),profile);
 
 	reload_pref_window(DEFAULT_PROFILE);
 }
 
 static void
-prof_add_cb(GntEntry *entry, gpointer null)
+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);
+	}
+
 	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);
@@ -837,6 +864,7 @@
 	GntWidget *win;
 
 	gint i;
+	GList *itr,*list;
 
 	if(pref_dialog) {
 		gnt_window_present(pref_dialog->window);
@@ -860,6 +888,16 @@
 	box = gnt_vbox_new(FALSE);
 	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("");
@@ -867,7 +905,7 @@
 
 	tmpbox = gnt_hbox_new(FALSE);
 	button = gnt_button_new("Add");
-	g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(prof_add_cb),NULL);
+	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);
--- a/finch/gntsound.h	Thu Jul 12 21:49:27 2007 +0000
+++ b/finch/gntsound.h	Thu Jul 12 23:37:35 2007 +0000
@@ -28,37 +28,62 @@
 #include "sound.h"
 
 /**********************************************************************/
-/** @name GNT Sound API                                               */
+/** @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 of the 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.
  * 
- * @param name  The name of the profile
+ * 
  */
 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.
- *         Caller must free the list (but not the data).
+ * @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.
- */
+* Gets GNT sound UI ops.
+*
+* @return The UI operations structure.
+*/
 PurpleSoundUiOps *finch_sound_get_ui_ops(void);
 
 /**
@@ -66,6 +91,13 @@
  */
 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