diff --git a/capplets/background/.cvsignore b/capplets/background/.cvsignore index 83cdca814..2c4b4b066 100644 --- a/capplets/background/.cvsignore +++ b/capplets/background/.cvsignore @@ -8,4 +8,7 @@ Makefile.in background.desktop background.desktop.in gnome-background-properties +gnome-wallpaper-properties *.oaf +*.server + diff --git a/capplets/background/ChangeLog b/capplets/background/ChangeLog index a6b5a891e..ba96b8bd2 100644 --- a/capplets/background/ChangeLog +++ b/capplets/background/ChangeLog @@ -1,3 +1,13 @@ +2004-01-12 Rodney Dawes + + * Makefile.am: Update for new capplet + * background.desktop.in: Update Name/Comment/Exec entries + * gnome-wp-capplet.[ch]: + * gnome-wp-info.[ch]: + * gnome-wp-item.[ch]: + * gnome-wp-utils.[ch]: + * gnome-wp-xml.[ch]: Add new capplet code to CVS + 2003-12-30 Jody Goldberg * Release 2.5.1.1 diff --git a/capplets/background/Makefile.am b/capplets/background/Makefile.am index 5e4967598..dbd3c8113 100644 --- a/capplets/background/Makefile.am +++ b/capplets/background/Makefile.am @@ -1,18 +1,40 @@ -bin_PROGRAMS = gnome-background-properties +INCLUDES = \ + $(CAPPLET_CFLAGS) \ + -DDATADIR=\""$(datadir)"\" \ + -DGNOMELOCALEDIR=\""$(localedir)"\" -gnome_background_properties_LDADD = $(GNOMECC_CAPPLETS_LIBS) $(top_builddir)/libbackground/libbackground.la -gnome_background_properties_SOURCES = background-properties-capplet.c +bin_PROGRAMS = gnome-wallpaper-properties + +noinst_LTLIBRARIES = libgnomewp.la + +gnome_wallpaper_properties_LDADD = \ + $(CAPPLET_LIBS) \ + libgnomewp.la + +gnome_wallpaper_properties_SOURCES = \ + gnome-wp-capplet.c gnome-wp-capplet.h \ + gnome-wp-info.c gnome-wp-info.h + +libgnomewp_la_SOURCES = \ + gnome-wp-item.c gnome-wp-item.h \ + gnome-wp-utils.c gnome-wp-utils.h \ + gnome-wp-xml.c gnome-wp-xml.h + +libgnomewp_la_LIBADD = \ + $(CAPPLET_LIBS) + +desktopdir = $(GNOMECC_DESKTOP_DIR) +desktop_in_files = background.desktop.in +desktop_DATA = $(desktop_in_files:.desktop.in=.desktop) @INTLTOOL_DESKTOP_RULE@ -Gladedir = $(GNOMECC_GLADE_DIR) -Glade_DATA = background-properties.glade +EXTRA_DIST = \ + $(desktop_in_files) -desktopdir = $(GNOMECC_DESKTOP_DIR) -Desktop_in_files = background.desktop.in -desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop) +CLEANFILES = \ + $(desktop_DATA) -INCLUDES = $(GNOMECC_CAPPLETS_CFLAGS) -I$(top_srcdir)/libbackground -CLEANFILES = $(GNOMECC_CAPPLETS_CLEANFILES) -EXTRA_DIST = $(Glade_DATA) $(Desktop_in_files) +MAINTAINERCLEANFILES = \ + Makefile.in diff --git a/capplets/background/background.desktop.in b/capplets/background/background.desktop.in index ecd661e1d..743f11434 100644 --- a/capplets/background/background.desktop.in +++ b/capplets/background/background.desktop.in @@ -1,8 +1,8 @@ [Desktop Entry] Encoding=UTF-8 -_Name=Background -_Comment=Customize your desktop background -Exec=gnome-background-properties +_Name=Desktop Wallpaper +_Comment=Desktop Wallpaper Preferences +Exec=gnome-wallpaper-properties Icon=gnome-settings-background Terminal=false Type=Application diff --git a/capplets/background/gnome-wp-capplet.c b/capplets/background/gnome-wp-capplet.c new file mode 100644 index 000000000..ebe030932 --- /dev/null +++ b/capplets/background/gnome-wp-capplet.c @@ -0,0 +1,1555 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include "gnome-wp-capplet.h" + +enum { + TARGET_URI_LIST, + TARGET_URL, + TARGET_COLOR, + TARGET_BGIMAGE, + TARGET_BACKGROUND_RESET +}; + +static GtkTargetEntry drop_types[] = { + {"text/uri-list", 0, TARGET_URI_LIST}, + /* { "application/x-color", 0, TARGET_COLOR }, */ + { "property/bgimage", 0, TARGET_BGIMAGE }, + /* { "x-special/gnome-reset-background", 0, TARGET_BACKGROUND_RESET }*/ +}; + +static void wp_props_load_wallpaper (gchar * key, + GnomeWPItem * item, + GnomeWPCapplet * capplet); + +static void wp_properties_error_dialog (GtkWindow * parent, char const * msg, + GError * err) { + if (err != NULL) { + GtkWidget *dialog; + + dialog = gtk_message_dialog_new (GTK_WINDOW (parent), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_CLOSE, + msg, err->message); + + g_signal_connect (G_OBJECT (dialog), + "response", + G_CALLBACK (gtk_widget_destroy), NULL); + gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE); + gtk_widget_show (dialog); + g_error_free (err); + } +} + +static void wp_properties_help (GtkWindow * parent, char const * helpfile, + char const * section) { + GError *error = NULL; + + g_return_if_fail (helpfile != NULL); + g_return_if_fail (section != NULL); + + gnome_help_display_desktop (NULL, "user-guide", helpfile, section, &error); + if (error != NULL) { + wp_properties_error_dialog (parent, + _("There was an error displaying help: %s"), + error); + } +} + +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; + 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); + + filesel = gtk_widget_get_toplevel (widget); + + files = gtk_file_selection_get_selections (GTK_FILE_SELECTION (filesel)); + + for (i = 0; files && files[i]; i++) { + GnomeWPItem * item; + + item = g_hash_table_lookup (capplet->wphash, files[i]); + if (item != NULL) { + GtkTreePath * path; + + 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); + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + 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); +} + +static void gnome_wp_file_open_dialog (GtkWidget * widget, + GnomeWPCapplet * capplet) { + static GtkWidget * filesel = NULL; + + if (filesel != NULL) { + gtk_widget_show (filesel); + return; + } + + 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, + GnomeWPCapplet * capplet) { + GnomeWPItem * item; + GdkColor color1, color2; + + item = g_hash_table_lookup (capplet->wphash, gnome_vfs_uri_get_path (uri)); + if (item != NULL) { + return; + } + + item = g_new0 (GnomeWPItem, 1); + + item->filename = gnome_vfs_unescape_string_for_display (gnome_vfs_uri_get_path (uri)); + item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs); + item->name = g_strdup (item->fileinfo->name); + item->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, + NULL); + + 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); + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item); + wp_props_load_wallpaper (item->filename, item, capplet); +} + +static void bg_properties_dragged_image (GtkWidget * widget, + GdkDragContext * context, + gint x, gint y, + GtkSelectionData * selection_data, + guint info, guint time, + GnomeWPCapplet * capplet) { + + if (info == TARGET_URI_LIST || info == TARGET_BGIMAGE) { + GList * uris; + + uris = gnome_vfs_uri_list_parse ((gchar *) selection_data->data); + + if (uris != NULL && uris->data != NULL) { + if (g_list_length (uris) == 1) { + GnomeVFSURI * uri = (GnomeVFSURI *) uris->data; + GnomeWPItem * item; + GtkTreePath * path; + + item = g_hash_table_lookup (capplet->wphash, + gnome_vfs_uri_get_path (uri)); + + if (item == NULL) { + GdkColor color1, color2; + + item = g_new0 (GnomeWPItem, 1); + + item->filename = gnome_vfs_unescape_string_for_display (gnome_vfs_uri_get_path (uri)); + item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs); + item->name = g_strdup (item->fileinfo->name); + item->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, + NULL); + + 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); + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + g_hash_table_insert (capplet->wphash, g_strdup (item->filename), + item); + wp_props_load_wallpaper (item->filename, item, capplet); + } + gconf_client_set_string (capplet->client, WP_FILE_KEY, + item->filename, NULL); + gconf_client_set_string (capplet->client, WP_OPTIONS_KEY, + item->options, 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); + } else if (g_list_length (uris) > 1) { + GdkCursor * cursor; + + cursor = gdk_cursor_new_for_display (gdk_display_get_default (), + GDK_WATCH); + gdk_window_set_cursor (capplet->window->window, cursor); + gdk_cursor_unref (cursor); + + g_list_foreach (uris, (GFunc) bg_add_multiple_files, capplet); + + gdk_window_set_cursor (capplet->window->window, NULL); + } + } + gnome_vfs_uri_list_free (uris); + } +} + +static void wp_props_load_wallpaper (gchar * key, + GnomeWPItem * item, + GnomeWPCapplet * capplet) { + GtkTreeIter iter; + GtkTreePath * path; + GdkPixbuf * pixbuf; + + if (item->deleted == TRUE) { + return; + } + + gtk_list_store_append (GTK_LIST_STORE (capplet->model), &iter); + + pixbuf = gnome_wp_item_get_thumbnail (item, capplet->thumbs); + + if (pixbuf != NULL) { + gtk_list_store_set (GTK_LIST_STORE (capplet->model), &iter, + 0, pixbuf, + 1, item->description, + 2, item->filename, + -1); + g_object_unref (pixbuf); + } else { + gtk_list_store_set (GTK_LIST_STORE (capplet->model), &iter, + 1, item->description, + 2, item->filename, + -1); + } + path = gtk_tree_model_get_path (capplet->model, &iter); + item->rowref = gtk_tree_row_reference_new (capplet->model, path); + gtk_tree_path_free (path); +} + +static gint gnome_wp_option_menu_get (GtkOptionMenu * menu) { + GtkWidget * widget; + + g_return_val_if_fail (GTK_IS_OPTION_MENU (menu), -1); + + widget = gtk_menu_get_active (GTK_MENU (menu->menu)); + + if (widget != NULL) { + return g_list_index (GTK_MENU_SHELL (menu->menu)->children, widget); + } + + return -1; +} + +static void gnome_wp_option_menu_set (GnomeWPCapplet * capplet, + const gchar * value, + gboolean shade_type) { + if (shade_type) { + if (!strcmp (value, "horizontal-gradient")) { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->color_opt), + GNOME_WP_SHADE_TYPE_HORIZ); + gtk_widget_show (capplet->sc_picker); + } else if (!strcmp (value, "vertical-gradient")) { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->color_opt), + GNOME_WP_SHADE_TYPE_VERT); + gtk_widget_show (capplet->sc_picker); + } else { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->color_opt), + GNOME_WP_SHADE_TYPE_SOLID); + gtk_widget_hide (capplet->sc_picker); + } + } else { + if (!strcmp (value, "centered")) { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->wp_opts), + GNOME_WP_SCALE_TYPE_CENTERED); + } else if (!strcmp (value, "stretched")) { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->wp_opts), + GNOME_WP_SCALE_TYPE_STRETCHED); + } else if (!strcmp (value, "scaled")) { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->wp_opts), + GNOME_WP_SCALE_TYPE_SCALED); + } else { + gtk_option_menu_set_history (GTK_OPTION_MENU (capplet->wp_opts), + GNOME_WP_SCALE_TYPE_TILED); + } + } +} + +static gboolean gnome_wp_props_wp_set (GnomeWPCapplet * capplet) { + GtkTreeIter iter; + GtkTreeModel * model; + GtkTreeSelection * selection; + GnomeWPItem * item; + gchar * wpfile; + GdkPixbuf * pixbuf; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + if (!strcmp (item->filename, "(none)")) { + gconf_client_set_string (capplet->client, WP_OPTIONS_KEY, + "none", NULL); + gtk_widget_set_sensitive (capplet->wp_opts, FALSE); + gtk_widget_set_sensitive (capplet->rm_button, FALSE); + } else { + gtk_widget_set_sensitive (capplet->wp_opts, TRUE); + gtk_widget_set_sensitive (capplet->rm_button, TRUE); + gconf_client_set_string (capplet->client, WP_FILE_KEY, + item->filename, NULL); + gconf_client_set_string (capplet->client, WP_OPTIONS_KEY, + item->options, NULL); + gnome_wp_option_menu_set (capplet, item->options, FALSE); + } + + gconf_client_set_string (capplet->client, WP_SHADING_KEY, + item->shade_type, NULL); + gnome_wp_option_menu_set (capplet, item->shade_type, TRUE); + + gconf_client_set_string (capplet->client, WP_PCOLOR_KEY, + item->pri_color, NULL); + gconf_client_set_string (capplet->client, WP_SCOLOR_KEY, + item->sec_color, NULL); + + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->pc_picker), + item->pcolor->red, + item->pcolor->green, + item->pcolor->blue, 65535); + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->sc_picker), + item->scolor->red, + item->scolor->green, + item->scolor->blue, 65535); + + g_free (wpfile); + + pixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->smenuitem), pixbuf); + g_object_unref (pixbuf); + + pixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_HORIZONTAL, + item->pcolor, item->scolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->hmenuitem), pixbuf); + g_object_unref (pixbuf); + + pixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_VERTICAL, + item->pcolor, item->scolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->vmenuitem), pixbuf); + g_object_unref (pixbuf); + } else { + gtk_widget_set_sensitive (capplet->rm_button, FALSE); + } + + return FALSE; +} + +static void gnome_wp_props_wp_selected (GtkTreeSelection * selection, + GnomeWPCapplet * capplet) { + if (capplet->idleid > 0) { + g_source_remove (capplet->idleid); + } + capplet->idleid = g_timeout_add (capplet->delay + 100, + (GSourceFunc) gnome_wp_props_wp_set, + capplet); +} + +static void gnome_wp_remove_wp (gchar * key, GnomeWPItem * item, + GnomeWPCapplet * capplet) { + GtkTreePath * path; + GtkTreeIter iter; + + if (item->rowref != NULL && item->deleted == FALSE) { + path = gtk_tree_row_reference_get_path (item->rowref); + gtk_tree_model_get_iter (capplet->model, &iter, path); + gtk_tree_path_free (path); + + gtk_list_store_remove (GTK_LIST_STORE (capplet->model), &iter); + } +} + +void gnome_wp_main_quit (GnomeWPCapplet * capplet) { + g_hash_table_foreach (capplet->wphash, (GHFunc) gnome_wp_remove_wp, + capplet); + + gnome_wp_xml_save_list (capplet); + + g_object_unref (capplet->thumbs); + + g_hash_table_destroy (capplet->wphash); + + gtk_main_quit (); +} + +static void wallpaper_properties_clicked (GtkWidget * dialog, + gint response_id, + GnomeWPCapplet * capplet) { + switch (response_id) { + case GTK_RESPONSE_HELP: + wp_properties_help (GTK_WINDOW (dialog), + "wgoscustdesk.xml", "goscustdesk-7"); + break; + case GTK_RESPONSE_CLOSE: { + gtk_widget_destroy (dialog); + gnome_wp_main_quit (capplet); + break; + } + } +} + +static void gnome_wp_scale_type_changed (GtkMenuShell * shell, + GnomeWPCapplet * capplet) { + GnomeWPItem * item = NULL; + GtkTreeIter iter; + GtkTreeModel * model; + GtkTreeSelection * selection; + gchar * wpfile; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + g_free (wpfile); + } + + if (item == NULL) { + return; + } + switch (gnome_wp_option_menu_get (GTK_OPTION_MENU (capplet->wp_opts))) { + case GNOME_WP_SCALE_TYPE_CENTERED: + item->options = g_strdup ("centered"); + break; + case GNOME_WP_SCALE_TYPE_STRETCHED: + item->options = g_strdup ("stretched"); + break; + case GNOME_WP_SCALE_TYPE_SCALED: + item->options = g_strdup ("scaled"); + break; + case GNOME_WP_SCALE_TYPE_TILED: + item->options = g_strdup ("wallpaper"); + break; + default: + break; + } + gconf_client_set_string (capplet->client, WP_OPTIONS_KEY, + item->options, NULL); +} + +static void gnome_wp_shade_type_changed (GtkMenuShell * shell, + GnomeWPCapplet * capplet) { + GnomeWPItem * item = NULL; + GtkTreeIter iter; + GtkTreeModel * model; + GtkTreeSelection * selection; + gchar * wpfile; + GdkPixbuf * pixbuf; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + g_free (wpfile); + } + + if (item == NULL) { + return; + } + + switch (gnome_wp_option_menu_get (GTK_OPTION_MENU (capplet->color_opt))) { + case GNOME_WP_SHADE_TYPE_HORIZ: + item->shade_type = g_strdup ("horizontal-gradient"); + gtk_widget_show (capplet->sc_picker); + break; + case GNOME_WP_SHADE_TYPE_VERT: + item->shade_type = g_strdup ("vertical-gradient"); + gtk_widget_show (capplet->sc_picker); + break; + case GNOME_WP_SHADE_TYPE_SOLID: + item->shade_type = g_strdup ("solid"); + gtk_widget_hide (capplet->sc_picker); + break; + default: + break; + } + pixbuf = gnome_wp_item_get_thumbnail (item, capplet->thumbs); + gtk_list_store_set (GTK_LIST_STORE (capplet->model), &iter, + 0, pixbuf, + -1); + g_object_unref (pixbuf); + gconf_client_set_string (capplet->client, WP_SHADING_KEY, + item->shade_type, NULL); +} + +static void gnome_wp_color_changed (GnomeWPCapplet * capplet, + gboolean primary) { + GnomeWPItem * item = NULL; + GtkTreeIter iter; + GtkTreeModel * model; + GtkTreeSelection * selection; + gchar * wpfile; + GdkPixbuf * pixbuf; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + g_free (wpfile); + } + + if (item == NULL) { + return; + } + + if (primary) { + gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (capplet->pc_picker), + &item->pcolor->red, + &item->pcolor->green, + &item->pcolor->blue, NULL); + item->pri_color = g_strdup_printf ("#%02X%02X%02X", + item->pcolor->red >> 8, + item->pcolor->green >> 8, + item->pcolor->blue >> 8); + gconf_client_set_string (capplet->client, WP_PCOLOR_KEY, + item->pri_color, NULL); + } else { + gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (capplet->sc_picker), + &item->scolor->red, + &item->scolor->green, + &item->scolor->blue, NULL); + item->sec_color = g_strdup_printf ("#%02X%02X%02X", + item->scolor->red >> 8, + item->scolor->green >> 8, + item->scolor->blue >> 8); + gconf_client_set_string (capplet->client, WP_SCOLOR_KEY, + item->sec_color, NULL); + } + + gnome_wp_shade_type_changed (NULL, capplet); + + pixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->smenuitem), pixbuf); + g_object_unref (pixbuf); + + pixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_HORIZONTAL, + item->pcolor, item->scolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->hmenuitem), pixbuf); + g_object_unref (pixbuf); + + pixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_VERTICAL, + item->pcolor, item->scolor, 14, 12); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->vmenuitem), pixbuf); + g_object_unref (pixbuf); +} + +static void gnome_wp_pcolor_changed (GtkWidget * widget, + guint r, guint g, guint b, guint a, + GnomeWPCapplet * capplet) { + gnome_wp_color_changed (capplet, TRUE); +} + +static void gnome_wp_scolor_changed (GtkWidget * widget, + guint r, guint g, guint b, guint a, + GnomeWPCapplet * capplet) { + gnome_wp_color_changed (capplet, FALSE); +} + +static void gnome_wp_remove_wallpaper (GtkWidget * widget, + GnomeWPCapplet * capplet) { + GtkTreeIter iter; + GtkTreeModel * model; + GtkTreeSelection * selection; + gchar * wpfile; + + if (capplet->idleid > 0) { + g_source_remove (capplet->idleid); + } + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + GnomeWPItem * item; + + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + item->deleted = TRUE; + + gtk_list_store_remove (GTK_LIST_STORE (model), &iter); + } +} + +static gboolean gnome_wp_load_stuffs (void * data) { + GnomeWPCapplet * capplet = (GnomeWPCapplet *) data; + gchar * imagepath; + GnomeWPItem * item; + GtkTreePath * path; + + gnome_wp_xml_load_list (capplet); + g_hash_table_foreach (capplet->wphash, (GHFunc) wp_props_load_wallpaper, + capplet); + + gdk_window_set_cursor (capplet->window->window, NULL); + + imagepath = gconf_client_get_string (capplet->client, + WP_FILE_KEY, + NULL); + item = g_hash_table_lookup (capplet->wphash, imagepath); + if (item != NULL) { + if (item->deleted == TRUE) { + 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); + + gnome_wp_option_menu_set (capplet, item->options, FALSE); + gnome_wp_option_menu_set (capplet, item->shade_type, TRUE); + + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->pc_picker), + item->pcolor->red, + item->pcolor->green, + item->pcolor->blue, 65535); + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->sc_picker), + item->scolor->red, + item->scolor->green, + item->scolor->blue, 65535); + } else { + GdkColor color1, color2; + + item = g_new0 (GnomeWPItem, 1); + + item->filename = g_strdup (imagepath); + + 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 (g_file_test (item->filename, G_FILE_TEST_EXISTS)) { + item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs); + item->name = g_strdup (item->fileinfo->name); + item->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, + NULL); + item->deleted = FALSE; + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item); + 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); + + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->pc_picker), + item->pcolor->red, + item->pcolor->green, + item->pcolor->blue, 65535); + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->sc_picker), + item->scolor->red, + item->scolor->green, + item->scolor->blue, 65535); + + gnome_wp_option_menu_set (capplet, item->options, FALSE); + gnome_wp_option_menu_set (capplet, item->shade_type, TRUE); + } else { + gnome_wp_item_free (item); + } + } + g_free (imagepath); + + item = g_hash_table_lookup (capplet->wphash, "(none)"); + if (item == NULL) { + GdkColor color1, color2; + + item = g_new0 (GnomeWPItem, 1); + + item->deleted = FALSE; + item->filename = g_strdup ("(none)"); + + 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); + + item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs); + item->name = g_strdup (item->fileinfo->name); + item->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, + NULL); + + item->description = g_strdup_printf ("%s", item->name); + + g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item); + wp_props_load_wallpaper (item->filename, item, capplet); + } else { + if (item->deleted == TRUE) { + item->deleted = FALSE; + wp_props_load_wallpaper (item->filename, item, capplet); + } + } + + return FALSE; +} + +static gint gnome_wp_list_sort (GtkTreeModel * model, + GtkTreeIter * a, GtkTreeIter * b, + GnomeWPCapplet * capplet) { + gchar * foo, * bar; + gchar * desca, * descb; + + gtk_tree_model_get (model, a, 1, &desca, 2, &foo, -1); + gtk_tree_model_get (model, b, 1, &descb, 2, &bar, -1); + + if (!strcmp (foo, "(none)")) { + return -1; + } else if (!strcmp (bar, "(none)")) { + return 1; + } else { + return strcmp (desca, descb); + } +} + +static void gnome_wp_file_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + GtkTreeSelection * selection; + GtkTreeModel * model; + GtkTreeIter iter; + GtkTreePath * path; + GnomeWPItem * item; + gchar * wpfile, * selected; + + wpfile = g_strdup (gconf_value_get_string (entry->value)); + item = g_hash_table_lookup (capplet->wphash, wpfile); + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &selected, -1); + if (strcmp (selected, wpfile) != 0) { + if (item != 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); + } else { + GdkColor color1, color2; + + item = g_new0 (GnomeWPItem, 1); + + item->filename = g_strdup (wpfile); + + 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 (g_file_test (item->filename, G_FILE_TEST_EXISTS)) { + item->fileinfo = gnome_wp_info_new (item->filename, capplet->thumbs); + item->name = g_strdup (item->fileinfo->name); + item->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, + NULL); + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + g_hash_table_insert (capplet->wphash, + g_strdup (item->filename), item); + 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); + } else { + gnome_wp_item_free (item); + } + } + } + g_free (wpfile); + g_free (selected); + } +} + +static void gnome_wp_options_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + GtkTreeSelection * selection; + GtkTreeModel * model; + GtkTreeIter iter; + GnomeWPItem * item; + gchar * wpfile; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + if (item != NULL) { + item->options = g_strdup (gconf_value_get_string (entry->value)); + gnome_wp_option_menu_set (capplet, item->options, FALSE); + } + g_free (wpfile); + } +} + +static void gnome_wp_shading_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + GtkTreeSelection * selection; + GtkTreeModel * model; + GtkTreeIter iter; + GnomeWPItem * item; + gchar * wpfile; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (capplet->treeview)); + if (gtk_tree_selection_get_selected (selection, &model, &iter)) { + gtk_tree_model_get (model, &iter, 2, &wpfile, -1); + + item = g_hash_table_lookup (capplet->wphash, wpfile); + + if (item != NULL) { + item->shade_type = g_strdup (gconf_value_get_string (entry->value)); + gnome_wp_option_menu_set (capplet, item->shade_type, TRUE); + } + g_free (wpfile); + } +} + +static void gnome_wp_color1_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + GdkColor color; + const gchar * colorhex; + + colorhex = gconf_value_get_string (entry->value); + + gdk_color_parse (colorhex, &color); + + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->pc_picker), + color.red, + color.green, + color.blue, 65535); + + gnome_wp_color_changed (capplet, TRUE); +} + +static void gnome_wp_color2_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + GdkColor color; + const gchar * colorhex; + + colorhex = gconf_value_get_string (entry->value); + + gdk_color_parse (colorhex, &color); + + gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (capplet->sc_picker), + color.red, + color.green, + color.blue, 65535); + + gnome_wp_color_changed (capplet, FALSE); +} + +static void gnome_wp_delay_changed (GConfClient * client, guint id, + GConfEntry * entry, + GnomeWPCapplet * capplet) { + capplet->delay = gconf_value_get_int (entry->value); +} + +static void gnome_wp_icon_theme_changed (GnomeIconTheme * theme, + GnomeWPCapplet * capplet) { + gchar * icofile; + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "background-capplet", + 48, NULL, NULL); + if (icofile != NULL) { + gtk_window_set_default_icon_from_file (icofile, NULL); + } + g_free (icofile); + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-center", + 16, NULL, NULL); + if (icofile != NULL) { + GdkPixbuf * pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (icofile, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->citem), pixbuf); + g_object_unref (pixbuf); + } + g_free (icofile); + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-fill", + 16, NULL, NULL); + if (icofile != NULL) { + GdkPixbuf * pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (icofile, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->fitem), pixbuf); + g_object_unref (pixbuf); + } + g_free (icofile); + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-scale", + 16, NULL, NULL); + if (icofile != NULL) { + GdkPixbuf * pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (icofile, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->sitem), pixbuf); + g_object_unref (pixbuf); + } + g_free (icofile); + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-tile", + 16, NULL, NULL); + if (icofile != NULL) { + GdkPixbuf * pixbuf; + + pixbuf = gdk_pixbuf_new_from_file (icofile, NULL); + gtk_image_set_from_pixbuf (GTK_IMAGE (capplet->witem), pixbuf); + g_object_unref (pixbuf); + } + g_free (icofile); +} + +static void wallpaper_properties_init (void) { + GnomeWPCapplet * capplet; + GtkWidget * label, * button; + GtkWidget * vbox, * hbox, * bbox; + GtkWidget * swin, * clabel; + GtkWidget * menu; + GtkWidget * mbox, * mitem; + GtkCellRenderer * renderer; + GtkTreeViewColumn * column; + GtkTreeSelection * selection; + GdkCursor * cursor; + gchar * icofile; + + capplet = g_new0 (GnomeWPCapplet, 1); + + if (capplet->client == NULL) { + capplet->client = gconf_client_get_default (); + } + + capplet->delay = gconf_client_get_int (capplet->client, + WP_DELAY_KEY, + NULL); + gconf_client_add_dir (capplet->client, WP_KEYBOARD_PATH, + GCONF_CLIENT_PRELOAD_NONE, NULL); + gconf_client_add_dir (capplet->client, WP_PATH_KEY, + GCONF_CLIENT_PRELOAD_NONE, NULL); + + gconf_client_notify_add (capplet->client, + WP_DELAY_KEY, + (GConfClientNotifyFunc) gnome_wp_delay_changed, + capplet, NULL, NULL); + gconf_client_notify_add (capplet->client, + WP_FILE_KEY, + (GConfClientNotifyFunc) gnome_wp_file_changed, + capplet, NULL, NULL); + gconf_client_notify_add (capplet->client, + WP_OPTIONS_KEY, + (GConfClientNotifyFunc) gnome_wp_options_changed, + capplet, NULL, NULL); + gconf_client_notify_add (capplet->client, + WP_SHADING_KEY, + (GConfClientNotifyFunc) gnome_wp_shading_changed, + capplet, NULL, NULL); + gconf_client_notify_add (capplet->client, + WP_PCOLOR_KEY, + (GConfClientNotifyFunc) gnome_wp_color1_changed, + capplet, NULL, NULL); + gconf_client_notify_add (capplet->client, + WP_SCOLOR_KEY, + (GConfClientNotifyFunc) gnome_wp_color2_changed, + capplet, NULL, NULL); + + capplet->wphash = g_hash_table_new_full (g_str_hash, g_str_equal, + g_free, + (GDestroyNotify) + gnome_wp_item_free); + + capplet->thumbs = gnome_thumbnail_factory_new (GNOME_THUMBNAIL_SIZE_NORMAL); + capplet->theme = gnome_icon_theme_new (); + gnome_icon_theme_set_allow_svg (capplet->theme, TRUE); + + g_signal_connect (G_OBJECT (capplet->theme), "changed", + G_CALLBACK (gnome_wp_icon_theme_changed), capplet); + + capplet->window = gtk_dialog_new (); + gtk_window_set_title (GTK_WINDOW (capplet->window), + _("Desktop Wallpaper Preferences")); + gtk_dialog_set_has_separator (GTK_DIALOG (capplet->window), FALSE); + gtk_window_set_default_size (GTK_WINDOW (capplet->window), 360, 418); + + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "background-capplet", + 48, NULL, NULL); + if (icofile != NULL) { + gtk_window_set_default_icon_from_file (icofile, NULL); + } + g_free (icofile); + + gtk_widget_realize (capplet->window); + + + + /* Drag and Drop Support */ + gtk_drag_dest_unset (capplet->window); + gtk_drag_dest_set (capplet->window, GTK_DEST_DEFAULT_ALL, drop_types, + sizeof (drop_types) / sizeof (drop_types[0]), + GDK_ACTION_COPY | GDK_ACTION_MOVE); + g_signal_connect (G_OBJECT (capplet->window), "drag_data_received", + G_CALLBACK (bg_properties_dragged_image), capplet); + + /* Dialog Buttons */ + /* We are hiding the help button for now, since we have no docs */ + /* + label = gtk_button_new_from_stock (GTK_STOCK_HELP); + gtk_dialog_add_action_widget (GTK_DIALOG (capplet->window), label, + GTK_RESPONSE_HELP); + gtk_widget_show (label); + */ + + label = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + gtk_dialog_add_action_widget (GTK_DIALOG (capplet->window), label, + GTK_RESPONSE_CLOSE); + gtk_widget_show (label); + + /* Main Contents */ + vbox = gtk_vbox_new (FALSE, 6); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); + gtk_box_pack_start (GTK_BOX (GTK_DIALOG (capplet->window)->vbox), vbox, + TRUE, TRUE, 0); + gtk_widget_show (vbox); + + clabel = gtk_label_new_with_mnemonic (_("Desktop _Wallpaper")); + gtk_misc_set_alignment (GTK_MISC (clabel), 0.0, 0.5); + gtk_label_set_use_markup (GTK_LABEL (clabel), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), clabel, FALSE, FALSE, 0); + gtk_widget_show (clabel); + + /* Treeview stuff goes in here */ + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0); + gtk_widget_show (hbox); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + swin = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swin), + GTK_SHADOW_IN); + gtk_box_pack_start (GTK_BOX (hbox), swin, TRUE, TRUE, 0); + + capplet->treeview = gtk_tree_view_new (); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (capplet->treeview), FALSE); + gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (capplet->treeview), FALSE); + gtk_container_add (GTK_CONTAINER (swin), capplet->treeview); + gtk_widget_show (capplet->treeview); + + gtk_label_set_mnemonic_widget (GTK_LABEL (clabel), capplet->treeview); + + capplet->model = GTK_TREE_MODEL (gtk_list_store_new (3, GDK_TYPE_PIXBUF, + G_TYPE_STRING, + G_TYPE_STRING)); + + gtk_tree_view_set_model (GTK_TREE_VIEW (capplet->treeview), capplet->model); + + column = gtk_tree_view_column_new (); + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "pixbuf", 0, + NULL); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_column_pack_start (column, renderer, FALSE); + gtk_tree_view_column_set_attributes (column, renderer, + "markup", 1, + NULL); + gtk_tree_view_column_set_spacing (column, 6); + + gtk_tree_view_append_column (GTK_TREE_VIEW (capplet->treeview), column); + + gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (capplet->model), 2, + (GtkTreeIterCompareFunc) gnome_wp_list_sort, + capplet, NULL); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (capplet->model), + 2, GTK_SORT_ASCENDING); + + gtk_rc_parse_string ("style \"wp-tree-defaults\" {\n" + " GtkTreeView::horizontal-separator = 6\n" + " GtkTreeView::vertical-separator = 6\n" + "} widget_class \"*TreeView*\"" + " style \"wp-tree-defaults\""); + + /* Need to add sorting stuff and whatnot */ + gtk_widget_show (swin); + + /* The Box for Fill Style and Add/Remove buttons */ + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new_with_mnemonic (_("_Style:")); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + capplet->wp_opts = gtk_option_menu_new (); + gtk_box_pack_start (GTK_BOX (hbox), capplet->wp_opts, FALSE, FALSE, 0); + gtk_widget_show (capplet->wp_opts); + + gtk_label_set_mnemonic_widget (GTK_LABEL (label), capplet->wp_opts); + + menu = gtk_menu_new (); + mitem = gtk_menu_item_new (); + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-center", + 16, NULL, NULL); + + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + if (icofile != NULL) { + capplet->citem = gtk_image_new_from_file (icofile); + gtk_box_pack_start (GTK_BOX (mbox), capplet->citem, FALSE, FALSE, 0); + gtk_widget_show (capplet->citem); + } + g_free (icofile); + + label = gtk_label_new (_("Centered")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_menu_append (GTK_MENU (menu), mitem); + gtk_widget_show (mitem); + + mitem = gtk_menu_item_new (); + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-fill", + 16, NULL, NULL); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + if (icofile != NULL) { + capplet->fitem = gtk_image_new_from_file (icofile); + gtk_box_pack_start (GTK_BOX (mbox), capplet->fitem, FALSE, FALSE, 0); + gtk_widget_show (capplet->fitem); + } + g_free (icofile); + + label = gtk_label_new (_("Fill Screen")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_menu_append (GTK_MENU (menu), mitem); + gtk_widget_show (mitem); + + mitem = gtk_menu_item_new (); + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-scale", + 16, NULL, NULL); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + if (icofile != NULL) { + capplet->sitem = gtk_image_new_from_file (icofile); + gtk_box_pack_start (GTK_BOX (mbox), capplet->sitem, FALSE, FALSE, 0); + gtk_widget_show (capplet->sitem); + } + label = gtk_label_new (_("Scaled")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_menu_append (GTK_MENU (menu), mitem); + gtk_widget_show (mitem); + + mitem = gtk_menu_item_new (); + icofile = gnome_icon_theme_lookup_icon (capplet->theme, + "stock_wallpaper-tile", + 16, NULL, NULL); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + if (icofile != NULL) { + capplet->witem = gtk_image_new_from_file (icofile); + gtk_box_pack_start (GTK_BOX (mbox), capplet->witem, FALSE, FALSE, 0); + gtk_widget_show (capplet->witem); + } + label = gtk_label_new (_("Tiled")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_menu_append (GTK_MENU (menu), mitem); + gtk_widget_show (mitem); + + gtk_option_menu_set_menu (GTK_OPTION_MENU (capplet->wp_opts), menu); + + g_signal_connect (G_OBJECT (menu), "deactivate", + G_CALLBACK (gnome_wp_scale_type_changed), capplet); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + /* Create the Remove button first, since it's ordered last */ + capplet->rm_button = gtk_button_new_from_stock (GTK_STOCK_REMOVE); + gtk_box_pack_end (GTK_BOX (hbox), capplet->rm_button, FALSE, FALSE, 0); + gtk_widget_show (capplet->rm_button); + + g_signal_connect (G_OBJECT (capplet->rm_button), "clicked", + G_CALLBACK (gnome_wp_remove_wallpaper), capplet); + + /* Now do the Add Wallpaper button */ + button = gtk_button_new (); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0); + + bbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (button), bbox); + label = gtk_image_new_from_stock (GTK_STOCK_ADD, GTK_ICON_SIZE_BUTTON); + gtk_box_pack_start (GTK_BOX (bbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + label = gtk_label_new_with_mnemonic (_("_Add Wallpaper")); + gtk_box_pack_start (GTK_BOX (bbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + gtk_widget_show (bbox); + + gtk_widget_show (button); + + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (gnome_wp_file_open_dialog), capplet); + + /* Silly Random Option */ + /* + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + */ + + /* Stupid Useless Label as a Spacer Hack */ + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + /* The Wallpaper Background Colors Section */ + clabel = gtk_label_new_with_mnemonic (_("_Desktop Colors ")); + gtk_misc_set_alignment (GTK_MISC (clabel), 0.0, 0.5); + gtk_label_set_use_markup (GTK_LABEL (clabel), TRUE); + gtk_box_pack_start (GTK_BOX (vbox), clabel, FALSE, FALSE, 0); + gtk_widget_show (clabel); + + hbox = gtk_hbox_new (FALSE, 6); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_widget_show (hbox); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + label = gtk_label_new (""); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_widget_show (label); + + capplet->color_opt = gtk_option_menu_new (); + gtk_widget_show (capplet->color_opt); + gtk_box_pack_start(GTK_BOX (hbox), capplet->color_opt, FALSE, FALSE, 0); + + menu = gtk_menu_new (); + mitem = gtk_menu_item_new (); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + capplet->smenuitem = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (mbox), capplet->smenuitem, FALSE, FALSE, 0); + gtk_widget_show (capplet->smenuitem); + + label = gtk_label_new (_("Solid Color")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_widget_show (mitem); + gtk_menu_append (GTK_MENU (menu), mitem); + + mitem = gtk_menu_item_new (); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + capplet->hmenuitem = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (mbox), capplet->hmenuitem, FALSE, FALSE, 0); + gtk_widget_show (capplet->hmenuitem); + + label = gtk_label_new (_("Horizontal Gradient")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_widget_show (mitem); + gtk_menu_append (GTK_MENU (menu), mitem); + + mitem = gtk_menu_item_new (); + mbox = gtk_hbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (mitem), mbox); + gtk_widget_show (mbox); + + capplet->vmenuitem = gtk_image_new (); + gtk_box_pack_start (GTK_BOX (mbox), capplet->vmenuitem, FALSE, FALSE, 0); + gtk_widget_show (capplet->vmenuitem); + + label = gtk_label_new (_("Vertical Gradient")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_box_pack_start (GTK_BOX (mbox), label, TRUE, TRUE, 0); + gtk_widget_show (label); + gtk_widget_show (mitem); + gtk_menu_append (GTK_MENU (menu), mitem); + + gtk_option_menu_set_menu (GTK_OPTION_MENU (capplet->color_opt), menu); + g_signal_connect (G_OBJECT (menu), "deactivate", + G_CALLBACK (gnome_wp_shade_type_changed), capplet); + + gtk_label_set_mnemonic_widget (GTK_LABEL (clabel), capplet->color_opt); + + capplet->pc_picker = gnome_color_picker_new (); + gtk_widget_show (capplet->pc_picker); + gtk_box_pack_start (GTK_BOX (hbox), capplet->pc_picker, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (capplet->pc_picker), "color_set", + G_CALLBACK (gnome_wp_pcolor_changed), capplet); + + capplet->sc_picker = gnome_color_picker_new (); + gtk_box_pack_start (GTK_BOX (hbox), capplet->sc_picker, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (capplet->sc_picker), "color_set", + G_CALLBACK (gnome_wp_scolor_changed), capplet); + + g_signal_connect (G_OBJECT (capplet->window), "response", + G_CALLBACK (wallpaper_properties_clicked), capplet); + + gtk_widget_show (capplet->window); + + cursor = gdk_cursor_new_for_display (gdk_display_get_default (), + GDK_WATCH); + gdk_window_set_cursor (capplet->window->window, cursor); + gdk_cursor_unref (cursor); + + g_idle_add (gnome_wp_load_stuffs, capplet); + + 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); +} + +gint main (gint argc, gchar *argv[]) { + GnomeProgram * proggie; + +#ifdef ENABLE_NLS + bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + textdomain (GETTEXT_PACKAGE); +#endif + + proggie = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, + argc, argv, GNOME_PARAM_POPT_TABLE, + NULL, NULL); + + wallpaper_properties_init (); + gtk_main (); + + return 0; +} diff --git a/capplets/background/gnome-wp-capplet.h b/capplets/background/gnome-wp-capplet.h new file mode 100644 index 000000000..4a4345bef --- /dev/null +++ b/capplets/background/gnome-wp-capplet.h @@ -0,0 +1,110 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _GNOME_WP_CAPPLET_H_ +#define _GNOME_WP_CAPPLET_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +typedef struct _GnomeWPCapplet GnomeWPCapplet; + +#include "gnome-wp-info.h" +#include "gnome-wp-item.h" +#include "gnome-wp-utils.h" +#include "gnome-wp-xml.h" + +struct _GnomeWPCapplet { + GtkWidget * window; + + /* The Tree View */ + GtkWidget * treeview; + GtkTreeModel * model; + + /* Option Menu for Scaling Options */ + GtkWidget * wp_opts; + GtkWidget * rm_button; + + /* Menu Items for Fill/Scale/Center/Tile Options */ + GtkWidget * fitem; + GtkWidget * sitem; + GtkWidget * citem; + GtkWidget * witem; + + /* Widgets for Color Options */ + GtkWidget * color_opt; + GtkWidget * pc_picker; + GtkWidget * sc_picker; + + /* Menu Items for Color Style Options */ + GtkWidget * smenuitem; + GtkWidget * hmenuitem; + GtkWidget * vmenuitem; + + /* GConf Client */ + GConfClient * client; + + /* Thumbnailing and Icon Theme stuff */ + GnomeThumbnailFactory * thumbs; + GnomeIconTheme * theme; + + /* Hash Table of Wallpapers */ + GHashTable * wphash; + + /* Keyboard Delay */ + gint delay; + + /* The Timeout ID for Setting the Wallpaper */ + gint idleid; +}; + +typedef enum { + GNOME_WP_SHADE_TYPE_SOLID, + GNOME_WP_SHADE_TYPE_HORIZ, + GNOME_WP_SHADE_TYPE_VERT +} GnomeWPShadeType; + +typedef enum { + GNOME_WP_SCALE_TYPE_CENTERED, + GNOME_WP_SCALE_TYPE_STRETCHED, + GNOME_WP_SCALE_TYPE_SCALED, + GNOME_WP_SCALE_TYPE_TILED +} GnomeWPScaleType; + +#define WP_PATH_KEY "/desktop/gnome/background" +#define WP_FILE_KEY WP_PATH_KEY "/picture_filename" +#define WP_OPTIONS_KEY WP_PATH_KEY "/picture_options" +#define WP_SHADING_KEY WP_PATH_KEY "/color_shading_type" +#define WP_PCOLOR_KEY WP_PATH_KEY "/primary_color" +#define WP_SCOLOR_KEY WP_PATH_KEY "/secondary_color" +#define WP_KEYBOARD_PATH "/desktop/gnome/peripherals/keyboard" +#define WP_DELAY_KEY WP_KEYBOARD_PATH "/delay" + +void gnome_wp_main_quit (GnomeWPCapplet * capplet); + +#endif + diff --git a/capplets/background/gnome-wp-info.c b/capplets/background/gnome-wp-info.c new file mode 100644 index 000000000..5425228de --- /dev/null +++ b/capplets/background/gnome-wp-info.c @@ -0,0 +1,103 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include +#include "gnome-wp-info.h" + +GnomeWPInfo * gnome_wp_info_new (const gchar * uri, + GnomeThumbnailFactory * thumbs) { + GnomeWPInfo * new; + GnomeVFSFileInfo * info; + GnomeVFSResult result; + + info = gnome_vfs_file_info_new (); + result = gnome_vfs_get_file_info (uri, info, + GNOME_VFS_FILE_INFO_DEFAULT | + GNOME_VFS_FILE_INFO_GET_MIME_TYPE | + GNOME_VFS_FILE_INFO_FOLLOW_LINKS); + if (info == NULL || info->mime_type == NULL || result != GNOME_VFS_OK) { + if (!strcmp (uri, "(none)")) { + new = g_new0 (GnomeWPInfo, 1); + + new->mime_type = g_strdup ("image/x-no-data"); + new->uri = g_strdup (uri); + + new->thumburi = g_strconcat (g_get_home_dir (), "/.thumbnails/normal/", + gnome_thumbnail_md5 (uri), ".png", NULL); + + new->name = g_strdup (_("No Wallpaper")); + + new->size = 0; + } else { + new = NULL; + } + } else { + new = g_new0 (GnomeWPInfo, 1); + + new->uri = g_strdup (uri); + + new->thumburi = gnome_thumbnail_factory_lookup (thumbs, + new->uri, info->mtime); + if (new->thumburi == NULL) { + new->thumburi = g_strconcat (g_get_home_dir (), "/.thumbnails/normal/", + gnome_thumbnail_md5 (uri), ".png", NULL); + } + new->name = g_strdup (info->name); + new->mime_type = g_strdup (info->mime_type); + + new->size = info->size; + new->mtime = info->mtime; + } + gnome_vfs_file_info_unref (info); + + return new; +} + +GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info) { + GnomeWPInfo * new; + + new = g_new0 (GnomeWPInfo, 1); + + new->uri = g_strdup (info->uri); + new->thumburi = g_strdup (info->uri); + + new->name = g_strdup (info->name); + new->mime_type = g_strdup (info->mime_type); + + new->size = info->size; + new->mtime = info->mtime; + + return new; +} + +void gnome_wp_info_free (GnomeWPInfo * info) { + if (info == NULL) { + return; + } + + g_free (info->uri); + g_free (info->thumburi); + g_free (info->name); + g_free (info->mime_type); + + info = NULL; +} + diff --git a/capplets/background/gnome-wp-info.h b/capplets/background/gnome-wp-info.h new file mode 100644 index 000000000..e3d75a042 --- /dev/null +++ b/capplets/background/gnome-wp-info.h @@ -0,0 +1,47 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _GNOME_WP_INFO_H_ +#define _GNOME_WP_INFO_H_ + +#include +#include +#include + +typedef struct _GnomeWPInfo GnomeWPInfo; + +struct _GnomeWPInfo { + gchar * uri; + gchar * thumburi; + gchar * name; + gchar * mime_type; + + GnomeVFSFileSize size; + + time_t mtime; +}; + +GnomeWPInfo * gnome_wp_info_new (const gchar * uri, + GnomeThumbnailFactory * thumbs); +GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info); +void gnome_wp_info_free (GnomeWPInfo * info); + +#endif + diff --git a/capplets/background/gnome-wp-item.c b/capplets/background/gnome-wp-item.c new file mode 100644 index 000000000..624e98a05 --- /dev/null +++ b/capplets/background/gnome-wp-item.c @@ -0,0 +1,134 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include "gnome-wp-item.h" +#include "gnome-wp-utils.h" + +void gnome_wp_item_free (GnomeWPItem * item) { + if (item == NULL) { + return; + } + + g_free (item->name); + g_free (item->filename); + g_free (item->description); + g_free (item->imguri); + g_free (item->options); + g_free (item->shade_type); + + g_free (item->pri_color); + g_free (item->sec_color); + + gdk_color_free (item->pcolor); + gdk_color_free (item->scolor); + + gnome_wp_info_free (item->fileinfo); + gnome_wp_info_free (item->uriinfo); + + gtk_tree_row_reference_free (item->rowref); + + item = NULL; +} + +GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item, + GnomeThumbnailFactory * thumbs) { + GdkPixbuf * pixbuf, * bgpixbuf; + GdkPixbuf * scaled = NULL; + gint w, h, ratio; + + w = gdk_screen_get_width (gdk_screen_get_default ()); + h = gdk_screen_get_height (gdk_screen_get_default ()); + ratio = h / 96; + + if (!strcmp (item->shade_type, "solid")) { + bgpixbuf = gnome_wp_pixbuf_new_solid (item->pcolor, w / ratio, h / ratio); + } else if (!strcmp (item->shade_type, "vertical-gradient")) { + bgpixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_VERTICAL, + item->pcolor, item->scolor, + w / ratio, h / ratio); + } else { + bgpixbuf = gnome_wp_pixbuf_new_gradient (GTK_ORIENTATION_HORIZONTAL, + item->pcolor, item->scolor, + w / ratio, h / ratio); + } + + if (item->fileinfo->thumburi != NULL && + g_file_test (item->fileinfo->thumburi, G_FILE_TEST_EXISTS)) { + pixbuf = gdk_pixbuf_new_from_file (item->fileinfo->thumburi, NULL); + } else if (!strcmp (item->filename, "(none)")) { + pixbuf = gdk_pixbuf_copy (bgpixbuf); + } else { + pixbuf = gnome_thumbnail_factory_generate_thumbnail (thumbs, + item->filename, + item->fileinfo->mime_type); + gnome_thumbnail_factory_save_thumbnail (thumbs, pixbuf, + item->filename, + item->fileinfo->mtime); + } + + if (pixbuf != NULL) { + w = gdk_pixbuf_get_width (pixbuf); + h = gdk_pixbuf_get_height (pixbuf); + ratio = h / 48; + + if (ratio == 1) + ratio = 2; + + scaled = gnome_thumbnail_scale_down_pixbuf (pixbuf, + w / ratio, h / ratio); + + if (w == h) { + item->options = g_strdup ("wallpaper"); + scaled = gnome_wp_pixbuf_tile (scaled, bgpixbuf); + + gnome_thumbnail_factory_save_thumbnail (thumbs, scaled, + item->filename, + item->fileinfo->mtime); + + w = gdk_pixbuf_get_width (scaled); + h = gdk_pixbuf_get_height (scaled); + ratio = h / 48; + + if (ratio == 1) + ratio = 2; + + scaled = gnome_thumbnail_scale_down_pixbuf (scaled, + w / ratio, h / ratio); + } + + if (!strcmp (item->options, "centered")) { + scaled = gnome_wp_pixbuf_center (scaled, bgpixbuf); + + w = gdk_pixbuf_get_width (scaled); + h = gdk_pixbuf_get_height (scaled); + ratio = h / 48; + + if (ratio == 1) + ratio = 2; + + scaled = gnome_thumbnail_scale_down_pixbuf (scaled, + w / ratio, h / ratio); + } + } + g_object_unref (pixbuf); + g_object_unref (bgpixbuf); + + return scaled; +} diff --git a/capplets/background/gnome-wp-item.h b/capplets/background/gnome-wp-item.h new file mode 100644 index 000000000..86fc6639f --- /dev/null +++ b/capplets/background/gnome-wp-item.h @@ -0,0 +1,62 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include +#include +#include +#include +#include +#include + +#ifndef _GNOME_WP_ITEM_H_ +#define _GNOME_WP_ITEM_H_ + +typedef struct _GnomeWPItem GnomeWPItem; + +struct _GnomeWPItem { + gchar * name; + gchar * filename; + gchar * description; + gchar * imguri; + gchar * options; + gchar * shade_type; + gchar * pri_color; + gchar * sec_color; + + /* Where the Item is in the List */ + GtkTreeRowReference * rowref; + + /* Real colors */ + GdkColor * pcolor; + GdkColor * scolor; + + GnomeWPInfo * fileinfo; + GnomeWPInfo * uriinfo; + + /* Did the user remove us? */ + gboolean deleted; +}; + +void gnome_wp_item_free (GnomeWPItem * item); +GdkPixbuf * gnome_wp_item_get_thumbnail (GnomeWPItem * item, + GnomeThumbnailFactory * thumbs); + +#endif + diff --git a/capplets/background/gnome-wp-utils.c b/capplets/background/gnome-wp-utils.c new file mode 100644 index 000000000..b051a1f06 --- /dev/null +++ b/capplets/background/gnome-wp-utils.c @@ -0,0 +1,162 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include "gnome-wp-utils.h" + +GdkPixbuf * gnome_wp_pixbuf_new_gradient (GtkOrientation orientation, + GdkColor * c1, + GdkColor * c2, + gint width, gint height) { + GdkPixbuf * pixbuf; + gint i, j; + gint dr, dg, db; + gint gs1; + gint vc = ((orientation == GTK_ORIENTATION_HORIZONTAL) || (c1 == c2)); + guchar * b, * row, * d; + int rowstride; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); + d = gdk_pixbuf_get_pixels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + dr = c2->red - c1->red; + dg = c2->green - c1->green; + db = c2->blue - c1->blue; + + gs1 = (orientation == GTK_ORIENTATION_VERTICAL) ? height - 1 : width - 1; + + row = g_new (unsigned char, rowstride); + + if (vc) { + b = row; + for (j = 0; j < width; j++) { + *b++ = (c1->red + (j * dr) / gs1) >> 8; + *b++ = (c1->green + (j * dg) / gs1) >> 8; + *b++ = (c1->blue + (j * db) / gs1) >> 8; + } + } + + for (i = 0; i < height; i++) { + if (!vc) { + unsigned char cr, cg, cb; + cr = (c1->red + (i * dr) / gs1) >> 8; + cg = (c1->green + (i * dg) / gs1) >> 8; + cb = (c1->blue + (i * db) / gs1) >> 8; + b = row; + for (j = 0; j < width; j++) { + *b++ = cr; + *b++ = cg; + *b++ = cb; + } + } + memcpy (d, row, width * 3); + d += rowstride; + } + g_free (row); + + return pixbuf; +} + +GdkPixbuf * gnome_wp_pixbuf_new_solid (GdkColor * color, + gint width, gint height) { + GdkPixbuf * pixbuf; + gint j, rowstride; + guchar * b, * d, * row; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height); + d = gdk_pixbuf_get_pixels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + + row = g_new (unsigned char, rowstride); + + b = row; + for (j = 0; j < width; j++) { + *b++ = color->red >> 8; + *b++ = color->green >> 8; + *b++ = color->blue >> 8; + } + + for (j = 0; j < height; j++) { + memcpy (d, row, width * 3); + d += rowstride; + } + + g_free (row); + + return pixbuf; +} + +GdkPixbuf * gnome_wp_pixbuf_tile (GdkPixbuf * src_pixbuf, + GdkPixbuf * dest_pixbuf) { + gdouble cx, cy; + gdouble colorv; + gint dwidth, dheight; + gint swidth, sheight; + guint alpha = 255; + + if (dest_pixbuf == NULL) { + return src_pixbuf; + } + + swidth = gdk_pixbuf_get_width (src_pixbuf); + sheight = gdk_pixbuf_get_height (src_pixbuf); + + dwidth = gdk_pixbuf_get_width (dest_pixbuf); + dheight = gdk_pixbuf_get_height (dest_pixbuf); + + for (cy = 0; cy < dheight; cy += sheight) { + for (cx = 0; cx < dwidth; cx += swidth) { + gdk_pixbuf_composite (src_pixbuf, dest_pixbuf, cx, cy, + MIN (swidth, dwidth - cx), + MIN (sheight, dheight - cy), + cx, cy, 1.0, 1.0, GDK_INTERP_BILINEAR, alpha); + } + } + + return dest_pixbuf; +} + +GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf, + GdkPixbuf * dest_pixbuf) { + gdouble cx, cy; + gdouble colorv; + gint dwidth, dheight; + gint swidth, sheight; + guint alpha = 255; + + if (dest_pixbuf == NULL) { + return src_pixbuf; + } + + swidth = gdk_pixbuf_get_width (src_pixbuf); + sheight = gdk_pixbuf_get_height (src_pixbuf); + + dwidth = gdk_pixbuf_get_width (dest_pixbuf); + dheight = gdk_pixbuf_get_height (dest_pixbuf); + + cx = (dwidth - swidth) / 2; + cy = (dheight - sheight) / 2; + + gdk_pixbuf_composite (src_pixbuf, dest_pixbuf, cx, cy, + swidth, sheight, + cx, cy, 1.0, 1.0, GDK_INTERP_BILINEAR, alpha); + return dest_pixbuf; +} + diff --git a/capplets/background/gnome-wp-utils.h b/capplets/background/gnome-wp-utils.h new file mode 100644 index 000000000..914d9737b --- /dev/null +++ b/capplets/background/gnome-wp-utils.h @@ -0,0 +1,42 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _GNOME_WP_UTILS_H_ +#define _GNOME_WP_UTILS_H_ + +#include +#include + +G_BEGIN_DECLS + +GdkPixbuf * gnome_wp_pixbuf_new_gradient (GtkOrientation orientation, + GdkColor * c1, + GdkColor * c2, + gint width, gint height); +GdkPixbuf * gnome_wp_pixbuf_new_solid (GdkColor * color, + gint width, gint height); +GdkPixbuf * gnome_wp_pixbuf_tile (GdkPixbuf * src_pixbuf, + GdkPixbuf * dest_pixbuf); +GdkPixbuf * gnome_wp_pixbuf_center (GdkPixbuf * src_pixbuf, + GdkPixbuf * dest_pixbuf); + +G_END_DECLS + +#endif diff --git a/capplets/background/gnome-wp-xml.c b/capplets/background/gnome-wp-xml.c new file mode 100644 index 000000000..708b81d51 --- /dev/null +++ b/capplets/background/gnome-wp-xml.c @@ -0,0 +1,370 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#include "gnome-wp-capplet.h" + +static gboolean gnome_wp_xml_get_bool (const xmlNode * parent, + const gchar * prop_name) { + gchar * prop; + gboolean ret_val = FALSE; + + g_return_val_if_fail (parent != NULL, FALSE); + g_return_val_if_fail (prop_name != NULL, FALSE); + + prop = xmlGetProp ((xmlNode *) parent, prop_name); + if (prop != NULL) { + if (!g_strcasecmp (prop, "true") || !g_strcasecmp (prop, "1")) { + ret_val = TRUE; + } else { + ret_val = FALSE; + } + g_free (prop); + } + + return ret_val; +} + +static void gnome_wp_xml_set_bool (const xmlNode * parent, + const gchar * prop_name, gboolean value) { + g_return_if_fail (parent != NULL); + g_return_if_fail (prop_name != NULL); + + if (value) { + xmlSetProp ((xmlNode *) parent, prop_name, "true"); + } else { + xmlSetProp ((xmlNode *) parent, prop_name, "false"); + } +} + +static void gnome_wp_load_legacy (GnomeWPCapplet * capplet) { + FILE * fp; + gchar * foo, * filename; + GdkColor color1, color2; + + filename = g_build_filename (g_get_home_dir (), ".gnome2", + "wallpapers.list", NULL); + + if (g_file_test (filename, G_FILE_TEST_EXISTS)) { + if ((fp = fopen (filename, "r")) != NULL) { + foo = (gchar *) g_malloc (sizeof (gchar) * 4096); + while (fgets (foo, 4096, fp)) { + GnomeWPItem * item; + + if (foo[strlen (foo) - 1] == '\n') { + foo[strlen (foo) - 1] = '\0'; + } + + item = g_hash_table_lookup (capplet->wphash, foo); + if (item != NULL) { + continue; + } + + item = g_new0 (GnomeWPItem, 1); + + item->filename = g_strdup (foo); + + 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); + + item->description = g_strdup_printf ("%s\n%s (%LuK)", + item->name, + gnome_vfs_mime_get_description (item->fileinfo->mime_type), + item->fileinfo->size / 1024); + + g_hash_table_insert (capplet->wphash, g_strdup (item->filename), item); + } else { + gnome_wp_item_free (item); + } + } + fclose (fp); + g_free (foo); + } + } +} + +static void gnome_wp_xml_load_xml (GnomeWPCapplet * capplet, + const gchar * filename) { + xmlDoc * wplist; + xmlNode * root, * list, * wpa; + GdkColor color1, color2; + + wplist = xmlParseFile (filename); + + root = xmlDocGetRootElement (wplist); + + g_return_if_fail (root != NULL); + + for (list = root->children; list != NULL; list = list->next) { + if (!strcmp (list->name, "wallpaper")) { + GnomeWPItem * wp; + + wp = g_new0 (GnomeWPItem, 1); + + wp->deleted = gnome_wp_xml_get_bool (list, "deleted"); + + for (wpa = list->children; wpa != NULL; wpa = wpa->next) { + if (!strcmp (wpa->name, "filename")) { + if (wpa->last != NULL) { + wp->filename = g_strdup (g_strstrip (wpa->last->content)); + } else { + break; + } + } else if (!strcmp (wpa->name, "name")) { + if (wpa->last != NULL) { + wp->name = g_strdup (g_strstrip (wpa->last->content)); + } + } else if (!strcmp (wpa->name, "imguri")) { + if (wpa->last != NULL) { + wp->imguri = g_strdup (g_strstrip (wpa->last->content)); + } + } else if (!strcmp (wpa->name, "options")) { + if (wpa->last != NULL) { + wp->options = g_strdup (g_strstrip (wpa->last->content)); + } else { + wp->options = gconf_client_get_string (capplet->client, + WP_OPTIONS_KEY, NULL); + } + } else if (!strcmp (wpa->name, "shade_type")) { + if (wpa->last != NULL) { + wp->shade_type = g_strdup (g_strstrip (wpa->last->content)); + } + } else if (!strcmp (wpa->name, "pcolor")) { + if (wpa->last != NULL) { + wp->pri_color = g_strdup (g_strstrip (wpa->last->content)); + } + } else if (!strcmp (wpa->name, "scolor")) { + if (wpa->last != NULL) { + wp->sec_color = g_strdup (g_strstrip (wpa->last->content)); + } + } else if (!strcmp (wpa->name, "text")) { + /* Do nothing here, libxml2 is being weird */ + } else { + g_warning ("Unknown Tag: %s\n", wpa->name); + } + } + + /* Verify the colors and alloc some GdkColors here */ + if (wp->shade_type == NULL) { + wp->shade_type = gconf_client_get_string (capplet->client, + WP_SHADING_KEY, NULL); + } + if (wp->pri_color == NULL) { + wp->pri_color = gconf_client_get_string (capplet->client, + WP_PCOLOR_KEY, NULL); + } + if (wp->sec_color == NULL) { + wp->sec_color = gconf_client_get_string (capplet->client, + WP_SCOLOR_KEY, NULL); + } + gdk_color_parse (wp->pri_color, &color1); + gdk_color_parse (wp->sec_color, &color2); + + wp->pcolor = gdk_color_copy (&color1); + wp->scolor = gdk_color_copy (&color2); + + if ((wp->filename != NULL && + g_file_test (wp->filename, G_FILE_TEST_EXISTS)) || + !strcmp (wp->filename, "(none)")) { + wp->fileinfo = gnome_wp_info_new (wp->filename, capplet->thumbs); + if (wp->name == NULL) { + wp->name = g_strdup (wp->fileinfo->name); + } + + if (!strcmp (wp->filename, "(none)")) { + wp->description = g_strdup_printf ("%s", wp->name); + } else { + wp->description = g_strdup_printf ("%s\n%s (%LuK)", + wp->name, + gnome_vfs_mime_get_description (wp->fileinfo->mime_type), + wp->fileinfo->size / 1024); + } + g_hash_table_insert (capplet->wphash, g_strdup (wp->filename), wp); + } else { + gnome_wp_item_free (wp); + } + } + } + xmlFreeDoc (wplist); +} + +static void gnome_wp_file_changed (GnomeVFSMonitorHandle * handle, + const gchar * monitor_uri, + const gchar * info_uri, + GnomeVFSMonitorEventType event_type, + GnomeWPCapplet * capplet) { + gchar * filename; + + switch (event_type) { + case GNOME_VFS_MONITOR_EVENT_CHANGED: + case GNOME_VFS_MONITOR_EVENT_CREATED: + filename = gnome_vfs_get_local_path_from_uri (info_uri); + gnome_wp_xml_load_xml (capplet, filename); + g_free (filename); + default: + break; + } +} + +void gnome_wp_xml_load_list (GnomeWPCapplet * capplet) { + GnomeVFSMonitorHandle * handle; + GList * list, * l; + gchar * wpdbfile, * xdgdirslist; + gchar ** xdgdirs; + gint i; + + wpdbfile = g_build_filename (g_get_home_dir (), + ".gnome2", + "wp-list.xml", + NULL); + + if (g_file_test (wpdbfile, G_FILE_TEST_EXISTS)) { + gnome_wp_xml_load_xml (capplet, wpdbfile); + } + g_free (wpdbfile); + + xdgdirslist = g_strdup (g_getenv ("XDG_DATA_DIRS")); + if (xdgdirslist == NULL || strlen (xdgdirslist) == 0) + xdgdirslist = g_strdup ("/usr/local/share:/usr/share"); + + xdgdirs = g_strsplit (xdgdirslist, ":", -1); + for (i = 0; xdgdirs && xdgdirs[i]; i++) { + gchar * datadir; + + datadir = g_build_filename (xdgdirs[i], "gnome-wallpaper-properties", + NULL); + if (g_file_test (datadir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + gnome_vfs_directory_list_load (&list, datadir, + GNOME_VFS_FILE_INFO_DEFAULT | + GNOME_VFS_FILE_INFO_FOLLOW_LINKS); + + for (l = list; l != NULL; l = l->next) { + GnomeVFSFileInfo * info = l->data; + + if (strcmp (".", info->name) != 0 && strcmp ("..", info->name) != 0) { + gchar * filename; + + filename = g_build_filename (datadir, info->name, NULL); + gnome_wp_xml_load_xml (capplet, filename); + g_free (filename); + } + } + g_list_free (list); + + gnome_vfs_monitor_add (&handle, datadir, GNOME_VFS_MONITOR_DIRECTORY, + (GnomeVFSMonitorCallback) gnome_wp_file_changed, + capplet); + } + g_free (datadir); + } + g_strfreev (xdgdirs); + g_free (xdgdirslist); + + wpdbfile = g_build_filename (DATADIR, "gnome-wallpaper-properties", NULL); + if (g_file_test (wpdbfile, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)) { + gnome_vfs_directory_list_load (&list, wpdbfile, + GNOME_VFS_FILE_INFO_DEFAULT | + GNOME_VFS_FILE_INFO_FOLLOW_LINKS); + + for (l = list; l != NULL; l = l->next) { + GnomeVFSFileInfo * info = l->data; + + if (strcmp (".", info->name) != 0 && strcmp ("..", info->name) != 0) { + gchar * filename; + + filename = g_build_filename (wpdbfile, info->name, NULL); + gnome_wp_xml_load_xml (capplet, filename); + g_free (filename); + } + } + g_list_free (list); + + gnome_vfs_monitor_add (&handle, wpdbfile, GNOME_VFS_MONITOR_DIRECTORY, + (GnomeVFSMonitorCallback) gnome_wp_file_changed, + capplet); + } + g_free (wpdbfile); + + gnome_wp_load_legacy (capplet); +} + +static void gnome_wp_list_flatten (const gchar * key, GnomeWPItem * item, + GList ** list) { + g_return_if_fail (key != NULL); + g_return_if_fail (item != NULL); + + *list = g_list_append (*list, item); +} + +void gnome_wp_xml_save_list (GnomeWPCapplet * capplet) { + xmlDoc * wplist; + xmlNode * root, * wallpaper, * item; + GList * list = NULL, * wp = NULL; + gchar * wpfile; + + g_hash_table_foreach (capplet->wphash, + (GHFunc) gnome_wp_list_flatten, &list); + + wpfile = g_strconcat (g_get_home_dir (), "/.gnome2/wp-list.xml", NULL); + + xmlKeepBlanksDefault (0); + + wplist = xmlNewDoc ("1.0"); + xmlCreateIntSubset (wplist, "wallpapers", NULL, "gnome-wp-list.dtd"); + root = xmlNewNode (NULL, "wallpapers"); + xmlDocSetRootElement (wplist, root); + + for (wp = list; wp != NULL; wp = wp->next) { + GnomeWPItem * wpitem = wp->data; + + wallpaper = xmlNewChild (root, NULL, "wallpaper", NULL); + gnome_wp_xml_set_bool (wallpaper, "deleted", wpitem->deleted); + item = xmlNewTextChild (wallpaper, NULL, "name", wpitem->name); + item = xmlNewTextChild (wallpaper, NULL, "filename", wpitem->filename); + item = xmlNewTextChild (wallpaper, NULL, "options", wpitem->options); + item = xmlNewTextChild (wallpaper, NULL, "shade_type", wpitem->shade_type); + item = xmlNewTextChild (wallpaper, NULL, "pcolor", wpitem->pri_color); + item = xmlNewTextChild (wallpaper, NULL, "scolor", wpitem->sec_color); + } + xmlSaveFormatFile (wpfile, wplist, 1); + xmlFreeDoc (wplist); + g_free (wpfile); +} + diff --git a/capplets/background/gnome-wp-xml.h b/capplets/background/gnome-wp-xml.h new file mode 100644 index 000000000..a882336aa --- /dev/null +++ b/capplets/background/gnome-wp-xml.h @@ -0,0 +1,28 @@ +/* + * Authors: Rodney Dawes + * + * Copyright 2003 Novell, Inc. (www.novell.com) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License + * as published by the Free Software Foundation + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. + * + */ + +#ifndef _GNOME_WP_XML_H_ +#define _GNOME_WP_XML_H_ + +void gnome_wp_xml_load_list (GnomeWPCapplet * capplet); +void gnome_wp_xml_save_list (GnomeWPCapplet * capplet); + +#endif +