mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
1) Add new dialog-file-access which combines the standard GTK file selection widget with
the database selection fields from the old database connection dialog. If --enable-dbi is specified at configuration time, this dialog is used instead of the file open and save-as dialogs. 2) Prompt to create a mysql db if it doesn't exist. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17976 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
dea5a1c388
commit
bcf974bd11
@ -54,6 +54,11 @@
|
||||
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
#define FILE_URI_TYPE "file"
|
||||
#define FILE_URI_PREFIX (FILE_URI_TYPE "://")
|
||||
#define SQLITE3_URI_TYPE "sqlite3"
|
||||
#define SQLITE3_URI_PREFIX (SQLITE3_URI_TYPE "://")
|
||||
|
||||
typedef gchar* (*CREATE_TABLE_DDL_FN)( GncSqlConnection* conn,
|
||||
const gchar* table_name,
|
||||
const GList* col_info_list );
|
||||
@ -103,6 +108,7 @@ struct GncDbiBackend_struct
|
||||
gboolean in_query;
|
||||
gboolean supports_transactions;
|
||||
gboolean is_pristine_db; // Are we saving to a new pristine db?
|
||||
gboolean exists; // Does the database exist?
|
||||
|
||||
gint obj_total; // Total # of objects (for percentage calculation)
|
||||
gint operations_done; // Number of operations (save/load) done
|
||||
@ -127,7 +133,7 @@ create_tables_cb( const gchar* type, gpointer data_p, gpointer be_p )
|
||||
}
|
||||
|
||||
static void
|
||||
error_fn( dbi_conn conn, void* user_data )
|
||||
sqlite3_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
GncDbiBackend *be = (GncDbiBackend*)user_data;
|
||||
const gchar* msg;
|
||||
@ -153,6 +159,14 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
|
||||
|
||||
ENTER (" ");
|
||||
|
||||
/* Remove uri type if present */
|
||||
if( g_str_has_prefix( book_id, FILE_URI_PREFIX ) ) {
|
||||
book_id += strlen( FILE_URI_PREFIX );
|
||||
}
|
||||
if( g_str_has_prefix( book_id, SQLITE3_URI_PREFIX ) ) {
|
||||
book_id += strlen( SQLITE3_URI_PREFIX );
|
||||
}
|
||||
|
||||
if (!create_if_nonexistent
|
||||
&& !g_file_test(book_id, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
|
||||
qof_backend_set_error(qbe, ERR_FILEIO_FILE_NOT_FOUND);
|
||||
@ -170,7 +184,7 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
|
||||
|
||||
dirname = g_path_get_dirname( book_id );
|
||||
basename = g_path_get_basename( book_id );
|
||||
dbi_conn_error_handler( be->conn, error_fn, be );
|
||||
dbi_conn_error_handler( be->conn, sqlite3_error_fn, be );
|
||||
dbi_conn_set_option( be->conn, "host", "localhost" );
|
||||
dbi_conn_set_option( be->conn, "dbname", basename );
|
||||
dbi_conn_set_option( be->conn, "sqlite3_dbdir", dirname );
|
||||
@ -189,6 +203,19 @@ gnc_dbi_sqlite3_session_begin( QofBackend *qbe, QofSession *session,
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
static void
|
||||
mysql_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
GncDbiBackend *be = (GncDbiBackend*)user_data;
|
||||
const gchar* msg;
|
||||
|
||||
dbi_conn_error( conn, &msg );
|
||||
PERR( "DBI error: %s\n", msg );
|
||||
if( g_str_has_prefix( msg, "1049: Unknown database" ) ) {
|
||||
be->exists = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_dbi_mysql_session_begin( QofBackend *qbe, QofSession *session,
|
||||
const gchar *book_id,
|
||||
@ -227,26 +254,53 @@ gnc_dbi_mysql_session_begin( QofBackend *qbe, QofSession *session,
|
||||
LEAVE( " " );
|
||||
return;
|
||||
}
|
||||
dbi_conn_error_handler( be->conn, error_fn, be );
|
||||
dbi_conn_error_handler( be->conn, mysql_error_fn, be );
|
||||
dbi_conn_set_option( be->conn, "host", host );
|
||||
dbi_conn_set_option_numeric( be->conn, "port", 0 );
|
||||
dbi_conn_set_option( be->conn, "dbname", dbname );
|
||||
dbi_conn_set_option( be->conn, "dbname", "mysql" );
|
||||
dbi_conn_set_option( be->conn, "username", username );
|
||||
dbi_conn_set_option( be->conn, "password", password );
|
||||
be->exists = TRUE;
|
||||
result = dbi_conn_connect( be->conn );
|
||||
g_free( dsn );
|
||||
if( result < 0 ) {
|
||||
if( result == 0 ) {
|
||||
result = dbi_conn_select_db( be->conn, dbname );
|
||||
if( result == 0 ) {
|
||||
be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_MYSQL, be->conn );
|
||||
} else {
|
||||
if( create_if_nonexistent ) {
|
||||
/* Couldn't select the db, so try to create it */
|
||||
dbi_result dresult;
|
||||
dresult = dbi_conn_queryf( be->conn, "CREATE DATABASE %s", dbname );
|
||||
result = dbi_conn_select_db( be->conn, dbname );
|
||||
if( result == 0 ) {
|
||||
be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_MYSQL, be->conn );
|
||||
} else {
|
||||
PERR( "Unable to connect to %s: %d\n", book_id, result );
|
||||
qof_backend_set_error( qbe, ERR_BACKEND_CANT_CONNECT );
|
||||
}
|
||||
} else {
|
||||
qof_backend_set_error( qbe, ERR_BACKEND_NO_SUCH_DB );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PERR( "Unable to connect to %s: %d\n", book_id, result );
|
||||
qof_backend_set_error( qbe, ERR_BACKEND_BAD_URL );
|
||||
LEAVE( " " );
|
||||
return;
|
||||
qof_backend_set_error( qbe, ERR_BACKEND_CANT_CONNECT );
|
||||
}
|
||||
|
||||
be->sql_be.conn = create_dbi_connection( GNC_DBI_PROVIDER_MYSQL, be->conn );
|
||||
|
||||
g_free( dsn );
|
||||
LEAVE (" ");
|
||||
}
|
||||
|
||||
static void
|
||||
pgsql_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
GncDbiBackend *be = (GncDbiBackend*)user_data;
|
||||
const gchar* msg;
|
||||
|
||||
dbi_conn_error( conn, &msg );
|
||||
PERR( "DBI error: %s\n", msg );
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
|
||||
const gchar *book_id,
|
||||
@ -285,7 +339,7 @@ gnc_dbi_postgres_session_begin( QofBackend *qbe, QofSession *session,
|
||||
LEAVE( " " );
|
||||
return;
|
||||
}
|
||||
dbi_conn_error_handler( be->conn, error_fn, be );
|
||||
dbi_conn_error_handler( be->conn, pgsql_error_fn, be );
|
||||
dbi_conn_set_option( be->conn, "host", host );
|
||||
dbi_conn_set_option_numeric( be->conn, "port", 0 );
|
||||
dbi_conn_set_option( be->conn, "dbname", dbname );
|
||||
@ -618,7 +672,16 @@ qof_backend_module_init(void)
|
||||
|
||||
prov = g_new0 (QofBackendProvider, 1);
|
||||
prov->provider_name = "GnuCash Libdbi (SQLITE3) Backend";
|
||||
prov->access_method = "file";
|
||||
prov->access_method = FILE_URI_TYPE;
|
||||
prov->partial_book_supported = FALSE;
|
||||
prov->backend_new = gnc_dbi_backend_sqlite3_new;
|
||||
prov->provider_free = gnc_dbi_provider_free;
|
||||
prov->check_data_type = gnc_dbi_check_sqlite3_file;
|
||||
qof_backend_register_provider( prov );
|
||||
|
||||
prov = g_new0 (QofBackendProvider, 1);
|
||||
prov->provider_name = "GnuCash Libdbi (SQLITE3) Backend";
|
||||
prov->access_method = SQLITE3_URI_TYPE;
|
||||
prov->partial_book_supported = FALSE;
|
||||
prov->backend_new = gnc_dbi_backend_sqlite3_new;
|
||||
prov->provider_free = gnc_dbi_provider_free;
|
||||
|
@ -20,8 +20,7 @@ AM_CPPFLAGS = \
|
||||
${GTKHTML_CFLAGS} \
|
||||
${GUILE_INCS} \
|
||||
${QOF_CFLAGS} \
|
||||
${GOFFICE_CFLAGS} \
|
||||
${LIBGDA_CFLAGS}
|
||||
${GOFFICE_CFLAGS}
|
||||
|
||||
libgncmod_gnome_utils_la_SOURCES = \
|
||||
QuickFill.c \
|
||||
@ -30,7 +29,7 @@ libgncmod_gnome_utils_la_SOURCES = \
|
||||
dialog-account.c \
|
||||
dialog-book-close.c \
|
||||
dialog-commodity.c \
|
||||
dialog-database-connection.c \
|
||||
dialog-file-access.c \
|
||||
dialog-options.c \
|
||||
dialog-preferences.c \
|
||||
dialog-query-list.c \
|
||||
@ -106,7 +105,7 @@ gncinclude_HEADERS = \
|
||||
dialog-account.h \
|
||||
dialog-book-close.h \
|
||||
dialog-commodity.h \
|
||||
dialog-database-connection.h \
|
||||
dialog-file-access.h \
|
||||
dialog-preferences.h \
|
||||
dialog-options.h \
|
||||
dialog-query-list.h \
|
||||
|
308
src/gnome-utils/dialog-file-access.c
Normal file
308
src/gnome-utils/dialog-file-access.c
Normal file
@ -0,0 +1,308 @@
|
||||
/********************************************************************\
|
||||
* dialog-file-access.c -- dialog for opening a file or making a *
|
||||
* connection to a libdbi database *
|
||||
* *
|
||||
* Copyright (C) 2009 Phil Longstaff (plongstaff@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@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <glade/glade.h>
|
||||
|
||||
#include "gnc-ui.h"
|
||||
#include "dialog-utils.h"
|
||||
#include "dialog-file-access.h"
|
||||
#include "gnc-file.h"
|
||||
#include "gnc-session.h"
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_GUI;
|
||||
|
||||
#define DEFAULT_HOST "localhost"
|
||||
#define DEFAULT_DATABASE "gnucash"
|
||||
#define FILE_ACCESS_OPEN 0
|
||||
#define FILE_ACCESS_SAVE_AS 1
|
||||
|
||||
void gnc_ui_file_access_response_cb( GtkDialog *, gint, GtkDialog * );
|
||||
void gnc_ui_file_access_rb_xml_clicked_cb( GtkToggleButton* tb );
|
||||
void gnc_ui_file_access_rb_sqlite3_clicked_cb( GtkToggleButton* tb );
|
||||
void gnc_ui_file_access_rb_mysql_clicked_cb( GtkToggleButton* tb );
|
||||
void gnc_ui_file_access_rb_pgsql_clicked_cb( GtkToggleButton* tb );
|
||||
|
||||
typedef struct FileAccessWindow
|
||||
{
|
||||
/* Parts of the dialog */
|
||||
int type;
|
||||
|
||||
GtkWidget* dialog;
|
||||
GtkWidget* frame_file;
|
||||
GtkWidget* frame_database;
|
||||
GtkFileChooser* fileChooser;
|
||||
GtkWidget* rb_xml;
|
||||
GtkWidget* rb_sqlite3;
|
||||
GtkWidget* rb_mysql;
|
||||
GtkWidget* rb_pgsql;
|
||||
GtkWidget* tf_host;
|
||||
GtkWidget* tf_database;
|
||||
GtkWidget* tf_username;
|
||||
GtkWidget* tf_password;
|
||||
} FileAccessWindow;
|
||||
|
||||
static gchar*
|
||||
geturl( FileAccessWindow* faw )
|
||||
{
|
||||
gchar* url;
|
||||
const gchar* host;
|
||||
const gchar* database;
|
||||
const gchar* username;
|
||||
const gchar* password;
|
||||
const gchar* type;
|
||||
const gchar* file;
|
||||
|
||||
host = gtk_entry_get_text( GTK_ENTRY(faw->tf_host) );
|
||||
database = gtk_entry_get_text( GTK_ENTRY(faw->tf_database) );
|
||||
username = gtk_entry_get_text( GTK_ENTRY(faw->tf_username) );
|
||||
password = gtk_entry_get_text( GTK_ENTRY(faw->tf_password) );
|
||||
file = gtk_file_chooser_get_filename( faw->fileChooser );
|
||||
|
||||
if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_xml) ) ) {
|
||||
type = "xml";
|
||||
url = g_strdup_printf( "%s://%s", type, file );
|
||||
} else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_sqlite3) ) ) {
|
||||
type = "sqlite3";
|
||||
url = g_strdup_printf( "%s://%s", type, file );
|
||||
} else if( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_mysql) ) ) {
|
||||
type = "mysql";
|
||||
url = g_strdup_printf( "%s://%s:%s:%s:%s",
|
||||
type, host, database, username, password );
|
||||
} else {
|
||||
g_assert( gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(faw->rb_pgsql) ) );
|
||||
type = "postgres";
|
||||
url = g_strdup_printf( "%s://%s:%s:%s:%s",
|
||||
type, host, database, username, password );
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused)
|
||||
{
|
||||
FileAccessWindow* faw;
|
||||
gchar* url;
|
||||
|
||||
g_return_if_fail( dialog != NULL );
|
||||
|
||||
faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
switch( response ) {
|
||||
case GTK_RESPONSE_HELP:
|
||||
gnc_gnome_help( HF_HELP, HL_GLOBPREFS );
|
||||
break;
|
||||
|
||||
case GTK_RESPONSE_OK:
|
||||
url = geturl( faw );
|
||||
if( faw->type == FILE_ACCESS_OPEN ) {
|
||||
gnc_file_open_file( url );
|
||||
} else if( faw->type == FILE_ACCESS_SAVE_AS ) {
|
||||
gnc_file_do_save_as( url );
|
||||
}
|
||||
break;
|
||||
|
||||
case GTK_RESPONSE_CANCEL:
|
||||
break;
|
||||
|
||||
default:
|
||||
PERR( "Invalid response" );
|
||||
break;
|
||||
}
|
||||
|
||||
if( response != GTK_RESPONSE_HELP ) {
|
||||
gtk_widget_destroy( GTK_WIDGET(dialog) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Activate the file chooser and deactivate the db selection fields */
|
||||
static void
|
||||
on_rb_filetype_clicked( FileAccessWindow* faw )
|
||||
{
|
||||
gtk_widget_set_sensitive( faw->frame_file, TRUE );
|
||||
gtk_widget_set_sensitive( faw->frame_database, FALSE );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_rb_xml_clicked_cb( GtkToggleButton* tb )
|
||||
{
|
||||
GtkWidget* dialog;
|
||||
FileAccessWindow* faw;
|
||||
|
||||
g_return_if_fail( tb != NULL );
|
||||
|
||||
if( gtk_toggle_button_get_active( tb ) ) {
|
||||
dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
|
||||
g_return_if_fail( dialog != NULL );
|
||||
faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
on_rb_filetype_clicked( faw );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_rb_sqlite3_clicked_cb( GtkToggleButton* tb )
|
||||
{
|
||||
GtkWidget* dialog;
|
||||
FileAccessWindow* faw;
|
||||
|
||||
if( gtk_toggle_button_get_active( tb ) ) {
|
||||
dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
|
||||
g_return_if_fail( dialog != NULL );
|
||||
faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
on_rb_filetype_clicked( faw );
|
||||
}
|
||||
}
|
||||
|
||||
/* Deactivate the file chooser and activate the db selection fields */
|
||||
static void
|
||||
on_rb_databasetype_clicked( FileAccessWindow* faw )
|
||||
{
|
||||
gtk_widget_set_sensitive( faw->frame_file, FALSE );
|
||||
gtk_widget_set_sensitive( faw->frame_database, TRUE );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_rb_mysql_clicked_cb( GtkToggleButton* tb )
|
||||
{
|
||||
GtkWidget* dialog;
|
||||
FileAccessWindow* faw;
|
||||
|
||||
if( gtk_toggle_button_get_active( tb ) ) {
|
||||
g_return_if_fail( tb != NULL );
|
||||
dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
|
||||
g_return_if_fail( dialog != NULL );
|
||||
faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
on_rb_databasetype_clicked( faw );
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_rb_pgsql_clicked_cb( GtkToggleButton* tb )
|
||||
{
|
||||
GtkWidget* dialog;
|
||||
FileAccessWindow* faw;
|
||||
|
||||
if( gtk_toggle_button_get_active( tb ) ) {
|
||||
g_return_if_fail( tb != NULL );
|
||||
dialog = gtk_widget_get_toplevel( GTK_WIDGET(tb) );
|
||||
g_return_if_fail( dialog != NULL );
|
||||
faw = g_object_get_data( G_OBJECT(dialog), "FileAccessWindow" );
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
on_rb_databasetype_clicked( faw );
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_ui_file_access( int type )
|
||||
{
|
||||
FileAccessWindow *faw;
|
||||
GladeXML* xml;
|
||||
GtkWidget* box;
|
||||
GList* ds_node;
|
||||
GtkButton* op;
|
||||
GtkWidget* align;
|
||||
GtkFileChooserWidget* fileChooser;
|
||||
GtkFileChooserAction fileChooserAction;
|
||||
|
||||
g_return_if_fail( type == FILE_ACCESS_OPEN || type == FILE_ACCESS_SAVE_AS );
|
||||
|
||||
faw = g_new0(FileAccessWindow, 1);
|
||||
g_return_if_fail( faw != NULL );
|
||||
|
||||
faw->type = type;
|
||||
|
||||
/* Open the dialog */
|
||||
xml = gnc_glade_xml_new( "dialog-file-access.glade", "File Access" );
|
||||
faw->dialog = glade_xml_get_widget( xml, "File Access" );
|
||||
|
||||
faw->frame_file = glade_xml_get_widget( xml, "frame_file" );
|
||||
faw->frame_database = glade_xml_get_widget( xml, "frame_database" );
|
||||
faw->rb_xml = glade_xml_get_widget( xml, "rb_xml" );
|
||||
faw->rb_sqlite3 = glade_xml_get_widget( xml, "rb_sqlite3" );
|
||||
faw->rb_mysql = glade_xml_get_widget( xml, "rb_mysql" );
|
||||
faw->rb_pgsql = glade_xml_get_widget( xml, "rb_pgsql" );
|
||||
faw->tf_host = glade_xml_get_widget( xml, "tf_host" );
|
||||
gtk_entry_set_text( GTK_ENTRY(faw->tf_host), DEFAULT_HOST );
|
||||
faw->tf_database = glade_xml_get_widget( xml, "tf_database" );
|
||||
gtk_entry_set_text( GTK_ENTRY(faw->tf_database), DEFAULT_DATABASE );
|
||||
faw->tf_username = glade_xml_get_widget( xml, "tf_username" );
|
||||
faw->tf_password = glade_xml_get_widget( xml, "tf_password" );
|
||||
op = GTK_BUTTON(glade_xml_get_widget( xml, "pb_op" ));
|
||||
if( op != NULL ) {
|
||||
switch( type ) {
|
||||
case FILE_ACCESS_OPEN:
|
||||
gtk_button_set_label( op, "gtk-open" );
|
||||
fileChooserAction = GTK_FILE_CHOOSER_ACTION_OPEN;
|
||||
break;
|
||||
|
||||
case FILE_ACCESS_SAVE_AS:
|
||||
gtk_button_set_label( op, "gtk-save-as" );
|
||||
fileChooserAction = GTK_FILE_CHOOSER_ACTION_SAVE;
|
||||
break;
|
||||
}
|
||||
gtk_button_set_use_stock( op, TRUE );
|
||||
}
|
||||
align = glade_xml_get_widget( xml, "alignment_file_chooser" );
|
||||
fileChooser = GTK_FILE_CHOOSER_WIDGET(gtk_file_chooser_widget_new( fileChooserAction ));
|
||||
faw->fileChooser = GTK_FILE_CHOOSER(fileChooser);
|
||||
gtk_container_add( GTK_CONTAINER(align), GTK_WIDGET(fileChooser) );
|
||||
|
||||
/* Autoconnect signals */
|
||||
glade_xml_signal_autoconnect_full( xml, gnc_glade_autoconnect_full_func,
|
||||
faw->dialog );
|
||||
|
||||
/* Clean up the xml data structure when the dialog is destroyed */
|
||||
g_object_set_data_full( G_OBJECT(faw->dialog), "dialog-file-access.glade",
|
||||
xml, g_object_unref );
|
||||
g_object_set_data_full( G_OBJECT(faw->dialog), "FileAccessWindow", faw,
|
||||
g_free );
|
||||
|
||||
/* Run the dialog */
|
||||
gtk_widget_show_all( faw->dialog );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_ui_file_access_for_open( void )
|
||||
{
|
||||
gnc_ui_file_access( FILE_ACCESS_OPEN );
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
gnc_ui_file_access_for_save_as( void )
|
||||
{
|
||||
gnc_ui_file_access( FILE_ACCESS_SAVE_AS );
|
||||
}
|
42
src/gnome-utils/dialog-file-access.h
Normal file
42
src/gnome-utils/dialog-file-access.h
Normal file
@ -0,0 +1,42 @@
|
||||
/********************************************************************\
|
||||
* dialog-file-access.h -- dialog for opening a file or making a *
|
||||
* connection to a libdbi database *
|
||||
* *
|
||||
* Copyright (C) 2009 Phil Longstaff (plongstaff@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@gnu.org *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef DIALOG_FILE_ACCESS_H
|
||||
#define DIALOG_FILE_ACCESS_H
|
||||
|
||||
/** @addtogroup GUI
|
||||
@{ */
|
||||
/** @file dialog-file-access.h
|
||||
*
|
||||
* This file contains the functions to present a GUI to select
|
||||
* a file or a database connection. Separate functions exist for
|
||||
* loading/open and for saving.
|
||||
*/
|
||||
|
||||
void gnc_ui_file_access_for_open( void );
|
||||
void gnc_ui_file_access_for_save_as( void );
|
||||
|
||||
/** @} */
|
||||
|
||||
#endif /* DIALOG_FILE_ACCESS_H */
|
@ -3,6 +3,7 @@ glade_DATA = \
|
||||
commodity.glade \
|
||||
dialog-book-close.glade \
|
||||
dialog-database-connection.glade \
|
||||
dialog-file-access.glade \
|
||||
dialog-query-list.glade \
|
||||
dialog-reset-warnings.glade \
|
||||
druid-provider-multifile.glade \
|
||||
|
266
src/gnome-utils/glade/dialog-file-access.glade
Normal file
266
src/gnome-utils/glade/dialog-file-access.glade
Normal file
@ -0,0 +1,266 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.4.5 on Thu Mar 5 16:47:47 2009 -->
|
||||
<glade-interface>
|
||||
<widget class="GtkDialog" id="File Access">
|
||||
<property name="border_width">5</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
<signal name="response" handler="gnc_ui_file_access_response_cb"/>
|
||||
<child internal-child="vbox">
|
||||
<widget class="GtkVBox" id="dialog-vbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox1">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox2">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkRadioButton" id="rb_xml">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">XML</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">rb_sqlite3</property>
|
||||
<signal name="clicked" handler="gnc_ui_file_access_rb_xml_clicked_cb"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkRadioButton" id="rb_sqlite3">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">SQLite3</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="clicked" handler="gnc_ui_file_access_rb_sqlite3_clicked_cb"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkRadioButton" id="rb_mysql">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">MySQL</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">rb_xml</property>
|
||||
<signal name="clicked" handler="gnc_ui_file_access_rb_mysql_clicked_cb"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkRadioButton" id="rb_pgsql">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">PostgreSQL</property>
|
||||
<property name="response_id">0</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">rb_xml</property>
|
||||
<signal name="clicked" handler="gnc_ui_file_access_rb_pgsql_clicked_cb"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkFrame" id="frame_database">
|
||||
<property name="visible">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment2">
|
||||
<property name="visible">True</property>
|
||||
<property name="left_padding">12</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox2">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox3">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label2">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">host</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label3">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">database</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label4">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">username</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label6">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">password</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vbox4">
|
||||
<property name="visible">True</property>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="tf_host">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="tf_database">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="tf_username">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkEntry" id="tf_password">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>Database Connection</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="type">label_item</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkFrame" id="frame_file">
|
||||
<property name="visible">True</property>
|
||||
<property name="label_xalign">0</property>
|
||||
<property name="shadow_type">GTK_SHADOW_IN</property>
|
||||
<child>
|
||||
<widget class="GtkAlignment" id="alignment_file_chooser">
|
||||
<property name="visible">True</property>
|
||||
<property name="left_padding">12</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label5">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes"><b>File</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="type">label_item</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<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="cancel_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="label" translatable="yes">gtk-cancel</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">-6</property>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="pb_op">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="label" translatable="yes">gtk-save-as</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">-5</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="pack_type">GTK_PACK_END</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</glade-interface>
|
@ -41,7 +41,7 @@
|
||||
|
||||
#include "dialog-book-close.h"
|
||||
#include "dialog-chart-export.h"
|
||||
#include "dialog-database-connection.h"
|
||||
#include "dialog-file-access.h"
|
||||
#include "dialog-fincalc.h"
|
||||
#include "dialog-find-transactions.h"
|
||||
#include "dialog-sx-since-last-run.h"
|
||||
@ -361,7 +361,11 @@ gnc_main_window_cmd_file_open (GtkAction *action, GncMainWindowActionData *data)
|
||||
return;
|
||||
|
||||
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
|
||||
#ifdef HAVE_DBI_DBI_H
|
||||
gnc_ui_file_access_for_open();
|
||||
#else
|
||||
gnc_file_open ();
|
||||
#endif
|
||||
gnc_window_set_progressbar_window (NULL);
|
||||
}
|
||||
|
||||
@ -373,7 +377,7 @@ gnc_main_window_cmd_file_db_connection (GtkAction *action, GncMainWindowActionDa
|
||||
if (!gnc_main_window_all_finish_pending())
|
||||
return;
|
||||
|
||||
gnc_ui_database_connection();
|
||||
gnc_ui_file_access_for_open();
|
||||
}
|
||||
|
||||
static void
|
||||
@ -399,7 +403,11 @@ gnc_main_window_cmd_file_save_as (GtkAction *action, GncMainWindowActionData *da
|
||||
return;
|
||||
|
||||
gnc_window_set_progressbar_window (GNC_WINDOW(data->window));
|
||||
#ifdef HAVE_DBI_DBI_H
|
||||
gnc_ui_file_access_for_save_as();
|
||||
#else
|
||||
gnc_file_save_as ();
|
||||
#endif
|
||||
gnc_window_set_progressbar_window (NULL);
|
||||
/* FIXME GNOME 2 Port (update the title etc.) */
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user