From f69be2bd96f7615e298dea845075e8c88df52d73 Mon Sep 17 00:00:00 2001 From: Rodney Dawes Date: Fri, 27 Jan 2006 03:01:58 +0000 Subject: [PATCH] Add an Apply button 2006-01-26 Rodney Dawes * gnome-background-properties.glade: Add an Apply button * gnome-wp-capplet.[ch]: Replace old_filename with an old_item struct (gnome_wp_props_wp_set): Set the filename key to empty string when setting the background to "No Wallpaper" (gnome_wp_props_revert): New method to revert changes in the dialog when the Cancel button is clicked (gnome_wp_main_quit): Free the old_item structure (wallpaper_properties_clicked): Handle the Apply button Handle closing the dialog for OK separately from Cancel/delete_event Revert the settings when Cancel or wm "x" or ESC are clicked (gnome_wp_load_stuffs): Set the old_item to the currently selected background setting, whether it be an image or "No Wallpaper" * gnome-wp-info.c (gnome_wp_info_dup): If info is NULL, just return NULL rather than trying to access members of an empty struct * gnome-wp-item.[ch] (gnome_wp_item_dup): New method to create a duplicate and newly allocated GnomeWPItem structure Fixes #327335 --- capplets/background/ChangeLog | 24 +++++++ .../gnome-background-properties.glade | 15 ++++- capplets/background/gnome-wp-capplet.c | 63 ++++++++++++++++++- capplets/background/gnome-wp-capplet.h | 7 +-- capplets/background/gnome-wp-info.c | 4 ++ capplets/background/gnome-wp-item.c | 38 +++++++++++ capplets/background/gnome-wp-item.h | 1 + 7 files changed, 144 insertions(+), 8 deletions(-) diff --git a/capplets/background/ChangeLog b/capplets/background/ChangeLog index 5282dcd73..14b3960f9 100644 --- a/capplets/background/ChangeLog +++ b/capplets/background/ChangeLog @@ -1,3 +1,27 @@ +2006-01-26 Rodney Dawes + + * gnome-background-properties.glade: Add an Apply button + + * gnome-wp-capplet.[ch]: Replace old_filename with an old_item struct + (gnome_wp_props_wp_set): Set the filename key to empty string when + setting the background to "No Wallpaper" + (gnome_wp_props_revert): New method to revert changes in the dialog + when the Cancel button is clicked + (gnome_wp_main_quit): Free the old_item structure + (wallpaper_properties_clicked): Handle the Apply button + Handle closing the dialog for OK separately from Cancel/delete_event + Revert the settings when Cancel or wm "x" or ESC are clicked + (gnome_wp_load_stuffs): Set the old_item to the currently selected + background setting, whether it be an image or "No Wallpaper" + + * gnome-wp-info.c (gnome_wp_info_dup): If info is NULL, just return + NULL rather than trying to access members of an empty struct + + * gnome-wp-item.[ch] (gnome_wp_item_dup): New method to create a + duplicate and newly allocated GnomeWPItem structure + + Fixes #327335 + 2006-01-14 Rodney Dawes * gnome-background-properties.glade: Set the visibility of the second diff --git a/capplets/background/gnome-background-properties.glade b/capplets/background/gnome-background-properties.glade index e4806c022..fa5b7700e 100644 --- a/capplets/background/gnome-background-properties.glade +++ b/capplets/background/gnome-background-properties.glade @@ -49,6 +49,19 @@ + True + True + True + gtk-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + + + True True True @@ -61,7 +74,7 @@ - + True True True diff --git a/capplets/background/gnome-wp-capplet.c b/capplets/background/gnome-wp-capplet.c index 0b4f03db9..3f600368c 100644 --- a/capplets/background/gnome-wp-capplet.c +++ b/capplets/background/gnome-wp-capplet.c @@ -284,11 +284,12 @@ static gboolean gnome_wp_props_wp_set (GnomeWPCapplet * capplet) { item = g_hash_table_lookup (capplet->wphash, wpfile); - if (g_utf8_collate (capplet->old_filename, wpfile) != 0) { + if (g_utf8_collate (capplet->old_item->filename, wpfile) != 0) { cs = gconf_change_set_new (); if (!strcmp (item->filename, "(none)")) { gconf_change_set_set_string (cs, WP_OPTIONS_KEY, "none"); + gconf_change_set_set_string (cs, WP_FILE_KEY, ""); } else { gchar * uri; @@ -319,6 +320,45 @@ static gboolean gnome_wp_props_wp_set (GnomeWPCapplet * capplet) { return retval; } +static gboolean gnome_wp_props_revert (GnomeWPCapplet * capplet) { + GnomeWPItem * item; + GConfChangeSet * cs; + gboolean retval = FALSE; + + item = capplet->old_item; + + cs = gconf_change_set_new (); + + if (!strcmp (item->filename, "(none)")) { + gconf_change_set_set_string (cs, WP_OPTIONS_KEY, "none"); + } else { + gchar * uri; + + if (g_utf8_validate (item->filename, -1, NULL)) + uri = g_strdup (item->filename); + else + uri = g_filename_to_utf8 (item->filename, -1, NULL, NULL, NULL); + + gconf_change_set_set_string (cs, WP_FILE_KEY, uri); + g_free (uri); + + gconf_change_set_set_string (cs, WP_OPTIONS_KEY, item->options); + } + + gconf_change_set_set_string (cs, WP_SHADING_KEY, item->shade_type); + + gconf_change_set_set_string (cs, WP_PCOLOR_KEY, item->pri_color); + gconf_change_set_set_string (cs, WP_SCOLOR_KEY, item->sec_color); + + gconf_client_commit_change_set (capplet->client, cs, TRUE, NULL); + + gconf_change_set_unref (cs); + + retval = TRUE; + + return retval; +} + static void gnome_wp_props_wp_selected (GtkTreeSelection * selection, GnomeWPCapplet * capplet) { GtkTreeIter iter; @@ -366,7 +406,7 @@ static void gnome_wp_remove_wp (gchar * key, GnomeWPItem * item, } void gnome_wp_main_quit (GnomeWPCapplet * capplet) { - g_free (capplet->old_filename); + gnome_wp_item_free (capplet->old_item); g_hash_table_foreach (capplet->wphash, (GHFunc) gnome_wp_remove_wp, capplet); @@ -387,6 +427,9 @@ static void wallpaper_properties_clicked (GtkWidget * dialog, wp_properties_help (GTK_WINDOW (dialog), "user-guide.xml", "goscustdesk-7"); break; + case GTK_RESPONSE_APPLY: + gnome_wp_props_wp_set (capplet); + break; case GTK_RESPONSE_OK: if (gnome_wp_props_wp_set (capplet)) { /* @@ -396,8 +439,18 @@ static void wallpaper_properties_clicked (GtkWidget * dialog, */ usleep (1400000); } + gtk_widget_destroy (dialog); + gnome_wp_main_quit (capplet); + break; case GTK_RESPONSE_DELETE_EVENT: case GTK_RESPONSE_CANCEL: { + if (gnome_wp_props_revert (capplet)) { + /* + Reverting the preferences will also have the same slowness as + applying them and quitting, so we need a timeout here as well + */ + usleep (1400000); + } gtk_widget_destroy (dialog); gnome_wp_main_quit (capplet); break; @@ -595,11 +648,11 @@ static gboolean gnome_wp_load_stuffs (void * data) { else imagepath = g_filename_from_utf8 (uri, -1, NULL, NULL, NULL); - capplet->old_filename = g_strdup (uri); g_free (uri); item = g_hash_table_lookup (capplet->wphash, imagepath); if (item != NULL && strcmp (style, "none") != 0) { + capplet->old_item = gnome_wp_item_dup (item); if (item->deleted == TRUE) { item->deleted = FALSE; wp_props_load_wallpaper (item->filename, item, capplet); @@ -632,6 +685,10 @@ static gboolean gnome_wp_load_stuffs (void * data) { if (!strcmp (style, "none")) { gnome_wp_capplet_scroll_to_item (capplet, item); + if (capplet->old_item) + gnome_wp_item_free (capplet->old_item); + + capplet->old_item = gnome_wp_item_dup (item); } } g_free (imagepath); diff --git a/capplets/background/gnome-wp-capplet.h b/capplets/background/gnome-wp-capplet.h index 8c31fa942..f2ef256d2 100644 --- a/capplets/background/gnome-wp-capplet.h +++ b/capplets/background/gnome-wp-capplet.h @@ -73,11 +73,10 @@ struct _GnomeWPCapplet { GtkWidget * image; /* - This is here to compare against when OK is pressed so that we can avoid - the 1.4 second timeout for Nautilus to actually give visual feedback, - when the filename didn't change + The GnomeWPItem of the wallpaper we were + already set to on startup */ - gchar * old_filename; + GnomeWPItem * old_item; }; typedef enum { diff --git a/capplets/background/gnome-wp-info.c b/capplets/background/gnome-wp-info.c index ec1fbffbd..8e5b899b6 100644 --- a/capplets/background/gnome-wp-info.c +++ b/capplets/background/gnome-wp-info.c @@ -96,6 +96,10 @@ GnomeWPInfo * gnome_wp_info_new (const gchar * uri, GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info) { GnomeWPInfo * new; + if (info == NULL) { + return NULL; + } + new = g_new0 (GnomeWPInfo, 1); new->uri = g_strdup (info->uri); diff --git a/capplets/background/gnome-wp-item.c b/capplets/background/gnome-wp-item.c index 21c59126e..e98b7ba59 100644 --- a/capplets/background/gnome-wp-item.c +++ b/capplets/background/gnome-wp-item.c @@ -109,6 +109,44 @@ void gnome_wp_item_free (GnomeWPItem * item) { item = NULL; } +GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item) { + GnomeWPItem * new_item; + GdkColor color1, color2; + + if (item == NULL) { + return NULL; + } + + new_item = g_new0 (GnomeWPItem, 1); + + new_item->name = g_strdup (item->name); + new_item->filename = g_strdup (item->filename); + new_item->description = g_strdup (item->description); + new_item->imguri = g_strdup (item->imguri); + new_item->options = g_strdup (item->options); + new_item->shade_type = g_strdup (item->shade_type); + + new_item->pri_color = g_strdup (item->pri_color); + new_item->sec_color = g_strdup (item->sec_color); + + gdk_color_parse (item->pri_color, &color1); + gdk_color_parse (item->sec_color, &color2); + + item->pcolor = gdk_color_copy (&color1); + item->scolor = gdk_color_copy (&color2); + + new_item->fileinfo = gnome_wp_info_dup (item->fileinfo); + new_item->uriinfo = gnome_wp_info_dup (item->uriinfo); + + new_item->rowref = gtk_tree_row_reference_copy (item->rowref); + + new_item->deleted = item->deleted; + new_item->width = item->width; + new_item->height = item->height; + + return new_item; +} + static void collect_save_options (GdkPixbuf * pixbuf, gchar *** keys, gchar *** vals, diff --git a/capplets/background/gnome-wp-item.h b/capplets/background/gnome-wp-item.h index abdc497d4..729e935c2 100644 --- a/capplets/background/gnome-wp-item.h +++ b/capplets/background/gnome-wp-item.h @@ -62,6 +62,7 @@ GnomeWPItem * gnome_wp_item_new (const gchar * filename, GHashTable * wallpapers, GnomeThumbnailFactory * thumbnails); void gnome_wp_item_free (GnomeWPItem * item); +GnomeWPItem * gnome_wp_item_dup (GnomeWPItem * item); GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item, GnomeThumbnailFactory * thumbs); void gnome_wp_item_update_description (GnomeWPItem * item);