r16582 - gnucash/branches/gda-dev/src - When initially loading accounts, an account's parent could be later in

Phil Longstaff plongstaff at cvs.gnucash.org
Wed Nov 7 14:54:13 EST 2007


Author: plongstaff
Date: 2007-11-07 14:54:13 -0500 (Wed, 07 Nov 2007)
New Revision: 16582
Trac: http://svn.gnucash.org/trac/changeset/16582

Modified:
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
   gnucash/branches/gda-dev/src/engine/SX-book.c
   gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c
Log:
When initially loading accounts, an account's parent could be later in
the list and therefore not exist yet.  Keep track of these orphaned
accounts and when all accounts are loaded, look for those whose parent
didn't exist yet and match it with its parent.



Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -32,6 +32,7 @@
 #include <libgda/libgda.h>
 
 #include "qof.h"
+#include "Account.h"
 #include "AccountP.h"
 #include "gnc-commodity.h"
 
@@ -50,6 +51,7 @@
 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 );
 
 #define ACCOUNT_MAX_NAME_LEN 50
 #define ACCOUNT_MAX_TYPE_LEN 50
@@ -70,7 +72,17 @@
     { "description",	CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
     { NULL }
 };
+static col_cvt_t parent_col_table[] =
+{
+    { "parent_guid",	CT_GUID,	0, 0,	NULL, NULL, NULL, set_parent_guid },
+    { NULL }
+};
 
+typedef struct {
+	Account* pAccount;
+	GUID guid;
+} account_parent_guid_struct;
+
 /* ================================================================= */
 static gpointer
 get_commodity( gpointer pObject, const QofParam* param )
@@ -126,6 +138,15 @@
 }
 
 static void
+set_parent_guid( gpointer pObject, gpointer pValue )
+{
+	account_parent_guid_struct* s = (account_parent_guid_struct*)pObject;
+    GUID* guid = (GUID*)pValue;
+
+	s->guid = *guid;
+}
+
+static void
 load_balances( GncGdaBackend* be, Account* pAccount )
 {
     gnc_numeric start_balance;
@@ -143,19 +164,18 @@
 
 static Account*
 load_single_account( GncGdaBackend* be, GdaDataModel* pModel, int row,
-            Account* pAccount )
+				GList** l_accounts_needing_parents )
 {
     const GUID* guid;
     GUID acc_guid;
+	Account* pAccount;
 
     guid = gnc_gda_load_guid( pModel, row );
     acc_guid = *guid;
 
+    pAccount = xaccAccountLookup( &acc_guid, be->primary_book );
     if( pAccount == NULL ) {
-        pAccount = xaccAccountLookup( &acc_guid, be->primary_book );
-        if( pAccount == NULL ) {
-            pAccount = xaccMallocAccount( be->primary_book );
-        }
+        pAccount = xaccMallocAccount( be->primary_book );
     }
     gnc_gda_load_object( pModel, row, GNC_ID_ACCOUNT, pAccount, col_table );
     gnc_gda_slots_load( be, xaccAccountGetGUID( pAccount ),
@@ -164,6 +184,15 @@
 
     qof_instance_mark_clean( QOF_INSTANCE(pAccount) );
 
+	/* If we don't have a parent, it might be because the parent account hasn't
+	   been loaded yet.  Remember the account and its parent guid for later. */
+	if( gnc_account_get_parent( pAccount ) == NULL ) {
+		account_parent_guid_struct* s = g_slice_new( account_parent_guid_struct );
+		s->pAccount = pAccount;
+		gnc_gda_load_object( pModel, row, GNC_ID_ACCOUNT, s, parent_col_table );
+		*l_accounts_needing_parents = g_list_prepend( *l_accounts_needing_parents, s );
+	}
+
     return pAccount;
 }
 
@@ -187,10 +216,12 @@
         int r;
         Account* pAccount;
         Account* parent;
+		GList* l_accounts_needing_parents = NULL;
 
         for( r = 0; r < numRows; r++ ) {
-            pAccount = load_single_account( be, pModel, r, NULL );
+            pAccount = load_single_account( be, pModel, r, &l_accounts_needing_parents );
 
+#if 0
             if( pAccount != NULL ) {
 
                 /* Backwards compatibility.  If there's no parent, see if
@@ -211,7 +242,45 @@
                     }
                 }
             }
+#endif
         }
+
+		/* While there are items on the list of accounts needing parents,
+		   try to see if the parent has now been loaded.  Theory says that if
+		   items are removed from the front and added to the back if the
+		   parent is still not available, then eventually, the list will
+		   shrink to size 0. */
+		if( l_accounts_needing_parents != NULL ) {
+			gboolean progress_made = TRUE;
+
+			Account* pParent;
+			GList* elem;
+			
+			while( progress_made ) {
+				progress_made = FALSE;
+				for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
+					account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
+					const gchar* name = xaccAccountGetName( s->pAccount );
+    				pParent = xaccAccountLookup( &s->guid, be->primary_book );
+					if( pParent != NULL ) {
+						gnc_account_append_child( pParent, s->pAccount );
+						l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, elem );
+						progress_made = TRUE;
+					}
+				}
+			}
+
+			/* Any accounts left over must be parented by the root account */
+			for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
+				account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
+                Account* root;
+                root = gnc_book_get_root_account( pBook );
+                if( root == NULL ) {
+                    root = gnc_account_create_root( pBook );
+                }
+                gnc_account_append_child( root, pAccount ); 
+			}
+		}
     }
 }
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -344,6 +344,9 @@
 
     be->loading = FALSE;
 
