-- cgit v1.2.3 From 61b06c26a149d8e9c7fa9459f4b62d0529f86ef3 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 15:39:30 +0000 Subject: Test for Dbus and enable if found (bzr r8254.1.2) --- configure.ac | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/configure.ac b/configure.ac index b804d0deb..418990602 100644 --- a/configure.ac +++ b/configure.ac @@ -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 Inkboard: ${with_inkboard} Enable SSL in Inkboard: ${with_inkboard_ssl} Enable Poppler-Cairo: ${enable_poppler_cairo} -- cgit v1.2.3 From f24f34bd713c7a26fbb6e13c2a44111223950738 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:02:09 +0000 Subject: Core Dbus files. Init creates interfaces on Inkscape startup. Application and document interface provide API functions over Dbus. service.in file makes sure Inkscape starts automatically when someone connects to it over Dbus. (bzr r8254.1.3) --- src/extension/dbus/Makefile_insert | 31 + src/extension/dbus/application-interface.cpp | 112 +++ src/extension/dbus/application-interface.h | 84 ++ src/extension/dbus/application-interface.xml | 65 ++ src/extension/dbus/dbus-init.cpp | 153 ++++ src/extension/dbus/dbus-init.h | 42 + src/extension/dbus/document-interface.cpp | 936 ++++++++++++++++++++ src/extension/dbus/document-interface.xml | 1223 ++++++++++++++++++++++++++ src/extension/dbus/org.inkscape.service.in | 4 + 9 files changed, 2650 insertions(+) create mode 100644 src/extension/dbus/Makefile_insert create mode 100644 src/extension/dbus/application-interface.cpp create mode 100644 src/extension/dbus/application-interface.h create mode 100644 src/extension/dbus/application-interface.xml create mode 100644 src/extension/dbus/dbus-init.cpp create mode 100644 src/extension/dbus/dbus-init.h create mode 100644 src/extension/dbus/document-interface.cpp create mode 100644 src/extension/dbus/document-interface.xml create mode 100644 src/extension/dbus/org.inkscape.service.in diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert new file mode 100644 index 000000000..c8bee0ca6 --- /dev/null +++ b/src/extension/dbus/Makefile_insert @@ -0,0 +1,31 @@ +## 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/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 $^ + +# 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@|$(bindir)|" $<> $@ + diff --git a/src/extension/dbus/application-interface.cpp b/src/extension/dbus/application-interface.cpp new file mode 100644 index 000000000..06e41ecf3 --- /dev/null +++ b/src/extension/dbus/application-interface.cpp @@ -0,0 +1,112 @@ +#include "application-interface.h" +#include +#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 index 000000000..a04c992c3 --- /dev/null +++ b/src/extension/dbus/application-interface.h @@ -0,0 +1,84 @@ +#ifndef INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_ +#define INKSCAPE_EXTENSION_APPLICATION_INTERFACE_H_ + +#include +#include +#include +#include + +#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 index 000000000..9b55a9b2b --- /dev/null +++ b/src/extension/dbus/application-interface.xml @@ -0,0 +1,65 @@ + + + + + + + + + + This string can be used to connect to the new interface that was created. + + + + + Create a new document interface and return it's location. + + + + + + + + A list of interfaces being provided by Inkscape. + + + + + List all the interfaces that it is possible to connect to. + + + + + + + Close all document interfaces without saving. + + + + + + + Exit Inkscape without saving. Fairly straightforward. + + + + + + + + + + This string can be used to connect to the new interface that was created. + + + + + 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. + 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. + + + + + diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp new file mode 100644 index 000000000..a30bb8fda --- /dev/null +++ b/src/extension/dbus/dbus-init.cpp @@ -0,0 +1,153 @@ + +#include +#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 +#include +#include + + + + +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; + + 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 index 000000000..f76483170 --- /dev/null +++ b/src/extension/dbus/dbus-init.h @@ -0,0 +1,42 @@ +/* + * Authors: + * Soren Berg + * + * Copyright (C) 2004 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/document-interface.cpp b/src/extension/dbus/document-interface.cpp new file mode 100644 index 000000000..94f442865 --- /dev/null +++ b/src/extension/dbus/document-interface.cpp @@ -0,0 +1,936 @@ +#include "document-interface.h" +#include + +#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 + +/**************************************************************************** + HELPER / SHORTCUT FUNCTIONS +****************************************************************************/ + +const gchar* intToCString(int i) +{ + std::stringstream ss; + ss << i; + return ss.str().c_str(); +} + +SPObject * +get_object_by_name (SPDesktop *desk, gchar *name) +{ + return sp_desktop_document(desk)->getObjectById(name); +} + +const gchar * +get_name_from_object (SPObject * obj) +{ + return obj->repr->attribute("id"); +} + +void +desktop_ensure_active (SPDesktop* desk) { + if (desk != SP_ACTIVE_DESKTOP) + inkscape_activate_desktop (desk); + return; +} + +Inkscape::XML::Node * +document_retrive_node (SPDocument *doc, gchar *name) { + return (doc->getObjectById(name))->repr; +} + +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); +} +//move_to etc +const GSList * +selection_swap(SPDesktop *desk, gchar *name) +{ + Inkscape::Selection *sel = sp_desktop_selection(desk); + const GSList *oldsel = g_slist_copy((GSList *)sel->list()); + + sel->set(get_object_by_name(desk, name)); + return oldsel; +} + +void +selection_restore(SPDesktop *desk, const GSList * oldsel) +{ + Inkscape::Selection *sel = sp_desktop_selection(desk); + sel->setList(oldsel); +} + +Inkscape::XML::Node * +dbus_create_node (SPDesktop *desk, gboolean isrect) +{ + SPDocument * doc = sp_desktop_document (desk); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); + gchar *type; + if (isrect) + type = (gchar *)"svg:rect"; + else + type = (gchar *)"svg:path"; + return xml_doc->createElement(type); +} + +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")); +} + +gboolean +dbus_call_verb (DocumentInterface *object, int verbid, GError **error) +{ + SPDesktop *desk2 = object->desk; + + if ( desk2 ) { + Inkscape::Verb *verb = Inkscape::Verb::get( 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())); + } + return TRUE; + } + } + } + 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); +} + +/**************************************************************************** + MISC FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_delete_all (DocumentInterface *object, GError **error) +{ + sp_edit_clear_all (object->desk); + return TRUE; +} + +void +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())); + } + } + } + } +} + + +/**************************************************************************** + 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, TRUE); + 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, FALSE); + 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, FALSE); + 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, FALSE); + 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, FALSE); + std::stringstream out; + printf("X2: %d\nY2 %d\n", x2, y2); + out << "m " << x << "," << y << " " << x2 << "," << y2; + printf ("PATH: %s\n", out.str().c_str()); + 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, FALSE); + 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"); + newNode->setAttribute("style", "fill:none"); + return retval; +} + +gchar* +document_interface_text (DocumentInterface *object, gchar *text, GError **error) +{ + return NULL; +} + +gchar* +document_interface_node (DocumentInterface *object, gchar *type, GError **error) +{ + return NULL; +} + +/**************************************************************************** + 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) +{ + return FALSE; +} + +gboolean +document_interface_document_set_css (DocumentInterface *object, + gchar *stylestring, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_document_resize_to_fit_selection (DocumentInterface *object, + GError **error) +{ + return FALSE; +} + +/**************************************************************************** + OBJECT FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_set_attribute (DocumentInterface *object, char *shape, + char *attribute, char *newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; + + /* ALTERNATIVE + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + */ + if (newNode) + { + newNode->setAttribute(attribute, newval, TRUE); + return TRUE; + } + return FALSE; +} + +void +document_interface_set_int_attribute (DocumentInterface *object, + char *shape, char *attribute, + int newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; + if (newNode) + sp_repr_set_int (newNode, attribute, newval); +} + + +void +document_interface_set_double_attribute (DocumentInterface *object, + char *shape, char *attribute, + double newval, GError **error) +{ + Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; + if (newNode) + sp_repr_set_svg_double (newNode, attribute, newval); +} + +gchar * +document_interface_get_attribute (DocumentInterface *object, char *shape, + char *attribute, GError **error) +{ + SPDesktop *desk2 = object->desk; + SPDocument * doc = sp_desktop_document (desk2); + + // FIXME: Not sure if this is the most efficient way. + Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; + + /* WORKS + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + */ + if (newNode) + return g_strdup(newNode->attribute(attribute)); + return FALSE; +} + +gboolean +document_interface_move (DocumentInterface *object, gchar *name, gdouble x, + gdouble y, GError **error) +{ + const GSList *oldsel = selection_swap(object->desk, name); + 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); + 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; +} + +void +document_interface_object_to_path (DocumentInterface *object, + char *shape, GError **error) +{ + const GSList *oldsel = selection_swap(object->desk, shape); + dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); + selection_restore(object->desk, oldsel); +} + +gboolean +document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) +{ + Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); + if (node == NULL || node->attribute("d") == NULL) { + g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + return FALSE; + } + gchar *pathstr = strdup(node->attribute("d")); + printf("PATH: %s\n", pathstr); + //gfree (pathstr); + std::istringstream iss(pathstr); + std::copy(std::istream_iterator(iss), + std::istream_iterator(), + std::ostream_iterator(std::cout, "\n")); + + return TRUE; +} + +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) +{ +return NULL; +} + +gboolean +document_interface_modify_css (DocumentInterface *object, gchar *shape, + gchar *cssattrb, gchar *newval, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_merge_css (DocumentInterface *object, gchar *shape, + gchar *stylestring, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_move_to_layer (DocumentInterface *object, gchar *shape, + gchar *layerstr, GError **error) +{ + return FALSE; +} + +DBUSPoint ** +document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) +{ + return NULL; +} + + +/**************************************************************************** + FILE I/O FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_save (DocumentInterface *object, GError **error){ + return FALSE; +} + +gboolean +document_interface_load (DocumentInterface *object, + gchar *filename, GError **error){ + return FALSE; +} + +gboolean +document_interface_save_as (DocumentInterface *object, + gchar *filename, GError **error){ + return FALSE; +} + +gboolean +document_interface_print (DocumentInterface *object, GError **error){ + return FALSE; +} + +/**************************************************************************** + 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 +****************************************************************************/ + +void +document_interface_pause_updates (DocumentInterface *object, GError **error) +{ + object->updates = FALSE; + 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; + sp_desktop_document(object->desk)->root->uflags = TRUE; + sp_desktop_document(object->desk)->root->mflags = TRUE; + //sp_desktop_document(object->desk)->_updateDocument(); + 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; + sp_desktop_document(object->desk)->_updateDocument(); + 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. +****************************************************************************/ + +gchar ** +document_interface_selection_get (DocumentInterface *object) +{ + Inkscape::Selection * sel = sp_desktop_selection(object->desk); + GSList const *oldsel = sel->list(); + + int size = g_slist_length((GSList *) oldsel); + int i; + printf("premalloc\n"); + gchar **list = (gchar **)malloc(size); + printf("postmalloc\n"); + for(i = 0; i < size; i++) + list[i] = (gchar *)malloc(sizeof(gchar) * 10); + printf("postmalloc2\n"); + i=0; + printf("prealloc\n"); + for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) { + strcpy (list[i], SP_OBJECT(iter->data)->repr->attribute("id")); + i++; + } + printf("postalloc\n"); + for (i=0; idesk); + Inkscape::Selection *selection = sp_desktop_selection(object->desk); + /* WORKS + Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + selection->add(repr2, TRUE); + */ + selection->add(doc->getObjectById(name)); + return TRUE; +} + +gboolean +document_interface_selection_add_list (DocumentInterface *object, + char **names, GError **error) +{ + return FALSE; +} + +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;((i<30000) && (names[i] != NULL));i++) { + printf("NAME: %s\n", names[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 TRUE; +} + +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 TRUE; +} + +gboolean +document_interface_select_all_in_all_layers(DocumentInterface *object, + GError **error) +{ + sp_edit_select_all_in_all_layers (object->desk); +} + +gboolean +document_interface_selection_box (DocumentInterface *object, int x, int y, + int x2, int y2, gboolean replace, + GError **error) +{ + return FALSE; +} + +gboolean +document_interface_selection_invert (DocumentInterface *object, GError **error) +{ + sp_edit_invert (object->desk); + return TRUE; +} + +gboolean +document_interface_selection_group (DocumentInterface *object, GError **error) +{ + sp_selection_group (object->desk); + return TRUE; +} +gboolean +document_interface_selection_ungroup (DocumentInterface *object, GError **error) +{ + sp_selection_ungroup (object->desk); + return TRUE; +} + +gboolean +document_interface_selection_cut (DocumentInterface *object, GError **error) +{ + sp_selection_cut (object->desk); + return TRUE; +} +gboolean +document_interface_selection_copy (DocumentInterface *object, GError **error) +{ + desktop_ensure_active (object->desk); + sp_selection_copy (); + return TRUE; +} +gboolean +document_interface_selection_paste (DocumentInterface *object, GError **error) +{ + desktop_ensure_active (object->desk); + sp_selection_paste (object->desk, TRUE); + return TRUE; +} + +gboolean +document_interface_selection_scale (DocumentInterface *object, gdouble grow, GError **error) +{ + Inkscape::Selection *selection = sp_desktop_selection(object->desk); + 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( (object->desk)->point() - sel_bbox->midpoint() ); + Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); + sp_selection_move_relative(sel, m, true); + + } + + //FIXME: dosn't work with transformations + //sp_selection_move (object->desk, x - selection_get_center_x(sel), + // 0 - (y - selection_get_center_y(sel))); + return TRUE; +} + +gboolean +document_interface_selection_move_to_layer (DocumentInterface *object, + gchar *layerstr, GError **error) +{ + return FALSE; +} + +gboolean +document_interface_selection_get_center (DocumentInterface *object) +{ + return FALSE; +} + +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 if (strcmp(cmd, "division") == 0) + dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); + else + return NULL; + + //FIXME: this WILL cause problems with division + return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); +} + +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) +{ + object->desk->setCurrentLayer (get_object_by_name (object->desk, layerstr)); + return TRUE; +} + +gchar ** +document_interface_layer_get_all (DocumentInterface *object) +{ + 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.xml b/src/extension/dbus/document-interface.xml new file mode 100644 index 000000000..ba8c7e2b3 --- /dev/null +++ b/src/extension/dbus/document-interface.xml @@ -0,0 +1,1223 @@ + + + + + + + + + + + + + + The string id of a verb. For example: "EditSelectAll". + + + + + 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: + + + + + + + + + + X coordinate for the top left corner of the rectangle. + + + + + Y coordinate for the top left corner of the rectangle. + + + + + Width of the rectangle. + + + + + Height of the rectangle. + + + + + + The name of the new rectangle. + + + + + This method creates a rectangle in the current layer using the current document style. + It is recommended that you save the return value if you will want to modify this particular shape later. + Additional variables include: + cx and cy: set these anywhere from zero to half the width or height respectively of the rectangle to give it rounded corners. + + Coordinate System + + + + + + + X coordinate for the top left corner of the ellipse. + + + + + Y coordinate for the top left corner of the ellipse. + + + + + Width of the ellipse. + + + + + Height of the ellipse. + + + + + + The name of the new ellipse. + + + + + This method creates a ellipse in the current layer using the current document style. + It is recommended that you save the return value if you will want to modify this particular shape later. + Additional variables include: + "sodipodi:start" and "sodipodi:end": set these between 0 and Pi to create wedges or Pacman like shapes. + + Coordinate System + + + + + + + X coordinate for the center of the polygon. + + + + + Y coordinate for the center of the polygon. + + + + + Radius from the center to one of the points. + + + + + Angle in degrees to rotate. 0 will have the first point pointing straight up. + + + + + Number of sides of the polygon. + + + + + + The name of the new polygon. + + + + + This method creates a polygon in the current layer using the current document style. + It is recommended that you save the return value if you will want to modify this particular shape later. + Note: this is actually a star with "sodipodi:flatsided" set to true, which causes it to ignore the arg2 and r2 values. + + Coordinate System + + + + + + + X coordinate for the center of the star. + + + + + Y coordinate for the center of the star. + + + + + distance from the center for the first point. + + + + + distance from the center for the second point. + + + + + Angle in radians for the first point. 0 is 90 degrees to the right of straight up. + + + + + Angle in radians for the second point. 0 is 90 degrees to the right of straight up. + + + + + Number of times to repeat the points around the star. + + + + + How rounded to make the star. 0 to 1 recommended for moderate to medium curves. 10 for extreme curves. + + + + + + The name of the new star. + + + + + This method creates a star in the current layer using the current document style. + It is recommended that you save the return value if you will want to modify this particular shape later. + 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. + + Coordinate System + + + + + + + X coordinate for the center of the spiral. + + + + + Y coordinate for the center of the spiral. + + + + + Radius of the spiral. + + + + + Number of revolutions. + + + + + + The name of the new spiral. + + + + + This method creates a spiral in the current layer using the current document style. However, fill is automatically set to "none". Stroke is unmodified. + It is recommended that you save the return value if you will want to modify this particular shape later. + Additional variables include: + "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. + "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. + "sodipodi:argument": Rotates the spiral. In radians. + + Coordinate System + + + + + + + X coordinate for the first point. + + + + + Y coordinate for the first point. + + + + + X coordinate for the second point. + + + + + Y coordinate for the second point. + + + + + + The name of the new line. + + + + + 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". + + Coordinate System + + + + + + + The text you want. + + + + + + The name of the new text object. + + + + + This method creates some text in the current layer. + + + + + + + + The type of node, probably "svg:path" + + + + + + The name of the new node. + + + + + Make any kind of node you want. Mostly for making paths. (May need to allow updateRepr to be called for it to show up.) + + + + + + + + + + + Document width. + + + + + Retrieve the width of the current document. anything outside the boundary will not be printed or exported but will be saved. + + + + + + + + + Document height. + + + + + Retrieve the height of the current document. anything outside the boundary will not be printed or exported but will be saved. + + + + + + + + + CSS attribute string for the document. + + + + + Get the current style for the document. All new shapes will use this style if it exists. + + Style Strings + + + + + + + A new CSS attribute string for the document. + + + + + Set the current style for the document. All new shapes will use this style if it exists. + + Style Strings + + + + + + + A new CSS attribute string for the document. + + + + + Merge this this string with the current style for the document. All new shapes will use this style if it exists. + + Style Strings, merge_css() + + + + + + + Resize the document to contain all of the currently selected objects. + This ensures that the image is not clipped when printing or exporting. + + + + + + + + + + The id of an object. + + + + + The name of the attribute. + + + + + The new value of the attribute. This will overwrite anything already set. To merge styles, see merge_css(). + + + + + Set any attribute, the available attributes depend on what kind of shape the object node represents. See shape creation functions for more details. + + + + + + + + The id of an object. + + + + + The name of the attribute. + + + + + The new value of the attribute. This will overwrite anything already set. + + + + + Set any attribute, the available attributes depend on what kind of shape the object node represents. See shape creation functions for more details. + This is a convenience function for set_attribute(). + + + + + + + + The id of an object. + + + + + The name of the attribute. + + + + + The new value of the attribute. This will overwrite anything already set. + + + + + Set any attribute, the available attributes depend on what kind of shape the node represents. See shape creation functions for more details. + This is a convenience function for set_attribute(). + + + + + + + + The id of an object. + + + + + The name of the attribute. + + + + + + The current value of the attribute. String is a copy and must be freed. + + + + + Get the value of any attribute. Not all objects will have every attribute their type supports, some are optional. See shape creation functions for more details. + + + + + + + + The id of an object. + + + + + Distance to move along the x axis. + + + + + Distance to move along the y axis. + + + + + This will move a shape (or any object) relative to it's current location. + This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object. + + Coordinate System + + + + + + + The id of an object. + + + + + the x coordinate of the desired location. + + + + + the y coordinate of the desired location. + + + + + 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. + 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. + This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the object. + + Coordinate System + + + + + + + The id of an object. + + + + + Turns an object into a path. Most objects contain paths (except rectangles) but are not paths themselves. + 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. + After doing this you will no longer be able to modify the shape using shape specific attributes (cx, radius etc.) except transform + Required for certain functions that work on paths (not yet present in this API.) + + + + + + + + The id of any node or object. + + + + + A string that represents a transformation. + + + + + 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. + Will merge with existing transformations. + + + + + + + + Any object with a style attribute. + + + + + + A CSS Style string + + + + + Retrieve the style of a object. Equivalent to calling get_attribute() for "style". + + Style Strings + + + + + + + Any object with a style attribute. + + + + + An attribute such as "fill" or "stroke-width". + + + + + The new value. + + + + + Set a particular attribute of a style string. Overwrites just that part of the style. + + Style Strings + + + + + + + Any object with a style attribute. + + + + + A full or partial CSS Style string. + + + + + Takes a CSS Style string and merges it with the objects current style, overwriting only the elements present in stylestring. + + Style Strings + + + + + + + The id of an object. + + + + + A layer name. + + + + + Moves an object to a different layer. + Will error if layer does not exist. + + layer_new() + + + + + + + A object that contains a path ("d") attribute. + + + + + + An array of points. + + + + + Returns an array of all of the X,Y coordinates of the points in the objects path. + If the path is a closed loop the first point is repeated at the end. + + + + + + + + + + Saves the current document with current name or a default name if has not been saved before. + Will overwrite without confirmation. + + + + + + + + The path for the file to be saved as. + + + + + Saves the current document as pathname. + Will overwrite without confirmation. + + + + + + + + The path to a valid svg file. + + + + + Loads the file at pathname. + Will lose all unsaved work in current document. + + + + + + + + Prints the current document with default settings. + Will only print things visible within the document boundaries. + + document_resize_to_fit_selection() + + + + + + + + + Close this document. + You will not be able to send any more commands on this interface. + + + + + + + + Exit Inkscape. + You will not be able to send any more commands on any interface. + + + + + + + + Undo the last action. + + + + + + + + Redo the last undone action. + + + + + + + + + + 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. + 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. + + + + + + + + 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. + This will update the display to show any changes that happened while updates were paused, a separate call to update() is not necessary. + + + + + + + + This will update the document once if updates are paused but it will not resume updates. + 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. + + + + + + + + + + + List of the ids of currently selected objects. + + + + + Returns the current selection in the form of a list of ids of selected objects. + Manipulating this list will not affect the selection. + + + + + + + + A object to add to the selection. + + + + + Adds a single object to the selection. + + + + + + + + An array of object ids to add to the selection. + + + + + Adds a list of objects to the selection. + + + + + + + + A object to select. + + + + + Replaces the selection with one containing just this object. + + + + + + + + A list of objects to select. + + + + + Replaces the selection with one containing just these objects. + + + + + + + + Angle in degrees to rotate. + + + + + Rotates the selection around the center of it's bounding box. + + + + + + + + Delete all objects in the selection. + + + + + + + + Deselect everything. Selection will be empty. + + + + + + + + Select all objects in current layer. + + + + + + + + Select all objects in every layer. + + + + + + + + X coordinate for the first point. + + + + + Y coordinate for the first point. + + + + + X coordinate for the second point. + + + + + Y coordinate for the second point. + + + + + True to replace selection, false to add to selection. + + + + + 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. + + + + + + + + Invert the selection in the current layer. + + + + + + + + Group the selection. + + Groups + + + + + + + Ungroup the selection. + + Groups + + + + + + + Cut the current selection. + + + + + + + + Copy the current selection. + + + + + + + + Paste the current selection at the same location it was cut from. + To paste to a particular location, simply use selection_paste() followed by selection_move_to(). + + + + + + + + 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. + + + + + Scale the selection relative to it's current size. + + + + + + + + Amount to move in the x direction. + + + + + Amount to move in the y direction. + + + + + This will move the selection relative to it's current location. + This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection. + + Coordinate System + + + + + + + X coordinate to move to. + + + + + Y coordinate to move to. + + + + + This will move the center of the selection to a specific location. + This may be accomplished with transformation attributes or by changing x and y attributes depending on the state of the objects in the selection. + + Coordinate System + + + + + + + layer to move the selection to. + + + + + Move every item in the selection to a different layer. + Will error if layer does not exist. + + Layers and Levels + + + + + + + + Center of the selection. + + + + + Gets the center of the selections bounding box in X,Y coordinates. + + Coordinate System + + + + + + + Turns all the objects in the selection into paths. + + object_to_path() + + + + + + + Type of combination. + + + + + + The new path created, if there is one. NULL otherwise. + + + + + Will erase all objects in the selection and replace with a single aggregate path. + There are 5 types that can be passed in: + 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.) + 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. + Difference: The area of the second shape is subtracted from the first, only works with two objects. + Exclusion: The new shape is the area(s) where none of the objects in the selection overlaped. Only works with two objects. + 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. + + + + + + + + How to change the level + + + + + + True if the objects changed levels. False if they don't(if they were already on top when being raised for example.) + + + + + 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. + There are 4 commands that can be passed in: + "raise" or "lower": Move the selection one level up, or one level down. + "to_top" of "to_bottom": Move the selection above all other objects or below all other objects. + + + + + + + + + + + The name of the new layer. + + + + + Turns all the objects in the selection into paths. + + Layers and Levels + + + + + + + The name of any layer. + + + + + Sets the layer given as the current layer + + Layers and Levels + + + + + + + + list of layers. + + + + + Get a list of all the layers in this document. + + Layers and Levels + + + + + + + How to change the level + + + + + + True if the layer was moved. False if it was not (if it was already on top when being raised for example.) + + + + + Will change the level of a layer, respective of other layers. Will not affect the relative level of objects within the layer. + There are 4 commands that can be passed in: + "raise" or "lower": Move the layer one level up, or one level down. + "to_top" of "to_bottom": Move the layer above all other layers or below all other layers. + + + + + + + + Sets the next (or higher) layer as active. + + Layers and Levels + + + + + + + Sets the previous (or lower) layer as active. + + Layers and Levels + + + + + + diff --git a/src/extension/dbus/org.inkscape.service.in b/src/extension/dbus/org.inkscape.service.in new file mode 100644 index 000000000..401d2d38e --- /dev/null +++ b/src/extension/dbus/org.inkscape.service.in @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=org.inkscape +Exec=/usr/local/bin/inkscape + -- cgit v1.2.3 From a747404be053f835da4c28a06a91503da115524d Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:52:57 +0000 Subject: Added code to initialize DBus (if enabled.) (bzr r8254.1.4) --- src/extension/init.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 84cc45de9..dc39ea430 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -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 -- cgit v1.2.3 From fce8e137470e83bbe1e8eb64afba819f36c33f5d Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:57:36 +0000 Subject: Added code to add a DBus interface for every desktop created. (bzr r8254.1.5) --- src/file.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/file.cpp b/src/file.cpp index 049c1acb4..7acd5fe5d 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -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" @@ -136,6 +137,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; } -- cgit v1.2.3 From af5da2b930e76796a69174b62b5f4c4064662729 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 16:59:19 +0000 Subject: Added some requested documentaion. (bzr r8254.1.6) --- src/selection.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/selection.h b/src/selection.h index ecb1ef45e..8eacf0d46 100644 --- a/src/selection.h +++ b/src/selection.h @@ -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; -- cgit v1.2.3 From bda22333701d1af321937c5c66926c6ed5c5fe07 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 17:02:17 +0000 Subject: Made public some functions so they could be used by the DBus code. Similar functions were already public so I think it's okay. (bzr r8254.1.7) --- src/inkscape.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/inkscape.h b/src/inkscape.h index ca2894227..d82092754 100644 --- a/src/inkscape.h +++ b/src/inkscape.h @@ -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); -- cgit v1.2.3 From 779ee4b74a28eef8186d19d632d61f88fbe5b1e0 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sun, 12 Jul 2009 17:08:53 +0000 Subject: Added makefile_insert for DBus, if enabled. (bzr r8254.1.8) --- src/Makefile.am | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Makefile.am b/src/Makefile.am index bc5b2d839..90b0be28c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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) \ @@ -104,6 +106,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 -- cgit v1.2.3 From 745136f6c9423a0f0c8b020980ec0321049dbedb Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 13 Jul 2009 17:33:36 +0000 Subject: Documentation helper files. Building documentation is currently done by shell script, but will be integrated into the build system eventually. (bzr r8254.1.9) --- src/extension/dbus/doc/config.xsl | 7 + src/extension/dbus/doc/dbus-introspect-docs.dtd | 33 ++ src/extension/dbus/doc/docbook.css | 79 ++++ src/extension/dbus/doc/inkscapeDbusRef.xml | 81 ++++ src/extension/dbus/doc/inkscapeDbusTerms.xml | 131 ++++++ src/extension/dbus/doc/spec-to-docbook.xsl | 544 ++++++++++++++++++++++++ 6 files changed, 875 insertions(+) create mode 100644 src/extension/dbus/doc/config.xsl create mode 100644 src/extension/dbus/doc/dbus-introspect-docs.dtd create mode 100644 src/extension/dbus/doc/docbook.css create mode 100644 src/extension/dbus/doc/inkscapeDbusRef.xml create mode 100644 src/extension/dbus/doc/inkscapeDbusTerms.xml create mode 100644 src/extension/dbus/doc/spec-to-docbook.xsl diff --git a/src/extension/dbus/doc/config.xsl b/src/extension/dbus/doc/config.xsl new file mode 100644 index 000000000..26949c4ef --- /dev/null +++ b/src/extension/dbus/doc/config.xsl @@ -0,0 +1,7 @@ + + + + + diff --git a/src/extension/dbus/doc/dbus-introspect-docs.dtd b/src/extension/dbus/doc/dbus-introspect-docs.dtd new file mode 100644 index 000000000..47816713e --- /dev/null +++ b/src/extension/dbus/doc/dbus-introspect-docs.dtd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/extension/dbus/doc/docbook.css b/src/extension/dbus/doc/docbook.css new file mode 100644 index 000000000..aed08dce1 --- /dev/null +++ b/src/extension/dbus/doc/docbook.css @@ -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 index 000000000..6bf134a60 --- /dev/null +++ b/src/extension/dbus/doc/inkscapeDbusRef.xml @@ -0,0 +1,81 @@ + + + + + + +]> + + + + Inkscape Dbus Documentation + Version 0.0 + 7 July, 2009 + + + Soren + Berg + +
+ glimmer07@gmail.com +
+
+
+
+
+ + + Introduction + +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. + + +The guiding principles behind the design of this API were: + + +Easy to use: 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. + + +Interactive: 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. + + +Responsive: 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. + + + + + Concepts + + &Terms; + + + + + Reference + + + D-Bus API Reference + + + + Inkscape provides a D-Bus API for programs to interactivly script vector graphics. + + + This API is not yet stable and is likely to change in the future. + + + + &dbus-Application; + &dbus-Document; + &dbus-Proposed; + + + + + + Index + + +
+ diff --git a/src/extension/dbus/doc/inkscapeDbusTerms.xml b/src/extension/dbus/doc/inkscapeDbusTerms.xml new file mode 100644 index 000000000..cd41195a9 --- /dev/null +++ b/src/extension/dbus/doc/inkscapeDbusTerms.xml @@ -0,0 +1,131 @@ + + Connecting to the API + + + Overview + +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. + + +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. + + + + Connection example + +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.) + + + +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) + + + + + + Shortcut + +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. + + +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. + + + +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) + + + + + + + + Terminology + + + + Coordinate System + +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. + + +For example: (100,100) would be just below and to the right of the top left corner of the document. + + + + + + Selections + +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 selection_set(), selection_add(), and selection_box() and then call whatever selection function you need. + + + + + + Groups + +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. + + + + + + Layers and Levels + +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. layer_change_level() changes the order of layers and selection_change_level() changes the order of objects within a layer. + + +Changing the level of a selection also deserves some explanation. The selection_change_level() 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. + + + + + + Style Strings + +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. + + + + + + Nodes and Paths + +To be written. + + + + + diff --git a/src/extension/dbus/doc/spec-to-docbook.xsl b/src/extension/dbus/doc/spec-to-docbook.xsl new file mode 100644 index 000000000..e200a05e0 --- /dev/null +++ b/src/extension/dbus/doc/spec-to-docbook.xsl @@ -0,0 +1,544 @@ + + + + + + + + + + + + + + + + + + + + + + interface + + + + Methods + + + + + + + + + + + Signals + + + + + + + + + + + Implemented Interfaces + + Objects implementing also implements + org.freedesktop.DBus.Introspectable, + org.freedesktop.DBus.Properties + + + + + + + Properties + + + + + + + + + + + Description + + + + + + + Details + + + + + + + + + Signal Details + + + + + + + + + + + Property Details + + + + + + + + + + + + + + + + +: + + + + + + + + + + + + + + + + + + + + + + <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 + +'' + + + + + + + + + + + + + +: + + + + + + + + + + + + + + + + + + + + + <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 + + () + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + : + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Since + + + + + + + + /> + + + + + + + is deprecated since version and should not be used in newly-written code. Use + + + + + : + + + :: + + + . + + + + + + + + + + + + + + + +instead. + + + + + + + + + + + + + + + + + +See also: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +: + + + + + + + + + + + + Errors + + + + : + + + + + + + + + + + + Permissions + + + + + + + + + + + + + + + + + + <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"/> () + + () + + + + + + + + + + + + + + + + +:'' + + + + + + + + + + + + +::() + + + + + + + + + + + + +.() + + + + + +'' +, + + + + + +'' +, + + + + + + +'' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 5045b4248d6c274a5787476889b9332c19940507 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 13 Jul 2009 17:54:55 +0000 Subject: TEMPORARY Added a shell script to build documentation until it's integrated into the build system. (bzr r8254.1.10) --- src/extension/dbus/builddocs.sh | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100755 src/extension/dbus/builddocs.sh diff --git a/src/extension/dbus/builddocs.sh b/src/extension/dbus/builddocs.sh new file mode 100755 index 000000000..2c16daf41 --- /dev/null +++ b/src/extension/dbus/builddocs.sh @@ -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 + -- cgit v1.2.3 From fc46b3cb436a03d787778e0e462f89e45038b716 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 13 Jul 2009 22:42:41 +0000 Subject: Implemented all the CSS style functions. Worked on some layer functions. (bzr r8254.1.11) --- src/extension/dbus/document-interface.cpp | 62 +++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 94f442865..f73d319f5 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -365,21 +365,30 @@ gboolean document_interface_document_merge_css (DocumentInterface *object, gchar *stylestring, GError **error) { - return FALSE; + 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; } +//FIXME this actually merges gboolean document_interface_document_set_css (DocumentInterface *object, gchar *stylestring, GError **error) { - return FALSE; + 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_resize_to_fit_selection (DocumentInterface *object, GError **error) { - return FALSE; + dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); + //verb_fit_canvas_to_selection(object->desk); + return TRUE; } /**************************************************************************** @@ -506,28 +515,46 @@ gchar * document_interface_get_css (DocumentInterface *object, gchar *shape, GError **error) { -return NULL; + 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) { - return FALSE; + gchar style[] = "style"; + Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; + 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) { - return FALSE; + SPCSSAttr * newstyle = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string (newstyle, stylestring); + + gchar style[] = "style"; + Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; + 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_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - return FALSE; + const GSList *oldsel = selection_swap(object->desk, shape); + document_interface_selection_move_to_layer(object, layerstr, error); + selection_restore(object->desk, oldsel); + return TRUE; } DBUSPoint ** @@ -818,11 +845,30 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou return TRUE; } +//FIXME: does not paste in new layer. gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error) { - return FALSE; + 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); + + if (next && (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0)) { + + sp_selection_cut(dt); + + dt->setCurrentLayer(next); + + sp_selection_paste(dt, TRUE); + } + return TRUE; } gboolean -- cgit v1.2.3 From 103aff597d89ef273a5d9cd12a0148c57f6a6435 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 15 Jul 2009 17:06:03 +0000 Subject: implemented a number of functions, including save/load functions. Removed the print function because I can see no way of doing it without bringing up a dialog. (bzr r8254.1.12) --- src/extension/dbus/document-interface.cpp | 107 +++++++++++++++++++++++------- src/extension/dbus/document-interface.xml | 5 +- 2 files changed, 86 insertions(+), 26 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index f73d319f5..1cdff0133 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -24,6 +24,14 @@ #include "style.h" //style_write +#include "file.h" //IO + +#include "extension/system.h" //IO + +#include "extension/output.h" //IO + +#include "print.h" //IO + /**************************************************************************** HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ @@ -330,13 +338,27 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, gchar* document_interface_text (DocumentInterface *object, gchar *text, GError **error) { + //FIXME: implement. return NULL; } gchar* document_interface_node (DocumentInterface *object, gchar *type, GError **error) { - return NULL; + 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")); } /**************************************************************************** @@ -371,14 +393,14 @@ document_interface_document_merge_css (DocumentInterface *object, return TRUE; } -//FIXME this actually merges 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); - sp_desktop_set_style (object->desk, style); + //Memory leak? + object->desk->current = style; return TRUE; } @@ -387,7 +409,6 @@ document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error) { dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); - //verb_fit_canvas_to_selection(object->desk); return TRUE; } @@ -440,7 +461,6 @@ document_interface_get_attribute (DocumentInterface *object, char *shape, SPDesktop *desk2 = object->desk; SPDocument * doc = sp_desktop_document (desk2); - // FIXME: Not sure if this is the most efficient way. Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; /* WORKS @@ -560,6 +580,7 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { + //FIXME: implement. return NULL; } @@ -569,48 +590,86 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape ****************************************************************************/ gboolean -document_interface_save (DocumentInterface *object, GError **error){ +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){ - return FALSE; + 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){ - return FALSE; -} + 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_print (DocumentInterface *object, GError **error){ - return FALSE; +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){ +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){ +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){ +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){ +document_interface_redo (DocumentInterface *object, GError **error) +{ return dbus_call_verb (object, SP_VERB_EDIT_REDO, error); } @@ -686,7 +745,6 @@ document_interface_selection_add (DocumentInterface *object, char *name, GError { if (name == NULL) return FALSE; - //FIXME: This gets called a lot. Efficient? SPDocument * doc = sp_desktop_document (object->desk); Inkscape::Selection *selection = sp_desktop_selection(object->desk); /* WORKS @@ -701,6 +759,7 @@ gboolean document_interface_selection_add_list (DocumentInterface *object, char **names, GError **error) { + //FIXME: implement. return FALSE; } @@ -717,6 +776,7 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { + //FIXME: broken array passing. sp_desktop_selection(object->desk)->clear(); int i; for (i=0;((i<30000) && (names[i] != NULL));i++) { @@ -760,6 +820,7 @@ document_interface_select_all_in_all_layers(DocumentInterface *object, GError **error) { sp_edit_select_all_in_all_layers (object->desk); + return TRUE; } gboolean @@ -767,6 +828,7 @@ document_interface_selection_box (DocumentInterface *object, int x, int y, int x2, int y2, gboolean replace, GError **error) { + //FIXME: implement. return FALSE; } @@ -836,12 +898,7 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou //Geom::Point m( (object->desk)->point() - sel_bbox->midpoint() ); Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); sp_selection_move_relative(sel, m, true); - } - - //FIXME: dosn't work with transformations - //sp_selection_move (object->desk, x - selection_get_center_x(sel), - // 0 - (y - selection_get_center_y(sel))); return TRUE; } @@ -874,6 +931,7 @@ document_interface_selection_move_to_layer (DocumentInterface *object, gboolean document_interface_selection_get_center (DocumentInterface *object) { + //FIXME: implement: pass struct. return FALSE; } @@ -945,6 +1003,7 @@ document_interface_layer_set (DocumentInterface *object, gchar ** document_interface_layer_get_all (DocumentInterface *object) { + //FIXME: implement. return NULL; } diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index ba8c7e2b3..f79816de1 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -719,8 +719,8 @@ - - + -- cgit v1.2.3 From c819feae71738f973920724e60029397dd1c92a1 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 16 Jul 2009 16:01:55 +0000 Subject: Added missing (and very important) file. Added get_path method. Added documentation on paths. (bzr r8254.1.13) --- src/extension/dbus/doc/inkscapeDbusTerms.xml | 15 +- src/extension/dbus/document-interface.cpp | 43 ++-- src/extension/dbus/document-interface.h | 353 +++++++++++++++++++++++++++ src/extension/dbus/document-interface.xml | 24 +- 4 files changed, 407 insertions(+), 28 deletions(-) create mode 100644 src/extension/dbus/document-interface.h diff --git a/src/extension/dbus/doc/inkscapeDbusTerms.xml b/src/extension/dbus/doc/inkscapeDbusTerms.xml index cd41195a9..507fcbf24 100644 --- a/src/extension/dbus/doc/inkscapeDbusTerms.xml +++ b/src/extension/dbus/doc/inkscapeDbusTerms.xml @@ -119,9 +119,20 @@ Style strings look something like this: "fill:#ff0000;fill-opacity:1;stroke:#000 - + - Nodes and Paths + Paths + +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. + + +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 object_to_path() 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. + + + + + + Nodes To be written. diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 1cdff0133..e3573989a 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -422,8 +422,8 @@ document_interface_set_attribute (DocumentInterface *object, char *shape, { Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; - /* ALTERNATIVE - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); + /* ALTERNATIVE (is this faster?) + Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); */ if (newNode) { @@ -458,14 +458,8 @@ gchar * document_interface_get_attribute (DocumentInterface *object, char *shape, char *attribute, GError **error) { - SPDesktop *desk2 = object->desk; - SPDocument * doc = sp_desktop_document (desk2); - - Inkscape::XML::Node *newNode = doc->getObjectById(shape)->repr; + Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; - /* WORKS - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); - */ if (newNode) return g_strdup(newNode->attribute(attribute)); return FALSE; @@ -493,16 +487,17 @@ document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, return TRUE; } -void +gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { const GSList *oldsel = selection_swap(object->desk, shape); dbus_call_verb (object, SP_VERB_OBJECT_TO_CURVE, error); selection_restore(object->desk, oldsel); + return TRUE; } -gboolean +gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); @@ -510,15 +505,7 @@ document_interface_get_path (DocumentInterface *object, char *pathname, GError * g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); return FALSE; } - gchar *pathstr = strdup(node->attribute("d")); - printf("PATH: %s\n", pathstr); - //gfree (pathstr); - std::istringstream iss(pathstr); - std::copy(std::istream_iterator(iss), - std::istream_iterator(), - std::ostream_iterator(std::cout, "\n")); - - return TRUE; + return strdup(node->attribute("d")); } gboolean @@ -580,7 +567,14 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { - //FIXME: implement. + //FIXME: not implemented. + Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); + if (node == NULL || node->attribute("d") == NULL) { + g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + return FALSE; + } + char * path = strdup(node->attribute("d")); + return NULL; } @@ -712,8 +706,8 @@ document_interface_update (DocumentInterface *object, GError **error) SELECTION FUNCTIONS FIXME: use call_verb where appropriate. ****************************************************************************/ -gchar ** -document_interface_selection_get (DocumentInterface *object) +gboolean +document_interface_selection_get (DocumentInterface *object, GSList const * listy, GError **error) { Inkscape::Selection * sel = sp_desktop_selection(object->desk); GSList const *oldsel = sel->list(); @@ -737,7 +731,8 @@ document_interface_selection_get (DocumentInterface *object) printf("%d = %s\n", i, list[i]); } - return list; + listy = oldsel; + return TRUE; } gboolean diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h new file mode 100644 index 000000000..ba60a6599 --- /dev/null +++ b/src/extension/dbus/document-interface.h @@ -0,0 +1,353 @@ +#ifndef INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ +#define INKSCAPE_EXTENSION_DOCUMENT_INTERFACE_H_ + +#include +#include +#include +#include +#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; +}; + +struct DBUSPoint { + int x; + int y; +}; +/**************************************************************************** + MISC FUNCTIONS +****************************************************************************/ + +gboolean +document_interface_delete_all (DocumentInterface *object, GError **error); + +void +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); + +gchar* +document_interface_text (DocumentInterface *object, gchar *text, + 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); + +void +document_interface_set_int_attribute (DocumentInterface *object, + char *shape, char *attribute, + int newval, GError **error); + +void +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_move_to_layer (DocumentInterface *object, gchar *shape, + gchar *layerstr, GError **error); + + +DBUSPoint ** +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_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, GSList const * listy, 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); + +gboolean +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_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 index f79816de1..14be0312b 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -556,6 +556,27 @@ After doing this you will no longer be able to modify the shape using shape specific attributes (cx, radius etc.) except transform Required for certain functions that work on paths (not yet present in this API.) + Paths + + + + + + + The id of an object. + + + + + + The path of the object. NULL if the object has no path. + + + + + Get the path value of an object. Equivilent to calling get_attribte() with argument "d". Will not turn object into a path if it is not already. + + Paths @@ -799,8 +820,7 @@ - - + List of the ids of currently selected objects. -- cgit v1.2.3 From 0c4a64e7df83742bb6d7a17f31985eed9d06ef26 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 16 Jul 2009 16:28:50 +0000 Subject: Whoops, fixed a bug in an incomplete method. (bzr r8254.1.14) --- src/extension/dbus/document-interface.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e3573989a..914303a91 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -567,14 +567,15 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, DBUSPoint ** document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { - //FIXME: not implemented. + //FIXME: Needs lot's of work. +/* Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); if (node == NULL || node->attribute("d") == NULL) { g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); return FALSE; } - char * path = strdup(node->attribute("d")); - + //char * path = strdup(node->attribute("d")); +*/ return NULL; } -- cgit v1.2.3 From 88870910722f4cef3a929b49479d2fa721e4f715 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 20 Jul 2009 20:34:13 +0000 Subject: Fixed selection_get() (bzr r8254.1.15) --- src/extension/dbus/document-interface.cpp | 49 +++++++++++++------------------ src/extension/dbus/document-interface.h | 2 +- src/extension/dbus/document-interface.xml | 1 + 3 files changed, 22 insertions(+), 30 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 914303a91..b9d8848cc 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -671,7 +671,7 @@ document_interface_redo (DocumentInterface *object, GError **error) /**************************************************************************** - UPDATE FUNCTIONS + UPDATE FUNCTIONS FIXME: test update system again. ****************************************************************************/ void @@ -689,6 +689,7 @@ document_interface_resume_updates (DocumentInterface *object, GError **error) 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"); } @@ -708,31 +709,22 @@ document_interface_update (DocumentInterface *object, GError **error) ****************************************************************************/ gboolean -document_interface_selection_get (DocumentInterface *object, GSList const * listy, GError **error) +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); - int i; - printf("premalloc\n"); - gchar **list = (gchar **)malloc(size); - printf("postmalloc\n"); - for(i = 0; i < size; i++) - list[i] = (gchar *)malloc(sizeof(gchar) * 10); - printf("postmalloc2\n"); - i=0; - printf("prealloc\n"); + + *out = g_new0 (char *, size + 1); + + int i = 0; for (GSList const *iter = oldsel; iter != NULL; iter = iter->next) { - strcpy (list[i], SP_OBJECT(iter->data)->repr->attribute("id")); + (*out)[i] = g_strdup(SP_OBJECT(iter->data)->repr->attribute("id")); i++; } - printf("postalloc\n"); - for (i=0; idesk); Inkscape::Selection *selection = sp_desktop_selection(object->desk); - /* WORKS - Inkscape::XML::Node *repr2 = sp_repr_lookup_name((doc->root)->repr, name); - selection->add(repr2, TRUE); - */ - selection->add(doc->getObjectById(name)); + + selection->add(get_object_by_name(object->desk, name)); return TRUE; } @@ -755,8 +743,12 @@ gboolean document_interface_selection_add_list (DocumentInterface *object, char **names, GError **error) { - //FIXME: implement. - return FALSE; + int i; + for (i=0;names[i] != NULL;i++) { + //printf("NAME: %s\n", names[i]); + document_interface_selection_add(object, names[i], error); + } + return TRUE; } gboolean @@ -772,11 +764,10 @@ gboolean document_interface_selection_set_list (DocumentInterface *object, gchar **names, GError **error) { - //FIXME: broken array passing. sp_desktop_selection(object->desk)->clear(); int i; - for (i=0;((i<30000) && (names[i] != NULL));i++) { - printf("NAME: %s\n", names[i]); + for (i=0;names[i] != NULL;i++) { + //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index ba60a6599..53fcacaaa 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -224,7 +224,7 @@ document_interface_update (DocumentInterface *object, GError **error); SELECTION FUNCTIONS ****************************************************************************/ gboolean -document_interface_selection_get (DocumentInterface *object, GSList const * listy, GError **error); +document_interface_selection_get (DocumentInterface *object, char ***out, GError **error); gboolean document_interface_selection_add (DocumentInterface *object, diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 14be0312b..5db3de763 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -821,6 +821,7 @@ + List of the ids of currently selected objects. -- cgit v1.2.3 From 40d5732d5a327c51e04c6aaab97725d0d61b2327 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 20 Jul 2009 22:55:35 +0000 Subject: Fixed selection_get_center and selection_combine. Added selection_divide. (bzr r8254.1.16) --- src/extension/dbus/document-interface.cpp | 37 +++++++++++++++++++++++-------- src/extension/dbus/document-interface.h | 6 ++++- src/extension/dbus/document-interface.xml | 17 +++++++++++++- 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index b9d8848cc..a939064e1 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -745,7 +745,6 @@ document_interface_selection_add_list (DocumentInterface *object, { int i; for (i=0;names[i] != NULL;i++) { - //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; @@ -767,7 +766,6 @@ document_interface_selection_set_list (DocumentInterface *object, sp_desktop_selection(object->desk)->clear(); int i; for (i=0;names[i] != NULL;i++) { - //printf("NAME: %s\n", names[i]); document_interface_selection_add(object, names[i], error); } return TRUE; @@ -882,7 +880,6 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou Geom::OptRect sel_bbox = sel->bounds(); if (sel_bbox) { - //Geom::Point m( (object->desk)->point() - sel_bbox->midpoint() ); Geom::Point m( x - selection_get_center_x(sel) , 0 - (y - selection_get_center_y(sel)) ); sp_selection_move_relative(sel, m, true); } @@ -915,11 +912,23 @@ document_interface_selection_move_to_layer (DocumentInterface *object, return TRUE; } -gboolean +GArray * document_interface_selection_get_center (DocumentInterface *object) { - //FIXME: implement: pass struct. - return FALSE; + 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 @@ -933,7 +942,6 @@ 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) @@ -947,8 +955,19 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, else return NULL; - //FIXME: this WILL cause problems with division - return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); + if (sp_desktop_selection(object->desk)->singleRepr() != NULL) + return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); + + //Division will have a list of things selected, should have it's own function. + 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 diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 53fcacaaa..afad56f59 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -298,7 +298,7 @@ gboolean document_interface_selection_move_to_layer (DocumentInterface *object, gchar *layerstr, GError **error); -gboolean +GArray * document_interface_selection_get_center (DocumentInterface *object); gboolean @@ -308,6 +308,10 @@ 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, diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 5db3de763..171508dcd 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -1084,7 +1084,7 @@ - + Center of the selection. @@ -1132,6 +1132,21 @@ + + + + + List of the ids of resulting paths. + + + + + Returns the result of cutting the bottom object by all other intersecting paths. + This may make many seperate layers. + + + + -- cgit v1.2.3 From c30b66d5e5f875384b4fa13f93ceb6bea8054830 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Tue, 21 Jul 2009 01:48:22 +0000 Subject: Worked on text, now works with limited capability. Started work on node_get_coordinates. (bzr r8254.1.17) --- src/extension/dbus/document-interface.cpp | 40 ++++++++++++++++++------------- src/extension/dbus/document-interface.h | 8 +++---- src/extension/dbus/document-interface.xml | 16 ++++++++----- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index a939064e1..a28bb92fa 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -32,6 +32,11 @@ #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 ****************************************************************************/ @@ -335,11 +340,17 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, return retval; } -gchar* -document_interface_text (DocumentInterface *object, gchar *text, GError **error) +gboolean +document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - //FIXME: implement. - return NULL; + //FIXME: Not selectable. + + 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* @@ -564,18 +575,19 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, return TRUE; } -DBUSPoint ** +GArray * document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { //FIXME: Needs lot's of work. -/* - Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); - if (node == NULL || node->attribute("d") == NULL) { - g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); + + Inkscape::XML::Node *shapenode = document_retrive_node (sp_desktop_document (object->desk), shape); + if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } - //char * path = strdup(node->attribute("d")); -*/ + const char * path = strdup(shapenode->attribute("d")); + printf("PATH: %s\n", path); + + Geom::parse_svg_path (path); return NULL; } @@ -705,7 +717,7 @@ document_interface_update (DocumentInterface *object, GError **error) } /**************************************************************************** - SELECTION FUNCTIONS FIXME: use call_verb where appropriate. + SELECTION FUNCTIONS FIXME: use call_verb where appropriate (once update system is tested.) ****************************************************************************/ gboolean @@ -950,15 +962,11 @@ document_interface_selection_combine (DocumentInterface *object, gchar *cmd, 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 if (strcmp(cmd, "division") == 0) - dbus_call_verb (object, SP_VERB_SELECTION_CUT, error); else return NULL; if (sp_desktop_selection(object->desk)->singleRepr() != NULL) return g_strdup((sp_desktop_selection(object->desk)->singleRepr())->attribute("id")); - - //Division will have a list of things selected, should have it's own function. return NULL; } diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index afad56f59..9b56da417 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -76,9 +76,9 @@ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error); -gchar* -document_interface_text (DocumentInterface *object, gchar *text, - GError **error); +gboolean +document_interface_text (DocumentInterface *object, int x, int y, + gchar *text, GError **error); gchar* document_interface_node (DocumentInterface *object, gchar *svgtype, @@ -169,7 +169,7 @@ document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error); -DBUSPoint ** +GArray * document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape); /**************************************************************************** diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 171508dcd..7126887af 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -276,15 +276,19 @@ - + - The text you want. + The x coordinate to put the text at. - - + - The name of the new text object. + The y coordinate to put the text at. + + + + + The text you want. @@ -688,7 +692,7 @@ A object that contains a path ("d") attribute. - + An array of points. -- cgit v1.2.3 From f09b3a57c8a6259ef82db7be0786ff2959874a24 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Tue, 21 Jul 2009 17:50:12 +0000 Subject: worked on path parsing. (bzr r8254.1.18) --- src/extension/dbus/document-interface.cpp | 5 ++++- src/extension/dbus/document-interface.xml | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index a28bb92fa..9a900e0ee 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -52,6 +52,9 @@ SPObject * get_object_by_name (SPDesktop *desk, gchar *name) { return sp_desktop_document(desk)->getObjectById(name); + /* ALTERNATIVE (is this faster if only repr is needed?) + Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); + */ } const gchar * @@ -584,7 +587,7 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } - const char * path = strdup(shapenode->attribute("d")); + char * path = strdup(shapenode->attribute("d")); printf("PATH: %s\n", path); Geom::parse_svg_path (path); diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 7126887af..37749c932 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -578,7 +578,7 @@ - Get the path value of an object. Equivilent to calling get_attribte() with argument "d". Will not turn object into a path if it is not already. + Get the path value of an object. Equivilent to calling get_attribte() with argument "d". Will not turn object into a path if it is not already. Paths -- cgit v1.2.3 From 4caca0b9edefb8470c058fdfed95ff50e0324499 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Wed, 22 Jul 2009 06:22:59 +0000 Subject: Fixed GErrors. Added many GErrors, especially for unfound objects. transfered many functions to using verbs instead of the function the verb calls to make error reporting easier. (bzr r8254.1.19) --- src/extension/dbus/dbus-init.cpp | 3 + src/extension/dbus/document-interface.cpp | 285 +++++++++++++++++++++-------- src/extension/dbus/document-interface.h | 23 ++- src/extension/dbus/document-interface.xml | 9 + src/extension/dbus/org.inkscape.service.in | 1 + 5 files changed, 244 insertions(+), 77 deletions(-) diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index a30bb8fda..dfd69d9fa 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -115,6 +115,9 @@ 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; diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 9a900e0ee..664655f0e 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -35,7 +35,7 @@ #include "live_effects/parameter/text.h" //text #include "display/canvas-text.h" //text -#include "2geom/svg-path-parser.h" //get_node_coordinates +//#include "2geom/svg-path-parser.h" //get_node_coordinates /**************************************************************************** HELPER / SHORTCUT FUNCTIONS @@ -48,19 +48,48 @@ const gchar* intToCString(int i) return ss.str().c_str(); } -SPObject * -get_object_by_name (SPDesktop *desk, gchar *name) +Inkscape::XML::Node * +get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) { - return sp_desktop_document(desk)->getObjectById(name); /* ALTERNATIVE (is this faster if only repr is needed?) - Inkscape::XML::Node *newnode = sp_repr_lookup_name((doc->root)->repr, name); + 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; +} + +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; +} + +gboolean +dbus_check_string (gchar *string, GError ** error, gchar * errorstr) +{ + if (string == NULL) + { + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_OTHER, "%s", errorstr); + return FALSE; + } + return TRUE; } const gchar * get_name_from_object (SPObject * obj) { - return obj->repr->attribute("id"); + return obj->repr->attribute("id"); } void @@ -70,11 +99,6 @@ desktop_ensure_active (SPDesktop* desk) { return; } -Inkscape::XML::Node * -document_retrive_node (SPDocument *doc, gchar *name) { - return (doc->getObjectById(name))->repr; -} - gdouble selection_get_center_x (Inkscape::Selection *sel){ NRRect *box = g_new(NRRect, 1);; @@ -90,12 +114,12 @@ selection_get_center_y (Inkscape::Selection *sel){ } //move_to etc const GSList * -selection_swap(SPDesktop *desk, gchar *name) +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)); + sel->set(get_object_by_name(desk, name, error)); return oldsel; } @@ -147,7 +171,8 @@ 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 ) { @@ -161,6 +186,7 @@ dbus_call_verb (DocumentInterface *object, int verbid, GError **error) } } } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb failed to execute"); return FALSE; } @@ -198,6 +224,42 @@ document_interface_new (void) return (DocumentInterface*)g_object_new (TYPE_DOCUMENT_INTERFACE, NULL); } +GQuark +inkscape_error_quark (void) +{ + static GQuark quark = 0; + if (!quark) + quark = g_quark_from_static_string ("inkscape_error"); + + return quark; +} + +/* This should really be standard. */ +#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 ****************************************************************************/ @@ -209,7 +271,7 @@ document_interface_delete_all (DocumentInterface *object, GError **error) return TRUE; } -void +gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error) { SPDesktop *desk2 = object->desk; @@ -226,6 +288,8 @@ document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError * } } } + g_set_error(error, INKSCAPE_ERROR, INKSCAPE_ERROR_VERB, "Verb '%s' failed to execute or was not found.", verbid); + return FALSE; } @@ -422,7 +486,7 @@ gboolean document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error) { - dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); + return dbus_call_verb (object, SP_VERB_FIT_CANVAS_TO_SELECTION, error); return TRUE; } @@ -434,56 +498,72 @@ gboolean document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name(object->desk, shape)->repr; + 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 (newNode) - { - newNode->setAttribute(attribute, newval, TRUE); - return TRUE; - } - return FALSE; + if (!dbus_check_string(newval, error, "New value string was empty.")) + return FALSE; + + if (!newNode) + return FALSE; + + newNode->setAttribute(attribute, newval, TRUE); + return TRUE; } -void +gboolean document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; - if (newNode) - sp_repr_set_int (newNode, attribute, newval); + 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; } -void +gboolean document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error) { - Inkscape::XML::Node *newNode = get_object_by_name (object->desk, shape)->repr; - if (newNode) - sp_repr_set_svg_double (newNode, attribute, newval); + 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_object_by_name(object->desk, shape)->repr; + Inkscape::XML::Node *newNode = get_repr_by_name(object->desk, shape, error); - if (newNode) - return g_strdup(newNode->attribute(attribute)); - return FALSE; + 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); + 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; @@ -493,7 +573,9 @@ gboolean document_interface_move_to (DocumentInterface *object, gchar *name, gdouble x, gdouble y, GError **error) { - const GSList *oldsel = selection_swap(object->desk, name); + 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))); @@ -505,7 +587,9 @@ gboolean document_interface_object_to_path (DocumentInterface *object, char *shape, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape); + 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; @@ -514,10 +598,15 @@ document_interface_object_to_path (DocumentInterface *object, gchar * document_interface_get_path (DocumentInterface *object, char *pathname, GError **error) { - Inkscape::XML::Node *node = document_retrive_node (sp_desktop_document (object->desk), pathname); - if (node == NULL || node->attribute("d") == NULL) { - g_set_error(error, DBUS_GERROR, DBUS_GERROR_REMOTE_EXCEPTION, "Object is not a path or does not exist."); - return FALSE; + 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")); } @@ -544,8 +633,15 @@ 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_object_by_name(object->desk, shape)->repr; + 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); @@ -556,11 +652,18 @@ 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); - gchar style[] = "style"; - Inkscape::XML::Node *node = get_object_by_name(object->desk, shape)->repr; SPCSSAttr * oldstyle = sp_repr_css_attr (node, style); sp_repr_css_merge(oldstyle, newstyle); @@ -572,7 +675,10 @@ gboolean document_interface_move_to_layer (DocumentInterface *object, gchar *shape, gchar *layerstr, GError **error) { - const GSList *oldsel = selection_swap(object->desk, shape); + 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; @@ -582,8 +688,8 @@ GArray * document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape) { //FIXME: Needs lot's of work. - - Inkscape::XML::Node *shapenode = document_retrive_node (sp_desktop_document (object->desk), shape); +/* + Inkscape::XML::Node *shapenode = get_repr_by_name (object->desk, shape, error); if (shapenode == NULL || shapenode->attribute("d") == NULL) { return FALSE; } @@ -592,6 +698,7 @@ document_interface_get_node_coordinates (DocumentInterface *object, gchar *shape Geom::parse_svg_path (path); return NULL; + */ } @@ -645,6 +752,16 @@ document_interface_save_as (DocumentInterface *object, //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) @@ -686,7 +803,10 @@ document_interface_redo (DocumentInterface *object, GError **error) /**************************************************************************** - UPDATE FUNCTIONS FIXME: test update system again. + 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 @@ -746,11 +866,13 @@ document_interface_selection_get (DocumentInterface *object, char ***out, GError gboolean document_interface_selection_add (DocumentInterface *object, char *name, GError **error) { - if (name == NULL) + SPObject * obj = get_object_by_name(object->desk, name, error); + if (!obj) return FALSE; + Inkscape::Selection *selection = sp_desktop_selection(object->desk); - selection->add(get_object_by_name(object->desk, name)); + selection->add(obj); return TRUE; } @@ -797,8 +919,8 @@ document_interface_selection_rotate (DocumentInterface *object, int angle, GErro gboolean document_interface_selection_delete (DocumentInterface *object, GError **error) { - sp_selection_delete (object->desk); - return TRUE; + //sp_selection_delete (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_DELETE, error); } gboolean @@ -811,16 +933,16 @@ document_interface_selection_clear (DocumentInterface *object, GError **error) gboolean document_interface_select_all (DocumentInterface *object, GError **error) { - sp_edit_select_all (object->desk); - return TRUE; + //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 TRUE; + //sp_edit_select_all_in_all_layers (object->desk); + return dbus_call_verb (object, SP_VERB_EDIT_SELECT_ALL_IN_ALL_LAYERS, error); } gboolean @@ -835,48 +957,55 @@ document_interface_selection_box (DocumentInterface *object, int x, int y, gboolean document_interface_selection_invert (DocumentInterface *object, GError **error) { - sp_edit_invert (object->desk); - return TRUE; + //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 TRUE; + //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 TRUE; + //sp_selection_ungroup (object->desk); + return dbus_call_verb (object, SP_VERB_SELECTION_UNGROUP, error); } gboolean document_interface_selection_cut (DocumentInterface *object, GError **error) { - sp_selection_cut (object->desk); - return TRUE; + //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 TRUE; + //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); - sp_selection_paste (object->desk, TRUE); - return TRUE; + //desktop_ensure_active (object->desk); + //sp_selection_paste (object->desk, TRUE); + 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; } @@ -914,9 +1043,12 @@ document_interface_selection_move_to_layer (DocumentInterface *object, if (selection->isEmpty()) return FALSE; - SPObject *next = get_object_by_name(object->desk, layerstr); + SPObject *next = get_object_by_name(object->desk, layerstr, error); + + if (!next) + return FALSE; - if (next && (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0)) { + if (strcmp("layer", (next->repr)->attribute("inkscape:groupmode")) == 0) { sp_selection_cut(dt); @@ -1013,7 +1145,12 @@ gboolean document_interface_layer_set (DocumentInterface *object, gchar *layerstr, GError **error) { - object->desk->setCurrentLayer (get_object_by_name (object->desk, layerstr)); + SPObject * obj = get_object_by_name (object->desk, layerstr, error); + + if (!obj) + return FALSE; + + object->desk->setCurrentLayer (obj); return TRUE; } diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 9b56da417..ff0452a14 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -31,6 +31,20 @@ 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; @@ -42,7 +56,7 @@ struct DBUSPoint { gboolean document_interface_delete_all (DocumentInterface *object, GError **error); -void +gboolean document_interface_call_verb (DocumentInterface *object, gchar *verbid, GError **error); @@ -118,12 +132,12 @@ document_interface_set_attribute (DocumentInterface *object, char *shape, char *attribute, char *newval, GError **error); -void +gboolean document_interface_set_int_attribute (DocumentInterface *object, char *shape, char *attribute, int newval, GError **error); -void +gboolean document_interface_set_double_attribute (DocumentInterface *object, char *shape, char *attribute, double newval, GError **error); @@ -186,6 +200,9 @@ document_interface_load (DocumentInterface *object, 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); diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 37749c932..7c16c6d1e 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -744,6 +744,15 @@ + + + + + Marks the document as unmodified/saved. + Will prevent save confirmation on close if called at end of script. + + + + + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include "document-interface.h" #include @@ -41,13 +58,16 @@ HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ -const gchar* intToCString(int i) -{ - std::stringstream ss; - ss << i; - return ss.str().c_str(); -} - +/* + * 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) { @@ -63,6 +83,9 @@ get_repr_by_name (SPDesktop *desk, gchar *name, GError **error) return node; } +/* + * See comment for get_repr_by_name, above. + */ SPObject * get_object_by_name (SPDesktop *desk, gchar *name, GError **error) { @@ -75,6 +98,11 @@ get_object_by_name (SPDesktop *desk, gchar *name, GError **error) 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) { @@ -86,12 +114,19 @@ dbus_check_string (gchar *string, GError ** error, const gchar * errorstr) 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) @@ -112,7 +147,21 @@ selection_get_center_y (Inkscape::Selection *sel){ box = sel->boundsInDocument(box); return box->y0 + ((box->y1 - box->y0)/2); } -//move_to etc + +/* + * 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) { @@ -123,6 +172,9 @@ selection_swap(SPDesktop *desk, gchar *name, GError **error) return oldsel; } +/* + * See selection_swap, above + */ void selection_restore(SPDesktop *desk, const GSList * oldsel) { @@ -130,6 +182,9 @@ selection_restore(SPDesktop *desk, const GSList * oldsel) sel->setList(oldsel); } +/* + * Shortcut for creating a Node. + */ Inkscape::XML::Node * dbus_create_node (SPDesktop *desk, const gchar *type) { @@ -139,6 +194,13 @@ dbus_create_node (SPDesktop *desk, const gchar *type) 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) { @@ -163,6 +225,14 @@ finish_create_shape (DocumentInterface *object, GError **error, Inkscape::XML::N 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) { @@ -223,6 +293,11 @@ 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) { @@ -233,7 +308,6 @@ inkscape_error_quark (void) return quark; } -/* This should really be standard. */ #define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC } GType @@ -409,7 +483,7 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, gboolean document_interface_text (DocumentInterface *object, int x, int y, gchar *text, GError **error) { - //FIXME: Not selectable. + //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), ""); @@ -1094,6 +1168,8 @@ document_interface_selection_move_to (DocumentInterface *object, gdouble x, gdou } //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) diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 436f6b118..8cf9b7ec1 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -1,3 +1,20 @@ +/* + * 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 + * + * 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_ diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index c9cd8aa69..2f1549488 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -1,3 +1,21 @@ + + +#include // (static.*(\n[^}]*)*(async)+.*(\n[^}]*)*})|typedef void .*; // http://www.josephkahn.com/music/index.xml @@ -50,6 +52,11 @@ dbus_register_object (DBusGConnection *connection, DOCUMENT INTERFACE CLASS STUFF ****************************************************************************/ +struct _DocumentInterface { + GObject parent; + DBusGProxy * proxy; +}; + G_DEFINE_TYPE(DocumentInterface, document_interface, G_TYPE_OBJECT) static void @@ -111,7 +118,7 @@ inkscape_desktop_init_dbus () } -static +//static gboolean inkscape_delete_all (DocumentInterface *doc, GError **error) { @@ -119,7 +126,7 @@ inkscape_delete_all (DocumentInterface *doc, GError **error) return org_inkscape_document_delete_all (proxy, error); } -static +//static gboolean inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error) { @@ -128,7 +135,7 @@ inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **err } -static +//static gchar * inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error) { @@ -138,7 +145,7 @@ inkscape_rectangle (DocumentInterface *doc, const gint IN_x, const gint IN_y, co return OUT_object_name; } -static +//static char * inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_width, const gint IN_height, GError **error) { @@ -148,7 +155,7 @@ inkscape_ellipse (DocumentInterface *doc, const gint IN_x, const gint IN_y, cons return OUT_object_name; } -static +//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) { @@ -158,7 +165,7 @@ inkscape_polygon (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, co return OUT_object_name; } -static +//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) { @@ -168,7 +175,7 @@ inkscape_star (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const return OUT_object_name; } -static +//static char * inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, const gint IN_r, const gint IN_revolutions, GError **error) { @@ -178,7 +185,7 @@ inkscape_spiral (DocumentInterface *doc, const gint IN_cx, const gint IN_cy, con return OUT_object_name; } -static +//static char * inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const gint IN_x2, const gint IN_y2, GError **error) { @@ -188,7 +195,7 @@ inkscape_line (DocumentInterface *doc, const gint IN_x, const gint IN_y, const g return OUT_object_name; } -static +//static gboolean inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error) { @@ -196,7 +203,7 @@ inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const c return org_inkscape_document_text (proxy, IN_x, IN_y, IN_text, error); } -static +//static char * inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error) { @@ -206,7 +213,7 @@ inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const return OUT_object_name; } -static +//static char * inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error) { @@ -216,7 +223,7 @@ inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error) return OUT_node_name; } -static +//static gdouble inkscape_document_get_width (DocumentInterface *doc, GError **error) { @@ -226,7 +233,7 @@ inkscape_document_get_width (DocumentInterface *doc, GError **error) return OUT_val; } -static +//static gdouble inkscape_document_get_height (DocumentInterface *doc, GError **error) { @@ -236,7 +243,7 @@ inkscape_document_get_height (DocumentInterface *doc, GError **error) return OUT_val; } -static +//static char * inkscape_document_get_css (DocumentInterface *doc, GError **error) { @@ -246,7 +253,7 @@ inkscape_document_get_css (DocumentInterface *doc, GError **error) return OUT_css; } -static +//static gboolean inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error) { @@ -254,7 +261,7 @@ inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, return org_inkscape_document_document_document_set_css (proxy, IN_stylestring, error); } -static +//static gboolean inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error) { @@ -262,7 +269,7 @@ inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring return org_inkscape_document_document_document_merge_css (proxy, IN_stylestring, error); } -static +//static gboolean inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error) { @@ -270,7 +277,7 @@ inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **erro return org_inkscape_document_document_document_resize_to_fit_selection (proxy, error); } -static +//static gboolean inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error) { @@ -278,7 +285,7 @@ inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const cha return org_inkscape_document_set_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); } -static +//static gboolean inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error) { @@ -286,7 +293,7 @@ inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const return org_inkscape_document_set_int_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); } -static +//static gboolean inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error) { @@ -294,7 +301,7 @@ inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, co return org_inkscape_document_set_double_attribute (proxy, IN_shape, IN_attribute, IN_newval, error); } -static +//static char * inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error) { @@ -304,7 +311,7 @@ inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const cha return OUT_val; } -static +//static gboolean inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error) { @@ -312,7 +319,7 @@ inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x return org_inkscape_document_move (proxy, IN_shape, IN_x, IN_y, error); } -static +//static gboolean inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error) { @@ -320,7 +327,7 @@ inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble I return org_inkscape_document_move_to (proxy, IN_shape, IN_x, IN_y, error); } -static +//static gboolean inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error) { @@ -328,7 +335,7 @@ inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GEr return org_inkscape_document_object_to_path (proxy, IN_objectname, error); } -static +//static char * inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error) { @@ -338,7 +345,7 @@ inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error return OUT_val; } -static +//static gboolean inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error) { @@ -346,7 +353,7 @@ inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * return org_inkscape_document_transform (proxy, IN_shape, IN_transformstr, error); } -static +//static char * inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error) { @@ -356,7 +363,7 @@ inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error) return OUT_css; } -static +//static gboolean inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error) { @@ -364,7 +371,7 @@ inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * return org_inkscape_document_modify_css (proxy, IN_shape, IN_cssattrib, IN_newval, error); } -static +//static gboolean inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error) { @@ -372,7 +379,7 @@ inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * return org_inkscape_document_merge_css (proxy, IN_shape, IN_stylestring, error); } -static +//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) { @@ -380,7 +387,7 @@ inkscape_set_color (DocumentInterface *doc, const char * IN_shape, const gint IN return org_inkscape_document_set_color (proxy, IN_shape, IN_red, IN_green, IN_blue, IN_fill, error); } -static +//static gboolean inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error) { @@ -388,7 +395,7 @@ inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, cons return org_inkscape_document_move_to_layer (proxy, IN_objectname, IN_layername, error); } -static +//static GArray* inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error) { @@ -398,7 +405,7 @@ inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GE return OUT_points; } -static +//static gboolean inkscape_save (DocumentInterface *doc, GError **error) { @@ -406,7 +413,7 @@ inkscape_save (DocumentInterface *doc, GError **error) return org_inkscape_document_save (proxy, error); } -static +//static gboolean inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error) { @@ -414,7 +421,7 @@ inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **err return org_inkscape_document_save_as (proxy, IN_pathname, error); } -static +//static gboolean inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error) { @@ -422,7 +429,7 @@ inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error) return org_inkscape_document_load (proxy, IN_pathname, error); } -static +//static gboolean inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error) { @@ -430,7 +437,7 @@ inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error) return org_inkscape_document_mark_as_unmodified (proxy, error); } -static +//static gboolean inkscape_close (DocumentInterface *doc, GError **error) { @@ -438,7 +445,7 @@ inkscape_close (DocumentInterface *doc, GError **error) return org_inkscape_document_close (proxy, error); } -static +//static gboolean inkscape_inkscape_exit (DocumentInterface *doc, GError **error) { @@ -446,7 +453,7 @@ inkscape_inkscape_exit (DocumentInterface *doc, GError **error) return org_inkscape_document_exit (proxy, error); } -static +//static gboolean inkscape_undo (DocumentInterface *doc, GError **error) { @@ -454,7 +461,7 @@ inkscape_undo (DocumentInterface *doc, GError **error) return org_inkscape_document_undo (proxy, error); } -static +//static gboolean inkscape_redo (DocumentInterface *doc, GError **error) { @@ -462,7 +469,7 @@ inkscape_redo (DocumentInterface *doc, GError **error) return org_inkscape_document_redo (proxy, error); } -static +//static gboolean inkscape_pause_updates (DocumentInterface *doc, GError **error) { @@ -470,7 +477,7 @@ inkscape_pause_updates (DocumentInterface *doc, GError **error) return org_inkscape_document_pause_updates (proxy, error); } -static +//static gboolean inkscape_resume_updates (DocumentInterface *doc, GError **error) { @@ -478,7 +485,7 @@ inkscape_resume_updates (DocumentInterface *doc, GError **error) return org_inkscape_document_resume_updates (proxy, error); } -static +//static gboolean inkscape_update (DocumentInterface *doc, GError **error) { @@ -486,7 +493,7 @@ inkscape_update (DocumentInterface *doc, GError **error) return org_inkscape_document_update (proxy, error); } -static +//static char ** inkscape_selection_get (DocumentInterface *doc, GError **error) { @@ -496,7 +503,7 @@ inkscape_selection_get (DocumentInterface *doc, GError **error) return OUT_listy; } -static +//static gboolean inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error) { @@ -504,7 +511,7 @@ inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **e return org_inkscape_document_selection_add (proxy, IN_name, error); } -static +//static gboolean inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error) { @@ -512,7 +519,7 @@ inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GErr return org_inkscape_document_selection_add_list (proxy, IN_name, error); } -static +//static gboolean inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error) { @@ -520,7 +527,7 @@ inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **e return org_inkscape_document_selection_set (proxy, IN_name, error); } -static +//static gboolean inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error) { @@ -528,7 +535,7 @@ inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GErr return org_inkscape_document_selection_set_list (proxy, IN_name, error); } -static +//static gboolean inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error) { @@ -536,7 +543,7 @@ inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError * return org_inkscape_document_selection_rotate (proxy, IN_angle, error); } -static +//static gboolean inkscape_selection_delete (DocumentInterface *doc, GError **error) { @@ -544,7 +551,7 @@ inkscape_selection_delete (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_delete (proxy, error); } -static +//static gboolean inkscape_selection_clear (DocumentInterface *doc, GError **error) { @@ -552,7 +559,7 @@ inkscape_selection_clear (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_clear (proxy, error); } -static +//static gboolean inkscape_select_all (DocumentInterface *doc, GError **error) { @@ -560,7 +567,7 @@ inkscape_select_all (DocumentInterface *doc, GError **error) return org_inkscape_document_select_all (proxy, error); } -static +//static gboolean inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error) { @@ -568,7 +575,7 @@ inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error) return org_inkscape_document_select_all_in_all_layers (proxy, error); } -static +//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) { @@ -576,7 +583,7 @@ inkscape_selection_box (DocumentInterface *doc, const gint IN_x, const gint IN_y return org_inkscape_document_selection_box (proxy, IN_x, IN_y, IN_x2, IN_y2, IN_replace, error); } -static +//static gboolean inkscape_selection_invert (DocumentInterface *doc, GError **error) { @@ -584,7 +591,7 @@ inkscape_selection_invert (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_invert (proxy, error); } -static +//static gboolean inkscape_selection_group (DocumentInterface *doc, GError **error) { @@ -592,7 +599,7 @@ inkscape_selection_group (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_group (proxy, error); } -static +//static gboolean inkscape_selection_ungroup (DocumentInterface *doc, GError **error) { @@ -600,7 +607,7 @@ inkscape_selection_ungroup (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_ungroup (proxy, error); } -static +//static gboolean inkscape_selection_cut (DocumentInterface *doc, GError **error) { @@ -608,7 +615,7 @@ inkscape_selection_cut (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_cut (proxy, error); } -static +//static gboolean inkscape_selection_copy (DocumentInterface *doc, GError **error) { @@ -616,7 +623,7 @@ inkscape_selection_copy (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_copy (proxy, error); } -static +//static gboolean inkscape_selection_paste (DocumentInterface *doc, GError **error) { @@ -624,7 +631,7 @@ inkscape_selection_paste (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_paste (proxy, error); } -static +//static gboolean inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error) { @@ -632,7 +639,7 @@ inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError return org_inkscape_document_selection_scale (proxy, IN_grow, error); } -static +//static gboolean inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error) { @@ -640,7 +647,7 @@ inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdoub return org_inkscape_document_selection_move (proxy, IN_x, IN_y, error); } -static +//static gboolean inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error) { @@ -648,7 +655,7 @@ inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gd return org_inkscape_document_selection_move_to (proxy, IN_x, IN_y, error); } -static +//static gboolean inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error) { @@ -656,7 +663,7 @@ inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, return org_inkscape_document_selection_move_to_layer (proxy, IN_layer, error); } -static +//static GArray * inkscape_selection_get_center (DocumentInterface *doc, GError **error) { @@ -666,7 +673,7 @@ inkscape_selection_get_center (DocumentInterface *doc, GError **error) return OUT_centerpoint; } -static +//static gboolean inkscape_selection_to_path (DocumentInterface *doc, GError **error) { @@ -674,7 +681,7 @@ inkscape_selection_to_path (DocumentInterface *doc, GError **error) return org_inkscape_document_selection_to_path (proxy, error); } -static +//static char * inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error) { @@ -684,7 +691,7 @@ inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError return OUT_newpath; } -static +//static char ** inkscape_selection_divide (DocumentInterface *doc, GError **error) { @@ -694,7 +701,7 @@ inkscape_selection_divide (DocumentInterface *doc, GError **error) return OUT_pieces; } -static +//static gboolean inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error) { @@ -704,7 +711,7 @@ inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command return OUT_objectsmoved; } -static +//static char * inkscape_layer_new (DocumentInterface *doc, GError **error) { @@ -714,7 +721,7 @@ inkscape_layer_new (DocumentInterface *doc, GError **error) return OUT_layername; } -static +//static gboolean inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error) { @@ -722,7 +729,7 @@ inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **erro return org_inkscape_document_layer_set (proxy, IN_layer, error); } -static +//static char ** inkscape_layer_get_all (DocumentInterface *doc, GError **error) { @@ -732,7 +739,7 @@ inkscape_layer_get_all (DocumentInterface *doc, GError **error) return OUT_layers; } -static +//static gboolean inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error) { @@ -742,7 +749,7 @@ inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GE return OUT_layermoved; } -static +//static gboolean inkscape_layer_next (DocumentInterface *doc, GError **error) { @@ -750,7 +757,7 @@ inkscape_layer_next (DocumentInterface *doc, GError **error) return org_inkscape_document_layer_next (proxy, error); } -static +//static gboolean inkscape_layer_previous (DocumentInterface *doc, GError **error) { diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h index c48a712b4..c314bf6f8 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.h @@ -4,8 +4,6 @@ #include #include -#include - //#include "document-client-glue-mod.h" //#include @@ -25,10 +23,7 @@ G_BEGIN_DECLS typedef struct _DocumentInterface DocumentInterface; typedef struct _DocumentInterfaceClass DocumentInterfaceClass; -struct _DocumentInterface { - GObject parent; - DBusGProxy * proxy; -}; +struct _DocumentInterface; struct _DocumentInterfaceClass { GObjectClass parent; @@ -40,305 +35,307 @@ GType document_interface_get_type (void); -DocumentInterface * inkscape_desktop_init_dbus (); -static +DocumentInterface * +inkscape_desktop_init_dbus (); + +//static gboolean inkscape_delete_all (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_call_verb (DocumentInterface *doc, const char * IN_verbid, GError **error); -static +//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 +//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 +//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 +//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 +//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 +//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 +//static gboolean inkscape_text (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error); -static +//static char * inkscape_image (DocumentInterface *doc, const gint IN_x, const gint IN_y, const char * IN_text, GError **error); -static +//static char * inkscape_node (DocumentInterface *doc, const char * IN_svgtype, GError **error); -static +//static gdouble inkscape_document_get_width (DocumentInterface *doc, GError **error); -static +//static gdouble inkscape_document_get_height (DocumentInterface *doc, GError **error); -static +//static char * inkscape_document_get_css (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_document_set_css (DocumentInterface *doc, const char * IN_stylestring, GError **error); -static +//static gboolean inkscape_document_merge_css (DocumentInterface *doc, const char * IN_stylestring, GError **error); -static +//static gboolean inkscape_document_resize_to_fit_selection (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_set_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const char * IN_newval, GError **error); -static +//static gboolean inkscape_set_int_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gint IN_newval, GError **error); -static +//static gboolean inkscape_set_double_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, const gdouble IN_newval, GError **error); -static +//static char * inkscape_get_attribute (DocumentInterface *doc, const char * IN_shape, const char * IN_attribute, GError **error); -static +//static gboolean inkscape_move (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error); -static +//static gboolean inkscape_move_to (DocumentInterface *doc, const char * IN_shape, const gdouble IN_x, const gdouble IN_y, GError **error); -static +//static gboolean inkscape_object_to_path (DocumentInterface *doc, const char * IN_objectname, GError **error); -static +//static char * inkscape_get_path (DocumentInterface *doc, const char * IN_shape, GError **error); -static +//static gboolean inkscape_transform (DocumentInterface *doc, const char * IN_shape, const char * IN_transformstr, GError **error); -static +//static char * inkscape_get_css (DocumentInterface *doc, const char * IN_shape, GError **error); -static +//static gboolean inkscape_modify_css (DocumentInterface *doc, const char * IN_shape, const char * IN_cssattrib, const char * IN_newval, GError **error); -static +//static gboolean inkscape_inkscape_merge_css (DocumentInterface *doc, const char * IN_shape, const char * IN_stylestring, GError **error); -static +//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 +//static gboolean inkscape_move_to_layer (DocumentInterface *doc, const char * IN_objectname, const char * IN_layername, GError **error); -static +//static GArray* inkscape_get_node_coordinates (DocumentInterface *doc, const char * IN_shape, GError **error); -static +//static gboolean inkscape_save (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_save_as (DocumentInterface *doc, const char * IN_pathname, GError **error); -static +//static gboolean inkscape_load (DocumentInterface *doc, const char * IN_pathname, GError **error); -static +//static gboolean inkscape_mark_as_unmodified (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_close (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_inkscape_exit (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_undo (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_redo (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_pause_updates (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_resume_updates (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_update (DocumentInterface *doc, GError **error); -static +//static char ** inkscape_selection_get (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_add (DocumentInterface *doc, const char * IN_name, GError **error); -static +//static gboolean inkscape_selection_add_list (DocumentInterface *doc, const char ** IN_name, GError **error); -static +//static gboolean inkscape_selection_set (DocumentInterface *doc, const char * IN_name, GError **error); -static +//static gboolean inkscape_selection_set_list (DocumentInterface *doc, const char ** IN_name, GError **error); -static +//static gboolean inkscape_selection_rotate (DocumentInterface *doc, const gint IN_angle, GError **error); -static +//static gboolean inkscape_selection_delete (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_clear (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_select_all (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_select_all_in_all_layers (DocumentInterface *doc, GError **error); -static +//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 +//static gboolean inkscape_selection_invert (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_group (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_ungroup (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_cut (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_copy (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_paste (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_scale (DocumentInterface *doc, const gdouble IN_grow, GError **error); -static +//static gboolean inkscape_selection_move (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error); -static +//static gboolean inkscape_selection_move_to (DocumentInterface *doc, const gdouble IN_x, const gdouble IN_y, GError **error); -static +//static gboolean inkscape_selection_move_to_layer (DocumentInterface *doc, const char * IN_layer, GError **error); -static +//static GArray * inkscape_selection_get_center (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_to_path (DocumentInterface *doc, GError **error); -static +//static char * inkscape_selection_combine (DocumentInterface *doc, const char * IN_type, GError **error); -static +//static char ** inkscape_selection_divide (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_selection_change_level (DocumentInterface *doc, const char * IN_command, GError **error); -static +//static char * inkscape_layer_new (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_layer_set (DocumentInterface *doc, const char * IN_layer, GError **error); -static +//static char ** inkscape_layer_get_all (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_layer_change_level (DocumentInterface *doc, const char * IN_command, GError **error); -static +//static gboolean inkscape_layer_next (DocumentInterface *doc, GError **error); -static +//static gboolean inkscape_layer_previous (DocumentInterface *doc, GError **error); -- cgit v1.2.3 From babbc935015ef0e1bce562b22bb771e8aba8a784 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 13 Aug 2009 20:57:14 +0000 Subject: Added file with some current issues listed for coders. (bzr r8254.1.25) --- src/extension/dbus/Notes.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/extension/dbus/Notes.txt diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt new file mode 100644 index 000000000..d91dc4039 --- /dev/null +++ b/src/extension/dbus/Notes.txt @@ -0,0 +1,35 @@ +BUGS: + *Inkscape crashes if widow is closed while code is running, + need better error handling. + + *Pause updates needs work. + + *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 retrive objects by name. + Switch to GQuark codes for object retrival? + + *Rethink how often activate_desktop needs to be called. + + + +FEATURES: + *Find out more about extension API. + *API compatibility for plugins? + +CLEANUP: + + + + -- cgit v1.2.3 From 3237876b9543c6ec900089dd0ffbd9e0a0bedfa3 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 13 Aug 2009 21:30:21 +0000 Subject: Added an intro to coders interested in modifing the code. (bzr r8254.1.26) --- src/extension/dbus/Notes.txt | 49 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt index d91dc4039..95b07a958 100644 --- a/src/extension/dbus/Notes.txt +++ b/src/extension/dbus/Notes.txt @@ -1,3 +1,47 @@ +INTRO: +For people that are interested in improving the DBus API here is a +intro to how everything is layed 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 relevent 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. Needs work. + +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 th documentation, +it also includes the introduction. + +doc/inkscapeDbusTerms.xml: This containes 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 seperate 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. @@ -15,14 +59,15 @@ BUGS: *The following do not behave like the documentation: -document_interface_transform -document_interface_text + + *Service file should point to wherever the inkscape executable + was placed. EFFICIENCY: *Need better way to retrive objects by name. Switch to GQuark codes for object retrival? *Rethink how often activate_desktop needs to be called. - - FEATURES: *Find out more about extension API. -- cgit v1.2.3 From 28c0df8446a7442667b2a2a938f544f5508ef0a0 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sat, 15 Aug 2009 18:26:08 +0000 Subject: Added proposed interface file. Fixed other xml files to have xml file declaration before comments. (bzr r8254.1.27) --- src/extension/dbus/application-interface.xml | 3 +- src/extension/dbus/document-interface.xml | 3 +- src/extension/dbus/proposed-interface.xml | 176 +++++++++++++++++++++++++++ 3 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 src/extension/dbus/proposed-interface.xml diff --git a/src/extension/dbus/application-interface.xml b/src/extension/dbus/application-interface.xml index e942117d6..ee2c4837b 100644 --- a/src/extension/dbus/application-interface.xml +++ b/src/extension/dbus/application-interface.xml @@ -1,3 +1,4 @@ + - - diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 2f1549488..8b0252765 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -1,3 +1,4 @@ + - + diff --git a/src/extension/dbus/proposed-interface.xml b/src/extension/dbus/proposed-interface.xml new file mode 100644 index 000000000..e82e433b4 --- /dev/null +++ b/src/extension/dbus/proposed-interface.xml @@ -0,0 +1,176 @@ + + + + + + + + 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. + + + + + + + + The id of the object. + + + + + Emitted when an object has been resized. + + + + + + + + The id of the object. + + + + + Emitted when an object has been moved. + + + + + + + + The id of the object. + + + + + Emitted when the style of an object has been changed. + + + + + + + + The id of the object. + + + + + Emitted when an object has been created. Possibly useful for working in conjunction with a live user. + + + + + + + + The id of the object. + + + + + Emitted when an object has been added to the selection. Possibly useful for working in conjunction with a live user. + + + + + + + + The x value to begin the path. + + + + + The y value to begin the path. + + + + + Begins a new path, extra nodes can be added with path_append(). + + + + + + + + The name of the path to append to. + + + + + A single letter denoting what type of node is beeing appended. + + + + + An array of numbers that describe the position and attributes of the path node. + + + + + Adds to an existing path. Close the path by sending "z" and no arguments. + You can no longer append to a path if it is closed. + + + + + + + + + + Any node with an "id" attribute. + + + + + + The id of this nodes parent, NULL if toplevel. + + + + + Returns the parent of any node. This function along with get_children() 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. + + + + + + + + Any node with an "id" attribute. + + + + + + The ids of this nodes children, NULL if bottom level. + + + + + Returns the children of any node. This function along with get_parent() 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. + + + + + + + + A object to remove from the selection. + + + + + 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. + + + + + + -- cgit v1.2.3 From 4335cee54fa4f142babf3d764e72feae9485b10a Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sat, 15 Aug 2009 18:29:16 +0000 Subject: Added copyright info to proposed interface. (bzr r8254.1.28) --- src/extension/dbus/proposed-interface.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/extension/dbus/proposed-interface.xml b/src/extension/dbus/proposed-interface.xml index e82e433b4..c281aff96 100644 --- a/src/extension/dbus/proposed-interface.xml +++ b/src/extension/dbus/proposed-interface.xml @@ -1,4 +1,19 @@ + -- cgit v1.2.3 From e28a44a795264136f7bd26e0f8926ed49b53473f Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sat, 15 Aug 2009 18:31:06 +0000 Subject: Fixed service file! Service file will now point to $(prefix) of most recently installed inkscape. (bzr r8254.1.29) --- src/extension/dbus/Makefile_insert | 2 +- src/extension/dbus/org.inkscape.service.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index a10dcdeba..00dba3b20 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -36,5 +36,5 @@ 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@|$(bindir)|" $<> $@ #Fix bindir + @sed -e "s|bindir|$(prefix)|" $<> $@ diff --git a/src/extension/dbus/org.inkscape.service.in b/src/extension/dbus/org.inkscape.service.in index 60d5b6b43..dcfff2ff2 100644 --- a/src/extension/dbus/org.inkscape.service.in +++ b/src/extension/dbus/org.inkscape.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.inkscape -Exec=/usr/local/bin/inkscape +Exec=bindir/inkscape -- cgit v1.2.3 From 1617fe112eeaa0c2a0e1b861b53bb956df379e9b Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Sat, 15 Aug 2009 19:24:51 +0000 Subject: Updated notes. (bzr r8254.1.30) --- src/extension/dbus/Notes.txt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt index 95b07a958..25c3f35b5 100644 --- a/src/extension/dbus/Notes.txt +++ b/src/extension/dbus/Notes.txt @@ -1,11 +1,11 @@ INTRO: For people that are interested in improving the DBus API here is a -intro to how everything is layed out. +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 relevent files: +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. @@ -20,7 +20,7 @@ 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. Needs work. +if it is not running when someone tries to connect. pytester.py: A python script that tests a lot of dbus functions. @@ -29,15 +29,15 @@ 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 th documentation, +doc/inkscapeDbusRef.xml: This is the top level file for laying out the documentation, it also includes the introduction. -doc/inkscapeDbusTerms.xml: This containes the terms sections of the documentation. +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 seperate from inkscape. +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. @@ -48,6 +48,8 @@ BUGS: *Pause updates needs work. + *Default style for new shapes is occasionally strange. + *The following methods are broken: -document_interface_selection_move_to_layer @@ -59,13 +61,10 @@ BUGS: *The following do not behave like the documentation: -document_interface_transform -document_interface_text - - *Service file should point to wherever the inkscape executable - was placed. EFFICIENCY: - *Need better way to retrive objects by name. - Switch to GQuark codes for object retrival? + *Need better way to retrieve objects by name. + Switch to GQuark codes for object retrieval? *Rethink how often activate_desktop needs to be called. -- cgit v1.2.3 From a2c6f05866dff7112c551e875ce9b3760f6cdd0e Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 18:51:36 +0000 Subject: Fixed directory for inkscape executable. Now points to $(prefix)/bin/inkscape (bin added.) (bzr r8254.1.31) --- src/extension/dbus/org.inkscape.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/dbus/org.inkscape.service.in b/src/extension/dbus/org.inkscape.service.in index dcfff2ff2..484c8e516 100644 --- a/src/extension/dbus/org.inkscape.service.in +++ b/src/extension/dbus/org.inkscape.service.in @@ -1,5 +1,5 @@ [D-BUS Service] Name=org.inkscape -Exec=bindir/inkscape +Exec=bindir/bin/inkscape -- cgit v1.2.3 From f8c188ba29f18db8bf7af03ed8f80841f613bbc0 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 18:52:11 +0000 Subject: More documentation. (bzr r8254.1.32) --- src/extension/dbus/Notes.txt | 1 + src/extension/dbus/dbus-init.cpp | 16 +++++++++++++++- src/extension/dbus/dbus-init.h | 2 +- src/extension/dbus/document-interface.cpp | 1 + 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt index 25c3f35b5..d7c34aac0 100644 --- a/src/extension/dbus/Notes.txt +++ b/src/extension/dbus/Notes.txt @@ -61,6 +61,7 @@ BUGS: *The following do not behave like the documentation: -document_interface_transform -document_interface_text + -document_interface_line EFFICIENCY: *Need better way to retrieve objects by name. diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index dfd69d9fa..253d6b938 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -1,4 +1,18 @@ - +/* + * 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 + * + * Copyright (C) 2009 Soren Berg + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + #include #include "dbus-init.h" diff --git a/src/extension/dbus/dbus-init.h b/src/extension/dbus/dbus-init.h index f76483170..4b07acfb4 100644 --- a/src/extension/dbus/dbus-init.h +++ b/src/extension/dbus/dbus-init.h @@ -2,7 +2,7 @@ * Authors: * Soren Berg * - * Copyright (C) 2004 Authors + * Copyright (C) 2009 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e7af7096c..05dd2925e 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -449,6 +449,7 @@ document_interface_ellipse (DocumentInterface *object, int x, int y, return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error); } +/* FIXME: makes line but gets one endpoint wrong.*/ gchar* document_interface_line (DocumentInterface *object, int x, int y, int x2, int y2, GError **error) -- cgit v1.2.3 From aa3973adee525143989826b16d47c48c8d737cef Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 19:05:00 +0000 Subject: Fixed document_interface_line (Warning: I don't know why it works this way, it just does.) (bzr r8254.1.33) --- src/extension/dbus/Notes.txt | 1 - src/extension/dbus/document-interface.cpp | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/extension/dbus/Notes.txt b/src/extension/dbus/Notes.txt index d7c34aac0..25c3f35b5 100644 --- a/src/extension/dbus/Notes.txt +++ b/src/extension/dbus/Notes.txt @@ -61,7 +61,6 @@ BUGS: *The following do not behave like the documentation: -document_interface_transform -document_interface_text - -document_interface_line EFFICIENCY: *Need better way to retrieve objects by name. diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 05dd2925e..ff691bab6 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -449,16 +449,14 @@ document_interface_ellipse (DocumentInterface *object, int x, int y, return document_interface_ellipse_center (object, x+rx, y+ry, rx, ry, error); } -/* FIXME: makes line but gets one endpoint wrong.*/ 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; - printf("X2: %d\nY2 %d\n", x2, y2); - out << "m " << x << "," << y << " " << x2 << "," << y2; - printf ("PATH: %s\n", out.str().c_str()); + // 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"); } -- cgit v1.2.3 From 5c45322163136ff2390a441ecf95dcf2c73f01b3 Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Mon, 17 Aug 2009 19:23:12 +0000 Subject: Fixed spirals. (bzr r8254.1.34) --- src/extension/dbus/document-interface.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index ff691bab6..e2d7a41a2 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -475,7 +475,10 @@ document_interface_spiral (DocumentInterface *object, int cx, int cy, 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"); - newNode->setAttribute("style", "fill:none"); + //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; } -- cgit v1.2.3 From 581760b8e2d2dac04182afd55f44199f631788dd Mon Sep 17 00:00:00 2001 From: Soren Berg Date: Thu, 20 Aug 2009 16:51:01 +0000 Subject: Added test script I thought was already added. (bzr r8254.1.35) --- src/extension/dbus/pytester.py | 290 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 290 insertions(+) create mode 100644 src/extension/dbus/pytester.py diff --git a/src/extension/dbus/pytester.py b/src/extension/dbus/pytester.py new file mode 100644 index 000000000..d4c41fb47 --- /dev/null +++ b/src/extension/dbus/pytester.py @@ -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() + -- cgit v1.2.3 From 1493fb8cfd802dd4566b933d4ad255ee64787b09 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Aug 2009 21:20:57 -0500 Subject: Add the build dir dbus directory to grab some headerfiles for distcheck. (bzr r8254.1.36) --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index 90b0be28c..e1fe86535 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,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 -- cgit v1.2.3 From 70a057a9c77a7e977bf6abe0d7029400a66cbd9e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 30 Dec 2009 23:57:49 -0600 Subject: Making BUILT_SOURCES an append (bzr r8254.1.39) --- src/Makefile.am | 2 ++ src/extension/dbus/Makefile_insert | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 3b2dfeeb6..7fa869012 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -54,6 +54,8 @@ ink_common_sources = inkscape_SOURCES = # Add Inkview-only sources here. inkview_SOURCES = +# Add sources that are built from meta files +BUILT_SOURCES = INCLUDES = \ $(PERL_CFLAGS) $(PYTHON_CFLAGS) \ diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 00dba3b20..3a8dc9ee6 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -10,7 +10,7 @@ ink_common_sources += \ ## Slightly concerned about this. ## Would use += but it has to be set first. -BUILT_SOURCES = \ +BUILT_SOURCES += \ extension/dbus/application-server-glue.h \ extension/dbus/document-server-glue.h \ extension/dbus/document-client-glue.h -- cgit v1.2.3 From f8e1a9f966ea52560102941b26c82f0710a60cd4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:07:45 -0600 Subject: Setting up a flag for local install for distcheck (bzr r8254.1.40) --- Makefile.am | 1 + configure.ac | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/Makefile.am b/Makefile.am index f07cf6979..fa9640a1d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,6 +16,7 @@ Graphics_DATA = $(Graphics_in_files:.desktop.in=.desktop) ## cp $(srcdir)/AUTHORS $(distdir) ## cp $(srcdir)/NEWS $(distdir) +DISTCHECK_CONFIGURE_FLAGS = --enable-localinstall man_MANS = inkscape.1 \ inkview.1 diff --git a/configure.ac b/configure.ac index 4db84a1d3..6d673ca0d 100644 --- a/configure.ac +++ b/configure.ac @@ -619,6 +619,14 @@ AM_CONDITIONAL(WITH_LIBWPG, test "x$with_libwpg" = "xyes") AC_SUBST(LIBWPG_LIBS) AC_SUBST(LIBWPG_CFLAGS) +dnl ****************************** +dnl Support doing a local install +dnl (mostly for distcheck) +dnl ****************************** + +with_localinstall="no" +AC_ARG_ENABLE(localinstall, AS_HELP_STRING([--enable-localinstall], [install system files in the local path (for distcheck)]), with_localinstall=$enableval, with_localinstall=no) + dnl ****************************** dnl Check for dbus functionality dnl ****************************** @@ -626,6 +634,12 @@ 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]) + if test "x$with_localinstall" = "xyes"; then + DBUSSERVICEDIR="${datadir}/dbus-1/services/" + else + DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1` + fi + AC_SUBST(DBUSSERVICEDIR) fi AM_CONDITIONAL(WITH_DBUS, test "x$with_dbus" = "xyes") @@ -1035,4 +1049,5 @@ Configuration: Enable Poppler-Cairo: ${enable_poppler_cairo} ImageMagick Magick++: ${magick_ok} Libwpg: ${with_libwpg} + Doing Local Install: ${with_localinstall} " -- cgit v1.2.3 From 36a20383a3c581ebb32087d369a18a76a195f0e1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:08:50 -0600 Subject: Installing the service files into the dbus service directory (bzr r8254.1.41) --- src/extension/dbus/Makefile_insert | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 3a8dc9ee6..8293a5e4d 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -30,7 +30,7 @@ extension/dbus/document-client-glue.h: extension/dbus/document-interface.xml # 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" +servicedir = $(DBUSSERVICEDIR) service_in_files = extension/dbus/org.inkscape.service.in service_DATA = $(service_in_files:.service.in=.service) -- cgit v1.2.3 From c84c93abfd99947d87e4f9865d4c0c43cf74c2d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:12:50 -0600 Subject: Adding dbus descriptions to EXTRA_DIST (bzr r8254.1.42) --- src/extension/dbus/Makefile_insert | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 8293a5e4d..cc363b7ce 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -25,6 +25,10 @@ extension/dbus/document-server-glue.h: extension/dbus/document-interface.xml extension/dbus/document-client-glue.h: extension/dbus/document-interface.xml dbus-binding-tool --mode=glib-client --output=$@ --prefix=document_interface $^ +EXTRA_DIST += \ + extension/dbus/application-interface.xml \ + extension/dbus/document-interface.xml + #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 -- cgit v1.2.3 From 1b5d271f226e3eeb2011d8762cc000e8a02eda1b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:23:23 -0600 Subject: Updating interface to add save type (bzr r8254.1.43) --- src/extension/dbus/document-interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index e2d7a41a2..b8b0c2ade 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -862,7 +862,7 @@ document_interface_save_as (DocumentInterface *object, try { Inkscape::Extension::save(NULL, doc, filename, - false, false, true); + false, false, true, Inkscape::Extension::FILE_SAVE_METHOD_SAVE_AS); } catch (...) { //SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("Document not saved.")); return false; -- cgit v1.2.3 From c22fb6c4e0b23c806ade6e42a8025384cc380f91 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 00:23:42 -0600 Subject: Clearing up EXTRA_DIST lifecycle (bzr r8254.1.44) --- src/Makefile.am | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 7fa869012..a064496ce 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -56,6 +56,8 @@ inkscape_SOURCES = inkview_SOURCES = # Add sources that are built from meta files BUILT_SOURCES = +# Extra files to distribute +EXTRA_DIST = INCLUDES = \ $(PERL_CFLAGS) $(PYTHON_CFLAGS) \ @@ -147,7 +149,7 @@ include trace/Makefile_insert include 2geom/Makefile_insert # Extra files not mentioned as sources to include in the source tarball -EXTRA_DIST = \ +EXTRA_DIST += \ $(top_srcdir)/Doxyfile \ sp-skeleton.cpp sp-skeleton.h \ algorithms/makefile.in \ -- cgit v1.2.3 From 56060b950f32a8227f5dd7f084a7468bd80938a4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 21:45:03 -0600 Subject: Cleaning up the Makefile so it's easier to read (bzr r8254.1.45) --- src/extension/dbus/Makefile_insert | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index cc363b7ce..65ead8c93 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -1,5 +1,9 @@ ## Makefile.am fragment sourced by src/Makefile.am. +############################# +# Sources for DBus interface +############################# + ink_common_sources += \ extension/dbus/dbus-init.cpp \ extension/dbus/dbus-init.h \ @@ -8,13 +12,9 @@ ink_common_sources += \ 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 +########################### +# Build DBus wrapper files +########################### extension/dbus/application-server-glue.h: extension/dbus/application-interface.xml dbus-binding-tool --mode=glib-server --output=$@ --prefix=application_interface $^ @@ -25,13 +25,22 @@ extension/dbus/document-server-glue.h: extension/dbus/document-interface.xml extension/dbus/document-client-glue.h: extension/dbus/document-interface.xml dbus-binding-tool --mode=glib-client --output=$@ --prefix=document_interface $^ +BUILT_SOURCES += \ + extension/dbus/application-server-glue.h \ + extension/dbus/document-server-glue.h \ + extension/dbus/document-client-glue.h + +########################### +# Distribut DBus interface +########################### + EXTRA_DIST += \ extension/dbus/application-interface.xml \ extension/dbus/document-interface.xml -#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 Activation Service +########################### # Dbus service file servicedir = $(DBUSSERVICEDIR) -- cgit v1.2.3 From e588e1f405fa74d8e14735172570f1a542513625 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 22:30:23 -0600 Subject: Adding all of the library stuff in. Including libtool in configure and libtoolize in autogen.sh (bzr r8254.1.46) --- autogen.sh | 3 ++- configure.ac | 1 + src/extension/dbus/Makefile_insert | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/autogen.sh b/autogen.sh index 6a7c6317b..eedf7f23c 100755 --- a/autogen.sh +++ b/autogen.sh @@ -152,7 +152,7 @@ test $TEST_TYPE $FILE || { if test -z "$ACLOCAL_FLAGS"; then acdir=`$ACLOCAL --print-ac-dir` - m4list="glib-2.0.m4 glib-gettext.m4 gtk-2.0.m4 intltool.m4 pkg.m4" + m4list="glib-2.0.m4 glib-gettext.m4 gtk-2.0.m4 intltool.m4 pkg.m4 libtool.m4" for file in $m4list do @@ -179,6 +179,7 @@ attempt_command 'underquoted definition of|[\)\#]Extending' \ attempt_command '' autoheader } +attempt_command '' libtoolize attempt_command '' $AUTOMAKE --copy --force --add-missing attempt_command '' autoconf attempt_command '^(Please add the files| codeset| progtest|from the|or directly|You will also|ftp://ftp.gnu.org|$)' \ diff --git a/configure.ac b/configure.ac index 6d673ca0d..5ef78b227 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,7 @@ AM_PROG_CC_STDC AM_PROG_AS AC_PROG_RANLIB AC_PROG_INTLTOOL(0.22) +AC_PROG_LIBTOOL AC_HEADER_STDC INK_SVN_SNAPSHOT_BUILD diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 65ead8c93..aa4d17f22 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -51,3 +51,31 @@ service_DATA = $(service_in_files:.service.in=.service) $(service_DATA): $(service_in_files) Makefile @sed -e "s|bindir|$(prefix)|" $<> $@ +############################ +# DBus Interface Helper Lib +############################ + +lib_LTLIBRARIES = \ + libinkdbus.la + +libinkdbusincludedir = $(includedir)/libinkdbus-0.48/libinkdbus +libinkdbusinclude_HEADERS = \ + extension/dbus/wrapper/inkscape-dbus-wrapper.h + +libinkdbus_la_SOURCES = \ + extension/dbus/wrapper/inkscape-dbus-wrapper.h \ + extension/dbus/wrapper/inkscape-dbus-wrapper.c + +libinkdbus_la_LDFLAGS = \ + -version-info 0:0:0 \ + -no-undefined \ + -export-symbols-regex "^[^_d].*" + +libinkdbus_la_CFLAGS = \ + $(DBUS_CFLAGS) \ + $(INKSCAPE_CFLAGS) \ + -Wall -Werror + +libinkdbus_la_LIBADD = \ + $(DBUS_LIBS) \ + $(INKSCAPE_LIBS) -- cgit v1.2.3 From 8d5161054d0e7bb3c1b2172898f09aa000d2f1d9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 22:33:04 -0600 Subject: Fixing includes (bzr r8254.1.47) --- src/extension/dbus/Makefile_insert | 1 + src/extension/dbus/wrapper/inkscape-dbus-wrapper.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index aa4d17f22..35b7c6fff 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -74,6 +74,7 @@ libinkdbus_la_LDFLAGS = \ libinkdbus_la_CFLAGS = \ $(DBUS_CFLAGS) \ $(INKSCAPE_CFLAGS) \ + -I$(builddir)/extension/dbus \ -Wall -Werror libinkdbus_la_LIBADD = \ diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c index e6d2818a2..5184affdf 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c @@ -5,7 +5,7 @@ -#include "../document-client-glue.h" +#include "document-client-glue.h" #include #include -- cgit v1.2.3 From b3d2e4c24cc409f0eedba79c890aefb60f43e7da Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 31 Dec 2009 22:38:19 -0600 Subject: Fixing some warnings/errors (bzr r8254.1.48) --- src/extension/dbus/wrapper/inkscape-dbus-wrapper.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c index 5184affdf..b59ee746b 100644 --- a/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c +++ b/src/extension/dbus/wrapper/inkscape-dbus-wrapper.c @@ -34,10 +34,11 @@ dbus_get_proxy(DBusGConnection *connection) { DBUS_INTERFACE_DBUS); } +#if 0 /* PRIVATE register an object on a bus */ static gpointer dbus_register_object (DBusGConnection *connection, - DBusGProxy *proxy, + DBusGProxy * proxy, GType object_type, const DBusGObjectInfo *info, const gchar *path) @@ -47,6 +48,7 @@ dbus_register_object (DBusGConnection *connection, dbus_g_connection_register_g_object (connection, path, object); return object; } +#endif /**************************************************************************** DOCUMENT INTERFACE CLASS STUFF @@ -229,7 +231,7 @@ 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); + org_inkscape_document_document_get_width (proxy, &OUT_val, error); return OUT_val; } @@ -239,7 +241,7 @@ 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); + org_inkscape_document_document_get_height (proxy, &OUT_val, error); return OUT_val; } @@ -249,7 +251,7 @@ 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); + org_inkscape_document_document_get_css (proxy, &OUT_css, error); return OUT_css; } @@ -258,7 +260,7 @@ 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); + return org_inkscape_document_document_set_css (proxy, IN_stylestring, error); } //static @@ -266,7 +268,7 @@ 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); + return org_inkscape_document_document_merge_css (proxy, IN_stylestring, error); } //static @@ -274,7 +276,7 @@ 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); + return org_inkscape_document_document_resize_to_fit_selection (proxy, error); } //static -- cgit v1.2.3 From 915b47e2dec38c79388446548288291d4c973766 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 1 Jan 2010 00:09:50 -0600 Subject: Removing extra makefile (bzr r8254.1.50) --- src/extension/dbus/wrapper/Makefile | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 src/extension/dbus/wrapper/Makefile diff --git a/src/extension/dbus/wrapper/Makefile b/src/extension/dbus/wrapper/Makefile deleted file mode 100644 index 692f4fa19..000000000 --- a/src/extension/dbus/wrapper/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -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) - -- cgit v1.2.3 From 2b0e6573d59004745df33e309f08e70e4de79e37 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 1 Jan 2010 00:22:15 -0600 Subject: Adding in building of the pkgconfig file. (bzr r8254.1.51) --- configure.ac | 1 + src/extension/dbus/wrapper/inkdbus.pc.in | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/extension/dbus/wrapper/inkdbus.pc.in diff --git a/configure.ac b/configure.ac index 5ef78b227..e6c379d48 100644 --- a/configure.ac +++ b/configure.ac @@ -957,6 +957,7 @@ src/extension/implementation/makefile src/extension/internal/makefile src/extension/makefile src/extension/script/makefile +src/extension/dbus/wrapper/inkdbus.pc src/filters/makefile src/helper/makefile src/inkjar/makefile diff --git a/src/extension/dbus/wrapper/inkdbus.pc.in b/src/extension/dbus/wrapper/inkdbus.pc.in new file mode 100644 index 000000000..2bdfb75eb --- /dev/null +++ b/src/extension/dbus/wrapper/inkdbus.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libinkdbus-0.1 +Requires: gobject-2.0 dbus-glib-1 +Libs: -L${libdir} -linkdbus + +Name: inkdbus +Description: Inkscape DBus Interface Wrapper +Version: @VERSION@ + -- cgit v1.2.3 From 4b04615e34476d7a073df30482417e2f75f21ada Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 1 Jan 2010 00:26:17 -0600 Subject: Installing the pkgconfig file (bzr r8254.1.52) --- src/extension/dbus/Makefile_insert | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/extension/dbus/Makefile_insert b/src/extension/dbus/Makefile_insert index 35b7c6fff..ce733364c 100644 --- a/src/extension/dbus/Makefile_insert +++ b/src/extension/dbus/Makefile_insert @@ -80,3 +80,11 @@ libinkdbus_la_CFLAGS = \ libinkdbus_la_LIBADD = \ $(DBUS_LIBS) \ $(INKSCAPE_LIBS) + +############################ +# DBus Pkgconfig file +############################ + +pkgconfig_DATA = extension/dbus/wrapper/inkdbus.pc +pkgconfigdir = $(libdir)/pkgconfig + -- cgit v1.2.3 From 0a63bd1f23b49de16a693d8b01b9b419e95b7ecf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sat, 15 May 2010 13:20:53 -0500 Subject: Making an enable/disable flag for building with dbus (bzr r8254.1.55) --- configure.ac | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index a5891b4a2..3e0408b15 100644 --- a/configure.ac +++ b/configure.ac @@ -699,20 +699,27 @@ 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]) - if test "x$with_localinstall" = "xyes"; then - DBUSSERVICEDIR="${datadir}/dbus-1/services/" - else - DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1` +AC_ARG_ENABLE(dbusapi, + [ --enable-dbusapi compile with support for DBus interface], + enable_dbusapi=$enableval,enable_dbusapi=yes) +AC_DEFINE(WITH_DBUS,1,[Build in dbus]) + +if test "x$dbusapi" = "xyes"; then + PKG_CHECK_MODULES(DBUS, dbus-glib-1, with_dbus=yes, with_dbus=no) + if test "x$with_dbus" = "xyes"; then + if test "x$with_localinstall" = "xyes"; then + DBUSSERVICEDIR="${datadir}/dbus-1/services/" + else + DBUSSERVICEDIR=`$PKG_CONFIG --variable=session_bus_services_dir dbus-1` + fi + AC_SUBST(DBUSSERVICEDIR) fi - AC_SUBST(DBUSSERVICEDIR) + + AC_SUBST(DBUS_LIBS) + AC_SUBST(DBUS_CFLAGS) fi -AM_CONDITIONAL(WITH_DBUS, test "x$with_dbus" = "xyes") -AC_SUBST(DBUS_LIBS) -AC_SUBST(DBUS_CFLAGS) +AM_CONDITIONAL(WITH_DBUS, test "x$with_dbus" = "xyes") dnl ****************************** dnl Check for ImageMagick Magick++ -- cgit v1.2.3