diff --git a/src/gnome-utils/dialog-file-access.c b/src/gnome-utils/dialog-file-access.c index 1853856bbe..adf9a6d000 100644 --- a/src/gnome-utils/dialog-file-access.c +++ b/src/gnome-utils/dialog-file-access.c @@ -131,6 +131,13 @@ gnc_ui_file_access_response_cb(GtkDialog *dialog, gint response, GtkDialog *unus { return; } + + if ( g_file_test( g_filename_from_uri( url, NULL, NULL ), + G_FILE_TEST_IS_DIR )) + { + gtk_file_chooser_set_current_folder_uri( faw->fileChooser, url ); + return; + } if ( faw->type == FILE_ACCESS_OPEN ) { gnc_file_open_file( url ); diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c index 515e0b210d..ac7845a0cf 100644 --- a/src/gnome-utils/gnc-file.c +++ b/src/gnome-utils/gnc-file.c @@ -631,7 +631,7 @@ gnc_post_file_open (const char * filename) ENTER(" "); - +RESTART: if (!filename) return FALSE; /* Convert user input into a normalized uri @@ -697,8 +697,26 @@ gnc_post_file_open (const char * filename) qof_session_begin (new_session, newfile, FALSE, FALSE, FALSE); io_err = qof_session_get_error (new_session); + + if (ERR_BACKEND_BAD_URL == io_err) + { + gchar *directory; + show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN); + io_err = ERR_BACKEND_NO_ERR; + if (g_file_test (filename, G_FILE_TEST_IS_DIR)) + directory = g_strdup (filename); + else + directory = gnc_get_default_directory (GCONF_DIR_OPEN_SAVE); + + filename = gnc_file_dialog (NULL, NULL, directory, + GNC_FILE_DIALOG_OPEN); + qof_session_destroy (new_session); + new_session = NULL; + g_free (directory); + goto RESTART; + } /* if file appears to be locked, ask the user ... */ - if (ERR_BACKEND_LOCKED == io_err || ERR_BACKEND_READONLY == io_err) + else if (ERR_BACKEND_LOCKED == io_err || ERR_BACKEND_READONLY == io_err) { GtkWidget *dialog; gchar *displayname = NULL; diff --git a/src/libqof/qof/qofsession.c b/src/libqof/qof/qofsession.c index 875870fc99..2498541abd 100644 --- a/src/libqof/qof/qofsession.c +++ b/src/libqof/qof/qofsession.c @@ -421,7 +421,7 @@ void qof_session_begin (QofSession *session, const char * book_id, gboolean ignore_lock, gboolean create, gboolean force) { - gchar **splituri; + gchar *scheme = NULL, *filename = NULL; if (!session) return; @@ -449,6 +449,22 @@ qof_session_begin (QofSession *session, const char * book_id, LEAVE("push error missing book_id"); return; } + scheme = g_uri_parse_scheme (book_id); + if (g_strcmp0 (scheme, "file") == 0) + filename = g_filename_from_uri (book_id, NULL, NULL); + else if (!scheme) + filename = g_strdup (book_id); + + if (filename && g_file_test (filename, G_FILE_TEST_IS_DIR)) + { + if (ERR_BACKEND_NO_ERR == qof_session_get_error(session)) + qof_session_push_error (session, ERR_BACKEND_BAD_URL, NULL); + g_free (filename); + g_free (scheme); + LEAVE("Can't open a directory"); + return; + } + /* destroy the old backend */ qof_session_destroy_backend(session); @@ -456,16 +472,12 @@ qof_session_begin (QofSession *session, const char * book_id, /* Store the session URL */ session->book_id = g_strdup (book_id); - /* Look for something of the form of "file://", "http://" or - * "postgres://". Everything before the colon is the access - * method. Load the first backend found for that access method. - */ - splituri = g_strsplit ( book_id, "://", 2 ); - if ( splituri[1] == NULL ) /* no access method in the uri, use generic "file" backend */ + if (filename) qof_session_load_backend(session, "file"); else /* access method found, load appropriate backend */ - qof_session_load_backend(session, splituri[0]); - g_strfreev ( splituri ); + qof_session_load_backend(session, scheme); + g_free (filename); + g_free (scheme); /* No backend was found. That's bad. */ if (NULL == session->backend)