index 5f8517c3d33fcfd8905d3ec99b38d95b232b552b..182b6f0968b8bb47f8635b73e1eee0eece0d3a41 100644 (file)
#include "file.h"
#include "extension/system.h"
#include "extension/output.h"
+#include <vector>
#ifdef WITH_GNOME_VFS
# include <libgnomevfs/gnome-vfs.h>
#ifdef WITH_GNOME_VFS
#define BUF_SIZE 8192
-gchar *
+static gchar *
_load_uri (const gchar *uri)
{
GnomeVFSHandle *handle = NULL;
GnomeVFSFileSize bytes_read;
- gchar buffer[BUF_SIZE] = "";
- gchar *doc = NULL;
- gchar *new_doc = NULL;
gsize bytesRead = 0;
gsize bytesWritten = 0;
GnomeVFSResult result = gnome_vfs_open (&handle, uri_local, GNOME_VFS_OPEN_READ);
if (result != GNOME_VFS_OK) {
- g_warning(gnome_vfs_result_to_string(result));
+ g_warning("%s", gnome_vfs_result_to_string(result));
}
+ std::vector<gchar> doc;
while (result == GNOME_VFS_OK) {
+ gchar buffer[BUF_SIZE];
result = gnome_vfs_read (handle, buffer, BUF_SIZE, &bytes_read);
- buffer[bytes_read] = '\0';
-
- if (doc == NULL) {
- doc = g_strndup(buffer, bytes_read);
- } else {
- new_doc = g_strconcat(doc, buffer, NULL);
- g_free(doc);
- doc = new_doc;
- }
+ doc.insert(doc.end(), buffer, buffer+bytes_read);
}
- return doc;
+ return g_strndup(&doc[0], doc.size());
}
#endif
This function is really simple, it just calls sp_document_new...
*/
SPDocument *
-Svg::open (Inkscape::Extension::Input *mod, const gchar *uri)
+Svg::open (Inkscape::Extension::Input */*mod*/, const gchar *uri)
{
#ifdef WITH_GNOME_VFS
- if (gnome_vfs_uri_is_local(gnome_vfs_uri_new(uri))) {
+ if (!gnome_vfs_initialized() || gnome_vfs_uri_is_local(gnome_vfs_uri_new(uri))) {
// Use built-in loader instead of VFS for this
return sp_document_new(uri, TRUE);
}
return NULL;
}
SPDocument * doc = sp_document_new_from_mem(buffer, strlen(buffer), 1);
-
+
g_free(buffer);
return doc;
#else
gchar *save_path = g_path_get_dirname (uri);
- gboolean const spns = (!mod->get_id()
+ gboolean const spns = (!mod->get_id()
|| !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE)
|| !strcmp (mod->get_id(), SP_MODULE_KEY_OUTPUT_SVGZ_INKSCAPE));
@@ -216,13 +208,13 @@ Svg::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
repr = sp_document_repr_root (doc);
} else {
rdoc = sp_repr_document_new ("svg:svg");
- repr = sp_repr_document_root (rdoc);
+ repr = rdoc->root();
repr = sp_document_root (doc)->updateRepr(repr, SP_OBJECT_WRITE_BUILD);
}
Inkscape::IO::fixupHrefs( doc, save_path, spns );
- gboolean const s = sp_repr_save_file (sp_repr_document (repr), uri, SP_SVG_NS_URI);
+ gboolean const s = sp_repr_save_file (repr->document(), uri, SP_SVG_NS_URI);
if (s == FALSE) {
throw Inkscape::Extension::Output::save_failed();
}