From 5021078a1ae5b9d919ef666324208f5b29170861 Mon Sep 17 00:00:00 2001 From: Anshudhar Date: Mon, 8 Mar 2021 16:58:58 +0530 Subject: [PATCH 1/6] Temporary default add suffix batch export Used only id with suffix to generate files in batch export --- src/ui/dialog/export.cpp | 58 +++++++++++++++++++++++++++++++++------- src/ui/interface.cpp | 40 +++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 10 deletions(-) diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 2e54619d7b..cab39479eb 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -605,6 +605,35 @@ std::string create_filepath_from_id(Glib::ustring id, const Glib::ustring &file_ return Glib::build_filename(directory, Glib::filename_from_utf8(id) + ".png"); } +std::string +create_filepath_from_id_with_suffix(Glib::ustring id, const Glib::ustring &file_entry_text) +{ + + std::string path = ""; + std::string temp_id; + path = create_filepath_from_id(id, file_entry_text); + if (!Inkscape::IO::file_test(path.c_str(), G_FILE_TEST_EXISTS)) + { + return path; + } + + unsigned int i=1; + while(i<100) + { + path = create_filepath_from_id(id + "_" + std::to_string(i), file_entry_text); + if (!Inkscape::IO::file_test(path.c_str(), G_FILE_TEST_EXISTS)) + { + return path; + } + i++; + } + + + //if not found return empty path + path = ""; + return path; +} + void Export::onBatchClicked () { if (batch_export.get_active()) { @@ -1040,18 +1069,20 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) onProgressCallback(0.0, prog_dlg); // retrieve export filename hint - const gchar *filename = item->getRepr()->attribute("inkscape:export-filename"); + // temporary disabled as filename is preventing adding suffix + // const gchar *filename = item->getRepr()->attribute("inkscape:export-filename"); + std::string path; - if (!filename) { - auto id = item->getId(); - if (!id) { - g_warning("object has no id"); - continue; - } - path = create_filepath_from_id(id, filename_entry.get_text()); - } else { - path = absolutize_path_from_document_location(doc, filename); + + //creating path only from id. TODO: create path from filename + id. + auto id = item->getId(); + if (!id) { + g_warning("object has no id"); + continue; } + path = create_filepath_from_id_with_suffix(id, filename_entry.get_text()); + if(path.empty()) + continue; // retrieve export dpi hints const gchar *dpi_hint = item->getRepr()->attribute("inkscape:export-xdpi"); // only xdpi, ydpi is always the same now @@ -1076,6 +1107,7 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) _("Exporting file %s..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, _("Exporting file %s..."), safeFile), desktop); + std::vector x; std::vector selected(desktop->getSelection()->items().begin(), desktop->getSelection()->items().end()); if (!sp_export_png_file (doc, path.c_str(), @@ -1102,9 +1134,15 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) n++; } +<<<<<<< HEAD desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, _("Successfully exported %d files from %d selected items."), export_count, num); +======= + + desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, + _("Successfully exported %d files from %d selected items."), export_count, num); +>>>>>>> 156f7eb34e... Temporary default add suffix batch export setExporting(false); delete prog_dlg; diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 089327c7ac..29eb19b86c 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -221,6 +221,46 @@ sp_ui_overwrite_file(gchar const *filename) return return_value; } +/* THIS FUNCTION IS NOT USED FOR THE TIME BEING. +int +sp_ui_overwrite_file_batch(std::set& conflicting_paths) +{ + //0 means no conflicting paths hence take no action. + if(conflicting_paths.size()<1) + return 1; + + //get space separated list of paths for printing in dialog + Glib::ustring sec_message = "These files already exists:\n"; + for(auto& path:conflicting_paths) + sec_message = sec_message + "- " + path + "\n"; + sec_message = sec_message + "You can also skip these files or make a copy with suitable suffix"; + + //dialog creation. reference taken from sp_ui_overwrite_file + Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); + + Gtk::MessageDialog *dialog = new Gtk::MessageDialog(*window, + "", + true, + Gtk::MESSAGE_WARNING, + Gtk::BUTTONS_NONE, + true + ); + + dialog->set_message("Files already exists. Do you want to replace them?"); + dialog->set_secondary_text(sec_message); + //Don't use -4 as it is reserved for Gtk::RESPONSE::DELETE_EVENT + dialog->add_button(_("_Cancel"), -1); + dialog->add_button(_("Skip"), 0); + dialog->add_button(_("Replace"), 1); + dialog->add_button(_("Add Suffix"), 2); + dialog->set_default_response(1); + auto response = dialog->run(); + + delete dialog; + return response; +} +*/ + /* Local Variables: mode:c++ -- GitLab From e29c187fae0f37df2b7f8fe82cb27587bdb1fcb2 Mon Sep 17 00:00:00 2001 From: Anshudhar Date: Mon, 8 Mar 2021 18:12:01 +0530 Subject: [PATCH 2/6] Increase Loop max and added Copy with suffix --- src/ui/dialog/export.cpp | 45 +++++++++++++++++++--------------------- src/ui/dialog/export.h | 3 +++ src/ui/interface.h | 5 +++++ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index cab39479eb..199b18db87 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -577,6 +577,23 @@ Glib::RefPtr Export::createSpinbutton( gchar const * /*key*/, } // end of createSpinbutton() +//moved up because there was no declaration in header file. Should we add? +static std::string absolutize_path_from_document_location(SPDocument *doc, const std::string &filename) +{ + std::string path; + //Make relative paths go from the document location, if possible: + if (!Glib::path_is_absolute(filename) && doc->getDocumentURI()) { + auto dirname = Glib::path_get_dirname(doc->getDocumentURI()); + if (!dirname.empty()) { + path = Glib::build_filename(dirname, filename); + } + } + if (path.empty()) { + path = filename; + } + return path; +} + std::string create_filepath_from_id(Glib::ustring id, const Glib::ustring &file_entry_text) { if (id.empty()) @@ -618,9 +635,9 @@ create_filepath_from_id_with_suffix(Glib::ustring id, const Glib::ustring &file_ } unsigned int i=1; - while(i<100) + while(igetDocumentURI()) { - auto dirname = Glib::path_get_dirname(doc->getDocumentURI()); - if (!dirname.empty()) { - path = Glib::build_filename(dirname, filename); - } - } - if (path.empty()) { - path = filename; - } - return path; -} - // Called when unit is changed void Export::onUnitChanged() { @@ -1061,6 +1062,7 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) gint export_count = 0; auto itemlist= desktop->getSelection()->items(); + for(auto i = itemlist.begin();i!=itemlist.end() && !interrupted ;++i){ SPItem *item = *i; @@ -1110,6 +1112,7 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) std::vector x; std::vector selected(desktop->getSelection()->items().begin(), desktop->getSelection()->items().end()); + if (!sp_export_png_file (doc, path.c_str(), *area, width, height, pHYs, pHYs, nv->pagecolor, @@ -1134,15 +1137,9 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) n++; } -<<<<<<< HEAD - - desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, - _("Successfully exported %d files from %d selected items."), export_count, num); -======= desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, _("Successfully exported %d files from %d selected items."), export_count, num); ->>>>>>> 156f7eb34e... Temporary default add suffix batch export setExporting(false); delete prog_dlg; diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h index 7379508351..c19de1ef84 100644 --- a/src/ui/dialog/export.h +++ b/src/ui/dialog/export.h @@ -25,6 +25,9 @@ #include "ui/dialog/dialog-base.h" #include "ui/widget/scrollprotected.h" +//For set<> in batch export +#include + namespace Inkscape { namespace UI { namespace Dialog { diff --git a/src/ui/interface.h b/src/ui/interface.h index 4fa80dab13..14fa2723e1 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -20,6 +20,10 @@ #include +//Added for sp_ui_overwrite_file_batch +#include +#include + typedef struct _GtkWidget GtkWidget; namespace Inkscape { @@ -59,6 +63,7 @@ Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view ); */ void sp_ui_error_dialog (char const* message); bool sp_ui_overwrite_file (char const* filename); +int sp_ui_overwrite_file_batch(std::set &conflicting_paths); #endif // SEEN_SP_INTERFACE_H -- GitLab From f8e31affb5c322cbd12443a03e970012359feaf5 Mon Sep 17 00:00:00 2001 From: Anshudhar Date: Mon, 8 Mar 2021 18:33:56 +0530 Subject: [PATCH 3/6] clean up --- src/ui/dialog/export.cpp | 3 ++- src/ui/interface.cpp | 39 --------------------------------------- src/ui/interface.h | 3 --- 3 files changed, 2 insertions(+), 43 deletions(-) diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 199b18db87..b48a463157 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -135,6 +135,7 @@ class ExportProgressDialog : public Gtk::Dialog { }; static std::string create_filepath_from_id(Glib::ustring, const Glib::ustring &); +static std::string absolutize_path_from_document_location(SPDocument *doc, const std::string &filename); /** A list of strings that is used both in the preferences, and in the data fields to describe the various values of \c selection_type. */ @@ -577,7 +578,7 @@ Glib::RefPtr Export::createSpinbutton( gchar const * /*key*/, } // end of createSpinbutton() -//moved up because there was no declaration in header file. Should we add? + static std::string absolutize_path_from_document_location(SPDocument *doc, const std::string &filename) { std::string path; diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index 29eb19b86c..e1c29d3cc2 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -221,45 +221,6 @@ sp_ui_overwrite_file(gchar const *filename) return return_value; } -/* THIS FUNCTION IS NOT USED FOR THE TIME BEING. -int -sp_ui_overwrite_file_batch(std::set& conflicting_paths) -{ - //0 means no conflicting paths hence take no action. - if(conflicting_paths.size()<1) - return 1; - - //get space separated list of paths for printing in dialog - Glib::ustring sec_message = "These files already exists:\n"; - for(auto& path:conflicting_paths) - sec_message = sec_message + "- " + path + "\n"; - sec_message = sec_message + "You can also skip these files or make a copy with suitable suffix"; - - //dialog creation. reference taken from sp_ui_overwrite_file - Gtk::Window *window = SP_ACTIVE_DESKTOP->getToplevel(); - - Gtk::MessageDialog *dialog = new Gtk::MessageDialog(*window, - "", - true, - Gtk::MESSAGE_WARNING, - Gtk::BUTTONS_NONE, - true - ); - - dialog->set_message("Files already exists. Do you want to replace them?"); - dialog->set_secondary_text(sec_message); - //Don't use -4 as it is reserved for Gtk::RESPONSE::DELETE_EVENT - dialog->add_button(_("_Cancel"), -1); - dialog->add_button(_("Skip"), 0); - dialog->add_button(_("Replace"), 1); - dialog->add_button(_("Add Suffix"), 2); - dialog->set_default_response(1); - auto response = dialog->run(); - - delete dialog; - return response; -} -*/ /* Local Variables: diff --git a/src/ui/interface.h b/src/ui/interface.h index 14fa2723e1..a7000a510b 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -20,9 +20,6 @@ #include -//Added for sp_ui_overwrite_file_batch -#include -#include typedef struct _GtkWidget GtkWidget; -- GitLab From 385cbfd932ffc24be905148d4556791f8a4839cb Mon Sep 17 00:00:00 2001 From: Anshudhar Date: Mon, 8 Mar 2021 19:17:21 +0530 Subject: [PATCH 4/6] removed error --- src/ui/interface.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ui/interface.h b/src/ui/interface.h index a7000a510b..8bc7775e07 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -60,7 +60,6 @@ Glib::ustring getLayoutPrefPath( Inkscape::UI::View::View *view ); */ void sp_ui_error_dialog (char const* message); bool sp_ui_overwrite_file (char const* filename); -int sp_ui_overwrite_file_batch(std::set &conflicting_paths); #endif // SEEN_SP_INTERFACE_H -- GitLab From c274a3f01472f254517781afe222e978e833c315 Mon Sep 17 00:00:00 2001 From: Anshudhar Kumar Singh Date: Mon, 8 Mar 2021 21:25:24 +0000 Subject: [PATCH 5/6] Reverted changes due to empty lines --- src/ui/dialog/export.cpp | 6 ++---- src/ui/dialog/export.h | 3 --- src/ui/interface.cpp | 1 - src/ui/interface.h | 1 - 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index b48a463157..210ff548fa 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -1110,10 +1110,8 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) _("Exporting file %s..."), safeFile), desktop); MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, _("Exporting file %s..."), safeFile), desktop); - std::vector x; std::vector selected(desktop->getSelection()->items().begin(), desktop->getSelection()->items().end()); - if (!sp_export_png_file (doc, path.c_str(), *area, width, height, pHYs, pHYs, nv->pagecolor, @@ -1138,9 +1136,9 @@ void Export::_export_raster(Inkscape::Extension::Output *extension) n++; } - + desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, - _("Successfully exported %d files from %d selected items."), export_count, num); + _("Successfully exported %d files from %d selected items."), export_count, num); setExporting(false); delete prog_dlg; diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h index c19de1ef84..7379508351 100644 --- a/src/ui/dialog/export.h +++ b/src/ui/dialog/export.h @@ -25,9 +25,6 @@ #include "ui/dialog/dialog-base.h" #include "ui/widget/scrollprotected.h" -//For set<> in batch export -#include - namespace Inkscape { namespace UI { namespace Dialog { diff --git a/src/ui/interface.cpp b/src/ui/interface.cpp index e1c29d3cc2..089327c7ac 100644 --- a/src/ui/interface.cpp +++ b/src/ui/interface.cpp @@ -221,7 +221,6 @@ sp_ui_overwrite_file(gchar const *filename) return return_value; } - /* Local Variables: mode:c++ diff --git a/src/ui/interface.h b/src/ui/interface.h index 8bc7775e07..4fa80dab13 100644 --- a/src/ui/interface.h +++ b/src/ui/interface.h @@ -20,7 +20,6 @@ #include - typedef struct _GtkWidget GtkWidget; namespace Inkscape { -- GitLab From 9efedc5508b069418a89a339b443a656cace4329 Mon Sep 17 00:00:00 2001 From: Anshudhar Kumar Singh Date: Tue, 9 Mar 2021 13:47:01 +0000 Subject: [PATCH 6/6] added comments --- src/ui/dialog/export.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 210ff548fa..6ec64c8063 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -629,25 +629,26 @@ create_filepath_from_id_with_suffix(Glib::ustring id, const Glib::ustring &file_ std::string path = ""; std::string temp_id; + // If file does not exist already return path without suffix path = create_filepath_from_id(id, file_entry_text); if (!Inkscape::IO::file_test(path.c_str(), G_FILE_TEST_EXISTS)) { return path; } - unsigned int i=1; - while(i