diff options
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp index 49ef33fc9..630411dde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,6 +169,9 @@ enum { SP_ARG_SHELL, SP_ARG_VERSION, SP_ARG_VACUUM_DEFS, +#ifdef WITH_DBUS + SP_ARG_DBUS_LISTEN, +#endif // WITH_DBUS SP_ARG_VERB_LIST, SP_ARG_VERB, SP_ARG_SELECT, @@ -222,7 +225,9 @@ 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; +#endif // WITH_DBUS static gchar *sp_export_png_utf8 = NULL; static gchar *sp_export_svg_utf8 = NULL; static gchar *sp_global_printer_utf8 = NULL; @@ -267,6 +272,9 @@ static void resetCommandlineGlobals() { sp_query_all = FALSE; sp_query_id = NULL; sp_vacuum_defs = FALSE; +#ifdef WITH_DBUS + sp_dbus_listen = FALSE; +#endif // WITH_DBUS sp_export_png_utf8 = NULL; sp_export_svg_utf8 = NULL; @@ -473,6 +481,13 @@ 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}, +#endif // WITH_DBUS {"verb-list", 0, POPT_ARG_NONE, NULL, SP_ARG_VERB_LIST, @@ -731,6 +746,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") ) { @@ -1038,6 +1056,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; @@ -1070,17 +1099,17 @@ static int sp_process_file_list(GSList *fl) doc->vacuumDocument(); } - bool has_performed_actions = false; - { - // Create layer model and selection model so we can run some verbs without a GUI - Inkscape::LayerModel layer_model; - layer_model.setDocument(doc); - Inkscape::Selection *selection = Inkscape::GC::release(new Inkscape::Selection(&layer_model, NULL)); - - // Execute command-line actions (selections and verbs) using our local models - Inkscape::ActionContext context(selection); - has_performed_actions = Inkscape::CmdLineAction::doList(context); + // 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 @@ -1248,7 +1277,7 @@ 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 && !sp_dbus_listen) { g_print("Nothing to do!\n"); exit(0); } |
