summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2012-05-25 03:38:14 +0000
committerJon A. Cruz <jon@joncruz.org>2012-05-25 03:38:14 +0000
commite923fb046a11797244b99393f0980bc11c0ff484 (patch)
tree430441358f34aa1e3399c17f5cb75425490c718e
parentFixing warnings. (diff)
downloadinkscape-e923fb046a11797244b99393f0980bc11c0ff484.tar.gz
inkscape-e923fb046a11797244b99393f0980bc11c0ff484.zip
Improve progress granularity when exporting multiple items.
(bzr r11415)
-rw-r--r--src/ui/dialog/export.cpp32
-rw-r--r--src/ui/dialog/export.h2
2 files changed, 23 insertions, 11 deletions
diff --git a/src/ui/dialog/export.cpp b/src/ui/dialog/export.cpp
index ee8e3c00d..7a6d3ad4d 100644
--- a/src/ui/dialog/export.cpp
+++ b/src/ui/dialog/export.cpp
@@ -820,13 +820,22 @@ void Export::onProgressCancel ()
/// Called for every progress iteration
-unsigned int Export::onProgressCallback (float value, void *dlg)
+unsigned int Export::onProgressCallback(float value, void *dlg)
{
Gtk::Dialog *dlg2 = reinterpret_cast<Gtk::Dialog*>(dlg);
if (dlg2->get_data("cancel")) {
return FALSE;
}
+ gint current = GPOINTER_TO_INT(dlg2->get_data("current"));
+ gint total = GPOINTER_TO_INT(dlg2->get_data("total"));
+ if (total > 0) {
+ double completed = current;
+ completed /= static_cast<double>(total);
+
+ value = completed + (value / static_cast<double>(total));
+ }
+
Gtk::ProgressBar *prg = reinterpret_cast<Gtk::ProgressBar *>(dlg2->get_data("progress"));
prg->set_fraction(value);
@@ -952,14 +961,13 @@ void Export::onExport ()
gint export_count = 0;
- for (GSList *i = const_cast<GSList *>(sp_desktop_selection(desktop)->itemList());
- i != NULL;
- i = i->next) {
- if (interrupted){
- break;
- }
+ for (GSList *i = const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()); i && !interrupted; i = i->next) {
SPItem *item = reinterpret_cast<SPItem *>(i->data);
+ prog_dlg->set_data("current", GINT_TO_POINTER(n));
+ prog_dlg->set_data("total", GINT_TO_POINTER(num));
+ onProgressCallback(0.0, prog_dlg);
+
// retrieve export filename hint
const gchar *filename = item->getRepr()->attribute("inkscape:export-filename");
Glib::ustring path;
@@ -996,7 +1004,8 @@ void Export::onExport ()
if (!sp_export_png_file (doc, path.c_str(),
*area, width, height, dpi, dpi,
nv->pagecolor,
- NULL, NULL, TRUE, // overwrite without asking
+ onProgressCallback, (void*)prog_dlg,
+ TRUE, // overwrite without asking
hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL
)) {
gchar * error = g_strdup_printf(_("Could not export to filename %s.\n"), safeFile);
@@ -1014,7 +1023,6 @@ void Export::onExport ()
}
n++;
- onProgressCallback((float)n/num, prog_dlg);
}
desktop->messageStack()->flashF(Inkscape::INFORMATION_MESSAGE,
@@ -1077,11 +1085,15 @@ void Export::onExport ()
prog_dlg->set_data("exportPanel", this);
setExporting(true, Glib::ustring::compose(_("Exporting %1 (%2 x %3)"), fn, width, height));
+ prog_dlg->set_data("current", GINT_TO_POINTER(0));
+ prog_dlg->set_data("total", GINT_TO_POINTER(0));
+
/* Do export */
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,
+ onProgressCallback, (void*)prog_dlg,
+ FALSE,
hide ? const_cast<GSList *>(sp_desktop_selection(desktop)->itemList()) : NULL
);
if (status == EXPORT_ERROR) {
diff --git a/src/ui/dialog/export.h b/src/ui/dialog/export.h
index 46bad3df2..6dc063c0c 100644
--- a/src/ui/dialog/export.h
+++ b/src/ui/dialog/export.h
@@ -241,7 +241,7 @@ private:
* @param value number between 0 and 1 indicating the fraction of progress (0.17 = 17 % progress)
* @param dlg void pointer to the Gtk::Dialog progress dialog
*/
- static unsigned int onProgressCallback (float value, void *dlg);
+ static unsigned int onProgressCallback(float value, void *dlg);
/**
* Callback for pressing the cancel button.