Small code cleanup

Using shared gkbd_strv_* utility functions, reducing the code
This commit is contained in:
Sergey V. Udaltsov 2010-10-04 11:23:56 +01:00
parent 3e27315e0d
commit b4acce05ff
4 changed files with 22 additions and 31 deletions

View file

@ -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))

View file

@ -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);
}

View file

@ -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"))) {

View file

@ -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++;
}