r23312 - gnucash/trunk/src - Add default-to-save timeout on save-on-changes dialog
Geert Janssens
gjanssens at code.gnucash.org
Tue Oct 22 11:44:27 EDT 2013
Author: gjanssens
Date: 2013-10-22 11:44:26 -0400 (Tue, 22 Oct 2013)
New Revision: 23312
Trac: http://svn.gnucash.org/trac/changeset/23312
Modified:
gnucash/trunk/src/gnome-utils/dialog-preferences.c
gnucash/trunk/src/gnome-utils/gnc-main-window.c
gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in
Log:
Add default-to-save timeout on save-on-changes dialog
If the timeout is reached, the dialog is closed as if the user clicked on save.
The timeout period can be set via the preferences dialog
Modified: gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in
===================================================================
--- gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in 2013-10-22 15:44:10 UTC (rev 23311)
+++ gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in 2013-10-22 15:44:26 UTC (rev 23312)
@@ -30,6 +30,16 @@
<summary>Auto-save time interval</summary>
<description>The number of minutes until saving of the data file to harddisk will be started automatically. If zero, no saving will be started automatically.</description>
</key>
+ <key name="save-on-close-expires" type="b">
+ <default>false</default>
+ <summary>Enable timeout on "Save changes on closing" question</summary>
+ <description>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.</description>
+ </key>
+ <key name="save-on-close-wait-time" type="i">
+ <default>20</default>
+ <summary>Time to wait for answer</summary>
+ <description>The number of seconds to wait before the question window will be closed and the changes saved automatically.</description>
+ </key>
<key name="negative-in-red" type="b">
<default>true</default>
<summary>Display negative amounts in red</summary>
Modified: gnucash/trunk/src/gnome-utils/dialog-preferences.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-preferences.c 2013-10-22 15:44:10 UTC (rev 23311)
+++ gnucash/trunk/src/gnome-utils/dialog-preferences.c 2013-10-22 15:44:26 UTC (rev 23312)
@@ -1073,6 +1073,7 @@
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");
Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c 2013-10-22 15:44:10 UTC (rev 23311)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c 2013-10-22 15:44:26 UTC (rev 23312)
@@ -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 @@
#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,7 +116,12 @@
/** 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);
static void gnc_main_window_init (GncMainWindow *window, GncMainWindowClass *klass);
@@ -1121,7 +1127,46 @@
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 @@
{
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 @@
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);
Modified: gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade 2013-10-22 15:44:10 UTC (rev 23311)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade 2013-10-22 15:44:26 UTC (rev 23312)
@@ -2,55 +2,6 @@
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
- <object class="GtkAdjustment" id="auto_decimal_places_adj">
- <property name="lower">1</property>
- <property name="upper">8</property>
- <property name="value">2</property>
- <property name="step_increment">1</property>
- <property name="page_increment">4</property>
- </object>
- <object class="GtkAdjustment" id="autosave_interval_minutes_adj">
- <property name="upper">99999</property>
- <property name="value">3</property>
- <property name="step_increment">1</property>
- <property name="page_increment">10</property>
- </object>
- <object class="GtkAdjustment" id="date_backmonth_adj">
- <property name="upper">11</property>
- <property name="value">6</property>
- <property name="step_increment">1</property>
- <property name="page_increment">4</property>
- </object>
- <object class="GtkListStore" id="date_formats">
- <columns>
- <!-- column-name name -->
- <column type="gchararray"/>
- <!-- column-name example -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0" translatable="yes">US</col>
- <col id="1" translatable="yes">07/31/2013</col>
- </row>
- <row>
- <col id="0" translatable="yes">UK</col>
- <col id="1" translatable="yes">31/07/2013</col>
- </row>
- <row>
- <col id="0" translatable="yes">Europe</col>
- <col id="1" translatable="yes">31.07.2013</col>
- </row>
- <row>
- <col id="0" translatable="yes">ISO</col>
- <col id="1" translatable="yes">2013-07-31</col>
- </row>
- <row>
- <col id="0" translatable="yes">Locale</col>
- <col id="1" translatable="yes">(dummy)</col>
- </row>
- </data>
- </object>
<object class="GtkDialog" id="GnuCash Preferences">
<property name="can_focus">False</property>
<property name="title" translatable="yes">GnuCash Preferences</property>
@@ -369,7 +320,7 @@
</packing>
</child>
<child>
- <object class="GtkHBox" id="pref/window.pages.account-tree.summary/end-period">
+ <object class="GtkHBox" id="pref/window.pages.account-tree.summary/end-period">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
@@ -1181,6 +1132,9 @@
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<object class="GtkRadioButton" id="pref/general/date-completion-thisyear">
<property name="label" translatable="yes">In the current calendar year</property>
<property name="visible">True</property>
@@ -1301,7 +1255,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
- <property name="n_rows">22</property>
+ <property name="n_rows">25</property>
<property name="n_columns">4</property>
<child>
<placeholder/>
@@ -1358,42 +1312,6 @@
<placeholder/>
</child>
<child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
<object class="GtkLabel" id="label50">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -1513,8 +1431,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">3</property>
- <property name="top_attach">17</property>
- <property name="bottom_attach">18</property>
+ <property name="top_attach">20</property>
+ <property name="bottom_attach">21</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options">GTK_FILL</property>
</packing>
@@ -1530,8 +1448,8 @@
</object>
<packing>
<property name="right_attach">4</property>
- <property name="top_attach">15</property>
- <property name="bottom_attach">16</property>
+ <property name="top_attach">18</property>
+ <property name="bottom_attach">19</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
<property name="x_padding">12</property>
@@ -1707,8 +1625,8 @@
<property name="use_markup">True</property>
</object>
<packing>
- <property name="top_attach">20</property>
- <property name="bottom_attach">21</property>
+ <property name="top_attach">23</property>
+ <property name="bottom_attach">24</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@@ -1723,8 +1641,8 @@
<property name="mnemonic_widget">pref/dialogs.search/new-search-limit</property>
</object>
<packing>
- <property name="top_attach">21</property>
- <property name="bottom_attach">22</property>
+ <property name="top_attach">24</property>
+ <property name="bottom_attach">25</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
<property name="x_padding">12</property>
@@ -1749,8 +1667,8 @@
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
- <property name="top_attach">21</property>
- <property name="bottom_attach">22</property>
+ <property name="top_attach">24</property>
+ <property name="bottom_attach">25</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@@ -1880,8 +1798,8 @@
<property name="xalign">0</property>
</object>
<packing>
- <property name="top_attach">19</property>
- <property name="bottom_attach">20</property>
+ <property name="top_attach">17</property>
+ <property name="bottom_attach">18</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@@ -1899,8 +1817,8 @@
<property name="group">pref/general/retain-type-days</property>
</object>
<packing>
- <property name="top_attach">16</property>
- <property name="bottom_attach">17</property>
+ <property name="top_attach">19</property>
+ <property name="bottom_attach">20</property>
<property name="x_padding">12</property>
</packing>
</child>
@@ -1917,8 +1835,8 @@
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="top_attach">17</property>
- <property name="bottom_attach">18</property>
+ <property name="top_attach">20</property>
+ <property name="bottom_attach">21</property>
<property name="x_padding">12</property>
</packing>
</child>
@@ -1935,11 +1853,159 @@
<property name="group">pref/general/retain-type-days</property>
</object>
<packing>
- <property name="top_attach">18</property>
- <property name="bottom_attach">19</property>
+ <property name="top_attach">21</property>
+ <property name="bottom_attach">22</property>
<property name="x_padding">12</property>
</packing>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="pref/general/save-on-close-expires">
+ <property name="label" translatable="yes">Enable timeout on "Save changes on closing" question</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">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.</property>
+ <property name="use_underline">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="right_attach">4</property>
+ <property name="top_attach">15</property>
+ <property name="bottom_attach">16</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ <property name="x_padding">12</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label15">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Time to wait for answer:</property>
+ <property name="use_underline">True</property>
+ <property name="mnemonic_widget">pref/general/autosave-interval-minutes</property>
+ </object>
+ <packing>
+ <property name="top_attach">16</property>
+ <property name="bottom_attach">17</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ <property name="x_padding">12</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkSpinButton" id="pref/general/save-on-close-wait-time">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="tooltip_text" translatable="yes">The number of seconds to wait before the question window will be closed and the changes saved automatically.</property>
+ <property name="invisible_char">●</property>
+ <property name="invisible_char_set">True</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ <property name="adjustment">save_on_close_adj</property>
+ <property name="climb_rate">1</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label16">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">seconds</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">16</property>
+ <property name="bottom_attach">17</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label19">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="top_attach">22</property>
+ <property name="bottom_attach">23</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options"/>
+ </packing>
+ </child>
</object>
<packing>
<property name="position">3</property>
@@ -2094,27 +2160,6 @@
<child>
<placeholder/>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="position">4</property>
@@ -3124,6 +3169,30 @@
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
<object class="GtkLabel" id="label72">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -3493,30 +3562,6 @@
<property name="y_options">GTK_FILL</property>
</packing>
</child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
- <child>
- <placeholder/>
- </child>
</object>
<packing>
<property name="position">8</property>
@@ -3548,6 +3593,55 @@
<action-widget response="-7">closebutton2</action-widget>
</action-widgets>
</object>
+ <object class="GtkAdjustment" id="auto_decimal_places_adj">
+ <property name="lower">1</property>
+ <property name="upper">8</property>
+ <property name="value">2</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">4</property>
+ </object>
+ <object class="GtkAdjustment" id="autosave_interval_minutes_adj">
+ <property name="upper">99999</property>
+ <property name="value">3</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkAdjustment" id="date_backmonth_adj">
+ <property name="upper">11</property>
+ <property name="value">6</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">4</property>
+ </object>
+ <object class="GtkListStore" id="date_formats">
+ <columns>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ <!-- column-name example -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0" translatable="yes">US</col>
+ <col id="1" translatable="yes">07/31/2013</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">UK</col>
+ <col id="1" translatable="yes">31/07/2013</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Europe</col>
+ <col id="1" translatable="yes">31.07.2013</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">ISO</col>
+ <col id="1" translatable="yes">2013-07-31</col>
+ </row>
+ <row>
+ <col id="0" translatable="yes">Locale</col>
+ <col id="1" translatable="yes">(dummy)</col>
+ </row>
+ </data>
+ </object>
<object class="GtkAdjustment" id="key_length_adj">
<property name="lower">1</property>
<property name="upper">999</property>
@@ -3574,6 +3668,12 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkAdjustment" id="save_on_close_adj">
+ <property name="upper">300</property>
+ <property name="value">20</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
<object class="GtkAdjustment" id="tab_width_adj">
<property name="lower">1</property>
<property name="upper">100</property>
More information about the gnucash-changes
mailing list