r16777 - gnucash/branches/gda-dev2/src - 1) Initial pass at database connection dialog. Further refinement

Phil Longstaff plongstaff at cvs.gnucash.org
Mon Dec 31 13:52:33 EST 2007


Author: plongstaff
Date: 2007-12-31 13:52:32 -0500 (Mon, 31 Dec 2007)
New Revision: 16777
Trac: http://svn.gnucash.org/trac/changeset/16777

Added:
   gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c
   gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.h
   gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade
Modified:
   gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c
   gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.h
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.h
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c
   gnucash/branches/gda-dev2/src/business/business-core/gda/gncmod-business-backend-gda.c
   gnucash/branches/gda-dev2/src/gnome-utils/Makefile.am
   gnucash/branches/gda-dev2/src/gnome-utils/glade/Makefile.am
   gnucash/branches/gda-dev2/src/gnome/gnc-plugin-basic-commands.c
   gnucash/branches/gda-dev2/src/gnome/ui/gnc-plugin-basic-commands-ui.xml
Log:
1) Initial pass at database connection dialog.  Further refinement
needed.
2) Fix bug where all columns are included in primary key
3) Fix crash with gda://@xxx url
4) When doing "save as" to a database, save the book info
5) Fix problems saving slots in business objects



Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -135,10 +135,8 @@
 		//    @<gda_connectionname>
 
 		if( dsn[0] == '@' ) {
-	    	dsn++;
-
 	    	be->pConnection = gda_client_open_connection( be->pClient,
-													dsn,
+													&dsn[1],
 													username, password,
 													0,
 													&error );
@@ -561,6 +559,7 @@
 
     /* Save all contents */
     //save_commodities( fbe, book );
+	gnc_gda_save_book( fbe, QOF_INSTANCE(book) );
     save_accounts( fbe, book );
     save_prices( fbe, book );
     save_transactions( fbe, book );

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -205,7 +205,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_STRING );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t string_handler
@@ -278,7 +278,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_INT );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t int_handler =
@@ -351,7 +351,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_INT );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t boolean_handler =
@@ -423,7 +423,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_INT64 );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t int64_handler =
@@ -496,7 +496,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_INT64 );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t double_handler =
@@ -575,7 +575,7 @@
             xmlNodePtr array_data, const col_cvt_t* table_row, gboolean pkey )
 {
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    "char", GUID_ENCODING_LENGTH, table_row->flags | pkey ? COL_PKEY : 0 );
+                    "char", GUID_ENCODING_LENGTH, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t guid_handler =
@@ -635,7 +635,7 @@
             xmlNodePtr array_data, const col_cvt_t* table_row, gboolean pkey )
 {
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    "char", GUID_ENCODING_LENGTH, table_row->flags | pkey ? COL_PKEY : 0 );
+                    "char", GUID_ENCODING_LENGTH, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 /* ----------------------------------------------------------------- */
@@ -731,7 +731,7 @@
     dbms_type = gda_server_provider_get_default_dbms_type( server,
                                                         cnn, G_TYPE_DATE );
     gnc_gda_add_table_column( server, cnn, array_data, table_row->col_name,
-                    dbms_type, table_row->size, table_row->flags | pkey ? COL_PKEY : 0 );
+                    dbms_type, table_row->size, table_row->flags | (pkey ? COL_PKEY : 0) );
 }
 
 static col_type_handler_t timespec_handler =

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -47,8 +47,6 @@
 
 static QofLogModule log_module = GNC_MOD_BACKEND;
 
-static void commit_book( GncGdaBackend* be, QofInstance* inst );
-
 static gpointer get_root_account_guid( gpointer pObject, const QofParam* );
 static void set_root_account_guid( gpointer pObject, gpointer pValue );
 static gpointer get_root_template_guid( gpointer pObject, const QofParam* );
@@ -69,7 +67,7 @@
     GNCBook* book = QOF_BOOK(pObject);
     const Account* root = gnc_book_get_root_account( book );
 
-    return (gpointer)qof_instance_get_guid( QOF_INSTANCE( root ) );
+    return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
 }
 
 static void 
