changeset 19150:9ba4c42926bd

Cleaned up a few missing NULL checks in GntWM Put a few comments about a warning and other potential NULL checks missing.
author Eric Polino <aluink@pidgin.im>
date Wed, 11 Jul 2007 19:40:49 +0000
parents 5a6f174bf6dd
children 700fe77a79b3
files finch/gntsound.c finch/libgnt/gntwm.c
diffstat 2 files changed, 50 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntsound.c	Wed Jul 11 16:20:12 2007 +0000
+++ b/finch/gntsound.c	Wed Jul 11 19:40:49 2007 +0000
@@ -691,19 +691,15 @@
 }
 
 static void
-pref_load_cb(GntWidget *button, gpointer null)
+prof_del_cb(GntWidget *button, gpointer null)
 {
-
-	const gchar * value = gnt_combo_box_get_selected_data(GNT_COMBO_BOX(pref_dialog->profiles));
-
-	purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile",value);
+	const gchar * value = gnt_entry_get_text(GNT_ENTRY(pref_dialog->profiles));
+	gchar * pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s",value);
 
-}
+	if(purple_prefs_exists(pref))
+		purple_prefs_remove(pref);
 
-static void
-pref_save_cb(GntWidget *button, gpointer null)
-{
-
+	g_free(pref);
 }
 
 static void
@@ -749,7 +745,7 @@
 }
 
 static void
-reload_pref_window(GntComboBox *box, gpointer oldkey, gpointer newkey, gpointer null)
+reload_pref_window(const char * newkey)
 {
 	gint i;
 	purple_prefs_set_string(FINCH_PREFS_ROOT "/sound/actprofile",(gchar *)newkey);
@@ -780,6 +776,22 @@
 	}
 }
 
+static void
+profile_text_load(GntEntry *entry, gpointer null)
+{
+	const char * profile = gnt_entry_get_text(entry);
+	gchar * pref = g_strdup_printf(FINCH_PREFS_ROOT "/sound/profiles/%s",profile);
+	if(purple_prefs_exists(pref))
+		reload_pref_window(profile);
+	g_free(pref);
+}
+
+static void
+profile_text_completion(GntEntry *entry, gpointer val1, gpointer val2, gpointer null)
+{
+	profile_text_load(entry,null);
+}
+
 void
 finch_sounds_show_all(void)
 {
@@ -903,23 +915,21 @@
 
 	gnt_box_add_widget(GNT_BOX(win),gnt_label_new_with_format(_("Profiles"),GNT_TEXT_FLAG_BOLD));
 	box = gnt_hbox_new(FALSE);
-	pref_dialog->profiles = cmbox = gnt_combo_box_new();
+	pref_dialog->profiles = entry = gnt_entry_new("");
 	list = itr = finch_sound_get_profiles();
 	for(;itr;itr = itr->next){
-		gnt_combo_box_add_data(GNT_COMBO_BOX(cmbox),itr->data,itr->data);
+		gnt_entry_add_suggest(GNT_ENTRY(entry),itr->data);
 	}
-	g_signal_connect(G_OBJECT(cmbox),"selection-changed",G_CALLBACK(reload_pref_window),NULL);
 	g_list_free(list);
-	gnt_box_add_widget(GNT_BOX(box),cmbox);
-	button = gnt_button_new("Load");
-	g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(pref_load_cb),NULL);
-	gnt_box_add_widget(GNT_BOX(box),button);
-	button = gnt_button_new("Save");
-	g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(pref_save_cb),NULL);
+	g_signal_connect(G_OBJECT(entry),"text_changed",G_CALLBACK(profile_text_load),NULL);
+	g_signal_connect(G_OBJECT(entry),"completion",G_CALLBACK(profile_text_completion),NULL);
+	g_signal_connect(G_OBJECT(entry),"activate",G_CALLBACK(profile_text_load),NULL);
+	gnt_box_add_widget(GNT_BOX(box),entry);
+	button = gnt_button_new("Delete");
+	g_signal_connect(G_OBJECT(button),"activate",G_CALLBACK(prof_del_cb),NULL);
 	gnt_box_add_widget(GNT_BOX(box),button);
 	gnt_box_add_widget(GNT_BOX(win),box);
 
-
 	/* Add new stuff before this */
 	box = gnt_hbox_new(FALSE);
 	gnt_box_set_pad(GNT_BOX(box),0);
@@ -934,7 +944,7 @@
 
 	g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL);
 
-	reload_pref_window(NULL,NULL,(gchar *)finch_sound_get_active_profile(),NULL);
+	reload_pref_window(finch_sound_get_active_profile());
 
 	gnt_widget_show(win);
 
--- a/finch/libgnt/gntwm.c	Wed Jul 11 16:20:12 2007 +0000
+++ b/finch/libgnt/gntwm.c	Wed Jul 11 19:40:49 2007 +0000
@@ -735,6 +735,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;
 			}
@@ -803,6 +804,9 @@
 	if (wm->_list.window)
 		return TRUE;
 
+	if(!wm->cws->ordered)
+		return FALSE;
+
 	shift_window(wm, wm->cws->ordered->data, -1);
 	return TRUE;
 }
@@ -811,9 +815,13 @@
 shift_right(GntBindable *bindable, GList *null)
 {
 	GntWM *wm = GNT_WM(bindable);
+	
 	if (wm->_list.window)
 		return TRUE;
 
+	if(!wm->cws->ordered)
+		return FALSE;
+
 	shift_window(wm, wm->cws->ordered->data, 1);
 	return TRUE;
 }
@@ -1146,7 +1154,13 @@
 help_for_window(GntBindable *bindable, GList *null)
 {
 	GntWM *wm = GNT_WM(bindable);
-	GntWidget *widget = wm->cws->ordered->data;
+	GntWidget *widget;
+	
+	
+	if(!wm->cws->ordered)
+		return FALSE;
+	
+	widget = wm->cws->ordered->data;
 
 	return help_for_bindable(wm,GNT_BINDABLE(widget));
 }
@@ -1947,7 +1961,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;
@@ -2009,6 +2024,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);