From 0ecfeba326af04a2b9cd27776aa84827f1f638a7 Mon Sep 17 00:00:00 2001
From: "Nickolay V. Shmyrev" <nshmyrev@src.gnome.org>
Date: Mon, 17 Oct 2005 18:41:22 +0000
Subject: [PATCH] Save a copy implemented for various backends.

	* configure.ac:
	* djvu/djvu-document.c: (djvu_document_load), (djvu_document_save),
	(djvu_document_finalize):
	* dvi/dvi-document.c: (dvi_document_load), (dvi_document_save),
	(dvi_document_finalize):
	* pixbuf/pixbuf-document.c: (pixbuf_document_load),
	(pixbuf_document_save), (pixbuf_document_finalize):
	* tiff/tiff-document.c: (tiff_document_load), (tiff_document_save),
	(tiff_document_finalize):

	Save a copy implemented for various backends.
---
 ChangeLog                | 16 +++++++++++++++-
 configure.ac             |  2 +-
 djvu/djvu-document.c     | 38 ++++++++++++++++++++++++++++++++++++--
 dvi/dvi-document.c       | 37 ++++++++++++++++++++++++++++++++++++-
 pixbuf/pixbuf-document.c | 38 ++++++++++++++++++++++++++++++++++++--
 tiff/tiff-document.c     | 39 +++++++++++++++++++++++++++++++++++++--
 6 files changed, 161 insertions(+), 9 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5df13cc9..591a3056 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,18 @@
-2005-10-17  Daniel Gryniewicz <dang@gentoo.org >
+2005-10-17  Nickolay V. Shmyrev  <<nshmyrev@yandex.ru>>
+
+	* configure.ac:
+	* djvu/djvu-document.c: (djvu_document_load), (djvu_document_save),
+	(djvu_document_finalize):
+	* dvi/dvi-document.c: (dvi_document_load), (dvi_document_save),
+	(dvi_document_finalize):
+	* pixbuf/pixbuf-document.c: (pixbuf_document_load),
+	(pixbuf_document_save), (pixbuf_document_finalize):
+	* tiff/tiff-document.c: (tiff_document_load), (tiff_document_save),
+	(tiff_document_finalize):
+	
+	Save a copy implemented for various backends.
+
+2005-10-17  Daniel Gryniewicz <dang@gentoo.org>
 
 	* configure.ac:
 	
diff --git a/configure.ac b/configure.ac
index 3fd1e9b4..a85e6f87 100644
--- a/configure.ac
+++ b/configure.ac
@@ -50,7 +50,7 @@ LIBGNOMEUI_REQUIRED=2.6.0
 KEYRING_REQUIRED=0.4.2
 
 PKG_CHECK_MODULES(LIB, gtk+-2.0 >= $GTK_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED)
-PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED)
+PKG_CHECK_MODULES(BACKEND, gtk+-2.0 >= $GTK_REQUIRED gnome-vfs-2.0)
 PKG_CHECK_MODULES(FRONTEND_CORE, gtk+-2.0 >= $GTK_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED libglade-2.0 poppler-glib >= $POPPLER_REQUIRED)
 PKG_CHECK_MODULES(POPPLER, poppler-glib >= $POPPLER_REQUIRED)
 PKG_CHECK_MODULES(SHELL_CORE, gtk+-2.0 >= $GTK_REQUIRED libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED gnome-vfs-2.0 libgnomeprint-2.2 >= 2.5.1 libgnomeprintui-2.2 libglade-2.0 gconf-2.0 poppler-glib >= $POPPLER_REQUIRED gnome-keyring-1 >= $KEYRING_REQUIRED)
diff --git a/djvu/djvu-document.c b/djvu/djvu-document.c
index 9f22537f..38147875 100644
--- a/djvu/djvu-document.c
+++ b/djvu/djvu-document.c
@@ -25,6 +25,11 @@
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixbuf-core.h>
 
+#include <libgnomevfs/gnome-vfs-uri.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-xfer.h>
+
 #define SCALE_FACTOR 0.2
 
 enum {
@@ -44,6 +49,8 @@ struct _DjvuDocument
 	ddjvu_context_t  *d_context;
 	ddjvu_document_t *d_document;
 	ddjvu_format_t   *d_format;
+	
+	gchar *uri;
 };
 
 typedef struct _DjvuDocumentClass DjvuDocumentClass;
@@ -85,6 +92,8 @@ djvu_document_load (EvDocument  *document,
 		    ddjvu_message_wait (djvu_document->d_context);
 		    ddjvu_message_pop (djvu_document->d_context);	
 	}
+	g_free (djvu_document->uri);
+	djvu_document->uri = g_strdup (uri);
 
 	return TRUE;
 }
