r16114 - gnucash/branches/gda-dev/src - Add dummy "Save as GDA" menu entry to save to GDA "gnucash" database.

Phil Longstaff plongstaff at cvs.gnucash.org
Sun May 20 20:58:22 EDT 2007


Author: plongstaff
Date: 2007-05-20 20:58:21 -0400 (Sun, 20 May 2007)
New Revision: 16114
Trac: http://svn.gnucash.org/trac/changeset/16114

Modified:
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h
   gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
   gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h
   gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c
   gnucash/branches/gda-dev/src/gnome-utils/gnc-file.h
   gnucash/branches/gda-dev/src/gnome/gnc-plugin-basic-commands.c
   gnucash/branches/gda-dev/src/gnome/ui/gnc-plugin-basic-commands-ui.xml
Log:
Add dummy "Save as GDA" menu entry to save to GDA "gnucash" database.
Backend sync_all creates new tables and stores commodities, accounts and
prices.



Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -205,8 +205,8 @@
 }
 
 /* ================================================================= */
-static void
-commit_account( GncGdaBackend* be, QofInstance* inst )
+void
+gnc_gda_save_account( GncGdaBackend* be, QofInstance* inst )
 {
     Account* pAcc = GNC_ACCOUNT(inst);
     const GUID* guid;
@@ -242,7 +242,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_ACCOUNT,
-        commit_account,				/* commit */
+        gnc_gda_save_account,				/* commit */
         load_all_accounts,				/* initial_load */
         create_account_tables		/* create_tables */
     };

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.h	2007-05-21 00:58:21 UTC (rev 16114)
@@ -33,5 +33,6 @@
 #include <gmodule.h>
 
 void gnc_gda_init_account_handler( void );
+void gnc_gda_save_account( GncGdaBackend* be, QofInstance* inst );
 
 #endif /* GNC_ACCOUNT_GDA_H_ */

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -47,6 +47,7 @@
 #include "gnc-commodity-gda.h"
 #include "gnc-lots-gda.h"
 #include "gnc-price-gda.h"
+#include "gnc-pricedb.h"
 #include "gnc-schedxaction-gda.h"
 #include "gnc-slots-gda.h"
 #include "gnc-transaction-gda.h"
@@ -243,9 +244,108 @@
 
 /* ================================================================= */
 
+static gint
+compare_namespaces(gconstpointer a, gconstpointer b)
+{
+  const gchar *sa = (const gchar *) a;
+  const gchar *sb = (const gchar *) b;
+  return(safe_strcmp(sa, sb));
+}
+
+static gint
+compare_commodity_ids(gconstpointer a, gconstpointer b)
+{
+  const gnc_commodity *ca = (const gnc_commodity *) a;
+  const gnc_commodity *cb = (const gnc_commodity *) b;
+  return(safe_strcmp(gnc_commodity_get_mnemonic(ca),
+                     gnc_commodity_get_mnemonic(cb)));
+}
+
 static void
