[gnumeric] lpsolve writer: add progress reporting.



commit 77ceb5866a95825c5a00c7c641ba2e6c78cbcfa8
Author: Morten Welinder <terra gnome org>
Date:   Fri Nov 6 21:43:20 2009 -0500

    lpsolve writer: add progress reporting.

 plugins/lpsolve/ChangeLog       |    4 ++++
 plugins/lpsolve/lpsolve-write.c |   31 ++++++++++++++++++++++++++-----
 2 files changed, 30 insertions(+), 5 deletions(-)
---
diff --git a/plugins/lpsolve/ChangeLog b/plugins/lpsolve/ChangeLog
index 6ccced8..ea665bc 100644
--- a/plugins/lpsolve/ChangeLog
+++ b/plugins/lpsolve/ChangeLog
@@ -1,3 +1,7 @@
+2009-11-06  Morten Welinder  <terra gnome org>
+
+	* lpsolve-write.c (lpsolve_file_save): Add progress reporting.
+
 2009-11-01  Morten Welinder <terra gnome org>
 
 	* Release 1.9.15
diff --git a/plugins/lpsolve/lpsolve-write.c b/plugins/lpsolve/lpsolve-write.c
index 6ec114e..aa26e66 100644
--- a/plugins/lpsolve/lpsolve-write.c
+++ b/plugins/lpsolve/lpsolve-write.c
@@ -133,7 +133,7 @@ lpsolve_affine_func (GString *dst, GnmCell *target,
 }
 
 static GString *
-lpsolve_create_program (Sheet *sheet, GError **err)
+lpsolve_create_program (Sheet *sheet, GOIOContext *io_context, GError **err)
 {
 	SolverParameters *sp = sheet->solver_parameters;
 	GString *prg = NULL;
@@ -143,6 +143,16 @@ lpsolve_create_program (Sheet *sheet, GError **err)
 	GSList *l;
 	GnmCell *target_cell = gnm_solver_param_get_target_cell (sp);
 	GSList *input_cells = gnm_solver_param_get_input_cells (sp);
+	gsize progress;
+
+	/* ---------------------------------------- */
+
+	progress = 2;
+	if (sp->options.assume_non_negative) progress++;
+	if (sp->options.assume_discrete) progress++;
+	progress += g_slist_length (sp->constraints);
+
+	go_io_count_progress_set (io_context, progress, 1);
 
 	/* ---------------------------------------- */
 
@@ -163,10 +173,12 @@ lpsolve_create_program (Sheet *sheet, GError **err)
 	default:
 		g_assert_not_reached ();
 	}
+	go_io_count_progress_update (io_context, 1);
 
 	if (!lpsolve_affine_func (objfunc, target_cell, input_cells, err))
 		goto fail;
 	g_string_append (objfunc, ";\n");
+	go_io_count_progress_update (io_context, 1);
 
 	/* ---------------------------------------- */
 
@@ -178,6 +190,7 @@ lpsolve_create_program (Sheet *sheet, GError **err)
 					 lpsolve_var_name (cell));
 			g_string_append (constraints, " >= 0;\n");
 		}
+		go_io_count_progress_update (io_context, 1);
 	}
 
 	if (sp->options.assume_discrete) {
@@ -189,6 +202,7 @@ lpsolve_create_program (Sheet *sheet, GError **err)
 					 lpsolve_var_name (cell));
 			g_string_append (declarations, ";\n");
 		}
+		go_io_count_progress_update (io_context, 1);
 	}
 
  	for (l = sp->constraints; l; l = l->next) {
@@ -251,6 +265,8 @@ lpsolve_create_program (Sheet *sheet, GError **err)
 				g_string_append (constraints, ";\n");
 			}
 		}
+
+		go_io_count_progress_update (io_context, 1);
 	}
 
 	/* ---------------------------------------- */
@@ -285,10 +301,11 @@ lpsolve_file_save (GOFileSaver const *fs, GOIOContext *io_context,
 	GString *prg;
 	GnmLocale *locale;
 
-	workbook_recalc (sheet->workbook);
+	go_io_progress_message (io_context,
+				_("Writing lpsolve file..."));
 
 	locale = gnm_push_C_locale ();
-	prg = lpsolve_create_program (sheet, &err);
+	prg = lpsolve_create_program (sheet, io_context, &err);
 	gnm_pop_C_locale (locale);
 
 	workbook_recalc (sheet->workbook);
@@ -296,10 +313,14 @@ lpsolve_file_save (GOFileSaver const *fs, GOIOContext *io_context,
 	if (!prg) {
 		go_cmd_context_error_import (GO_CMD_CONTEXT (io_context),
 					     err ? err->message : "?");
-		g_error_free (err);
-		return;
+		goto fail;
 	}
 
 	gsf_output_write (output, prg->len, prg->str);
 	g_string_free (prg, TRUE);
+
+fail:
+	go_io_progress_unset (io_context);
+	if (err)
+		g_error_free (err);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]