From 0dfb205f6ae400c996093098102e089f6140a09e Mon Sep 17 00:00:00 2001 From: David Moore Date: Mon, 22 Dec 2003 14:50:57 +0000 Subject: Implemented; sets an image attachment as the GNOME wallpaper. 2003-12-22 David Moore * em-popup.c (emp_part_popup_set_background): Implemented; sets an image attachment as the GNOME wallpaper. * em-utils.c (emu_save_part_done): Created a prototype at the top of the file. (em_utils_save_part_to_file): Added; save a message part to a specified file on disk. svn path=/trunk/; revision=23998 --- mail/em-popup.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) (limited to 'mail/em-popup.c') diff --git a/mail/em-popup.c b/mail/em-popup.c index 8312be3770..e1efd4f268 100644 --- a/mail/em-popup.c +++ b/mail/em-popup.c @@ -22,8 +22,15 @@ #include #include #include +#include +#include #include +#include +#include + +#include + static void emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data); struct _EMPopupFactory { @@ -602,8 +609,67 @@ emp_part_popup_saveas(GtkWidget *w, EMPopupTarget *t) static void emp_part_popup_set_background(GtkWidget *w, EMPopupTarget *t) { - /* set as background ... */ - printf("UNIMPLEMENTED: set background, but it would be cool, no?\n"); + GConfClient *gconf; + char *str, *filename, *path, *extension; + unsigned int i=1; + + filename = g_strdup(camel_mime_part_get_filename(t->data.part.part)); + + /* if filename is blank, create a default filename based on MIME type */ + if (!filename || !filename[0]) { + CamelContentType *ct; + + ct = camel_mime_part_get_content_type(t->data.part.part); + g_free (filename); + filename = g_strdup_printf (_("untitled_image.%s"), ct->subtype); + } + + e_filename_make_safe(filename); + + path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", filename, NULL); + + extension = strrchr(filename, '.'); + if (extension) + *extension++ = 0; + + /* if file exists, stick a (number) on the end */ + while (g_file_test(path, G_FILE_TEST_EXISTS)) { + char *name; + name = g_strdup_printf(extension?"%s (%d).%s":"%s (%d)", filename, i++, extension); + g_free(path); + path = g_build_filename(g_get_home_dir(), ".gnome2", "wallpapers", name, NULL); + g_free(name); + } + + g_free(filename); + + if (em_utils_save_part_to_file(w, path, t->data.part.part)) { + gconf = gconf_client_get_default(); + + /* if the filename hasn't changed, blank the filename before + * setting it so that gconf detects a change and updates it */ + if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_filename", NULL)) != NULL + && strcmp (str, path) == 0) { + gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", "", NULL); + } + + g_free (str); + gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", path, NULL); + + /* if GNOME currently doesn't display a picture, set to "wallpaper" + * display mode, otherwise leave it alone */ + if ((str = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_options", NULL)) == NULL + || strcmp(str, "none") == 0) { + gconf_client_set_string(gconf, "/desktop/gnome/background/picture_options", "wallpaper", NULL); + } + + gconf_client_suggest_sync(gconf, NULL); + + g_free(str); + g_object_unref(gconf); + } + + g_free(path); } static void -- cgit v1.2.3