evolution r35409 - in trunk: addressbook addressbook/gui/widgets e-util



Author: mcrha
Date: Wed Apr 23 09:19:23 2008
New Revision: 35409
URL: http://svn.gnome.org/viewvc/evolution?rev=35409&view=rev

Log:
2008-04-23  Milan Crha  <mcrha redhat com>

	** Fix for bug #529254

	* e-util/e-util.c: (e_write_file_uri):	Save file properly.
	Handle either URI or filename. Return success or failure, not gint.

	* addressbook/gui/widgets/eab-gui-util.c: (save_it):
	Prototype and return value of e_write_file_uri has been changed.



Modified:
   trunk/addressbook/ChangeLog
   trunk/addressbook/gui/widgets/eab-gui-util.c
   trunk/e-util/ChangeLog
   trunk/e-util/e-util.c
   trunk/e-util/e-util.h

Modified: trunk/addressbook/gui/widgets/eab-gui-util.c
==============================================================================
--- trunk/addressbook/gui/widgets/eab-gui-util.c	(original)
+++ trunk/addressbook/gui/widgets/eab-gui-util.c	Wed Apr 23 09:19:23 2008
@@ -353,7 +353,6 @@
 {
 	const char *filename;
 	char *uri;
-	gint error = 0;
 	gint response = 0;
 
 
@@ -370,8 +369,7 @@
 		}
 	}
 
-	error = e_write_file_uri (uri, info->vcard);
-	if (error != 0) {
+	if (!e_write_file_uri (uri, info->vcard)) {
 		char *err_str_ext;
 		if (info->has_multiple_contacts) {
 			/* more than one, finding the total number of contacts might

Modified: trunk/e-util/e-util.c
==============================================================================
--- trunk/e-util/e-util.c	(original)
+++ trunk/e-util/e-util.c	Wed Apr 23 09:19:23 2008
@@ -161,19 +161,29 @@
 	return (nx == ny) ? 0 : (nx < ny) ? -1 : 1;
 }
 
-gint
+gboolean
 e_write_file_uri (const gchar *filename, const gchar *data)
 {
-	gsize length = strlen (data);
-	gssize bytes;
+	gboolean res;
+	gsize length;
 	GFile *file;
 	GOutputStream *stream;
 	GError *error = NULL;
 
-	file = g_file_new_for_path (filename);
+	g_return_val_if_fail (filename != NULL, FALSE);
+	g_return_val_if_fail (data != NULL, FALSE);
+
+	length = strlen (data);
+
+	/* if it is uri, then create file for uri, otherwise for path */
+	if (strstr (filename, "://"))
+		file = g_file_new_for_uri (filename);
+	else
+		file = g_file_new_for_path (filename);
+
 	if (!file) {
 		g_warning ("Couldn't save item");
-		return 1;
+		return FALSE;
 	}
 
 	stream = G_OUTPUT_STREAM (g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &error));
@@ -188,25 +198,14 @@
 		if (error)
 			g_error_free (error);
 
-		return 1;
+		return FALSE;
 	}
 
-	while (length > 0) {
-		bytes = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
-		if (bytes > 0 && !error) {
-			length -= bytes;
-			data += bytes;
-		} else {
-			g_warning ("Couldn't save item%s%s", error ? ": " : "", error ? error->message : "");
-
-			if (error)
-				g_error_free (error);
-
-			g_output_stream_close (stream, NULL, NULL);
-			g_object_unref (stream);
+	res = g_output_stream_write_all (stream, data, length, NULL, NULL, &error);
 
-			return 1;
-		}
+	if (error) {
+		g_warning ("Couldn't save item: %s", error->message);
+		g_clear_error (&error);
 	}
 
 	g_output_stream_close (stream, NULL, &error);
@@ -217,7 +216,7 @@
 		g_error_free (error);
 	}
 
-	return 0;
+	return res;
 }
 
 /* Include build marshalers */

Modified: trunk/e-util/e-util.h
==============================================================================
--- trunk/e-util/e-util.h	(original)
+++ trunk/e-util/e-util.h	Wed Apr 23 09:19:23 2008
@@ -55,7 +55,7 @@
 						 gconstpointer y);
 gint		e_int_compare                   (gconstpointer x,
 						 gconstpointer y);
-gint		e_write_file_uri		(const gchar *filename,
+gboolean	e_write_file_uri		(const gchar *filename,
 						 const gchar *data);
 
 /* This only makes a filename safe for usage as a filename.



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