From 09ce234c1fc367a2607936e6cf106cb24c60e94f Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 3 Jul 2013 20:06:11 +0100 Subject: Modified dbus interface so that it works in console mode (--dbus-listen) Modified action context setup so that in console mode, when a document is added to the main inkscape app instance, it gets a selection model and layer model automatically set up for it Made a couple more verbs work in console mode (bzr r12387.1.4) --- src/extension/dbus/dbus-init.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 9ff6897e5..96d72c0f6 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -108,7 +108,11 @@ init_document (void) { doc = SPDocument::createNewDoc(NULL, 1, TRUE); std::string name("/org/inkscape/"); - name.append(doc->getName()); + // This only works because a new document's name happens to contain + // only valid DBus characters [A-Z][a-z][0-9]_ + // TODO: use the document->serial() instead, like below, and similar to + // how desktops work? + name.append(doc->getName()); std::replace(name.begin(), name.end(), ' ', '_'); connection = dbus_get_connection(); @@ -122,6 +126,38 @@ init_document (void) { return strdup(name.c_str()); } //init_document +gchar * +init_active_document() +{ + SPDocument *doc = inkscape_active_document(); + if (!doc) { + return NULL; + } + + // Document name is not suitable for DBus name, as it might contain invalid chars + std::string name("/org/inkscape/document_"); + std::stringstream ss; + ss << doc->serial(); + name.append(ss.str()); + + DBusGConnection *connection = dbus_get_connection(); + DBusGProxy *proxy = dbus_get_proxy(connection); + + // Has the active document already been registered? + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + // No - register it + DocumentInterface *obj = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + obj->context = inkscape_active_action_context(); + } + return strdup(name.c_str()); +} + gchar * dbus_init_desktop_interface (SPDesktop * dt) { @@ -142,7 +178,7 @@ dbus_init_desktop_interface (SPDesktop * dt) obj = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->desk = dt; + obj->context = Inkscape::ActionContext(dt); obj->updates = TRUE; dt->dbus_document_interface=obj; return strdup(name.c_str()); -- cgit v1.2.3 From 104efe4e3ecadc975ab76748c66f041abf8ee7b1 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 15:01:44 +0100 Subject: Code readability improvements and licence changes for action-context.* based on merge request code review and feedback (bzr r12387.1.7) --- src/extension/dbus/dbus-init.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index 96d72c0f6..fe59fc154 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -153,7 +153,7 @@ init_active_document() name.c_str()); // Set the document info for this interface - obj->context = inkscape_active_action_context(); + obj->doc_context = inkscape_active_action_context(); } return strdup(name.c_str()); } @@ -178,7 +178,7 @@ dbus_init_desktop_interface (SPDesktop * dt) obj = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->context = Inkscape::ActionContext(dt); + obj->doc_context = Inkscape::ActionContext(dt); obj->updates = TRUE; dt->dbus_document_interface=obj; return strdup(name.c_str()); -- cgit v1.2.3 From 036013caefc09f34ef9b418e1ca148a821c777d6 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 23:51:56 +0100 Subject: Further renaming of DBus variables (object -> app_interface/doc_interface and doc_context -> target) Fixes to application interface for document_new (now only works in console mode, and behaves as expected) (bzr r12387.1.8) --- src/extension/dbus/dbus-init.cpp | 107 ++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 53 deletions(-) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index fe59fc154..eb62f4b3a 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -78,6 +78,44 @@ dbus_register_object (DBusGConnection *connection, return object; } +/* + * PRIVATE register a document interface for the document in the given ActionContext, if none exists. + * Return the DBus path to the interface (something like /org/inkscape/document_0). + * Note that while a DocumentInterface could be used either for a document with no desktop, or a + * document with a desktop, this function is only used for creating interfaces in the former case. + * Desktop-associated DocumentInterfaces are named /org/inkscape/desktop_0, etc. + * FIXME: This state of affairs probably needs tidying up at some point in the future. + */ +static gchar * +dbus_register_document(Inkscape::ActionContext const & target) +{ + SPDocument *doc = target.getDocument(); + g_assert(doc != NULL); + + // Document name is not suitable for DBus name, as it might contain invalid chars + std::string name("/org/inkscape/document_"); + std::stringstream ss; + ss << doc->serial(); + name.append(ss.str()); + + DBusGConnection *connection = dbus_get_connection(); + DBusGProxy *proxy = dbus_get_proxy(connection); + + // Has the document already been registered? + if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { + // No - register it + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, + proxy, + TYPE_DOCUMENT_INTERFACE, + &dbus_glib_document_interface_object_info, + name.c_str()); + + // Set the document info for this interface + doc_interface->target = target; + } + return strdup(name.c_str()); +} + /* Initialize a Dbus service */ void init (void) @@ -97,34 +135,19 @@ init (void) TYPE_APPLICATION_INTERFACE, &dbus_glib_application_interface_object_info, DBUS_APPLICATION_INTERFACE_PATH); -} //init +} gchar * -init_document (void) { - DBusGConnection *connection; - DBusGProxy *proxy; - SPDocument *doc; - - doc = SPDocument::createNewDoc(NULL, 1, TRUE); - - std::string name("/org/inkscape/"); - // This only works because a new document's name happens to contain - // only valid DBus characters [A-Z][a-z][0-9]_ - // TODO: use the document->serial() instead, like below, and similar to - // how desktops work? - name.append(doc->getName()); - std::replace(name.begin(), name.end(), ' ', '_'); - - connection = dbus_get_connection(); - proxy = dbus_get_proxy(connection); +init_document (void) +{ + // This is for command-line use only + g_assert(!inkscape_use_gui()); - dbus_register_object (connection, - proxy, - TYPE_DOCUMENT_INTERFACE, - &dbus_glib_document_interface_object_info, - name.c_str()); - return strdup(name.c_str()); -} //init_document + // Create a blank document and get its selection model etc in an ActionContext + SPDocument *doc = SPDocument::createNewDoc(NULL, 1, TRUE); + inkscape_add_document(doc); + return dbus_register_document(inkscape_action_context_for_document(doc)); +} gchar * init_active_document() @@ -134,28 +157,7 @@ init_active_document() return NULL; } - // Document name is not suitable for DBus name, as it might contain invalid chars - std::string name("/org/inkscape/document_"); - std::stringstream ss; - ss << doc->serial(); - name.append(ss.str()); - - DBusGConnection *connection = dbus_get_connection(); - DBusGProxy *proxy = dbus_get_proxy(connection); - - // Has the active document already been registered? - if (!dbus_g_connection_lookup_g_object(connection, name.c_str())) { - // No - register it - DocumentInterface *obj = (DocumentInterface*) dbus_register_object (connection, - proxy, - TYPE_DOCUMENT_INTERFACE, - &dbus_glib_document_interface_object_info, - name.c_str()); - - // Set the document info for this interface - obj->doc_context = inkscape_active_action_context(); - } - return strdup(name.c_str()); + return dbus_register_document(inkscape_active_action_context()); } gchar * @@ -163,7 +165,6 @@ dbus_init_desktop_interface (SPDesktop * dt) { DBusGConnection *connection; DBusGProxy *proxy; - DocumentInterface *obj; std::string name("/org/inkscape/desktop_"); std::stringstream out; @@ -175,12 +176,12 @@ dbus_init_desktop_interface (SPDesktop * dt) connection = dbus_get_connection(); proxy = dbus_get_proxy(connection); - obj = (DocumentInterface*) dbus_register_object (connection, + DocumentInterface *doc_interface = (DocumentInterface*) dbus_register_object (connection, proxy, TYPE_DOCUMENT_INTERFACE, &dbus_glib_document_interface_object_info, name.c_str()); - obj->doc_context = Inkscape::ActionContext(dt); - obj->updates = TRUE; - dt->dbus_document_interface=obj; + doc_interface->target = Inkscape::ActionContext(dt); + doc_interface->updates = TRUE; + dt->dbus_document_interface=doc_interface; return strdup(name.c_str()); } @@ -195,7 +196,7 @@ init_desktop (void) { out << dt->dkey; name.append(out.str()); return strdup(name.c_str()); -} //init_desktop +} -- cgit v1.2.3 From bea3d29ac007d6c8faca786538fafb0d7d789ffc Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Wed, 10 Jul 2013 11:50:45 +0100 Subject: Added "dbus-name" command line option to allow a D-Bus bus name other than "org.inkscape" to be specified. This allows multiple Inkscape instances to be controlled over D-Bus in a single user session. (bzr r12402.1.1) --- src/extension/dbus/dbus-init.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/extension/dbus/dbus-init.cpp') diff --git a/src/extension/dbus/dbus-init.cpp b/src/extension/dbus/dbus-init.cpp index eb62f4b3a..19b48e10d 100644 --- a/src/extension/dbus/dbus-init.cpp +++ b/src/extension/dbus/dbus-init.cpp @@ -36,7 +36,14 @@ #include - +namespace +{ + // This stores the bus name to use for this app instance. By default, it + // will be set to org.inkscape. However, users may provide other names by + // setting command-line parameters when starting Inkscape, so that more + // than one instance of Inkscape may be used by external scripts. + gchar *instance_bus_name = NULL; +} namespace Inkscape { namespace Extension { @@ -120,6 +127,11 @@ dbus_register_document(Inkscape::ActionContext const & target) void init (void) { + if (instance_bus_name == NULL) { + // Set the bus name to the default + instance_bus_name = strdup("org.inkscape"); + } + guint result; GError *error = NULL; DBusGConnection *connection; @@ -127,7 +139,7 @@ init (void) connection = dbus_get_connection(); proxy = dbus_get_proxy(connection); org_freedesktop_DBus_request_name (proxy, - "org.inkscape", + instance_bus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error); //create interface for application dbus_register_object (connection, @@ -198,6 +210,19 @@ init_desktop (void) { return strdup(name.c_str()); } +void +dbus_set_bus_name(gchar * bus_name) +{ + g_assert(bus_name != NULL); + g_assert(instance_bus_name == NULL); + instance_bus_name = strdup(bus_name); +} +gchar * +dbus_get_bus_name() +{ + g_assert(instance_bus_name != NULL); + return instance_bus_name; +} } } } /* namespace Inkscape::Extension::Dbus */ -- cgit v1.2.3