[gnome-panel/gnome-3-18] panel-properties-dialog: simplify code
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/gnome-3-18] panel-properties-dialog: simplify code
- Date: Tue, 9 Feb 2016 11:34:30 +0000 (UTC)
commit 8b4849ba265bd296a4680f2281e8ce9dbda2960b
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Dec 23 04:00:37 2015 +0200
panel-properties-dialog: simplify code
gnome-panel/panel-properties-dialog.c | 88 +++++++++++----------------------
1 files changed, 29 insertions(+), 59 deletions(-)
---
diff --git a/gnome-panel/panel-properties-dialog.c b/gnome-panel/panel-properties-dialog.c
index 15132b7..314f9d3 100644
--- a/gnome-panel/panel-properties-dialog.c
+++ b/gnome-panel/panel-properties-dialog.c
@@ -403,65 +403,40 @@ panel_properties_dialog_image_chooser_setup (PanelPropertiesDialog *dialog,
* Background color *
\********************/
-static void
-panel_properties_dialog_background_color_get_rgba (PanelPropertiesDialog *dialog,
- GdkRGBA *color)
+static gboolean
+get_color (GValue *value,
+ GVariant *variant,
+ gpointer user_data)
{
- char *color_str;
-
- color_str = g_settings_get_string (dialog->settings_background,
- PANEL_BACKGROUND_COLOR_KEY);
+ const gchar *color;
+ GdkRGBA rgba;
- if (!gdk_rgba_parse (color, color_str))
- gdk_rgba_parse (color, PANEL_BACKGROUND_COLOR_DEFAULT);
- g_free (color_str);
-}
+ color = g_variant_get_string (variant, NULL);
-static void
-panel_properties_dialog_background_color_update_from_rgba (PanelPropertiesDialog *dialog,
- GdkRGBA *color)
-{
- /* note: we might not be fully setup, so we have to do checks */
- if (dialog->color_button)
- gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER (dialog->color_button),
- color);
-}
+ if (!gdk_rgba_parse (&rgba, color))
+ return FALSE;
-static void
-panel_properties_dialog_background_color_set_from_rgba (PanelPropertiesDialog *dialog,
- GdkRGBA *color)
-{
- char *color_str;
+ g_value_set_boxed (value, &rgba);
- color_str = gdk_rgba_to_string (color);
- g_settings_set_string (dialog->settings_background,
- PANEL_BACKGROUND_COLOR_KEY, color_str);
- g_free (color_str);
-
- /* make sure all widgets are consistent */
- panel_properties_dialog_background_color_update_from_rgba (dialog, color);
+ return TRUE;
}
-static void
-panel_properties_dialog_background_color_update (PanelPropertiesDialog *dialog)
+static GVariant *
+set_color (const GValue *value,
+ const GVariantType *expected_type,
+ gpointer user_data)
{
- GdkRGBA color;
+ GdkRGBA *rgba;
+ gchar *color;
+ GVariant *variant;
- panel_properties_dialog_background_color_get_rgba (dialog, &color);
- panel_properties_dialog_background_color_update_from_rgba (dialog, &color);
-}
+ rgba = g_value_get_boxed (value);
+ color = gdk_rgba_to_string (rgba);
-static void
-panel_properties_dialog_color_button_changed (PanelPropertiesDialog *dialog,
- GtkColorChooser *color_button)
-{
- GdkRGBA old_color;
- GdkRGBA new_color;
+ variant = g_variant_new_string (color);
+ g_free (color);
- panel_properties_dialog_background_color_get_rgba (dialog, &old_color);
- gtk_color_chooser_get_rgba (color_button, &new_color);
- new_color.alpha = old_color.alpha;
- panel_properties_dialog_background_color_set_from_rgba (dialog, &new_color);
+ return variant;
}
static void
@@ -471,15 +446,12 @@ panel_properties_dialog_color_button_setup (PanelPropertiesDialog *dialog,
dialog->color_button = PANEL_GTK_BUILDER_GET (gui, "color_button");
g_return_if_fail (dialog->color_button != NULL);
- panel_properties_dialog_background_color_update (dialog);
-
- g_signal_connect_swapped (dialog->color_button, "color_set",
- G_CALLBACK (panel_properties_dialog_color_button_changed),
- dialog);
-
- g_settings_bind_writable (dialog->settings_background,
- PANEL_BACKGROUND_COLOR_KEY,
- dialog->color_button, "sensitive", FALSE);
+ g_settings_bind_with_mapping (dialog->settings_background,
+ PANEL_BACKGROUND_COLOR_KEY,
+ dialog->color_button, "rgba",
+ G_SETTINGS_BIND_DEFAULT,
+ get_color, set_color,
+ dialog, NULL);
if (!g_settings_is_writable (dialog->settings_background,
PANEL_BACKGROUND_COLOR_KEY))
@@ -605,8 +577,6 @@ panel_properties_dialog_background_changed (GSettings *settings,
panel_properties_dialog_background_type_update (dialog);
else if (g_strcmp0 (key, PANEL_BACKGROUND_IMAGE_URI_KEY) == 0)
panel_properties_dialog_background_image_update (dialog);
- else if (g_strcmp0 (key, PANEL_BACKGROUND_COLOR_KEY) == 0)
- panel_properties_dialog_background_color_update (dialog);
}
/******************************\
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]