-gnc_gda_sync_all(QofBackend* be, QofBook *book)
+save_commodities( GncGdaBackend* be, QofBook* book )
 {
+    gnc_commodity_table* tbl;
+    GList* namespaces;
+    GList* lp;
+
+    tbl = gnc_book_get_commodity_table( book );
+    namespaces = gnc_commodity_table_get_namespaces( tbl );
+    if( namespaces != NULL ) {
+        namespaces = g_list_sort( namespaces, compare_namespaces );
+    }
+    for( lp = namespaces; lp != NULL; lp = lp->next ) {
+        GList* comms;
+        GList* lp2;
+        
+        comms = gnc_commodity_table_get_commodities( tbl, lp->data );
+        comms = g_list_sort( comms, compare_commodity_ids );
+
+        for( lp2 = comms; lp2 != NULL; lp2 = lp2->next ) {
+	    gnc_gda_save_commodity( be, GNC_COMMODITY(lp2->data) );
+        }
+    }
+}
+
+static void
+save_account_tree( GncGdaBackend* be, Account* root )
+{
+    GList* descendants;
+    GList* node;
+
+    descendants = gnc_account_get_descendants( root );
+    for( node = descendants; node != NULL; node = g_list_next(node) ) {
+        gnc_gda_save_account( be, QOF_INSTANCE(GNC_ACCOUNT(node->data)) );
+    }
+    g_list_free( descendants );
+}
+
+static void
+save_accounts( GncGdaBackend* be, QofBook* book )
+{
+    save_account_tree( be, gnc_book_get_root_account( book ) );
+}
+
+static void
+save_budgets( GncGdaBackend* be, QofBook* book )
+{
+}
+
+static gboolean
+save_price( GNCPrice* p, gpointer data )
+{
+    GncGdaBackend* be = (GncGdaBackend*)data;
+
+    gnc_gda_save_price( be, QOF_INSTANCE(p) );
+
+    return TRUE;
+}
+
+static void
+save_prices( GncGdaBackend* be, QofBook* book )
+{
+    GNCPriceDB* priceDB = gnc_book_get_pricedb( book );
+
+    gnc_pricedb_foreach_price( priceDB, save_price, be, TRUE );
+}
+
+static void
+save_transactions( GncGdaBackend* be, QofBook* book )
+{
+}
+
+static void
+save_template_transactions( GncGdaBackend* be, QofBook* book )
+{
+}
+
+static void
+save_schedXactions( GncGdaBackend* be, QofBook* book )
+{
+}
+
+static void
+gnc_gda_sync_all( QofBackend* be, QofBook *book )
+{
     GncGdaBackend *fbe = (GncGdaBackend *) be;
     GdaDataModel* tables;
     GError* error = NULL;
@@ -279,6 +379,12 @@
         }
     }
 
+    // Update the dictionary because new tables may exist
+    gda_dict_update_dbms_meta_data( fbe->pDict, 0, NULL, &error );
+    if( error != NULL ) {
+        g_critical( "gda_dict_update_dbms_meta_data() error: %s\n", error->message );
+    }
+
     /* Create new tables */
     be_data.ok = FALSE;
     be_data.be = fbe;
@@ -292,13 +398,14 @@
     }
 
     /* Save all contents */
+    //save_commodities( fbe, book );
+    save_accounts( fbe, book );
+    save_prices( fbe, book );
+    save_transactions( fbe, book );
+    save_template_transactions( fbe, book );
+    save_schedXactions( fbe, book );
+    save_budgets( fbe, book );
 
-    /* Accounts */
-    /* Prices */
-    /* Budgets */
-    /* Sched tx */
-    /* Transactions */
-
     LEAVE ("book=%p", book);
 }
 

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -69,7 +69,7 @@
     { "fullname",        CT_STRING,    COMMODITY_MAX_FULLNAME_LEN, COL_NNUL,    NULL,
             (QofAccessFunc)gnc_commodity_get_fullname,
             (QofSetterFunc)gnc_commodity_set_fullname },
-    { "cusip",            CT_STRING,    COMMODITY_MAX_CUSIP_LEN, COL_NNUL,    NULL,
+    { "cusip",            CT_STRING,    COMMODITY_MAX_CUSIP_LEN, 0,    NULL,
             (QofAccessFunc)gnc_commodity_get_cusip,
             (QofSetterFunc)gnc_commodity_set_cusip },
     { "fraction",        CT_INT,        0, COL_NNUL,    NULL,
@@ -198,7 +198,8 @@
                                 pCommodity, col_table );
 }
 
