rework how scheduled xactions are handled inside the book,

in preparation for removal.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8536 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-06-10 05:13:13 +00:00
parent 4716e80539
commit 7a5e046a01
2 changed files with 54 additions and 23 deletions

View File

@ -44,7 +44,6 @@ struct gnc_book_struct
/* The kvp_frame provides a place for top-level data associated
* with this book. */
kvp_frame *kvp_data;
gboolean dirty;
/* The entity table associates the GUIDs of all the objects
* belonging to this book, with their pointers to the respective
@ -52,8 +51,6 @@ struct gnc_book_struct
*/
GNCEntityTable *entity_table;
gboolean sx_notsaved; /* true if sched_xactions is changed */
/* In order to store arbitrary data, for extensibility, add a table
* that will be used to hold arbitrary pointers.
*/
@ -64,6 +61,11 @@ struct gnc_book_struct
*/
char book_open;
/* dirty/clean flag. If dirty, then this book has been modified,
* but has not yet been written out to storage (file/database)
*/
gboolean dirty;
/* version number, used for tracking multiuser updates */
gint32 version;
@ -88,7 +90,6 @@ struct gnc_book_struct
*/
void gnc_book_set_guid(GNCBook *book, GUID guid);
void gnc_book_set_schedxactions( GNCBook *book, GList *newList );
void gnc_book_set_template_group( GNCBook *book, AccountGroup *templateGroup );
void gnc_book_set_backend (GNCBook *book, Backend *be);

View File

@ -46,41 +46,66 @@
#include "Backend.h"
#include "BackendP.h"
#include "GroupP.h"
#include "QueryObject.h"
#include "SchedXaction.h"
#include "TransLog.h"
#include "engine-helpers.h"
#include "gnc-book.h"
#include "gnc-book-p.h"
#include "gnc-date.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-event.h"
#include "gnc-event-p.h"
#include "gnc-module.h"
#include "gnc-pricedb-p.h"
#include "gncObjectP.h"
/* remove these when finished */
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "GroupP.h"
#include "gnc-pricedb-p.h"
#include "SchedXaction.h"
#include "SchedXactionP.h"
static short module = MOD_ENGINE;
/* ====================================================================== */
typedef struct xaccSchedXactionListDef {
GNCBook *book;
GList *sx_list;
gboolean sx_notsaved;
} SchedXactionList;
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
GList *
gnc_book_get_schedxactions( GNCBook *book )
static SchedXactionList *
gnc_book_get_schedxaction_list( GNCBook *book )
{
if ( book == NULL ) return NULL;
return gnc_book_get_data (book, GNC_SCHEDXACTIONS);
}
GList *
gnc_book_get_schedxactions( GNCBook *book )
{
SchedXactionList *list;
if ( book == NULL ) return NULL;
list = gnc_book_get_data (book, GNC_SCHEDXACTIONS);
return list->sx_list;
}
void
gnc_book_set_schedxactions( GNCBook *book, GList *newList )
{
SchedXactionList *old_list, *new_list;
if ( book == NULL ) return;
gnc_book_set_data (book, GNC_SCHEDXACTIONS, newList);
book->sx_notsaved = TRUE;
old_list = gnc_book_get_data (book, GNC_SCHEDXACTIONS);
if (old_list->sx_list == newList) return;
new_list = g_new (SchedXactionList, 1);
new_list->sx_notsaved = TRUE;
new_list->book = book;
new_list->sx_list = newList;
gnc_book_set_data (book, GNC_SCHEDXACTIONS, new_list);
g_free (old_list);
}
/* ====================================================================== */
@ -97,7 +122,10 @@ mark_sx_clean(gpointer data, gpointer user_data)
static void
book_sxns_mark_saved(GNCBook *book)
{
book->sx_notsaved = FALSE;
SchedXactionList *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if (sxl) sxl->sx_notsaved = FALSE;
g_list_foreach(gnc_book_get_schedxactions(book),
mark_sx_clean,
NULL);
@ -109,7 +137,10 @@ book_sxlist_notsaved(GNCBook *book)
{
GList *sxlist;
SchedXaction *sx;
if(book->sx_notsaved
SchedXactionList *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if((sxl && sxl->sx_notsaved)
||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
@ -160,8 +191,7 @@ gnc_book_populate (GNCBook *book)
gnc_pricedb_set_db (book, gnc_pricedb_create(book));
gnc_book_set_schedxactions (book,NULL);
book->sx_notsaved = FALSE;
gnc_book_set_schedxactions (book, NULL);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
@ -178,7 +208,8 @@ gnc_book_depopulate (GNCBook *book)
gnc_commodity_table_set_table (book, NULL);
gnc_book_set_template_group (book, NULL);
/* FIXME: destroy SX data members here, too */
gnc_book_set_schedxactions (book, NULL);
}
/* ====================================================================== */
@ -372,8 +403,7 @@ gnc_book_equal (GNCBook *book_1, GNCBook *book_2)
/* ====================================================================== */
/* Store arbitrary pointers in the GNCBook for data storage extensibility */
/* XXX if data is NULL, should we store a null pointer, or should
* we remove the key from the hash table?
/* XXX if data is NULL, we ashould remove the key from the hash table!
*/
void
gnc_book_set_data (GNCBook *book, const char *key, gpointer data)