From d4e3354c470ea1a2c70b4a66287d968de93d1c64 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Sun, 23 Jan 2011 17:50:43 +0000 Subject: [PATCH] Provide more detail in commit error when it's caused by a read-only book. Mark error message for translation. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20155 57a11ea4-9604-0410-9ed3-97b8803252fd --- configure.ac | 2 +- src/gnome-utils/gnc-file.c | 50 ++++++++++++++++++++++--------- src/gnome-utils/gnc-main-window.c | 7 +++-- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/configure.ac b/configure.ac index af7736e875..7ecd3de238 100644 --- a/configure.ac +++ b/configure.ac @@ -79,7 +79,7 @@ AC_DEFINE_UNQUOTED(GNUCASH_LATEST_STABLE_SERIES, "$GNUCASH_LATEST_STABLE_SERIES" [Most recent stable GnuCash series]) dnl Set of available languages. -ALL_LINGUAS="bg ca cs da de el en_GB es_NI es eu fa fi fr he hu it ja ko lt lv nb ne nl pl pt_BR pt ro ru rw sk sv ta tr uk vi zh_CN zh_TW" +ALL_LINGUAS="bg ca cs da de el en en_GB es_NI es eu fa fi fr he hu it ja ko lt lv nb ne nl pl pt_BR pt ro ru rw sk sv ta tr uk vi zh_CN zh_TW" GETTEXT_PACKAGE=gnucash AC_SUBST(GETTEXT_PACKAGE) diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c index 69c3d493db..e9a1943465 100644 --- a/src/gnome-utils/gnc-file.c +++ b/src/gnome-utils/gnc-file.c @@ -411,12 +411,19 @@ show_session_error (QofBackendError io_error, case ERR_SQL_DB_TOO_OLD: fmt = _("This database is from an older version of GnuCash. " - "Do you want to want to upgrade the database " - "to the current version?"); - if (gnc_verify_dialog (parent, TRUE, "%s", fmt)) - { - uh_oh = FALSE; - } + "Select OK to upgrade it to the current version, Cancel " + "to mark it read-only."); + + response = gnc_ok_cancel_dialog(parent, GTK_RESPONSE_CANCEL, "%s", fmt); + uh_oh = (response == GTK_RESPONSE_CANCEL); + break; + + case ERR_SQL_DB_TOO_NEW: + fmt = _("This database is from a newer version of GnuCash. " + "This version can read it, but cannot safely save to it. " + "It will be marked read-only until you do File>Save As."); + gnc_warning_dialog (parent, "%s", fmt); + uh_oh = TRUE; break; case ERR_SQL_DB_BUSY: @@ -740,8 +747,7 @@ gnc_post_file_open (const char * filename) } } /* if the database doesn't exist, ask the user ... */ - else if ((ERR_BACKEND_NO_SUCH_DB == io_err) || - (ERR_SQL_DB_TOO_OLD == io_err)) + else if ((ERR_BACKEND_NO_SUCH_DB == io_err)) { if (FALSE == show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN)) { @@ -757,12 +763,12 @@ gnc_post_file_open (const char * filename) * don't bother with the message, just die. */ io_err = qof_session_get_error (new_session); if ((ERR_BACKEND_LOCKED == io_err) || - (ERR_BACKEND_READONLY == io_err) || - (ERR_BACKEND_NO_SUCH_DB == io_err) || - (ERR_SQL_DB_TOO_OLD == io_err)) + (ERR_BACKEND_READONLY == io_err) || + (ERR_BACKEND_NO_SUCH_DB == io_err)) { uh_oh = TRUE; } + else { uh_oh = show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN); @@ -786,11 +792,10 @@ gnc_post_file_open (const char * filename) xaccLogEnable(); /* check for i/o error, put up appropriate error dialog */ - io_err = qof_session_get_error (new_session); + io_err = qof_session_pop_error (new_session); if (io_err == ERR_FILEIO_NO_ENCODING) { - qof_session_pop_error (new_session); if (gnc_xml_convert_single_file (newfile)) { /* try to load once again */ @@ -807,7 +812,24 @@ gnc_post_file_open (const char * filename) } uh_oh = show_session_error (io_err, newfile, GNC_FILE_DIALOG_OPEN); - + /* Attempt to update the database if it's too old */ + if ( !uh_oh && io_err == ERR_SQL_DB_TOO_OLD ) + { + gnc_window_show_progress(_("Re-saving user data..."), 0.0); + qof_session_safe_save(new_session, gnc_window_show_progress); + io_err = qof_session_get_error(new_session); + uh_oh = show_session_error(io_err, newfile, GNC_FILE_DIALOG_SAVE); + } + /* Database is either too old and couldn't (or user didn't + * want it to) be updated or it's too new. Mark it as + * read-only + */ + if (uh_oh && io_err == ERR_SQL_DB_TOO_OLD || + io_err == ERR_SQL_DB_TOO_NEW) + { + qof_book_mark_readonly(qof_session_get_book(new_session)); + uh_oh = FALSE; + } new_root = gnc_book_get_root_account (qof_session_get_book (new_session)); if (uh_oh) new_root = NULL; diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c index 50a4fc0f0d..f8f3bd6b6a 100644 --- a/src/gnome-utils/gnc-main-window.c +++ b/src/gnome-utils/gnc-main-window.c @@ -2351,12 +2351,15 @@ gnc_main_window_engine_commit_error_callback( gpointer data, { GncMainWindow* window = GNC_MAIN_WINDOW(data); GtkWidget* dialog; - + gchar *reason = "."; + if ( errcode == ERR_BACKEND_READONLY ) + reason = _(": Book is marked read-only."); dialog = gtk_message_dialog_new( GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, - "Unable to save to database" ); + _("Unable to save to database%s"), + reason ); gtk_dialog_run(GTK_DIALOG (dialog)); gtk_widget_destroy(dialog);