+static void
+save_session_crashed_in_idle (EvApplication *application)
+{
+ if (application->crashed_idle > 0)
+ g_source_remove (application->crashed_idle);
+ application->crashed_idle =
+ g_idle_add ((GSourceFunc)save_session_crashed_in_idle_cb,
+ application);
+}
+
+static gboolean
+ev_application_run_crash_recovery_dialog (EvApplication *application)
+{
+ GtkWidget *dialog;
+ gint response;
+
+ dialog = gtk_message_dialog_new (NULL,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_NONE,
+ _("Recover previous documents?"));
+ gtk_message_dialog_format_secondary_text (
+ GTK_MESSAGE_DIALOG (dialog),
+ _("Evince appears to have exited unexpectedly the last time "
+ "it was run. You can recover the opened documents."));
+
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Don't Recover"),
+ GTK_RESPONSE_CANCEL);
+ gtk_dialog_add_button (GTK_DIALOG (dialog),
+ _("_Recover"),
+ GTK_RESPONSE_ACCEPT);
+
+ gtk_window_set_title (GTK_WINDOW (dialog), _("Crash Recovery"));
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), "evince");
+ gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
+ gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), FALSE);
+ gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
+
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+
+ return response == GTK_RESPONSE_ACCEPT;
+}
+
+gboolean
+ev_application_load_session (EvApplication *application)
+{
+ GKeyFile *state_file;
+ gchar **uri_list;
+
+#ifdef WITH_SMCLIENT
+ if (egg_sm_client_is_resumed (application->smclient)) {
+ state_file = egg_sm_client_get_state_file (application->smclient);
+ if (!state_file)
+ return FALSE;
+ } else
+#endif /* WITH_SMCLIENT */
+ if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
+ if (ev_application_run_crash_recovery_dialog (application)) {
+ state_file = g_key_file_new ();
+ g_key_file_load_from_file (state_file,
+ application->crashed_file,
+ G_KEY_FILE_NONE,
+ NULL);
+ } else {
+ return FALSE;
+ }
+ } else {
+ return FALSE;