26 #include "gnc-autosave.h" 28 #include <glib/gi18n.h> 30 #include "gnc-session.h" 36 #include "gnc-gui-query.h" 37 #include "dialog-utils.h" 40 #define GNC_PREF_AUTOSAVE_SHOW_EXPLANATION "autosave-show-explanation" 41 #define GNC_PREF_AUTOSAVE_INTERVAL "autosave-interval-minutes" 42 #define AUTOSAVE_SOURCE_ID "autosave_source_id" 47 #define G_LOG_DOMAIN "gnc.gui.autosave" 51 autosave_remove_timer_cb(QofBook *book, gpointer key, gpointer user_data);
81 static gboolean autosave_confirm(GtkWidget *toplevel)
86 gboolean switch_off_autosave, show_expl_again, save_now;
89 #define YES_THIS_TIME 1 92 #define NO_NOT_THIS_TIME 4 96 gtk_message_dialog_new(GTK_WINDOW(toplevel),
97 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
101 _(
"Save file automatically?"));
104 gtk_widget_set_name (GTK_WIDGET(dialog),
"gnc-id-auto-save");
106 gtk_message_dialog_format_secondary_text
107 (GTK_MESSAGE_DIALOG(dialog),
108 ngettext(
"Your data file needs to be saved to your hard disk to save your changes. " 109 "GnuCash has a feature to save the file automatically every %d minute, " 110 "just as if you had pressed the \"Save\" button each time.\n\n" 111 "You can change the time interval or turn off this feature under " 112 "Edit->Preferences->General->Auto-save time interval.\n\n" 113 "Should your file be saved automatically?",
114 "Your data file needs to be saved to your hard disk to save your changes. " 115 "GnuCash has a feature to save the file automatically every %d minutes, " 116 "just as if you had pressed the \"Save\" button each time.\n\n" 117 "You can change the time interval or turn off this feature under " 118 "Edit->Preferences->General->Auto-save time interval.\n\n" 119 "Should your file be saved automatically?",
122 gtk_dialog_add_buttons(GTK_DIALOG(dialog),
123 _(
"_Yes, this time"), YES_THIS_TIME,
124 _(
"Yes, _always"), YES_ALWAYS,
125 _(
"No, n_ever"), NO_NEVER,
126 _(
"_No, not this time"), NO_NOT_THIS_TIME,
128 gtk_dialog_set_default_response( GTK_DIALOG(dialog), NO_NOT_THIS_TIME);
131 response = gtk_dialog_run( GTK_DIALOG( dialog ) );
132 gtk_widget_destroy( dialog );
138 switch_off_autosave = FALSE;
139 show_expl_again = TRUE;
143 switch_off_autosave = FALSE;
144 show_expl_again = FALSE;
148 switch_off_autosave = TRUE;
149 show_expl_again = FALSE;
153 case NO_NOT_THIS_TIME:
154 switch_off_autosave = FALSE;
155 show_expl_again = TRUE;
160 gnc_prefs_set_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTOSAVE_SHOW_EXPLANATION, show_expl_again);
161 DEBUG(
"autosave_timeout_cb: Show explanation again=%s\n",
162 (show_expl_again ?
"TRUE" :
"FALSE"));
165 if (switch_off_autosave)
168 DEBUG(
"autosave_timeout_cb: User chose to disable auto-save.\n");
175 static gboolean autosave_timeout_cb(gpointer user_data)
177 QofBook *book = user_data;
178 gboolean show_explanation;
179 gboolean save_now = TRUE;
182 DEBUG(
"autosave_timeout_cb called\n");
187 if (gnc_file_save_in_progress() || !gnc_current_session_exist()
197 if (show_explanation)
199 save_now = autosave_confirm(toplevel);
204 DEBUG(
"autosave_timeout_cb: Really trigger auto-save now.\n");
207 if (GNC_IS_MAIN_WINDOW(toplevel))
210 DEBUG(
"autosave_timeout_cb: toplevel is not a GNC_MAIN_WINDOW\n");
211 if (GNC_IS_WINDOW(toplevel))
212 gnc_window_set_progressbar_window( GNC_WINDOW( toplevel ) );
214 DEBUG(
"autosave_timeout_cb: toplevel is not a GNC_WINDOW\n");
216 gnc_file_save (GTK_WINDOW (toplevel));
228 DEBUG(
"autosave_timeout_cb: No auto-save this time, let the timeout run again.\n");
236 autosave_remove_timer_cb(QofBook *book, gpointer key, gpointer user_data)
238 guint autosave_source_id = GPOINTER_TO_UINT(user_data);
241 if (autosave_source_id > 0)
243 res = g_source_remove (autosave_source_id);
244 DEBUG(
"Removing auto save timer with id %d, result=%s\n",
245 autosave_source_id, (res ?
"TRUE" :
"FALSE"));
249 GUINT_TO_POINTER(0), autosave_remove_timer_cb);
253 void gnc_autosave_remove_timer(QofBook *book)
255 autosave_remove_timer_cb(book, AUTOSAVE_SOURCE_ID,
259 static void gnc_autosave_add_timer(QofBook *book)
261 guint interval_mins =
265 if ( interval_mins > 0
266 && ( ! gnc_file_save_in_progress() )
267 && gnc_current_session_exist() )
271 guint autosave_source_id =
272 g_timeout_add_seconds(interval_mins * 60,
273 autosave_timeout_cb, book);
274 DEBUG(
"Adding new auto-save timer with id %d\n", autosave_source_id);
279 GUINT_TO_POINTER(autosave_source_id),
280 autosave_remove_timer_cb);
284 void gnc_autosave_dirty_handler (QofBook *book, gboolean dirty)
286 DEBUG(
"gnc_main_window_autosave_dirty(dirty = %s)\n",
287 (dirty ?
"TRUE" :
"FALSE"));
301 gnc_autosave_remove_timer(book);
304 gnc_autosave_add_timer(book);
308 DEBUG(
"Shutting down book, ignoring dirty book");
315 gnc_autosave_remove_timer(book);
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define DEBUG(format, args...)
Print a debugging message.
Functions that are supported by all types of windows.
Functions for adding content to a window.
gboolean gnc_prefs_set_bool(const gchar *group, const gchar *pref_name, gboolean value)
Store a boolean value into the preferences backend.
void qof_book_set_data_fin(QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
Same as qof_book_set_data(), except that the callback will be called when the book is destroyed...
gboolean gnc_prefs_set_float(const gchar *group, const gchar *pref_name, gdouble value)
Store a float value into the preferences backend.
All type declarations for the whole Gnucash engine.
Generic api to store and retrieve preferences.
gboolean qof_book_is_readonly(const QofBook *book)
Return whether the book is read only.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
gboolean qof_book_shutting_down(const QofBook *book)
Is the book shutting down?
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.
void gnc_main_window_set_progressbar_window(GncMainWindow *window)
Set the window where all progressbar updates should occur.
gdouble gnc_prefs_get_float(const gchar *group, const gchar *pref_name)
Get an float value from the preferences backend.