[gnome-control-center] Small code cleanup



commit b4acce05ff57f25aeac30bc95e4b4b2b3e483f1b
Author: Sergey V. Udaltsov <svu gnome org>
Date:   Mon Oct 4 11:23:56 2010 +0100

    Small code cleanup
    
    Using shared gkbd_strv_* utility functions, reducing the code

 panels/keyboard/gnome-keyboard-properties-xkb.h    |    1 +
 panels/keyboard/gnome-keyboard-properties-xkblt.c  |   18 +++++++++---------
 .../keyboard/gnome-keyboard-properties-xkbltadd.c  |   19 +++++++++----------
 panels/keyboard/gnome-keyboard-properties-xkbot.c  |   15 +++------------
 4 files changed, 22 insertions(+), 31 deletions(-)
---
diff --git a/panels/keyboard/gnome-keyboard-properties-xkb.h b/panels/keyboard/gnome-keyboard-properties-xkb.h
index bd42b87..4007a92 100644
--- a/panels/keyboard/gnome-keyboard-properties-xkb.h
+++ b/panels/keyboard/gnome-keyboard-properties-xkb.h
@@ -28,6 +28,7 @@
 #include <gtk/gtk.h>
 
 #include "libgnomekbd/gkbd-keyboard-config.h"
+#include "libgnomekbd/gkbd-util.h"
 
 G_BEGIN_DECLS
 #define CWID(s) GTK_WIDGET (gtk_builder_get_object (chooser_dialog, s))
diff --git a/panels/keyboard/gnome-keyboard-properties-xkblt.c b/panels/keyboard/gnome-keyboard-properties-xkblt.c
index c8fdccd..d1591d2 100644
--- a/panels/keyboard/gnome-keyboard-properties-xkblt.c
+++ b/panels/keyboard/gnome-keyboard-properties-xkblt.c
@@ -172,11 +172,10 @@ xkb_layouts_dnd_data_received (GtkWidget * widget, GdkDragContext * dc,
 		return;
 
 	layouts_list = xkb_layouts_get_selected_list ();
-	id = layouts_list[sidx];
+	id = g_strdup (layouts_list[sidx]);
 
 	/* Remove the element at position sidx */
-	memmove (layouts_list + sidx, layouts_list + sidx + 1,
-		 sizeof (gchar *) * g_strv_length (layouts_list + sidx));
+	gkbd_strv_behead (layouts_list + sidx);
 
 	if (!gtk_tree_view_get_dest_row_at_pos
 	    (GTK_TREE_VIEW (tree_view), x, y, &path, &pos)) {
@@ -191,10 +190,13 @@ xkb_layouts_dnd_data_received (GtkWidget * widget, GdkDragContext * dc,
 		gtk_tree_path_free (path);
 		/* Move to the new position */
 		if (sidx != didx) {
-			memmove (layouts_list + didx,
-				 layouts_list + didx + 1,
+			memmove (layouts_list + didx + 1,
+				 layouts_list + didx,
 				 g_strv_length (layouts_list + didx));
+			layouts_list[didx] = id;
 			xkb_layouts_set_selected_list (layouts_list);
+		} else {
+			g_free (id);
 		}
 	}
 	g_strfreev (layouts_list);
@@ -358,9 +360,7 @@ remove_selected_layout (GtkWidget * button, GtkBuilder * dialog)
 
 	if (idx != -1) {
 		gchar **layouts_list = xkb_layouts_get_selected_list ();
-		g_free (layouts_list[idx]);
-		memmove (layouts_list + idx, layouts_list + idx + 1,
-			 g_strv_length (layouts_list + idx));
+		gkbd_strv_behead (layouts_list + idx);
 
 		if (default_group > idx)
 			xkb_save_default_group (default_group - 1);
@@ -437,5 +437,5 @@ void
 xkb_layouts_register_conf_listener (GtkBuilder * dialog)
 {
 	g_signal_connect (xkb_keyboard_settings, "changed",
-			  (GCallback)xkb_layouts_update_list, dialog);
+			  (GCallback) xkb_layouts_update_list, dialog);
 }
diff --git a/panels/keyboard/gnome-keyboard-properties-xkbltadd.c b/panels/keyboard/gnome-keyboard-properties-xkbltadd.c
index fee0d15..b9fc183 100644
--- a/panels/keyboard/gnome-keyboard-properties-xkbltadd.c
+++ b/panels/keyboard/gnome-keyboard-properties-xkbltadd.c
@@ -57,6 +57,7 @@ static void
 
 
 
+
 xkb_layout_chooser_available_layouts_fill (GtkBuilder * chooser_dialog,
 					   const gchar cblid[],
 					   const gchar cbvid[],
@@ -75,6 +76,7 @@ static void
 
 
 
+
 xkb_layout_chooser_available_language_variants_fill (GtkBuilder *
 						     chooser_dialog);
 
@@ -88,6 +90,7 @@ static void
 
 
 
+
 xkb_layout_chooser_available_country_variants_fill (GtkBuilder *
 						    chooser_dialog);
 
@@ -410,21 +413,17 @@ xkb_layout_chooser_response (GtkDialog * dialog,
 		if (selected_id != NULL) {
 			gchar **layouts_list =
 			    xkb_layouts_get_selected_list ();
-			gint len = g_strv_length(layouts_list);
-			gchar **new_layouts_list = g_new0(gchar*, len + 2);
 
-			selected_id = g_strdup (selected_id);
+			layouts_list =
+			    gkbd_strv_append (layouts_list,
+					      g_strdup (selected_id));
 
-			memcpy(new_layouts_list, layouts_list, sizeof (gchar*) * len);
-			new_layouts_list[len] = selected_id;
-			g_free(layouts_list);
-			
-			xkb_layouts_set_selected_list (new_layouts_list);
+			xkb_layouts_set_selected_list (layouts_list);
 
 			xkl_layout_chooser_add_default_switcher_if_necessary
-			    (new_layouts_list);
+			    (layouts_list);
 
-			g_strfreev (new_layouts_list);
+			g_strfreev (layouts_list);
 		}
 	} else if (response == gtk_dialog_get_response_for_widget
 		   (dialog, CWID ("btnPrint"))) {
diff --git a/panels/keyboard/gnome-keyboard-properties-xkbot.c b/panels/keyboard/gnome-keyboard-properties-xkbot.c
index 6e07d62..8c09433 100644
--- a/panels/keyboard/gnome-keyboard-properties-xkbot.c
+++ b/panels/keyboard/gnome-keyboard-properties-xkbot.c
@@ -124,14 +124,8 @@ xkb_options_select (gchar * optionname)
 	}
 
 	if (!already_selected) {
-		gint old_length = g_strv_length (options_list);
-		gchar **new_options_list =
-		    g_new0 (gchar *, old_length + 2);
-		memcpy (new_options_list, options_list,
-			sizeof (gchar *) * old_length);
-		new_options_list[old_length] = g_strdup (optionname);
-		xkb_options_set_selected_list (new_options_list);
-		g_free (new_options_list);
+		options_list = gkbd_strv_append (options_list, g_strdup (optionname));
+		xkb_options_set_selected_list (options_list);
 	}
 
 	g_strfreev (options_list);
@@ -147,10 +141,7 @@ xkb_options_deselect (gchar * optionname)
 		while (*option != NULL) {
 			gchar *id = *option;
 			if (!strcmp (id, optionname)) {
-				g_free (*option);
-				memmove (option, option + 1,
-					 g_strv_length (option) *
-					 sizeof (gchar *));
+				gkbd_strv_behead(option);
 			} else
 				option++;
 		}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]