@@ -79,7 +77,7 @@
     const Account* root = gnc_book_get_root_account( book );
     GUID* guid = (GUID*)pValue;
 
-    qof_instance_set_guid( QOF_INSTANCE( root ), guid );
+    qof_instance_set_guid( QOF_INSTANCE(root), guid );
 }
 
 static gpointer
@@ -88,7 +86,7 @@
     const GNCBook* book = QOF_BOOK(pObject);
     const Account* root = gnc_book_get_template_root( book );
 
-    return (gpointer)qof_instance_get_guid( QOF_INSTANCE( root ) );
+    return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
 }
 
 static void 
@@ -105,7 +103,7 @@
         xaccAccountCommitEdit( root );
         gnc_book_set_template_root( book, root );
     }
-    qof_instance_set_guid( QOF_INSTANCE( root ), guid );
+    qof_instance_set_guid( QOF_INSTANCE(root), guid );
 }
 
 /* ================================================================= */
@@ -150,7 +148,7 @@
 
 		// If there are no rows, try committing the book
 		if( numRows == 0 ) {
-   	    	commit_book( be, QOF_INSTANCE( be->primary_book ) );
+   	    	gnc_gda_save_book( be, QOF_INSTANCE(be->primary_book) );
 		} else {
 			// Otherwise, load the 1st book.
             (void)load_single_book( be, pModel, 0 );
@@ -166,8 +164,8 @@
 }
 
 /* ================================================================= */
-static void
-commit_book( GncGdaBackend* be, QofInstance* inst )
+void
+gnc_gda_save_book( GncGdaBackend* be, QofInstance* inst )
 {
     GNCBook* pBook = QOF_BOOK(inst);
     const GUID* guid;
@@ -197,9 +195,9 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_BOOK,
-        commit_book,                /* commit */
+        gnc_gda_save_book,                 /* commit */
         load_all_books,                    /* initial_load */
-        create_book_tables            /* create_tables */
+        create_book_tables 		           /* create_tables */
     };
 
     qof_object_register_backend( GNC_ID_BOOK, GNC_GDA_BACKEND, &be_data );

Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.h
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.h	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-book-gda.h	2007-12-31 18:52:32 UTC (rev 16777)
@@ -33,5 +33,6 @@
 #include <gmodule.h>
 
 void gnc_gda_init_book_handler( void );
+void gnc_gda_save_book( GncGdaBackend* be, QofInstance* inst );
 
 #endif /* GNC_BOOK_GDA_H_ */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -29,6 +29,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncBillTermP.h"
 #include "gncInvoice.h"

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.h
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.h	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-bill-term-gda.h	2007-12-31 18:52:32 UTC (rev 16777)
@@ -35,5 +35,6 @@
 #define CT_BILLTERMREF "billterm"
 
 void gnc_billterm_gda_initialize( void );
+void gnc_gda_save_billterm( GncGdaBackend* be, QofInstance* inst );
 
 #endif /* GNC_BILLTERM_GDA_H */

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-customer-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -29,6 +29,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncBillTermP.h"
 #include "gncCustomerP.h"
