r16689 - gnucash/branches/gda-dev/src/backend/gda - More common code merging - commodity/account/tx guids

Phil Longstaff plongstaff at cvs.gnucash.org
Wed Dec 19 22:31:11 EST 2007


Author: plongstaff
Date: 2007-12-19 22:31:10 -0500 (Wed, 19 Dec 2007)
New Revision: 16689
Trac: http://svn.gnucash.org/trac/changeset/16689

Modified:
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-backend-util-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
Log:
More common code merging - commodity/account/tx guids


Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -47,8 +47,6 @@
 
 #define TABLE_NAME "accounts"
 
-static gpointer get_commodity( gpointer pObject, const QofParam* );
-static void set_commodity( gpointer pObject, gpointer pValue );
 static gpointer get_parent( gpointer pObject, const QofParam* );
 static void set_parent( gpointer pObject, gpointer pValue );
 static void set_parent_guid( gpointer pObject, gpointer pValue );
@@ -63,9 +61,8 @@
     { "guid",           CT_GUID,   0,                           COL_NNUL, "guid" },
     { "name",           CT_STRING, ACCOUNT_MAX_NAME_LEN,        COL_NNUL, "name" },
     { "account_type",   CT_STRING, ACCOUNT_MAX_TYPE_LEN,        COL_NNUL, NULL, ACCOUNT_TYPE_ },
-//    { "commodity_guid", CT_GUID_C, 0,                           COL_NNUL, NULL, NULL, get_commodity, set_commodity },
     { "commodity_guid", CT_GUID_C, 0,                           COL_NNUL, "commodity" },
-    { "parent_guid",    CT_GUID_A, 0,                           0,        NULL, NULL, get_parent,    set_parent },
+    { "parent_guid",    CT_GUID,   0,                           0,        NULL, NULL, get_parent,    set_parent },
     { "code",           CT_STRING, ACCOUNT_MAX_CODE_LEN,        0,        "code" },
     { "description",    CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0,        "description" },
     { NULL }
@@ -82,27 +79,7 @@
 } account_parent_guid_struct;
 
 /* ================================================================= */
-static gpointer
-get_commodity( gpointer pObject, const QofParam* param )
-{
-    const Account* pAccount = GNC_ACCOUNT(pObject);
 
-    return (gpointer)qof_instance_get_guid(
-                        QOF_INSTANCE(xaccAccountGetCommodity( pAccount )) );
-}
-
-static void 
-set_commodity( gpointer pObject, gpointer pValue )
-{
-    Account* pAccount = GNC_ACCOUNT(pObject);
-    QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
-    gnc_commodity* pCommodity;
-    GUID* guid = (GUID*)pValue;
-
-    pCommodity = gnc_commodity_find_commodity_by_guid( guid, pBook );
-    xaccAccountSetCommodity( pAccount, pCommodity );
-}
-
 static gpointer
 get_parent( gpointer pObject, const QofParam* param )
 {

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-util-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-util-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-util-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -603,6 +603,7 @@
     const GValue* val;
     GUID guid;
     const GUID* pGuid;
+	Account* account = NULL;
 
     val = gda_data_model_get_value_at_col_name( pModel, table->col_name, row );
     if( gda_value_is_null( val ) ) {
@@ -611,10 +612,13 @@
         string_to_guid( g_value_get_string( val ), &guid );
         pGuid = &guid;
     }
+	if( pGuid != NULL ) {
+		account = xaccAccountLookup( pGuid, be->primary_book );
+	}
     if( table->gobj_param_name != NULL ) {
-		g_object_set( pObject, table->gobj_param_name, pGuid, NULL );
+		g_object_set( pObject, table->gobj_param_name, account, NULL );
     } else {
-		(*setter)( pObject, (const gpointer)pGuid );
+		(*setter)( pObject, (const gpointer)account );
     }
 }
 
