finish moving commodities, prices and sx out of gnc-book;

finish conversion of above to use the gncObject infrastructure.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8562 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2003-06-10 22:22:47 +00:00
parent a01a217180
commit c30ca9efed
10 changed files with 270 additions and 139 deletions

View File

@ -51,15 +51,18 @@ typedef const char * GNCIdTypeConst;
#define GNC_ID_NONE NULL
#define GNC_ID_ACCOUNT "Account"
#define GNC_ID_BOOK "Book"
#define GNC_ID_COMMODITY_TABLE "CommodityTable"
#define GNC_ID_FREQSPEC "FreqSpec"
#define GNC_ID_GROUP "AccountGroup"
#define GNC_ID_LOT "Lot"
#define GNC_ID_NULL "null"
#define GNC_ID_PERIOD "Period"
#define GNC_ID_PRICE "Price"
#define GNC_ID_PRICEDB "PriceDB"
#define GNC_ID_SPLIT "Split"
#define GNC_ID_SCHEDXACTION "SchedXaction"
#define GNC_ID_SESSION "Session"
#define GNC_ID_SXTT "SXTT"
#define GNC_ID_TRANS "Trans"

View File

@ -1297,7 +1297,6 @@ printf ("duude calling group foreach \n");
static void
group_book_begin (GNCBook *book)
{
printf ("duude call group book begin \n");
xaccSetAccountGroup (book, xaccMallocAccountGroup(book));
}

View File

@ -47,4 +47,6 @@ void gnc_book_set_schedxactions( GNCBook *book, GList *newList );
/* Associate the given template group with a book */
void gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup);
gboolean gnc_sxtt_register (void);
#endif /* GNC_SX_BOOK_P_H */

View File

@ -38,6 +38,7 @@
#include <glib.h>
#include "gncObject.h"
#include "gnc-book.h"
#include "gnc-book-p.h"
#include "gnc-engine.h"
@ -127,4 +128,100 @@ gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup)
xaccAccountGroupDestroy (old_grp);
}
/* ====================================================================== */
/* gncObject function implementation and registration */
/* XXX Its not clear to me if the template group and the sched xactions
* should be treated together or not. I got lazy, and mashed them together.
* For right now, this works. If you feel you need to slit this up into
* two separate gnc Objects, that's OK with me.
*/
static void
sxtt_book_begin (GNCBook *book)
{
gnc_book_set_schedxactions (book, NULL);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
sxtt_book_end (GNCBook *book)
{
gnc_book_set_template_group (book, NULL);
gnc_book_set_schedxactions (book, NULL);
}
/* ====================================================================== */
/* dirty flag stuff */
static void
mark_sx_clean(gpointer data, gpointer user_data)
{
SchedXaction *sx = (SchedXaction *) data;
xaccSchedXactionSetDirtyness(sx, FALSE);
}
static void
book_sxns_mark_saved(GNCBook *book)
{
SchedXactions *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);
}
static gboolean
book_sxlist_notsaved(GNCBook *book)
{
GList *sxlist;
SchedXaction *sx;
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if((sxl && sxl->sx_notsaved)
||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
for(sxlist = gnc_book_get_schedxactions(book);
sxlist != NULL;
sxlist = g_list_next(sxlist))
{
sx = (SchedXaction *) (sxlist->data);
if (xaccSchedXactionIsDirty( sx ))
return TRUE;
}
return FALSE;
}
static void
sxtt_mark_clean(GNCBook *book)
{
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
}
static GncObject_t sxtt_object_def =
{
interface_version: GNC_OBJECT_VERSION,
name: GNC_ID_SXTT,
type_label: "SXTT",
book_begin: sxtt_book_begin,
book_end: sxtt_book_end,
is_dirty: book_sxlist_notsaved,
mark_clean: sxtt_mark_clean,
foreach: NULL,
printable: NULL,
};
gboolean
gnc_sxtt_register (void)
{
return gncObjectRegister (&sxtt_object_def);
}
/* ========================== END OF FILE =============================== */

View File

@ -48,138 +48,11 @@
#include "gnc-book-p.h"
#include "gnc-event.h"
#include "gnc-event-p.h"
#include "gnc-trace.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"
#include "SX-book.h"
#include "SX-book-p.h"
static short module = MOD_ENGINE;
/* ====================================================================== */
/* dirty flag stuff */
/* XXX these need to be moved to gncObject is_dirty/mark_clean() callbacks! */
static void
mark_sx_clean(gpointer data, gpointer user_data)
{
SchedXaction *sx = (SchedXaction *) data;
xaccSchedXactionSetDirtyness(sx, FALSE);
return;
}
static void
book_sxns_mark_saved(GNCBook *book)
{
SchedXactions *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);
return;
}
static gboolean
book_sxlist_notsaved(GNCBook *book)
{
GList *sxlist;
SchedXaction *sx;
SchedXactions *sxl;
sxl = gnc_book_get_schedxaction_list (book);
if((sxl && sxl->sx_notsaved)
||
xaccGroupNotSaved(gnc_book_get_template_group(book))) return TRUE;
for(sxlist = gnc_book_get_schedxactions(book);
sxlist != NULL;
sxlist = g_list_next(sxlist))
{
sx = (SchedXaction *) (sxlist->data);
if (xaccSchedXactionIsDirty( sx ))
return TRUE;
}
return FALSE;
}
void
gnc_book_mark_saved(GNCBook *book)
{
if (!book) return;
book->dirty = FALSE;
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
xaccGroupMarkSaved(gnc_book_get_template_group(book));
book_sxns_mark_saved(book);
/* Mark everything as clean */
gncObjectMarkClean (book);
}
/* ====================================================================== */
/* XXX the following 'populates' need to be moved to GNCObject->book_begin
* callbacks!
*/
static void
gnc_book_populate (GNCBook *book)
{
gnc_commodity_table *ct;
ct = gnc_commodity_table_new ();
if(!gnc_commodity_table_add_default_data(ct))
{
PWARN("unable to initialize book's commodity_table");
}
gnc_commodity_table_set_table (book, ct);
gnc_pricedb_set_db (book, gnc_pricedb_create(book));
gnc_book_set_schedxactions (book, NULL);
gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
}
static void
gnc_book_depopulate (GNCBook *book)
{
/* unhook the prices */
gnc_pricedb_set_db (book, NULL);
gnc_commodity_table_set_table (book, NULL);
gnc_book_set_template_group (book, NULL);
gnc_book_set_schedxactions (book, NULL);
}
/* ====================================================================== */
gboolean
gnc_book_not_saved(GNCBook *book)
{
if (!book) return FALSE;
return(book->dirty
||
gnc_pricedb_dirty(gnc_book_get_pricedb(book))
||
book_sxlist_notsaved(book)
||
gncObjectIsDirty (book));
}
/* ====================================================================== */
/* constructor / destructor */
@ -197,9 +70,6 @@ gnc_book_init (GNCBook *book)
book->data_tables = g_hash_table_new (g_str_hash, g_str_equal);
/* XXX this needs to go away */
gnc_book_populate (book);
book->book_open = 'y';
book->version = 0;
book->idata = 0;
@ -232,9 +102,6 @@ gnc_book_destroy (GNCBook *book)
gncObjectBookEnd (book);
/* XXX this needs to go away */
gnc_book_depopulate (book);
xaccRemoveEntity (book->entity_table, &book->guid);
xaccEntityTableDestroy (book->entity_table);
book->entity_table = NULL;
@ -259,6 +126,25 @@ gnc_book_equal (GNCBook *book_1, GNCBook *book_2)
return TRUE;
}
/* ====================================================================== */
gboolean
gnc_book_not_saved(GNCBook *book)
{
if (!book) return FALSE;
return(book->dirty || gncObjectIsDirty (book));
}
void
gnc_book_mark_saved(GNCBook *book)
{
if (!book) return;
book->dirty = FALSE;
gncObjectMarkClean (book);
}
/* ====================================================================== */
/* getters */

