Bug 784420 - "Save changes on closing" window waits 2^32 seconds when...

"Time to wait for answer" is set 0.

Set minimum value of 1 for the save_on_close_adj.
Disable the associated spinner if the timeout is disabled.
Protect secs_to_save from rolling over if it's already 0.
This commit is contained in:
John Ralls 2018-09-20 17:04:25 -07:00
parent 77fb01db82
commit 39575f2272
3 changed files with 25 additions and 2 deletions

View File

@ -90,6 +90,7 @@ static QofLogModule log_module = GNC_MOD_PREFS;
void gnc_preferences_response_cb(GtkDialog *dialog, gint response, GtkDialog *unused);
void gnc_account_separator_pref_changed_cb (GtkEntry *entry, GtkWidget *dialog);
gboolean gnc_account_separator_validate_cb (GtkEntry *entry, GdkEvent *event, GtkWidget *dialog);
void gnc_save_on_close_expires_cb (GtkToggleButton *button, GtkWidget *dialog);
/** This data structure holds the information for a single addition to
* the preferences dialog. */
@ -200,6 +201,18 @@ gnc_account_separator_validate_cb (GtkEntry *entry, GdkEvent *event, GtkWidget *
return FALSE;
}
/** Called when the save-on-close checkbutton is toggled.
* @internal
* @param button the toggle button.
* @param dialog the prefs dialog.
*/
void
gnc_save_on_close_expires_cb (GtkToggleButton *button, GtkWidget *dialog)
{
GtkWidget *spinner = g_object_get_data (G_OBJECT (dialog),
"save_on_close_wait_time");
gtk_widget_set_sensitive(spinner, gtk_toggle_button_get_active(button));
}
/** This function compares two add-ins to see if they specify the same
* tab name.
@ -1200,7 +1213,7 @@ static GtkWidget *
gnc_preferences_dialog_create(GtkWindow *parent)
{
GtkBuilder *builder;
GtkWidget *dialog, *notebook, *label, *image;
GtkWidget *dialog, *notebook, *label, *image, *spinner;
GtkWidget *box, *date, *period, *currency, *fcb, *button;
GHashTable *prefs_table;
GDate* gdate = NULL;
@ -1261,6 +1274,9 @@ gnc_preferences_dialog_create(GtkWindow *parent)
image = GTK_WIDGET(gtk_builder_get_object (builder, "separator_error"));
g_object_set_data(G_OBJECT(dialog), "separator_error", image);
spinner = GTK_WIDGET(gtk_builder_get_object (builder, "pref/general/save-on-close-wait-time"));
g_object_set_data(G_OBJECT(dialog), "save_on_close_wait_time", spinner);
DEBUG("autoconnect");
gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);
@ -1363,6 +1379,9 @@ gnc_preferences_dialog_create(GtkWindow *parent)
label = GTK_WIDGET(gtk_builder_get_object (builder, "locale_currency2"));
gtk_label_set_label(GTK_LABEL(label), currency_name);
button = GTK_WIDGET(gtk_builder_get_object (builder, "pref/general/save-on-close-expires"));
gnc_save_on_close_expires_cb (GTK_TOGGLE_BUTTON(button), dialog);
g_object_unref(G_OBJECT(builder));
LEAVE("dialog %p", dialog);

View File

@ -1188,7 +1188,9 @@ static gboolean auto_save_countdown (GtkWidget *dialog)
if (!GTK_IS_LABEL (label))
return FALSE; /* remove timer */
secs_to_save--;
/* Protect against rolling over to MAXUINT */
if (secs_to_save)
--secs_to_save;
DEBUG ("Counting down: %d seconds", secs_to_save);
timeoutstr = g_strdup_printf (MSG_AUTO_SAVE, secs_to_save);

View File

@ -85,6 +85,7 @@
<property name="page_increment">10</property>
</object>
<object class="GtkAdjustment" id="save_on_close_adj">
<property name="lower">1</property>
<property name="upper">300</property>
<property name="value">20</property>
<property name="step_increment">1</property>
@ -1624,6 +1625,7 @@ many months before the current month:</property>
<property name="margin_left">12</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="gnc_save_on_close_expires_cb" swapped="no"/>
</object>
<packing>
<property name="left_attach">0</property>