summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRodney Dawes <dobey@ximian.com>2004-03-01 04:09:06 +0000
committerRodney Dawes <dobey@src.gnome.org>2004-03-01 04:09:06 +0000
commite7928dbfa41221d3cc2746161a6a712d2e478eea (patch)
tree73eb039d1574e43bf0635ae172d0bdbac3f23028
parentd6b98e44354767947ea6f3bfb1ccdd3f1f204ba2 (diff)
downloadgnome-control-center-e7928dbfa41221d3cc2746161a6a712d2e478eea.tar.gz
Split out real image adding code into a separate call
2004-02-29 Rodney Dawes <dobey@ximian.com> * gnome-wp-capplet.c (gnome_wp_add_image): Split out real image adding code into a separate call (gnome_wp_add_images): (gnome_wp_file_open_dialog): (gnome_wp_properties_init): Add support for GtkFileChooser (#135317) (bg_properties_dragged_image): Fix re-addition of deleted images * gnome-wp-capplet.h: Store the filesel widget in GnomeWPCapplet * gnome-wp-item.c: Fix warning about gnome_vfs_mime_get_description Fixes #135317
-rw-r--r--capplets/background/ChangeLog13
-rw-r--r--capplets/background/gnome-wp-capplet.c186
-rw-r--r--capplets/background/gnome-wp-capplet.h3
-rw-r--r--capplets/background/gnome-wp-item.c1
4 files changed, 121 insertions, 82 deletions
diff --git a/capplets/background/ChangeLog b/capplets/background/ChangeLog
index 08a5043f9..ee00e1d67 100644
--- a/capplets/background/ChangeLog
+++ b/capplets/background/ChangeLog
@@ -1,3 +1,16 @@
+2004-02-29 Rodney Dawes <dobey@ximian.com>
+
+ * gnome-wp-capplet.c (gnome_wp_add_image): Split out real image adding
+ code into a separate call
+ (gnome_wp_add_images):
+ (gnome_wp_file_open_dialog):
+ (gnome_wp_properties_init): Add support for GtkFileChooser (#135317)
+ (bg_properties_dragged_image): Fix re-addition of deleted images
+ * gnome-wp-capplet.h: Store the filesel widget in GnomeWPCapplet
+ * gnome-wp-item.c: Fix warning about gnome_vfs_mime_get_description
+
+ Fixes #135317
+
2004-02-24 Rodney Dawes <dobey@ximian.com>
* gnome-wp-info.c (gnome_wp_info_new):
diff --git a/capplets/background/gnome-wp-capplet.c b/capplets/background/gnome-wp-capplet.c
index c76def5ae..cb7b8620b 100644
--- a/capplets/background/gnome-wp-capplet.c
+++ b/capplets/background/gnome-wp-capplet.c
@@ -74,111 +74,112 @@ static void wp_properties_help (GtkWindow * parent, char const * helpfile,
}
}
-static void gnome_wp_file_open_cancel (GtkWidget * widget, gpointer data) {
- gtk_widget_hide (gtk_widget_get_toplevel (widget));
-}
-
-static void gnome_wp_file_open_get_files (GtkWidget * widget,
- GnomeWPCapplet * capplet) {
- GtkWidget * filesel;
+static void gnome_wp_add_image (GnomeWPCapplet * capplet,
+ const gchar * filename) {
+ GnomeWPItem * item;
GdkColor color1, color2;
- gchar ** files;
- GdkCursor * cursor;
- gint i;
- cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
- GDK_WATCH);
- gdk_window_set_cursor (capplet->window->window, cursor);
- gdk_cursor_unref (cursor);
+ item = g_hash_table_lookup (capplet->wphash, filename);
+ if (item != NULL) {
+ GtkTreePath * path;
+
+ if (item->deleted) {
+ item->deleted = FALSE;
+ wp_props_load_wallpaper (item->filename, item, capplet);
+ }
- filesel = gtk_widget_get_toplevel (widget);
+ path = gtk_tree_row_reference_get_path (item->rowref);
+ gtk_tree_view_set_cursor (GTK_TREE_VIEW (capplet->treeview), path,
+ NULL, FALSE);
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (capplet->treeview),
+ path, NULL, TRUE, 0.5, 0.0);
+ gtk_tree_path_free (path);
- files = gtk_file_selection_get_selections (GTK_FILE_SELECTION (filesel));
+ return;
+ }
- for (i = 0; files && files[i]; i++) {
- GnomeWPItem * item;
+ item = g_new0 (GnomeWPItem, 1);
+
+ item->filename = g_strdup (filename);
- item = g_hash_table_lookup (capplet->wphash, files[i]);
- if (item != NULL) {
- GtkTreePath * path;
+ item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs);
- if (item->deleted) {
- item->deleted = FALSE;
- wp_props_load_wallpaper (item->filename, item, capplet);
- }
+ item->shade_type = gconf_client_get_string (capplet->client,
+ WP_SHADING_KEY, NULL);
+ item->pri_color = gconf_client_get_string (capplet->client,
+ WP_PCOLOR_KEY, NULL);
+ item->sec_color = gconf_client_get_string (capplet->client,
+ WP_SCOLOR_KEY, NULL);
- path = gtk_tree_row_reference_get_path (item->rowref);
- gtk_tree_view_set_cursor (GTK_TREE_VIEW (capplet->treeview), path,
- NULL, FALSE);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (capplet->treeview),
- path, NULL, TRUE, 0.5, 0.0);
- gtk_tree_path_free (path);
+ 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);
- continue;
+ if (!strncmp (item->fileinfo->mime_type, "image/", strlen ("image/"))) {
+ if (item->name == NULL) {
+ item->name = g_strdup (item->fileinfo->name);
}
+ item->options = gconf_client_get_string (capplet->client,
+ WP_OPTIONS_KEY,
+ NULL);
- item = g_new0 (GnomeWPItem, 1);
-
- item->filename = g_strdup (files[i]);
+ gnome_wp_item_update_description (item);
+
+ g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item);
+ wp_props_load_wallpaper (item->filename, item, capplet);
+ } else {
+ gnome_wp_item_free (item);
+ }
+}
- item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs);
+static void gnome_wp_add_images (GnomeWPCapplet * capplet,
+ GSList * images,
+ gchar ** files) {
+ GdkCursor * cursor;
+ gint i;
- item->shade_type = gconf_client_get_string (capplet->client,
- WP_SHADING_KEY, NULL);
- item->pri_color = gconf_client_get_string (capplet->client,
- WP_PCOLOR_KEY, NULL);
- item->sec_color = gconf_client_get_string (capplet->client,
- WP_SCOLOR_KEY, NULL);
+ cursor = gdk_cursor_new_for_display (gdk_display_get_default (),
+ GDK_WATCH);
+ gdk_window_set_cursor (capplet->window->window, cursor);
+ gdk_cursor_unref (cursor);
- 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);
-
- if (!strncmp (item->fileinfo->mime_type, "image/", strlen ("image/"))) {
- if (item->name == NULL) {
- item->name = g_strdup (item->fileinfo->name);
- }
- item->options = gconf_client_get_string (capplet->client,
- WP_OPTIONS_KEY,
- NULL);
-
- gnome_wp_item_update_description (item);
-
- g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item);
- wp_props_load_wallpaper (item->filename, item, capplet);
- } else {
- gnome_wp_item_free (item);
- }
+ if (images != NULL) {
+ for (; images != NULL; images = images->next) {
+ gnome_wp_add_image (capplet, images->data);
+ }
+ } else {
+ for (i = 0; files && files[i]; i++) {
+ gnome_wp_add_image (capplet, files[i]);
+ }
}
- g_strfreev (files);
- gtk_widget_hide (filesel);
-
gdk_window_set_cursor (capplet->window->window, NULL);
}
static void gnome_wp_file_open_dialog (GtkWidget * widget,
GnomeWPCapplet * capplet) {
- static GtkWidget * filesel = NULL;
+#if GTK_CHECK_VERSION (2, 3, 0)
+ GSList * files;
+#else
+ gchar ** files;
+#endif
- if (filesel != NULL) {
- gtk_widget_show (filesel);
- return;
+ switch (gtk_dialog_run (GTK_DIALOG (capplet->filesel))) {
+ case GTK_RESPONSE_OK:
+#if GTK_CHECK_VERSION (2, 3, 0)
+ files = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (capplet->filesel));
+ gnome_wp_add_images (capplet, files, NULL);
+#else
+ files = gtk_file_selection_get_selections (GTK_FILE_SELECTION (capplet->filesel));
+ gnome_wp_add_images (capplet, NULL, files);
+#endif
+ case GTK_RESPONSE_CANCEL:
+ default:
+ gtk_widget_hide (capplet->filesel);
+ break;
}
-
- filesel = gtk_file_selection_new (_("Add Wallpapers"));
- gtk_file_selection_set_select_multiple (GTK_FILE_SELECTION (filesel), TRUE);
-
- g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->ok_button),
- "clicked",
- G_CALLBACK (gnome_wp_file_open_get_files), capplet);
- g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filesel)->cancel_button),
- "clicked",
- G_CALLBACK (gnome_wp_file_open_cancel), capplet);
-
- gtk_widget_show (filesel);
}
static void bg_add_multiple_files (GnomeVFSURI * uri,
@@ -270,6 +271,9 @@ static void bg_properties_dragged_image (GtkWidget * widget,
g_hash_table_insert (capplet->wphash, g_strdup (item->filename),
item);
wp_props_load_wallpaper (item->filename, item, capplet);
+ } else if (item->deleted) {
+ item->deleted = FALSE;
+ wp_props_load_wallpaper (item->filename, item, capplet);
}
gconf_client_set_string (capplet->client, WP_FILE_KEY,
item->filename, NULL);
@@ -1422,6 +1426,24 @@ static void wallpaper_properties_init (void) {
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview));
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnome_wp_props_wp_selected), capplet);
+
+ /* Create the file chooser dialog stuff here */
+#if GTK_CHECK_VERSION (2, 3, 0)
+ capplet->filesel = gtk_file_chooser_dialog_new (_("Add Wallpapers"),
+ GTK_WINDOW (capplet->window),
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL,
+ GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN,
+ GTK_RESPONSE_OK,
+ NULL);
+ gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (capplet->filesel),
+ TRUE);
+#else
+ capplet->filesel = gtk_file_selection_new (_("Add Wallpapers"));
+ gtk_file_selection_set_select_multiple (GTK_FILE_SELECTION (capplet->filesel),
+ TRUE);
+#endif
}
gint main (gint argc, gchar *argv[]) {
diff --git a/capplets/background/gnome-wp-capplet.h b/capplets/background/gnome-wp-capplet.h
index ab1ab0857..024b10e93 100644
--- a/capplets/background/gnome-wp-capplet.h
+++ b/capplets/background/gnome-wp-capplet.h
@@ -81,6 +81,9 @@ struct _GnomeWPCapplet {
/* The Timeout ID for Setting the Wallpaper */
gint idleid;
+
+ /* File Chooser Dialog */
+ GtkWidget * filesel;
};
typedef enum {
diff --git a/capplets/background/gnome-wp-item.c b/capplets/background/gnome-wp-item.c
index 2f5199849..b49ab9b13 100644
--- a/capplets/background/gnome-wp-item.c
+++ b/capplets/background/gnome-wp-item.c
@@ -21,6 +21,7 @@
#include "gnome-wp-item.h"
#include "gnome-wp-utils.h"
#include <string.h>
+#include <libgnomevfs/gnome-vfs-mime-handlers.h>
void gnome_wp_item_free (GnomeWPItem * item) {
if (item == NULL) {