@@ -623,17 +627,21 @@
                 const col_cvt_t* table_row, GValue* value )
 {
     QofAccessFunc getter;
-    const GUID* guid;
+    const GUID* guid = NULL;
     gchar guid_buf[GUID_ENCODING_LENGTH+1];
+	Account* account;
 
     memset( value, 0, sizeof( GValue ) );
 
 	if( table_row->gobj_param_name != NULL ) {
-		g_object_get( pObject, table_row->gobj_param_name, &guid, NULL );
+		g_object_get( pObject, table_row->gobj_param_name, &account, NULL );
 	} else {
     	getter = get_getter( obj_name, table_row );
-    	guid = (*getter)( pObject, NULL );
+    	account = (*getter)( pObject, NULL );
 	}
+	if( account != NULL ) {
+		guid = qof_instance_get_guid( QOF_INSTANCE(account) );
+	}
     if( guid != NULL ) {
         (void)guid_to_string_buff( guid, guid_buf );
         g_value_init( value, G_TYPE_STRING );
@@ -769,6 +777,7 @@
     const GValue* val;
     GUID guid;
     const GUID* pGuid;
+	Transaction* tx = NULL;
 
     val = gda_data_model_get_value_at_col_name( pModel, table->col_name, row );
     if( gda_value_is_null( val ) ) {
@@ -777,10 +786,13 @@
         string_to_guid( g_value_get_string( val ), &guid );
         pGuid = &guid;
     }
+	if( pGuid != NULL ) {
+		tx = xaccTransLookup( pGuid, be->primary_book );
+	}
     if( table->gobj_param_name != NULL ) {
-		g_object_set( pObject, table->gobj_param_name, pGuid, NULL );
+		g_object_set( pObject, table->gobj_param_name, tx, NULL );
     } else {
-		(*setter)( pObject, (const gpointer)pGuid );
+		(*setter)( pObject, (const gpointer)tx );
     }
 }
 
@@ -789,17 +801,21 @@
                 const col_cvt_t* table_row, GValue* value )
 {
     QofAccessFunc getter;
-    const GUID* guid;
+    const GUID* guid = NULL;
     gchar guid_buf[GUID_ENCODING_LENGTH+1];
+	Transaction* tx;
 
     memset( value, 0, sizeof( GValue ) );
 
 	if( table_row->gobj_param_name != NULL ) {
-		g_object_get( pObject, table_row->gobj_param_name, &guid, NULL );
+		g_object_get( pObject, table_row->gobj_param_name, &tx, NULL );
 	} else {
     	getter = get_getter( obj_name, table_row );
-    	guid = (*getter)( pObject, NULL );
+    	tx = (*getter)( pObject, NULL );
 	}
+	if( tx != NULL ) {
+		guid = qof_instance_get_guid( QOF_INSTANCE(tx) );
+	}
     if( guid != NULL ) {
         (void)guid_to_string_buff( guid, guid_buf );
         g_value_init( value, G_TYPE_STRING );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -57,8 +57,8 @@
 static col_cvt_t col_table[] =
 {
     { "guid",               CT_GUID, 0, COL_NNUL, "guid" },
-    { "root_account_guid",  CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_root_account_guid,  set_root_account_guid },
-    { "root_template_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_root_template_guid, set_root_template_guid },
+    { "root_account_guid",  CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_account_guid,  set_root_account_guid },
+    { "root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_template_guid, set_root_template_guid },
     { NULL }
 };
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -51,7 +51,7 @@
 static col_cvt_t col_table[] =
 {
     { "guid",         CT_GUID,   0, COL_NNUL, "guid" },
-    { "account_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_lot_account,   set_lot_account },
+    { "account_guid", CT_GUID,   0, COL_NNUL, NULL, NULL, get_lot_account,   set_lot_account },
     { "is_closed",    CT_STRING, 1, COL_NNUL, NULL, NULL, get_lot_is_closed, set_lot_is_closed },
     { NULL }
 };

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -73,7 +73,7 @@
     { "adv_notify",        CT_INT,     0,               COL_NNUL, NULL, NULL,
             (QofAccessFunc)xaccSchedXactionGetAdvanceReminder,
             (QofSetterFunc)xaccSchedXactionSetAdvanceReminder },
-    { "template_act_guid", CT_GUID_A,  0,               COL_NNUL, NULL, NULL,        get_template_act_guid, set_template_act_guid },
+    { "template_act_guid", CT_GUID,    0,               COL_NNUL, NULL, NULL,        get_template_act_guid, set_template_act_guid },
     { NULL }
 };
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2007-12-20 02:55:12 UTC (rev 16688)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2007-12-20 03:31:10 UTC (rev 16689)
@@ -72,19 +72,15 @@
 {
     { "guid",          CT_GUID,     0,                      COL_NNUL, "guid" },
     { "currency_guid", CT_GUID_C,   0,                      COL_NNUL, NULL, NULL,
-			(QofAccessFunc)xaccTransGetCurrency,
-			(QofSetterFunc)xaccTransSetCurrency },
+			(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
     { "num",           CT_STRING,   TX_MAX_NUM_LEN,         COL_NNUL, NULL, NULL, get_tx_num,           set_tx_num },
     { "post_date",     CT_TIMESPEC, 0,                      COL_NNUL, NULL, NULL, get_tx_post_date,     set_tx_post_date },
     { "enter_date",    CT_TIMESPEC, 0,                      COL_NNUL, NULL, NULL, get_tx_enter_date,    set_tx_enter_date },
     { "description",   CT_STRING,   TX_MAX_DESCRIPTION_LEN, 0,        NULL, NULL,
-            (QofAccessFunc)xaccTransGetDescription,
-            (QofSetterFunc)xaccTransSetDescription },
+            (QofAccessFunc)xaccTransGetDescription, (QofSetterFunc)xaccTransSetDescription },
     { NULL }
 };
 
-static gpointer get_split_tx_guid( gpointer pObject, const QofParam* param );
-static void set_split_tx_guid( gpointer pObject, gpointer pValue );
 static gpointer get_split_reconcile_state( gpointer pObject, const QofParam* param );
 static void set_split_reconcile_state( gpointer pObject, gpointer pValue );
 static gpointer get_split_reconcile_date( gpointer pObject, const QofParam* param );
@@ -93,8 +89,6 @@
 static void set_split_value( gpointer pObject, gpointer pValue );
 static gpointer get_split_quantity( gpointer pObject, const QofParam* param );
 static void set_split_quantity( gpointer pObject, gpointer pValue );
-static gpointer get_split_account_guid( gpointer pObject, const QofParam* param );
-static void set_split_account_guid( gpointer pObject, gpointer pValue );
 
 #define SPLIT_MAX_MEMO_LEN 50
 #define SPLIT_MAX_ACTION_LEN 50
@@ -102,8 +96,10 @@
 static col_cvt_t split_col_table[] =
 {
     { "guid",            CT_GUID,     0,                    COL_NNUL, "guid" },
-    { "tx_guid",         CT_GUID_T,   0,                    COL_NNUL, NULL, NULL,    get_split_tx_guid,         set_split_tx_guid },
-    { "account_guid",    CT_GUID_A,   0,                    COL_NNUL, NULL, NULL,    get_split_account_guid,    set_split_account_guid },
+    { "tx_guid",         CT_GUID_T,   0,                    COL_NNUL, NULL, NULL,
+			(QofAccessFunc)xaccSplitGetParent, (QofSetterFunc)xaccSplitSetParent },
+    { "account_guid",    CT_GUID_A,   0,                    COL_NNUL, NULL, NULL,
+			(QofAccessFunc)xaccSplitGetAccount, (QofSetterFunc)xaccSplitSetAccount },
     { "memo",            CT_STRING,   SPLIT_MAX_MEMO_LEN,   COL_NNUL, NULL, SPLIT_MEMO },
     { "action",          CT_STRING,   SPLIT_MAX_ACTION_LEN, COL_NNUL, NULL, SPLIT_ACTION },
     { "reconcile_state", CT_STRING,   1,                    COL_NNUL, NULL, NULL,    get_split_reconcile_state, set_split_reconcile_state },
@@ -119,6 +115,8 @@
     { NULL }
 };
 
+static void retrieve_numeric_value( gpointer pObject, gpointer pValue );
+
 /* ================================================================= */
 static gpointer
 get_guid( gpointer pObject, const QofParam* param )
@@ -193,26 +191,6 @@
 }
 
 static gpointer
-get_split_tx_guid( gpointer pObject, const QofParam* param )
-{
-    const Split* pSplit = GNC_SPLIT(pObject);
-    Transaction* pTx = xaccSplitGetParent( pSplit );
-
-    return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pTx) );
-}
-
-static void 
-set_split_tx_guid( gpointer pObject, gpointer pValue )
-{
-    Split* pSplit = GNC_SPLIT(pObject);
-    QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
-    GUID* guid = (GUID*)pValue;
-    Transaction* pTx = xaccTransLookup( guid, pBook );
-
-    xaccSplitSetParent( pSplit, pTx );
-}
-
-static gpointer
 get_split_reconcile_state( gpointer pObject, const QofParam* param )
 {
     const Split* pSplit = GNC_SPLIT(pObject);
@@ -289,29 +267,7 @@
     xaccSplitSetAmount( pSplit, *pV );
 }
 
-static gpointer
-get_split_account_guid( gpointer pObject, const QofParam* param )
-{
-    const Split* pSplit = GNC_SPLIT(pObject);
-    Account* pAccount = xaccSplitGetAccount( pSplit );
-
-    return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pAccount) );
-}
-
 static void 
-set_split_account_guid( gpointer pObject, gpointer pValue )
-{
-    Split* pSplit = GNC_SPLIT(pObject);
-    QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
-    GUID* guid = (GUID*)pValue;
-    Account* pAccount = xaccAccountLookup( guid, pBook );
-
-    xaccSplitSetAccount( pSplit, pAccount );
-}
-
-static void retrieve_numeric_value( gpointer pObject, gpointer pValue );
-
-static void 
 retrieve_numeric_value( gpointer pObject, gpointer pValue )
 {
     gnc_numeric* pResult = (gnc_numeric*)pObject;
@@ -321,7 +277,7 @@
 }
 
 
-// Table to retrieve just the guid
+// Table to retrieve just the quantity
 static col_cvt_t quantity_table[] =
 {
     { "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, NULL, NULL, retrieve_numeric_value },



More information about the gnucash-changes mailing list