remove some book-setting craziness

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6190 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas
2001-12-04 07:36:45 +00:00
parent 14e5a14e26
commit 8d3f314e82
6 changed files with 45 additions and 51 deletions

View File

@@ -466,6 +466,13 @@ xaccAccountGetVersion (Account *acc)
return (acc->version);
}
GNCBook *
xaccAccountGetBook (Account *account)
{
if (!account) return NULL;
return account->book;
}
/********************************************************************\
\********************************************************************/

View File

@@ -212,36 +212,6 @@ xaccGroupGetBook (AccountGroup *group)
return group->book;
}
void
xaccGroupSetBook (AccountGroup *group, GNCBook *book)
{
GList *node;
if (!group) return;
group->book = book;
for (node = group->accounts; node; node = node->next)
{
Account *account = node->data;
xaccGroupSetBook (account->children, book);
}
}
GNCBook *
xaccAccountGetBook (Account *account)
{
AccountGroup *group;
if (!account) return NULL;
group = xaccAccountGetParent (account);
if (!group) return NULL;
return group->book;
}
/********************************************************************\
\********************************************************************/
@@ -653,8 +623,6 @@ xaccGroupRemoveAccount (AccountGroup *grp, Account *acc)
xaccFreeAccountGroup (grp);
}
xaccGroupSetBook (acc->children, NULL);
gnc_engine_generate_event (&acc->guid, GNC_EVENT_MODIFY);
}
@@ -716,7 +684,7 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc)
{
xaccGroupRemoveAccount (acc->parent, acc);
/* switch over betwen books, if needed */
/* switch over between books, if needed */
if (grp->book != acc->book)
{
// xxxxxxxxxxxxxxxxxxxxxxx
@@ -728,6 +696,8 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc)
*
* A 'correct' implementation similar to this is in Period.c
* except its for transactions ...
*
* Note also, we need to reparent the children to the new book as well.
*/
PWARN ("reparenting accounts accross books is not correctly supported\n");
@@ -751,8 +721,6 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc)
grp->saved = 0;
xaccGroupSetBook (acc->children, grp->book);
gnc_engine_generate_event (&acc->guid, GNC_EVENT_MODIFY);
}

View File

@@ -61,17 +61,6 @@ struct account_group_s
gint32 editlevel;
};
/*
* The xaccGroupSetBook() routine merely sets the 'book' member
* in the structure above. It does not actually invoke the
* backend to physically move the group from one book to another,
* and thus is a 'dangerous' routine, because it may not have
* the effect that the user was intending (of actually moving
* the book).
*/
void xaccGroupSetBook (AccountGroup *group, GNCBook *book);
/*
* The xaccAccountRemoveGroup() subroutine will remove the indicated
* account group from its parent account. It will NOT free the

View File

@@ -72,6 +72,14 @@ struct gnc_book_struct
Backend *backend;
};
/*
* These gnc_book_set_*() routines are used by backends to
* initialize the pointers in the book structure to
* soemthing that contains actual data. These routines
* should not be used otherwise. (Its somewhat questionable
* if the backends should even be doing this much, but for
* backwards compatibility, we leave these here.)
*/
void gnc_book_set_group(GNCBook *book, AccountGroup *grp);
void gnc_book_set_pricedb(GNCBook *book, GNCPriceDB *db);
void gnc_book_set_schedxactions( GNCBook *book, GList *newList );

View File

@@ -182,13 +182,26 @@ gnc_book_set_group (GNCBook *book, AccountGroup *grp)
if (!book) return;
/* Do not free the old topgroup here unless you also fix
* all the other uses of gnc_book_set_group! */
* all the other uses of gnc_book_set_group!
*/
if (book->topgroup == grp)
return;
xaccGroupSetBook (book->topgroup, NULL);
xaccGroupSetBook (grp, book);
if (grp->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
/* Note: code that used to be here to set/reset the book
* a group belonged to was removed, mostly because it
* was wrong: You can't just change the book a group
* belongs to without also dealing with the entity
* tables. The previous code would have allowed entity
* tables to reside in one book, while the groups were
* in another. Note: please remove this comment sometime
* after gnucash-1.8 goes out.
*/
book->topgroup = grp;
}
@@ -268,8 +281,11 @@ gnc_book_set_template_group (GNCBook *book, AccountGroup *templateGroup)
if (book->template_group == templateGroup)
return;
xaccGroupSetBook (book->template_group, NULL);
xaccGroupSetBook (templateGroup, book);
if (templateGroup->book != book)
{
PERR ("cannot mix and match books freely!");
return;
}
book->template_group = templateGroup;
}

View File

@@ -90,11 +90,14 @@ run_test (void)
gnc_book_set_group (book, group2);
#if 0
/* a group cannot have a 'null' book; this test is nonsense. */
if (!group_has_book (group1, NULL))
{
failure("gnc_book_set_group didn't clear old");
exit(get_rv());
}
#endif
if (!group_has_book (group2, book))
{
@@ -137,11 +140,14 @@ run_test (void)
exit(get_rv());
}
#if 0
/* a group cannot have a 'null' book; this test is nonsense. */
if (!group_has_book (xaccAccountGetParent (account2), NULL))
{
failure("remove group didn't clear book");
exit(get_rv());
}
#endif
}
static void