@@ -125,8 +126,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_customer( GncGdaBackend* be, QofInstance* inst )
+static void
+save_customer( GncGdaBackend* be, QofInstance* inst )
 {
     GncCustomer* customer = GNC_CUSTOMER(inst);
     const GUID* guid;
@@ -154,7 +155,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_CUSTOMER,
-        gnc_gda_save_customer,				/* commit */
+        save_customer,						/* commit */
         load_all_customers,					/* initial_load */
         create_customer_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-employee-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -30,10 +30,15 @@
 
 #include <libgda/libgda.h>
 
+#include "gnc-commodity.h"
+
+#include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
+#include "gnc-commodity-gda.h"
+
 #include "gncEmployeeP.h"
 #include "gnc-employee-gda.h"
 #include "gnc-address-gda.h"
-#include "gnc-commodity.h"
 
 #include "gnc-backend-util-gda.h"
 
@@ -121,8 +126,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_employee( GncGdaBackend* be, QofInstance* inst )
+static void
+save_employee( GncGdaBackend* be, QofInstance* inst )
 {
     GncEmployee* emp = GNC_EMPLOYEE(inst);
     const GUID* guid;
@@ -153,7 +158,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_EMPLOYEE,
-        gnc_gda_save_employee,				/* commit */
+        save_employee,						/* commit */
         load_all_employees,					/* initial_load */
         create_employee_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-entry-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -30,6 +30,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncEntryP.h"
 #include "gncOrderP.h"
@@ -181,8 +182,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_entry( GncGdaBackend* be, QofInstance* inst )
+static void
+save_entry( GncGdaBackend* be, QofInstance* inst )
 {
     GncEntry* v = GNC_ENTRY(inst);
     const GUID* guid;
@@ -210,7 +211,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_ENTRY,
-        gnc_gda_save_entry,					/* commit */
+        save_entry,							/* commit */
         load_all_entries,					/* initial_load */
         create_entry_tables					/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-invoice-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -28,7 +28,11 @@
 
 #include <libgda/libgda.h>
 
+#include "gnc-commodity.h"
+
 #include "gnc-backend-util-gda.h"
+#include "gnc-commodity-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncBillTermP.h"
 #include "gncInvoiceP.h"
@@ -125,8 +129,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_invoice( GncGdaBackend* be, QofInstance* inst )
+static void
+save_invoice( GncGdaBackend* be, QofInstance* inst )
 {
     GncInvoice* v = GNC_INVOICE(inst);
     const GUID* guid;
@@ -188,7 +192,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_INVOICE,
-        gnc_gda_save_invoice,				/* commit */
+        save_invoice,						/* commit */
         load_all_invoices,					/* initial_load */
         create_invoice_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-job-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -29,6 +29,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncJobP.h"
 #include "gnc-job-gda.h"
@@ -110,8 +111,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_job( GncGdaBackend* be, QofInstance* inst )
+static void
+save_job( GncGdaBackend* be, QofInstance* inst )
 {
     GncJob* job = GNC_JOB(inst);
     const GUID* guid;
@@ -139,7 +140,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_JOB,
-        gnc_gda_save_job,				/* commit */
+        save_job,						/* commit */
         load_all_jobs,					/* initial_load */
         create_job_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-order-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -29,6 +29,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncOrderP.h"
 
@@ -113,8 +114,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_order( GncGdaBackend* be, QofInstance* inst )
+static void
+save_order( GncGdaBackend* be, QofInstance* inst )
 {
     GncOrder* v = GNC_ORDER(inst);
     const GUID* guid;
@@ -173,7 +174,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_ORDER,
-        gnc_gda_save_order,				/* commit */
+        save_order,						/* commit */
         load_all_orders,				/* initial_load */
         create_order_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-tax-table-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -31,6 +31,7 @@
 #include <libgda/libgda.h>
 
 #include "gnc-backend-util-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gncEntry.h"
 #include "gncTaxTableP.h"
@@ -279,8 +280,8 @@
     }
 }
 
-void
-gnc_gda_save_taxtable( GncGdaBackend* be, QofInstance* inst )
+static void
+save_taxtable( GncGdaBackend* be, QofInstance* inst )
 {
     GncTaxTable* tt = GNC_TAXTABLE(inst);
     const GUID* guid;
@@ -341,7 +342,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_TAXTABLE,
-        gnc_gda_save_taxtable,				/* commit */
+        save_taxtable,						/* commit */
         load_all_taxtables,					/* initial_load */
         create_taxtable_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gnc-vendor-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -30,7 +30,11 @@
 
 #include <libgda/libgda.h>
 
+#include "gnc-commodity.h"
+
 #include "gnc-backend-util-gda.h"
+#include "gnc-commodity-gda.h"
+#include "gnc-slots-gda.h"
 
 #include "gnc-commodity.h"
 #include "gncBillTermP.h"
@@ -125,8 +129,8 @@
 }
 
 /* ================================================================= */
-void
-gnc_gda_save_vendor( GncGdaBackend* be, QofInstance* inst )
+static void
+save_vendor( GncGdaBackend* be, QofInstance* inst )
 {
     GncVendor* v = GNC_VENDOR(inst);
     const GUID* guid;
@@ -157,7 +161,7 @@
     {
         GNC_GDA_BACKEND_VERSION,
         GNC_ID_VENDOR,
-        gnc_gda_save_vendor,				/* commit */
+        save_vendor,						/* commit */
         load_all_vendors,					/* initial_load */
         create_vendor_tables				/* create_tables */
     };

Modified: gnucash/branches/gda-dev2/src/business/business-core/gda/gncmod-business-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/business/business-core/gda/gncmod-business-backend-gda.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/business/business-core/gda/gncmod-business-backend-gda.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -26,10 +26,14 @@
 #include "config.h"
 #include <gmodule.h>
 
+#include <libgda/libgda.h>
+
 #include "gnc-module.h"
 #include "gnc-module-api.h"
 #include "gnc-engine.h"
 
+#include "gnc-backend-util-gda.h"
+
 #include "gnc-address-gda.h"
 #include "gnc-bill-term-gda.h"
 #include "gnc-customer-gda.h"

Modified: gnucash/branches/gda-dev2/src/gnome/gnc-plugin-basic-commands.c
===================================================================
--- gnucash/branches/gda-dev2/src/gnome/gnc-plugin-basic-commands.c	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/gnome/gnc-plugin-basic-commands.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -41,6 +41,7 @@
 
 #include "dialog-book-close.h"
 #include "dialog-chart-export.h"
+#include "dialog-database-connection.h"
 #include "dialog-fincalc.h"
 #include "dialog-find-transactions.h"
 #include "dialog-sx-since-last-run.h"
@@ -67,6 +68,7 @@
 /* Command callbacks */
 static void gnc_main_window_cmd_file_new (GtkAction *action, GncMainWindowActionData *data);
 static void gnc_main_window_cmd_file_open (GtkAction *action, GncMainWindowActionData *data);
+static void gnc_main_window_cmd_file_db_connection (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_qsf_import (GtkAction *action, GncMainWindowActionData *data);
@@ -101,6 +103,9 @@
   { "FileOpenAction", GTK_STOCK_OPEN, N_("_Open..."), NULL,
     N_("Open an existing GnuCash file"),
     G_CALLBACK (gnc_main_window_cmd_file_open) },
+  { "FileDatabaseConnectionAction", NULL, N_("_Database Connection"), NULL,
+    N_("Connect to a database"),
+    G_CALLBACK (gnc_main_window_cmd_file_db_connection) },
   { "FileSaveAction", GTK_STOCK_SAVE, N_("_Save"), "<control>s",
     N_("Save the current file"),
     G_CALLBACK (gnc_main_window_cmd_file_save) },
@@ -333,6 +338,17 @@
 }
 
 static void
+gnc_main_window_cmd_file_db_connection (GtkAction *action, GncMainWindowActionData *data)
+{
+  g_return_if_fail (data != NULL);
+
+  if (!gnc_main_window_all_finish_pending())
+    return;
+
+  gnc_ui_database_connection();
+}
+
+static void
 gnc_main_window_cmd_file_save (GtkAction *action, GncMainWindowActionData *data)
 {
   g_return_if_fail (data != NULL);

Modified: gnucash/branches/gda-dev2/src/gnome/ui/gnc-plugin-basic-commands-ui.xml
===================================================================
--- gnucash/branches/gda-dev2/src/gnome/ui/gnc-plugin-basic-commands-ui.xml	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/gnome/ui/gnc-plugin-basic-commands-ui.xml	2007-12-31 18:52:32 UTC (rev 16777)
@@ -12,6 +12,7 @@
         </placeholder>
       </menu>
       <placeholder name="FileSavePlaceholder">
+		<menuitem name="FileDatabaseConnection" action="FileDatabaseConnectionAction"/>
         <menuitem name="FileSave" action="FileSaveAction"/>
         <menuitem name="FileSaveAs" action="FileSaveAsAction"/>
       </placeholder>

Modified: gnucash/branches/gda-dev2/src/gnome-utils/Makefile.am
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/Makefile.am	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/gnome-utils/Makefile.am	2007-12-31 18:52:32 UTC (rev 16777)
@@ -20,7 +20,8 @@
   ${GTKHTML_CFLAGS} \
   ${GUILE_INCS} \
   ${QOF_CFLAGS} \
-  ${GOFFICE_CFLAGS}
+  ${GOFFICE_CFLAGS} \
+  ${LIBGDA_CFLAGS}
 
 libgncmod_gnome_utils_la_SOURCES = \
   QuickFill.c \
@@ -29,6 +30,7 @@
   dialog-account.c \
   dialog-book-close.c \
   dialog-commodity.c \
+  dialog-database-connection.c \
   dialog-options.c \
   dialog-preferences.c \
   dialog-query-list.c \
@@ -102,6 +104,7 @@
   account-quickfill.h \
   dialog-account.h \
   dialog-book-close.h \
+  dialog-database-connection.h \
   dialog-commodity.h \
   dialog-preferences.h \
   dialog-options.h \

Added: gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c	                        (rev 0)
+++ gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.c	2007-12-31 18:52:32 UTC (rev 16777)
@@ -0,0 +1,158 @@
+/********************************************************************\
+ * dialog-database-connection.c -- dialog for opening a connection  *
+ *                        to a libgda database, either predefined   *
+ *                        in ~/.libgda/config or explicit using     *
+ *                        provider and database.                    *
+ *                                                                  *
+ * Copyright (C) 2007-8 Phil Longstaff (plongstaff at rogers.com)      *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+#include <glade/glade.h>
+
+#include <libgda/libgda.h>
+
+#include "gnc-ui.h"
+#include "dialog-utils.h"
+#include "dialog-database-connection.h"
+#include "gnc-file.h"
+#include "gnc-session.h"
+
+void gnc_database_connection_response_cb( GtkDialog *, gint, GtkDialog * );
+
+struct DatabaseConnectionWindow
+{
+  /* Parts of the dialog */
+  GtkWidget* dialog;
+  GtkWidget* rb_predefined;
+  GtkWidget* rb_general;
+  GtkWidget* cb_predefined;
+  GtkWidget* tf_general;
+
+  /* The final settings */
+};
+
+static void
+save_to_db( const gchar* url )
+{
+	gnc_file_do_save_as( url );
+}
+
+static void
+discard_and_open_db( const gchar* url )
+{
+  	QofBook* current_book;
+
+    current_book = qof_session_get_book( gnc_get_current_session() );
+	qof_book_mark_saved( current_book );
+	gnc_file_open_file( url );
+}
+
+void
+gnc_database_connection_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused)
+{
+    struct DatabaseConnectionWindow* dcw;
+	gchar* url;
+
+    g_return_if_fail( dialog != NULL );
+
+    dcw = g_object_get_data( G_OBJECT(dialog), "DatabaseConnectionWindow" );
+    g_return_if_fail(dcw);
+
+    switch( response ) {
+    case GTK_RESPONSE_HELP:
+        gnc_gnome_help( HF_HELP, HL_GLOBPREFS );
+        break;
+  
+    case GTK_RESPONSE_OK:
+		if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(dcw->rb_predefined) ) ) {
+			/* Selection from predefined list */
+			url = g_strdup_printf( "gda://@%s", gtk_combo_box_get_active_text( GTK_COMBO_BOX(dcw->cb_predefined) ) );
+
+		} else {
+			/* Selection using entered info */
+			url = g_strdup_printf( "gdk://%s", gtk_entry_get_text( GTK_ENTRY(dcw->tf_general) ) );
+		}
+		save_to_db( url );
+
+      /* FALLTHROUGH */ 
+    default:
+        gtk_widget_destroy( GTK_WIDGET(dialog) );
+        break;
+    }
+}
+
+void gnc_ui_database_connection( void )
+{
+    struct DatabaseConnectionWindow *dcw;
+    GladeXML* xml;
+    GtkWidget* box;
+	GList* ds_list;
+	GList* ds_node;
+	int n_rows;
+
+    dcw = g_new0(struct DatabaseConnectionWindow, 1);
+    g_return_if_fail(dcw);
+
+    /* Open the dialog */
+    xml = gnc_glade_xml_new( "dialog-database-connection.glade", "Database Connection" );
+    dcw->dialog = glade_xml_get_widget( xml, "Database Connection" );
+
+    /* Predefined */
+    dcw->rb_predefined = glade_xml_get_widget( xml, "rb_predefined" );
+	box = glade_xml_get_widget( xml, "predefined_connection_box" );
+//    dcw->cb_predefined = glade_xml_get_widget( xml, "cb_predefined_db_connections" );
+	dcw->cb_predefined = gtk_combo_box_new_text();
+	ds_list = gda_config_get_data_source_list();
+	n_rows = 0;
+	for( ds_node = ds_list; ds_node != NULL; ds_node = ds_node->next ) {
+		GdaDataSourceInfo* ds_info = ds_node->data;
+		gtk_combo_box_append_text( GTK_COMBO_BOX(dcw->cb_predefined), g_strdup(ds_info->name) );
+		n_rows++;
+	}
+	gda_config_free_data_source_list( ds_list );
+	if( n_rows != 0 ) {
+		gtk_combo_box_set_active( GTK_COMBO_BOX(dcw->cb_predefined), 0 );
+	} else {
+		gtk_widget_set_sensitive( dcw->rb_predefined, FALSE );
+	}
+	gtk_box_pack_start( GTK_BOX(box), dcw->cb_predefined, TRUE, TRUE, 0 );
+
+    /* General */
+    dcw->rb_general = glade_xml_get_widget( xml, "rb_general" );
+    dcw->tf_general = glade_xml_get_widget( xml, "tf_general_db_info" );
+
+    /* Autoconnect signals */
+    glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func,
+				    					dcw->dialog );
+
+    /* Clean up the xml data structure when the dialog is destroyed */
+    g_object_set_data_full( G_OBJECT(dcw->dialog), "dialog-database-connection.glade",
+			 				xml, g_object_unref );
+    g_object_set_data_full( G_OBJECT(dcw->dialog), "DatabaseConnectionWindow", dcw,
+			 				g_free );
+
+    /* Run the dialog */
+    gtk_widget_show_all( dcw->dialog );
+}
+

Added: gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.h
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.h	                        (rev 0)
+++ gnucash/branches/gda-dev2/src/gnome-utils/dialog-database-connection.h	2007-12-31 18:52:32 UTC (rev 16777)
@@ -0,0 +1,46 @@
+/********************************************************************\
+ * dialog-database-connection.h -- dialog for opening a connection  *
+ *                        to a libgda database, either predefined   *
+ *                        in ~/.libgda/config or explicit using     *
+ *                        provider and database.                    *
+ *                                                                  *
+ * Copyright (C) 2007-8 Phil Longstaff (plongstaff at rogers.com)      *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+
+#ifndef DIALOG_DATABASE_CONNECTION_H
+#define DIALOG_DATABASE_CONNECTION_H
+
+/** @addtogroup GUI
+    @{ */
+/** @file dialog-database-connection.h
+ *
+ *  This file contains the functions to present a GUI to select
+ *  a database connection.
+ */
+
+/** Create and run the dialog to close the book.
+ *
+ */
+void gnc_ui_database_connection( void );
+
+
+/** @} */
+
+#endif /* DIALOG_DATABASE_CONNECTION_H */

Modified: gnucash/branches/gda-dev2/src/gnome-utils/glade/Makefile.am
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/glade/Makefile.am	2007-12-31 13:52:24 UTC (rev 16776)
+++ gnucash/branches/gda-dev2/src/gnome-utils/glade/Makefile.am	2007-12-31 18:52:32 UTC (rev 16777)
@@ -2,6 +2,7 @@
 glade_DATA = \
   commodity.glade \
   dialog-book-close.glade \
+  dialog-database-connection.glade \
   dialog-query-list.glade \
   dialog-reset-warnings.glade \
   druid-provider-multifile.glade \

Added: gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade
===================================================================
--- gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade	                        (rev 0)
+++ gnucash/branches/gda-dev2/src/gnome-utils/glade/dialog-database-connection.glade	2007-12-31 18:52:32 UTC (rev 16777)
@@ -0,0 +1,185 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkDialog" id="Database Connection">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">Database Connection</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
+  <property name="has_separator">True</property>
+  <signal name="response" handler="gnc_database_connection_response_cb"/>
+
+  <child internal-child="vbox">
+    <widget class="GtkVBox" id="dialog-vbox1">
+      <property name="visible">True</property>
+      <property name="homogeneous">False</property>
+      <property name="spacing">0</property>
+
+      <child internal-child="action_area">
+	<widget class="GtkHButtonBox" id="dialog-action_area1">
+	  <property name="visible">True</property>
+	  <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+	  <child>
+	    <widget class="GtkButton" id="pb_help">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-help</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+		  <property name="response_id">-11</property>
+	    </widget>
+	  </child>
+
+	  <child>
+	    <widget class="GtkButton" id="pb_cancel">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-cancel</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+		  <property name="response_id">-6</property>
+	    </widget>
+	  </child>
+
+	  <child>
+	    <widget class="GtkButton" id="pb_ok">
+	      <property name="visible">True</property>
+	      <property name="can_default">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label">gtk-ok</property>
+	      <property name="use_stock">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+		  <property name="response_id">-5</property>
+	    </widget>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+      <child>
+	<widget class="GtkTable" id="table1">
+	  <property name="visible">True</property>
+	  <property name="n_rows">2</property>
+	  <property name="n_columns">2</property>
+	  <property name="homogeneous">False</property>
+	  <property name="row_spacing">0</property>
+	  <property name="column_spacing">0</property>
+
+	  <child>
+	    <widget class="GtkRadioButton" id="rb_predefined">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label" translatable="yes">Predefined</property>
+	      <property name="use_underline">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="active">False</property>
+	      <property name="inconsistent">False</property>
+	      <property name="draw_indicator">True</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">0</property>
+	      <property name="right_attach">1</property>
+	      <property name="top_attach">0</property>
+	      <property name="bottom_attach">1</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkRadioButton" id="rb_general">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="label" translatable="yes">General</property>
+	      <property name="use_underline">True</property>
+	      <property name="relief">GTK_RELIEF_NORMAL</property>
+	      <property name="focus_on_click">True</property>
+	      <property name="active">False</property>
+	      <property name="inconsistent">False</property>
+	      <property name="draw_indicator">True</property>
+	      <property name="group">rb_predefined</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">0</property>
+	      <property name="right_attach">1</property>
+	      <property name="top_attach">1</property>
+	      <property name="bottom_attach">2</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkEntry" id="tf_general_db_info">
+	      <property name="visible">True</property>
+	      <property name="can_focus">True</property>
+	      <property name="editable">True</property>
+	      <property name="visibility">True</property>
+	      <property name="max_length">0</property>
+	      <property name="text" translatable="yes"></property>
+	      <property name="has_frame">True</property>
+	      <property name="invisible_char">●</property>
+	      <property name="activates_default">False</property>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</property>
+	      <property name="top_attach">1</property>
+	      <property name="bottom_attach">2</property>
+	      <property name="y_options"></property>
+	    </packing>
+	  </child>
+
+	  <child>
+	    <widget class="GtkHBox" id="predefined_connection_box">
+	      <property name="visible">True</property>
+	      <property name="homogeneous">False</property>
+	      <property name="spacing">0</property>
+
+	      <child>
+		<placeholder/>
+	      </child>
+	    </widget>
+	    <packing>
+	      <property name="left_attach">1</property>
+	      <property name="right_attach">2</property>
+	      <property name="top_attach">0</property>
+	      <property name="bottom_attach">1</property>
+	      <property name="x_options">fill</property>
+	      <property name="y_options">fill</property>
+	    </packing>
+	  </child>
+	</widget>
+	<packing>
+	  <property name="padding">0</property>
+	  <property name="expand">True</property>
+	  <property name="fill">True</property>
+	</packing>
+      </child>
+    </widget>
+  </child>
+</widget>
+
+</glade-interface>



More information about the gnucash-changes mailing list