[Gnucash-changes] r13810 - gnucash/trunk - If the report already
has an id assigned (i.e. restored reports) then
David Hampton
hampton at cvs.gnucash.org
Wed Apr 19 20:05:00 EDT 2006
Author: hampton
Date: 2006-04-19 20:05:00 -0400 (Wed, 19 Apr 2006)
New Revision: 13810
Trac: http://svn.gnucash.org/trac/changeset/13810
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/report/report-system/gnc-report.c
Log:
If the report already has an id assigned (i.e. restored reports) then
add it to the table using that id. Only generate ids for reports that
don't have them yet.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-04-19 22:28:04 UTC (rev 13809)
+++ gnucash/trunk/ChangeLog 2006-04-20 00:05:00 UTC (rev 13810)
@@ -1,5 +1,10 @@
2006-04-19 David Hampton <hampton at employees.org>
+ * src/report/report-system/gnc-report.c: If the report already has
+ an id assigned (i.e. restored reports) then add it to the table
+ using that id. Only generate ids for reports that don't have them
+ yet.
+
* src/gnome-utils/gnc-main-window.c: Don't call shutdown directly
from the delete_event handler, but use a periodic idle function
that checks to insure that gnucash isn't saving the data file
Modified: gnucash/trunk/src/report/report-system/gnc-report.c
===================================================================
--- gnucash/trunk/src/report/report-system/gnc-report.c 2006-04-19 22:28:04 UTC (rev 13809)
+++ gnucash/trunk/src/report/report-system/gnc-report.c 2006-04-20 00:05:00 UTC (rev 13810)
@@ -69,13 +69,41 @@
int gnc_report_add(SCM report)
{
- gint *key;
+ SCM get_id = scm_c_eval_string("gnc:report-id");
+ SCM value;
+ gint id, *key;
+
gnc_report_init_table();
- key = g_new(gint, 1);
- *key = report_next_serial_id++;
- g_hash_table_insert(reports, key, (gpointer)report);
- scm_gc_protect_object(report);
- return *key;
+
+ value = scm_call_1(get_id, report);
+ if (SCM_NUMBERP(value)) {
+ id = scm_num2int(value, SCM_ARG1, __FUNCTION__);
+ if (!g_hash_table_lookup(reports, &id)) {
+ key = g_new(gint, 1);
+ *key = id;
+ g_hash_table_insert(reports, key, (gpointer)report);
+ scm_gc_protect_object(report);
+ return id;
+ }
+ g_warning("Report specified id of %d is already is use. "
+ "Using generated id.", id);
+ }
+
+ id = report_next_serial_id++;
+ while (id < G_MAXINT) {
+ if (!g_hash_table_lookup(reports, &id)) {
+ key = g_new(gint, 1);
+ *key = id;
+ g_hash_table_insert(reports, key, (gpointer)report);
+ scm_gc_protect_object(report);
+ return id;
+ }
+ id = report_next_serial_id++;
+ }
+
+ g_warning("Unable to add report to table. %d reports in use.", G_MAXINT);
+ report_next_serial_id = G_MAXINT;
+ return G_MAXINT;
}
static gboolean
More information about the gnucash-changes
mailing list