@@ -95,8 +104,32 @@ djvu_document_save (EvDocument  *document,
 		      const char  *uri,
 		      GError     **error)
 {
-	g_warning ("djvu_document_save not implemented"); /* FIXME */
-	return TRUE;
+	DjvuDocument *djvu_document = DJVU_DOCUMENT (document);
+	GnomeVFSResult result;
+	GnomeVFSURI *source_uri;
+	GnomeVFSURI *target_uri;
+	
+	if (!djvu_document->uri)
+		return FALSE;
+	
+	source_uri = gnome_vfs_uri_new (djvu_document->uri);
+	target_uri = gnome_vfs_uri_new (uri);
+
+	result = gnome_vfs_xfer_uri (source_uri, target_uri, 
+				     GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
+				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
+				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+				     NULL,
+				     NULL);
+	gnome_vfs_uri_unref (target_uri);
+	gnome_vfs_uri_unref (source_uri);
+    
+	if (result != GNOME_VFS_OK)
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     0,
+			     gnome_vfs_result_to_string (result));			
+	return (result == GNOME_VFS_OK);
 }
 
 static int
@@ -182,6 +215,7 @@ djvu_document_finalize (GObject *object)
 
 	ddjvu_context_release (djvu_document->d_context);
 	ddjvu_format_release (djvu_document->d_format);
+	g_free (djvu_document->uri);
 	
 	G_OBJECT_CLASS (djvu_document_parent_class)->finalize (object);
 }
diff --git a/dvi/dvi-document.c b/dvi/dvi-document.c
index d4627580..6ecbc3a2 100644
--- a/dvi/dvi-document.c
+++ b/dvi/dvi-document.c
@@ -29,6 +29,10 @@
 
 #include <gtk/gtk.h>
 #include <glib/gi18n.h>
+#include <libgnomevfs/gnome-vfs-uri.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-xfer.h>
 
 GMutex *dvi_context_mutex = NULL;
 
@@ -54,6 +58,8 @@ struct _DviDocument
 	
 	double base_width;
 	double base_height;
+	
+	gchar *uri;
 };
 
 typedef struct _DviDocumentClass DviDocumentClass;
@@ -113,6 +119,8 @@ dvi_document_load (EvDocument  *document,
 
     dvi_context_mutex = g_mutex_new ();
 
+    g_free (dvi_document->uri);
+    dvi_document->uri = g_strdup (uri);
 
     return TRUE;
 }
@@ -123,7 +131,32 @@ dvi_document_save (EvDocument  *document,
 		      const char  *uri,
 		      GError     **error)
 {
-	g_warning ("dvi_document_save not implemented"); /* FIXME */
+	DviDocument *dvi_document = DVI_DOCUMENT (document);
+	GnomeVFSResult result;
+	GnomeVFSURI *source_uri;
+	GnomeVFSURI *target_uri;
+	
+	if (!dvi_document->uri)
+		return FALSE;
+	
+	source_uri = gnome_vfs_uri_new (dvi_document->uri);
+	target_uri = gnome_vfs_uri_new (uri);
+
+	result = gnome_vfs_xfer_uri (source_uri, target_uri, 
+				     GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
+				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
+				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+				     NULL,
+				     NULL);
+	gnome_vfs_uri_unref (target_uri);
+	gnome_vfs_uri_unref (source_uri);
+    
+	if (result != GNOME_VFS_OK)
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     0,
+			     gnome_vfs_result_to_string (result));			
+	return (result == GNOME_VFS_OK);
 	return TRUE;
 }
 
@@ -210,6 +243,8 @@ dvi_document_finalize (GObject *object)
 
 	if (dvi_document->params)
 		g_free (dvi_document->params);
+
+        g_free (dvi_document->uri);
 		
 	G_OBJECT_CLASS (dvi_document_parent_class)->finalize (object);
 }
diff --git a/pixbuf/pixbuf-document.c b/pixbuf/pixbuf-document.c
index e2bfaca3..f19d2d5e 100644
--- a/pixbuf/pixbuf-document.c
+++ b/pixbuf/pixbuf-document.c
@@ -20,6 +20,11 @@
 #include "pixbuf-document.h"
 #include "ev-document-thumbnails.h"
 
+#include <libgnomevfs/gnome-vfs-uri.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-xfer.h>
+
 struct _PixbufDocumentClass
 {
 	GObjectClass parent_class;
@@ -30,6 +35,8 @@ struct _PixbufDocument
 	GObject parent_instance;
 
 	GdkPixbuf *pixbuf;
+	
+	gchar *uri;
 };
 
 typedef struct _PixbufDocumentClass PixbufDocumentClass;
