[Buoh-dev] CVS commit to /cvsroot/buoh/buoh/src by carlosgc



CVS commit to /cvsroot/buoh/buoh/src by carlosgc

Modified Files:
	buoh-comic-cache.c buoh-comic.c buoh-comic.h buoh-window.c 
	buoh.c 
Log Message:
2005-12-01  Carlos Garcia Campos  <carlosgc gnome org>
	* src/buoh-comic.[ch]: Add buoh_comic_image_save for saving an image
	to disk
	* src/buoh-window.c: Save the original image instead of a new png when
	saving a copy.
	* src/buoh-comic-cache.c: Use buoh_comic_image_save for saving to disk
	* src/buoh.c: Use 644 instead of 755 for creating the user comics
	file when GTK+ version <= 2.6

===================================================================
RCS file: /cvsroot/buoh/buoh/src/buoh-comic-cache.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /cvsroot/buoh/buoh/src/buoh-comic-cache.c	2005/11/30 10:48:02	1.3
+++ /cvsroot/buoh/buoh/src/buoh-comic-cache.c	2005/12/01 21:55:27	1.4
@@ -198,7 +198,7 @@
 			  BuohComicImage *image)
 {
 	gchar  *path;
-	gint    fd;
+	GError *error = NULL;
 
 	g_assert (uri != NULL);
 	g_assert (image != NULL);
@@ -213,21 +213,10 @@
 		g_free (path);
 		return;
 	}
-	
-	if ((fd = open (path, O_CREAT | O_WRONLY, 0644)) < 0) {
-		g_warning ("Error saving %s to disk", uri);
-		g_free (path);
-		return;
-	}
-
-	if (write (fd, image->data, image->size) < 0) {
-		g_warning ("Error saving %s to disk", uri);
-		close (fd);
-		g_free (path);
-		return;
-	}
 
-	if (close (fd) < 0) {
+	if (!buoh_comic_image_save (image, path, &error)) {
+		g_warning (error->message);
+		g_error_free (error);
 		g_free (path);
 		return;
 	}
@@ -367,10 +356,13 @@
 		item = g_list_find_custom (cache->priv->image_list,
 					   (gconstpointer) uri,
 					   (GCompareFunc) g_ascii_strcasecmp);
-		cache->priv->image_list = g_list_remove_link (cache->priv->image_list,
-							      item);
-		cache->priv->image_list = g_list_prepend (cache->priv->image_list, item->data);
-		g_list_free (item);
+		if (item != cache->priv->image_list) {
+			cache->priv->image_list = g_list_remove_link (cache->priv->image_list,
+								      item);
+			cache->priv->image_list = g_list_prepend (cache->priv->image_list,
+								  item->data);
+			g_list_free (item);
+		}
 		
 		buoh_debug ("CACHE: return image from memory");
 		return image;
===================================================================
RCS file: /cvsroot/buoh/buoh/src/buoh-comic.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- /cvsroot/buoh/buoh/src/buoh-comic.c	2005/11/30 10:48:02	1.11
+++ /cvsroot/buoh/buoh/src/buoh-comic.c	2005/12/01 21:55:27	1.12
@@ -19,6 +19,11 @@
 
 #include <glib.h>
 #include <glib/gi18n.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
 
 #include "buoh.h"
 #include "buoh-comic.h"
@@ -449,6 +454,44 @@
 	return filename;
 }
 