View File

@ -1,7 +1,7 @@
/********************************************************************
* gnc-commodity.c -- api for tradable commodities (incl. currency) *
* Copyright (C) 2000 Bill Gribble *
* Copyright (C) 2001 Linas Vepstas <linas@linas.org> *
* Copyright (C) 2001,2003 Linas Vepstas <linas@linas.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -31,19 +31,22 @@
#include <stdio.h>
#include <glib.h>
#include "gncObject.h"
#include "gnc-book.h"
#include "gnc-commodity.h"
#include "gnc-engine-util.h"
#include "gnc-trace.h"
#include "guid.h"
static short module = MOD_ENGINE;
/* parts per unit is nominal, i.e. number of 'partname' units in
/* Parts per unit is nominal, i.e. number of 'partname' units in
* a 'unitname' unit. fraction is transactional, i.e. how many
* of the smallest-transactional-units of the currency are there
* in a 'unitname' unit. */
struct gnc_commodity_s {
struct gnc_commodity_s
{
char * fullname;
char * namespace;
char * mnemonic;
@ -1094,4 +1097,67 @@ gnc_commodity_table_add_default_data(gnc_commodity_table *table)
return TRUE;
}
/********************************************************************
********************************************************************/
/* gncObject function implementation and registration */
static void
commodity_table_foreach (GNCBook *book, foreachObjectCB cb, gpointer ud)
{
// GNCEntityTable *et;
g_return_if_fail (book);
g_return_if_fail (cb);
printf ("duude calling commodity_table foreach \n");
/*
et = gnc_book_get_entity_table (book);
xaccForeachEntity (et, GNC_ID_COMMODITY, cb, ud);
*/
}
static void
commodity_table_book_begin (GNCBook *book)
{
gnc_commodity_table *ct;
printf ("duude call commodity_table book begin \n");
ct = gnc_commodity_table_new ();
if(!gnc_commodity_table_add_default_data(ct))
{
PWARN("unable to initialize book's commodity_table");
}
gnc_commodity_table_set_table (book, ct);
}
static void
commodity_table_book_end (GNCBook *book)
{
gnc_commodity_table_set_table (book, NULL);
}
/* XXX Why is the commodity table never marked dirty/clean?
* Don't we have to save user-created/modified commodities?
* I don't get it ... does this need fixing?
*/
static GncObject_t commodity_table_object_def =
{
interface_version: GNC_OBJECT_VERSION,
name: GNC_ID_COMMODITY_TABLE,
type_label: "CommodityTable",
book_begin: commodity_table_book_begin,
book_end: commodity_table_book_end,
is_dirty: NULL,
mark_clean: NULL,
foreach: commodity_table_foreach,
printable: NULL,
};
gboolean
gnc_commodity_table_register (void)
{
return gncObjectRegister (&commodity_table_object_def);
}
/* ========================= END OF FILE ============================== */

View File

@ -431,6 +431,12 @@ gnc_commodity_table * gnc_commodity_table_get_table(GNCBook *book);
*/
void gnc_commodity_table_set_table(GNCBook *book, gnc_commodity_table *ct);
/** You should probably not be using gnc_commodity_table_register()
* It is an internal routine for registering the gncObject for the
* commodity table.
*/
gboolean gnc_commodity_table_register (void);
/** @} */

View File

@ -33,9 +33,12 @@
#include "AccountP.h"
#include "GroupP.h"
#include "SX-book-p.h"
#include "TransactionP.h"
#include "gnc-book-p.h"
#include "gnc-commodity.h"
#include "gnc-lot-p.h"
#include "gnc-pricedb-p.h"
static GList * engine_init_hooks = NULL;
static int engine_is_initialized = 0;
@ -85,6 +88,9 @@ gnc_engine_init(int argc, char ** argv)
xaccTransRegister ();
xaccAccountRegister ();
xaccGroupRegister ();
gnc_sxtt_register ();
gnc_pricedb_register ();
gnc_commodity_table_register();
gnc_book_register ();
gnc_lot_register ();

View File

@ -1,6 +1,7 @@
/********************************************************************
* gnc-pricedb-p.h -- a simple price database for gnucash. *
* Copyright (C) 2001 Rob Browning *
* Copyright (C) 2003 Linas Vepstas <linas@linas.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -102,5 +103,7 @@ void gnc_pricedb_substitute_commodity(GNCPriceDB *db,
gnc_commodity *new_c);
void gnc_price_set_guid (GNCPrice *p, const GUID *guid);
/** register the pricedb object with the gncObject system */
gboolean gnc_pricedb_register (void);
#endif

View File

@ -29,10 +29,11 @@
#include "BackendP.h"
#include "GNCIdP.h"
#include "gncObject.h"
#include "gnc-book-p.h"
#include "gnc-book-p.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-book-p.h"
#include "gnc-event-p.h"
#include "gnc-pricedb-p.h"
#include "guid.h"
@ -1911,4 +1912,66 @@ gnc_pricedb_print_contents(GNCPriceDB *db, FILE *f)
fprintf(f, "</gnc:pricedb>\n");
}
/* ==================================================================== */
/* gncObject function implementation and registration */
static void
pricedb_foreach (GNCBook *book, foreachObjectCB cb, gpointer ud)
{
// GNCEntityTable *et;
g_return_if_fail (book);
g_return_if_fail (cb);
printf ("duude calling pricedb foreach \n");
/*
et = gnc_book_get_entity_table (book);
xaccForeachEntity (et, GNC_ID_PRICEDB, cb, ud);
*/
}
static void
pricedb_book_begin (GNCBook *book)
{
gnc_pricedb_set_db (book, gnc_pricedb_create(book));
}
static void
pricedb_book_end (GNCBook *book)
{
/* unhook the prices */
gnc_pricedb_set_db (book, NULL);
}
static gboolean
pricedb_is_dirty (GNCBook *book)
{
return gnc_pricedb_dirty(gnc_book_get_pricedb(book));
}
static void
pricedb_mark_clean(GNCBook *book)
{
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
}
static GncObject_t pricedb_object_def =
{
interface_version: GNC_OBJECT_VERSION,
name: GNC_ID_PRICEDB,
type_label: "PriceDB",
book_begin: pricedb_book_begin,
book_end: pricedb_book_end,
is_dirty: pricedb_is_dirty,
mark_clean: pricedb_mark_clean,
foreach: pricedb_foreach,
printable: NULL,
};
gboolean
gnc_pricedb_register (void)
{
return gncObjectRegister (&pricedb_object_def);
}
/* ========================= END OF FILE ============================== */