/* Set up the property editors in the dialog. */
static void
setup_dialog (GtkBuilder *dialog)
{
	GtkRadioButton *radio;
	gboolean        touchpad_present, mouse_present;

	/* Orientation radio buttons */
	radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
	g_settings_bind (mouse_settings, "left-handed", radio, "active", G_SETTINGS_BIND_DEFAULT);

	/* explicitly connect to button-release so that you can change orientation with either button */
	g_signal_connect (WID ("right_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);
	g_signal_connect (WID ("left_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);

	/* Double-click time */
	g_settings_bind (mouse_settings, "double-click",
			 gtk_range_get_adjustment (GTK_RANGE (WID ("double_click_scale"))), "value",
			 G_SETTINGS_BIND_DEFAULT);

	/* Mouse section */
	mouse_present = mouse_is_present ();
	gtk_widget_set_visible (WID ("mouse_vbox"), mouse_present);

	g_signal_connect (WID ("pointer_speed_scale"), "value-changed",
			  G_CALLBACK (pointer_speed_scale_event), dialog);

	/* Trackpad page */
	touchpad_present = touchpad_is_present ();
	gtk_widget_set_visible (WID ("touchpad_vbox"), touchpad_present);

	g_settings_bind (touchpad_settings, "touchpad-enabled",
			 WID ("touchpad_enabled_switch"), "active",
			 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (touchpad_settings, "touchpad-enabled",
			 WID ("touchpad_options_box"), "sensitive",
			 G_SETTINGS_BIND_GET);

	g_settings_bind (touchpad_settings, "disable-while-typing",
			 WID ("disable_w_typing_toggle"), "active",
			 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (touchpad_settings, "tap-to-click",
			 WID ("tap_to_click_toggle"), "active",
			 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (touchpad_settings, "natural-scroll",
			 WID ("natural_scroll_toggle"), "active",
			 G_SETTINGS_BIND_DEFAULT);

	g_signal_connect (WID ("touchpad_pointer_speed_scale"), "value-changed",
			  G_CALLBACK (pointer_speed_scale_event), dialog);

	if (touchpad_present) {
		synaptics_check_capabilities (dialog);
		setup_scrollmethod_radios (dialog);
	}

	g_signal_connect (WID ("two_finger_scroll_toggle"), "toggled",
			  G_CALLBACK (scrollmethod_changed_event), dialog);
}
static void
device_changed (GsdDeviceManager *device_manager,
		GsdDevice *device,
		CcMousePropertiesPrivate *d)
{
	d->have_touchpad = have_device_type (d->device_manager, GSD_DEVICE_TYPE_TOUCHPAD);
	gtk_widget_set_visible (WID ("touchpad_vbox"), d->have_touchpad);

	if (d->have_touchpad) {
		d->changing_scroll = TRUE;
		synaptics_check_capabilities (d);
		setup_scrollmethod_radios (d);
		d->changing_scroll = FALSE;
	}

	d->have_mouse = have_device_type (d->device_manager, GSD_DEVICE_TYPE_MOUSE);
	gtk_widget_set_visible (WID ("mouse_vbox"), d->have_mouse);
	gtk_widget_set_visible (WID ("touchpad_enabled_switch"), 
				show_touchpad_enabling_switch (d));
}
static void
device_changed (GdkDeviceManager *device_manager,
		GdkDevice        *device,
		GtkBuilder       *dialog)
{
	gboolean present;

	present = touchpad_is_present ();
	gtk_widget_set_visible (WID ("touchpad_vbox"), present);

	if (present) {
		changing_scroll = TRUE;
		synaptics_check_capabilities (dialog);
		setup_scrollmethod_radios (dialog);
		changing_scroll = FALSE;
	}

	present = mouse_is_present ();
	gtk_widget_set_visible (WID ("mouse_vbox"), present);
}
/* Set up the property editors in the dialog. */
static void
setup_dialog (CcMousePropertiesPrivate *d)
{
	GtkRadioButton *radio;

	/* Orientation radio buttons */
	radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
	g_settings_bind (d->mouse_settings, "left-handed", radio, "active", G_SETTINGS_BIND_DEFAULT);

	/* explicitly connect to button-release so that you can change orientation with either button */
	g_signal_connect (WID ("right_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);
	g_signal_connect (WID ("left_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);

	/* Double-click time */
	g_settings_bind (d->gsd_mouse_settings, "double-click",
			 gtk_range_get_adjustment (GTK_RANGE (WID ("double_click_scale"))), "value",
			 G_SETTINGS_BIND_DEFAULT);

	/* Mouse section */
	gtk_widget_set_visible (WID ("mouse_vbox"), d->have_mouse);

	gtk_scale_add_mark (GTK_SCALE (WID ("pointer_speed_scale")), 0,
			    GTK_POS_TOP, NULL);
	g_settings_bind (d->mouse_settings, "speed",
			 gtk_range_get_adjustment (GTK_RANGE (WID ("pointer_speed_scale"))), "value",
			 G_SETTINGS_BIND_DEFAULT);

	/* Trackpad page */
	gtk_widget_set_visible (WID ("touchpad_vbox"), d->have_touchpad);
	gtk_widget_set_visible (WID ("touchpad_enabled_switch"), 
				show_touchpad_enabling_switch (d));

	g_settings_bind_with_mapping (d->touchpad_settings, "send-events",
				      WID ("touchpad_enabled_switch"), "active",
				      G_SETTINGS_BIND_DEFAULT,
				      touchpad_enabled_get_mapping,
				      touchpad_enabled_set_mapping,
				      NULL, NULL);
	g_settings_bind_with_mapping (d->touchpad_settings, "send-events",
				      WID ("touchpad_options_box"), "sensitive",
				      G_SETTINGS_BIND_GET,
				      touchpad_enabled_get_mapping,
				      touchpad_enabled_set_mapping,
				      NULL, NULL);

	g_settings_bind (d->touchpad_settings, "tap-to-click",
			 WID ("tap_to_click_toggle"), "active",
			 G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (d->touchpad_settings, "natural-scroll",
			 WID ("natural_scroll_toggle"), "active",
			 G_SETTINGS_BIND_DEFAULT);
	gtk_scale_add_mark (GTK_SCALE (WID ("touchpad_pointer_speed_scale")), 0,
			    GTK_POS_TOP, NULL);
	g_settings_bind (d->touchpad_settings, "speed",
			 gtk_range_get_adjustment (GTK_RANGE (WID ("touchpad_pointer_speed_scale"))), "value",
			 G_SETTINGS_BIND_DEFAULT);

	if (d->have_touchpad) {
		synaptics_check_capabilities (d);
		setup_scrollmethod_radios (d);
	}

	g_signal_connect (WID ("two_finger_scroll_toggle"), "toggled",
			  G_CALLBACK (scrollmethod_changed_event), d);
}
/* Set up the property editors in the dialog. */
static void
setup_dialog (GtkBuilder *dialog)
{
	GtkRadioButton    *radio;

	/* Orientation radio buttons */
	radio = GTK_RADIO_BUTTON (WID ("left_handed_radio"));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio),
		g_settings_get_boolean(mouse_settings, "left-handed"));
	/* explicitly connect to button-release so that you can change orientation with either button */
	g_signal_connect (WID ("right_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);
	g_signal_connect (WID ("left_handed_radio"), "button_release_event",
		G_CALLBACK (orientation_radio_button_release_event), NULL);
	g_signal_connect (WID ("left_handed_radio"), "toggled",
		G_CALLBACK (orientation_radio_button_toggled), dialog);

	/* Locate pointer toggle */
	g_settings_bind (mouse_settings, "locate-pointer", WID ("locate_pointer_toggle"),
		"active", G_SETTINGS_BIND_DEFAULT);

	/* Double-click time */
	g_settings_bind (mouse_settings, DOUBLE_CLICK_KEY,
		gtk_range_get_adjustment (GTK_RANGE (WID ("delay_scale"))), "value",
		G_SETTINGS_BIND_DEFAULT);
	
	gtk_image_set_from_stock (GTK_IMAGE (WID ("double_click_image")), MOUSE_DBLCLCK_OFF, mouse_capplet_dblclck_icon_get_size ());
	g_object_set_data (G_OBJECT (WID ("double_click_eventbox")), "image", WID ("double_click_image"));
	g_signal_connect (WID ("double_click_eventbox"), "button_press_event",
			  G_CALLBACK (event_box_button_press_event), NULL);

	/* speed */
	g_settings_bind (mouse_settings, "motion-acceleration",
		gtk_range_get_adjustment (GTK_RANGE (WID ("accel_scale"))), "value",
		G_SETTINGS_BIND_DEFAULT);
	g_settings_bind (mouse_settings, "motion-threshold",
		gtk_range_get_adjustment (GTK_RANGE (WID ("sensitivity_scale"))), "value",
		G_SETTINGS_BIND_DEFAULT);

	/* DnD threshold */
	g_settings_bind (mouse_settings, "drag-threshold",
		gtk_range_get_adjustment (GTK_RANGE (WID ("drag_threshold_scale"))), "value",
		G_SETTINGS_BIND_DEFAULT);

	/* Trackpad page */
	if (find_synaptics () == FALSE)
		gtk_notebook_remove_page (GTK_NOTEBOOK (WID ("prefs_widget")), -1);
	else {
		g_settings_bind (touchpad_settings, "touchpad-enabled",
			WID ("touchpad_enable"), "active",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "touchpad-enabled",
			WID ("vbox_touchpad_general"), "sensitive",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "touchpad-enabled",
			WID ("vbox_touchpad_scrolling"), "sensitive",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "disable-while-typing",
			WID ("disable_w_typing_toggle"), "active",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "tap-to-click",
			WID ("tap_to_click_toggle"), "active",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "horiz-scroll-enabled",
			WID ("horiz_scroll_toggle"), "active",
			G_SETTINGS_BIND_DEFAULT);
		g_settings_bind (touchpad_settings, "natural-scroll",
			WID ("natural_scroll_toggle"), "active",
			G_SETTINGS_BIND_DEFAULT);

		scrollmethod_gsettings_changed_event (touchpad_settings, "scroll-method", dialog);

		char * emulation_values[] = { _("Disabled"), _("Left button"), _("Middle button"), _("Right button") };

		GtkWidget *two_click_comboxbox = gtk_combo_box_text_new ();
		GtkWidget *three_click_comboxbox = gtk_combo_box_text_new ();
		gtk_box_pack_start (GTK_BOX (WID ("hbox_two_finger_click")), two_click_comboxbox, FALSE, FALSE, 6);
		gtk_box_pack_start (GTK_BOX (WID ("hbox_three_finger_click")), three_click_comboxbox, FALSE, FALSE, 6);
		int i;
		for (i=0; i<4; i++) {
			gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (two_click_comboxbox), emulation_values[i]);	
			gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (three_click_comboxbox), emulation_values[i]);	
		}
		
		gtk_combo_box_set_active (GTK_COMBO_BOX (two_click_comboxbox), g_settings_get_int (touchpad_settings, "two-finger-click"));
		gtk_combo_box_set_active (GTK_COMBO_BOX (three_click_comboxbox), g_settings_get_int (touchpad_settings, "three-finger-click"));
		gtk_widget_show (two_click_comboxbox);
		gtk_widget_show (three_click_comboxbox);
		g_signal_connect (two_click_comboxbox, "changed", G_CALLBACK (comboxbox_changed_callback), "two-finger-click");
		g_signal_connect (three_click_comboxbox, "changed", G_CALLBACK (comboxbox_changed_callback), "three-finger-click");

		radio = GTK_RADIO_BUTTON (WID ("scroll_disabled_radio"));
		GSList *radio_group = gtk_radio_button_get_group (radio);
		GSList *item = NULL;

		synaptics_check_capabilities (dialog);
		for (item = radio_group; item != NULL; item = item->next) {
			g_signal_connect (G_OBJECT (item->data), "clicked",
				  G_CALLBACK(scrollmethod_clicked_event),
				  dialog);
		}
		g_signal_connect (touchpad_settings,
			"changed::scroll-method",
			G_CALLBACK(scrollmethod_gsettings_changed_event),
			dialog);
	}

}