Code

Merging in from trunk
authorTed Gould <ted@gould.cx>
Sun, 29 Nov 2009 19:01:07 +0000 (13:01 -0600)
committerTed Gould <ted@gould.cx>
Sun, 29 Nov 2009 19:01:07 +0000 (13:01 -0600)
31 files changed:
configure.ac
src/Makefile.am
src/display/sp-canvas.cpp
src/display/sp-canvas.h
src/extension/dbus/Makefile_insert [new file with mode: 0644]
src/extension/dbus/Notes.txt [new file with mode: 0644]
src/extension/dbus/application-interface.cpp [new file with mode: 0644]
src/extension/dbus/application-interface.h [new file with mode: 0644]
src/extension/dbus/application-interface.xml [new file with mode: 0644]
src/extension/dbus/builddocs.sh [new file with mode: 0755]
src/extension/dbus/dbus-init.cpp [new file with mode: 0644]
src/extension/dbus/dbus-init.h [new file with mode: 0644]
src/extension/dbus/doc/config.xsl [new file with mode: 0644]
src/extension/dbus/doc/dbus-introspect-docs.dtd [new file with mode: 0644]
src/extension/dbus/doc/docbook.css [new file with mode: 0644]
src/extension/dbus/doc/inkscapeDbusRef.xml [new file with mode: 0644]
src/extension/dbus/doc/inkscapeDbusTerms.xml [new file with mode: 0644]
src/extension/dbus/doc/spec-to-docbook.xsl [new file with mode: 0644]
src/extension/dbus/document-interface.cpp [new file with mode: 0644]
src/extension/dbus/document-interface.h [new file with mode: 0644]
src/extension/dbus/document-interface.xml [new file with mode: 0644]
src/extension/dbus/org.inkscape.service.in [new file with mode: 0644]
src/extension/dbus/proposed-interface.xml [new file with mode: 0644]
src/extension/dbus/pytester.py [new file with mode: 0644]
src/extension/dbus/wrapper/Makefile [new file with mode: 0644]
src/extension/dbus/wrapper/inkscape-dbus-wrapper.c [new file with mode: 0644]
src/extension/dbus/wrapper/inkscape-dbus-wrapper.h [new file with mode: 0644]
src/extension/init.cpp
src/file.cpp
src/inkscape.h
src/selection.h

index fbfa2e5df6e0a3aa898443042112daeea23f1805..5e7c9aa31b16056c60570b3fda87fc6e9e69332f 100644 (file)
@@ -616,6 +616,19 @@ AM_CONDITIONAL(WITH_LIBWPG, test "x$with_libwpg" = "xyes")
 AC_SUBST(LIBWPG_LIBS)
 AC_SUBST(LIBWPG_CFLAGS)
 
+dnl ******************************
+dnl Check for dbus functionality
+dnl ******************************
+
+PKG_CHECK_MODULES(DBUS, dbus-glib-1, with_dbus=yes, with_dbus=no)
+if test "x$with_dbus" = "xyes"; then
+       AC_DEFINE(WITH_DBUS,1,[Build in dbus])
+fi
+AM_CONDITIONAL(WITH_DBUS, test "x$with_dbus" = "xyes")
+
+AC_SUBST(DBUS_LIBS)
+AC_SUBST(DBUS_CFLAGS)
+
 dnl ******************************
 dnl Check for ImageMagick Magick++ 
 dnl ******************************
@@ -1008,6 +1021,7 @@ Configuration:
         Internal Python:          ${with_python}
         Internal Perl:            ${with_perl}
         Enable LittleCms:         ${enable_lcms}
+        Enable DBUS               ${with_dbus} 
         Enable Poppler-Cairo:     ${enable_poppler_cairo}
         ImageMagick Magick++:     ${magick_ok}
         Libwpg:                   ${with_libwpg}
index 63b27398afd27db6e97dd9ce2081d98ed472d941..8f9682832785c2143c8d615aabd24f97af159790 100644 (file)
@@ -45,6 +45,7 @@ all_libs =                    \
        $(PYTHON_LIBS)          \
        $(INKBOARD_LIBS)        \
        $(LIBWPG_LIBS)          \
+       $(DBUS_LIBS)            \
        $(IMAGEMAGICK_LIBS)
 
 # Add sources common for Inkscape and Inkview to this variable.
@@ -62,6 +63,7 @@ INCLUDES =    \
        $(IMAGEMAGICK_CFLAGS) \
        $(INKBOARD_CFLAGS) \
        $(LIBWPG_CFLAGS) \
+       $(DBUS_CFLAGS) \
        $(XFT_CFLAGS)   \
        $(LCMS_CFLAGS)  \
        $(POPPLER_CFLAGS)       \
@@ -72,6 +74,7 @@ INCLUDES =    \
        $(WIN32_CFLAGS) \
        -I$(srcdir)/bind/javainc \
        -I$(srcdir)/bind/javainc/linux \
+       -I$(builddir)/extension/dbus \
        $(AM_CPPFLAGS)
 
 CXXTEST_TEMPLATE = $(srcdir)/cxxtest-template.tpl
@@ -104,6 +107,7 @@ include dialogs/Makefile_insert
 include display/Makefile_insert
 include dom/Makefile_insert
 include extension/Makefile_insert
+include extension/dbus/Makefile_insert
 include extension/implementation/Makefile_insert
 include extension/internal/Makefile_insert
 include extension/script/Makefile_insert
index aee53838f45275e72daf006ea3f036d6fabe7a3c..e640911d66ce9cba1d5292fdbfbd5fb4958e8e1a 100644 (file)
@@ -1028,6 +1028,8 @@ sp_canvas_init (SPCanvas *canvas)
 
     // See comment at in sp-canvas.h.
     canvas->gen_all_enter_events = false;
+    
+    canvas->drawing_disabled = false;
 
     canvas->tiles=NULL;
     canvas->tLeft=canvas->tTop=canvas->tRight=canvas->tBottom=0;
