From c5f6ddd9b268dd6b5165a2353ee1a893075da91a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 18:56:35 +0200 Subject: Inkview: Fix loading files with non-ASCII characters in filename Fixed bugs: - https://launchpad.net/bugs/488997 (bzr r15690.1.1) --- src/inkview.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index b52d69825..1848cccd3 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -31,7 +31,6 @@ #endif #include -#include #include @@ -53,6 +52,8 @@ #include "document.h" #include "svg-view.h" #include "svg-view-widget.h" + +#include "io/sys.h" #include "util/units.h" #ifdef ENABLE_NLS #include "helper/gettext.h" @@ -289,10 +290,8 @@ int main (int argc, char **argv) for(auto file : filenames) { - struct stat st; - if (stat(file.c_str(), &st) - || !S_ISREG (st.st_mode) - || (st.st_size < 64)) { + if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) + { std::cerr << "could not open file " << file << std::endl; } else { auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); -- cgit v1.2.3 From 8c9ccd06ff0c11ec7728775ebedc4247d4e41234 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 19:21:17 +0200 Subject: Inkview: Print error in correct encoding. (bzr r15690.1.2) --- src/inkview.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 1848cccd3..3cca34d6c 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -246,10 +246,8 @@ private: #ifdef WIN32 // minimal print handler (just prints the string to stdout) -void g_print_no_convert(const gchar *buf) -{ - fputs(buf, stdout); -} +void g_print_no_convert(const gchar *buf) { fputs(buf, stdout); } +void g_printerr_no_convert(const gchar *buf) { fputs(buf, stderr); } #endif int main (int argc, char **argv) @@ -258,6 +256,7 @@ int main (int argc, char **argv) // Ugly hack to make g_print emit UTF-8 encoded characters. Otherwise glib will *always* // perform character conversion to the system's ANSI code page making UTF-8 output impossible. g_set_print_handler(g_print_no_convert); + g_set_printerr_handler(g_print_no_convert); #endif #ifdef ENABLE_NLS Inkscape::initialize_gettext(); @@ -290,9 +289,8 @@ int main (int argc, char **argv) for(auto file : filenames) { - if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) - { - std::cerr << "could not open file " << file << std::endl; + if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { + g_printerr("File does not exist: %s\n", file.c_str()); } else { auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); -- cgit v1.2.3 From d6170f0d771ce86df57dc90c9c9ac4d6f8845c7d Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 21:06:24 +0200 Subject: Inkview: Put checking for valid files in separate function (bzr r15690.1.3) --- src/inkview.cpp | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 3cca34d6c..0358fe917 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -244,6 +244,29 @@ private: }; +/** get a list of valid SVG files from a list of strings */ +std::vector get_valid_files(std::vector filenames) +{ + std::vector valid_files; + + for(auto file : filenames) + { + if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { + g_printerr("File does not exist: %s\n", file.c_str()); + } else { + auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); + + if(doc) + { + /* Append to list */ + valid_files.push_back(file); + } + } + } + + return valid_files; +} + #ifdef WIN32 // minimal print handler (just prints the string to stdout) void g_print_no_convert(const gchar *buf) { fputs(buf, stdout); } @@ -285,23 +308,7 @@ int main (int argc, char **argv) exit(EXIT_FAILURE); } - std::vector valid_files; - - for(auto file : filenames) - { - if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { - g_printerr("File does not exist: %s\n", file.c_str()); - } else { - auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); - - if(doc) - { - /* Append to list */ - valid_files.push_back(file); - } - } - } - + std::vector valid_files = get_valid_files(filenames); if(valid_files.empty()) { return 1; /* none of the slides loadable */ } -- cgit v1.2.3 From 5725bbcbd308cd7341da49947484dcce7df9eeb4 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 22:40:24 +0200 Subject: Inkview: Support folders as input. All .svg and .svgz files contained in the specified folder(s) will be opened. Note: Currently this is done non-recursively, but a command line option to make this recursive could be easily added in future (see "recursive" parameter of "get_valid_files()" function). (bzr r15690.1.4) --- src/inkview.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 0358fe917..f41e36cb1 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -46,8 +46,8 @@ #include "inkgc/gc-core.h" #include "preferences.h" +#include #include -#include #include "document.h" #include "svg-view.h" @@ -245,21 +245,36 @@ private: /** get a list of valid SVG files from a list of strings */ -std::vector get_valid_files(std::vector filenames) +std::vector get_valid_files(std::vector filenames, bool recursive = false) { std::vector valid_files; for(auto file : filenames) { if (!Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_EXISTS )) { - g_printerr("File does not exist: %s\n", file.c_str()); + g_printerr("%s: %s\n", _("File or folder does not exist"), file.c_str()); } else { - auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); + if (Inkscape::IO::file_test( file.c_str(), G_FILE_TEST_IS_DIR )) { + if (recursive) { + std::vector new_filenames; + Glib::Dir directory(file); + for (auto new_file: directory) { + Glib::ustring extension = new_file.substr( new_file.find_last_of(".") + 1 ); + if (!extension.compare("svg") || !extension.compare("svgz")) { + new_filenames.push_back(Glib::build_filename(file, new_file)); + } + } + std::vector new_files = get_valid_files(new_filenames); + valid_files.insert(valid_files.end(), new_files.begin(), new_files.end()); + } + } else { + auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); - if(doc) - { - /* Append to list */ - valid_files.push_back(file); + if(doc) + { + /* Append to list */ + valid_files.push_back(file); + } } } } @@ -308,7 +323,7 @@ int main (int argc, char **argv) exit(EXIT_FAILURE); } - std::vector valid_files = get_valid_files(filenames); + std::vector valid_files = get_valid_files(filenames, true); if(valid_files.empty()) { return 1; /* none of the slides loadable */ } -- cgit v1.2.3 From 1fead914d382ed1173d8bc4941c8ed270fe95b08 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 23:01:29 +0200 Subject: Inkview: Print warning if a file failed to load. (bzr r15690.1.5) --- src/inkview.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index f41e36cb1..5ba896a40 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -269,11 +269,11 @@ std::vector get_valid_files(std::vector filenames, } } else { auto doc = SPDocument::createNewDoc(file.c_str(), TRUE, false); - - if(doc) - { + if(doc) { /* Append to list */ valid_files.push_back(file); + } else { + g_printerr("%s: %s\n", _("Could not open file"), file.c_str()); } } } -- cgit v1.2.3 From b22b1218a3b22272e5c223959272fd22bb477548 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 23:16:17 +0200 Subject: Inkview: Show number of current slide and total number of slides in title (bzr r15690.1.6) --- src/inkview.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 5ba896a40..897ecb3fb 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -93,7 +93,12 @@ public: /// Update the window title with current document name void update_title() { - set_title(_doc->getName()); + Glib::ustring title(_doc->getName()); + if (_slides.size() > 1) { + title += Glib::ustring::compose(" (%1/%2)", _current+1, _slides.size()); + } + + set_title(title); } SPSlideShow(std::vector const &slides); -- cgit v1.2.3 From b2280a117695f1205e549066f9a459b26cf89f8d Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sat, 13 May 2017 23:27:16 +0200 Subject: Inkview: Title was not updated when using controls in control window. (bzr r15690.1.7) --- src/inkview.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 897ecb3fb..f39dd4cf4 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -205,7 +205,6 @@ static int sp_svgview_main_key_press (GtkWidget */*widget*/, break; } - ss->update_title(); return TRUE; } @@ -429,6 +428,7 @@ void SPSlideShow::set_document(SPDocument *doc, reinterpret_cast(SP_VIEW_WIDGET_VIEW (_view))->setDocument (doc); _doc = doc; _current = current; + update_title(); } } -- cgit v1.2.3 From 030f2f1ebd1f776b45576079a1a4c2768553873a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 02:12:38 +0200 Subject: Inkview: Refactoring - move SPSlideShow to separate source file (bzr r15690.1.8) --- src/inkview.cpp | 330 +------------------------------------------------------- 1 file changed, 5 insertions(+), 325 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index f39dd4cf4..abb690619 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -25,188 +25,29 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include -#include - - #include -#include -#include -#include #include #include -#include - -#include "inkgc/gc-core.h" -#include "preferences.h" #include #include #include "document.h" -#include "svg-view.h" -#include "svg-view-widget.h" - -#include "io/sys.h" -#include "util/units.h" +#include "inkscape.h" +#include "preferences.h" #ifdef ENABLE_NLS #include "helper/gettext.h" #endif +#include "inkgc/gc-core.h" +#include "io/sys.h" +#include "svg-view-slideshow.h" -#include "inkscape.h" - -#include "ui/icon-names.h" - -class SPSlideShow; - -static int sp_svgview_main_delete (GtkWidget *widget, - GdkEvent *event, - struct SPSlideShow *ss); - -static int sp_svgview_main_key_press (GtkWidget *widget, - GdkEventKey *event, - struct SPSlideShow *ss); - -/** - * The main application window for the slideshow - */ -class SPSlideShow : public Gtk::ApplicationWindow { -private: - std::vector _slides; ///< List of filenames for each slide - int _current; ///< Index of the currently displayed slide - SPDocument *_doc; ///< The currently displayed slide - int _timer; - GtkWidget *_view; - Gtk::Window *_ctrlwin; ///< Window containing slideshow control buttons - -public: - /// Current state of application (full-screen or windowed) - bool is_fullscreen; - - /// Update the window title with current document name - void update_title() - { - Glib::ustring title(_doc->getName()); - if (_slides.size() > 1) { - title += Glib::ustring::compose(" (%1/%2)", _current+1, _slides.size()); - } - - set_title(title); - } - - SPSlideShow(std::vector const &slides); - - void set_timer(int timer) {_timer = timer;} - void control_show(); - void show_next(); - void show_prev(); - void goto_first(); - void goto_last(); - - static int ctrlwin_delete (GtkWidget *widget, - GdkEvent *event, - void *data); -protected: - void waiting_cursor(); - void normal_cursor(); - void set_document(SPDocument *doc, - int current); -}; - -SPSlideShow::SPSlideShow(std::vector const &slides) - : - _slides(slides), - _current(0), - _doc(SPDocument::createNewDoc(_slides[0].c_str(), true, false)), - _view(NULL), - is_fullscreen(false), - _timer(0), - _ctrlwin(NULL) -{ - update_title(); - - auto default_screen = Gdk::Screen::get_default(); - - set_default_size(MIN ((int)_doc->getWidth().value("px"), default_screen->get_width() - 64), - MIN ((int)_doc->getHeight().value("px"), default_screen->get_height() - 64)); - - g_signal_connect (G_OBJECT (gobj()), "delete_event", (GCallback) sp_svgview_main_delete, this); - g_signal_connect (G_OBJECT (gobj()), "key_press_event", (GCallback) sp_svgview_main_key_press, this); - - _doc->ensureUpToDate(); - _view = sp_svg_view_widget_new (_doc); - _doc->doUnref (); - SP_SVG_VIEW_WIDGET(_view)->setResize( false, _doc->getWidth().value("px"), _doc->getHeight().value("px") ); - gtk_widget_show (_view); - add(*Glib::wrap(_view)); - - show(); -} - - -static int sp_svgview_main_delete (GtkWidget */*widget*/, - GdkEvent */*event*/, - struct SPSlideShow */*ss*/) -{ - Gtk::Main::quit(); - return FALSE; -} - -static int sp_svgview_main_key_press (GtkWidget */*widget*/, - GdkEventKey *event, - struct SPSlideShow *ss) -{ - switch (event->keyval) { - case GDK_KEY_Up: - case GDK_KEY_Home: - ss->goto_first(); - break; - case GDK_KEY_Down: - case GDK_KEY_End: - ss->goto_last(); - break; - case GDK_KEY_F11: - if (ss->is_fullscreen) { - ss->unfullscreen(); - ss->is_fullscreen = false; - } else { - ss->fullscreen(); - ss->is_fullscreen = true; - } - break; - case GDK_KEY_Return: - ss->control_show(); - break; - case GDK_KEY_KP_Page_Down: - case GDK_KEY_Page_Down: - case GDK_KEY_Right: - case GDK_KEY_space: - ss->show_next(); - break; - case GDK_KEY_KP_Page_Up: - case GDK_KEY_Page_Up: - case GDK_KEY_Left: - case GDK_KEY_BackSpace: - ss->show_prev(); - break; - case GDK_KEY_Escape: - case GDK_KEY_q: - case GDK_KEY_Q: - Gtk::Main::quit(); - break; - default: - break; - } - - return TRUE; -} /// List of all input filenames static Glib::OptionGroup::vecustrings filenames; @@ -339,167 +180,6 @@ int main (int argc, char **argv) return 0; } -int SPSlideShow::ctrlwin_delete (GtkWidget */*widget*/, - GdkEvent */*event*/, - void *data) -{ - auto ss = reinterpret_cast(data); - if(ss->_ctrlwin) delete ss->_ctrlwin; - - ss->_ctrlwin = NULL; - return FALSE; -} - -/** - * @brief Show the control buttons (next, previous etc) for the application - */ -void SPSlideShow::control_show() -{ - if (!_ctrlwin) { - _ctrlwin = new Gtk::Window(); - _ctrlwin->set_resizable(false); - _ctrlwin->set_transient_for(*this); - g_signal_connect(G_OBJECT (_ctrlwin->gobj()), "key_press_event", (GCallback) sp_svgview_main_key_press, this); - g_signal_connect(G_OBJECT (_ctrlwin->gobj()), "delete_event", (GCallback) SPSlideShow::ctrlwin_delete, this); - auto t = Gtk::manage(new Gtk::ButtonBox()); - _ctrlwin->add(*t); - - auto btn_go_first = Gtk::manage(new Gtk::Button()); - auto img_go_first = Gtk::manage(new Gtk::Image()); - img_go_first->set_from_icon_name(INKSCAPE_ICON("go-first"), Gtk::ICON_SIZE_BUTTON); - btn_go_first->set_image(*img_go_first); - t->add(*btn_go_first); - btn_go_first->signal_clicked().connect(sigc::mem_fun(*this, &SPSlideShow::goto_first)); - - auto btn_go_prev = Gtk::manage(new Gtk::Button()); - auto img_go_prev = Gtk::manage(new Gtk::Image()); - img_go_prev->set_from_icon_name(INKSCAPE_ICON("go-previous"), Gtk::ICON_SIZE_BUTTON); - btn_go_prev->set_image(*img_go_prev); - t->add(*btn_go_prev); - btn_go_prev->signal_clicked().connect(sigc::mem_fun(*this, &SPSlideShow::show_prev)); - - auto btn_go_next = Gtk::manage(new Gtk::Button()); - auto img_go_next = Gtk::manage(new Gtk::Image()); - img_go_next->set_from_icon_name(INKSCAPE_ICON("go-next"), Gtk::ICON_SIZE_BUTTON); - btn_go_next->set_image(*img_go_next); - t->add(*btn_go_next); - btn_go_next->signal_clicked().connect(sigc::mem_fun(*this, &SPSlideShow::show_next)); - - auto btn_go_last = Gtk::manage(new Gtk::Button()); - auto img_go_last = Gtk::manage(new Gtk::Image()); - img_go_last->set_from_icon_name(INKSCAPE_ICON("go-last"), Gtk::ICON_SIZE_BUTTON); - btn_go_last->set_image(*img_go_last); - t->add(*btn_go_last); - btn_go_last->signal_clicked().connect(sigc::mem_fun(*this, &SPSlideShow::goto_last)); - - _ctrlwin->show_all(); - } else { - _ctrlwin->present(); - } -} - -void SPSlideShow::waiting_cursor() -{ - auto display = Gdk::Display::get_default(); - auto waiting = Gdk::Cursor::create(display, Gdk::WATCH); - get_window()->set_cursor(waiting); - - if (_ctrlwin) { - _ctrlwin->get_window()->set_cursor(waiting); - } - while(Gtk::Main::events_pending()) { - Gtk::Main::iteration(); - } -} - -void SPSlideShow::normal_cursor() -{ - get_window()->set_cursor(); - if (_ctrlwin) { - _ctrlwin->get_window()->set_cursor(); - } -} - -void SPSlideShow::set_document(SPDocument *doc, - int current) -{ - if (doc && doc != _doc) { - doc->ensureUpToDate(); - reinterpret_cast(SP_VIEW_WIDGET_VIEW (_view))->setDocument (doc); - _doc = doc; - _current = current; - update_title(); - } -} - -/** - * @brief Show the next file in the slideshow - */ -void SPSlideShow::show_next() -{ - waiting_cursor(); - - SPDocument *doc = NULL; - while (!doc && (_current < _slides.size() - 1)) { - doc = SPDocument::createNewDoc ((_slides[++_current]).c_str(), TRUE, false); - } - - set_document(doc, _current); - normal_cursor(); -} - -/** - * @brief Show the previous file in the slideshow - */ -void SPSlideShow::show_prev() -{ - waiting_cursor(); - - SPDocument *doc = NULL; - while (!doc && (_current > 0)) { - doc = SPDocument::createNewDoc ((_slides[--_current]).c_str(), TRUE, false); - } - - set_document(doc, _current); - normal_cursor(); -} - -/** - * @brief Switch to first slide in slideshow - */ -void SPSlideShow::goto_first() -{ - waiting_cursor(); - - SPDocument *doc = NULL; - int current = 0; - while ( !doc && (current < _slides.size() - 1)) { - doc = SPDocument::createNewDoc((_slides[current++]).c_str(), TRUE, false); - } - - set_document(doc, current - 1); - - normal_cursor(); -} - -/** - * @brief Switch to last slide in slideshow - */ -void SPSlideShow::goto_last() -{ - waiting_cursor(); - - SPDocument *doc = NULL; - int current = _slides.size() - 1; - while (!doc && (current >= 0)) { - doc = SPDocument::createNewDoc((_slides[current--]).c_str(), TRUE, false); - } - - set_document(doc, current + 1); - - normal_cursor(); -} - /* Local Variables: mode:c++ -- cgit v1.2.3 From 9607306c03378d38b9ba67b7f0120593b7820826 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 02:41:40 +0200 Subject: Inkview: Some more refactoring (bzr r15690.1.9) --- src/inkview.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index abb690619..04d223091 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -29,7 +29,6 @@ # include "config.h" #endif -#include #include #include -- cgit v1.2.3 From 8b5ac2ae58d3857d98b4e6d12b95be8430a1ca50 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 03:49:13 +0200 Subject: Inkview: Finally implement the -t or --timer option after we dragged it around for over 10 years without implementation (bzr r15690.1.10) --- src/inkview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index 04d223091..bc4782b39 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -172,8 +172,7 @@ int main (int argc, char **argv) return 1; /* none of the slides loadable */ } - SPSlideShow ss(valid_files); - ss.set_timer(timer); + SPSlideShow ss(valid_files, timer); main_instance.run(); return 0; -- cgit v1.2.3 From 556ddf2fb4dd71d9677082cc9238b1c117aa2497 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 04:59:36 +0200 Subject: Inkview: refactor InkviewOptionsGroup and other minor refactoring (bzr r15690.1.12) --- src/inkview.cpp | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index bc4782b39..b4edfa22f 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -48,11 +48,7 @@ -/// List of all input filenames -static Glib::OptionGroup::vecustrings filenames; -/// Input timer option -static int timer = 0; /** * \brief Set of command-line options for Inkview @@ -60,14 +56,17 @@ static int timer = 0; class InkviewOptionsGroup : public Glib::OptionGroup { public: - InkviewOptionsGroup() - : - Glib::OptionGroup(N_("Inkscape Options"), - N_("Default program options")), - _entry_timer(), - _entry_args() + /// List of all input filenames + Glib::OptionGroup::vecustrings filenames; + + /// Input timer option + int timer = 0; + + InkviewOptionsGroup() : Glib::OptionGroup(N_("Inkscape Options"), + N_("Default program options")) { // Entry for the "timer" option + Glib::OptionEntry _entry_timer; _entry_timer.set_short_name('t'); _entry_timer.set_long_name("timer"); _entry_timer.set_arg_description(N_("NUM")); @@ -75,16 +74,13 @@ public: add_entry(_entry_timer, timer); // Entry for the remaining non-option arguments + Glib::OptionEntry _entry_args; _entry_args.set_short_name('\0'); _entry_args.set_long_name(G_OPTION_REMAINING); _entry_args.set_arg_description(N_("FILES …")); add_entry(_entry_args, filenames); } - -private: - Glib::OptionEntry _entry_timer; - Glib::OptionEntry _entry_args; }; @@ -122,7 +118,7 @@ std::vector get_valid_files(std::vector filenames, } } } - + return valid_files; } @@ -144,15 +140,15 @@ int main (int argc, char **argv) Inkscape::initialize_gettext(); #endif - Glib::OptionContext opt(N_("Open SVG files")); - opt.set_translation_domain(GETTEXT_PACKAGE); - - InkviewOptionsGroup grp; - grp.set_translation_domain(GETTEXT_PACKAGE); - - opt.set_main_group(grp); + Glib::OptionContext context(N_("Open SVG files")); + context.set_translation_domain(GETTEXT_PACKAGE); - Gtk::Main main_instance (argc, argv, opt); + InkviewOptionsGroup options; + options.set_translation_domain(GETTEXT_PACKAGE); + + context.set_main_group(options); + + Gtk::Main main_instance (argc, argv, context); LIBXML_TEST_VERSION @@ -161,18 +157,18 @@ int main (int argc, char **argv) Inkscape::Application::create(argv[0], true); - if(filenames.empty()) + if(options.filenames.empty()) { - g_print("%s", opt.get_help().c_str()); + g_print("%s", context.get_help().c_str()); exit(EXIT_FAILURE); } - std::vector valid_files = get_valid_files(filenames, true); + std::vector valid_files = get_valid_files(options.filenames, true); if(valid_files.empty()) { return 1; /* none of the slides loadable */ } - - SPSlideShow ss(valid_files, timer); + + SPSlideShow ss(valid_files, options.timer); main_instance.run(); return 0; -- cgit v1.2.3 From 32e1550bf1f16ade2bd14b833bc366dc12b50af5 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 05:46:43 +0200 Subject: Inkview: Add additional information to help output and update option description (bzr r15690.1.13) --- src/inkview.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index b4edfa22f..f1eb1cfc6 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -70,14 +70,13 @@ public: _entry_timer.set_short_name('t'); _entry_timer.set_long_name("timer"); _entry_timer.set_arg_description(N_("NUM")); - _entry_timer.set_description(N_("Reset timer:")); + _entry_timer.set_description(N_("Change image every NUM seconds")); add_entry(_entry_timer, timer); // Entry for the remaining non-option arguments Glib::OptionEntry _entry_args; - _entry_args.set_short_name('\0'); _entry_args.set_long_name(G_OPTION_REMAINING); - _entry_args.set_arg_description(N_("FILES …")); + _entry_args.set_arg_description(N_("FILES/FOLDERS …")); add_entry(_entry_args, filenames); } @@ -140,7 +139,13 @@ int main (int argc, char **argv) Inkscape::initialize_gettext(); #endif - Glib::OptionContext context(N_("Open SVG files")); + Glib::OptionContext context(N_("- display SVG files")); + context.set_summary(N_( + "Quickly browse through a collection of .svg(z) files\n" + "or show them as a slide show.")); + context.set_description(N_( + "Example:\n" + " inkview -t 3 file1.svg file2.svgz series*.svg more_files")); context.set_translation_domain(GETTEXT_PACKAGE); InkviewOptionsGroup options; -- cgit v1.2.3 From 1be23961b14fb409ee1a13fde6de676111587356 Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 06:11:55 +0200 Subject: Inkview: add option -s or --scale to set a factor by witch to scale the displayed image Fixed bugs: - https://launchpad.net/bugs/1550897 (bzr r15690.1.14) --- src/inkview.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index f1eb1cfc6..e50c76ab0 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -59,26 +59,37 @@ public: /// List of all input filenames Glib::OptionGroup::vecustrings filenames; - /// Input timer option + /// timer for the slideshow int timer = 0; + + /// scale factor for images (currently only applied to the first image - others are resized to window dimensions) + double scale = 1; InkviewOptionsGroup() : Glib::OptionGroup(N_("Inkscape Options"), N_("Default program options")) { // Entry for the "timer" option - Glib::OptionEntry _entry_timer; - _entry_timer.set_short_name('t'); - _entry_timer.set_long_name("timer"); - _entry_timer.set_arg_description(N_("NUM")); - _entry_timer.set_description(N_("Change image every NUM seconds")); - add_entry(_entry_timer, timer); + Glib::OptionEntry entry_timer; + entry_timer.set_short_name('t'); + entry_timer.set_long_name("timer"); + entry_timer.set_arg_description(N_("NUM")); + entry_timer.set_description(N_("Change image every NUM seconds")); + add_entry(entry_timer, timer); + + // Entry for the "scale" option + Glib::OptionEntry entry_scale; + entry_scale.set_short_name('s'); + entry_scale.set_long_name("scale"); + entry_scale.set_arg_description(N_("NUM")); + entry_scale.set_description(N_("Scale image by factor NUM")); + add_entry(entry_scale, scale); // Entry for the remaining non-option arguments - Glib::OptionEntry _entry_args; - _entry_args.set_long_name(G_OPTION_REMAINING); - _entry_args.set_arg_description(N_("FILES/FOLDERS …")); + Glib::OptionEntry entry_args; + entry_args.set_long_name(G_OPTION_REMAINING); + entry_args.set_arg_description(N_("FILES/FOLDERS …")); - add_entry(_entry_args, filenames); + add_entry(entry_args, filenames); } }; @@ -173,7 +184,7 @@ int main (int argc, char **argv) return 1; /* none of the slides loadable */ } - SPSlideShow ss(valid_files, options.timer); + SPSlideShow ss(valid_files, options.timer, options.scale); main_instance.run(); return 0; -- cgit v1.2.3 From 7ac22eb4ab56e0ddc1242b88cdb03a275631615a Mon Sep 17 00:00:00 2001 From: Eduard Braun Date: Sun, 14 May 2017 06:38:05 +0200 Subject: Inkview: Don't crash when unknow command line option is specified (bzr r15690.1.15) --- src/inkview.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/inkview.cpp') diff --git a/src/inkview.cpp b/src/inkview.cpp index e50c76ab0..05d8cd1eb 100644 --- a/src/inkview.cpp +++ b/src/inkview.cpp @@ -164,7 +164,14 @@ int main (int argc, char **argv) context.set_main_group(options); - Gtk::Main main_instance (argc, argv, context); + Gtk::Main main_instance(true); + try { + context.parse(argc, argv); + } catch (const Glib::Error& ex) { + g_printerr("%s\n\n", ex.what().c_str()); + g_print("%s", context.get_help().c_str()); + exit(EXIT_FAILURE); + } LIBXML_TEST_VERSION -- cgit v1.2.3