Code

Added code to initialize DBus (if enabled.)
[inkscape.git] / src / extension / internal / gdkpixbuf-input.cpp
index 0b01a6ab1a7ec703ee21e0290807ded2388b9408..64a099c8a42e3c673b89b3348936c0e4050d6174 100644 (file)
@@ -3,7 +3,6 @@
 #endif
 #include "document-private.h"
 #include <dir-util.h>
-#include "prefs-utils.h"
 #include "extension/system.h"
 #include "gdkpixbuf-input.h"
 #include "selection-chemistry.h"
@@ -20,10 +19,11 @@ namespace Internal {
 SPDocument *
 GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
 {
-    SPDocument *doc = sp_document_new(NULL, TRUE, TRUE);
+    SPDocument *doc = NULL;
     GdkPixbuf *pb = Inkscape::IO::pixbuf_new_from_file( uri, NULL );
 
     if (pb) {         /* We are readable */
+        doc = sp_document_new(NULL, TRUE, TRUE);
         bool saved = sp_document_get_undo_sensitive(doc);
         sp_document_set_undo_sensitive(doc, false); // no need to undo in this temporary document
 
@@ -55,9 +55,22 @@ GdkpixbufInput::open(Inkscape::Extension::Input */*mod*/, char const *uri)
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
         // import as <image>
         repr = xml_doc->createElement("svg:image");
-        // both are the same, as we don't know our base dir here and cannot relativate href (importer will fixupHrefs):
-        repr->setAttribute("xlink:href", uri);
-        repr->setAttribute("sodipodi:absref", uri);
+
+        // convert filename to uri
+        gchar* _uri = g_filename_to_uri(uri, NULL, NULL);
+        if(_uri) {
+            repr->setAttribute("xlink:href", _uri);
+            g_free(_uri);
+        } else {
+            repr->setAttribute("xlink:href", uri);
+        }
+        /* impl: doc->base is currently NULL, so we can use uri for href whether it's absolute
+         * or relative.  The href will get rewritten by rebase_hrefs if by chance uri is relative
+         * and doc gets saved to a different directory.
+         *
+         * We don't bother setting sodipodi:absref, as we assume it's never useful to have
+         * sodipodi:absref with the same value as xlink:href, and rebase_hrefs will provide
+         * sodipodi:absref values where necessary. */
 
         sp_repr_set_svg_double(repr, "width", width);
         sp_repr_set_svg_double(repr, "height", height);
@@ -110,7 +123,7 @@ GdkpixbufInput::init(void)
             }
 
             gchar *xmlString = g_strdup_printf(
-                "<inkscape-extension>\n"
+                "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
                     "<name>" N_("%s GDK pixbuf Input") "</name>\n"
                     "<id>org.inkscape.input.gdkpixbuf.%s</id>\n"
                     "<input>\n"