+	// Mark the book as clean
+	qof_instance_mark_clean( QOF_INSTANCE(book) );
+
     LEAVE( "" );
 }
 
@@ -595,10 +598,15 @@
     GncGdaBackend *be = (GncGdaBackend*)be_start;
     gda_backend be_data;
 
+    ENTER( " " );
+
     /* During initial load where objects are being created, don't commit
     anything */
 
-    if( be->loading ) return;
+    if( be->loading ) {
+		LEAVE( "" );
+	    return;
+	}
 
     g_debug( "gda_commit_edit(): %s dirty = %d, do_free=%d\n",
              (inst->e_type ? inst->e_type : "(null)"),
@@ -623,6 +631,8 @@
 
     qof_instance_mark_clean(inst);
     qof_book_mark_saved( be->primary_book );
+
+	LEAVE( "" );
 }
 /* ---------------------------------------------------------------------- */
 
@@ -748,6 +758,8 @@
     gda_backend be_data;
     gnc_gda_query_info* pQueryInfo;
 
+	ENTER( " " );
+
     searchObj = qof_query_get_search_for( pQuery );
 
     pQueryInfo = g_malloc( sizeof( gnc_gda_query_info ) );
@@ -761,6 +773,7 @@
 
     qof_object_foreach_backend( GNC_GDA_BACKEND, compile_query_cb, &be_data );
     if( be_data.ok ) {
+		LEAVE( "" );
         return be_data.pQueryInfo;
     }
 
@@ -793,6 +806,8 @@
     g_debug( "Compiled: %s\n", sql );
     pQueryInfo->pCompiledQuery =  g_strdup( sql );
 
+	LEAVE( "" );
+
     return pQueryInfo;
 }
 
@@ -821,6 +836,8 @@
     gnc_gda_query_info* pQueryInfo = (gnc_gda_query_info*)pQuery;
     gda_backend be_data;
 
+	ENTER( " " );
+
     // Try various objects first
     be_data.ok = FALSE;
     be_data.be = be;
@@ -829,12 +846,15 @@
 
     qof_object_foreach_backend( GNC_GDA_BACKEND, free_query_cb, &be_data );
     if( be_data.ok ) {
+		LEAVE( "" );
         return;
     }
 
     g_debug( "gda_free_query(): %s\n", (gchar*)pQueryInfo->pCompiledQuery );
     g_free( pQueryInfo->pCompiledQuery );
     g_free( pQueryInfo );
+
+	LEAVE( "" );
 }
 
 static void
@@ -864,6 +884,8 @@
 
     g_return_if_fail( !be->in_query );
 
+	ENTER( " " );
+
     be->loading = TRUE;
     be->in_query = TRUE;
 
@@ -879,11 +901,17 @@
     be->loading = FALSE;
     be->in_query = FALSE;
     qof_event_resume();
