Commit f217668f authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

Complete the port to gio/gvfs. Patch by Jesse van den Kieboom. Bug

2008-08-13  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-tab.c:
	* gedit/gedit-document-loader.c:
	* gedit/gedit-local-document-saver.c:
	* gedit/gedit-document-loader.h:
	* gedit/gedit.c:
	* gedit/gedit-gio-document-saver.c:
	* gedit/gedit-gio-document-saver.h:
	* gedit/gedit-io-error-message-area.c:
	* gedit/gedit-gio-document-loader.c:
	* gedit/gedit-gio-document-loader.h:
	* gedit/gedit-mmap-document-loader.c:
	* gedit/gedit-document.c:
	* gedit/gedit-document.h:
	* gedit/gedit-document-saver.c:
	* gedit/Makefile.am:
	* gedit/gedit-document-saver.h:
	* configure.ac:

	Complete the port to gio/gvfs. Patch by Jesse van den Kieboom.
	Bug #506350.


svn path=/trunk/; revision=6388
parent d466f885
2008-08-13 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-tab.c:
* gedit/gedit-document-loader.c:
* gedit/gedit-local-document-saver.c:
* gedit/gedit-document-loader.h:
* gedit/gedit.c:
* gedit/gedit-gio-document-saver.c:
* gedit/gedit-gio-document-saver.h:
* gedit/gedit-io-error-message-area.c:
* gedit/gedit-gio-document-loader.c:
* gedit/gedit-gio-document-loader.h:
* gedit/gedit-mmap-document-loader.c:
* gedit/gedit-document.c:
* gedit/gedit-document.h:
* gedit/gedit-document-saver.c:
* gedit/Makefile.am:
* gedit/gedit-document-saver.h:
* configure.ac:
Complete the port to gio/gvfs. Patch by Jesse van den Kieboom.
Bug #506350.
2008-08-12 Matthias Clasen <mclasen@redhat.com>
Bug 547129 – use standard icon name in file-browser plugin
......
......@@ -164,11 +164,10 @@ dnl ================================================================
PKG_CHECK_MODULES(GEDIT, [
glib-2.0 >= 2.13.0
gio-2.0 >= 2.16.0
gtk+-2.0 >= 2.13.0
gtksourceview-2.0 >= 2.2.0
libgnomeui-2.0 >= 2.16.0
gnome-vfs-2.0 >= 2.16.0
gio-2.0 >= 2.16.0
])
GEDIT_LIBS="${GEDIT_LIBS}"
AC_SUBST(GEDIT_LIBS)
......
......@@ -63,10 +63,10 @@ NOINST_H_FILES = \
gedit-documents-panel.h \
gedit-document-loader.h \
gedit-mmap-document-loader.h \
gedit-gnomevfs-document-loader.h\
gedit-gio-document-loader.h \
gedit-document-saver.h \
gedit-local-document-saver.h \
gedit-gnomevfs-document-saver.h \
gedit-gio-document-saver.h \
gedit-history-entry.h \
gedit-print-job.h \
gedit-print-preview.h \
......@@ -127,10 +127,10 @@ libgedit_la_SOURCES = \
gedit-document.c \
gedit-document-loader.c \
gedit-mmap-document-loader.c \
gedit-gnomevfs-document-loader.c\
gedit-gio-document-loader.c \
gedit-document-saver.c \
gedit-local-document-saver.c \
gedit-gnomevfs-document-saver.c \
gedit-gio-document-saver.c \
gedit-documents-panel.c \
gedit-encodings.c \
gedit-encodings-option-menu.c \
......
......@@ -44,7 +44,7 @@
/* Those are for the the gedit_document_loader_new() factory */
#include "gedit-mmap-document-loader.h"
#include "gedit-gnomevfs-document-loader.h"
#include "gedit-gio-document-loader.h"
G_DEFINE_ABSTRACT_TYPE(GeditDocumentLoader, gedit_document_loader, G_TYPE_OBJECT)
......@@ -367,7 +367,7 @@ gedit_document_loader_new (GeditDocument *doc,
if (gedit_utils_uri_has_file_scheme (uri))
loader_type = GEDIT_TYPE_MMAP_DOCUMENT_LOADER;
else
loader_type = GEDIT_TYPE_GNOMEVFS_DOCUMENT_LOADER;
loader_type = GEDIT_TYPE_GIO_DOCUMENT_LOADER;
loader = GEDIT_DOCUMENT_LOADER (g_object_new (loader_type,
"document", doc,
......@@ -417,11 +417,11 @@ gedit_document_loader_get_uri (GeditDocumentLoader *loader)
/* it may return NULL, it's up to gedit-document handle it */
const gchar *
gedit_document_loader_get_mime_type (GeditDocumentLoader *loader)
gedit_document_loader_get_content_type (GeditDocumentLoader *loader)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), NULL);
return GEDIT_DOCUMENT_LOADER_GET_CLASS (loader)->get_mime_type (loader);
return GEDIT_DOCUMENT_LOADER_GET_CLASS (loader)->get_content_type (loader);
}
time_t
......
......@@ -85,7 +85,7 @@ struct _GeditDocumentLoaderClass
/* VTable */
void (* load) (GeditDocumentLoader *loader);
gboolean (* cancel) (GeditDocumentLoader *loader);
const gchar * (* get_mime_type) (GeditDocumentLoader *loader);
const gchar * (* get_content_type) (GeditDocumentLoader *loader);
time_t (* get_mtime) (GeditDocumentLoader *loader);
goffset (* get_file_size) (GeditDocumentLoader *loader);
goffset (* get_bytes_read) (GeditDocumentLoader *loader);
......@@ -122,7 +122,7 @@ gboolean gedit_document_loader_cancel (GeditDocumentLoader *loader);
#define STDIN_URI "stdin:"
const gchar *gedit_document_loader_get_uri (GeditDocumentLoader *loader);
const gchar *gedit_document_loader_get_mime_type (GeditDocumentLoader *loader);
const gchar *gedit_document_loader_get_content_type (GeditDocumentLoader *loader);
time_t gedit_document_loader_get_mtime (GeditDocumentLoader *loader);
......
......@@ -45,7 +45,7 @@
#include "gedit-enum-types.h"
#include "gedit-local-document-saver.h"
#include "gedit-gnomevfs-document-saver.h"
#include "gedit-gio-document-saver.h"
G_DEFINE_ABSTRACT_TYPE(GeditDocumentSaver, gedit_document_saver, G_TYPE_OBJECT)
......@@ -127,7 +127,6 @@ gedit_document_saver_get_property (GObject *object,
}
}
static void
gedit_document_saver_finalize (GObject *object)
{
......@@ -221,7 +220,7 @@ gedit_document_saver_new (GeditDocument *doc,
if (gedit_utils_uri_has_file_scheme (uri))
saver_type = GEDIT_TYPE_LOCAL_DOCUMENT_SAVER;
else
saver_type = GEDIT_TYPE_GNOMEVFS_DOCUMENT_SAVER;
saver_type = GEDIT_TYPE_GIO_DOCUMENT_SAVER;
if (encoding == NULL)
encoding = gedit_encoding_get_utf8 ();
......@@ -236,28 +235,54 @@ gedit_document_saver_new (GeditDocument *doc,
return saver;
}
/*
* Write the document contents in fd.
*/
gboolean
gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
gint fd,
GError **error)
gchar *
gedit_document_saver_get_end_newline (GeditDocumentSaver *saver,
gsize *len)
{
gchar *n_buffer = NULL;
gsize n_len = 0;
if (saver->encoding != gedit_encoding_get_utf8 ())
{
n_buffer = gedit_convert_from_utf8 ("\n",
-1,
saver->encoding,
&n_len,
NULL);
if (n_buffer == NULL)
{
/* we do not error out for this */
g_warning ("Cannot convert '\\n' to the desired encoding.");
}
}
else
{
n_buffer = g_strdup ("\n");
n_len = 1;
}
*len = n_len;
return n_buffer;
}
/* FIXME: we should rework the code to not need to fetch the
whole buffer in memory. Also encoding conversion should
be done in chunks */
gchar *
gedit_document_saver_get_document_contents (GeditDocumentSaver *saver,
gsize *len,
GError **error)
{
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (saver->document);
GtkTextIter start_iter;
GtkTextIter end_iter;
gchar *contents;
gsize len;
ssize_t written;
gboolean res;
gedit_debug (DEBUG_SAVER);
gtk_text_buffer_get_bounds (buffer, &start_iter, &end_iter);
contents = gtk_text_buffer_get_slice (buffer, &start_iter, &end_iter, TRUE);
len = strlen (contents);
*len = strlen (contents);
if (saver->encoding != gedit_encoding_get_utf8 ())
{
......@@ -265,7 +290,7 @@ gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
gsize new_len;
converted_contents = gedit_convert_from_utf8 (contents,
len,
*len,
saver->encoding,
&new_len,
error);
......@@ -274,14 +299,34 @@ gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
if (*error != NULL)
{
/* Conversion error */
return FALSE;
return NULL;
}
else
{
contents = converted_contents;
len = new_len;
*len = new_len;
}
}
return contents;
}
/*
* Write the document contents in fd.
*/
gboolean
gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
gint fd,
GError **error)
{
gsize len;
ssize_t written;
gboolean res;
gchar *contents;
gedit_debug (DEBUG_SAVER);
contents = gedit_document_saver_get_document_contents (saver, &len, error);
/* make sure we are at the start */
res = (lseek (fd, 0, SEEK_SET) != -1);
......@@ -319,32 +364,19 @@ gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
that we strip the trailing \n when loading the file */
if (res)
{
if (saver->encoding != gedit_encoding_get_utf8 ())
{
gchar *converted_n = NULL;
gsize n_len;
converted_n = gedit_convert_from_utf8 ("\n",
-1,
saver->encoding,
&n_len,
NULL);
gchar *n_buf;
gsize n_len;
if (converted_n == NULL)
{
/* we do not error out for this */
g_warning ("Cannot add '\\n' at the end of the file.");
}
else
{
written = write (fd, converted_n, n_len);
res = (written != -1 && (gsize) written == n_len);
g_free (converted_n);
}
n_buf = gedit_document_saver_get_end_newline (saver, &n_len);
if (n_buf != NULL)
{
written = write (fd, n_buf, n_len);
res = (written != -1 && (gsize) written == n_len);
g_free (n_buf);
}
else
{
res = (write (fd, "\n", 1) == 1);
g_warning ("Cannot add '\\n' at the end of the file.");
}
}
......@@ -352,12 +384,10 @@ gedit_document_saver_write_document_contents (GeditDocumentSaver *saver,
if (!res)
{
GnomeVFSResult result = gnome_vfs_result_from_errno ();
g_set_error (error,
GEDIT_DOCUMENT_ERROR,
result,
gnome_vfs_result_to_string (result));
g_io_error_from_errno (errno),
g_strerror (errno));
}
return res;
......@@ -430,11 +460,11 @@ gedit_document_saver_get_uri (GeditDocumentSaver *saver)
}
const gchar *
gedit_document_saver_get_mime_type (GeditDocumentSaver *saver)
gedit_document_saver_get_content_type (GeditDocumentSaver *saver)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT_SAVER (saver), NULL);
return GEDIT_DOCUMENT_SAVER_GET_CLASS (saver)->get_mime_type (saver);
return GEDIT_DOCUMENT_SAVER_GET_CLASS (saver)->get_content_type (saver);
}
time_t
......
......@@ -86,7 +86,7 @@ struct _GeditDocumentSaverClass
/* VTable */
void (* save) (GeditDocumentSaver *saver,
time_t old_mtime);
const gchar * (* get_mime_type) (GeditDocumentSaver *saver);
const gchar * (* get_content_type) (GeditDocumentSaver *saver);
time_t (* get_mtime) (GeditDocumentSaver *saver);
goffset (* get_file_size) (GeditDocumentSaver *saver);
goffset (* get_bytes_written) (GeditDocumentSaver *saver);
......@@ -103,6 +103,14 @@ GeditDocumentSaver *gedit_document_saver_new (GeditDocument *doc,
const GeditEncoding *encoding,
GeditDocumentSaveFlags flags);
gchar *gedit_document_saver_get_document_contents (
GeditDocumentSaver *saver,
gsize *len,
GError **error);
gchar *gedit_document_saver_get_end_newline (GeditDocumentSaver *saver,
gsize *len);
gboolean gedit_document_saver_write_document_contents (
GeditDocumentSaver *saver,
gint fd,
......@@ -125,7 +133,7 @@ const gchar *gedit_document_saver_get_backup_uri (GeditDocumentSaver *saver);
void *gedit_document_saver_set_backup_uri (GeditDocumentSaver *saver,
const gchar *backup_uri);
const gchar *gedit_document_saver_get_mime_type (GeditDocumentSaver *saver);
const gchar *gedit_document_saver_get_content_type (GeditDocumentSaver *saver);
time_t gedit_document_saver_get_mtime (GeditDocumentSaver *saver);
......
......@@ -132,6 +132,10 @@ struct _GeditDocumentPrivate
/* Search highlighting support variables */
GeditTextRegion *to_search_region;
GtkTextTag *found_tag;
/* Mount operation factory */
GeditMountOperationFactory mount_operation_factory;
gpointer mount_operation_userdata;
};
enum {
......@@ -849,7 +853,9 @@ void
gedit_document_set_uri (GeditDocument *doc,
const gchar *uri)
{
gchar * mime_type = g_strdup (doc->priv->mime_type);
gchar *mime_type;
mime_type = g_strdup (doc->priv->mime_type);
set_uri (doc, uri, mime_type);
g_free (mime_type);
......@@ -976,9 +982,11 @@ document_loader_loaded (GeditDocumentLoader *loader,
if (error == NULL)
{
GtkTextIter iter;
const gchar *mime_type;
const gchar *content_type;
gchar *mime_type;
mime_type = gedit_document_loader_get_mime_type (loader);
content_type = gedit_document_loader_get_content_type (loader);
mime_type = g_content_type_get_mime_type (content_type);
doc->priv->mtime = gedit_document_loader_get_mtime (loader);
......@@ -994,6 +1002,8 @@ document_loader_loaded (GeditDocumentLoader *loader,
/* We already set the uri */
set_uri (doc, NULL, mime_type);
g_free (mime_type);
/* move the cursor at the requested line if any */
if (doc->priv->requested_line_pos > 0)
{
......@@ -1039,7 +1049,7 @@ document_loader_loaded (GeditDocumentLoader *loader,
/* special case creating a named new doc */
else if (doc->priv->create &&
(error->code == GNOME_VFS_ERROR_NOT_FOUND) &&
(error->code == G_IO_ERROR_NOT_FOUND) &&
(gedit_utils_uri_has_file_scheme (doc->priv->uri)))
{
reset_temp_loading_data (doc);
......@@ -1161,10 +1171,13 @@ document_saver_saving (GeditDocumentSaver *saver,
if (error == NULL)
{
const gchar *uri;
const gchar *mime_type;
const gchar *content_type;
gchar *mime_type;
uri = gedit_document_saver_get_uri (saver);
mime_type = gedit_document_saver_get_mime_type (saver);
content_type = gedit_document_saver_get_content_type (saver);
mime_type = g_content_type_get_mime_type (content_type);
doc->priv->mtime = gedit_document_saver_get_mtime (saver);
......@@ -1177,6 +1190,8 @@ document_saver_saving (GeditDocumentSaver *saver,
set_uri (doc, uri, mime_type);
g_free (mime_type);
set_encoding (doc,
doc->priv->requested_encoding,
TRUE);
......@@ -2179,3 +2194,26 @@ gedit_document_get_enable_search_highlighting (GeditDocument *doc)
return (doc->priv->to_search_region != NULL);
}
void
gedit_document_set_mount_operation_factory (GeditDocument *doc,
GeditMountOperationFactory callback,
gpointer userdata)
{
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
doc->priv->mount_operation_factory = callback;
doc->priv->mount_operation_userdata = userdata;
}
GMountOperation *
gedit_document_create_mount_operation (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
if (doc->priv->mount_operation_factory == NULL)
return g_mount_operation_new ();
else
return doc->priv->mount_operation_factory (doc,
doc->priv->mount_operation_userdata);
}
......@@ -135,16 +135,17 @@ struct _GeditDocumentClass
GtkTextIter *end);
};
typedef GMountOperation *(*GeditMountOperationFactory)(GeditDocument *doc,
gpointer userdata);
#define GEDIT_DOCUMENT_ERROR gedit_document_error_quark ()
enum
{
/* start at GNOME_VFS_NUM_ERRORS since we use GnomeVFSResult
* for the error codes */
GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED = GNOME_VFS_NUM_ERRORS,
GEDIT_DOCUMENT_ERROR_NOT_REGULAR_FILE,
/* we use GIO error codes, so start at some high number? */
GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED = 1 << 10,
GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
GEDIT_DOCUMENT_ERROR_TOO_BIG,
GEDIT_DOCUMENT_NUM_ERRORS
};
......@@ -242,6 +243,15 @@ void gedit_document_set_enable_search_highlighting
gboolean gedit_document_get_enable_search_highlighting
(GeditDocument *doc);
void gedit_document_set_mount_operation_factory
(GeditDocument *doc,
GeditMountOperationFactory callback,
gpointer userdata);
GMountOperation
*gedit_document_create_mount_operation
(GeditDocument *doc);
/*
* Non exported functions
*/
......
/*
* gedit-gio-document-loader.c
* This file is part of gedit
*
* Copyright (C) 2005 - Paolo Maggi
* Copyright (C) 2007 - Paolo Maggi, Steve Frécinaux
* Copyright (C) 2008 - Jesse van den Kieboom
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the gedit Team, 2005-2008. See the AUTHORS file for a
* list of people on the gedit Team.
* See the ChangeLog files for a list of changes.
*
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
#include "gedit-gio-document-loader.h"
#include "gedit-debug.h"
#include "gedit-metadata-manager.h"
#include "gedit-utils.h"
typedef struct
{
GeditGioDocumentLoader *loader;
GCancellable *cancellable;
gboolean tried_mount;
} AsyncData;
#define READ_CHUNK_SIZE 8192
#define REMOTE_QUERY_ATTRIBUTES G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE "," \
G_FILE_ATTRIBUTE_STANDARD_TYPE "," \
G_FILE_ATTRIBUTE_TIME_MODIFIED "," \
G_FILE_ATTRIBUTE_STANDARD_SIZE "," \
G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE
#define GEDIT_GIO_DOCUMENT_LOADER_GET_PRIVATE(object) \
(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
GEDIT_TYPE_GIO_DOCUMENT_LOADER, \
GeditGioDocumentLoaderPrivate))
static void gedit_gio_document_loader_load (GeditDocumentLoader *loader);
static gboolean gedit_gio_document_loader_cancel (GeditDocumentLoader *loader);
static const gchar *gedit_gio_document_loader_get_content_type (GeditDocumentLoader *loader);
static time_t gedit_gio_document_loader_get_mtime (GeditDocumentLoader *loader);
static goffset gedit_gio_document_loader_get_file_size (GeditDocumentLoader *loader);
static goffset gedit_gio_document_loader_get_bytes_read (GeditDocumentLoader *loader);
static gboolean gedit_gio_document_loader_get_readonly (GeditDocumentLoader *loader);
static void open_async_read (AsyncData *async);
struct _GeditGioDocumentLoaderPrivate
{
/* Info on the current file */
GFile *gfile;
GFileInfo *info;
goffset bytes_read;
/* Handle for remote files */
GCancellable *cancellable;
GFileInputStream *stream;
gchar *buffer;
GError *error;
};
G_DEFINE_TYPE(GeditGioDocumentLoader, gedit_gio_document_loader, GEDIT_TYPE_DOCUMENT_LOADER)
static void
gedit_gio_document_loader_finalize (GObject *object)
{
GeditGioDocumentLoaderPrivate *priv;
priv = GEDIT_GIO_DOCUMENT_LOADER (object)->priv;
if (priv->cancellable != NULL)
{
g_cancellable_cancel (priv->cancellable);
g_object_unref (priv->cancellable);
}
if (priv->info)
g_object_unref (priv->info);
if (priv->stream)
g_object_unref (priv->stream);
g_free (priv->buffer);
if (priv->gfile)
g_object_unref (priv->gfile);
if (priv->error)
g_error_free (priv->error);
G_OBJECT_CLASS (gedit_gio_document_loader_parent_class)->finalize (object);
}
static void
gedit_gio_document_loader_class_init (GeditGioDocumentLoaderClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GeditDocumentLoaderClass *loader_class = GEDIT_DOCUMENT_LOADER_CLASS (klass);
object_class->finalize = gedit_gio_document_loader_finalize;
loader_class->load = gedit_gio_document_loader_load;
loader_class->cancel = gedit_gio_document_loader_cancel;
loader_class->get_content_type = gedit_gio_document_loader_get_content_type;
loader_class->get_mtime = gedit_gio_document_loader_get_mtime;
loader_class->get_file_size = gedit_gio_document_loader_get_file_size;
loader_class->get_bytes_read = gedit_gio_document_loader_get_bytes_read;
loader_class->get_readonly = gedit_gio_document_loader_get_readonly;
g_type_class_add_private (object_class, sizeof(GeditGioDocumentLoaderPrivate));
}
static void
gedit_gio_document_loader_init (GeditGioDocumentLoader *gvloader)
{
gvloader->priv = GEDIT_GIO_DOCUMENT_LOADER_GET_PRIVATE (gvloader);
gvloader->priv->error = NULL;
}
static AsyncData *
async_data_new (GeditGioDocumentLoader *gvloader)
{
AsyncData *async;
async = g_new (AsyncData, 1);
async->loader = gvloader;
async->cancellable = g_object_ref (gvloader->priv->cancellable);
async->tried_mount = FALSE;
return async;
}
static void
async_data_free (AsyncData *async)
{
g_object_unref (async->cancellable);
g_free (async);
}
static void
remote_load_completed_or_failed (GeditGioDocumentLoader *gvloader, AsyncData *async)
{
/* free the buffer */
g_free (gvloader->priv->buffer);
gvloader->priv->buffer = NULL;
if (async)
async_data_free (async);
if (gvloader->priv->stream)
g_input_stream_close_async (G_INPUT_STREAM (gvloader->priv->stream), G_PRIORITY_HIGH, NULL, NULL, NULL);
gedit_document_loader_loading (GEDIT_DOCUMENT_LOADER (gvloader),
TRUE,
gvloader->priv->error);
}
/* prototype, because they call each other... isn't C lovely */
static void read_file_chunk (AsyncData *async);
static void
async_read_cb (GInputStream *stream,
GAsyncResult *res,
AsyncData *async)
{
gedit_debug (DEBUG_LOADER);
GError *error = NULL;
GeditGioDocumentLoader *gvloader;
gssize bytes_read;
/* manually check cancelled state */
if (g_cancellable_is_cancelled (async->cancellable))
{
g_input_stream_close_async (stream, G_PRIORITY_HIGH, NULL, NULL, NULL);
async_data_free (async);
return;
}
gvloader = async->loader;
bytes_read = g_input_stream_read_finish (stream, res, &error);
/* error occurred */
if (bytes_read == -1)
{
g_set_error (&gvloader->priv->error,
GEDIT_DOCUMENT_ERROR,
error->code,
error->message);
remote_load_completed_or_failed (gvloader, async);
return;
}
/* Check for the extremely unlikely case where the file size overflows. */
if (gvloader->priv->bytes_read + bytes_read < gvloader->priv->bytes_read)
{
g_set_error (&gvloader->priv->error,
GEDIT_DOCUMENT_ERROR,
GEDIT_DOCUMENT_ERROR_TOO_BIG,
_("File too big"));
remote_load_completed_or_failed (gvloader, async);
return;
}
/* Bump the size. */
gvloader->priv->bytes_read += bytes_read;
/* end of the file, we are done! */
if (bytes_read == 0)
{
gedit_document_loader_update_document_contents (
GEDIT_DOCUMENT_LOADER (gvloader),
gvloader->priv->buffer,
gvloader->priv->bytes_read,