mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add dialogs to create a new database, if it didn't exist before
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3593 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
102
src/FileDialog.c
102
src/FileDialog.c
@@ -118,6 +118,12 @@ show_book_error (GNCBackendError io_error, const char *newfile)
|
||||
gnc_error_dialog (fmt);
|
||||
break;
|
||||
|
||||
case ERR_SQL_BAD_LOCATION:
|
||||
fmt = _("Can't parse the database URL\n %s\n");
|
||||
buf = g_strdup_printf (fmt, newfile);
|
||||
gnc_error_dialog (buf);
|
||||
break;
|
||||
|
||||
case ERR_SQL_CANT_CONNECT:
|
||||
fmt = _("Can't connect to the database\n %s\n"
|
||||
"The host, username or password were incorrect.");
|
||||
@@ -138,6 +144,50 @@ show_book_error (GNCBackendError io_error, const char *newfile)
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static gboolean
|
||||
gncLockFailHandler (const char *file)
|
||||
{
|
||||
const char *format = _("Gnucash could not obtain the lock for\n"
|
||||
" %s.\n"
|
||||
"That database may be in use by another user,\n"
|
||||
"in which case you should not open the database.\n"
|
||||
"\nDo you want to proceed with opening the database?");
|
||||
char *message;
|
||||
gboolean result;
|
||||
|
||||
if (file == NULL)
|
||||
return FALSE;
|
||||
|
||||
message = g_strdup_printf (format, file);
|
||||
result = gnc_verify_dialog (message, FALSE);
|
||||
g_free (message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static gboolean
|
||||
gncCreateFailHandler (const char *file)
|
||||
{
|
||||
const char *format = _("The database\n"
|
||||
" %s\n"
|
||||
"doesn't seem to exist. Do you want to create it?\n");
|
||||
char *message;
|
||||
gboolean result;
|
||||
|
||||
if (file == NULL)
|
||||
return FALSE;
|
||||
|
||||
message = g_strdup_printf (format, file);
|
||||
result = gnc_verify_dialog (message, FALSE);
|
||||
g_free (message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
void
|
||||
gncFileNew (void)
|
||||
{
|
||||
@@ -206,29 +256,6 @@ gncFileQuerySave (void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
|
||||
static gboolean
|
||||
gncLockFailHandler (const char *file)
|
||||
{
|
||||
const char *format = _("Gnucash could not obtain the lock for\n"
|
||||
" %s.\n"
|
||||
"That database may be in use by another user,\n"
|
||||
"in which case you should not open the database.\n"
|
||||
"\nDo you want to proceed with opening the database?");
|
||||
char *message;
|
||||
gboolean result;
|
||||
|
||||
if (file == NULL)
|
||||
return FALSE;
|
||||
|
||||
message = g_strdup_printf (format, file);
|
||||
result = gnc_verify_dialog (message, FALSE);
|
||||
g_free (message);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* ======================================================== */
|
||||
/* private utilities for file open; done in two stages */
|
||||
|
||||
@@ -272,7 +299,7 @@ gncPostFileOpen (const char * filename)
|
||||
|
||||
new_group = NULL;
|
||||
|
||||
gnc_book_begin (new_book, newfile, FALSE);
|
||||
gnc_book_begin (new_book, newfile, FALSE, FALSE);
|
||||
io_err = gnc_book_get_error (new_book);
|
||||
|
||||
/* if file appears to be locked, ask the user ... */
|
||||
@@ -281,7 +308,17 @@ gncPostFileOpen (const char * filename)
|
||||
if (gncLockFailHandler (newfile))
|
||||
{
|
||||
/* user told us to ignore locks. So ignore them. */
|
||||
gnc_book_begin (new_book, newfile, TRUE);
|
||||
gnc_book_begin (new_book, newfile, TRUE, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* if the database doesn't exist, ask the user ... */
|
||||
else if (ERR_BACKEND_NO_SUCH_DB == io_err)
|
||||
{
|
||||
if (gncCreateFailHandler (newfile))
|
||||
{
|
||||
/* user told us to create a new database. Do it. */
|
||||
gnc_book_begin (new_book, newfile, FALSE, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,19 +519,30 @@ gncFileSaveAs (void)
|
||||
* edit; the mass deletetion of accounts and transactions during
|
||||
* switchover is not something we want to keep in a journal. */
|
||||
new_book = gnc_book_new ();
|
||||
gnc_book_begin (new_book, newfile, FALSE);
|
||||
gnc_book_begin (new_book, newfile, FALSE, FALSE);
|
||||
|
||||
io_err = gnc_book_get_error (new_book);
|
||||
|
||||
/* if file appears to be locked, ask the user ... */
|
||||
if (ERR_BACKEND_LOCKED == io_err)
|
||||
{
|
||||
if (gncLockFailHandler (newfile))
|
||||
{
|
||||
/* user told us to ignore locks. So ignore them. */
|
||||
gnc_book_begin (new_book, newfile, TRUE);
|
||||
gnc_book_begin (new_book, newfile, TRUE, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* if the database doesn't exist, ask the user ... */
|
||||
else if (ERR_BACKEND_NO_SUCH_DB == io_err)
|
||||
{
|
||||
if (gncCreateFailHandler (newfile))
|
||||
{
|
||||
/* user told us to create a new database. Do it. */
|
||||
gnc_book_begin (new_book, newfile, FALSE, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/* check again for session errors (since above dialog may have
|
||||
* cleared a file lock & moved things forward some more)
|
||||
* This time, errors will be fatal.
|
||||
|
||||
Reference in New Issue
Block a user