diff --git a/src/FileDialog.c b/src/FileDialog.c index 549c80dc15..d7dc07d307 100644 --- a/src/FileDialog.c +++ b/src/FileDialog.c @@ -171,7 +171,7 @@ gncFileQuerySave (void) * up the file-selection dialog, we don't blow em out of the water; * instead, give them another chance to say "no" to the verify box. */ - while ( xaccAccountGroupNotSaved (grp) ) + while ( xaccGroupNotSaved (grp) ) { GNCVerifyResult result; @@ -383,7 +383,7 @@ gncFileSave (void) /* going down -- abandon ship */ if (uh_oh) return; - xaccAccountGroupMarkSaved (topgroup); + xaccGroupMarkSaved (topgroup); } /* ======================================================== */ diff --git a/src/engine/Account.c b/src/engine/Account.c index 343e29c6b3..161b23f8b1 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -100,6 +100,7 @@ xaccInitAccount (Account * acc) acc->changed = 0; acc->open = 0; + acc->mark = 0; } /********************************************************************\ @@ -193,6 +194,7 @@ xaccFreeAccount( Account *acc ) acc->changed = 0; acc->open = 0; + acc->mark = 0; _free(acc); } @@ -269,6 +271,68 @@ xaccGetAccountFlags (Account *acc) return acc->flags; } +/********************************************************************\ +\********************************************************************/ + +short +xaccAccountGetMark (Account *acc) +{ + if (!acc) return 0; + return acc->mark; +} + +void +xaccAccountSetMark (Account *acc, short m) +{ + if (!acc) return; + acc->mark = m; +} + +void +xaccClearMark (Account *acc, short val) +{ + AccountGroup *topgrp; + + if (!acc) return; + topgrp = xaccGetAccountRoot (acc); + if (topgrp) { + int i, nacc = topgrp->numAcc; + for (i=0; iaccount[i], val); + } + } else { + xaccClearMarkDown (acc, val); + } +} + +void +xaccClearMarkDown (Account *acc, short val) +{ + AccountGroup *chillin; + if (!acc) return; + acc->mark = val; + + chillin = acc->children; + if (chillin) { + int i, nacc = chillin->numAcc; + for (i=0; iaccount[i], val); + } + } +} + +void +xaccClearMarkDownGr (AccountGroup *grp, short val) +{ + int i, nacc; + if (!grp) return; + nacc = grp->numAcc; + for (i=0; iaccount[i], val); + } +} + + /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Account.h b/src/engine/Account.h index 9d758950fb..d9c2c258d8 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -64,6 +64,11 @@ const GUID * xaccAccountGetGUID (Account *account); Account * xaccAccountLookup (const GUID *guid); int xaccGetAccountID (Account *); + +/* AccountFlags is currently not used for anything. + * If you need to add a bitflag, this may not be a bad + * way to go. This flag *is* stored in the file-file DB. + */ char xaccGetAccountFlags (Account *); /* @@ -182,4 +187,21 @@ gncBoolean xaccAccountsHaveCommonCurrency(Account *account_1, * Returns false if either is NULL. */ gncBoolean xaccAccountHasAncestor (Account *, Account * ancestor); +/* Get and Set a mark on the account. The meaning of this mark is + * completely undefined. Its presented here as a utility for the + * programmer, to use as desired. Handy for performing customer traversals + * over the account tree. The mark is *not* stored in the database/file + * format. When accounts are newly created, the mark is set to zero. + * + * The xaccClearMark will find the topmost group, and clear the mark in + * the entire group tree. + * The xaccClearMarkDown will clear the mark inly in this and in + * sub-accounts. + */ +short xaccAccountGetMark (Account *acc); +void xaccAccountSetMark (Account *acc, short mark); +void xaccClearMark (Account *, short val); +void xaccClearMarkDown (Account *, short val); +void xaccClearMarkDownGr (AccountGroup *, short val); + #endif /* __XACC_ACCOUNT_H__ */ diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index 0e54cb9b8e..7d3c982f31 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -117,6 +117,10 @@ struct _account { * various housekeeping operations by the engine. */ int id; /* unique account id, internally assigned */ + + /* the 'flags' field is currently unused. If you need some + * persistant flags, this is it. It *is* stored in the flat-file DB. + */ char flags; /* protected data, cached parameters */ @@ -132,13 +136,18 @@ struct _account { Split **splits; /* ptr to array of ptrs to splits */ /* The "changed" flag is used to invalidate cached values in this structure. - * currently, the balances and the cost basis are cached. + * Currently, the balances and the cost basis are cached. */ short changed; - /* the "open" flag indicates if the account has been + /* The "open" flag indicates if the account has been * opened for editing. */ short open; + + /* The "mark" flag can be used by the user to mark this account + * in any way desired. Handy for specialty traversals of the + * account tree. */ + short mark; }; /* bitfields for the changed flag */ diff --git a/src/engine/FileIO.c b/src/engine/FileIO.c index f16fe7bb7f..273d7787ae 100644 --- a/src/engine/FileIO.c +++ b/src/engine/FileIO.c @@ -350,7 +350,7 @@ xaccReadAccountGroup( int fd ) /* 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. */ - xaccAccountGroupMarkSaved (grp); + xaccGroupMarkSaved (grp); /* auto-number the accounts, if they are not already numbered */ xaccGroupDepthAutoCode (grp); diff --git a/src/engine/Group.c b/src/engine/Group.c index 52eebadb0e..74eedee015 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -112,7 +112,7 @@ xaccFreeAccountGroup( AccountGroup *grp ) \********************************************************************/ void -xaccAccountGroupMarkSaved (AccountGroup *grp) +xaccGroupMarkSaved (AccountGroup *grp) { int i; @@ -120,7 +120,7 @@ xaccAccountGroupMarkSaved (AccountGroup *grp) grp->saved = GNC_T; for (i=0; inumAcc; i++) { - xaccAccountGroupMarkSaved (grp->account[i]->children); + xaccGroupMarkSaved (grp->account[i]->children); } } @@ -128,7 +128,7 @@ xaccAccountGroupMarkSaved (AccountGroup *grp) \********************************************************************/ void -xaccAccountGroupMarkNotSaved (AccountGroup *grp) +xaccGroupMarkNotSaved (AccountGroup *grp) { if (!grp) return; grp->saved = GNC_F; @@ -136,8 +136,9 @@ xaccAccountGroupMarkNotSaved (AccountGroup *grp) /********************************************************************\ \********************************************************************/ + int -xaccAccountGroupNotSaved (AccountGroup *grp) +xaccGroupNotSaved (AccountGroup *grp) { int not_saved; int i; @@ -146,7 +147,7 @@ xaccAccountGroupNotSaved (AccountGroup *grp) if (GNC_F == grp->saved) return 1; for (i=0; inumAcc; i++) { - not_saved = xaccAccountGroupNotSaved (grp->account[i]->children); + not_saved = xaccGroupNotSaved (grp->account[i]->children); if (not_saved) return 1; } return 0; @@ -154,6 +155,7 @@ xaccAccountGroupNotSaved (AccountGroup *grp) /********************************************************************\ \********************************************************************/ + const GUID * xaccGroupGetGUID (AccountGroup *group) { @@ -165,7 +167,9 @@ xaccGroupGetGUID (AccountGroup *group) /********************************************************************\ \********************************************************************/ -void xaccGroupSetGUID (AccountGroup *group, GUID *guid) + +void +xaccGroupSetGUID (AccountGroup *group, GUID *guid) { if (!group || !guid) return; diff --git a/src/engine/Group.h b/src/engine/Group.h index 055964cea4..1a0aefa56e 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -59,20 +59,20 @@ void xaccConcatGroups (AccountGroup *to, AccountGroup *from); void xaccMergeAccounts (AccountGroup *grp); /* - * The xaccAccountGroupNotSaved() subroutine will return + * The xaccGroupNotSaved() subroutine will return * a non-zero value if any account in the group or in * any subgroup hasn't been saved. * - * The xaccAccountGroupMarkSaved() subroutine will mark + * The xaccGroupMarkSaved() subroutine will mark * the entire group as having been saved, including * all of the child accounts. * - * The xaccAccountGroupMarkNotSaved() subroutine will mark + * The xaccGroupMarkNotSaved() subroutine will mark * the given group as not having been saved. */ -int xaccAccountGroupNotSaved (AccountGroup *grp); -void xaccAccountGroupMarkSaved (AccountGroup *grp); -void xaccAccountGroupMarkNotSaved (AccountGroup *grp); +int xaccGroupNotSaved (AccountGroup *grp); +void xaccGroupMarkSaved (AccountGroup *grp); +void xaccGroupMarkNotSaved (AccountGroup *grp); /* * The xaccRemoveAccount() subroutine will remove the indicated diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index 476e12422d..8d988c16a5 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -243,10 +243,10 @@ xaccConfigGetForceDoubleEntry (void) /********************************************************************\ \********************************************************************/ -#define MARK_SPLIT(split) { \ - Account *acc = (Account *) ((split)->acc); \ - if (acc) acc->changed |= ACC_INVALIDATE_ALL; \ - if (acc) xaccAccountGroupMarkNotSaved(acc->parent); \ +#define MARK_SPLIT(split) { \ + Account *acc = (Account *) ((split)->acc); \ + if (acc) acc->changed |= ACC_INVALIDATE_ALL; \ + if (acc) xaccGroupMarkNotSaved(acc->parent); \ } static void