diff options
author | David Moore <davmre@bellsouth.net> | 2003-12-22 22:50:57 +0800 |
---|---|---|
committer | JP Rosevear <jpr@src.gnome.org> | 2003-12-22 22:50:57 +0800 |
commit | 0dfb205f6ae400c996093098102e089f6140a09e (patch) | |
tree | aec28c0766ba978049360a1746c79ff28644e908 /mail | |
parent | 207effbb708067c6316f0c73f5b5ae9ebd341d20 (diff) | |
download | gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar.gz gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar.bz2 gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar.lz gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar.xz gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.tar.zst gsoc2013-evolution-0dfb205f6ae400c996093098102e089f6140a09e.zip |
Implemented; sets an image attachment as the GNOME wallpaper.
2003-12-22 David Moore <davmre@bellsouth.net>
* 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
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 10 | ||||
-rw-r--r-- | mail/em-popup.c | 70 | ||||
-rw-r--r-- | mail/em-utils.c | 54 | ||||
-rw-r--r-- | mail/em-utils.h | 1 |
4 files changed, 132 insertions, 3 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 0575247467..7ff4f83e1e 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,13 @@ +2003-12-22 David Moore <davmre@bellsouth.net> + + * 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. + 2003-12-18 Rodney Dawes <dobey@ximian.com> * em-message-browser.c (emmb_init): Merge in 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 <camel/camel-folder.h> #include <camel/camel-mime-message.h> #include <camel/camel-string-utils.h> +#include <camel/camel-mime-utils.h> +#include <camel/camel-mime-part.h> #include <camel/camel-url.h> +#include <gconf/gconf.h> +#include <gconf/gconf-client.h> + +#include <gal/util/e-util.h> + 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 diff --git a/mail/em-utils.c b/mail/em-utils.c index e2da2fa6d3..4e93f2801c 100644 --- a/mail/em-utils.c +++ b/mail/em-utils.c @@ -33,6 +33,7 @@ #include <camel/camel-stream-fs.h> #include <camel/camel-url-scanner.h> +#include <camel/camel-file-utils.h> #include <filter/filter-editor.h> @@ -52,6 +53,7 @@ #include "em-format-quote.h" static EAccount *guess_account (CamelMimeMessage *message); +static void emu_save_part_done (CamelMimePart *part, char *name, int done, void *data); /** * em_utils_prompt_user: @@ -1387,6 +1389,55 @@ em_utils_save_part(GtkWidget *parent, const char *prompt, CamelMimePart *part) gtk_widget_show((GtkWidget *)filesel); } +/** + * em_utils_save_part_to_file: + * @parent: parent window + * @filename: filename to save to + * @part: part to save + * + * Save a part's content to a specific file + * Creates all needed directories and overwrites without prompting + * + * Returns %TRUE if saving succeeded, %FALSE otherwise + **/ +gboolean +em_utils_save_part_to_file(GtkWidget *parent, const char *filename, CamelMimePart *part) +{ + int done; + char *dirname; + struct stat st; + + if (filename[0] == 0) + return FALSE; + + dirname = g_path_get_dirname(filename); + if (camel_mkdir(dirname, 0777) == -1) { + e_notice(parent, GTK_MESSAGE_ERROR, + _("Cannot save to `%s'\n %s"), filename, g_strerror(errno)); + g_free(dirname); + return FALSE; + } + g_free(dirname); + + if (access(filename, F_OK) == 0) { + if (access(filename, W_OK) != 0) { + e_notice(parent, GTK_MESSAGE_ERROR, + _("Cannot save to `%s'\n %s"), filename, g_strerror(errno)); + return FALSE; + } + } + + if (stat(filename, &st) != -1 && !S_ISREG(st.st_mode)) { + e_notice(parent, GTK_MESSAGE_ERROR, + _("Error: '%s' exists and is not a regular file"), filename); + return FALSE; + } + + /* FIXME: This doesn't handle default charsets */ + mail_msg_wait(mail_save_part(part, filename, emu_save_part_done, &done)); + + return done; +} struct _save_messages_data { CamelFolder *folder; @@ -2258,7 +2309,8 @@ em_utils_expunge_folder (GtkWidget *parent, CamelFolder *folder) camel_object_get(folder, NULL, CAMEL_OBJECT_DESCRIPTION, &name, 0); - if (!em_utils_prompt_user(parent, GTK_RESPONSE_NO, "/apps/evolution/mail/prompts/expunge", + if (!em_utils_prompt_user(parent, GTK_RESPONSE_NO, + "/apps/evolution/mail/prompts/expunge", _("This operation will permanently remove all deleted messages " "in the folder `%s'. If you continue, you " "will not be able to recover these messages.\n" diff --git a/mail/em-utils.h b/mail/em-utils.h index 502b52e19d..f0d8e4249a 100644 --- a/mail/em-utils.h +++ b/mail/em-utils.h @@ -86,6 +86,7 @@ void em_utils_reply_to_message_by_uid (struct _CamelFolder *folder, const char * void em_utils_post_reply_to_message_by_uid (struct _CamelFolder *folder, const char *uid); void em_utils_save_part(struct _GtkWidget *parent, const char *prompt, struct _CamelMimePart *part); +gboolean em_utils_save_part_to_file(struct _GtkWidget *parent, const char *filename, struct _CamelMimePart *part); void em_utils_save_messages (struct _GtkWidget *parent, struct _CamelFolder *folder, GPtrArray *uids); void em_utils_add_address(struct _GtkWidget *parent, const char *email); |