diff options
| author | Nicolas Dufour <nicoduf@yahoo.fr> | 2011-08-21 07:42:08 +0000 |
|---|---|---|
| committer | JazzyNico <nicoduf@yahoo.fr> | 2011-08-21 07:42:08 +0000 |
| commit | cf0c689f665675b976215e80ec7c9acf1b2e49e6 (patch) | |
| tree | e354db785e6a49f4fde879d82c23f05d0c61b339 /src | |
| parent | Filters. More filters clean-up. (diff) | |
| download | inkscape-cf0c689f665675b976215e80ec7c9acf1b2e49e6.tar.gz inkscape-cf0c689f665675b976215e80ec7c9acf1b2e49e6.zip | |
DBUS. Merging lp:~joakim-verona/inkscape/dbus-fixes changes.
(bzr r10559)
Diffstat (limited to 'src')
| -rw-r--r-- | src/desktop.h | 3 | ||||
| -rw-r--r-- | src/extension/dbus/dbus-init.cpp | 2 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.cpp | 181 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.h | 26 | ||||
| -rw-r--r-- | src/extension/dbus/document-interface.xml | 163 | ||||
| -rw-r--r-- | src/extension/dbus/proposed-interface.xml | 50 | ||||
| -rw-r--r-- | src/file.cpp | 6 | ||||
| -rw-r--r-- | src/file.h | 2 | ||||
| -rw-r--r-- | src/select-context.cpp | 8 |
9 files changed, 381 insertions, 60 deletions
diff --git a/src/desktop.h b/src/desktop.h index e4b71ca59..5fd786936 100644 --- a/src/desktop.h +++ b/src/desktop.h @@ -50,6 +50,7 @@ struct SPItem; struct SPNamedView; struct SPObject; struct SPStyle; +typedef struct _DocumentInterface DocumentInterface;//struct DocumentInterface; namespace Gtk { @@ -98,7 +99,7 @@ public: SPEventContext *event_context; Inkscape::LayerManager *layer_manager; Inkscape::EventLog *event_log; - + DocumentInterface *dbus_document_interface; Inkscape::Display::TemporaryItemList *temporary_item_list; Inkscape::Display::SnapIndicator *snapindicator; diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 3e453d048..1b6baa979 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -147,7 +147,7 @@ dbus_init_desktop_interface (SPDesktop * dt) &dbus_glib_document_interface_object_info, name.c_str()); obj->desk = dt; obj->updates = TRUE; - + dt->dbus_document_interface=obj; return strdup(name.c_str()); } diff --git a/src/extension/dbus/document-interface.cpp b/src/extension/dbus/document-interface.cpp index 4e629a1a9..1e6577173 100644 --- a/src/extension/dbus/document-interface.cpp +++ b/src/extension/dbus/document-interface.cpp @@ -17,7 +17,7 @@ #include "document-interface.h" #include <string.h> - +#include <dbus/dbus-glib.h> #include "desktop-handles.h" //sp_desktop_document() #include "desktop-style.h" //sp_desktop_get_style #include "display/canvas-text.h" //text @@ -56,6 +56,25 @@ //#include "2geom/svg-path-parser.h" //get_node_coordinates +#include <glib.h> +#include <dbus/dbus-glib.h> + +#if 0 +#include <libxml/tree.h> +#include <libxml/parser.h> +#include <libxml/xpath.h> +#include <libxml/xpathInternals.h> +#endif + + enum + { + OBJECT_MOVED_SIGNAL, + LAST_SIGNAL + }; + + static guint signals[LAST_SIGNAL] = { 0 }; + + /**************************************************************************** HELPER / SHORTCUT FUNCTIONS ****************************************************************************/ @@ -280,6 +299,14 @@ document_interface_class_init (DocumentInterfaceClass *klass) GObjectClass *object_class; object_class = G_OBJECT_CLASS (klass); object_class->finalize = document_interface_finalize; + signals[OBJECT_MOVED_SIGNAL] = + g_signal_new ("object_moved", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); } static void @@ -587,6 +614,44 @@ document_interface_document_resize_to_fit_selection (DocumentInterface *object, return TRUE; } +gboolean +document_interface_document_set_display_area (DocumentInterface *object, + double x0, + double y0, + double x1, + double y1, + double border, + GError **error) +{ + object->desk->set_display_area (x0, + y0, + x1, + y1, + border, false); + return TRUE; +} + + +GArray * +document_interface_document_get_display_area (DocumentInterface *object) +{ + Geom::Rect const d = object->desk->get_display_area(); + + GArray * dArr = g_array_new (TRUE, TRUE, sizeof(double)); + + double x0 = d.min()[Geom::X]; + double y0 = d.min()[Geom::Y]; + double x1 = d.max()[Geom::X]; + double y1 = d.max()[Geom::Y]; + g_array_append_val (dArr, x0); // + g_array_append_val (dArr, y0); + g_array_append_val (dArr, x1); + g_array_append_val (dArr, y1); + return dArr; + +} + + /**************************************************************************** OBJECT FUNCTIONS ****************************************************************************/ @@ -835,6 +900,35 @@ document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text } + +gboolean +document_interface_text_apply_style (DocumentInterface *object, gchar *name, + int start_pos, int end_pos, gchar *style, gchar *styleval, + GError **error) +{ + + SPItem* text_obj=(SPItem* )get_object_by_name(object->desk, name, error); + + //void sp_te_apply_style(SPItem *text, Inkscape::Text::Layout::iterator const &start, Inkscape::Text::Layout::iterator const &end, SPCSSAttr const *css) + //TODO verify object type + if (!text_obj) + return FALSE; + Inkscape::Text::Layout const *layout = te_get_layout(text_obj); + Inkscape::Text::Layout::iterator start = layout->charIndexToIterator (start_pos); + Inkscape::Text::Layout::iterator end = layout->charIndexToIterator (end_pos); + + SPCSSAttr *css = sp_repr_css_attr_new(); + sp_repr_css_set_property(css, style, styleval); + + sp_te_apply_style(text_obj, + start, + end, + css); + return TRUE; + +} + + /**************************************************************************** FILE I/O FUNCTIONS ****************************************************************************/ @@ -861,8 +955,22 @@ gboolean document_interface_load(DocumentInterface *object, return TRUE; } -gboolean document_interface_save_as(DocumentInterface *object, - const gchar *filename, GError ** /*error*/) +gchar * +document_interface_import (DocumentInterface *object, + gchar *filename, GError **error) +{ + desktop_ensure_active (object->desk); + const Glib::ustring file(filename); + SPDocument * doc = sp_desktop_document(object->desk); + + SPObject *new_obj = NULL; + new_obj = file_import(doc, file, NULL); + return strdup(new_obj->getRepr()->attribute("id")); +} + +gboolean +document_interface_save_as (DocumentInterface *object, + const gchar *filename, GError **error) { SPDocument * doc = sp_desktop_document(object->desk); #ifdef WITH_GNOME_VFS @@ -1329,6 +1437,73 @@ document_interface_layer_previous (DocumentInterface *object, GError **error) return dbus_call_verb (object, SP_VERB_LAYER_PREV, error); } + +//////////////signals + + +DocumentInterface *fugly; +gboolean dbus_send_ping (SPDesktop* desk, SPItem *item) +{ + //DocumentInterface *obj; + g_signal_emit (desk->dbus_document_interface, signals[OBJECT_MOVED_SIGNAL], 0, item->getId()); + g_print("Ping!\n"); + return TRUE; +} + +//////////tree + + +gboolean +document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error) +{ + SPItem* parent=(SPItem* )get_object_by_name(object->desk, name, error); + + GSList const *children = parent->childList(false); + + int size = g_slist_length((GSList *) children); + + *out = g_new0 (char *, size + 1); + + int i = 0; + for (GSList const *iter = children; iter != NULL; iter = iter->next) { + (*out)[i] = g_strdup(SP_OBJECT(iter->data)->getRepr()->attribute("id")); + i++; + } + (*out)[i] = NULL; + + return TRUE; + +} + + +gchar* +document_interface_get_parent (DocumentInterface *object, char *name, GError **error) +{ + SPItem* node=(SPItem* )get_object_by_name(object->desk, name, error); + + SPObject* parent=node->parent; + + return g_strdup(parent->getRepr()->attribute("id")); + +} + +#if 0 +//just pseudo code +gboolean +document_interface_get_xpath (DocumentInterface *object, char *xpath_expression, char ***out, GError **error){ + SPDocument * doc = sp_desktop_document (object->desk); + Inkscape::XML::Document *repr = doc->getReprDoc(); + + xmlXPathObjectPtr xpathObj; + xmlXPathContextPtr xpathCtx; + xpathCtx = xmlXPathNewContext(repr);//XmlDocPtr + xpathObj = xmlXPathEvalExpression(xmlCharStrdup(xpath_expression), xpathCtx); + + //xpathresult result = xpatheval(repr, xpath_selection); + //convert resut to a string array we can return via dbus + return TRUE; +} +#endif /* Local Variables: mode:c++ diff --git a/src/extension/dbus/document-interface.h b/src/extension/dbus/document-interface.h index 0283d987e..e7e55cb7d 100644 --- a/src/extension/dbus/document-interface.h +++ b/src/extension/dbus/document-interface.h @@ -121,6 +121,10 @@ document_interface_text (DocumentInterface *object, int x, int y, gboolean document_interface_set_text (DocumentInterface *object, gchar *name, gchar *text, GError **error); +gboolean +document_interface_text_apply_style (DocumentInterface *object, gchar *name, + int start_pos, int end_pos, gchar *style, gchar *styleval, + GError **error); gchar * document_interface_image (DocumentInterface *object, int x, int y, @@ -154,6 +158,16 @@ document_interface_document_set_css (DocumentInterface *object, gboolean document_interface_document_resize_to_fit_selection (DocumentInterface *object, GError **error); +gboolean +document_interface_document_set_display_area (DocumentInterface *object, + double x0, + double y0, + double x1, + double y1, + double border, + GError **error); +GArray * +document_interface_document_get_display_area (DocumentInterface *object); /**************************************************************************** OBJECT FUNCTIONS @@ -404,6 +418,18 @@ document_interface_layer_previous (DocumentInterface *object, GError **error); DocumentInterface *document_interface_new (void); GType document_interface_get_type (void); +extern DocumentInterface *fugly; +gboolean dbus_send_ping (SPDesktop* desk, SPItem *item); + +gboolean +document_interface_get_children (DocumentInterface *object, char *name, char ***out, GError **error); + +gchar* +document_interface_get_parent (DocumentInterface *object, char *name, GError **error); + +gchar* +document_interface_import (DocumentInterface *object, + gchar *filename, GError **error); G_END_DECLS diff --git a/src/extension/dbus/document-interface.xml b/src/extension/dbus/document-interface.xml index 94f39ae7e..aeacfae44 100644 --- a/src/extension/dbus/document-interface.xml +++ b/src/extension/dbus/document-interface.xml @@ -352,6 +352,27 @@ </doc:doc> </method> + <method name="import"> + <arg type="s" name="pathname" direction="in" > + <doc:doc> + <doc:summary>The path to a valid svg file.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="object_name" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The name of the new image.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Imports the file at pathname. Similar to the image + method.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="node"> <arg type="s" name="svgtype" direction="in" > <doc:doc> @@ -453,6 +474,56 @@ </doc:doc> </method> + + + <method name="document_set_display_area"> + <arg type="d" name="x0" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y0" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="x1" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="y1" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <arg type="d" name="border" direction="in" > + <doc:doc> + <doc:summary></doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Set display area.</doc:para> + </doc:description> + </doc:doc> + </method> + + <method name="document_get_display_area"> + <doc:doc> + <doc:description> + <doc:para>Get display area.</doc:para> + </doc:description> + </doc:doc> + <arg type="ad" name="area" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value=""/> + <doc:doc> + <doc:summary>area</doc:summary> + </doc:doc> + </arg> + </method> + + <!-- OBJECT FUNCTIONS --> <method name="set_attribute"> @@ -499,6 +570,43 @@ </method> + <method name="text_apply_style"> + <arg type="s" name="shape" direction="in" > + <doc:doc> + <doc:summary>The id of an object.</doc:summary> + </doc:doc> + </arg> + + <arg type="i" name="start" direction="in" > + <doc:doc> + <doc:summary>start text pos.</doc:summary> + </doc:doc> + </arg> + <arg type="i" name="end" direction="in" > + <doc:doc> + <doc:summary>end text pos.</doc:summary> + </doc:doc> + </arg> + + <arg type="s" name="css_attrib" direction="in" > + <doc:doc> + <doc:summary>css attribute.</doc:summary> + </doc:doc> + </arg> + + <arg type="s" name="css_attrib_val" direction="in" > + <doc:doc> + <doc:summary>css attribute value.</doc:summary> + </doc:doc> + </arg> + + + <doc:doc> + <doc:description> + <doc:para>set styling of partial text object.</doc:para> + </doc:description> + </doc:doc> + </method> <method name="set_int_attribute"> @@ -864,6 +972,9 @@ </doc:description> </doc:doc> </method> + + + <!-- <method name="print_to_file" > <doc:doc> @@ -1379,6 +1490,56 @@ </doc:doc> </method> +<!-- signals --> + <signal name="ObjectMoved"> + <arg name="object_name" type="s"> + <doc:doc> + <doc:summary>The id of the object.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Emitted when an object has been moved.</doc:para> + </doc:description> + </doc:doc> + </signal> +<!-- tree --> + + <method name="get_children" > + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>Any node with an "id" attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="as" name="parentid" direction="out" > + <doc:doc> + <doc:summary>The ids of this nodes children, NULL if bottom level.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the children of any node. This function along with <doc:ref type="method" to="get_parent">get_parent()</doc:ref> can be used to navigate the XML tree. </doc:para> + </doc:description> + </doc:doc> + </method> + <method name="get_parent" > + <arg type="s" name="type" direction="in" > + <doc:doc> + <doc:summary>Any node with an "id" attribute.</doc:summary> + </doc:doc> + </arg> + <arg type="s" name="parentid" direction="out" > + <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> + <doc:doc> + <doc:summary>The id of this nodes parent, NULL if toplevel.</doc:summary> + </doc:doc> + </arg> + <doc:doc> + <doc:description> + <doc:para>Returns the parent of any node. This function along with <doc:ref type="method" to="get_children">get_children()</doc:ref> can be used to navigate the XML tree. </doc:para> + </doc:description> + </doc:doc> + </method> - </interface> +</interface> </node> diff --git a/src/extension/dbus/proposed-interface.xml b/src/extension/dbus/proposed-interface.xml index c281aff96..ac74b64f9 100644 --- a/src/extension/dbus/proposed-interface.xml +++ b/src/extension/dbus/proposed-interface.xml @@ -40,19 +40,6 @@ </doc:doc> </signal> - <signal name="ObjectMoved"> - <arg name="object_name" type="s"> - <doc:doc> - <doc:summary>The id of the object.</doc:summary> - </doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para>Emitted when an object has been moved.</doc:para> - </doc:description> - </doc:doc> - </signal> - <signal name="ObjectStyleModified"> <arg name="object_name" type="s"> <doc:doc> @@ -136,43 +123,6 @@ <!-- USE document-subset.h FILES --> - <method name="get_parent" > - <arg type="s" name="type" direction="in" > - <doc:doc> - <doc:summary>Any node with an "id" attribute.</doc:summary> - </doc:doc> - </arg> - <arg type="s" name="parentid" direction="out" > - <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> - <doc:doc> - <doc:summary>The id of this nodes parent, NULL if toplevel.</doc:summary> - </doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para>Returns the parent of any node. This function along with <doc:ref type="method" to="proposed.get_children">get_children()</doc:ref> can be used to navigate the XML tree. In proposed because I think it might confuse users who don't know about the SVG tree structure. In the main API I have de-emphasized nodes and required no knowledge of internal representation.</doc:para> - </doc:description> - </doc:doc> - </method> - - <method name="get_children" > - <arg type="s" name="type" direction="in" > - <doc:doc> - <doc:summary>Any node with an "id" attribute.</doc:summary> - </doc:doc> - </arg> - <arg type="as" name="parentid" direction="out" > - <annotation name="org.freedesktop.DBus.GLib.ReturnVal" value="error"/> - <doc:doc> - <doc:summary>The ids of this nodes children, NULL if bottom level.</doc:summary> - </doc:doc> - </arg> - <doc:doc> - <doc:description> - <doc:para>Returns the children of any node. This function along with <doc:ref type="method" to="proposed.get_parent">get_parent()</doc:ref> can be used to navigate the XML tree. In proposed because I think it might confuse users who don't know about the SVG tree structure. In the main API I have de-emphasized nodes and required no knowledge of internal representation.</doc:para> - </doc:description> - </doc:doc> - </method> <method name="selection_remove"> <arg type="s" name="name" direction="in" > diff --git a/src/file.cpp b/src/file.cpp index 43d1ddaaa..c6d43fa51 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -952,7 +952,7 @@ sp_file_save_a_copy(Gtk::Window &parentWindow, gpointer /*object*/, gpointer /*d /** * Import a resource. Called by sp_file_import() */ -void +SPObject * file_import(SPDocument *in_doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key) { @@ -1067,14 +1067,14 @@ file_import(SPDocument *in_doc, const Glib::ustring &uri, doc->doUnref(); DocumentUndo::done(in_doc, SP_VERB_FILE_IMPORT, _("Import")); - + return new_obj; } else { gchar *text = g_strdup_printf(_("Failed to load the requested file %s"), uri.c_str()); sp_ui_error_dialog(text); g_free(text); } - return; + return NULL; } diff --git a/src/file.h b/src/file.h index 0041af81f..cf3adec2b 100644 --- a/src/file.h +++ b/src/file.h @@ -129,7 +129,7 @@ void sp_file_import (Gtk::Window &parentWindow); /** * Imports a resource */ -void file_import(SPDocument *in_doc, const Glib::ustring &uri, +SPObject* file_import(SPDocument *in_doc, const Glib::ustring &uri, Inkscape::Extension::Extension *key); /*###################### diff --git a/src/select-context.cpp b/src/select-context.cpp index 143fb1ae2..1ce3ccd25 100644 --- a/src/select-context.cpp +++ b/src/select-context.cpp @@ -33,6 +33,9 @@ #include "select-context.h" #include "selection-chemistry.h" +#ifdef WITH_DBUS +#include "extension/dbus/document-interface.h" +#endif #include "desktop.h" #include "desktop-handles.h" #include "sp-root.h" @@ -47,6 +50,7 @@ using Inkscape::DocumentUndo; + static void sp_select_context_class_init(SPSelectContextClass *klass); static void sp_select_context_init(SPSelectContext *select_context); static void sp_select_context_dispose(GObject *object); @@ -622,6 +626,10 @@ sp_select_context_root_handler(SPEventContext *event_context, GdkEvent *event) // item has been moved seltrans->ungrab(); sc->moved = FALSE; +#ifdef WITH_DBUS + g_print("moved!\n");//JAVE + dbus_send_ping(desktop, sc->item); +#endif } else if (sc->item && !drag_escaped) { // item has not been moved -> simply a click, do selecting if (!selection->isEmpty()) { |
