r15066 - gnucash/branches/remove-group2 - Rebase the remove group changes on a branch pulled after the
David Hampton
hampton at cvs.gnucash.org
Tue Oct 31 19:01:46 EST 2006
Author: hampton
Date: 2006-10-31 19:01:35 -0500 (Tue, 31 Oct 2006)
New Revision: 15066
Trac: http://svn.gnucash.org/trac/changeset/15066
Removed:
gnucash/branches/remove-group2/src/backend/file/io-gncbin-r.c
gnucash/branches/remove-group2/src/backend/file/io-gncbin.h
gnucash/branches/remove-group2/src/engine/Group.c
gnucash/branches/remove-group2/src/engine/Group.h
gnucash/branches/remove-group2/src/engine/GroupP.h
Modified:
gnucash/branches/remove-group2/ChangeLog
gnucash/branches/remove-group2/gnucash.m4
gnucash/branches/remove-group2/lib/libqof/backend/file/qof-backend-qsf.h
gnucash/branches/remove-group2/lib/libqof/qof/qofinstance-p.h
gnucash/branches/remove-group2/lib/libqof/qof/qofinstance.h
gnucash/branches/remove-group2/lib/libqof/qof/qofsession.h
gnucash/branches/remove-group2/src/app-utils/app-utils.i
gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.c
gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.h
gnucash/branches/remove-group2/src/app-utils/gnc-component-manager.c
gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.c
gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.h
gnucash/branches/remove-group2/src/app-utils/guile-util.h
gnucash/branches/remove-group2/src/app-utils/options.scm
gnucash/branches/remove-group2/src/backend/file/gnc-account-xml-v2.c
gnucash/branches/remove-group2/src/backend/file/gnc-book-xml-v2.c
gnucash/branches/remove-group2/src/backend/file/gnc-commodity-xml-v2.c
gnucash/branches/remove-group2/src/backend/file/gnc-schedxaction-xml-v2.c
gnucash/branches/remove-group2/src/backend/file/io-example-account.c
gnucash/branches/remove-group2/src/backend/file/io-example-account.h
gnucash/branches/remove-group2/src/backend/file/io-gncxml-v1.c
gnucash/branches/remove-group2/src/backend/file/io-gncxml-v2.c
gnucash/branches/remove-group2/src/backend/file/io-utils.c
gnucash/branches/remove-group2/src/backend/file/io-utils.h
gnucash/branches/remove-group2/src/backend/file/test/test-load-xml2.c
gnucash/branches/remove-group2/src/backend/file/test/test-xml-account.c
gnucash/branches/remove-group2/src/backend/file/test/test-xml-transaction.c
gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.c
gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.h
gnucash/branches/remove-group2/src/backend/postgres/account.c
gnucash/branches/remove-group2/src/backend/postgres/account.h
gnucash/branches/remove-group2/src/backend/postgres/checkpoint.c
gnucash/branches/remove-group2/src/backend/postgres/checkpoint.h
gnucash/branches/remove-group2/src/backend/postgres/events.c
gnucash/branches/remove-group2/src/backend/postgres/table.m4
gnucash/branches/remove-group2/src/backend/postgres/test/test-db.c
gnucash/branches/remove-group2/src/backend/postgres/test/test-period.c
gnucash/branches/remove-group2/src/backend/postgres/txn.c
gnucash/branches/remove-group2/src/backend/postgres/txn.h
gnucash/branches/remove-group2/src/backend/postgres/txnmass.c
gnucash/branches/remove-group2/src/business/business-core/gncInvoice.c
gnucash/branches/remove-group2/src/business/business-gnome/business-gnome-utils.c
gnucash/branches/remove-group2/src/business/business-gnome/dialog-payment.c
gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-business.c
gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-page-invoice.c
gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedger.c
gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedgerLoad.c
gnucash/branches/remove-group2/src/business/business-reports/owner-report.scm
gnucash/branches/remove-group2/src/engine/Account.c
gnucash/branches/remove-group2/src/engine/Account.h
gnucash/branches/remove-group2/src/engine/AccountP.h
gnucash/branches/remove-group2/src/engine/Makefile.am
gnucash/branches/remove-group2/src/engine/Period.c
gnucash/branches/remove-group2/src/engine/SX-book-p.h
gnucash/branches/remove-group2/src/engine/SX-book.c
gnucash/branches/remove-group2/src/engine/SX-book.h
gnucash/branches/remove-group2/src/engine/SchedXaction.c
gnucash/branches/remove-group2/src/engine/Scrub.c
gnucash/branches/remove-group2/src/engine/Scrub.h
gnucash/branches/remove-group2/src/engine/Scrub2.c
gnucash/branches/remove-group2/src/engine/Scrub3.c
gnucash/branches/remove-group2/src/engine/Scrub3.h
gnucash/branches/remove-group2/src/engine/ScrubP.h
gnucash/branches/remove-group2/src/engine/Split.c
gnucash/branches/remove-group2/src/engine/TransLog.c
gnucash/branches/remove-group2/src/engine/Transaction.c
gnucash/branches/remove-group2/src/engine/Transaction.h
gnucash/branches/remove-group2/src/engine/cap-gains.c
gnucash/branches/remove-group2/src/engine/cashobjects.c
gnucash/branches/remove-group2/src/engine/engine-helpers.c
gnucash/branches/remove-group2/src/engine/engine-utilities.scm
gnucash/branches/remove-group2/src/engine/engine.i
gnucash/branches/remove-group2/src/engine/engine.scm
gnucash/branches/remove-group2/src/engine/gnc-associate-account.c
gnucash/branches/remove-group2/src/engine/gnc-budget.c
gnucash/branches/remove-group2/src/engine/gnc-engine.c
gnucash/branches/remove-group2/src/engine/gnc-engine.h
gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.c
gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.h
gnucash/branches/remove-group2/src/engine/test/test-create-account.scm
gnucash/branches/remove-group2/src/engine/test/test-group-vs-book.c
gnucash/branches/remove-group2/src/engine/test/test-lots.c
gnucash/branches/remove-group2/src/engine/test/test-period.c
gnucash/branches/remove-group2/src/engine/test/test-query.c
gnucash/branches/remove-group2/src/experimental/cgi-bin/gnc-server.c
gnucash/branches/remove-group2/src/experimental/cgi-bin/hello2.c
gnucash/branches/remove-group2/src/experimental/cgi-bin/hello3.c
gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.c
gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.h
gnucash/branches/remove-group2/src/gnome-utils/dialog-account.c
gnucash/branches/remove-group2/src/gnome-utils/dialog-account.h
gnucash/branches/remove-group2/src/gnome-utils/dialog-transfer.c
gnucash/branches/remove-group2/src/gnome-utils/dialog-utils.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-account-sel.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-file.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-html.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.h
gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model.h
gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.c
gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.h
gnucash/branches/remove-group2/src/gnome-utils/window-main-summarybar.c
gnucash/branches/remove-group2/src/gnome/dialog-commodities.c
gnucash/branches/remove-group2/src/gnome/dialog-find-transactions.c
gnucash/branches/remove-group2/src/gnome/dialog-sxsincelast.c
gnucash/branches/remove-group2/src/gnome/druid-acct-period.c
gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c
gnucash/branches/remove-group2/src/gnome/druid-merge.c
gnucash/branches/remove-group2/src/gnome/druid-merge.h
gnucash/branches/remove-group2/src/gnome/druid-stock-split.c
gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-account-tree.c
gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-register.c
gnucash/branches/remove-group2/src/gnome/gnc-split-reg.c
gnucash/branches/remove-group2/src/gnome/reconcile-list.c
gnucash/branches/remove-group2/src/gnome/top-level.c
gnucash/branches/remove-group2/src/gnome/window-reconcile.c
gnucash/branches/remove-group2/src/import-export/binary-import/druid-commodity.c
gnucash/branches/remove-group2/src/import-export/hbci/druid-hbci-utils.c
gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-gettrans.c
gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-transfer.c
gnucash/branches/remove-group2/src/import-export/import-account-matcher.c
gnucash/branches/remove-group2/src/import-export/import-backend.c
gnucash/branches/remove-group2/src/import-export/import-match-map.c
gnucash/branches/remove-group2/src/import-export/ofx/gnc-ofx-import.c
gnucash/branches/remove-group2/src/import-export/qif-import/druid-qif-import.c
gnucash/branches/remove-group2/src/import-export/qif-import/qif-dialog-utils.scm
gnucash/branches/remove-group2/src/import-export/qif-import/qif-guess-map.scm
gnucash/branches/remove-group2/src/import-export/qif-import/qif-import.scm
gnucash/branches/remove-group2/src/import-export/qif-import/qif-merge-groups.scm
gnucash/branches/remove-group2/src/import-export/qif-import/qif-to-gnc.scm
gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-acct-table.scm
gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-io-core.scm
gnucash/branches/remove-group2/src/import-export/qif-io-core/test/test-import-phase-1.scm
gnucash/branches/remove-group2/src/register/ledger-core/gnc-ledger-display.c
gnucash/branches/remove-group2/src/register/ledger-core/split-register-control.c
gnucash/branches/remove-group2/src/register/ledger-core/split-register-load.c
gnucash/branches/remove-group2/src/register/ledger-core/split-register-model.c
gnucash/branches/remove-group2/src/register/ledger-core/split-register-p.h
gnucash/branches/remove-group2/src/register/ledger-core/split-register.c
gnucash/branches/remove-group2/src/register/ledger-core/split-register.h
gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf-de_DE.scm
gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf.scm
gnucash/branches/remove-group2/src/report/report-system/commodity-utilities.scm
gnucash/branches/remove-group2/src/report/report-system/html-acct-table.scm
gnucash/branches/remove-group2/src/report/report-system/html-utilities.scm
gnucash/branches/remove-group2/src/report/report-system/report-system.scm
gnucash/branches/remove-group2/src/report/report-system/report-utilities.scm
gnucash/branches/remove-group2/src/report/standard-reports/account-piecharts.scm
gnucash/branches/remove-group2/src/report/standard-reports/account-summary.scm
gnucash/branches/remove-group2/src/report/standard-reports/advanced-portfolio.scm
gnucash/branches/remove-group2/src/report/standard-reports/average-balance.scm
gnucash/branches/remove-group2/src/report/standard-reports/balance-sheet.scm
gnucash/branches/remove-group2/src/report/standard-reports/budget.scm
gnucash/branches/remove-group2/src/report/standard-reports/cash-flow.scm
gnucash/branches/remove-group2/src/report/standard-reports/category-barchart.scm
gnucash/branches/remove-group2/src/report/standard-reports/daily-reports.scm
gnucash/branches/remove-group2/src/report/standard-reports/equity-statement.scm
gnucash/branches/remove-group2/src/report/standard-reports/general-journal.scm
gnucash/branches/remove-group2/src/report/standard-reports/income-statement.scm
gnucash/branches/remove-group2/src/report/standard-reports/net-barchart.scm
gnucash/branches/remove-group2/src/report/standard-reports/portfolio.scm
gnucash/branches/remove-group2/src/report/standard-reports/price-scatter.scm
gnucash/branches/remove-group2/src/report/standard-reports/transaction.scm
gnucash/branches/remove-group2/src/report/standard-reports/trial-balance.scm
gnucash/branches/remove-group2/src/scm/price-quotes.scm
Log:
Rebase the remove group changes on a branch pulled after the
gwrap -> swig changeover.
Modified: gnucash/branches/remove-group2/ChangeLog
===================================================================
--- gnucash/branches/remove-group2/ChangeLog 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/ChangeLog 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,3 +1,40 @@
+2006-10-31 David Hampton <hampton at employees.org>
+
+ * Changes ported from the remove-group branch to the remove-group2
+ branch. (The latter was pulled after the swig changeover.)
+
+2006-08-22 David Hampton <hampton at employees.org>
+
+ * src/app-utils/gnc-account-merge.c: Merge account trees properly.
+
+ * src/backend/file/io-gncxml-v2.c:
+ * src/engine/Account.c: Make sure the root account exists when the
+ code asks for it. This works both for reading a new file and a
+ user performing File->New->New File.
+
+ * src/gnome-utils/gnc-tree-model-account.c: Fix a mistake in the
+ updated tree model.
+
+ * src/backend/file/gnc-account-xml-v2.c:
+ * src/backend/file/io-gncxml-v2.c:
+ * src/engine/Account.[ch]:
+ * src/engine/Scrub.c: Don't require the root account to have a
+ commodity.
+
+2006-08-21 David Hampton <hampton at employees.org>
+
+ * src/engine/Account.[ch]:
+ * src/engine/SX-book.[ch]:
+ * src/engine/SX-book-p.h: Mark a couple of functions as static.
+
+ * numerous: Initial removal of the engine Group.h, GroupP.h, and
+ Group.c files. This completely removes the AccountGroup data
+ structure.
+
+======================================================================
+ The remove-group2 branch ChangeLog is above this point.
+======================================================================
+
2006-10-09 Josh Sled <jsled at asynchronous.org>
* art/: Add, with 2.0 {banner,icon,logo,splash} art.
Modified: gnucash/branches/remove-group2/gnucash.m4
===================================================================
--- gnucash/branches/remove-group2/gnucash.m4 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/gnucash.m4 2006-11-01 00:01:35 UTC (rev 15066)
@@ -83,7 +83,6 @@
#include <stdlib.h>
#include <gnc-engine.h>
-#include <Group.h>
int
main ()
Modified: gnucash/branches/remove-group2/lib/libqof/backend/file/qof-backend-qsf.h
===================================================================
--- gnucash/branches/remove-group2/lib/libqof/backend/file/qof-backend-qsf.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/lib/libqof/backend/file/qof-backend-qsf.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -61,8 +61,7 @@
QSF itself is now being built into the QOF library for use with pilot-link to allow
Palm objects to be described in QOF, written to XML as QSF and imported directly into
GnuCash and other QOF-compliant applications. As a generic format, it does not depend
-on any pre-defined objects - as the current GnuCash XML format depends on AccountGroup.
-Instead, QSF is a simple container for all QOF objects.
+on any pre-defined objects. Instead, QSF is a simple container for all QOF objects.
QSF grew from the qof_book_merge code base and uses the qof_book_merge code that is now
part of QOF. Any QofBook generated by QSF still needs to be merged into the existing
Modified: gnucash/branches/remove-group2/lib/libqof/qof/qofinstance-p.h
===================================================================
--- gnucash/branches/remove-group2/lib/libqof/qof/qofinstance-p.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/lib/libqof/qof/qofinstance-p.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -74,9 +74,6 @@
gboolean infant;
};
-/* reset the dirty flag */
-void qof_instance_mark_clean (QofInstance *);
-
void qof_instance_set_slots (QofInstance *, KvpFrame *);
/* Set the last_update time. Reserved for use by the SQL backend;
Modified: gnucash/branches/remove-group2/lib/libqof/qof/qofinstance.h
===================================================================
--- gnucash/branches/remove-group2/lib/libqof/qof/qofinstance.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/lib/libqof/qof/qofinstance.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -92,6 +92,9 @@
*/
void qof_instance_set_dirty(QofInstance* inst);
+/* reset the dirty flag */
+void qof_instance_mark_clean (QofInstance *);
+
gboolean qof_instance_check_edit(const QofInstance *inst);
gboolean qof_instance_do_free(const QofInstance *inst);
Modified: gnucash/branches/remove-group2/lib/libqof/qof/qofsession.h
===================================================================
--- gnucash/branches/remove-group2/lib/libqof/qof/qofsession.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/lib/libqof/qof/qofsession.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -228,7 +228,7 @@
/** The qof_session_save() method will commit all changes that have been
* made to the session. For the file backend, this is nothing
- * more than a write to the file of the current AccountGroup & etc.
+ * more than a write to the file of the current Accounts & etc.
* For the SQL backend, this is typically a no-op (since all data
* has already been written out to the database.
*/
Modified: gnucash/branches/remove-group2/src/app-utils/app-utils.i
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/app-utils.i 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/app-utils.i 2006-11-01 00:01:35 UTC (rev 15066)
@@ -23,7 +23,7 @@
typedef int GNCOptionDBHandle;
QofBook * gnc_get_current_book (void);
-AccountGroup * gnc_get_current_group (void);
+Account * gnc_get_current_root_account (void);
char * gnc_gettext_helper(const char *string);
Modified: gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.c
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -3,7 +3,6 @@
#include <glib.h>
#include "gnc-account-merge.h"
#include "Account.h"
-#include "Group.h"
GncAccountMergeDisposition
determine_account_merge_disposition(Account *existing_acct, Account *new_acct)
@@ -17,50 +16,48 @@
}
GncAccountMergeDisposition
-determine_merge_disposition(AccountGroup *existing_root, Account *new_acct)
+determine_merge_disposition(Account *existing_root, Account *new_acct)
{
Account *existing_acct;
gchar *full_name;
full_name = xaccAccountGetFullName(new_acct);
- existing_acct = xaccGetAccountFromFullName(existing_root, full_name);
+ existing_acct = gnc_account_lookup_by_full_name(existing_root, full_name);
g_free(full_name);
return determine_account_merge_disposition(existing_acct, new_acct);
}
void
-account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp)
+account_trees_merge(Account *existing_root, Account *new_accts_root)
{
- GList *accounts_copy;
- AccountList *accounts;
- g_return_if_fail(new_grp != NULL);
- g_return_if_fail(existing_grp != NULL);
+ GList *accounts, *node;
+ g_return_if_fail(new_accts_root != NULL);
+ g_return_if_fail(existing_root != NULL);
/* since we're have a chance of mutating the list (via
- * xaccGroupInsertAccount) while we're iterating over it, iterate over a
- * copy. */
- accounts_copy = g_list_copy(xaccGroupGetAccountList(new_grp));
- for (accounts = accounts_copy; accounts; accounts = accounts->next)
+ * gnc_account_add_child) while we're iterating over it, iterate
+ * over a copy. */
+ accounts = gnc_account_get_children(new_accts_root);
+ for (node = accounts; node; node = g_list_next(node))
{
Account *existing_named, *new_acct;
const char *name;
- new_acct = (Account*)accounts->data;
+ new_acct = (Account*)node->data;
name = xaccAccountGetName(new_acct);
- existing_named = xaccGetAccountFromName(existing_grp, name);
+ existing_named = gnc_account_lookup_by_name(existing_root, name);
switch (determine_account_merge_disposition(existing_named, new_acct))
{
case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING:
/* recurse */
- account_group_merge(xaccAccountGetChildren(existing_named),
- xaccAccountGetChildren(new_acct));
+ account_trees_merge(existing_named, new_acct);
break;
case GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW:
/* merge this one in. */
- xaccGroupInsertAccount(existing_grp, new_acct);
+ gnc_account_append_child(existing_root, new_acct);
break;
}
}
- g_list_free(accounts_copy);
+ g_list_free(accounts);
}
Modified: gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.h
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/gnc-account-merge.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -4,7 +4,6 @@
#define GNC_ACCOUNT_MERGE_H
#include "Account.h"
-#include "Group.h"
typedef enum {
GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING,
@@ -18,8 +17,8 @@
} GncAccountMergeError;
GncAccountMergeDisposition determine_account_merge_disposition(Account *existing_acct, Account *new_acct);
-GncAccountMergeDisposition determine_merge_disposition(AccountGroup *existing_root, Account *new_acct);
+GncAccountMergeDisposition determine_merge_disposition(Account *existing_root, Account *new_acct);
-void account_group_merge(AccountGroup *existing_grp, AccountGroup *new_grp);
+void account_trees_merge(Account *existing_root, Account *new_accts_root);
#endif /* GNC_ACCOUNT_MERGE_H */
Modified: gnucash/branches/remove-group2/src/app-utils/gnc-component-manager.c
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/gnc-component-manager.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/gnc-component-manager.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -21,7 +21,6 @@
#include <stdio.h>
-#include "Group.h"
#include "gnc-component-manager.h"
#include "qof.h"
#include "gnc-ui-util.h"
Modified: gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -45,7 +45,6 @@
#include "gnc-hooks.h"
#include "gnc-module.h"
#include "gnc-ui-util.h"
-#include "Group.h"
#include "Transaction.h"
#include "guile-mappings.h"
#include "gnc-session.h"
@@ -206,10 +205,10 @@
return qof_session_get_book (gnc_get_current_session ());
}
-AccountGroup *
-gnc_get_current_group (void)
+Account *
+gnc_get_current_root_account (void)
{
- return gnc_book_get_group (gnc_get_current_book ());
+ return gnc_book_get_root_account (gnc_get_current_book ());
}
gnc_commodity_table *
@@ -374,11 +373,9 @@
if (include_children)
{
- AccountGroup *children_group;
GList *children, *node;
- children_group = xaccAccountGetChildren (account);
- children = xaccGroupGetSubAccounts (children_group);
+ children = gnc_account_get_descendants(account);
for (node = children; node; node = node->next)
{
@@ -393,6 +390,8 @@
child_balance, child_currency, currency);
balance = gnc_numeric_add_fixed (balance, child_balance);
}
+
+ g_list_free(children);
}
/* reverse sign if needed */
@@ -573,11 +572,11 @@
}
Account *
-gnc_find_or_create_equity_account (AccountGroup *group,
+gnc_find_or_create_equity_account (QofBook *book,
GNCEquityType equity_type,
- gnc_commodity *currency,
- QofBook *book)
+ gnc_commodity *currency)
{
+ Account *root;
Account *parent;
Account *account;
gboolean name_exists;
@@ -588,11 +587,12 @@
g_return_val_if_fail (equity_type >= 0, NULL);
g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, NULL);
g_return_val_if_fail (currency != NULL, NULL);
- g_return_val_if_fail (group != NULL, NULL);
+ g_return_val_if_fail (book != NULL, NULL);
base_name = equity_base_name (equity_type);
- account = xaccGetAccountFromName (group, base_name);
+ root = gnc_book_get_root_account(book);
+ account = gnc_account_lookup_by_name(root, base_name);
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
account = NULL;
@@ -600,7 +600,7 @@
{
base_name = base_name && *base_name ? _(base_name) : "";
- account = xaccGetAccountFromName (group, base_name);
+ account = gnc_account_lookup_by_name(root, base_name);
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
account = NULL;
}
@@ -613,7 +613,7 @@
name = g_strconcat (base_name, " - ",
gnc_commodity_get_mnemonic (currency), NULL);
- account = xaccGetAccountFromName (group, name);
+ account = gnc_account_lookup_by_name(root, name);
if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
account = NULL;
@@ -638,9 +638,10 @@
name = g_strdup (base_name);
}
- parent = xaccGetAccountFromName (group, _("Equity"));
+ parent = gnc_account_lookup_by_name(root, _("Equity"));
if (parent && xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
- parent = NULL;
+ parent = root;
+ g_assert(parent);
account = xaccMallocAccount (book);
@@ -650,14 +651,9 @@
xaccAccountSetType (account, ACCT_TYPE_EQUITY);
xaccAccountSetCommodity (account, currency);
- if (parent)
- {
- xaccAccountBeginEdit (parent);
- xaccAccountInsertSubAccount (parent, account);
- xaccAccountCommitEdit (parent);
- }
- else
- xaccGroupInsertAccount (group, account);
+ xaccAccountBeginEdit (parent);
+ gnc_account_append_child (parent, account);
+ xaccAccountCommitEdit (parent);
xaccAccountCommitEdit (account);
@@ -682,10 +678,9 @@
g_return_val_if_fail (account != NULL, FALSE);
equity_account =
- gnc_find_or_create_equity_account (xaccAccountGetRoot (account),
+ gnc_find_or_create_equity_account (book,
EQUITY_OPENING_BALANCE,
- xaccAccountGetCommodity (account),
- book);
+ xaccAccountGetCommodity (account));
if (!equity_account)
return FALSE;
Modified: gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.h
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/gnc-ui-util.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -36,7 +36,6 @@
#include <locale.h>
#include "Account.h"
-#include "Group.h"
#include "qof.h"
@@ -77,7 +76,7 @@
/* Engine enhancements & i18n ***************************************/
QofBook * gnc_get_current_book (void);
-AccountGroup * gnc_get_current_group (void);
+Account * gnc_get_current_root_account (void);
gnc_commodity_table * gnc_get_current_commodities (void);
/*
@@ -184,10 +183,9 @@
NUM_EQUITY_TYPES
} GNCEquityType;
-Account * gnc_find_or_create_equity_account (AccountGroup *group,
+Account * gnc_find_or_create_equity_account (QofBook *book,
GNCEquityType equity_type,
- gnc_commodity *currency,
- QofBook *book);
+ gnc_commodity *currency);
gboolean gnc_account_create_opening_balance (Account *account,
gnc_numeric balance,
time_t date,
Modified: gnucash/branches/remove-group2/src/app-utils/guile-util.h
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/guile-util.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/guile-util.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,9 +29,8 @@
#include "gnc-book.h"
#include "qof.h"
-#include "Group.h"
+#include "Account.h"
-
/* Helpful functions for calling functions that return
* specific kinds of values. These functions do error
* checking to verify the result is of the correct type. */
Modified: gnucash/branches/remove-group2/src/app-utils/options.scm
===================================================================
--- gnucash/branches/remove-group2/src/app-utils/options.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/app-utils/options.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -735,8 +735,8 @@
this-account
(find-first (cdr account-list))))))
- (let* ((current-group (gnc-get-current-group))
- (account-list (xaccGroupGetSubAccountsSorted current-group)))
+ (let* ((current-root (gnc-get-current-root-account))
+ (account-list (gnc-account-get-descendants current-root)))
(find-first account-list)))
(define (get-default)
Modified: gnucash/branches/remove-group2/src/backend/file/gnc-account-xml-v2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/gnc-account-xml-v2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/gnc-account-xml-v2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -44,7 +44,6 @@
#include "sixtp-dom-parsers.h"
#include "AccountP.h"
#include "Account.h"
-#include "Group.h"
static QofLogModule log_module = GNC_MOD_IO;
@@ -77,6 +76,7 @@
kvp_frame *kf;
xmlNodePtr ret;
GList *n;
+ Account *parent;
ENTER ("(account=%p)", act);
@@ -123,11 +123,11 @@
}
}
- if(xaccAccountGetParentAccount(act))
+ parent = gnc_account_get_parent(act);
+ if (parent)
{
- xmlAddChild(ret, guid_to_dom_tree(
- act_parent_string,
- xaccAccountGetGUID(xaccAccountGetParentAccount(act))));
+ xmlAddChild(ret, guid_to_dom_tree(act_parent_string,
+ xaccAccountGetGUID(parent)));
}
n = xaccAccountGetLotList (act);
@@ -322,7 +322,7 @@
g_return_val_if_fail(parent, FALSE);
}
- xaccAccountInsertSubAccount(parent, pdata->account);
+ gnc_account_append_child(parent, pdata->account);
g_free (gid);
@@ -405,10 +405,11 @@
gpointer *result, const gchar *tag)
{
int successful;
- Account *acc;
+ Account *acc, *parent, *root;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
QofBook *book = gdata->bookdata;
+ int type;
successful = TRUE;
@@ -436,6 +437,21 @@
* rebalances with #accounts rebalances at the end. A BIG win!
*/
xaccAccountBeginEdit(acc);
+
+ /* Backwards compatability. If there's no parent, see if this
+ * account is of type ROOT. If not, find or create a ROOT
+ * account and make that the parent. */
+ parent = gnc_account_get_parent(acc);
+ if (parent == NULL) {
+ type = xaccAccountGetType(acc);
+ if (type != ACCT_TYPE_ROOT) {
+ root = gnc_book_get_root_account(book);
+ if (root == NULL) {
+ root = gnc_account_create_root(book);
+ }
+ gnc_account_append_child(root, acc);
+ }
+ }
}
xmlFreeNode(tree);
Modified: gnucash/branches/remove-group2/src/backend/file/gnc-book-xml-v2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/gnc-book-xml-v2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/gnc-book-xml-v2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -45,7 +45,6 @@
#include "sixtp-dom-parsers.h"
#include "qof.h"
-#include "Group.h"
/* non-static because it's used in io-gncxml-v2.c */
const gchar *gnc_v2_book_version_string = "2.0.0";
@@ -62,25 +61,22 @@
#ifdef IMPLEMENT_BOOK_DOM_TREES_LATER
static void
-append_group(xmlNodePtr parent, AccountGroup *grp)
+append_account_tree (xmlNodePtr parent, Account *account)
{
- GList *list;
- GList *node;
+ GList *children, *node;
- list = xaccGroupGetAccountList(grp);
-
- for (node = list; node; node = node->next) {
+ children = gnc_account_get_children(account);
+ for (node = children; node; node = node->next)
+ {
xmlNodePtr accnode;
- AccountGroup *newgrp;
+ Account *account;
- accnode = gnc_account_dom_tree_create((Account*)(node->data), FALSE);
+ account = node->data;
+ accnode = gnc_account_dom_tree_create(account, FALSE);
xmlAddChild (parent, accnode);
-
- newgrp = xaccAccountGetChildren((Account*)(node->data));
-
- if (newgrp)
- append_group(accnode, newgrp);
+ append_account_tree(accnode, account);
}
+ g_list_free(children);
}
static int
@@ -125,9 +121,10 @@
xmlAddChild(ret, gnc_commodity_dom_tree_create(
gnc_book_get_commodity_table(book)));
xmlAddChild(ret, gnc_pricedb_dom_tree_create(gnc_book_get_pricedb(book)));
- append_group(ret, gnc_book_get_group(book));
+ append_account_tree (ret, gnc_book_get_root(book));
- xaccGroupForEachTransaction(gnc_book_get_group(book), traverse_txns, ret);
+ xaccAccountTreeForEachTransaction (gnc_book_get_root_account(book),
+ traverse_txns, ret);
xmlAddChild(ret, gnc_freqSpec_dom_tree_create (book));
Modified: gnucash/branches/remove-group2/src/backend/file/gnc-commodity-xml-v2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/gnc-commodity-xml-v2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/gnc-commodity-xml-v2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -42,7 +42,6 @@
#include "sixtp-dom-parsers.h"
#include "AccountP.h"
#include "Account.h"
-#include "Group.h"
static QofLogModule log_module = GNC_MOD_IO;
Modified: gnucash/branches/remove-group2/src/backend/file/gnc-schedxaction-xml-v2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/gnc-schedxaction-xml-v2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/gnc-schedxaction-xml-v2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -26,7 +26,6 @@
#include <glib.h>
#include <string.h>
-#include "Group.h"
#include "SchedXactionP.h"
#include "SX-book.h"
@@ -633,7 +632,7 @@
/* FIXME: this should be removed somewhere near 1.8 release time. */
if ( sx->template_acct == NULL )
{
- AccountGroup *ag = NULL;
+ Account *ra = NULL;
const char *id = NULL;
Account *acct = NULL;
sixtp_gdv2 *sixdata = gdata->parsedata;
@@ -644,18 +643,18 @@
/* We're dealing with a pre-200107<near-end-of-month> rgmerk
change re: storing template accounts. */
/* Fix: get account with name of our GUID from the template
- accounts group. Make that our template_acct pointer. */
+ accounts. Make that our template_acct pointer. */
/* THREAD-UNSAFE */
id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
- ag = gnc_book_get_template_group(book);
- if ( ag == NULL )
+ ra = gnc_book_get_template_root(book);
+ if ( ra == NULL )
{
- PERR( "Error getting template account group "
+ PERR( "Error getting template root account "
"from being-parsed Book." );
xmlFreeNode( tree );
return FALSE;
}
- acct = xaccGetAccountFromName( ag, id );
+ acct = gnc_account_lookup_by_name( ra, id );
if ( acct == NULL )
{
PERR( "Error getting template account "
@@ -769,9 +768,9 @@
txd.accts = NULL;
txd.transactions = NULL;
- /* the DOM tree will have an account tree [the template group
- and account] and a list of transactions [which will be
- members of the template account].
+ /* the DOM tree will have an account tree [the template
+ accounts] and a list of transactions [which will be members
+ of the template account].
we want to parse through the dom trees for each, placing
the null-parent account in the book's template-group slot,
Modified: gnucash/branches/remove-group2/src/backend/file/io-example-account.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-example-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-example-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -43,7 +43,6 @@
#include "sixtp-dom-parsers.h"
#include "sixtp-parsers.h"
-#include "Group.h"
#include "Scrub.h"
#include "TransLog.h"
@@ -69,11 +68,11 @@
g_free(gea->filename);
gea->filename = NULL;
}
- if(gea->group != NULL)
+ if(gea->root != NULL)
{
- xaccAccountGroupBeginEdit (gea->group);
- xaccAccountGroupDestroy(gea->group);
- gea->group = NULL;
+ xaccAccountBeginEdit (gea->root);
+ xaccAccountDestroy(gea->root);
+ gea->root = NULL;
}
if(gea->short_description != NULL)
{
@@ -138,9 +137,9 @@
xaccAccountScrubCommodity (act);
- if (!xaccAccountGetParent(act))
+ if (!gnc_account_get_parent(act))
{
- xaccGroupInsertAccount(gea->group, act);
+ gnc_account_append_child(gea->root, act);
}
}
@@ -301,7 +300,7 @@
gea->book = book;
gea->filename = g_strdup(filename);
- gea->group = xaccMallocAccountGroup(book);
+ gea->root = xaccMallocAccount(book);
top_parser = sixtp_new();
main_parser = sixtp_new();
@@ -327,6 +326,8 @@
return FALSE;
}
+ xaccAccountBeginEdit(gea->root);
+
if(!gnc_xml_parse_file(top_parser, filename,
generic_callback, gea, book))
{
@@ -335,8 +336,7 @@
return FALSE;
}
- xaccGroupMarkSaved(gea->group);
- xaccAccountGroupCommitEdit(gea->group);
+ xaccAccountCommitEdit(gea->root);
return gea;
}
@@ -389,7 +389,7 @@
write_bool_part(out, GNC_ACCOUNT_EXCLUDEP, gea->exclude_from_select_all);
- write_account_group(out, gea->group, NULL);
+ write_account_tree(out, gea->root, NULL);
fprintf(out, "</" GNC_ACCOUNT_STRING ">\n\n");
Modified: gnucash/branches/remove-group2/src/backend/file/io-example-account.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-example-account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-example-account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -35,7 +35,7 @@
gchar *title;
gchar *filename;
QofBook *book;
- AccountGroup *group;
+ Account *root;
gchar *short_description;
gchar *long_description;
gboolean exclude_from_select_all;
Deleted: gnucash/branches/remove-group2/src/backend/file/io-gncbin-r.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-gncbin-r.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-gncbin-r.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,1532 +0,0 @@
-/********************************************************************\
- * io-gncbin-r.c -- read (old X-Accountant format) binary datafile *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
- ********************************************************************
- * @file io-gncbin-r.c
- * @brief read (old X-Accountant format) binary datafile
- * @author Copyright (C) 1997 Robin D. Clark
- * @author Copyright (C) 1997-2001 Linas Vepstas <linas at linas.org>
- * @author Copyright (C) 1999-2000 Rob Browning
- *
- * NOTE: the readxxxx/writexxxx functions changed the current *
- * position in the file, and so the order which these *
- * functions are called in important *
- * *
- * Version 1 is the original file format *
- * Version 2 of the file format supports reading and writing of *
- * double-entry transactions. *
- * Version 3 of the file format supports actions (Buy, Sell, etc.) *
- * Version 4 of the file format adds account groups *
- * Version 5 of the file format adds splits *
- * Version 6 of the file format removes the source split *
- * Version 7 of the file format adds currency & security types *
- * Version 8 of the file format adds misc fields *
- * Version 9 changes the time format to a 64-bit int *
- * Version 10 adds auxilliary account info *
- * *
- * the format of the data in the file: *
- * file ::== token Group *
- * Group ::== numAccounts (Account)^numAccounts *
- * Account ::== accID flags type accountName accountCode *
- * description notes currency security *
- * AccInfo *
- * numTran (Transaction)^numTrans *
- * numGroups (Group)^numGroups *
- * Transaction ::== num date_entered date_posted description *
- * docref numSplits (Split)^numSplits *
- * Split ::== memo action reconciled date_recned *
- * docref amount share_price account *
- * token ::== int [the version of file format == VERSION] *
- * numTrans ::== int *
- * numAccounts ::== int *
- * accID ::== int *
- * flags ::== char *
- * type ::== char *
- * accountName ::== String *
- * accountCode ::== String *
- * description ::== String *
- * notes ::== String *
- * currency ::== String *
- * security ::== String *
- * AccInfo ::== (variable, depends on account type, ... ) *
- * *
- * num ::== String *
- * date_entered::== Date *
- * date_posted ::== Date *
- * date_recned ::== Date *
- * description ::== String *
- * memo ::== String *
- * action ::== String *
- * docref ::== String *
- * reconciled ::== char *
- * amount ::== double *
- * share_price ::== double *
- * account ::== int *
- * String ::== size (char)^size *
- * size ::== int *
- * Date ::== seconds nanoseconds *
- * seconds ::== signed 64 bit int *
- * nanoseconds ::== signed 32 bit int *
-\********************************************************************/
-
-#include <glib.h>
-#include <glib/gi18n.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "config.h"
-
-#include "Account.h"
-#include "AccountP.h"
-#include "io-gncbin.h"
-#include "Group.h"
-#include "GroupP.h"
-#include "Transaction.h"
-#include "TransactionP.h"
-#include "TransLog.h"
-#include "gnc-engine.h"
-#include "gnc-pricedb.h"
-#include "gnc-pricedb-p.h"
-
-#define PERMS 0666
-#define WFLAGS (O_WRONLY | O_CREAT | O_TRUNC)
-#define RFLAGS O_RDONLY
-
-#undef VERSION
-#define VERSION 10
-
-
-/* The binary file format does not support most of the
- * new/improved account & transaction structures
- */
-
-/* This static indicates the debugging module that this .o belongs to. */
-static QofLogModule log_module = GNC_MOD_IO;
-
-/** GLOBALS *********************************************************/
-
-/* the default currency is used when importin old-style
- * file formats, or when importing files with no currency
- * specified. This should probably be something that
- * is configurable from some user config menu.
- */
-#define DEFAULT_CURRENCY "USD"
-
-static int error_code=0; /* error code, if error occurred */
-
-static AccountGroup *holder; /* temporary holder for
- * unclassified accounts */
-static AccountGroup *maingrp; /* temporary holder for file
- * being read */
-
-/* Store mappings from the old/abolished id's to accounts since id's
- have been deleted from Account's.
-
- These shouldn't be global, but since the rest of this file is
- completely non-reentrant, and since this file is dead once the xml
- format is finished, I'm not going to get too torn up about it...
-
- FIXME: a bigger issue is whether or not we're being totally kosher
- in our handling of keys and values here. We use int32s and
- pointers interchangably ATM, and that may be problematic on some
- architectures...
-
- Only used *during* file read process.
-*/
-
-static GHashTable *ids_to_finished_accounts;
-static GHashTable *ids_to_unfinished_accounts;
-
-/** PriceDB bits ******************************************************/
-/* Commodity prices (stock quotes, etc.) used to be stored as zero
- quantity (damount) splits inside the relevant accounts. Now we
- used the pricedb. potential_quotes is where we put the info from
- all these "quote splits" while reading, until we have a chance to
- cram them into the pricedb. We can't do it any sooner because
- until we finish reading the file, the Account*'s havent' been
- filled out and so their commodities and types may not have been
- initilized yet.
-
- This shouldn't be a static global but see comments above RE ids_to*
- hashes. */
-
-typedef struct {
- Split *split;
- gnc_numeric price;
-} GNCPotentialQuote;
-
-static GSList *potential_quotes;
-
-
-#define EPS (1.0e-6)
-#define DEQEPS(x,y,eps) (((((x)+(eps))>(y)) ? 1 : 0) && ((((x)-(eps))<(y)) ? 1 : 0))
-#define DEQ(x,y) DEQEPS(x,y,EPS)
-
-static void
-mark_potential_quote(Split *s, double price, double quantity)
-{
- if((price != 0) && DEQ(quantity, 0)){
- GNCPotentialQuote *q = g_new0(GNCPotentialQuote, 1);
- q->split = s;
- q->price = double_to_gnc_numeric(price,
- GNC_DENOM_AUTO,
- GNC_DENOM_SIGFIGS(9) | GNC_RND_ROUND);
- potential_quotes = g_slist_prepend(potential_quotes, q);
- }
-}
-
-static gboolean
-cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
- QofBook *book)
-{
- GSList *item = potential_quotes;
-
- *prices = gnc_book_get_pricedb(book);
- if (!*prices) return FALSE;
-
- while(item)
- {
- GNCPotentialQuote *q = (GNCPotentialQuote *) item->data;
- Account *split_acct = xaccSplitGetAccount(q->split);
-
- /* at this point, we already know it's a split with a zero amount */
- if (xaccAccountIsPriced(split_acct)) {
- /* this is a quote -- file it in the db and kill the split */
- Transaction *txn = xaccSplitGetParent(q->split);
- GNCPrice *price = gnc_price_create(book);
- Timespec time = xaccTransRetDatePostedTS(txn);
-
- gnc_price_begin_edit(price);
- gnc_price_set_commodity(price,
- DxaccAccountGetSecurity(split_acct));
- gnc_price_set_currency(price,
- xaccTransGetCurrency(txn));
- gnc_price_set_time(price, time);
- gnc_price_set_source(price, "old-file-import");
- gnc_price_set_type(price, "unknown");
- gnc_price_set_value(price, q->price);
- gnc_price_commit_edit(price);
- if(!gnc_pricedb_add_price(*prices, price)) {
- PERR("problem adding price to pricedb.\n");
- }
- gnc_price_unref(price);
-
- xaccTransBeginEdit(txn);
- xaccSplitDestroy(q->split);
- xaccTransCommitEdit(txn);
- }
- g_free(item->data);
- item->data = NULL;
- item = item->next;
- }
- g_slist_free(potential_quotes);
- potential_quotes = NULL;
-
- return TRUE;
-}
-
-/** PROTOTYPES ******************************************************/
-static Account *locateAccount (int acc_id, QofBook *book);
-
-static AccountGroup *readGroup( QofBook *, int fd, Account *, int token );
-static Account *readAccount( QofBook *book, int fd,
- AccountGroup *, int token );
-static gboolean readAccInfo( int fd, Account *, int token );
-static Transaction *readTransaction( QofBook *book,
- int fd, Account *, int token );
-static Split *readSplit( QofBook *book, int fd, int token );
-static char *readString( int fd, int token );
-static time_t readDMYDate( int fd, int token );
-static int readTSDate( int fd, Timespec *, int token );
-
-/*******************************************************/
-/* backwards compatibility definitions for numeric value
- * of account type. These numbers are used (are to be
- * used) nowhere else but here, precisely because they
- * are non-portable. The values of these defines MUST
- * NOT BE CHANGED; ANY CHANGES WILL BREAK FILE COMPATIBILITY.
- * YOU HAVE BEEN WARNED!!!!
- */
-
-#define FF_BANK 0
-#define FF_CASH 1
-#define FF_ASSET 2
-#define FF_CREDIT 3
-#define FF_LIABILITY 4
-#define FF_STOCK 5
-#define FF_MUTUAL 6
-#define FF_INCOME 7
-#define FF_EXPENSE 8
-#define FF_EQUITY 9
-#define FF_CHECKING 10
-#define FF_SAVINGS 11
-#define FF_MONEYMRKT 12
-#define FF_CREDITLINE 13
-#define FF_CURRENCY 14
-
-/*******************************************************/
-
-QofBackendError
-gnc_get_binfile_io_error(void)
-{
- /* reset the error code */
- int rc = error_code;
- error_code = 0;
- return rc;
-}
-
-/*******************************************************/
-/* some endian stuff */
-
-/* if we are running on a little-endian system, we need to
- * do some endian flipping, because the xacc/gnucash native data
- * format is big-endian. In particular, Intel x86 is little-endian. */
-#if WORDS_BIGENDIAN
- #define XACC_FLIP_DOUBLE(x)
- #define XACC_FLIP_LONG_LONG(x)
- #define XACC_FLIP_INT(x)
- #define XACC_FLIP_SHORT(x)
-#else
-
-/* flip endianness of int, short, etc */
-static int
-xaccFlipInt (int val)
-{
- guint32 flip;
- flip = (val & 0xff000000) >> 24;
- flip |= (val & 0xff0000) >> 8;
- flip |= (val & 0xff00) << 8;
- flip |= (val & 0xff) << 24;
- return (int) flip;
-}
-
-static double
-xaccFlipDouble (double val)
-{
- union {
- guint32 i[2];
- double d;
- } u;
- guint32 w0, w1;
- u.d = val;
- w0 = xaccFlipInt (u.i[0]);
- w1 = xaccFlipInt (u.i[1]);
-
- u.i[0] = w1;
- u.i[1] = w0;
- return u.d;
-}
-
-static gint64
-xaccFlipLongLong (gint64 val)
-{
- union {
- guint32 i[2];
- gint64 d;
- } u;
- guint32 w0, w1;
- u.d = val;
- w0 = xaccFlipInt (u.i[0]);
- w1 = xaccFlipInt (u.i[1]);
-
- u.i[0] = w1;
- u.i[1] = w0;
- return u.d;
-}
-
- #define XACC_FLIP_DOUBLE(x) { (x) = xaccFlipDouble (x); }
- #define XACC_FLIP_LONG_LONG(x) { (x) = xaccFlipLongLong (x); }
- #define XACC_FLIP_INT(x) { (x) = xaccFlipInt (x); }
- #define XACC_FLIP_SHORT(x) { (x) = xaccFlipShort (x); }
-#endif /* WORDS_BIGENDIAN */
-
-
-
-/********************************************************************
- * handle legacy currencies : after we load old files, we MUST run the
- * gnucash currency conversion functions to get rid of the
- * GNC_LEGACY_CURRENCIES namespace.
- ********************************************************************/
-
-static gnc_commodity *
-gnc_commodity_import_legacy(QofBook *book, const char * currency_name)
-{
- gnc_commodity_table *table;
- gnc_commodity * old = NULL;
-
- table = gnc_book_get_commodity_table (book);
-
- g_return_val_if_fail (table != NULL, NULL);
-
- if(currency_name && (currency_name[0] != 0) ) {
- old = gnc_commodity_table_lookup(table,
- GNC_COMMODITY_NS_LEGACY,
- currency_name);
-
- if(!old) {
- old = gnc_commodity_new(book, currency_name,
- GNC_COMMODITY_NS_LEGACY, currency_name,
- 0, 100000);
- old = gnc_commodity_table_insert(table, old);
- }
- return old;
- }
- else {
- return NULL;
- }
-}
-
-
-/********************************************************************\
- ********************** LOAD DATA ***********************************
-\********************************************************************/
-
-gboolean gnc_is_bin_file (const gchar *name)
-{
- int fd, err, token;
-
- err = 0;
- token = 0;
- fd = open( name, RFLAGS, 0 );
-
- /* check for valid file descriptor */
- if( 0 > fd ) { return FALSE; }
-
- /* Read in the file format token */
- err = read( fd, &token, sizeof(int) );
- if( sizeof(int) != err ) { return FALSE; }
- XACC_FLIP_INT (token);
- close(fd);
- if(token == VERSION ) { return TRUE; }
- return FALSE;
-}
-
-/********************************************************************\
- * reads in the data from file descriptor *
- * *
- * Args: book -- the book in which to store the data *
- * fd -- the file descriptor to read the data from *
- * Return: the struct with the program data in it *
-\********************************************************************/
-static gboolean
-gnc_load_financials_from_fd(QofBook *book, int fd)
-{
- int err=0;
- int token=0;
- int num_unclaimed;
- AccountGroup *grp = 0x0;
-
- maingrp = 0x0;
- error_code = ERR_BACKEND_NO_ERR;
-
- /* check for valid file descriptor */
- if( 0 > fd )
- {
- error_code = ERR_FILEIO_FILE_NOT_FOUND;
- return FALSE;
- }
-
- /* Read in the file format token */
- err = read( fd, &token, sizeof(int) );
- if( sizeof(int) != err )
- {
- error_code = ERR_FILEIO_FILE_EMPTY;
- return FALSE;
- }
- XACC_FLIP_INT (token);
- PINFO ("reading file version %d", token);
-
- /* If this is an old file, ask the user if the file
- * should be updated */
- if( VERSION > token ) {
- error_code = ERR_FILEIO_FILE_TOO_OLD;
- }
-
- /* If this is a newer file than we know how to deal
- * with, warn the user */
- if( VERSION < token ) {
- error_code = ERR_BACKEND_TOO_NEW;
- return FALSE;
- }
-
- /* FIXME: is this OK (i.e. direct hashes for ints?) */
- ids_to_finished_accounts = g_hash_table_new(g_direct_hash, g_direct_equal);
- if(!ids_to_finished_accounts) {
- error_code = ERR_BACKEND_ALLOC;
- return FALSE;
- }
-
- ids_to_unfinished_accounts = g_hash_table_new(g_direct_hash, g_direct_equal);
- if(!ids_to_unfinished_accounts) {
- error_code = ERR_BACKEND_ALLOC;
-
- g_hash_table_destroy(ids_to_finished_accounts);
- ids_to_finished_accounts = NULL;
-
- return FALSE;
- }
-
- potential_quotes = NULL;
-
- /* disable logging during load; otherwise its just a mess */
- xaccLogDisable();
- holder = xaccMallocAccountGroup(book);
- grp = readGroup (book, fd, NULL, token);
-
- /* the number of unclaimed accounts should be zero if the
- * read succeeded. But just in case of a very unlikely
- * error, try to continue anyway. */
- num_unclaimed = xaccGroupGetNumSubAccounts (holder);
- if (num_unclaimed) {
- Account *acc;
- error_code = ERR_FILEIO_FILE_BAD_READ;
-
- /* create a lost account, put the missing accounts there */
- acc = xaccMallocAccount(book);
- xaccAccountBeginEdit (acc);
- /* Translators: Name of the account where all the missing accounts
- are put into. (FIXME: is this correct?) */
- xaccAccountSetName (acc, _("Lost Accounts"));
- acc -> children = holder;
- xaccAccountCommitEdit (acc);
- xaccGroupInsertAccount (grp, acc);
- } else {
- xaccFreeAccountGroup (holder);
- holder = NULL;
- }
-
- maingrp = NULL;
- g_hash_table_destroy(ids_to_finished_accounts);
- ids_to_finished_accounts = NULL;
- g_hash_table_destroy(ids_to_unfinished_accounts);
- ids_to_unfinished_accounts = NULL;
-
- {
- GNCPriceDB *tmpdb;
- if(!cvt_potential_prices_to_pricedb_and_cleanup(&tmpdb, book))
- {
- PWARN("pricedb import failed.");
- error_code = ERR_BACKEND_MISC;
- gnc_pricedb_destroy(tmpdb);
- }
- }
-
- xaccLogEnable();
-
- xaccSetAccountGroup(book, grp);
-
- /* mark the newly read book as saved, since the act of putting it
- * together will have caused it to be marked up as not-saved. */
- qof_book_mark_saved(book);
-
- return (error_code == ERR_BACKEND_NO_ERR);
-}
-
-/********************************************************************\
- * xaccReadAccountGroupFile *
- * reads in the data from file datafile *
- * *
- * Args: datafile - the file to load the data from *
- * Return: the struct with the program data in it *
-\********************************************************************/
-void
-qof_session_load_from_binfile(QofBook *book, const char * datafile)
-{
- int fd;
-
- if(!datafile) {
- error_code = ERR_BACKEND_MISC;
- return;
- }
-
- maingrp = NULL;
- error_code = ERR_BACKEND_NO_ERR;
-
- fd = open( datafile, RFLAGS, 0 );
- if( 0 > fd ) {
- error_code = ERR_FILEIO_FILE_NOT_FOUND;
- return;
- }
-
- xaccDisableDataScrubbing();
- gnc_load_financials_from_fd(book, fd);
- xaccEnableDataScrubbing();
-
- close(fd);
-}
-
-/********************************************************************\
- * readGroup *
- * reads in a group of accounts *
- * *
- * Args: *
- * Return: the struct with the program data in it *
-\********************************************************************/
-static AccountGroup *
-readGroup (QofBook *book, int fd, Account *aparent, int token)
- {
- int numAcc;
- int err=0;
- int i;
- AccountGroup *grp = xaccMallocAccountGroup(book);
-
- ENTER (" ");
-
- if (NULL == aparent) {
- maingrp = grp;
- }
-
- /* read numAccs */
- err = read( fd, &numAcc, sizeof(int) );
- if( sizeof(int) != err )
- {
- xaccFreeAccountGroup (grp);
- return NULL;
- }
- XACC_FLIP_INT (numAcc);
-
- DEBUG ("expecting %d accounts", numAcc);
-
- /* read in the accounts */
- for( i=0; i<numAcc; i++ )
- {
- Account * acc = readAccount( book, fd, grp, token );
- if( NULL == acc ) {
- PERR("Short group read: \n"
- "\texpected %d, got %d accounts\n",numAcc,i);
- break;
- }
- }
-
- /* if reading an account subgroup, place the subgroup
- * into the parent account */
- grp->parent = aparent;
- if (aparent) {
- aparent->children = grp;
- }
- return grp;
-}
-
-/********************************************************************\
- * readAccount *
- * reads in the data for an account from the datafile *
- * *
- * Args: book - the top-level account object *
- * fd - the filedescriptor of the data file *
- * acc - the account structure to be filled in *
- * token - the datafile version *
- * Return: error value, 0 if OK, else -1 *
-\********************************************************************/
-static Account *
-readAccount( QofBook *book, int fd, AccountGroup *grp, int token )
-{
- int err=0;
- int i;
- int numTrans, accID;
- Account *acc;
- gnc_commodity * currency;
- gnc_commodity * security;
- char * tmp;
-
- ENTER (" ");
-
- /* version 1 does not store the account number */
- if (1 < token) {
- err = read( fd, &accID, sizeof(int) );
- if( err != sizeof(int) ) { return NULL; }
- XACC_FLIP_INT (accID);
- acc = locateAccount (accID, book);
- /* locateAccountAlways should always accounts that are open for
- editing in this situation */
- } else {
- acc = xaccMallocAccount(book);
- xaccGroupInsertAccount (holder, acc);
- xaccAccountBeginEdit (acc);
- }
-
- {
- /* flags are now gone - if you need these, use kv pairs */
- char tmpflags;
- err = read( fd, &tmpflags, sizeof(char) );
- if( err != sizeof(char) ) { return NULL; }
- }
-
- /* if (9999>= token) */ {
- char ff_acctype;
- int acctype;
- err = read( fd, &(ff_acctype), sizeof(char) );
- if( err != sizeof(char) ) { return NULL; }
- switch (ff_acctype) {
- case FF_BANK: { acctype = ACCT_TYPE_BANK; break; }
- case FF_CASH: { acctype = ACCT_TYPE_CASH; break; }
- case FF_ASSET: { acctype = ACCT_TYPE_ASSET; break; }
- case FF_CREDIT: { acctype = ACCT_TYPE_CREDIT; break; }
- case FF_LIABILITY: { acctype = ACCT_TYPE_LIABILITY; break; }
- case FF_STOCK: { acctype = ACCT_TYPE_STOCK; break; }
- case FF_MUTUAL: { acctype = ACCT_TYPE_MUTUAL; break; }
- case FF_INCOME: { acctype = ACCT_TYPE_INCOME; break; }
- case FF_EXPENSE: { acctype = ACCT_TYPE_EXPENSE; break; }
- case FF_EQUITY: { acctype = ACCT_TYPE_EQUITY; break; }
- case FF_CHECKING: { acctype = ACCT_TYPE_CHECKING; break; }
- case FF_SAVINGS: { acctype = ACCT_TYPE_SAVINGS; break; }
- case FF_MONEYMRKT: { acctype = ACCT_TYPE_MONEYMRKT; break; }
- case FF_CREDITLINE: { acctype = ACCT_TYPE_CREDITLINE; break; }
- case FF_CURRENCY: { acctype = ACCT_TYPE_CURRENCY; break; }
- default: return NULL;
- }
- xaccAccountSetType (acc, acctype);
- }
-
- tmp = readString( fd, token );
- if( NULL == tmp) return NULL;
- DEBUG ("reading acct %s", tmp);
- xaccAccountSetName (acc, tmp);
- g_free (tmp);
-
- if (8 <= token) {
- tmp = readString( fd, token );
- if( NULL == tmp) return NULL;
- xaccAccountSetCode (acc, tmp);
- g_free (tmp);
- }
-
- tmp = readString( fd, token );
- if( NULL == tmp ) return NULL;
- xaccAccountSetDescription (acc, tmp);
- g_free (tmp);
-
- tmp = readString( fd, token );
- if( NULL == tmp ) return NULL;
- if(strlen(tmp) > 0) {
- xaccAccountSetNotes (acc, tmp);
- }
- g_free (tmp);
-
- /* currency and security strings first introduced
- * in version 7 of the file format */
- if (7 <= token) {
- tmp = readString( fd, token );
- if( NULL == tmp ) return NULL;
-
- PINFO ("currency is %s", tmp);
- currency = gnc_commodity_import_legacy(book, tmp);
- DxaccAccountSetCurrency (acc, currency);
-
- if(tmp) g_free (tmp);
-
- tmp = readString( fd, token );
-
- if (!tmp || *tmp == '\0')
- {
- if (xaccAccountIsPriced(acc)) {
- if (tmp) g_free (tmp);
-
- tmp = strdup (xaccAccountGetName (acc));
- if (tmp == NULL) return NULL;
- }
- }
-
- PINFO ("security is %s", tmp);
- security = gnc_commodity_import_legacy(book, tmp);
- DxaccAccountSetSecurity (acc, security);
-
- if(tmp) g_free (tmp);
- }
- else {
- /* set the default currency when importing old files */
- currency = gnc_commodity_import_legacy(book, DEFAULT_CURRENCY);
- DxaccAccountSetCurrency (acc, currency);
- }
-
- /* aux account info first appears in version ten files */
- if (10 <= token) {
- if(!readAccInfo(fd, acc, token)) {
- return(NULL);
- }
- }
-
- err = read( fd, &numTrans, sizeof(int) );
- if( err != sizeof(int) ) { return NULL; }
- XACC_FLIP_INT (numTrans);
-
- DEBUG ("expecting %d transactions", numTrans);
- /* read the transactions */
- for( i=0; i<numTrans; i++ ) {
- Transaction *trans;
- trans = readTransaction(book, fd, acc, token );
- if(trans == NULL ) {
- PERR ("Short Transaction Read: \n"
- "\texpected %d got %d transactions \n", numTrans, i);
- break;
- }
- }
-
- /* Not needed now. Since we always look in ids_to_finished_accounts
- * first, it doesn't matter if we don't ever delete anything from
- * unfinished_accounts...
- *
- * springAccount (acc->id); */
-
- xaccGroupInsertAccount (grp, acc);
-
- /* version 4 is the first file version that introduces
- * sub-accounts */
- if (4 <= token) {
- int numGrps;
- err = read( fd, &numGrps, sizeof(int) );
- if( err != sizeof(int) ) {
- return NULL;
- }
- XACC_FLIP_INT (numGrps);
- if (numGrps) {
- readGroup (book, fd, acc, token);
- }
- }
-
- xaccAccountCommitEdit (acc);
-
- return acc;
-}
-
-/********************************************************************\
- * locateAccount
- *
- * With the double-entry system, the file may reference accounts that
- * have not yet been read or properly parented. Thus, we need a way
- * of dealing with this, and this routine performs this
- * work. Basically, accounts are requested by their id. If an account
- * with the indicated ID does not exist, it is created and placed in a
- * temporary hash. Accounts in the temp hash can be located, (so that
- * transactions can be added to them) and sprung (so that they can be
- * properly parented into a group).
- *
- * Also, if locate account creates a new account, it'll be open for
- * editing.
- */
-
-static Account *
-locateAccount (int acc_id, QofBook *book)
-{
- Account * acc;
- /* negative account ids denote no account */
- if (0 > acc_id) return NULL;
-
- /* first, see if we've already created the account */
- acc = (Account *) g_hash_table_lookup(ids_to_finished_accounts,
- GINT_TO_POINTER(acc_id));
- if (acc) return acc;
-
- /* next, see if its an unclaimed account */
- acc = (Account *) g_hash_table_lookup(ids_to_unfinished_accounts,
- GINT_TO_POINTER(acc_id));
- if (acc) return acc;
-
- /* if neither, then it does not yet exist. Create it.
- * Put it in the drunk tank. */
- acc = xaccMallocAccount (book);
- xaccAccountBeginEdit(acc);
- g_hash_table_insert(ids_to_unfinished_accounts,
- GINT_TO_POINTER(acc_id),
- (gpointer) acc);
- return acc;
-}
-
-/********************************************************************\
- * readAccInfo *
- * reads in the auxilliary account info *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the accinfo structure *
-\********************************************************************/
-
-static gboolean
-readAccInfo(int fd, Account *acc, int token) {
-
- /* The only data that was ever stored in the account info was a
- price src if it was an investment account. The AccInfo
- abstraction has been abandoned, and all that stuff will soon be
- handled by other means, so we're just going to cram pricesrc into
- the account kv table for now... */
-
- GNCAccountType acc_type;
-
- if(!acc) return(FALSE);
-
- acc_type = xaccAccountGetType(acc);
- if ((acc_type == ACCT_TYPE_STOCK) || (acc_type == ACCT_TYPE_MUTUAL)) {
- const char *tmp = readString( fd, token );
- if(NULL == tmp) return(FALSE);
- if(strlen(tmp) > 0) dxaccAccountSetPriceSrc(acc, tmp);
- g_free((char *) tmp);
- }
- return(TRUE);
-}
-
-static void
-xaccTransSetMemo (Transaction *trans, const char *memo)
-{
- Split *s;
-
- if (!trans || !memo) return;
-
- s = xaccTransGetSplit (trans, 0);
- xaccSplitSetMemo (s, memo);
-
- if (xaccTransCountSplits (trans) != 2)
- return;
-
- s = xaccTransGetSplit (trans, 1);
- xaccSplitSetMemo (s, memo);
-}
-
-static void
-xaccTransSetAction (Transaction *trans, const char *action)
-{
- Split *s;
-
- if (!trans || !action) return;
-
- s = xaccTransGetSplit (trans, 0);
- xaccSplitSetAction (s, action);
-
- if (xaccTransCountSplits (trans) != 2)
- return;
-
- s = xaccTransGetSplit (trans, 1);
- xaccSplitSetAction (s, action);
-}
-
-/********************************************************************\
- * readTransaction *
- * reads in the data for a transaction from the datafile *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the transaction structure *
-\********************************************************************/
-
-static Transaction *
-readTransaction(QofBook *book, int fd, Account *acc, int revision)
- {
- int err=0;
- int acc_id;
- int i;
- int dummy_category;
- int numSplits;
- Transaction *trans = 0x0;
- char *tmp;
- char recn;
- double num_shares = 0.0;
- double share_price = 0.0;
-
- ENTER (" ");
-
- /* create a transaction structure */
- trans = xaccMallocTransaction(book);
- xaccTransBeginEdit (trans);
-
- tmp = readString( fd, revision );
- if (NULL == tmp)
- {
- PERR ("Premature end of Transaction at num");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- xaccTransSetNum (trans, tmp);
- g_free (tmp);
-
- if (revision <= 7) {
- time_t secs;
- secs = readDMYDate( fd, revision );
- if( 0 == secs )
- {
- PERR ("Premature end of Transaction at date");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- xaccTransSetDateSecs (trans, secs);
- xaccTransSetDateEnteredSecs (trans, secs);
- } else {
- Timespec ts;
- int rc;
-
- /* read posted date first ... */
- rc = readTSDate( fd, &ts, revision );
- if( -1 == rc )
- {
- PERR ("Premature end of Transaction at date");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- xaccTransSetDatePostedTS (trans, &ts);
-
- /* then the entered date ... */
- rc = readTSDate( fd, &ts, revision );
- if( -1 == rc )
- {
- PERR ("Premature end of Transaction at date");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- xaccTransSetDateEnteredTS (trans, &ts);
- }
-
- tmp = readString( fd, revision );
- if( NULL == tmp )
- {
- PERR ("Premature end of Transaction at description");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- PINFO ("description=%s", tmp);
- xaccTransSetDescription (trans, tmp);
- g_free (tmp);
-
- /* docref first makes an appearance in version 8. They're now
- deprecated, and we don't think anyone ever used them anyway, but
- to be safe, if we find one, we store it in the old-docref slot, a
- la old-price-source. */
- if (revision >= 8) {
- tmp = readString( fd, revision );
- if( NULL == tmp ) {
- PERR ("Premature end of Transaction at docref");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- if(strlen(tmp) > 0) {
- kvp_value *new_value = kvp_value_new_string(tmp);
- if(!new_value) {
- PERR ("Failed to allocate kvp_value for transaction docref.");
- g_free(tmp);
- return(NULL);
- }
- kvp_frame_set_slot_nc(xaccTransGetSlots(trans), "old-docref", new_value);
- }
- g_free (tmp);
- }
-
- /* At version 5, most of the transaction stuff was
- * moved to splits. Thus, vast majority of stuff below
- * is skipped
- */
- if (revision <= 4) {
- Split* s;
-
- tmp = readString( fd, revision );
- if( NULL == tmp )
- {
- PERR ("Premature end of Transaction at memo");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
-
- if(strlen(tmp) > 0) {
- xaccTransSetMemo (trans, tmp);
- }
- g_free (tmp);
-
- /* action first introduced in version 3 of the file format */
- if (revision >= 3)
- {
- tmp = readString( fd, revision );
- if( NULL == tmp )
- {
- PERR ("Premature end of Transaction at action");
- xaccTransDestroy (trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- xaccTransSetAction (trans, tmp);
- g_free (tmp);
- }
-
- /* category is now obsolete */
- err = read( fd, &(dummy_category), sizeof(int) );
- if( sizeof(int) != err )
- {
- PERR ("Premature end of Transaction at category");
- xaccTransDestroy (trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
-
- err = read( fd, &recn, sizeof(char) );
- if( sizeof(char) != err )
- {
- PERR ("Premature end of Transaction at reconciled");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
-
- /* The code below really wants to assume that there are a pair
- * of splits in every transaction, so make it so.
- */
- s = xaccMallocSplit (book);
- xaccTransAppendSplit (trans, s);
- s = xaccMallocSplit (book);
- xaccTransAppendSplit (trans, s);
-
- s = xaccTransGetSplit (trans, 0);
- xaccSplitSetReconcile (s, recn);
- s = xaccTransGetSplit (trans, 1);
- xaccSplitSetReconcile (s, recn);
-
- if(revision <= 1) {
- /* Note: this is for version 0 of file format only.
- * What used to be reconciled, is now cleared... transactions
- * aren't reconciled until you get your bank statement, and
- * use the reconcile window to mark the transaction reconciled
- */
- if( YREC == recn ) {
- s = xaccTransGetSplit (trans, 0);
- xaccSplitSetReconcile (s, CREC);
- s = xaccTransGetSplit (trans, 1);
- xaccSplitSetReconcile (s, CREC);
- }
- }
-
- /* Version 1 files stored the amount as an integer,
- * with the amount recorded as pennies.
- * Version 2 and above store the share amounts and
- * prices as doubles. */
- if (1 == revision) {
- int amount;
-
- err = read( fd, &amount, sizeof(int) );
- if( sizeof(int) != err )
- {
- PERR ("Premature end of Transaction at V1 amount");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_INT (amount);
- num_shares = 0.01 * ((double) amount); /* file stores pennies */
- s = xaccTransGetSplit (trans, 0);
- DxaccSplitSetShareAmount (s, num_shares);
-
- /* Version 1 files did not do double-entry */
- s = xaccTransGetSplit (trans, 0);
- xaccAccountInsertSplit( acc, s );
- } else {
- Account *peer_acc;
- double damount;
-
- /* first, read number of shares ... */
- err = read( fd, &damount, sizeof(double) );
- if( sizeof(double) != err )
- {
- PERR ("Premature end of Transaction at amount");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_DOUBLE (damount);
- num_shares = damount;
-
- /* ... next read the share price ... */
- err = read( fd, &damount, sizeof(double) );
- if( err != sizeof(double) )
- {
- PERR ("Premature end of Transaction at share_price");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_DOUBLE (damount);
- share_price = damount;
- s = xaccTransGetSplit (trans, 0);
-
- DxaccSplitSetSharePriceAndAmount (s, share_price, num_shares);
-
- /* Read the account numbers for double-entry */
- /* These are first used in Version 2 of the file format */
-
- /* first, read the credit account number */
- err = read( fd, &acc_id, sizeof(int) );
- if( err != sizeof(int) )
- {
- PERR ("Premature end of Transaction at credit");
- xaccTransDestroy (trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_INT (acc_id);
- DEBUG ("credit %d\n", acc_id);
- peer_acc = locateAccount (acc_id, book);
-
- /* insert the split part of the transaction into
- * the credited account */
- s = xaccTransGetSplit (trans, 0);
- if (peer_acc) xaccAccountInsertSplit( peer_acc, s);
-
- mark_potential_quote(s, share_price, num_shares);
-
- /* next read the debit account number */
- err = read( fd, &acc_id, sizeof(int) );
- if( err != sizeof(int) )
- {
- PERR ("Premature end of Transaction at debit");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_INT (acc_id);
- DEBUG ("debit %d\n", acc_id);
- peer_acc = locateAccount (acc_id, book);
- if (peer_acc) {
- Split *s0 = xaccTransGetSplit (trans, 0);
- Split *s1 = xaccTransGetSplit (trans, 1);
-
- /* duplicate many of the attributes in the credit split */
- DxaccSplitSetSharePriceAndAmount (s1, share_price, -num_shares);
- xaccSplitSetReconcile (s1, xaccSplitGetReconcile (s0));
- xaccSplitSetMemo (s1, xaccSplitGetMemo (s0));
- xaccSplitSetAction (s1, xaccSplitGetAction (s0));
- xaccAccountInsertSplit (peer_acc, s1);
- mark_potential_quote(s1, share_price, -num_shares);
- }
- }
- } else { /* else, read version 5 and above files */
-
- const char *notes = NULL;
-
- if (revision == 5) {
- /* Version 5 files included a split that immediately
- * followed the transaction, before the destination splits.
- * Later versions don't have this. */
- Split *split = readSplit (book, fd, revision);
- xaccTransAppendSplit(trans, split);
- }
-
- /* read number of splits */
- err = read( fd, &(numSplits), sizeof(int) );
- if( err != sizeof(int) ) {
- PERR ("Premature end of Transaction at num-splits");
- xaccTransDestroy(trans);
- xaccTransCommitEdit (trans);
- return NULL;
- }
- XACC_FLIP_INT (numSplits);
- for (i = 0; i < numSplits; i++) {
- Split *split = readSplit(book, fd, revision);
- xaccTransAppendSplit(trans, split);
-
- if(!notes) {
- notes = xaccSplitGetMemo (split);
- if(notes) xaccTransSetNotes (trans, notes);
- }
- }
- }
-
- xaccTransCommitEdit (trans);
-
- return trans;
-}
-
-/********************************************************************\
- * readSplit *
- * reads in the data for a split from the datafile *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the transaction structure *
-\********************************************************************/
-
-static Split *
-readSplit ( QofBook *book, int fd, int token )
-{
- Account *peer_acc;
- Split *split;
- int err=0;
- int acc_id;
- char *tmp;
- char recn;
- double num_shares, share_price;
-
- ENTER (" ");
-
- /* create a split structure */
- split = xaccMallocSplit(book);
-
- tmp = readString( fd, token );
- if( NULL == tmp )
- {
- PERR ("Premature end of Split at memo");
- xaccSplitDestroy(split);
- return NULL;
- }
- PINFO ("memo=%s", tmp);
- xaccSplitSetMemo (split, tmp);
- g_free (tmp);
-
- tmp = readString( fd, token );
- if( tmp == NULL )
- {
- PERR ("Premature end of Split at action");
- xaccSplitDestroy (split);
- return NULL;
- }
- xaccSplitSetAction (split, tmp);
- g_free (tmp);
-
- err = read( fd, &recn, sizeof(char) );
- if( err != sizeof(char) )
- {
- PERR ("Premature end of Split at reconciled");
- xaccSplitDestroy (split);
- return NULL;
- }
-
- /* make sure the value of split->reconciled is valid...
- * Do this mainly in case we change what NREC and
- * YREC are defined to be... this way it might loose all
- * the reconciled data, but at least the field is valid */
- if( (YREC != recn) &&
- (FREC != recn) &&
- (CREC != recn) ) {
- recn = NREC;
- }
- xaccSplitSetReconcile (split, recn);
-
- /* version 8 and newer files store date-reconciled */
- if (8 <= token) {
- Timespec ts;
- int rc;
-
- rc = readTSDate( fd, &ts, token );
- if( -1 == rc )
- {
- PERR ("Premature end of Split at date");
- xaccSplitDestroy (split);
- return NULL;
- }
- xaccSplitSetDateReconciledTS (split, &ts);
- } else {
- time_t now;
- now = time (0);
- xaccSplitSetDateReconciledSecs (split, now);
- }
-
- /* docref first makes an appearance in version 8. They're now
- deprecated, and we don't think anyone ever used them anyway, but
- to be safe, if we find one, we store it in the old-docref slot, a
- la old-price-source. */
- if (8 <= token) {
- tmp = readString( fd, token );
- if( NULL == tmp ) {
- PERR ("Premature end of Split at docref");
- xaccSplitDestroy (split);
- return NULL;
- }
- if(strlen(tmp) > 0) {
- kvp_value *new_value = kvp_value_new_string(tmp);
- if(!new_value) {
- PERR ("Failed to allocate kvp_value for split docref.");
- g_free(tmp);
- return(NULL);
- }
- kvp_frame_set_slot_nc(xaccSplitGetSlots(split), "old-docref", new_value);
- }
- g_free (tmp);
- }
-
- /* first, read number of shares ... */
- err = read( fd, &num_shares, sizeof(double) );
- if( sizeof(double) != err )
- {
- PERR ("Premature end of Split at amount");
- xaccSplitDestroy (split);
- return NULL;
- }
- XACC_FLIP_DOUBLE (num_shares);
-
- /* ... next read the share price ... */
- err = read( fd, &share_price, sizeof(double) );
- if( sizeof(double) != err )
- {
- PERR ("Premature end of Split at share_price");
- xaccSplitDestroy (split);
- return NULL;
- }
- XACC_FLIP_DOUBLE (share_price);
-
- DxaccSplitSetSharePriceAndAmount (split, share_price, num_shares);
-
- DEBUG ("num_shares %f", num_shares);
-
- /* Read the account number */
-
- err = read( fd, &acc_id, sizeof(int) );
- if( sizeof(int) != err )
- {
- PERR ("Premature end of Split at account");
- xaccSplitDestroy (split);
- return NULL;
- }
- XACC_FLIP_INT (acc_id);
- DEBUG ("account id %d", acc_id);
- peer_acc = locateAccount (acc_id, book);
- xaccAccountInsertSplit (peer_acc, split);
-
- mark_potential_quote(split, share_price, num_shares);
- return split;
-}
-
-/********************************************************************\
- * readString *
- * reads in a string (char *) from the datafile *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the string *
-\********************************************************************/
-static char *
-readString( int fd, int token )
- {
- int err=0;
- int size;
- char *str;
-
- err = read( fd, &size, sizeof(int) );
- if( err != sizeof(int) )
- return NULL;
- XACC_FLIP_INT (size);
-
- str = (char *) g_malloc (size);
- if (!str) {
- PERR("malloc failed on size %d bytes at position %ld\n", size,
- (long int) lseek(fd, 0, SEEK_CUR));
- return NULL;
- }
- err = read( fd, str, size );
- if( err != size )
- {
- PERR("size = %d err = %d str = %s\n", size, err, str );
- g_free(str);
- return NULL;
- }
-
- return str;
- }
-
-/********************************************************************\
- * readTSDate *
- * reads in a Date struct from the datafile *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the Date struct *
-\********************************************************************/
-static int
-readTSDate( int fd, Timespec *ts, int token )
- {
- int err=0;
- gint64 secs = 0; /* 64-bit int */
- gint32 nsecs = 0;
-
- /* secs is a 32-bit in in version 8 & earlier files,
- * and goes 64-bit in the later files */
- if (8 >= token)
- {
- gint32 sicks;
- err = read( fd, &sicks, sizeof(gint32) );
- if( err != sizeof(gint32) )
- {
- return -1;
- }
- XACC_FLIP_INT (sicks);
- secs = sicks;
- }
- else
- {
- err = read( fd, &secs, sizeof(gint64) );
- if( err != sizeof(gint64) )
- {
- return -1;
- }
- XACC_FLIP_LONG_LONG (secs);
- }
-
- err = read( fd, &nsecs, sizeof(gint32) );
- if( err != sizeof(gint32) )
- {
- return -1;
- }
- XACC_FLIP_INT (nsecs);
-
- ts->tv_sec = secs;
- ts->tv_nsec = nsecs;
-
- return 2*err;
- }
-
-/********************************************************************\
- * readDMYDate *
- * reads in a Date struct from the datafile *
- * *
- * Args: fd - the filedescriptor of the data file *
- * token - the datafile version *
- * Return: the Date struct *
-\********************************************************************/
-static time_t
-readDMYDate( int fd, int token )
- {
- int err=0;
- int day, month, year;
- time_t secs;
-
- err = read( fd, &year, sizeof(int) );
- if( err != sizeof(int) )
- {
- return 0;
- }
- XACC_FLIP_INT (year);
-
- err = read( fd, &month, sizeof(int) );
- if( err != sizeof(int) )
- {
- return 0;
- }
- XACC_FLIP_INT (month);
-
- err = read( fd, &day, sizeof(int) );
- if( err != sizeof(int) )
- {
- return 0;
- }
- XACC_FLIP_INT (day);
-
- secs = xaccDMYToSec (day, month, year);
- return secs;
- }
-
-
-/*********************** END OF FILE *********************************/
Deleted: gnucash/branches/remove-group2/src/backend/file/io-gncbin.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-gncbin.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-gncbin.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,64 +0,0 @@
-/********************************************************************\
- * io-gncbin.h -- read (old X-Accountant format) binary datafile *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
- * Author: Rob Clark *
- * Internet: rclark at cs.hmc.edu *
- * Address: 609 8th Street *
- * Huntington Beach, CA 92648-4632 *
-\********************************************************************/
-
-#ifndef IO_GNCBIN_H
-#define IO_GNCBIN_H
-
-#include "qof.h"
-
-/* @file io-gncbin.h
- * @brief read (old X-Accountant format) binary datafile
- * @author Copyright (C) 1997 Robin D. Clark
- * @author Copyright (C) 1998, 1999 Linas Vepstas <linas at linas.org>
-
- @note These routines should not be used directly for file IO. They
- are not inherently safe against file-locking errors. For direct
- file IO, the QofBook's higher level functions should be used.
-*/
-/** Load the financial data represented by the book's file_path
-into the indicated book.*/
-void qof_session_load_from_binfile(QofBook *, const char * filepath);
-
-/** Error handler.
-
-\return an error code for any error
- detected that occured during reading or writing.
-
-The error code will be reset after the call.
-
- The current implementation can be
- thought of as a "stack of depth one", and this routine as a "pop".
-*/
-QofBackendError gnc_get_binfile_io_error(void);
-
-/** \brief Attempt to identify the binary format.
-
-Instead of assuming that anything not v1 or v2 XML is the gnc
-binary format, this function tries to load the version token
-from the file.
-*/
-gboolean gnc_is_bin_file (const gchar *name);
-
-#endif /* IO_GNCBIN_H */
Modified: gnucash/branches/remove-group2/src/backend/file/io-gncxml-v1.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-gncxml-v1.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-gncxml-v1.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -35,8 +35,6 @@
#include "gnc-xml-helper.h"
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Query.h"
#include "QueryP.h"
#include "Scrub.h"
@@ -95,8 +93,8 @@
/* The book */
QofBook *book;
- /* The account group */
- AccountGroup *account_group;
+ /* The root account */
+ Account *root_account;
/* The pricedb */
GNCPriceDB *pricedb;
@@ -222,7 +220,7 @@
-----------
start: NA
before-child: make sure we don't get two ledger-data's (not allowed ATM).
- after-child: if a ledger-data child, parse_data->account_group = *result.
+ after-child: if a ledger-data child, parse_data->root_account = *result.
characters: allow_and_ignore_only_whitespace
Similarly, only one query is allowed ...
@@ -252,7 +250,7 @@
g_return_val_if_fail(pstatus, FALSE);
if(strcmp(child_tag, "ledger-data") == 0) {
- if(pstatus->account_group) {
+ if(pstatus->root_account) {
return(FALSE);
}
}
@@ -283,7 +281,7 @@
{
g_return_val_if_fail(child_result, FALSE);
g_return_val_if_fail(child_result->data, FALSE);
- pstatus->account_group = (AccountGroup *) child_result->data;
+ pstatus->root_account = (Account *) child_result->data;
child_result->should_cleanup = FALSE;
}
@@ -345,7 +343,7 @@
global_parse_status->seen_version = FALSE;
global_parse_status->gnc_parser = gnc_pr;
- global_parse_status->account_group = NULL;
+ global_parse_status->root_account = NULL;
global_parse_status->pricedb = NULL;
// global_parse_status->query = NULL;
global_parse_status->error = GNC_PARSE_ERR_NONE;
@@ -382,15 +380,15 @@
if(parse_ok)
{
- if(!global_parse_status.account_group) return FALSE;
+ if(!global_parse_status.root_account) return FALSE;
- xaccSetAccountGroup(book, global_parse_status.account_group);
+ gnc_book_set_root_account(book, global_parse_status.root_account);
/* Fix account and transaction commodities */
- xaccGroupScrubCommodities (gnc_book_get_group(book));
+ xaccAccountTreeScrubCommodities (gnc_book_get_root_account(book));
/* Fix split amount/value */
- xaccGroupScrubSplits (gnc_book_get_group(book));
+ xaccAccountTreeScrubSplits (gnc_book_get_root_account(book));
return(TRUE);
} else {
@@ -1079,18 +1077,18 @@
/****************************************************************************/
/* <ledger-data> (parent <gnc-data>)
- On failure or on normal cleanup, the account group will be killed,
+ On failure or on normal cleanup, the root account will be killed,
so if you want it, you better set should_cleanup to false
input: NA
- to-children-via-*result: new AccountGroup*
- returns: an AccountGroup*
- start: creates the account group and puts it into *result
+ to-children-via-*result: new root Account*
+ returns: an Account*
+ start: creates the root account and puts it into *result
characters: NA
- end: finishes up the account group and leaves it in result.
- cleanup-result: deletes the account group (use should_cleanup to avoid).
+ end: finishes up the root account and leaves it in result.
+ cleanup-result: deletes the root account (use should_cleanup to avoid).
cleanup-chars: NA
- fail: deletes the account group in *result.
+ fail: deletes the root account in *result.
result-fail: same as cleanup-result.
chars-fail: NA
@@ -1103,16 +1101,16 @@
gpointer *result, const gchar *tag, gchar **attrs)
{
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
- AccountGroup *ag;
+ Account *ra;
/* disable logging during load; otherwise its just a mess */
xaccLogDisable();
- ag = xaccMallocAccountGroup(pstatus->book);
+ ra = xaccMallocAccount(pstatus->book);
- g_return_val_if_fail(ag, FALSE);
+ g_return_val_if_fail(ra, FALSE);
- *data_for_children = ag;
- return(ag != NULL);
+ *data_for_children = ra;
+ return(ra != NULL);
}
static gboolean
@@ -1154,23 +1152,21 @@
gpointer *result, const gchar *tag)
{
- AccountGroup *ag = (AccountGroup *) data_for_children;
+ Account *ra = (Account *) data_for_children;
+ GList *descendants;
- g_return_val_if_fail(ag, FALSE);
+ g_return_val_if_fail(ra, FALSE);
- /* mark the newly read group as saved, since the act of putting
- * it together will have caused it to be marked up as not-saved.
- */
- xaccGroupMarkSaved (ag);
-
- /* commit all groups, this completes the BeginEdit started when the
+ /* commit all accounts, this completes the BeginEdit started when the
* account_end_handler finished reading the account.
*/
- xaccAccountGroupCommitEdit (ag);
+ descendants = gnc_account_get_descendants(ra);
+ g_list_foreach(descendants, (GFunc)xaccAccountCommitEdit, NULL);
+ g_list_free(descendants);
xaccLogEnable();
- *result = ag;
+ *result = ra;
return(TRUE);
}
@@ -1183,22 +1179,22 @@
gpointer *result,
const gchar *tag)
{
- AccountGroup *ag = (AccountGroup *) data_for_children;
- if(ag)
+ Account *account = (Account *) data_for_children;
+ if (account)
{
- xaccAccountGroupBeginEdit(ag);
- xaccAccountGroupDestroy(ag);
+ xaccAccountBeginEdit(account);
+ xaccAccountDestroy(account);
}
}
static void
ledger_data_result_cleanup(sixtp_child_result *cr)
{
- AccountGroup *ag = (AccountGroup *) cr->data;
- if(ag)
+ Account *account = (Account *) cr->data;
+ if (account)
{
- xaccAccountGroupBeginEdit(ag);
- xaccAccountGroupDestroy(ag);
+ xaccAccountBeginEdit(account);
+ xaccAccountDestroy(account);
}
}
@@ -1245,9 +1241,9 @@
to its children. It generates no data of its own, so it doesn't
need any cleanup.
- input: AccountGroup*
+ input: Account*
- to-children-via-*result: AccountGroup*
+ to-children-via-*result: Account*
returns: NA
@@ -1291,7 +1287,7 @@
if the resultant account is OK, and if so, we add it to the
ledger-data's account group.
- input: AccountGroup*
+ input: Account*
to-children-via-*result: new Account*
returns: NA
start: create new Account*, and leave in for children.
@@ -1331,21 +1327,21 @@
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
- AccountGroup *ag = (AccountGroup *) parent_data;
+ Account *parent = (Account *) parent_data;
Account *acc = (Account *) *result;
- AccountGroup *parent_ag;
+ Account *acc_parent;
- g_return_val_if_fail((ag && acc), FALSE);
+ g_return_val_if_fail((parent && acc), FALSE);
/* CHECKME: do we need to xaccAccountRecomputeBalance(acc) here? */
xaccAccountCommitEdit(acc);
/* If the account doesn't have a parent yet, just cram it into the
top level */
- parent_ag = xaccAccountGetParent(acc);
+ acc_parent = gnc_account_get_parent(acc);
+ if(!acc_parent)
+ gnc_account_append_child(parent, acc);
- if(!parent_ag) xaccGroupInsertAccount(ag, acc);
-
*result = NULL;
/* Now return the account to the "edit" state. At the end of reading
@@ -1713,7 +1709,7 @@
g_return_val_if_fail(parent, FALSE);
- xaccAccountInsertSubAccount(parent, acc);
+ gnc_account_append_child(parent, acc);
return(TRUE);
}
@@ -2682,9 +2678,9 @@
to its children. It generates no data of its own, so it doesn't
need any cleanup.
- input: AccountGroup*
+ input: Account*
- to-children-via-*result: AccountGroup*
+ to-children-via-*result: Account*
returns: NA
@@ -2724,7 +2720,7 @@
see if the resultant account is OK, and if so, we add it to the
ledger-data's account group.
- from parent: AccountGroup*
+ from parent: Account*
for children: new Transaction*
@@ -2772,11 +2768,11 @@
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
{
- AccountGroup *ag = (AccountGroup *) parent_data;
+ Account *parent = (Account *) parent_data;
Transaction *trans = (Transaction *) data_for_children;
g_return_val_if_fail(trans, FALSE);
- if(!ag) {
+ if (!parent) {
xaccTransDestroy(trans);
xaccTransCommitEdit(trans);
return(FALSE);
Modified: gnucash/branches/remove-group2/src/backend/file/io-gncxml-v2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-gncxml-v2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-gncxml-v2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -34,8 +34,6 @@
#include "gnc-engine.h"
#include "gnc-pricedb-p.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Scrub.h"
#include "SX-book.h"
#include "SX-book-p.h"
@@ -163,6 +161,8 @@
add_account_local(sixtp_gdv2 *data, Account *act)
{
gnc_commodity_table *table;
+ Account *parent, *root;
+ int type;
table = gnc_book_get_commodity_table (data->book);
@@ -180,10 +180,20 @@
xaccAccountScrubCommodity (act);
xaccAccountScrubKvp (act);
- if(!xaccAccountGetParent(act))
- {
- xaccGroupInsertAccount(gnc_book_get_group(data->book), act);
+ /* Backwards compatability. If there's no parent, see if this
+ * account is of type ROOT. If not, find or create a ROOT
+ * account and make that the parent. */
+ type = xaccAccountGetType(act);
+ if (type == ACCT_TYPE_ROOT) {
+ gnc_book_set_root_account(data->book, act);
+ } else {
+ parent = gnc_account_get_parent(act);
+ if (parent == NULL) {
+ root = gnc_book_get_root_account(data->book);
+ gnc_account_append_child(root, act);
+ }
}
+
data->counter.accounts_loaded++;
run_callback(data, "account");
@@ -255,7 +265,7 @@
{
GList *n;
Account *tmpAcct;
- AccountGroup *acctGroup = NULL;
+ Account *acctRoot = NULL;
QofBook *book;
book = data->book;
@@ -264,22 +274,20 @@
/* . template accounts. */
/* . transactions in those accounts. */
for ( n = txd->accts; n; n = n->next ) {
- if ( xaccAccountGetParent( (Account*)n->data ) == NULL ) {
+ if ( gnc_account_get_parent( (Account*)n->data ) == NULL ) {
/* remove the gnc_book_init-created account of the same name */
- acctGroup =
- gnc_book_get_template_group(book);
- tmpAcct =
- xaccGetAccountFromName( acctGroup,
+ acctRoot = gnc_book_get_template_root(book);
+ tmpAcct = gnc_account_lookup_by_name( acctRoot,
xaccAccountGetName( (Account*)n->data ) );
if ( tmpAcct != NULL ) {
/* XXX hack alert FIXME .... Should this be 'Remove', or 'Destroy'?
* If we just remove, then this seems to be a memory leak to me, since
* it is never reparented. Shouldn't it be a Destroy ???
*/
- xaccGroupRemoveAccount( acctGroup, tmpAcct );
+ gnc_account_remove_child( acctRoot, tmpAcct );
}
- xaccGroupInsertAccount( acctGroup, (Account*)n->data );
+ gnc_account_append_child( acctRoot, (Account*)n->data );
}
}
@@ -289,8 +297,6 @@
add_transaction_local( data, (Transaction*)n->data );
}
- xaccAccountGroupCommitEdit (acctGroup);
-
return TRUE;
}
@@ -642,7 +648,7 @@
FileBackend *fbe, QofBook *book,
sixtp_push_handler push_handler, gpointer push_user_data)
{
- AccountGroup *grp;
+ Account *root;
QofBackend *be = &fbe->be;
sixtp_gdv2 *gd;
sixtp *top_parser;
@@ -749,19 +755,21 @@
qof_object_foreach_backend (GNC_FILE_BACKEND, scrub_cb, &be_data);
/* fix price quote sources */
- grp = gnc_book_get_group(book);
- xaccGroupScrubQuoteSources (grp, gnc_book_get_commodity_table(book));
+ root = gnc_book_get_root_account(book);
+ xaccAccountTreeScrubQuoteSources (root, gnc_book_get_commodity_table(book));
/* Fix account and transaction commodities */
- xaccGroupScrubCommodities (grp);
+ xaccAccountTreeScrubCommodities (root);
/* Fix split amount/value */
- xaccGroupScrubSplits (grp);
+ xaccAccountTreeScrubSplits (root);
/* commit all groups, this completes the BeginEdit started when the
* account_end_handler finished reading the account.
*/
- xaccAccountGroupCommitEdit (grp);
+ gnc_account_foreach_descendant(root,
+ (AccountCb) xaccAccountCommitEdit,
+ NULL);
/* start logging again */
xaccLogEnable ();
@@ -928,7 +936,7 @@
gnc_commodity_table_get_size(
gnc_book_get_commodity_table(book)),
"account",
- 1 + xaccGroupGetNumSubAccounts(gnc_book_get_group(book)),
+ 1 + gnc_account_n_descendants(gnc_book_get_root_account(book)),
"transaction",
gnc_book_count_transactions(book),
"schedxaction",
@@ -1040,26 +1048,26 @@
be_data.out = out;
be_data.gd = gd;
- xaccGroupForEachTransaction(gnc_book_get_group(book),
- xml_add_trn_data,
- (gpointer) &be_data);
+ xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
+ xml_add_trn_data,
+ (gpointer) &be_data);
}
static void
write_template_transaction_data( FILE *out, QofBook *book, sixtp_gdv2 *gd )
{
- AccountGroup *ag;
+ Account *ra;
struct file_backend be_data;
be_data.out = out;
be_data.gd = gd;
- ag = gnc_book_get_template_group(book);
- if ( xaccGroupGetNumSubAccounts(ag) > 0 )
+ ra = gnc_book_get_template_root(book);
+ if ( gnc_account_n_descendants(ra) > 0 )
{
fprintf( out, "<%s>\n", TEMPLATE_TRANSACTION_TAG );
- write_account_group( out, ag, gd );
- xaccGroupForEachTransaction( ag, xml_add_trn_data, (gpointer)&be_data );
+ write_account_tree( out, ra, gd );
+ xaccAccountTreeForEachTransaction( ra, xml_add_trn_data, (gpointer)&be_data );
fprintf( out, "</%s>\n", TEMPLATE_TRANSACTION_TAG );
}
}
@@ -1172,7 +1180,7 @@
gd->counter.commodities_total =
gnc_commodity_table_get_size(gnc_book_get_commodity_table(book));
gd->counter.accounts_total = 1 +
- xaccGroupGetNumSubAccounts(gnc_book_get_group(book));
+ gnc_account_n_descendants(gnc_book_get_root_account(book));
gd->counter.transactions_total = gnc_book_count_transactions(book);
gd->counter.schedXactions_total =
g_list_length( gnc_book_get_schedxactions(book));
@@ -1194,14 +1202,14 @@
gnc_book_write_accounts_to_xml_filehandle_v2(QofBackend *be, QofBook *book, FILE *out)
{
gnc_commodity_table *table;
- AccountGroup *grp;
+ Account *root;
int ncom, nacc;
sixtp_gdv2 *gd;
if (!out) return FALSE;
- grp = gnc_book_get_group(book);
- nacc = 1 + xaccGroupGetNumSubAccounts(grp);
+ root = gnc_book_get_root_account(book);
+ nacc = 1 + gnc_account_n_descendants(root);
table = gnc_book_get_commodity_table(book);
ncom = gnc_commodity_table_get_size(table);
Modified: gnucash/branches/remove-group2/src/backend/file/io-utils.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-utils.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-utils.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -28,7 +28,6 @@
#include <glib.h>
-#include "Group.h"
#include "gnc-xml.h"
#include "gnc-xml.h"
#include "io-utils.h"
@@ -51,40 +50,36 @@
fprintf(out, emacs_trailer);
}
-void
-write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd)
+static void
+write_one_account(FILE *out, Account *account, sixtp_gdv2 *gd)
{
- GList *list;
- GList *node;
+ xmlNodePtr accnode;
- list = xaccGroupGetAccountList(grp);
+ accnode = gnc_account_dom_tree_create(account, gd && gd->exporting);
- for (node = list; node; node = node->next)
- {
- xmlNodePtr accnode;
- AccountGroup *newgrp;
-
- accnode = gnc_account_dom_tree_create((Account*)(node->data),
- gd && gd->exporting);
+ xmlElemDump(out, NULL, accnode);
+ fprintf(out, "\n");
- xmlElemDump(out, NULL, accnode);
- fprintf(out, "\n");
+ xmlFreeNode(accnode);
+ gd->counter.accounts_loaded++;
+ run_callback(gd, "account");
+}
- xmlFreeNode(accnode);
- gd->counter.accounts_loaded++;
- run_callback(gd, "account");
+void
+write_account_tree(FILE *out, Account *root, sixtp_gdv2 *gd)
+{
+ GList *descendants, *node;
- newgrp = xaccAccountGetChildren((Account*)(node->data));
+ write_one_account(out, root, gd);
- if (newgrp)
- {
- write_account_group(out, newgrp, gd);
- }
- }
+ descendants = gnc_account_get_descendants(root);
+ for (node = descendants; node; node = g_list_next(node))
+ write_one_account(out, node->data, gd);
+ g_list_free(descendants);
}
void
write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd)
{
- write_account_group(out, gnc_book_get_group(book), gd);
+ write_account_tree(out, gnc_book_get_root_account(book), gd);
}
Modified: gnucash/branches/remove-group2/src/backend/file/io-utils.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-utils.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/io-utils.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -27,11 +27,10 @@
#include <stdio.h>
-#include "Group.h"
#include "io-gncxml-v2.h"
#include "qof.h"
-void write_account_group(FILE *out, AccountGroup *grp, sixtp_gdv2 *gd);
+void write_account_tree(FILE *out, Account *root, sixtp_gdv2 *gd);
void write_accounts(FILE *out, QofBook *book, sixtp_gdv2 *gd);
void write_book_parts(FILE *out, QofBook *book);
void write_commodities(FILE *out, QofBook *book, sixtp_gdv2 *gd);
Modified: gnucash/branches/remove-group2/src/backend/file/test/test-load-xml2.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/test/test-load-xml2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/test/test-load-xml2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -38,7 +38,6 @@
#include <glib-object.h>
#include "cashobjects.h"
-#include "Group.h"
#include "TransLog.h"
#include "gnc-engine.h"
#include "gnc-backend-file.h"
@@ -78,7 +77,7 @@
{
QofSession *session;
QofBook *book;
- AccountGroup *grp;
+ Account *root;
gboolean ignore_lock;
session = qof_session_new();
@@ -91,9 +90,9 @@
qof_session_load(session, NULL);
book = qof_session_get_book (session);
- grp = xaccGetAccountGroup(book);
- do_test (xaccGroupGetBook (grp) == book,
- "book and group don't match");
+ root = gnc_book_get_root_account(book);
+ do_test (gnc_account_get_book (root) == book,
+ "book and root account don't match");
do_test_args(qof_session_get_error(session) == ERR_BACKEND_NO_ERR,
"session load xml2", __FILE__, __LINE__,
Modified: gnucash/branches/remove-group2/src/backend/file/test/test-xml-account.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/test/test-xml-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/test/test-xml-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -41,7 +41,6 @@
#include "test-file-stuff.h"
#include "Account.h"
-#include "Group.h"
#include "Scrub.h"
static QofBook *sixbook;
@@ -114,7 +113,8 @@
else if(safe_strcmp((char*)mark->name, "act:commodity") == 0)
{
if(!equals_node_val_vs_commodity(
- mark, xaccAccountGetCommodity(act), xaccAccountGetBook(act)))
+ mark, xaccAccountGetCommodity(act),
+ gnc_account_get_book(act)))
{
return g_strdup("commodities differ");
}
@@ -146,8 +146,7 @@
else if(safe_strcmp((char*)mark->name, "act:parent") == 0)
{
if(!equals_node_val_vs_guid(
- mark, xaccAccountGetGUID(xaccGroupGetParentAccount(
- xaccAccountGetParent(act)))))
+ mark, xaccAccountGetGUID(gnc_account_get_parent(act))))
{
return g_strdup("parent ids differ");
}
@@ -317,7 +316,7 @@
/* act1 = get_random_account(); */
/* act2 = get_random_account(); */
-/* xaccAccountInsertSubAccount(act1, act2); */
+/* gnc_account_append_child(act1, act2); */
/* test_account(-1, act2); */
/* test_account(-1, act1); */
@@ -334,9 +333,9 @@
char *msg;
Account *act = (Account*)data;
- if(!xaccAccountGetParent(act))
+ if(!gnc_account_get_parent(act))
{
- xaccGroupInsertAccount(xaccGetAccountGroup(sixbook), act);
+ gnc_account_append_child(gnc_book_get_root_account(sixbook), act);
}
msg = node_and_account_equal((xmlNodePtr)global_data, act);
Modified: gnucash/branches/remove-group2/src/backend/file/test/test-xml-transaction.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/test/test-xml-transaction.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/file/test/test-xml-transaction.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -365,14 +365,12 @@
for(i = 0; i < 50; i++)
{
Transaction *ran_trn;
- AccountGroup *grp;
xmlNodePtr test_node;
gnc_commodity *com;
gchar *compare_msg;
gchar *filename1;
int fd;
- grp = get_random_group(book);
ran_trn = get_random_transaction(book);
if(!ran_trn)
{
Modified: gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -38,8 +38,6 @@
#include <libpq-fe.h>
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-pricedb.h"
@@ -713,7 +711,7 @@
PGBackend *be = (PGBackend *)bend;
Query *q = (Query*) q_p;
const char * sql_query_string;
- AccountGroup *topgroup;
+ Account *root;
sqlQuery *sq;
ENTER ("be=%p, qry=%p", be, q);
@@ -728,10 +726,10 @@
sq = sqlQuery_new();
sql_query_string = sqlQuery_build (sq, q);
- topgroup = gnc_book_get_group (pgendGetBook(be));
+ root = gnc_book_get_root_account(pgendGetBook(be));
/* stage transactions, save some postgres overhead */
- xaccGroupBeginStagedTransactionTraversals (topgroup);
+ gnc_account_tree_begin_staged_transaction_traversals (root);
/* We will be doing a bulk insertion of transactions below.
* We can gain a tremendous performance improvement,
@@ -746,17 +744,13 @@
* by not very much.
*/
ncalls = 0;
- xaccAccountGroupBeginEdit(topgroup);
+ xaccAccountBeginEdit(root);
pgendFillOutToCheckpoint (be, sql_query_string);
- xaccAccountGroupCommitEdit(topgroup);
+ xaccAccountCommitEdit(root);
PINFO ("number of calls to fill out=%d", ncalls);
sql_Query_destroy(sq);
- /* the fill-out will dirty a lot of data. That's irrelevent,
- * mark it all as having been saved. */
- xaccGroupMarkSaved (topgroup);
-
pgendEnable(be);
qof_event_resume();
@@ -793,7 +787,7 @@
static void
-pgendGetAllTransactions (PGBackend *be, AccountGroup *grp)
+pgendGetAllTransactions (PGBackend *be, Account *root)
{
GList *node, *xaction_list = NULL;
@@ -804,14 +798,14 @@
xaction_list = pgendGetResults (be, get_all_trans_cb, xaction_list);
/* restore the transactions */
- xaccAccountGroupBeginEdit (grp);
+ xaccAccountBeginEdit (root);
for (node=xaction_list; node; node=node->next)
{
xxxpgendCopyTransactionToEngine (be, (GUID *)node->data);
guid_free (node->data);
}
g_list_free(xaction_list);
- xaccAccountGroupCommitEdit (grp);
+ xaccAccountCommitEdit (root);
pgendEnable(be);
qof_event_resume();
@@ -871,9 +865,9 @@
pgendSync (QofBackend *bend, QofBook *book)
{
PGBackend *be = (PGBackend *)bend;
- AccountGroup *grp = gnc_book_get_group (book);
+ Account *root = gnc_book_get_root_account(book);
- ENTER ("be=%p, grp=%p", be, grp);
+ ENTER ("be=%p, root=%p", be, root);
pgend_set_book (be, book);
be->version_check = (guint32) time(0);
@@ -894,8 +888,8 @@
pgendStoreBook (be, book);
/* store the account group hierarchy, and then all transactions */
- pgendStoreGroup (be, grp);
- pgendStoreAllTransactions (be, grp);
+ pgendStoreAccountTree (be, root);
+ pgendStoreAllTransactions (be, root);
/* don't send events to GUI, don't accept callbacks to backend */
qof_event_suspend();
@@ -907,7 +901,7 @@
(MODE_SINGLE_UPDATE != be->session_mode))
{
Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
- pgendGroupGetAllBalances (be, grp, ts);
+ pgendAccountTreeGetAllBalances (be, root, ts);
}
else
{
@@ -958,9 +952,9 @@
char buff[4000];
char *p;
PGBackend *be = (PGBackend *)bend;
- AccountGroup *grp = gnc_book_get_group (book);
+ Account *root = gnc_book_get_root_account(book);
- ENTER ("be=%p, grp=%p", be, grp);
+ ENTER ("be=%p, root=%p", be, root);
pgend_set_book (be, book);
@@ -1017,14 +1011,14 @@
pgendStoreBookNoLock (be, book, TRUE);
/* Store accounts and commodities */
- xaccClearMarkDownGr (grp, 0);
- pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
- xaccClearMarkDownGr (grp, 0);
+ xaccClearMarkDown (root, 0);
+ pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
+ xaccClearMarkDown (root, 0);
/* Recursively walk transactions. Start by reseting the write
* flags. We use this to avoid infinite recursion */
- xaccGroupBeginStagedTransactionTraversals(grp);
- xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be);
+ gnc_account_tree_begin_staged_transaction_traversals(root);
+ gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
/* hack alert -- In some deranged theory, we should be
* syncing prices here, as well as syncing any/all other
@@ -1424,7 +1418,7 @@
* it might be opened in multi-user mode next time. Thus, update
* the account balance checkpoints just in case.
*/
- /* pgendGroupRecomputeAllCheckpoints (be, be->topgroup); */
+ /* pgendAccountTreeRecomputeAllCheckpoints (be, be->root); */
break;
case MODE_POLL:
@@ -1481,7 +1475,7 @@
pgend_book_load_poll (QofBackend *bend, QofBook *book)
{
Timespec ts = gnc_iso8601_to_timespec_gmt (CK_BEFORE_LAST_DATE);
- AccountGroup *grp;
+ Account *root;
PGBackend *be = (PGBackend *)bend;
if (!be) return;
@@ -1508,10 +1502,10 @@
pgendGetAllAccountsInBook (be, book);
- grp = gnc_book_get_group (book);
- xaccAccountGroupBeginEdit (grp);
- pgendGroupGetAllBalances (be, grp, ts);
- xaccAccountGroupCommitEdit (grp);
+ root = gnc_book_get_root_account (book);
+ xaccAccountBeginEdit (root);
+ pgendAccountTreeGetAllBalances (be, root, ts);
+ xaccAccountCommitEdit (root);
/* re-enable events */
pgendEnable(be);
Modified: gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/PostgresBackend.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -37,7 +37,6 @@
#include <gmodule.h>
#include <libpq-fe.h>
-#include "Group.h"
#include "qof.h"
#include "Transaction.h"
Modified: gnucash/branches/remove-group2/src/backend/postgres/account.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -30,8 +30,6 @@
#include "AccountP.h"
#include "qof.h"
-#include "Group.h"
-#include "GroupP.h"
#include "gnc-commodity.h"
#include "gnc-pricedb.h"
@@ -48,7 +46,7 @@
/* ============================================================= */
/* ============================================================= */
-/* ACCOUNT AND GROUP STUFF */
+/* ACCOUNT STUFF */
/* (UTILITIES FIRST, THEN SETTERS, THEN GETTERS) */
/* ============================================================= */
/* ============================================================= */
@@ -136,8 +134,8 @@
}
/* ============================================================= */
-/* The pgendStoreGroup() routine stores the account hierarchy to
- * the sql database. That is, it stores not oonly the top-level
+/* The pgendStoreAccountTree() routine stores the account hierarchy
+ * to the sql database. That is, it stores not oonly the top-level
* accounts, but all of thier children too. It also stores the
* commodities associated with the accounts. It does *not* store
* any of the transactions.
@@ -150,38 +148,30 @@
*/
void
-pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp,
+pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
gboolean do_mark, gboolean do_check_version)
{
- GList *start, *node;
+ GList *descendants, *node;
- if (!be || !grp) return;
- ENTER("grp=%p mark=%d", grp, do_mark);
+ if (!be || !root) return;
+ ENTER("root=%p mark=%d", root, do_mark);
/* walk the account tree, and store subaccounts */
- start = xaccGroupGetAccountList (grp);
- for (node=start; node; node=node->next)
- {
- AccountGroup *subgrp;
- Account *acc = node->data;
-
- pgendStoreAccountNoLock (be, acc, do_mark, do_check_version);
-
- /* recursively walk to child accounts */
- subgrp = xaccAccountGetChildren (acc);
- if (subgrp) pgendStoreGroupNoLock(be, subgrp, do_mark,
- do_check_version);
- }
+ pgendStoreAccountNoLock (be, root, do_mark, do_check_version);
+ descendants = gnc_account_get_descendants (root);
+ for (node=descendants; node; node=node->next)
+ pgendStoreAccountNoLock (be, node->data, do_mark, do_check_version);
+ g_list_free(descendants);
LEAVE(" ");
}
void
-pgendStoreGroup (PGBackend *be, AccountGroup *grp)
+pgendStoreAccountTree (PGBackend *be, Account *root)
{
char *p;
- ENTER ("be=%p, grp=%p", be, grp);
- if (!be || !grp) return;
+ ENTER ("be=%p, root=%p", be, root);
+ if (!be || !root) return;
/* lock it up so that we store atomically */
p = "BEGIN;\n"
@@ -192,12 +182,12 @@
/* Clear the account marks; this is used to avoid visiting
* the same account more than once. */
- xaccClearMarkDownGr (grp, 0);
+ xaccClearMarkDown (root, 0);
- pgendStoreGroupNoLock (be, grp, TRUE, TRUE);
+ pgendStoreAccountTreeNoLock (be, root, TRUE, TRUE);
/* reset the write flags again */
- xaccClearMarkDownGr (grp, 0);
+ xaccClearMarkDown (root, 0);
p = "COMMIT;\n"
"NOTIFY gncAccount;";
@@ -211,23 +201,23 @@
/* ============================================================= */
/* ============================================================= */
-/* This routine walks the account group, gets all KVP values */
+/* This routine walks the account tree, gets all KVP values */
-static gpointer
+static void
restore_cb (Account *acc, void * cb_data)
{
PGBackend *be = (PGBackend *) cb_data;
- if (0 == acc->idata) return NULL;
+ if (0 == acc->idata) return;
acc->inst.kvp_data = pgendKVPFetch (be, acc->idata, acc->inst.kvp_data);
- return NULL;
}
static void
-pgendGetAllAccountKVP (PGBackend *be, AccountGroup *grp)
+pgendGetAllAccountKVP (PGBackend *be, Account *root)
{
- if (!grp) return;
+ if (!root) return;
- xaccGroupForEachAccount (grp, restore_cb, be, TRUE);
+ restore_cb(root, NULL);
+ gnc_account_foreach_descendant(root, restore_cb, be);
}
/* ============================================================= */
@@ -319,8 +309,8 @@
if (guid_equal(guid_null(), &acct_guid))
{
/* if the parent guid is null, then this
- * account belongs in the top group */
- xaccGroupInsertAccount (gnc_book_get_group(book), acc);
+ * account belongs in the top level */
+ gnc_account_append_child (gnc_book_get_root_account(book), acc);
}
else
{
@@ -338,7 +328,7 @@
else
{
xaccAccountBeginEdit(parent);
- xaccAccountInsertSubAccount(parent, acc);
+ gnc_account_append_child(parent, acc);
xaccAccountCommitEdit(parent);
}
}
@@ -375,7 +365,7 @@
pgendGetCommodity (be, ri->commodity_string);
commodity = gnc_string_to_commodity (ri->commodity_string,
- xaccAccountGetBook (ri->account));
+ gnc_account_get_book(ri->account));
if (commodity)
{
@@ -403,7 +393,7 @@
if (parent)
{
xaccAccountBeginEdit(parent);
- xaccAccountInsertSubAccount(parent, ri->account);
+ gnc_account_append_child(parent, ri->account);
xaccAccountCommitEdit(parent);
}
else
@@ -441,13 +431,8 @@
for (node=be->blist; node; node=node->next)
{
QofBook *book = node->data;
- AccountGroup *topgrp = gnc_book_get_group (book);
- pgendGetAllAccountKVP (be, topgrp);
-
- /* Mark the newly read group as saved, since the act of putting
- * it together will have caused it to be marked up as not-saved.
- */
- xaccGroupMarkSaved (topgrp);
+ Account *root = gnc_book_get_root_account(book);
+ pgendGetAllAccountKVP (be, root);
}
LEAVE (" ");
@@ -457,7 +442,7 @@
pgendGetAllAccountsInBook (PGBackend *be, QofBook *book)
{
char *p, buff[400];
- AccountGroup *topgrp;
+ Account *root;
ENTER ("be=%p", be);
if (!be || !book) return;
@@ -474,14 +459,9 @@
SEND_QUERY (be, buff, );
pgendGetAccounts (be, book);
- topgrp = gnc_book_get_group (book);
- pgendGetAllAccountKVP (be, topgrp);
+ root = gnc_book_get_root_account(book);
+ pgendGetAllAccountKVP (be, root);
- /* Mark the newly read group as saved, since the act of putting
- * it together will have caused it to be marked up as not-saved.
- */
- xaccGroupMarkSaved (topgrp);
-
LEAVE (" ");
}
@@ -568,7 +548,6 @@
pgend_account_commit_edit (QofBackend * bend,
Account * acct)
{
- AccountGroup *parent;
char *p;
QofBackendError err;
PGBackend *be = (PGBackend *)bend;
@@ -578,8 +557,6 @@
if (FALSE == acct->inst.dirty)
{
- parent = xaccAccountGetParent(acct);
- if (parent) parent->saved = 1;
LEAVE ("account not written because not dirty");
return;
}
@@ -641,13 +618,6 @@
SEND_QUERY (be,p,);
FINISH_QUERY(be->connection);
- /* Mark this up so that we don't get that annoying gui dialog
- * about having to save to file. unfortunately,however, this
- * is too liberal, and could screw up synchronization if we've lost
- * contact with the back end at some point. So hack alert -- fix
- * this. */
- parent = xaccAccountGetParent(acct);
- if (parent) parent->saved = 1;
LEAVE ("commited");
return;
}
Modified: gnucash/branches/remove-group2/src/backend/postgres/account.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -24,7 +24,7 @@
#ifndef POSTGRES_ACCOUNT_H
#define POSTGRES_ACCOUNT_H
-#include "Group.h"
+#include "Account.h"
#include "qof.h"
#include "PostgresBackend.h"
@@ -33,8 +33,8 @@
void pgendGetAllAccounts (PGBackend *be);
-void pgendStoreGroup (PGBackend *be, AccountGroup *grp);
-void pgendStoreGroupNoLock (PGBackend *be, AccountGroup *grp,
+void pgendStoreAccountTree (PGBackend *be, Account *root);
+void pgendStoreAccountTreeNoLock (PGBackend *be, Account *root,
gboolean do_mark, gboolean do_check_version);
Account * pgendCopyAccountToEngine (PGBackend *be, const GUID *acct_guid);
Modified: gnucash/branches/remove-group2/src/backend/postgres/checkpoint.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/checkpoint.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/checkpoint.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -45,7 +45,6 @@
#include "Account.h"
#include "AccountP.h"
#include "qof.h"
-#include "Group.h"
#include "gnc-commodity.h"
#include "builder.h"
@@ -235,11 +234,13 @@
/* recompute fresh balance checkpoints for every account */
void
-pgendGroupRecomputeAllCheckpoints (PGBackend *be, AccountGroup *grp)
+pgendAccountTreeRecomputeAllCheckpoints (PGBackend *be, Account *parent)
{
GList *acclist, *node;
- acclist = xaccGroupGetSubAccounts(grp);
+ pgendAccountRecomputeAllCheckpoints (be, xaccAccountGetGUID(parent));
+
+ acclist = gnc_account_get_descendants(parent);
for (node = acclist; node; node=node->next)
{
Account *acc = (Account *) node->data;
@@ -510,16 +511,16 @@
/* get checkpoint value for all accounts */
void
-pgendGroupGetAllBalances (PGBackend *be, AccountGroup *grp,
+pgendAccountTreeGetAllBalances (PGBackend *be, Account *root,
Timespec as_of_date)
{
GList *acclist, *node;
- if (!be || !grp) return;
+ if (!be || !root) return;
ENTER("be=%p", be);
/* loop over all accounts */
- acclist = xaccGroupGetSubAccounts (grp);
+ acclist = gnc_account_get_descendants (root);
for (node=acclist; node; node=node->next)
{
Account *acc = (Account *) node->data;
Modified: gnucash/branches/remove-group2/src/backend/postgres/checkpoint.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/checkpoint.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/checkpoint.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -35,7 +35,6 @@
#define CHECKPOINT_H
#include "Account.h"
-#include "Group.h"
#include "qof.h"
#include "Transaction.h"
@@ -79,8 +78,8 @@
void pgendTransactionRecomputeCheckpoints (PGBackend *be, Transaction *trans);
void pgendAccountRecomputeOneCheckpoint (PGBackend *be, Account *acc, Timespec ts);
-void pgendGroupRecomputeAllCheckpoints (PGBackend *, AccountGroup *);
-void pgendGroupGetAllBalances (PGBackend *, AccountGroup *, Timespec as_of_date);
+void pgendAccountTreeRecomputeAllCheckpoints (PGBackend *, Account *);
+void pgendAccountTreeGetAllBalances (PGBackend *, Account *, Timespec as_of_date);
/* The pgendAccountGetBalance() routine goes to the sql database and finds the
* balance as of the 'as_of_date' argument. It sets the starting balance for
Modified: gnucash/branches/remove-group2/src/backend/postgres/events.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/events.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/events.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,4 +1,4 @@
-/********************************************************************\
+/******************************************************************** \
* events.c -- implements event handling for postgres backend *
* Copyright (c) 2001 Linas Vepstas <linas at linas.org> *
* *
@@ -290,16 +290,13 @@
/* if the remote user created an account, mirror it here */
acc = pgendCopyAccountToEngine (be, &(ev->guid));
- xaccGroupMarkSaved (xaccAccountGetRoot(acc));
ent = (QofEntity*)acc;
break;
}
case QOF_EVENT_DESTROY: {
Account * acc = pgendAccountLookup (be, &(ev->guid));
- AccountGroup *topgrp = xaccAccountGetRoot(acc);
xaccAccountBeginEdit (acc);
xaccAccountDestroy (acc);
- xaccGroupMarkSaved (topgrp);
ent = (QofEntity*)acc;
break;
}
Modified: gnucash/branches/remove-group2/src/backend/postgres/table.m4
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/table.m4 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/table.m4 2006-11-01 00:01:35 UTC (rev 15066)
@@ -13,8 +13,8 @@
commodity, , char *, gnc_commodity_get_unique_name(xaccAccountGetCommodity(ptr)),
version, , int32, xaccAccountGetVersion(ptr),
iguid, , int32, ptr->idata,
- bookGUID, , GUID *, qof_entity_get_guid((QofEntity*)xaccAccountGetBook(ptr)),
- parentGUID, , GUID *, xaccAccountGetGUID(xaccAccountGetParentAccount(ptr)),
+ bookGUID, , GUID *, qof_entity_get_guid((QofEntity*)gnc_account_get_book(ptr)),
+ parentGUID, , GUID *, xaccAccountGetGUID(gnc_account_get_parent(ptr)),
accountGUID, KEY, GUID *, xaccAccountGetGUID(ptr),
')
Modified: gnucash/branches/remove-group2/src/backend/postgres/test/test-db.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/test/test-db.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/test/test-db.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -251,14 +251,12 @@
return TRUE;
}
-static gpointer
+static void
mark_account_commodities(Account * a, gpointer data)
{
GHashTable *hash = data;
g_hash_table_insert(hash, xaccAccountGetCommodity(a), hash);
-
- return NULL;
}
static int
@@ -311,10 +309,10 @@
book = qof_session_get_book(session);
- xaccGroupForEachAccount(gnc_book_get_group(book),
- mark_account_commodities, cdi.hash, TRUE);
+ gnc_account_foreach_descendant(gnc_book_get_root_account(book),
+ mark_account_commodities, cdi.hash);
- xaccGroupForEachTransaction(gnc_book_get_group(book),
+ xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
mark_transaction_commodities, cdi.hash);
gnc_pricedb_foreach_price(gnc_book_get_pricedb(book),
@@ -473,16 +471,16 @@
static int
session_num_trans(QofSession * session)
{
- AccountGroup *group;
+ Account *root;
QofBook *book;
int num = 0;
g_return_val_if_fail(session, 0);
book = qof_session_get_book(session);
- group = gnc_book_get_group(book);
+ root = gnc_book_get_root_account(book);
- xaccGroupForEachTransaction(group, num_trans_helper, &num);
+ xaccAccountTreeForEachTransaction(root, num_trans_helper, &num);
return num;
}
@@ -626,7 +624,7 @@
ok = TRUE;
- list = xaccGroupGetSubAccounts(gnc_book_get_group(book_1));
+ list = gnc_account_get_descendants(gnc_book_get_root_account(book_1));
for (node = list; node; node = node->next) {
Account *account_1 = node->data;
Account *account_2;
@@ -677,21 +675,21 @@
test_queries(QofSession * session_base, DbInfo *dbinfo)
{
QueryTestData qtd;
- AccountGroup *group;
+ Account *root;
QofBook *book;
gboolean ok;
g_return_val_if_fail(dbinfo->dbname && dbinfo->mode, FALSE);
book = qof_session_get_book(session_base);
- group = gnc_book_get_group(book);
+ root = gnc_book_get_root_account(book);
qtd.session_base = session_base;
qtd.dbinfo = dbinfo;
qtd.loaded = 0;
qtd.total = 0;
- ok = xaccGroupForEachTransaction(group, test_trans_query, &qtd);
+ ok = xaccAccountTreeForEachTransaction(root, test_trans_query, &qtd);
#if 0
g_warning("average percentage loaded = %3.2f%%",
@@ -708,8 +706,8 @@
QofBook *book_1;
QofBook *book_2;
- AccountGroup *group_1;
- AccountGroup *group_2;
+ Account *root_1;
+ Account *root_2;
GList *accounts_1;
GList *accounts_2;
@@ -834,8 +832,8 @@
td.session_1 = session_base;
td.book_1 = qof_session_get_book(session_base);
- td.group_1 = gnc_book_get_group(td.book_1);
- td.accounts_1 = xaccGroupGetSubAccounts(td.group_1);
+ td.root_1 = gnc_book_get_root_account(td.book_1);
+ td.accounts_1 = gnc_account_get_descendants(td.root_1);
td.session_2 = qof_session_new();
@@ -845,12 +843,12 @@
multi_user_get_everything(td.session_2, NULL);
td.book_2 = qof_session_get_book(td.session_2);
- td.group_2 = gnc_book_get_group(td.book_2);
- td.accounts_2 = xaccGroupGetSubAccounts(td.group_2);
+ td.root_2 = gnc_book_get_root_account(td.book_2);
+ td.accounts_2 = gnc_account_get_descendants(td.root_2);
ok = TRUE;
transes = NULL;
- xaccGroupForEachTransaction(td.group_1, add_trans_helper, &transes);
+ xaccAccountTreeForEachTransaction(td.root_1, add_trans_helper, &transes);
for (node = transes; node; node = node->next) {
ok = test_trans_update(node->data, &td);
if (!ok)
@@ -891,8 +889,8 @@
xaccAccountBeginEdit(account);
xaccAccountBeginEdit(child);
- xaccGroupInsertAccount(td.group_1, account);
- xaccAccountInsertSubAccount(account, child);
+ gnc_account_append_child(td.root_1, account);
+ gnc_account_append_child(account, child);
xaccAccountCommitEdit(child);
xaccAccountCommitEdit(account);
@@ -1128,8 +1126,8 @@
set_max_kvp_depth(3);
set_max_kvp_frame_elements(3);
- set_max_group_depth(3);
- set_max_group_accounts(3);
+ set_max_account_tree_depth(3);
+ set_max_accounts_per_level(3);
random_timespec_zero_nsec(TRUE);
Modified: gnucash/branches/remove-group2/src/backend/postgres/test/test-period.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/test/test-period.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/test/test-period.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -28,7 +28,6 @@
#include <time.h>
#include "Account.h"
-#include "Group.h"
#include "Period.h"
#include "qof.h"
#include "test-stuff.h"
@@ -43,9 +42,8 @@
QofBackendError io_err;
QofSession *session;
QofBook *openbook, *closedbook;
- AccountGroup *grp;
- AccountList *acclist, *anode;
- Account * acc = NULL;
+ GList *acclist, *anode;
+ Account *root, *acc = NULL;
SplitList *splist;
Split *sfirst, *slast;
Transaction *tfirst, *tlast;
@@ -72,9 +70,9 @@
add_random_transactions_to_book (openbook, 12);
- grp = gnc_book_get_group (openbook);
+ root = gnc_book_get_root_account(openbook);
- acclist = xaccGroupGetSubAccounts (grp);
+ acclist = gnc_account_get_descendants (root);
for (anode=acclist; anode; anode=anode->next)
{
int ns;
@@ -83,6 +81,7 @@
if (2 <= ns) break;
acc = NULL;
}
+ g_list_free(acclist);
if(!acc)
{
Modified: gnucash/branches/remove-group2/src/backend/postgres/txn.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/txn.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/txn.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -31,8 +31,6 @@
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-pricedb.h"
@@ -350,11 +348,11 @@
void
-pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp)
+pgendStoreAllTransactions (PGBackend *be, Account *root)
{
char *p;
- ENTER ("be=%p, grp=%p", be, grp);
- if (!be || !grp) return;
+ ENTER ("be=%p, root=%p", be, root);
+ if (!be || !root) return;
/* lock it up so that we store atomically */
p = "BEGIN;\n"
@@ -365,8 +363,8 @@
/* Recursively walk transactions. Start by reseting the write
* flags. We use this to avoid infinite recursion */
- xaccGroupBeginStagedTransactionTraversals(grp);
- xaccGroupStagedTransactionTraversal (grp, 1, trans_traverse_cb, be);
+ gnc_account_tree_begin_staged_transaction_traversals(root);
+ gnc_account_tree_staged_transaction_traversal (root, 1, trans_traverse_cb, be);
p = "COMMIT;\n"
"NOTIFY gncTransaction;";
@@ -378,7 +376,7 @@
if ((MODE_POLL == be->session_mode) ||
(MODE_EVENT == be->session_mode))
{
- pgendGroupRecomputeAllCheckpoints(be, grp);
+ pgendAccountTreeRecomputeAllCheckpoints(be, root);
}
LEAVE(" ");
}
@@ -503,8 +501,6 @@
if (acc)
{
- int save_state;
-
if (acc != previous_acc)
{
xaccAccountCommitEdit (previous_acc);
@@ -512,15 +508,7 @@
previous_acc = acc;
}
- if (acc->parent)
- save_state = acc->parent->saved;
- else
- save_state = 1;
-
xaccAccountInsertSplit(acc, s);
-
- if (acc->parent)
- acc->parent->saved = save_state;
}
/* It's ok to set value without an account, since
@@ -570,21 +558,12 @@
if (account)
{
gnc_numeric amount;
- int save_state;
int acct_frac;
- if (account->parent)
- save_state = account->parent->saved;
- else
- save_state = 1;
-
xaccAccountBeginEdit (account);
xaccAccountInsertSplit (account, sri->split);
xaccAccountCommitEdit (account);
- if (account->parent)
- account->parent->saved = save_state;
-
acct_frac = xaccAccountGetCommoditySCU (account);
amount = gnc_numeric_create (sri->amount, acct_frac);
xaccSplitSetAmount (sri->split, amount);
@@ -1059,12 +1038,17 @@
* what should happen is the user should get a chance to
* resynchronize their data with the backend, before quiting out.
*/
+#if 0
+ /* DRH - Is this code required any more? The whole point seems to
+ * be to clear the dirty flag in any of the AccountGroup data
+ * structures. Since these structures no longer exist.... */
{
Split * s = xaccTransGetSplit (trans, 0);
Account *acc = xaccSplitGetAccount (s);
- AccountGroup *top = xaccAccountGetRoot (acc);
+ AccountGroup *top = gnc_account_get_root (acc);
xaccGroupMarkSaved (top);
}
+#endif
LEAVE ("commited");
return;
Modified: gnucash/branches/remove-group2/src/backend/postgres/txn.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/txn.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/txn.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -36,7 +36,6 @@
#include <glib.h>
-#include "Group.h"
#include "qof.h"
#include "Transaction.h"
@@ -45,7 +44,7 @@
int pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid);
void pgendCopySplitsToEngine (PGBackend *be, Transaction *trans);
-void pgendStoreAllTransactions (PGBackend *be, AccountGroup *grp);
+void pgendStoreAllTransactions (PGBackend *be, Account *root);
void pgendStoreTransactionNoLock (PGBackend *be, Transaction *trans, gboolean do_check_version);
void pgend_trans_commit_edit (QofBackend * bend, Transaction * trans, Transaction * oldtrans);
Modified: gnucash/branches/remove-group2/src/backend/postgres/txnmass.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/postgres/txnmass.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/backend/postgres/txnmass.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -31,8 +31,6 @@
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "Transaction.h"
@@ -215,7 +213,7 @@
{
char *p, buff[900];
GList *node, *xaction_list = NULL;
- AccountGroup *grp;
+ Account *root;
qof_event_suspend();
pgendDisable(be);
@@ -233,8 +231,8 @@
SEND_QUERY (be, buff, );
/* restore the transactions */
- grp = gnc_book_get_group (book);
- xaccAccountGroupBeginEdit (grp);
+ root = gnc_book_get_root_account (book);
+ xaccAccountBeginEdit (root);
be->tmp_return = NULL;
pgendGetResults (be, get_mass_trans_cb, book);
@@ -280,7 +278,7 @@
}
g_list_free(xaction_list);
- xaccAccountGroupCommitEdit (grp);
+ xaccAccountCommitEdit (root);
pgendEnable(be);
qof_event_resume();
Modified: gnucash/branches/remove-group2/src/business/business-core/gncInvoice.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-core/gncInvoice.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-core/gncInvoice.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1262,7 +1262,7 @@
g_return_val_if_fail (owner->owner.undefined != NULL, NULL);
/* Compute the ancillary data */
- book = xaccAccountGetBook (posted_acc);
+ book = gnc_account_get_book (posted_acc);
name = gncOwnerGetName (gncOwnerGetEndOwner (owner));
commodity = gncOwnerGetCurrency (owner);
reverse = (gncOwnerGetType (owner) == GNC_OWNER_CUSTOMER);
Modified: gnucash/branches/remove-group2/src/business/business-gnome/business-gnome-utils.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-gnome/business-gnome-utils.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-gnome/business-gnome-utils.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -28,7 +28,6 @@
#include <gtk/gtk.h>
#include <glib/gi18n.h>
-#include "Group.h"
#include "Account.h"
#include "gnc-ui-util.h"
#include "qof.h"
@@ -318,7 +317,7 @@
/* Figure out if anything is set in the combo */
text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo));
- list = xaccGroupGetSubAccounts (gnc_book_get_group (book));
+ list = gnc_account_get_descendants (gnc_book_get_root_account (book));
/* Clear the existing list */
entry = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(combo)));
Modified: gnucash/branches/remove-group2/src/business/business-gnome/dialog-payment.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-gnome/dialog-payment.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-gnome/dialog-payment.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -255,7 +255,7 @@
return;
}
- post = xaccGetAccountFromFullName (gnc_book_get_group (pw->book), text);
+ post = gnc_account_lookup_by_full_name (gnc_book_get_root_account (pw->book), text);
if (!post) {
char *msg = g_strdup_printf (
Modified: gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-business.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-business.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-business.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -886,7 +886,7 @@
GncInvoice *invoice = gncInvoiceCreate(book);
GncOwner *owner = gncOwnerCreate();
GncJob *job = gncJobCreate(book);
- AccountGroup *group = xaccGetAccountGroup(book);
+ Account *root = gnc_book_get_root_account(book);
Account *inc_acct = xaccMallocAccount(book);
Account *bank_acct = xaccMallocAccount(book);
Account *tax_acct = xaccMallocAccount(book);
@@ -925,25 +925,25 @@
xaccAccountSetType(ar_acct, ACCT_TYPE_RECEIVABLE);
xaccAccountSetName(ar_acct, "A/R");
xaccAccountSetCommodity(ar_acct, gnc_default_currency());
- xaccGroupInsertAccount(group, ar_acct);
+ gnc_account_append_child(root, ar_acct);
// Create the Income account
xaccAccountSetType(inc_acct, ACCT_TYPE_INCOME);
xaccAccountSetName(inc_acct, "Income");
xaccAccountSetCommodity(inc_acct, gnc_default_currency());
- xaccGroupInsertAccount(group, inc_acct);
+ gnc_account_append_child(root, inc_acct);
// Create the Bank account
xaccAccountSetType(bank_acct, ACCT_TYPE_BANK);
xaccAccountSetName(bank_acct, "Bank");
xaccAccountSetCommodity(bank_acct, gnc_default_currency());
- xaccGroupInsertAccount(group, bank_acct);
+ gnc_account_append_child(root, bank_acct);
// Create the Tax account
xaccAccountSetType(tax_acct, ACCT_TYPE_LIABILITY);
xaccAccountSetName(tax_acct, "Tax-Holding");
xaccAccountSetCommodity(tax_acct, gnc_default_currency());
- xaccGroupInsertAccount(group, tax_acct);
+ gnc_account_append_child(root, tax_acct);
// Launch the invoice editor
gnc_ui_invoice_edit(invoice);
Modified: gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-page-invoice.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-page-invoice.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-gnome/gnc-plugin-page-invoice.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -534,7 +534,7 @@
g_return_if_fail(GNC_IS_PLUGIN_PAGE_INVOICE(plugin_page));
ENTER("(action %p, plugin_page %p)", action, plugin_page);
- gnc_ui_new_account_window (NULL);
+ gnc_ui_new_account_window (gnc_get_current_book(), NULL);
LEAVE(" ");
}
Modified: gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedger.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedger.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedger.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -86,7 +86,7 @@
Account *account;
/* Find the account */
- account = xaccGetAccountFromFullName (gnc_get_current_group (), name);
+ account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name);
if (!account) {
/* Ask if they want to create a new one. */
Modified: gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedgerLoad.c
===================================================================
--- gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedgerLoad.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-ledger/gncEntryLedgerLoad.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -180,13 +180,13 @@
static void
load_xfer_type_cells (GncEntryLedger *ledger)
{
- AccountGroup *group;
+ Account *root;
ComboCell *cell;
QuickFill *qf=NULL;
GtkListStore *store = NULL;
- group = gnc_book_get_group (ledger->book);
- if (group == NULL) return;
+ root = gnc_book_get_root_account (ledger->book);
+ if (root == NULL) return;
/* Use a common, shared quickfill. For the ORDER or INVOICE,
* ledgers, we don't want expense-type accounts in the menu.
@@ -198,9 +198,9 @@
case GNCENTRY_ORDER_VIEWER:
case GNCENTRY_INVOICE_ENTRY:
case GNCENTRY_INVOICE_VIEWER:
- qf = gnc_get_shared_account_name_quickfill (group, IKEY,
+ qf = gnc_get_shared_account_name_quickfill (root, IKEY,
skip_expense_acct_cb, NULL);
- store = gnc_get_shared_account_name_list_store (group, IKEY,
+ store = gnc_get_shared_account_name_list_store (root, IKEY,
skip_expense_acct_cb, NULL);
break;
@@ -209,9 +209,9 @@
case GNCENTRY_EXPVOUCHER_ENTRY:
case GNCENTRY_EXPVOUCHER_VIEWER:
case GNCENTRY_NUM_REGISTER_TYPES:
- qf = gnc_get_shared_account_name_quickfill (group, EKEY,
+ qf = gnc_get_shared_account_name_quickfill (root, EKEY,
skip_income_acct_cb, NULL);
- store = gnc_get_shared_account_name_list_store (group, EKEY,
+ store = gnc_get_shared_account_name_list_store (root, EKEY,
skip_income_acct_cb, NULL);
break;
}
Modified: gnucash/branches/remove-group2/src/business/business-reports/owner-report.scm
===================================================================
--- gnucash/branches/remove-group2/src/business/business-reports/owner-report.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/business/business-reports/owner-report.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -626,20 +626,19 @@
document))
(define (find-first-account type)
- (define (find-first group num index)
+ (define (find-first account num index)
(if (>= index num)
'()
- (let* ((this-account (xaccGroupGetAccount group index))
- (account-type (xaccAccountGetType this-account)))
+ (let* ((this-child (gnc-account-nth-child account index))
+ (account-type (xaccAccountGetType this-child)))
(if (eq? account-type type)
- this-account
- (find-first group num (+ index 1))))))
+ this-child
+ (find-first account num (+ index 1))))))
- (let* ((current-group (gnc-get-current-group))
- (num-accounts (xaccGroupGetNumAccounts
- current-group)))
+ (let* ((current-root (gnc-get-current-root-account))
+ (num-accounts (gnc-account-n-children current-root)))
(if (> num-accounts 0)
- (find-first current-group num-accounts 0)
+ (find-first current-root num-accounts 0)
'())))
(define (find-first-account-for-owner owner)
Modified: gnucash/branches/remove-group2/src/engine/Account.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -30,8 +30,8 @@
#include <string.h>
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
+#include "Split.h"
+#include "Transaction.h"
#include "TransactionP.h"
#include "gnc-event.h"
#include "gnc-glib-utils.h"
@@ -40,6 +40,8 @@
#include "gnc-pricedb.h"
#include "policy.h"
+#define GNC_ID_ROOT_ACCOUNT "RootAccount"
+
static QofLogModule log_module = GNC_MOD_ACCOUNT;
/* The Canonical Account Separator. Pre-Initialized. */
@@ -100,7 +102,6 @@
void
mark_account (Account *acc)
{
- if (acc->parent) acc->parent->saved = FALSE;
qof_instance_set_dirty(&acc->inst);
}
@@ -151,7 +152,64 @@
/********************************************************************\
\********************************************************************/
+static Account *
+gnc_coll_get_root_account (QofCollection *col)
+{
+ if (!col) return NULL;
+ return qof_collection_get_data (col);
+}
+
+static void
+gnc_coll_set_root_account (QofCollection *col, Account *root)
+{
+ Account *old_root;
+ if (!col) return;
+
+ old_root = gnc_coll_get_root_account (col);
+ if (old_root == root) return;
+
+ qof_collection_set_data (col, root);
+
+ if (old_root) {
+ xaccAccountBeginEdit (old_root);
+ xaccAccountDestroy (old_root);
+ }
+}
+
Account *
+gnc_book_get_root_account (QofBook *book)
+{
+ QofCollection *col;
+ Account *root;
+
+ if (!book) return NULL;
+ col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
+ root = gnc_coll_get_root_account (col);
+ if (root == NULL)
+ root = gnc_account_create_root(book);
+ return root;
+}
+
+void
+gnc_book_set_root_account (QofBook *book, Account *root)
+{
+ QofCollection *col;
+ if (!book) return;
+
+ if (root && gnc_account_get_book(root) != book)
+ {
+ PERR ("cannot mix and match books freely!");
+ return;
+ }
+
+ col = qof_book_get_collection (book, GNC_ID_ROOT_ACCOUNT);
+ gnc_coll_set_root_account (col, root);
+}
+
+/********************************************************************\
+\********************************************************************/
+
+Account *
xaccMallocAccount (QofBook *book)
{
Account *acc;
@@ -165,6 +223,19 @@
return acc;
}
+Account *
+gnc_account_create_root (QofBook *book)
+{
+ Account *root;
+
+ root = xaccMallocAccount(book);
+ xaccAccountBeginEdit(root);
+ root->type = ACCT_TYPE_ROOT;
+ xaccAccountCommitEdit(root);
+ gnc_book_set_root_account(book, root);
+ return root;
+}
+
static Account *
xaccCloneAccountCommon(const Account *from, QofBook *book)
{
@@ -222,6 +293,32 @@
/********************************************************************\
\********************************************************************/
+static void
+xaccFreeOneChildAccount (Account *acc, gpointer dummy)
+{
+ /* FIXME: this code is kind of hacky. actually, all this code
+ * seems to assume that the account edit levels are all 1. */
+ if (acc->inst.editlevel == 0)
+ xaccAccountBeginEdit(acc);
+ xaccAccountDestroy(acc);
+}
+
+static void
+xaccFreeAccountChildren (Account *acc)
+{
+ GList *children;
+
+ /* Copy the list since it will be modified */
+ children = g_list_copy(acc->children);
+ g_list_foreach(children, (GFunc)xaccFreeOneChildAccount, NULL);
+ g_list_free(children);
+
+ /* The foreach should have removed all the children already. */
+ if (acc->children)
+ g_list_free(acc->children);
+ acc->children = NULL;
+}
+
void
xaccFreeAccount (Account *acc)
{
@@ -237,8 +334,7 @@
" xaccAccountBeginEdit(); xaccAccountDestroy(); \n");
/* First, recursively free children */
- xaccFreeAccountGroup (acc->children);
- acc->children = NULL;
+ xaccFreeAccountChildren(acc);
}
/* remove lots -- although these should be gone by now. */
@@ -329,7 +425,9 @@
static inline void acc_free (QofInstance *inst)
{
Account *acc = (Account *) inst;
- xaccGroupRemoveAccount(acc->parent, acc);
+
+ if (acc->parent)
+ gnc_account_remove_child(acc->parent, acc);
xaccFreeAccount(acc);
}
@@ -360,8 +458,7 @@
acc->inst.editlevel++;
/* First, recursively free children */
- xaccFreeAccountGroup (acc->children);
- acc->children = NULL;
+ xaccFreeAccountChildren(acc);
PINFO ("freeing splits for account %p (%s)",
acc, acc->accountName ? acc->accountName : "(null)");
@@ -432,6 +529,48 @@
/********************************************************************\
\********************************************************************/
+static gboolean
+xaccAcctChildrenEqual(const GList *na,
+ const GList *nb,
+ gboolean check_guids)
+{
+ if ((!na && nb) || (na && !nb))
+ {
+ PWARN ("only one has accounts");
+ return(FALSE);
+ }
+
+ while (na && nb)
+ {
+ Account *aa = na->data;
+ Account *ab = nb->data;
+
+ if (!xaccAccountEqual(aa, ab, check_guids))
+ {
+ char sa[GUID_ENCODING_LENGTH + 1];
+ char sb[GUID_ENCODING_LENGTH + 1];
+
+ guid_to_string_buff (xaccAccountGetGUID (aa), sa);
+ guid_to_string_buff (xaccAccountGetGUID (ab), sb);
+
+ PWARN ("accounts %s and %s differ", sa, sb);
+
+ return(FALSE);
+ }
+
+ na = na->next;
+ nb = nb->next;
+ }
+
+ if (na || nb)
+ {
+ PWARN ("different numbers of accounts");
+ return(FALSE);
+ }
+
+ return(TRUE);
+}
+
gboolean
xaccAccountEqual(const Account *aa, const Account *ab, gboolean check_guids)
{
@@ -633,7 +772,7 @@
}
}
- if (!xaccGroupEqual(aa->children, ab->children, check_guids))
+ if (!xaccAcctChildrenEqual(aa->children, ab->children, check_guids))
{
PWARN ("children differ");
return FALSE;
@@ -712,72 +851,26 @@
void
xaccClearMark (Account *acc, short val)
{
- AccountGroup *topgrp;
+ Account *root;
if (!acc) return;
- topgrp = xaccAccountGetRoot (acc);
-
- if (topgrp)
- {
- GList *list;
- GList *node;
-
- list = xaccGroupGetAccountList (topgrp);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccClearMarkDown (account, val);
- }
- }
- else
- xaccClearMarkDown (acc, val);
+ root = gnc_account_get_root (acc);
+ xaccClearMarkDown (root ? root : acc, val);
}
void
xaccClearMarkDown (Account *acc, short val)
{
- AccountGroup *children;
+ GList *node;
if (!acc) return;
acc->mark = val;
- children = acc->children;
- if (children)
- {
- GList *list;
- GList *node;
-
- list = xaccGroupGetAccountList (children);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccClearMarkDown (account, val);
- }
+ for (node = acc->children; node; node = node->next) {
+ xaccClearMarkDown (node->data, val);
}
}
-void
-xaccClearMarkDownGr (AccountGroup *grp, short val)
-{
- GList *list;
- GList *node;
-
- if (!grp) return;
-
- list = xaccGroupGetAccountList (grp);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccClearMarkDown (account, val);
- }
-}
-
/********************************************************************\
\********************************************************************/
@@ -996,20 +1089,20 @@
int
-xaccAccountOrder (const Account **aa, const Account **ab)
+xaccAccountOrder (const Account *aa, const Account *ab)
{
char *da, *db;
char *endptr = NULL;
int ta, tb, result;
long la, lb;
- if ( (*aa) && !(*ab) ) return -1;
- if ( !(*aa) && (*ab) ) return +1;
- if ( !(*aa) && !(*ab) ) return 0;
+ if ( aa && !ab ) return -1;
+ if ( !aa && ab ) return +1;
+ if ( !aa && !ab ) return 0;
/* sort on accountCode strings */
- da = (*aa)->accountCode;
- db = (*ab)->accountCode;
+ da = aa->accountCode;
+ db = ab->accountCode;
/* If accountCodes are both base 36 integers do an integer sort */
la = strtoul (da, &endptr, 36);
@@ -1036,24 +1129,30 @@
}
/* otherwise, sort on account type */
- ta = (*aa)->type;
- tb = (*ab)->type;
+ ta = aa->type;
+ tb = ab->type;
ta = revorder[ta];
tb = revorder[tb];
if (ta < tb) return -1;
if (ta > tb) return +1;
/* otherwise, sort on accountName strings */
- da = (*aa)->accountName;
- db = (*ab)->accountName;
+ da = aa->accountName;
+ db = ab->accountName;
result = safe_utf8_collate(da, db);
if (result)
return result;
/* guarantee a stable sort */
- return guid_compare (&((*aa)->inst.entity.guid), &((*ab)->inst.entity.guid));
+ return guid_compare (&(aa->inst.entity.guid), &(ab->inst.entity.guid));
}
+static int
+qof_xaccAccountOrder (const Account **aa, const Account **ab)
+{
+ return xaccAccountOrder(*aa, *ab);
+}
+
/********************************************************************\
\********************************************************************/
@@ -1115,7 +1214,7 @@
parent_acc = (Account*)parent;
xaccAccountBeginEdit(acc);
xaccAccountBeginEdit(parent_acc);
- xaccAccountInsertSubAccount(parent_acc, acc);
+ gnc_account_append_child(parent_acc, acc);
mark_account (parent_acc);
mark_account (acc);
xaccAccountCommitEdit(acc);
@@ -1258,30 +1357,384 @@
/********************************************************************\
\********************************************************************/
-AccountGroup *
-xaccAccountGetChildren (const Account *acc)
+void
+gnc_account_append_child (Account *new_parent, Account *child)
{
- return acc ? acc->children : NULL;
+ Account *old_parent;
+ QofCollection *col;
+
+ g_assert(new_parent);
+ g_assert(child);
+
+ old_parent = child->parent;
+ if (old_parent == new_parent)
+ return;
+
+ // xaccAccountBeginEdit(new_parent);
+ xaccAccountBeginEdit(child);
+ if (old_parent) {
+ gnc_account_remove_child(old_parent, child);
+
+ if (old_parent->inst.book != new_parent->inst.book) {
+ /* hack alert -- this implementation is not exactly correct.
+ * If the entity tables are not identical, then the 'from' book
+ * may have a different backend than the 'to' book. This means
+ * that we should get the 'from' backend to destroy this account,
+ * and the 'to' backend to save it. Right now, this is broken.
+ *
+ * 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 across books is not correctly supported\n");
+
+ qof_event_gen (&child->inst.entity, QOF_EVENT_DESTROY, NULL);
+ col = qof_book_get_collection (new_parent->inst.book, GNC_ID_ACCOUNT);
+ qof_collection_insert_entity (col, &child->inst.entity);
+ qof_event_gen (&child->inst.entity, QOF_EVENT_CREATE, NULL);
+ }
+ }
+ child->parent = new_parent;
+ new_parent->children = g_list_append(new_parent->children, child);
+ qof_instance_set_dirty(&new_parent->inst);
+ qof_instance_set_dirty(&child->inst);
+
+ /* Send events data. Warning: The call to commit_edit is also gpoing
+ * to send a MODIFY event. If the gtktreemodelfilter code gets the
+ * MODIFY before it gets the ADD, it gets very confused and thinks
+ * that two nodes have been added. */
+ qof_event_gen (&child->inst.entity, QOF_EVENT_ADD, NULL);
+ // qof_event_gen (&new_parent->inst.entity, QOF_EVENT_MODIFY, NULL);
+
+ xaccAccountCommitEdit (child);
+ // xaccAccountCommitEdit(new_parent);
}
-AccountGroup *
-xaccAccountGetParent (const Account *acc)
+void
+gnc_account_remove_child (Account *parent, Account *child)
{
+ GncEventData ed;
+
+ if (!child) return;
+
+ /* Note this routine might be called on accounts which
+ * are not yet parented. */
+ if (!parent) return;
+
+ if (child->parent != parent)
+ {
+ PERR ("account not a child of parent");
+ return;
+ }
+
+ /* Gather event data */
+ ed.node = parent;
+ ed.idx = g_list_index(parent->children, child);
+
+ parent->children = g_list_remove (parent->children, child);
+
+ /* Now send the event. */
+ qof_event_gen(&child->inst.entity, QOF_EVENT_REMOVE, &ed);
+
+ /* clear the account's parent pointer after REMOVE event generation. */
+ child->parent = NULL;
+
+ qof_event_gen (&parent->inst.entity, QOF_EVENT_MODIFY, NULL);
+}
+
+Account *
+gnc_account_get_parent (const Account *acc)
+{
return acc ? acc->parent : NULL;
}
Account *
-xaccAccountGetParentAccount (const Account * acc)
+gnc_account_get_root (Account *acc)
{
- return acc ? xaccGroupGetParentAccount(acc->parent) : NULL;
+ if (!acc)
+ return NULL;
+
+ while (acc->parent) {
+ acc = acc->parent;
+ }
+
+ return acc;
}
+gboolean
+gnc_account_is_root (const Account *account)
+{
+ return (account && account->parent == NULL);
+}
+
GList *
-xaccAccountGetDescendants (const Account *acc)
+gnc_account_get_children (const Account *account)
{
- return acc ? xaccGroupGetSubAccounts(acc->children) : NULL;
+ return account ? g_list_copy(account->children) : NULL;
}
+GList *
+gnc_account_get_children_sorted (const Account *account)
+{
+ if (!account || !account->children)
+ return NULL;
+ return g_list_sort(g_list_copy(account->children), (GCompareFunc)xaccAccountOrder);
+}
+
+gint
+gnc_account_n_children (const Account *account)
+{
+ return account ? g_list_length(account->children) : 0;
+}
+
+gint
+gnc_account_child_index (const Account *parent, const Account *child)
+{
+ return parent ? g_list_index(parent->children, child) : -1;
+}
+
+Account *
+gnc_account_nth_child (const Account *parent, gint num)
+{
+ return parent ? g_list_nth_data(parent->children, num) : NULL;
+}
+
+GList *
+gnc_account_get_descendants (const Account *account)
+{
+ GList *child, *descendants;
+
+ if (!account || !account->children)
+ return NULL;
+
+ descendants = NULL;
+ for (child = account->children; child; child = g_list_next(child)) {
+ descendants = g_list_append(descendants, child->data);
+ descendants = g_list_concat(descendants,
+ gnc_account_get_descendants(child->data));
+ }
+ return descendants;
+}
+
+GList *
+gnc_account_get_descendants_sorted (const Account *account)
+{
+ GList *child, *children, *descendants;
+
+ if (!account || !account->children)
+ return NULL;
+
+ descendants = NULL;
+ children = g_list_sort(g_list_copy(account->children), (GCompareFunc)xaccAccountOrder);
+ for (child = children; child; child = g_list_next(child)) {
+ descendants = g_list_append(descendants, child->data);
+ descendants = g_list_concat(descendants,
+ gnc_account_get_descendants(child->data));
+ }
+ g_list_free(children);
+ return descendants;
+}
+
+gint
+gnc_account_n_descendants (const Account *account)
+{
+ GList *node;
+ gint count = 0;
+
+ if (!account)
+ return 0;
+
+ for (node = account->children; node; node = g_list_next(node)) {
+ count += gnc_account_n_descendants(node->data) + 1;
+ }
+ return count;
+}
+
+gint
+gnc_account_get_depth (const Account *account)
+{
+ GList *node;
+ gint depth = 0, child_depth;
+
+ if (!account)
+ return 0;
+ if (!account->children)
+ return 1;
+
+ for (node = account->children; node; node = g_list_next(node)) {
+ child_depth = gnc_account_get_depth(node->data);
+ depth = MAX(depth, child_depth);
+ }
+ return depth + 1;
+}
+
+Account *
+gnc_account_lookup_by_name (const Account *parent, const char * name)
+{
+ Account *child, *result;
+ GList *node;
+
+ if (!parent) return NULL;
+ if (!name) return NULL;
+
+ /* first, look for accounts hanging off the current node */
+ for (node = parent->children; node; node = node->next)
+ {
+ child = node->data;
+ if (safe_strcmp(child->accountName, name) == 0)
+ return child;
+ }
+
+ /* if we are still here, then we haven't found the account yet.
+ * Recursively search each of the child accounts next */
+ for (node = parent->children; node; node = node->next)
+ {
+ child = node->data;
+ result = gnc_account_lookup_by_name (child, name);
+ if (result)
+ return result;
+ }
+
+ return NULL;
+}
+
+/********************************************************************\
+ * Fetch an account, given its full name *
+\********************************************************************/
+
+static Account *
+gnc_account_lookup_by_full_name_helper (const Account *parent,
+ gchar **names)
+{
+ Account *found;
+ GList *node;
+
+ g_return_val_if_fail(parent, NULL);
+ g_return_val_if_fail(names, NULL);
+
+ /* Look for the first name in the children. */
+ for (node = parent->children; node; node = node->next) {
+ Account *account = node->data;
+
+ if (safe_strcmp(account->accountName, names[0]) == 0) {
+ /* We found an account. If the next entry is NULL, there is
+ * nothing left in the name, so just return the account. */
+ if (names[1] == NULL)
+ return account;
+
+ /* No children? We're done. */
+ if (!account->children)
+ return NULL;
+
+ /* There's stuff left to search for. Search recursively. */
+ found = gnc_account_lookup_by_full_name_helper(account, &names[1]);
+ if (found != NULL) {
+ return found;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+
+Account *
+gnc_account_lookup_by_full_name (const Account *any_acc,
+ const gchar *name)
+{
+ const Account *root;
+ Account *found;
+ gchar **names;
+
+ if (!any_acc) return NULL;
+ if (!name) return NULL;
+
+ root = any_acc;
+ while (root->parent)
+ root = root->parent;
+ names = g_strsplit(name, gnc_get_account_separator_string(), -1);
+ found = gnc_account_lookup_by_full_name_helper(root, names);
+ g_strfreev(names);
+ return found;
+}
+
+void
+gnc_account_foreach_child (const Account *acc,
+ AccountCb thunk,
+ gpointer user_data)
+{
+ GList *node;
+
+ if (!acc || !thunk) return;
+
+ for (node = acc->children; node; node = node->next) {
+ thunk (node->data, user_data);
+ }
+}
+
+gpointer
+gnc_account_foreach_child_until (const Account *acc,
+ AccountCb2 thunk,
+ gpointer user_data)
+{
+ GList *node;
+ gpointer result;
+
+ if (!acc || !thunk) return(NULL);
+
+ for (node = acc->children; node; node = node->next) {
+ result = thunk (node->data, user_data);
+ if (result)
+ return(result);
+ }
+
+ return(NULL);
+}
+
+void
+gnc_account_foreach_descendant (const Account *acc,
+ AccountCb thunk,
+ gpointer user_data)
+{
+ GList *node;
+ Account *child;
+
+ if (!acc || !thunk) return;
+
+ for (node = acc->children; node; node = node->next) {
+ child = node->data;
+ thunk(child, user_data);
+ gnc_account_foreach_descendant(child, thunk, user_data);
+ }
+}
+
+gpointer
+gnc_account_foreach_descendant_until (const Account *acc,
+ AccountCb2 thunk,
+ gpointer user_data)
+{
+ GList *node;
+ Account *child;
+ gpointer result;
+
+ if (!acc || !thunk) return(NULL);
+
+ for (node = acc->children; node; node = node->next) {
+ child = node->data;
+ result = thunk(child, user_data);
+ if (result)
+ return(result);
+
+ result = gnc_account_foreach_descendant_until(child, thunk, user_data);
+ if (result)
+ return(result);
+ }
+
+ return(NULL);
+}
+
+
GNCAccountType
xaccAccountGetType (const Account *acc)
{
@@ -1314,23 +1767,25 @@
gchar **names;
int level;
- if (account == NULL)
+ if (!account || !account->parent)
return g_strdup("");
- /* Figure out how much space is needed */
+ /* Figure out how much space is needed by counting the nodes up to
+ * the root. */
level = 0;
- for (a = account; a; a = xaccAccountGetParentAccount(a)) {
+ for (a = account; a; a = a->parent) {
level++;
}
- /* Get all the pointers in the right order. */
- names = g_malloc((level+1) * sizeof(gchar *));
- names[level] = NULL;
- for (a = account; a; a = xaccAccountGetParentAccount(a)) {
+ /* Get all the pointers in the right order. The root node "entry"
+ * becomes the terminating NULL pointer for the array of strings. */
+ names = g_malloc(level * sizeof(gchar *));
+ names[--level] = NULL;
+ for (a = account; level > 0; a = a->parent) {
names[--level] = a->accountName;
}
- /* Build it */
+ /* Build the full name */
fullname = g_strjoinv(account_separator, names);
g_free(names);
@@ -1551,7 +2006,7 @@
gnc_commodity_equiv (balance_currency, new_currency))
return balance;
- book = xaccGroupGetBook (xaccAccountGetRoot (acc));
+ book = gnc_account_get_book (acc);
pdb = gnc_pricedb_get_db (book);
balance = gnc_pricedb_convert_balance_latest_price(
@@ -1579,7 +2034,7 @@
gnc_commodity_equiv (balance_currency, new_currency))
return balance;
- book = xaccGroupGetBook (xaccAccountGetRoot (acc));
+ book = gnc_account_get_book (acc);
pdb = gnc_book_get_pricedb (book);
ts.tv_sec = date;
@@ -1639,34 +2094,33 @@
* tree. This function is called once per account, and sums up the
* values of all these accounts.
*/
-static gpointer
+static void
xaccAccountBalanceHelper (Account *acc, gpointer data)
{
CurrencyBalance *cb = data;
gnc_numeric balance;
if (!cb->fn || !cb->currency)
- return NULL;
+ return;
balance = xaccAccountGetXxxBalanceInCurrency (acc, cb->fn, cb->currency);
cb->balance = gnc_numeric_add (cb->balance, balance,
gnc_commodity_get_fraction (cb->currency),
GNC_HOW_RND_ROUND);
- return NULL;
}
-static gpointer
+
+static void
xaccAccountBalanceAsOfDateHelper (Account *acc, gpointer data)
{
CurrencyBalance *cb = data;
gnc_numeric balance;
- g_return_val_if_fail (cb->asOfDateFn && cb->currency, NULL);
+ g_return_if_fail (cb->asOfDateFn && cb->currency);
balance = xaccAccountGetXxxBalanceAsOfDateInCurrency (
acc, cb->date, cb->asOfDateFn, cb->currency);
cb->balance = gnc_numeric_add (cb->balance, balance,
gnc_commodity_get_fraction (cb->currency),
GNC_HOW_RND_ROUND);
- return NULL;
}
@@ -1700,8 +2154,7 @@
if (include_children) {
CurrencyBalance cb = { report_commodity, balance, fn, NULL, 0 };
- xaccGroupForEachAccount (acc->children, xaccAccountBalanceHelper,
- &cb, TRUE);
+ gnc_account_foreach_descendant (acc, xaccAccountBalanceHelper, &cb);
balance = cb.balance;
}
@@ -1727,8 +2180,7 @@
if (include_children) {
CurrencyBalance cb = { report_commodity, balance, NULL, fn, date };
- xaccGroupForEachAccount (acc->children,
- xaccAccountBalanceAsOfDateHelper, &cb, TRUE);
+ gnc_account_foreach_descendant (acc, xaccAccountBalanceAsOfDateHelper, &cb);
balance = cb.balance;
}
@@ -1974,7 +2426,7 @@
if (!acc) return PLACEHOLDER_NONE;
if (xaccAccountGetPlaceholder(acc)) return PLACEHOLDER_THIS;
- descendants = xaccGroupGetSubAccounts(acc->children);
+ descendants = gnc_account_get_descendants(acc);
for (node = descendants; node; node = node->next)
if (xaccAccountGetPlaceholder((Account *) node->data)) {
ret = PLACEHOLDER_CHILD;
@@ -2018,7 +2470,7 @@
if (xaccAccountGetHidden(acc))
return TRUE;
- while ((acc = xaccAccountGetParentAccount(acc)) != NULL) {
+ while ((acc = acc->parent) != NULL) {
if (xaccAccountGetHidden(acc))
return TRUE;
}
@@ -2036,7 +2488,7 @@
if (!acc || !ancestor) return FALSE;
while (parent && parent != ancestor)
- parent = xaccAccountGetParentAccount(parent);
+ parent = parent->parent;
return (parent == ancestor);
}
@@ -2068,6 +2520,7 @@
GNC_RETURN_ENUM_AS_STRING(EQUITY);
GNC_RETURN_ENUM_AS_STRING(RECEIVABLE);
GNC_RETURN_ENUM_AS_STRING(PAYABLE);
+ GNC_RETURN_ENUM_AS_STRING(ROOT);
GNC_RETURN_ENUM_AS_STRING(CHECKING);
GNC_RETURN_ENUM_AS_STRING(SAVINGS);
GNC_RETURN_ENUM_AS_STRING(MONEYMRKT);
@@ -2102,6 +2555,7 @@
GNC_RETURN_ON_MATCH(EQUITY);
GNC_RETURN_ON_MATCH(RECEIVABLE);
GNC_RETURN_ON_MATCH(PAYABLE);
+ GNC_RETURN_ON_MATCH(ROOT);
GNC_RETURN_ON_MATCH(CHECKING);
GNC_RETURN_ON_MATCH(SAVINGS);
GNC_RETURN_ON_MATCH(MONEYMRKT);
@@ -2580,18 +3034,6 @@
/********************************************************************\
\********************************************************************/
-gint
-xaccAccountForEachTransaction(const Account *acc, TransactionCallback proc,
- void *data)
-{
- if (!acc || !proc) return 0;
- xaccAccountBeginStagedTransactionTraversals (acc);
- return xaccAccountStagedTransactionTraversal(acc, 42, proc, data);
-}
-
-/********************************************************************\
-\********************************************************************/
-
/* The caller of this function can get back one or both of the
* matching split and transaction pointers, depending on whether
* a valid pointer to the location to store those pointers is
@@ -2652,6 +3094,286 @@
}
/* ================================================================ */
+/* Concatenation, Mergeing functions */
+
+void
+gnc_account_join_children (Account *to_parent, Account *from_parent)
+{
+ GList *children, *node;
+
+ if (!to_parent || !from_parent) return;
+ if (!from_parent->children) return;
+
+ ENTER (" ");
+ children = g_list_copy(from_parent->children);
+ for (node = children; node; node = g_list_next(node))
+ gnc_account_append_child(to_parent, node->data);
+ g_list_free(children);
+ LEAVE (" ");
+}
+
+void
+gnc_account_copy_children (Account *to, Account *from)
+{
+ GList *node;
+ QofBook *to_book;
+
+ if (!to || !from) return;
+ if (!from->children) return;
+ to_book = gnc_account_get_book(to);
+ if (!to_book) return;
+
+ ENTER (" ");
+ xaccAccountBeginEdit(to);
+ xaccAccountBeginEdit(from);
+ for (node = from->children; node; node=node->next)
+ {
+ Account *to_acc, *from_acc = node->data;
+
+ /* This will copy the basic data and the KVP. It will
+ * not copy any splits/transactions. It will gemini. */
+ to_acc = xaccCloneAccount (from_acc, to_book);
+
+ xaccAccountBeginEdit (to_acc);
+ to->children = g_list_append (to->children, to_acc);
+
+ to_acc->parent = to;
+ qof_instance_set_dirty(&to_acc->inst);
+
+ /* Copy child accounts too. */
+ if (from_acc->children)
+ {
+ gnc_account_copy_children(to_acc, from_acc);
+ }
+ xaccAccountCommitEdit (to_acc);
+ qof_event_gen (&to_acc->inst.entity, QOF_EVENT_CREATE, NULL);
+ /* DRH - Should this send ADD/REMOVE events */
+ }
+ xaccAccountCommitEdit(from);
+ xaccAccountCommitEdit(to);
+ LEAVE (" ");
+}
+
+/********************************************************************\
+\********************************************************************/
+
+void
+gnc_account_merge_children (Account *parent)
+{
+ GList *node_a;
+ GList *node_b;
+
+ if (!parent) return;
+
+ for (node_a = parent->children; node_a; node_a = node_a->next)
+ {
+ Account *acc_a = node_a->data;
+
+ for (node_b = node_a->next; node_b; node_b = g_list_next(node_b))
+ {
+ Account *acc_b = node_b->data;
+
+ if (0 != safe_strcmp(acc_a->accountName, acc_b->accountName))
+ continue;
+ if (0 != safe_strcmp(acc_a->accountCode, acc_b->accountCode))
+ continue;
+ if (0 != safe_strcmp(acc_a->description, acc_b->description))
+ continue;
+ if (!gnc_commodity_equiv(acc_a->commodity, acc_b->commodity))
+ continue;
+ if (0 != safe_strcmp(xaccAccountGetNotes(acc_a),
+ xaccAccountGetNotes(acc_b)))
+ continue;
+ if (acc_a->type != acc_b->type)
+ continue;
+
+ /* consolidate children */
+ if (acc_b->children) {
+ acc_a->children = g_list_concat(acc_a->children, acc_b->children);
+ acc_b->children = NULL;
+ qof_event_gen (&acc_a->inst.entity, QOF_EVENT_MODIFY, NULL);
+ qof_event_gen (&acc_b->inst.entity, QOF_EVENT_MODIFY, NULL);
+ }
+
+ /* recurse to do the children's children */
+ gnc_account_merge_children (acc_a);
+
+ /* consolidate transactions */
+ while (acc_b->splits)
+ xaccSplitSetAccount (acc_b->splits->data, acc_a);
+
+ /* move back one before removal. next iteration around the loop
+ * will get the node after node_b */
+ node_b = g_list_previous(node_b);
+
+ /* The destroy function will remove from list -- node_a is ok,
+ * it's before node_b */
+ xaccAccountBeginEdit (acc_b);
+ xaccAccountDestroy (acc_b);
+ }
+ }
+}
+
+/* ================================================================ */
+/* Transaction Traversal functions */
+
+
+void
+xaccSplitsBeginStagedTransactionTraversals (GList *splits)
+{
+ GList *lp;
+
+ for (lp = splits; lp; lp = lp->next)
+ {
+ Split *s = lp->data;
+ Transaction *trans = s->parent;
+
+ if (trans)
+ trans->marker = 0;
+ }
+}
+
+/* original function */
+void
+xaccAccountBeginStagedTransactionTraversals (const Account *account)
+{
+ if (account)
+ xaccSplitsBeginStagedTransactionTraversals (account->splits);
+}
+
+gboolean
+xaccTransactionTraverse (Transaction *trans, int stage)
+{
+ if (trans == NULL) return FALSE;
+
+ if (trans->marker < stage)
+ {
+ trans->marker = stage;
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+gboolean
+xaccSplitTransactionTraverse (Split *split, int stage)
+{
+ if (split == NULL) return FALSE;
+
+ return xaccTransactionTraverse (split->parent, stage);
+}
+
+static void do_one_split (Split *s, gpointer data)
+{
+ Transaction *trans = s->parent;
+ trans->marker = 0;
+}
+
+static void do_one_account (Account *account, gpointer data)
+{
+ g_list_foreach(account->splits, (GFunc)do_one_split, NULL);
+}
+
+/* Replacement for xaccGroupBeginStagedTransactionTraversals */
+void
+gnc_account_tree_begin_staged_transaction_traversals (Account *account)
+{
+ GList *descendants;
+
+ descendants = gnc_account_get_descendants(account);
+ g_list_foreach(descendants, (GFunc)do_one_account, NULL);
+ g_list_free(descendants);
+}
+
+int
+xaccAccountStagedTransactionTraversal (const Account *acc,
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *cb_data)
+{
+ GList *split_p;
+ Transaction *trans;
+ Split *s;
+ int retval;
+
+ if (!acc) return 0;
+
+ for(split_p = acc->splits; split_p; split_p = g_list_next(split_p)) {
+ s = split_p->data;
+ trans = s->parent;
+ if (trans && (trans->marker < stage)) {
+ trans->marker = stage;
+ if (thunk) {
+ retval = thunk(trans, cb_data);
+ if (retval) return retval;
+ }
+ }
+ }
+
+ return 0;
+}
+
+int
+gnc_account_tree_staged_transaction_traversal (const Account *acc,
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *cb_data)
+{
+ GList *acc_p, *split_p;
+ Transaction *trans;
+ Split *s;
+ int retval;
+
+ if (!acc) return 0;
+
+ /* depth first traversal */
+ for (acc_p = acc->children; acc_p; acc_p = g_list_next(acc_p)) {
+ retval = gnc_account_tree_staged_transaction_traversal(acc_p->data, stage,
+ thunk, cb_data);
+ if (retval) return retval;
+ }
+
+ /* Now this account */
+ for(split_p = acc->splits; split_p; split_p = g_list_next(split_p)) {
+ s = split_p->data;
+ trans = s->parent;
+ if (trans && (trans->marker < stage)) {
+ trans->marker = stage;
+ if (thunk) {
+ retval = thunk(trans, cb_data);
+ if (retval) return retval;
+ }
+ }
+ }
+
+ return 0;
+}
+
+/********************************************************************\
+\********************************************************************/
+
+int
+xaccAccountTreeForEachTransaction (Account *acc,
+ int (*proc)(Transaction *t, void *data),
+ void *data)
+{
+ if (!acc || !proc) return 0;
+
+ gnc_account_tree_begin_staged_transaction_traversals (acc);
+ return gnc_account_tree_staged_transaction_traversal (acc, 42, proc, data);
+}
+
+
+gint
+xaccAccountForEachTransaction(const Account *acc, TransactionCallback proc,
+ void *data)
+{
+ if (!acc || !proc) return 0;
+ xaccAccountBeginStagedTransactionTraversals (acc);
+ return xaccAccountStagedTransactionTraversal(acc, 42, proc, data);
+}
+
+/* ================================================================ */
/* QofObject function implementation and registration */
static QofObject account_object_def = {
@@ -2706,7 +3428,7 @@
(QofAccessFunc) xaccAccountGetNonStdSCU,
(QofSetterFunc) xaccAccountSetNonStdSCU },
{ ACCOUNT_PARENT, GNC_ID_ACCOUNT,
- (QofAccessFunc) xaccAccountGetParentAccount,
+ (QofAccessFunc) gnc_account_get_parent,
(QofSetterFunc) qofAccountSetParent },
{ QOF_PARAM_BOOK, QOF_ID_BOOK,
(QofAccessFunc) qof_instance_get_book, NULL },
@@ -2717,7 +3439,7 @@
{ NULL },
};
- qof_class_register (GNC_ID_ACCOUNT, (QofSortFunc) xaccAccountOrder, params);
+ qof_class_register (GNC_ID_ACCOUNT, (QofSortFunc) qof_xaccAccountOrder, params);
return qof_object_register (&account_object_def);
}
Modified: gnucash/branches/remove-group2/src/engine/Account.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/Account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -32,8 +32,7 @@
(e.g. "IBM", "McDonald's"), a currency (e.g. "USD", "GBP"), or
anything added to the commodity table.
- Accounts can be arranged in a hierarchical tree. The nodes of the tree
- are called "Account Groups" (@pxref{Account Groups}). By accounting
+ Accounts can be arranged in a hierarchical tree. By accounting
convention, the value of an Account is equal to the value of all of its
Splits plus the value of all of its sub-Accounts.
@{ */
@@ -57,6 +56,9 @@
typedef gnc_numeric (*xaccGetBalanceAsOfDateFn) (
Account *account, time_t date);
+typedef void (*AccountCb)(Account *a, gpointer data);
+typedef gpointer (*AccountCb2)(Account *a, gpointer data);
+
#define GNC_IS_ACCOUNT(obj) (QOF_CHECK_TYPE((obj), GNC_ID_ACCOUNT))
#define GNC_ACCOUNT(obj) (QOF_CHECK_CAST((obj), GNC_ID_ACCOUNT, Account))
@@ -121,17 +123,19 @@
ACCT_TYPE_PAYABLE = 12, /**< A/P account type */
- NUM_ACCOUNT_TYPES = 13, /**< stop here; the following types
+ ACCT_TYPE_ROOT = 13, /**< The hidden root account of an account tree. */
+
+ NUM_ACCOUNT_TYPES = 14, /**< stop here; the following types
* just aren't ready for prime time */
/* bank account types */
- ACCT_TYPE_CHECKING = 13, /**< bank account type -- don't use this
+ ACCT_TYPE_CHECKING = 14, /**< bank account type -- don't use this
* for now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_SAVINGS = 14, /**< bank account type -- don't use this for
+ ACCT_TYPE_SAVINGS = 15, /**< bank account type -- don't use this for
* now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_MONEYMRKT = 15, /**< bank account type -- don't use this
+ ACCT_TYPE_MONEYMRKT = 16, /**< bank account type -- don't use this
* for now, see NUM_ACCOUNT_TYPES */
- ACCT_TYPE_CREDITLINE = 16, /**< line of credit -- don't use this for
+ ACCT_TYPE_CREDITLINE = 17, /**< line of credit -- don't use this for
* now, see NUM_ACCOUNT_TYPES */
} GNCAccountType;
@@ -143,6 +147,9 @@
/** Constructor */
Account * xaccMallocAccount (QofBook *book);
+/** Create a new root level account. */
+Account * gnc_account_create_root (QofBook *book);
+
/** The xaccCloneAccount() does the same as xaccCloneAccountSimple(),
* except that it also also places a pair of GUID-pointers
* of each account to the other, in the other's kvp slot.
@@ -188,7 +195,7 @@
* the account codes are compared, and if these are equal, then
* account types, and, if these are equal, the account names.
*/
-int xaccAccountOrder (const Account **account_1, const Account **account_2);
+int xaccAccountOrder (const Account *account_1, const Account *account_2);
/** @} */
@@ -205,8 +212,11 @@
gunichar gnc_get_account_separator (void);
void gnc_set_account_separator (const gchar *separator);
+Account *gnc_book_get_root_account(QofBook *book);
+void gnc_book_set_root_account(QofBook *book, Account *root);
+
/** @deprecated */
-#define xaccAccountGetBook(X) qof_instance_get_book(QOF_INSTANCE(X))
+#define gnc_account_get_book(X) qof_instance_get_book(QOF_INSTANCE(X))
#define xaccAccountGetGUID(X) qof_entity_get_guid(QOF_ENTITY(X))
#define xaccAccountReturnGUID(X) (X ? *(qof_entity_get_guid(QOF_ENTITY(X))) : *(guid_null()))
@@ -445,33 +455,271 @@
@{
*/
-/** This routine returns the group holding the set of subaccounts
- * for this account. */
-AccountGroup * xaccAccountGetChildren (const Account *account);
+/** This function will remove from the child account any pre-existing
+ * parent relationship, and will then add the account as a child of
+ * the new parent. The exception to this is when the old and new
+ * parent accounts are the same, in which case this function does
+ * nothing.
+ *
+ * If the child account belongs to a different book than the
+ * specified new parent account, the child will be removed from the
+ * other book (and thus, the other book's entity tables, generating a
+ * destroy event), and will be added to the new book (generating a
+ * create event).
+ *
+ * @param new_parent The new parent account to which the child should
+ * be attached.
+ *
+ * @param child The account to attach.
+ */
+void gnc_account_append_child (Account *new_parent, Account *child);
-/** This routine returns the group which contains this account.
+/** This function will remove the speified child account from the
+ * specified parent account. It will NOT free the associated memory
+ * or otherwise alter the account: the account can now be reparented
+ * to a new location. Note, however, that it will mark the old
+ * parents as having been modified.
+ *
+ * @param parent The parent account from which the child should be
+ * removed.
+ *
+ * @param child The child account to remove. */
+void gnc_account_remove_child (Account *parent, Account *child);
+
+/** This routine returns a pointer to the parent of the specified
+ * account. If the account has no parent, i.e it is either the root
+ * node or is a disconnected account, then its parent will be NULL.
+ *
+ * @param account A pointer to any exiting account.
+ *
+ * @return A pointer to the parent account node, or NULL if there is
+ * no parent account. */
+Account * gnc_account_get_parent (const Account *account);
+
+/** This routine returns the root account of the account tree that the
+ * specified account belongs to. It is the equivalent of repeatedly
+ * calling the gnc_account_get_parent() routine until that routine
+ * returns NULL.
+ *
+ * @param account A pointer to any existing account.
+ *
+ * @return The root node of the account tree to which this account
+ * belongs. NULL if the account is not part of any account tree. */
+Account * gnc_account_get_root (Account *account);
+
+/** This routine indicates whether the spcified account is the root
+ * node of an account tree.
+ *
+ * @param account A pointer to any account.
+ *
+ * @return TRUE if this account is of type ROOT. FALSE otherwise. */
+gboolean gnc_account_is_root (const Account *account);
+
+/** This routine returns a GList of all children of the specified
+ * account. This function only returns the immediate children of the
+ * specified account. For a list of all descendant accounts, use the
+ * gnc_account_get_descendants() function.
+ *
+ * @param account The account whose children should be returned.
+ *
+ * @return A GList of account pointers, or NULL if there are no
+ * children. It is the callers responsibility to free any returned
+ * list with the g_list_free() function. */
+GList *gnc_account_get_children (const Account *account);
+GList *gnc_account_get_children_sorted (const Account *account);
+
+/** Return the number of children of the specified account. The
+ * returned number does not include the account itself.
+ *
+ * @param account The account to query.
+ *
+ * @return The number of children of the specified account. */
+gint gnc_account_n_children (const Account *account);
+
+/** Return the index of the specified child within the list of the
+ * parent's children. The first child index is 0. This function
+ * returns -1 if the parent account is NULL of if the specified child
+ * does not belong to the parent account.
+ *
+ * @param parent The parent account to check.
+ *
+ * @param child The child account to find.
+ *
+ * @return The index of the child account within the specified
+ * parent, or -1. */
+gint gnc_account_child_index (const Account *parent, const Account *child);
+
+/** Return the n'th child account of the specified parent account. If
+ * the parent account is not specified or the child index number is
+ * invalid, this function returns NULL.
+ *
+ * @param parent The parent account to check.
+ *
+ * @param num The index number of the child account that should be
+ * returned.
+ *
+ * @return A pointer to the specified child account, or NULL */
+Account *gnc_account_nth_child (const Account *parent, gint num);
+
+/** This routine returns a flat list of all of the accounts that are
+ * descendants of the specified account. This includes not only the
+ * the children, but the children of the children, etc. For a list of
+ * only the immediate child accounts, use the
+ * gnc_account_get_children() function. Within each set of child
+ * accounts, the accounts returned by this function are unordered.
+ * For a list of descendants where each set of children is sorted via
+ * the standard account sort function, use the
+ * gnc_account_get_descendants_sorted() function.
+ *
+ * @param account The account whose descendants should be returned.
+ *
+ * @return A GList of account pointers, or NULL if there are no
+ * descendants. It is the callers responsibility to free any returned
+ * list with the g_list_free() function. */
+GList * gnc_account_get_descendants (const Account *account);
+
+/** This function returns a GList containing all the descendants of
+ * the specified account, sorted at each level. This includes not
+ * only the the children, but the children of the children, etc.
+ * Within each set of child accounts, the accounts returned by this
+ * function are ordered via the standard account sort function. For
+ * a list of descendants where each set of children is unordered, use
+ * the gnc_account_get_descendants() function.
+ *
+ * Note: Use this function where the results are intended for display
+ * to the user. If the results are internal to GnuCash or will be
+ * resorted at som later point in time you should use the
+ * gnc_account_get_descendants() function.
+ *
+ * @param account The account whose descendants should be returned.
+ *
+ * @return A GList of account pointers, or NULL if there are no
+ * descendants. It is the callers responsibility to free any returned
+ * list with the g_list_free() function. */
+GList *gnc_account_get_descendants_sorted (const Account *account);
+
+/** Return the number of descendants of the specified account. The
+ * returned number does not include the account itself.
+ *
+ * @param account The account to query.
+ *
+ * @return The number of descendants of the specified account. */
+gint gnc_account_n_descendants (const Account *account);
+
+/** Return the number of levels of descendants accounts below the
+ * specified account. The returned number does not include the
+ * specifed account itself.
+ *
+ * @param account The account to query.
+ *
+ * @return The number of levels of descendants. */
+gint gnc_account_get_depth (const Account *account);
+
+/** @name ForEach
+ @{
+*/
+
+/** This method will traverse the immediate children of this accounts,
+ * calling 'func' on each account. This function traverses all
+ * children nodes. To traverse only a subset of the child nodes use
+ * the gnc_account_foreach_child_until() function.
+ *
+ * @param account A pointer to the account on whose children the
+ * function should be called.
+ *
+ * @param func A function taking two arguments, an Account and a
+ * gpointer.
+ *
+ * @param user_data This data will be passed to each call of func. */
+void gnc_account_foreach_child (const Account *account,
+ AccountCb func, gpointer user_data);
+
+/** This method will traverse the immediate children of this accounts,
+ * calling 'func' on each account. Traversal will stop when func
+ * returns a non-null value, and the routine will return with that
+ * value. Therefore, this function will return null iff func returns
+ * null for every account. For a simpler function that always
+ * traverses all children nodes, use the gnc_account_foreach_child()
+ * function.
+ *
+ * @param account A pointer to the account on whose children the
+ * function should be called.
+ *
+ * @param func A function taking two arguments, an Account and a
+ * gpointer.
+ *
+ * @param user_data This data will be passed to each call of func. */
+gpointer gnc_account_foreach_child_until (const Account *account,
+ AccountCb2 func, gpointer user_data);
+
+
+/** This method will traverse all children of this accounts and their
+ * descendants, calling 'func' on each account. This function
+ * traverses all descendant nodes. To traverse only a subset of the
+ * descendant nodes use the gnc_account_foreach_descendant_until()
+ * function.
+ *
+ * @param account A pointer to the account on whose descendants the
+ * function should be called.
+ *
+ * @param func A function taking two arguments, an Account and a
+ * gpointer.
+ *
+ * @param user_data This data will be passed to each call of func. */
+void gnc_account_foreach_descendant (const Account *account,
+ AccountCb func, gpointer user_data);
+
+/** This method will traverse all children of this accounts and their
+ * descendants, calling 'func' on each account. Traversal will stop
+ * when func returns a non-null value, and the routine will return
+ * with that value. Therefore, this function will return null iff
+ * func returns null for every account. For a simpler function that
+ * always traverses all children nodes, use the
+ * gnc_account_foreach_descendant() function.
+ *
+ * @param account A pointer to the account on whose descendants the
+ * function should be called.
+ *
+ * @param func A function taking two arguments, an Account and a
+ * gpointer.
+ *
+ * @param user_data This data will be passed to each call of func. */
+gpointer gnc_account_foreach_descendant_until (const Account *account,
+ AccountCb2 func, gpointer user_data);
+
+
+/** @} */
+
+/** @name Concatenation, Merging
+ @{
+*/
+
+/** The gnc_account_join_children() subroutine will move (reparent)
+ * all child accounts from the from_parent account to the to_parent
+ * account, preserving the account heirarchy. It will also take care
+ * that the moved accounts will have the to_parent's book parent
+ * as well.
*/
-AccountGroup * xaccAccountGetParent (const Account *account);
+void gnc_account_join_children (Account *to_parent, Account *from_parent);
-/** This routine returns the parent of the group that is the parent
- * of this account. It is equivalent to the nested call
- * xaccGroupGetParentAccount (xaccAccountGetParent ())
- * Note that if the account is in the root group node, then its
- * parent will be NULL.
+/** The gnc_account_copy_children() subroutine will copy all child
+ * accounts from the "src" account to the "dest" account, preserving
+ * the account heirarchy. It will also take care that the moved
+ * accounts will have the "dest" account's book parent as well. This
+ * routine will *NOT* copy any splits/transactions. It will copy the
+ * KVP trees in each account.
*/
-Account * xaccAccountGetParentAccount (const Account *account);
+void gnc_account_copy_children (Account *dest, Account *src);
-/** This routine returns a flat list of all of the accounts
- * that are descendents of this account. This includes not
- * only the the children, but the children of the children, etc.
- * This routine is equivalent to the nested calls
- * xaccGroupGetSubAccounts (xaccAccountGetChildren())
- *
- * The returned list should be freed with g_list_free() when
- * no longer needed.
+/** The gnc_account_merge_children() subroutine will go through an
+ * account, merging all child accounts that have the same name and
+ * description. This function is useful when importing Quicken(TM)
+ * files.
*/
-GList * xaccAccountGetDescendants (const Account *account);
+void gnc_account_merge_children (Account *parent);
+/** @} */
+
/** DOCUMENT ME! */
void xaccAccountSetReconcileChildrenStatus(Account *account, gboolean status);
@@ -489,7 +737,29 @@
/** @} */
+/** @name Getting Accounts and Subaccounts by Name
+ @{
+*/
+/** The gnc_account_lookup_by_name() subroutine fetches the account by
+ * name from the descendants of the specified account. The immediate
+ * children are searched first. If there is no match,, then a
+ * recursive search of all descendants is performed looking for a
+ * match.
+ *
+ * @return A pointer to the account with the specified name, or NULL
+ * if the account was not found.
+ */
+Account *gnc_account_lookup_by_name (const Account *parent, const char *name);
+/** The gnc_account_lookup_full_name() subroutine works like
+ * gnc_account_lookup_by_name, but uses fully-qualified names using the
+ * given separator.
+ */
+Account *gnc_account_lookup_by_full_name (const Account *any_account,
+ const gchar *name);
+
+/** @} */
+
/* ------------------ */
/** @name GNCAccountType conversion/checking
@@ -694,7 +964,7 @@
/** Get the "placeholder" flag for an account. If this flag is set
* then the account may not be modified by the user.
*
- * @param acc The account whose flag should be retrieved.
+ * @param account The account whose flag should be retrieved.
*
* @return The current state of the account's "placeholder" flag. */
gboolean xaccAccountGetPlaceholder (const Account *account);
@@ -702,13 +972,13 @@
/** Set the "placeholder" flag for an account. If this flag is set
* then the account may not be modified by the user.
*
- * @param acc The account whose flag should be retrieved.
+ * @param account The account whose flag should be retrieved.
*
* @param val The new state for the account's "placeholder" flag. */
-void xaccAccountSetPlaceholder (Account *account, gboolean option);
+void xaccAccountSetPlaceholder (Account *account, gboolean val);
/** Returns PLACEHOLDER_NONE if account is NULL or neither account nor
- * any descendent of account is a placeholder. If account is a
+ * any descendant of account is a placeholder. If account is a
* placeholder, returns PLACEHOLDER_THIS. Otherwise, if any
* descendant of account is a placeholder, return PLACEHOLDER_CHILD.
*/
@@ -782,18 +1052,152 @@
/** Get the mark set by xaccAccountSetMark */
short xaccAccountGetMark (const Account *account);
-/** The xaccClearMark will find the topmost group, and clear the mark in
- * the entire group tree. */
+/** The xaccClearMark will find the root account, and clear the mark in
+ * the entire account tree. */
void xaccClearMark (Account *account, short val);
/** The xaccClearMarkDown will clear the mark only in this and in
* sub-accounts.*/
void xaccClearMarkDown (Account *account, short val);
-/** Will clear the mark for all the accounts of the AccountGroup .*/
-void xaccClearMarkDownGr (AccountGroup *group, short val);
/** @} */
+/** @name Staged Traversal
+ * The following functions provide support for "staged traversals"
+ * over all of the transactions in an account or group. The idea
+ * is to be able to perform a sequence of traversals ("stages"),
+ * and perform an operation on each transaction exactly once
+ * for that stage.
+ *
+ * Only transactions whose current "stage" is less than the
+ * stage of the current traversal will be affected, and they will
+ * be "brought up" to the current stage when they are processed.
+ *
+ * For example, you could perform a stage 1 traversal of all the
+ * transactions in an account, and then perform a stage 1 traversal of
+ * the transactions in a second account. Presuming the traversal of
+ * the first account didn't abort prematurely, any transactions shared
+ * by both accounts would be ignored during the traversal of the
+ * second account since they had been processed while traversing the
+ * first account.
+ *
+ * However, if you had traversed the second account using a stage
+ * of 2, then all the transactions in the second account would have
+ * been processed.
+ *
+ * Traversal can be aborted by having the callback function return
+ * a non-zero value. The traversal is aborted immediately, and the
+ * non-zero value is returned. Note that an aborted traversal can
+ * be restarted; no information is lost due to an abort.
+ *
+ * The initial impetus for this particular approach came from
+ * generalizing a mark/sweep practice that was already being
+ * used in FileIO.c.
+ *
+ * Note that currently, there is a hard limit of 256 stages, which
+ * can be changed by enlarging "marker" in the transaction struct.
+ *
+ @{
+*/
+/** gnc_account_tree_begin_staged_transaction_traversals()
+ * resets the traversal marker inside every transactions of every
+ * account in the account tree originating with the specified node.
+ * This is done so that a new sequence of staged traversals can
+ * begin.
+ */
+void gnc_account_tree_begin_staged_transaction_traversals(Account *acc);
+
+/** xaccSplitsBeginStagedTransactionTraversals() resets the traversal
+ * marker for each transaction which is a parent of one of the
+ * splits in the list.
+ */
+void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
+
+/** xaccAccountBeginStagedTransactionTraversals() resets the traversal
+ * marker for each transaction which is a parent of one of the
+ * splits in the account.
+ */
+void xaccAccountBeginStagedTransactionTraversals(const Account *account);
+
+/** xaccTransactionTraverse() checks the stage of the given transaction.
+ * If the transaction hasn't reached the given stage, the transaction
+ * is updated to that stage and the function returns TRUE. Otherwise
+ * no change is made and the function returns FALSE.
+ */
+gboolean xaccTransactionTraverse(Transaction *trans, int stage);
+
+/** xaccSplitTransactionTraverse() behaves as above using the parent of
+ * the given split.
+ */
+gboolean xaccSplitTransactionTraverse(Split *split, int stage);
+
+/** xaccAccountStagedTransactionTraversal() calls thunk on each
+ * transaction in the account whose current marker is less than the
+ * given `stage' and updates each transaction's marker to be `stage'.
+ * The traversal will stop if thunk() returns a non-zero value.
+ * xaccAccountStagedTransactionTraversal() function will return zero
+ * or the non-zero value returned by thunk().
+ * This API does not handle handle recursive traversals.
+ *
+ * Currently the result of adding or removing transactions during
+ * a traversal is undefined, so don't do that.
+ */
+
+int xaccAccountStagedTransactionTraversal(const Account *a,
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *data);
+
+/** gnc_account_tree_staged_transaction_traversal() calls thunk on each
+ * transaction in the group whose current marker is less than the
+ * given `stage' and updates each transaction's marker to be `stage'.
+ * The traversal will stop if thunk() returns a non-zero value.
+ * gnc_account_tree_staged_transaction_traversal() function will return zero
+ * or the non-zero value returned by thunk(). This
+ * API does not handle handle recursive traversals.
+ *
+ * Currently the result of adding or removing transactions during
+ * a traversal is undefined, so don't do that.
+ */
+
+int gnc_account_tree_staged_transaction_traversal(const Account *account,
+ unsigned int stage,
+ TransactionCallback thunk,
+ void *data);
+
+/** Traverse all of the transactions in the given account group.
+ Continue processing IFF proc returns 0. This function
+ will descend recursively to traverse transactions in the
+ children of the accounts in the group.
+
+ Proc will be called exactly once for each transaction that is
+ pointed to by at least one split in any account in the hierarchy
+ topped by the root Account acc.
+
+ The result of this function will be 0 IFF every relevant
+ transaction was traversed exactly once; otherwise, the return
+ value is the last non-zero value returned by the callback.
+
+ Note that the traversal occurs only over the transactions that
+ are locally cached in the local gnucash engine. If the gnucash
+ engine is attached to a remote database, the database may contain
+ (many) transactions that are not mirrored in the local cache.
+ This routine will not cause an SQL database query to be performed;
+ it will not traverse transactions present only in the remote
+ database.
+
+ Note that this routine is just a trivial wrapper for
+
+ gnc_account_tree_begin_staged_transaction_traversals(g);
+ gnc_account_tree_staged_transaction_traversal(g, 42, proc, data);
+ */
+
+int xaccAccountTreeForEachTransaction(Account *acc,
+ TransactionCallback proc, void *data);
+
+/** @} */
+
+
/** @name Deprecated Routines.
@{
*/
Modified: gnucash/branches/remove-group2/src/engine/AccountP.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/AccountP.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/AccountP.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -98,8 +98,8 @@
/* The parent and children pointers are used to implement an account
* hierarchy, of accounts that have sub-accounts ("detail accounts").
*/
- AccountGroup *parent; /* back-pointer to parent */
- AccountGroup *children; /* pointer to sub-accounts */
+ Account *parent; /* back-pointer to parent */
+ GList *children; /* list of sub-accounts */
/* protected data, cached parameters */
gnc_numeric starting_balance;
Deleted: gnucash/branches/remove-group2/src/engine/Group.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Group.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Group.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,1322 +0,0 @@
-/********************************************************************\
- * Group.c -- chart of accounts (hierarchical tree of accounts) *
- * Copyright (C) 1997 Robin D. Clark *
- * Copyright (C) 1997-2001,2003 Linas Vepstas <linas at 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 *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
-\********************************************************************/
-
-#include "config.h"
-
-#include <glib.h>
-#include <string.h>
-
-#include "Account.h"
-#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
-#include "TransactionP.h"
-#include "gnc-event.h"
-
-static QofLogModule log_module = GNC_MOD_ENGINE;
-
-/********************************************************************\
- * Because I can't use C++ for this project, doesn't mean that I *
- * can't pretend to! These functions perform actions on the *
- * AccountGroup data structure, in order to encapsulate the *
- * knowledge of the internals of the AccountGroup in one file. *
-\********************************************************************/
-
-/********************************************************************\
-\********************************************************************/
-
-static void
-xaccInitializeAccountGroup (AccountGroup *grp, QofBook *book)
-{
- grp->saved = 1;
-
- grp->parent = NULL;
- grp->accounts = NULL;
-
- grp->book = book;
- grp->editlevel = 0;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-AccountGroup *
-xaccMallocAccountGroup (QofBook *book)
-{
- AccountGroup *grp;
- g_return_val_if_fail (book, NULL);
-
- grp = g_new (AccountGroup, 1);
- xaccInitializeAccountGroup (grp, book);
-
- return grp;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-AccountGroup *
-xaccCollGetAccountGroup (const QofCollection *col)
-{
- if (!col) return NULL;
- return qof_collection_get_data (col);
-}
-
-void
-xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp)
-{
- AccountGroup *old_grp;
- if (!col) return;
-
- old_grp = xaccCollGetAccountGroup (col);
- if (old_grp == grp) return;
-
- qof_collection_set_data (col, grp);
-
- xaccAccountGroupBeginEdit (old_grp);
- xaccAccountGroupDestroy (old_grp);
-}
-
-AccountGroup *
-xaccGetAccountGroup (QofBook *book)
-{
- QofCollection *col;
- if (!book) return NULL;
- col = qof_book_get_collection (book, GNC_ID_GROUP);
- return xaccCollGetAccountGroup (col);
-}
-
-void
-xaccSetAccountGroup (QofBook *book, AccountGroup *grp)
-{
- QofCollection *col;
- if (!book) return;
-
- if (grp && grp->book != book)
- {
- PERR ("cannot mix and match books freely!");
- return;
- }
-
- col = qof_book_get_collection (book, GNC_ID_GROUP);
- xaccCollSetAccountGroup (col, grp);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-gboolean
-xaccGroupEqual(const AccountGroup *ga,
- const AccountGroup *gb,
- gboolean check_guids)
-{
- GList *na;
- GList *nb;
-
- if (!ga && !gb) return(TRUE);
-
- if (!ga || !gb)
- {
- PWARN ("one is NULL");
- return(FALSE);
- }
-
- na = ga->accounts;
- nb = gb->accounts;
-
- if ((!na && nb) || (na && !nb))
- {
- PWARN ("only one has accounts");
- return(FALSE);
- }
-
- while (na && nb)
- {
- Account *aa = na->data;
- Account *ab = nb->data;
-
- if (!xaccAccountEqual(aa, ab, check_guids))
- {
- char sa[GUID_ENCODING_LENGTH + 1];
- char sb[GUID_ENCODING_LENGTH + 1];
-
- guid_to_string_buff (xaccAccountGetGUID (aa), sa);
- guid_to_string_buff (xaccAccountGetGUID (ab), sb);
-
- PWARN ("accounts %s and %s differ", sa, sb);
-
- return(FALSE);
- }
-
- na = na->next;
- nb = nb->next;
- }
-
- if (na || nb)
- {
- PWARN ("different numbers of accounts");
- return(FALSE);
- }
-
- return(TRUE);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccAccountGroupBeginEdit (AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return;
- grp->editlevel++;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccAccountBeginEdit (account);
- xaccAccountGroupBeginEdit (account->children);
- }
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccAccountGroupCommitEdit (AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccAccountGroupCommitEdit (account->children);
- xaccAccountCommitEdit (account);
- }
- grp->editlevel--;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-static void
-xaccGroupMarkDoFree (AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- account->inst.do_free = TRUE;
- xaccGroupMarkDoFree (account->children);
- }
-}
-
-void
-xaccAccountGroupDestroy (AccountGroup *grp)
-{
- xaccGroupMarkDoFree (grp);
- xaccFreeAccountGroup (grp);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-QofBook *
-xaccGroupGetBook (const AccountGroup *group)
-{
- if (!group) return NULL;
- return group->book;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccFreeAccountGroup (AccountGroup *grp)
-{
- gboolean root_grp;
-
- if (!grp) return;
-
- root_grp = grp->parent == NULL;
-
- if (grp->accounts)
- {
- Account *account;
- /* This is a weird iterator & needs some explanation.
- * xaccAccountDestroy() will rip the account out of the list, thus
- * iterating while grp->accounts is non-null is enough to iterate
- * the loop. But when it deletes the last account, then it will
- * also delete the group, unless it's the root group, making the
- * grp pointer invalid. So we have to be careful with the last
- * deletion: in particular, g_free(grp) would be freeing that
- * memory a second time, so don't do it. */
- while (grp->accounts->next)
- {
- account = grp->accounts->next->data;
-
- /* FIXME: this and the same code below is kind of hacky.
- * actually, all this code seems to assume that
- * the account edit levels are all 1. */
- if (account->inst.editlevel == 0)
- xaccAccountBeginEdit (account);
-
- xaccAccountDestroy (account);
- }
- account = grp->accounts->data;
- if (account->inst.editlevel == 0)
- xaccAccountBeginEdit (account);
- xaccAccountDestroy (account);
-
- if (!root_grp) return;
- }
-
- if (grp->parent) grp->parent->children = NULL;
-
- grp->parent = NULL;
-
- g_free (grp);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupMarkSaved (AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return;
-
- grp->saved = 1;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccGroupMarkSaved (account->children);
- }
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupMarkNotSaved (AccountGroup *grp)
-{
- if (!grp) return;
-
- grp->saved = 0;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-gboolean
-xaccGroupNotSaved (const AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return FALSE;
-
- if (grp->saved == 0) return TRUE;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- if (xaccGroupNotSaved (account->children))
- return TRUE;
- }
-
- return FALSE;
-}
-
-/********************************************************************\
- * Get the number of accounts, including subaccounts *
-\********************************************************************/
-
-int
-xaccGroupGetNumSubAccounts (const AccountGroup *grp)
-{
- GList *node;
- int num_acc;
-
- if (!grp) return 0;
-
- num_acc = g_list_length (grp->accounts);
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- num_acc += xaccGroupGetNumSubAccounts (account->children);
- }
-
- return num_acc;
-}
-
-/********************************************************************\
- * Recursively get all of the accounts, including subaccounts *
-\********************************************************************/
-
-static void
-xaccPrependAccounts (const AccountGroup *grp, GList **accounts_p)
-{
- GList *node;
-
- if (!grp || !accounts_p) return;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- *accounts_p = g_list_prepend (*accounts_p, account);
-
- xaccPrependAccounts (account->children, accounts_p);
- }
-}
-
-AccountList *
-xaccGroupGetSubAccounts (const AccountGroup *grp)
-{
- GList *accounts = NULL;
-
- if (!grp) return NULL;
-
- xaccPrependAccounts (grp, &accounts);
-
- return g_list_reverse (accounts);
-}
-
-static int
-group_sort_helper (gconstpointer a, gconstpointer b)
-{
- const Account *aa = (const Account *) a;
- const Account *bb = (const Account *) b;
-
- /* xaccAccountOrder returns > 1 if aa should come after bb.
- * This funciton is building a reversed list. */
- return xaccAccountOrder (&aa, &bb);
-}
-
-static void
-xaccPrependAccountsSorted (const AccountGroup *grp, GList **accounts_p)
-{
- GList *node, *tmp_list;
-
- if (!grp || !accounts_p) return;
-
- tmp_list = g_list_copy(grp->accounts);
- tmp_list = g_list_sort(tmp_list, group_sort_helper);
-
- for (node = tmp_list; node; node = node->next)
- {
- Account *account = node->data;
-
- *accounts_p = g_list_prepend (*accounts_p, account);
-
- xaccPrependAccountsSorted (account->children, accounts_p);
- }
- g_list_free(tmp_list);
-}
-
-AccountList *
-xaccGroupGetSubAccountsSorted (const AccountGroup *grp)
-{
- GList *accounts = NULL;
-
- if (!grp) return NULL;
-
- xaccPrependAccountsSorted (grp, &accounts);
-
- return g_list_reverse (accounts);
-}
-
-AccountList *
-xaccGroupGetAccountList (const AccountGroup *grp)
-{
- if (!grp) return NULL;
-
- return grp->accounts;
-}
-
-AccountList *
-xaccGroupGetAccountListSorted (const AccountGroup *grp)
-{
- if (!grp) return NULL;
-
- return g_list_sort(g_list_copy(grp->accounts), group_sort_helper);
-
-}
-
-/********************************************************************\
- * Fetch the root of the tree *
-\********************************************************************/
-
-AccountGroup *
-xaccGroupGetRoot (const AccountGroup * grp)
-{
- const AccountGroup * root = NULL;
-
- /* find the root of the account group structure */
- while (grp)
- {
- Account *parent_acc;
-
- root = grp;
- parent_acc = grp->parent;
-
- if (parent_acc)
- grp = parent_acc->parent;
- else
- grp = NULL;
- }
-
- return (AccountGroup*)root;
-}
-
-AccountGroup *
-xaccAccountGetRoot (const Account * acc)
-{
- return acc ? xaccGroupGetRoot (acc->parent) : NULL;
-}
-
-/********************************************************************\
- * Fetch an account, given its name *
-\********************************************************************/
-
-Account *
-xaccGetAccountFromName (const AccountGroup *grp, const char * name)
-{
- GList *node;
-
- if (!grp) return NULL;
- if (!name) return NULL;
-
- /* first, look for accounts hanging off the root */
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- if (safe_strcmp(xaccAccountGetName (account), name) == 0)
- return account;
- }
-
- /* if we are still here, then we haven't found the account yet.
- * Recursively search the subgroups next */
- /* first, look for accounts hanging off the root */
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- Account *acc;
-
- acc = xaccGetAccountFromName (account->children, name);
- if (acc)
- return acc;
- }
-
- return NULL;
-}
-
-/********************************************************************\
- * Fetch an account, given its full name *
-\********************************************************************/
-
-static Account *
-xaccGetAccountFromFullNameHelper (const AccountGroup *grp,
- gchar **names)
-{
- Account *found = NULL;
- GList *node;
- gchar *name_str, *temp_str;
- const gchar *separator;
- gboolean str_alloced = FALSE;
-
- g_return_val_if_fail(grp, NULL);
- g_return_val_if_fail(names, NULL);
-
- separator = gnc_get_account_separator_string();
- /* start with the first name in the list */
- name_str = names[0];
-
- /* Make sure we actually HAVE a string! */
- if (name_str == NULL)
- return NULL;
-
- while (1)
- {
- /* Look for the first name in the children. */
- for (node = grp->accounts; node; node = node->next) {
- Account *account = node->data;
-
- if (safe_strcmp(xaccAccountGetName (account), name_str) == 0) {
- /* We found an account. If the next entry is NULL, there is
- * nothing left in the name, so just return the account. */
- if (names[1] == NULL) {
- found = account;
- goto done;
- }
-
- /* No children? We're done. */
- if (!account->children) {
- found = NULL;
- goto done;
- }
-
- /* There's stuff left to search for. Search recursively. */
- found = xaccGetAccountFromFullNameHelper(account->children, &names[1]);
- if (found != NULL) {
- goto done;
- }
- }
- }
-
- /* If we got here then we didn't find a match based on name_str
- * so build a new name_str using the next token and try again.
- */
-
- /* If there's no more names then we're done. We didn't find anything */
- if (names[1] == NULL) {
- found = NULL;
- break;
- }
-
- /* If we are here, we didn't find anything and there
- * must be more separators. So, continue looking with
- * a longer name, in case there is a name with the
- * separator character in it. */
-
- /* Build the new name string */
- temp_str = g_strconcat(name_str, separator, names[1], NULL);
- if (str_alloced)
- g_free(name_str);
- str_alloced = TRUE;
- names++;
- name_str = temp_str;
- }
-
-done:
- if (str_alloced)
- g_free(name_str);
- return found;
-}
-
-
-Account *
-xaccGetAccountFromFullName (const AccountGroup *grp,
- const char *name)
-{
- Account *found;
- gchar **names;
-
- if (!grp) return NULL;
- if (!name) return NULL;
-
- names = g_strsplit(name, gnc_get_account_separator_string(), -1);
- found = xaccGetAccountFromFullNameHelper(grp, names);
- g_strfreev(names);
- return found;
-}
-
-/********************************************************************\
- * Fetch an account, given its name *
-\********************************************************************/
-
-Account *
-xaccGetPeerAccountFromName (const Account *acc, const char * name)
-{
- AccountGroup * root;
- Account *peer_acc;
-
- if (!acc) return NULL;
- if (!name) return NULL;
-
- /* first, find the root of the account group structure */
- root = xaccAccountGetRoot (acc);
-
- /* now search all accounts hanging off the root */
- peer_acc = xaccGetAccountFromName (root, name);
-
- return peer_acc;
-}
-
-/********************************************************************\
- * Fetch an account, given its full name *
-\********************************************************************/
-
-Account *
-xaccGetPeerAccountFromFullName (const Account *acc, const char * name)
-{
- AccountGroup * root;
- Account *peer_acc;
-
- if (!acc) return NULL;
- if (!name) return NULL;
-
- /* first, find the root of the account group structure */
- root = xaccAccountGetRoot (acc);
-
- /* now search all acounts hanging off the root */
- peer_acc = xaccGetAccountFromFullName (root, name);
-
- return peer_acc;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccAccountRemoveGroup (Account *acc)
-{
- AccountGroup *grp;
-
- /* if this group has no parent, it must be the topgroup */
- if (!acc) return;
-
- grp = acc->children;
-
- if (grp) grp->parent = NULL;
- acc->children = NULL;
-
- /* make sure that the parent of the group is marked
- * as having been modified. */
- grp = acc->parent;
- if (!grp) return;
-
- grp->saved = 0;
-
- qof_event_gen (&acc->inst.entity, QOF_EVENT_MODIFY, NULL);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupRemoveAccount (AccountGroup *grp, Account *acc)
-{
- GncEventData ed;
-
- if (!acc) return;
-
- /* Note this routine might be called on accounts which
- * are not yet parented. */
- if (!grp) return;
-
- if (acc->parent != grp)
- {
- PERR ("account not in group");
- return;
- }
-
- /* Gather event data */
- ed.node = grp->parent;
- ed.idx = g_list_index(grp->accounts, acc);
-
- grp->accounts = g_list_remove (grp->accounts, acc);
-
- /* Now send the event. */
- qof_event_gen(&acc->inst.entity, QOF_EVENT_REMOVE, &ed);
-
- /* clear the account's group pointer after REMOVE event generation. */
- acc->parent = NULL;
-
- grp->saved = 0;
-
- /* if this was the last account in a group, delete
- * the group as well (unless its a root group) */
- if ((grp->accounts == NULL) && (grp->parent))
- {
- xaccAccountRemoveGroup (grp->parent);
- xaccFreeAccountGroup (grp);
- }
-
- qof_event_gen (&acc->inst.entity, QOF_EVENT_MODIFY, NULL);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccAccountInsertSubAccount (Account *adult, Account *child)
-{
- if (!adult) return;
-
- /* if a container for the children doesn't yet exist, add it */
- if (adult->children == NULL)
- adult->children = xaccMallocAccountGroup (adult->inst.book);
-
- /* set back-pointer to parent */
- adult->children->parent = adult;
-
- /* allow side-effect of creating a child-less account group */
- if (!child) return;
-
- xaccGroupInsertAccount (adult->children, child);
-
- qof_event_gen (&adult->inst.entity, QOF_EVENT_MODIFY, NULL);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupInsertAccount (AccountGroup *grp, Account *acc)
-{
- if (!grp || !grp->book) return;
- if (!acc) return;
-
- ENTER("group %p, account %p named %s", grp, acc, xaccAccountGetName(acc));
- /* If the account is currently in another group, remove it there
- * first. Basically, we can't have accounts being in two places at
- * once. If old and new parents are the same, reinsertion causes
- * the sort order to be checked. */
- if (acc->parent != grp)
- {
- xaccAccountBeginEdit (acc);
-
- if (acc->parent)
- {
- xaccGroupRemoveAccount (acc->parent, acc);
-
- /* switch over between books, if needed */
- if (grp->book != acc->inst.book)
- {
- QofCollection *col;
-// xxxxxxxxxxxxxxxxxxxxxxx
- /* hack alert -- this implementation is not exactly correct.
- * If the entity tables are not identical, then the 'from' book
- * may have a different backend than the 'to' book. This means
- * that we should get the 'from' backend to destroy this account,
- * and the 'to' backend to save it. Right now, this is broken.
- *
- * 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 across books is not correctly supported\n");
-
- qof_event_gen (&acc->inst.entity, QOF_EVENT_DESTROY, NULL);
- col = qof_book_get_collection (grp->book, GNC_ID_ACCOUNT);
- qof_collection_insert_entity (col, &acc->inst.entity);
- qof_event_gen (&acc->inst.entity, QOF_EVENT_CREATE, NULL);
- }
- }
-
- /* set back-pointer to the account's parent */
- acc->parent = grp;
-
- grp->accounts = g_list_append (grp->accounts, acc);
-
- /* Gather event data */
- qof_event_gen (&acc->inst.entity, QOF_EVENT_ADD, NULL);
-
- qof_instance_set_dirty(&acc->inst);
- xaccAccountCommitEdit (acc);
- }
-
- grp->saved = 0;
-
- qof_event_gen (&acc->inst.entity, QOF_EVENT_MODIFY, NULL);
- LEAVE(" ");
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupConcatGroup (AccountGroup *togrp, AccountGroup *fromgrp)
-{
- if (!togrp) return;
- if (!fromgrp) return;
-
- /* The act of inserting the account into togrp also causes it to
- * automatically be deleted from fromgrp. This causes linked
- * lists to be re-written, and so a cursor traversal is not safe.
- * Be careful! */
-
- while (TRUE)
- {
- Account *account;
- GList *accounts;
- GList *next;
-
- accounts = fromgrp->accounts;
- if (!accounts) return;
-
- next = accounts->next;
-
- account = accounts->data;
-
- xaccGroupInsertAccount (togrp, account);
-
- if (!next) return;
- }
-}
-
-void
-xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from)
-{
- int i;
- GList *node;
- if (!to || !from) return;
- if (!from->accounts || !to->book) return;
-
- ENTER (" ");
- xaccAccountGroupBeginEdit(to);
- xaccAccountGroupBeginEdit(from);
- for (node = from->accounts; node; node=node->next)
- {
- Account *to_acc, *from_acc = node->data;
-
- /* This will copy the basic data and the KVP. It will
- * not copy any splits/transactions. It will gemini. */
- to_acc = xaccCloneAccount (from_acc, to->book);
-
- xaccAccountBeginEdit (to_acc);
- to->accounts = g_list_append (to->accounts, to_acc);
-
- to_acc->parent = to;
- qof_instance_set_dirty(&to_acc->inst);
-
- /* Copy child accounts too. */
- if (from_acc->children)
- {
- to_acc->children = xaccMallocAccountGroup (to->book);
- to_acc->children->parent = to_acc;
- xaccGroupCopyGroup (to_acc->children, from_acc->children);
- }
- xaccAccountCommitEdit (to_acc);
- qof_event_gen (&to_acc->inst.entity, QOF_EVENT_CREATE, NULL);
-
- /* make sure that we have a symmetric, uniform number of
- * begin-edits, so that subsequent GroupCommitEdit's
- * balance out. */
- for (i=0; i<to->editlevel; i++)
- {
- xaccAccountBeginEdit (to_acc);
- xaccAccountGroupBeginEdit (to_acc->children);
- }
- }
- xaccAccountGroupCommitEdit(from);
- xaccAccountGroupCommitEdit(to);
- LEAVE (" ");
-}
-
-/********************************************************************\
-\********************************************************************/
-
-void
-xaccGroupMergeAccounts (AccountGroup *grp)
-{
- GList *node_a;
- GList *node_b;
-
- if (!grp) return;
-
- for (node_a = grp->accounts; node_a; node_a = node_a->next)
- {
- Account *acc_a = node_a->data;
-
- for (node_b = node_a->next; node_b; node_b = node_b->next)
- {
- Account *acc_b = node_b->data;
-
- if ((0 == safe_strcmp(xaccAccountGetName(acc_a),
- xaccAccountGetName(acc_b))) &&
- (0 == safe_strcmp(xaccAccountGetCode(acc_a),
- xaccAccountGetCode(acc_b))) &&
- (0 == safe_strcmp(xaccAccountGetDescription(acc_a),
- xaccAccountGetDescription(acc_b))) &&
- (gnc_commodity_equiv(xaccAccountGetCommodity(acc_a),
- xaccAccountGetCommodity(acc_b))) &&
- (0 == safe_strcmp(xaccAccountGetNotes(acc_a),
- xaccAccountGetNotes(acc_b))) &&
- (xaccAccountGetType(acc_a) == xaccAccountGetType(acc_b)))
- {
- AccountGroup *ga, *gb;
-
- /* consolidate children */
- ga = (AccountGroup *) acc_a->children;
- gb = (AccountGroup *) acc_b->children;
-
- if (gb)
- {
- if (!ga)
- {
- acc_a->children = gb;
- gb->parent = acc_a;
- acc_b->children = NULL;
-
- qof_event_gen (&acc_a->inst.entity, QOF_EVENT_MODIFY, NULL);
- qof_event_gen (&acc_b->inst.entity, QOF_EVENT_MODIFY, NULL);
- }
- else
- {
- xaccGroupConcatGroup (ga, gb);
- acc_b->children = NULL;
- qof_event_gen (&acc_b->inst.entity, QOF_EVENT_MODIFY, NULL);
- }
- }
-
- /* recurse to do the children's children */
- xaccGroupMergeAccounts (ga);
-
- /* consolidate transactions */
- while (acc_b->splits)
- xaccSplitSetAccount (acc_b->splits->data, acc_a);
-
- /* move back one before removal */
- node_b = node_b->prev;
-
- /* The destroy function will remove from list -- node_a is ok,
- * it's before node_b */
- xaccAccountBeginEdit (acc_b);
- xaccAccountDestroy (acc_b);
- break;
- }
- }
- }
-}
-
-/********************************************************************\
-\********************************************************************/
-
-int
-xaccGroupGetNumAccounts (const AccountGroup *grp)
-{
- if (!grp) return 0;
-
- return g_list_length (grp->accounts);
-}
-
-Account *
-xaccGroupGetAccount (const AccountGroup *grp, int i)
-{
- if (!grp) return NULL;
-
- return g_list_nth_data (grp->accounts, i);
-}
-
-Account *
-xaccGroupGetParentAccount (const AccountGroup * grp)
-{
- if (!grp) return NULL;
-
- return grp->parent;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-int
-xaccGroupGetDepth (const AccountGroup *grp)
-{
- GList *node;
- int depth = 0;
- int maxdepth = 0;
-
- if (!grp) return 0;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
-
- depth = xaccGroupGetDepth (account->children);
-
- if (depth > maxdepth)
- maxdepth = depth;
- }
-
- maxdepth++;
-
- return maxdepth;
-}
-
-/********************************************************************\
-\********************************************************************/
-void
-xaccSplitsBeginStagedTransactionTraversals (GList *splits)
-{
- GList *lp;
-
- for (lp = splits; lp; lp = lp->next)
- {
- Split *s = lp->data;
- Transaction *trans = s->parent;
-
- if (trans)
- trans->marker = 0;
- }
-}
-
-void
-xaccAccountBeginStagedTransactionTraversals (const Account *account)
-{
- if (account)
- xaccSplitsBeginStagedTransactionTraversals (account->splits);
-}
-
-gboolean
-xaccTransactionTraverse (Transaction *trans, int stage)
-{
- if (trans == NULL) return FALSE;
-
- if (trans->marker < stage)
- {
- trans->marker = stage;
- return TRUE;
- }
-
- return FALSE;
-}
-
-gboolean
-xaccSplitTransactionTraverse (Split *split, int stage)
-{
- if (split == NULL) return FALSE;
-
- return xaccTransactionTraverse (split->parent, stage);
-}
-
-void
-xaccGroupBeginStagedTransactionTraversals (AccountGroup *grp)
-{
- GList *node;
-
- if (!grp) return;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- GList *lp;
-
- /* recursively do sub-accounts */
- xaccGroupBeginStagedTransactionTraversals (account->children);
-
- for (lp = account->splits; lp; lp = lp->next)
- {
- Split *s = lp->data;
- Transaction *trans = s->parent;
- trans->marker = 0;
- }
- }
-}
-
-int
-xaccAccountStagedTransactionTraversal (const Account *acc,
- unsigned int stage,
- int (*callback)(Transaction *t,
- void *cb_data),
- void *cb_data)
-{
- GList *lp;
- if (!acc) return 0;
-
- for(lp = acc->splits; lp; lp = lp->next)
- {
- Split *s = (Split *) lp->data;
- Transaction *trans = s->parent;
- if (trans && (trans->marker < stage))
- {
- trans->marker = stage;
- if (callback)
- {
- int retval;
- retval = callback(trans, cb_data);
- if (retval) return retval;
- }
- }
- }
-
- return 0;
-}
-
-int
-xaccGroupStagedTransactionTraversal (AccountGroup *grp,
- unsigned int stage,
- int (*callback)(Transaction *t,
- void *cb_data),
- void *cb_data)
-{
- GList *node;
-
- if (!grp) return 0;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- int retval;
-
- /* recursively do sub-accounts */
- retval = xaccGroupStagedTransactionTraversal (account->children, stage,
- callback, cb_data);
- if (retval) return retval;
-
- retval = xaccAccountStagedTransactionTraversal (account, stage,
- callback, cb_data);
- if (retval) return retval;
- }
-
- return 0;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-int
-xaccGroupForEachTransaction (AccountGroup *g,
- int (*proc)(Transaction *t, void *data),
- void *data)
-{
- if (!g || !proc) return 0;
-
- xaccGroupBeginStagedTransactionTraversals (g);
- return xaccGroupStagedTransactionTraversal (g, 42, proc, data);
-}
-
-/********************************************************************\
-\********************************************************************/
-
-AccountList *
-xaccGroupMapAccounts (AccountGroup *grp,
- gpointer (*thunk)(Account *a, gpointer data),
- gpointer data)
-{
- GList *result = NULL;
- GList *node;
-
- if (!grp || !thunk) return NULL;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- gpointer thunk_result = thunk (account, data);
-
- if (thunk_result)
- {
- result = g_list_append (result, thunk_result);
- }
- }
-
- return (result);
-}
-
-gpointer
-xaccGroupForEachAccount (AccountGroup *grp,
- gpointer (*thunk)(Account *a, gpointer data),
- gpointer data,
- gboolean deeply)
-{
- GList *node;
-
- if (!grp || !thunk) return(NULL);
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- gpointer result = thunk (account, data);
-
- if (result)
- return(result);
-
- if(deeply)
- result = xaccGroupForEachAccount (account->children,
- thunk, data, TRUE);
-
- if (result)
- return(result);
- }
-
- return(NULL);
-}
-
-/* ============================================================== */
-
-QofBackend *
-xaccGroupGetBackend (const AccountGroup *grp)
-{
- grp = xaccGroupGetRoot (grp);
- if (!grp || !grp->book) return NULL;
- return qof_book_get_backend(grp->book);
-}
-
-/* ============================================================== */
-/* gncObject function implementation and registration */
-
-static void
-group_book_begin (QofBook *book)
-{
- xaccSetAccountGroup (book, xaccMallocAccountGroup(book));
-}
-
-static void
-group_book_end (QofBook *book)
-{
- xaccSetAccountGroup (book, NULL);
-}
-
-static gboolean
-group_is_dirty (const QofCollection *col)
-{
- return xaccGroupNotSaved(xaccCollGetAccountGroup(col));
-}
-
-static void
-group_mark_clean(QofCollection *col)
-{
- xaccGroupMarkSaved(xaccCollGetAccountGroup(col));
-}
-
-static QofObject group_object_def =
-{
- interface_version: QOF_OBJECT_VERSION,
- e_type: GNC_ID_GROUP,
- type_label: "AccountGroup",
- create: (gpointer)xaccMallocAccountGroup,
- book_begin: group_book_begin,
- book_end: group_book_end,
- is_dirty: group_is_dirty,
- mark_clean: group_mark_clean,
- foreach: NULL,
- printable: NULL,
- version_cmp: NULL,
-};
-
-gboolean
-xaccGroupRegister (void)
-{
- return qof_object_register (&group_object_def);
-}
-
-/* ========================= END OF FILE ======================== */
Deleted: gnucash/branches/remove-group2/src/engine/Group.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/Group.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Group.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,439 +0,0 @@
-/********************************************************************\
- * Group.h -- chart of accounts (hierarchical tree of accounts) *
- * *
- * This program is free software; you can redistribute it and/or *
- * modify it under the terms of the GNU General Public License as *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
-\********************************************************************/
-/** @addtogroup Engine
- @{ */
-/** @addtogroup Group Account Heirarchy Tree
- Accounts are organized into a heirarchical tree. The account
- group is the parent node that holds accounts.
- @{ */
-/** @file Group.h
- @brief Account handling public routines
- @author Copyright (C) 1997 Robin D. Clark
- @author Copyright (C) 1997-2000,2003 Linas Vepstas <linas at linas.org>
-*/
-
-
-#ifndef XACC_ACCOUNT_GROUP_H
-#define XACC_ACCOUNT_GROUP_H
-
-#include <glib.h>
-#include "qof.h"
-#include "Account.h"
-
-/* PROTOTYPES ******************************************************/
-/** @name Constructors, Destructors
- @{
-*/
-/**
- * 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 (QofBook *book);
-
-/**
- * The xaccGetAccountGroup() routine will return the top-most
- * account group associated with the indicated book.
- */
-AccountGroup * xaccGetAccountGroup (QofBook *book);
-
-/**
- * The xaccCollAccountGroup() routine will return the top-most
- * account group associated with the indicated collection.
- */
-AccountGroup * xaccCollGetAccountGroup (const QofCollection *col);
-
-/** 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.
- */
-void xaccAccountGroupDestroy (AccountGroup *grp);
-
-/* @deprecated XXX backwards-compat define, remove at later convenience */
-#define gnc_book_get_group xaccGetAccountGroup
-
-/** Return the book to which this account belongs */
-QofBook * xaccGroupGetBook (const AccountGroup *group);
-
-/** Compare two account groups
-
-warns if one is NULL, if one has no accounts or if the two
-groups have different numbers of accounts.
-
- at return TRUE if the two account groups are equal, FALSE otherwise.
-*/
-gboolean xaccGroupEqual(const AccountGroup *a, const AccountGroup *b,
- gboolean check_guids);
-
-/** @} */
-
-/** @name Editing
- @{
-*/
-/** Start of begine/commit sequence. All changes to an account
- * group should be bracketed by calls to begin-edit/commit-edit
- */
-void xaccAccountGroupBeginEdit (AccountGroup *grp);
-
-/** End of begine/commit sequence. All changes to an account
- * group should be bracketed by calls to begin-edit/commit-edit
- */
-void xaccAccountGroupCommitEdit (AccountGroup *grp);
-
-/** The xaccGroupNotSaved() subroutine will return TRUE
- * if any account in the group or in any subgroup
- * hasn't been saved.
- XXX this should be moved to private header file, this is not a public routine!
- */
-gboolean xaccGroupNotSaved (const AccountGroup *grp);
-
-/** The xaccGroupMarkSaved() subroutine will mark
- * the entire group as having been saved, including
- * all of the child accounts.
-
- XXX this should be moved to private header file, this is not a public routine!
- */
-void xaccGroupMarkSaved (AccountGroup *grp);
-
-/** The xaccGroupMarkNotSaved() subroutine will mark
- * the given group as not having been saved.
- XXX this should be moved to private header file, this is not a public routine!
- */
-void xaccGroupMarkNotSaved (AccountGroup *grp);
-/** @} */
-
-/** @name Concatenation, Merging
- @{
-*/
-/**
- * The xaccGroupConcatGroup() subroutine will move (reparent)
- * all accounts from the "src" group to the "dest" group,
- * preserving the account heirarchy. It will also take care
- * that the moved accounts will have the "dest" group's book
- * parent as well.
- */
-void xaccGroupConcatGroup (AccountGroup *dest, AccountGroup *src);
-
-/** The xaccGroupCopyGroup() subroutine will copy all accounts
- * from the "src" group to the "dest" group, preserving the
- * account heirarchy. It will also take care that the moved
- * accounts will have the "dest" group's book parent as well.
- * This routine will *NOT* copy any splits/transactions.
- * It will copy the KVP trees in each account.
- */
-void xaccGroupCopyGroup (AccountGroup *dest, AccountGroup *src);
-
-/** The xaccGroupMergeAccounts() subroutine will go through a group,
- * merging all accounts that have the same name and description.
- * This function is useful when importing Quicken(TM) files.
- */
-void xaccGroupMergeAccounts (AccountGroup *grp);
-
-/** The xaccGroupInsertAccount() subroutine will insert the indicated
- * account into the indicated group. If it already is the child
- * of another group, it will be removed there first. If the
- * account belongs to a different book than the the group, it
- * will be removed from the other book (and thus, the other book's
- * entity tables, generating destroy & create events). If the
- * account is removed from and inserted into the same group, the
- * overall account sort order will be recomputed.
- */
-void xaccGroupInsertAccount (AccountGroup *grp, Account *acc);
-
-/** The xaccAccountInsertSubAccount() does the same, except that
- * the parent is specified as an account.
- */
-void xaccAccountInsertSubAccount (Account *parent, Account *child);
-/** @} */
-
-/** @name Counting the Size and Depth of the Account Tree
- @{
-*/
-/** The xaccGroupGetNumSubAccounts() subroutine returns the number
- * of accounts, including subaccounts, in the account group
- */
-int xaccGroupGetNumSubAccounts (const AccountGroup *grp);
-
-/** The xaccGroupGetNumAccounts() subroutine returns the number
- * of accounts in the indicated group only (children not counted).
- */
-int xaccGroupGetNumAccounts (const AccountGroup *grp);
-
-/** The xaccGroupGetDepth() subroutine returns the length of the
- * longest tree branch. Each link between an account and its
- * (non-null) children counts as one unit of length.
- */
-int xaccGroupGetDepth (const AccountGroup *grp);
-/** @} */
-
-/** @name Getting Accounts and Subaccounts
- @{
-*/
-/** DOCUMENT ME! is this routine deprecated? XXX using index is weird! */
-Account * xaccGroupGetAccount (const AccountGroup *group, int index);
-
-/** The xaccGroupGetSubAccounts() subroutine returns an list of the accounts,
- * including subaccounts, in the account group. The returned list
- * should be freed with g_list_free() when no longer needed.
- */
-AccountList * xaccGroupGetSubAccounts (const AccountGroup *grp);
-
-/** The xaccGroupGetSubAccounts() subroutine returns a sorted list of
- * the accounts, including subaccounts, in the account group. The
- * returned list should be freed with g_list_free() when no longer
- * needed.
- */
-AccountList * xaccGroupGetSubAccountsSorted (const AccountGroup *grp);
-
-/** The xaccGroupGetAccountList() subroutines returns only the immediate
- * children of the account group. The returned list should *not*
- * be freed by the caller.
- */
-AccountList * xaccGroupGetAccountList (const AccountGroup *grp);
-
-/** The xaccGroupGetAccountList() subroutines returns only the
- * immediate children of the account group. The returned list
- * should be freed with g_list_free() when no longer needed.
- */
-AccountList * xaccGroupGetAccountListSorted (const AccountGroup *grp);
-
-/** The xaccGroupGetRoot() subroutine will find the topmost
- * (root) group to which this group belongs.
- */
-AccountGroup * xaccGroupGetRoot (const AccountGroup *grp);
-
-/** The xaccGetAccountRoot() subroutine will find the topmost
- * (root) group to which this account belongs.
- */
-AccountGroup * xaccAccountGetRoot (const Account *account);
-
-/** The xaccGroupGetParentAccount() subroutine returns the parent
- * account of the group, or NULL.
- */
-Account * xaccGroupGetParentAccount (const AccountGroup *group);
-
-/** @} */
-
-/** @name Getting Accounts and Subaccounts by Name
- @{
-*/
-/** The xaccGetAccountFromName() subroutine fetches the
- * account by name from the collection of accounts
- * in the indicated AccountGroup group. It returns NULL if the
- * account was not found.
- */
-Account *xaccGetAccountFromName (const AccountGroup *group, const char *name);
-
-/** The xaccGetAccountFromFullName() subroutine works like
- * xaccGetAccountFromName, but uses fully-qualified names
- * using the given separator.
- */
-Account *xaccGetAccountFromFullName (const AccountGroup *group,
- const char *name);
-
-/** The xaccGetPeerAccountFromName() subroutine fetches the
- * account by name from the collection of accounts
- * in the same AccountGroup anchor group. It returns NULL if the
- * account was not found.
- */
-Account *xaccGetPeerAccountFromName (const Account *account, const char *name);
-
-/** The xaccGetPeerAccountFromFullName() subroutine works like
- * xaccGetPeerAccountFromName, but uses fully-qualified
- * names using the given separator.
- */
-Account *xaccGetPeerAccountFromFullName (const Account *acc,
- const char * name);
-
-/** @} */
-
-/** @name Traversal, ForEach
- @{
-*/
-
-typedef gpointer (*AccountCallback) (Account *a, gpointer data);
-
-/** The xaccGroupMapAccounts() routine will traverse the account
- group, returning a list of accounts. If the callback
- returns null for a given item, it won't show up in
- the result list. You should free the returned list when
- you are done with it.
-*/
-AccountList *xaccGroupMapAccounts(AccountGroup *grp,
- AccountCallback func,
- gpointer data);
-
-/** The xaccGroupForEachAccount() method will traverse the AccountGroup
- * tree, calling 'func' on each account. Traversal will stop when
- * func returns a non-null value, and the routine will return with that
- * value. Therefore, this function will return null iff func returns
- * null for every account.
- *
- * If 'deeply' is FALSE, then only the immediate children of
- * the account will be traversed. If TRUE, then the whole tree will
- * be traversed.
- */
-
-gpointer xaccGroupForEachAccount (AccountGroup *grp,
- AccountCallback func,
- gpointer data,
- gboolean deeply);
-
-/** @} */
-
-/** @name Staged Traversal
-
- * The following functions provide support for "staged traversals"
- * over all of the transactions in an account or group. The idea
- * is to be able to perform a sequence of traversals ("stages"),
- * and perform an operation on each transaction exactly once
- * for that stage.
- *
- * Only transactions whose current "stage" is less than the
- * stage of the current traversal will be affected, and they will
- * be "brought up" to the current stage when they are processed.
- *
- * For example, you could perform a stage 1 traversal of all the
- * transactions in an account, and then perform a stage 1 traversal of
- * the transactions in a second account. Presuming the traversal of
- * the first account didn't abort prematurely, any transactions shared
- * by both accounts would be ignored during the traversal of the
- * second account since they had been processed while traversing the
- * first account.
- *
- * However, if you had traversed the second account using a stage
- * of 2, then all the transactions in the second account would have
- * been processed.
- *
- * Traversal can be aborted by having the callback function return
- * a non-zero value. The traversal is aborted immediately, and the
- * non-zero value is returned. Note that an aborted traversal can
- * be restarted; no information is lost due to an abort.
- *
- * The initial impetus for this particular approach came from
- * generalizing a mark/sweep practice that was already being
- * used in FileIO.c.
- *
- * Note that currently, there is a hard limit of 256 stages, which
- * can be changed by enlarging "marker" in the transaction struct.
- *
- @{
-*/
-/** xaccGroupBeginStagedTransactionTraversals() resets the traversal
- * marker inside each of all the transactions in the group so that
- * a new sequence of staged traversals can begin.
- */
-void xaccGroupBeginStagedTransactionTraversals(AccountGroup *grp);
-
-/** xaccSplitsBeginStagedTransactionTraversals() resets the traversal
- * marker for each transaction which is a parent of one of the
- * splits in the list.
- */
-void xaccSplitsBeginStagedTransactionTraversals(SplitList *splits);
-
-/** xaccAccountBeginStagedTransactionTraversals() resets the traversal
- * marker for each transaction which is a parent of one of the
- * splits in the account.
- */
-void xaccAccountBeginStagedTransactionTraversals(const Account *account);
-
-/** xaccTransactionTraverse() checks the stage of the given transaction.
- * If the transaction hasn't reached the given stage, the transaction
- * is updated to that stage and the function returns TRUE. Otherwise
- * no change is made and the function returns FALSE.
- */
-gboolean xaccTransactionTraverse(Transaction *trans, int stage);
-
-/** xaccSplitTransactionTraverse() behaves as above using the parent of
- * the given split.
- */
-gboolean xaccSplitTransactionTraverse(Split *split, int stage);
-
-/** xaccGroupStagedTransactionTraversal() calls thunk on each
- * transaction in the group whose current marker is less than the
- * given `stage' and updates each transaction's marker to be `stage'.
- * The traversal will stop if thunk() returns a non-zero value.
- * xaccGroupStagedTransactionTraversal() function will return zero
- * or the non-zero value returned by thunk(). This
- * API does not handle handle recursive traversals.
- *
- * Currently the result of adding or removing transactions during
- * a traversal is undefined, so don't do that.
- */
-
-int xaccGroupStagedTransactionTraversal(AccountGroup *grp,
- unsigned int stage,
- TransactionCallback,
- void *data);
-
-/** xaccAccountStagedTransactionTraversal() calls thunk on each
- * transaction in the account whose current marker is less than the
- * given `stage' and updates each transaction's marker to be `stage'.
- * The traversal will stop if thunk() returns a non-zero value.
- * xaccAccountStagedTransactionTraversal() function will return zero
- * or the non-zero value returned by thunk().
- * This API does not handle handle recursive traversals.
- *
- * Currently the result of adding or removing transactions during
- * a traversal is undefined, so don't do that.
- */
-
-int xaccAccountStagedTransactionTraversal(const Account *a,
- unsigned int stage,
- TransactionCallback thunk,
- void *data);
-
-/** Traverse all of the transactions in the given account group.
- Continue processing IFF proc returns 0. This function
- will descend recursively to traverse transactions in the
- children of the accounts in the group.
-
- Proc will be called exactly once for each transaction that is
- pointed to by at least one split in any account in the hierarchy
- topped by AccountGroup g.
-
- The result of this function will be 0 IFF every relevant
- transaction was traversed exactly once; otherwise, the return
- value is the last non-zero value returned by the callback.
-
- Note that the traversal occurs only over the transactions that
- are locally cached in the local gnucash engine. If the gnucash
- engine is attached to a remote database, the database may contain
- (many) transactions that are not mirrored in the local cache.
- This routine will not cause an SQL database query to be performed;
- it will not traverse transactions present only in the remote
- database.
-
- Note that this routine is just a trivial wrapper for
-
- xaccGroupBeginStagedTransactionTraversals(g);
- xaccGroupStagedTransactionTraversal(g, 42, proc, data);
- */
-
-int xaccGroupForEachTransaction(AccountGroup *g,
- TransactionCallback proc, void *data);
-
-/** @} */
-#endif /* XACC_ACCOUNT_GROUP_H */
-/** @} */
-/** @} */
Deleted: gnucash/branches/remove-group2/src/engine/GroupP.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/GroupP.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/GroupP.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1,102 +0,0 @@
-/********************************************************************\
- * GroupP.h -- private header file for chart of accounts *
- * Copyright (C) 1997 Robin D. Clark *
- * Copyright (C) 1997, 1998, 1999, 2000 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 *
- * published by the Free Software Foundation; either version 2 of *
- * the License, or (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License*
- * along with this program; if not, contact: *
- * *
- * Free Software Foundation Voice: +1-617-542-5942 *
- * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
- * Boston, MA 02110-1301, USA gnu at gnu.org *
- * *
-\********************************************************************/
-
-/*
- * FILE:
- * GroupP.h
- *
- * FUNCTION:
- * This is the *private* account group structure.
- * This header should *not* be included by any code outside of the
- * engine.
- *
- */
-
-#ifndef XACC_GROUP_P_H
-#define XACC_GROUP_P_H
-
-#include "Group.h"
-#include "Transaction.h"
-
-/** STRUCTS *********************************************************/
-struct account_group_s
-{
- /* The flags: */
- unsigned int saved : 1;
-
- Account *parent; /* back-pointer to parent */
-
- AccountList *accounts; /* list of account pointers */
-
- QofBook *book; /* The book which this group belongs to */
-
- /* keep track of nesting level of begin/end edit calls */
- gint32 editlevel;
-};
-
-/*
- * The xaccAccountRemoveGroup() subroutine will remove the indicated
- * account group from its parent account. It will NOT free the
- * associated memory or otherwise alter the account group: the
- * account group can now be reparented to a new location.
- * Note, however, that it will mark the old parents as having
- * been modified.
- *
- * The xaccGroupRemoveAccount() subroutine will remove the indicated
- * account from its parent account group. It will NOT free the
- * associated memory or otherwise alter the account: the account
- * can now be reparented to a new location.
- * Note, however, that it will mark the old parents as having
- * been modified.
- *
- * Both of the above routines are private routines, since they are slightly
- * dangerous: If the removed group/account is not immediately reparented,
- * it can be lost, i.e. turn into a memory leak. If the GUI or other engine
- * user needs to move an account or group from here to there, it should use
- * the 'Insert' routines, such as xaccGroupInsertAccount(), to make the move.
- * The 'Insert' routines will automatically remove the account from its
- * previous location.
- */
-
-void xaccAccountRemoveGroup (Account *acc);
-void xaccGroupRemoveAccount (AccountGroup *grp, Account *account);
-
-/*
- * The xaccFreeAccountGroup() subroutine will ...
- */
-void xaccFreeAccountGroup (AccountGroup *account_group);
-
-/* Set the top-level group in the book */
-void xaccSetAccountGroup (QofBook *book, AccountGroup *grp);
-void xaccCollSetAccountGroup (QofCollection *col, AccountGroup *grp);
-
-/*
- * The xaccGroupGetBackend() subroutine will find the
- * persistent-data storage backend associated with this account group.
- */
-QofBackend * xaccGroupGetBackend (const AccountGroup *group);
-
-gboolean xaccGroupRegister (void);
-
-#endif
Modified: gnucash/branches/remove-group2/src/engine/Makefile.am
===================================================================
--- gnucash/branches/remove-group2/src/engine/Makefile.am 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Makefile.am 2006-11-01 00:01:35 UTC (rev 15066)
@@ -16,7 +16,6 @@
Account.c \
FreqSpec.c \
Recurrence.c \
- Group.c \
Period.c \
Query.c \
SchedXaction.c \
@@ -57,7 +56,6 @@
FreqSpec.h \
Recurrence.h \
GNCId.h \
- Group.h \
Period.h \
SchedXaction.h \
SX-book.h \
@@ -96,7 +94,6 @@
noinst_HEADERS = \
AccountP.h \
FreqSpecP.h \
- GroupP.h \
QueryP.h \
SchedXactionP.h \
ScrubP.h \
Modified: gnucash/branches/remove-group2/src/engine/Period.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Period.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Period.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -40,9 +40,8 @@
#include "gnc-lot-p.h"
#include "gnc-pricedb.h"
#include "gnc-pricedb-p.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Period.h"
+#include "Transaction.h"
#include "TransactionP.h"
/* This static indicates the debugging module that this .o belongs to. */
@@ -432,29 +431,19 @@
/* clear the markers for the above routines */
static void
-clear_markers (AccountGroup *grp)
+clear_markers (Account *account, gpointer dummy)
{
- GList *node;
+ GList *lp;
- if (!grp) return;
-
- for (node = grp->accounts; node; node = node->next)
- {
- Account *account = node->data;
- GList *lp;
-
- /* recursively do sub-accounts */
- clear_markers (account->children);
-
- for (lp = account->splits; lp; lp = lp->next)
- {
- Split *s = lp->data;
- Transaction *trans = s->parent;
- GNCLot *lot = s->lot;
- trans->marker = 0;
- if (lot) lot->marker = 0;
- }
- }
+ if (!account) return;
+
+ for (lp = xaccAccountGetSplitList(account); lp; lp = lp->next) {
+ Split *s = lp->data;
+ Transaction *trans = s->parent;
+ GNCLot *lot = s->lot;
+ trans->marker = 0;
+ if (lot) lot->marker = 0;
+ }
}
/* ================================================================ */
@@ -526,7 +515,7 @@
gnc_book_partition_txn (QofBook *dest_book, QofBook *src_book, QofQuery *query)
{
gnc_commodity_table *src_tbl, *dst_tbl;
- AccountGroup *src_grp, *dst_grp;
+ Account *src_root, *dst_root;
time_t now;
TransList *trans_list, *tnode;
LotList *lot_list, *lnode;
@@ -552,18 +541,18 @@
/* hack alert -- FIXME -- this should really be a merge, not a
* clobber copy, but I am too lazy to write an account-group merge
* routine, and it is not needed for the current usage. */
- src_grp = xaccGetAccountGroup (src_book);
- dst_grp = xaccGetAccountGroup (dest_book);
- xaccGroupCopyGroup (dst_grp, src_grp);
+ src_root = gnc_book_get_root_account (src_book);
+ dst_root = gnc_book_get_root_account (dest_book);
+ gnc_account_copy_children (dst_root, src_root);
/* Next, run the query */
- xaccAccountGroupBeginEdit (dst_grp);
- xaccAccountGroupBeginEdit (src_grp);
+ xaccAccountBeginEdit (dst_root);
+ xaccAccountBeginEdit (src_root);
qof_query_set_book (query, src_book);
trans_list = qof_query_run (query);
/* Preen: remove open lots/ open trnasactions */
- clear_markers (src_grp);
+ gnc_account_foreach_descendant(src_root, clear_markers, NULL);
trans_list = trans_list_preen_open_lots (trans_list);
lot_list = create_lot_list_from_trans_list (trans_list);
lot_list = lot_list_preen_open_lots (lot_list);
@@ -583,8 +572,8 @@
gnc_book_insert_trans (dest_book, trans);
}
- xaccAccountGroupCommitEdit (src_grp);
- xaccAccountGroupCommitEdit (dst_grp);
+ xaccAccountCommitEdit (src_root);
+ xaccAccountCommitEdit (dst_root);
/* Make note of the sibling books */
now = time(0);
@@ -603,41 +592,37 @@
static Account *
find_nearest_equity_acct (Account *acc)
{
- AccountList *acc_list, *node;
- AccountGroup *parent;
- Account *next_up, *candidate;
+ QofBook *book;
+ GList *acc_list, *node;
+ Account *parent, *root, *candidate;
- /* See if we can find an equity account that is peered to this account */
- parent = xaccAccountGetParent (acc);
+ parent = gnc_account_get_parent (acc);
g_return_val_if_fail (parent, NULL);
- acc_list = xaccGroupGetAccountList (parent);
- for (node=acc_list; node; node=node->next)
- {
- candidate = (Account *) node->data;
- if ((ACCT_TYPE_EQUITY == xaccAccountGetType (candidate)) &&
- gnc_commodity_equiv(xaccAccountGetCommodity(acc),
- xaccAccountGetCommodity(candidate)))
- {
+ /* See if we can find an equity account that is peered to this
+ * account. If not, check succssively higher levels. */
+ while (parent != NULL) {
+ acc_list = gnc_account_get_children(parent);
+ for (node=acc_list; node; node=node->next) {
+ candidate = (Account *) node->data;
+ if ((ACCT_TYPE_EQUITY == xaccAccountGetType (candidate)) &&
+ gnc_commodity_equiv(xaccAccountGetCommodity(acc),
+ xaccAccountGetCommodity(candidate))) {
return candidate;
- }
+ }
+ }
+ g_list_free(acc_list);
+ parent = gnc_account_get_parent (parent);
}
- /* If we got to here, we did not find a peer equity account.
- * So go up one layer, and look there */
- next_up = xaccGroupGetParentAccount (parent);
- if (next_up)
- {
- candidate = find_nearest_equity_acct (next_up);
- if (candidate) return candidate;
- }
-
- /* If we got to here, then we are at the top group, and there is no
+ /* If we got to here, then we are at the root account, and there is no
* equity account to be found. So we need to create one. */
-
- candidate = xaccMallocAccount (xaccGroupGetBook(parent));
+
+ book = gnc_account_get_book(acc);
+ root = gnc_book_get_root_account(book);
+ candidate = xaccMallocAccount (book);
xaccAccountBeginEdit (candidate);
- xaccGroupInsertAccount (parent, candidate);
+ gnc_account_append_child (root, candidate);
xaccAccountSetType (candidate, ACCT_TYPE_EQUITY);
xaccAccountSetName (candidate, xaccAccountGetTypeStr(ACCT_TYPE_EQUITY));
xaccAccountSetCommodity (candidate, xaccAccountGetCommodity(acc));
@@ -650,28 +635,27 @@
/* Traverse all accounts, get account balances */
static void
-add_closing_balances (AccountGroup *closed_grp,
+add_closing_balances (Account *parent,
QofBook *open_book,
QofBook *closed_book,
Account *equity_account,
Timespec *post_date, Timespec *date_entered,
const char *desc)
{
- AccountList *acc_list, *node;
+ GList *acc_list, *node;
- if (!closed_grp) return;
+ if (!parent) return;
ENTER (" enter=%s post=%s desc=%s", gnc_print_date(*date_entered),
gnc_print_date (*post_date), desc);
xaccAccountBeginEdit (equity_account);
/* Walk accounts in closed book */
- acc_list = xaccGroupGetAccountList (closed_grp);
+ acc_list = gnc_account_get_children(parent);
for (node=acc_list; node; node=node->next)
{
KvpFrame *cwd;
Account *twin;
- AccountGroup *childs;
Account * candidate = (Account *) node->data;
GNCAccountType tip = xaccAccountGetType (candidate);
@@ -774,16 +758,16 @@
xaccAccountCommitEdit (twin);
/* Recurse down to the children */
- childs = xaccAccountGetChildren(candidate);
- if (childs)
+ if (gnc_account_n_children(candidate) > 0)
{
PINFO ("add closing baln to subaccts of %s",
candidate->description);
- add_closing_balances (childs, open_book, closed_book,
+ add_closing_balances (candidate, open_book, closed_book,
equity_account,
post_date, date_entered, desc);
}
}
+ g_list_free(acc_list);
xaccAccountCommitEdit (equity_account);
LEAVE (" ");
}
@@ -884,7 +868,7 @@
/* add in transactions to equity accounts that will
* hold the colsing balances */
- add_closing_balances (xaccGetAccountGroup(closing_book),
+ add_closing_balances (gnc_book_get_root_account(closing_book),
existing_book, closing_book,
equity_account,
&calve_date, &ts, memo);
Modified: gnucash/branches/remove-group2/src/engine/SX-book-p.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/SX-book-p.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/SX-book-p.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -47,11 +47,11 @@
void gnc_collection_set_schedxactions( QofCollection *col, GList *newList );
-/* Associate the given template group with a book */
-void gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup);
-void gnc_collection_set_template_group (QofCollection *col, AccountGroup *templateGroup);
+/* Associate the given template root account with a book */
+void gnc_book_set_template_root (QofBook *book, Account *templateRoot);
+
gboolean gnc_sxtt_register (void);
#endif /* GNC_SX_BOOK_P_H */
Modified: gnucash/branches/remove-group2/src/engine/SX-book.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/SX-book.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/SX-book.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -39,8 +39,8 @@
#include <glib.h>
#include "gnc-engine.h"
-#include "Group.h"
-#include "GroupP.h"
+#include "Account.h"
+#include "Split.h"
#include "SchedXaction.h"
#include "SX-book.h"
#include "SX-book-p.h"
@@ -52,52 +52,54 @@
/* ====================================================================== */
-AccountGroup *
-gnc_collection_get_template_group( const QofCollection *col )
+static Account *
+gnc_collection_get_template_root( const QofCollection *col )
{
return qof_collection_get_data (col);
}
-AccountGroup *
-gnc_book_get_template_group( QofBook *book )
+Account *
+gnc_book_get_template_root( QofBook *book )
{
QofCollection *col;
if (!book) return NULL;
col = qof_book_get_collection (book, GNC_ID_SXTG);
- return gnc_collection_get_template_group (col);
+ return gnc_collection_get_template_root (col);
}
-void
-gnc_collection_set_template_group (QofCollection *col,
- AccountGroup *templateGroup)
+static void
+gnc_collection_set_template_root (QofCollection *col,
+ Account *templateRoot)
{
- AccountGroup *old_grp;
+ Account *old_root;
if (!col) return;
- old_grp = gnc_collection_get_template_group (col);
- if (old_grp == templateGroup) return;
+ old_root = gnc_collection_get_template_root (col);
+ if (old_root == templateRoot) return;
- qof_collection_set_data (col, templateGroup);
+ qof_collection_set_data (col, templateRoot);
- xaccAccountGroupBeginEdit (old_grp);
- xaccAccountGroupDestroy (old_grp);
+ if (old_root) {
+ xaccAccountBeginEdit (old_root);
+ xaccAccountDestroy (old_root);
+ }
}
void
-gnc_book_set_template_group (QofBook *book, AccountGroup *templateGroup)
+gnc_book_set_template_root (QofBook *book, Account *templateRoot)
{
QofCollection *col;
if (!book) return;
- if (templateGroup && templateGroup->book != book)
+ if (templateRoot && gnc_account_get_book(templateRoot) != book)
{
PERR ("cannot mix and match books freely!");
return;
}
col = qof_book_get_collection (book, GNC_ID_SXTG);
- gnc_collection_set_template_group (col, templateGroup);
+ gnc_collection_set_template_root (col, templateRoot);
}
@@ -107,26 +109,55 @@
static void
sxtg_book_begin (QofBook *book)
{
- gnc_book_set_template_group (book, xaccMallocAccountGroup(book));
+ Account *root;
+
+ root = xaccMallocAccount(book);
+ xaccAccountBeginEdit(root);
+ xaccAccountSetType(root, ACCT_TYPE_ROOT);
+ xaccAccountCommitEdit(root);
+ gnc_book_set_template_root (book, root);
}
static void
sxtg_book_end (QofBook *book)
{
- gnc_book_set_template_group (book, NULL);
+ gnc_book_set_template_root (book, NULL);
}
static gboolean
sxtg_is_dirty(const QofCollection *col)
{
- return xaccGroupNotSaved(gnc_collection_get_template_group(col));
+ Account *root;
+ GList *accounts, *node;
+ gboolean dirty = FALSE;
+
+ root = gnc_collection_get_template_root(col);
+ accounts = gnc_account_get_descendants(root);
+ for (node = accounts; node; node = g_list_next(node)) {
+ if (qof_instance_is_dirty(node->data)) {
+ dirty = TRUE;
+ break;
+ }
+ }
+ g_list_free(accounts);
+
+ return dirty;
}
static void
sxtg_mark_clean(QofCollection *col)
{
- xaccGroupMarkSaved(gnc_collection_get_template_group(col));
+ Account *root;
+ GList *accounts, *node;
+
+ root = gnc_collection_get_template_root(col);
+ qof_collection_mark_clean(col);
+
+ accounts = gnc_account_get_descendants(root);
+ for (node = accounts; node; node = g_list_next(node))
+ qof_instance_mark_clean(node->data);
+ g_list_free(accounts);
}
static QofObject sxtg_object_def =
Modified: gnucash/branches/remove-group2/src/engine/SX-book.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/SX-book.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/SX-book.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -48,8 +48,7 @@
GList * gnc_book_get_schedxactions(QofBook *book);
/** Returns the template group from the book. **/
-AccountGroup * gnc_book_get_template_group(QofBook *book);
-AccountGroup * gnc_collection_get_template_group(const QofCollection *col);
+Account *gnc_book_get_template_root(QofBook *book);
/** @return The list of SXes which reference the given Account. Caller should free this list. **/
GList* gnc_sx_get_sxes_referencing_account(QofBook *book, Account *acct);
Modified: gnucash/branches/remove-group2/src/engine/SchedXaction.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/SchedXaction.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/SchedXaction.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -32,8 +32,6 @@
#include "FreqSpec.h"
#include "Account.h"
#include "gnc-book.h"
-#include "Group.h"
-#include "GroupP.h"
#include "SX-book.h"
#include "SX-ttinfo.h"
#include "SchedXaction.h"
@@ -50,7 +48,7 @@
static void
xaccSchedXactionInit(SchedXaction *sx, QofBook *book)
{
- AccountGroup *ag;
+ Account *ra;
qof_instance_init (&sx->inst, GNC_ID_SCHEDXACTION, book);
@@ -79,8 +77,8 @@
"template", "template",
"template", "template", 1 ) );
xaccAccountSetType( sx->template_acct, ACCT_TYPE_BANK );
- ag = gnc_book_get_template_group( book );
- xaccGroupInsertAccount( ag, sx->template_acct );
+ ra = gnc_book_get_template_root( book );
+ gnc_account_append_child( ra, sx->template_acct );
}
SchedXaction*
Modified: gnucash/branches/remove-group2/src/engine/Scrub.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Scrub.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Scrub.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -45,8 +45,6 @@
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Scrub.h"
#include "ScrubP.h"
#include "Transaction.h"
@@ -58,34 +56,19 @@
/* ================================================================ */
void
-xaccGroupScrubOrphans (AccountGroup *grp)
-{
- GList *list;
- GList *node;
-
- if (!grp) return;
-
- list = xaccGroupGetAccountList (grp);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccAccountTreeScrubOrphans (account);
- }
-}
-
-void
xaccAccountTreeScrubOrphans (Account *acc)
{
+ GList *descendants;
if (!acc) return;
- xaccGroupScrubOrphans (xaccAccountGetChildren(acc));
xaccAccountScrubOrphans (acc);
+ descendants = gnc_account_get_descendants(acc);
+ g_list_foreach(descendants, (GFunc)xaccAccountScrubOrphans, NULL);
+ g_list_free(descendants);
}
static void
-TransScrubOrphansFast (Transaction *trans, AccountGroup *root)
+TransScrubOrphansFast (Transaction *trans, Account *root)
{
GList *node;
@@ -125,7 +108,7 @@
Split *split = node->data;
TransScrubOrphansFast (xaccSplitGetParent (split),
- xaccAccountGetRoot (acc));
+ gnc_account_get_root (acc));
}
}
@@ -135,14 +118,14 @@
{
SplitList *node;
QofBook *book = NULL;
- AccountGroup *root = NULL;
+ Account *root = NULL;
for (node = trans->splits; node; node = node->next)
{
Split *split = node->data;
if (split->acc)
{
- TransScrubOrphansFast (trans, xaccAccountGetRoot(split->acc));
+ TransScrubOrphansFast (trans, gnc_account_get_root(split->acc));
return;
}
}
@@ -154,35 +137,21 @@
*/
PINFO ("Free Floating Transaction!");
book = xaccTransGetBook (trans);
- root = xaccGetAccountGroup (book);
+ root = gnc_book_get_root_account (book);
TransScrubOrphansFast (trans, root);
}
/* ================================================================ */
void
-xaccGroupScrubSplits (AccountGroup *group)
-{
- GList *list;
- GList *node;
-
- if (!group) return;
-
- list = xaccGroupGetAccountList (group);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccAccountTreeScrubSplits (account);
- }
-}
-
-void
xaccAccountTreeScrubSplits (Account *account)
{
- xaccGroupScrubSplits (xaccAccountGetChildren(account));
+ GList *descendants;
+
xaccAccountScrubSplits (account);
+ descendants = gnc_account_get_descendants(account);
+ g_list_foreach(descendants, (GFunc)xaccAccountScrubSplits, NULL);
+ g_list_free(descendants);
}
void
@@ -289,28 +258,14 @@
/* ================================================================ */
void
-xaccGroupScrubImbalance (AccountGroup *grp)
-{
- GList *list;
- GList *node;
-
- if (!grp) return;
-
- list = xaccGroupGetAccountList (grp);
-
- for (node = list; node; node = node->next)
- {
- Account *account = node->data;
-
- xaccAccountTreeScrubImbalance (account);
- }
-}
-
-void
xaccAccountTreeScrubImbalance (Account *acc)
{
- xaccGroupScrubImbalance (xaccAccountGetChildren(acc));
+ GList *descendants;
+
xaccAccountScrubImbalance (acc);
+ descendants = gnc_account_get_descendants(acc);
+ g_list_foreach(descendants, (GFunc)xaccAccountScrubImbalance, NULL);
+ g_list_free(descendants);
}
void
@@ -332,7 +287,7 @@
xaccTransScrubCurrencyFromSplits(trans);
- xaccTransScrubImbalance (trans, xaccAccountGetRoot (acc), NULL);
+ xaccTransScrubImbalance (trans, gnc_account_get_root (acc), NULL);
}
}
@@ -397,7 +352,7 @@
}
void
-xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
+xaccTransScrubImbalance (Transaction *trans, Account *root,
Account *account)
{
Split *balance_split = NULL;
@@ -418,7 +373,7 @@
{
if (!root)
{
- root = xaccGetAccountGroup (xaccTransGetBook (trans));
+ root = gnc_book_get_root_account (xaccTransGetBook (trans));
if (NULL == root)
{
/* This can't occur, things should be in books */
@@ -711,6 +666,7 @@
gnc_commodity *commodity;
if (!account) return;
+ if (xaccAccountGetType(account) == ACCT_TYPE_ROOT) return;
commodity = xaccAccountGetCommodity (account);
if (commodity) return;
@@ -754,27 +710,22 @@
return 0;
}
-static gpointer
+static void
scrub_account_commodity_helper (Account *account, gpointer data)
{
xaccAccountScrubCommodity (account);
xaccAccountDeleteOldData (account);
- return NULL;
}
void
-xaccGroupScrubCommodities (AccountGroup *group)
+xaccAccountTreeScrubCommodities (Account *acc)
{
- if (!group) return;
+ if (!acc) return;
- xaccAccountGroupBeginEdit (group);
+ xaccAccountTreeForEachTransaction (acc, scrub_trans_currency_helper, NULL);
- xaccGroupForEachTransaction (group, scrub_trans_currency_helper, NULL);
-
- xaccGroupForEachAccount (group, scrub_account_commodity_helper,
- NULL, TRUE);
-
- xaccAccountGroupCommitEdit (group);
+ scrub_account_commodity_helper (acc, NULL);
+ gnc_account_foreach_descendant (acc, scrub_account_commodity_helper, NULL);
}
/* ================================================================ */
@@ -788,7 +739,7 @@
return TRUE;
}
-static gpointer
+static void
move_quote_source (Account *account, gpointer data)
{
gnc_commodity *com;
@@ -798,12 +749,12 @@
com = xaccAccountGetCommodity(account);
if (!com)
- return NULL;
+ return;
if (!new_style) {
source = dxaccAccountGetPriceSrc(account);
if (!source || !*source)
- return NULL;
+ return;
tz = dxaccAccountGetQuoteTZ(account);
PINFO("to %8s from %s", gnc_commodity_get_mnemonic(com),
@@ -818,27 +769,26 @@
dxaccAccountSetPriceSrc(account, NULL);
dxaccAccountSetQuoteTZ(account, NULL);
- return NULL;
+ return;
}
void
-xaccGroupScrubQuoteSources (AccountGroup *group, gnc_commodity_table *table)
+xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table)
{
gboolean new_style = FALSE;
ENTER(" ");
- if (!group || !table) {
+ if (!root || !table) {
LEAVE("Oops");
return;
}
gnc_commodity_table_foreach_commodity (table, check_quote_source, &new_style);
- xaccAccountGroupBeginEdit (group);
- xaccGroupForEachAccount (group, move_quote_source,
- GINT_TO_POINTER(new_style), TRUE);
- xaccAccountGroupCommitEdit (group);
+ move_quote_source(root, GINT_TO_POINTER(new_style));
+ gnc_account_foreach_descendant (root, move_quote_source,
+ GINT_TO_POINTER(new_style));
LEAVE("Migration done");
}
@@ -874,7 +824,7 @@
/* ================================================================ */
Account *
-xaccScrubUtilityGetOrMakeAccount (AccountGroup *root, gnc_commodity * currency,
+xaccScrubUtilityGetOrMakeAccount (Account *root, gnc_commodity * currency,
const char *name_root)
{
char * accname;
@@ -893,19 +843,19 @@
gnc_commodity_get_mnemonic (currency), NULL);
/* See if we've got one of these going already ... */
- acc = xaccGetAccountFromName (root, accname);
+ acc = gnc_account_lookup_by_name(root, accname);
if (acc == NULL)
{
/* Guess not. We'll have to build one. */
- acc = xaccMallocAccount (root->book);
+ acc = xaccMallocAccount(gnc_account_get_book (root));
xaccAccountBeginEdit (acc);
xaccAccountSetName (acc, accname);
xaccAccountSetCommodity (acc, currency);
xaccAccountSetType (acc, ACCT_TYPE_BANK);
/* Hang the account off the root. */
- xaccGroupInsertAccount (root, acc);
+ gnc_account_append_child (root, acc);
xaccAccountCommitEdit (acc);
}
Modified: gnucash/branches/remove-group2/src/engine/Scrub.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/Scrub.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Scrub.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -50,7 +50,6 @@
#ifndef XACC_SCRUB_H
#define XACC_SCRUB_H
-#include "Group.h"
#include "gnc-engine.h"
/** @name Double-Entry Scrubbing
@@ -85,11 +84,6 @@
*/
void xaccAccountTreeScrubOrphans (Account *acc);
-/** The xaccGroupScrubOrphans() method performs this scrub for the
- * child accounts of this group.
- */
-void xaccGroupScrubOrphans (AccountGroup *grp);
-
/** The xaccSplitScrub method ensures that if this split has the same
* commodity and currency, then it will have the same amount and value.
* If the commoidty is the currency, the split->amount is set to the
@@ -106,18 +100,16 @@
void xaccTransScrubSplits (Transaction *trans);
void xaccAccountScrubSplits (Account *account);
void xaccAccountTreeScrubSplits (Account *account);
-void xaccGroupScrubSplits (AccountGroup *group);
/** The xaccScrubImbalance() method searches for transactions that do
* not balance to zero. If any such transactions are found, a split
* is created to offset this amount and is added to an "imbalance"
* account.
*/
-void xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
+void xaccTransScrubImbalance (Transaction *trans, Account *root,
Account *parent);
void xaccAccountScrubImbalance (Account *acc);
void xaccAccountTreeScrubImbalance (Account *acc);
-void xaccGroupScrubImbalance (AccountGroup *grp);
/** The xaccTransScrubCurrency method fixes transactions without a
* common_currency by using the old account currency and security
@@ -137,9 +129,10 @@
* a commodity by using the old account currency and security. */
void xaccAccountScrubCommodity (Account *account);
-/** The xaccGroupScrubCommodities will scrub the currency/commodity
- * of all accounts & transactions in the group. */
-void xaccGroupScrubCommodities (AccountGroup *group);
+/** The xaccAccountTreeScrubCommodities will scrub the
+ * currency/commodity of all accounts & transactions in the specified
+ * account or any child account. */
+void xaccAccountTreeScrubCommodities (Account *acc);
/** This routine will migrate the information about price quote
* sources from the account data structures to the commodity data
@@ -148,13 +141,13 @@
* out as part of the account. Just in case anyone needs to fall
* back from CVS to a production version of code.
*
- * @param group A pointer to the account group containing all
+ * @param acc A pointer to the root account containing all
* accounts in the current book.
*
* @param table A pointer to the commodity table for the current
* book.
*/
-void xaccGroupScrubQuoteSources (AccountGroup *group, gnc_commodity_table *table);
+void xaccAccountTreeScrubQuoteSources (Account *root, gnc_commodity_table *table);
void xaccAccountScrubKvp (Account *account);
Modified: gnucash/branches/remove-group2/src/engine/Scrub2.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Scrub2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Scrub2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -36,8 +36,6 @@
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Transaction.h"
#include "TransactionP.h"
#include "Scrub2.h"
Modified: gnucash/branches/remove-group2/src/engine/Scrub3.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Scrub3.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Scrub3.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -40,7 +40,6 @@
#include "policy-p.h"
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
#include "Scrub2.h"
#include "Scrub3.h"
#include "Transaction.h"
@@ -176,27 +175,19 @@
/* ============================================================== */
-static gpointer
+static void
lot_scrub_cb (Account *acc, gpointer data)
{
- if (FALSE == xaccAccountHasTrades (acc)) return NULL;
+ if (FALSE == xaccAccountHasTrades (acc)) return;
xaccAccountScrubLots (acc);
- return NULL;
}
void
-xaccGroupScrubLots (AccountGroup *grp)
-{
- if (!grp) return;
- xaccGroupForEachAccount (grp, lot_scrub_cb, NULL, TRUE);
-}
-
-void
xaccAccountTreeScrubLots (Account *acc)
{
if (!acc) return;
- xaccGroupScrubLots (acc->children);
+ gnc_account_foreach_descendant(acc, lot_scrub_cb, NULL);
xaccAccountScrubLots (acc);
}
Modified: gnucash/branches/remove-group2/src/engine/Scrub3.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/Scrub3.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Scrub3.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -62,16 +62,11 @@
* lot structure, and the cap-gains for an account are in good
* order.
*
- * The xaccGroupScrubLots() routine walks the account tree, and invokes
- * xaccAccountScrubLots() on all accounts that are trading accounts.
- * The xaccAccountTreeScrubLots() does the same.
- *
* Most GUI routines will want to use one of these xacc[*]ScrubLots()
* routines, instead of the various component routines, since it will
* usually makes sense to work only with these high-level routines.
*/
void xaccAccountScrubLots (Account *acc);
-void xaccGroupScrubLots (AccountGroup *grp);
void xaccAccountTreeScrubLots (Account *acc);
/** @} */
Modified: gnucash/branches/remove-group2/src/engine/ScrubP.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/ScrubP.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/ScrubP.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -33,7 +33,7 @@
#include "gnc-engine.h"
/* Utility to make account by name. Not for public use. */
-Account * xaccScrubUtilityGetOrMakeAccount (AccountGroup *root,
+Account * xaccScrubUtilityGetOrMakeAccount (Account *root,
gnc_commodity * currency, const char *name_root);
Modified: gnucash/branches/remove-group2/src/engine/Split.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Split.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Split.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -36,7 +36,6 @@
#include "Split.h"
#include "AccountP.h"
-#include "Group.h"
#include "Scrub.h"
#include "Scrub3.h"
#include "TransactionP.h"
Modified: gnucash/branches/remove-group2/src/engine/TransLog.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/TransLog.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/TransLog.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,7 +29,6 @@
#include <string.h>
#include "Account.h"
-#include "AccountP.h"
#include "Transaction.h"
#include "TransactionP.h"
#include "TransLog.h"
Modified: gnucash/branches/remove-group2/src/engine/Transaction.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/Transaction.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Transaction.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -35,7 +35,6 @@
#include <unistd.h>
#include "AccountP.h"
-#include "Group.h"
#include "Scrub.h"
#include "Scrub3.h"
#include "TransactionP.h"
@@ -1665,50 +1664,14 @@
gnc_book_count_transactions(QofBook *book)
{
guint count = 0;
- xaccGroupForEachTransaction(xaccGetAccountGroup(book),
+ xaccAccountTreeForEachTransaction(gnc_book_get_root_account(book),
counter_thunk, (void*)&count);
return count;
}
/********************************************************************\
\********************************************************************/
-/* walk through the splits, looking for any account */
-static Account *
-get_any_account(const Transaction *trans)
-{
- GList *node;
- if (!trans) return NULL;
- for (node = trans->splits; node; node = node->next)
- if (((Split *)node->data)->acc)
- return ((Split *)node->data)->acc;
- return NULL;
-}
-Account *
-xaccGetAccountByName (const Transaction *trans, const char * name)
-{
- Account *acc;
- if (!trans || !name) return NULL;
- acc = get_any_account(trans);
- return acc ? xaccGetPeerAccountFromName (acc, name) : NULL;
-}
-
-/********************************************************************\
-\********************************************************************/
-
-Account *
-xaccGetAccountByFullName (const Transaction *trans, const char * name)
-{
- Account *acc;
- if (!trans || !name) return NULL;
-
- acc = get_any_account(trans);
- return acc ? xaccGetPeerAccountFromFullName (acc, name) : NULL;
-}
-
-/********************************************************************\
-\********************************************************************/
-
void
xaccTransVoid(Transaction *trans, const char *reason)
{
Modified: gnucash/branches/remove-group2/src/engine/Transaction.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/Transaction.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/Transaction.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -452,16 +452,6 @@
\********************************************************************/
-/** The xaccGetAccountByName() is a convenience routine that
- * is essentially identical to xaccGetPeerAccountFromName(),
- * except that it accepts the handy transaction as root.*/
-Account * xaccGetAccountByName (const Transaction *trans, const char *name);
-/** The xaccGetAccountByFullName routine is similar to xaccGetAccountByName, but uses
- * full names using the given separator.*/
-Account * xaccGetAccountByFullName (const Transaction *trans,
- const char *name);
-
-
/** @name Transaction voiding
@{
*/
Modified: gnucash/branches/remove-group2/src/engine/cap-gains.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/cap-gains.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/cap-gains.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -58,10 +58,7 @@
#include <glib.h>
#include <glib/gi18n.h>
-#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "Scrub2.h"
#include "Scrub3.h"
#include "Transaction.h"
@@ -221,7 +218,7 @@
/* Similar to GetOrMakeAccount, but different in important ways */
static Account *
-GetOrMakeLotOrphanAccount (AccountGroup *root, gnc_commodity * currency)
+GetOrMakeLotOrphanAccount (Account *root, gnc_commodity * currency)
{
char * accname;
Account * acc;
@@ -239,12 +236,12 @@
gnc_commodity_get_mnemonic (currency), NULL);
/* See if we've got one of these going already ... */
- acc = xaccGetAccountFromName (root, accname);
+ acc = gnc_account_lookup_by_name(root, accname);
if (acc == NULL)
{
/* Guess not. We'll have to build one. */
- acc = xaccMallocAccount (root->book);
+ acc = xaccMallocAccount (gnc_account_get_book(root));
xaccAccountBeginEdit (acc);
xaccAccountSetName (acc, accname);
xaccAccountSetCommodity (acc, currency);
@@ -256,7 +253,7 @@
"that haven't been recorded elsewhere."));
/* Hang the account off the root. */
- xaccGroupInsertAccount (root, acc);
+ gnc_account_append_child (root, acc);
xaccAccountCommitEdit (acc);
}
@@ -344,10 +341,10 @@
* for this account, then create such a place */
if (NULL == gain_acct)
{
- AccountGroup *root;
+ Account *root;
xaccAccountBeginEdit (acc);
- root = xaccAccountGetRoot(acc);
+ root = gnc_account_get_root(acc);
gain_acct = GetOrMakeLotOrphanAccount (root, currency);
vvv = kvp_value_new_guid (xaccAccountGetGUID (gain_acct));
Modified: gnucash/branches/remove-group2/src/engine/cashobjects.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/cashobjects.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/cashobjects.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -27,7 +27,6 @@
#include "cashobjects.h"
#include "gnc-engine.h"
#include "AccountP.h"
-#include "GroupP.h"
#include "TransactionP.h"
#include "FreqSpec.h"
#include "SchedXaction.h"
@@ -43,7 +42,6 @@
g_return_val_if_fail(xaccAccountRegister(), FALSE);
g_return_val_if_fail ( xaccTransRegister(), FALSE);
g_return_val_if_fail ( xaccSplitRegister(), FALSE);
- g_return_val_if_fail ( xaccGroupRegister(), FALSE);
g_return_val_if_fail ( FreqSpecRegister(), FALSE);
g_return_val_if_fail ( SXRegister (), FALSE);
g_return_val_if_fail ( gnc_sxtt_register(), FALSE);
Modified: gnucash/branches/remove-group2/src/engine/engine-helpers.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/engine-helpers.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/engine-helpers.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,7 +29,6 @@
#include <string.h>
#include "Account.h"
-#include "Group.h"
#include "engine-helpers.h"
#include "glib-helpers.h"
#include "gnc-date.h"
Modified: gnucash/branches/remove-group2/src/engine/engine-utilities.scm
===================================================================
--- gnucash/branches/remove-group2/src/engine/engine-utilities.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/engine-utilities.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -21,10 +21,10 @@
;; Copyright 2000 Rob Browning <rlb at cs.utexas.edu>
-(define (gnc:group-map-all-accounts thunk group)
- (let ((accounts (or (xaccGroupGetSubAccountsSorted group) '())))
- (map thunk accounts)))
+(define (gnc:account-map-descendants thunk account)
+ (let ((descendants (or (gnc-account-get-descendants account) '())))
+ (map thunk descendants)))
-(define (gnc:group-map-accounts thunk group)
- (let ((accounts (or (xaccGroupGetAccountListSorted group) '())))
- (map thunk accounts)))
+(define (gnc:account-map-children thunk account)
+ (let ((children (or (gnc-account-get-children account) '())))
+ (map thunk children)))
Modified: gnucash/branches/remove-group2/src/engine/engine.i
===================================================================
--- gnucash/branches/remove-group2/src/engine/engine.i 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/engine.i 2006-11-01 00:01:35 UTC (rev 15066)
@@ -4,7 +4,6 @@
#include <config.h>
#include <glib.h>
#include <qof.h>
-#include <Group.h>
#include <Query.h>
#include <gnc-budget.h>
#include <gnc-commodity.h>
@@ -61,9 +60,6 @@
wrapped. So, we should contract the interface to wrap only the used
functions. */
-%newobject xaccGroupGetSubAccountsSorted;
-%newobject xaccGroupGetAccountListSorted;
-
%delobject gnc_price_list_destroy;
%newobject gnc_pricedb_lookup_latest_any_currency;
@@ -96,8 +92,6 @@
QofSession * qof_session_new (void);
QofBook * qof_session_get_book (QofSession *session);
-%include <Group.h>
-
// TODO: Maybe unroll
void qof_book_kvp_changed (QofBook *book);
@@ -194,7 +188,7 @@
void gnc_hook_run (const gchar *name, gpointer data);
%include <gnc-hooks.h>
-AccountGroup * gnc_book_get_template_group(QofBook *book);
+Account * gnc_book_get_template_root(QofBook *book);
// KVP stuff
%typemap(in) KvpValue * " $1 = gnc_scm_to_kvp_value_ptr($input); "
Modified: gnucash/branches/remove-group2/src/engine/engine.scm
===================================================================
--- gnucash/branches/remove-group2/src/engine/engine.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/engine.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -42,8 +42,8 @@
(export GNC_COMMODITY_NS_MUTUAL)
(export gnc:url->loaded-session)
-(export gnc:group-map-all-accounts)
-(export gnc:group-map-accounts)
+(export gnc:account-map-descendants)
+(export gnc:account-map-children)
(export gnc:split-structure)
(export gnc:make-split-scm)
Modified: gnucash/branches/remove-group2/src/engine/gnc-associate-account.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/gnc-associate-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/gnc-associate-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -28,7 +28,6 @@
#include "config.h"
-#include "AccountP.h"
#include "gnc-associate-account.h"
#include "gnc-engine.h"
#include "qof.h"
@@ -297,7 +296,8 @@
kvpd_on_account_list = kvp_frame_get_slot(account_frame,
expense_to_key[category]);
- return de_kvp_account_list(kvpd_on_account_list, stock_account->inst.book);
+ return de_kvp_account_list(kvpd_on_account_list,
+ gnc_account_get_book(stock_account));
}
/*********************************************************************\
@@ -329,7 +329,8 @@
kvpd_on_account_list = kvp_frame_get_slot(income_acc_frame,
income_to_key[category]);
- return de_kvp_account_list(kvpd_on_account_list, stock_account->inst.book);
+ return de_kvp_account_list(kvpd_on_account_list,
+ gnc_account_get_book(stock_account));
}
/*********************************************************************\
@@ -440,7 +441,7 @@
inc_or_expense_account_guid = xaccAccountGetGUID(inc_or_expense_account);
stock_account = xaccAccountLookup
- (stock_account_guid, inc_or_expense_account->inst.book);
+ (stock_account_guid, gnc_account_get_book(inc_or_expense_account));
stock_account_kvpframe = xaccAccountGetSlots(stock_account);
Modified: gnucash/branches/remove-group2/src/engine/gnc-budget.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/gnc-budget.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/gnc-budget.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -32,7 +32,6 @@
#include "glib-compat.h"
#include "Account.h"
-#include "Group.h"
#include "gnc-budget.h"
#include "gnc-commodity.h"
@@ -290,14 +289,12 @@
static gboolean
xaccAccountChildrenHaveSameCommodity(Account *account)
{
- AccountGroup *grp;
gpointer different;
gnc_commodity *comm;
comm = xaccAccountGetCommodity(account);
- grp = xaccAccountGetChildren(account);
- different = xaccGroupForEachAccount(
- grp, is_same_commodity, comm, TRUE);
+ different =
+ gnc_account_foreach_descendant_until(account, is_same_commodity, comm);
return (different == NULL);
}
#endif
Modified: gnucash/branches/remove-group2/src/engine/gnc-engine.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/gnc-engine.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/gnc-engine.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -28,7 +28,6 @@
#include "qof.h"
#include "cashobjects.h"
#include "AccountP.h"
-#include "GroupP.h"
#include "SX-book-p.h"
#include "gnc-budget.h"
#include "TransactionP.h"
Modified: gnucash/branches/remove-group2/src/engine/gnc-engine.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/gnc-engine.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/gnc-engine.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -92,7 +92,6 @@
#define GNC_ID_COMMODITY_NAMESPACE "CommodityNamespace"
#define GNC_ID_COMMODITY_TABLE "CommodityTable"
#define GNC_ID_FREQSPEC "FreqSpec"
-#define GNC_ID_GROUP "AccountGroup"
#define GNC_ID_LOT "Lot"
#define GNC_ID_PERIOD "Period"
#define GNC_ID_PRICE "Price"
@@ -130,10 +129,6 @@
* through the functions in Account.h .*/
typedef struct account_s Account;
-/** @brief A group of accounts in Gnucash.
-*/
-typedef struct account_group_s AccountGroup;
-
/** @brief Split in Gnucash.
* A "split" is more commonly refered to as a "entry" in a
* "transaction". Each split belongs to one Account and one
Modified: gnucash/branches/remove-group2/src/engine/test/test-create-account.scm
===================================================================
--- gnucash/branches/remove-group2/src/engine/test/test-create-account.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test/test-create-account.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -9,10 +9,10 @@
(let* ((session (qof-session-new))
(book (qof-session-get-book session))
- (group (xaccMallocAccountGroup book))
+ (root (xaccMallocAccount book))
(acct (xaccMallocAccount book)))
(xaccAccountBeginEdit acct)
(xaccAccountSetName acct "foo")
(xaccAccountCommitEdit acct)
- (xaccGroupInsertAccount group acct))
+ (gnc-account-append-child root acct))
#t)
Modified: gnucash/branches/remove-group2/src/engine/test/test-group-vs-book.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/test/test-group-vs-book.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test/test-group-vs-book.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,34 +25,30 @@
#include <glib.h>
#include "qof.h"
#include "cashobjects.h"
-#include "Group.h"
-#include "GroupP.h"
+#include "Account.h"
#include "TransLog.h"
#include "gnc-engine.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
static gboolean
-group_has_book (AccountGroup *group, QofBook *book)
+account_tree_has_book (Account *parent, QofBook *book)
{
- GList *node;
+ GList *children, *node;
- if (!group)
+ if (!parent)
return (book == NULL);
- if (xaccGroupGetBook (group) != book)
+ if (gnc_account_get_book(parent) != book)
return FALSE;
- for (node = xaccGroupGetAccountList (group); node; node = node->next)
+ children = gnc_account_get_children(parent);
+ for (node = children; node; node = node->next)
{
- AccountGroup *children = xaccAccountGetChildren (node->data);
-
- if (!children)
- continue;
-
- if (!group_has_book (children, book))
+ if (!account_tree_has_book (node->data, book))
return FALSE;
}
+ g_list_free(children);
return TRUE;
}
@@ -61,8 +57,8 @@
static void
run_test (void)
{
- AccountGroup *group1;
- AccountGroup *group2;
+ Account *root1;
+ Account *root2;
Account *account1;
Account *account2;
QofBook *book;
@@ -74,16 +70,16 @@
exit(get_rv());
}
- group1 = get_random_group (book);
- if(!group1)
+ root1 = get_random_account (book);
+ if(!root1)
{
- failure("group1 not created");
+ failure("root1 not created");
exit(get_rv());
}
- if (!group_has_book (group1, book))
+ if (!account_tree_has_book (root1, book))
{
- failure("new group has wrong book");
+ failure("new root has wrong book");
exit(get_rv());
}
@@ -93,34 +89,34 @@
* interface. the maintenance of the correct
* book pointers is important for correct
* engine operation. */
- xaccSetAccountGroup (book, group1);
- if (!group_has_book (group1, book))
+ gnc_book_set_root_account (book, root1);
+ if (!account_tree_has_book (root1, book))
{
- failure("xaccSetAccountGroup didn't take");
+ failure("gnc_book_set_root_account didn't take");
exit(get_rv());
}
- group2 = get_random_group (book);
- if(!group2)
+ root2 = get_random_account (book);
+ if(!root2)
{
- failure("group2 not created");
+ failure("root2 not created");
exit(get_rv());
}
- xaccSetAccountGroup (book, group2);
+ gnc_book_set_root_account (book, root2);
#if 0
/* a group cannot have a 'null' book; this test is nonsense. */
- if (!group_has_book (group1, NULL))
+ if (!account_tree_has_book (root1, NULL))
{
- failure("xaccSetAccountGroup didn't clear old");
+ failure("gnc_book_set_root_account didn't clear old");
exit(get_rv());
}
#endif
- if (!group_has_book (group2, book))
+ if (!account_tree_has_book (root2, book))
{
- failure("xaccSetAccountGroup didn't take");
+ failure("gnc_book_set_root_account didn't take");
exit(get_rv());
}
@@ -131,8 +127,8 @@
exit(get_rv());
}
- xaccGroupInsertAccount (group2, account1);
- if (group2 != xaccAccountGetParent (account1))
+ gnc_account_append_child (root2, account1);
+ if (root2 != gnc_account_get_parent (account1))
{
failure("group insert account didn't work");
exit(get_rv());
@@ -145,15 +141,15 @@
exit(get_rv());
}
- xaccAccountInsertSubAccount (account1, account2);
- if (!group_has_book (xaccAccountGetParent (account2), book))
+ gnc_account_append_child (account1, account2);
+ if (!account_tree_has_book (gnc_account_get_parent (account2), book))
{
failure("account2 has wrong book");
exit(get_rv());
}
- xaccGroupRemoveAccount (group2, account1);
- if (xaccAccountGetParent (account1) != NULL)
+ gnc_account_remove_child (root2, account1);
+ if (gnc_account_get_parent (account1) != NULL)
{
failure("remove group didn't take");
exit(get_rv());
Modified: gnucash/branches/remove-group2/src/engine/test/test-lots.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/test/test-lots.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test/test-lots.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -30,7 +30,6 @@
#include <glib.h>
#include "qof.h"
#include "Account.h"
-#include "Group.h"
#include "Scrub3.h"
#include "cashobjects.h"
#include "test-stuff.h"
@@ -45,7 +44,7 @@
{
QofSession *sess;
QofBook *book;
- AccountGroup *grp;
+ Account *root;
/* --------------------------------------------------------- */
/* In the first test, we will merely try to see if we can run
@@ -56,8 +55,8 @@
add_random_transactions_to_book (book, transaction_num);
- grp = xaccGetAccountGroup (book);
- xaccGroupScrubLots (grp);
+ root = gnc_book_get_root_account (book);
+ xaccAccountTreeScrubLots (root);
/* --------------------------------------------------------- */
/* In the second test, we create an account with unrealized gains,
Modified: gnucash/branches/remove-group2/src/engine/test/test-period.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/test/test-period.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test/test-period.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -32,7 +32,6 @@
#include <time.h>
#include "cashobjects.h"
#include "Account.h"
-#include "Group.h"
#include "Period.h"
#include "test-stuff.h"
#include "test-engine-stuff.h"
@@ -44,9 +43,8 @@
{
QofSession *sess1, *sess2;
QofBook *openbook, *closedbook;
- AccountGroup *grp;
- AccountList *acclist, *anode;
- Account *acc, *equity;
+ GList *acclist, *anode;
+ Account *root, *acc, *equity;
SplitList *splist;
Split *sfirst, *slast;
Transaction *tfirst, *tlast;
@@ -66,9 +64,9 @@
add_random_transactions_to_book (openbook, num_trans);
- grp = xaccGetAccountGroup (openbook);
+ root = gnc_book_get_root_account (openbook);
- acclist = xaccGroupGetSubAccounts (grp);
+ acclist = gnc_account_get_descendants (root);
for (anode=acclist; anode; anode=anode->next)
{
int ns;
@@ -77,10 +75,11 @@
if (2 <= ns) break;
acc = NULL;
}
+ g_list_free(acclist);
if(!acc)
{
- failure("group didn't have accounts with enough splits");
+ failure("book didn't have accounts with enough splits");
exit(get_rv());
}
Modified: gnucash/branches/remove-group2/src/engine/test/test-query.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/test/test-query.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test/test-query.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,7 +25,6 @@
#include <glib.h>
#include "qof.h"
#include "cashobjects.h"
-#include "Group.h"
#include "Transaction.h"
#include "TransLog.h"
#include "gnc-engine.h"
@@ -70,16 +69,16 @@
run_test (void)
{
QofSession *session;
- AccountGroup *group;
+ Account *root;
QofBook *book;
session = get_random_session ();
book = qof_session_get_book (session);
- group = xaccGetAccountGroup (book);
+ root = gnc_book_get_root_account (book);
add_random_transactions_to_book (book, 20);
- xaccGroupForEachTransaction (group, test_trans_query, book);
+ xaccAccountTreeForEachTransaction (root, test_trans_query, book);
qof_session_end (session);
}
Modified: gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.c
===================================================================
--- gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,8 +29,6 @@
#include "Account.h"
#include "AccountP.h"
-#include "Group.h"
-#include "GroupP.h"
#include "gnc-engine.h"
#include "Transaction.h"
#include "TransactionP.h"
@@ -45,8 +43,8 @@
static gint kvp_max_depth = 5;
static gint kvp_frame_max_elements = 10;
-static gint max_group_depth = 1;
-static gint max_group_accounts = 3;
+static gint max_tree_depth = 1;
+static gint max_level_accounts = 3;
static gint max_total_accounts = 10;
static gint max_trans_num = 1000;
static gint total_num_accounts = 0;
@@ -69,15 +67,15 @@
/* Set control parameters governing the run. */
void
-set_max_group_depth (gint max_group_depth_in)
+set_max_account_tree_depth (gint max_tree_depth_in)
{
- max_group_depth = MAX (max_group_depth_in, 1);
+ max_tree_depth = MAX (max_tree_depth_in, 1);
}
void
-set_max_group_accounts (gint max_group_accounts_in)
+set_max_accounts_per_level (gint max_level_accounts_in)
{
- max_group_accounts = MAX (max_group_accounts_in, 1);
+ max_level_accounts = MAX (max_level_accounts_in, 1);
}
void
@@ -838,7 +836,7 @@
{
Account *sub = get_random_account (book);
- xaccAccountInsertSubAccount (account, sub);
+ gnc_account_append_child (account, sub);
total_num_accounts ++;
if (total_num_accounts > max_total_accounts) return;
@@ -848,64 +846,40 @@
}
static void
-make_random_group_depth (QofBook *book, AccountGroup *group, int depth)
+make_random_account_tree (QofBook *book, Account *root)
{
- int num_accounts;
-
- g_return_if_fail (book);
- g_return_if_fail (group);
-
- if (depth <= 0)
- return;
-
- num_accounts = get_random_int_in_range (1, max_group_accounts);
-
- while (num_accounts-- > 0)
- {
- Account *account = get_random_account (book);
-
- xaccGroupInsertAccount (group, account);
- total_num_accounts++;
-
- account_add_subaccounts (book, account, depth - 1);
- }
-}
-
-static void
-make_random_group (QofBook *book, AccountGroup *group)
-{
int depth;
g_return_if_fail (book);
- g_return_if_fail (group);
+ g_return_if_fail (root);
total_num_accounts = 0;
- depth = get_random_int_in_range (1, max_group_depth);
+ depth = get_random_int_in_range (1, max_tree_depth);
- make_random_group_depth (book, group, depth);
+ account_add_subaccounts (book, root, depth);
/* Make sure we have at least two accounts! */
if (total_num_accounts <= 1)
- make_random_group_depth (book, group, 1);
+ account_add_subaccounts (book, root, 1);
}
-AccountGroup *
-get_random_group (QofBook *book)
+Account *
+get_random_accounts (QofBook *book)
{
- AccountGroup * group;
+ Account * root;
g_return_val_if_fail (book, NULL);
- group = xaccGetAccountGroup (book);
- if (!group)
+ root = gnc_book_get_root_account (book);
+ if (!root)
{
- group = xaccMallocAccountGroup (book);
- xaccSetAccountGroup (book, group);
+ root = xaccMallocAccount (book);
+ gnc_book_set_root_account (book, root);
}
- make_random_group (book, group);
+ make_random_account_tree (book, root);
- return group;
+ return root;
}
/* ================================================================= */
@@ -1073,7 +1047,7 @@
}
void
-make_random_changes_to_group (QofBook *book, AccountGroup *group)
+make_random_changes_to_level (QofBook *book, Account *parent)
{
Account *new_account;
Account *account;
@@ -1082,24 +1056,24 @@
GList *splits;
GList *node;
- g_return_if_fail (group && book);
+ g_return_if_fail (parent && book);
- accounts = xaccGroupGetSubAccounts (group);
+ accounts = gnc_account_get_descendants (parent);
/* Add a new account */
new_account = get_random_account (book);
if (get_random_boolean () || !accounts)
- xaccGroupInsertAccount (group, new_account);
+ gnc_account_append_child (parent, new_account);
else
{
account = get_random_list_element (accounts);
- xaccAccountInsertSubAccount (account, new_account);
+ gnc_account_append_child (account, new_account);
}
g_list_free (accounts);
- accounts = xaccGroupGetSubAccounts (group);
+ accounts = gnc_account_get_descendants (parent);
/* Add some new transactions */
add_random_transactions_to_book (book, get_random_int_in_range (1, 6));
@@ -1115,7 +1089,7 @@
/* Mess with the transactions & splits */
transes = NULL;
- xaccGroupForEachTransaction (group, add_trans_helper, &transes);
+ xaccAccountTreeForEachTransaction (parent, add_trans_helper, &transes);
for (node = transes; node; node = node->next)
{
@@ -1161,7 +1135,7 @@
g_list_free (splits);
g_list_free (accounts);
- accounts = xaccGroupGetSubAccounts (group);
+ accounts = gnc_account_get_descendants (parent);
/* move some accounts around */
if (accounts && (g_list_length (accounts) > 1))
@@ -1181,7 +1155,7 @@
if (!a2)
{
- xaccGroupInsertAccount (group, a1);
+ gnc_account_append_child (parent, a1);
continue;
}
@@ -1193,7 +1167,7 @@
continue;
}
- xaccAccountInsertSubAccount (a2, a1);
+ gnc_account_append_child (a2, a1);
}
}
@@ -1203,8 +1177,7 @@
Account*
get_random_account(QofBook *book)
{
- AccountGroup *grp;
- Account *ret;
+ Account *root, *ret;
int tmp_int;
ret = xaccMallocAccount(book);
@@ -1224,13 +1197,13 @@
xaccAccountSetSlots_nc(ret, get_random_kvp_frame());
- grp = xaccGetAccountGroup (book);
- if (!grp)
+ root = gnc_book_get_root_account (book);
+ if (!root)
{
- grp = xaccMallocAccountGroup (book);
- xaccSetAccountGroup (book, grp);
+ root = xaccMallocAccount (book);
+ gnc_book_set_root_account (book, root);
}
- xaccGroupInsertAccount (grp, ret);
+ gnc_account_append_child (root, ret);
xaccAccountCommitEdit(ret);
return ret;
@@ -1430,7 +1403,7 @@
numstr = g_new0(gchar, 10);
if (!account_list)
{
- account_list = xaccGroupGetSubAccounts (xaccGetAccountGroup (book));
+ account_list = gnc_account_get_descendants (gnc_book_get_root_account (book));
}
/* Gotta have at least two different accounts */
@@ -1878,7 +1851,7 @@
book = qof_book_new ();
- get_random_group (book);
+ get_random_accounts (book);
get_random_pricedb (book);
return book;
@@ -1894,7 +1867,7 @@
book = qof_session_get_book (session);
- get_random_group (book);
+ get_random_accounts (book);
get_random_pricedb (book);
return session;
@@ -1910,7 +1883,7 @@
g_return_if_fail (book);
- accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup (book));
+ accounts = gnc_account_get_descendants (gnc_book_get_root_account (book));
g_return_if_fail (accounts);
table = gnc_commodity_table_get_table (book);
@@ -1931,7 +1904,7 @@
{
g_return_if_fail (book);
- make_random_changes_to_group (book, xaccGetAccountGroup (book));
+ make_random_changes_to_level (book, gnc_book_get_root_account (book));
make_random_changes_to_pricedb (book, gnc_pricedb_get_db (book));
#if 0
Modified: gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.h
===================================================================
--- gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/engine/test-core/test-engine-stuff.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -35,13 +35,13 @@
void kvp_exclude_type (KvpValueType kvp_type);
void set_max_kvp_depth (gint max_kvp_depth);
void set_max_kvp_frame_elements (gint max_kvp_frame_elements);
-void set_max_group_depth (gint max_group_depth);
-void set_max_group_accounts (gint max_group_accounts);
+void set_max_account_tree_depth (gint max_tree_depth);
+void set_max_accounts_per_level (gint max_accounts);
GNCPrice * get_random_price(QofBook *book);
gboolean make_random_pricedb (QofBook *book, GNCPriceDB *pdb);
GNCPriceDB * get_random_pricedb(QofBook *book);
-AccountGroup * get_random_group(QofBook * book);
+Account * get_random_accounts(QofBook * book);
Account* get_random_account(QofBook * book);
Split* get_random_split(QofBook *book, Account *account, Transaction *trn);
Transaction* get_random_transaction(QofBook *book);
@@ -84,7 +84,7 @@
Transaction *trans,
GList *accounts);
void make_random_changes_to_account (QofBook *book, Account *account);
-void make_random_changes_to_group (QofBook *book, AccountGroup *group);
+void make_random_changes_to_level (QofBook *book, Account *parent);
void make_random_changes_to_book (QofBook *book);
void make_random_changes_to_session (QofSession *session);
Modified: gnucash/branches/remove-group2/src/experimental/cgi-bin/gnc-server.c
===================================================================
--- gnucash/branches/remove-group2/src/experimental/cgi-bin/gnc-server.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/experimental/cgi-bin/gnc-server.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -17,7 +17,6 @@
#include "gnc-book.h"
#include "gnc-engine.h"
-#include "Group.h"
#include "io-gncxml.h"
#include <fcgi_stdio.h>
@@ -213,7 +212,7 @@
int err, fake_argc =1;
char * fake_argv[] = {"hello", 0};
GNCBook *book;
- AccountGroup *grp;
+ Account *root;
char *request_bufp, *reply_bufp;
int rc, sz;
@@ -230,8 +229,8 @@
rc = gnc_book_load (book);
if (!rc) goto bookerrexit;
- /* the grp pointer points to our local cache of the data */
- grp = gnc_book_get_group (book);
+ /* the root pointer points to our local cache of the data */
+ root = gnc_book_get_root_account (book);
/* --------------------------------------------------- */
/* done with initialization, go into event loop */
@@ -326,7 +325,7 @@
* in, send them the full set of accounts.
* (Do not send them any transactions yet).
*/
- gncxml_write_group_to_buf(grp, &reply_bufp, &sz);
+ gncxml_write_group_to_buf(root, &reply_bufp, &sz);
/* send the xml to the client */
printf ("%s", reply_bufp);
@@ -345,7 +344,7 @@
/* conver the xml input into a gnucash query structure... */
q = gncxml_read_query (request_bufp, read_len);
- xaccQuerySetGroup (q, grp);
+ xaccQuerySetGroup (q, root);
/* hack -- limit to 30 splits ... */
xaccQuerySetMaxSplits (q, 30);
Modified: gnucash/branches/remove-group2/src/experimental/cgi-bin/hello2.c
===================================================================
--- gnucash/branches/remove-group2/src/experimental/cgi-bin/hello2.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/experimental/cgi-bin/hello2.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -12,7 +12,6 @@
#include "gnc-book.h"
#include "gnc-engine.h"
-#include "Group.h"
#include "io-gncxml.h"
#include "Query.h"
@@ -22,7 +21,7 @@
int fake_argc =1;
char * fake_argv[] = {"hello2", 0};
GNCBook *book;
- AccountGroup *grp;
+ Account *root;
Query *q, *qq;
GList *split_list, *sl2, *node;
Split *s;
@@ -54,12 +53,12 @@
goto bookerrexit;
}
- /* the grp pointer points to our local cache of the data */
- grp = gnc_book_get_group (book);
+ /* the root pointer points to our local cache of the data */
+ root = gnc_book_get_root_account (book);
/* build a query */
q = xaccMallocQuery ();
- xaccQuerySetGroup (q, grp);
+ xaccQuerySetGroup (q, root);
xaccQuerySetMaxSplits (q, 30);
/* Get everything between some random dates */
@@ -81,7 +80,7 @@
gncxml_write_query_to_buf(q, &bufp, &sz);
qq = gncxml_read_query (bufp, sz);
xaccQuerySetMaxSplits (qq, 30);
- xaccQuerySetGroup (qq, grp);
+ xaccQuerySetGroup (qq, root);
sl2 = xaccQueryGetSplits (qq);
/* count number of splits */
Modified: gnucash/branches/remove-group2/src/experimental/cgi-bin/hello3.c
===================================================================
--- gnucash/branches/remove-group2/src/experimental/cgi-bin/hello3.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/experimental/cgi-bin/hello3.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -16,7 +16,6 @@
#include "gnc-book.h"
#include "gnc-engine.h"
-#include "Group.h"
#include "io-gncxml.h"
#include <fcgi_stdio.h>
@@ -28,7 +27,7 @@
int err, fake_argc =1;
char * fake_argv[] = {"hello", 0};
GNCBook *book;
- AccountGroup *grp;
+ Account *root;
char *bufp;
int rc, sz;
@@ -44,8 +43,8 @@
rc = gnc_book_load (book);
if (!rc) goto bookerrexit;
- /* the grp pointer points to our local cache of the data */
- grp = gnc_book_get_group (book);
+ /* the root pointer points to our local cache of the data */
+ root = gnc_book_get_root_account (book);
/* --------------------------------------------------- */
/* done with initialization, go into event loop */
@@ -65,7 +64,7 @@
* but not the transactions/splits. */
if (!strcmp ("GET", request_method))
{
- gncxml_write_group_to_buf(grp, &bufp, &sz);
+ gncxml_write_group_to_buf(root, &bufp, &sz);
/* print the HTTP header */
printf("Content-type: text/gnc-xml\r\n"
@@ -92,7 +91,7 @@
/* conver the xml input into a gnucash query structure... */
q = gncxml_read_query (bufp, read_len);
- xaccQuerySetGroup (q, grp);
+ xaccQuerySetGroup (q, root);
/* hack -- limit to 30 splits ... */
xaccQuerySetMaxSplits (q, 30);
Modified: gnucash/branches/remove-group2/src/gnome/dialog-commodities.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/dialog-commodities.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/dialog-commodities.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -113,7 +113,7 @@
if (commodity == NULL)
return;
- accounts = xaccGroupGetSubAccounts (xaccGetAccountGroup(cd->book));
+ accounts = gnc_account_get_descendants (gnc_book_get_root_account(cd->book));
can_delete = TRUE;
do_delete = FALSE;
Modified: gnucash/branches/remove-group2/src/gnome/dialog-find-transactions.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/dialog-find-transactions.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/dialog-find-transactions.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -141,8 +141,8 @@
/* In lieu of not "mis-using" some portion of the infrastructure by writing
* a bunch of new code, we just filter out the accounts of the template
- * transactions. While these are in a seperate AccountGroup just for this
- * reason, the query engine makes no distinction between AccountGroups.
+ * transactions. While these are in a seperate Account trees just for this
+ * reason, the query engine makes no distinction between Account trees.
* See Gnome Bug 86302.
* -- jsled
*
@@ -152,15 +152,15 @@
* key in the KVP frame of the split.
*/
{
- AccountGroup *tAG;
- AccountList *al;
+ Account *tRoot;
+ GList *al;
- tAG = gnc_book_get_template_group( gnc_get_current_book() );
- al = xaccGroupGetSubAccounts( tAG );
+ tRoot = gnc_book_get_template_root( gnc_get_current_book() );
+ al = gnc_account_get_descendants( tRoot );
xaccQueryAddAccountMatch( start_q, al, GUID_MATCH_NONE, QUERY_AND );
g_list_free (al);
al = NULL;
- tAG = NULL;
+ tRoot = NULL;
}
ftd->q = start_q; /* save this to destroy it later */
Modified: gnucash/branches/remove-group2/src/gnome/dialog-sxsincelast.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/dialog-sxsincelast.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/dialog-sxsincelast.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -56,7 +56,6 @@
#include <limits.h>
#include "Account.h"
-#include "Group.h"
#include "Query.h"
#include "QueryNew.h"
#include "SchedXaction.h"
@@ -2736,22 +2735,21 @@
GList **creation_errors)
{
createData createUD;
- AccountGroup *ag;
- Account *acct;
+ Account *root, *acct;
const char *id;
if (tci) {
g_assert(g_date_compare(gd, tci->date) == 0);
}
- ag = gnc_book_get_template_group( gnc_get_current_book () );
+ root = gnc_book_get_template_root( gnc_get_current_book () );
id = guid_to_string( xaccSchedXactionGetGUID(sx) );
- if ( !(ag && id) ) {
+ if ( !(root && id) ) {
return;
}
/* This looks strange but it's right. The account is
named after the guid string. */
- acct = xaccGetAccountFromName( ag, id );
+ acct = gnc_account_lookup_by_name( root, id );
if (!acct) {
return;
}
@@ -2864,14 +2862,13 @@
void
sxsl_get_sx_vars( SchedXaction *sx, GHashTable *var_hash )
{
- AccountGroup *ag;
- Account *acct;
+ Account *root, *acct;
const char *id;
- ag = gnc_book_get_template_group( gnc_get_current_book () );
+ root = gnc_book_get_template_root( gnc_get_current_book () );
id = guid_to_string( xaccSchedXactionGetGUID(sx) );
/* Get account named after guid string. */
- acct = xaccGetAccountFromName( ag, id );
+ acct = gnc_account_lookup_by_name( root, id );
xaccAccountForEachTransaction(acct,
_get_vars_helper,
var_hash);
@@ -2972,17 +2969,16 @@
/* Setup the query for the to-create register to only show the
* transaction[s] associated with this lineitem. */
{
- AccountGroup *ag;
- Account *acct;
+ Account *root, *acct;
Query *q;
const gchar *sxGUIDstr;
SplitRegister *sr;
q = xaccMallocQuery();
xaccQuerySetBook( q, gnc_get_current_book() );
- ag = gnc_book_get_template_group( gnc_get_current_book() );
+ root = gnc_book_get_template_root( gnc_get_current_book() );
sxGUIDstr = guid_to_string( xaccSchedXactionGetGUID( tci->parentTCT->sx ) );
- acct = xaccGetAccountFromName( ag, sxGUIDstr );
+ acct = gnc_account_lookup_by_name( root, sxGUIDstr );
g_assert( acct != NULL );
xaccQueryAddSingleAccountMatch( q, acct, QUERY_AND );
Modified: gnucash/branches/remove-group2/src/gnome/druid-acct-period.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-acct-period.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/druid-acct-period.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,7 +29,6 @@
#include "glib-compat.h"
#include "FreqSpec.h"
-#include "Group.h"
#include "Period.h"
#include "Query.h"
#include "Scrub.h"
@@ -280,7 +279,7 @@
ntrans = get_num_xactions_before_date(currbook,
gnc_timet_get_day_end_gdate (&info->closing_date));
- nacc = xaccGroupGetNumSubAccounts (xaccGetAccountGroup (currbook));
+ nacc = gnc_account_n_descendants (gnc_book_get_root_account (currbook));
/* Display the book info */
period_text =
@@ -390,11 +389,11 @@
static void
scrub_all(void)
{
- AccountGroup *group = gnc_get_current_group ();
- xaccGroupScrubOrphans (group);
- xaccGroupScrubImbalance (group);
+ Account *root = gnc_get_current_root_account ();
+ xaccAccountTreeScrubOrphans (root);
+ xaccAccountTreeScrubImbalance (root);
// XXX: Lots are disabled
- //xaccGroupScrubLots (group);
+ // xaccAccountTreeScrubLots (root);
}
/* =============================================================== */
Modified: gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,7 +29,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include "Group.h"
#include "gnc-account-merge.h"
#include "dialog-new-user.h"
#include "dialog-utils.h"
@@ -88,7 +87,7 @@
/** Map<Account*,gnc_numeric*> **/
GHashTable *balance_hash;
- AccountGroup *our_final_group;
+ Account *our_account_tree;
QofBook *temporary;
gboolean account_list_added;
@@ -487,7 +486,7 @@
buffer = gtk_text_view_get_buffer(data->category_description);
gtk_text_buffer_set_text(buffer, gea->long_description, -1);
- tree_view = gnc_tree_view_account_new_with_group (gea->group, FALSE);
+ tree_view = gnc_tree_view_account_new_with_root (gea->root, FALSE);
/* Override the normal fixed (user settable) sizing */
column = gtk_tree_view_get_column(GTK_TREE_VIEW(tree_view), 0);
gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
@@ -549,13 +548,13 @@
************************************************************/
static void
-delete_our_final_group (hierarchy_data *data)
+delete_our_account_tree (hierarchy_data *data)
{
- if (data->our_final_group != NULL)
+ if (data->our_account_tree != NULL)
{
- xaccAccountGroupBeginEdit (data->our_final_group);
- xaccAccountGroupDestroy (data->our_final_group);
- data->our_final_group = NULL;
+ xaccAccountBeginEdit (data->our_account_tree);
+ xaccAccountDestroy (data->our_account_tree);
+ data->our_account_tree = NULL;
}
}
@@ -573,27 +572,27 @@
struct add_group_data_struct
{
- AccountGroup *to;
+ Account *to;
Account *parent;
gnc_commodity *com;
};
-static gpointer
+static void
add_groups_for_each (Account *toadd, gpointer data)
{
struct add_group_data_struct *dadata = data;
Account *foundact;
- foundact = xaccGetAccountFromName (dadata->to, xaccAccountGetName(toadd));
+ foundact = gnc_account_lookup_by_name(dadata->to, xaccAccountGetName(toadd));
if (!foundact)
{
foundact = clone_account (toadd, dadata->com);
if (dadata->to)
- xaccGroupInsertAccount (dadata->to, foundact);
+ gnc_account_append_child (dadata->to, foundact);
else if (dadata->parent)
- xaccAccountInsertSubAccount (dadata->parent, foundact);
+ gnc_account_append_child (dadata->parent, foundact);
else
{
g_warning ("add_groups_for_each: no valid parent");
@@ -601,26 +600,21 @@
}
{
- AccountGroup *addgrp = xaccAccountGetChildren (toadd);
-
- if (xaccGroupGetNumAccounts(addgrp) > 0)
+ if (gnc_account_n_children(toadd) > 0)
{
struct add_group_data_struct downdata;
- downdata.to = xaccAccountGetChildren(foundact);
+ downdata.to = foundact;
downdata.parent = foundact;
downdata.com = dadata->com;
- xaccGroupForEachAccount (addgrp, add_groups_for_each,
- &downdata, FALSE);
+ gnc_account_foreach_child (toadd, add_groups_for_each, &downdata);
}
}
-
- return NULL;
}
static void
-add_groups_to_with_random_guids (AccountGroup *into, AccountGroup *from,
+add_new_accts_with_random_guids (Account *into, Account *from,
gnc_commodity *com)
{
struct add_group_data_struct data;
@@ -628,20 +622,20 @@
data.parent = NULL;
data.com = com;
- xaccGroupForEachAccount (from, add_groups_for_each, &data, FALSE);
+ gnc_account_foreach_child (from, add_groups_for_each, &data);
}
-static AccountGroup *
-hierarchy_merge_groups (GSList *dalist, gnc_commodity *com)
+static Account *
+hierarchy_merge_accounts (GSList *dalist, gnc_commodity *com)
{
GSList *mark;
- AccountGroup *ret = xaccMallocAccountGroup (gnc_get_current_book ());
+ Account *ret = xaccMallocAccount (gnc_get_current_book ());
for (mark = dalist; mark; mark = mark->next)
{
GncExampleAccount *xea = mark->data;
- add_groups_to_with_random_guids (ret, xea->group, com);
+ add_new_accts_with_random_guids (ret, xea->root, com);
}
return ret;
@@ -712,7 +706,7 @@
string=_("zero");
} else {
GncAccountMergeDisposition disp;
- disp = determine_merge_disposition(gnc_book_get_group(gnc_get_current_book()), account);
+ disp = determine_merge_disposition(gnc_book_get_root_account(gnc_get_current_book()), account);
if (disp == GNC_ACCOUNT_MERGE_DISPOSITION_CREATE_NEW)
{
allow_value = !xaccAccountGetPlaceholder(account);
@@ -765,22 +759,22 @@
GtkTreeIter *iter,
gpointer user_data)
{
- Account *account;
+ Account *account, *root;
gboolean willbe_placeholder = FALSE;
GncAccountMergeDisposition disp;
g_return_if_fail (GTK_TREE_MODEL (model));
account = gnc_tree_view_account_get_account_from_iter (model, iter);
- disp = determine_merge_disposition(gnc_book_get_group(gnc_get_current_book()), account);
+ root = gnc_book_get_root_account(gnc_get_current_book());
+ disp = determine_merge_disposition(root, account);
switch (disp)
{
case GNC_ACCOUNT_MERGE_DISPOSITION_USE_EXISTING: {
/* find the existing account, do whatever it is. */
gchar *full_name;
Account *existing_acct;
- AccountGroup *root_group = gnc_book_get_group(gnc_get_current_book());
full_name = xaccAccountGetFullName(account);
- existing_acct = xaccGetAccountFromFullName(root_group, full_name);
+ existing_acct = gnc_account_lookup_by_full_name(root, full_name);
willbe_placeholder = xaccAccountGetPlaceholder(existing_acct);
g_free(full_name);
} break;
@@ -801,7 +795,7 @@
gpointer user_data)
{
Account *new_acct;
- AccountGroup *real_root;
+ Account *real_root;
GncAccountMergeDisposition disposition;
char *to_user = "(error; unknown condition)";
@@ -813,7 +807,7 @@
return;
}
- real_root = gnc_book_get_group(gnc_get_current_book());
+ real_root = gnc_book_get_root_account(gnc_get_current_book());
disposition = determine_merge_disposition(real_root, new_acct);
switch (disposition)
{
@@ -852,18 +846,18 @@
gtk_widget_destroy(GTK_WIDGET(data->final_account_tree));
data->final_account_tree = NULL;
}
- delete_our_final_group (data);
+ delete_our_account_tree (data);
/* Build a new account list */
actlist = get_selected_account_list (data->categories_tree);
com = gnc_currency_edit_get_currency (GNC_CURRENCY_EDIT(data->currency_selector));
- data->our_final_group = hierarchy_merge_groups (actlist, com);
+ data->our_account_tree = hierarchy_merge_accounts (actlist, com);
/* Now build a new account tree */
data->final_account_tree
- = GNC_TREE_VIEW_ACCOUNT(gnc_tree_view_account_new_with_group (data->our_final_group, FALSE));
+ = GNC_TREE_VIEW_ACCOUNT(gnc_tree_view_account_new_with_root (data->our_account_tree, FALSE));
tree_view = GTK_TREE_VIEW(data->final_account_tree);
gnc_tree_view_account_set_name_edited(data->final_account_tree,
gnc_tree_view_account_name_edited_cb);
@@ -921,7 +915,7 @@
}
// only in the case where there *are* existing accounts...
- if (xaccGroupGetNumSubAccounts(gnc_book_get_group(gnc_get_current_book())) > 0)
+ if (gnc_account_n_descendants(gnc_book_get_root_account(gnc_get_current_book())) > 0)
{
GList *renderers;
column = gnc_tree_view_add_text_column(GNC_TREE_VIEW(tree_view),
@@ -954,13 +948,13 @@
{
gnc_suspend_gui_refresh ();
delete_hierarchy_dialog (data);
- delete_our_final_group (data);
+ delete_our_account_tree (data);
gncp_new_user_finish ();
g_free(data);
gnc_resume_gui_refresh ();
}
-static gpointer
+static void
starting_balance_helper (Account *account, hierarchy_data *data)
{
gnc_numeric balance;
@@ -971,8 +965,6 @@
if (!gnc_numeric_zero_p (balance))
gnc_account_create_opening_balance (account, balance, time (NULL),
gnc_get_current_book ());
-
- return NULL;
}
void
@@ -983,11 +975,11 @@
GncHierarchyDruidFinishedCallback when_completed;
ENTER (" ");
- if (data->our_final_group)
+ if (data->our_account_tree)
{
- xaccGroupForEachAccount (data->our_final_group,
- (AccountCallback)starting_balance_helper,
- data, TRUE);
+ gnc_account_foreach_descendant (data->our_account_tree,
+ (AccountCb)starting_balance_helper,
+ data);
}
// delete before we suspend GUI events, and then muck with the model,
@@ -998,9 +990,9 @@
gnc_suspend_gui_refresh ();
- account_group_merge(gnc_get_current_group(), data->our_final_group);
+ account_trees_merge(gnc_get_current_root_account(), data->our_account_tree);
- delete_our_final_group (data);
+ delete_our_account_tree (data);
qof_book_destroy(data->temporary);
when_completed = data->when_completed;
Modified: gnucash/branches/remove-group2/src/gnome/druid-merge.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-merge.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/druid-merge.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -38,7 +38,6 @@
#include "druid-hierarchy.h"
#include "gnc-ui-util.h"
#include "Account.h"
-#include "Group.h"
GtkWidget *druid_hierarchy_window = NULL;
static GtkWidget *qsf_import_merge_window = NULL;
@@ -197,12 +196,15 @@
}
}
+/* If the account has no parent, shove it into the top level under the root. */
void reference_parent_cb ( QofEntity* ent, gpointer user_data)
{
+ Account *root;
+
if(!ent) return;
- if(xaccAccountGetParent((Account*)ent) == NULL) {
- xaccGroupInsertAccount(xaccGroupGetRoot(
- xaccGetAccountGroup(targetBook)), (Account*)ent);
+ if(gnc_account_get_parent((Account*)ent) == NULL) {
+ root = gnc_book_get_root_account(targetBook);
+ gnc_account_append_child(root, (Account*)ent);
}
}
Modified: gnucash/branches/remove-group2/src/gnome/druid-merge.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-merge.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/druid-merge.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -81,7 +81,7 @@
/** \brief gncCommodity is not QOF enabled, need to set a default commodity before the merge */
void currency_transfer_cb ( QofEntity* ent, gpointer user_data);
-/** \brief workaround for AccountGroup not being fully QOF enabled. */
+/** \brief workaround for AccountGroup not being fully QOF enabled. Eh? */
void reference_parent_cb ( QofEntity* ent, gpointer user_data);
/** @} */
Modified: gnucash/branches/remove-group2/src/gnome/druid-stock-split.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-stock-split.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/druid-stock-split.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -27,7 +27,6 @@
#include <gnome.h>
#include <glib/gi18n.h>
-#include "Group.h"
#include "Transaction.h"
#include "dialog-utils.h"
#include "druid-stock-split.h"
@@ -132,7 +131,7 @@
gtk_list_store_clear (list);
- accounts = xaccGroupGetSubAccountsSorted (gnc_get_current_group ());
+ accounts = gnc_account_get_descendants_sorted (gnc_get_current_root_account ());
for (node = accounts; node; node = node->next)
{
Account *account = node->data;
@@ -226,7 +225,7 @@
xaccAccountGetCommoditySCU (account));
commodity = xaccAccountGetCommodity (account);
- book = xaccAccountGetBook (account);
+ book = gnc_account_get_book (account);
db = gnc_book_get_pricedb(book);
prices = gnc_pricedb_lookup_latest_any_currency(db, commodity);
Modified: gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-account-tree.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-account-tree.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-account-tree.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -670,7 +670,7 @@
account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT(view));
sensitive = (account != NULL);
- subaccounts = (xaccAccountGetChildren(account) != NULL);
+ subaccounts = (gnc_account_n_children(account) != 0);
/* Check here for placeholder accounts, etc. */
}
@@ -694,7 +694,7 @@
{
Account *account = gnc_plugin_page_account_tree_get_current_account (page);
- gnc_ui_new_account_window_with_default (NULL, account);
+ gnc_ui_new_account_window (gnc_get_current_book(), account);
}
static void
@@ -848,7 +848,6 @@
Account *account = gnc_plugin_page_account_tree_get_current_account (page);
gchar *acct_name;
GList *splits;
- AccountGroup *children;
delete_helper_t delete_res = { FALSE, FALSE };
GtkWidget *widget;
GtkWidget *window;
@@ -871,13 +870,12 @@
}
splits = xaccAccountGetSplitList(account);
- children = xaccAccountGetChildren(account);
/*
* If the account has transactions or child accounts then conduct a
* dialog to allow the user to specify what should be done with them.
*/
- if ((NULL != splits) || (NULL != children)) {
+ if ((NULL != splits) || (gnc_account_n_children(account) > 0)) {
GList *filter;
GladeXML *xml;
GtkWidget *label;
@@ -926,12 +924,12 @@
/*
* Adjust the dialog based on whether the account has children.
*/
- if (children != NULL) {
+ if (gnc_account_n_children(account) > 0) {
/*
* Check for RO txns in descendants
*/
- xaccGroupForEachAccount(children, delete_account_helper,
- &delete_res, TRUE);
+ gnc_account_foreach_descendant_until(account, delete_account_helper,
+ &delete_res);
if (delete_res.has_ro_splits) {
gtk_widget_destroy(glade_xml_get_widget (xml, "sa_trans_rw"));
widget = glade_xml_get_widget (xml, "dtdrb");
@@ -999,7 +997,7 @@
lines[++i] = g_strdup_printf("%s", format);
}
}
- if (children) {
+ if (gnc_account_n_children(account) > 0) {
if (daa) {
name = xaccAccountGetFullName(daa);
format = _("All of its sub-accounts will be moved to "
@@ -1048,17 +1046,16 @@
GList *acct_list, *ptr;
xaccAccountBeginEdit (daa);
- acct_list = g_list_copy(xaccGroupGetAccountList(children));
+ acct_list = gnc_account_get_children(account);
for (ptr = acct_list; ptr; ptr = g_list_next(ptr))
- xaccAccountInsertSubAccount (daa, ptr->data);
+ gnc_account_append_child (daa, ptr->data);
g_list_free(acct_list);
xaccAccountCommitEdit (daa);
} else if (NULL != dta) {
/* Move the splits of its subaccounts, if any. */
- xaccGroupForEachAccount (children,
- (gpointer (*)(Account *, gpointer))
- xaccAccountMoveAllSplits,
- dta, TRUE);
+ gnc_account_foreach_descendant(account,
+ (AccountCb)xaccAccountMoveAllSplits,
+ dta);
}
if (NULL != ta) {
/* Move the splits of the account to be deleted. */
@@ -1195,15 +1192,14 @@
static void
gnc_plugin_page_account_tree_cmd_scrub_all (GtkAction *action, GncPluginPageAccountTree *page)
{
- AccountGroup *group = gnc_get_current_group ();
+ Account *root = gnc_get_current_root_account ();
gnc_suspend_gui_refresh ();
- xaccGroupScrubOrphans (group);
- xaccGroupScrubImbalance (group);
-
+ xaccAccountTreeScrubOrphans (root);
+ xaccAccountTreeScrubImbalance (root);
// XXX: Lots are disabled
- //xaccGroupScrubLots (group);
+ // xaccAccountTreeScrubLots (root);
gnc_resume_gui_refresh ();
}
Modified: gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-register.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-register.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/gnc-plugin-page-register.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -997,8 +997,8 @@
acct_name = g_key_file_get_string(key_file, group_name,
KEY_ACCOUNT_NAME, &error);
book = qof_session_get_book(gnc_get_current_session());
- account = xaccGetAccountFromFullName(xaccGetAccountGroup(book),
- acct_name);
+ account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
+ acct_name);
g_free(acct_name);
if (account == NULL) {
LEAVE("Bad account name");
@@ -2577,7 +2577,7 @@
{
GncPluginPageRegisterPrivate *priv;
Query *query;
- AccountGroup *root;
+ Account *root;
Transaction *trans;
SplitRegister *reg;
@@ -2600,7 +2600,7 @@
}
gnc_suspend_gui_refresh();
- root = gnc_get_current_group();
+ root = gnc_get_current_root_account();
xaccTransScrubOrphans(trans);
xaccTransScrubImbalance(trans, root, NULL);
gnc_resume_gui_refresh();
@@ -2613,7 +2613,7 @@
{
GncPluginPageRegisterPrivate *priv;
Query *query;
- AccountGroup *root;
+ Account *root;
Transaction *trans;
Split *split;
GList *node;
@@ -2630,7 +2630,7 @@
}
gnc_suspend_gui_refresh();
- root = gnc_get_current_group();
+ root = gnc_get_current_root_account();
for (node = xaccQueryGetSplits(query); node; node = node->next)
{
Modified: gnucash/branches/remove-group2/src/gnome/gnc-split-reg.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/gnc-split-reg.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/gnc-split-reg.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -483,7 +483,7 @@
commodity = xaccAccountGetCommodity (account);
currency = gnc_default_currency ();
- book = xaccAccountGetBook (account);
+ book = gnc_account_get_book (account);
pdb = gnc_book_get_pricedb (book);
return gnc_pricedb_lookup_latest (pdb, commodity, currency);
@@ -501,7 +501,7 @@
if (!account) return NULL;
commodity = xaccAccountGetCommodity (account);
- book = xaccAccountGetBook (account);
+ book = gnc_account_get_book (account);
pdb = gnc_book_get_pricedb (book);
price_list = gnc_pricedb_lookup_latest_any_currency (pdb, commodity);
Modified: gnucash/branches/remove-group2/src/gnome/reconcile-list.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/reconcile-list.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/reconcile-list.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -144,7 +144,7 @@
include_children = xaccAccountGetReconcileChildrenStatus(account);
if (include_children)
- accounts = xaccAccountGetDescendants(account);
+ accounts = gnc_account_get_descendants(account);
/* match the account */
accounts = g_list_prepend (accounts, account);
@@ -290,7 +290,6 @@
static void
gnc_reconcile_list_toggle_children(Account *account, GNCReconcileList *list, Split *split)
{
- AccountGroup *account_group;
GList *child_accounts, *node;
Transaction *transaction;
@@ -301,8 +300,7 @@
*
* For each of these splits toggle them all to the same state.
*/
- account_group = xaccAccountGetChildren(account);
- child_accounts = xaccGroupGetSubAccounts(account_group);
+ child_accounts = gnc_account_get_descendants(account);
child_accounts = g_list_prepend(child_accounts, account);
transaction = xaccSplitGetParent(split);
for(node = xaccTransGetSplitList(transaction); node; node = node->next)
@@ -331,6 +329,7 @@
}
gnc_reconcile_list_toggle_split(current_list, other_split);
}
+ g_list_free(child_accounts);
}
static void
Modified: gnucash/branches/remove-group2/src/gnome/top-level.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/top-level.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/top-level.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -119,8 +119,8 @@
/* href="gnc-register:account=My Bank Account" */
if (strncmp("account=", location, 8) == 0)
{
- account = xaccGetAccountFromFullName (gnc_get_current_group (),
- location + 8);
+ account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (),
+ location + 8);
}
/* href="gnc-register:guid=12345678901234567890123456789012" */
Modified: gnucash/branches/remove-group2/src/gnome/window-reconcile.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/window-reconcile.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome/window-reconcile.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1393,7 +1393,7 @@
include_children = xaccAccountGetReconcileChildrenStatus(account);
if (include_children)
- accounts = xaccAccountGetDescendants(account);
+ accounts = gnc_account_get_descendants(account);
/* match the account */
accounts = g_list_prepend (accounts, account);
Modified: gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -54,7 +54,7 @@
gboolean load_list_store;
GtkListStore *list_store;
QofBook *book;
- AccountGroup *group;
+ Account *root;
gint listener;
AccountBoolCB dont_add_cb;
gpointer dont_add_data;
@@ -105,7 +105,7 @@
/* Splat the account name into the shared quickfill object */
-static gpointer
+static void
load_shared_qf_cb (Account *account, gpointer data)
{
QFB *qfb = data;
@@ -115,11 +115,11 @@
if (qfb->dont_add_cb)
{
gboolean skip = (qfb->dont_add_cb) (account, qfb->dont_add_data);
- if (skip) return NULL;
+ if (skip) return;
}
name = xaccAccountGetFullName (account);
- if (NULL == name) return NULL;
+ if (NULL == name) return;
gnc_quickfill_insert (qfb->qf, name, QUICKFILL_ALPHA);
if (qfb->load_list_store) {
gtk_list_store_append (qfb->list_store, &iter);
@@ -129,8 +129,6 @@
-1);
}
g_free(name);
-
- return NULL;
}
static void
@@ -142,7 +140,7 @@
gnc_quickfill_purge(qfb->qf);
gtk_list_store_clear(qfb->list_store);
qfb->load_list_store = TRUE;
- xaccGroupForEachAccount (qfb->group, load_shared_qf_cb, qfb, TRUE);
+ gnc_account_foreach_descendant(qfb->root, load_shared_qf_cb, qfb);
qfb->load_list_store = FALSE;
}
@@ -151,7 +149,7 @@
* Essentially same loop as in gnc_load_xfer_cell() above.
*/
static QFB *
-build_shared_quickfill (QofBook *book, AccountGroup *group, const char * key,
+build_shared_quickfill (QofBook *book, Account *root, const char * key,
AccountBoolCB cb, gpointer data)
{
QFB *qfb;
@@ -159,7 +157,7 @@
qfb = g_new0(QFB, 1);
qfb->qf = gnc_quickfill_new ();
qfb->book = book;
- qfb->group = group;
+ qfb->root = root;
qfb->listener = 0;
qfb->dont_add_cb = cb;
qfb->dont_add_data = data;
@@ -171,7 +169,7 @@
shared_quickfill_gconf_changed,
qfb);
- xaccGroupForEachAccount (group, load_shared_qf_cb, qfb, TRUE);
+ gnc_account_foreach_descendant(root, load_shared_qf_cb, qfb);
qfb->load_list_store = FALSE;
qfb->listener =
@@ -183,36 +181,36 @@
}
QuickFill *
-gnc_get_shared_account_name_quickfill (AccountGroup *group,
+gnc_get_shared_account_name_quickfill (Account *root,
const char * key,
AccountBoolCB cb, gpointer cb_data)
{
QFB *qfb;
QofBook *book;
- book = xaccGroupGetBook (group);
+ book = gnc_account_get_book (root);
qfb = qof_book_get_data (book, key);
if (qfb) return qfb->qf;
- qfb = build_shared_quickfill (book, group, key, cb, cb_data);
+ qfb = build_shared_quickfill (book, root, key, cb, cb_data);
return qfb->qf;
}
GtkListStore *
-gnc_get_shared_account_name_list_store (AccountGroup *group,
+gnc_get_shared_account_name_list_store (Account *root,
const char * key,
AccountBoolCB cb, gpointer cb_data)
{
QFB *qfb;
QofBook *book;
- book = xaccGroupGetBook (group);
+ book = gnc_account_get_book (root);
qfb = qof_book_get_data (book, key);
if (qfb) return qfb->list_store;
- qfb = build_shared_quickfill (book, group, key, cb, cb_data);
+ qfb = build_shared_quickfill (book, root, key, cb, cb_data);
return qfb->list_store;
}
@@ -245,8 +243,8 @@
ENTER("entity %p, event type %x, user data %p, ecent data %p",
entity, event_type, user_data, event_data);
- if (xaccAccountGetRoot(account) != qfb->group) {
- LEAVE("root group mismatch");
+ if (gnc_account_get_root(account) != qfb->root) {
+ LEAVE("root account mismatch");
return;
}
@@ -262,7 +260,7 @@
/* Find the account (and all its descendants) in the model. The
* full name of all these accounts has changed. */
- data.accounts = xaccAccountGetDescendants(account);
+ data.accounts = gnc_account_get_descendants(account);
data.accounts = g_list_prepend(data.accounts, account);
gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
shared_quickfill_find_accounts, &data);
@@ -313,7 +311,7 @@
/* Remove from qf */
gnc_quickfill_purge(qfb->qf);
- xaccGroupForEachAccount (qfb->group, load_shared_qf_cb, qfb, TRUE);
+ gnc_account_foreach_descendant(qfb->root, load_shared_qf_cb, qfb);
/* Does the account exist in the model? */
data.accounts = g_list_append(NULL, account);
Modified: gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/account-quickfill.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -43,7 +43,6 @@
#include <gtk/gtk.h>
#include "Account.h"
-#include "Group.h"
#include "QuickFill.h"
typedef gboolean (*AccountBoolCB) (Account *, gpointer);
@@ -57,7 +56,7 @@
* the quickfill. The 'cb_data' is passed to the callback.
*
* The quickfill is created only once; it is then stored with
- * the QofBook that is the parent of the AccountGroup. It is
+ * the QofBook that is the parent of the root account. It is
* automatically destroyed when the QofBook is destroyed.
*
* Multiple, distinct quickfills, for different uses, are allowed.
@@ -69,12 +68,12 @@
* it). This code does not currently listen to account-destroy
* events.
*/
-QuickFill * gnc_get_shared_account_name_quickfill (AccountGroup *group,
+QuickFill * gnc_get_shared_account_name_quickfill (Account *root,
const char * key,
AccountBoolCB skip_cb,
gpointer cb_data);
GtkListStore *
-gnc_get_shared_account_name_list_store (AccountGroup *group,
+gnc_get_shared_account_name_list_store (Account *root,
const char * key,
AccountBoolCB cb, gpointer cb_data);
Modified: gnucash/branches/remove-group2/src/gnome-utils/dialog-account.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/dialog-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/dialog-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -70,13 +70,13 @@
typedef struct _AccountWindow
{
+ QofBook *book;
gboolean modal;
GtkWidget *dialog;
AccountDialogType dialog_type;
GUID account;
- Account *top_level_account; /* owned by the model */
Account *created_account;
gchar **subaccount_names;
@@ -161,7 +161,7 @@
if (!aw)
return NULL;
- return xaccAccountLookup (&aw->account, gnc_get_current_book ());
+ return xaccAccountLookup (&aw->account, aw->book);
}
static void
@@ -246,7 +246,8 @@
static gboolean
-gnc_account_create_transfer_balance (Account *account,
+gnc_account_create_transfer_balance (QofBook *book,
+ Account *account,
Account *transfer,
gnc_numeric balance,
time_t date)
@@ -263,7 +264,7 @@
xaccAccountBeginEdit (account);
xaccAccountBeginEdit (transfer);
- trans = xaccMallocTransaction (gnc_get_current_book ());
+ trans = xaccMallocTransaction (book);
xaccTransBeginEdit (trans);
@@ -271,7 +272,7 @@
xaccTransSetDateSecs (trans, date);
xaccTransSetDescription (trans, _("Opening Balance"));
- split = xaccMallocSplit (gnc_get_current_book ());
+ split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (account, split);
@@ -281,7 +282,7 @@
balance = gnc_numeric_neg (balance);
- split = xaccMallocSplit (gnc_get_current_book ());
+ split = xaccMallocSplit (book);
xaccTransAppendSplit (trans, split);
xaccAccountInsertSplit (transfer, split);
@@ -383,18 +384,11 @@
xaccAccountSetHidden (account, flag);
parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
- if (parent_account == aw->top_level_account)
- parent_account = NULL;
- if (parent_account != NULL)
- {
- xaccAccountBeginEdit (parent_account);
- if (parent_account != xaccAccountGetParentAccount (account))
- xaccAccountInsertSubAccount (parent_account, account);
- xaccAccountCommitEdit (parent_account);
- }
- else
- xaccGroupInsertAccount (gnc_get_current_group (), account);
+ if (parent_account == NULL)
+ parent_account = gnc_get_current_root_account();
+ if (parent_account != gnc_account_get_parent (account))
+ gnc_account_append_child (parent_account, account);
xaccAccountCommitEdit (account);
@@ -417,8 +411,7 @@
if (use_equity)
{
- if (!gnc_account_create_opening_balance (account, balance, date,
- gnc_get_current_book ()))
+ if (!gnc_account_create_opening_balance (account, balance, date, aw->book))
{
const char *message = _("Could not create opening balance.");
gnc_error_dialog(aw->dialog, message);
@@ -434,7 +427,7 @@
return;
}
- gnc_account_create_transfer_balance (account, transfer, balance, date);
+ gnc_account_create_transfer_balance (aw->book, account, transfer, balance, date);
}
LEAVE(" ");
}
@@ -443,14 +436,13 @@
static void
set_children_types (Account *account, GNCAccountType type)
{
- AccountGroup *children;
- GList *iter;
+ GList *children, *iter;
- children = xaccAccountGetChildren (account);
+ children = gnc_account_get_children(account);
if (children == NULL)
return;
- for (iter=xaccGroupGetAccountList (children); iter; iter=iter->next) {
+ for (iter=children; iter; iter=iter->next) {
account = iter->data;
if (type == xaccAccountGetType(account))
continue;
@@ -464,6 +456,7 @@
set_children_types (account, type);
}
+ g_list_free(children);
}
static void
@@ -505,7 +498,7 @@
gnc_suspend_gui_refresh ();
parent = aw_get_account (aw);
- account = xaccMallocAccount (gnc_get_current_book ());
+ account = xaccMallocAccount (aw->book);
aw->account = *xaccAccountGetGUID (account);
aw->type = xaccAccountGetType (parent);
@@ -551,8 +544,7 @@
if (gtk_expander_get_expanded (expander) &&
!gtk_bin_get_child (GTK_BIN (expander))) {
- view = gnc_tree_view_account_new_with_group (
- xaccAccountGetChildren (account), FALSE);
+ view = gnc_tree_view_account_new_with_root (account, FALSE);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
@@ -573,7 +565,6 @@
verify_children_compatible (AccountWindow *aw)
{
Account *account;
- AccountGroup *children;
GtkWidget *dialog, *vbox, *hbox, *label, *expander;
gchar *str;
gboolean result;
@@ -588,9 +579,7 @@
if (xaccAccountTypesCompatible (xaccAccountGetType (account), aw->type))
return TRUE;
- children = xaccAccountGetChildren (account);
- if (!children ||
- !xaccGroupGetNumAccounts (children))
+ if (gnc_account_n_children(account) == 0)
return TRUE;
dialog = gtk_dialog_new_with_buttons ("",
@@ -684,7 +673,7 @@
if (aw_account == NULL)
return FALSE;
- if (account == aw->top_level_account)
+ if (gnc_account_is_root(account))
return TRUE;
if (account == aw_account)
@@ -700,14 +689,13 @@
static gboolean
gnc_common_ok (AccountWindow *aw)
{
- Account *account, *parent;
- AccountGroup *group;
+ Account *root, *account, *parent;
gnc_commodity * commodity;
gchar *fullname, *fullname_parent;
const gchar *name, *separator;
ENTER("aw %p", aw);
- group = gnc_get_current_group ();
+ root = gnc_book_get_root_account (aw->book);
separator = gnc_get_account_separator_string();
@@ -724,12 +712,12 @@
parent = gnc_tree_view_account_get_selected_account
(GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
if (parent == NULL) {
- account = xaccGetAccountFromFullName(group, name);
+ account = gnc_account_lookup_by_full_name(root, name);
} else {
fullname_parent = xaccAccountGetFullName(parent);
fullname = g_strconcat(fullname_parent, separator, name, NULL);
- account = xaccGetAccountFromFullName(group, fullname);
+ account = gnc_account_lookup_by_full_name(root, fullname);
g_free(fullname_parent);
g_free(fullname);
@@ -759,7 +747,7 @@
}
/* check whether the types of child and parent are compatible */
- if (parent != aw->top_level_account &&
+ if (!gnc_account_is_root(parent) &&
!xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) {
const char *message = _("The selected account type is incompatible with "
"the one of the selected parent.");
@@ -945,8 +933,6 @@
gnc_unregister_gui_component (aw->component_id);
- aw->top_level_account = NULL;
-
gnc_resume_gui_refresh ();
if (aw->subaccount_names) {
@@ -976,7 +962,7 @@
if (!parent_account)
return;
- if (parent_account == aw->top_level_account) {
+ if (gnc_account_is_root(parent_account)) {
types = aw->valid_types;
} else {
types = aw->valid_types &
@@ -1232,15 +1218,12 @@
box = glade_xml_get_widget (xml, "parent_scroll");
- // group = gnc_book_get_group (gnc_get_current_book ());
aw->parent_tree = gnc_tree_view_account_new(TRUE);
gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(aw->parent_tree));
gtk_widget_show(GTK_WIDGET(aw->parent_tree));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->parent_tree));
g_signal_connect (G_OBJECT (selection), "changed",
G_CALLBACK (gnc_account_parent_changed_cb), aw);
- aw->top_level_account =
- gnc_tree_view_account_get_top_level (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
aw->tax_related_button = glade_xml_get_widget (xml, "tax_related_button");
aw->placeholder_button = glade_xml_get_widget (xml, "placeholder_button");
@@ -1302,13 +1285,9 @@
if (!name || *name == '\0')
name = _("<No name>");
- parent_account = NULL;
-
parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
- if (parent_account == aw->top_level_account)
- parent_account = NULL;
- if (parent_account)
+ if (!gnc_account_is_root(parent_account))
{
char *parent_name;
const gchar *separator;
@@ -1421,7 +1400,8 @@
static AccountWindow *
-gnc_ui_new_account_window_internal (Account *base_account,
+gnc_ui_new_account_window_internal (QofBook *book,
+ Account *base_account,
gchar **subaccount_names,
GList *valid_types,
gnc_commodity * default_commodity,
@@ -1432,16 +1412,15 @@
Account *account;
GList *list;
+ g_return_val_if_fail(book, NULL);
+
aw = g_new0 (AccountWindow, 1);
+ aw->book = book;
aw->modal = modal;
aw->dialog_type = NEW_ACCOUNT;
- aw->valid_types = 0;
- for (list = valid_types; list; list = list->next)
- aw->valid_types |= (1 << GPOINTER_TO_INT (list->data));
-
- account = xaccMallocAccount (gnc_get_current_book ());
+ account = xaccMallocAccount (book);
aw->account = *xaccAccountGetGUID (account);
if (base_account) {
@@ -1477,8 +1456,9 @@
commodity);
gnc_account_commodity_from_type (aw, FALSE);
- if (base_account == NULL)
- base_account = aw->top_level_account;
+ if (base_account == NULL) {
+ base_account = gnc_book_get_root_account(book);
+ }
gtk_tree_view_collapse_all (aw->parent_tree);
gnc_tree_view_account_set_selected_account (
@@ -1504,21 +1484,20 @@
static gchar **
-gnc_split_account_name (const char *in_name, Account **base_account)
+gnc_split_account_name (QofBook *book, const char *in_name, Account **base_account)
{
- AccountGroup *group;
- Account *account;
+ Account *root, *account;
gchar **names, **ptr, **out_names;
GList *list, *node;
- group = gnc_get_current_group ();
+ root = gnc_book_get_root_account (book);
+ list = gnc_account_get_children(root);
names = g_strsplit(in_name, gnc_get_account_separator_string(), -1);
for (ptr = names; *ptr; ptr++) {
/* Stop if there are no children at the current level. */
- if (group == NULL)
+ if (list == NULL)
break;
- list = xaccGroupGetAccountList (group);
/* Look for the first name in the children. */
for (node = list; node; node = g_list_next(node)) {
@@ -1535,11 +1514,14 @@
if (node == NULL)
break;
- group = xaccAccountGetChildren (account);
+ g_list_free(list);
+ list = gnc_account_get_children (account);
}
out_names = g_strdupv(ptr);
g_strfreev(names);
+ if (list)
+ g_list_free(list);
return out_names;
}
@@ -1567,6 +1549,7 @@
gnc_commodity * default_commodity,
Account * parent)
{
+ QofBook *book;
AccountWindow *aw;
Account *base_account = NULL;
Account *created_account = NULL;
@@ -1576,19 +1559,20 @@
ENTER("name %s, valid %p, commodity %p, account %p",
name, valid_types, default_commodity, parent);
+ book = gnc_get_current_book();
if (!name || *name == '\0')
{
subaccount_names = NULL;
base_account = NULL;
}
else
- subaccount_names = gnc_split_account_name (name, &base_account);
+ subaccount_names = gnc_split_account_name (book, name, &base_account);
if (parent != NULL)
{
base_account=parent;
}
- aw = gnc_ui_new_account_window_internal (base_account, subaccount_names,
+ aw = gnc_ui_new_account_window_internal (book, base_account, subaccount_names,
valid_types, default_commodity,
TRUE);
@@ -1659,6 +1643,7 @@
aw = g_new0 (AccountWindow, 1);
+ aw->book = gnc_account_get_book(account);
aw->modal = FALSE;
aw->dialog_type = EDIT_ACCOUNT;
aw->account = *xaccAccountGetGUID (account);
@@ -1675,9 +1660,9 @@
gtk_widget_show_all (aw->dialog);
gtk_widget_hide (aw->opening_balance_page);
- parent = xaccAccountGetParentAccount (account);
+ parent = gnc_account_get_parent (account);
if (parent == NULL)
- parent = aw->top_level_account;
+ parent = account; /* must be at the root */
gtk_tree_view_collapse_all (aw->parent_tree);
gnc_tree_view_account_set_selected_account (
@@ -1703,33 +1688,24 @@
/*
* opens up a window to create a new account
*
- * Args: group - not used
+ * Args: book - containing book for the new account
+ * parent - The initial parent for the new account (optional)
*/
void
-gnc_ui_new_account_window (AccountGroup *this_is_not_used)
+gnc_ui_new_account_window(QofBook *book, Account *parent)
{
- /* FIXME get_current_account went away. */
- gnc_ui_new_account_window_internal (NULL, NULL, NULL, NULL, FALSE);
-}
+ g_return_if_fail(book != NULL);
+ if (parent && book)
+ g_return_if_fail(gnc_account_get_book(parent) == book);
-/*
- * opens up a window to create a new account
- *
- * Args: group - not used
- * parent - The initial parent for the new account
- */
-void
-gnc_ui_new_account_window_with_default(AccountGroup *this_is_not_used,
- Account * parent)
-{
- gnc_ui_new_account_window_internal (parent, NULL, NULL, NULL, FALSE);
+ gnc_ui_new_account_window_internal (book, parent, NULL, NULL, NULL, FALSE);
}
void
-gnc_ui_new_account_with_types( AccountGroup *unused,
+gnc_ui_new_account_with_types( QofBook *book,
GList *valid_types )
{
- gnc_ui_new_account_window_internal( NULL, NULL, valid_types, NULL, FALSE );
+ gnc_ui_new_account_window_internal( book, NULL, NULL, valid_types, NULL, FALSE );
}
/************************************************************
@@ -1798,7 +1774,6 @@
gint response,
RenumberDialog *data)
{
- AccountGroup *group;
GList *children, *tmp;
gchar *str;
gchar *prefix;
@@ -1806,8 +1781,7 @@
if (response == GTK_RESPONSE_OK) {
gtk_widget_hide(data->dialog);
- group = xaccAccountGetChildren(data->parent);
- children = xaccGroupGetAccountListSorted(group);
+ children = gnc_account_get_children(data->parent);
prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
interval =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
@@ -1820,6 +1794,7 @@
g_free(str);
}
gnc_unset_busy_cursor (NULL);
+ g_list_free(children);
}
gtk_widget_destroy(data->dialog);
@@ -1831,14 +1806,12 @@
{
RenumberDialog *data;
GladeXML *xml;
- AccountGroup *children;
GtkWidget *widget;
gchar *string;
data = g_new(RenumberDialog, 1);
data->parent = account;
- children = xaccAccountGetChildren(account);
- data->num_children = xaccGroupGetNumAccounts(children);
+ data->num_children = gnc_account_n_children(account);
xml = gnc_glade_xml_new ("account.glade", "Renumber Accounts");
data->dialog = glade_xml_get_widget (xml, "Renumber Accounts");
Modified: gnucash/branches/remove-group2/src/gnome-utils/dialog-account.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/dialog-account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/dialog-account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,7 +25,6 @@
#define DIALOG_ACCOUNT_H
#include "Account.h"
-#include "Group.h"
/** @addtogroup GUI
@{ */
@@ -52,28 +51,24 @@
void gnc_ui_edit_account_window (Account *account);
-/** Disply a window for creating a new account
- *
- * @param group This parameter is not used.
- */
-void gnc_ui_new_account_window (AccountGroup *group);
-
-
/** Disply a window for creating a new account. This function will
* also initially set the parent account of the new account to what
* the caller specified. The user is free, however, to choose any
* parent account they wish.
*
- * @param group This parameter is not used.
+ * @param book The book in which the new account should be created.
+ * This is a required argument.
*
- * @param parent The initially selected parent account.
+ * @param parent The initially selected parent account. This
+ * argument is optional, but if supplied must be an account contained
+ * in the specified book.
*/
-void gnc_ui_new_account_window_with_default (AccountGroup *group,
- Account * parent);
+void gnc_ui_new_account_window (QofBook *book, Account *parent);
/** Disply a window for creating a new account. This function will
- * restrict the available account type values to the list specified by the caller.
+ * restrict the available account type values to the list specified
+ * by the caller.
*
* @param unused This parameter is not used.
*
@@ -81,7 +76,7 @@
* which are allowed to be created. The calling function is
* responsible for freeing this list.
*/
-void gnc_ui_new_account_with_types (AccountGroup *unused,
+void gnc_ui_new_account_with_types (QofBook *book,
GList *valid_types);
/** @} */
Modified: gnucash/branches/remove-group2/src/gnome-utils/dialog-transfer.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/dialog-transfer.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/dialog-transfer.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1868,7 +1868,7 @@
xferData->transaction_cb = NULL;
if (initial) {
- book = xaccAccountGetBook (initial);
+ book = gnc_account_get_book (initial);
} else {
book = gnc_get_current_book ();
}
Modified: gnucash/branches/remove-group2/src/gnome-utils/dialog-utils.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/dialog-utils.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/dialog-utils.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -37,7 +37,6 @@
#include "dialog-utils.h"
#include "gnc-commodity.h"
-#include "Group.h"
#include "gnc-path.h"
#include "gnc-engine.h"
#include "gnc-euro.h"
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-account-sel.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-account-sel.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-account-sel.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -171,7 +171,7 @@
gas_populate_list( GNCAccountSel *gas )
{
account_filter_data atnd;
- AccountGroup *ag;
+ Account *root;
Account *acc;
GtkTreeIter iter;
GtkEntry *entry;
@@ -183,8 +183,8 @@
currentSel = gtk_editable_get_chars(
GTK_EDITABLE(entry), 0, -1 );
- ag = gnc_book_get_group( gnc_get_current_book() );
- accts = (GList*)xaccGroupGetSubAccountsSorted( ag );
+ root = gnc_book_get_root_account( gnc_get_current_book() );
+ accts = gnc_account_get_descendants_sorted( root );
filteredAccts = NULL;
atnd.gas = gas;
@@ -404,7 +404,7 @@
gnc_ui_new_accounts_from_name_window_with_types ( NULL,
gas->acctTypeFilters );
else
- gnc_ui_new_account_with_types( NULL, gas->acctTypeFilters );
+ gnc_ui_new_account_with_types( gnc_get_current_book(), gas->acctTypeFilters );
}
gint
@@ -442,7 +442,7 @@
while (acc) {
if (acc == target)
break;
- acc = xaccAccountGetParentAccount(acc);
+ acc = gnc_account_get_parent(acc);
}
if (acc == target)
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-file.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-file.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -744,7 +744,7 @@
if (!uh_oh)
{
- AccountGroup *new_group;
+ Account *new_root;
char * logpath = xaccResolveFilePath(newfile);
PINFO ("logpath=%s", logpath ? logpath : "(null)");
@@ -776,12 +776,12 @@
uh_oh = show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN);
- new_group = gnc_book_get_group (qof_session_get_book (new_session));
- if (uh_oh) new_group = NULL;
+ new_root = gnc_book_get_root_account (qof_session_get_book (new_session));
+ if (uh_oh) new_root = NULL;
/* Umm, came up empty-handed, but no error:
* The backend forgot to set an error. So make one up. */
- if (!uh_oh && !new_group)
+ if (!uh_oh && !new_root)
{
uh_oh = show_session_error (ERR_BACKEND_MISC, newfile,
GNC_FILE_DIALOG_OPEN);
@@ -797,11 +797,11 @@
qof_session_destroy (new_session);
xaccLogEnable();
- /* well, no matter what, I think it's a good idea to have a
- * topgroup around. For example, early in the gnucash startup
+ /* well, no matter what, I think it's a good idea to have a root
+ * account around. For example, early in the gnucash startup
* sequence, the user opens a file; if this open fails for any
- * reason, we don't want to leave them high & dry without a
- * topgroup, because if the user continues, then bad things will
+ * reason, we don't want to leave them high & dry without a root
+ * account, because if the user continues, then bad things will
* happen. */
gnc_get_current_session ();
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-html.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-html.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-html.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -43,7 +43,6 @@
#include <gtkhtml/gtkhtml-embedded.h>
#include "Account.h"
-#include "Group.h"
#include "print-session.h"
#include "gnc-engine.h"
#include "gnc-gui-query.h"
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -32,7 +32,6 @@
#include "gnc-tree-model-account.h"
#include "gnc-component-manager.h"
#include "Account.h"
-#include "Group.h"
#include "gnc-accounting-period.h"
#include "gnc-commodity.h"
#include "gnc-gconf-utils.h"
@@ -84,10 +83,6 @@
GtkTreeIter *iter,
GtkTreeIter *child);
-/** Helper Functions ****************************************************/
-static void gnc_tree_model_account_set_toplevel (GncTreeModelAccount *model,
- Account *toplevel);
-
/** Component Manager Callback ******************************************/
static void gnc_tree_model_account_event_handler (QofEntity *entity,
QofEventId event_type,
@@ -98,8 +93,7 @@
typedef struct GncTreeModelAccountPrivate
{
QofBook *book;
- AccountGroup *root;
- Account *toplevel;
+ Account *root;
gint event_handler_id;
const gchar *negative_color;
} GncTreeModelAccountPrivate;
@@ -208,7 +202,6 @@
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
priv->book = NULL;
priv->root = NULL;
- priv->toplevel = NULL;
priv->negative_color = red ? "red" : "black";
gnc_gconf_general_register_cb(KEY_NEGATIVE_IN_RED,
@@ -275,18 +268,18 @@
/************************************************************/
GtkTreeModel *
-gnc_tree_model_account_new (AccountGroup *group)
+gnc_tree_model_account_new (Account *root)
{
GncTreeModelAccount *model;
GncTreeModelAccountPrivate *priv;
const GList *item;
- ENTER("group %p", group);
+ ENTER("root %p", root);
item = gnc_gobject_tracking_get_list(GNC_TREE_MODEL_ACCOUNT_NAME);
for ( ; item; item = g_list_next(item)) {
model = (GncTreeModelAccount *)item->data;
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (priv->root == group) {
+ if (priv->root == root) {
g_object_ref(G_OBJECT(model));
LEAVE("returning existing model %p", model);
return GTK_TREE_MODEL(model);
@@ -298,15 +291,8 @@
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
priv->book = gnc_get_current_book();
- priv->root = group;
+ priv->root = root;
- {
- Account *account;
-
- account = xaccMallocAccount(priv->book);
- gnc_tree_model_account_set_toplevel (model, account);
- }
-
priv->event_handler_id = qof_event_register_handler
((QofEventHandler)gnc_tree_model_account_event_handler, model);
@@ -441,9 +427,8 @@
{
GncTreeModelAccountPrivate *priv;
GncTreeModelAccount *model;
- Account *account = NULL;
- AccountGroup *group = NULL, *children;
- gint i = 0, *indices;
+ Account *account, *parent;
+ gint i, *indices;
{
gchar *path_string = gtk_tree_path_to_string(path);
@@ -454,55 +439,36 @@
model = GNC_TREE_MODEL_ACCOUNT (tree_model);
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (priv->toplevel != NULL) {
- if (gtk_tree_path_get_depth (path) > 1) {
- i++;
- } else {
- iter->user_data = priv->toplevel;
- iter->user_data2 = NULL;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
-
- LEAVE("iter (1) %s", iter_to_string(iter));
- return TRUE;
- }
+ if (gtk_tree_path_get_depth (path) <= 0) {
+ LEAVE("bad depth");
+ return FALSE;
}
- if (priv->root == NULL) {
- LEAVE("failed (2)");
+ indices = gtk_tree_path_get_indices (path);
+ if (indices[0] != 0) {
+ LEAVE("bad root index");
return FALSE;
}
- children = priv->root;
-
- indices = gtk_tree_path_get_indices (path);
- for (; i < gtk_tree_path_get_depth (path); i++) {
- group = children;
- if (indices[i] >= xaccGroupGetNumAccounts (group)) {
+ parent = NULL;
+ account = priv->root;
+ for (i = 1; i < gtk_tree_path_get_depth (path); i++) {
+ parent = account;
+ account = gnc_account_nth_child(parent, indices[i]);
+ if (account == NULL) {
iter->stamp = 0;
-
- LEAVE("failed (3)");
+ LEAVE("bad index");
return FALSE;
}
-
- account = xaccGroupGetAccount (group, indices[i]);
- children = xaccAccountGetChildren (account);
}
- if (account == NULL || group == NULL) {
- iter->stamp = 0;
-
- LEAVE("failed (4)");
- return FALSE;
- }
-
iter->stamp = model->stamp;
iter->user_data = account;
- iter->user_data2 = group;
+ iter->user_data2 = parent;
iter->user_data3 = GINT_TO_POINTER (indices[i - 1]);
- LEAVE("iter (5) %s", iter_to_string(iter));
+ LEAVE("iter %s", iter_to_string(iter));
return TRUE;
}
@@ -512,11 +478,9 @@
{
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT (tree_model);
GncTreeModelAccountPrivate *priv;
- Account *account;
- AccountGroup *group;
+ Account *account, *parent;
GtkTreePath *path;
gint i;
- gboolean found, finished = FALSE;
ENTER("model %p, iter %s", model, iter_to_string(iter));
g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), NULL);
@@ -531,50 +495,24 @@
}
account = (Account *) iter->user_data;
- group = (AccountGroup *) iter->user_data2;
+ parent = (Account *) iter->user_data2;
path = gtk_tree_path_new ();
-
- if (priv->toplevel != NULL) {
- if (account == priv->toplevel) {
- gtk_tree_path_append_index (path, 0);
-
- {
- gchar *path_string = gtk_tree_path_to_string(path);
- LEAVE("path (2) %s", path_string);
- g_free(path_string);
- }
- return path;
- }
- }
-
- do {
- found = FALSE;
- for (i = 0; i < xaccGroupGetNumAccounts (group); i++) {
- if (xaccGroupGetAccount (group, i) == account) {
- found = TRUE;
- if (group == priv->root)
- finished = TRUE;
- break;
- }
- }
-
- if (!found) {
+ while (parent) {
+ i = gnc_account_child_index(parent, account);
+ if (i == -1) {
gtk_tree_path_free (path);
LEAVE("failed (3)");
return NULL;
}
-
gtk_tree_path_prepend_index (path, i);
+ account = parent;
+ parent = gnc_account_get_parent(account);
+ };
- account = xaccAccountGetParentAccount (account);
- group = xaccAccountGetParent (account);
- } while (!finished);
+ /* Add the root node. */
+ gtk_tree_path_prepend_index (path, 0);
- if (priv->toplevel != NULL) {
- gtk_tree_path_prepend_index (path, 0);
- }
-
{
gchar *path_string = gtk_tree_path_to_string(path);
LEAVE("path (4) %s", path_string);
@@ -608,7 +546,7 @@
gnc_numeric b3;
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (acct == priv->toplevel)
+ if (acct == priv->root)
return g_strdup("");
t1 = gnc_accounting_period_fiscal_start();
@@ -652,7 +590,7 @@
switch (column) {
case GNC_TREE_MODEL_ACCOUNT_COL_NAME:
g_value_init (value, G_TYPE_STRING);
- if (account == priv->toplevel)
+ if (account == priv->root)
g_value_set_string (value, _("New top level account"));
else
g_value_set_string (value, xaccAccountGetName (account));
@@ -850,8 +788,7 @@
{
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT (tree_model);
GncTreeModelAccountPrivate *priv;
- Account *account;
- AccountGroup *group;
+ Account *account, *parent;
gint i;
ENTER("model %p, iter %s", tree_model, iter_to_string(iter));
@@ -861,23 +798,17 @@
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (iter->user_data == priv->toplevel) {
- iter->stamp = 0;
- LEAVE("failed (1)");
- return FALSE;
- }
- group = (AccountGroup *) iter->user_data2;
- i = GPOINTER_TO_INT (iter->user_data3);
-
- if (i > xaccGroupGetNumAccounts (group) - 2) {
- iter->stamp = 0;
- LEAVE("failed (2)");
- return FALSE;
+ parent = (Account *) iter->user_data2;
+ if (parent == NULL) {
+ /* This is the root. There is no next. */
+ LEAVE("at root");
+ return FALSE;
}
- account = xaccGroupGetAccount (group, i + 1);
-
+ /* Get the *next* sibling account. */
+ i = GPOINTER_TO_INT (iter->user_data3);
+ account = gnc_account_nth_child (parent, i + 1);
if (account == NULL) {
iter->stamp = 0;
LEAVE("failed (3)");
@@ -885,7 +816,7 @@
}
iter->user_data = account;
- iter->user_data2 = group;
+ iter->user_data2 = parent;
iter->user_data3 = GINT_TO_POINTER (i + 1);
LEAVE("iter %s", iter_to_string(iter));
@@ -895,84 +826,51 @@
static gboolean
gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
- GtkTreeIter *parent)
+ GtkTreeIter *parent_iter)
{
GncTreeModelAccountPrivate *priv;
GncTreeModelAccount *model;
- Account *account;
- AccountGroup *group;
+ Account *account, *parent;
- if (parent) {
- ENTER("model %p, iter %p (to be filed in), parent %s",
- tree_model, iter, iter_to_string(parent));
+ if (parent_iter) {
+ ENTER("model %p, iter %p (to be filed in), parent_iter %s",
+ tree_model, iter, iter_to_string(parent_iter));
} else {
- ENTER("model %p, iter %p (to be filed in), parent (null)", tree_model, iter);
+ ENTER("model %p, iter %p (to be filed in), parent_iter (null)", tree_model, iter);
}
g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE);
model = GNC_TREE_MODEL_ACCOUNT (tree_model);
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (priv->toplevel != NULL) {
- if (parent == NULL) {
- iter->user_data = priv->toplevel;
- iter->user_data2 = NULL;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
- LEAVE("iter (1) %s", iter_to_string(iter));
- return TRUE;
- } else if (parent->user_data == priv->toplevel) {
- parent = NULL;
- }
- }
-
- if (priv->root == NULL ||
- xaccGroupGetNumAccounts (priv->root) == 0) {
+ if (priv->root == NULL) {
iter->stamp = 0;
- LEAVE("failed (either no group or group has no accounts)");
+ LEAVE("failed (no root)");
return FALSE;
}
- if (parent == NULL) {
- account = xaccGroupGetAccount (priv->root, 0);
-
- if (account == NULL) {
- iter->stamp = 0;
- LEAVE("failed (couldn't get account from group)");
- return FALSE;
- }
-
- iter->user_data = account;
- iter->user_data2 = priv->root;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
- LEAVE("iter (2) %s", iter_to_string(iter));
- return TRUE;
+ /* Special case when no parent supplied. */
+ if (!parent_iter) {
+ iter->user_data = priv->root;
+ iter->user_data2 = NULL;
+ iter->user_data3 = GINT_TO_POINTER (0);
+ iter->stamp = model->stamp;
+ LEAVE("iter (3) %s", iter_to_string(iter));
+ return TRUE;
}
- g_return_val_if_fail (parent != NULL, FALSE);
- g_return_val_if_fail (parent->user_data != NULL, FALSE);
- g_return_val_if_fail (parent->stamp == model->stamp, FALSE);
-
- group = xaccAccountGetChildren ((Account *) parent->user_data);
-
- if (group == NULL || xaccGroupGetNumAccounts (group) == 0) {
- iter->stamp = 0;
- LEAVE("failed (children group was %s)",
- group ? "empty" : "null");
- return FALSE;
- }
-
- account = xaccGroupGetAccount (group, 0);
-
+ g_return_val_if_fail (parent_iter->user_data != NULL, FALSE);
+ g_return_val_if_fail (parent_iter->stamp == model->stamp, FALSE);
+ parent = (Account *)parent_iter->user_data;
+ account = gnc_account_nth_child (parent, 0);
if (account == NULL) {
iter->stamp = 0;
- LEAVE("failed (group's account is null)");
+ LEAVE("failed (child account is null)");
return FALSE;
}
iter->user_data = account;
- iter->user_data2 = group;
+ iter->user_data2 = parent;
iter->user_data3 = GINT_TO_POINTER (0);
iter->stamp = model->stamp;
LEAVE("iter (3) %s", iter_to_string(iter));
@@ -985,7 +883,7 @@
{
GncTreeModelAccount *model;
GncTreeModelAccountPrivate *priv;
- AccountGroup *group;
+ Account *account;
ENTER("model %p, iter %s", tree_model, iter_to_string(iter));
g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE);
@@ -997,19 +895,14 @@
g_return_val_if_fail (iter->user_data != NULL, FALSE);
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
- if (iter->user_data == priv->toplevel) {
- group = priv->root;
- } else {
- group = xaccAccountGetChildren ((Account *) iter->user_data);
+ account = (Account *) iter->user_data;
+ if (gnc_account_n_children(account) > 0) {
+ LEAVE("yes");
+ return TRUE;
}
- if (group == NULL || xaccGroupGetNumAccounts (group) == 0) {
- LEAVE("no");
- return FALSE;
- }
-
- LEAVE("yes");
- return TRUE;
+ LEAVE("no");
+ return FALSE;
}
static int
@@ -1018,7 +911,7 @@
{
GncTreeModelAccount *model;
GncTreeModelAccountPrivate *priv;
- AccountGroup *group;
+ gint num;
ENTER("model %p, iter %s", tree_model, iter_to_string(iter));
g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE);
@@ -1027,50 +920,41 @@
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
if (iter == NULL) {
- if (priv->toplevel != NULL) {
- LEAVE("count is 1");
- return 1;
- } else {
- LEAVE("count is %d", xaccGroupGetNumAccounts (priv->root));
- return xaccGroupGetNumAccounts (priv->root);
- }
+ /* How many children does the invisible root node
+ * have. One! Its the real root account node. */
+ LEAVE("count is 1");
+ return 1;
}
g_return_val_if_fail (iter != NULL, FALSE);
g_return_val_if_fail (iter->user_data != NULL, FALSE);
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
- if (priv->toplevel == iter->user_data) {
- group = priv->root;
- } else {
- group = xaccAccountGetChildren ((Account *) iter->user_data);
- }
-
- LEAVE("count is %d", xaccGroupGetNumAccounts (group));
- return xaccGroupGetNumAccounts (group);
+ num = gnc_account_n_children(iter->user_data);
+ LEAVE("count is %d", num);
+ return num;
}
static gboolean
gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
- GtkTreeIter *parent,
+ GtkTreeIter *parent_iter,
int n)
{
GncTreeModelAccount *model;
GncTreeModelAccountPrivate *priv;
- Account *account;
- AccountGroup *group;
+ Account *account, *parent;
- if (parent) {
+ if (parent_iter) {
gchar *parent_string;
- parent_string = strdup(iter_to_string(parent));
- ENTER("model %p, iter %s, parent %s, n %d",
+ parent_string = strdup(iter_to_string(parent_iter));
+ ENTER("model %p, iter %s, parent_iter %s, n %d",
tree_model, iter_to_string(iter),
parent_string, n);
g_free(parent_string);
} else {
- ENTER("model %p, iter %s, parent (null), n %d",
+ ENTER("model %p, iter %s, parent_iter (null), n %d",
tree_model, iter_to_string(iter), n);
}
g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE);
@@ -1078,66 +962,37 @@
model = GNC_TREE_MODEL_ACCOUNT (tree_model);
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (parent == NULL) {
- if (priv->toplevel != NULL) {
- if (n > 0) {
- iter->stamp = 0;
- LEAVE("failed (1)");
- return FALSE;
- } else {
- iter->user_data = priv->toplevel;
- iter->user_data2 = NULL;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
- LEAVE("iter (1) %s", iter_to_string(iter));
- return TRUE;
- }
- }
+ /* Special case when no parent supplied. */
+ if (!parent_iter) {
+ if (n != 0) {
+ LEAVE("bad root index");
+ return FALSE;
+ }
- account = xaccGroupGetAccount (priv->root, n);
-
- if (account == NULL) {
- iter->stamp = 0;
- LEAVE("failed (2)");
- return FALSE;
- }
-
- iter->user_data = account;
- iter->user_data2 = priv->root;
- iter->user_data3 = GINT_TO_POINTER (n);
- iter->stamp = model->stamp;
- LEAVE("iter (2) %s", iter_to_string(iter));
- return TRUE;
+ iter->user_data = priv->root;
+ iter->user_data2 = NULL;
+ iter->user_data3 = GINT_TO_POINTER (0);
+ iter->stamp = model->stamp;
+ LEAVE("root %s", iter_to_string(iter));
+ return TRUE;
}
- g_return_val_if_fail (parent->user_data != NULL, FALSE);
- g_return_val_if_fail (parent->stamp == model->stamp, FALSE);
+ g_return_val_if_fail (parent_iter->user_data != NULL, FALSE);
+ g_return_val_if_fail (parent_iter->stamp == model->stamp, FALSE);
+ parent = (Account *)parent_iter->user_data;
+ account = gnc_account_nth_child(parent, n);
- if (priv->toplevel == parent->user_data) {
- group = priv->root;
- } else {
- group = xaccAccountGetChildren ((Account *) parent->user_data);
- }
-
- if (group == NULL || xaccGroupGetNumAccounts (group) <= n) {
- iter->stamp = 0;
- LEAVE("failed (3)");
- return FALSE;
- }
-
- account = xaccGroupGetAccount (group, n);
-
if (account == NULL) {
iter->stamp = 0;
- LEAVE("failed (4)");
+ LEAVE("failed (2)");
return FALSE;
}
iter->user_data = account;
- iter->user_data2 = group;
+ iter->user_data2 = parent;
iter->user_data3 = GINT_TO_POINTER (n);
iter->stamp = model->stamp;
- LEAVE("iter (3) %s", iter_to_string(iter));
+ LEAVE("iter (2) %s", iter_to_string(iter));
return TRUE;
}
@@ -1148,8 +1003,7 @@
{
GncTreeModelAccount *model;
GncTreeModelAccountPrivate *priv;
- Account *account;
- AccountGroup *group;
+ Account *account, *parent;
gint i;
if (child) {
@@ -1174,150 +1028,31 @@
g_return_val_if_fail (child->stamp == model->stamp, FALSE);
account = (Account *) child->user_data;
-
- if (account == priv->toplevel) {
+ account = gnc_account_get_parent(account);
+ if (account == NULL) {
+ /* Can't go up from the root node */
iter->stamp = 0;
LEAVE("failed (1)");
return FALSE;
}
- account = xaccAccountGetParentAccount (account);
- group = xaccAccountGetParent (account);
-
- if (account == NULL || group == NULL) {
- if (priv->toplevel != NULL) {
- iter->user_data = priv->toplevel;
- iter->user_data2 = NULL;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
- LEAVE("iter (1) %s", iter_to_string(iter));
- return TRUE;
- } else {
- iter->stamp = 0;
- LEAVE("failed (2)");
- return FALSE;
- }
+ parent = gnc_account_get_parent(account);
+ if (parent == NULL) {
+ /* Now at the root. */
+ i = 0;
+ } else {
+ i = gnc_account_child_index(parent, account);
}
-
- for (i = 0; i < xaccGroupGetNumAccounts (group); i++) {
- if (xaccGroupGetAccount (group, i) == account) {
- iter->user_data = account;
- iter->user_data2 = group;
- iter->user_data3 = GINT_TO_POINTER (i);
- iter->stamp = model->stamp;
- LEAVE("iter (2) %s", iter_to_string(iter));
- return TRUE;
- }
- }
-
- if (priv->toplevel != NULL) {
- iter->user_data = priv->toplevel;
- iter->user_data2 = NULL;
- iter->user_data3 = GINT_TO_POINTER (0);
- iter->stamp = model->stamp;
- LEAVE("iter (3) %s", iter_to_string(iter));
- return TRUE;
- }
- iter->stamp = 0;
- LEAVE("failed (3)");
- return FALSE;
+ iter->user_data = account;
+ iter->user_data2 = parent;
+ iter->user_data3 = GINT_TO_POINTER (i);
+ iter->stamp = model->stamp;
+ LEAVE("iter (2) %s", iter_to_string(iter));
+ return TRUE;
}
/************************************************************/
-/* Account Tree View Root Functions */
-/************************************************************/
-
-static gpointer
-account_row_inserted (Account *account,
- gpointer data)
-{
- GtkTreePath *path;
- GtkTreeIter iter;
-
- ENTER("account %p (%s), model %p",
- account, xaccAccountGetName(account), data);
- if (!gnc_tree_model_account_get_iter_from_account
- (GNC_TREE_MODEL_ACCOUNT (data), account, &iter))
- return NULL;
-
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter);
-
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (data), path, &iter);
-
- gtk_tree_path_free (path);
-
- LEAVE(" ");
- return NULL;
-}
-
-/*
- * Gets the top node of the model. This node is for a pseudo-account
- * that lives above the main level accounts in the engine.
- */
-Account *
-gnc_tree_model_account_get_toplevel (GncTreeModelAccount *model)
-{
- GncTreeModelAccountPrivate *priv;
-
- g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), NULL);
-
- priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- return priv->toplevel;
-}
-
-/*
- * Add a new top node to the model. This node is for a pseudo-account
- * that lives above the main level accounts in the engine.
- */
-static void
-gnc_tree_model_account_set_toplevel (GncTreeModelAccount *model,
- Account *toplevel)
-{
- GncTreeModelAccountPrivate *priv;
- GtkTreePath *path;
- gint i;
- GtkTreeIter iter;
-
- ENTER("model %p, toplevel %p", model, toplevel);
- g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model));
-
- priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- DEBUG("old toplevel %p", priv->toplevel);
- if (priv->toplevel != NULL) {
- /* CAS: this can't happen because we only set toplevel on
- * new tree models. */
- path = gtk_tree_path_new_first ();
- gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
- gtk_tree_path_free (path);
- } else {
- /* CAS: I think this is bogus for the same reason - we'll
- * have no rows, so why are we emitting a bunch of
- * "row_deleted" signals when no rows can exist? */
- path = gtk_tree_path_new_first ();
- for (i = 0; i < xaccGroupGetNumAccounts (priv->root); i++) {
- gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
- }
- gtk_tree_path_free (path);
- }
-
- DEBUG("set new toplevel %p", toplevel);
- priv->toplevel = toplevel;
-
- if (priv->toplevel != NULL) {
- path = gtk_tree_path_new_first ();
- if (gtk_tree_model_get_iter (GTK_TREE_MODEL (model), &iter, path))
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
- }
-
- if (priv->root != NULL) {
- xaccGroupForEachAccount (priv->root, account_row_inserted, model, TRUE);
- }
- LEAVE("new toplevel %p", priv->root);
-}
-
-/************************************************************/
/* Account Tree View Filter Functions */
/************************************************************/
@@ -1348,8 +1083,7 @@
GtkTreeIter *iter)
{
GncTreeModelAccountPrivate *priv;
- AccountGroup *group;
- gboolean found = FALSE;
+ Account *parent;
gint i;
ENTER("model %p, account %p, iter %p", model, account, iter);
@@ -1361,32 +1095,24 @@
iter->stamp = model->stamp;
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
- if (account == priv->toplevel) {
+ if (account == priv->root) {
iter->user_data2 = NULL;
iter->user_data3 = GINT_TO_POINTER (0);
- LEAVE("Matched top level");
+ LEAVE("Matched root");
return TRUE;
}
- if (priv->root != xaccAccountGetRoot (account)) {
+ if (priv->root != gnc_account_get_root (account)) {
LEAVE("Root doesn't match");
return FALSE;
}
- group = xaccAccountGetParent (account);
- DEBUG("Looking through %d accounts at this level",
- xaccGroupGetNumAccounts (group));
- for (i = 0; i < xaccGroupGetNumAccounts (group); i++) {
- if (xaccGroupGetAccount (group, i) == account) {
- found = TRUE;
- break;
- }
- }
-
- iter->user_data2 = group;
+ parent = gnc_account_get_parent(account);
+ i = gnc_account_child_index(parent, account);
+ iter->user_data2 = parent;
iter->user_data3 = GINT_TO_POINTER (i);
LEAVE("iter %s", iter_to_string(iter));
- return found;
+ return (i != -1);
}
/*
@@ -1438,9 +1164,16 @@
{
GtkTreeIter iter;
- /* Immediate parent */
- if (gtk_tree_path_up(path) &&
- gtk_tree_model_get_iter(model, &iter, path)) {
+ /* Already at the invisible root node? */
+ if (!gtk_tree_path_up(path))
+ return;
+
+ /* Did we just move up to the invisible root node? */
+ if (gtk_tree_path_get_depth(path) == 0)
+ return;
+
+ /* Handle the immediate parent */
+ if (gtk_tree_model_get_iter(model, &iter, path)) {
gtk_tree_model_row_changed(model, path, &iter);
if (gtk_tree_model_iter_n_children(model, &iter) == toggle_if_num)
gtk_tree_model_row_has_child_toggled(model, path, &iter);
@@ -1502,11 +1235,11 @@
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
account = GNC_ACCOUNT(entity);
- if (xaccAccountGetBook(account) != priv->book) {
+ if (gnc_account_get_book(account) != priv->book) {
LEAVE("not in this book");
return;
}
- if (xaccAccountGetRoot(account) != priv->root) {
+ if (gnc_account_get_root(account) != priv->root) {
LEAVE("not in this model");
return;
}
@@ -1532,7 +1265,7 @@
case QOF_EVENT_REMOVE:
if (!ed) /* Required for a remove. */
break;
- parent = ed->node ? GNC_ACCOUNT(ed->node) : priv->toplevel;
+ parent = ed->node ? GNC_ACCOUNT(ed->node) : priv->root;
parent_name = ed->node ? xaccAccountGetName(parent) : "Root";
DEBUG("remove child %d of account %p (%s)", ed->idx, parent, parent_name);
path = gnc_tree_model_account_get_path_from_account(model, parent);
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model-account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -39,7 +39,7 @@
#include <gtk/gtktreemodel.h>
#include "gnc-tree-model.h"
-#include "Group.h"
+#include "Account.h"
G_BEGIN_DECLS
@@ -124,28 +124,13 @@
*
* @param group The account group to put at the top level of the tree
* hierarchy. */
-GtkTreeModel *gnc_tree_model_account_new (AccountGroup *group);
+GtkTreeModel *gnc_tree_model_account_new (Account *root);
/** @} */
/** @name Account Tree Model Get/Set Functions
@{ */
-/** This function returns the account associated with the top level
- * pseudo-account. The gnucash engine does not have a single top
- * level account (it has a list of top level accounts), but this code
- * provides one so that it can be used with all parts of the gnucash
- * gui.
- *
- * @internal This function should only be called from gnc-tree-view-account.c.
- *
- * @param account_view A pointer to an account tree view.
- *
- * @return The top-level pseudo-account.
- */
-Account *gnc_tree_model_account_get_toplevel (GncTreeModelAccount *model);
-
-
/** Convert a model/iter pair to a gnucash account. This routine should
* only be called from an account tree view filter function. The
* model and iter values will be provided as part of the call to the
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-model.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -37,8 +37,6 @@
#include <gtk/gtktreemodel.h>
-#include "Group.h"
-
G_BEGIN_DECLS
/* type macros */
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -38,7 +38,6 @@
#include "gnc-tree-view-account.h"
#include "Account.h"
-#include "Group.h"
#include "gnc-accounting-period.h"
#include "gnc-commodity.h"
#include "gnc-component-manager.h"
@@ -71,8 +70,6 @@
GtkTreeIter *iter,
gpointer data);
-static Account *gtva_get_top_level_from_model (GtkTreeModel *s_model);
-
static void gtva_setup_column_renderer_edited_cb(GncTreeViewAccount *account_view,
GtkTreeViewColumn *column,
GtkCellRenderer *renderer,
@@ -290,7 +287,7 @@
result = safe_utf8_collate(str1, str2);
if (result != 0)
return result;
- return xaccAccountOrder(&account1, &account2);
+ return xaccAccountOrder(account1, account2);
}
static gint
@@ -304,7 +301,7 @@
sort_cb_setup (f_model, f_iter_a, f_iter_b, &account_a, &account_b);
/* Default ordering uses this column first. */
- return xaccAccountOrder(&account_a, &account_b);
+ return xaccAccountOrder(account_a, account_b);
}
static gint
@@ -329,7 +326,7 @@
result = gnc_numeric_compare(balance_a, balance_b);
if (result != 0)
return result;
- return xaccAccountOrder(&account_a, &account_b);
+ return xaccAccountOrder(account_a, account_b);
}
static gint
@@ -412,7 +409,7 @@
return -1;
else if (flag_a < flag_b)
return 1;
- return xaccAccountOrder(&account_a, &account_b);
+ return xaccAccountOrder(account_a, account_b);
}
static gint
@@ -438,7 +435,7 @@
result = gnc_numeric_compare(b1, b2);
if (result != 0)
return result;
- return xaccAccountOrder((const Account **)&acct1, (const Account **)&acct2);
+ return xaccAccountOrder(acct1, acct2);
}
static gint
@@ -470,7 +467,7 @@
* model.
*/
GtkTreeView *
-gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
+gnc_tree_view_account_new_with_root (Account *root, gboolean show_root)
{
GncTreeView *view;
GtkTreeModel *model, *f_model, *s_model;
@@ -486,7 +483,7 @@
priv = GNC_TREE_VIEW_ACCOUNT_GET_PRIVATE(GNC_TREE_VIEW_ACCOUNT (view));
/* Create/get a pointer to the existing model for this set of books. */
- model = gnc_tree_model_account_new (group);
+ model = gnc_tree_model_account_new (root);
/* Set up the view private filter layer on the common model. */
if (!show_root)
@@ -683,10 +680,10 @@
GtkTreeView *
gnc_tree_view_account_new (gboolean show_root)
{
- AccountGroup *group;
+ Account *root;
- group = gnc_book_get_group (gnc_get_current_book ());
- return gnc_tree_view_account_new_with_group (group, show_root);
+ root = gnc_book_get_root_account (gnc_get_current_book ());
+ return gnc_tree_view_account_new_with_root (root, show_root);
}
/************************************************************/
@@ -951,35 +948,7 @@
/* Account Tree View Get/Set Functions */
/************************************************************/
-static Account *
-gtva_get_top_level_from_model (GtkTreeModel *s_model)
-{
- GtkTreeModel *model, *f_model;
-
- g_return_val_if_fail (GTK_TREE_MODEL_SORT (s_model), NULL);
-
- f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (s_model));
- model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (f_model));
-
- return gnc_tree_model_account_get_toplevel (GNC_TREE_MODEL_ACCOUNT (model));
-}
-
/*
- * Return the account associated with the top level pseudo-account for
- * the tree.
- */
-Account *
-gnc_tree_view_account_get_top_level (GncTreeViewAccount *view)
-{
- GtkTreeModel *s_model;
-
- g_return_val_if_fail (GNC_IS_TREE_VIEW_ACCOUNT (view), NULL);
- s_model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
-
- return gtva_get_top_level_from_model (s_model);
-}
-
-/*
* Retrieve the selected account from an account tree view. The
* account tree must be in single selection mode.
*/
@@ -2015,8 +1984,8 @@
QofBook *book;
book = qof_session_get_book(gnc_get_current_session());
- account = xaccGetAccountFromFullName(xaccGetAccountGroup(book),
- account_name);
+ account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
+ account_name);
if (account)
gnc_tree_view_account_expand_to_account(view, account);
}
@@ -2037,8 +2006,8 @@
QofBook *book;
book = qof_session_get_book(gnc_get_current_session());
- account = xaccGetAccountFromFullName(xaccGetAccountGroup(book),
- account_name);
+ account = gnc_account_lookup_by_full_name(gnc_book_get_root_account(book),
+ account_name);
if (account)
gnc_tree_view_account_set_selected_account(view, account);
}
@@ -2121,12 +2090,12 @@
void
gnc_tree_view_account_name_edited_cb(Account *account, GtkTreeViewColumn *col, const gchar *new_name)
{
- // check for accounts with the same name in our parent's group.
+ // check for accounts with the same name among our parent's children.
// should probably factor this consistency check out to the account
- // itself... or maybe the account group.
+ // itself....
{
- AccountGroup *parent = xaccAccountGetParent(account);
- Account *existing = xaccGetAccountFromName(parent, new_name);
+ Account *parent = gnc_account_get_parent(account);
+ Account *existing = gnc_account_lookup_by_name(parent, new_name);
if (existing != NULL && existing != account)
{
PERR("account with the same name [%s] already exists.", new_name);
Modified: gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.h
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/gnc-tree-view-account.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -38,7 +38,6 @@
#include <gtk/gtktreeview.h>
#include "gnc-tree-view.h"
-#include "Group.h"
#include "gnc-ui-util.h"
#include "gnc-plugin-page.h"
@@ -132,8 +131,8 @@
*
* @return A pointer to a new account tree view.
*/
-GtkTreeView *gnc_tree_view_account_new_with_group (AccountGroup *group,
- gboolean show_root);
+GtkTreeView *gnc_tree_view_account_new_with_root (Account *root,
+ gboolean show_root);
/** Create a new account tree view. This view may or may not show a
* pseudo top-level account. The gnucash engine does not have a
@@ -339,24 +338,6 @@
-/** This function returns the account associated with the top level
- * pseudo-account. The gnucash engine does not have a single top
- * level account (it has a list of top level accounts), but this code
- * provides one so that it can be used with all parts of the gnucash
- * gui.
- *
- * @note It only makes sense to call this function when the account
- * tree is created such that the "top level account" is visible. At
- * the time this was written, only the "New/Edit Account" dialog does
- * that.
- *
- * @param view A pointer to an account tree view.
- *
- * @return The top-level pseudo-account.
- */
-Account * gnc_tree_view_account_get_top_level (GncTreeViewAccount *view);
-
-
/** This function returns the account associated with the specified
* path. This function is useful in selection callbacks on an
* account tree widget.
Modified: gnucash/branches/remove-group2/src/gnome-utils/window-main-summarybar.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome-utils/window-main-summarybar.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/gnome-utils/window-main-summarybar.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -29,7 +29,6 @@
#include <glib/gi18n.h>
#include "Account.h"
-#include "Group.h"
#include "gnc-accounting-period.h"
#include "gnc-component-manager.h"
#include "gnc-euro.h"
@@ -120,14 +119,13 @@
* @fixme Move this non-GUI code into the engine.
**/
static void
-gnc_ui_accounts_recurse (AccountGroup *group, GList **currency_list,
+gnc_ui_accounts_recurse (Account *parent, GList **currency_list,
GNCSummarybarOptions options)
{
gnc_numeric start_amount;
gnc_numeric start_amount_default_currency;
gnc_numeric end_amount;
gnc_numeric end_amount_default_currency;
- AccountGroup *children;
GNCAccountType account_type;
gnc_commodity * account_currency;
gnc_commodity * euro_commodity;
@@ -135,21 +133,20 @@
GNCCurrencyAcc *euro_accum = NULL;
GNCCurrencyAcc *grand_total_accum = NULL;
GNCCurrencyAcc *non_curr_accum = NULL;
- GList *list;
- GList *node;
+ GList *children, *node;
gboolean non_currency = FALSE;
Timespec end_timespec;
Timespec start_timespec;
+ if (parent == NULL) return;
- list = xaccGroupGetAccountList (group);
- for (node = list; node; node = node->next)
+ children = gnc_account_get_children(parent);
+ for (node = children; node; node = g_list_next(node))
{
Account *account = node->data;
account_type = xaccAccountGetType(account);
account_currency = xaccAccountGetCommodity(account);
- children = xaccAccountGetChildren(account);
if(options.grand_total)
grand_total_accum = gnc_ui_get_currency_accumulator(currency_list,
@@ -226,8 +223,7 @@
GNC_RND_ROUND);
}
- if (children != NULL)
- gnc_ui_accounts_recurse(children, currency_list, options);
+ gnc_ui_accounts_recurse(account, currency_list, options);
break;
case ACCT_TYPE_INCOME:
case ACCT_TYPE_EXPENSE:
@@ -292,8 +288,7 @@
GNC_RND_ROUND);
}
- if (children != NULL)
- gnc_ui_accounts_recurse(children, currency_list, options);
+ gnc_ui_accounts_recurse(account, currency_list, options);
break;
case ACCT_TYPE_EQUITY:
/* no-op, see comments at top about summing assets */
@@ -303,6 +298,7 @@
break;
}
}
+ g_list_free(children);
}
static char*
@@ -358,7 +354,7 @@
static void
gnc_main_window_summary_refresh (GNCMainSummary * summary)
{
- AccountGroup *group;
+ Account *root;
char asset_string[256];
char profit_string[256];
GNCCurrencyAcc *currency_accum;
@@ -387,8 +383,8 @@
gnc_ui_get_currency_accumulator (¤cy_list, options.default_currency,
TOTAL_SINGLE);
- group = gnc_get_current_group ();
- gnc_ui_accounts_recurse(group, ¤cy_list, options);
+ root = gnc_get_current_root_account ();
+ gnc_ui_accounts_recurse(root, ¤cy_list, options);
{
GtkTreeIter iter;
Modified: gnucash/branches/remove-group2/src/import-export/binary-import/druid-commodity.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/binary-import/druid-commodity.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/binary-import/druid-commodity.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -460,7 +460,7 @@
comm);
/* now replace all the accounts using old_comm with new_comm */
- accts = xaccGroupGetSubAccounts(gnc_get_current_group ());
+ accts = gnc_account_get_descendants(gnc_get_current_root_account ());
for(node = accts; node; node = node->next)
{
@@ -493,10 +493,10 @@
g_hash_table_foreach(cd->new_map, &finish_helper, (gpointer)cd);
/* Fix account and transaction commodities */
- xaccGroupScrubCommodities (gnc_get_current_group ());
+ xaccAccountTreeScrubCommodities (gnc_get_current_root_account ());
/* Fix split amount/value */
- xaccGroupScrubSplits (gnc_get_current_group ());
+ xaccAccountTreeScrubSplits (gnc_get_current_root_account ());
/* destroy the dialog */
gnc_ui_commodity_druid_destroy(cd);
Modified: gnucash/branches/remove-group2/src/import-export/hbci/druid-hbci-utils.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/hbci/druid-hbci-utils.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/hbci/druid-hbci-utils.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -66,7 +66,7 @@
(gnc_acc, AB_Account_GetBankCode(hbci_acc));
}
-static gpointer accounts_clear_kvp (Account *gnc_acc, gpointer user_data)
+static void accounts_clear_kvp (Account *gnc_acc, gpointer user_data)
{
if (gnc_hbci_get_account_uid(gnc_acc))
gnc_hbci_set_account_uid (gnc_acc, 0);
@@ -74,7 +74,6 @@
gnc_hbci_set_account_accountid (gnc_acc, "");
if (gnc_hbci_get_account_bankcode(gnc_acc))
gnc_hbci_set_account_bankcode (gnc_acc, "");
- return NULL;
}
/* hash is a DIRECT hash from each HBCI account to each gnucash
@@ -82,13 +81,11 @@
void
accounts_save_kvp (GHashTable *hash)
{
- AccountGroup *grp;
+ Account *root;
g_assert(hash);
- grp = gnc_book_get_group (gnc_get_current_book ());
- xaccGroupForEachAccount (grp,
- &accounts_clear_kvp,
- NULL, TRUE);
+ root = gnc_book_get_root_account (gnc_get_current_book ());
+ gnc_account_foreach_descendant (root, accounts_clear_kvp, NULL);
g_hash_table_foreach (hash, &accounts_save_kvp_cb, NULL);
}
@@ -112,7 +109,7 @@
GHashTable *hash;
};
-static gpointer
+static void
gnc_hbci_new_hash_from_kvp_cb (Account *gnc_acc, gpointer user_data)
{
struct hbci_acc_cb_data *data = user_data;
@@ -122,7 +119,6 @@
if (hbci_acc) {
g_hash_table_insert (data->hash, hbci_acc, gnc_acc);
}
- return NULL;
}
GHashTable *
@@ -133,12 +129,10 @@
hash = g_hash_table_new (&g_direct_hash, &g_direct_equal);
if (api) {
struct hbci_acc_cb_data data;
- AccountGroup *grp = gnc_book_get_group (gnc_get_current_book ());
+ Account *root = gnc_book_get_root_account (gnc_get_current_book ());
data.api = api;
data.hash = hash;
- xaccGroupForEachAccount (grp,
- &gnc_hbci_new_hash_from_kvp_cb,
- &data, TRUE);
+ gnc_account_foreach_descendant(root, gnc_hbci_new_hash_from_kvp_cb, &data);
}
return hash;
}
Modified: gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-gettrans.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-gettrans.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-gettrans.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -256,7 +256,7 @@
gnc_acc = data->gnc_acc;
g_assert(gnc_acc);
- book = xaccAccountGetBook(gnc_acc);
+ book = gnc_account_get_book(gnc_acc);
/* Create new gnucash transaction for the given hbci one */
gnc_trans = xaccMallocTransaction(book);
Modified: gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-transfer.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-transfer.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/hbci/gnc-hbci-transfer.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -78,7 +78,7 @@
GList *template_list =
gnc_trans_templ_glist_from_kvp_glist
( gnc_hbci_get_book_template_list
- ( xaccAccountGetBook(gnc_acc)));
+ ( gnc_account_get_book(gnc_acc)));
int result;
gboolean successful = FALSE;
HBCITransDialog *td;
@@ -224,7 +224,7 @@
g_list_length(template_list),
kvp_value_glist_to_string(kvp_list));*/
gnc_hbci_set_book_template_list
- (xaccAccountGetBook(gnc_acc), kvp_list);
+ (gnc_account_get_book(gnc_acc), kvp_list);
}
}
Modified: gnucash/branches/remove-group2/src/import-export/import-account-matcher.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/import-account-matcher.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/import-account-matcher.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -158,12 +158,12 @@
/*DEBUG("Looking for account with online_id: %s", account_online_id_value);*/
if(account_online_id_value!=NULL)
{
- retval = xaccGroupForEachAccount(gnc_get_current_group (),
+ retval =
+ gnc_account_foreach_descendant_until(gnc_get_current_root_account (),
test_acct_online_id_match,
/* This argument will only be
used as a "const char*" */
- (void*)account_online_id_value,
- TRUE);
+ (void*)account_online_id_value);
}
if(retval==NULL && auto_create != 0)
{
Modified: gnucash/branches/remove-group2/src/import-export/import-backend.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/import-backend.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/import-backend.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -845,7 +845,7 @@
/* Create the 'other' split. */
Split *split =
xaccMallocSplit
- (xaccAccountGetBook
+ (gnc_account_get_book
(gnc_import_TransInfo_get_destacc (trans_info)));
xaccTransAppendSplit
(gnc_import_TransInfo_get_trans (trans_info), split);
Modified: gnucash/branches/remove-group2/src/import-export/import-match-map.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/import-match-map.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/import-match-map.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -31,7 +31,6 @@
#include <string.h>
#include <glib.h>
#include "import-match-map.h"
-#include "Group.h"
#include "gnc-ui-util.h"
#include "gnc-engine.h"
@@ -66,7 +65,7 @@
* marking dirtiness
*/
if (acc)
- book = xaccAccountGetBook (acc);
+ book = gnc_account_get_book (acc);
imap->acc = acc;
imap->book = book;
@@ -442,8 +441,8 @@
{
PINFO("found match");
LEAVE(" ");
- return xaccGetAccountFromFullName(gnc_book_get_group(imap->book),
- account_i.account_name);
+ return gnc_account_lookup_by_full_name(gnc_book_get_root_account(imap->book),
+ account_i.account_name);
}
PINFO("no match");
Modified: gnucash/branches/remove-group2/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/ofx/gnc-ofx-import.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/ofx/gnc-ofx-import.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -132,7 +132,7 @@
gnc_utf8_strip_invalid(data.memo);
/********** Create the transaction and setup transaction data ************/
- book = xaccAccountGetBook(account);
+ book = gnc_account_get_book(account);
transaction = xaccMallocTransaction(book);
xaccTransBeginEdit(transaction);
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/druid-qif-import.c
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/druid-qif-import.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/druid-qif-import.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -116,7 +116,7 @@
SCM new_stocks;
SCM ticker_map;
- SCM imported_account_group;
+ SCM imported_account_tree;
SCM match_transactions;
int selected_transaction;
};
@@ -189,7 +189,7 @@
scm_gc_unprotect_object(window->stock_hash);
scm_gc_unprotect_object(window->new_stocks);
scm_gc_unprotect_object(window->ticker_map);
- scm_gc_unprotect_object(window->imported_account_group);
+ scm_gc_unprotect_object(window->imported_account_tree);
scm_gc_unprotect_object(window->match_transactions);
g_free(window);
@@ -1203,7 +1203,7 @@
{
SCM qif_to_gnc = scm_c_eval_string("qif-import:qif-to-gnc");
- SCM find_duplicates = scm_c_eval_string("gnc:group-find-duplicates");
+ SCM find_duplicates = scm_c_eval_string("gnc:account-tree-find-duplicates");
SCM retval;
SCM current_xtn;
SCM window;
@@ -1256,8 +1256,9 @@
}
}
- /* call a scheme function to do the work. The return value is an
- * account group containing all the new accounts and transactions */
+ /* call a scheme function to do the work. The return value is the
+ * root account of an account tree containing all the new accounts
+ * and transactions */
window = SWIG_NewPointerObj(wind->window, SWIG_TypeQuery("_p_GtkWidget"), 0);
retval = scm_apply(qif_to_gnc,
SCM_LIST7(wind->imported_files,
@@ -1276,20 +1277,20 @@
_("An error occurred while importing "
"QIF transactions into GnuCash. Your "
"accounts are unchanged."));
- scm_gc_unprotect_object(wind->imported_account_group);
- wind->imported_account_group = SCM_BOOL_F;
- scm_gc_protect_object(wind->imported_account_group);
+ scm_gc_unprotect_object(wind->imported_account_tree);
+ wind->imported_account_tree = SCM_BOOL_F;
+ scm_gc_protect_object(wind->imported_account_tree);
}
else {
- scm_gc_unprotect_object(wind->imported_account_group);
- wind->imported_account_group = retval;
- scm_gc_protect_object(wind->imported_account_group);
+ scm_gc_unprotect_object(wind->imported_account_tree);
+ wind->imported_account_tree = retval;
+ scm_gc_protect_object(wind->imported_account_tree);
/* now detect duplicate transactions */
gnc_set_busy_cursor(NULL, TRUE);
retval = scm_call_3(find_duplicates,
- scm_c_eval_string("(gnc-get-current-group)"),
- wind->imported_account_group, window);
+ scm_c_eval_string("(gnc-get-current-root-account)"),
+ wind->imported_account_tree, window);
gnc_unset_busy_cursor(NULL);
scm_gc_unprotect_object(wind->match_transactions);
@@ -1853,7 +1854,7 @@
{
SCM save_map_prefs = scm_c_eval_string("qif-import:save-map-prefs");
- SCM cat_and_merge = scm_c_eval_string("gnc:group-catenate-and-merge");
+ SCM cat_and_merge = scm_c_eval_string("gnc:account-tree-catenate-and-merge");
SCM prune_xtns = scm_c_eval_string("gnc:prune-matching-transactions");
QIFImportWindow * wind = user_data;
@@ -1867,8 +1868,8 @@
/* actually add in the new transactions. */
scm_call_2(cat_and_merge,
- scm_c_eval_string("(gnc-get-current-group)"),
- wind->imported_account_group);
+ scm_c_eval_string("(gnc-get-current-root-account)"),
+ wind->imported_account_tree);
gnc_resume_gui_refresh();
@@ -2056,7 +2057,7 @@
retval->stock_hash = SCM_BOOL_F;
retval->new_stocks = SCM_BOOL_F;
retval->ticker_map = SCM_BOOL_F;
- retval->imported_account_group = SCM_BOOL_F;
+ retval->imported_account_tree = SCM_BOOL_F;
retval->match_transactions = SCM_BOOL_F;
retval->selected_transaction = 0;
@@ -2221,7 +2222,7 @@
scm_gc_protect_object(retval->stock_hash);
scm_gc_protect_object(retval->new_stocks);
scm_gc_protect_object(retval->ticker_map);
- scm_gc_protect_object(retval->imported_account_group);
+ scm_gc_protect_object(retval->imported_account_tree);
scm_gc_protect_object(retval->match_transactions);
/* set a default currency for new accounts */
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/qif-dialog-utils.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/qif-dialog-utils.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/qif-dialog-utils.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -606,10 +606,10 @@
(not (hash-ref stock-hash stock-name)))
(let* ((separator (string-ref (gnc-get-account-separator-string) 0))
(existing-gnc-acct
- (xaccGetAccountFromFullName
- (gnc-get-current-group)
+ (gnc-get-account-from-full-name
+ (gnc-get-current-root-account)
(qif-map-entry:gnc-name map-entry)))
- (book (xaccGroupGetBook (gnc-get-current-group)))
+ (book (gnc-account-get-book (gnc:get-current-root-account)))
(existing-type
(xaccAccountGetType existing-gnc-acct)))
(if (and (not (null? existing-gnc-acct))
@@ -713,7 +713,7 @@
separator)
#f)
accts)))
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group)))
+ (gnc-account-get-descendants (gnc-get-current-root-account)))
;; now build a tree structure
(for-each
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/qif-guess-map.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/qif-guess-map.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/qif-guess-map.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,10 +25,10 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (qif-import:load-map-prefs)
- (define (extract-all-account-info agroup root-name)
- (if (null? agroup)
+ (define (extract-all-account-info an-account root-name)
+ (if (null? an-account)
'()
- (let ((children-list (xaccGroupGetAccountListSorted agroup))
+ (let ((children-list (gnc-account-get-children an-account))
(names '()))
;; now descend the tree of child accounts.
@@ -43,9 +43,7 @@
name)))
(set! names
(append (cons (list name fullname child-acct)
- (extract-all-account-info
- (xaccAccountGetChildren child-acct)
- fullname))
+ (extract-all-account-info child-acct fullname))
names))))
children-list)
names)))
@@ -110,7 +108,7 @@
(make-hash-table 20)))))
;; now build the list of all known account names
- (let* ((all-accounts (gnc-get-current-group))
+ (let* ((all-accounts (gnc-get-current-root-account))
(all-account-info (extract-all-account-info all-accounts #f)))
(set! results (cons all-account-info results)))
results))
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/qif-import.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/qif-import.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/qif-import.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -65,6 +65,6 @@
(export qif-dialog:make-category-display)
(export qif-dialog:make-memo-display)
-(export gnc:group-find-duplicates)
-(export gnc:group-catenate-and-merge)
+(export gnc:account-tree-find-duplicates)
+(export gnc:account-tree-catenate-and-merge)
(export gnc:prune-matching-transactions)
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/qif-merge-groups.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/qif-merge-groups.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/qif-merge-groups.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -5,16 +5,16 @@
;;; Copyright 2001 Bill Gribble <grib at billgribble.com>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(define (gnc:group-get-transactions group)
+(define (gnc:account-tree-get-transactions root)
(let ((query (qof-query-create-for-splits))
(xtns #f))
- (qof-query-set-book query (xaccGroupGetBook group))
+ (qof-query-set-book query (gnc-account-get-book root))
;; we want to find all transactions with every split inside the
;; account group.
(xaccQueryAddAccountMatch query
- (xaccGroupGetSubAccountsSorted group)
+ (gnc-account-get-descendants root)
QOF-GUID-MATCH-ANY QOF-QUERY-AND)
(set! xtns (xaccQueryGetTransactions query QUERY-TXN-MATCH-ALL))
@@ -25,16 +25,16 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; gnc:group-find-duplicates
+;; gnc:account-tree-find-duplicates
;; detect redundant splits/xtns from 'new' and return
;; them in a list.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(define (gnc:group-find-duplicates old-group new-group window)
+(define (gnc:account-tree-find-duplicates old-root new-root window)
;; get all the transactions in the new group, then iterate over them
;; trying to find matches in the new group. If there are matches,
;; push the matches onto a list.
- (let* ((new-xtns (gnc:group-get-transactions new-group))
+ (let* ((new-xtns (gnc:account-tree-get-transactions new-root))
(progress-dialog #f)
(work-to-do (length new-xtns))
(work-done 0)
@@ -47,7 +47,7 @@
(gnc-progress-dialog-set-heading progress-dialog
(_ "Finding duplicate transactions..."))))
- ;; for each transaction in the new group, build a query that could
+ ;; for each transaction in the new account tree, build a query that could
;; match possibly similar transactions.
(for-each
(lambda (xtn)
@@ -59,11 +59,11 @@
progress-dialog (/ work-done work-to-do))
(gnc-progress-dialog-update progress-dialog)))
- (qof-query-set-book query (xaccGroupGetBook old-group))
+ (qof-query-set-book query (gnc-account-get-book old-root))
;; first, we want to find only transactions from the old group.
(xaccQueryAddAccountMatch query
- (xaccGroupGetSubAccountsSorted old-group)
+ (gnc-account-get-descendants old-root)
QOF-GUID-MATCH-ANY QOF-QUERY-AND)
;; the date should be close to the same.. +/- a week.
@@ -78,22 +78,22 @@
(for-each
(lambda (split)
(let ((sq (qof-query-create-for-splits)))
- (qof-query-set-book sq (xaccGroupGetBook old-group))
+ (qof-query-set-book sq (gnc-account-get-book old-root))
- ;; we want to match the account in the old group that
- ;; has the same name as an account in the new group. If
- ;; there's not one (new account), the match will be NULL
- ;; and we know the query won't find anything. optimize
- ;; this later.
+ ;; we want to match the account in the old account
+ ;; tree that has the same name as an account in the
+ ;; new account tree. If there's not one (new
+ ;; account), the match will be NULL and we know the
+ ;; query won't find anything. optimize this later.
(xaccQueryAddSingleAccountMatch
sq
- (xaccGetAccountFromFullName
- old-group (gnc-account-get-full-name
+ (gnc-get-account-from-full-name
+ old-root (gnc-account-get-full-name
(xaccSplitGetAccount split)))
QOF-QUERY-AND)
;; we want the value for the split to match the value
- ;; the old-group split. We should really check for
+ ;; the old-root split. We should really check for
;; fuzziness.
(xaccQueryAddValueMatch
sq (xaccSplitGetValue split)
@@ -111,14 +111,14 @@
(xaccTransGetSplitList xtn))
;; now q-splits will match any split that is the same as one
- ;; split in the old-group xtn. Merge it in.
+ ;; split in the old-root xtn. Merge it in.
(let ((q-new (qof-query-merge query q-splits QOF-QUERY-AND)))
(qof-query-destroy query)
(qof-query-destroy q-splits)
(set! query q-new)))
;; now that we have built a query, get transactions in the old
- ;; account group that matches it.
+ ;; account tree that matches it.
(let ((old-xtns (xaccQueryGetTransactions query QUERY-TXN-MATCH-ALL)))
(set! old-xtns (map
(lambda (elt)
@@ -156,9 +156,9 @@
(xaccTransCommitEdit new-xtn)))))
match-list))
-(define (gnc:group-catenate-and-merge old-group new-group)
- ;; stuff the new accounts into the old group and merge the accounts
- (xaccGroupConcatGroup old-group new-group)
- (xaccAccountGroupBeginEdit new-group)
- (xaccAccountGroupDestroy new-group)
- (xaccGroupMergeAccounts old-group))
+(define (gnc:account-tree-catenate-and-merge old-root new-root)
+ ;; stuff the new accounts into the old account tree and merge the accounts
+ (gnc:account-join-children old-root new-root)
+ (gnc:account-begin-edit new-root)
+ (gnc:account-destroy new-root)
+ (gnc:account-merge-children old-root))
Modified: gnucash/branches/remove-group2/src/import-export/qif-import/qif-to-gnc.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-import/qif-to-gnc.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-import/qif-to-gnc.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -14,12 +14,12 @@
(define (qif-import:find-or-make-acct acct-info check-types? commodity
check-commodity? default-currency
- gnc-acct-hash old-group new-group)
+ gnc-acct-hash old-root new-root)
(let* ((separator (string-ref (gnc-get-account-separator-string) 0))
(gnc-name (qif-map-entry:gnc-name acct-info))
(existing-account (hash-ref gnc-acct-hash gnc-name))
(same-gnc-account
- (xaccGetAccountFromFullName old-group gnc-name))
+ (gnc-get-account-from-full-name old-root gnc-name))
(allowed-types
(qif-map-entry:allowed-types acct-info))
(make-new-acct #f)
@@ -38,12 +38,12 @@
#t))))
(define (make-unique-name-variant long-name short-name)
- (if (not (null? (xaccGetAccountFromFullName old-group long-name)))
+ (if (not (null? (gnc-get-account-from-full-name old-root long-name)))
(let loop ((count 2))
(let* ((test-name
(string-append long-name (sprintf #f " %a" count)))
(test-acct
- (xaccGetAccountFromFullName old-group test-name)))
+ (gnc-get-account-from-full-name old-root test-name)))
(if (and (not (null? test-acct)) (not (compatible? test-acct)))
(loop (+ 1 count))
(string-append short-name (sprintf #f " %a" count)))))
@@ -156,10 +156,10 @@
(set! parent-acct (qif-import:find-or-make-acct
pinfo #t default-currency #f default-currency
- gnc-acct-hash old-group new-group))))
+ gnc-acct-hash old-root new-root))))
(if (and parent-acct (not (null? parent-acct)))
- (xaccAccountInsertSubAccount parent-acct new-acct)
- (xaccGroupInsertAccount new-group new-acct))
+ (gnc:account-append-child parent-acct new-acct)
+ (gnc:account-append-child new-root new-acct))
(hash-set! gnc-acct-hash gnc-name new-acct)
new-acct))))
@@ -178,8 +178,8 @@
default-currency-name window)
(gnc:backtrace-if-exception
(lambda ()
- (let* ((old-group (gnc-get-current-group))
- (new-group (xaccMallocAccountGroup (gnc-get-current-book)))
+ (let* ((old-root (gnc-get-current-root-account))
+ (new-root (xaccMallocAccount (gnc-get-current-book)))
(gnc-acct-hash (make-hash-table 20))
(separator (string-ref (gnc-get-account-separator-string) 0))
(default-currency
@@ -266,16 +266,16 @@
(qif-import:find-or-make-acct acctinfo #f
security #t default-currency
gnc-acct-hash
- old-group new-group))
+ old-root new-root))
((and security (or stock?
(gnc-commodity-is-currency security)))
(qif-import:find-or-make-acct
acctinfo #f security #t default-currency
- gnc-acct-hash old-group new-group))
+ gnc-acct-hash old-root new-root))
(#t
(qif-import:find-or-make-acct
acctinfo #f default-currency #t default-currency
- gnc-acct-hash old-group new-group)))))
+ gnc-acct-hash old-root new-root)))))
sorted-accounts-list)
;; before trying to mark transactions, prune down the list of
@@ -356,7 +356,7 @@
(if (not (null? progress-dialog))
(gnc-progress-dialog-destroy progress-dialog))
- new-group))))
+ new-root))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; qif-import:qif-xtn-to-gnc-xtn
Modified: gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-acct-table.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-acct-table.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-acct-table.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -43,13 +43,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; qif-io:acct-table-make-gnc-group
+;; qif-io:acct-table-make-gnc-acct-tree
;; fill in information for the gnucash accounts and organize them
;; in a group tree
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(define (qif-io:acct-table-make-gnc-group acct-table qif-file commodity)
- (let ((group (xaccMallocAccountGroup (gnc-get-current-book))))
+(define (qif-io:acct-table-make-gnc-acct-tree acct-table qif-file commodity)
+ (let ((root (xaccMallocAccount (gnc-get-current-book))))
;; poke through the qif-file accounts to see if any of them
;; show up in the data
(let ((qif-acct-table (qif-io:acct-table-accounts acct-table)))
@@ -81,7 +81,7 @@
(let ((type (xaccAccountGetType acct)))
(if (= type -1)
(xaccAccountSetType acct GNC-BANK-TYPE)))
- (xaccGroupInsertAccount group acct)
+ (gnc-account-append-child root acct)
#t) #t (qif-io:acct-table-accounts acct-table)))
;; now the categories
@@ -116,11 +116,11 @@
(let ((type (xaccAccountGetType acct)))
(if (= type -1)
(xaccAccountSetType acct GNC-EXPENSE-TYPE)))
- (xaccGroupInsertAccount group acct)
+ (gnc-account-append-child root acct)
#t) #t (qif-io:acct-table-categories acct-table)))
;; the securities
;; the other brokerage-related accounts
- group))
+ root))
Modified: gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-io-core.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-io-core.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-io-core/qif-io-core.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -85,7 +85,7 @@
;; acct-table.scm
(export qif-io:acct-table-lookup)
(export qif-io:acct-table-insert!)
-(export qif-io:acct-table-make-gnc-group)
+(export qif-io:acct-table-make-gnc-acct-tree)
;; from main
(export simple-format)
Modified: gnucash/branches/remove-group2/src/import-export/qif-io-core/test/test-import-phase-1.scm
===================================================================
--- gnucash/branches/remove-group2/src/import-export/qif-io-core/test/test-import-phase-1.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/import-export/qif-io-core/test/test-import-phase-1.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -56,14 +56,14 @@
(qif-io:invst-xtn-import xtn qiffile acct-table commodity))
(qif-io:file-invst-xtns qiffile))
- ;; build a gnucash account group
- (let ((group (qif-io:acct-table-make-gnc-group
- acct-table qiffile commodity)))
+ ;; build a gnucash account tree
+ (let ((root (qif-io:acct-table-make-gnc-acct-tree
+ acct-table qiffile commodity)))
;; write the file
(let* ((name (simple-format #f "file:~A.gnc" filename)))
(simple-format #t "using book name='~A'\n" name)
- (xaccGroupConcatGroup (xaccGetAccountGroup book) group)
- (xaccAccountGroupDestroy group)
+ (gnc-account-join-children (gnc-book-get-root book) root)
+ (xaccAccountDestroy root)
(gnc:session-begin session name #t #t)
(gnc:session-save session)
(gnc:session-end session)
Modified: gnucash/branches/remove-group2/src/register/ledger-core/gnc-ledger-display.c
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/gnc-ledger-display.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/gnc-ledger-display.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -26,7 +26,6 @@
#include <time.h>
#include "Account.h"
-#include "Group.h"
#include "Query.h"
#include "QueryCore.h"
#include "QueryNew.h"
@@ -311,9 +310,7 @@
gpointer ret;
reg_type = GENERAL_LEDGER;
- ret = xaccGroupForEachAccount (xaccAccountGetChildren (leader),
- look_for_portfolio_cb,
- NULL, TRUE);
+ ret = gnc_account_foreach_descendant_until(leader, look_for_portfolio_cb, NULL);
if (ret) reg_type = PORTFOLIO_LEDGER;
break;
}
@@ -404,20 +401,20 @@
/* In lieu of not "mis-using" some portion of the infrastructure by writing
* a bunch of new code, we just filter out the accounts of the template
- * transactions. While these are in a seperate AccountGroup just for this
- * reason, the query engine makes no distinction between AccountGroups.
+ * transactions. While these are in a seperate Account trees just for this
+ * reason, the query engine makes no distinction between Account trees.
* See Gnome Bug 86302.
* -- jsled */
{
- AccountGroup *tAG;
- AccountList *al;
+ Account *tRoot;
+ GList *al;
- tAG = gnc_book_get_template_group( gnc_get_current_book() );
- al = xaccGroupGetSubAccounts( tAG );
+ tRoot = gnc_book_get_template_root( gnc_get_current_book() );
+ al = gnc_account_get_descendants( tRoot );
xaccQueryAddAccountMatch( query, al, GUID_MATCH_NONE, QUERY_AND );
g_list_free (al);
al = NULL;
- tAG = NULL;
+ tRoot = NULL;
}
gnc_tm_get_today_start(&tm);
@@ -448,8 +445,7 @@
Query *q;
GNCLedgerDisplay *ld;
SplitRegister *sr;
- AccountGroup *ag;
- Account *acct;
+ Account *root, *acct;
gboolean isTemplateModeTrue;
acct = NULL;
@@ -461,8 +457,8 @@
xaccQuerySetBook (q, book);
if ( id != NULL ) {
- ag = gnc_book_get_template_group (book);
- acct = xaccGetAccountFromName (ag, id);
+ root = gnc_book_get_template_root (book);
+ acct = gnc_account_lookup_by_name(root, id);
g_assert( acct );
xaccQueryAddSingleAccountMatch (q, acct, QUERY_AND);
}
@@ -630,7 +626,7 @@
leader = gnc_ledger_display_leader (ld);
if (ld->ld_type == LD_SUBACCOUNT)
- accounts = xaccGroupGetSubAccounts (xaccAccountGetChildren (leader));
+ accounts = gnc_account_get_descendants (leader);
else
accounts = NULL;
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register-control.c
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register-control.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register-control.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,7 +25,6 @@
#include <glib.h>
#include <glib/gi18n.h>
-#include "Group.h"
#include "Scrub.h"
#include "combocell.h"
#include "gnc-component-manager.h"
@@ -53,6 +52,7 @@
int default_value;
Account *default_account;
Account *other_account;
+ Account *root;
GList *radio_list = NULL;
const char *title = _("Rebalance Transaction");
const char *message = _("The current transaction is not balanced.");
@@ -133,6 +133,7 @@
g_list_free (radio_list);
+ root = gnc_account_get_root(default_account);
switch (choice)
{
default:
@@ -140,17 +141,15 @@
break;
case 1:
- xaccTransScrubImbalance (trans, gnc_get_current_group (), NULL);
+ xaccTransScrubImbalance (trans, root, NULL);
break;
case 2:
- xaccTransScrubImbalance (trans, gnc_get_current_group (),
- default_account);
+ xaccTransScrubImbalance (trans, root, default_account);
break;
case 3:
- xaccTransScrubImbalance (trans, gnc_get_current_group (),
- other_account);
+ xaccTransScrubImbalance (trans, root, other_account);
break;
}
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register-load.c
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register-load.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register-load.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -24,7 +24,6 @@
#include "config.h"
-#include "Group.h"
#include "account-quickfill.h"
#include "combocell.h"
#include "gnc-component-manager.h"
@@ -579,20 +578,19 @@
static void
gnc_split_register_load_xfer_cells (SplitRegister *reg, Account *base_account)
{
- AccountGroup *group;
+ Account *root;
QuickFill *qf;
ComboCell *cell;
GtkListStore *store;
- group = xaccAccountGetRoot(base_account);
- if (group == NULL)
- group = gnc_get_current_group();
-
- if (group == NULL)
+ root = gnc_account_get_root(base_account);
+ if (root == NULL)
+ root = gnc_get_current_root_account();
+ if (root == NULL)
return;
- qf = gnc_get_shared_account_name_quickfill (group, QKEY, skip_cb, NULL);
- store = gnc_get_shared_account_name_list_store (group, QKEY, skip_cb, NULL);
+ qf = gnc_get_shared_account_name_quickfill (root, QKEY, skip_cb, NULL);
+ store = gnc_get_shared_account_name_list_store (root, QKEY, skip_cb, NULL);
cell = (ComboCell *)
gnc_table_layout_get_cell (reg->table->layout, XFRM_CELL);
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register-model.c
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register-model.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register-model.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -25,7 +25,6 @@
#include <glib.h>
#include <glib/gi18n.h>
-#include "Group.h"
#include "datecell.h"
#include "dialog-utils.h"
#include "gnc-engine.h"
@@ -83,7 +82,7 @@
const char *name;
name = gnc_table_layout_get_cell_value (reg->table->layout, XFRM_CELL);
- account = xaccGetAccountFromFullName (gnc_get_current_group (), name);
+ account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name);
}
if (!account)
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register-p.h
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register-p.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register-p.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -23,7 +23,6 @@
#ifndef SPLIT_REGISTER_P_H
#define SPLIT_REGISTER_P_H
-#include "Group.h"
#include "split-register.h"
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register.c
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register.c 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register.c 2006-11-01 00:01:35 UTC (rev 15066)
@@ -1504,7 +1504,7 @@
return NULL;
/* Find the account */
- account = xaccGetAccountFromFullName (gnc_get_current_group (), name);
+ account = gnc_account_lookup_by_full_name (gnc_get_current_root_account (), name);
if (!account) {
/* Ask if they want to create a new one. */
Modified: gnucash/branches/remove-group2/src/register/ledger-core/split-register.h
===================================================================
--- gnucash/branches/remove-group2/src/register/ledger-core/split-register.h 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/register/ledger-core/split-register.h 2006-11-01 00:01:35 UTC (rev 15066)
@@ -135,7 +135,6 @@
#include <glib.h>
-#include "Group.h"
#include "Transaction.h"
#include "table-allgui.h"
Modified: gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf-de_DE.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf-de_DE.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf-de_DE.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -315,8 +315,7 @@
(payer-src (gnc:account-get-txf-payer-source account))
(account-name (let* ((named-acct
(if (eq? payer-src 'parent)
- (xaccGroupGetParentAccount
- (xaccAccountGetParent account))
+ (gnc-account-get-parent account)
account))
(name (xaccAccountGetName named-acct)))
(if name
@@ -435,8 +434,7 @@
#t
;; check children
(if (null? (validate
- (xaccGroupGetSubAccountsSorted
- (xaccAccountGetChildren a))))
+ (gnc-account-get-descendants a)))
#f
#t)))
accounts))
@@ -454,13 +452,13 @@
;; the number of account generations: children, grandchildren etc.
(define (num-generations account gen)
- (let ((children (xaccAccountGetChildren account)))
- (if (eq? (xaccGroupGetNumAccounts children) 0)
+ (let ((children (gnc-account-get-children account)))
+ (if (null? children)
(if (and (xaccAccountGetTaxRelated account)
(txf-special-split? (gnc:account-get-txf-code account)))
(+ gen 1) ; Est Fed Tax has a extra generation
gen) ; no kids, return input
- (apply max (gnc:group-map-accounts
+ (apply max (gnc:account-map-children
(lambda (x) (num-generations x (+ 1 gen)))
children)))))
@@ -482,8 +480,8 @@
(selected-accounts (if (not (null? user-sel-accnts))
valid-user-sel-accnts
(validate (reverse
- (xaccGroupGetAccountListSorted
- (gnc-get-current-group))))))
+ (gnc-account-get-children
+ (gnc-get-current-root-account))))))
(generations (if (pair? selected-accounts)
(apply max (map (lambda (x) (num-generations x 1))
selected-accounts))
@@ -643,7 +641,7 @@
(for-each (lambda (x)
(if (gnc:account-is-inc-exp? x)
(set! sum (+ sum (+ 1 (count-accounts (+ 1 level)
- (gnc:account-get-immediate-subaccounts x)))))
+ (gnc-account-get-children x)))))
0))
accounts)
sum)
@@ -656,7 +654,7 @@
(/ work-done work-to-do)
1)))
(if (gnc:account-is-inc-exp? account)
- (let* ((children (xaccAccountGetChildren account))
+ (let* ((children (gnc-account-get-children-sorted account))
(to-special #f) ; clear special-splits-period
(from-special #f)
(childrens-output
@@ -679,8 +677,7 @@
(if (>= max-level (+ 1 level))
(handle-level-x-account (+ 1 level) x)
'()))
- (reverse
- (xaccGroupGetAccountListSorted children)))))
+ (reverse children))))
(account-balance
(if (xaccAccountGetTaxRelated account)
Modified: gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/locale-specific/us/taxtxf.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -290,8 +290,7 @@
(payer-src (gnc:account-get-txf-payer-source account))
(account-name (let* ((named-acct
(if (eq? payer-src 'parent)
- (xaccGroupGetParentAccount
- (xaccAccountGetParent account))
+ (gnc-account-get-parent account)
account))
(name (xaccAccountGetName named-acct)))
(if name
@@ -412,8 +411,7 @@
#t
;; check children
(if (null? (validate
- (xaccGroupGetSubAccountsSorted
- (xaccAccountGetChildren a))))
+ (gnc-account-get-descendants a)))
#f
#t)))
accounts))
@@ -431,13 +429,13 @@
;; the number of account generations: children, grandchildren etc.
(define (num-generations account gen)
- (let ((children (xaccAccountGetChildren account)))
- (if (eq? (xaccGroupGetNumAccounts children) 0)
+ (let ((children (gnc-account-get-children account)))
+ (if (null? children)
(if (and (xaccAccountGetTaxRelated account)
(txf-special-split? (gnc:account-get-txf-code account)))
(+ gen 1) ; Est Fed Tax has a extra generation
gen) ; no kids, return input
- (apply max (gnc:group-map-accounts
+ (apply max (gnc:account-map-children
(lambda (x) (num-generations x (+ 1 gen)))
children)))))
@@ -459,8 +457,8 @@
(selected-accounts (if (not (null? user-sel-accnts))
valid-user-sel-accnts
(validate (reverse
- (xaccGroupGetAccountListSorted
- (gnc-get-current-group))))))
+ (gnc-account-get-children-sorted
+ (gnc-get-current-root-account))))))
(generations (if (pair? selected-accounts)
(apply max (map (lambda (x) (num-generations x 1))
selected-accounts))
@@ -620,7 +618,7 @@
(for-each (lambda (x)
(if (gnc:account-is-inc-exp? x)
(set! sum (+ sum (+ 1 (count-accounts (+ 1 level)
- (gnc:account-get-immediate-subaccounts x)))))
+ (gnc-account-get-children x)))))
0))
accounts)
sum)
@@ -633,7 +631,7 @@
(/ work-done work-to-do)
1)))
(if (gnc:account-is-inc-exp? account)
- (let* ((children (xaccAccountGetChildren account))
+ (let* ((children (gnc-account-get-children-sorted account))
(to-special #f) ; clear special-splits-period
(from-special #f)
(childrens-output
@@ -656,8 +654,7 @@
(if (>= max-level (+ 1 level))
(handle-level-x-account (+ 1 level) x)
'()))
- (reverse
- (xaccGroupGetAccountListSorted children)))))
+ (reverse children))))
(account-balance
(if (xaccAccountGetTaxRelated account)
Modified: gnucash/branches/remove-group2/src/report/report-system/commodity-utilities.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/report-system/commodity-utilities.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/report-system/commodity-utilities.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -210,7 +210,7 @@
(let ((currency-accounts
;;(filter gnc:account-has-shares?
;; -- use all accounts, not only share accounts, since gnucash-1.7
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group)))
+ (gnc-account-get-descendants (gnc-get-current-root-account)))
(work-to-do (length commodity-list))
(work-done 0))
(map
@@ -311,7 +311,7 @@
(let ((currency-accounts
;;(filter gnc:account-has-shares?
;; -- use all accounts, not only share accounts, since gnucash-1.7
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group)))
+ (gnc-account-get-descendants (gnc-get-current-root-account)))
(work-to-do (length commodity-list))
(work-done 0))
(map
@@ -530,7 +530,7 @@
(let ((curr-accounts
;;(filter gnc:account-has-shares? ))
;; -- use all accounts, not only share accounts, since gnucash-1.7
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group)))
+ (gnc-account-get-descendants (gnc-get-current-root-account)))
;; sumlist: a multilevel alist. Each element has a commodity
;; as key, and another alist as a value. The value-alist's
;; elements consist of a commodity as a key, and a pair of two
Modified: gnucash/branches/remove-group2/src/report/report-system/html-acct-table.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/report-system/html-acct-table.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/report-system/html-acct-table.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -625,7 +625,7 @@
)
))
;; local variables
- (toplvl-accts (xaccGroupGetAccountListSorted (gnc-get-current-group)))
+ (toplvl-accts (gnc-account-get-children (gnc-get-current-root-account)))
(acct-depth-reached 0)
(logi-depth-reached (if depth-limit (- depth-limit 1) 0))
(disp-depth-reached 0)
@@ -691,13 +691,13 @@
(my-get-balance-nosub account start-date end-date)))
(for-each
(lambda (x) (if x (gnc-commodity-collector-merge this-collector x)))
- (gnc:group-map-all-accounts
+ (gnc:account-map-descendants
(lambda (a)
;; Important: Calculate the balance if and only if the
;; account a is shown, i.e. (use-acct? a) == #t.
(and (use-acct? a)
(my-get-balance-nosub a start-date end-date)))
- (xaccAccountGetChildren account)))
+ account))
this-collector))
@@ -709,14 +709,14 @@
(for-each
(lambda (acct)
- (let* ((subaccts (gnc:account-get-immediate-subaccounts acct))
+ (let* ((subaccts (gnc-account-get-children acct))
;; assign output parameters
(account acct)
(account-name (xaccAccountGetName acct))
(account-code (xaccAccountGetCode acct))
(account-path (gnc-account-get-full-name acct))
(account-anchor (gnc:html-account-anchor acct))
- (account-parent (xaccAccountGetParentAccount acct))
+ (account-parent (gnc-account-get-parent acct))
(account-children subaccts)
(account-depth acct-depth)
(logical-depth logi-depth)
Modified: gnucash/branches/remove-group2/src/report/report-system/html-utilities.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/report-system/html-utilities.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/report-system/html-utilities.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -428,8 +428,8 @@
(let ((table (gnc:make-html-table))
(work-to-do 0)
(work-done 0)
- (topl-accounts (xaccGroupGetAccountListSorted
- (gnc-get-current-group))))
+ (topl-accounts (gnc-account-get-children
+ (gnc-get-current-root-account))))
;; The following functions are defined inside build-acct-table
;; to avoid passing tons of arguments which are constant anyway
@@ -458,13 +458,13 @@
(lambda (x) (if x
(gnc-commodity-collector-merge
this-collector x )))
- (gnc:group-map-all-accounts
+ (gnc:account-map-descendants
(lambda (a)
;; Important: Calculate the balance if and only if the
;; account a is shown, i.e. (use-acct? a) == #t.
(and (use-acct? a)
(my-get-balance-nosub a)))
- (xaccAccountGetChildren account)))
+ account))
this-collector))
;; Use this account in the account hierarchy? Check against the
@@ -474,7 +474,7 @@
(define (use-acct? a)
(or (member a accounts)
(and show-subaccts?
- (let ((parent (xaccAccountGetParentAccount a)))
+ (let ((parent (gnc-account-get-parent a)))
(and parent
(use-acct? parent))))))
@@ -580,7 +580,7 @@
(lambda (acct)
(let ((subaccts (filter
use-acct?
- (gnc:account-get-immediate-subaccounts acct))))
+ (gnc-account-get-children acct))))
(set! sum (+ sum 1))
(if (or (= current-depth tree-depth) (null? subaccts))
sum
@@ -647,7 +647,7 @@
(lambda (acct)
(let ((subaccts (filter
use-acct?
- (gnc:account-get-immediate-subaccounts acct))))
+ (gnc-account-get-children acct))))
(set! work-done (+ 1 work-done))
(if start-percent
(gnc:report-percent-done
Modified: gnucash/branches/remove-group2/src/report/report-system/report-system.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/report-system/report-system.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/report-system/report-system.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -561,10 +561,8 @@
(export gnc:decompose-accountlist)
(export gnc:account-get-type-string-plural)
(export gnc:accounts-get-commodities)
-(export gnc:get-current-group-depth)
+(export gnc:get-current-account-tree-depth)
(export gnc:split-get-corr-account-full-name)
-(export gnc:account-get-immediate-subaccounts)
-(export gnc:account-get-all-subaccounts)
(export gnc:acccounts-get-all-subaccounts)
(export gnc:make-stats-collector)
(export gnc:make-drcr-collector)
@@ -579,10 +577,8 @@
(export gnc:accounts-get-comm-total-income)
(export gnc:accounts-get-comm-total-expense)
(export gnc:accounts-get-comm-total-assets)
-(export gnc:group-get-comm-balance-at-date)
(export gnc:account-get-balance-interval)
(export gnc:account-get-comm-balance-interval)
-(export gnc:group-get-comm-balance-interval)
(export gnc:accountlist-get-comm-balance-interval)
(export gnc:accountlist-get-comm-balance-at-date)
(export gnc:query-set-match-non-voids-only!)
Modified: gnucash/branches/remove-group2/src/report/report-system/report-utilities.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/report-system/report-utilities.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/report-system/report-utilities.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -133,57 +133,20 @@
;; Returns the depth of the current account hierarchy, that is, the
-;; maximum level of subaccounts in the current-group.
-(define (gnc:get-current-group-depth)
- ;; Given a list of accounts, this function determines the maximum
- ;; sub-account level that there is.
- (define (accounts-get-children-depth accounts)
- (apply max
- (map (lambda (acct)
- (let ((children
- (gnc:account-get-immediate-subaccounts acct)))
- (if (null? children)
- 1
- (+ 1 (accounts-get-children-depth children)))))
- accounts)))
- (accounts-get-children-depth
- (xaccGroupGetAccountListSorted (gnc-get-current-group))))
+;; maximum level of subaccounts in the tree
+(define (gnc:get-current-account-tree-depth)
+ (let ((root (gnc:get-current-root-account)))
+ (gnc-account-get-depth root)))
(define (gnc:split-get-corr-account-full-name split)
(xaccSplitGetCorrAccountFullName split))
-;; get children that are the direct descendant of this acct
-(define (gnc:account-get-immediate-subaccounts acct)
- (define (acctptr-eq? a1 a2)
- (let ((a1-str
- (with-output-to-string (lambda () (write a1))))
- (a2-str
- (with-output-to-string (lambda () (write a2)))))
- (string=? a1-str a2-str)))
-
- (let* ((group (xaccAccountGetChildren acct))
- (children (xaccGroupGetSubAccountsSorted group))
- (retval '()))
- (for-each
- (lambda (child)
- (if (acctptr-eq? acct (xaccAccountGetParentAccount child))
- (begin
- (set! retval (cons child retval)))))
- children)
- (reverse retval)))
-
-;; get all children of this account
-(define (gnc:account-get-all-subaccounts acct)
- (let ((group (xaccAccountGetChildren acct)))
- (xaccGroupGetSubAccountsSorted group)))
-
;; Get all children of this list of accounts.
(define (gnc:acccounts-get-all-subaccounts accountlist)
(append-map
(lambda (a)
- (xaccGroupGetSubAccountsSorted
- (xaccAccountGetChildren a)))
+ (gnc-account-get-descendants a))
accountlist))
;;; Here's a statistics collector... Collects max, min, total, and makes
@@ -493,14 +456,19 @@
;; values rather than double values.
(define (gnc:account-get-comm-balance-at-date account
date include-children?)
- (let ((balance-collector
- (if include-children?
- (gnc:group-get-comm-balance-at-date
- (xaccAccountGetChildren account) date)
- (gnc:make-commodity-collector)))
- (query (qof-query-create-for-splits))
- (splits #f))
-
+ (let ((balance-collector (gnc:make-commodity-collector))
+ (query (qof-query-create-for-splits))
+ (splits #f))
+
+ (if include-children?
+ (for-each
+ (lambda (x)
+ (gnc:commodity-collector-merge balance-collector x))
+ (gnc:account-map-descendants
+ (lambda (child)
+ (gnc:account-get-comm-balance-at-date child date #f))
+ account)))
+
(qof-query-set-book query (gnc-get-current-book))
(xaccQueryAddSingleAccountMatch query account QOF-QUERY-AND)
(xaccQueryAddDateMatchTS query #f date #t date QOF-QUERY-AND)
@@ -580,19 +548,6 @@
get-balance-fn
(lambda(x) #f)))
-;; returns a commodity-collector
-(define (gnc:group-get-comm-balance-at-date group date)
- (let ((this-collector (gnc:make-commodity-collector)))
- (for-each
- (lambda (x)
- (gnc-commodity-collector-merge this-collector x))
- (gnc:group-map-all-accounts
- (lambda (account)
- (gnc:account-get-comm-balance-at-date
- account date #f))
- group))
- this-collector))
-
;; get the change in balance from the 'from' date to the 'to' date.
;; this isn't quite as efficient as it could be, but it's a whole lot
;; simpler :)
@@ -618,17 +573,6 @@
include-children?))
this-collector))
-;; the version which returns a commodity-collector
-(define (gnc:group-get-comm-balance-interval group from to)
- (let ((this-collector (gnc:make-commodity-collector)))
- (for-each (lambda (x)
- (gnc-commodity-collector-merge this-collector x))
- (gnc:group-map-all-accounts
- (lambda (account)
- (gnc:account-get-comm-balance-interval
- account from to #t)) group))
- this-collector))
-
;; This calculates the increase in the balance(s) of all accounts in
;; <accountlist> over the period from <from-date> to <to-date>.
;; Returns a commodity collector.
@@ -708,10 +652,10 @@
(gnc:accounts-count-splits (cdr accounts)))
0))
-;; Sums up any splits of a certain type affecting a group of accounts.
+;; Sums up any splits of a certain type affecting a set of accounts.
;; the type is an alist '((str "match me") (cased #f) (regexp #f))
(define (gnc:account-get-trans-type-balance-interval
- group type start-date-tp end-date-tp)
+ account-list type start-date-tp end-date-tp)
(let* ((query (qof-query-create-for-splits))
(splits #f)
(get-val (lambda (alist key)
@@ -724,7 +668,7 @@
)
(qof-query-set-book query (gnc-get-current-book))
(gnc:query-set-match-non-voids-only! query (gnc-get-current-book))
- (xaccQueryAddAccountMatch query group QOF-GUID-MATCH-ANY QOF-QUERY-AND)
+ (xaccQueryAddAccountMatch query account-list QOF-GUID-MATCH-ANY QOF-QUERY-AND)
(xaccQueryAddDateMatchTS
query
(and start-date-tp #t) start-date-tp
@@ -751,7 +695,7 @@
;; similar, but only counts transactions with non-negative shares and
;; *ignores* any closing entries
(define (gnc:account-get-pos-trans-total-interval
- group type start-date-tp end-date-tp)
+ account-list type start-date-tp end-date-tp)
(let* ((str-query (qof-query-create-for-splits))
(sign-query (qof-query-create-for-splits))
(total-query #f)
@@ -769,8 +713,8 @@
(qof-query-set-book sign-query (gnc-get-current-book))
(gnc:query-set-match-non-voids-only! str-query (gnc-get-current-book))
(gnc:query-set-match-non-voids-only! sign-query (gnc-get-current-book))
- (xaccQueryAddAccountMatch str-query group QOF-GUID-MATCH-ANY QOF-QUERY-AND)
- (xaccQueryAddAccountMatch sign-query group QOF-GUID-MATCH-ANY QOF-QUERY-AND)
+ (xaccQueryAddAccountMatch str-query account-list QOF-GUID-MATCH-ANY QOF-QUERY-AND)
+ (xaccQueryAddAccountMatch sign-query account-list QOF-GUID-MATCH-ANY QOF-QUERY-AND)
(xaccQueryAddDateMatchTS
str-query
(and start-date-tp #t) start-date-tp
Modified: gnucash/branches/remove-group2/src/report/standard-reports/account-piecharts.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/account-piecharts.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/account-piecharts.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -110,7 +110,7 @@
(lambda ()
(gnc:filter-accountlist-type
account-types
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
(lambda (accounts)
(list #t
(gnc:filter-accountlist-type
@@ -200,8 +200,8 @@
(chart (gnc:make-html-piechart))
(topl-accounts (gnc:filter-accountlist-type
account-types
- (xaccGroupGetAccountListSorted
- (gnc-get-current-group)))))
+ (gnc-account-get-children
+ (gnc-get-current-root-account)))))
;; Returns true if the account a was selected in the account
;; selection option.
@@ -223,7 +223,7 @@
(let* ((exchange-fn (gnc:case-exchange-fn
price-source report-currency to-date-tp))
(tree-depth (if (equal? account-levels 'all)
- (gnc:get-current-group-depth)
+ (gnc:get-current-account-tree-depth)
account-levels))
(combined '())
(other-anchor "")
@@ -251,7 +251,7 @@
(for-each
(lambda (a)
(set! sum (+ sum (+ 1 (count-accounts (+ 1 current-depth)
- (gnc:account-get-immediate-subaccounts a))))))
+ (gnc-account-get-children a))))))
accts)
sum)
(length (filter show-acct? accts))))
@@ -281,7 +281,7 @@
(set! res (append
(traverse-accounts
(+ 1 current-depth)
- (gnc:account-get-immediate-subaccounts a))
+ (gnc-account-get-children a))
res))))
accts)
res)
@@ -356,8 +356,7 @@
(if (string? (cadr pair))
other-anchor
(let* ((acct (cadr pair))
- (subaccts
- (gnc:account-get-immediate-subaccounts acct)))
+ (subaccts (gnc-account-get-children acct)))
(if (null? subaccts)
;; if leaf-account, make this an anchor
;; to the register.
Modified: gnucash/branches/remove-group2/src/report/standard-reports/account-summary.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/account-summary.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/account-summary.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -158,7 +158,7 @@
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL ACCT-TYPE-CURRENCY
ACCT-TYPE-PAYABLE ACCT-TYPE-RECEIVABLE
ACCT-TYPE-EQUITY ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
(gnc:options-add-account-levels!
options gnc:pagename-accounts optname-depth-limit
@@ -315,7 +315,7 @@
(doc (gnc:make-html-document))
;; just in case we need this information...
(tree-depth (if (equal? depth-limit 'all)
- (gnc:get-current-group-depth)
+ (gnc:get-current-account-tree-depth)
depth-limit))
;; exchange rates calculation parameters
(exchange-fn
@@ -492,8 +492,7 @@
report-commodity exchange-fn
(append-map
(lambda (a)
- (xaccGroupGetSubAccountsSorted
- (xaccAccountGetChildren a)))
+ (gnc-account-get-descendants a))
accounts))))
)
)
Modified: gnucash/branches/remove-group2/src/report/standard-reports/advanced-portfolio.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/advanced-portfolio.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/advanced-portfolio.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -151,8 +151,8 @@
"b"
(N_ "Stock Accounts to report on")
(lambda () (filter gnc:account-is-stock?
- (xaccGroupGetSubAccountsSorted
- (gnc-get-current-group))))
+ (gnc-account-get-descendants
+ (gnc-get-current-root-account))))
(lambda (accounts) (list #t
(filter gnc:account-is-stock? accounts)))
#t))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/average-balance.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/average-balance.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/average-balance.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -77,7 +77,7 @@
;; or: (list ACCT-TYPE-BANK ACCT-TYPE-CASH
;; ACCT-TYPE-CHECKING ACCT-TYPE-SAVINGS ACCT-TYPE-STOCK
;; ACCT-TYPE-MUTUAL ACCT-TYPE-MONEYMRKT)
- (xaccGroupGetAccountListSorted (gnc-get-current-group)))))))
+ (gnc-account-get-children (gnc-get-current-root-account)))))))
#f #t))
;; Display tab
@@ -353,7 +353,7 @@
(for-each
(lambda (acct)
(let ((this-acct-subs
- (gnc:account-get-all-subaccounts acct)))
+ (gnc-account-get-descendants acct)))
(if (list? this-acct-subs)
(set! subaccts
(append subaccts this-acct-subs)))))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/balance-sheet.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/balance-sheet.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/balance-sheet.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -182,7 +182,7 @@
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL ACCT-TYPE-CURRENCY
ACCT-TYPE-PAYABLE ACCT-TYPE-RECEIVABLE
ACCT-TYPE-EQUITY ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
(gnc:options-add-account-levels!
options gnc:pagename-accounts optname-depth-limit
@@ -356,7 +356,7 @@
;; is the only simple way to ensure that all three tables
;; (asset, liability, equity) have the same width.
(tree-depth (if (equal? depth-limit 'all)
- (gnc:get-current-group-depth)
+ (gnc:get-current-account-tree-depth)
depth-limit))
;; exchange rates calculation parameters
(exchange-fn
@@ -423,7 +423,7 @@
(gnc:html-make-no-account-warning
reportname (gnc:report-id report-obj)))
- ;; Get all the balances for each account group.
+ ;; Get all the balances for each of the account types.
(let* ((asset-balance #f)
(neg-liability-balance #f) ;; credit balances are < 0
(liability-balance #f)
Modified: gnucash/branches/remove-group2/src/report/standard-reports/budget.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/budget.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/budget.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -92,7 +92,7 @@
(gnc:filter-accountlist-type
(list ACCT-TYPE-ASSET ACCT-TYPE-LIABILITY ACCT-TYPE-INCOME
ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f)
;; Set the general page as default option tab
@@ -284,7 +284,7 @@
;; helper for account depth
(define (account-get-depth account)
(define (account-get-depth-internal account-internal depth)
- (let ((parent (xaccAccountGetParentAccount account-internal)))
+ (let ((parent (gnc-account-get-parent account-internal)))
(if (not (null? parent))
(account-get-depth-internal parent (+ depth 1))
depth)))
@@ -294,7 +294,7 @@
(apply max
(map (lambda (acct)
(let ((children
- (gnc:account-get-immediate-subaccounts acct)))
+ (gnc-account-get-children acct)))
(if (null? children)
1
(+ 1 (accounts-get-children-depth children)))))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/cash-flow.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/cash-flow.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/cash-flow.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -93,7 +93,7 @@
(gnc:filter-accountlist-type
(list ACCT-TYPE-BANK ACCT-TYPE-CASH ACCT-TYPE-ASSET
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f)
;; Set the general page as default option tab
@@ -184,7 +184,7 @@
;; helper for account depth
(define (account-get-depth account)
(define (account-get-depth-internal account-internal depth)
- (let ((parent (xaccAccountGetParentAccount account-internal)))
+ (let ((parent (gnc-account-get-parent account-internal)))
(if (not (null? parent))
(account-get-depth-internal parent (+ depth 1))
depth)))
@@ -194,7 +194,7 @@
(apply max
(map (lambda (acct)
(let ((children
- (gnc:account-get-immediate-subaccounts acct)))
+ (gnc-account-get-children acct)))
(if (null? children)
1
(+ 1 (accounts-get-children-depth children)))))
@@ -382,7 +382,7 @@
(if (<= (account-get-depth account) tree-depth)
(let* ((anchor (gnc:html-markup/format
(if (and (= (account-get-depth account) tree-depth)
- (not (eq? (gnc:account-get-immediate-subaccounts account) '())))
+ (not (eq? (gnc-account-get-children account) '())))
(if show-subaccts?
(_ "%s and subaccounts")
(_ "%s and selected subaccounts"))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/category-barchart.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/category-barchart.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/category-barchart.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -116,7 +116,7 @@
(lambda ()
(gnc:filter-accountlist-type
account-types
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
(lambda (accounts)
(list #t
(gnc:filter-accountlist-type account-types accounts)))
@@ -212,8 +212,8 @@
(chart (gnc:make-html-barchart))
(topl-accounts (gnc:filter-accountlist-type
account-types
- (xaccGroupGetAccountListSorted
- (gnc-get-current-group)))))
+ (gnc-account-get-children
+ (gnc-get-current-root-account)))))
;; Returns true if the account a was selected in the account
;; selection option.
@@ -227,7 +227,7 @@
(let* ((commodity-list #f)
(exchange-fn #f)
(tree-depth (if (equal? account-levels 'all)
- (gnc:get-current-group-depth)
+ (gnc:get-current-account-tree-depth)
account-levels))
;; This is the list of date intervals to calculate.
(dates-list (if do-intervals?
@@ -297,7 +297,7 @@
(for-each
(lambda (a)
(set! sum (+ sum (+ 1 (count-accounts (+ 1 current-depth)
- (gnc:account-get-immediate-subaccounts a))))))
+ (gnc-account-get-children a))))))
accts)
sum)
(length (filter show-acct? accts))))
@@ -331,7 +331,7 @@
(set! res (append
(traverse-accounts
(+ 1 current-depth)
- (gnc:account-get-immediate-subaccounts a))
+ (gnc-account-get-children a))
res))))
accts)
res)
@@ -487,7 +487,7 @@
other-anchor
(let* ((acct (car pair))
(subaccts
- (gnc:account-get-immediate-subaccounts acct)))
+ (gnc-account-get-children acct)))
(if (null? subaccts)
;; if leaf-account, make this an anchor
;; to the register.
Modified: gnucash/branches/remove-group2/src/report/standard-reports/daily-reports.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/daily-reports.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/daily-reports.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -102,7 +102,7 @@
(lambda ()
(gnc:filter-accountlist-type
account-types
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
(lambda (accounts)
(list #t
(gnc:filter-accountlist-type
@@ -314,8 +314,8 @@
(chart (gnc:make-html-piechart))
(topl-accounts (gnc:filter-accountlist-type
account-types
- (xaccGroupGetAccountListSorted
- (gnc-get-current-group)))))
+ (gnc-account-get-children
+ (gnc-get-current-root-account)))))
(define (monetary->double foreign-monetary date)
(gnc-numeric-to-double
@@ -391,7 +391,7 @@
(for-each
(lambda (acct)
(let ((this-acct-subs
- (gnc:account-get-all-subaccounts acct)))
+ (gnc-account-get-descendants acct)))
(if (list? this-acct-subs)
(set! subaccts
(append subaccts this-acct-subs)))))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/equity-statement.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/equity-statement.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/equity-statement.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -134,7 +134,7 @@
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL ACCT-TYPE-CURRENCY
ACCT-TYPE-PAYABLE ACCT-TYPE-RECEIVABLE
ACCT-TYPE-EQUITY ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
;; all about currencies
Modified: gnucash/branches/remove-group2/src/report/standard-reports/general-journal.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/general-journal.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/general-journal.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -70,7 +70,7 @@
(xaccQueryAddAccountMatch
query
- (xaccGroupGetSubAccountsSorted (gnc-book-get-template-group (gnc-get-current-book)))
+ (gnc-account-get-descendants (gnc-book-get-template-root (gnc-get-current-book)))
QOF-GUID-MATCH-NONE
QOF-QUERY-AND)
Modified: gnucash/branches/remove-group2/src/report/standard-reports/income-statement.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/income-statement.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/income-statement.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -158,7 +158,7 @@
(gnc:filter-accountlist-type
;; select, by default, only income and expense accounts
(list ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
(gnc:options-add-account-levels!
options gnc:pagename-accounts optname-depth-limit
@@ -347,7 +347,7 @@
;; is the only simple way to ensure that both tables
;; (revenue, expense) have the same width.
(tree-depth (if (equal? depth-limit 'all)
- (gnc:get-current-group-depth)
+ (gnc:get-current-account-tree-depth)
depth-limit))
;; exchange rates calculation parameters
(exchange-fn
@@ -411,7 +411,7 @@
(gnc:html-make-no-account-warning
reportname (gnc:report-id report-obj)))
- ;; Get all the balances for each account group.
+ ;; Get all the balances for each of the account types.
(let* ((revenue-closing #f)
(expense-closing #f)
(neg-revenue-total #f)
Modified: gnucash/branches/remove-group2/src/report/standard-reports/net-barchart.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/net-barchart.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/net-barchart.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -88,7 +88,7 @@
(if inc-exp?
gnc:account-is-inc-exp?
(lambda (account) (not (gnc:account-is-inc-exp? account))))
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
(lambda (accounts)
(list #t
(filter
Modified: gnucash/branches/remove-group2/src/report/standard-reports/portfolio.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/portfolio.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/portfolio.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -72,8 +72,8 @@
"b"
(N_ "Stock Accounts to report on")
(lambda () (filter gnc:account-is-stock?
- (xaccGroupGetSubAccountsSorted
- (gnc-get-current-group))))
+ (gnc-account-get-descendants
+ (gnc-get-current-root-account))))
(lambda (accounts) (list #t
(filter gnc:account-is-stock? accounts)))
#t))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/price-scatter.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/price-scatter.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/price-scatter.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -166,8 +166,8 @@
(document (gnc:make-html-document))
(chart (gnc:make-html-scatter))
(currency-accounts
- (filter gnc:account-has-shares? (xaccGroupGetSubAccountsSorted
- (gnc-get-current-group))))
+ (filter gnc:account-has-shares? (gnc-account-get-descendants
+ (gnc-get-current-root-account))))
(data '()))
;; Short helper for all the warnings below
Modified: gnucash/branches/remove-group2/src/report/standard-reports/transaction.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/transaction.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/transaction.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -577,7 +577,7 @@
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL ACCT-TYPE-CURRENCY
ACCT-TYPE-PAYABLE ACCT-TYPE-RECEIVABLE
ACCT-TYPE-EQUITY ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
(gnc:register-trep-option
@@ -587,10 +587,9 @@
(lambda ()
;; FIXME : gnc:get-current-accounts disappeared.
(let ((current-accounts '())
- (num-accounts (xaccGroupGetNumAccounts
- (gnc-get-current-group)))
- (first-account (xaccGroupGetAccount
- (gnc-get-current-group) 0)))
+ (root (gnc-get-current-root-account))
+ (num-accounts (gnc-account-n-children root))
+ (first-account (gnc-account-nth-child root 0)))
(cond ((not (null? current-accounts))
(list (car current-accounts)))
((> num-accounts 0) (list first-account))
Modified: gnucash/branches/remove-group2/src/report/standard-reports/trial-balance.scm
===================================================================
--- gnucash/branches/remove-group2/src/report/standard-reports/trial-balance.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/report/standard-reports/trial-balance.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -185,7 +185,7 @@
ACCT-TYPE-STOCK ACCT-TYPE-MUTUAL ACCT-TYPE-CURRENCY
ACCT-TYPE-PAYABLE ACCT-TYPE-RECEIVABLE
ACCT-TYPE-EQUITY ACCT-TYPE-INCOME ACCT-TYPE-EXPENSE)
- (xaccGroupGetSubAccountsSorted (gnc-get-current-group))))
+ (gnc-account-get-descendants (gnc-get-current-root-account))))
#f #t))
(gnc:options-add-account-levels!
options gnc:pagename-accounts optname-depth-limit
Modified: gnucash/branches/remove-group2/src/scm/price-quotes.scm
===================================================================
--- gnucash/branches/remove-group2/src/scm/price-quotes.scm 2006-10-31 03:45:13 UTC (rev 15065)
+++ gnucash/branches/remove-group2/src/scm/price-quotes.scm 2006-11-01 00:01:35 UTC (rev 15066)
@@ -600,8 +600,7 @@
;; FIXME: uses of gnc:warn in here need to be cleaned up. Right
;; now, they'll result in funny formatting.
- (let* ((group (xaccGetAccountGroup book))
- (fq-call-data (book->commodity->fq-call-data book))
+ (let* ((fq-call-data (book->commodity->fq-call-data book))
(fq-calls (and fq-call-data
(apply append
(map fq-call-data->fq-calls fq-call-data))))
More information about the gnucash-changes
mailing list