From cf0c689f665675b976215e80ec7c9acf1b2e49e6 Mon Sep 17 00:00:00 2001 From: Nicolas Dufour Date: Sun, 21 Aug 2011 09:42:08 +0200 Subject: DBUS. Merging lp:~joakim-verona/inkscape/dbus-fixes changes. (bzr r10559) --- src/desktop.h | 3 +- src/extension/dbus/dbus-init.cpp | 2 +- src/extension/dbus/document-interface.cpp | 181 +++++++++++++++++++++++++++++- src/extension/dbus/document-interface.h | 26 +++++ src/extension/dbus/document-interface.xml | 163 ++++++++++++++++++++++++++- src/extension/dbus/proposed-interface.xml | 50 --------- src/file.cpp | 6 +- src/file.h | 2 +- src/select-context.cpp | 8 ++ 9 files changed, 381 insertions(+), 60 deletions(-) (limited to 'src') 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 - +#include #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 +#include + +#if 0 +#include +#include +#include +#include +#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 @@ + + + + The path to a valid svg file. + + + + + + The name of the new image. + + + + + Imports the file at pathname. Similar to the image + method. + + + + + @@ -453,6 +474,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Set display area. + + + + + + + + Get display area. + + + + + + area + + + + + @@ -499,6 +570,43 @@ + + + + The id of an object. + + + + + + start text pos. + + + + + end text pos. + + + + + + css attribute. + + + + + + css attribute value. + + + + + + + set styling of partial text object. + + + @@ -864,6 +972,9 @@ + + + + + + + The id of the object. + + + + + Emitted when an object has been moved. + + + + + + + + + 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. + + + + + + + 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. + + + - + 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 @@ - - - - The id of the object. - - - - - Emitted when an object has been moved. - - - - @@ -136,43 +123,6 @@ - - - - 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. - - - 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()) { -- cgit v1.2.3