diff --git a/src/gnome-utils/dialog-preferences.c b/src/gnome-utils/dialog-preferences.c index a94327726b..8436962335 100644 --- a/src/gnome-utils/dialog-preferences.c +++ b/src/gnome-utils/dialog-preferences.c @@ -1073,6 +1073,7 @@ gnc_preferences_dialog_create(void) gnc_builder_add_from_file (builder, "dialog-preferences.glade", "auto_decimal_places_adj"); gnc_builder_add_from_file (builder, "dialog-preferences.glade", "autosave_interval_minutes_adj"); + gnc_builder_add_from_file (builder, "dialog-preferences.glade", "save_on_close_adj"); gnc_builder_add_from_file (builder, "dialog-preferences.glade", "date_backmonth_adj"); gnc_builder_add_from_file (builder, "dialog-preferences.glade", "max_transactions_adj"); gnc_builder_add_from_file (builder, "dialog-preferences.glade", "key_length_adj"); diff --git a/src/gnome-utils/gnc-main-window.c b/src/gnome-utils/gnc-main-window.c index 100da6777e..f9691fc018 100644 --- a/src/gnome-utils/gnc-main-window.c +++ b/src/gnome-utils/gnc-main-window.c @@ -63,7 +63,6 @@ #include "core-utils/gnc-version.h" #include "gnc-window.h" #include "gnc-prefs.h" -#include "gnc-prefs.h" #include "option-util.h" // +JSLED //#include "gnc-html.h" @@ -100,6 +99,8 @@ enum #define GNC_PREF_TAB_POSITION_RIGHT "tab-position-right" #define GNC_PREF_TAB_WIDTH "tab-width" #define GNC_PREF_TAB_COLOR "show-account-color-tabs" +#define GNC_PREF_SAVE_CLOSE_EXPIRES "save-on-close-expires" +#define GNC_PREF_SAVE_CLOSE_WAIT_TIME "save-on-close-wait-time" #define GNC_MAIN_WINDOW_NAME "GncMainWindow" @@ -115,6 +116,11 @@ static GQuark window_type = 0; /** A list of all extant main windows. This is for convenience as the * same information can be obtained from the object tracking code. */ static GList *active_windows = NULL; +/** Count down timer for the save changes dialog. If the timer reaches zero + * any changes will be saved and the save dialog closed automatically */ +static uint secs_to_save = 0; + +#define MSG_AUTO_SAVE _("Changes will be saved automatically in %d seconds") /* Declarations *********************************************************/ static void gnc_main_window_class_init (GncMainWindowClass *klass); @@ -1121,6 +1127,45 @@ gnc_main_window_page_exists (GncPluginPage *page) return FALSE; } +static gboolean auto_save_countdown (GtkWidget *dialog) +{ + GtkWidget *label; + gchar *timeoutstr = NULL; + + if (secs_to_save < 0) + { + PWARN ("Count down aborted - timer reached a negative value.\n" + "This is probably because the timer was improperly initialized."); + return G_SOURCE_REMOVE; + } + + /* Stop count down if user closed the dialog since the last time we were called */ + if (!GTK_IS_DIALOG (dialog)) + return G_SOURCE_REMOVE; + + /* Stop count down if count down text can't be updated */ + label = GTK_WIDGET (g_object_get_data (G_OBJECT (dialog), "count-down-label")); + if (!GTK_IS_LABEL (label)) + return G_SOURCE_REMOVE; + + secs_to_save--; + DEBUG ("Counting down: %d seconds", secs_to_save); + + timeoutstr = g_strdup_printf (MSG_AUTO_SAVE, secs_to_save); + gtk_label_set_text (GTK_LABEL (label), timeoutstr); + g_free (timeoutstr); + + /* Count down reached 0. Save and close dialog */ + if (!secs_to_save) + { + gtk_dialog_response (GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); + return G_SOURCE_REMOVE; + } + + /* Run another cycle */ + return G_SOURCE_CONTINUE; +} + /** This function prompts the user to save the file with a dialog that * follows the HIG guidelines. @@ -1136,7 +1181,7 @@ gnc_main_window_prompt_for_save (GtkWidget *window) { QofSession *session; QofBook *book; - GtkWidget *dialog; + GtkWidget *dialog, *msg_area, *label; gint response; const gchar *filename, *tmp; const gchar *title = _("Save changes to file %s before closing?"); @@ -1194,6 +1239,28 @@ gnc_main_window_prompt_for_save (GtkWidget *window) GTK_STOCK_SAVE, GTK_RESPONSE_APPLY, NULL); gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_APPLY); + + /* If requested by the user, add a timeout to the question to save automatically + * if the user doesn't answer after a chosen number of seconds. + */ + if (gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_CLOSE_EXPIRES)) + { + gchar *timeoutstr = NULL; + + secs_to_save = gnc_prefs_get_int (GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_CLOSE_WAIT_TIME); + timeoutstr = g_strdup_printf (MSG_AUTO_SAVE, secs_to_save); + label = GTK_WIDGET(gtk_label_new (timeoutstr)); + g_free (timeoutstr); + gtk_widget_show (label); + + msg_area = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG(dialog)); + gtk_box_pack_end (GTK_BOX(msg_area), label, TRUE, TRUE, 0); + g_object_set (G_OBJECT (label), "xalign", 0.0, NULL); + + g_object_set_data (G_OBJECT (dialog), "count-down-label", label); + g_timeout_add_seconds (1, (GSourceFunc)auto_save_countdown, dialog); + } + response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy(dialog); diff --git a/src/gnome-utils/gtkbuilder/dialog-preferences.glade b/src/gnome-utils/gtkbuilder/dialog-preferences.glade index 6ecac873a5..49c8a4c79f 100644 --- a/src/gnome-utils/gtkbuilder/dialog-preferences.glade +++ b/src/gnome-utils/gtkbuilder/dialog-preferences.glade @@ -2,55 +2,6 @@ - - 1 - 8 - 2 - 1 - 4 - - - 99999 - 3 - 1 - 10 - - - 11 - 6 - 1 - 4 - - - - - - - - - - - US - 07/31/2013 - - - UK - 31/07/2013 - - - Europe - 31.07.2013 - - - ISO - 2013-07-31 - - - Locale - (dummy) - - - False GnuCash Preferences @@ -369,7 +320,7 @@ - + True False @@ -1180,6 +1131,9 @@ + + + In the current calendar year @@ -1301,7 +1255,7 @@ many months before the current month: True False 6 - 22 + 25 4 @@ -1357,42 +1311,6 @@ many months before the current month: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - True @@ -1513,8 +1431,8 @@ many months before the current month: 1 3 - 17 - 18 + 20 + 21 GTK_FILL GTK_FILL @@ -1530,8 +1448,8 @@ many months before the current month: 4 - 15 - 16 + 18 + 19 GTK_FILL 12 @@ -1707,8 +1625,8 @@ many months before the current month: True - 20 - 21 + 23 + 24 GTK_FILL @@ -1723,8 +1641,8 @@ many months before the current month: pref/dialogs.search/new-search-limit - 21 - 22 + 24 + 25 GTK_FILL 12 @@ -1749,8 +1667,8 @@ many months before the current month: 1 2 - 21 - 22 + 24 + 25 GTK_FILL @@ -1880,8 +1798,8 @@ many months before the current month: 0 - 19 - 20 + 17 + 18 GTK_FILL @@ -1899,8 +1817,8 @@ many months before the current month: pref/general/retain-type-days - 16 - 17 + 19 + 20 12 @@ -1917,8 +1835,8 @@ many months before the current month: True - 17 - 18 + 20 + 21 12 @@ -1935,11 +1853,159 @@ many months before the current month: pref/general/retain-type-days - 18 - 19 + 21 + 22 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Enable timeout on "Save changes on closing" question + True + True + False + If enabeled, the "Save changes on closing" question will only wait a limited number of seconds for an answer. If the user didn't answer within that time, the changes will be saved automatically and the question window closed. + True + True + + + 4 + 15 + 16 + GTK_FILL + + 12 + + + + + True + False + 0 + Time to wait for answer: + True + pref/general/autosave-interval-minutes + + + 16 + 17 + GTK_FILL + + 12 + + + + + True + False + 6 + + + True + True + The number of seconds to wait before the question window will be closed and the changes saved automatically. + + True + False + False + True + True + save_on_close_adj + 1 + + + False + True + 0 + + + + + True + False + 0 + seconds + + + False + False + 1 + + + + + 1 + 2 + 16 + 17 + GTK_FILL + GTK_FILL + + + + + + + + + + + + + + True + False + 0 + + + 22 + 23 + GTK_FILL + + + 3 @@ -2094,27 +2160,6 @@ many months before the current month: - - - - - - - - - - - - - - - - - - - - - 4 @@ -3123,6 +3168,30 @@ many months before the current month: + + + + + + + + + + + + + + + + + + + + + + + + True @@ -3493,30 +3562,6 @@ many months before the current month: GTK_FILL - - - - - - - - - - - - - - - - - - - - - - - - 8 @@ -3548,6 +3593,55 @@ many months before the current month: closebutton2 + + 1 + 8 + 2 + 1 + 4 + + + 99999 + 3 + 1 + 10 + + + 11 + 6 + 1 + 4 + + + + + + + + + + + US + 07/31/2013 + + + UK + 31/07/2013 + + + Europe + 31.07.2013 + + + ISO + 2013-07-31 + + + Locale + (dummy) + + + 1 999 @@ -3574,6 +3668,12 @@ many months before the current month: 1 10 + + 300 + 20 + 1 + 10 + 1 100 diff --git a/src/gnome/gschemas/org.gnucash.gschema.xml.in b/src/gnome/gschemas/org.gnucash.gschema.xml.in index 3bc56406de..63faa9aed4 100644 --- a/src/gnome/gschemas/org.gnucash.gschema.xml.in +++ b/src/gnome/gschemas/org.gnucash.gschema.xml.in @@ -30,6 +30,16 @@ Auto-save time interval The number of minutes until saving of the data file to harddisk will be started automatically. If zero, no saving will be started automatically. + + false + Enable timeout on "Save changes on closing" question + If enabeled, the "Save changes on closing" question will only wait a limited number of seconds for an answer. If the user didn't answer within that time, the changes will be saved automatically and the question window closed. + + + 20 + Time to wait for answer + The number of seconds to wait before the question window will be closed and the changes saved automatically. + true Display negative amounts in red