mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Move entity tables into sessions.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5483 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
ba19fb2327
commit
654c4cb31e
@ -561,7 +561,6 @@ gnc_file_save_as (void)
|
||||
{
|
||||
GNCSession *new_session;
|
||||
GNCSession *session;
|
||||
GNCBook *book;
|
||||
const char *filename;
|
||||
char *newfile;
|
||||
const char *oldfile;
|
||||
@ -592,11 +591,6 @@ gnc_file_save_as (void)
|
||||
|
||||
/* -- this session code is NOT identical in FileOpen and FileSaveAs -- */
|
||||
|
||||
/* FIXME: this might want to be a function of the GNCSession, since
|
||||
* it needs to sync with changes to the internals/structure of
|
||||
* GNCSession. */
|
||||
book = gnc_session_get_book (session);
|
||||
|
||||
new_session = gnc_session_new ();
|
||||
gnc_session_begin (new_session, newfile, FALSE, FALSE);
|
||||
|
||||
@ -638,8 +632,9 @@ gnc_file_save_as (void)
|
||||
|
||||
/* if we got to here, then we've successfully gotten a new session */
|
||||
/* close up the old file session (if any) */
|
||||
gnc_session_set_book (session, NULL);
|
||||
gnc_session_swap_data (session, new_session);
|
||||
gnc_session_destroy (session);
|
||||
session = NULL;
|
||||
|
||||
current_session = new_session;
|
||||
|
||||
@ -667,9 +662,6 @@ gnc_file_save_as (void)
|
||||
/* Whoa-ok. Blow away the previous file. */
|
||||
}
|
||||
|
||||
/* OK, save the data to the file ... */
|
||||
gnc_session_set_book (new_session, book);
|
||||
|
||||
gnc_file_save ();
|
||||
|
||||
g_free (newfile);
|
||||
|
@ -562,8 +562,7 @@ xaccAccountLookupEntityTable (const GUID *guid,
|
||||
GNCEntityTable *entity_table)
|
||||
{
|
||||
if (!guid) return NULL;
|
||||
/* FIXME: uncomment when entity tables are in sessions */
|
||||
/* g_return_val_if_fail (entity_table, NULL); */
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
return xaccLookupEntity (entity_table, guid, GNC_ID_ACCOUNT);
|
||||
}
|
||||
|
||||
@ -662,6 +661,9 @@ xaccAccountInsertSplit (Account *acc, Split *split)
|
||||
if (!acc) return;
|
||||
if (!split) return;
|
||||
|
||||
/* check for session mix-up */
|
||||
g_return_if_fail (acc->entity_table == split->entity_table);
|
||||
|
||||
xaccAccountBeginEdit(acc);
|
||||
|
||||
acc->balance_dirty = TRUE;
|
||||
|
@ -674,7 +674,7 @@ xaccFreqSpecGetMonthly( FreqSpec *fs, int *outRepeat, int *outDayOfMonth, int *o
|
||||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: add month-relative getter
|
||||
/* FIXME: add month-relative getter */
|
||||
|
||||
GList*
|
||||
xaccFreqSpecCompositeGet( FreqSpec *fs )
|
||||
|
@ -42,9 +42,13 @@ typedef struct entity_node
|
||||
gpointer entity;
|
||||
} EntityNode;
|
||||
|
||||
struct gnc_entity_table
|
||||
{
|
||||
GHashTable * hash;
|
||||
};
|
||||
|
||||
|
||||
/** Static global variables *****************************************/
|
||||
static GHashTable * entity_table = NULL;
|
||||
static GMemChunk *guid_memchunk = NULL;
|
||||
static short module = MOD_ENGINE;
|
||||
|
||||
@ -98,16 +102,17 @@ entity_node_destroy(gpointer key, gpointer value, gpointer not_used)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
entity_table_destroy (void)
|
||||
void
|
||||
xaccEntityTableDestroy (GNCEntityTable *entity_table)
|
||||
{
|
||||
if (entity_table == NULL)
|
||||
return;
|
||||
|
||||
g_hash_table_foreach_remove(entity_table, entity_node_destroy, NULL);
|
||||
g_hash_table_destroy(entity_table);
|
||||
g_hash_table_foreach_remove (entity_table->hash, entity_node_destroy, NULL);
|
||||
g_hash_table_destroy (entity_table->hash);
|
||||
entity_table->hash = NULL;
|
||||
|
||||
entity_table = NULL;
|
||||
g_free (entity_table);
|
||||
}
|
||||
|
||||
static guint
|
||||
@ -156,33 +161,31 @@ print_node(gpointer key, gpointer value, gpointer not_used)
|
||||
}
|
||||
|
||||
static void
|
||||
summarize_table(void)
|
||||
summarize_table (GNCEntityTable *entity_table)
|
||||
{
|
||||
if (entity_table == NULL)
|
||||
return;
|
||||
|
||||
g_hash_table_foreach(entity_table, print_node, NULL);
|
||||
g_hash_table_foreach (entity_table->hash, print_node, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
entity_table_init(void)
|
||||
GNCEntityTable *
|
||||
xaccEntityTableNew (void)
|
||||
{
|
||||
if (entity_table != NULL)
|
||||
entity_table_destroy();
|
||||
GNCEntityTable *entity_table;
|
||||
|
||||
entity_table = g_hash_table_new(id_hash, id_compare);
|
||||
entity_table = g_new0 (GNCEntityTable, 1);
|
||||
|
||||
xaccStoreEntity(entity_table, NULL, xaccGUIDNULL(), GNC_ID_NULL);
|
||||
entity_table->hash = g_hash_table_new (id_hash, id_compare);
|
||||
|
||||
#if GNCID_DEBUG
|
||||
atexit(summarize_table);
|
||||
#endif
|
||||
xaccStoreEntity (entity_table, NULL, xaccGUIDNULL(), GNC_ID_NULL);
|
||||
|
||||
return entity_table;
|
||||
}
|
||||
|
||||
GNCIdType
|
||||
xaccGUIDTypeEntityTable (const GUID * guid,
|
||||
GNCEntityTable *entity_table_tmp)
|
||||
xaccGUIDTypeEntityTable (const GUID * guid, GNCEntityTable *entity_table)
|
||||
{
|
||||
EntityNode *e_node;
|
||||
GNCIdType entity_type;
|
||||
@ -190,12 +193,9 @@ xaccGUIDTypeEntityTable (const GUID * guid,
|
||||
if (guid == NULL)
|
||||
return GNC_ID_NONE;
|
||||
|
||||
if (entity_table == NULL)
|
||||
entity_table_init();
|
||||
|
||||
g_return_val_if_fail (entity_table, GNC_ID_NONE);
|
||||
|
||||
e_node = g_hash_table_lookup(entity_table, guid->data);
|
||||
e_node = g_hash_table_lookup (entity_table->hash, guid->data);
|
||||
if (e_node == NULL)
|
||||
return GNC_ID_NONE;
|
||||
|
||||
@ -207,7 +207,7 @@ xaccGUIDTypeEntityTable (const GUID * guid,
|
||||
}
|
||||
|
||||
GNCIdType
|
||||
xaccGUIDType(const GUID * guid, GNCSession *session)
|
||||
xaccGUIDType (const GUID * guid, GNCSession *session)
|
||||
{
|
||||
return xaccGUIDTypeEntityTable (guid,
|
||||
gnc_session_get_entity_table (session));
|
||||
@ -219,8 +219,7 @@ xaccGUIDNewEntityTable (GUID *guid, GNCEntityTable *entity_table)
|
||||
if (guid == NULL)
|
||||
return;
|
||||
|
||||
/* FIXME */
|
||||
/* g_return_if_fail (entity_table); */
|
||||
g_return_if_fail (entity_table);
|
||||
|
||||
do
|
||||
{
|
||||
@ -269,18 +268,17 @@ xaccGUIDNULL(void)
|
||||
}
|
||||
|
||||
gpointer
|
||||
xaccLookupEntity (GNCEntityTable *entity_table_tmp,
|
||||
xaccLookupEntity (GNCEntityTable *entity_table,
|
||||
const GUID * guid, GNCIdType entity_type)
|
||||
{
|
||||
EntityNode *e_node;
|
||||
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
|
||||
if (guid == NULL)
|
||||
return NULL;
|
||||
|
||||
if (entity_table == NULL)
|
||||
entity_table_init();
|
||||
|
||||
e_node = g_hash_table_lookup(entity_table, guid->data);
|
||||
e_node = g_hash_table_lookup (entity_table->hash, guid->data);
|
||||
if (e_node == NULL)
|
||||
return NULL;
|
||||
|
||||
@ -291,12 +289,14 @@ xaccLookupEntity (GNCEntityTable *entity_table_tmp,
|
||||
}
|
||||
|
||||
void
|
||||
xaccStoreEntity (GNCEntityTable *entity_table_tmp, gpointer entity,
|
||||
xaccStoreEntity (GNCEntityTable *entity_table, gpointer entity,
|
||||
const GUID * guid, GNCIdType entity_type)
|
||||
{
|
||||
EntityNode *e_node;
|
||||
GUID *new_guid;
|
||||
|
||||
g_return_if_fail (entity_table);
|
||||
|
||||
if (guid == NULL)
|
||||
return;
|
||||
|
||||
@ -305,54 +305,40 @@ xaccStoreEntity (GNCEntityTable *entity_table_tmp, gpointer entity,
|
||||
|
||||
if (guid_equal(guid, xaccGUIDNULL())) return;
|
||||
|
||||
xaccRemoveEntity(entity_table, guid);
|
||||
xaccRemoveEntity (entity_table, guid);
|
||||
|
||||
e_node = g_new(EntityNode, 1);
|
||||
e_node->entity_type = entity_type;
|
||||
e_node->entity = entity;
|
||||
|
||||
new_guid = xaccGUIDMalloc();
|
||||
new_guid = xaccGUIDMalloc ();
|
||||
|
||||
if(!new_guid) return;
|
||||
if (!new_guid) return;
|
||||
|
||||
*new_guid = *guid;
|
||||
|
||||
g_hash_table_insert(entity_table, new_guid, e_node);
|
||||
g_hash_table_insert (entity_table->hash, new_guid, e_node);
|
||||
}
|
||||
|
||||
void
|
||||
xaccRemoveEntity (GNCEntityTable *entity_table_tmp, const GUID * guid)
|
||||
xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid)
|
||||
{
|
||||
EntityNode *e_node;
|
||||
gpointer old_guid;
|
||||
gpointer node;
|
||||
|
||||
g_return_if_fail (entity_table);
|
||||
|
||||
if (guid == NULL)
|
||||
return;
|
||||
|
||||
if (entity_table == NULL)
|
||||
entity_table_init();
|
||||
|
||||
if (g_hash_table_lookup_extended(entity_table, guid, &old_guid, &node))
|
||||
if (g_hash_table_lookup_extended(entity_table->hash, guid, &old_guid, &node))
|
||||
{
|
||||
e_node = node;
|
||||
if (e_node->entity_type == GNC_ID_NULL)
|
||||
return;
|
||||
|
||||
g_hash_table_remove(entity_table, old_guid);
|
||||
entity_node_destroy(old_guid, node, NULL);
|
||||
g_hash_table_remove (entity_table->hash, old_guid);
|
||||
entity_node_destroy (old_guid, node, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
GHashTable *
|
||||
xaccGetAndResetEntityTable(void) {
|
||||
GHashTable *result = entity_table;
|
||||
entity_table = NULL;
|
||||
return(result);
|
||||
}
|
||||
|
||||
void
|
||||
xaccSetEntityTable(GHashTable *et) {
|
||||
if(entity_table) entity_table_destroy();
|
||||
entity_table = et;
|
||||
}
|
||||
|
@ -32,7 +32,11 @@
|
||||
/* This file defines an engine-only API for using gnucash entity
|
||||
* identifiers. */
|
||||
|
||||
typedef GHashTable GNCEntityTable;
|
||||
typedef struct gnc_entity_table GNCEntityTable;
|
||||
|
||||
/* Create and destroy entity tables */
|
||||
GNCEntityTable * xaccEntityTableNew (void);
|
||||
void xaccEntityTableDestroy (GNCEntityTable *table);
|
||||
|
||||
/* Generate a new id. This function is guaranteed to return an id that
|
||||
* is unique within the scope of all GnuCash entities being managed by
|
||||
@ -60,9 +64,6 @@ void xaccRemoveEntity (GNCEntityTable *entity_table, const GUID * guid);
|
||||
GNCIdType xaccGUIDTypeEntityTable (const GUID * guid,
|
||||
GNCEntityTable *entity_table);
|
||||
|
||||
GHashTable *xaccGetAndResetEntityTable (void);
|
||||
void xaccSetEntityTable (GHashTable *et);
|
||||
|
||||
/* Initialize and shutdown the GNC Id system. */
|
||||
void xaccGUIDInit (void);
|
||||
void xaccGUIDShutdown (void);
|
||||
|
@ -74,8 +74,7 @@ xaccMallocAccountGroupEntityTable (GNCEntityTable *entity_table)
|
||||
{
|
||||
AccountGroup *grp;
|
||||
|
||||
/* FIXME: uncomment when entity tables are finally in sessions. */
|
||||
/* g_return_val_if_fail (entity_table, NULL); */
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
|
||||
grp = g_new (AccountGroup, 1);
|
||||
|
||||
@ -650,8 +649,7 @@ xaccAccountInsertSubAccount (Account *adult, Account *child)
|
||||
{
|
||||
if (!adult || !child) return;
|
||||
|
||||
/* FIXME: uncomment when entity tables are finished. */
|
||||
/* g_return_if_fail (adult->entity_table); */
|
||||
g_return_if_fail (adult->entity_table);
|
||||
g_return_if_fail (adult->entity_table == child->entity_table);
|
||||
|
||||
/* if a container for the children doesn't yet exist, add it */
|
||||
@ -691,6 +689,8 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc)
|
||||
if (!grp) return;
|
||||
if (!acc) return;
|
||||
|
||||
g_return_if_fail (grp->entity_table == acc->entity_table);
|
||||
|
||||
/* 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
|
||||
@ -727,6 +727,8 @@ xaccGroupConcatGroup (AccountGroup *togrp, AccountGroup *fromgrp)
|
||||
if (!togrp) return;
|
||||
if (!fromgrp) return;
|
||||
|
||||
g_return_if_fail (togrp->entity_table == fromgrp->entity_table);
|
||||
|
||||
/* The act of inserting the account into togrp also causes it to
|
||||
* automatically be deleted from fromgrp. Be careful! */
|
||||
|
||||
|
@ -132,9 +132,7 @@ xaccMallocSplitEntityTable (GNCEntityTable *entity_table)
|
||||
{
|
||||
Split *split;
|
||||
|
||||
/* FIXME: uncomment this when done with moving entity
|
||||
* tables into sessions. */
|
||||
/* g_return_val_if_fail (entity_table, NULL); */
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
|
||||
split = g_new (Split, 1);
|
||||
xaccInitSplit (split, entity_table);
|
||||
@ -162,23 +160,24 @@ xaccCloneSplit (Split *s)
|
||||
{
|
||||
Split *split = g_new0 (Split, 1);
|
||||
|
||||
/* copy(!) the guid. The cloned split is *not* unique,
|
||||
/* copy(!) the guid and entity table. The cloned split is *not* unique,
|
||||
* is a sick twisted clone that holds 'undo' information. */
|
||||
split->guid = s->guid;
|
||||
split->entity_table = s->entity_table;
|
||||
|
||||
xaccSplitSetAccountGUID(split, s->acc_guid);
|
||||
split->parent = s->parent;
|
||||
split->parent = s->parent;
|
||||
|
||||
split->memo = g_cache_insert (gnc_engine_get_string_cache(), s->memo);
|
||||
split->action = g_cache_insert (gnc_engine_get_string_cache(), s->action);
|
||||
split->memo = g_cache_insert (gnc_engine_get_string_cache(), s->memo);
|
||||
split->action = g_cache_insert (gnc_engine_get_string_cache(), s->action);
|
||||
|
||||
split->kvp_data = kvp_frame_copy (s->kvp_data);
|
||||
split->kvp_data = kvp_frame_copy (s->kvp_data);
|
||||
|
||||
split->reconciled = s->reconciled;
|
||||
split->reconciled = s->reconciled;
|
||||
split->date_reconciled = s->date_reconciled;
|
||||
|
||||
split->value = s->value;
|
||||
split->amount = s->amount;
|
||||
split->value = s->value;
|
||||
split->amount = s->amount;
|
||||
|
||||
/* no need to futz with the balances; these get wiped each time ...
|
||||
* split->balance = s->balance;
|
||||
@ -377,8 +376,7 @@ Split *
|
||||
xaccSplitLookupEntityTable (const GUID *guid, GNCEntityTable *entity_table)
|
||||
{
|
||||
if (!guid) return NULL;
|
||||
/* FIXME: uncomment soon */
|
||||
/* g_return_val_if_fail (entity_table, NULL); */
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
return xaccLookupEntity(entity_table, guid, GNC_ID_SPLIT);
|
||||
}
|
||||
|
||||
@ -726,9 +724,11 @@ xaccCloneTransaction (Transaction *t)
|
||||
trans->do_free = FALSE;
|
||||
trans->orig = NULL;
|
||||
|
||||
/* copy(!) the guid. The cloned transaction is *not* unique,
|
||||
* is a sick twisted clone that holds 'undo' information. */
|
||||
/* copy(!) the guid and entity table. The cloned transaction is
|
||||
* *not* unique, is a sick twisted clone that holds 'undo'
|
||||
* information. */
|
||||
trans->guid = t->guid;
|
||||
trans->entity_table = t->entity_table;
|
||||
|
||||
return trans;
|
||||
}
|
||||
@ -904,8 +904,7 @@ Transaction *
|
||||
xaccTransLookupEntityTable (const GUID *guid,
|
||||
GNCEntityTable *entity_table)
|
||||
{
|
||||
/* FIXME: uncomment when entity tables are in sessions */
|
||||
/* g_return_val_if_fail (entity_table, NULL); */
|
||||
g_return_val_if_fail (entity_table, NULL);
|
||||
return xaccLookupEntity (entity_table, guid, GNC_ID_TRANS);
|
||||
}
|
||||
|
||||
@ -1781,6 +1780,7 @@ xaccTransAppendSplit (Transaction *trans, Split *split)
|
||||
Transaction *oldtrans;
|
||||
|
||||
if (!trans || !split) return;
|
||||
g_return_if_fail (trans->entity_table == split->entity_table);
|
||||
check_open (trans);
|
||||
|
||||
/* first, make sure that the split isn't already inserted
|
||||
@ -1959,7 +1959,8 @@ get_corr_account_split(Split *sa, Split **retval)
|
||||
sa_value = xaccSplitGetValue(sa);
|
||||
sa_value_positive = gnc_numeric_positive_p(sa_value);
|
||||
|
||||
for(split_list = xaccTransGetSplitList(ta);split_list; split_list = split_list->next)
|
||||
for (split_list = xaccTransGetSplitList(ta);
|
||||
split_list; split_list = split_list->next)
|
||||
{
|
||||
current_split = split_list->data;
|
||||
if(current_split != sa)
|
||||
|
@ -119,8 +119,8 @@ gnc_session_init (GNCSession *session)
|
||||
{
|
||||
if (!session) return;
|
||||
|
||||
session->entity_table = xaccEntityTableNew ();
|
||||
session->book = gnc_book_new (session);
|
||||
session->entity_table = NULL;
|
||||
session->book_id = NULL;
|
||||
session->fullpath = NULL;
|
||||
session->logpath = NULL;
|
||||
@ -573,6 +573,9 @@ gnc_session_destroy (GNCSession *session)
|
||||
gnc_book_destroy (session->book);
|
||||
session->book = NULL;
|
||||
|
||||
xaccEntityTableDestroy (session->entity_table);
|
||||
session->entity_table = NULL;
|
||||
|
||||
xaccLogEnable();
|
||||
|
||||
g_free (session);
|
||||
@ -580,6 +583,28 @@ gnc_session_destroy (GNCSession *session)
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
void
|
||||
gnc_session_swap_data (GNCSession *session_1, GNCSession *session_2)
|
||||
{
|
||||
GNCBook *book_1, *book_2;
|
||||
GNCEntityTable *entity_table_1, *entity_table_2;
|
||||
|
||||
if (session_1 == session_2) return;
|
||||
if (!session_1 || !session_2) return;
|
||||
|
||||
book_1 = session_1->book;
|
||||
entity_table_1 = session_1->entity_table;
|
||||
|
||||
book_2 = session_2->book;
|
||||
entity_table_2 = session_2->entity_table;
|
||||
|
||||
session_1->book = book_2;
|
||||
session_1->entity_table = entity_table_2;
|
||||
|
||||
session_2->book = book_1;
|
||||
session_2->entity_table = entity_table_1;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_session_events_pending (GNCSession *session)
|
||||
{
|
||||
@ -839,7 +864,7 @@ xaccResolveURL (const char * pathfrag)
|
||||
* resolved. If there's an error connecting, we'll find out later.
|
||||
*
|
||||
* FIXME -- we should probably use ghttp_uri_validate
|
||||
* to make sure hte uri is in good form...
|
||||
* to make sure the uri is in good form.
|
||||
*/
|
||||
|
||||
if (!g_strncasecmp (pathfrag, "http://", 7) ||
|
||||
|
@ -60,8 +60,14 @@
|
||||
GNCSession * gnc_session_new (void);
|
||||
void gnc_session_destroy (GNCSession *session);
|
||||
|
||||
/* The gnc_session_begin () method begins a new session. It takes as an argument
|
||||
* the book id. The book id must be a string in the form of a URI/URL.
|
||||
/* The gnc_session_swap_data () method swaps the book and
|
||||
* entity tables of the two given sessions. It is useful
|
||||
* for 'Save As' type functionality. */
|
||||
void gnc_session_swap_data (GNCSession *session_1, GNCSession *session_2);
|
||||
|
||||
/* The gnc_session_begin () method begins a new session.
|
||||
* It takes as an argument the book id. The book id must be a string
|
||||
* in the form of a URI/URL.
|
||||
* In the current implementation, the following URL's are supported
|
||||
* -- File URI of the form
|
||||
* "file:/home/somewhere/somedir/file.xac"
|
||||
|
Loading…
Reference in New Issue
Block a user