@@ -65,6 +72,8 @@ pixbuf_document_load (EvDocument  *document,
 		return FALSE;
 
 	pixbuf_document->pixbuf = pixbuf;
+	g_free (pixbuf_document->uri);
+	pixbuf_document->uri = g_strdup (uri);
 	
 	return TRUE;
 }
@@ -74,8 +83,32 @@ pixbuf_document_save (EvDocument  *document,
 		      const char  *uri,
 		      GError     **error)
 {
-	g_warning ("pixbuf_document_save not implemented"); /* FIXME */
-	return TRUE;
+	PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (document);
+	GnomeVFSResult result;
+	GnomeVFSURI *source_uri;
+	GnomeVFSURI *target_uri;
+	
+	if (!pixbuf_document->uri)
+		return FALSE;
+	
+	source_uri = gnome_vfs_uri_new (pixbuf_document->uri);
+	target_uri = gnome_vfs_uri_new (uri);
+
+	result = gnome_vfs_xfer_uri (source_uri, target_uri, 
+				     GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
+				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
+				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+				     NULL,
+				     NULL);
+	gnome_vfs_uri_unref (target_uri);
+	gnome_vfs_uri_unref (source_uri);
+    
+	if (result != GNOME_VFS_OK)
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     0,
+			     gnome_vfs_result_to_string (result));			
+	return (result == GNOME_VFS_OK);
 }
 
 static int
@@ -120,6 +153,7 @@ pixbuf_document_finalize (GObject *object)
 	PixbufDocument *pixbuf_document = PIXBUF_DOCUMENT (object);
 
 	g_object_unref (pixbuf_document->pixbuf);
+	g_free (pixbuf_document->uri);
 	
 	G_OBJECT_CLASS (pixbuf_document_parent_class)->finalize (object);
 }
diff --git a/tiff/tiff-document.c b/tiff/tiff-document.c
index 7831bc6f..cb64678b 100644
--- a/tiff/tiff-document.c
+++ b/tiff/tiff-document.c
@@ -30,6 +30,11 @@
 #include "ev-document-thumbnails.h"
 #include "ev-ps-exporter.h"
 
+#include <libgnomevfs/gnome-vfs-uri.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-ops.h>
+#include <libgnomevfs/gnome-vfs-xfer.h>
+
 struct _TiffDocumentClass
 {
   GObjectClass parent_class;
@@ -42,6 +47,8 @@ struct _TiffDocument
   TIFF *tiff;
   gint n_pages;
   TIFF2PSContext *ps_export_ctx;
+  
+  gchar *uri;
 };
 
 typedef struct _TiffDocumentClass TiffDocumentClass;
@@ -108,6 +115,8 @@ tiff_document_load (EvDocument  *document,
       return FALSE;
     }
   tiff_document->tiff = tiff;
+  g_free (tiff_document->uri);
+  tiff_document->uri = g_strdup (uri);
 
   pop_handlers ();
   return TRUE;
@@ -117,8 +126,33 @@ static gboolean
 tiff_document_save (EvDocument  *document,
 		      const char  *uri,
 		      GError     **error)
-{
-	return FALSE;
+{		
+	TiffDocument *tiff_document = TIFF_DOCUMENT (document);
+	GnomeVFSResult result;
+	GnomeVFSURI *source_uri;
+	GnomeVFSURI *target_uri;
+	
+	if (!tiff_document->uri)
+		return FALSE;
+	
+	source_uri = gnome_vfs_uri_new (tiff_document->uri);
+	target_uri = gnome_vfs_uri_new (uri);
+
+	result = gnome_vfs_xfer_uri (source_uri, target_uri, 
+				     GNOME_VFS_XFER_DEFAULT | GNOME_VFS_XFER_FOLLOW_LINKS,
+				     GNOME_VFS_XFER_ERROR_MODE_ABORT,
+				     GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE,
+				     NULL,
+				     NULL);
+	gnome_vfs_uri_unref (target_uri);
+	gnome_vfs_uri_unref (source_uri);
+    
+	if (result != GNOME_VFS_OK)
+		g_set_error (error,
+			     EV_DOCUMENT_ERROR,
+			     0,
+			     gnome_vfs_result_to_string (result));			
+	return (result == GNOME_VFS_OK);
 }
 
 static int
@@ -269,6 +303,7 @@ tiff_document_finalize (GObject *object)
 	TiffDocument *tiff_document = TIFF_DOCUMENT (object);
 
 	TIFFClose (tiff_document->tiff);
+	g_free (tiff_document->uri);
 
 	G_OBJECT_CLASS (tiff_document_parent_class)->finalize (object);
 }
-- 
2.43.5