Re: Re: [evolution-patches] Bounty Hunt patch: Set wallpaper from



New patch attached.

> We shouldn't just store the image as "~/.background/" really. It adds
yet another dot-file to deal with. If we had an implementation for the
XDG Spec to use, I would suggest using the more appropriate path of
"$XDG_DATA_HOME/Wallpapers/$filename", but maybe we can just use a path
of "~/.gnome2/Wallpapers/$filename" for now instead.

Okay, changed. I'm using ~/.gnome2/backgrounds because "background" seems to be the official GNOME terminology here (it's what the control-center applet is named, at any rate).

> What you want to do is, if the full string for the gconf key is the same
as what you are aout to set it to, do nothing, otherwise, set it to the
new image filename

The trouble with that is that GNOME won't register a change unless you modify the gconf key. So just doing nothing would leave the old image in place until the next login. Maybe there's a better way to force GNOME to update the background, but I don't know of any. In any case, it doesn't really matter much now, because the images aren't all overwriting each other in the same .background file any more.

> You want to default to "wallpaper", not "stretched". This prevents very
small images from being stretched up to a very large screen. Another
good default might be "centered", since it avoids the stretching issue
as well.

I see your point, but I don't know too many people who tile/center background images - they all stretch them. Anyway, it defaults to "wallpaper" now.

> 
> From: Rodney Dawes <dobey ximian com>
> Date: 2003/11/26 Wed PM 01:11:12 EST
> To: David Moore <davmre bellsouth net>
> CC: Not Zed <notzed ximian com>,  evolution-patches lists ximian com
> Subject: Re: Re: [evolution-patches] Bounty Hunt patch: Set wallpaper from
> 
> 
Index: mail/ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/mail/ChangeLog,v
retrieving revision 1.2901
diff -u -r1.2901 ChangeLog
--- mail/ChangeLog	26 Nov 2003 15:26:42 -0000	1.2901
+++ mail/ChangeLog	26 Nov 2003 20:10:12 -0000
@@ -1,3 +1,13 @@
+2003-11-26  David Moore  <davmre bellsouth net>
+ 
+ 	* em-popup.c (emp_part_popup_set_background): Implemented; sets an 
+	image attachment as the GNOME background image.
+ 	
+ 	* em-utils.c (emu_save_part_done): Created a prototype to the top
+ 	of the file, so it can be called from anywhere within
+ 	(em_utils_save_part_to_file): Added; save a message part to a 
+ 	specified file on disk.
+
 2003-11-26  JP Rosevear  <jpr ximian com>
 
 	* Makefile.am: turn on deprecated Gtk stuff
Index: mail/em-popup.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-popup.c,v
retrieving revision 1.7
diff -u -r1.7 em-popup.c
--- mail/em-popup.c	12 Nov 2003 21:12:59 -0000	1.7
+++ mail/em-popup.c	26 Nov 2003 20:10:13 -0000
@@ -23,6 +23,9 @@
 #include <camel/camel-mime-message.h>
 #include <camel/camel-string-utils.h>
 
+#include <gconf/gconf.h>
+#include <gconf/gconf-client.h>
+
 static void emp_standard_menu_factory(EMPopup *emp, EMPopupTarget *target, void *data);
 
 struct _EMPopupFactory {
@@ -601,8 +604,40 @@
 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 *current_setting, *path;
+	const char *filename;
+	
+	filename = camel_mime_part_get_filename(t->data.part.part);
+	if(filename == NULL)
+		filename = _("Unknown");
+	
+	path=g_build_filename(g_get_home_dir(), ".gnome2", "backgrounds", filename, NULL);
+	
+	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 ((current_setting = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_filename", NULL)) != NULL) {
+			if (strcmp(current_setting, path) == 0)
+				gconf_client_set_string(gconf, "/desktop/gnome/background/picture_filename", "", NULL);
+		}
+		g_free(current_setting);
+		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 ((current_setting = gconf_client_get_string(gconf, "/desktop/gnome/background/picture_options", NULL)) != NULL) {
+			if (strcmp(current_setting, "none") == 0)
+				gconf_client_set_string(gconf, "/desktop/gnome/background/picture_options", "wallpaper", NULL);
+		}
+		g_free(current_setting);
+		
+		g_object_unref(gconf);
+	}
+	
+	g_free(path);
 }
 
 static void
Index: mail/em-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-utils.c,v
retrieving revision 1.8
diff -u -r1.8 em-utils.c
--- mail/em-utils.c	19 Nov 2003 21:22:12 -0000	1.8
+++ mail/em-utils.c	26 Nov 2003 20:10:16 -0000
@@ -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:
@@ -1382,6 +1384,57 @@
 	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;
+	struct stat st;
+		
+	if (filename[0] == 0)
+		return FALSE;
+	
+	if (camel_mkdir(g_path_get_dirname(filename), 0754) == -1) {
+		e_notice (parent, GTK_MESSAGE_ERROR,
+				 _("Cannot save to `%s'\n %s"), filename, g_strerror (errno));
+		return FALSE;
+	}
+
+	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));
+	
+	if (!done) {
+		/* mail_save_part should popup an error box automagically */
+		return FALSE;
+	}
+	
+	return TRUE;
+}
 
 struct _save_messages_data {
 	CamelFolder *folder;
Index: mail/em-utils.h
===================================================================
RCS file: /cvs/gnome/evolution/mail/em-utils.h,v
retrieving revision 1.4
diff -u -r1.4 em-utils.h
--- mail/em-utils.h	27 Oct 2003 21:31:19 -0000	1.4
+++ mail/em-utils.h	26 Nov 2003 20:10:16 -0000
@@ -86,6 +86,7 @@
 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_flag_for_followup (struct _GtkWidget *parent, struct _CamelFolder *folder, GPtrArray *uids);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]