diff options
author | infirit <[email protected]> | 2014-07-27 20:52:16 +0200 |
---|---|---|
committer | infirit <[email protected]> | 2014-07-27 21:16:30 +0200 |
commit | 845be7089dfde1cb1168e19b01e9fdbb9852cf1e (patch) | |
tree | 94164136edf089bc2c55ccf7a6ae66cdc1e47ea3 /src | |
parent | cfafe5ebda5b0b6c77458614440d939c4832003c (diff) | |
download | eom-845be7089dfde1cb1168e19b01e9fdbb9852cf1e.tar.bz2 eom-845be7089dfde1cb1168e19b01e9fdbb9852cf1e.tar.xz |
Rework gsettings code to be more like eog
Diffstat (limited to 'src')
-rw-r--r-- | src/eom-config-keys.h | 10 | ||||
-rw-r--r-- | src/eom-plugin-engine.c | 2 | ||||
-rw-r--r-- | src/eom-preferences-dialog.c | 110 | ||||
-rw-r--r-- | src/eom-scroll-view.c | 64 | ||||
-rw-r--r-- | src/eom-window.c | 74 |
5 files changed, 126 insertions, 134 deletions
diff --git a/src/eom-config-keys.h b/src/eom-config-keys.h index bf743a3..f91295a 100644 --- a/src/eom-config-keys.h +++ b/src/eom-config-keys.h @@ -27,6 +27,12 @@ #ifndef __EOM_CONFIG_KEYS_H__ #define __EOM_CONFIG_KEYS_H__ +#define EOM_CONF_DOMAIN "org.mate.eom" +#define EOM_CONF_FULLSCREEN EOM_CONF_DOMAIN".full-screen" +#define EOM_CONF_PLUGINS EOM_CONF_DOMAIN".plugins" +#define EOM_CONF_UI EOM_CONF_DOMAIN".ui" +#define EOM_CONF_VIEW EOM_CONF_DOMAIN".view" + #define EOM_CONF_BACKGROUND_SCHEMA "org.mate.background" #define EOM_CONF_BACKGROUND_FILE "picture-filename" @@ -35,7 +41,6 @@ #define EOM_CONF_LOCKDOWN_CAN_PRINT "disable-printing" #define EOM_CONF_LOCKDOWN_CAN_SETUP_PAGE "disable-print-setup" -#define EOM_CONF_VIEW_SCHEMA "org.mate.eom.view" #define EOM_CONF_VIEW_BACKGROUND_COLOR "background-color" #define EOM_CONF_VIEW_INTERPOLATE "interpolate" #define EOM_CONF_VIEW_EXTRAPOLATE "extrapolate" @@ -46,13 +51,11 @@ #define EOM_CONF_VIEW_TRANS_COLOR "trans-color" #define EOM_CONF_VIEW_USE_BG_COLOR "use-background-color" -#define EOM_CONF_FULLSCREEN_SCHEMA "org.mate.eom.full-screen" #define EOM_CONF_FULLSCREEN_RANDOM "random" #define EOM_CONF_FULLSCREEN_LOOP "loop" #define EOM_CONF_FULLSCREEN_UPSCALE "upscale" #define EOM_CONF_FULLSCREEN_SECONDS "seconds" -#define EOM_CONF_UI_SCHEMA "org.mate.eom.ui" #define EOM_CONF_UI_TOOLBAR "toolbar" #define EOM_CONF_UI_STATUSBAR "statusbar" #define EOM_CONF_UI_IMAGE_COLLECTION "image-collection" @@ -65,7 +68,6 @@ #define EOM_CONF_UI_FILECHOOSER_XDG_FALLBACK "filechooser-xdg-fallback" #define EOM_CONF_UI_PROPSDIALOG_NETBOOK_MODE "propsdialog-netbook-mode" -#define EOM_CONF_PLUGINS_SCHEMA "org.mate.eom.plugins" #define EOM_CONF_PLUGINS_ACTIVE_PLUGINS "active-plugins" #endif /* __EOM_CONFIG_KEYS_H__ */ diff --git a/src/eom-plugin-engine.c b/src/eom-plugin-engine.c index b283ea4..11a59ea 100644 --- a/src/eom-plugin-engine.c +++ b/src/eom-plugin-engine.c @@ -395,7 +395,7 @@ eom_plugin_engine_init (void) return FALSE; } - eom_plugin_engine_settings = g_settings_new (EOM_CONF_PLUGINS_SCHEMA); + eom_plugin_engine_settings = g_settings_new (EOM_CONF_PLUGINS); g_signal_connect (eom_plugin_engine_settings, "changed::" EOM_CONF_PLUGINS_ACTIVE_PLUGINS, diff --git a/src/eom-preferences-dialog.c b/src/eom-preferences-dialog.c index d551341..7039fb0 100644 --- a/src/eom-preferences-dialog.c +++ b/src/eom-preferences-dialog.c @@ -55,27 +55,45 @@ struct _EomPreferencesDialogPrivate { static GObject *instance = NULL; -static void -pd_color_change_cb (MateColorButton *button, GSettings *settings) +static gboolean +pd_string_to_color_mapping (GValue *value, + GVariant *variant, + gpointer user_data) { GdkColor color; - char *key = NULL; - char *value = NULL; - mate_color_button_get_color (button, &color); + g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING), FALSE); - value = g_strdup_printf ("#%02X%02X%02X", - color.red / 256, - color.green / 256, - color.blue / 256); + if (gdk_color_parse (g_variant_get_string (variant, NULL), &color)) { + g_value_set_boxed (value, &color); + return TRUE; + } - key = g_object_get_data (G_OBJECT (button), GSETTINGS_OBJECT_KEY); + return FALSE; +} - if (key == NULL || value == NULL) - return; +static GVariant* +pd_color_to_string_mapping (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ - g_settings_set_string (settings, key, value); - g_free (value); + GVariant *variant = NULL; + GdkColor *color; + gchar *hex_val; + + g_return_val_if_fail (G_VALUE_TYPE (value) == GDK_TYPE_COLOR, NULL); + g_return_val_if_fail (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING), NULL); + + color = g_value_get_boxed (value); + hex_val = g_strdup_printf ("#%02X%02X%02X", + color->red / 256, + color->green / 256, + color->blue / 256); + variant = g_variant_new_string (hex_val); + g_free (hex_val); + + return variant; } static void @@ -147,6 +165,9 @@ eom_preferences_dialog_constructor (GType type, priv = EOM_PREFERENCES_DIALOG (object)->priv; + priv->view_settings = g_settings_new (EOM_CONF_VIEW); + priv->fullscreen_settings = g_settings_new (EOM_CONF_FULLSCREEN); + eom_dialog_construct (EOM_DIALOG (object), "eom-preferences-dialog.ui", "eom_preferences_dialog"); @@ -195,22 +216,13 @@ eom_preferences_dialog_constructor (GType type, "active", G_SETTINGS_BIND_DEFAULT); - value = g_settings_get_string (priv->view_settings, - EOM_CONF_VIEW_BACKGROUND_COLOR); - if (gdk_color_parse (value, &color)){ - mate_color_button_set_color (MATE_COLOR_BUTTON (bg_color_button), - &color); - } - g_free (value); - - g_object_set_data (G_OBJECT (bg_color_button), - GSETTINGS_OBJECT_KEY, - EOM_CONF_VIEW_BACKGROUND_COLOR); - - g_signal_connect (G_OBJECT (bg_color_button), - "color-set", - G_CALLBACK (pd_color_change_cb), - priv->view_settings); + g_settings_bind_with_mapping (priv->view_settings, + EOM_CONF_VIEW_BACKGROUND_COLOR, + bg_color_button, "color", + G_SETTINGS_BIND_DEFAULT, + pd_string_to_color_mapping, + pd_color_to_string_mapping, + NULL, NULL); g_object_set_data (G_OBJECT (color_radio), GSETTINGS_OBJECT_KEY, @@ -266,30 +278,16 @@ eom_preferences_dialog_constructor (GType type, g_free (value); - value = g_settings_get_string (priv->view_settings, - EOM_CONF_VIEW_TRANS_COLOR); - - if (gdk_color_parse (value, &color)) { - mate_color_button_set_color (MATE_COLOR_BUTTON (color_button), - &color); - } - - g_object_set_data (G_OBJECT (color_button), - GSETTINGS_OBJECT_KEY, - EOM_CONF_VIEW_TRANS_COLOR); - - g_signal_connect (G_OBJECT (color_button), - "color-set", - G_CALLBACK (pd_color_change_cb), - priv->view_settings); - - g_free (value); + g_settings_bind_with_mapping (priv->view_settings, + EOM_CONF_VIEW_TRANS_COLOR, + color_button, "color", + G_SETTINGS_BIND_DEFAULT, + pd_string_to_color_mapping, + pd_color_to_string_mapping, + NULL, NULL); - g_settings_bind (priv->fullscreen_settings, - EOM_CONF_FULLSCREEN_UPSCALE, - G_OBJECT (upscale_check), - "active", - G_SETTINGS_BIND_DEFAULT); + g_settings_bind (priv->fullscreen_settings, EOM_CONF_FULLSCREEN_UPSCALE, + upscale_check, "active", G_SETTINGS_BIND_DEFAULT); g_settings_bind (priv->fullscreen_settings, EOM_CONF_FULLSCREEN_LOOP, @@ -357,9 +355,9 @@ eom_preferences_dialog_init (EomPreferencesDialog *pref_dlg) { pref_dlg->priv = EOM_PREFERENCES_DIALOG_GET_PRIVATE (pref_dlg); - pref_dlg->priv->view_settings = g_settings_new (EOM_CONF_VIEW_SCHEMA); - pref_dlg->priv->fullscreen_settings = g_settings_new (EOM_CONF_FULLSCREEN_SCHEMA); - pref_dlg->priv->ui_settings = g_settings_new (EOM_CONF_UI_SCHEMA); + pref_dlg->priv->view_settings = g_settings_new (EOM_CONF_VIEW); + pref_dlg->priv->fullscreen_settings = g_settings_new (EOM_CONF_FULLSCREEN); + pref_dlg->priv->ui_settings = g_settings_new (EOM_CONF_UI); } GObject * diff --git a/src/eom-scroll-view.c b/src/eom-scroll-view.c index 52bce7e..01f22af 100644 --- a/src/eom-scroll-view.c +++ b/src/eom-scroll-view.c @@ -10,6 +10,7 @@ #include <librsvg/rsvg.h> #endif +#include "eom-config-keys.h" #include "eom-marshal.h" #include "eom-scroll-view.h" #include "eom-debug.h" @@ -2383,12 +2384,54 @@ eom_scroll_view_scrollbars_visible (EomScrollView *view) object creation/freeing ---------------------------------*/ +static gboolean +sv_string_to_color_mapping (GValue *value, + GVariant *variant, + gpointer user_data) +{ + GdkColor color; + + g_return_val_if_fail (g_variant_is_of_type (variant, G_VARIANT_TYPE_STRING), FALSE); + + if (gdk_color_parse (g_variant_get_string (variant, NULL), &color)) { + g_value_set_boxed (value, &color); + return TRUE; + } + + return FALSE; +} + +static GVariant* +sv_color_to_string_mapping (const GValue *value, + const GVariantType *expected_type, + gpointer user_data) +{ + GVariant *variant = NULL; + GdkColor *color; + gchar *hex_val; + + g_return_val_if_fail (G_VALUE_TYPE (value) == GDK_TYPE_COLOR, NULL); + g_return_val_if_fail (g_variant_type_equal (expected_type, G_VARIANT_TYPE_STRING), NULL); + + color = g_value_get_boxed (value); + hex_val = g_strdup_printf ("#%02X%02X%02X", + color->red / 256, + color->green / 256, + color->blue / 256); + variant = g_variant_new_string (hex_val); + g_free (hex_val); + + return variant; +} + static void eom_scroll_view_init (EomScrollView *view) { + GSettings *settings; EomScrollViewPrivate *priv; priv = view->priv = EOM_SCROLL_VIEW_GET_PRIVATE (view); + settings = g_settings_new (EOM_CONF_VIEW); priv->zoom = 1.0; priv->min_zoom = MIN_ZOOM_FACTOR; @@ -2408,8 +2451,6 @@ eom_scroll_view_init (EomScrollView *view) priv->cursor = EOM_SCROLL_VIEW_CURSOR_NORMAL; priv->menu = NULL; priv->background_color = NULL; - priv->override_bg_color = NULL; - priv->background_surface = NULL; priv->hadj = GTK_ADJUSTMENT (gtk_adjustment_new (0, 100, 0, 10, 10, 100)); g_signal_connect (priv->hadj, "value_changed", @@ -2488,6 +2529,17 @@ eom_scroll_view_init (EomScrollView *view) GTK_FILL, GTK_FILL, 0, 0); + g_settings_bind (settings, EOM_CONF_VIEW_USE_BG_COLOR, view, + "use-background-color", G_SETTINGS_BIND_DEFAULT); + g_settings_bind_with_mapping (settings, EOM_CONF_VIEW_BACKGROUND_COLOR, + view, "background-color", + G_SETTINGS_BIND_DEFAULT, + sv_string_to_color_mapping, + sv_color_to_string_mapping, NULL, NULL); + g_object_unref (settings); + + priv->override_bg_color = NULL; + priv->background_surface = NULL; } static void @@ -2805,12 +2857,12 @@ _eom_scroll_view_update_bg_color (EomScrollView *view) const GdkColor *selected; EomScrollViewPrivate *priv = view->priv; - if (priv->override_bg_color) + if (!priv->use_bg_color) + selected = NULL; + else if (priv->override_bg_color) selected = priv->override_bg_color; - else if (priv->use_bg_color) - selected = priv->background_color; else - selected = NULL; + selected = priv->background_color; if (priv->transp_style == EOM_TRANSP_BACKGROUND && priv->background_surface != NULL) { diff --git a/src/eom-window.c b/src/eom-window.c index 2fb032e..db585f9 100644 --- a/src/eom-window.c +++ b/src/eom-window.c @@ -269,7 +269,7 @@ static void eom_window_transparency_changed_cb (GSettings *settings, gchar *key, gpointer user_data) { EomWindowPrivate *priv; - char *value = NULL; + gchar *value = NULL; g_return_if_fail (EOM_IS_WINDOW (user_data)); @@ -285,7 +285,7 @@ eom_window_transparency_changed_cb (GSettings *settings, gchar *key, gpointer us return; } else if (g_ascii_strcasecmp (value, "COLOR") == 0) { GdkColor color; - char *color_str; + gchar *color_str; color_str = g_settings_get_string (priv->view_settings, EOM_CONF_VIEW_TRANS_COLOR); if (gdk_color_parse (color_str, &color)) { @@ -304,56 +304,12 @@ eom_window_transparency_changed_cb (GSettings *settings, gchar *key, gpointer us } static void -eom_window_bg_color_changed_cb (GSettings *settings, gchar *key, gpointer user_data) -{ - EomWindowPrivate *priv; - GdkColor color; - char *color_str; - - g_return_if_fail (EOM_IS_WINDOW (user_data)); - - eom_debug (DEBUG_PREFERENCES); - - priv = EOM_WINDOW (user_data)->priv; - - g_return_if_fail (EOM_IS_SCROLL_VIEW (priv->view)); - - color_str = g_settings_get_string (settings, key); - - if (gdk_color_parse (color_str, &color)) { - eom_scroll_view_set_background_color (EOM_SCROLL_VIEW (priv->view), &color); - } - g_free (color_str); -} - -static void -eom_window_use_bg_color_changed_cb (GSettings *settings, gchar *key, gpointer user_data) -{ - EomWindowPrivate *priv; - gboolean use_bg_color = TRUE; - - eom_debug (DEBUG_PREFERENCES); - - g_return_if_fail (EOM_IS_WINDOW (user_data)); - - priv = EOM_WINDOW (user_data)->priv; - - g_return_if_fail (EOM_IS_SCROLL_VIEW (priv->view)); - - use_bg_color = g_settings_get_boolean (settings, key); - - eom_scroll_view_set_use_bg_color (EOM_SCROLL_VIEW (priv->view), - use_bg_color); -} - - -static void eom_window_trans_color_changed_cb (GSettings *settings, gchar *key, gpointer user_data) { EomWindowPrivate *priv; GdkColor color; - char *color_str; - char *value; + gchar *color_str = NULL; + gchar *value = NULL; g_return_if_fail (EOM_IS_WINDOW (user_data)); @@ -4543,12 +4499,6 @@ eom_window_construct_ui (EomWindow *window) eom_window_interp_out_type_changed_cb (priv->view_settings, EOM_CONF_VIEW_INTERPOLATE, window); - eom_window_bg_color_changed_cb (priv->view_settings, - EOM_CONF_VIEW_BACKGROUND_COLOR, - window); - eom_window_use_bg_color_changed_cb (priv->view_settings, - EOM_CONF_VIEW_USE_BG_COLOR, - window); eom_window_transparency_changed_cb (priv->view_settings, EOM_CONF_VIEW_TRANSPARENCY, window); @@ -4589,9 +4539,9 @@ eom_window_init (EomWindow *window) priv = window->priv = EOM_WINDOW_GET_PRIVATE (window); - priv->view_settings = g_settings_new (EOM_CONF_VIEW_SCHEMA); - priv->ui_settings = g_settings_new (EOM_CONF_UI_SCHEMA); - priv->fullscreen_settings = g_settings_new (EOM_CONF_FULLSCREEN_SCHEMA); + priv->view_settings = g_settings_new (EOM_CONF_VIEW); + priv->ui_settings = g_settings_new (EOM_CONF_UI); + priv->fullscreen_settings = g_settings_new (EOM_CONF_FULLSCREEN); priv->lockdown_settings = g_settings_new (EOM_CONF_LOCKDOWN_SCHEMA); g_signal_connect (priv->view_settings, @@ -4605,16 +4555,6 @@ eom_window_init (EomWindow *window) window); g_signal_connect (priv->view_settings, - "changed::" EOM_CONF_VIEW_BACKGROUND_COLOR, - G_CALLBACK (eom_window_bg_color_changed_cb), - window); - - g_signal_connect (priv->view_settings, - "changed::" EOM_CONF_VIEW_USE_BG_COLOR, - G_CALLBACK (eom_window_use_bg_color_changed_cb), - window); - - g_signal_connect (priv->view_settings, "changed::" EOM_CONF_VIEW_TRANSPARENCY, G_CALLBACK (eom_window_transparency_changed_cb), window); |