-    if( be_data.ok ) {
-       	return;
-    }
+//    if( be_data.ok ) {
+//		LEAVE( "" );
+//       	return;
+//    }
 
-    g_debug( "gda_run_query(): %s\n", (gchar*)pQueryInfo->pCompiledQuery );
+	// Mark the book as clean
+	qof_instance_mark_clean( QOF_INSTANCE(be->primary_book) );
+
+//    g_debug( "gda_run_query(): %s\n", (gchar*)pQueryInfo->pCompiledQuery );
+
+	LEAVE( "" );
 }
 
 /* ================================================================= */

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-book-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -53,12 +53,13 @@
 static void set_root_account_guid( gpointer pObject, gpointer pValue );
 static gpointer get_root_template_guid( gpointer pObject, const QofParam* );
 static void set_root_template_guid( gpointer pObject, gpointer pValue );
+static void ignore( gpointer pObject, gpointer pValue );
 
 static col_cvt_t col_table[] =
 {
     { "guid",            CT_GUID,    0, COL_NNUL|COL_PKEY,    NULL, NULL,
             (QofAccessFunc)qof_instance_get_guid,
-            (QofSetterFunc)qof_instance_set_guid },
+            /*(QofSetterFunc)qof_instance_set_guid*/ ignore },
     { "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,
@@ -67,6 +68,11 @@
 };
 
 /* ================================================================= */
+static void 
+ignore( gpointer pObject, gpointer pValue )
+{
+}
+
 static gpointer
 get_root_account_guid( gpointer pObject, const QofParam* param )
 {
@@ -114,18 +120,19 @@
 
 /* ================================================================= */
 static GNCBook*
-load_single_book( GncGdaBackend* be, GdaDataModel* pModel, int row,
-            GNCBook* pBook )
+load_single_book( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     const GUID* guid;
     GUID book_guid;
+	GNCBook* pBook;
 
     guid = gnc_gda_load_guid( pModel, row );
     book_guid = *guid;
 
-    if( pBook == NULL ) {
-        pBook = gnc_book_new();
-    }
+	pBook = be->primary_book;
+	if( pBook == NULL ) {
+	    pBook = gnc_book_new();
+	}
 
     gnc_gda_load_object( pModel, row, GNC_ID_BOOK, pBook, col_table );
     gnc_gda_slots_load( be, gnc_book_get_guid( pBook ),
@@ -150,16 +157,14 @@
     if( GDA_IS_DATA_MODEL( ret ) ) {
         GdaDataModel* pModel = GDA_DATA_MODEL(ret);
         int numRows = gda_data_model_get_n_rows( pModel );
-        int r;
 
-        for( r = 0; r < numRows; r++ ) {
-            (void)load_single_book( be, pModel, r, NULL );
-        }
-
-	// If there are no rows, try committing the book
-	if( numRows == 0 ) {
-    	    commit_book( be, QOF_INSTANCE( be->primary_book ) );
-	}
+		// If there are no rows, try committing the book
+		if( numRows == 0 ) {
+   	    	commit_book( be, QOF_INSTANCE( be->primary_book ) );
+		} else {
+			// Otherwise, load the 1st book.
+            (void)load_single_book( be, pModel, 0 );
+		}
     }
 }
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -136,20 +136,18 @@
 
 /* ================================================================= */
 static GncBudget*
-load_single_budget( GncGdaBackend* be, GdaDataModel* pModel, int row,
-            GncBudget* pBudget )
+load_single_budget( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     const GUID* guid;
     GUID budget_guid;
+	GncBudget* pBudget;
 
     guid = gnc_gda_load_guid( pModel, row );
     budget_guid = *guid;
 
+    pBudget = gnc_budget_lookup( &budget_guid, be->primary_book );
     if( pBudget == NULL ) {
-        pBudget = gnc_budget_lookup( &budget_guid, be->primary_book );
-        if( pBudget == NULL ) {
-            pBudget = gnc_budget_new( be->primary_book );
-        }
+        pBudget = gnc_budget_new( be->primary_book );
     }
 
     gnc_gda_load_object( pModel, row, GNC_ID_BUDGET, pBudget, col_table );
@@ -178,7 +176,7 @@
         int r;
 
         for( r = 0; r < numRows; r++ ) {
-            (void)load_single_budget( be, pModel, r, NULL );
+            (void)load_single_budget( be, pModel, r );
         }
     }
 }

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -109,16 +109,14 @@
 }
 
 static gnc_commodity*
