Code

Added code to initialize DBus (if enabled.)
[inkscape.git] / src / extension / internal / svg.cpp
index ab9c59830f99df36bf2cf958884af4ec25c25e5d..a3589e9051556fe27c523cd368df1b79dfda34b1 100644 (file)
@@ -51,12 +51,12 @@ Svg::init(void)
 
     /* SVG in */
     ext = Inkscape::Extension::build_from_mem(
-        "<inkscape-extension>\n"
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
             "<name>" N_("SVG Input") "</name>\n"
             "<id>" SP_MODULE_KEY_INPUT_SVG "</id>\n"
             "<input>\n"
                 "<extension>.svg</extension>\n"
-                "<mimetype>image/x-svg</mimetype>\n"
+                "<mimetype>image/svg+xml</mimetype>\n"
                 "<filetypename>" N_("Scalable Vector Graphic (*.svg)") "</filetypename>\n"
                 "<filetypetooltip>" N_("Inkscape native file format and W3C standard") "</filetypetooltip>\n"
                 "<output_extension>" SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "</output_extension>\n"
@@ -65,26 +65,26 @@ Svg::init(void)
 
     /* SVG out Inkscape */
     ext = Inkscape::Extension::build_from_mem(
-        "<inkscape-extension>\n"
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
             "<name>" N_("SVG Output Inkscape") "</name>\n"
             "<id>" SP_MODULE_KEY_OUTPUT_SVG_INKSCAPE "</id>\n"
             "<output>\n"
                 "<extension>.svg</extension>\n"
-                "<mimetype>image/x-svg</mimetype>\n"
+                "<mimetype>image/x-inkscape-svg</mimetype>\n"
                 "<filetypename>" N_("Inkscape SVG (*.svg)") "</filetypename>\n"
                 "<filetypetooltip>" N_("SVG format with Inkscape extensions") "</filetypetooltip>\n"
-                "<dataloss>FALSE</dataloss>\n"
+                "<dataloss>false</dataloss>\n"
             "</output>\n"
         "</inkscape-extension>", new Svg());
 
     /* SVG out */
     ext = Inkscape::Extension::build_from_mem(
-        "<inkscape-extension>\n"
+        "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
             "<name>" N_("SVG Output") "</name>\n"
             "<id>" SP_MODULE_KEY_OUTPUT_SVG "</id>\n"
             "<output>\n"
                 "<extension>.svg</extension>\n"
-                "<mimetype>image/x-svg</mimetype>\n"
+                "<mimetype>image/svg+xml</mimetype>\n"
                 "<filetypename>" N_("Plain SVG (*.svg)") "</filetypename>\n"
                 "<filetypetooltip>" N_("Scalable Vector Graphics format as defined by the W3C") "</filetypetooltip>\n"
             "</output>\n"
@@ -102,7 +102,7 @@ Svg::init(void)
 #ifdef WITH_GNOME_VFS
 #define BUF_SIZE 8192
 
-gchar *
+static gchar *
 _load_uri (const gchar *uri)
 {
     GnomeVFSHandle   *handle = NULL;
@@ -120,7 +120,7 @@ _load_uri (const gchar *uri)
     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;
@@ -145,10 +145,10 @@ _load_uri (const gchar *uri)
     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);
     }
@@ -158,7 +158,7 @@ Svg::open (Inkscape::Extension::Input *mod, const gchar *uri)
         return NULL;
     }
     SPDocument * doc = sp_document_new_from_mem(buffer, strlen(buffer), 1);
-    
+
     g_free(buffer);
     return doc;
 #else
@@ -175,9 +175,9 @@ Svg::open (Inkscape::Extension::Input *mod, const gchar *uri)
     \param     doc   Document to save.
     \param     uri   The filename to save the file to.
 
-    This function first checks it's parameters, and makes sure that
+    This function first checks its parameters, and makes sure that
     we're getting good data.  It also checks the module ID of the
-    incoming module to figure out if this is save should include
+    incoming module to figure out whether this save should include
     the Inkscape namespace stuff or not.  The result of that comparison
     is stored in the spns variable.
 
@@ -191,14 +191,14 @@ Svg::open (Inkscape::Extension::Input *mod, const gchar *uri)
     all of this code.  I just stole it.
 */
 void
-Svg::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
+Svg::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename)
 {
     g_return_if_fail(doc != NULL);
-    g_return_if_fail(uri != NULL);
+    g_return_if_fail(filename != NULL);
 
-    gchar *save_path = g_path_get_dirname (uri);
+    gchar *save_path = g_path_get_dirname(filename);
 
-    gboolean const spns = (!mod->get_id() 
+    bool 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));
 
@@ -208,14 +208,12 @@ 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 = sp_document_root (doc)->updateRepr(repr, SP_OBJECT_WRITE_BUILD);
+        repr = rdoc->root();
+        repr = sp_document_root (doc)->updateRepr(rdoc, 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);
-    if (s == FALSE) {
+    if (!sp_repr_save_rebased_file(repr->document(), filename, SP_SVG_NS_URI,
+                                   doc->base, filename)) {
         throw Inkscape::Extension::Output::save_failed();
     }