summaryrefslogtreecommitdiffstats
path: root/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp75
1 files changed, 72 insertions, 3 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 19ea3f181..4e2f2fd2b 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -60,6 +60,8 @@
#include "macros.h"
#include "file.h"
#include "document.h"
+#include "layer-model.h"
+#include "selection.h"
#include "sp-object.h"
#include "interface.h"
#include "print.h"
@@ -85,6 +87,7 @@
#include "debug/logger.h"
#include "debug/log-display-config.h"
+#include "helper/action-context.h"
#include "helper/png-write.h"
#include "helper/geom.h"
@@ -100,6 +103,11 @@
#endif // WIN32
#include "extension/init.h"
+// Not ideal, but there doesn't appear to be a nicer system in place for
+// passing command-line parameters to extensions before initialization...
+#ifdef WITH_DBUS
+#include "extension/dbus/dbus-init.h"
+#endif // WITH_DBUS
#include <glibmm/i18n.h>
#include <glibmm/main.h>
@@ -166,6 +174,10 @@ enum {
SP_ARG_SHELL,
SP_ARG_VERSION,
SP_ARG_VACUUM_DEFS,
+#ifdef WITH_DBUS
+ SP_ARG_DBUS_LISTEN,
+ SP_ARG_DBUS_NAME,
+#endif // WITH_DBUS
SP_ARG_VERB_LIST,
SP_ARG_VERB,
SP_ARG_SELECT,
@@ -219,7 +231,10 @@ static gboolean sp_query_all = FALSE;
static gchar *sp_query_id = NULL;
static gboolean sp_shell = FALSE;
static gboolean sp_vacuum_defs = FALSE;
-
+#ifdef WITH_DBUS
+static gboolean sp_dbus_listen = FALSE;
+static gchar *sp_dbus_name = NULL;
+#endif // WITH_DBUS
static gchar *sp_export_png_utf8 = NULL;
static gchar *sp_export_svg_utf8 = NULL;
static gchar *sp_global_printer_utf8 = NULL;
@@ -264,6 +279,10 @@ static void resetCommandlineGlobals() {
sp_query_all = FALSE;
sp_query_id = NULL;
sp_vacuum_defs = FALSE;
+#ifdef WITH_DBUS
+ sp_dbus_listen = FALSE;
+ sp_dbus_name = NULL;
+#endif // WITH_DBUS
sp_export_png_utf8 = NULL;
sp_export_svg_utf8 = NULL;
@@ -470,6 +489,18 @@ struct poptOption options[] = {
POPT_ARG_NONE, &sp_vacuum_defs, SP_ARG_VACUUM_DEFS,
N_("Remove unused definitions from the defs section(s) of the document"),
NULL},
+
+#ifdef WITH_DBUS
+ {"dbus-listen", 0,
+ POPT_ARG_NONE, &sp_dbus_listen, SP_ARG_DBUS_LISTEN,
+ N_("Enter a listening loop for D-Bus messages in console mode"),
+ NULL},
+
+ {"dbus-name", 0,
+ POPT_ARG_STRING, &sp_dbus_name, SP_ARG_DBUS_NAME,
+ N_("Specify the D-Bus bus name to listen for messages on (default is org.inkscape)"),
+ N_("BUS-NAME")},
+#endif // WITH_DBUS
{"verb-list", 0,
POPT_ARG_NONE, NULL, SP_ARG_VERB_LIST,
@@ -728,6 +759,9 @@ main(int argc, char **argv)
|| !strcmp(argv[i], "-Y")
|| !strncmp(argv[i], "--query-y", 9)
|| !strcmp(argv[i], "--vacuum-defs")
+#ifdef WITH_DBUS
+ || !strcmp(argv[i], "--dbus-listen")
+#endif // WITH_DBUS
|| !strcmp(argv[i], "--shell")
)
{
@@ -864,6 +898,13 @@ static int sp_common_main( int argc, char const **argv, GSList **flDest )
if ( sp_global_printer )
sp_global_printer_utf8 = g_strdup( sp_global_printer );
}
+
+#ifdef WITH_DBUS
+ // Before initializing extensions, we must set the DBus bus name if required
+ if (sp_dbus_name != NULL) {
+ Inkscape::Extension::Dbus::dbus_set_bus_name(sp_dbus_name);
+ }
+#endif
// Return the list if wanted, else free it up.
if ( flDest ) {
@@ -1035,6 +1076,17 @@ sp_main_gui(int argc, char const **argv)
static int sp_process_file_list(GSList *fl)
{
int retVal = 0;
+#ifdef WITH_DBUS
+ if (!fl) {
+ // If we've been asked to listen for D-Bus messages, enter a main loop here
+ // The main loop may be exited by calling "exit" on the D-Bus application interface.
+ if (sp_dbus_listen) {
+ Gtk::Main main_dbus_loop(0, NULL);
+ main_dbus_loop.run();
+ }
+ }
+#endif // WITH_DBUS
+
while (fl) {
const gchar *filename = (gchar *)fl->data;
@@ -1066,7 +1118,20 @@ static int sp_process_file_list(GSList *fl)
if (sp_vacuum_defs) {
doc->vacuumDocument();
}
- if (sp_vacuum_defs && !sp_export_svg) {
+
+ // Execute command-line actions (selections and verbs) using our local models
+ bool has_performed_actions = Inkscape::CmdLineAction::doList(inkscape_active_action_context());
+
+#ifdef WITH_DBUS
+ // If we've been asked to listen for D-Bus messages, enter a main loop here
+ // The main loop may be exited by calling "exit" on the D-Bus application interface.
+ if (sp_dbus_listen) {
+ Gtk::Main main_dbus_loop(0, NULL);
+ main_dbus_loop.run();
+ }
+#endif // WITH_DBUS
+
+ if (!sp_export_svg && (sp_vacuum_defs || has_performed_actions)) {
// save under the name given in the command line
sp_repr_save_file(doc->rdoc, filename, SP_SVG_NS_URI);
}
@@ -1232,7 +1297,11 @@ int sp_main_console(int argc, char const **argv)
int retVal = sp_common_main( argc, argv, &fl );
g_return_val_if_fail(retVal == 0, 1);
- if (fl == NULL && !sp_shell) {
+ if (fl == NULL && !sp_shell
+#ifdef WITH_DBUS
+ && !sp_dbus_listen
+#endif // WITH_DBUS
+ ) {
g_print("Nothing to do!\n");
exit(0);
}