gpointing-device-settings r254 - in trunk: modules src



Author: hiikezoe
Date: Mon Mar 23 03:37:26 2009
New Revision: 254
URL: http://svn.gnome.org/viewvc/gpointing-device-settings?rev=254&view=rev

Log:
added a new object, GpdsXInputUI. Touchpad and mouse module use this object.

Added:
   trunk/src/gpds-xinput-ui.c
   trunk/src/gpds-xinput-ui.h
Modified:
   trunk/modules/gpds-mouse-ui.c
   trunk/modules/gpds-touchpad-ui.c
   trunk/src/Makefile.am
   trunk/src/gpds-ui.c
   trunk/src/gpds-ui.h
   trunk/src/gpointing-device-settings.h

Modified: trunk/modules/gpds-mouse-ui.c
==============================================================================
--- trunk/modules/gpds-mouse-ui.c	(original)
+++ trunk/modules/gpds-mouse-ui.c	Mon Mar 23 03:37:26 2009
@@ -24,7 +24,7 @@
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
 #include <gpointing-device-settings.h>
-#include <gpds-xinput.h>
+#include <gpds-xinput-ui.h>
 #include <gpds-xinput-utils.h>
 #include <gconf/gconf-client.h>
 
@@ -43,14 +43,13 @@
 
 struct _GpdsMouseUI
 {
-    GpdsUI parent;
-    GpdsXInput *xinput;
+    GpdsXInputUI parent;
     gchar *ui_file_path;
 };
 
 struct _GpdsMouseUIClass
 {
-    GpdsUIClass parent_class;
+    GpdsXInputUIClass parent_class;
 };
 
 GType gpds_mouse_ui_get_type (void) G_GNUC_CONST;
@@ -61,7 +60,7 @@
 static GtkWidget *get_content_widget (GpdsUI  *ui, GError **error);
 static GdkPixbuf *get_icon_pixbuf    (GpdsUI  *ui, GError **error);
 
-G_DEFINE_DYNAMIC_TYPE(GpdsMouseUI, gpds_mouse_ui, GPDS_TYPE_UI)
+G_DEFINE_DYNAMIC_TYPE(GpdsMouseUI, gpds_mouse_ui, GPDS_TYPE_XINPUT_UI)
 
 static void
 gpds_mouse_ui_class_init (GpdsMouseUIClass *klass)
@@ -85,7 +84,6 @@
 static void
 gpds_mouse_ui_init (GpdsMouseUI *ui)
 {
-    ui->xinput = NULL;
     ui->ui_file_path = g_build_filename(gpds_get_ui_file_directory(),
                                         "mouse.ui",
                                         NULL);
@@ -113,11 +111,6 @@
 {
     GpdsMouseUI *ui = GPDS_MOUSE_UI(object);
 
-    if (ui->xinput) {
-        g_object_unref(ui->xinput);
-        ui->xinput = NULL;
-    }
-
     g_free(ui->ui_file_path);
 
     if (G_OBJECT_CLASS(gpds_mouse_ui_parent_class)->dispose)
@@ -134,27 +127,6 @@
 }
 
 static void
-set_toggle_property (GpdsXInput *xinput, GtkToggleButton *button, GpdsMouseProperty property)
-{
-    GError *error = NULL;
-    gboolean active;
-    gint properties[1];
-
-    active = gtk_toggle_button_get_active(button);
-
-    properties[0] = active ? 1 : 0;
-    gpds_xinput_set_int_properties(xinput,
-                                   property,
-                                   &error,
-                                   properties,
-                                   1);
-    if (error) {
-        show_error(error);
-        g_error_free(error);
-    }
-}
-
-static void
 set_spin_property (GpdsXInput *xinput, GtkSpinButton *button, GpdsMouseProperty property)
 {
     GError *error = NULL;
@@ -175,35 +147,12 @@
     }
 }
 
