From 42c170078bddadd4a888c8fb91dde25d0bdec3d7 Mon Sep 17 00:00:00 2001 From: Rachel Hestilow Date: Mon, 11 Feb 2002 04:13:39 +0000 Subject: [PATCH] Reverting changes back to hovinen's pre-seth-ui setup. --- .../background-properties-capplet.c | 781 +++------------ .../background/background-properties.glade | 911 ++++++------------ libbackground/applier.c | 112 ++- libbackground/preferences.c | 101 +- libbackground/preferences.h | 15 +- 5 files changed, 490 insertions(+), 1430 deletions(-) diff --git a/capplets/background/background-properties-capplet.c b/capplets/background/background-properties-capplet.c index 71a7382ee..572767d55 100644 --- a/capplets/background/background-properties-capplet.c +++ b/capplets/background/background-properties-capplet.c @@ -1,11 +1,10 @@ -/* -*- mode: c; style: linux tab-width: 8; c-basic-offset: 8 -*- */ +/* -*- mode: c; style: linux -*- */ /* background-properties-capplet.c * Copyright (C) 2000-2001 Ximian, Inc. * * Written by: Bradford Hovinen , * Richard Hestilow - * Seth Nickell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,238 +22,18 @@ * 02111-1307, USA. */ -#include +#ifdef HAVE_CONFIG_H +# include +#endif -#include #include #include #include -#include #include "capplet-util.h" #include "gconf-property-editor.h" #include "applier.h" -typedef enum { - BACKGROUND_TYPE_NO_PICTURE = 0, - BACKGROUND_TYPE_WALLPAPER, - BACKGROUND_TYPE_CENTERED, - BACKGROUND_TYPE_SCALED, - BACKGROUND_TYPE_STRETCHED, - NUMBER_BACKGROUND_TYPES -} BackgroundType; - -enum { - TARGET_URI_LIST -}; - -static GtkTargetEntry drop_types[] = { - {"text/uri-list", 0, TARGET_URI_LIST} -}; -static gint n_drop_types = sizeof (drop_types) / sizeof (GtkTargetEntry); - -BGApplier *appliers[NUMBER_BACKGROUND_TYPES]; -GtkWidget *toggle_array[NUMBER_BACKGROUND_TYPES]; - -GObject *bg_root_applier = NULL; -GObject *bg_preferences = NULL; -GConfClient *gconf_client; - -GtkWidget *background_image_preview; -GtkWidget *background_image_label; - -GtkWidget *border_shading_label; - -GladeXML *dialog; - -static void set_background_picture (const char *filename); - -static void -set_picture_is_present (gboolean present) -{ - int i; - - for (i=1; i < NUMBER_BACKGROUND_TYPES; i++) { - gtk_widget_set_sensitive (GTK_WIDGET (toggle_array[i]), present); - } -} - -static BackgroundType -string_to_background_type (char *string) -{ - BackgroundType type = BACKGROUND_TYPE_NO_PICTURE; - - if (string) { - if (!strncmp (string, "wallpaper", sizeof ("wallpaper"))) { - type = BACKGROUND_TYPE_WALLPAPER; - } else if (!strncmp (string, "centered", sizeof ("centered"))) { - type = BACKGROUND_TYPE_CENTERED; - } else if (!strncmp (string, "scaled", sizeof ("scaled"))) { - type = BACKGROUND_TYPE_SCALED; - } else if (!strncmp (string, "stretched", sizeof ("stretched"))) { - type = BACKGROUND_TYPE_STRETCHED; - } - g_free (string); - } - - return type; -} - -static const char * -background_type_to_string (BackgroundType type) -{ - const char *tmp_string; - - switch (type) { - case 0 /* NO_PICTURE */: tmp_string = "none"; break; - case 1 /* WALLPAPER */: tmp_string = "wallpaper"; break; - case 2 /* CENTERED */: tmp_string = "centered"; break; - case 3 /* SCALED */: tmp_string = "scaled"; break; - case 4 /* STRETCHED */: tmp_string = "stretched"; break; - default: - tmp_string = "scaled"; - } - - return tmp_string; -} - -static const char * -orientation_to_string (orientation_t orientation) -{ - const char *tmp_string; - - switch (orientation) { - case ORIENTATION_HORIZ: tmp_string = "horizontal-gradient"; break; - case ORIENTATION_VERT: tmp_string = "vertical-gradient"; break; - default: - tmp_string = "solid"; - } - - return tmp_string; -} - -static orientation_t -string_to_orientation (gchar *string) -{ - orientation_t type = ORIENTATION_SOLID; - - if (string) { - if (!strncmp (string, "vertical-gradient", sizeof ("vertical-gradient"))) { - type = ORIENTATION_VERT; - } else if (!strncmp (string, "horizontal-gradient", sizeof ("horizontal-gradient"))) { - type = ORIENTATION_HORIZ; - } - g_free (string); - } - - return type; -} - -static GConfValue * -peditor_string_to_orientation (GConfValue *value) -{ - GConfValue *new_value; - const char *shading_string; - - shading_string = gconf_value_get_string (value); - - new_value = gconf_value_new (GCONF_VALUE_INT); - - gconf_value_set_int (new_value, string_to_orientation (strdup (shading_string))); - return new_value; -} - -static GConfValue * -peditor_orientation_to_string (GConfValue *value) -{ - GConfValue *new_value; - int orientation; - - orientation = gconf_value_get_int (value); - - new_value = gconf_value_new (GCONF_VALUE_STRING); - - gconf_value_set_string (new_value, orientation_to_string (orientation)); - return new_value; -} - -static gboolean -drag_motion_cb (GtkWidget *widget, GdkDragContext *context, - gint x, gint y, guint time, gpointer data) -{ - printf ("motion\n"); - return FALSE; -} - -static void -drag_leave_cb (GtkWidget *widget, GdkDragContext *context, - guint time, gpointer data) -{ - printf ("left\n"); - gtk_widget_queue_draw (widget); -} - -static void -drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, - gint x, gint y, - GtkSelectionData *selection_data, - guint info, guint time, gpointer data) -{ - GList *list; - GList *uris; - GnomeVFSURI *uri; - - printf ("received\n"); - - if (info == TARGET_URI_LIST) { - uris = gnome_vfs_uri_list_parse ((gchar *) selection_data-> - data); - for (list = uris; list; list = list->next) { - uri = (GnomeVFSURI *) list->data; - set_background_picture (gnome_vfs_uri_get_path (uri)); - } - gnome_vfs_uri_list_free (uris); - } - -} - -static void -update_preview_widgets (const BGPreferences *preferences, BGApplier **appliers, BGApplier *bg_root_applier) -{ - BGPreferences *tmp_prefs; - - tmp_prefs = BG_PREFERENCES (bg_preferences_clone (preferences)); - - if (!GTK_WIDGET_REALIZED (bg_applier_get_preview_widget (appliers[BACKGROUND_TYPE_NO_PICTURE]))) { - return; - } - - /* BACKGROUND_TYPE_NO_PICTURE */ - tmp_prefs->wallpaper_enabled = FALSE; - bg_applier_apply_prefs (appliers[BACKGROUND_TYPE_NO_PICTURE], tmp_prefs); - tmp_prefs->wallpaper_enabled = TRUE; - - /* BACKGROUND_TYPE_WALLPAPER */ - tmp_prefs->wallpaper_type = WPTYPE_TILED; - bg_applier_apply_prefs (appliers[BACKGROUND_TYPE_WALLPAPER], tmp_prefs); - - /* BACKGROUND_TYPE_CENTERED */ - tmp_prefs->wallpaper_type = WPTYPE_CENTERED; - bg_applier_apply_prefs (appliers[BACKGROUND_TYPE_CENTERED], tmp_prefs); - - /* BACKGROUND_TYPE_SCALED */ - tmp_prefs->wallpaper_type = WPTYPE_SCALED; - bg_applier_apply_prefs (appliers[BACKGROUND_TYPE_SCALED], tmp_prefs); - - /* BACKGROUND_TYPE_STRETCHED */ - tmp_prefs->wallpaper_type = WPTYPE_STRETCHED; - bg_applier_apply_prefs (appliers[BACKGROUND_TYPE_STRETCHED], tmp_prefs); - - //bg_applier_apply_prefs (bg_root_applier, preferences); - - g_object_unref (G_OBJECT (tmp_prefs)); -} - /* Retrieve legacy gnome_config settings and store them in the GConf * database. This involves some translation of the settings' meanings. */ @@ -263,7 +42,6 @@ static void get_legacy_settings (void) { int val_int; - const char *tmp_string; char *val_string; gboolean val_boolean; gboolean def; @@ -273,50 +51,51 @@ get_legacy_settings (void) client = gconf_client_get_default (); - gconf_client_set_bool (client, BG_PREFERENCES_DRAW_BACKGROUND, + gconf_client_set_bool (client, "/desktop/gnome/background/enabled", gnome_config_get_bool ("/Background/Default/Enabled=true"), NULL); val_filename = gnome_config_get_string ("/Background/Default/wallpaper=(none)"); - + gconf_client_set_string (client, "/desktop/gnome/background/wallpaper-filename", + val_filename, NULL); + if (val_filename != NULL && strcmp (val_filename, "(none)")) - gconf_client_set_string (client, BG_PREFERENCES_PICTURE_OPTIONS, "none", NULL); - else if (val_filename != NULL) - gconf_client_set_string (client, BG_PREFERENCES_PICTURE_FILENAME, - val_filename, NULL); + gconf_client_set_bool (client, "/desktop/gnome/background/wallpaper-enabled", TRUE, NULL); + else + gconf_client_set_bool (client, "/desktop/gnome/background/wallpaper-enabled", FALSE, NULL); + g_free (val_filename); - val_int = gnome_config_get_int ("/Background/Default/wallpaperAlign=0"); - gconf_client_set_string (client, BG_PREFERENCES_PICTURE_OPTIONS, - background_type_to_string (val_int), NULL); + gconf_client_set_int (client, "/desktop/gnome/background/wallpaper-type", + gnome_config_get_int ("/Background/Default/wallpaperAlign=0"), NULL); - gconf_client_set_string (client, BG_PREFERENCES_PRIMARY_COLOR, + gconf_client_set_string (client, "/desktop/gnome/background/color1", gnome_config_get_string ("/Background/Default/color1"), NULL); - gconf_client_set_string (client, BG_PREFERENCES_SECONDARY_COLOR, + gconf_client_set_string (client, "/desktop/gnome/background/color2", gnome_config_get_string ("/Background/Default/color2"), NULL); /* Code to deal with new enum - messy */ - tmp_string = NULL; + val_int = -1; val_string = gnome_config_get_string_with_default ("/Background/Default/simple=solid", &def); if (!def) { if (!strcmp (val_string, "solid")) { - tmp_string = "solid"; + val_int = ORIENTATION_SOLID; } else { g_free (val_string); val_string = gnome_config_get_string_with_default ("/Background/Default/gradient=vertical", &def); if (!def) - tmp_string = (!strcmp (val_string, "vertical")) ? "vertical-gradient" : "horizontal-gradient"; + val_int = (!strcmp (val_string, "vertical")) ? ORIENTATION_VERT : ORIENTATION_HORIZ; } } g_free (val_string); - if (tmp_string != NULL) - gconf_client_set_string (client, BG_PREFERENCES_COLOR_SHADING_TYPE, tmp_string, NULL); + if (val_int != -1) + gconf_client_set_int (client, "/desktop/gnome/background/orientation", val_int, NULL); val_boolean = gnome_config_get_bool_with_default ("/Background/Default/adjustOpacity=true", &def); if (!def && val_boolean) - gconf_client_set_int (client, BG_PREFERENCES_PICTURE_OPACITY, + gconf_client_set_int (client, "/desktop/gnome/background/opacity", gnome_config_get_int ("/Background/Default/opacity=100"), NULL); } @@ -328,7 +107,6 @@ get_legacy_settings (void) * making it feel more natural to the user. */ -#if 0 static gboolean real_realize_cb (BGPreferences *prefs) { @@ -350,70 +128,19 @@ real_realize_cb (BGPreferences *prefs) return FALSE; } -#endif -#if 0 static gboolean realize_2_cb (BGPreferences *prefs) { gtk_idle_add ((GtkFunction) real_realize_cb, prefs); return FALSE; } -#endif -#if 0 static void realize_cb (GtkWidget *widget, BGPreferences *prefs) { gtk_timeout_add (100, (GtkFunction) realize_2_cb, prefs); } -#endif - -static void -setup_color_widgets (int orientation) -{ - gboolean two_colors = TRUE; - char *color1_string = NULL; - char *color2_string = NULL; - - GtkWidget *color1_label; - GtkWidget *color2_label; - GtkWidget *color2_box; - - switch (orientation) { - case 0: /* solid */ - color1_string = "Color"; - two_colors = FALSE; - break; - case 1: /* horiz */ - color1_string = "Left Color"; - color2_string = "Right Color"; - break; - case 2: /* vert */ - color1_string = "Top Color"; - color2_string = "Bottom Color"; - break; - default: - break; - } - - - color1_label = glade_xml_get_widget (dialog, "color1_label"); - color2_label = glade_xml_get_widget (dialog, "color2_label"); - color2_box = glade_xml_get_widget (dialog, "color2_box"); - - g_assert (color1_label); - gtk_label_set_text (GTK_LABEL(color1_label), color1_string); - - if (two_colors) { - gtk_widget_show (color2_box); - - g_assert (color2_label); - gtk_label_set_text (GTK_LABEL(color2_label), color2_string); - } else { - gtk_widget_hide (color2_box); - } -} /* Callback issued when some value changes in a property editor. This merges the * value with the preferences object and applies the settings to the preview. It @@ -426,369 +153,139 @@ setup_color_widgets (int orientation) static void peditor_value_changed (GConfPropertyEditor *peditor, const gchar *key, const GConfValue *value, BGPreferences *prefs) { - bg_preferences_load (prefs); - update_preview_widgets (prefs, appliers, BG_APPLIER (bg_root_applier)); - - if (strncmp (key, BG_PREFERENCES_COLOR_SHADING_TYPE, sizeof (BG_PREFERENCES_COLOR_SHADING_TYPE)) == 0) { - int orientation; + GConfEntry *entry; + BGApplier *bg_applier; + GtkWidget *color_frame; - orientation = string_to_orientation (strdup (gconf_value_get_string (value))); - setup_color_widgets (orientation); + entry = gconf_entry_new (key, value); + bg_preferences_merge_entry (prefs, entry); + gconf_entry_free (entry); + + bg_applier = g_object_get_data (G_OBJECT (prefs), "applier"); + + if (GTK_WIDGET_REALIZED (bg_applier_get_preview_widget (bg_applier))) + bg_applier_apply_prefs (bg_applier, BG_PREFERENCES (prefs)); + + if (!strcmp (key, "/desktop/gnome/background/wallpaper-enabled") || + !strcmp (key, "/desktop/gnome/background/wallpaper-filename") || + !strcmp (key, "/desktop/gnome/background/wallpaper-type")) + { + color_frame = g_object_get_data (G_OBJECT (prefs), "color-frame"); + gtk_widget_set_sensitive (color_frame, bg_applier_render_color_p (bg_applier, prefs)); } } -static gboolean -set_background_image_preview (const char *filename) -{ - int i, length; - gboolean found = FALSE; - GdkPixbuf *pixbuf, *scaled_pixbuf; - int width, height; - float aspect_ratio; - char *message; - GtkWidget *box; - - g_assert (background_image_label != NULL); - g_assert (background_image_preview != NULL); - - if ((filename == NULL) || (!g_file_test (filename, G_FILE_TEST_EXISTS))) { - gtk_label_set_text (GTK_LABEL (background_image_label), "No Picture"); - gtk_image_set_from_stock (GTK_IMAGE (background_image_preview), GTK_STOCK_MISSING_IMAGE, - GTK_ICON_SIZE_DIALOG); - set_picture_is_present (FALSE); - - if (filename) { - gconf_client_set_string (gconf_client, BG_PREFERENCES_PICTURE_OPTIONS, "none", NULL); - message = g_strdup_printf (_("Couldn't find the file '%s'.\n\nPlease make " - "sure it exists and try again, " - "or choose a different background picture."), - filename); - - box = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - message); - gtk_dialog_run (GTK_DIALOG (box)); - gtk_widget_destroy (box); - g_free (message); - } - return FALSE; - } else { - pixbuf = gdk_pixbuf_new_from_file (filename, NULL); - } - - if (pixbuf == NULL) { - gtk_label_set_text (GTK_LABEL (background_image_label), "No Picture"); - gtk_image_set_from_stock (GTK_IMAGE (background_image_preview), GTK_STOCK_MISSING_IMAGE, - GTK_ICON_SIZE_DIALOG); - set_picture_is_present (FALSE); - gconf_client_set_string (gconf_client, BG_PREFERENCES_PICTURE_OPTIONS, "none", NULL); - message = g_strdup_printf (_("I don't know how to open the file '%s'.\n" - "Perhaps its " - "a kind of picture that is not yet supported.\n\n" - "Please select a different picture instead."), - filename); - - box = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - message); - gtk_dialog_run (GTK_DIALOG (box)); - gtk_widget_destroy (box); - g_free (message); - return FALSE; - } - - set_picture_is_present (TRUE); - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - aspect_ratio = ((float)width) / ((float)height); - - if (aspect_ratio > (4.0f / 3.0f)) { - height = (int)((160.0f / (float)width) * (float)height); - width = 160; - } else { - width = (int)((120.0f / (float)height) * (float)width); - height = 120; - } - - scaled_pixbuf = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR); - gtk_image_set_from_pixbuf (GTK_IMAGE (background_image_preview), scaled_pixbuf); - g_object_unref (G_OBJECT (scaled_pixbuf)); - g_object_unref (G_OBJECT (pixbuf)); - - length = strlen (filename); - - for (i=length; (i >= 0) && !found; i--) { - found = (filename[i] == '/'); - } - - g_assert (found); - - gtk_label_set_text (GTK_LABEL (background_image_label), &(filename[i + 2])); - - return TRUE; -} - -void file_selector_cb (GtkWidget *widget, gpointer user_data) { - const char *filename; - - GtkFileSelection *selector = GTK_FILE_SELECTION (user_data); - - filename = gtk_file_selection_get_filename (selector); - - gtk_widget_destroy (GTK_WIDGET (selector)); - - set_background_picture (filename); -} +/* Set up the property editors in the dialog. This also loads the preferences + * and sets up the callbacks. + */ static void -image_filename_clicked (GtkButton *button, gpointer user_data) +setup_dialog (GladeXML *dialog, GConfChangeSet *changeset, BGApplier *bg_applier) { - GtkWidget *file_selector; - char *old_filename; + GObject *prefs; + GObject *peditor; + GConfClient *client; - old_filename = gconf_client_get_string (gconf_client, BG_PREFERENCES_PICTURE_FILENAME, NULL); + /* Override the enabled setting to make sure background is enabled */ + client = gconf_client_get_default (); + gconf_client_set_bool (client, "/desktop/gnome/background/enabled", TRUE, NULL); - /* Create the selector */ - - file_selector = gtk_file_selection_new ("Select an image for the background"); + /* Load preferences */ + prefs = bg_preferences_new (); + bg_preferences_load (BG_PREFERENCES (prefs)); - if (old_filename != NULL && old_filename != "") { - printf ("setting a filename\n"); - gtk_file_selection_set_filename (GTK_FILE_SELECTION(file_selector), old_filename); - } + /* We need to be able to retrieve the applier and the color frame in + callbacks */ + g_object_set_data (prefs, "color-frame", WID ("color_frame")); + g_object_set_data (prefs, "applier", bg_applier); - g_signal_connect (G_OBJECT (file_selector), "destroy", - (GCallback) gtk_widget_destroyed, - &file_selector); + peditor = gconf_peditor_new_select_menu + (changeset, "/desktop/gnome/background/orientation", WID ("color_option"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); + peditor = gconf_peditor_new_color + (changeset, "/desktop/gnome/background/color1", WID ("colorpicker1"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); - g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (file_selector)->ok_button), - "clicked", (GCallback ) file_selector_cb, file_selector); + peditor = gconf_peditor_new_color + (changeset, "/desktop/gnome/background/color2", WID ("colorpicker2"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); - g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (file_selector)->cancel_button), - "clicked", (GCallback ) gtk_widget_destroy, file_selector); - - /* Display that dialog */ - - gtk_widget_show (file_selector); + peditor = gconf_peditor_new_filename + (changeset, "/desktop/gnome/background/wallpaper-filename", WID ("image_fileentry"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); + + peditor = gconf_peditor_new_select_menu + (changeset, "/desktop/gnome/background/wallpaper-type", WID ("image_option"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); + + peditor = gconf_peditor_new_boolean + (changeset, "/desktop/gnome/background/wallpaper-enabled", WID ("picture_enabled_check"), NULL); + g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, prefs); + + gconf_peditor_widget_set_guard (GCONF_PROPERTY_EDITOR (peditor), WID ("picture_frame")); + + /* Make sure preferences get applied to the preview */ + if (GTK_WIDGET_REALIZED (bg_applier_get_preview_widget (bg_applier))) + bg_applier_apply_prefs (bg_applier, BG_PREFERENCES (prefs)); + else + g_signal_connect_after (G_OBJECT (bg_applier_get_preview_widget (bg_applier)), "realize", + (GCallback) realize_cb, prefs); + + /* Make sure the preferences object gets destroyed when the dialog is + closed */ + g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_object_unref, prefs); } - -static void -background_type_toggled (GtkWidget *widget, gpointer data) -{ - GtkWidget **toggle_array = (GtkWidget **)data; - static gboolean lock = FALSE; - int i; - - if (lock == TRUE) { - return; - } else { - lock = TRUE; - } - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)) == FALSE) { - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE); - lock = FALSE; - return; - } - - for (i = 0; i < NUMBER_BACKGROUND_TYPES; i++) { - if (widget != toggle_array[i]) { - g_object_set (G_OBJECT (toggle_array[i]), "active", FALSE, NULL); - } else { - gconf_client_set_string (gconf_client, BG_PREFERENCES_PICTURE_OPTIONS, - background_type_to_string (i), NULL); - } - } - - - bg_preferences_load (BG_PREFERENCES (bg_preferences)); - - lock = FALSE; -} - -static void -change_background_type_toggles (BackgroundType background_type, GtkWidget **toggle_array) -{ - if (background_type > NUMBER_BACKGROUND_TYPES) { - g_warning ("An unknown background type, %d, was set. Ignoring...", background_type); - return; - } - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_array[background_type]), TRUE); - - if (background_type == BACKGROUND_TYPE_NO_PICTURE) { - gtk_label_set_text (GTK_LABEL (border_shading_label), "Fill the background with a:"); - } else { - gtk_label_set_text (GTK_LABEL (border_shading_label), "Border the picture with a:"); - } -} - -static void -background_type_changed (GConfClient *client, guint cnxn_id, - GConfEntry *entry, gpointer user_data) -{ - int background_type; - GtkWidget **toggle_array = (GtkWidget **) user_data; - - background_type = string_to_background_type (strdup (gconf_value_get_string (gconf_entry_get_value (entry)))); - - change_background_type_toggles (background_type, toggle_array); -} - - -static void -set_background_picture (const char *filename) -{ - gboolean image_is_valid; - - image_is_valid = set_background_image_preview (filename); - - gconf_client_set_string (gconf_client, BG_PREFERENCES_PICTURE_FILENAME, filename, NULL); - - bg_preferences_load (BG_PREFERENCES (bg_preferences)); - - update_preview_widgets (BG_PREFERENCES (bg_preferences), appliers, BG_APPLIER (bg_root_applier)); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (toggle_array[BACKGROUND_TYPE_NO_PICTURE]))) { - /* no picture is selected, change to centered so people don't get confused as - to why the image isn't "taking */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_array[BACKGROUND_TYPE_CENTERED]), TRUE); - } -} - - /* Construct the dialog */ static GladeXML * -create_dialog (BGApplier **bg_appliers) +create_dialog (BGApplier *bg_applier) { + GtkWidget *holder; GtkWidget *widget; - - GObject *peditor; - - int i, background_type; - char *filename; GladeXML *dialog; - gboolean image_is_valid; /* FIXME: What the hell is domain? */ - dialog = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/background-properties.glade", "background_preferences_widget", NULL); - - widget = WID ("background_preferences_widget"); + dialog = glade_xml_new (GNOMECC_DATA_DIR "/interfaces/background-properties.glade", "prefs_widget", NULL); + widget = glade_xml_get_widget (dialog, "prefs_widget"); - toggle_array[BACKGROUND_TYPE_NO_PICTURE] = glade_xml_get_widget (dialog, "no_picture_toggle"); - toggle_array[BACKGROUND_TYPE_WALLPAPER] = glade_xml_get_widget (dialog, "wallpaper_toggle"); - toggle_array[BACKGROUND_TYPE_CENTERED] = glade_xml_get_widget (dialog, "centered_toggle"); - toggle_array[BACKGROUND_TYPE_SCALED] = glade_xml_get_widget (dialog, "scaled_toggle"); - toggle_array[BACKGROUND_TYPE_STRETCHED] = glade_xml_get_widget (dialog, "stretched_toggle"); - - for (i = 0; i < NUMBER_BACKGROUND_TYPES; i++) { - g_signal_connect (G_OBJECT (toggle_array[i]), - "clicked", (GCallback) background_type_toggled, - toggle_array); - } + /* Minor GUI addition */ + holder = WID ("prefs_widget"); + gtk_box_pack_start (GTK_BOX (holder), bg_applier_get_preview_widget (bg_applier), TRUE, TRUE, 0); + gtk_widget_show_all (holder); - border_shading_label = glade_xml_get_widget (dialog, "border_shading_label"); - - background_type = string_to_background_type (gconf_client_get_string (gconf_client, - BG_PREFERENCES_PICTURE_OPTIONS, - NULL)); - - change_background_type_toggles (background_type, toggle_array); - - gconf_client_notify_add (gconf_client, BG_PREFERENCES_PICTURE_OPTIONS, - &background_type_changed, toggle_array, NULL, NULL); - - - widget = glade_xml_get_widget (dialog, "color1"); - peditor = gconf_peditor_new_color - (NULL, BG_PREFERENCES_PRIMARY_COLOR, widget, NULL); - g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, bg_preferences); - - widget = glade_xml_get_widget (dialog, "color2"); - peditor = gconf_peditor_new_color - (NULL, BG_PREFERENCES_SECONDARY_COLOR, widget, NULL); - g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, bg_preferences); - - widget = glade_xml_get_widget (dialog, "border_shading"); - peditor = gconf_peditor_new_select_menu - (NULL, BG_PREFERENCES_COLOR_SHADING_TYPE, widget, - "conv-to-widget-cb", peditor_string_to_orientation, - "conv-from-widget-cb", peditor_orientation_to_string, NULL); - - g_signal_connect (peditor, "value-changed", (GCallback) peditor_value_changed, bg_preferences); - - - - widget = glade_xml_get_widget (dialog, "no_picture_frame"); - gtk_box_pack_end (GTK_BOX (widget), bg_applier_get_preview_widget (bg_appliers [BACKGROUND_TYPE_NO_PICTURE]), TRUE, TRUE, 0); - - widget = glade_xml_get_widget (dialog, "wallpaper_frame"); - gtk_box_pack_end (GTK_BOX (widget), bg_applier_get_preview_widget (bg_appliers [BACKGROUND_TYPE_WALLPAPER]), TRUE, TRUE, 0); - - widget = glade_xml_get_widget (dialog, "centered_frame"); - gtk_box_pack_end (GTK_BOX (widget), bg_applier_get_preview_widget (bg_appliers [BACKGROUND_TYPE_CENTERED]), TRUE, TRUE, 0); - - widget = glade_xml_get_widget (dialog, "scaled_frame"); - gtk_box_pack_end (GTK_BOX (widget), bg_applier_get_preview_widget (bg_appliers [BACKGROUND_TYPE_SCALED]), TRUE, TRUE, 0); - - widget = glade_xml_get_widget (dialog, "stretched_frame"); - gtk_box_pack_end (GTK_BOX (widget), bg_applier_get_preview_widget (bg_appliers [BACKGROUND_TYPE_STRETCHED]), TRUE, TRUE, 0); - - widget = glade_xml_get_widget (dialog, "background_image_button"); - g_signal_connect (G_OBJECT (widget), "clicked", (GCallback) image_filename_clicked, NULL); - - background_image_preview = glade_xml_get_widget (dialog, "background_image_preview"); - - background_image_label = glade_xml_get_widget (dialog, "image_filename_label"); - filename = gconf_client_get_string (gconf_client, BG_PREFERENCES_PICTURE_FILENAME, NULL); - - image_is_valid = set_background_image_preview (filename); + g_object_weak_ref (G_OBJECT (widget), (GWeakNotify) g_object_unref, dialog); return dialog; } -static gboolean -idle_draw (gpointer data) -{ - update_preview_widgets (BG_PREFERENCES (bg_preferences), appliers, BG_APPLIER (bg_root_applier)); - return FALSE; -} +/* Callback issued when a button is clicked on the dialog */ static void -dialog_button_clicked_cb (GtkDialog *dialog, gint response_id, GConfChangeSet *changeset) +dialog_button_clicked_cb (GnomeDialog *dialog, gint response_id, GConfChangeSet *changeset) { switch (response_id) { + case GTK_RESPONSE_APPLY: + gconf_client_commit_change_set (gconf_client_get_default (), changeset, TRUE, NULL); + break; + case GTK_RESPONSE_CLOSE: gtk_main_quit (); break; } } -static void -quit_cb (GtkWidget *widget, gpointer data) -{ - gtk_main_quit(); -} - int main (int argc, char **argv) { + GConfClient *client; GConfChangeSet *changeset; - GtkWidget *dialog_win; - GdkPixbuf *pixbuf; + GladeXML *dialog; + GtkWidget *dialog_win; + GObject *bg_applier; - int orientation; - int i; static gboolean get_legacy; - static struct poptOption cap_options[] = { { "get-legacy", '\0', POPT_ARG_NONE, &get_legacy, 0, N_("Retrieve and store legacy settings"), NULL }, @@ -803,69 +300,29 @@ main (int argc, char **argv) GNOME_PARAM_POPT_TABLE, cap_options, NULL); - setup_session_mgmt (argv[0]); - - gconf_client = gconf_client_get_default (); - gconf_client_add_dir (gconf_client, "/desktop/gnome/background", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + client = gconf_client_get_default (); + gconf_client_add_dir (client, "/desktop/gnome/background", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); if (get_legacy) { get_legacy_settings (); } else { changeset = gconf_change_set_new (); - - for (i=0; i < NUMBER_BACKGROUND_TYPES; i++) { - appliers[i] = BG_APPLIER (bg_applier_new (BG_APPLIER_PREVIEW)); - } - - /* setup a background preferences object */ - bg_preferences = bg_preferences_new (); - bg_preferences_load (BG_PREFERENCES (bg_preferences)); - - /* setup a background applier for the root window */ - bg_root_applier = bg_applier_new (BG_APPLIER_ROOT); - - dialog = create_dialog (appliers); + bg_applier = bg_applier_new (BG_APPLIER_PREVIEW); + dialog = create_dialog (BG_APPLIER (bg_applier)); + setup_dialog (dialog, changeset, BG_APPLIER (bg_applier)); dialog_win = gtk_dialog_new_with_buttons - (_("Background Properties"), NULL, -1, + (_("Background properties"), NULL, -1, + GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); - gtk_window_set_modal (GTK_WINDOW(dialog_win), FALSE); - pixbuf = gdk_pixbuf_new_from_file (GNOMECC_DATA_DIR "/icons/background-capplet.png", NULL); - gtk_window_set_icon (GTK_WINDOW(dialog_win), pixbuf); - + g_signal_connect (G_OBJECT (dialog_win), "response", (GCallback) dialog_button_clicked_cb, changeset); - gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_win)->vbox), - WID ("background_preferences_widget"), TRUE, - TRUE, GNOME_PAD_SMALL); - - gtk_drag_dest_set (dialog_win, GTK_DEST_DEFAULT_ALL, - drop_types, n_drop_types, - GDK_ACTION_COPY | GDK_ACTION_LINK | GDK_ACTION_MOVE); - g_signal_connect (G_OBJECT (dialog_win), "drag-motion", - G_CALLBACK (drag_motion_cb), NULL); - g_signal_connect (G_OBJECT (dialog_win), "drag-leave", - G_CALLBACK (drag_leave_cb), NULL); - g_signal_connect (G_OBJECT (dialog_win), "drag-data-received", - G_CALLBACK (drag_data_received_cb), - NULL); - - g_signal_connect (G_OBJECT (dialog_win), "close", - G_CALLBACK (quit_cb), NULL); - g_signal_connect (G_OBJECT (dialog_win), "response", - G_CALLBACK (quit_cb), NULL); + g_object_weak_ref (G_OBJECT (dialog_win), (GWeakNotify) g_object_unref, bg_applier); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog_win)->vbox), WID ("prefs_widget"), TRUE, TRUE, GNOME_PAD_SMALL); gtk_widget_show_all (dialog_win); - orientation = string_to_orientation (gconf_client_get_string (gconf_client, BG_PREFERENCES_COLOR_SHADING_TYPE, NULL)); - setup_color_widgets (orientation); - - gtk_idle_add (idle_draw, NULL); - - /* Make sure the preferences object gets destroyed when the dialog is - closed */ - g_object_weak_ref (G_OBJECT (dialog), (GWeakNotify) g_object_unref, bg_preferences); - gtk_main (); gconf_change_set_unref (changeset); } diff --git a/capplets/background/background-properties.glade b/capplets/background/background-properties.glade index 21505f632..156493dfd 100644 --- a/capplets/background/background-properties.glade +++ b/capplets/background/background-properties.glade @@ -4,8 +4,8 @@ - - Background Properties + + window1 GTK_WINDOW_TOPLEVEL no no @@ -14,197 +14,236 @@ GTK_WIN_POS_NONE - - yes - yes - yes - GTK_POS_TOP - no - 2 - 2 - no + + 4 + no + 0 yes - - no - 0 + + 4 + Background picture + 0 + GTK_SHADOW_ETCHED_IN yes - + 10 no - 0 + 10 + 3 + 2 + 2 yes - - no - 15 + + Image: + GTK_JUSTIFY_CENTER + no + 0 + 0.5 + 0 + 0 + yes + + + 0 + 1 + 0 + 1 + 0 + 0 + fill + + + + + + + Style: + GTK_JUSTIFY_CENTER + no + 0 + 0.5 + 0 + 0 + yes + + + 0 + 1 + 1 + 2 + 0 + 0 + fill + + + + + + + 7.45058e-09 + 0.5 + 0 + 1 yes - - Picture: - 0 - GTK_SHADOW_NONE + + yes + 0 yes - - - yes - GTK_RELIEF_NORMAL + + yes - - no - 0 + yes - - 0.5 - 0.5 - 0 - 0 + + Tiled + 0.0 + convertwidget2 + yes yes - - 0 - yes - yes - + + + + + + yes - - - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 + + Centered + 0.0 + convertwidget3 + yes + yes + + + + + + + + yes + + + + Scaled (keep aspect ratio) + 0.0 + convertwidget4 + yes + yes + + + + + + + + yes + + + + Stretched + 0.0 + convertwidget5 + yes yes - - 0 - no - no - - - 0 - yes - yes - - - - - - no - 0 - yes - - - - - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - yes - no - - - - - - You can drag image files -into the window to set the -background picture. - GTK_JUSTIFY_LEFT - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - yes - yes - - - - - - - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - yes - no - - - - - 0 - yes - yes - - 0 - yes - yes + 1 + 2 + 1 + 2 + 0 + 0 + fill + + + + + + + no + no + yes + + + + yes + yes + + 0 + yes + yes + + + + + 1 + 2 + 0 + 1 + 0 + 0 + expand|fill + - - 0 - yes - yes - + + + 0 + no + no + GTK_PACK_END + + + + + + 4 + Background colors + 0 + GTK_SHADOW_ETCHED_IN + yes - + 10 no - 0 + 8 yes - - Border the picture with a: - GTK_JUSTIFY_LEFT + + Style: + GTK_JUSTIFY_CENTER no - 7.45058e-09 + 0.5 0.5 - 3 + 0 0 yes @@ -216,535 +255,125 @@ background picture. - - no - 0 + + yes + 0 yes - - - no - 0 + + yes - - yes - 0 + yes - - + + + Solid color + 0.0 + convertwidget11 + yes + yes + + + + + + + + yes + + + + Horizontal gradient + 0.0 + convertwidget12 + yes + yes + + + + + + + + yes + + + + Vertical gradient + 0.0 + convertwidget13 + yes yes - - - - yes - - - - Solid Colour - 0.0 - convertwidget2 - yes - yes - - - - - - - - yes - - - - Horizontal Gradient - 0.0 - convertwidget3 - yes - yes - - - - - - - - yes - - - - Vertical Gradient - 0.0 - convertwidget4 - yes - yes - - - - - - 0 - no - no - - - 0 - no - no - - - - - - no - 10 - yes - - - - - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - yes - no - - - - - - no - 3 - yes - - - - Color 1 - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - no - no - - - - - - yes - yes - no - Pick a color - yes - - - 0 - no - no - - - - - 0 - no - yes - - - - - - no - 3 - yes - - - - Color 2 - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - 0 - no - no - - - - - - yes - yes - no - Pick a color - yes - - - 0 - no - no - - - - - 0 - no - yes - - - - - 0 - yes - yes - 0 - yes - yes + no + no + + + + + + yes + yes + no + Pick a color + yes + + + 0 + no + no + + + + + + yes + yes + no + Pick a color + yes + + + 0 + no + no - - 0 - yes - yes - GTK_PACK_END - - - - - 10 - Picture Options: - 0 - GTK_SHADOW_NONE - yes - - - - no - 2 - yes - - - - yes - 5 - yes - - - - yes - GTK_RELIEF_NORMAL - no - yes - - - - no - 0 - yes - - - - _No Picture - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - yes - - - 0 - no - no - GTK_PACK_END - - - - - - - 0 - no - yes - - - - - - yes - GTK_RELIEF_NORMAL - no - yes - - - - no - 0 - yes - - - - _Wallpaper - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - yes - - - 0 - no - no - GTK_PACK_END - - - - - - - 0 - no - yes - - - - - - yes - GTK_RELIEF_NORMAL - no - yes - - - - no - 0 - yes - - - - _Centered - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - yes - - - 0 - no - no - GTK_PACK_END - - - - - - - 0 - no - yes - - - - - - yes - GTK_RELIEF_NORMAL - no - yes - - - - no - 0 - yes - - - - _Scaled - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - yes - - - 0 - no - no - GTK_PACK_END - - - - - - - 0 - no - yes - - - - - - yes - GTK_RELIEF_NORMAL - no - yes - - - - no - 0 - yes - - - - S_tretched - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - yes - - - 0 - no - no - GTK_PACK_END - - - - - - - 0 - no - yes - - - - - 0 - yes - yes - - - - - - - 0 - yes - yes - GTK_PACK_END - - - - - - - - E-Mail - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - tab + 0 + no + no + GTK_PACK_END - - yes - - - - - - Workspace 3 - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 + + yes + Use a picture for the background + no + yes yes - tab - - - - - - yes - - - - - - Workspace 4 - GTK_JUSTIFY_CENTER - no - 0.5 - 0.5 - 0 - 0 - yes - - - tab + 0 + no + no + GTK_PACK_END diff --git a/libbackground/applier.c b/libbackground/applier.c index 794d33bb3..04967e955 100644 --- a/libbackground/applier.c +++ b/libbackground/applier.c @@ -42,10 +42,10 @@ #include "applier.h" -#define MONITOR_CONTENTS_X 0 -#define MONITOR_CONTENTS_Y 0 -#define MONITOR_CONTENTS_WIDTH 51 -#define MONITOR_CONTENTS_HEIGHT 38 +#define MONITOR_CONTENTS_X 20 +#define MONITOR_CONTENTS_Y 10 +#define MONITOR_CONTENTS_WIDTH 157 +#define MONITOR_CONTENTS_HEIGHT 111 enum { PROP_0, @@ -390,27 +390,21 @@ bg_applier_apply_prefs (BGApplier *bg_applier, bg_applier->p->wallpaper_pixbuf = NULL; if (new_prefs->wallpaper_enabled) { - if (new_prefs->wallpaper_filename == NULL) { - new_prefs->wallpaper_enabled = FALSE; - } else { - g_return_if_fail (new_prefs->wallpaper_filename != NULL); + g_return_if_fail (new_prefs->wallpaper_filename != NULL); - bg_applier->p->wallpaper_pixbuf = - gdk_pixbuf_new_from_file (new_prefs->wallpaper_filename, NULL); + bg_applier->p->wallpaper_pixbuf = + gdk_pixbuf_new_from_file (new_prefs->wallpaper_filename, NULL); - if (bg_applier->p->wallpaper_pixbuf == NULL) { - g_warning (_("Could not load pixbuf \"%s\"; disabling wallpaper."), - new_prefs->wallpaper_filename); - new_prefs->wallpaper_enabled = FALSE; - - } - else - { - if (bg_applier->p->timeout) + if (bg_applier->p->wallpaper_pixbuf == NULL) { + g_warning (_("Could not load pixbuf \"%s\"; disabling wallpaper."), + new_prefs->wallpaper_filename); + new_prefs->wallpaper_enabled = FALSE; + } + else + { + if (bg_applier->p->timeout) g_source_remove (bg_applier->p->timeout); - bg_applier->p->timeout = g_timeout_add (30000, (GSourceFunc) cleanup_cb, bg_applier); - - } + bg_applier->p->timeout = g_timeout_add (30000, (GSourceFunc) cleanup_cb, bg_applier); } } } @@ -443,15 +437,68 @@ bg_applier_render_color_p (const BGApplier *bg_applier, const BGPreferences *pre GtkWidget * bg_applier_get_preview_widget (BGApplier *bg_applier) { - if (bg_applier->p->preview_widget == NULL) { - GdkPixmap *pixmap; + GdkPixbuf *pixbuf; + GdkPixmap *pixmap; + GdkBitmap *mask; + GdkVisual *visual; + GdkColormap *colormap; + gchar *filename; + GdkGC *gc; - /* fixme: What to do here? gdk does not export root_parent publicly (Lauris) */ - pixmap = gdk_pixmap_new (GDK_ROOT_PARENT(), 51, 38, -1); - bg_applier->p->preview_widget = gtk_image_new_from_pixmap (pixmap, NULL); - } + g_return_val_if_fail (bg_applier != NULL, NULL); + g_return_val_if_fail (IS_BG_APPLIER (bg_applier), NULL); - return bg_applier->p->preview_widget; + if (bg_applier->p->type != BG_APPLIER_PREVIEW) + return NULL; + + if (bg_applier->p->preview_widget != NULL) + return bg_applier->p->preview_widget; + + filename = gnome_pixmap_file ("monitor.png"); + visual = gdk_window_get_visual (GDK_ROOT_PARENT ()); + colormap = gdk_window_get_colormap (GDK_ROOT_PARENT ()); + + gtk_widget_push_visual (visual); + gtk_widget_push_colormap (colormap); + + pixbuf = gdk_pixbuf_new_from_file (filename, NULL); + + if (pixbuf == NULL) return NULL; + + pixmap = gdk_pixmap_new (GDK_ROOT_PARENT (), + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + visual->depth); + mask = gdk_pixmap_new (GDK_ROOT_PARENT (), + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + 1); + + gc = gdk_gc_new (GDK_ROOT_PARENT ()); + + gdk_pixbuf_render_threshold_alpha (pixbuf, mask, + 0, 0, 0, 0, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + 1); + + gdk_gc_set_clip_mask (gc, mask); + + gdk_pixbuf_render_to_drawable (pixbuf, pixmap, gc, + 0, 0, 0, 0, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf), + GDK_RGB_DITHER_MAX, 0, 0); + + bg_applier->p->preview_widget = gtk_pixmap_new (pixmap, mask); + gtk_widget_show (bg_applier->p->preview_widget); + g_object_unref (G_OBJECT (pixbuf)); + g_free (filename); + + gtk_widget_pop_visual (); + gtk_widget_pop_colormap (); + + return bg_applier->p->preview_widget; } GdkPixbuf * @@ -474,8 +521,6 @@ draw_disabled_message (GtkWidget *widget) gint x, y, w, h; const char *disabled_string = _("Disabled"); - printf ("disabled\n"); - g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_IMAGE (widget)); @@ -806,8 +851,7 @@ create_pixmap (BGApplier *bg_applier, const BGPreferences *prefs) if (!GTK_WIDGET_REALIZED (bg_applier->p->preview_widget)) gtk_widget_realize (bg_applier->p->preview_widget); - g_assert (gtk_image_get_storage_type (GTK_IMAGE(bg_applier->p->preview_widget)) == GTK_IMAGE_PIXMAP); - gtk_image_get_pixmap (GTK_IMAGE (bg_applier->p->preview_widget), &bg_applier->p->pixmap, NULL); + bg_applier->p->pixmap = GTK_PIXMAP (bg_applier->p->preview_widget)->pixmap; bg_applier->p->pixmap_is_set = TRUE; break; } @@ -918,8 +962,6 @@ get_geometry (wallpaper_type_t wallpaper_type, src_geom->width = pwidth; src_geom->height = pheight; break; - case WPTYPE_EMBOSSED: - g_warning ("Embossing is not yet supported"); default: g_error ("Bad wallpaper type"); break; diff --git a/libbackground/preferences.c b/libbackground/preferences.c index 90f6f7665..ddf377bf4 100644 --- a/libbackground/preferences.c +++ b/libbackground/preferences.c @@ -41,8 +41,6 @@ static void bg_preferences_class_init (BGPreferencesClass *class); static void bg_preferences_finalize (GObject *object); static GdkColor *read_color_from_string (const gchar *string); -static orientation_t read_orientation_from_string (gchar *string); -static wallpaper_type_t read_wptype_from_string (gchar *string); GType bg_preferences_get_type (void) @@ -175,30 +173,22 @@ bg_preferences_load (BGPreferences *prefs) client = gconf_client_get_default (); - prefs->enabled = gconf_client_get_bool (client, BG_PREFERENCES_DRAW_BACKGROUND, &error); - prefs->wallpaper_filename = gconf_client_get_string (client, BG_PREFERENCES_PICTURE_FILENAME, &error); - - prefs->color1 = read_color_from_string (gconf_client_get_string (client, BG_PREFERENCES_PRIMARY_COLOR, &error)); - prefs->color2 = read_color_from_string (gconf_client_get_string (client, BG_PREFERENCES_SECONDARY_COLOR, &error)); - - prefs->opacity = gconf_client_get_int (client, BG_PREFERENCES_PICTURE_OPACITY, &error); + prefs->enabled = gconf_client_get_bool (client, "/desktop/gnome/background/enabled", &error); + prefs->wallpaper_type = gconf_client_get_int (client, "/desktop/gnome/background/wallpaper-type", &error); + prefs->wallpaper_filename = gconf_client_get_string (client, "/desktop/gnome/background/wallpaper-filename", &error); + prefs->wallpaper_enabled = gconf_client_get_bool (client, "/desktop/gnome/background/wallpaper-enabled", &error); + prefs->color1 = read_color_from_string (gconf_client_get_string (client, "/desktop/gnome/background/color1", &error)); + prefs->color2 = read_color_from_string (gconf_client_get_string (client, "/desktop/gnome/background/color2", &error)); + prefs->opacity = gconf_client_get_int (client, "/desktop/gnome/background/opacity", &error); if (prefs->opacity >= 100 || prefs->opacity < 0) prefs->adjust_opacity = FALSE; - prefs->orientation = read_orientation_from_string (gconf_client_get_string (client, BG_PREFERENCES_COLOR_SHADING_TYPE, &error)); + prefs->orientation = gconf_client_get_int (client, "/desktop/gnome/background/orientation", &error); + if (prefs->orientation == ORIENTATION_SOLID) prefs->gradient_enabled = FALSE; else prefs->gradient_enabled = TRUE; - - prefs->wallpaper_type = read_wptype_from_string (gconf_client_get_string (client, BG_PREFERENCES_PICTURE_OPTIONS, &error)); - - if (prefs->wallpaper_type == -1) { - prefs->wallpaper_enabled = FALSE; - prefs->wallpaper_type = WPTYPE_CENTERED; - } else { - prefs->wallpaper_enabled = TRUE; - } } /* Parse the event name given (the event being notification of a property having @@ -215,17 +205,10 @@ bg_preferences_merge_entry (BGPreferences *prefs, g_return_if_fail (prefs != NULL); g_return_if_fail (IS_BG_PREFERENCES (prefs)); - if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPTIONS)) { - prefs->wallpaper_type = read_wptype_from_string (g_strdup (gconf_value_get_string (value))); - if (prefs->wallpaper_type == -1) { - prefs->wallpaper_enabled = FALSE; - prefs->wallpaper_type = WPTYPE_CENTERED; - } else { - prefs->wallpaper_enabled = TRUE; - } - + if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper_type")) { + prefs->wallpaper_type = gconf_value_get_int (value); } - else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_FILENAME)) { + else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-filename")) { prefs->wallpaper_filename = g_strdup (gconf_value_get_string (value)); if (prefs->wallpaper_filename != NULL && @@ -235,27 +218,27 @@ bg_preferences_merge_entry (BGPreferences *prefs, else prefs->wallpaper_enabled = FALSE; } - else if (!strcmp (entry->key, BG_PREFERENCES_PRIMARY_COLOR)) { + else if (!strcmp (entry->key, "/desktop/gnome/background/color1")) { prefs->color1 = read_color_from_string (gconf_value_get_string (value)); } - else if (!strcmp (entry->key, BG_PREFERENCES_SECONDARY_COLOR)) { + else if (!strcmp (entry->key, "/desktop/gnome/background/color2")) { prefs->color2 = read_color_from_string (gconf_value_get_string (value)); } - else if (!strcmp (entry->key, BG_PREFERENCES_PICTURE_OPACITY)) { + else if (!strcmp (entry->key, "/desktop/gnome/background/opacity")) { prefs->opacity = gconf_value_get_int (value); if (prefs->opacity >= 100) prefs->adjust_opacity = FALSE; } - else if (!strcmp (entry->key, BG_PREFERENCES_COLOR_SHADING_TYPE)) { - prefs->orientation = read_orientation_from_string (g_strdup (gconf_value_get_string (value))); + else if (!strcmp (entry->key, "/desktop/gnome/background/orientation")) { + prefs->orientation = gconf_value_get_int (value); if (prefs->orientation == ORIENTATION_SOLID) prefs->gradient_enabled = FALSE; else prefs->gradient_enabled = TRUE; } - else if (!strcmp (entry->key, BG_PREFERENCES_DRAW_BACKGROUND)) { + else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-enabled")) { if (gconf_value_get_bool (value) && (prefs->wallpaper_filename != NULL) && strcmp (prefs->wallpaper_filename, "") != 0 && @@ -263,51 +246,14 @@ bg_preferences_merge_entry (BGPreferences *prefs, prefs->wallpaper_enabled = TRUE; else prefs->wallpaper_enabled = FALSE; + } + else if (!strcmp (entry->key, "/desktop/gnome/background/wallpaper-type")) { + prefs->wallpaper_type = gconf_value_get_int (value); } else { - g_warning ("%s: Unknown property: %s", __FUNCTION__, entry->key); + g_warning ("%s: Unknown property: %s", G_GNUC_FUNCTION, entry->key); } } -static wallpaper_type_t -read_wptype_from_string (gchar *string) -{ - wallpaper_type_t type = -1; - - if (string) { - if (!strncmp (string, "wallpaper", sizeof ("wallpaper"))) { - type = WPTYPE_TILED; - } else if (!strncmp (string, "centered", sizeof ("centered"))) { - type = WPTYPE_CENTERED; - } else if (!strncmp (string, "scaled", sizeof ("scaled"))) { - type = WPTYPE_SCALED; - } else if (!strncmp (string, "stretched", sizeof ("stretched"))) { - type = WPTYPE_STRETCHED; - } else if (!strncmp (string, "embossed", sizeof ("embossed"))) { - type = WPTYPE_EMBOSSED; - } - g_free (string); - } - - return type; -} - -static orientation_t -read_orientation_from_string (gchar *string) -{ - orientation_t type = ORIENTATION_SOLID; - - if (string) { - if (!strncmp (string, "vertical-gradient", sizeof ("vertical-gradient"))) { - type = ORIENTATION_VERT; - } else if (!strncmp (string, "horizontal-gradient", sizeof ("horizontal-gradient"))) { - type = ORIENTATION_HORIZ; - } - g_free (string); - } - - return type; -} - static GdkColor * read_color_from_string (const gchar *string) { @@ -321,10 +267,7 @@ read_color_from_string (const gchar *string) rgb = ((color->red >> 8) << 16) || ((color->green >> 8) << 8) || (color->blue >> 8); -#if 0 - /* fixme: I am not sure, but this can be accomplished otherwise */ color->pixel = gdk_rgb_xpixel_from_rgb (rgb); -#endif } return color; diff --git a/libbackground/preferences.h b/libbackground/preferences.h index 00b6a55d4..dcb73df80 100644 --- a/libbackground/preferences.h +++ b/libbackground/preferences.h @@ -32,26 +32,15 @@ #define BG_PREFERENCES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, bg_preferences_get_type (), BGPreferencesClass) #define IS_BG_PREFERENCES(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, bg_preferences_get_type ()) -#define BG_PREFERENCES_DRAW_BACKGROUND "/desktop/gnome/background/draw_background" -#define BG_PREFERENCES_PRIMARY_COLOR "/desktop/gnome/background/primary_color" -#define BG_PREFERENCES_SECONDARY_COLOR "/desktop/gnome/background/secondary_color" -#define BG_PREFERENCES_COLOR_SHADING_TYPE "/desktop/gnome/background/color_shading_type" -#define BG_PREFERENCES_PICTURE_OPTIONS "/desktop/gnome/background/picture_options" -#define BG_PREFERENCES_PICTURE_OPACITY "/desktop/gnome/background/picture_opacity" -#define BG_PREFERENCES_PICTURE_FILENAME "/desktop/gnome/background/picture_filename" - - typedef struct _BGPreferences BGPreferences; typedef struct _BGPreferencesClass BGPreferencesClass; typedef enum _orientation_t { - ORIENTATION_SOLID = 0, - ORIENTATION_HORIZ, - ORIENTATION_VERT + ORIENTATION_SOLID, ORIENTATION_HORIZ, ORIENTATION_VERT } orientation_t; typedef enum _wallpaper_type_t { - WPTYPE_TILED = 0, WPTYPE_CENTERED, WPTYPE_SCALED, + WPTYPE_TILED, WPTYPE_CENTERED, WPTYPE_SCALED, WPTYPE_STRETCHED, WPTYPE_EMBOSSED } wallpaper_type_t;