mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
remove account group from book structure
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8527 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* Group.c -- chart of accounts (hierarchical tree of accounts) *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997-2001 Linas Vepstas <linas@linas.org> *
|
||||
* Copyright (C) 1997-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 *
|
||||
@@ -81,6 +81,39 @@ xaccMallocAccountGroup (GNCBook *book)
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
#define GNC_TOP_GROUP "gnc_top_group"
|
||||
AccountGroup *
|
||||
xaccGetAccountGroup (GNCBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
return gnc_book_get_data (book, GNC_TOP_GROUP);
|
||||
}
|
||||
|
||||
void
|
||||
xaccSetAccountGroup (GNCBook *book, AccountGroup *grp)
|
||||
{
|
||||
if (!book) return;
|
||||
|
||||
/* XXX Do not free the old topgroup here unless you also fix
|
||||
* all the other uses of gnc_book_set_group! That's because
|
||||
* the account group is not reference-counted, and there's some
|
||||
* chance that we'll leave a dangling pointer somewhere.
|
||||
*/
|
||||
|
||||
if (gnc_book_get_group (book) == grp) return;
|
||||
|
||||
if (grp && grp->book != book)
|
||||
{
|
||||
PERR ("cannot mix and match books freely!");
|
||||
return;
|
||||
}
|
||||
|
||||
gnc_book_set_data (book, GNC_TOP_GROUP, grp);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
gboolean
|
||||
xaccGroupEqual(AccountGroup *ga,
|
||||
AccountGroup *gb,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* Group.h -- chart of accounts (hierarchical tree of accounts) *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
|
||||
* Copyright (C) 1997-2000,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 *
|
||||
@@ -34,15 +34,31 @@
|
||||
|
||||
|
||||
/** PROTOTYPES ******************************************************/
|
||||
/*
|
||||
* The xaccMallocAccountGroup() routine will create a new account group.
|
||||
* This is an internal-use function, you almost certainly want to
|
||||
* be using the xaccGetAccountGroup() routine instead.
|
||||
*/
|
||||
AccountGroup *xaccMallocAccountGroup (GNCBook *book);
|
||||
|
||||
/*
|
||||
* The xaccGetAccountGroup() routine will return the top-most
|
||||
* account group associated with the indicated book.
|
||||
*/
|
||||
AccountGroup * xaccGetAccountGroup (GNCBook *book);
|
||||
|
||||
/*
|
||||
* The xaccAccountDestroy() routine will destroy and free all
|
||||
* the data associated with this account group. The group
|
||||
* must have been opened for editing with
|
||||
* xaccAccountGroupBeginEdit() first, before the Destroy is called.
|
||||
*/
|
||||
AccountGroup *xaccMallocAccountGroup (GNCBook *book);
|
||||
void xaccAccountGroupDestroy (AccountGroup *grp);
|
||||
|
||||
|
||||
/* XXX backwards-compat define, remove at later convenience */
|
||||
#define gnc_book_get_group xaccGetAccountGroup
|
||||
|
||||
GNCBook * xaccGroupGetBook (AccountGroup *group);
|
||||
|
||||
void xaccAccountGroupBeginEdit (AccountGroup *grp);
|
||||
|
||||
@@ -94,4 +94,7 @@ void xaccGroupRemoveAccount (AccountGroup *grp, Account *account);
|
||||
*/
|
||||
void xaccFreeAccountGroup (AccountGroup *account_group);
|
||||
|
||||
/* Set the top-level group in the book */
|
||||
void xaccSetAccountGroup (GNCBook *book, AccountGroup *grp);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -87,7 +87,6 @@ struct gnc_book_struct
|
||||
* backwards compatibility, we leave these here.)
|
||||
*/
|
||||
void gnc_book_set_guid(GNCBook *book, GUID guid);
|
||||
void gnc_book_set_group(GNCBook *book, AccountGroup *grp);
|
||||
void gnc_book_set_schedxactions( GNCBook *book, GList *newList );
|
||||
void gnc_book_set_template_group( GNCBook *book, AccountGroup *templateGroup );
|
||||
|
||||
|
||||
@@ -66,39 +66,6 @@ static short module = MOD_ENGINE;
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
#define GNC_TOP_GROUP "gnc_top_group"
|
||||
AccountGroup *
|
||||
gnc_book_get_group (GNCBook *book)
|
||||
{
|
||||
if (!book) return NULL;
|
||||
printf ("duude get topgrp\n");
|
||||
return gnc_book_get_data (book, GNC_TOP_GROUP);
|
||||
}
|
||||
|
||||
void
|
||||
gnc_book_set_group (GNCBook *book, AccountGroup *grp)
|
||||
{
|
||||
if (!book) return;
|
||||
|
||||
/* XXX Do not free the old topgroup here unless you also fix
|
||||
* all the other uses of gnc_book_set_group! That's because
|
||||
* the account group is not reference-counted, and there's some
|
||||
* chance that we'll leave a dangling pointer somewhere.
|
||||
*/
|
||||
|
||||
if (gnc_book_get_group (book) == grp) return;
|
||||
|
||||
if (grp && grp->book != book)
|
||||
{
|
||||
PERR ("cannot mix and match books freely!");
|
||||
return;
|
||||
}
|
||||
|
||||
gnc_book_set_data (book, GNC_TOP_GROUP, grp);
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
#define GNC_SCHEDXACTIONS "gnc_schedxactions"
|
||||
GList *
|
||||
gnc_book_get_schedxactions( GNCBook *book )
|
||||
@@ -189,7 +156,7 @@ gnc_book_mark_saved(GNCBook *book)
|
||||
|
||||
book->dirty = FALSE;
|
||||
|
||||
xaccGroupMarkSaved(gnc_book_get_group(book));
|
||||
xaccGroupMarkSaved(xaccGetAccountGroup(book));
|
||||
gnc_pricedb_mark_clean(gnc_pricedb_get_db(book));
|
||||
|
||||
xaccGroupMarkSaved(gnc_book_get_template_group(book));
|
||||
@@ -201,6 +168,24 @@ gnc_book_mark_saved(GNCBook *book)
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
static gboolean
|
||||
counter_thunk(Transaction *t, void *data)
|
||||
{
|
||||
(*((guint*)data))++;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
guint
|
||||
gnc_book_count_transactions(GNCBook *book)
|
||||
{
|
||||
guint count = 0;
|
||||
xaccGroupForEachTransaction(xaccGetAccountGroup(book),
|
||||
counter_thunk, (void*)&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
static void
|
||||
gnc_book_populate (GNCBook *book)
|
||||
{
|
||||
@@ -213,7 +198,7 @@ gnc_book_populate (GNCBook *book)
|
||||
}
|
||||
gnc_commodity_table_set_table (book, ct);
|
||||
|
||||
gnc_book_set_group (book, xaccMallocAccountGroup(book));
|
||||
xaccSetAccountGroup (book, xaccMallocAccountGroup(book));
|
||||
|
||||
gnc_pricedb_set_db (book, gnc_pricedb_create(book));
|
||||
|
||||
@@ -230,10 +215,10 @@ gnc_book_depopulate (GNCBook *book)
|
||||
gnc_commodity_table *ct;
|
||||
|
||||
/* unhook the top-level group */
|
||||
grp = gnc_book_get_group (book);
|
||||
grp = xaccGetAccountGroup (book);
|
||||
xaccAccountGroupBeginEdit (grp);
|
||||
xaccAccountGroupDestroy (grp);
|
||||
gnc_book_set_group (book, NULL);
|
||||
xaccSetAccountGroup (book, NULL);
|
||||
|
||||
/* unhook the prices */
|
||||
gnc_pricedb_set_db (book, NULL);
|
||||
@@ -254,7 +239,7 @@ gnc_book_not_saved(GNCBook *book)
|
||||
|
||||
return(book->dirty
|
||||
||
|
||||
xaccGroupNotSaved(gnc_book_get_group(book))
|
||||
xaccGroupNotSaved(xaccGetAccountGroup(book))
|
||||
||
|
||||
gnc_pricedb_dirty(gnc_book_get_pricedb(book))
|
||||
||
|
||||
@@ -406,8 +391,8 @@ gnc_book_equal (GNCBook *book_1, GNCBook *book_2)
|
||||
if (book_1 == book_2) return TRUE;
|
||||
if (!book_1 || !book_2) return FALSE;
|
||||
|
||||
if (!xaccGroupEqual (gnc_book_get_group (book_1),
|
||||
gnc_book_get_group (book_2),
|
||||
if (!xaccGroupEqual (xaccGetAccountGroup (book_1),
|
||||
xaccGetAccountGroup (book_2),
|
||||
TRUE))
|
||||
{
|
||||
PWARN ("groups differ");
|
||||
@@ -455,24 +440,6 @@ gnc_book_get_data (GNCBook *book, const char *key)
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
static gboolean
|
||||
counter_thunk(Transaction *t, void *data)
|
||||
{
|
||||
(*((guint*)data))++;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
guint
|
||||
gnc_book_count_transactions(GNCBook *book)
|
||||
{
|
||||
guint count = 0;
|
||||
xaccGroupForEachTransaction(gnc_book_get_group(book),
|
||||
counter_thunk, (void*)&count);
|
||||
return count;
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
|
||||
gint64
|
||||
gnc_book_get_counter (GNCBook *book, const char *counter_name)
|
||||
{
|
||||
|
||||
@@ -55,9 +55,6 @@ const GUID * gnc_book_get_guid (GNCBook *book);
|
||||
/** \return The kvp data for the book */
|
||||
kvp_frame * gnc_book_get_slots (GNCBook *book);
|
||||
|
||||
/** \return The top-level group in the book.*/
|
||||
AccountGroup * gnc_book_get_group (GNCBook *book);
|
||||
|
||||
/** \return A GList of the scheduled transactions in the book. */
|
||||
GList * gnc_book_get_schedxactions( GNCBook *book );
|
||||
|
||||
|
||||
@@ -68,13 +68,13 @@ run_test (void)
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
/* this test is testing routines that are private
|
||||
/* This test is testing routines that are private
|
||||
* to the engine. these tests are intended to test
|
||||
* the engine as a whole, not just the public
|
||||
* interface. the maintenance of the correct
|
||||
* book pointers is important for correct
|
||||
* engine operation. */
|
||||
gnc_book_set_group (book, group1);
|
||||
xaccSetAccountGroup (book, group1);
|
||||
if (!group_has_book (group1, book))
|
||||
{
|
||||
failure("gnc_book_set_group didn't take");
|
||||
@@ -88,7 +88,7 @@ run_test (void)
|
||||
exit(get_rv());
|
||||
}
|
||||
|
||||
gnc_book_set_group (book, group2);
|
||||
xaccSetAccountGroup (book, group2);
|
||||
|
||||
#if 0
|
||||
/* a group cannot have a 'null' book; this test is nonsense. */
|
||||
|
||||
Reference in New Issue
Block a user