From 21e5d5f3296e379da7120ecaf13f293598084b91 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 25 Nov 2001 05:38:23 +0000 Subject: [PATCH] use kvp's to identify sibling copies of accounts git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6043 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Group.c | 62 +++++++++++++++++++++++++++++++++++++++++- src/engine/Group.h | 2 ++ src/engine/kvp_doc.txt | 34 +++++++++++++++++++++-- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/engine/Group.c b/src/engine/Group.c index db87cb369d..4f3841052c 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -1,7 +1,7 @@ /********************************************************************\ * Group.c -- chart of accounts (hierarchical tree of accounts) * * Copyright (C) 1997 Robin D. Clark * - * Copyright (C) 1997-2000 Linas Vepstas * + * Copyright (C) 1997-2001 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 * @@ -789,21 +789,81 @@ xaccGroupConcatGroup (AccountGroup *togrp, AccountGroup *fromgrp) /********************************************************************\ \********************************************************************/ +/* mark the guid and date of the copy, using kvp. The info will be + * places in /gemini/ncopies, /gemini//guid, /gemini//date, + * where = ncopies-1. + */ + + +static void +gemini (kvp_frame *kvp_root, const GUID *guid, time_t secs) +{ + char buff[80]; + kvp_frame *cwd, *pwd; + kvp_value *v_ncopies, *vvv; + gint64 ncopies = 0; + Timespec ts; + + /* cwd == 'current working directory' */ + pwd = kvp_frame_get_frame (kvp_root, "gemini"); + if (!pwd) + { + pwd = kvp_frame_new(); + kvp_frame_set_slot_nc (kvp_root, + "gemini", kvp_value_new_frame(pwd)); + } + + /* find, increment, store number of copies */ + v_ncopies = kvp_frame_get_slot (pwd, "ncopies"); + if (v_ncopies) + { + ncopies = kvp_value_get_gint64 (v_ncopies); + } + + ncopies ++; + v_ncopies = kvp_value_new_gint64 (ncopies); + kvp_frame_set_slot_nc (pwd, "ncopies", v_ncopies); + + /* OK, now create subdirectory and put the actual data */ + --ncopies; + sprintf (buff, "%lld", ncopies); + cwd = kvp_frame_new(); + kvp_frame_set_slot_nc(pwd, buff, kvp_value_new_frame(cwd)); + + vvv = kvp_value_new_guid (guid); + kvp_frame_set_slot_nc (cwd, "guid", vvv); + + ts.tv_sec = secs; + ts.tv_nsec = 0; + vvv = kvp_value_new_timespec (ts); + kvp_frame_set_slot_nc (cwd, "date", vvv); +} void xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) { + time_t now; GList *node; if (!to || !from) return; if (!from->accounts || !to->book) return; + now = time(0); 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. */ to_acc = xaccCloneAccountSimple (from_acc, to->book); xaccAccountBeginEdit (to_acc); to->accounts = g_list_append (to->accounts, to_acc); + + /* put in markers giving relationships */ + gemini (to_acc->kvp_data, &from_acc->guid, now); + gemini (from_acc->kvp_data, &to_acc->guid, now); + + /* copy child accounts too. */ if (from_acc->children) { to_acc->children = xaccMallocAccountGroup (to->book); diff --git a/src/engine/Group.h b/src/engine/Group.h index aa209a297f..04d917a68f 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -53,6 +53,8 @@ void xaccAccountGroupCommitEdit (AccountGroup *grp); * from the "from" group to the "to" group, preserving the * account heirarchy. It will also take care that the moved * accounts will have the "to" groups book parent as well. + * This routine will *NOT* copy any splits/transactions. + * It will copy the KVP tree. * * The xaccGroupMergeAccounts() subroutine will go through a group, * merging all accounts that have the same name and description. diff --git a/src/engine/kvp_doc.txt b/src/engine/kvp_doc.txt index 20341f3bba..df84d7f21a 100644 --- a/src/engine/kvp_doc.txt +++ b/src/engine/kvp_doc.txt @@ -42,6 +42,34 @@ Entities: Transaction Use: Identifies that the Transaction was created from a ScheduledTransaction, and stores the GUID of that SX. +Name: /gemini/ +Type: kvp_frame +Entities: Accounts +Use: subdirectory holding identification of accounts that are copies + of this account. + +Name: /gemini/ncopies +Type: int64 +Entities: Accounts +Use: number of subdirectories containing copy info. + +Name: /gemini/0/ +Type: kvp_frame +Entities: Accounts +Use: subdirectory holding identification of the first copied account. + Other copies would appear in directories /gemini/1/, /gemini/2/, + etc. + +Name: /gemini/0/guid +Type: guid +Entities: Accounts +Use: guid of another account that is a copy of this one. + +Name: /gemini/0/date +Type: timespec +Entities: Accounts +Use: date that copy was created. + Name: last-num Type: string Entities: Account @@ -157,13 +185,13 @@ Type: gint64 Entities: Account Use: A boolean flag indicated whether the Account is tax-related. -Name: sched-xaction +Name: /sched-xaction/ Type: frame Entities: Split in a SchedXaction Use: Storage for the various fields of a scheduled transaction's template Splits. -Name: sched-xaction/account +Name: /sched-xaction/account Type: GUID Entities: Split associated with a SchedXaction Use: The GUID of this Split's xfrm account. @@ -173,7 +201,7 @@ Type: string Entities: Split associated with a SchedXaction Use: Store the formula for the credit side of the split -Name: sched-xaction/debit-formula +Name: /sched-xaction/debit-formula Type: string Entities: Split associated with a SchedXaction Use: Formula for the debit. Either the credit or the