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
This commit is contained in:
parent
d6b98e4435
commit
e7928dbfa4
4 changed files with 124 additions and 85 deletions
|
@ -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>
|
2004-02-24 Rodney Dawes <dobey@ximian.com>
|
||||||
|
|
||||||
* gnome-wp-info.c (gnome_wp_info_new):
|
* gnome-wp-info.c (gnome_wp_info_new):
|
||||||
|
|
|
@ -74,15 +74,69 @@ static void wp_properties_help (GtkWindow * parent, char const * helpfile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gnome_wp_file_open_cancel (GtkWidget * widget, gpointer data) {
|
static void gnome_wp_add_image (GnomeWPCapplet * capplet,
|
||||||
gtk_widget_hide (gtk_widget_get_toplevel (widget));
|
const gchar * filename) {
|
||||||
|
GnomeWPItem * item;
|
||||||
|
GdkColor color1, color2;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
item = g_new0 (GnomeWPItem, 1);
|
||||||
|
|
||||||
|
item->filename = g_strdup (filename);
|
||||||
|
|
||||||
|
item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gnome_wp_file_open_get_files (GtkWidget * widget,
|
static void gnome_wp_add_images (GnomeWPCapplet * capplet,
|
||||||
GnomeWPCapplet * capplet) {
|
GSList * images,
|
||||||
GtkWidget * filesel;
|
gchar ** files) {
|
||||||
GdkColor color1, color2;
|
|
||||||
gchar ** files;
|
|
||||||
GdkCursor * cursor;
|
GdkCursor * cursor;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
|
@ -91,94 +145,41 @@ static void gnome_wp_file_open_get_files (GtkWidget * widget,
|
||||||
gdk_window_set_cursor (capplet->window->window, cursor);
|
gdk_window_set_cursor (capplet->window->window, cursor);
|
||||||
gdk_cursor_unref (cursor);
|
gdk_cursor_unref (cursor);
|
||||||
|
|
||||||
filesel = gtk_widget_get_toplevel (widget);
|
if (images != NULL) {
|
||||||
|
for (; images != NULL; images = images->next) {
|
||||||
files = gtk_file_selection_get_selections (GTK_FILE_SELECTION (filesel));
|
gnome_wp_add_image (capplet, images->data);
|
||||||
|
}
|
||||||
for (i = 0; files && files[i]; i++) {
|
} else {
|
||||||
GnomeWPItem * item;
|
for (i = 0; files && files[i]; i++) {
|
||||||
|
gnome_wp_add_image (capplet, files[i]);
|
||||||
item = g_hash_table_lookup (capplet->wphash, files[i]);
|
|
||||||
if (item != NULL) {
|
|
||||||
GtkTreePath * path;
|
|
||||||
|
|
||||||
if (item->deleted) {
|
|
||||||
item->deleted = FALSE;
|
|
||||||
wp_props_load_wallpaper (item->filename, item, capplet);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
item = g_new0 (GnomeWPItem, 1);
|
|
||||||
|
|
||||||
item->filename = g_strdup (files[i]);
|
|
||||||
|
|
||||||
item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g_strfreev (files);
|
|
||||||
gtk_widget_hide (filesel);
|
|
||||||
|
|
||||||
gdk_window_set_cursor (capplet->window->window, NULL);
|
gdk_window_set_cursor (capplet->window->window, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gnome_wp_file_open_dialog (GtkWidget * widget,
|
static void gnome_wp_file_open_dialog (GtkWidget * widget,
|
||||||
GnomeWPCapplet * capplet) {
|
GnomeWPCapplet * capplet) {
|
||||||
static GtkWidget * filesel = NULL;
|
#if GTK_CHECK_VERSION (2, 3, 0)
|
||||||
|
GSList * files;
|
||||||
|
#else
|
||||||
|
gchar ** files;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (filesel != NULL) {
|
switch (gtk_dialog_run (GTK_DIALOG (capplet->filesel))) {
|
||||||
gtk_widget_show (filesel);
|
case GTK_RESPONSE_OK:
|
||||||
return;
|
#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,
|
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),
|
g_hash_table_insert (capplet->wphash, g_strdup (item->filename),
|
||||||
item);
|
item);
|
||||||
wp_props_load_wallpaper (item->filename, item, capplet);
|
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,
|
gconf_client_set_string (capplet->client, WP_FILE_KEY,
|
||||||
item->filename, NULL);
|
item->filename, NULL);
|
||||||
|
@ -1422,6 +1426,24 @@ static void wallpaper_properties_init (void) {
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview));
|
||||||
g_signal_connect (G_OBJECT (selection), "changed",
|
g_signal_connect (G_OBJECT (selection), "changed",
|
||||||
G_CALLBACK (gnome_wp_props_wp_selected), capplet);
|
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[]) {
|
gint main (gint argc, gchar *argv[]) {
|
||||||
|
|
|
@ -81,6 +81,9 @@ struct _GnomeWPCapplet {
|
||||||
|
|
||||||
/* The Timeout ID for Setting the Wallpaper */
|
/* The Timeout ID for Setting the Wallpaper */
|
||||||
gint idleid;
|
gint idleid;
|
||||||
|
|
||||||
|
/* File Chooser Dialog */
|
||||||
|
GtkWidget * filesel;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "gnome-wp-item.h"
|
#include "gnome-wp-item.h"
|
||||||
#include "gnome-wp-utils.h"
|
#include "gnome-wp-utils.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
|
||||||
|
|
||||||
void gnome_wp_item_free (GnomeWPItem * item) {
|
void gnome_wp_item_free (GnomeWPItem * item) {
|
||||||
if (item == NULL) {
|
if (item == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue