diff options
| author | su_v <suv-sf@users.sourceforge.net> | 2013-08-29 21:06:10 +0000 |
|---|---|---|
| committer | ~suv <suv-sf@users.sourceforge.net> | 2013-08-29 21:06:10 +0000 |
| commit | 4d331e73a76dce7d703716093923ca01b3cc5936 (patch) | |
| tree | b444657ba269b25f60684e66858a138b74fe240d /src/main.cpp | |
| parent | Fix compiler warnings (diff) | |
| parent | Updating outdated test. Fixes bug #1202271. (diff) | |
| download | inkscape-4d331e73a76dce7d703716093923ca01b3cc5936.tar.gz inkscape-4d331e73a76dce7d703716093923ca01b3cc5936.zip | |
merge from trunk (r12487)
(bzr r11668.1.75)
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp index 19ea3f181..29f431aa8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,13 +60,14 @@ #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" #include "color.h" #include "sp-item.h" #include "sp-root.h" -#include "unit-constants.h" #include "svg/svg.h" #include "svg/svg-color.h" @@ -85,6 +86,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 +102,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 +173,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 +230,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 +278,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 +488,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 +758,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 +897,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 +1075,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 +1117,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); } @@ -1218,12 +1282,15 @@ int sp_main_console(int argc, char const **argv) { /* We are started in text mode */ +#if !GLIB_CHECK_VERSION(2,36,0) /* Do this g_type_init(), so that we can use Xft/Freetype2 (Pango) * in a non-Gtk environment. Used in libnrtype's * FontInstance.cpp and FontFactory.cpp. * http://mail.gnome.org/archives/gtk-list/2003-December/msg00063.html */ g_type_init(); +#endif + char **argv2 = const_cast<char **>(argv); gtk_init_check( &argc, &argv2 ); //setlocale(LC_ALL, ""); @@ -1232,7 +1299,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); } @@ -1452,7 +1523,7 @@ static int sp_do_export_png(SPDocument *doc) // default dpi if (dpi == 0.0) { - dpi = PX_PER_IN; + dpi = Inkscape::Util::Quantity::convert(1, "in", "px"); } unsigned long int width = 0; @@ -1465,7 +1536,7 @@ static int sp_do_export_png(SPDocument *doc) g_warning("Export width %lu out of range (1 - %lu). Nothing exported.", width, (unsigned long int)PNG_UINT_31_MAX); return 1; } - dpi = (gdouble) width * PX_PER_IN / area.width(); + dpi = (gdouble) width * Inkscape::Util::Quantity::convert(1, "in", "px") / area.width(); } if (sp_export_height) { @@ -1475,15 +1546,15 @@ static int sp_do_export_png(SPDocument *doc) g_warning("Export height %lu out of range (1 - %lu). Nothing exported.", height, (unsigned long int)PNG_UINT_31_MAX); return 1; } - dpi = (gdouble) height * PX_PER_IN / area.height(); + dpi = (gdouble) height * Inkscape::Util::Quantity::convert(1, "in", "px") / area.height(); } if (!sp_export_width) { - width = (unsigned long int) (area.width() * dpi / PX_PER_IN + 0.5); + width = (unsigned long int) (area.width() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); } if (!sp_export_height) { - height = (unsigned long int) (area.height() * dpi / PX_PER_IN + 0.5); + height = (unsigned long int) (area.height() * dpi / Inkscape::Util::Quantity::convert(1, "in", "px") + 0.5); } guint32 bgcolor = 0x00000000; |
