mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
start trying to fix how the price db begin-edit/end-edit so that
books can be closed. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@9094 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
d1341ae7ce
commit
032a820e49
@ -62,7 +62,10 @@ struct gnc_price_s
|
||||
struct gnc_price_db_s
|
||||
{
|
||||
GHashTable *commodity_hash;
|
||||
QofBook *book; /* book to which this database and all the prices belong to */
|
||||
QofBook *book; /* book holding this database and all its prices */
|
||||
|
||||
/* 'private' object management fields */
|
||||
gint32 editlevel; /* nesting level of begin/end edit calls */
|
||||
gboolean dirty;
|
||||
};
|
||||
|
||||
|
@ -239,6 +239,88 @@ gnc_price_commit_edit (GNCPrice *p)
|
||||
LEAVE ("pr=%p, not-saved=%d do-free=%d", p, p->not_saved, p->do_free);
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
|
||||
void
|
||||
gnc_pricedb_begin_edit (GNCPriceDB *pdb)
|
||||
{
|
||||
QofBackend *be;
|
||||
|
||||
if (!pdb) return;
|
||||
pdb->editlevel++;
|
||||
if (1 < pdb->editlevel) return;
|
||||
ENTER ("pdb=%p\n", pdb);
|
||||
|
||||
if (0 >= pdb->editlevel)
|
||||
{
|
||||
PERR ("unbalanced call - resetting (was %d)", pdb->editlevel);
|
||||
pdb->editlevel = 1;
|
||||
}
|
||||
|
||||
/* See if there's a backend. If there is, invoke it. */
|
||||
be = xaccPriceDBGetBackend (pdb);
|
||||
if (be && be->begin)
|
||||
{
|
||||
(be->begin) (be, GNC_ID_PRICEDB, pdb);
|
||||
}
|
||||
|
||||
LEAVE ("pdb=%p\n", pdb);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_pricedb_commit_edit (GNCPriceDB *pdb)
|
||||
{
|
||||
QofBackend *be;
|
||||
if (!pdb) return;
|
||||
|
||||
pdb->editlevel--;
|
||||
if (0 < pdb->editlevel) return;
|
||||
|
||||
ENTER ("pdb=%p\n", pdb);
|
||||
if (0 > pdb->editlevel)
|
||||
{
|
||||
PERR ("unbalanced call - resetting (was %d)", pdb->editlevel);
|
||||
pdb->editlevel = 0;
|
||||
}
|
||||
|
||||
/* See if there's a backend. If there is, invoke it. */
|
||||
/* We may not be able to find the backend, so make not of that .. */
|
||||
be = xaccPriceDBGetBackend (pdb);
|
||||
if (be && be->commit)
|
||||
{
|
||||
QofBackendError errcode;
|
||||
|
||||
/* clear errors */
|
||||
do {
|
||||
errcode = qof_backend_get_error (be);
|
||||
} while (ERR_BACKEND_NO_ERR != errcode);
|
||||
|
||||
/* if we haven't been able to call begin edit before, call it now */
|
||||
if (TRUE == pdb->dirty)
|
||||
{
|
||||
if (be->begin)
|
||||
{
|
||||
(be->begin) (be, GNC_ID_PRICEDB, pdb);
|
||||
}
|
||||
}
|
||||
|
||||
(be->commit) (be, GNC_ID_PRICEDB, pdb);
|
||||
errcode = qof_backend_get_error (be);
|
||||
if (ERR_BACKEND_NO_ERR != errcode)
|
||||
{
|
||||
/* XXX hack alert FIXME implement price rollback */
|
||||
PERR (" backend asked engine to rollback, but this isn't"
|
||||
" handled yet. Return code=%d", errcode);
|
||||
|
||||
/* push error back onto the stack */
|
||||
qof_backend_set_error (be, errcode);
|
||||
}
|
||||
}
|
||||
pdb->dirty = FALSE;
|
||||
|
||||
LEAVE ("pdb=%p\n", pdb);
|
||||
}
|
||||
|
||||
/* ==================================================================== */
|
||||
/* setters */
|
||||
|
||||
@ -641,6 +723,8 @@ gnc_pricedb_create(QofBook * book)
|
||||
|
||||
result = g_new0(GNCPriceDB, 1);
|
||||
result->book = book;
|
||||
result->editlevel = 0;
|
||||
result->dirty = FALSE;
|
||||
result->commodity_hash = g_hash_table_new(commodity_hash, commodity_equal);
|
||||
g_return_val_if_fail (result->commodity_hash, NULL);
|
||||
return result;
|
||||
|
@ -1,6 +1,5 @@
|
||||
/********************************************************************
|
||||
* gnc-pricedb.h -- a simple price database for gnucash. *
|
||||
* Copyright (C) 2001 Rob Browning, Linas Vepstas *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -38,7 +37,8 @@
|
||||
@{ */
|
||||
/**********************************************************************/
|
||||
/** @file gnc-pricedb.h
|
||||
|
||||
@author Copyright (C) 2001 Rob Browning
|
||||
@author Copyright (C) 2001,2003 Linas Vepstas <linas@linas.org>
|
||||
@brief a simple price database for gnucash
|
||||
|
||||
The PriceDB is intended to be a database of price quotes, or more
|
||||
@ -202,9 +202,11 @@ gboolean gnc_price_equal(GNCPrice *p1, GNCPrice *p2);
|
||||
/** gnc_price_list_insert - insert a price into the given list, calling
|
||||
gnc_price_ref on it during the process. */
|
||||
gboolean gnc_price_list_insert(GList **prices, GNCPrice *p);
|
||||
|
||||
/** gnc_price_list_remove - remove the price, p, from the given list,
|
||||
calling gnc_price_unref on it during the process. */
|
||||
gboolean gnc_price_list_remove(GList **prices, GNCPrice *p);
|
||||
|
||||
/** gnc_price_list_destroy - destroy the given price list, calling
|
||||
gnc_price_unref on all the prices included in the list. */
|
||||
void gnc_price_list_destroy(GList *prices);
|
||||
@ -242,6 +244,10 @@ GNCPriceDB * gnc_pricedb_get_db(QofBook *book);
|
||||
prices. Other code may still be holding references to them. */
|
||||
void gnc_pricedb_destroy(GNCPriceDB *db);
|
||||
|
||||
/** Used for editing the pricedb en-mass */
|
||||
void gnc_pricedb_begin_edit (GNCPriceDB *);
|
||||
void gnc_pricedb_commit_edit (GNCPriceDB *);
|
||||
|
||||
/** gnc_pricedb_add_price - add a price to the pricedb, you may drop
|
||||
your reference to the price (i.e. call unref) after this
|
||||
succeeds, whenever you're finished with the price. */
|
||||
|
Loading…
Reference in New Issue
Block a user