Handle specifying a directory as a dataset file.

The file chooser dialog would return a directory if the user selected
one and clicked "Open"; then, or if the users specified a directory on
the command line, Gnucash would present the rather misleading error "No
backend found".

So, first, if the user selects a directory and clicks open, the chooser
will now open the directory for browsing, just as if she had
double-clicked on the directory name in the tree view.

Next, if a directory is presented to qof_session_begin it will detect
that and set ERR_BACKEND_BAD_URL, which gnc_post_file_open will detect
and re-present the file chooser, open to that directory. (To prevent
confusion, gnc_post_file_open will put up the error dialog for BAD_URL;
the new file chooser dialog will open after that's dismissed. Since
there are other possible causes of a BAD_URL, if the filename isn't a
directory the chooser will open to the registered default directory from
GConf.)

BP

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21459 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
John Ralls 2011-10-19 00:02:59 +00:00
parent 43820fe81a
commit dffd44139d
3 changed files with 48 additions and 11 deletions

View File

@ -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 );

View File

@ -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;

View File

@ -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)