=== modified file 'src/dialogs/export.cpp' --- old/src/dialogs/export.cpp 2010-03-05 22:44:33 +0000 +++ new/src/dialogs/export.cpp 2010-04-08 09:46:48 +0000 @@ -60,6 +60,10 @@ #include "helper/png-write.h" +// required to set status message after export +#include "desktop.h" +#include "message-stack.h" + #ifdef WIN32 #include #include @@ -1096,12 +1100,18 @@ gint n = 0; if (num < 1) + { + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->push(Inkscape::ERROR_MESSAGE, _("No items selected.")); return; + } gchar *progress_text = g_strdup_printf (_("Exporting %d files"), num); GtkWidget *prog_dlg = create_progress_dialog (base, progress_text); g_free (progress_text); + gint export_count = 0; + for (GSList *i = (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList(); i != NULL; i = i->next) { @@ -1143,17 +1153,29 @@ gchar * error; gchar * safeFile = Inkscape::IO::sanitizeString(path); error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->pushF(Inkscape::ERROR_MESSAGE, + _("Could not export to filename %s."), safeFile); + sp_ui_error_dialog(error); g_free(safeFile); g_free(error); } + else + ++export_count; // one more item exported successfully } } + n++; g_free(path); sp_export_progress_callback((float)n/num, base); } + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->pushF(Inkscape::INFORMATION_MESSAGE, + _("Successfully exported %d files from %d selected items."), export_count, num); + gtk_widget_destroy (prog_dlg); g_object_set_data (G_OBJECT (base), "cancel", (gpointer) 0); @@ -1173,11 +1195,17 @@ if (filename == NULL || *filename == '\0') { sp_ui_error_dialog(_("You have to enter a filename")); + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->push(Inkscape::ERROR_MESSAGE, + _("You have to enter a filename.")); return; } if (!((x1 > x0) && (y1 > y0) && (width > 0) && (height > 0))) { sp_ui_error_dialog (_("The chosen area to be exported is invalid")); + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->push(Inkscape::ERROR_MESSAGE, + _("The chosen area to be exported is invalid.")); return; } @@ -1194,6 +1222,11 @@ gchar *safeDir = Inkscape::IO::sanitizeString(dirname); gchar *error = g_strdup_printf(_("Directory %s does not exist or is not a directory.\n"), safeDir); + + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->pushF(Inkscape::ERROR_MESSAGE, + _("Directory %s does not exist or is not a directory."), safeDir); + sp_ui_error_dialog(error); g_free(safeDir); g_free(error); @@ -1211,19 +1244,40 @@ g_free (progress_text); /* Do export */ - if (!sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), path, + export_result status = sp_export_png_file (sp_desktop_document (SP_ACTIVE_DESKTOP), path, Geom::Rect(Geom::Point(x0, y0), Geom::Point(x1, y1)), width, height, xdpi, ydpi, nv->pagecolor, sp_export_progress_callback, base, FALSE, hide ? (GSList *) sp_desktop_selection(SP_ACTIVE_DESKTOP)->itemList() : NULL - )) { + ); + if(status == EXPORT_ERROR) + { gchar * error; gchar * safeFile = Inkscape::IO::sanitizeString(path); error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile); + + if(SP_ACTIVE_DESKTOP->messageStack() != NULL) + SP_ACTIVE_DESKTOP->messageStack()->pushF(Inkscape::ERROR_MESSAGE, + _("Could not export to filename %s."), safeFile); + sp_ui_error_dialog(error); g_free(safeFile); g_free(error); } + else if(SP_ACTIVE_DESKTOP->messageStack() != NULL) // inform that export did finish + { + if(status == EXPORT_OK) + { + gchar *safeFile = Inkscape::IO::sanitizeString(path); + + SP_ACTIVE_DESKTOP->messageStack()->pushF(Inkscape::INFORMATION_MESSAGE, + _("Drawing exported to %s."), safeFile); + + g_free(safeFile); + } + else + SP_ACTIVE_DESKTOP->messageStack()->push(Inkscape::INFORMATION_MESSAGE, _("Export aborted.")); + } /* Reset the filename so that it can be changed again by changing selections and all that */ === modified file 'src/helper/png-write.cpp' --- old/src/helper/png-write.cpp 2010-04-06 14:11:54 +0000 +++ new/src/helper/png-write.cpp 2010-04-08 10:14:20 +0000 @@ -386,9 +386,9 @@ /** * 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. + * \return EXPORT_OK if succeeded, EXPORT_ABORTED if no action was taken, EXPORT_ERROR (false) if an error occurred. */ -bool sp_export_png_file (SPDocument *doc, gchar const *filename, +export_result 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, @@ -399,7 +399,7 @@ 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 +export_result sp_export_png_file(SPDocument *doc, gchar const *filename, Geom::Rect const &area, unsigned long width, unsigned long height, double xdpi, double ydpi, @@ -408,18 +408,15 @@ 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; } sp_document_ensure_up_to_date(doc); @@ -495,7 +492,7 @@ /* Free arena */ nr_object_unref((NRObject *) arena); - return write_status; + return write_status ? EXPORT_OK : EXPORT_ERROR; } === modified file 'src/helper/png-write.h' --- old/src/helper/png-write.h 2009-08-06 14:17:17 +0000 +++ new/src/helper/png-write.h 2010-04-08 09:58:22 +0000 @@ -16,12 +16,19 @@ #include <2geom/forward.h> struct SPDocument; -bool sp_export_png_file (SPDocument *doc, gchar const *filename, +enum export_result +{ + EXPORT_ERROR = 0, + EXPORT_OK, + EXPORT_ABORTED +}; + +export_result 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, +export_result 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,