diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2012-05-24 05:49:41 +0000 |
|---|---|---|
| committer | Jon A. Cruz <jon@joncruz.org> | 2012-05-24 05:49:41 +0000 |
| commit | ce96adf2fdd6425ab43a13506c0c629d68b91891 (patch) | |
| tree | fb95a82be5086ca1bc8d64718a9c5efdf4959b2b /src | |
| parent | Add Mesh tool (experimental, requires Cario >= 1.11.4, disabled by default). (diff) | |
| download | inkscape-ce96adf2fdd6425ab43a13506c0c629d68b91891.tar.gz inkscape-ce96adf2fdd6425ab43a13506c0c629d68b91891.zip | |
Applied modified patch to add export messages. Partially fixes bug #43730.
Fixed bugs:
- https://launchpad.net/bugs/43730
(bzr r11407)
Diffstat (limited to 'src')
| -rw-r--r-- | src/helper/png-write.cpp | 56 | ||||
| -rw-r--r-- | src/helper/png-write.h | 40 | ||||
| -rw-r--r-- | src/ui/dialog/export.cpp | 122 |
3 files changed, 146 insertions, 72 deletions
diff --git a/src/helper/png-write.cpp b/src/helper/png-write.cpp index 35fd5a62a..c43a207c8 100644 --- a/src/helper/png-write.cpp +++ b/src/helper/png-write.cpp @@ -4,6 +4,7 @@ * Authors: * Lauris Kaplinski <lauris@kaplinski.com> * Whoever wrote this example in libpng documentation + * Peter Bostrom * Jon A. Cruz <jon@joncruz.org> * Abhishek Sharma * @@ -379,43 +380,36 @@ static void hide_other_items_recursively(SPObject *o, GSList *list, unsigned dke } -/** - * Export the given document as a Portable Network Graphics (PNG) file. - * - * \return true if succeeded (or if no action was taken), false if an error occurred. - */ -bool sp_export_png_file (SPDocument *doc, gchar const *filename, - double x0, double y0, double x1, double y1, - unsigned long int width, unsigned long int height, double xdpi, double ydpi, - unsigned long bgcolor, - unsigned int (*status) (float, void *), - void *data, bool force_overwrite, - GSList *items_only) +ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, + double x0, double y0, double x1, double y1, + unsigned long int width, unsigned long int height, double xdpi, double ydpi, + unsigned long bgcolor, + unsigned int (*status) (float, void *), + void *data, bool force_overwrite, + GSList *items_only) { return sp_export_png_file(doc, filename, Geom::Rect(Geom::Point(x0,y0),Geom::Point(x1,y1)), width, height, xdpi, ydpi, bgcolor, status, data, force_overwrite, items_only); } -bool -sp_export_png_file(SPDocument *doc, gchar const *filename, - Geom::Rect const &area, - unsigned long width, unsigned long height, double xdpi, double ydpi, - unsigned long bgcolor, - unsigned (*status)(float, void *), - void *data, bool force_overwrite, - GSList *items_only) + +ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, + Geom::Rect const &area, + unsigned long width, unsigned long height, double xdpi, double ydpi, + unsigned long bgcolor, + unsigned (*status)(float, void *), + void *data, bool force_overwrite, + GSList *items_only) { - g_return_val_if_fail(doc != NULL, false); - g_return_val_if_fail(filename != NULL, false); - g_return_val_if_fail(width >= 1, false); - g_return_val_if_fail(height >= 1, false); - g_return_val_if_fail(!area.hasZeroArea(), false); + g_return_val_if_fail(doc != NULL, EXPORT_ERROR); + g_return_val_if_fail(filename != NULL, EXPORT_ERROR); + g_return_val_if_fail(width >= 1, EXPORT_ERROR); + g_return_val_if_fail(height >= 1, EXPORT_ERROR); + g_return_val_if_fail(!area.hasZeroArea(), EXPORT_ERROR); + if (!force_overwrite && !sp_ui_overwrite_file(filename)) { - /* Remark: We return true so as not to invoke an error dialog in case export is cancelled - by the user; currently this is safe because the callers only act when false is returned. - If this changes in the future we need better distinction of return types (e.g., use int) - */ - return true; + // aborted overwrite + return EXPORT_ABORTED; } doc->ensureUpToDate(); @@ -482,7 +476,7 @@ sp_export_png_file(SPDocument *doc, gchar const *filename, // Hide items, this releases arenaitem doc->getRoot()->invoke_hide(dkey); - return write_status; + return write_status ? EXPORT_OK : EXPORT_ERROR; } diff --git a/src/helper/png-write.h b/src/helper/png-write.h index f8ba4bbf6..a8658ef88 100644 --- a/src/helper/png-write.h +++ b/src/helper/png-write.h @@ -1,11 +1,13 @@ -#ifndef __SP_PNG_WRITE_H__ -#define __SP_PNG_WRITE_H__ +#ifndef SEEN_SP_PNG_WRITE_H +#define SEEN_SP_PNG_WRITE_H /* * PNG file format utilities * * Authors: * Lauris Kaplinski <lauris@kaplinski.com> + * Peter Bostrom + * Jon A. Cruz <jon@joncruz.org> * * Copyright (C) 1999-2002 Lauris Kaplinski * @@ -16,15 +18,27 @@ #include <2geom/forward.h> struct SPDocument; -bool sp_export_png_file (SPDocument *doc, gchar const *filename, - double x0, double y0, double x1, double y1, - unsigned long int width, unsigned long int height, double xdpi, double ydpi, - unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); -bool sp_export_png_file (SPDocument *doc, gchar const *filename, - Geom::Rect const &area, - unsigned long int width, unsigned long int height, double xdpi, double ydpi, - unsigned long bgcolor, - unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); +enum ExportResult { + EXPORT_ERROR = 0, + EXPORT_OK, + EXPORT_ABORTED +}; -#endif +/** + * Export the given document as a Portable Network Graphics (PNG) file. + * + * @return EXPORT_OK if succeeded, EXPORT_ABORTED if no action was taken, EXPORT_ERROR (false) if an error occurred. + */ +ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, + double x0, double y0, double x1, double y1, + unsigned long int width, unsigned long int height, double xdpi, double ydpi, + unsigned long bgcolor, + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + +ExportResult sp_export_png_file(SPDocument *doc, gchar const *filename, + Geom::Rect const &area, + unsigned long int width, unsigned long int height, double xdpi, double ydpi, + unsigned long bgcolor, + unsigned int (*status) (float, void *), void *data, bool force_overwrite = false, GSList *items_only = NULL); + +#endif // SEEN_SP_PNG_WRITE_H diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp index 99b93e99f..0582ab471 100644 --- a/src/ui/dialog/export.cpp +++ b/src/ui/dialog/export.cpp @@ -6,6 +6,7 @@ * Lauris Kaplinski <lauris@kaplinski.com> * bulia byak <buliabyak@users.sf.net> * Johan Engelen <j.b.c.engelen@ewi.utwente.nl> + * Peter Bostrom * Jon A. Cruz <jon@joncruz.org> * Abhishek Sharma * Kris De Gussem <Kris.DeGussem@gmail.com> @@ -66,6 +67,10 @@ #include "helper/png-write.h" +// required to set status message after export +#include "desktop.h" +#include "message-stack.h" + #ifdef WIN32 #include <windows.h> #include <commdlg.h> @@ -86,6 +91,33 @@ #include "verbs.h" #include "export.h" +namespace { + +class MessageCleaner +{ +public: + MessageCleaner(Inkscape::MessageId messageId, SPDesktop *desktop) : + _desktop(desktop), + _messageId(messageId) + { + } + + ~MessageCleaner() + { + if (_messageId && _desktop) { + _desktop->messageStack()->cancel(_messageId); + } + } + +private: + MessageCleaner(MessageCleaner const &other); + MessageCleaner &operator=(MessageCleaner const &other); + + SPDesktop *_desktop; + Inkscape::MessageId _messageId; +}; + +} // namespace namespace Inkscape { namespace UI { @@ -804,7 +836,7 @@ unsigned int Export::onProgressCallback (float value, void *dlg) Gtk::Dialog * Export::create_progress_dialog (Glib::ustring progress_text) { Gtk::Dialog *dlg = new Gtk::Dialog(_("Export in progress"), TRUE); - + Gtk::ProgressBar *prg = new Gtk::ProgressBar (); prg->set_text(progress_text); dlg->set_data ("progress", prg); @@ -828,7 +860,7 @@ Gtk::Dialog * Export::create_progress_dialog (Glib::ustring progress_text) { Glib::ustring Export::filename_add_extension (Glib::ustring filename, Glib::ustring extension) { Glib::ustring::size_type dot; - + dot = filename.find_last_of("."); if ( !dot ) { @@ -866,24 +898,29 @@ Glib::ustring Export::absolutize_path_from_document_location (SPDocument *doc, c /// Called when export button is clicked void Export::onExport () { - if (!SP_ACTIVE_DESKTOP) return; + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + if (!desktop) return; - SPNamedView *nv = sp_desktop_namedview(SP_ACTIVE_DESKTOP); - SPDocument *doc = sp_desktop_document (SP_ACTIVE_DESKTOP); + SPNamedView *nv = sp_desktop_namedview(desktop); + SPDocument *doc = sp_desktop_document (desktop); bool hide = hide_export.get_active (); if (batch_export.get_active ()) { // Batch export of selected objects - gint num = g_slist_length(const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList())); + gint num = g_slist_length(const_cast<GSList *>(sp_desktop_selection(desktop)->itemList())); gint n = 0; - if (num < 1) + if (num < 1) { + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("No items selected.")); return; + } + + prog_dlg = create_progress_dialog(Glib::ustring::compose(_("Exporting %1 files"), num)); - prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 files"),num)); + gint export_count = 0; - for (GSList *i = const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()); + for (GSList *i = const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()); i != NULL; i = i->next) { if (interrupted){ @@ -917,38 +954,52 @@ void Export::onExport () gint height = (gint) (area->height() * dpi / PX_PER_IN + 0.5); if (width > 1 && height > 1) { - /* Do export */ + // Do export + gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); + MessageCleaner msgCleanup(desktop->messageStack()->pushF(Inkscape::IMMEDIATE_MESSAGE, + _("Exporting file <b>%s</b>..."), safeFile), desktop); + MessageCleaner msgFlashCleanup(desktop->messageStack()->flashF(Inkscape::IMMEDIATE_MESSAGE, + _("Exporting file <b>%s</b>..."), safeFile), desktop); + if (!sp_export_png_file (doc, path.c_str(), *area, width, height, dpi, dpi, nv->pagecolor, NULL, NULL, TRUE, // overwrite without asking - hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL + hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL )) { - gchar * error; - gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); - error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + + desktop->messageStack()->flashF(Inkscape::ERROR_MESSAGE, + _("Could not export to filename <b>%s</b>."), safeFile); + sp_ui_error_dialog(error); - g_free(safeFile); g_free(error); + } else { + ++export_count; // one more item exported successfully } + g_free(safeFile); } } + n++; onProgressCallback((float)n/num, prog_dlg); } + desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, + _("Successfully exported <b>%d</b> files from <b>%d</b> selected items."), export_count, num); + delete prog_dlg; prog_dlg = NULL; interrupted = false; - } else { Glib::ustring filename = filename_entry.get_text(); if (filename.empty()){ + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You have to enter a filename.")); sp_ui_error_dialog(_("You have to enter a filename")); return; } - + float const x0 = getValuePx(x0_adj); float const y0 = getValuePx(y0_adj); float const x1 = getValuePx(x1_adj); @@ -959,7 +1010,8 @@ void Export::onExport () unsigned long int const height = int(getValue(bmheight_adj) + 0.5); if (!((x1 > x0) && (y1 > y0) && (width > 0) && (height > 0))) { - sp_ui_error_dialog (_("The chosen area to be exported is invalid")); + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The chosen area to be exported is invalid.")); + sp_ui_error_dialog(_("The chosen area to be exported is invalid")); return; } @@ -975,7 +1027,10 @@ void Export::onExport () gchar *safeDir = Inkscape::IO::sanitizeString(dirname.c_str()); gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"), safeDir); + + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, error); sp_ui_error_dialog(error); + g_free(safeDir); g_free(error); return; @@ -987,18 +1042,29 @@ void Export::onExport () prog_dlg = create_progress_dialog (Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height)); /* Do export */ - if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), path.c_str(), - Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, - nv->pagecolor, - onProgressCallback, (void*)prog_dlg, FALSE, - hide ? const_cast<GSList *>(sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList()) : NULL - )) { - gchar * error; + ExportResult status = sp_export_png_file(sp_desktop_document(desktop), path.c_str(), + Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, + nv->pagecolor, + onProgressCallback, (void*)prog_dlg, FALSE, + hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL + ); + if (status == EXPORT_ERROR) { gchar * safeFile = Inkscape::IO::sanitizeString(path.c_str()); - error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + + desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, error); sp_ui_error_dialog(error); + g_free(safeFile); g_free(error); + } else if (status == EXPORT_OK) { + gchar *safeFile = Inkscape::IO::sanitizeString(path.c_str()); + + desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE, _("Drawing exported to <b>%s</b>."), safeFile); + + g_free(safeFile); + } else { + desktop->messageStack()->flash(Inkscape::INFORMATION_MESSAGE, _("Export aborted.")); } /* Reset the filename so that it can be changed again by changing @@ -1050,7 +1116,7 @@ void Export::onExport () bool saved = DocumentUndo::getUndoSensitive(doc); DocumentUndo::setUndoSensitive(doc, false); - reprlst = sp_desktop_selection(SP_ACTIVE_DESKTOP)->reprList(); + reprlst = sp_desktop_selection(desktop)->reprList(); for(; reprlst != NULL; reprlst = reprlst->next) { Inkscape::XML::Node * repr = static_cast<Inkscape::XML::Node *>(reprlst->data); @@ -1234,7 +1300,7 @@ void Export::detectSize() { static const selection_type test_order[SELECTION_NUMBER_OF] = {SELECTION_SELECTION, SELECTION_DRAWING, SELECTION_PAGE, SELECTION_CUSTOM}; selection_type this_test[SELECTION_NUMBER_OF + 1]; selection_type key = SELECTION_NUMBER_OF; - + Geom::Point x(getValuePx(x0_adj), getValuePx(y0_adj)); Geom::Point y(getValuePx(x1_adj), |