@@ -2085,6 +2087,9 @@ do_update (SPCanvas *canvas)
 {
     if (!canvas->root || !canvas->pixmap_gc) // canvas may have already be destroyed by closing desktop durring interrupted display!
         return TRUE;
+        
+    if (canvas->drawing_disabled)
+        return TRUE;
 
     /* Cause the update if necessary */
     if (canvas->need_update) {
index 35e3fb5de863d56f4de46a597f28f061ea92f679..a17e2e086ffc4854cfcfd2d12c83baecc2569ac6 100644 (file)
@@ -181,6 +181,9 @@ struct SPCanvas {
     // connector tool).  If so, they may temporarily set this flag to
     // 'true'.
     bool gen_all_enter_events;
+    
+    /* For scripting, sometimes we want to delay drawing. */
+    bool drawing_disabled;
 
     int rendermode;
 
diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert
new file mode 100644 (file)
index 0000000..00dba3b
--- /dev/null
@@ -0,0 +1,40 @@
+## Makefile.am fragment sourced by src/Makefile.am.
+
+ink_common_sources +=  \
+       extension/dbus/dbus-init.cpp  \
+       extension/dbus/dbus-init.h  \
+       extension/dbus/application-interface.cpp  \
+       extension/dbus/application-interface.h  \
+       extension/dbus/document-interface.cpp  \
+       extension/dbus/document-interface.h
+
+## Slightly concerned about this.
+## Would use += but it has to be set first.
+BUILT_SOURCES =   \
+       extension/dbus/application-server-glue.h   \
+       extension/dbus/document-server-glue.h   \
+       extension/dbus/document-client-glue.h
+#      extension/dbus/wrapper/libinkdbus.so.1.0 this probably belongs somewhere else
+
+extension/dbus/application-server-glue.h: extension/dbus/application-interface.xml
+       dbus-binding-tool --mode=glib-server --output=$@ --prefix=application_interface $^
+
+extension/dbus/document-server-glue.h: extension/dbus/document-interface.xml
+       dbus-binding-tool --mode=glib-server --output=$@ --prefix=document_interface $^
+
+extension/dbus/document-client-glue.h: extension/dbus/document-interface.xml
+       dbus-binding-tool --mode=glib-client --output=$@ --prefix=document_interface $^
+
+#extension/dbus/wrapper/libinkdbus.so.1.0: extension/dbus/wrapper/inkscape-dbus-wrapper.c extension/dbus/wrapper/inkscape-dbus-wrapper.h extension/dbus/document-interface.xml
+#      gcc -fPIC -c extension/dbus/wrapper/inkscape-dbus-wrapper.c -o extension/dbus/wrapper/inkscape-dbus-wrapper.o $(shell pkg-config --cflags --libs glib-2.0 gobject-2.0 dbus-glib-1)
+#      ld -shared -soname libinkdbus.so.1 -o extension/dbus/wrapper/libinkdbus.so.1.0 -lc extension/dbus/wrapper/inkscape-dbus-wrapper.o
+
+# Dbus service file
+servicedir = "/usr/share/dbus-1/services"
+service_in_files = extension/dbus/org.inkscape.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+# Rule to make the service file with bindir expanded
+$(service_DATA): $(service_in_files) Makefile
+       @sed -e "s|bindir|$(prefix)|" $<> $@
+
diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt
new file mode 100644 (file)
index 0000000..25c3f35
--- /dev/null
@@ -0,0 +1,79 @@
+INTRO:
+For people that are interested in improving the DBus API here is a 
+intro to how everything is laid out.
+
+First read the documentation for a general idea of how the different interfaces 
+fit together and how Dbus is used in this application.
+
+Here are short descriptions of the relevant files:
+
+document-interface.cpp: This has most of the "meat" of the interface, this is where
+most functions are implemented.
+
+application-interface.cpp: This is where the application interface is implemented.
+
+(document/application)-interface.xml: These files are the master record of the interfaces.
+All of the documentation is generated from these files as is a lot of glue code.
+Any changes MUST be reflected here.
+
+dbus-init.cpp: This is where the interface is exposed when Inkscape starts up.
+Here is where the names given to the various interfaces are set.  The application interface is constant but the document interfaces are generated on the fly.
+
+org.inkscape.service.in: This sets where DBus looks for the Inkscape executable
+if it is not running when someone tries to connect.
+
+pytester.py: A python script that tests a lot of dbus functions.
+
+doc/builddocs.sh: builds documentation out of the XML files and some others.
+
+config.xsl, dbus-introspect-docs.dtd, spec-to-docbook.xsl, docbook.css: I borrowed 
+these files, they set how the documentation looks, I have no idea how to edit them.
+
+doc/inkscapeDbusRef.xml: This is the top level file for laying out the documentation,
+it also includes the introduction.
+
+doc/inkscapeDbusTerms.xml: This contains the terms sections of the documentation.  
+Also the overview and all the tutorials.
+
+*.ref.xml: These are intermediate files, do not edit.
+
+wrapper/inkscape-dbus-wrapper.c: This is actually completely separate from inkscape.
+It has a wrapper for each function in the document interface and includes the
+client generated bindings.  It is used to create a shared object that will allow 
+people to use the interface without even knowing anything about Dbus.
+
+BUGS:
+    *Inkscape crashes if widow is closed while code is running,
+        need better error handling.
+    
+    *Pause updates needs work.
+    
+    *Default style for new shapes is occasionally strange.
+    
+    *The following methods are broken:
+        -document_interface_selection_move_to_layer
+    
+    *The following are not implemented:
+        -document_interface_layer_get_all
+        -document_interface_selection_box
+        -document_interface_get_node_coordinates
+        
+    *The following do not behave like the documentation:
+        -document_interface_transform
+        -document_interface_text
+
+EFFICIENCY:
+    *Need better way to retrieve objects by name.
+        Switch to GQuark codes for object retrieval?
+    
+    *Rethink how often activate_desktop needs to be called.
+
+FEATURES:
+    *Find out more about extension API.
+    *API compatibility for plugins?
+
+CLEANUP:
+
+
+
+
diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp
new file mode 100644 (file)
index 0000000..b183be9
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * This is where the implementation of the DBus based application API lives.
+ * All the methods in here are designed to be called remotly via DBus.
+ * document-interface.cpp has all of the actual manipulation methods.
+ * This interface is just for creating new document interfaces.
+ *
+ * Documentation for these methods is in application-interface.xml
+ * which is the "gold standard" as to how the interface should work.
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#include "application-interface.h"
+#include <string.h>
+#include "dbus-init.h"
+
+G_DEFINE_TYPE(ApplicationInterface, application_interface, G_TYPE_OBJECT)
+
+static void
+application_interface_finalize (GObject *object)
+{
+        G_OBJECT_CLASS (application_interface_parent_class)->finalize (object);
+}
+
+
+static void
+application_interface_class_init (ApplicationInterfaceClass *klass)
+{
+        GObjectClass *object_class;
+        object_class = G_OBJECT_CLASS (klass);
+        object_class->finalize = application_interface_finalize;
+}
+
+static void
+application_interface_init (ApplicationInterface *object)
+{
+}
+
+
+ApplicationInterface *
+application_interface_new (void)
+{
+        return (ApplicationInterface*)g_object_new (TYPE_APPLICATION_INTERFACE, NULL);
+}
+
+/****************************************************************************
+     DESKTOP FUNCTIONS
+****************************************************************************/
+
+gchar* 
+application_interface_desktop_new (ApplicationInterface *object, 
+                                   GError **error) 
+{
+  return (gchar*)Inkscape::Extension::Dbus::init_desktop();
+}
+
+gchar** 
+application_interface_get_desktop_list (ApplicationInterface *object)
+{
+  return NULL;
+}
+
+gchar* 
+application_interface_get_active_desktop (ApplicationInterface *object,
+                                          GError **error)
+{
+  return NULL;
+}
+
+gboolean
+application_interface_set_active_desktop (ApplicationInterface *object, 
+                                          gchar* document_name,
+                                          GError **error)
+{
+  return TRUE;
+}
+
+gboolean
+application_interface_desktop_close_all (ApplicationInterface *object,
+                                          GError **error) 
+{
+  return TRUE;
+}
+
+gboolean
+application_interface_exit (ApplicationInterface *object, GError **error)
+{
+    return TRUE;
+}
+
+/****************************************************************************
+     DOCUMENT FUNCTIONS
+****************************************************************************/
+
+gchar* application_interface_document_new (ApplicationInterface *object,
+                                           GError **error)
+{
+  return (gchar*)Inkscape::Extension::Dbus::init_document();
+}
+
+gchar** 
+application_interface_get_document_list (ApplicationInterface *object)
+{
+  return NULL;
+}
+
+gboolean
+application_interface_document_close_all (ApplicationInterface *object,
+                                          GError **error) 
+{
+  return TRUE;
+}
+
+/* INTERESTING FUNCTIONS
+    SPDesktop  *desktop = SP_ACTIVE_DESKTOP;
+    g_assert(desktop != NULL);
+
+    SPDocument *doc = sp_desktop_document(desktop);
+    g_assert(doc != NULL);
+
+    Inkscape::XML::Node     *repr = sp_document_repr_root(doc);
+    g_assert(repr != NULL);
+*/
+
diff --git a/src/extension/dbus/application-interface.h b/src/extension/dbus/application-interface.h
new file mode 100644 (file)
index 0000000..e782bd1
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * This is where the implementation of the DBus based application API lives.
+ * All the methods in here are designed to be called remotly via DBus.
+ * document-interface.cpp has all of the actual manipulation methods.
+ * This interface is just for creating new document interfaces.
+ *
+ * Documentation for these methods is in application-interface.xml
+ * which is the "gold standard" as to how the interface should work.
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_
+#define INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#define DBUS_APPLICATION_INTERFACE_PATH  "/org/inkscape/application"
+        
+#define TYPE_APPLICATION_INTERFACE            (application_interface_get_type ())
+#define APPLICATION_INTERFACE(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_APPLICATION_INTERFACE, ApplicationInterface))
+#define APPLICATION_INTERFACE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_APPLICATION_INTERFACE, ApplicationInterfaceClass))
+#define IS_APPLICATION_INTERFACE(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_APPLICATION_INTERFACE))
+#define IS_APPLICATION_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_APPLICATION_INTERFACE))
+#define APPLICATION_INTERFACE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_APPLICATION_INTERFACE, ApplicationInterfaceClass))
+
+G_BEGIN_DECLS
+
+typedef struct _ApplicationInterface ApplicationInterface;
+typedef struct _ApplicationInterfaceClass ApplicationInterfaceClass;
+
+struct _ApplicationInterface {
+        GObject parent;
+};
+
+struct _ApplicationInterfaceClass {
+        GObjectClass parent;
+};
+
+/****************************************************************************
+     DESKTOP FUNCTIONS
+****************************************************************************/
+
+gchar* 
+application_interface_desktop_new (ApplicationInterface *object, 
+                                   GError **error);
+
+gchar** 
+application_interface_get_desktop_list (ApplicationInterface *object);
+
+gchar* 
+application_interface_get_active_desktop (ApplicationInterface *object, 
+                                          GError **error);
+
+gboolean
+application_interface_set_active_desktop (ApplicationInterface *object,
+                                          gchar* document_name, 
+                                          GError **error);
+
+gboolean
+application_interface_desktop_close_all (ApplicationInterface *object, 
+                                         GError **error);
+
+gboolean
+application_interface_exit (ApplicationInterface *object, GError **error);
+
+/****************************************************************************
+     DOCUMENT FUNCTIONS
+****************************************************************************/
+
+gchar* 
+application_interface_document_new (ApplicationInterface *object, 
+                                    GError **error);
+
+gchar** 
+application_interface_get_document_list (ApplicationInterface *object);
+
+gboolean
+application_interface_document_close_all (ApplicationInterface *object,
+                                          GError **error);
+
+
+/****************************************************************************
+     SETUP
+****************************************************************************/
+
+ApplicationInterface *application_interface_new (void);
+GType application_interface_get_type (void);
+
+
+G_END_DECLS
+
+#endif // INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_
diff --git a/src/extension/dbus/application-interface.xml b/src/extension/dbus/application-interface.xml
new file mode 100644 (file)
index 0000000..ee2c483
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * This is the master description of the DBus application interface.
+ * The interface is mostly just for creating new document instances.
+ *
+ * This file is used to generate both glue code and documentation.
+ * The methods are in the same order as the .cpp/.h and the sections are labeled.
+ *
+ * Any change to method prototypes in application-interface.cpp MUST be reflected here.
+ *
+ * This file is the proverbial gold standard for the application interface. 
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+-->
+<node name="/org/inkscape/application"
+  xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"
+>
+  <interface name="org.inkscape.application">
+
+    <!-- DESKTOP FUNCTIONS -->
+    <method name="desktop_new">
+      <arg type="s" name="desktop_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>This string can be used to connect to the new interface that was created.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Create a new document interface and return it's location.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+    <method name="get_desktop_list">
+      <arg type="as" name="document_list" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>A list of interfaces being provided by Inkscape.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>List all the interfaces that it is possible to connect to.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+    <method name="desktop_close_all">
+      <doc:doc>
+        <doc:description>
+          <doc:para>Close all document interfaces without saving.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+    <method name="exit">
+      <doc:doc>
+        <doc:description>
+          <doc:para>Exit Inkscape without saving.  Fairly straightforward. </doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- DOCUMENT FUNCTIONS -->
+    <method name="document_new">
+      <arg type="s" name="document_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>This string can be used to connect to the new interface that was created.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Originally, there were going to be two interfaces.  A desktop and a document.  Desktops would be used when the user wanted to see the result of their code and documents would be used when less overhead was desired.  Unfortunately as more and more of the code can to rely on the desktop and it's associated support code (including selections and verbs) the document interface was looking more and more limited.  Ultimately I decided to just go with the desktop interface since I didn't have a compelling reason for keeping the other one and having two similar interfaces could be very confusing.  The desktop interface inherited the document name because I believe it's more familiar to people.</doc:para>
+          <doc:para>Perhaps it would be best to have an option as to whether or not to create a window and fail with a good error message when they call a function that requires one.  Or have a second interface for different use cases but have it be completely different, rather than a subset of the first if there are use cases that support it.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+  </interface>
+</node>
diff --git a/src/extension/dbus/builddocs.sh b/src/extension/dbus/builddocs.sh
new file mode 100755 (executable)
index 0000000..2c16daf
--- /dev/null
@@ -0,0 +1,6 @@
+xsltproc doc/spec-to-docbook.xsl application-interface.xml > doc/org.inkscape.application.ref.xml &&
+xsltproc doc/spec-to-docbook.xsl document-interface.xml > doc/org.inkscape.document.ref.xml &&
+xsltproc doc/spec-to-docbook.xsl proposed-interface.xml > doc/org.inkscape.proposed.ref.xml &&
+xmlto --skip-validation xhtml-nochunks -o doc -m doc/config.xsl doc/inkscapeDbusRef.xml &&
+firefox doc/inkscapeDbusRef.html
+
diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp
new file mode 100644 (file)
index 0000000..253d6b9
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * This is where Inkscape connects to the DBus when it starts and 
+ * registers the main interface.
+ *
+ * Also where new interfaces are registered when a new document is created.
+ * (Not called directly by application-interface but called indirectly.)
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#include <dbus/dbus-glib.h>
+#include "dbus-init.h"
+
+#include "application-interface.h"
+#include "application-server-glue.h"
+
+#include "document-interface.h"
+#include "document-server-glue.h"
+
+#include "inkscape.h"
+#include "document.h"
+#include "desktop.h"
+#include "file.h"
+#include "verbs.h"
+#include "helper/action.h"
+
+#include <algorithm>
+#include <iostream>
+#include <sstream>
+
+
+
+
+namespace Inkscape {
+namespace Extension {
+namespace Dbus {
+
+/* PRIVATE get a connection to the session bus */
+DBusGConnection *
+dbus_get_connection() {
+       GError *error = NULL;
+       DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+       if (error) {
+               fprintf(stderr, "Failed to get connection");
+               return NULL;
+       }
+       else
+               return connection;
+}
+
+/* PRIVATE create a proxy object for a bus.*/
+DBusGProxy *
+dbus_get_proxy(DBusGConnection *connection) {
+       return dbus_g_proxy_new_for_name (connection,
+                DBUS_SERVICE_DBUS,
+                DBUS_PATH_DBUS,
+                DBUS_INTERFACE_DBUS);
+}
+
+/* PRIVATE register an object on a bus */
+static gpointer
+dbus_register_object (DBusGConnection *connection,
+                      DBusGProxy *proxy,
+                      GType object_type,
+                      const DBusGObjectInfo *info,
+                      const gchar *path)
+{
+        GObject *object = (GObject*)g_object_new (object_type, NULL);
+        dbus_g_object_type_install_info (object_type, info);
+        dbus_g_connection_register_g_object (connection, path, object);
+        return object;
+}
+
+/* Initialize a Dbus service */
+void 
+init (void)
+{
+        guint   result;
+        GError *error = NULL;
+        DBusGConnection *connection;
+        DBusGProxy *proxy;
+           DocumentInterface *obj;
+        connection = dbus_get_connection();
+        proxy = dbus_get_proxy(connection);
+        org_freedesktop_DBus_request_name (proxy,
+                "org.inkscape",
+                DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error);
+        //create interface for application
+        dbus_register_object (connection, 
+                proxy,
+                TYPE_APPLICATION_INTERFACE,
+                &dbus_glib_application_interface_object_info,
+                DBUS_APPLICATION_INTERFACE_PATH);
+} //init
+
+gchar *
+init_document (void) {
+        guint   result;
+        GError *error = NULL;
+        DBusGConnection *connection;
+        DBusGProxy *proxy;
+       SPDocument *doc;
+
+       doc = sp_document_new(NULL, 1, TRUE);
+
+        std::string name("/org/inkscape/");
+       name.append(doc->name);
+        std::replace(name.begin(), name.end(), ' ', '_');
+
+        connection = dbus_get_connection();
+        proxy = dbus_get_proxy(connection);
+
+        dbus_register_object (connection, 
+                proxy,
+                TYPE_DOCUMENT_INTERFACE,
+                &dbus_glib_document_interface_object_info,
+                name.c_str());
+       return strdup(name.c_str());
+} //init_document
+
+gchar *
+dbus_init_desktop_interface (SPDesktop * dt)
+{
+    DBusGConnection *connection;
+    DBusGProxy *proxy;
+       DocumentInterface *obj;
+       dbus_g_error_domain_register (INKSCAPE_ERROR,
+                               NULL,
+                               INKSCAPE_TYPE_ERROR);
+
+    std::string name("/org/inkscape/desktop_");
+       std::stringstream out;
+       out << dt->dkey;
+       name.append(out.str());
+
+       //printf("DKEY: %d\n, NUMBER %d\n NAME: %s\n", dt->dkey, dt->number, name.c_str());
+
+    connection = dbus_get_connection();
+    proxy = dbus_get_proxy(connection);
+
+    obj = (DocumentInterface*) dbus_register_object (connection, 
+          proxy, TYPE_DOCUMENT_INTERFACE,
+          &dbus_glib_document_interface_object_info, name.c_str());
+       obj->desk = dt;
+    obj->updates = TRUE;
+
+    return strdup(name.c_str());
+}
+
+gchar *
+init_desktop (void) {
+    //this function will create a new desktop and call
+    //dbus_init_desktop_interface.
+       SPDesktop * dt = sp_file_new_default();
+
+    std::string name("/org/inkscape/desktop_");
+       std::stringstream out;
+       out << dt->dkey;
+       name.append(out.str());
+    return strdup(name.c_str());
+} //init_desktop
+
+
+
+} } } /* namespace Inkscape::Extension::Dbus */
diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h
new file mode 100644 (file)
index 0000000..4b07acf
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Authors:
+ *   Soren Berg <glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef INKSCAPE_EXTENSION_DBUS_INIT_H__
+#define INKSCAPE_EXTENSION_DBUS_INIT_H__
+
+#include "desktop.h"
+
+namespace Inkscape {
+namespace Extension {
+namespace Dbus {
+
+/** \brief  Dbus stuff.  For registering objects on the bus. */
+
+void init (void);
+
+gchar * init_document (void);
+
+gchar * init_desktop (void);
+
+gchar * dbus_init_desktop_interface (SPDesktop * dt);
+
+} } }  /* namespace Dbus, Extension, Inkscape */
+
+#endif /* INKSCAPE_EXTENSION_DBUS_INIT_H__ */
+
+/*
+  Local Variables:
+  mode:c++
+  c-file-style:"stroustrup"
+  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+  indent-tabs-mode:nil
+  fill-column:99
+  End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/dbus/doc/config.xsl b/src/extension/dbus/doc/config.xsl
new file mode 100644 (file)
index 0000000..26949c4
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version='1.0'?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+                xmlns:fo="http://www.w3.org/1999/XSL/Format"
+                version="1.0">
+  <xsl:param name="html.stylesheet" select="'docbook.css'"/>
+</xsl:stylesheet>
+
diff --git a/src/extension/dbus/doc/dbus-introspect-docs.dtd b/src/extension/dbus/doc/dbus-introspect-docs.dtd
new file mode 100644 (file)
index 0000000..4781671
--- /dev/null
@@ -0,0 +1,33 @@
+<!-- DTD for D-Bus Introspection Documentation -->
+
+<!ELEMENT doc (summary?,description?,errors?,permission?,since?,deprecated,seealso?)>
+
+<!ELEMENT summary (#PCDATA|ref)*>
+<!ELEMENT description (#PCDATA|para|example)*>
+<!ELEMENT errors (error)*>
+<!ELEMENT permission (#PCDATA|ref|para)*>
+<!ELEMENT since EMPTY>
+<!ATTLIST since version CDATA #REQUIRED>
+<!ELEMENT deprecated (#PCDATA|ref)>
+<!ATTLIST deprecated version CDATA #REQUIRED>
+<!ATTLIST deprecated instead CDATA #REQUIRED>
+<!ELEMENT seealso (ref+)>
+
+<!ELEMENT error (#PCDATA|para)*>
+<!ATTLIST error name CDATA #REQUIRED>
+<!ELEMENT para (#PCDATA|example|code|list|ref)*>
+<!ELEMENT example (#PCDATA|para|code|ref)*>
+<!ATTLIST language (c|glib|python|shell) #REQUIRED>
+<!ATTLIST title CDATA #IMPLIED>
+<!ELEMENT list (item*)>
+<!ATTLIST list type (bullet|number) #REQUIRED>
+<!ELEMENT item (term|definition)*>
+<!ELEMENT term (#PCDATA|ref)*>
+<!ELEMENT definition (#PCDATA|para)*>
+
+<!ELEMENT code (#PCDATA)>
+<!ATTLIST code lang CDATA #IMPLIED>
+<!ELEMENT ref CDATA>
+<!ATTLIST ref type (parameter|arg|signal|method|interface) #REQUIRED>
+<!ATTLIST ref to CDATA #REQUIRED>
+
diff --git a/src/extension/dbus/doc/docbook.css b/src/extension/dbus/doc/docbook.css
new file mode 100644 (file)
index 0000000..aed08dc
--- /dev/null
@@ -0,0 +1,79 @@
+body
+{
+  font-family: sans-serif;
+}
+h1.title
+{
+}
+.permission
+{
+  color: #ee0000;
+  text-decoration: underline;
+}
+.synopsis, .classsynopsis
+{
+  background: #eeeeee;
+  border: solid 1px #aaaaaa;
+  padding: 0.5em;
+}
+.programlisting
+{
+  background: #eeeeff;
+  border: solid 1px #aaaaff;
+  padding: 0.5em;
+}
+.variablelist
+{
+  padding: 4px;
+  margin-left: 3em;
+}
+.variablelist td:first-child
+{
+  vertical-align: top;
+}
+td.shortcuts
+{
+  color: #770000;
+  font-size: 80%;
+}
+div.refnamediv
+{
+  margin-top: 2em;
+}
+div.toc
+{
+  border: 2em;
+}
+a
+{
+  text-decoration: none;
+}
+a:hover
+{
+  text-decoration: underline;
+  color: #FF0000;
+}
+
+div.table table
+{
+  border-collapse: collapse;
+  border-spacing: 0px;
+  border-style: solid;
+  border-color: #777777;
+  border-width: 1px;
+}
+
+div.table table td, div.table table th
+{
+  border-style: solid;
+  border-color: #777777;
+  border-width: 1px;
+  padding: 3px;
+  vertical-align: top;
+}
+
+div.table table th
+{
+  background-color: #eeeeee;
+}
+
diff --git a/src/extension/dbus/doc/inkscapeDbusRef.xml b/src/extension/dbus/doc/inkscapeDbusRef.xml
new file mode 100644 (file)
index 0000000..6bf134a
--- /dev/null
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
+<!ENTITY dbus-Application SYSTEM "org.inkscape.application.ref.xml">
+<!ENTITY dbus-Document SYSTEM "org.inkscape.document.ref.xml">
+<!ENTITY dbus-Proposed SYSTEM "org.inkscape.proposed.ref.xml">
+<!ENTITY Terms SYSTEM "inkscapeDbusTerms.xml">
+
+]>
+
+<book id="index">
+  <bookinfo>
+    <title>Inkscape Dbus Documentation</title>
+    <releaseinfo>Version 0.0</releaseinfo>
+    <date>7 July, 2009</date>
+    <authorgroup>
+      <author>
+        <firstname>Soren</firstname>
+        <surname>Berg</surname>
+        <affiliation>
+          <address>
+            <email>glimmer07@gmail.com</email>
+          </address>
+        </affiliation>
+      </author>
+    </authorgroup>
+  </bookinfo>
+
+  <preface>
+    <title>Introduction</title>
+    <para>
+This is the documentation for scripting Inkscape using Dbus.  This framework was developed to let users quickly and easily write scripts to create or manipulate images in a variety of languages.  Once the API has stabilized there will also be a C library that encapsulates the Dbus functionality.
+    </para>
+    <para>
+The guiding principles behind the design of this API were:
+    </para>
+    <para>
+<emphasis>Easy to use:</emphasis>  Use of insider terms was limited where possible, and many functions have been simplified to provide a easy entry point for beginning users.  Ideally one should not need any experience with Inkscape or even vector graphics to begin using the interface.  At the same time, functions that can call arbitrary verbs or manipulate nodes and their attributes directly give knowledgeable users some flexibility.
+    </para>
+    <para>
+<emphasis>Interactive:</emphasis>  Since Dbus ties in with the main loop, users can mix scripting and mouse driven actions seamlessly.  This allows for some unique uses but more importantly makes it easier for people to learn the API since they can play around with it in a scripting console, or even a simple python shell.  
+    </para>
+    <para>
+<emphasis>Responsive:</emphasis>  Since one of the advantages of scripting is the ability to repeat actions many times with great precision it is obvious that the system would have to be fairly fast.  The amount of overhead has been limited where possible and functions have been tested for speed.  A system to pause updates and only refresh the display after a large number of operations have been completed, ensures that even very complicated renders will not take too long.
+    </para>
+  </preface>
+
+  <part>
+    <title>Concepts</title>
+
+    &Terms;
+
+  </part>
+
+  <part>
+    <title>Reference</title>
+
+    <reference id="dbus-reference">
+      <title>D-Bus API Reference</title>
+
+      <partintro>
+        <para>
+        Inkscape provides a D-Bus API for programs to interactivly script vector graphics.
+        </para>
+        <para>
+        This API is not yet stable and is likely to change in the future.
+        </para>
+      </partintro>
+
+      &dbus-Application;
+      &dbus-Document;
+      &dbus-Proposed;
+
+    </reference>
+  </part>
+
+  <index>
+    <title>Index</title>
+  </index>
+
+</book>
+
diff --git a/src/extension/dbus/doc/inkscapeDbusTerms.xml b/src/extension/dbus/doc/inkscapeDbusTerms.xml
new file mode 100644 (file)
index 0000000..507fcbf
--- /dev/null
@@ -0,0 +1,142 @@
+<chapter id="connecting">
+  <title>Connecting to the API</title>
+
+  <sect1>
+    <title>Overview</title>
+    <para>
+There are really two Dbus interfaces provided by Inkscape.  One is the application interface, which is constant, and allows one to control the Inkscape application as a whole and create new documents or windows.  The second is the document interface.  A document interface is automatically generated for every open window, and the commands sent to that interface will affect that particular window.
+    </para>
+    <para>
+So the basic way of connecting goes like this:  Connect to the session bus.  Connect to the application interface.  Request a new document.  Connect to the newly created document interface using the name returned in the last step.  Manipulate the document however you want (load files, create shapes, save, etc.)  After the connection example there is a shortcut that will shorten this process somewhat in certain circumstances.
+    </para>
+  </sect1>
+  <sect1>
+    <title>Connection example</title>
+    <para>
+Here is a basic example of connecting to the Bus and getting a new document.  (In python for now because it's easy to read.)
+    </para>
+    <informalexample language="python" title="simple example">
+    <programlisting>
+import dbus
+
+#get the session bus.
+bus = dbus.SessionBus()
+
+#get the object for the application.
+inkapp = bus.get_object('org.inkscape',
+                       '/org/inkscape/application')
+
+#request a new desktop.
+desk2 = inkapp.desktop_new(dbus_interface='org.inkscape.application')
+
+#get the object for that desktop.
+inkdoc1 = bus.get_object('org.inkscape', desk2)
+
+#tell it what interface it is using so we don't have to type it for every method.
+doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document")
+
+#use!
+doc1.rectangle (0,0,100,100)
+    </programlisting>
+    </informalexample>
+  </sect1>
+
+  <sect1>
+    <title>Shortcut</title>
+    <para>
+Here is a quicker way if you don't need multiple documents open at once.  Since Inkscape starts automatically, and it always creates a blank document we can just connect to that.  
+    </para>
+    <warning><para>
+WARNING: This may not always work, it also might connect you to a document that is in use if Inkscape was already running.  Only recommended for testing/experimenting.
+    </para></warning>
+    <informalexample language="python" title="simple example">
+    <programlisting>
+import dbus
+
+#get the session bus.
+bus = dbus.SessionBus()
+
+#get object
+inkdoc1 = bus.get_object('org.inkscape', '/org/inkscape/desktop_0')
+
+#get interface
+doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document")
+
+#ta-da
+doc1.rectangle (0,0,100,100)
+    </programlisting>
+    </informalexample>
+  </sect1>
+
+</chapter>
+
+<chapter id="terms">
+  <title>Terminology</title>
+
+  <anchor id="Coordinate System"/>
+  <sect1>
+    <title>Coordinate System</title>
+    <para>
+The coordinate system used by this API may be different than what you are used to (although it is standard in the computer graphics industry.)  Simply put the origin (0,0) is in the upper left hand corner of the document.  X increases to the right and Y increases downwards.  Therefore everything with positive coordinates is in the document.
+    </para>
+    <para>
+For example: (100,100) would be just below and to the right of the top left corner of the document.
+    </para>
+  </sect1>
+
+  <anchor id="Selections"/>
+  <sect1>
+    <title>Selections</title>
+    <para>
+Selections are extremely useful ways of managing groups of objects and applying effects to all of them at once.  Since much of Inkscapes core functionality is built around manipulating selections they are the key to much of this APIs utility.  Manipulate the list of selected objects with <link linkend="document.selection_set">selection_set()</link>, <link linkend="document.selection_add">selection_add()</link>, and <link linkend="document.selection_box">selection_box()</link> and then call whatever selection function you need.
+    </para>
+  </sect1>
+
+  <anchor id="Groups"/>
+  <sect1>
+    <title>Groups</title>
+    <para>
+Groups are collections of objects that are treated as a single object.  Groups have their own id and can be passed to any function that accepts an object, though some will not have any effect (groups ignore style for instance.)  Groups can be transformed and occupy a single level in their layer.  Objects within a group can still be modified using their ids, but this will not have any affect on the other group members.  Functions like move_to may not work as expected if used on an object that is part of a group that has a transformation applied.
+    </para>
+  </sect1>
+
+  <anchor id="Layers and Levels"/>
+  <sect1>
+    <title>Layers and Levels</title>
+    <para>
+The basic idea is that things on top cover up things beneath them.  The potentially confusing part is that Inkscape implements this in two ways: layers and levels.  Levels are what order objects are in within a single layer.  So the highest level object is still below all of the objects in the layer above it. <link linkend="document.layer_change_level">layer_change_level()</link> changes the order of layers and <link linkend="document.selection_change_level">selection_change_level()</link> changes the order of objects within a layer.
+    </para>
+    <para>
+Changing the level of a selection also deserves some explanation.  The <link linkend="document.selection_change_level">selection_change_level()</link> function can work in two ways.  It can be absolute, "to_top" and "to_bottom" work like you'd expect, sending the entire selection to the top or bottom of that layer.  But it can also be relative.  "raise" and "lower" only work if there is another shape overlaping above or beneath the selection at the moment.  Also if you have two objects selected and they are both occluded by a third, raising the selection once will only raise the first object in the selection above the third object.  In other words selections don't move as a group.  
+    </para>
+  </sect1>
+
+  <anchor id="Style Strings"/>
+  <sect1>
+    <title>Style Strings</title>
+    <para>
+Style strings look something like this: "fill:#ff0000;fill-opacity:1;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none".  It is a string of key value pairs that determines the style of a particular object.  Style strings affect most objects.  They can be set all at once or specific key value pairs can be added one by one.  Style strings can also be merged, with the new string replacing key/value pairs that it contains and leaving the rest as they were.  One could also think of it as the new string taking any attributes it does not have and adopting them from the old string. 
+    </para>
+  </sect1>
+
+  <anchor id="Paths"/>
+  <sect1>
+    <title>Paths</title>
+    <para>
+A path is a string representing a series of points, and how the line curves between the points.  It looks something like this: "m 351.42857,296.64789 a 54.285713,87.14286 0 1 1 -108.57143,0 54.285713,87.14286 0 1 1 108.57143,0 z" and is usually found as an attribute of a shape with the label "d".  All shapes except rectangles have this "d" attribute.
+    </para>
+    <para>
+Just because a shape has a path does not mean it IS a path however.  A path object has no attributes except the path and a style.  Calling <link linkend="document.object_to_path">object_to_path()</link> will convert any object to a path, stripping away any other attributes except id and style which stay the same.  This will not change the visual appearance but you will no longer be able to use shape handles or affect it by changing any attributes except for "style", "d", and "transform".  Some functions may require paths.
+    </para>
+  </sect1>
+
+  <anchor id="Nodes"/>
+  <sect1>
+    <title>Nodes</title>
+    <para>
+To be written.
+    </para>
+  </sect1>
+
+</chapter>
+
diff --git a/src/extension/dbus/doc/spec-to-docbook.xsl b/src/extension/dbus/doc/spec-to-docbook.xsl
new file mode 100644 (file)
index 0000000..e200a05
--- /dev/null
@@ -0,0 +1,544 @@
+<?xml version='1.0'?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+  xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"
+  exclude-result-prefixes="doc">
+<!--
+     Convert D-Bus Glib xml into DocBook refentries
+     Copyright (C) 2007 William Jon McCann
+     License: GPL
+-->
+<xsl:output method="xml" indent="yes" encoding="UTF-8"/>
+
+<xsl:template match="/">
+
+<xsl:variable name="interface" select="//interface/@name"/>
+<xsl:variable name="basename">
+  <xsl:call-template name="interface-basename">
+    <xsl:with-param name="str" select="$interface"/>
+  </xsl:call-template>
+</xsl:variable>
+
+<refentry><xsl:attribute name="id"><xsl:value-of select="$basename"/></xsl:attribute>
+  <refmeta>
+    <refentrytitle role="top_of_page"><xsl:value-of select="//interface/@name"/></refentrytitle>
+  </refmeta>
+
+  <refnamediv>
+    <refname><xsl:value-of select="//interface/@name"/></refname>
+    <refpurpose><xsl:value-of select="$basename"/> interface</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv role="synopsis">
+    <title role="synopsis.title">Methods</title>
+    <synopsis>
+  <xsl:call-template name="methods-synopsis">
+    <xsl:with-param name="basename" select="$basename"/>
+  </xsl:call-template>
+    </synopsis>
+  </refsynopsisdiv>
+
+  <xsl:choose>
+    <xsl:when test="count(///signal) > 0">
+      <refsect1 role="signal_proto">
+        <title role="signal_proto.title">Signals</title>
+        <synopsis>
+          <xsl:call-template name="signals-synopsis">
+            <xsl:with-param name="basename" select="$basename"/>
+          </xsl:call-template>
+        </synopsis>
+      </refsect1>
+    </xsl:when>
+  </xsl:choose>
+
+  <refsect1 role="impl_interfaces">
+    <title role="impl_interfaces.title">Implemented Interfaces</title>
+    <para>
+    Objects implementing <xsl:value-of select="$interface"/> also implements
+    org.freedesktop.DBus.Introspectable,
+    org.freedesktop.DBus.Properties
+    </para>
+  </refsect1>
+
+  <xsl:choose>
+    <xsl:when test="count(///property) > 0">
+      <refsect1 role="properties">
+        <title role="properties.title">Properties</title>
+        <synopsis>
+          <xsl:call-template name="properties-synopsis">
+            <xsl:with-param name="basename" select="$basename"/>
+          </xsl:call-template>
+        </synopsis>
+      </refsect1>
+    </xsl:when>
+  </xsl:choose>
+
+  <refsect1 role="desc">
+    <title role="desc.title">Description</title>
+    <para>
+      <xsl:apply-templates select="//interface/doc:doc"/>
+    </para>
+  </refsect1>
+
+  <refsect1 role="details">
+    <title role="details.title">Details</title>
+    <xsl:call-template name="method-details">
+      <xsl:with-param name="basename" select="$basename"/>
+    </xsl:call-template>
+  </refsect1>
+
+  <xsl:choose>
+    <xsl:when test="count(///signal) > 0">
+      <refsect1 role="signals">
+        <title role="signals.title">Signal Details</title>
+        <xsl:call-template name="signal-details">
+          <xsl:with-param name="basename" select="$basename"/>
+        </xsl:call-template>
+      </refsect1>
+    </xsl:when>
+  </xsl:choose>
+
+  <xsl:choose>
+    <xsl:when test="count(///property) > 0">
+      <refsect1 role="property_details">
+        <title role="property_details.title">Property Details</title>
+        <xsl:call-template name="property-details">
+          <xsl:with-param name="basename" select="$basename"/>
+        </xsl:call-template>
+      </refsect1>
+    </xsl:when>
+  </xsl:choose>
+
+</refentry>
+</xsl:template>
+
+
+<xsl:template name="property-doc">
+  <xsl:apply-templates select="doc:doc/doc:description"/>
+
+  <variablelist role="params">
+    <xsl:for-each select="arg">
+<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term>
+<listitem><simpara><xsl:value-of select="doc:doc/doc:summary"/></simpara></listitem>
+</varlistentry>
+    </xsl:for-each>
+  </variablelist>
+
+  <xsl:apply-templates select="doc:doc/doc:since"/>
+  <xsl:apply-templates select="doc:doc/doc:deprecated"/>
+  <xsl:apply-templates select="doc:doc/doc:permission"/>
+  <xsl:apply-templates select="doc:doc/doc:seealso"/>
+</xsl:template>
+
+
+<xsl:template name="property-details">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///property">
+  <refsect2>
+    <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>:<xsl:value-of select="@name"/></xsl:attribute></anchor>The "<xsl:value-of select="@name"/>" property</title>
+<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm>
+<programlisting>'<xsl:value-of select="@name"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="2"/></xsl:call-template>
+<xsl:call-template name="property-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/></xsl:call-template></programlisting>
+  </refsect2>
+
+  <xsl:call-template name="property-doc"/>
+
+  </xsl:for-each>
+</xsl:template>
+
+<xsl:template name="signal-doc">
+  <xsl:apply-templates select="doc:doc/doc:description"/>
+
+  <variablelist role="params">
+    <xsl:for-each select="arg">
+<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term>
+<listitem><simpara><xsl:value-of select="doc:doc/doc:summary"/></simpara></listitem>
+</varlistentry>
+    </xsl:for-each>
+  </variablelist>
+
+  <xsl:apply-templates select="doc:doc/doc:since"/>
+  <xsl:apply-templates select="doc:doc/doc:deprecated"/>
+  <xsl:apply-templates select="doc:doc/doc:permission"/>
+  <xsl:apply-templates select="doc:doc/doc:seealso"/>
+</xsl:template>
+
+<xsl:template name="signal-details">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///signal">
+  <refsect2>
+    <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>::<xsl:value-of select="@name"/></xsl:attribute></anchor>The <xsl:value-of select="@name"/> signal</title>
+<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm>
+<programlisting><xsl:value-of select="@name"/> (<xsl:call-template name="signal-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/><xsl:with-param name="prefix" select="."/></xsl:call-template>)</programlisting>
+  </refsect2>
+
+  <xsl:call-template name="signal-doc"/>
+
+  </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="doc:code">
+<programlisting>
+<xsl:apply-templates />
+</programlisting>
+</xsl:template>
+
+<xsl:template match="doc:tt">
+  <literal>
+    <xsl:apply-templates />
+  </literal>
+</xsl:template>
+
+<xsl:template match="doc:i">
+  <emphasis>
+    <xsl:apply-templates />
+  </emphasis>
+</xsl:template>
+
+<xsl:template match="doc:b">
+  <emphasis role="bold">
+    <xsl:apply-templates />
+  </emphasis>
+</xsl:template>
+
+<xsl:template match="doc:ulink">
+  <ulink>
+    <xsl:attribute name="url"><xsl:value-of select="@url"/></xsl:attribute>
+    <xsl:value-of select="."/>
+  </ulink>
+</xsl:template>
+
+<xsl:template match="doc:summary">
+  <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="doc:example">
+<informalexample>
+<xsl:apply-templates />
+</informalexample>
+</xsl:template>
+
+<xsl:template name="listitems-do-term">
+  <xsl:param name="str"/>
+  <xsl:choose>
+    <xsl:when test="string-length($str) > 0">
+      <emphasis role="bold"><xsl:value-of select="$str"/>: </emphasis>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="do-listitems">
+  <xsl:for-each select="doc:item">
+    <listitem>
+      <xsl:call-template name="listitems-do-term"><xsl:with-param name="str" select="doc:term"/></xsl:call-template>
+      <xsl:apply-templates select="doc:definition"/>
+    </listitem>
+  </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="doc:list">
+  <para>
+    <xsl:choose>
+      <xsl:when test="contains(@type,'number')">
+        <orderedlist>
+          <xsl:call-template name="do-listitems"/>
+        </orderedlist>
+      </xsl:when>
+      <xsl:otherwise>
+        <itemizedlist>
+          <xsl:call-template name="do-listitems"/>
+        </itemizedlist>
+      </xsl:otherwise>
+    </xsl:choose>
+  </para>
+</xsl:template>
+
+<xsl:template match="doc:para">
+<para>
+<xsl:apply-templates />
+</para>
+</xsl:template>
+
+<xsl:template match="doc:description">
+<xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="doc:since">
+<para role="since">Since <xsl:value-of select="@version"/>
+</para>
+</xsl:template>
+
+<xsl:template match="doc:deprecated">
+  <xsl:variable name="name" select="../../@name"/>
+  <xsl:variable name="parent">
+    <xsl:call-template name="interface-basename">
+      <xsl:with-param name="str" select="../../../@name"/>/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:variable name="type" select="name(../..)"/>
+
+  <para role="deprecated">
+  <warning><para><literal><xsl:value-of select="$name"/></literal> is deprecated since version <xsl:value-of select="@version"/> and should not be used in newly-written code. Use
+
+  <xsl:variable name="to">
+  <xsl:choose>
+    <xsl:when test="contains($type,'property')">
+      <xsl:value-of select="$parent"/>:<xsl:value-of select="@instead"/>
+    </xsl:when>
+    <xsl:when test="contains($type,'signal')">
+      <xsl:value-of select="$parent"/>::<xsl:value-of select="@instead"/>
+    </xsl:when>
+    <xsl:when test="contains($type,'method')">
+      <xsl:value-of select="$parent"/>.<xsl:value-of select="@instead"/>
+    </xsl:when>
+    <xsl:when test="contains($type,'interface')">
+      <xsl:value-of select="@instead"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="@instead"/>
+    </xsl:otherwise>
+  </xsl:choose>
+  </xsl:variable>
+
+  <xsl:call-template name="create-link">
+    <xsl:with-param name="type" select="$type"/>
+    <xsl:with-param name="to" select="$to"/>
+    <xsl:with-param name="val" select="@instead"/>
+  </xsl:call-template>
+instead.</para></warning>
+</para>
+</xsl:template>
+
+<xsl:template match="doc:permission">
+<para role="permission">
+<xsl:apply-templates />
+</para>
+</xsl:template>
+
+<xsl:template match="doc:errors">
+<para role="errors">
+<xsl:apply-templates />
+</para>
+</xsl:template>
+
+<xsl:template match="doc:seealso">
+<para>
+See also:
+<xsl:apply-templates />
+
+</para>
+</xsl:template>
+
+<xsl:template name="create-link">
+  <xsl:param name="type"/>
+  <xsl:param name="to"/>
+  <xsl:param name="val"/>
+
+  <xsl:choose>
+    <xsl:when test="contains($type,'property')">
+      <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><literal><xsl:value-of select="$val"/></literal></link>
+    </xsl:when>
+    <xsl:when test="contains($type,'signal')">
+      <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><literal><xsl:value-of select="$val"/></literal></link>
+    </xsl:when>
+    <xsl:when test="contains($type,'method')">
+      <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><function><xsl:value-of select="$val"/></function></link>
+    </xsl:when>
+    <xsl:when test="contains($type,'interface')">
+      <link><xsl:attribute name="linkend"><xsl:value-of select="$to"/></xsl:attribute><xsl:value-of select="$val"/></link>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="doc:ref">
+  <xsl:call-template name="create-link">
+    <xsl:with-param name="type" select="@type"/>
+    <xsl:with-param name="to" select="@to"/>
+    <xsl:with-param name="val" select="."/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="method-doc">
+  <xsl:apply-templates select="doc:doc/doc:description"/>
+
+  <variablelist role="params">
+    <xsl:for-each select="arg">
+<varlistentry><term><parameter><xsl:value-of select="@name"/></parameter>:</term>
+<listitem><simpara><xsl:apply-templates select="doc:doc/doc:summary"/></simpara></listitem>
+</varlistentry>
+    </xsl:for-each>
+  </variablelist>
+
+  <xsl:apply-templates select="doc:doc/doc:since"/>
+  <xsl:apply-templates select="doc:doc/doc:deprecated"/>
+
+  <xsl:choose>
+    <xsl:when test="count(doc:doc/doc:errors) > 0">
+      <refsect3>
+        <title>Errors</title>
+        <variablelist role="errors">
+          <xsl:for-each select="doc:doc/doc:errors/doc:error">
+            <varlistentry>
+              <term><parameter><xsl:value-of select="@name"/></parameter>:</term>
+              <listitem><simpara><xsl:apply-templates select="."/></simpara></listitem>
+            </varlistentry>
+          </xsl:for-each>
+        </variablelist>
+      </refsect3>
+    </xsl:when>
+  </xsl:choose>
+
+  <xsl:choose>
+    <xsl:when test="count(doc:doc/doc:permission) > 0">
+      <refsect3>
+        <title>Permissions</title>
+        <xsl:apply-templates select="doc:doc/doc:permission"/>
+      </refsect3>
+    </xsl:when>
+  </xsl:choose>
+
+  <xsl:apply-templates select="doc:doc/doc:seealso"/>
+</xsl:template>
+
+<xsl:template name="method-details">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///method">
+    <refsect2>
+    <title><anchor role="function"><xsl:attribute name="id"><xsl:value-of select="$basename"/>.<xsl:value-of select="@name"/></xsl:attribute></anchor><xsl:value-of select="@name"/> ()</title>
+<indexterm><primary><xsl:value-of select="@name"/></primary><secondary><xsl:value-of select="$basename"/></secondary></indexterm>
+<programlisting><xsl:value-of select="@name"/> (<xsl:call-template name="method-args"><xsl:with-param name="indent" select="string-length(@name) + 2"/><xsl:with-param name="prefix" select="."/></xsl:call-template>)</programlisting>
+    </refsect2>
+
+    <xsl:call-template name="method-doc"/>
+
+  </xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="properties-synopsis">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="///property/@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///property">
+<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>:<xsl:value-of select="@name"/></xsl:attribute>'<xsl:value-of select="@name"/>'</link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template> <xsl:call-template name="property-args"><xsl:with-param name="indent" select="$longest + 2"/></xsl:call-template>
+</xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="signals-synopsis">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="///signal/@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///signal">
+<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>::<xsl:value-of select="@name"/></xsl:attribute><xsl:value-of select="@name"/></link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template>(<xsl:call-template name="signal-args"><xsl:with-param name="indent" select="$longest + 2"/><xsl:with-param name="prefix" select="///signal"/></xsl:call-template>)
+</xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="methods-synopsis">
+  <xsl:param name="basename"/>
+  <xsl:variable name="longest">
+    <xsl:call-template name="find-longest">
+      <xsl:with-param name="set" select="///method/@name"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:for-each select="///method">
+<link><xsl:attribute name="linkend"><xsl:value-of select="$basename"/>.<xsl:value-of select="@name"/></xsl:attribute><xsl:value-of select="@name"/></link><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@name) + 1"/></xsl:call-template>(<xsl:call-template name="method-args"><xsl:with-param name="indent" select="$longest + 2"/><xsl:with-param name="prefix" select="///method"/></xsl:call-template>)
+</xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="method-args"><xsl:param name="indent"/><xsl:param name="prefix"/><xsl:variable name="longest"><xsl:call-template name="find-longest"><xsl:with-param name="set" select="$prefix/arg/@type"/></xsl:call-template></xsl:variable><xsl:for-each select="arg"><xsl:value-of select="@direction"/>
+<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="4 - string-length(@direction)"/></xsl:call-template>'<xsl:value-of select="@type"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@type) + 1"/></xsl:call-template>
+<xsl:value-of select="@name"/><xsl:if test="not(position() = last())">,
+<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$indent"/></xsl:call-template></xsl:if>
+</xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="signal-args"><xsl:param name="indent"/><xsl:param name="prefix"/><xsl:variable name="longest"><xsl:call-template name="find-longest"><xsl:with-param name="set" select="$prefix/arg/@type"/></xsl:call-template></xsl:variable><xsl:for-each select="arg">'<xsl:value-of select="@type"/>'<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$longest - string-length(@type) + 1"/></xsl:call-template>
+<xsl:value-of select="@name"/><xsl:if test="not(position() = last())">,
+<xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="$indent"/></xsl:call-template></xsl:if>
+</xsl:for-each>
+</xsl:template>
+
+
+<xsl:template name="property-args"><xsl:param name="indent"/>
+<xsl:value-of select="@access"/><xsl:call-template name="pad-spaces"><xsl:with-param name="width" select="9 - string-length(@access) + 1"/></xsl:call-template>'<xsl:value-of select="@type"/>'
+</xsl:template>
+
+
+<xsl:template name="pad-spaces">
+  <xsl:param name="width"/>
+  <xsl:variable name="spaces" xml:space="preserve">                                                                        </xsl:variable>
+  <xsl:value-of select="substring($spaces,1,$width)"/>
+</xsl:template>
+
+
+<xsl:template name="find-longest">
+  <xsl:param name="set"/>
+  <xsl:param name="index" select="1"/>
+  <xsl:param name="longest" select="0"/>
+
+  <xsl:choose>
+    <xsl:when test="$index > count($set)">
+      <!--finished looking-->
+      <xsl:value-of select="$longest"/>
+    </xsl:when>
+    <xsl:when test="string-length($set[$index])>$longest">
+      <!--found new longest-->
+      <xsl:call-template name="find-longest">
+        <xsl:with-param name="set" select="$set"/>
+        <xsl:with-param name="index" select="$index + 1"/>
+        <xsl:with-param name="longest" select="string-length($set[$index])"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <!--this isn't any longer-->
+      <xsl:call-template name="find-longest">
+        <xsl:with-param name="set" select="$set"/>
+        <xsl:with-param name="index" select="$index + 1"/>
+        <xsl:with-param name="longest" select="$longest"/>
+      </xsl:call-template>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+
+<xsl:template name="interface-basename">
+  <xsl:param name="str"/>
+  <xsl:choose>
+    <xsl:when test="contains($str,'.')">
+      <xsl:call-template name="interface-basename">
+       <xsl:with-param name="str" select="substring-after($str,'.')"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$str"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp
new file mode 100644 (file)
index 0000000..e2d7a41
--- /dev/null
@@ -0,0 +1,1336 @@
+/*
+ * This is where the implementation of the DBus based document API lives.
+ * All the methods in here (except in the helper section) are 
+ * designed to be called remotly via DBus. application-interface.cpp
+ * has the methods used to connect to the bus and get a document instance.
+ *
+ * Documentation for these methods is in document-interface.xml
+ * which is the "gold standard" as to how the interface should work.
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "document-interface.h"
+#include <string.h>
+
+#include "verbs.h"
+#include "helper/action.h" //sp_action_perform
+
+#include "inkscape.h" //inkscape_find_desktop_by_dkey, activate desktops
+
+#include "desktop-handles.h" //sp_desktop_document()
+#include "xml/repr.h" //sp_repr_document_new
+
+#include "sp-object.h"
+
+#include "document.h" // sp_document_repr_doc
+
+#include "desktop-style.h" //sp_desktop_get_style
+
+#include "selection.h" //selection struct
+#include "selection-chemistry.h"// lots of selection functions
+
+#include "sp-ellipse.h"
+
+#include "layer-fns.h" //LPOS_BELOW
+
+#include "style.h" //style_write
+
+#include "file.h" //IO
+
+#include "extension/system.h" //IO
+
+#include "extension/output.h" //IO
+
+#include "print.h" //IO
+
+#include "live_effects/parameter/text.h" //text
+#include "display/canvas-text.h" //text
+
+//#include "2geom/svg-path-parser.h" //get_node_coordinates
+
+/****************************************************************************
+     HELPER / SHORTCUT FUNCTIONS
+****************************************************************************/
+
+/* 
+ * This function or the one below it translates the user input for an object
+ * into Inkscapes internal representation.  It is called by almost every
+ * method so it should be as fast as possible.
+ *
+ * (eg turns "rect2234" to an SPObject or Inkscape::XML::Node)
+ *
+ * If the internal representation changes (No more 'id' attributes) this is the
+ * place to adjust things.
+ */
+Inkscape::XML::Node *
+get_repr_by_name (SPDesktop *desk, gchar *name, GError **error)
+{
+    /* ALTERNATIVE (is this faster if only repr is needed?)
+    Inkscape::XML::Node *node = sp_repr_lookup_name((doc->root)->repr, name);
+    */
+    Inkscape::XML::Node * node = sp_desktop_document(desk)->getObjectById(name)->repr;
+    if (!node)
+    {
+        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name);
+        return NULL;
+    }
+    return node;
+}
+
+/* 
+ * See comment for get_repr_by_name, above.
+ */
+SPObject *
+get_object_by_name (SPDesktop *desk, gchar *name, GError **error)
+{
+    SPObject * obj = sp_desktop_document(desk)->getObjectById(name);
+    if (!obj)
+    {
+        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object '%s' not found in document.", name);
+        return NULL;
+    }
+    return obj;
+}
+
+/*
+ * Tests for NULL strings and throws an appropriate error.
+ * Every method that takes a string parameter (other than the 
+ * name of an object, that's tested seperatly) should call this.
+ */
+gboolean
+dbus_check_string (gchar *string, GError ** error, const gchar * errorstr)
+{
+    if (string == NULL)
+    {
+        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "%s", errorstr);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+/* 
+ * This is used to return object values to the user
+ */
+const gchar *
+get_name_from_object (SPObject * obj)
+{
+    return obj->repr->attribute("id"); 
+}
+
+/*
+ * Some verbs (cut, paste) only work on the active layer.
+ * This makes sure that the document that is about to recive a command is active.
+ */
+void
+desktop_ensure_active (SPDesktop* desk) {
+    if (desk != SP_ACTIVE_DESKTOP)
+        inkscape_activate_desktop (desk);
+    return;
+}
+
+gdouble
+selection_get_center_x (Inkscape::Selection *sel){
+    NRRect *box = g_new(NRRect, 1);;
+    box = sel->boundsInDocument(box);
+    return box->x0 + ((box->x1 - box->x0)/2);
+}
+
+gdouble
+selection_get_center_y (Inkscape::Selection *sel){
+    NRRect *box = g_new(NRRect, 1);;
+    box = sel->boundsInDocument(box);
+    return box->y0 + ((box->y1 - box->y0)/2);
+}
+
+/* 
+ * This function is used along with selection_restore to
+ * take advantage of functionality provided by a selection
+ * for a single object.
+ *
+ * It saves the current selection and sets the selection to 
+ * the object specified.  Any selection verb can be used on the
+ * object and then selection_restore is called, restoring the 
+ * original selection.
+ *
+ * This should be mostly transparent to the user who need never
+ * know we never bothered to implement it seperatly.  Although
+ * they might see the selection box flicker if used in a loop.
+ */
+const GSList *
+selection_swap(SPDesktop *desk, gchar *name, GError **error)
+{
+    Inkscape::Selection *sel = sp_desktop_selection(desk);
+    const GSList *oldsel = g_slist_copy((GSList *)sel->list());
+    
+    sel->set(get_object_by_name(desk, name, error));
+    return oldsel;
+}
+
+/*
+ * See selection_swap, above
+ */
+void
+selection_restore(SPDesktop *desk, const GSList * oldsel)
+{
+    Inkscape::Selection *sel = sp_desktop_selection(desk);
+    sel->setList(oldsel);
+}
+
+/*
+ * Shortcut for creating a Node.
+ */
+Inkscape::XML::Node *
+dbus_create_node (SPDesktop *desk, const gchar *type)
+{
+    SPDocument * doc = sp_desktop_document (desk);
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+
+    return xml_doc->createElement(type);
+}
+
+/*
+ * Called by the shape creation functions.  Gets the default style for the doc
+ * or sets it arbitrarily if none.
+ *
+ * There is probably a better way to do this (use the shape tools default styles)
+ * but I'm not sure how.
+ */
+gchar *
+finish_create_shape (DocumentInterface *object, GError **error, Inkscape::XML::Node *newNode, gchar *desc)
+{
+
+    SPCSSAttr *style = sp_desktop_get_style(object->desk, TRUE);
+    
+    if (style) {
+        newNode->setAttribute("style", sp_repr_css_write_string(style), TRUE);
+    }
+    else {
+        newNode->setAttribute("style", "fill:#0000ff;fill-opacity:1;stroke:#c900b9;stroke-width:0;stroke-miterlimit:0;stroke-opacity:1;stroke-dasharray:none", TRUE);
+    }
+
+    object->desk->currentLayer()->appendChildRepr(newNode);
+    object->desk->currentLayer()->updateRepr();
+
+    if (object->updates)
+        sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)desc);
+    //else
+        //document_interface_pause_updates(object, error);
+
+    return strdup(newNode->attribute("id"));
+}
+
+/*
+ * This is the code used internally to call all the verbs.
+ *
+ * It handles error reporting and update pausing (which needs some work.)
+ * This is a good place to improve efficiency as it is called a lot.
+ *
+ * document_interface_call_verb is similar but is called by the user.
+ */
+gboolean
+dbus_call_verb (DocumentInterface *object, int verbid, GError **error)
+{    
+    SPDesktop *desk2 = object->desk;
+    desktop_ensure_active (desk2);
+    
+    if ( desk2 ) {
+        Inkscape::Verb *verb = Inkscape::Verb::get( verbid );
+        if ( verb ) {
+            SPAction *action = verb->get_action(desk2);
+            if ( action ) {
+                //if (!object->updates)
+                    //document_interface_pause_updates (object, error);
+                sp_action_perform( action, NULL );
+                if (object->updates)
+                    sp_document_done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip()));
+                //if (!object->updates)
+                    //document_interface_pause_updates (object, error);
+                return TRUE;
+            }
+        }
+    }
+    g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb failed to execute");
+    return FALSE;
+}
+
+/****************************************************************************
+     DOCUMENT INTERFACE CLASS STUFF
+****************************************************************************/
+
+G_DEFINE_TYPE(DocumentInterface, document_interface, G_TYPE_OBJECT)
+
+static void
+document_interface_finalize (GObject *object)
+{
+        G_OBJECT_CLASS (document_interface_parent_class)->finalize (object);
+}
+
+
+static void
+document_interface_class_init (DocumentInterfaceClass *klass)
+{
+        GObjectClass *object_class;
+        object_class = G_OBJECT_CLASS (klass);
+        object_class->finalize = document_interface_finalize;
+}
+
+static void
+document_interface_init (DocumentInterface *object)
+{
+       object->desk = NULL;
+}
+
+
+DocumentInterface *
+document_interface_new (void)
+{
+        return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL);
+}
+
+/* 
+ * Error stuff...
+ *
+ * To add a new error type, edit here and in the .h InkscapeError enum.
+ */
+GQuark
+inkscape_error_quark (void)
+{
+  static GQuark quark = 0;
+  if (!quark)
+    quark = g_quark_from_static_string ("inkscape_error");
+
+  return quark;
+}
+
+#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
+
+GType
+inkscape_error_get_type (void)
+{
+       static GType etype = 0;
+
+       if (etype == 0)
+       {
+               static const GEnumValue values[] =
+               {
+
+                       ENUM_ENTRY (INKSCAPE_ERROR_SELECTION, "Incompatible_Selection"),
+                       ENUM_ENTRY (INKSCAPE_ERROR_OBJECT, "Incompatible_Object"),
+                       ENUM_ENTRY (INKSCAPE_ERROR_VERB, "Failed_Verb"),
+                       ENUM_ENTRY (INKSCAPE_ERROR_OTHER, "Generic_Error"),
+                       { 0, 0, 0 }
+               };
+
+               etype = g_enum_register_static ("InkscapeError", values);
+       }
+
+       return etype;
+}
+
+/****************************************************************************
+     MISC FUNCTIONS
+****************************************************************************/
+
+gboolean
+document_interface_delete_all (DocumentInterface *object, GError **error)
+{
+    sp_edit_clear_all (object->desk);
+    return TRUE;
+}
+
+gboolean
+document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error)
+{
+    SPDesktop *desk2 = object->desk;
+    desktop_ensure_active (object->desk);
+    if ( desk2 ) {
+        Inkscape::Verb *verb = Inkscape::Verb::getbyid( verbid );
+        if ( verb ) {
+            SPAction *action = verb->get_action(desk2);
+            if ( action ) {
+                sp_action_perform( action, NULL );
+                if (object->updates) {
+                    sp_document_done(sp_desktop_document(desk2), verb->get_code(), g_strdup(verb->get_tip()));
+                }
+            }
+        }
+    }
+    g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb '%s' failed to execute or was not found.", verbid);
+    return FALSE;
+}
+
+
+/****************************************************************************
+     CREATION FUNCTIONS
+****************************************************************************/
+
+gchar* 
+document_interface_rectangle (DocumentInterface *object, int x, int y, 
+                              int width, int height, GError **error)
+{
+
+
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:rect");
+    sp_repr_set_int(newNode, "x", x);  //could also use newNode->setAttribute()
+    sp_repr_set_int(newNode, "y", y);
+    sp_repr_set_int(newNode, "width", width);
+    sp_repr_set_int(newNode, "height", height);
+    return finish_create_shape (object, error, newNode, (gchar *)"create rectangle");
+}
+
+gchar*
+document_interface_ellipse_center (DocumentInterface *object, int cx, int cy, 
+                                   int rx, int ry, GError **error)
+{
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path");
+    newNode->setAttribute("sodipodi:type", "arc");
+    sp_repr_set_int(newNode, "sodipodi:cx", cx);
+    sp_repr_set_int(newNode, "sodipodi:cy", cy);
+    sp_repr_set_int(newNode, "sodipodi:rx", rx);
+    sp_repr_set_int(newNode, "sodipodi:ry", ry);
+    return finish_create_shape (object, error, newNode, (gchar *)"create circle");
+}
+
+gchar* 
+document_interface_polygon (DocumentInterface *object, int cx, int cy, 
+                            int radius, int rotation, int sides, 
+                            GError **error)
+{
+    gdouble rot = ((rotation / 180.0) * 3.14159265) - ( 3.14159265 / 2.0);
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path");
+    newNode->setAttribute("inkscape:flatsided", "true");
+    newNode->setAttribute("sodipodi:type", "star");
+    sp_repr_set_int(newNode, "sodipodi:cx", cx);
+    sp_repr_set_int(newNode, "sodipodi:cy", cy);
+    sp_repr_set_int(newNode, "sodipodi:r1", radius);
+    sp_repr_set_int(newNode, "sodipodi:r2", radius);
+    sp_repr_set_int(newNode, "sodipodi:sides", sides);
+    sp_repr_set_int(newNode, "inkscape:randomized", 0);
+    sp_repr_set_svg_double(newNode, "sodipodi:arg1", rot);
+    sp_repr_set_svg_double(newNode, "sodipodi:arg2", rot);
+    sp_repr_set_svg_double(newNode, "inkscape:rounded", 0);
+
+    return finish_create_shape (object, error, newNode, (gchar *)"create polygon");
+}
+
+gchar* 
+document_interface_star (DocumentInterface *object, int cx, int cy, 
+                         int r1, int r2, int sides, gdouble rounded,
+                         gdouble arg1, gdouble arg2, GError **error)
+{
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path");
+    newNode->setAttribute("inkscape:flatsided", "false");
+    newNode->setAttribute("sodipodi:type", "star");
+    sp_repr_set_int(newNode, "sodipodi:cx", cx);
+    sp_repr_set_int(newNode, "sodipodi:cy", cy);
+    sp_repr_set_int(newNode, "sodipodi:r1", r1);
+    sp_repr_set_int(newNode, "sodipodi:r2", r2);
+    sp_repr_set_int(newNode, "sodipodi:sides", sides);
+    sp_repr_set_int(newNode, "inkscape:randomized", 0);
+    sp_repr_set_svg_double(newNode, "sodipodi:arg1", arg1);
+    sp_repr_set_svg_double(newNode, "sodipodi:arg2", arg2);
+    sp_repr_set_svg_double(newNode, "inkscape:rounded", rounded);
+
+    return finish_create_shape (object, error, newNode, (gchar *)"create star");
+}
+
+gchar* 
+document_interface_ellipse (DocumentInterface *object, int x, int y, 
+                            int width, int height, GError **error)
+{
+    int rx = width/2;
+    int ry = height/2;
+    return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error);
+}
+
+gchar* 
+document_interface_line (DocumentInterface *object, int x, int y, 
+                              int x2, int y2, GError **error)
+{
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path");
+    std::stringstream out;
+    // Not sure why this works.
+       out << "m " << x << "," << y << " " << x2 - x << "," << y2 - y;
+    newNode->setAttribute("d", out.str().c_str());
+    return finish_create_shape (object, error, newNode, (gchar *)"create line");
+}
+
+gchar* 
+document_interface_spiral (DocumentInterface *object, int cx, int cy, 
+                           int r, int revolutions, GError **error)
+{
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:path");
+    newNode->setAttribute("sodipodi:type", "spiral");
+    sp_repr_set_int(newNode, "sodipodi:cx", cx);
+    sp_repr_set_int(newNode, "sodipodi:cy", cy);
+    sp_repr_set_int(newNode, "sodipodi:radius", r);
+    sp_repr_set_int(newNode, "sodipodi:revolution", revolutions);
+    sp_repr_set_int(newNode, "sodipodi:t0", 0);
+    sp_repr_set_int(newNode, "sodipodi:argument", 0);
+    sp_repr_set_int(newNode, "sodipodi:expansion", 1);
+    gchar * retval = finish_create_shape (object, error, newNode, (gchar *)"create spiral");
+    //Makes sure there is no fill for spirals by default.
+    gchar* newString = g_strconcat(newNode->attribute("style"), ";fill:none", NULL);
+    newNode->setAttribute("style", newString);
+    g_free(newString);
+    return retval;
+}
+
+gboolean
+document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error)
+{
+    //FIXME: Not selectable (aka broken).  Needs to be rewritten completely.
+
+    SPDesktop *desktop = object->desk;
+    SPCanvasText * canvas_text = (SPCanvasText *) sp_canvastext_new(sp_desktop_tempgroup(desktop), desktop, Geom::Point(0,0), "");
+    sp_canvastext_set_text (canvas_text, text);
+    sp_canvastext_set_coords (canvas_text, x, y);
+
+    return TRUE;
+}
+
+gchar *
+document_interface_image (DocumentInterface *object, int x, int y, gchar *filename, GError **error)
+{
+    gchar * uri = g_filename_to_uri (filename, FALSE, error);
+    if (!uri)
+        return FALSE;
+    
+    Inkscape::XML::Node *newNode = dbus_create_node(object->desk, "svg:image");
+    sp_repr_set_int(newNode, "x", x);
+    sp_repr_set_int(newNode, "y", y);
+    newNode->setAttribute("xlink:href", uri);
+    
+    object->desk->currentLayer()->appendChildRepr(newNode);
+    object->desk->currentLayer()->updateRepr();
+
+    if (object->updates)
+        sp_document_done(sp_desktop_document(object->desk), 0, "Imported bitmap.");
+
+    //g_free(uri);
+    return strdup(newNode->attribute("id"));
+}
+
+gchar* 
+document_interface_node (DocumentInterface *object, gchar *type, GError **error)
+{
+    SPDocument * doc = sp_desktop_document (object->desk);
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+
+    Inkscape::XML::Node *newNode =  xml_doc->createElement(type);
+
+    object->desk->currentLayer()->appendChildRepr(newNode);
+    object->desk->currentLayer()->updateRepr();
+
+    if (object->updates)
+        sp_document_done(sp_desktop_document(object->desk), 0, (gchar *)"created empty node");
+    //else
+        //document_interface_pause_updates(object, error);
+
+    return strdup(newNode->attribute("id"));
+}
+
+/****************************************************************************
+     ENVIORNMENT FUNCTIONS
+****************************************************************************/
+gdouble
+document_interface_document_get_width (DocumentInterface *object)
+{
+    return sp_document_width(sp_desktop_document(object->desk));
+}
+
+gdouble
+document_interface_document_get_height (DocumentInterface *object)
+{
+    return sp_document_height(sp_desktop_document(object->desk));
+}
+
+gchar *
+document_interface_document_get_css (DocumentInterface *object, GError **error)
+{
+    SPCSSAttr *current = (object->desk)->current;
+    return sp_repr_css_write_string(current);
+}
+
+gboolean 
+document_interface_document_merge_css (DocumentInterface *object,
+                                       gchar *stylestring, GError **error)
+{
+    SPCSSAttr * style = sp_repr_css_attr_new();
+    sp_repr_css_attr_add_from_string (style, stylestring);
+    sp_desktop_set_style (object->desk, style);
+    return TRUE;
+}
+
+gboolean 
+document_interface_document_set_css (DocumentInterface *object,
+                                     gchar *stylestring, GError **error)
+{
+    SPCSSAttr * style = sp_repr_css_attr_new();
+    sp_repr_css_attr_add_from_string (style, stylestring);
+    //Memory leak?
+    object->desk->current = style;
+    return TRUE;
+}
+
+gboolean 
+document_interface_document_resize_to_fit_selection (DocumentInterface *object,
+                                                     GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error);
+    return TRUE;
+}
+
+/****************************************************************************
+     OBJECT FUNCTIONS
+****************************************************************************/
+
+gboolean
+document_interface_set_attribute (DocumentInterface *object, char *shape, 
+                                  char *attribute, char *newval, GError **error)
+{
+    Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error);
+
+    /* ALTERNATIVE (is this faster?)
+    Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name);
+    */
+    if (!dbus_check_string(newval, error, "New value string was empty."))
+        return FALSE;
+        
+    if (!newNode)
+        return FALSE;
+        
+    newNode->setAttribute(attribute, newval, TRUE);
+    return TRUE;
+}
+
+gboolean 
+document_interface_set_int_attribute (DocumentInterface *object, 
+                                      char *shape, char *attribute, 
+                                      int newval, GError **error)
+{
+    Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error);
+    if (!newNode)
+        return FALSE;
+        
+    sp_repr_set_int (newNode, attribute, newval);
+    return TRUE;
+}
+
+
+gboolean
+document_interface_set_double_attribute (DocumentInterface *object, 
+                                         char *shape, char *attribute, 
+                                         double newval, GError **error)
+{
+    Inkscape::XML::Node *newNode = get_repr_by_name (object->desk, shape, error);
+    
+    if (!dbus_check_string (attribute, error, "New value string was empty."))
+        return FALSE;
+    if (!newNode)
+        return FALSE;
+    
+    sp_repr_set_svg_double (newNode, attribute, newval);
+    return TRUE;
+}
+
+gchar *
+document_interface_get_attribute (DocumentInterface *object, char *shape, 
+                                  char *attribute, GError **error)
+{
+    Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error);
+
+    if (!dbus_check_string (attribute, error, "Attribute name empty."))
+        return NULL;
+    if (!newNode)
+        return NULL;
+        
+    return g_strdup(newNode->attribute(attribute));
+}
+
+gboolean
+document_interface_move (DocumentInterface *object, gchar *name, gdouble x, 
+                         gdouble y, GError **error)
+{
+    const GSList *oldsel = selection_swap(object->desk, name, error);
+    if (!oldsel)
+        return FALSE;
+    sp_selection_move (object->desk, x, 0 - y);
+    selection_restore(object->desk, oldsel);
+    return TRUE;
+}
+
+gboolean
+document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, 
+                         gdouble y, GError **error)
+{
+    const GSList *oldsel = selection_swap(object->desk, name, error);
+    if (!oldsel)
+        return FALSE;
+    Inkscape::Selection * sel = sp_desktop_selection(object->desk);
+    sp_selection_move (object->desk, x - selection_get_center_x(sel),
+                                     0 - (y - selection_get_center_y(sel)));
+    selection_restore(object->desk, oldsel);
+    return TRUE;
+}
+
+gboolean
+document_interface_object_to_path (DocumentInterface *object, 
+                                   char *shape, GError **error)
+{
+    const GSList *oldsel = selection_swap(object->desk, shape, error);
+    if (!oldsel)
+        return FALSE;
+    dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error);
+    selection_restore(object->desk, oldsel);
+    return TRUE;
+}
+
+gchar *
+document_interface_get_path (DocumentInterface *object, char *pathname, GError **error)
+{
+    Inkscape::XML::Node *node = get_repr_by_name(object->desk, pathname, error);
+    
+    if (!node)
+        return NULL;
+        
+    if (node->attribute("d") == NULL)
+    {
+        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OBJECT, "Object is not a path.");
+        return NULL;
+    }
+    return strdup(node->attribute("d"));
+}
+
+gboolean 
+document_interface_transform (DocumentInterface *object, gchar *shape,
+                              gchar *transformstr, GError **error)
+{
+    //FIXME: This should merge transformations.
+    gchar trans[] = "transform";
+    document_interface_set_attribute (object, shape, trans, transformstr, error);
+    return TRUE;
+}
+
+gchar *
+document_interface_get_css (DocumentInterface *object, gchar *shape,
+                            GError **error)
+{
+    gchar style[] = "style";
+    return document_interface_get_attribute (object, shape, style, error);
+}
+
+gboolean 
+document_interface_modify_css (DocumentInterface *object, gchar *shape,
+                               gchar *cssattrb, gchar *newval, GError **error)
+{
+    // Doesn't like non-variable strings for some reason.
+    gchar style[] = "style";
+    Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error);
+    
+    if (!dbus_check_string (cssattrb, error, "Attribute string empty."))
+        return FALSE;
+    if (!node)
+        return FALSE;
+        
+    SPCSSAttr * oldstyle = sp_repr_css_attr (node, style);
+    sp_repr_css_set_property(oldstyle, cssattrb, newval);
+    node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE);
+    return TRUE;
+}
+
+gboolean 
+document_interface_merge_css (DocumentInterface *object, gchar *shape,
+                               gchar *stylestring, GError **error)
+{
+    gchar style[] = "style";
+    
+    Inkscape::XML::Node *node = get_repr_by_name(object->desk, shape, error);
+    
+    if (!dbus_check_string (stylestring, error, "Style string empty."))
+        return FALSE;
+    if (!node)
+        return FALSE;
+        
+    SPCSSAttr * newstyle = sp_repr_css_attr_new();
+    sp_repr_css_attr_add_from_string (newstyle, stylestring);
+
+    SPCSSAttr * oldstyle = sp_repr_css_attr (node, style);
+
+    sp_repr_css_merge(oldstyle, newstyle);
+    node->setAttribute (style, sp_repr_css_write_string (oldstyle), TRUE);
+    return TRUE;
+}
+
+gboolean 
+document_interface_set_color (DocumentInterface *object, gchar *shape,
+                              int r, int g, int b, gboolean fill, GError **error)
+{
+    gchar style[15];
+    if (r<0 || r>255 || g<0 || g>255 || b<0 || b>255)
+    {
+        g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "Given (%d,%d,%d).  All values must be between 0-255 inclusive.", r, g, b);
+        return FALSE;
+    }
+    
+    if (fill)
+        snprintf(style, 15, "fill:#%.2x%.2x%.2x", r, g, b);
+    else
+        snprintf(style, 15, "stroke:#%.2x%.2x%.2x", r, g, b);
+    
+    if (strcmp(shape, "document") == 0)
+        return document_interface_document_merge_css (object, style, error);
+    
+    return document_interface_merge_css (object, shape, style, error);
+}
+
+gboolean 
+document_interface_move_to_layer (DocumentInterface *object, gchar *shape, 
+                              gchar *layerstr, GError **error)
+{
+    const GSList *oldsel = selection_swap(object->desk, shape, error);
+    if (!oldsel)
+        return FALSE;
+        
+    document_interface_selection_move_to_layer(object, layerstr, error);
+    selection_restore(object->desk, oldsel);
+    return TRUE;
+}
+
+GArray *
+document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape)
+{
+    //FIXME: Needs lot's of work.
+/*
+    Inkscape::XML::Node *shapenode = get_repr_by_name (object->desk, shape, error);
+    if (shapenode == NULL || shapenode->attribute("d") == NULL) {
+        return FALSE;
+    }
+    char * path = strdup(shapenode->attribute("d"));
+    printf("PATH: %s\n", path);
+    
+    Geom::parse_svg_path (path);
+    return NULL;
+    */
+    return NULL;
+}
+
+
+/****************************************************************************
+     FILE I/O FUNCTIONS
+****************************************************************************/
+
+gboolean 
+document_interface_save (DocumentInterface *object, GError **error)
+{
+    SPDocument * doc = sp_desktop_document(object->desk);
+    printf("1:  %s\n2:  %s\n3:  %s\n", doc->uri, doc->base, doc->name);
+    if (doc->uri)
+        return document_interface_save_as (object, doc->uri, error);
+    return FALSE;
+}
+
+gboolean 
+document_interface_load (DocumentInterface *object, 
+                        gchar *filename, GError **error)
+{
+    desktop_ensure_active (object->desk);
+    const Glib::ustring file(filename);
+    sp_file_open(file, NULL, TRUE, TRUE);
+    if (object->updates)
+        sp_document_done(sp_desktop_document(object->desk), SP_VERB_FILE_OPEN, "Opened File");
+    return TRUE;
+}
+
+gboolean 
+document_interface_save_as (DocumentInterface *object, 
+                           gchar *filename, GError **error)
+{
+    SPDocument * doc = sp_desktop_document(object->desk);
+    #ifdef WITH_GNOME_VFS
+    const Glib::ustring file(filename);
+    return file_save_remote(doc, file, NULL, TRUE, TRUE);
+    #endif
+    if (!doc || strlen(filename)<1) //Safety check
+        return false;
+
+    try {
+        Inkscape::Extension::save(NULL, doc, filename,
+                 false, false, true);
+    } catch (...) {
+        //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved."));
+        return false;
+    }
+
+    //SP_ACTIVE_DESKTOP->event_log->rememberFileSave();
+    //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::NORMAL_MESSAGE, "Document saved.");
+    return true;
+}
+
+gboolean
+document_interface_mark_as_unmodified (DocumentInterface *object, GError **error)
+{
+    SPDocument * doc = sp_desktop_document(object->desk);
+    if (doc)
+        doc->modified_since_save = FALSE;
+    return TRUE;
+}
+
+/*
+gboolean 
+document_interface_print_to_file (DocumentInterface *object, GError **error)
+{
+    SPDocument * doc = sp_desktop_document(object->desk);
+    sp_print_document_to_file (doc, g_strdup("/home/soren/test.pdf"));
+                               
+    return TRUE;
+}
+*/
+/****************************************************************************
+     PROGRAM CONTROL FUNCTIONS
+****************************************************************************/
+
+gboolean
+document_interface_close (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_FILE_CLOSE_VIEW, error);
+}
+
+gboolean
+document_interface_exit (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_FILE_QUIT, error);
+}
+
+gboolean
+document_interface_undo (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_EDIT_UNDO, error);
+}
+
+gboolean
+document_interface_redo (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_EDIT_REDO, error);
+}
+
+
+
+/****************************************************************************
+     UPDATE FUNCTIONS 
+     FIXME: This would work better by adding a flag to SPDesktop to prevent
+     updating but that would be very intrusive so for now there is a workaround.
+     Need to make sure it plays well with verbs because they are used so much.
+****************************************************************************/
+
+void
+document_interface_pause_updates (DocumentInterface *object, GError **error)
+{
+    object->updates = FALSE;
+    object->desk->canvas->drawing_disabled = 1;
+    //object->desk->canvas->need_redraw = 0;
+    //object->desk->canvas->need_repick = 0;
+    //sp_desktop_document(object->desk)->root->uflags = FALSE;
+    //sp_desktop_document(object->desk)->root->mflags = FALSE;
+}
+
+void
+document_interface_resume_updates (DocumentInterface *object, GError **error)
+{
+    object->updates = TRUE;
+    object->desk->canvas->drawing_disabled = 0;
+    //object->desk->canvas->need_redraw = 1;
+    //object->desk->canvas->need_repick = 1;
+    //sp_desktop_document(object->desk)->root->uflags = TRUE;
+    //sp_desktop_document(object->desk)->root->mflags = TRUE;
+    //sp_desktop_document(object->desk)->_updateDocument();
+    //FIXME: use better verb than rect.
+    sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions");
+}
+
+void
+document_interface_update (DocumentInterface *object, GError **error)
+{
+    sp_desktop_document(object->desk)->root->uflags = TRUE;
+    sp_desktop_document(object->desk)->root->mflags = TRUE;
+    object->desk->enableInteraction();
+    sp_desktop_document(object->desk)->_updateDocument();
+    object->desk->disableInteraction();
+    sp_desktop_document(object->desk)->root->uflags = FALSE;
+    sp_desktop_document(object->desk)->root->mflags = FALSE;
+    //sp_document_done(sp_desktop_document(object->desk), SP_VERB_CONTEXT_RECT, "Multiple actions");
+}
+
+/****************************************************************************
+     SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.)
+****************************************************************************/
+
+gboolean
+document_interface_selection_get (DocumentInterface *object, char ***out, GError **error)
+{
+    Inkscape::Selection * sel = sp_desktop_selection(object->desk);
+    GSList const *oldsel = sel->list();
+
+    int size = g_slist_length((GSList *) oldsel);
+
+    *out = g_new0 (char *, size + 1);
+
+    int i = 0;
+    for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) {
+        (*out)[i] = g_strdup(SP_OBJECT(iter->data)->repr->attribute("id"));
+        i++;
+    }
+    (*out)[i] = NULL;
+
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_add (DocumentInterface *object, char *name, GError **error)
+{
+    SPObject * obj = get_object_by_name(object->desk, name, error);
+    if (!obj)
+        return FALSE;
+    
+    Inkscape::Selection *selection = sp_desktop_selection(object->desk);
+
+    selection->add(obj);
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_add_list (DocumentInterface *object, 
+                                       char **names, GError **error)
+{
+    int i;
+    for (i=0;names[i] != NULL;i++) {
+        document_interface_selection_add(object, names[i], error);       
+    }
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_set (DocumentInterface *object, char *name, GError **error)
+{
+    SPDocument * doc = sp_desktop_document (object->desk);
+    Inkscape::Selection *selection = sp_desktop_selection(object->desk);
+    selection->set(doc->getObjectById(name));
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_set_list (DocumentInterface *object, 
+                                       gchar **names, GError **error)
+{
+    sp_desktop_selection(object->desk)->clear();
+    int i;
+    for (i=0;names[i] != NULL;i++) {
+        document_interface_selection_add(object, names[i], error);       
+    }
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_rotate (DocumentInterface *object, int angle, GError **error)
+{
+    Inkscape::Selection *selection = sp_desktop_selection(object->desk);
+    sp_selection_rotate(selection, angle);
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_delete (DocumentInterface *object, GError **error)
+{
+    //sp_selection_delete (object->desk);
+    return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error);
+}
+
+gboolean
+document_interface_selection_clear (DocumentInterface *object, GError **error)
+{
+    sp_desktop_selection(object->desk)->clear();
+    return TRUE;
+}
+
+gboolean
+document_interface_select_all (DocumentInterface *object, GError **error)
+{
+    //sp_edit_select_all (object->desk);
+    return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL, error);
+}
+
+gboolean
+document_interface_select_all_in_all_layers(DocumentInterface *object, 
+                                            GError **error)
+{
+    //sp_edit_select_all_in_all_layers (object->desk);
+    return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error);
+}
+
+gboolean
+document_interface_selection_box (DocumentInterface *object, int x, int y,
+                                  int x2, int y2, gboolean replace, 
+                                  GError **error)
+{
+    //FIXME: implement.
+    return FALSE;
+}
+
+gboolean
+document_interface_selection_invert (DocumentInterface *object, GError **error)
+{
+    //sp_edit_invert (object->desk);
+    return dbus_call_verb (object, SP_VERB_EDIT_INVERT, error);
+}
+
+gboolean
+document_interface_selection_group (DocumentInterface *object, GError **error)
+{
+    //sp_selection_group (object->desk);
+    return dbus_call_verb (object, SP_VERB_SELECTION_GROUP, error);
+}
+gboolean
+document_interface_selection_ungroup (DocumentInterface *object, GError **error)
+{
+    //sp_selection_ungroup (object->desk);
+    return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error);
+}
+gboolean
+document_interface_selection_cut (DocumentInterface *object, GError **error)
+{
+    //desktop_ensure_active (object->desk);
+    //sp_selection_cut (object->desk);
+    return dbus_call_verb (object, SP_VERB_EDIT_CUT, error);
+}
+
+gboolean
+document_interface_selection_copy (DocumentInterface *object, GError **error)
+{
+    //desktop_ensure_active (object->desk);
+    //sp_selection_copy ();
+    return dbus_call_verb (object, SP_VERB_EDIT_COPY, error);
+}
+/*
+gboolean
+document_interface_selection_paste (DocumentInterface *object, GError **error)
+{
+    desktop_ensure_active (object->desk);
+                    if (!object->updates)
+                    document_interface_pause_updates (object, error);
+    sp_selection_paste (object->desk, TRUE);
+                    if (!object->updates)
+                    document_interface_pause_updates (object, error);
+    return TRUE;
+    //return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error);
+}
+*/
+gboolean
+document_interface_selection_paste (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_EDIT_PASTE, error);
+}
+
+gboolean
+document_interface_selection_scale (DocumentInterface *object, gdouble grow, GError **error)
+{
+    Inkscape::Selection *selection = sp_desktop_selection(object->desk);
+    if (!selection)
+    {
+        return FALSE;
+    }     
+    sp_selection_scale (selection, grow);
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_move (DocumentInterface *object, gdouble x, gdouble y, GError **error)
+{
+    sp_selection_move (object->desk, x, 0 - y); //switching coordinate systems.
+    return TRUE;
+}
+
+gboolean
+document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdouble y, GError **error)
+{
+    Inkscape::Selection * sel = sp_desktop_selection(object->desk);
+
+    Geom::OptRect sel_bbox = sel->bounds();
+    if (sel_bbox) {
+        Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) );
+        sp_selection_move_relative(sel, m, true);
+    }
+    return TRUE;
+}
+
+//FIXME: does not paste in new layer.
+// This needs to use lower level cut_impl and paste_impl (messy)
+// See the built-in sp_selection_to_next_layer and duplicate.
+gboolean 
+document_interface_selection_move_to_layer (DocumentInterface *object,
+                                            gchar *layerstr, GError **error)
+{
+    SPDesktop * dt = object->desk;
+
+    Inkscape::Selection *selection = sp_desktop_selection(dt);
+
+    // check if something is selected
+    if (selection->isEmpty())
+        return FALSE;
+
+    SPObject *next = get_object_by_name(object->desk, layerstr, error);
+    
+    if (!next)
+        return FALSE;
+
+    if (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0) {
+
+        sp_selection_cut(dt);
+
+        dt->setCurrentLayer(next);
+
+        sp_selection_paste(dt, TRUE);
+        }
+    return TRUE;
+}
+
+GArray *
+document_interface_selection_get_center (DocumentInterface *object)
+{
+    Inkscape::Selection * sel = sp_desktop_selection(object->desk);
+
+    if (sel) 
+    {
+        gdouble x = selection_get_center_x(sel);
+        gdouble y = selection_get_center_y(sel);
+        GArray * intArr = g_array_new (TRUE, TRUE, sizeof(double));
+
+        g_array_append_val (intArr, x);
+        g_array_append_val (intArr, y);
+        return intArr;
+    }
+
+    return NULL;
+}
+
+gboolean 
+document_interface_selection_to_path (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error);    
+}
+
+
+gchar *
+document_interface_selection_combine (DocumentInterface *object, gchar *cmd,
+                                      GError **error)
+{
+    if (strcmp(cmd, "union") == 0)
+        dbus_call_verb (object, SP_VERB_SELECTION_UNION, error);
+    else if (strcmp(cmd, "intersection") == 0)
+        dbus_call_verb (object, SP_VERB_SELECTION_INTERSECT, error);
+    else if (strcmp(cmd, "difference") == 0)
+        dbus_call_verb (object, SP_VERB_SELECTION_DIFF, error);
+    else if (strcmp(cmd, "exclusion") == 0)
+        dbus_call_verb (object, SP_VERB_SELECTION_SYMDIFF, error);
+    else
+        return NULL;
+
+    if (sp_desktop_selection(object->desk)->singleRepr() != NULL)
+        return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id"));
+    return NULL;
+}
+
+gboolean
+document_interface_selection_divide (DocumentInterface *object, char ***out, GError **error)
+{
+    dbus_call_verb (object, SP_VERB_SELECTION_CUT, error);
+
+    return document_interface_selection_get (object, out, error);
+}
+
+gboolean
+document_interface_selection_change_level (DocumentInterface *object, gchar *cmd,
+                                      GError **error)
+{
+    if (strcmp(cmd, "raise") == 0)
+        return dbus_call_verb (object, SP_VERB_SELECTION_RAISE, error);
+    if (strcmp(cmd, "lower") == 0)
+        return dbus_call_verb (object, SP_VERB_SELECTION_LOWER, error);
+    if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0))
+        return dbus_call_verb (object, SP_VERB_SELECTION_TO_FRONT, error);
+    if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0))
+        return dbus_call_verb (object, SP_VERB_SELECTION_TO_BACK, error);
+    return TRUE;
+}
+
+/****************************************************************************
+     LAYER FUNCTIONS
+****************************************************************************/
+
+gchar *
+document_interface_layer_new (DocumentInterface *object, GError **error)
+{
+    SPDesktop * dt = object->desk;
+    SPObject *new_layer = Inkscape::create_layer(dt->currentRoot(), dt->currentLayer(), Inkscape::LPOS_BELOW);
+    dt->setCurrentLayer(new_layer);
+    return g_strdup(get_name_from_object (new_layer));
+}
+
+gboolean 
+document_interface_layer_set (DocumentInterface *object,
+                              gchar *layerstr, GError **error)
+{
+    SPObject * obj = get_object_by_name (object->desk, layerstr, error);
+    
+    if (!obj)
+        return FALSE;
+        
+    object->desk->setCurrentLayer (obj);
+    return TRUE;
+}
+
+gchar **
+document_interface_layer_get_all (DocumentInterface *object)
+{
+    //FIXME: implement.
+    return NULL;
+}
+
+gboolean 
+document_interface_layer_change_level (DocumentInterface *object,
+                                       gchar *cmd, GError **error)
+{
+    if (strcmp(cmd, "raise") == 0)
+        return dbus_call_verb (object, SP_VERB_LAYER_RAISE, error);
+    if (strcmp(cmd, "lower") == 0)
+        return dbus_call_verb (object, SP_VERB_LAYER_LOWER, error);
+    if ((strcmp(cmd, "to_top") == 0) || (strcmp(cmd, "to_front") == 0))
+        return dbus_call_verb (object, SP_VERB_LAYER_TO_TOP, error);
+    if ((strcmp(cmd, "to_bottom") == 0) || (strcmp(cmd, "to_back") == 0))
+        return dbus_call_verb (object, SP_VERB_LAYER_TO_BOTTOM, error);
+    return TRUE;
+}
+
+gboolean 
+document_interface_layer_next (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_LAYER_NEXT, error);
+}
+
+gboolean 
+document_interface_layer_previous (DocumentInterface *object, GError **error)
+{
+    return dbus_call_verb (object, SP_VERB_LAYER_PREV, error);
+}
+
+
+
+
+
+
diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h
new file mode 100644 (file)
index 0000000..8cf9b7e
--- /dev/null
@@ -0,0 +1,399 @@
+/*
+ * This is where the implementation of the DBus based document API lives.
+ * All the methods in here (except in the helper section) are 
+ * designed to be called remotly via DBus. application-interface.cpp
+ * has the methods used to connect to the bus and get a document instance.
+ *
+ * Documentation for these methods is in document-interface.xml
+ * which is the "gold standard" as to how the interface should work.
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+#ifndef INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
+#define INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
+
+#include <glib.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include "desktop.h"
+
+#define DBUS_DOCUMENT_INTERFACE_PATH  "/org/inkscape/document"
+        
+#define TYPE_DOCUMENT_INTERFACE            (document_interface_get_type ())
+#define DOCUMENT_INTERFACE(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface))
+#define DOCUMENT_INTERFACE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass))
+#define IS_DOCUMENT_INTERFACE(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_DOCUMENT_INTERFACE))
+#define IS_DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_INTERFACE))
+#define DOCUMENT_INTERFACE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass))
+
+G_BEGIN_DECLS
+
+typedef struct _DocumentInterface DocumentInterface;
+typedef struct _DocumentInterfaceClass DocumentInterfaceClass;
+
+struct _DocumentInterface {
+        GObject parent;
+       SPDesktop *desk;
+    gboolean updates;
+};
+
+struct _DocumentInterfaceClass {
+        GObjectClass parent;
+};
+
+typedef enum
+{
+  INKSCAPE_ERROR_SELECTION,
+  INKSCAPE_ERROR_OBJECT,
+  INKSCAPE_ERROR_VERB,
+  INKSCAPE_ERROR_OTHER
+} InkscapeError;
+
+#define INKSCAPE_ERROR (inkscape_error_quark ())
+#define INKSCAPE_TYPE_ERROR (inkscape_error_get_type ()) 
+
+GQuark inkscape_error_quark (void);
+GType inkscape_error_get_type (void);
+
+struct DBUSPoint {
+    int x;
+    int y;
+};
+/****************************************************************************
+     MISC FUNCTIONS
+****************************************************************************/
+
+gboolean 
+document_interface_delete_all (DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_call_verb (DocumentInterface *object, 
+                              gchar *verbid, GError **error);
+
+/****************************************************************************
+     CREATION FUNCTIONS
+****************************************************************************/
+
+gchar* 
+document_interface_rectangle (DocumentInterface *object, int x, int y, 
+                              int width, int height, GError **error);
+
+gchar* 
+document_interface_ellipse (DocumentInterface *object, int x, int y, 
+                              int width, int height, GError **error);
+
+gchar* 
+document_interface_polygon (DocumentInterface *object, int cx, int cy, 
+                            int radius, int rotation, int sides, 
+                            GError **error);
+
+gchar* 
+document_interface_star (DocumentInterface *object, int cx, int cy, 
+                         int r1, int r2, int sides, gdouble rounded,
+                         gdouble arg1, gdouble arg2, GError **error);
+
+gchar* 
+document_interface_spiral (DocumentInterface *object, int cx, int cy, 
+                                   int r, int revolutions, GError **error);
+
+gchar* 
+document_interface_line (DocumentInterface *object, int x, int y, 
+                              int x2, int y2, GError **error);
+
+gboolean
+document_interface_text (DocumentInterface *object, int x, int y, 
+                         gchar *text, GError **error);
+                         
+gchar *
+document_interface_image (DocumentInterface *object, int x, int y, 
+                          gchar *filename, GError **error);
+
+gchar* 
+document_interface_node (DocumentInterface *object, gchar *svgtype, 
+                             GError **error);
+
+
+/****************************************************************************
+     ENVIORNMENT FUNCTIONS
+****************************************************************************/
+gdouble
+document_interface_document_get_width (DocumentInterface *object);
+
+gdouble
+document_interface_document_get_height (DocumentInterface *object);
+
+gchar *
+document_interface_document_get_css (DocumentInterface *object, GError **error);
+
+gboolean 
+document_interface_document_merge_css (DocumentInterface *object,
+                                       gchar *stylestring, GError **error);
+
+gboolean 
+document_interface_document_set_css (DocumentInterface *object,
+                                     gchar *stylestring, GError **error);
+
+gboolean 
+document_interface_document_resize_to_fit_selection (DocumentInterface *object,
+                                                     GError **error);
+
+/****************************************************************************
+     OBJECT FUNCTIONS
+****************************************************************************/
+
+gboolean
+document_interface_set_attribute (DocumentInterface *object, 
+                                  char *shape, char *attribute, 
+                                  char *newval, GError **error);
+
+gboolean
+document_interface_set_int_attribute (DocumentInterface *object, 
+                                      char *shape, char *attribute, 
+                                      int newval, GError **error);
+
+gboolean
+document_interface_set_double_attribute (DocumentInterface *object, 
+                                         char *shape, char *attribute, 
+                                         double newval, GError **error);
+
+gchar * 
+document_interface_get_attribute (DocumentInterface *object, 
+                                  char *shape, char *attribute, GError **error);
+
+gboolean 
+document_interface_move (DocumentInterface *object, gchar *name, 
+                         gdouble x, gdouble y, GError **error);
+
+gboolean 
+document_interface_move_to (DocumentInterface *object, gchar *name, 
+                            gdouble x, gdouble y, GError **error);
+
+gboolean
+document_interface_object_to_path (DocumentInterface *object, 
+                                   char *shape, GError **error);
+
+gchar *
+document_interface_get_path (DocumentInterface *object, 
+                             char *pathname, GError **error);
+
+gboolean 
+document_interface_transform (DocumentInterface *object, gchar *shape,
+                              gchar *transformstr, GError **error);
+
+gchar *
+document_interface_get_css (DocumentInterface *object, gchar *shape,
+                            GError **error);
+
+gboolean 
+document_interface_modify_css (DocumentInterface *object, gchar *shape,
+                               gchar *cssattrb, gchar *newval, GError **error);
+
+gboolean 
+document_interface_merge_css (DocumentInterface *object, gchar *shape,
+                               gchar *stylestring, GError **error);
+
+gboolean 
+document_interface_set_color (DocumentInterface *object, gchar *shape,
+                              int r, int g, int b, gboolean fill, GError **error);
+
+gboolean 
+document_interface_move_to_layer (DocumentInterface *object, gchar *shape, 
+                              gchar *layerstr, GError **error);
+
+
+GArray *
+document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape);
+
+/****************************************************************************
+     FILE I/O FUNCTIONS
+****************************************************************************/
+
+gboolean 
+document_interface_save (DocumentInterface *object, GError **error);
+
+gboolean 
+document_interface_load (DocumentInterface *object, 
+                        gchar *filename, GError **error);
+
+gboolean 
+document_interface_save_as (DocumentInterface *object, 
+                           gchar *filename, GError **error);
+
+gboolean 
+document_interface_mark_as_unmodified (DocumentInterface *object, GError **error);
+/*
+gboolean 
+document_interface_print_to_file (DocumentInterface *object, GError **error);
+*/
+
+/****************************************************************************
+     PROGRAM CONTROL FUNCTIONS
+****************************************************************************/
+
+gboolean
+document_interface_close (DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_exit (DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_undo (DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_redo (DocumentInterface *object, GError **error);
+
+
+/****************************************************************************
+     UPDATE FUNCTIONS
+****************************************************************************/
+void
+document_interface_pause_updates (DocumentInterface *object, GError **error);
+
+void
+document_interface_resume_updates (DocumentInterface *object, GError **error);
+
+void
+document_interface_update (DocumentInterface *object, GError **error);
+
+/****************************************************************************
+     SELECTION FUNCTIONS
+****************************************************************************/
+gboolean
+document_interface_selection_get (DocumentInterface *object, char ***out, GError **error);
+
+gboolean
+document_interface_selection_add (DocumentInterface *object, 
+                                  char *name, GError **error);
+
+gboolean
+document_interface_selection_add_list (DocumentInterface *object, 
+                                       char **names, GError **error);
+
+gboolean
+document_interface_selection_set (DocumentInterface *object, 
+                                  char *name, GError **error);
+
+gboolean
+document_interface_selection_set_list (DocumentInterface *object, 
+                                       gchar **names, GError **error);
+
+gboolean
+document_interface_selection_rotate (DocumentInterface *object, 
+                                     int angle, GError **error);
+
+gboolean
+document_interface_selection_delete(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_clear(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_select_all(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_select_all_in_all_layers(DocumentInterface *object, 
+                                            GError **error);
+
+gboolean
+document_interface_selection_box (DocumentInterface *object, int x, int y,
+                                  int x2, int y2, gboolean replace, 
+                                  GError **error);
+
+gboolean
+document_interface_selection_invert (DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_group(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_ungroup(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_cut(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_copy(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_paste(DocumentInterface *object, GError **error);
+
+gboolean
+document_interface_selection_scale (DocumentInterface *object, 
+                                    gdouble grow, GError **error);
+
+gboolean
+document_interface_selection_move (DocumentInterface *object, gdouble x, 
+                                   gdouble y, GError **error);
+
+gboolean
+document_interface_selection_move_to (DocumentInterface *object, gdouble x, 
+                                      gdouble y, GError **error);
+
+gboolean 
+document_interface_selection_move_to_layer (DocumentInterface *object,
+                                            gchar *layerstr, GError **error);
+
+GArray * 
+document_interface_selection_get_center (DocumentInterface *object);
+
+gboolean 
+document_interface_selection_to_path (DocumentInterface *object, GError **error);
+
+gchar *
+document_interface_selection_combine (DocumentInterface *object, gchar *cmd,
+                                      GError **error);
+
+gboolean
+document_interface_selection_divide (DocumentInterface *object, 
+                                     char ***out, GError **error);
+
+
+gboolean
+document_interface_selection_change_level (DocumentInterface *object, gchar *cmd,
+                                      GError **error);
+
+/****************************************************************************
+     LAYER FUNCTIONS
+****************************************************************************/
+
+gchar *
+document_interface_layer_new (DocumentInterface *object, GError **error);
+
+gboolean 
+document_interface_layer_set (DocumentInterface *object,
+                              gchar *layerstr, GError **error);
+
+gchar **
+document_interface_layer_get_all (DocumentInterface *object);
+
+gboolean 
+document_interface_layer_change_level (DocumentInterface *object,
+                                       gchar *cmd, GError **error);
+
+gboolean 
+document_interface_layer_next (DocumentInterface *object, GError **error);
+
+gboolean 
+document_interface_layer_previous (DocumentInterface *object, GError **error);
+
+
+
+
+
+
+
+
+DocumentInterface *document_interface_new (void);
+GType document_interface_get_type (void);
+
+
+G_END_DECLS
+
+#endif // INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml
new file mode 100644 (file)
index 0000000..8b02527
--- /dev/null
@@ -0,0 +1,1355 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * This is the master description of the DBus document interface.
+ *
+ * This file is used to generate both glue code and documentation.
+ * The methods are in the same order as the .cpp/.h and the sections are labeled.
+ *
+ * Any change to method prototypes in document-interface.cpp MUST be reflected here.
+ *
+ * This file is the proverbial gold standard for the document interface. 
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+-->
+<node name="/org/inkscape/document"
+  xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"
+>
+
+  <interface name="org.inkscape.document">
+
+    <!-- MISC FUNCTIONS -->
+
+    <method name="delete_all" >
+    </method>
+
+    <method name="call_verb">
+      <arg type="s" name="verbid" direction="in">
+        <doc:doc>
+          <doc:summary>The string id of a verb.  For example: "EditSelectAll".</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method allows you to call any Inkscape verb using it's associated string.  Every button and menu item has an associated verb, so this allows access to some extra functionality if one is willing to do the prerequisite research.  The list of verbs can be found at:</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- CREATION FUNCTIONS -->
+
+    <method name="rectangle">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the top left corner of the rectangle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the top left corner of the rectangle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="width" direction="in" >
+        <doc:doc>
+          <doc:summary>Width of the rectangle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="height" direction="in" >
+        <doc:doc>
+          <doc:summary>Height of the rectangle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new rectangle.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a rectangle in the current layer using the current document style.</doc:para>
+          <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para>
+          <doc:para>Additional variables include:</doc:para>
+          <doc:para>cx and cy: set these anywhere from zero to half the width or height respectively of the rectangle to give it rounded corners.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="ellipse">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the top left corner of the ellipse.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the top left corner of the ellipse.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="width" direction="in" >
+        <doc:doc>
+          <doc:summary>Width of the ellipse.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="height" direction="in" >
+        <doc:doc>
+          <doc:summary>Height of the ellipse.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new ellipse.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a ellipse in the current layer using the current document style.</doc:para>
+          <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para>
+          <doc:para>Additional variables include:</doc:para>
+          <doc:para>"sodipodi:start" and "sodipodi:end": set these between 0 and Pi to create wedges or Pacman like shapes.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="polygon">
+      <arg type="i" name="cx" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the center of the polygon.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="cy" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the center of the polygon.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="radius" direction="in" >
+        <doc:doc>
+          <doc:summary>Radius from the center to one of the points.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="rotation" direction="in" >
+        <doc:doc>
+          <doc:summary>Angle in degrees to rotate.  0 will have the first point pointing straight up.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="sides" direction="in" >
+        <doc:doc>
+          <doc:summary>Number of sides of the polygon.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new polygon.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a polygon in the current layer using the current document style.</doc:para>
+          <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para>
+          <doc:para>Note: this is actually a <doc:ref type="method" to="document.star">star</doc:ref> with "sodipodi:flatsided" set to true, which causes it to ignore the arg2 and r2 values.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="star">
+      <arg type="i" name="cx" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the center of the star.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="cy" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the center of the star.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="r1" direction="in" >
+        <doc:doc>
+          <doc:summary>distance from the center for the first point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="r2" direction="in" >
+        <doc:doc>
+          <doc:summary>distance from the center for the second point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="arg1" direction="in" >
+        <doc:doc>
+          <doc:summary>Angle in radians for the first point.  0 is 90 degrees to the right of straight up.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="arg2" direction="in" >
+        <doc:doc>
+          <doc:summary>Angle in radians for the second point. 0 is 90 degrees to the right of straight up.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="sides" direction="in" >
+        <doc:doc>
+          <doc:summary>Number of times to repeat the points around the star.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="rounded" direction="in" >
+        <doc:doc>
+          <doc:summary>How rounded to make the star.  0 to 1 recommended for moderate to medium curves.  10 for extreme curves.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new star.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a star in the current layer using the current document style.</doc:para>
+          <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para>
+          <doc:para>Stars are quite complicated.  Here is how they are represented:  There are two points, represented by sodipodi:arg1 and sodipodi:arg2 for angle in radians and sodipodi:r1 and sodipodi:r2 for respective radius from the center point.  The further one is a point of the star, the shorter one one of the valleys.  This point and valley are repeated according to sodipodi:sides.  sodipodi:rounded controls their control handles.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="spiral">
+      <arg type="i" name="cx" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the center of the spiral.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="cy" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the center of the spiral.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="r" direction="in" >
+        <doc:doc>
+          <doc:summary>Radius of the spiral.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="revolutions" direction="in" >
+        <doc:doc>
+          <doc:summary>Number of revolutions.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new spiral.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a spiral in the current layer using the current document style.  However, fill is automatically set to "none".  Stroke is unmodified.</doc:para>
+          <doc:para>It is recommended that you save the return value if you will want to modify this particular shape later.</doc:para>
+          <doc:para>Additional variables include:</doc:para>
+          <doc:para>"sodipodi:expansion": at 1 the spiral gets bigger at a constant rate.  Less than one and the loops get tighter and tighter as it goes.  More than one and they get looser and looser.  This affects the number of revolutions so that it might not actually match the "sodipodi:revolutions" argument.</doc:para>
+          <doc:para>"sodipodi:t0": at 0 the entire spiral is drawn, at 0.5 it is only drawn %50 of the way (starting from the outside) etc.</doc:para>
+          <doc:para>"sodipodi:argument": Rotates the spiral.  In radians.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="line">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the first point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the first point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="x2" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the second point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y2" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the second point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new line.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates a line in the current layer using the current document style.  It's a path, so the only attribute it will pay any attention to is "transform".</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="text">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>The x coordinate to put the text at.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>The y coordinate to put the text at.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="text" direction="in" >
+        <doc:doc>
+          <doc:summary>The text you want.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method creates some text in the current layer.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+    
+    <method name="image">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>The x coordinate to put the image at.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>The y coordinate to put the image at.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="text" direction="in" >
+        <doc:doc>
+          <doc:summary>The full path of the image you want.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="object_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new image.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method imports a non-vector image (such as a jpeg, png, etc.) and places it at the given coordinates.  The resulting shape has no style or path but can be treated like a rectangle.  With and height can be set explicitly (will deform image) or transform strings or <doc:ref type="method" to="document.selection_scale">selection_scale()</doc:ref> can scale it relatively.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="node">
+      <arg type="s" name="svgtype" direction="in" >
+        <doc:doc>
+          <doc:summary>The type of node, probably "svg:path"</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="node_name" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new node.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Make any kind of node you want.  Mostly for making paths.  (May need to allow updateRepr to be called for it to show up.)</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- ENVIRONMENT FUNCTIONS -->
+
+    <method name="document_get_width">
+      <arg type="d" name="val" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>Document width.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Retrieve the width of the current document. anything outside the boundary will not be printed or exported but will be saved.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="document_get_height">
+      <arg type="d" name="val" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>Document height.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Retrieve the height of the current document. anything outside the boundary will not be printed or exported but will be saved.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="document_get_css">
+      <arg type="s" name="css" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>CSS attribute string for the document.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Get the current style for the document.  All new shapes will use this style if it exists.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="document_set_css">
+      <arg type="s" name="stylestring" direction="in" >
+        <doc:doc>
+          <doc:summary>A new CSS attribute string for the document.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Set the current style for the document.  All new shapes will use this style if it exists.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="document_merge_css">
+      <arg type="s" name="stylestring" direction="in" >
+        <doc:doc>
+          <doc:summary>A new CSS attribute string for the document.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Merge this this string with the current style for the document.  All new shapes will use this style if it exists.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref>, <doc:ref type="method" to="document.merge_css">merge_css()</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="document_resize_to_fit_selection">
+      <doc:doc>
+        <doc:description>
+          <doc:para>Resize the document to contain all of the currently selected objects.</doc:para>
+          <doc:para>This ensures that the image is not clipped when printing or exporting.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- OBJECT FUNCTIONS -->
+
+    <method name="set_attribute">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="attribute" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of the attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="newval" direction="in" >
+        <doc:doc>
+          <doc:summary>The new value of the attribute.  This will overwrite anything already set.  To merge styles, see <doc:ref type="method" to="document.merge_css">merge_css()</doc:ref>. </doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Set any attribute, the available attributes depend on what kind of shape the object node represents.  See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="set_int_attribute">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="attribute" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of the attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="newval" direction="in" >
+        <doc:doc>
+          <doc:summary>The new value of the attribute.  This will overwrite anything already set.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Set any attribute, the available attributes depend on what kind of shape the object node represents.  See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para>
+          <doc:para>This is a convenience function for <doc:ref type="method" to="document.set_attribute">set_attribute()</doc:ref>.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="set_double_attribute">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="attribute" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of the attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="newval" direction="in" >
+        <doc:doc>
+          <doc:summary>The new value of the attribute.  This will overwrite anything already set.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Set any attribute, the available attributes depend on what kind of shape the node represents.  See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para>
+          <doc:para>This is a convenience function for <doc:ref type="method" to="document.set_attribute">set_attribute()</doc:ref>.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="get_attribute">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="attribute" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of the attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="val" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The current value of the attribute.  String is a copy and must be freed.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Get the value of any attribute.  Not all objects will have every attribute their type supports, some are optional.   See <doc:ref type="method" to="document.rectangle">shape creation functions</doc:ref> for more details.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="move">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>Distance to move along the x axis.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Distance to move along the y axis.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This will move a shape (or any object) relative to it's current location.</doc:para>
+          <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="move_to">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>the x coordinate of the desired location.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>the y coordinate of the desired location.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This will move a shape (or any object) to an absolute location.  The point moved is the center of the bounding box, which is usually similar to the center of the shape.</doc:para>
+          <doc:para>Note that creating a rectangle or ellipse at 100,100 and calling move_to to move it to 100,100 will not produce the same results.</doc:para>
+          <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="object_to_path">
+      <arg type="s" name="objectname" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Turns an object into a path.  Most objects contain paths (except rectangles) but are not paths themselves. </doc:para>
+          <doc:para>This will remove every attribute except d (the path attribute) style and id.  id will not change.  The appearance will be the same as well, it essentially encodes all information about the shape into the path.</doc:para>
+          <doc:para>After doing this you will no longer be able to modify the shape using shape specific attributes (cx, radius etc.) except transform</doc:para>
+          <doc:para>Required for certain functions that work on paths (not yet present in this API.)</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Paths">Paths</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="get_path">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="val" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The path of the object.  NULL if the object has no path.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Get the path value of an object.  Equivilent to calling <doc:ref type="method" to="document.get_attribute">get_attribte()</doc:ref> with argument "d".  Will not turn object into a path if it is not already.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Paths">Paths</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="transform">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of any node or object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="transformstr" direction="in" >
+        <doc:doc>
+          <doc:summary>A string that represents a transformation.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Takes a transformation string ("matrix(0.96629885,0.25742286,-0.25742286,0.96629885,0,0)" or "rotate(45)") and applies it to any shape or path.</doc:para>
+          <doc:para>Will merge with existing transformations.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="get_css">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>Any object with a style attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="css" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>A CSS Style string</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Retrieve the style of a object.  Equivalent to calling <doc:ref type="method" to="document.get_attribute">get_attribute()</doc:ref> for "style".</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="modify_css">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>Any object with a style attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="cssattrib" direction="in" >
+        <doc:doc>
+          <doc:summary>An attribute such as "fill" or "stroke-width".</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="newval" direction="in" >
+        <doc:doc>
+          <doc:summary>The new value.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Set a particular attribute of a style string.  Overwrites just that part of the style.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="merge_css">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>Any object with a style attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="stylestring" direction="in" >
+        <doc:doc>
+          <doc:summary>A full or partial CSS Style string.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Takes a CSS Style string and merges it with the objects current style, overwriting only the elements present in stylestring.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Style Strings">Style Strings</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+    
+    <method name="set_color">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>Any object, or 'document' to apply to document style.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="red" direction="in" >
+        <doc:doc>
+          <doc:summary>The red component.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="green" direction="in" >
+        <doc:doc>
+          <doc:summary>The green component.</doc:summary>
+        </doc:doc>
+      </arg>
+            <arg type="i" name="blue" direction="in" >
+        <doc:doc>
+          <doc:summary>The blue component.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="b" name="fill" direction="in" >
+        <doc:doc>
+          <doc:summary>True to change fill color, false for stroke color.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Modifies the fill or stroke color of an object (or the document style) based on RGB values.</doc:para>
+          <doc:para>Red green and blue must be between 0-255 inclusive.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="move_to_layer">
+      <arg type="s" name="objectname" direction="in" >
+        <doc:doc>
+          <doc:summary>The id of an object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="layername" direction="in" >
+        <doc:doc>
+          <doc:summary>A layer name.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Moves an object to a different layer.</doc:para>
+          <doc:para>Will error if layer does not exist.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="document.layer_new">layer_new()</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="get_node_coordinates">
+      <arg type="s" name="shape" direction="in" >
+        <doc:doc>
+          <doc:summary>A object that contains a path ("d") attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="ai" name="points" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>An array of points.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Returns an array of all of the X,Y coordinates of the points in the objects path.</doc:para>
+          <doc:para>If the path is a closed loop the first point is repeated at the end.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- FILE I/O FUNCTIONS -->
+
+    <method name="save" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Saves the current document with current name or a default name if has not been saved before.</doc:para>
+          <doc:para>Will overwrite without confirmation.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="save_as">
+      <arg type="s" name="pathname" direction="in" >
+        <doc:doc>
+          <doc:summary>The path for the file to be saved as.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Saves the current document as pathname.</doc:para>
+          <doc:para>Will overwrite without confirmation.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="load">
+      <arg type="s" name="pathname" direction="in" >
+        <doc:doc>
+          <doc:summary>The path to a valid svg file.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Loads the file at pathname.</doc:para>
+          <doc:para>Will lose all unsaved work in current document.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="mark_as_unmodified" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Marks the document as unmodified/saved.</doc:para>
+          <doc:para>Will prevent save confirmation on close if called at end of script.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+    <!--
+    <method name="print_to_file" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Prints the current document with default settings.</doc:para>
+          <doc:para>Will only print things visible within the document boundaries.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="document.document_resize_to_fit_selection">document_resize_to_fit_selection()</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+    -->
+
+    <!-- PROGRAM CONTROL FUNCTIONS -->
+
+    <method name="close" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Close this document.</doc:para>
+          <doc:para>You will not be able to send any more commands on this interface.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="exit" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Exit Inkscape.</doc:para>
+          <doc:para>You will not be able to send any more commands on any interface.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="undo" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Undo the last action.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="redo" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Redo the last undone action.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- UPDATE FUNCTIONS -->
+
+    <method name="pause_updates" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>When updates are paused Inkscape will not draw every change as it is made.  Also you will not be able to undo individual actions made while updates were paused and will only be able to undo them in a group.  Inkscape may refresh the screen every couple of seconds even with updates off.</doc:para>
+          <doc:para>The advantage is a 2-5x speed increase, depending on the type of functions being called.  This is most useful when creating large numbers of shapes.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="resume_updates" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Resume updates after they have been paused.  If undo is called at this point it will undo everything that happened since pause_updates() was called.</doc:para>
+          <doc:para>This will update the display to show any changes that happened while updates were paused, a separate call to update() is not necessary.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="update" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>This will update the document once if updates are paused but it will not resume updates.</doc:para>
+          <doc:para>This could be used to check on the progress of a complex drawing function, or to add in undo steps at certain points in a render.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- SELECTION FUNCTIONS -->
+
+    <method name="selection_get">
+      <arg type="as" name="listy" direction="out" >
+       <!-- <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> -->
+        <doc:doc>
+          <doc:summary>List of the ids of currently selected objects.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Returns the current selection in the form of a list of ids of selected objects.</doc:para>
+          <doc:para>Manipulating this list will not affect the selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_add">
+      <arg type="s" name="name" direction="in" >
+        <doc:doc>
+          <doc:summary>A object to add to the selection.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Adds a single object to the selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_add_list">
+      <arg type="as" name="name" direction="in" >
+        <doc:doc>
+          <doc:summary>An array of object ids to add to the selection.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Adds a list of objects to the selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_set">
+      <arg type="s" name="name" direction="in" >
+        <doc:doc>
+          <doc:summary>A object to select.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Replaces the selection with one containing just this object.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_set_list">
+      <arg type="as" name="name" direction="in" >
+        <doc:doc>
+          <doc:summary>A list of objects to select.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Replaces the selection with one containing just these objects.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_rotate">
+      <arg type="i" name="angle" direction="in" >
+        <doc:doc>
+          <doc:summary>Angle in degrees to rotate.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Rotates the selection around the center of it's bounding box.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_delete" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Delete all objects in the selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_clear" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Deselect everything.  Selection will be empty.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="select_all" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Select all objects in current layer.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="select_all_in_all_layers" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Select all objects in every layer.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_box">
+      <arg type="i" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the first point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the first point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="x2" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate for the second point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="i" name="y2" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate for the second point.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="b" name="replace" direction="in" >
+        <doc:doc>
+          <doc:summary>True to replace selection, false to add to selection.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This method finds all of the objects inside the box and adds them to the current selection.  If replace is true it will clear the old selection first.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_invert" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Invert the selection in the current layer.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_group" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Group the selection.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Groups">Groups</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_ungroup" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Ungroup the selection.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Groups">Groups</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_cut" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Cut the current selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_copy" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Copy the current selection.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_paste" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Paste the current selection at the same location it was cut from.</doc:para>
+          <doc:para>To paste to a particular location, simply use selection_paste() followed by <doc:ref type="method" to="document.selection_move_to">selection_move_to()</doc:ref>.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_scale">
+      <arg type="d" name="grow" direction="in" >
+        <doc:doc>
+          <doc:summary>The amount to scale the selection, 1 has no effect. Between 0 and 1 will shrink it proportionally.  Greater than one will grow it proportionally.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Scale the selection relative to it's current size.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_move">
+      <arg type="d" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>Amount to move in the x direction.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Amount to move in the y direction.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This will move the selection relative to it's current location.</doc:para>
+          <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_move_to">
+      <arg type="d" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>X coordinate to move to.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>Y coordinate to move to.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>This will move the center of the selection to a specific location.</doc:para>
+          <doc:para>This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_move_to_layer">
+      <arg type="s" name="layer" direction="in" >
+        <doc:doc>
+          <doc:summary>layer to move the selection to.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Move every item in the selection to a different layer.</doc:para>
+          <doc:para>Will error if layer does not exist.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_get_center">
+      <arg type="ad" name="centerpoint" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>Center of the selection.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Gets the center of the selections bounding box in X,Y coordinates.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Coordinate System">Coordinate System</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_to_path" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Turns all the objects in the selection into paths.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="method" to="document.object_to_path">object_to_path()</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="selection_combine" >
+      <arg type="s" name="type" direction="in" >
+        <doc:doc>
+          <doc:summary>Type of combination.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="newpath" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The new path created, if there is one.  NULL otherwise.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Will erase all objects in the selection and replace with a single aggregate path.</doc:para>
+          <doc:para>There are 5 types that can be passed in:</doc:para>
+          <doc:para>Union: The new shape is all of the other shapes put together, even if they don't overlap (paths can have multiple non-contiguous areas.)</doc:para>
+          <doc:para>Intersection:  The new shape is composed of the area where ALL the objects in the selection overlap.  If there is no area where all shapes overlap the new shape will be empty.</doc:para>
+          <doc:para>Difference: The area of the second shape is subtracted from the first, only works with two objects.</doc:para>
+          <doc:para>Exclusion: The new shape is the area(s) where none of the objects in the selection overlaped.  Only works with two objects.</doc:para>
+          <doc:para>Division: the first object is split into multiple segments by the second object.  Only works with two objects and if multiple paths result they are grouped and the group id is returned.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_divide">
+      <arg type="as" name="pieces" direction="out" >
+       <!-- <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> -->
+        <doc:doc>
+          <doc:summary>List of the ids of resulting paths.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Returns the result of cutting the bottom object by all other intersecting paths.</doc:para>
+          <doc:para>This may make many seperate layers.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_change_level" >
+      <arg type="s" name="command" direction="in" >
+        <doc:doc>
+          <doc:summary>How to change the level</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="b" name="objectsmoved" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>True if the objects changed levels.  False if they don't(if they were already on top when being raised for example.)</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Will change the level of a selection, respective of other objects in the same layer.  Will not affect the overlap of objects in different layers.  Will do nothing if the selection contains objects in multiple layers.</doc:para>
+          <doc:para>There are 4 commands that can be passed in:</doc:para>
+          <doc:para>"raise" or "lower": Move the selection one level up, or one level down.</doc:para>
+          <doc:para>"to_top" of "to_bottom": Move the selection above all other objects or below all other objects.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <!-- LAYER FUNCTIONS -->
+
+    <method name="layer_new">
+      <arg type="s" name="layername" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The name of the new layer.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Turns all the objects in the selection into paths.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="layer_set">
+      <arg type="s" name="layer" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of any layer.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Sets the layer given as the current layer</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="layer_get_all">
+      <arg type="as" name="layers" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/>
+        <doc:doc>
+          <doc:summary>list of layers.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Get a list of all the layers in this document.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="layer_change_level" >
+      <arg type="s" name="command" direction="in" >
+        <doc:doc>
+          <doc:summary>How to change the level</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="b" name="layermoved" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>True if the layer was moved.  False if it was not (if it was already on top when being raised for example.)</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Will change the level of a layer, respective of other layers.  Will not affect the relative level of objects within the layer.</doc:para>
+          <doc:para>There are 4 commands that can be passed in:</doc:para>
+          <doc:para>"raise" or "lower": Move the layer one level up, or one level down.</doc:para>
+          <doc:para>"to_top" of "to_bottom": Move the layer above all other layers or below all other layers.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="layer_next" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Sets the next (or higher) layer as active.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+    <method name="layer_previous" >
+      <doc:doc>
+        <doc:description>
+          <doc:para>Sets the previous (or lower) layer as active.</doc:para>
+        </doc:description>
+        <doc:seealso><doc:ref type="interface" to="Layers and Levels">Layers and Levels</doc:ref></doc:seealso>
+      </doc:doc>
+    </method>
+
+
+  </interface>
+</node>
diff --git a/src/extension/dbus/org.inkscape.service.in b/src/extension/dbus/org.inkscape.service.in
new file mode 100644 (file)
index 0000000..484c8e5
--- /dev/null
@@ -0,0 +1,5 @@
+[D-BUS Service]
+Name=org.inkscape
+Exec=bindir/bin/inkscape
+
+
diff --git a/src/extension/dbus/proposed-interface.xml b/src/extension/dbus/proposed-interface.xml
new file mode 100644 (file)
index 0000000..c281aff
--- /dev/null
@@ -0,0 +1,191 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ * These are some of the proposed functions for the document interface.
+ *
+ * It is only used in generating documentation.
+ *
+ * None of these methods are implemented.  If someone does code one of 
+ * these methods, remove it from here and add it to document-interface.xml.
+ *
+ * Authors:
+ *   Soren Berg <Glimmer07@gmail.com>
+ *
+ * Copyright (C) 2009 Soren Berg
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+-->
+<node name="/org/inkscape/proposed"
+  xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"
+>
+  <interface name="org.inkscape.proposed">
+
+    <signal name="Signals_Proposal">
+      <doc:doc>
+        <doc:description>
+          <doc:para>Signals would undoubtedly be a useful thing to have in many circumstances.  They are in proposed for two reasons: One, they complicate things for script writers and may conflict with the proposed C wrapper library.  Two, I'm not sure how much coding it would take to implement them because I am familiar with neither Dbus signals or Inkscape events.  Until I have done more experimenting I don't want to promise anything I'm not sure can be implemented in a timely fashion.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ObjectResized">
+      <arg name="object_name" type="s">
+        <doc:doc>
+          <doc:summary>The id of the object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when an object has been resized.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ObjectMoved">
+      <arg name="object_name" type="s">
+        <doc:doc>
+          <doc:summary>The id of the object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when an object has been moved.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ObjectStyleModified">
+      <arg name="object_name" type="s">
+        <doc:doc>
+          <doc:summary>The id of the object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when the style of an object has been changed.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ObjectCreated">
+      <arg name="object_name" type="s">
+        <doc:doc>
+          <doc:summary>The id of the object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when an object has been created.  Possibly useful for working in conjunction with a live user.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <signal name="ObjectAddedToSelection">
+      <arg name="object_name" type="s">
+        <doc:doc>
+          <doc:summary>The id of the object.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Emitted when an object has been added to the selection.  Possibly useful for working in conjunction with a live user.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </signal>
+
+    <method name="path_new" >
+      <arg type="d" name="x" direction="in" >
+        <doc:doc>
+          <doc:summary>The x value to begin the path.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="d" name="y" direction="in" >
+        <doc:doc>
+          <doc:summary>The y value to begin the path.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Begins a new path, extra nodes can be added with path_append().</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="path_append" >
+      <arg type="s" name="path" direction="in" >
+        <doc:doc>
+          <doc:summary>The name of the path to append to.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="type" direction="in" >
+        <doc:doc>
+          <doc:summary>A single letter denoting what type of node is beeing appended.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="ad" name="arguments" direction="in" >
+        <doc:doc>
+          <doc:summary>An array of numbers that describe the position and attributes of the path node.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Adds to an existing path.  Close the path by sending "z" and no arguments.</doc:para>
+          <doc:para>You can no longer append to a path if it is closed.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+
+<!-- USE document-subset.h FILES -->
+    <method name="get_parent" >
+      <arg type="s" name="type" direction="in" >
+        <doc:doc>
+          <doc:summary>Any node with an "id" attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="s" name="parentid" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The id of this nodes parent, NULL if toplevel.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Returns the parent of any node.  This function along with <doc:ref type="method" to="proposed.get_children">get_children()</doc:ref> can be used to navigate the XML tree.  In proposed because I think it might confuse users who don't know about the SVG tree structure.  In the main API I have de-emphasized nodes and required no knowledge of internal representation.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="get_children" >
+      <arg type="s" name="type" direction="in" >
+        <doc:doc>
+          <doc:summary>Any node with an "id" attribute.</doc:summary>
+        </doc:doc>
+      </arg>
+      <arg type="as" name="parentid" direction="out" >
+        <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/>
+        <doc:doc>
+          <doc:summary>The ids of this nodes children, NULL if bottom level.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Returns the children of any node.  This function along with <doc:ref type="method" to="proposed.get_parent">get_parent()</doc:ref> can be used to navigate the XML tree.  In proposed because I think it might confuse users who don't know about the SVG tree structure.  In the main API I have de-emphasized nodes and required no knowledge of internal representation.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+    <method name="selection_remove">
+      <arg type="s" name="name" direction="in" >
+        <doc:doc>
+          <doc:summary>A object to remove from the selection.</doc:summary>
+        </doc:doc>
+      </arg>
+      <doc:doc>
+        <doc:description>
+          <doc:para>Removes a single object from the selection.  In proposed because I already have a ton of selection functions and am not sure people would need this.</doc:para>
+        </doc:description>
+      </doc:doc>
+    </method>
+
+  </interface>
+</node>
diff --git a/src/extension/dbus/pytester.py b/src/extension/dbus/pytester.py
new file mode 100644 (file)
index 0000000..d4c41fb
--- /dev/null
@@ -0,0 +1,290 @@
+#####################################################################
+# Python test script for Inkscape DBus API.
+#
+# Contains many examples of functions and various stress tests etc.
+# Multiple tests can be run at once but the output will be a bit chaotic.
+# List of test functions can be found at the bottom of the script. 
+#####################################################################
+
+import dbus
+import random
+
+#####################################################################
+# Various test functions, called at bottom of script
+#####################################################################
+
+def randomrect (document):
+  document.rectangle( random.randint(0,1000), 
+                      random.randint(0,1000),
+                      random.randint(1,100),
+                      random.randint(1,100))
+
+def lottarects ( document ):
+  document.pause_updates()
+  listy = []
+  for x in range(1,2000):
+    if x == 1000:
+      print "HALFWAY"
+    if x == 1:
+      print "BEGUN"
+    document.rectangle( 0, 0, 100, 100)
+    #randomrect(document)
+  print "DONE"
+  for x in listy:
+    print x
+    selection_set(x)
+  document.resume_updates()
+  
+def lottaverbs (doc):
+  doc.pause_updates()
+  doc.document_set_css ("fill:#ff0000;fill-opacity:.5;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none")
+  doc.rectangle( 0, 0, 100, 100)
+  doc.select_all()
+  doc.selection_copy()
+  for x in range(1,2000):
+    if x == 1000:
+      print "HALFWAY"
+    if x == 1:
+      print "BEGUN"
+    doc.selection_paste()
+    #doc.rectangle( 0, 0, 100, 100)
+  doc.resume_updates()
+  
+def testDrawing (doc):
+  doc.document_set_css ("fill:#000000;fill-opacity:.5;stroke:#000000;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none")
+  doc.ellipse( 0, 0, 100, 100)
+  doc.select_all()
+  doc.selection_copy()
+  for x in range(1,2000):
+    if x == 1000:
+      print "HALFWAY"
+    if x == 1:
+      print "BEGUN"
+    doc.selection_paste()
+    newrect = doc.selection_get()[0]
+    doc.set_color(newrect, 255 - x%255, 0, 200, True)
+    doc.set_color(newrect, 0, 255 - x%75, x%75, False)
+    doc.mark_as_unmodified()
+
+
+def testcopypaste (document ):
+  #document.pause_updates()
+  print document.rectangle (400, 500, 100, 100)
+  print document.rectangle (200, 200, 100, 100)
+  document.select_all()
+  document.selection_copy()
+  document.selection_paste()
+  #document.resume_updates()
+
+def testShapes (doc):
+  doc.rectangle (0, 0, 100, 100)
+  doc.ellipse (100, 100, 100, 100)
+  doc.star (250, 250, 50, 25, 5, False, .9, 1.4)
+  doc.polygon (350, 350, 50, 0, 5)
+  doc.line (400,400,500,500)
+  doc.spiral (550,550,50,3)
+
+def testMovement (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (0, 100, 100, 100)
+  rect3 = doc.rectangle (0, 200, 100, 100)
+  doc.select_all()
+  doc.move(rect2, 100,100)
+  
+def testImport (doc):
+  # CHANGE TO LOCAL SVG FILE!
+  img1 = doc.image(0,0, "/home/soren/chavatar.jpg")
+  doc.selection_add(img1)
+  doc.selection_scale(500)
+  doc.transform(img1, "rotate(30)")
+
+def testSelections (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (0, 100, 100, 100)
+  rect3 = doc.rectangle (0, 200, 100, 100)
+  rect4 = doc.rectangle (0, 300, 100, 100)
+
+  doc.selection_add (rect1)
+  center = doc.selection_get_center()
+  for d in center:
+    print d
+  doc.selection_to_path()
+  doc.get_path(rect1)
+  doc.selection_move(100.0, 100.0)
+  doc.selection_set(rect2)
+  doc.selection_move_to(0.0,0.0)
+  doc.selection_set(rect3)
+  doc.move(rect4, 500.0, 500.0)
+  doc.select_all()
+  doc.selection_to_path()
+  result = doc.selection_get()
+  print len(result)
+  for d in result:
+    print d
+
+def testLevels (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  rect4 = doc.rectangle (60, 60, 100, 100)
+
+  doc.selection_set(rect1)
+  doc.selection_change_level("raise")
+
+  doc.selection_set(rect4)
+  doc.selection_change_level("to_bottom")
+
+def testCombinations (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  rect4 = doc.rectangle (60, 60, 100, 100)
+  rect5 = doc.rectangle (80, 80, 100, 100)
+  rect6 = doc.rectangle (100, 100, 100, 100)
+  rect7 = doc.rectangle (120, 120, 100, 100)
+  rect8 = doc.rectangle (140, 140, 100, 100)
+  rect9 = doc.rectangle (160, 160, 100, 100)
+  rect10 = doc.rectangle (180, 180, 100, 100)
+
+  doc.selection_set_list([rect1, rect2])
+  print doc.selection_combine("union")
+  doc.selection_set_list([rect3, rect4])
+  print doc.selection_combine("intersection")
+  doc.selection_set_list([rect5, rect6])
+  print doc.selection_combine("difference")
+  doc.selection_set_list([rect7, rect8])
+  print doc.selection_combine("exclusion")
+  doc.selection_set_list([rect9, rect10])
+  for d in doc.selection_divide():
+    print d
+
+def testTransforms (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  doc.set_attribute(rect1, "transform", "matrix(0.08881734,0.94288151,-0.99604793,0.68505564,245.36153,118.60315)")
+  doc.selection_set(rect1)
+
+  doc.selection_move_to(200, 200)
+
+def testLayer (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  print doc.new_layer()
+  rect2 = doc.rectangle (20, 20, 100, 100)
+
+def testGetSelection (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  doc.select_all()
+  result = doc.selection_get()
+  print result
+  print len(result)
+  for d in result:
+    print d
+
+
+def testDocStyle (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  doc.document_set_css ("fill:#ff0000;fill-opacity:.5;stroke:#0000ff;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none")
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  doc.document_set_css ("fill:#ffff00;fill-opacity:1;stroke:#009002;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none")
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  doc.document_set_css ("fill:#00ff00;fill-opacity:1")
+  rect4 = doc.rectangle (60, 60, 100, 100)
+
+def testStyle (doc):
+  doc.document_set_css ("fill:#ffff00;fill-opacity:1;stroke:#009002;stroke-width:5;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none")
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  rect4 = doc.rectangle (60, 60, 100, 100)
+
+  doc.modify_css (rect3, "fill-opacity", ".5")
+  doc.merge_css (rect4, "fill:#0000ff;fill-opacity:.25;")
+  print doc.get_css (rect4)
+
+def testLayers (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  layer1 = doc.layer_new()
+  layer2 = doc.layer_new()
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  doc.selection_add(rect3)
+  doc.selection_move_to_layer(layer1)
+
+def testLoadSave (doc):
+  doc.load("/home/soren/testfile.svg")
+  rect2 = doc.rectangle (0, 0, 200, 200)
+  doc.save_as("/home/soren/testsave.svg")
+  rect1 = doc.rectangle (20, 20, 200, 200)
+  doc.save()
+  rect3 = doc.rectangle (40, 40, 200, 200)
+  doc.save_as("/home/soren/testsave2.svg")
+
+def testArray (doc):
+  rect1 = doc.rectangle (0, 0, 100, 100)
+  rect2 = doc.rectangle (20, 20, 100, 100)
+  rect3 = doc.rectangle (40, 40, 100, 100)
+  doc.selection_set_list([rect1, rect2, rect3])
+
+def testPath (doc):
+  cr1 = doc.ellipse(0,0,50,50)
+  print doc.get_path(cr1)
+  doc.object_to_path(cr1)
+  print doc.get_path(cr1)
+  #doc.get_node_coordinates(cr1)
+
+# Needs work.
+def testText(doc):
+  print doc.text(200, 200, "svg:text")
+  
+
+#####################################################################
+# Setup bus connection, create documents.
+#####################################################################
+
+# Connect to bus
+bus = dbus.SessionBus()
+
+# Get interface for default document 
+inkdoc1 = bus.get_object('org.inkscape', '/org/inkscape/desktop_0')
+doc1 = dbus.Interface(inkdoc1, dbus_interface="org.inkscape.document")
+
+# Create new window and get the interface for that. (optional)
+inkapp = bus.get_object('org.inkscape',
+                       '/org/inkscape/application')
+desk2 = inkapp.desktop_new(dbus_interface='org.inkscape.application')
+inkdoc2 = bus.get_object('org.inkscape', desk2)
+doc2 = dbus.Interface(inkdoc2, dbus_interface="org.inkscape.document")
+
+
+#####################################################################
+# Call desired test functions
+#####################################################################
+
+#lottaverbs (doc1)
+#lottarects (doc1)
+#testDrawing (doc1)
+
+#doc1.pause_updates()
+
+testShapes(doc1)
+#testMovement(doc1)
+#testImport(doc1) # EDIT FUNCTION TO OPEN EXISTING FILE!
+#testcopypaste (doc1)
+#testTransforms (doc1)
+#testDocStyle(doc1)
+#testLayers(doc1)
+#testLoadSave(doc1)
+#testArray(doc1)
+#testSelections(doc1)
+#testCombinations(doc1)
+#testText(doc1)
+#testPath(doc1)
+
+#doc1.resume_updates
+
+
+# Prevents asking if you want to save when closing document.
+doc1.mark_as_unmodified()
+
diff --git a/src/extension/dbus/wrapper/Makefile b/src/extension/dbus/wrapper/Makefile
new file mode 100644 (file)
index 0000000..692f4fa
--- /dev/null
@@ -0,0 +1,9 @@
+wrapper: #inkscape-dbus-wrapper.c inkscape-dbus-wrapper.h
+       gcc -fPIC -c inkscape-dbus-wrapper.c $(shell pkg-config --cflags --libs glib-2.0 gobject-2.0 dbus-glib-1 dbus-1)
+       ld -shared -soname libinkdbus.so.1 -o libinkdbus.so.1.0 -lc inkscape-dbus-wrapper.o
+       ln -sf libinkdbus.so.1.0 libinkdbus.so
+       ln -sf libinkdbus.so.1.0 libinkdbus.so.1
+
+test: wrapper tester.c
+       gcc -Wall -L. tester.c -linkdbus -o test $(shell pkg-config --cflags --libs glib-2.0 gobject-2.0)
+
diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c
new file mode 100644 (file)
index 0000000..e6d2818
--- /dev/null
@@ -0,0 +1,782 @@
+#include "inkscape-dbus-wrapper.h"
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+
+#include "../document-client-glue.h"
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+
+// (static.*(\n[^}]*)*(async)+.*(\n[^}]*)*})|typedef void .*;
+// http://www.josephkahn.com/music/index.xml
+
+/* PRIVATE get a connection to the session bus */
+DBusGConnection *
+dbus_get_connection() {
+       GError *error = NULL;
+       DBusGConnection *connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+       if (error) {
+               fprintf(stderr, "Failed to get connection");
+               return NULL;
+       }
+       else
+               return connection;
+}
+
+/* PRIVATE create a proxy object for a bus.*/
+DBusGProxy *
+dbus_get_proxy(DBusGConnection *connection) {
+       return dbus_g_proxy_new_for_name (connection,
+                DBUS_SERVICE_DBUS,
+                DBUS_PATH_DBUS,
+                DBUS_INTERFACE_DBUS);
+}
+
+/* PRIVATE register an object on a bus */
+static gpointer
+dbus_register_object (DBusGConnection *connection,
+                      DBusGProxy *proxy,
+                      GType object_type,
+                      const DBusGObjectInfo *info,
+                      const gchar *path)
+{
+        GObject *object = (GObject*)g_object_new (object_type, NULL);
+        dbus_g_object_type_install_info (object_type, info);
+        dbus_g_connection_register_g_object (connection, path, object);
+        return object;
+}
+
+/****************************************************************************
+     DOCUMENT INTERFACE CLASS STUFF
+****************************************************************************/
+
+struct _DocumentInterface {
+       GObject parent;
+       DBusGProxy * proxy;
+};
+
+G_DEFINE_TYPE(DocumentInterface, document_interface, G_TYPE_OBJECT)
+
+static void
+document_interface_finalize (GObject *object)
+{
+        G_OBJECT_CLASS (document_interface_parent_class)->finalize (object);
+}
+
+
+static void
+document_interface_class_init (DocumentInterfaceClass *klass)
+{
+        GObjectClass *object_class;
+        object_class = G_OBJECT_CLASS (klass);
+        object_class->finalize = document_interface_finalize;
+}
+
+static void
+document_interface_init (DocumentInterface *object)
+{
+       object->proxy = NULL;
+}
+
+
+DocumentInterface *
+document_interface_new (void)
+{
+        return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL);
+}
+
+DocumentInterface *
+inkscape_desktop_init_dbus ()
+{
+    DBusGConnection *connection;
+    GError *error;
+    DBusGProxy *proxy;
+  
+    g_type_init ();
+
+    error = NULL;
+    connection = dbus_g_bus_get (DBUS_BUS_SESSION,
+                               &error);
+    if (connection == NULL)
+        {
+            g_printerr ("Failed to open connection to bus: %s\n",
+                  error->message);
+            g_error_free (error);
+            exit (1);
+        }
+  
+    proxy = dbus_g_proxy_new_for_name (connection,
+                                     "org.inkscape",
+                                     "/org/inkscape/desktop_0",
+                                     "org.inkscape.document");
+
+     DocumentInterface * inkdesk = (DocumentInterface *)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL);
+    inkdesk->proxy = proxy;
+    return inkdesk;
+}
+
+
+//static
+gboolean
+inkscape_delete_all (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+    return org_inkscape_document_delete_all (proxy, error);
+}
+
+//static
+gboolean
+inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_call_verb(proxy, IN_verbid, error);
+}
+
+//static
+gchar *
+inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_rectangle (proxy, IN_x, IN_y, IN_width, IN_height, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_ellipse (proxy, IN_x, IN_y, IN_width, IN_height, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_polygon (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_radius, const gint IN_rotation, const gint IN_sides, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_polygon (proxy, IN_cx, IN_cy, IN_radius, IN_rotation, IN_sides, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_star (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r1, const gint IN_r2, const gdouble IN_arg1, const gdouble IN_arg2, const gint IN_sides, const gdouble IN_rounded, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_star (proxy, IN_cx, IN_cy, IN_r1, IN_r2, IN_arg1, IN_arg2, IN_sides, IN_rounded, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r, const gint IN_revolutions, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_spiral (proxy, IN_cx, IN_cy, IN_r, IN_revolutions, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_line (proxy, IN_x, IN_y, IN_x2, IN_y2, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+gboolean
+inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_text (proxy, IN_x, IN_y, IN_text, error);
+}
+
+//static
+char *
+inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error)
+{
+  char * OUT_object_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_image (proxy, IN_x, IN_y, IN_text, &OUT_object_name, error);
+  return OUT_object_name;
+}
+
+//static
+char *
+inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error)
+{
+  char *OUT_node_name;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_node (proxy, IN_svgtype, &OUT_node_name, error);
+  return OUT_node_name;
+}
+
+//static
+gdouble
+inkscape_document_get_width (DocumentInterface *doc, GError **error)
+{
+  gdouble OUT_val;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_document_document_get_width (proxy, &OUT_val, error);
+  return OUT_val;
+}
+
+//static
+gdouble
+inkscape_document_get_height (DocumentInterface *doc, GError **error)
+{
+  gdouble OUT_val;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_document_document_get_height (proxy, &OUT_val, error);
+  return OUT_val;
+}
+
+//static
+char *
+inkscape_document_get_css (DocumentInterface *doc, GError **error)
+{
+  char * OUT_css;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_document_document_get_css (proxy, &OUT_css, error);
+  return OUT_css;
+}
+
+//static
+gboolean
+inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_document_document_set_css (proxy, IN_stylestring, error);
+}
+
+//static
+gboolean
+inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_document_document_merge_css (proxy, IN_stylestring, error);
+}
+
+//static
+gboolean
+inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_document_document_resize_to_fit_selection (proxy, error);
+}
+
+//static
+gboolean
+inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_set_attribute (proxy, IN_shape, IN_attribute, IN_newval, error);
+}
+
+//static
+gboolean
+inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_set_int_attribute (proxy, IN_shape, IN_attribute, IN_newval, error);
+}
+
+//static
+gboolean
+inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_set_double_attribute (proxy, IN_shape, IN_attribute, IN_newval, error);
+}
+
+//static
+char *
+inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error)
+{
+  char * OUT_val;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_get_attribute (proxy, IN_shape, IN_attribute, &OUT_val, error);
+  return OUT_val;
+}
+
+//static
+gboolean
+inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_move (proxy, IN_shape, IN_x, IN_y, error);
+}
+
+//static
+gboolean
+inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_move_to (proxy, IN_shape, IN_x, IN_y, error);
+}
+
+//static
+gboolean
+inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_object_to_path (proxy, IN_objectname, error);
+}
+
+//static
+char *
+inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error)
+{
+  char * OUT_val;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_get_path (proxy, IN_shape, &OUT_val, error);
+  return OUT_val;
+}
+
+//static
+gboolean
+inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_transform (proxy, IN_shape, IN_transformstr, error);
+}
+
+//static
+char *
+inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error)
+{
+  char * OUT_css;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_get_css (proxy, IN_shape, &OUT_css, error);
+  return OUT_css;
+}
+
+//static
+gboolean
+inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_modify_css (proxy, IN_shape, IN_cssattrib, IN_newval, error);
+}
+
+//static
+gboolean
+inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_merge_css (proxy, IN_shape, IN_stylestring, error);
+}
+
+//static
+gboolean
+inkscape_set_color (DocumentInterface *doc, const char * IN_shape, const gint IN_red, const gint IN_green, const gint IN_blue, const gboolean IN_fill, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_set_color (proxy, IN_shape, IN_red, IN_green, IN_blue, IN_fill, error);
+}
+
+//static
+gboolean
+inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_move_to_layer (proxy, IN_objectname, IN_layername, error);
+}
+
+//static
+GArray*
+inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error)
+{
+  GArray* OUT_points;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_get_node_coordinates (proxy, IN_shape, &OUT_points, error);
+  return OUT_points;
+}
+
+//static
+gboolean
+inkscape_save (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_save (proxy, error);
+}
+
+//static
+gboolean
+inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_save_as (proxy, IN_pathname, error);
+}
+
+//static
+gboolean
+inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_load (proxy, IN_pathname, error);
+}
+
+//static
+gboolean
+inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_mark_as_unmodified (proxy, error);
+}
+
+//static
+gboolean
+inkscape_close (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_close (proxy, error);
+}
+
+//static
+gboolean
+inkscape_inkscape_exit (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_exit (proxy, error);
+}
+
+//static
+gboolean
+inkscape_undo (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_undo (proxy, error);
+}
+
+//static
+gboolean
+inkscape_redo (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_redo (proxy, error);
+}
+
+//static
+gboolean
+inkscape_pause_updates (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_pause_updates (proxy, error);
+}
+
+//static
+gboolean
+inkscape_resume_updates (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_resume_updates (proxy, error);
+}
+
+//static
+gboolean
+inkscape_update (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_update (proxy, error);
+}
+
+//static
+char **
+inkscape_selection_get (DocumentInterface *doc, GError **error)
+{
+  char ** OUT_listy;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_selection_get (proxy, &OUT_listy, error);
+  return OUT_listy;
+}
+
+//static
+gboolean
+inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_add (proxy, IN_name, error);
+}
+
+//static
+gboolean
+inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_add_list (proxy, IN_name, error);
+}
+
+//static
+gboolean
+inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_set (proxy, IN_name, error);
+}
+
+//static
+gboolean
+inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_set_list (proxy, IN_name, error);
+}
+
+//static
+gboolean
+inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_rotate (proxy, IN_angle, error);
+}
+
+//static
+gboolean
+inkscape_selection_delete (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_delete (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_clear (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_clear (proxy, error);
+}
+
+//static
+gboolean
+inkscape_select_all (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_select_all (proxy, error);
+}
+
+//static
+gboolean
+inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_select_all_in_all_layers (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_box (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, const gboolean IN_replace, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_box (proxy, IN_x, IN_y, IN_x2, IN_y2, IN_replace, error);
+}
+
+//static
+gboolean
+inkscape_selection_invert (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_invert (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_group (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_group (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_ungroup (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_ungroup (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_cut (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_cut (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_copy (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_copy (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_paste (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_paste (proxy, error);
+}
+
+//static
+gboolean
+inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_scale (proxy, IN_grow, error);
+}
+
+//static
+gboolean
+inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_move (proxy, IN_x, IN_y, error);
+}
+
+//static
+gboolean
+inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_move_to (proxy, IN_x, IN_y, error);
+}
+
+//static
+gboolean
+inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_move_to_layer (proxy, IN_layer, error);
+}
+
+//static
+GArray *
+inkscape_selection_get_center (DocumentInterface *doc, GError **error)
+{
+  GArray* OUT_centerpoint;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_selection_get_center (proxy, &OUT_centerpoint, error);
+  return OUT_centerpoint;
+}
+
+//static
+gboolean
+inkscape_selection_to_path (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_selection_to_path (proxy, error);
+}
+
+//static
+char *
+inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error)
+{
+  char * OUT_newpath;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_selection_combine (proxy, IN_type, &OUT_newpath, error);
+  return OUT_newpath;
+}
+
+//static
+char **
+inkscape_selection_divide (DocumentInterface *doc, GError **error)
+{
+  char ** OUT_pieces; 
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_selection_divide (proxy, &OUT_pieces, error);
+  return OUT_pieces;
+}
+
+//static
+gboolean
+inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error)
+{
+  gboolean OUT_objectsmoved; 
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_selection_change_level (proxy, IN_command, &OUT_objectsmoved, error);
+  return OUT_objectsmoved;
+}
+
+//static
+char *
+inkscape_layer_new (DocumentInterface *doc, GError **error)
+{
+  char * OUT_layername;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_layer_new (proxy, &OUT_layername, error);
+  return OUT_layername;
+}
+
+//static
+gboolean
+inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_layer_set (proxy, IN_layer, error);
+}
+
+//static
+char **
+inkscape_layer_get_all (DocumentInterface *doc, GError **error)
+{
+  char ** OUT_layers;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_layer_get_all (proxy, &OUT_layers, error);
+  return OUT_layers;
+}
+
+//static
+gboolean
+inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error)
+{
+  gboolean OUT_layermoved;
+  DBusGProxy *proxy = doc->proxy;
+  org_inkscape_document_layer_change_level (proxy, IN_command, &OUT_layermoved, error);
+  return OUT_layermoved;
+}
+
+//static
+gboolean
+inkscape_layer_next (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_layer_next (proxy, error);
+}
+
+//static
+gboolean
+inkscape_layer_previous (DocumentInterface *doc, GError **error)
+{
+  DBusGProxy *proxy = doc->proxy;
+  return org_inkscape_document_layer_previous (proxy, error);
+}
+
+/*
+int
+main (int argc, char** argv) 
+{
+    gchar * result;
+    GError *error = NULL;
+    DocumentInterface * doc = inkscape_desktop_init_dbus ();
+    result = rectangle (doc->proxy, 10, 10, 100, 100, &error);
+    printf("RESULT: %s\n", result);
+     
+    //dbus_g_proxy_call(doc->proxy, "rectangle", &error, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INT, 100, G_TYPE_INVALID, G_TYPE_INVALID);
+    printf("yes\n");
+}
+*/
+
diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h
new file mode 100644 (file)
index 0000000..c314bf6
--- /dev/null
@@ -0,0 +1,344 @@
+#ifndef INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
+#define INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
+
+#include <glib.h>
+#include <glib-object.h>
+
+//#include "document-client-glue-mod.h"
+
+//#include <dbus/dbus-glib-bindings.h>
+//#include <dbus/dbus-glib-lowlevel.h>
+
+#define DBUS_DOCUMENT_INTERFACE_PATH  "/org/inkscape/document"
+        
+#define TYPE_DOCUMENT_INTERFACE            (document_interface_get_type ())
+#define DOCUMENT_INTERFACE(object)         (G_TYPE_CHECK_INSTANCE_CAST ((object), TYPE_DOCUMENT_INTERFACE, DocumentInterface))
+#define DOCUMENT_INTERFACE_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass))
+#define IS_DOCUMENT_INTERFACE(object)      (G_TYPE_CHECK_INSTANCE_TYPE ((object), TYPE_DOCUMENT_INTERFACE))
+#define IS_DOCUMENT_INTERFACE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_DOCUMENT_INTERFACE))
+#define DOCUMENT_INTERFACE_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_DOCUMENT_INTERFACE, DocumentInterfaceClass))
+
+G_BEGIN_DECLS
+
+typedef struct _DocumentInterface DocumentInterface;
+typedef struct _DocumentInterfaceClass DocumentInterfaceClass;
+
+struct _DocumentInterface;
+
+struct _DocumentInterfaceClass {
+       GObjectClass parent;
+};
+
+
+DocumentInterface *document_interface_new (void);
+GType document_interface_get_type (void);
+
+
+
+DocumentInterface * 
+inkscape_desktop_init_dbus ();
+
+//static
+gboolean
+inkscape_delete_all (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error);
+
+//static
+gchar *
+inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error);
+
+//static
+char *
+inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error);
+
+//static
+char *
+inkscape_polygon (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_radius, const gint IN_rotation, const gint IN_sides, GError **error);
+
+//static
+char *
+inkscape_star (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r1, const gint IN_r2, const gdouble IN_arg1, const gdouble IN_arg2, const gint IN_sides, const gdouble IN_rounded, GError **error);
+
+//static
+char *
+inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r, const gint IN_revolutions, GError **error);
+
+//static
+char *
+inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, GError **error);
+
+//static
+gboolean
+inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error);
+
+//static
+char *
+inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error);
+
+//static
+char *
+inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error);
+
+//static
+gdouble
+inkscape_document_get_width (DocumentInterface *doc, GError **error);
+
+//static
+gdouble
+inkscape_document_get_height (DocumentInterface *doc, GError **error);
+
+//static
+char *
+inkscape_document_get_css (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error);
+
+//static
+gboolean
+inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error);
+
+//static
+gboolean
+inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error);
+
+//static
+gboolean
+inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error);
+
+//static
+gboolean
+inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error);
+
+//static
+char *
+inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error);
+
+//static
+gboolean
+inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error);
+
+//static
+gboolean
+inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error);
+
+//static
+gboolean
+inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error);
+
+//static
+char *
+inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error);
+
+//static
+gboolean
+inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error);
+
+//static
+char *
+inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error);
+
+//static
+gboolean
+inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error);
+
+//static
+gboolean
+inkscape_inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error);
+
+//static
+gboolean
+inkscape_set_color (DocumentInterface *doc, const char * IN_shape, const gint IN_red, const gint IN_green, const gint IN_blue, const gboolean IN_fill, GError **error);
+
+//static
+gboolean
+inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error);
+
+//static
+GArray*
+inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error);
+
+//static
+gboolean
+inkscape_save (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error);
+
+//static
+gboolean
+inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error);
+
+//static
+gboolean
+inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_close (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_inkscape_exit (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_undo (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_redo (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_pause_updates (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_resume_updates (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_update (DocumentInterface *doc, GError **error);
+
+//static
+char **
+inkscape_selection_get (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error);
+
+//static
+gboolean
+inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error);
+
+//static
+gboolean
+inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error);
+
+//static
+gboolean
+inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error);
+
+//static
+gboolean
+inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error);
+
+//static
+gboolean
+inkscape_selection_delete (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_clear (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_select_all (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_box (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, const gboolean IN_replace, GError **error);
+
+//static
+gboolean
+inkscape_selection_invert (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_group (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_ungroup (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_cut (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_copy (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_paste (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error);
+
+//static
+gboolean
+inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error);
+
+//static
+gboolean
+inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error);
+
+//static
+gboolean
+inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error);
+
+//static
+GArray *
+inkscape_selection_get_center (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_to_path (DocumentInterface *doc, GError **error);
+
+//static
+char *
+inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error);
+
+//static
+char **
+inkscape_selection_divide (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error);
+
+//static
+char *
+inkscape_layer_new (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error);
+
+//static
+char **
+inkscape_layer_get_all (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error);
+
+//static
+gboolean
+inkscape_layer_next (DocumentInterface *doc, GError **error);
+
+//static
+gboolean
+inkscape_layer_previous (DocumentInterface *doc, GError **error);
+
+G_END_DECLS
+
+#endif // INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_
index 84cc45de965fedb98592b528521cd940646d0d6d..dc39ea430538286895a6eb80e13c8d1eaa3d1e1b 100644 (file)
@@ -55,6 +55,9 @@
 #endif
 #include "preferences.h"
 #include "io/sys.h"
+#ifdef WITH_DBUS
+#include "dbus/dbus-init.h"
+#endif
 
 #ifdef WITH_IMAGE_MAGICK
 #include "internal/bitmap/adaptiveThreshold.h"
@@ -185,6 +188,10 @@ init()
     Internal::BlurEdge::init();
     Internal::GimpGrad::init();
     Internal::Grid::init();
+
+#ifdef WITH_DBUS
+    Dbus::init();
+#endif
        
     /* Raster Effects */
 #ifdef WITH_IMAGE_MAGICK
index e0ecd50843f8b96e1f298fbb6c3e45c593d10f66..1186a1f0794924ef5aba92b0f49b4cdca13937da 100644 (file)
@@ -42,6 +42,7 @@
 #include "extension/input.h"
 #include "extension/output.h"
 #include "extension/system.h"
+#include "extension/dbus/dbus-init.h"
 #include "file.h"
 #include "helper/png-write.h"
 #include "id-clash.h"
@@ -135,6 +136,7 @@ sp_file_new(const Glib::ustring &templ)
         sp_namedview_window_from_document(dt);
         sp_namedview_update_layers_from_document(dt);
     }
+    Inkscape::Extension::Dbus::dbus_init_desktop_interface(dt);
     return dt;
 }
 
index ca2894227c1d8589c30cf54497058fa9a80dda63..d820927542f8dbaf072a366dadec3c20235d0adc 100644 (file)
@@ -42,6 +42,8 @@ Inkscape::XML::Node *inkscape_get_menus (Inkscape::Application * inkscape);
 
 Inkscape::Application *inkscape_get_instance();
 
+SPDesktop * inkscape_find_desktop_by_dkey (unsigned int dkey);
+
 #define SP_ACTIVE_EVENTCONTEXT inkscape_active_event_context ()
 SPEventContext * inkscape_active_event_context (void);
 
@@ -57,6 +59,7 @@ gchar *homedir_path(const char *filename);
 gchar *profile_path(const char *filename);
 
 /* Inkscape desktop stuff */
+void inkscape_activate_desktop (SPDesktop * desktop);
 void inkscape_switch_desktops_next ();
 void inkscape_switch_desktops_prev ();
 void inkscape_get_all_desktops (std::list< SPDesktop* >& listbuf);
index ecb1ef45e5399780cbe4812bf52a1bb18b6517ce..8eacf0d46c61969a11f211e5c4422abe3edc8aec 100644 (file)
@@ -249,14 +249,16 @@ public:
     /**
      * @brief Returns the bounding rectangle of the selection
      *
-     * \todo how is this different from bounds()?
+     * Gives the coordinates in internal format, does not match onscreen guides.
+     * (0,0 is the upper left corner, not the lower left corner)
      */
     NRRect *boundsInDocument(NRRect *dest, SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;
 
     /**
      * @brief Returns the bounding rectangle of the selection
      *
-     * \todo how is this different from bounds()?
+     * Gives the coordinates in internal format, does not match onscreen guides.
+     * (0,0 is the upper left corner, not the lower left corner)
      */
     Geom::OptRect boundsInDocument(SPItem::BBoxType type = SPItem::APPROXIMATE_BBOX) const;