[gnome-control-center] wacom: Clean up action type sanity check



commit 7d147e06a660a7ad1ddd1e3cc3f26506d6043ac0
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Dec 20 12:07:00 2012 +0100

    wacom: Clean up action type sanity check

 panels/wacom/cc-wacom-page.c |   17 +++++++++++++----
 1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c
index 5c91c39..2bb6fa9 100644
--- a/panels/wacom/cc-wacom-page.c
+++ b/panels/wacom/cc-wacom-page.c
@@ -277,6 +277,17 @@ calibrate_button_clicked_cb (GtkButton   *button,
 	gtk_widget_set_sensitive (GTK_WIDGET (button), FALSE);
 }
 
+/* This avoids us crashing when a newer version of
+ * gnome-control-center has been used, and we load up an
+ * old one, as the action type if unknown to the old g-c-c */
+static gboolean
+action_type_is_valid (GsdWacomActionType type)
+{
+	if (type >= G_N_ELEMENTS(action_table))
+		return FALSE;
+	return TRUE;
+}
+
 static char *
 get_elevator_shortcut_string (GSettings        *settings,
 			      GtkDirectionType  dir)
@@ -613,8 +624,7 @@ add_button_to_store (GtkListStore         *model,
 		dir_name = NULL;
 	}
 
-	/* Sanity check */
-	if (type >= G_N_ELEMENTS(action_table))
+	if (action_type_is_valid (type) == FALSE)
 		type = GSD_WACOM_ACTION_TYPE_NONE;
 
 	gtk_list_store_append (model, &new_row);
@@ -671,8 +681,7 @@ action_set_func (GtkTreeViewColumn *tree_column,
 	}
 
 	type = g_settings_get_enum (button->settings, ACTION_TYPE_KEY);
-	/* Sanity check */
-	if (type >= G_N_ELEMENTS(action_table))
+	if (action_type_is_valid (type) == FALSE);
 		type = GSD_WACOM_ACTION_TYPE_NONE;
 
 	g_object_set (cell,



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