-load_single_commodity( GncGdaBackend* be, GdaDataModel* pModel, int row,
-                gnc_commodity* pCommodity )
+load_single_commodity( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     QofBook* pBook = be->primary_book;
     int col;
     const GValue* val;
+    gnc_commodity* pCommodity;
 
-    if( pCommodity == NULL ) {
-        pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
-    }
+    pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
 
     gnc_gda_load_object( pModel, row, GNC_ID_COMMODITY, pCommodity, col_table );
     gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE(pCommodity) ),
@@ -149,7 +147,7 @@
         for( r = 0; r < numRows; r++ ) {
             gnc_commodity* c;
 
-            pCommodity = load_single_commodity( be, pModel, r, NULL );
+            pCommodity = load_single_commodity( be, pModel, r );
 
             if( pCommodity != NULL ) {
                 GUID guid;

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-lots-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -101,12 +101,12 @@
 }
 
 static GNCLot*
-load_single_lot( GncGdaBackend* be, GdaDataModel* pModel, int row, GNCLot* lot )
+load_single_lot( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
-    if( lot == NULL ) {
-        lot = gnc_lot_new( be->primary_book );
-    }
+	GNCLot* lot;
 
+    lot = gnc_lot_new( be->primary_book );
+
     gnc_gda_load_object( pModel, row, GNC_ID_LOT, lot, col_table );
     gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE(lot) ),
                             qof_instance_get_slots( QOF_INSTANCE(lot) ) );
@@ -133,7 +133,7 @@
         GNCLot* lot;
 
         for( r = 0; r < numRows; r++ ) {
-            lot = load_single_lot( be, pModel, r, NULL );
+            lot = load_single_lot( be, pModel, r );
         }
     }
 }

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -154,12 +154,12 @@
 }
 
 static GNCPrice*
-load_single_price( GncGdaBackend* be, GdaDataModel* pModel, int row, GNCPrice* pPrice )
+load_single_price( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
-    if( pPrice == NULL ) {
-        pPrice = gnc_price_create( be->primary_book );
-    }
+	GNCPrice* pPrice;
 
+    pPrice = gnc_price_create( be->primary_book );
+
     gnc_gda_load_object( pModel, row, GNC_ID_PRICE, pPrice, col_table );
 
     qof_instance_mark_clean( QOF_INSTANCE(pPrice) );
@@ -186,7 +186,7 @@
         GNCPrice* pPrice;
 
         for( r = 0; r < numRows; r++ ) {
-            pPrice = load_single_price( be, pModel, r, NULL );
+            pPrice = load_single_price( be, pModel, r );
 
             if( pPrice != NULL ) {
                 gnc_pricedb_add_price( pPriceDB, pPrice );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-schedxaction-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -124,18 +124,16 @@
 
 /* ================================================================= */
 static SchedXaction*
-load_single_sx( GncGdaBackend* be, GdaDataModel* pModel, int row,
-            SchedXaction* pSx )
+load_single_sx( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     const GUID* guid;
     GUID sx_guid;
+	SchedXaction* pSx;
 
     guid = gnc_gda_load_guid( pModel, row );
     sx_guid = *guid;
 
-    if( pSx == NULL ) {
-        pSx = xaccSchedXactionMalloc( be->primary_book );
-    }
+    pSx = xaccSchedXactionMalloc( be->primary_book );
 
     gnc_gda_load_object( pModel, row, /*GNC_ID_SCHEDXACTION*/GNC_SX_ID, pSx, col_table );
     gnc_gda_slots_load( be, qof_instance_get_guid( QOF_INSTANCE(pSx) ),
@@ -163,7 +161,7 @@
         int r;
 
         for( r = 0; r < numRows; r++ ) {
-            (void)load_single_sx( be, pModel, r, NULL );
+            (void)load_single_sx( be, pModel, r );
         }
     }
 }

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -467,10 +467,11 @@
 }
 
 static Split*
-load_single_split( GncGdaBackend* be, GdaDataModel* pModel, int row, Split* pSplit )
+load_single_split( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     const GUID* guid;
     GUID split_guid;
+	Split* pSplit;
 
     guid = gnc_gda_load_guid( pModel, row );
     split_guid = *guid;
@@ -525,25 +526,24 @@
         int r;
 
         for( r = 0; r < numRows; r++ ) {
-            load_single_split( be, pModel, r, NULL );
+            load_single_split( be, pModel, r );
         }
     }
 }
 
 static Transaction*
-load_single_tx( GncGdaBackend* be, GdaDataModel* pModel, int row, Transaction* pTx )
+load_single_tx( GncGdaBackend* be, GdaDataModel* pModel, int row )
 {
     const GUID* guid;
     GUID tx_guid;
+	Transaction* pTx;
 
     guid = gnc_gda_load_guid( pModel, row );
     tx_guid = *guid;
 
+    pTx = xaccTransLookup( &tx_guid, be->primary_book );
     if( pTx == NULL ) {
-        pTx = xaccTransLookup( &tx_guid, be->primary_book );
-        if( pTx == NULL ) {
-            pTx = xaccMallocTransaction( be->primary_book );
-        }
+        pTx = xaccMallocTransaction( be->primary_book );
     }
     xaccTransBeginEdit( pTx );
     gnc_gda_load_object( pModel, row, GNC_ID_TRANS, pTx, tx_col_table );
@@ -571,7 +571,7 @@
         int r;
 
         for( r = 0; r < numRows; r++ ) {
-            load_single_tx( be, pModel, r, NULL );
+            load_single_tx( be, pModel, r );
         }
     }
 }