+gboolean
+buoh_comic_image_save (BuohComicImage *image,
+		       const gchar    *path,
+		       GError        **error)
+{
+	g_return_val_if_fail (image != NULL && image->data != NULL, FALSE);
+	g_return_val_if_fail (path != NULL, FALSE);
+
+	gint fd;
+
+	if ((fd = open (path, O_CREAT | O_WRONLY, 0644)) < 0) {
+		g_set_error (error, G_FILE_ERROR,
+			     g_file_error_from_errno (errno),
+			     _("Cannot create file '%s': %s"),
+			     path, g_strerror (errno));
+		return FALSE;
+	}
+
+	if (write (fd, image->data, image->size) < 0) {
+		g_set_error (error, G_FILE_ERROR,
+			     g_file_error_from_errno (errno),
+			     _("Error writting to file '%s': %s"),
+			     path, g_strerror (errno));
+		close (fd);
+		return FALSE;
+	}
+
+	if (close (fd) < 0) {
+		g_set_error (error, G_FILE_ERROR,
+			     g_file_error_from_errno (errno),
+			     _("Error writting to file '%s': %s"),
+			     path, g_strerror (errno));
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
 void
 buoh_comic_image_free (BuohComicImage *image)
 {
===================================================================
RCS file: /cvsroot/buoh/buoh/src/buoh-comic.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- /cvsroot/buoh/buoh/src/buoh-comic.h	2005/11/30 10:48:02	1.7
+++ /cvsroot/buoh/buoh/src/buoh-comic.h	2005/12/01 21:55:27	1.8
@@ -79,6 +79,9 @@
 GdkPixbuf *buoh_comic_get_thumbnail        (BuohComic      *comic);
 gchar     *buoh_comic_get_filename         (BuohComic      *comic);
 
+gboolean   buoh_comic_image_save           (BuohComicImage *image,
+					    const gchar    *path,
+					    GError        **error);
 void       buoh_comic_image_free           (BuohComicImage *image);
 
 G_END_DECLS
===================================================================
RCS file: /cvsroot/buoh/buoh/src/buoh-window.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- /cvsroot/buoh/buoh/src/buoh-window.c	2005/11/16 20:40:22	1.30
+++ /cvsroot/buoh/buoh/src/buoh-window.c	2005/12/01 21:55:27	1.31
@@ -540,20 +540,16 @@
 	GtkWidget        *chooser;
 	GtkFileFilter    *filter;
 	gchar            *suggested;
-	gchar            *basename;
-	gchar            *extension;
-	gchar            *filename = NULL;
 	static gchar     *folder = NULL;
 	BuohWindow       *window = BUOH_WINDOW (gdata);
 	BuohComic        *comic;
-	GdkPixbuf        *pixbuf;
+	BuohComicImage   *image;
 	GtkWidget        *dialog;
 	gboolean          successful;
-	GError           *error;
 
 	filter = gtk_file_filter_new ();
-	gtk_file_filter_add_pattern (filter, "*.png");
-	gtk_file_filter_set_name (filter, _("PNG Images"));
+	gtk_file_filter_set_name (filter, _("Images"));
+	gtk_file_filter_add_pixbuf_formats (filter);
 
 	chooser = gtk_file_chooser_dialog_new (_("Save Comic"),
 					       GTK_WINDOW (window),
@@ -572,22 +568,18 @@
 	}
 
 	comic  = buoh_view_get_comic (window->priv->view);
-	pixbuf = buoh_comic_get_pixbuf (comic);
-	
-	/* Change the extension to .png */
-	filename = buoh_comic_get_filename (comic);
-	extension = g_strrstr (filename, ".");
-	basename = g_strndup (filename, strlen (filename) - strlen (extension));
-	suggested = g_strconcat (basename, ".png", NULL);
-	
-	g_free (basename);
-	g_free (filename);
+	image = buoh_comic_get_image (comic);
 	
+	suggested = buoh_comic_get_filename (comic);
 	gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (chooser),
 					   suggested);
+	g_free (suggested);
 
 	do {
 		if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT) {
+			gchar  *filename;
+			GError *error = NULL;
+			
 			filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
 
 			if (folder != NULL)
@@ -595,9 +587,7 @@
 
 			folder = gtk_file_chooser_get_current_folder_uri (GTK_FILE_CHOOSER (chooser));
 
-			error = NULL;
-
-			if (!gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL)) {
+			if (!buoh_comic_image_save (image, filename, &error)) {
 				successful = FALSE;
 
 				dialog = gtk_message_dialog_new (GTK_WINDOW (chooser),
@@ -622,8 +612,6 @@
 		}
 	} while (!successful);
 
-//	g_object_unref (pixbuf);
-	g_free (suggested);
 	gtk_widget_destroy (chooser);
 }
 
===================================================================
RCS file: /cvsroot/buoh/buoh/src/buoh.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- /cvsroot/buoh/buoh/src/buoh.c	2005/11/21 19:44:13	1.27
+++ /cvsroot/buoh/buoh/src/buoh.c	2005/12/01 21:55:27	1.28
@@ -354,14 +354,14 @@
 }
 
 static gboolean
-buoh_create_comics_file (Buoh *buoh, const char *filename, const char *contents)
+buoh_create_comics_file (Buoh *buoh, const gchar *filename, const gchar *contents)
 {
 #if GTK_CHECK_VERSION(2,8,0)
 	return g_file_set_contents (filename, contents, -1, NULL);
 #else
-	int fd;
+	gint fd;
 
-	if ((fd = open (filename, O_CREAT | O_WRONLY, 0755)) < 0) {
+	if ((fd = open (filename, O_CREAT | O_WRONLY, 0644)) < 0) {
 		return FALSE;
 	}
 



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