-static void
-set_widget_sensitivity (GtkBuilder *builder,
-                        const gchar *widget_id, 
-                        GtkToggleButton *button)
-{
-    GObject *object;
-
-    object = gtk_builder_get_object(builder, widget_id);
-    gtk_widget_set_sensitive(GTK_WIDGET(object),
-                             gtk_toggle_button_get_active(button));
-}
-
-#define DEFINE_EMULATION_BUTTON_TOGGLED_CALLBACK(name, KEY_NAME, box_name)          \
-static void                                                                         \
-cb_ ## name ## _toggled (GtkToggleButton *button,                                   \
-                         gpointer user_data)                                        \
-{                                                                                   \
-    GtkBuilder *builder;                                                            \
-    gboolean enable;                                                                \
-    GpdsMouseUI *ui = GPDS_MOUSE_UI(user_data);                                     \
-    set_toggle_property(ui->xinput, button, GPDS_MOUSE_ ## KEY_NAME);               \
-    enable = gtk_toggle_button_get_active(button);                                  \
-    gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_MOUSE_ ## KEY_NAME ## _KEY, enable);   \
-    builder = gpds_ui_get_builder(GPDS_UI(user_data));                              \
-    set_widget_sensitivity(builder, box_name, button);                              \
-}
-
-DEFINE_EMULATION_BUTTON_TOGGLED_CALLBACK(middle_button_emulation, MIDDLE_BUTTON_EMULATION, "middle_button_emulation_box")
-DEFINE_EMULATION_BUTTON_TOGGLED_CALLBACK(wheel_emulation, WHEEL_EMULATION, "wheel_emulation_box")
+GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(middle_button_emulation,
+                                             GPDS_MOUSE_MIDDLE_BUTTON_EMULATION,
+                                             "middle_button_emulation_box")
+GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(wheel_emulation,
+                                             GPDS_MOUSE_WHEEL_EMULATION,
+                                             "wheel_emulation_box")
 
 static void
 cb_wheel_emulation_button_changed (GtkComboBox *combo, gpointer user_data)
@@ -215,10 +164,15 @@
     GError *error = NULL;
     GpdsMouseUI *ui = GPDS_MOUSE_UI(user_data);
     GtkBuilder *builder;
+    GpdsXInput *xinput;
 
     if (!gtk_combo_box_get_active_iter(combo, &iter))
         return;
 
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
+
     builder = gpds_ui_get_builder(GPDS_UI(ui));
     list_store = gtk_builder_get_object(builder, "wheel_emulation_button_list_store");
     gtk_tree_model_get_value(GTK_TREE_MODEL(list_store),
@@ -228,7 +182,7 @@
     properties[0] = g_value_get_int(&value);
     g_value_unset(&value);
 
-    if (!gpds_xinput_set_int_properties(ui->xinput,
+    if (!gpds_xinput_set_int_properties(xinput,
                                         GPDS_MOUSE_WHEEL_EMULATION_BUTTON,
                                         &error,
                                         properties,
@@ -250,6 +204,11 @@
     GError *error = NULL;
     gboolean active;
     gint properties[4];
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
     builder = gpds_ui_get_builder(GPDS_UI(ui));
 
@@ -273,7 +232,7 @@
         properties[3] = 0;
     }
 
-    gpds_xinput_set_int_properties(ui->xinput,
+    gpds_xinput_set_int_properties(xinput,
                                    GPDS_MOUSE_WHEEL_EMULATION_AXES,
                                    &error,
                                    properties,
@@ -306,7 +265,11 @@
 {                                                                                   \
     gdouble value;                                                                  \
     GpdsMouseUI *ui = GPDS_MOUSE_UI(user_data);                                     \
-    set_spin_property(ui->xinput, button, GPDS_MOUSE_ ## NAME);                     \
+    GpdsXInput *xinput;                                                             \
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));                         \
+    if (!xinput)                                                                    \
+        return;                                                                     \
+    set_spin_property(xinput, button, GPDS_MOUSE_ ## NAME);                         \
     value = gtk_spin_button_get_value(button);                                      \
     gpds_ui_set_gconf_int(GPDS_UI(ui), GPDS_MOUSE_ ## NAME ## _KEY, (gint)value);   \
 }
@@ -338,82 +301,6 @@
 #undef CONNECT
 }
 
-static gboolean
-get_integer_properties (GpdsXInput *xinput, gint property_enum,
-                        gint **values, gulong *n_values)
-{
-    GError *error = NULL;
-
-    if (!gpds_xinput_get_int_properties(xinput,
-                                        property_enum,
-                                        &error,
-                                        values, n_values)) {
-        if (error) {
-            show_error(error);
-            g_error_free(error);
-        }
-        return FALSE;
-    }
-
-    return TRUE;
-
-}
-
-static void
-set_integer_property_from_preference (GpdsMouseUI *ui,
-                                      GpdsMouseProperty property,
-                                      const gchar *gconf_key_name,
-                                      GtkBuilder *builder,
-                                      const gchar *object_name)
-{
-    GObject *object;
-    gint *values;
-    gulong n_values;
-    gint value;
-
-    if (!get_integer_properties(ui->xinput, property,
-                                &values, &n_values)) {
-        return;
-    }
-
-    if (!gpds_ui_get_gconf_int(GPDS_UI(ui), gconf_key_name, &value))
-        value = values[0];
-
-    object = gtk_builder_get_object(builder, object_name);
-    gtk_spin_button_set_value(GTK_SPIN_BUTTON(object), value);
-    g_free(values);
-}
-
-static void
-set_boolean_property_from_preference (GpdsMouseUI *ui,
-                                      GpdsMouseProperty property,
-                                      const gchar *gconf_key_name,
-                                      GtkBuilder *builder,
-                                      const gchar *object_name)
-{
-    GObject *object;
-    gint *values;
-    gulong n_values;
-    gboolean enable;
-    gchar *box_name;
-
-    if (!get_integer_properties(ui->xinput, property,
-                                &values, &n_values)) {
-        return;
-    }
-
-    if (!gpds_ui_get_gconf_bool(GPDS_UI(ui), gconf_key_name, &enable))
-        enable = (values[0] == 1);
-
-    object = gtk_builder_get_object(builder, object_name);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object), enable);
-    g_free(values);
-
-    box_name = g_strconcat(object_name, "_box", NULL);
-    set_widget_sensitivity (builder, box_name, GTK_TOGGLE_BUTTON(object));
-    g_free(box_name);
-}
-
 static void
 set_scroll_axes_property_from_preference (GpdsMouseUI *ui,
                                           GtkBuilder *builder)
@@ -423,9 +310,9 @@
     gulong n_values;
     gboolean horizontal_enable = FALSE, vertical_enable = FALSE;
 
-    if (!get_integer_properties(ui->xinput, 
-                                GPDS_MOUSE_WHEEL_EMULATION_AXES,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_MOUSE_WHEEL_EMULATION_AXES,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -522,9 +409,9 @@
     gulong n_values;
     gint button;
 
-    if (!get_integer_properties(ui->xinput,
-                                GPDS_MOUSE_WHEEL_EMULATION_BUTTON,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_MOUSE_WHEEL_EMULATION_BUTTON,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -540,34 +427,34 @@
 {
     GpdsMouseUI *mouse_ui = GPDS_MOUSE_UI(ui);
 
-    set_boolean_property_from_preference(mouse_ui,
+    gpds_xinput_ui_set_toggle_button_state_from_preference(
+                                         GPDS_XINPUT_UI(ui),
                                          GPDS_MOUSE_MIDDLE_BUTTON_EMULATION,
                                          GPDS_MOUSE_MIDDLE_BUTTON_EMULATION_KEY,
-                                         builder,
                                          "middle_button_emulation");
-    set_boolean_property_from_preference(mouse_ui,
+    gpds_xinput_ui_set_toggle_button_state_from_preference(
+                                         GPDS_XINPUT_UI(ui),
                                          GPDS_MOUSE_WHEEL_EMULATION,
                                          GPDS_MOUSE_WHEEL_EMULATION_KEY,
-                                         builder,
                                          "wheel_emulation");
     setup_num_buttons(ui);
     set_wheel_emulation_button_property_from_preference(mouse_ui);
 
-    set_integer_property_from_preference(mouse_ui,
-                                         GPDS_MOUSE_MIDDLE_BUTTON_TIMEOUT,
-                                         GPDS_MOUSE_MIDDLE_BUTTON_TIMEOUT_KEY,
-                                         builder,
-                                         "middle_button_timeout");
-    set_integer_property_from_preference(mouse_ui,
-                                         GPDS_MOUSE_WHEEL_EMULATION_TIMEOUT,
-                                         GPDS_MOUSE_WHEEL_EMULATION_TIMEOUT_KEY,
-                                         builder,
-                                         "wheel_emulation_timeout");
-    set_integer_property_from_preference(mouse_ui,
-                                         GPDS_MOUSE_WHEEL_EMULATION_INERTIA,
-                                         GPDS_MOUSE_WHEEL_EMULATION_INERTIA_KEY,
-                                         builder,
-                                         "wheel_emulation_inertia");
+    gpds_xinput_ui_set_widget_value_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_MOUSE_MIDDLE_BUTTON_TIMEOUT,
+                                        GPDS_MOUSE_MIDDLE_BUTTON_TIMEOUT_KEY,
+                                        "middle_button_timeout");
+    gpds_xinput_ui_set_widget_value_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_MOUSE_WHEEL_EMULATION_TIMEOUT,
+                                        GPDS_MOUSE_WHEEL_EMULATION_TIMEOUT_KEY,
+                                        "wheel_emulation_timeout");
+    gpds_xinput_ui_set_widget_value_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_MOUSE_WHEEL_EMULATION_INERTIA,
+                                        GPDS_MOUSE_WHEEL_EMULATION_INERTIA_KEY,
+                                        "wheel_emulation_inertia");
 
     set_scroll_axes_property_from_preference(mouse_ui,
                                              builder);
@@ -576,6 +463,11 @@
 static gboolean
 is_available (GpdsUI *ui, GError **error)
 {
+    if (GPDS_UI_CLASS(gpds_mouse_ui_parent_class)->is_available &&
+        !GPDS_UI_CLASS(gpds_mouse_ui_parent_class)->is_available(ui, error)) {
+        return FALSE;
+    }
+
     if (!g_file_test(GPDS_MOUSE_UI(ui)->ui_file_path,
                      G_FILE_TEST_EXISTS)) {
         g_set_error(error,
@@ -593,6 +485,7 @@
 build (GpdsUI  *ui, GError **error)
 {
     GtkBuilder *builder;
+    GpdsXInput *xinput;
 
     builder = gpds_ui_get_builder(ui);
 
@@ -602,9 +495,14 @@
         return FALSE;
     }
 
-    gpds_ui_set_gconf_string(ui, GPDS_GCONF_DEVICE_TYPE_KEY, "mouse");
-    GPDS_MOUSE_UI(ui)->xinput = gpds_mouse_xinput_new(gpds_ui_get_device_name(ui));
+    xinput = gpds_mouse_xinput_new(gpds_ui_get_device_name(ui));
+    if (!xinput) {
+        return FALSE;
+    }
+    gpds_xinput_ui_set_xinput(GPDS_XINPUT_UI(ui), xinput);
+    g_object_unref(xinput);
 
+    gpds_ui_set_gconf_string(ui, GPDS_GCONF_DEVICE_TYPE_KEY, "mouse");
     setup_current_values(ui, builder);
     setup_signals(ui, builder);
 

Modified: trunk/modules/gpds-touchpad-ui.c
==============================================================================
--- trunk/modules/gpds-touchpad-ui.c	(original)
+++ trunk/modules/gpds-touchpad-ui.c	Mon Mar 23 03:37:26 2009
@@ -42,14 +42,13 @@
 
 struct _GpdsTouchpadUI
 {
-    GpdsUI parent;
-    GpdsXInput *xinput;
+    GpdsXInputUI parent;
     gchar *ui_file_path;
 };
 
 struct _GpdsTouchpadUIClass
 {
-    GpdsUIClass parent_class;
+    GpdsXInputUIClass parent_class;
 };
 
 GType gpds_touchpad_ui_get_type (void) G_GNUC_CONST;
@@ -60,7 +59,7 @@
 static GtkWidget *get_content_widget (GpdsUI  *ui, GError **error);
 static GdkPixbuf *get_icon_pixbuf    (GpdsUI  *ui, GError **error);
 
-G_DEFINE_DYNAMIC_TYPE(GpdsTouchpadUI, gpds_touchpad_ui, GPDS_TYPE_UI)
+G_DEFINE_DYNAMIC_TYPE(GpdsTouchpadUI, gpds_touchpad_ui, GPDS_TYPE_XINPUT_UI)
 
 static void
 gpds_touchpad_ui_class_init (GpdsTouchpadUIClass *klass)
@@ -84,7 +83,6 @@
 static void
 gpds_touchpad_ui_init (GpdsTouchpadUI *ui)
 {
-    ui->xinput = NULL;
     ui->ui_file_path = 
         g_build_filename(gpds_get_ui_file_directory(), "touchpad.ui", NULL);
 }
@@ -111,11 +109,6 @@
 {
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(object);
 
-    if (ui->xinput) {
-        g_object_unref(ui->xinput);
-        ui->xinput = NULL;
-    }
-
     g_free(ui->ui_file_path);
 
     if (G_OBJECT_CLASS(gpds_touchpad_ui_parent_class)->dispose)
@@ -143,26 +136,6 @@
 }
 
 static void
-set_toggle_property (GpdsXInput *xinput, GtkToggleButton *button, GpdsTouchpadProperty property)
-{
-    GError *error = NULL;
-    gint properties[1];
-
-    properties[0] = gtk_toggle_button_get_active(button) ? 1 : 0;
-
-    if (!gpds_xinput_set_int_properties(xinput,
-                                        property,
-                                        &error,
-                                        properties,
-                                        1)) {
-        if (error) {
-            show_error(error);
-            g_error_free(error);
-        }
-    }
-}
-
-static void
 set_edge_scrolling_toggle_property (GpdsXInput *xinput, GtkBuilder *builder)
 {
     GError *error = NULL;
@@ -192,16 +165,15 @@
     }
 }
 
-static void
-cb_palm_detection_toggled (GtkToggleButton *button, gpointer user_data)
-{
-    GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
-    gboolean check;
-
-    set_toggle_property(ui->xinput, button, GPDS_TOUCHPAD_PALM_DETECTION);
-    check = gtk_toggle_button_get_active(button);
-    gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_TOUCHPAD_PALM_DETECTION_KEY, check);
-}
+GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(palm_detection,
+                                             GPDS_TOUCHPAD_PALM_DETECTION,
+                                             NULL)
+GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(faster_tapping_check,
+                                             GPDS_TOUCHPAD_TAP_FAST_TAP,
+                                             NULL)
+GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(circular_scrolling,
+                                             GPDS_TOUCHPAD_CIRCULAR_SCROLLING,
+                                             "circular_scrolling_box")
 
 static void
 set_two_finger_scrolling_toggle_property (GpdsXInput *xinput, GtkBuilder *builder)
@@ -280,10 +252,15 @@
 {
     GError *error = NULL;
     gint properties[1];
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
     properties[0] = trigger;
 
-    if (!gpds_xinput_set_int_properties(ui->xinput,
+    if (!gpds_xinput_set_int_properties(xinput,
                                         GPDS_TOUCHPAD_CIRCULAR_SCROLLING_TRIGGER,
                                         &error,
                                         properties,
@@ -300,50 +277,33 @@
 {
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
     gdouble time;
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
-    set_range_property(ui->xinput, range, GPDS_TOUCHPAD_TAP_TIME);
+    set_range_property(xinput, range, GPDS_TOUCHPAD_TAP_TIME);
 
     time = gtk_range_get_value(range);
     gpds_ui_set_gconf_int(GPDS_UI(ui), GPDS_TOUCHPAD_TAP_TIME_KEY, (gint)time);
 }
 
 static void
-cb_faster_tapping_check_toggled (GtkToggleButton *button, gpointer user_data)
-{
-    GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
-    gboolean check;
-
-    set_toggle_property(ui->xinput, button, GPDS_TOUCHPAD_TAP_FAST_TAP);
-    check = gtk_toggle_button_get_active(button);
-    gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_TOUCHPAD_TAP_FAST_TAP_KEY, check);
-}
-
-static void
-cb_circular_scrolling_toggled (GtkToggleButton *button, gpointer user_data)
-{
-    GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
-    GtkBuilder *builder;
-    gboolean check;
-
-    builder = gpds_ui_get_builder(GPDS_UI(user_data));
-
-    set_toggle_property(ui->xinput, button, GPDS_TOUCHPAD_CIRCULAR_SCROLLING);
-
-    check = gtk_toggle_button_get_active(button);
-    set_widget_sensitivity(builder, "circular_scrolling_box", check);
-    gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_TOUCHPAD_CIRCULAR_SCROLLING_KEY, check);
-}
-
-static void
 cb_vertical_scrolling_scale_value_changed (GtkRange *range, gpointer user_data)
 {
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
     GtkBuilder *builder;
     gdouble distance;
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
     builder = gpds_ui_get_builder(GPDS_UI(user_data));
 
-    set_scrolling_distance_range_property(ui->xinput, builder);
+    set_scrolling_distance_range_property(xinput, builder);
 
     distance = gtk_range_get_value(range);
     gpds_ui_set_gconf_int(GPDS_UI(ui), GPDS_TOUCHPAD_HORIZONTAL_SCROLLING_DISTANCE_KEY, (gint)distance);
@@ -355,10 +315,15 @@
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
     GtkBuilder *builder;
     gdouble distance;
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
     builder = gpds_ui_get_builder(GPDS_UI(user_data));
 
-    set_scrolling_distance_range_property(ui->xinput, builder);
+    set_scrolling_distance_range_property(xinput, builder);
 
     distance = gtk_range_get_value(range);
     gpds_ui_set_gconf_int(GPDS_UI(ui), GPDS_TOUCHPAD_VERTICAL_SCROLLING_DISTANCE_KEY, (gint)distance);
@@ -372,8 +337,12 @@
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);                                       \
     GtkBuilder *builder;                                                                    \
     gboolean check;                                                                         \
+    GpdsXInput *xinput;                                                                     \
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));                                 \
+    if (!xinput)                                                                            \
+        return;                                                                             \
     builder = gpds_ui_get_builder(GPDS_UI(user_data));                                      \
-    set_edge_scrolling_toggle_property(ui->xinput, builder);                                \
+    set_edge_scrolling_toggle_property(xinput, builder);                                    \
     check = gtk_toggle_button_get_active(button);                                           \
     gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_TOUCHPAD_ ## TYPE ## _SCROLLING_KEY, check);   \
 }
@@ -390,8 +359,12 @@
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);                                                       \
     GtkBuilder *builder;                                                                                    \
     gboolean check;                                                                                         \
+    GpdsXInput *xinput;                                                                                     \
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));                                                 \
+    if (!xinput)                                                                                            \
+        return;                                                                                             \
     builder = gpds_ui_get_builder(GPDS_UI(user_data));                                                      \
-    set_two_finger_scrolling_toggle_property(ui->xinput, builder);                                          \
+    set_two_finger_scrolling_toggle_property(xinput, builder);                                              \
     check = gtk_toggle_button_get_active(button);                                                           \
     gpds_ui_set_gconf_bool(GPDS_UI(ui), GPDS_TOUCHPAD_TWO_FINGER_ ## DIRECTION ## _SCROLLING_KEY, check);   \
 }
@@ -523,9 +496,14 @@
     GpdsTouchpadUI *ui = GPDS_TOUCHPAD_UI(user_data);
     gint properties[1];
     GError *error = NULL;
+    GpdsXInput *xinput;
+
+    xinput = gpds_xinput_ui_get_xinput(GPDS_XINPUT_UI(ui));
+    if (!xinput)
+        return;
 
     properties[0] = gtk_combo_box_get_active(combo);
-    if (!gpds_xinput_set_int_properties(ui->xinput,
+    if (!gpds_xinput_set_int_properties(xinput,
                                         GPDS_TOUCHPAD_OFF,
                                         &error,
                                         properties,
@@ -577,77 +555,6 @@
 #undef CONNECT
 }
 
-static gboolean
-get_integer_properties (GpdsXInput *xinput, GpdsTouchpadProperty property,
-                        gint **values, gulong *n_values)
-{
-    GError *error = NULL;
-
-    if (!gpds_xinput_get_int_properties(xinput,
-                                        property,
-                                        &error,
-                                        values, n_values)) {
-        if (error) {
-            show_error(error);
-            g_error_free(error);
-        }
-        return FALSE;
-    }
-
-    return TRUE;
-
-}
-
-static void
-set_integer_property_from_preference (GpdsTouchpadUI *ui,
-                                      GpdsTouchpadProperty property,
-                                      const gchar *gconf_key_name,
-                                      GtkBuilder *builder,
-                                      const gchar *object_name)
-{
-    GObject *object;
-    gint *values;
-    gulong n_values;
-    gint value;
-
-    if (!get_integer_properties(ui->xinput, property,
-                                &values, &n_values)) {
-        return;
-    }
-
-    if (!gpds_ui_get_gconf_int(GPDS_UI(ui), gconf_key_name, &value))
-        value = values[0];
-    object = gtk_builder_get_object(builder, object_name);
-    gtk_range_set_value(GTK_RANGE(object), value);
-    g_free(values);
-}
-
-static gboolean
-set_boolean_property_from_preference (GpdsTouchpadUI *ui,
-                                      GpdsTouchpadProperty property,
-                                      const gchar *gconf_key_name,
-                                      GtkBuilder *builder,
-                                      const gchar *object_name)
-{
-    GObject *object;
-    gint *values;
-    gulong n_values;
-    gboolean enable;
-
-    if (!get_integer_properties(ui->xinput, property,
-                                &values, &n_values)) {
-        return FALSE;
-    }
-
-    if (!gpds_ui_get_gconf_bool(GPDS_UI(ui), gconf_key_name, &enable))
-        enable = (values[0] == 1);
-    object = gtk_builder_get_object(builder, object_name);
-    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(object), enable);
-    g_free(values);
-
-    return enable;
-}
-
 static void
 set_edge_scrolling_property_from_preference (GpdsTouchpadUI *ui,
                                              GtkBuilder *builder)
@@ -657,8 +564,9 @@
     gulong n_values;
     gboolean enable;
 
-    if (!get_integer_properties(ui->xinput, GPDS_TOUCHPAD_EDGE_SCROLLING,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_TOUCHPAD_EDGE_SCROLLING,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -696,8 +604,9 @@
     gulong n_values;
     gboolean enable;
 
-    if (!get_integer_properties(ui->xinput, GPDS_TOUCHPAD_TWO_FINGER_SCROLLING,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_TOUCHPAD_TWO_FINGER_SCROLLING,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -728,9 +637,9 @@
     gulong n_values;
     gint distance;
 
-    if (!get_integer_properties(ui->xinput,
-                                GPDS_TOUCHPAD_SCROLLING_DISTANCE,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_TOUCHPAD_SCROLLING_DISTANCE,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -753,21 +662,6 @@
 }
 
 static void
-set_circular_scrolling_property_from_preference (GpdsTouchpadUI *ui,
-                                                 GtkBuilder *builder)
-{
-    gboolean enable;
-
-    enable = set_boolean_property_from_preference(ui,
-                                                  GPDS_TOUCHPAD_CIRCULAR_SCROLLING,
-                                                  GPDS_TOUCHPAD_CIRCULAR_SCROLLING_KEY,
-                                                  builder,
-                                                  "circular_scrolling");
-
-    set_widget_sensitivity(builder, "circular_scrolling_box", enable);
-}
-
-static void
 set_circular_scrolling_trigger_property_from_preference (GpdsTouchpadUI *ui,
                                                          GtkBuilder *builder)
 {
@@ -775,9 +669,9 @@
     gulong n_values;
     GpdsTouchpadCircularScrollingTrigger trigger;
 
-    if (!get_integer_properties(ui->xinput,
-                                GPDS_TOUCHPAD_CIRCULAR_SCROLLING_TRIGGER,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_TOUCHPAD_CIRCULAR_SCROLLING_TRIGGER,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -796,9 +690,9 @@
     gulong n_values;
     GpdsTouchpadUseType type;
 
-    if (!get_integer_properties(ui->xinput,
-                                GPDS_TOUCHPAD_OFF,
-                                &values, &n_values)) {
+    if (!gpds_xinput_ui_get_xinput_int_property(GPDS_XINPUT_UI(ui),
+                                                GPDS_TOUCHPAD_OFF,
+                                                &values, &n_values)) {
         return;
     }
 
@@ -814,22 +708,26 @@
 {
     GpdsTouchpadUI *touchpad_ui = GPDS_TOUCHPAD_UI(ui);
 
-    set_integer_property_from_preference(touchpad_ui,
-                                         GPDS_TOUCHPAD_TAP_TIME,
-                                         GPDS_TOUCHPAD_TAP_TIME_KEY,
-                                         builder,
-                                         "tapping_time_scale");
-    set_boolean_property_from_preference(touchpad_ui,
-                                         GPDS_TOUCHPAD_TAP_FAST_TAP, 
-                                         GPDS_TOUCHPAD_TAP_FAST_TAP_KEY,
-                                         builder,
-                                         "faster_tapping_check");
-    set_boolean_property_from_preference(touchpad_ui,
-                                         GPDS_TOUCHPAD_PALM_DETECTION, 
-                                         GPDS_TOUCHPAD_PALM_DETECTION_KEY,
-                                         builder,
-                                         "palm_detection");
-    set_circular_scrolling_property_from_preference(touchpad_ui, builder);
+    gpds_xinput_ui_set_widget_value_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_TOUCHPAD_TAP_TIME,
+                                        GPDS_TOUCHPAD_TAP_TIME_KEY,
+                                        "tapping_time_scale");
+    gpds_xinput_ui_set_toggle_button_state_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_TOUCHPAD_TAP_FAST_TAP, 
+                                        GPDS_TOUCHPAD_TAP_FAST_TAP_KEY,
+                                        "faster_tapping_check");
+    gpds_xinput_ui_set_toggle_button_state_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_TOUCHPAD_PALM_DETECTION, 
+                                        GPDS_TOUCHPAD_PALM_DETECTION_KEY,
+                                        "palm_detection");
+    gpds_xinput_ui_set_toggle_button_state_from_preference(
+                                        GPDS_XINPUT_UI(ui),
+                                        GPDS_TOUCHPAD_CIRCULAR_SCROLLING,
+                                        GPDS_TOUCHPAD_CIRCULAR_SCROLLING_KEY,
+                                        "circular_scrolling");
     set_edge_scrolling_property_from_preference(touchpad_ui, builder);
     set_scroll_distance_property_from_preference(touchpad_ui, builder);
     set_circular_scrolling_trigger_property_from_preference(touchpad_ui, builder);
@@ -841,6 +739,11 @@
 static gboolean
 is_available (GpdsUI *ui, GError **error)
 {
+    if (GPDS_UI_CLASS(gpds_touchpad_ui_parent_class)->is_available &&
+        !GPDS_UI_CLASS(gpds_touchpad_ui_parent_class)->is_available(ui, error)) {
+        return FALSE;
+    }
+
     if (!g_file_test(GPDS_TOUCHPAD_UI(ui)->ui_file_path, G_FILE_TEST_EXISTS)) {
         g_set_error(error,
                     GPDS_UI_ERROR,
@@ -857,6 +760,7 @@
 build (GpdsUI  *ui, GError **error)
 {
     GtkBuilder *builder;
+    GpdsXInput *xinput;
 
     builder = gpds_ui_get_builder(ui);
 
@@ -866,9 +770,14 @@
         return FALSE;
     }
 
-    gpds_ui_set_gconf_string(ui, GPDS_GCONF_DEVICE_TYPE_KEY, "touchpad");
-    GPDS_TOUCHPAD_UI(ui)->xinput = gpds_touchpad_xinput_new(gpds_ui_get_device_name(ui));
+    xinput = gpds_touchpad_xinput_new(gpds_ui_get_device_name(ui));
+    if (!xinput) {
+        return FALSE;
+    }
+    gpds_xinput_ui_set_xinput(GPDS_XINPUT_UI(ui), xinput);
+    g_object_unref(xinput);
 
+    gpds_ui_set_gconf_string(ui, GPDS_GCONF_DEVICE_TYPE_KEY, "touchpad");
     setup_current_values(ui, builder);
     setup_signals(ui, builder);
 

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Mar 23 03:37:26 2009
@@ -6,6 +6,7 @@
 	gpds-gconf.h			\
 	gpds-utils.h			\
 	gpds-ui.h			\
+	gpds-xinput-ui.h		\
 	gpds-xinput.h			\
 	gpds-xinput-pointer-info.h	\
 	gpds-xinput-utils.h
@@ -15,6 +16,7 @@
 	gpds-module.c			\
 	gpds-module.h			\
 	gpds-ui.c			\
+	gpds-xinput-ui.c		\
 	gpds-gconf.c			\
 	gpds-utils.c			\
 	gpds-xinput.c			\

Modified: trunk/src/gpds-ui.c
==============================================================================
--- trunk/src/gpds-ui.c	(original)
+++ trunk/src/gpds-ui.c	Mon Mar 23 03:37:26 2009
@@ -28,7 +28,6 @@
 #include <gconf/gconf-client.h>
 #include "gpds-module.h"
 #include "gpds-gconf.h"
-#include "gpds-xinput-utils.h"
 
 static GList *uis = NULL;
 
@@ -206,15 +205,6 @@
 
     g_return_val_if_fail(GPDS_IS_UI(ui), FALSE);
 
-    if (!gpds_xinput_utils_exist_device(gpds_ui_get_device_name(ui))) {
-        g_set_error(error,
-                    GPDS_XINPUT_UTILS_ERROR,
-                    GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
-                    _("No %s found."), 
-                    gpds_ui_get_device_name(ui));
-        return FALSE;
-    }
-
     klass = GPDS_UI_GET_CLASS(ui);
 
     return (klass->is_available) ? klass->is_available(ui, error) : FALSE;
@@ -261,6 +251,19 @@
     return GPDS_UI_GET_PRIVATE(ui)->builder;
 }
 
+GObject *
+gpds_ui_get_ui_object_by_name (GpdsUI *ui, const gchar *name)
+{
+    GpdsUIPriv *priv;
+
+    g_return_val_if_fail(GPDS_IS_UI(ui), NULL);
+
+    priv = GPDS_UI_GET_PRIVATE(ui);
+    g_return_val_if_fail(priv->builder, NULL);
+
+    return gtk_builder_get_object(priv->builder, name);
+}
+
 const gchar *
 gpds_ui_get_device_name (GpdsUI *ui)
 {

Modified: trunk/src/gpds-ui.h
==============================================================================
--- trunk/src/gpds-ui.h	(original)
+++ trunk/src/gpds-ui.h	Mon Mar 23 03:37:26 2009
@@ -72,6 +72,7 @@
 GtkWidget   *gpds_ui_get_content_widget   (GpdsUI *ui, GError **error);
 GdkPixbuf   *gpds_ui_get_icon_pixbuf      (GpdsUI *ui, GError **error);
 GtkBuilder  *gpds_ui_get_builder          (GpdsUI *ui);
+GObject     *gpds_ui_get_ui_object_by_name(GpdsUI *ui, const gchar *name);
 const gchar *gpds_ui_get_device_name      (GpdsUI *ui);
 void         gpds_ui_set_gconf_bool       (GpdsUI *ui,
                                            const gchar *key,

Added: trunk/src/gpds-xinput-ui.c
==============================================================================
--- (empty file)
+++ trunk/src/gpds-xinput-ui.c	Mon Mar 23 03:37:26 2009
@@ -0,0 +1,254 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "gpds-xinput-ui.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include "gpds-module.h"
+#include "gpds-xinput-utils.h"
+
+typedef struct _GpdsXInputUIPriv GpdsXInputUIPriv;
+struct _GpdsXInputUIPriv
+{
+    GpdsXInput *xinput;
+};
+
+#define GPDS_XINPUT_UI_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), GPDS_TYPE_XINPUT_UI, GpdsXInputUIPriv))
+
+G_DEFINE_ABSTRACT_TYPE(GpdsXInputUI, gpds_xinput_ui, GPDS_TYPE_UI)
+
+static void     dispose      (GObject      *object);
+static gboolean is_available (GpdsUI  *ui, GError **error);
+
+static void
+gpds_xinput_ui_class_init (GpdsXInputUIClass *klass)
+{
+    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
+    GpdsUIClass *ui_class = GPDS_UI_CLASS(klass);
+
+    gobject_class->dispose = dispose;
+
+    ui_class->is_available = is_available;
+
+    g_type_class_add_private(gobject_class, sizeof(GpdsXInputUIPriv));
+}
+
+static void
+gpds_xinput_ui_init (GpdsXInputUI *ui)
+{
+    GpdsXInputUIPriv *priv = GPDS_XINPUT_UI_GET_PRIVATE(ui);
+
+    priv->xinput = NULL;
+}
+
+static void
+dispose (GObject *object)
+{
+    GpdsXInputUIPriv *priv = GPDS_XINPUT_UI_GET_PRIVATE(object);
+
+    if (priv->xinput) {
+        g_object_unref(priv->xinput);
+        priv->xinput = NULL;
+    }
+
+    if (G_OBJECT_CLASS(gpds_xinput_ui_parent_class)->dispose)
+        G_OBJECT_CLASS(gpds_xinput_ui_parent_class)->dispose(object);
+}
+
+static gboolean
+is_available (GpdsUI *ui, GError **error)
+{
+    if (GPDS_UI_CLASS(gpds_xinput_ui_parent_class)->is_available &&
+        !GPDS_UI_CLASS(gpds_xinput_ui_parent_class)->is_available(ui, error)) {
+        return FALSE;
+    }
+
+    if (!gpds_xinput_utils_exist_device(gpds_ui_get_device_name(ui))) {
+        g_set_error(error,
+                    GPDS_XINPUT_UTILS_ERROR,
+                    GPDS_XINPUT_UTILS_ERROR_NO_DEVICE,
+                    _("No %s found."), 
+                    gpds_ui_get_device_name(ui));
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+void
+gpds_xinput_ui_set_xinput (GpdsXInputUI *ui, GpdsXInput *xinput)
+{
+    GpdsXInputUIPriv *priv;
+    g_return_if_fail(GPDS_IS_XINPUT_UI(ui));
+
+    priv = GPDS_XINPUT_UI_GET_PRIVATE(ui);
+    priv->xinput = xinput;
+    if (priv->xinput)
+        g_object_ref(priv->xinput);
+}
+
+GpdsXInput *
+gpds_xinput_ui_get_xinput (GpdsXInputUI *ui)
+{
+    g_return_val_if_fail(GPDS_IS_XINPUT_UI(ui), NULL);
+
+    return GPDS_XINPUT_UI_GET_PRIVATE(ui)->xinput;
+}
+
+static void
+show_error (GError *error)
+{
+    if (!error)
+        return;
+
+    g_print("%s\n", error->message);
+}
+
+gboolean
+gpds_xinput_ui_get_xinput_int_property (GpdsXInputUI *ui,
+                                        gint property,
+                                        gint **values,
+                                        gulong *n_values)
+{
+    GError *error = NULL;
+    GpdsXInputUIPriv *priv;
+
+    g_return_val_if_fail(GPDS_IS_XINPUT_UI(ui), FALSE);
+
+    priv = GPDS_XINPUT_UI_GET_PRIVATE(ui);
+    g_return_val_if_fail(priv->xinput, FALSE);
+
+    if (!gpds_xinput_get_int_properties(priv->xinput,
+                                        property,
+                                        &error,
+                                        values, n_values)) {
+        if (error) {
+            show_error(error);
+            g_error_free(error);
+        }
+        return FALSE;
+    }
+    return TRUE;
+}
+
+void
+gpds_xinput_ui_set_xinput_property_from_toggle_button_state (GpdsXInputUI *ui,
+                                                             gint property,
+                                                             GtkToggleButton *button)
+{
+    GError *error = NULL;
+    gint properties[1];
+    GpdsXInputUIPriv *priv;
+
+    g_return_if_fail(GPDS_IS_XINPUT_UI(ui));
+    g_return_if_fail(GTK_TOGGLE_BUTTON(button));
+
+    priv = GPDS_XINPUT_UI_GET_PRIVATE(ui);
+    if (!priv->xinput)
+        return;
+
+    properties[0] = gtk_toggle_button_get_active(button) ? 1 : 0;
+
+    if (!gpds_xinput_set_int_properties(priv->xinput,
+                                        property,
+                                        &error,
+                                        properties,
+                                        1)) {
+        if (error) {
+            show_error(error);
+            g_error_free(error);
+        }
+    }
+}
+
+void
+gpds_xinput_ui_set_toggle_button_state_from_preference (GpdsXInputUI *ui,
+                                                        gint property,
+                                                        const gchar *gconf_key_name,
+                                                        const gchar *button_name)
+{
+    GObject *button, *depend_widget;
+    gint *values;
+    gulong n_values;
+    gboolean enable;
+    gchar *depend_widget_name;
+
+    g_return_if_fail(GPDS_IS_XINPUT_UI(ui));
+
+    if (!gpds_xinput_ui_get_xinput_int_property(ui,
+                                                property,
+                                                &values, &n_values)) {
+        return;
+    }
+
+    if (!gpds_ui_get_gconf_bool(GPDS_UI(ui), gconf_key_name, &enable))
+        enable = (values[0] == 1);
+
+    button = gpds_ui_get_ui_object_by_name(GPDS_UI(ui), button_name);
+    g_return_if_fail(GTK_TOGGLE_BUTTON(button));
+
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), enable);
+    g_free(values);
+
+    depend_widget_name = g_strconcat(button_name, "_box", NULL);
+    depend_widget = gpds_ui_get_ui_object_by_name(GPDS_UI(ui), depend_widget_name);
+    if (depend_widget)
+        gtk_widget_set_sensitive(GTK_WIDGET(depend_widget), enable);
+    g_free(depend_widget_name);
+}
+
+void
+gpds_xinput_ui_set_widget_value_from_preference (GpdsXInputUI *ui,
+                                                 gint property,
+                                                 const gchar *gconf_key_name,
+                                                 const gchar *widget_name)
+{
+    GObject *object;
+    gint *values;
+    gulong n_values;
+    gint value;
+    gdouble double_value;
+
+    g_return_if_fail(GPDS_IS_XINPUT_UI(ui));
+
+    if (!gpds_xinput_ui_get_xinput_int_property(ui,
+                                                property,
+                                                &values, &n_values)) {
+        return;
+    }
+
+    if (!gpds_ui_get_gconf_int(GPDS_UI(ui), gconf_key_name, &value))
+        value = values[0];
+
+    double_value = value;
+    object = gpds_ui_get_ui_object_by_name(GPDS_UI(ui), widget_name);
+    if (GTK_IS_RANGE(object))
+        object = G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(object)));
+    g_object_set(object, "value", double_value, NULL);
+    g_free(values);
+}
+
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Added: trunk/src/gpds-xinput-ui.h
==============================================================================
--- (empty file)
+++ trunk/src/gpds-xinput-ui.h	Mon Mar 23 03:37:26 2009
@@ -0,0 +1,99 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ *  Copyright (C) 2009 Hiroyuki Ikezoe  <poincare ikezoe net>
+ *
+ *  This library is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __GPDS_XINPUT_UI_H__
+#define __GPDS_XINPUT_UI_H__
+
+#include <gpds-ui.h>
+#include <gpds-xinput.h>
+
+G_BEGIN_DECLS
+
+#define GPDS_XINPUT_UI_ERROR           (gpds_xinput_ui_error_quark())
+
+#define GPDS_TYPE_XINPUT_UI            (gpds_xinput_ui_get_type ())
+#define GPDS_XINPUT_UI(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GPDS_TYPE_XINPUT_UI, GpdsXInputUI))
+#define GPDS_XINPUT_UI_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GPDS_TYPE_XINPUT_UI, GpdsXInputUIClass))
+#define GPDS_IS_XINPUT_UI(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GPDS_TYPE_XINPUT_UI))
+#define GPDS_IS_XINPUT_UI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GPDS_TYPE_XINPUT_UI))
+#define GPDS_XINPUT_UI_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GPDS_TYPE_XINPUT_UI, GpdsXInputUIClass))
+
+typedef struct _GpdsXInputUI GpdsXInputUI;
+typedef struct _GpdsXInputUIClass GpdsXInputUIClass;
+
+struct _GpdsXInputUI
+{
+    GpdsUI parent;
+};
+
+struct _GpdsXInputUIClass
+{
+    GpdsUIClass parent_class;
+};
+
+GType       gpds_xinput_ui_get_type         (void) G_GNUC_CONST;
+void        gpds_xinput_ui_set_xinput       (GpdsXInputUI *ui,
+                                             GpdsXInput *xinput);
+GpdsXInput *gpds_xinput_ui_get_xinput       (GpdsXInputUI *ui);
+gboolean    gpds_xinput_ui_get_xinput_int_property
+                                            (GpdsXInputUI *ui,
+                                             gint property,
+                                             gint **values,
+                                             gulong *n_values);
+void        gpds_xinput_ui_set_xinput_property_from_toggle_button_state
+                                            (GpdsXInputUI *ui,
+                                             gint property,
+                                             GtkToggleButton *button);
+void        gpds_xinput_ui_set_toggle_button_state_from_preference
+                                            (GpdsXInputUI *ui,
+                                             gint property,
+                                             const gchar *gconf_key_name,
+                                             const gchar *button_name);
+void        gpds_xinput_ui_set_widget_value_from_preference
+                                            (GpdsXInputUI *ui,
+                                             gint property,
+                                             const gchar *gconf_key_name,
+                                             const gchar *widget_name);
+
+#define GPDS_XINPUT_UI_DEFINE_TOGGLE_BUTTON_CALLBACK(function_name, PROPERTY_NAME, depend_widget_name)  \
+static void                                                                                             \
+cb_ ## function_name ## _toggled (GtkToggleButton *button,                                              \
+                                  gpointer user_data)                                                   \
+{                                                                                                       \
+    GtkBuilder *builder;                                                                                \
+    GObject *depend_widget = NULL;                                                                      \
+    gboolean enable;                                                                                    \
+    gpds_xinput_ui_set_xinput_property_from_toggle_button_state(GPDS_XINPUT_UI(user_data),              \
+                                                                PROPERTY_NAME,                          \
+                                                                button);                                \
+    enable = gtk_toggle_button_get_active(button);                                                      \
+    gpds_ui_set_gconf_bool(GPDS_UI(user_data), PROPERTY_NAME ## _KEY, enable);                          \
+    builder = gpds_ui_get_builder(GPDS_UI(user_data));                                                  \
+    if (!depend_widget)                                                                                 \
+        return;                                                                                         \
+    depend_widget = gtk_builder_get_object(builder, depend_widget_name);                                \
+    gtk_widget_set_sensitive(GTK_WIDGET(depend_widget), enable);                                        \
+}
+
+G_END_DECLS
+
+#endif /* __GPDS_XINPUT_UI_H__ */
+/*
+vi:ts=4:nowrap:ai:expandtab:sw=4
+*/

Modified: trunk/src/gpointing-device-settings.h
==============================================================================
--- trunk/src/gpointing-device-settings.h	(original)
+++ trunk/src/gpointing-device-settings.h	Mon Mar 23 03:37:26 2009
@@ -25,6 +25,7 @@
 #include <gpds-gconf.h>
 #include <gpds-utils.h>
 #include <gpds-gconf.h>
+#include <gpds-xinput-ui.h>
 
 #endif /* __GPOINTING_DEVICE_SETTINGS_H__ */
 /*



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