-void gnc_gda_save_commodity( GncGdaBackend* be, gnc_commodity* pCommodity )
+void
+gnc_gda_save_commodity( GncGdaBackend* be, gnc_commodity* pCommodity )
 {
     if( !is_commodity_in_db( be, pCommodity ) ) {
         commit_commodity( be, QOF_INSTANCE(pCommodity) );

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -204,8 +204,8 @@
 
 /* ================================================================= */
 
-static void
-commit_price( GncGdaBackend* be, QofInstance* inst )
+void
+gnc_gda_save_price( GncGdaBackend* be, QofInstance* inst )
 {
     GNCPrice* pPrice = GNC_PRICE(inst);
 
@@ -228,7 +228,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_PRICE,
-        commit_price,            /* commit */
+        gnc_gda_save_price,            /* commit */
         load_all_prices,            /* initial_load */
         create_prices_tables    /* create tables */
     };

Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.h	2007-05-21 00:58:21 UTC (rev 16114)
@@ -33,5 +33,6 @@
 #include <gmodule.h>
 
 void gnc_gda_init_price_handler( void );
+void gnc_gda_save_price( GncGdaBackend* be, QofInstance* inst );
 
 #endif /* GNC_PRICE_GDA_H_ */

Modified: gnucash/branches/gda-dev/src/gnome/gnc-plugin-basic-commands.c
===================================================================
--- gnucash/branches/gda-dev/src/gnome/gnc-plugin-basic-commands.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/gnome/gnc-plugin-basic-commands.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -67,6 +67,7 @@
 static void gnc_main_window_cmd_file_open (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_save (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_save_as (GtkAction *action, GncMainWindowActionData *data);
+static void gnc_main_window_cmd_file_save_gda (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_qsf_import (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_export_accounts (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_chart_export (GtkAction *action, GncMainWindowActionData *data);
@@ -104,6 +105,9 @@
   { "FileSaveAsAction", GTK_STOCK_SAVE_AS, N_("Save _As..."), "<shift><control>s",
     NULL,
     G_CALLBACK (gnc_main_window_cmd_file_save_as) },
+  { "FileSaveGDAAction", NULL, N_("Save _GDA..."), NULL,
+    NULL,
+    G_CALLBACK (gnc_main_window_cmd_file_save_gda) },
   { "FileImportQSFAction", GTK_STOCK_CONVERT,
     N_("_QSF Import"), NULL,
     N_("Import a QSF object file"),
@@ -351,6 +355,20 @@
 }
 
 static void
+gnc_main_window_cmd_file_save_gda (GtkAction *action, GncMainWindowActionData *data)
+{
+  g_return_if_fail (data != NULL);
+
+  if (!gnc_main_window_all_finish_pending())
+    return;
+
+  gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
+  gnc_file_do_save_as( "gda://gnucash" );
+  gnc_window_set_progressbar_window (NULL);
+  /* FIXME GNOME 2 Port (update the title etc.) */
+}
+
+static void
 qsf_file_select_ok(GtkWidget *w, GtkFileSelection *fs )
 {
   QofSession *qsf_session, *first_session;

Modified: gnucash/branches/gda-dev/src/gnome/ui/gnc-plugin-basic-commands-ui.xml
===================================================================
--- gnucash/branches/gda-dev/src/gnome/ui/gnc-plugin-basic-commands-ui.xml	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/gnome/ui/gnc-plugin-basic-commands-ui.xml	2007-05-21 00:58:21 UTC (rev 16114)
@@ -14,6 +14,7 @@
       <placeholder name="FileSavePlaceholder">
         <menuitem name="FileSave" action="FileSaveAction"/>
         <menuitem name="FileSaveAs" action="FileSaveAsAction"/>
+        <menuitem name="FileSaveGDA" action="FileSaveGDAAction"/>
       </placeholder>
       <menu name="FileImport" action="FileImportAction">
         <menuitem name="FileImportQSF" action="FileImportQSFAction"/>

Modified: gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/gnome-utils/gnc-file.c	2007-05-21 00:58:21 UTC (rev 16114)
@@ -1025,6 +1025,24 @@
   g_free(default_dir);
   if (!filename) return;
 
+  gnc_file_do_save_as( filename );
+
+  LEAVE (" ");
+}
+
+void
+gnc_file_do_save_as (const char* filename)
+{
+  QofSession *new_session;
+  QofSession *session;
+  char *default_dir = NULL;        /* Default to last open */
+  char *last;
+  char *newfile;
+  const char *oldfile;
+  QofBackendError io_err = ERR_BACKEND_NO_ERR;
+
+  ENTER(" ");
+
   /* Check to see if the user specified the same file as the current
    * file. If so, then just do that, instead of the below, which
    * assumes a truly new name was given. */

Modified: gnucash/branches/gda-dev/src/gnome-utils/gnc-file.h
===================================================================
--- gnucash/branches/gda-dev/src/gnome-utils/gnc-file.h	2007-05-20 20:56:19 UTC (rev 16113)
+++ gnucash/branches/gda-dev/src/gnome-utils/gnc-file.h	2007-05-21 00:58:21 UTC (rev 16114)
@@ -127,6 +127,7 @@
 gboolean gnc_file_open (void);
 void gnc_file_save (void);
 void gnc_file_save_as (void);
+void gnc_file_do_save_as(const char* filename);
 
 /** Tell the user about errors in the backends
 



More information about the gnucash-changes mailing list