Modified: gnucash/branches/gda-dev/src/engine/SX-book.c
===================================================================
--- gnucash/branches/gda-dev/src/engine/SX-book.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/engine/SX-book.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -113,11 +113,14 @@
 {
   Account *root;
 
-  root = xaccMallocAccount(book);
-  xaccAccountBeginEdit(root);
-  xaccAccountSetType(root, ACCT_TYPE_ROOT);
-  xaccAccountCommitEdit(root);
-  gnc_book_set_template_root (book, root);
+  root = gnc_book_get_template_root( book );
+  if( root == NULL ) {
+  	root = xaccMallocAccount(book);
+  	xaccAccountBeginEdit(root);
+  	xaccAccountSetType(root, ACCT_TYPE_ROOT);
+  	xaccAccountCommitEdit(root);
+  	gnc_book_set_template_root (book, root);
+  }
 }
 
 static void 

Modified: gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c	2007-11-07 08:27:27 UTC (rev 16581)
+++ gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c	2007-11-07 19:54:13 UTC (rev 16582)
@@ -166,13 +166,41 @@
   response = gtk_dialog_run(GTK_DIALOG(file_box));
 
   if (response == GTK_RESPONSE_ACCEPT) {
+  	gboolean need_free = FALSE;
+
     /* look for constructs like postgres://foo */
     internal_name = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER (file_box));
     if (strstr (internal_name, "file://") == internal_name) {
+	  gchar* cur_folder;
+	  char* colon;
+	  char* slash;
+
       /* nope, a local file name */
       internal_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER (file_box));
+	  cur_folder = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( file_box ) );
+	  if( g_str_has_prefix( internal_name, cur_folder ) ) {
+	    internal_name += strlen( cur_folder )+1;
+
+		/* If there's a ':' before a '/', assume it was from an access method
+		 * and rearrange the name.
+		 */
+		colon = strstr( internal_name, ":" );
+		slash = strstr( internal_name, "/" );
+		if( colon != NULL && (slash == NULL || slash > colon) ) {
+		    const gchar* access_method = internal_name;
+			gchar* rest = colon+1;
+			*colon = '\0';
+
+			internal_name = g_strconcat( access_method, ":",
+										 cur_folder, "/", rest, NULL );
+			need_free = TRUE;
+		}
+	  }
     }
     file_name = g_strdup(internal_name);
+	if( need_free ) {
+		g_free( (gchar*)internal_name );
+	}
   }
   gtk_widget_destroy(GTK_WIDGET(file_box));
   LEAVE("%s", file_name ? file_name : "(null)");



More information about the gnucash-changes mailing list