+ crashed_file = g_key_file_new ();
+ save_session (application, windows, crashed_file);
+
+ data = g_key_file_to_data (crashed_file, (gsize *)&data_length, NULL);
+ g_file_set_contents (application->crashed_file, data, data_length, &error);
+ if (error) {
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ }
+ g_free (data);
+ g_key_file_free (crashed_file);
+ } else if (g_file_test (application->crashed_file, G_FILE_TEST_IS_REGULAR)) {
+ GFile *file;
+
+ file = g_file_new_for_path (application->crashed_file);
+ g_file_delete (file, NULL, NULL);
+ g_object_unref (file);
+ }
+}
+
+static gboolean
+save_session_crashed_in_idle_cb (EvApplication *application)
+{
+ ev_application_save_session_crashed (application);
+ application->crashed_idle = 0;
+
+ return FALSE;
+}
+
+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,
+ const gchar **files)
+{
+ GtkWidget *dialog;
+ gint response;
+
+ /* Do not show the recover dialog if the requested file is the
+ * only one to be recovered
+ */
+ if (files && g_strv_length ((gchar **)files) == 1) {
+ GKeyFile *state_file;
+ gchar **uri_list;
+
+ state_file = g_key_file_new ();
+ g_key_file_load_from_file (state_file,
+ application->crashed_file,
+ G_KEY_FILE_NONE,
+ NULL);
+ uri_list = g_key_file_get_string_list (state_file,
+ "Evince",
+ "documents",
+ NULL, NULL);
+ if (uri_list && g_strv_length (uri_list) == 1) {
+ GFile *file;
+ gchar *uri;
+
+ file = g_file_new_for_commandline_arg (files[0]);
+ uri = g_file_get_uri (file);
+ g_object_unref (file);
+ if (g_ascii_strcasecmp (uri, uri_list[0]) == 0) {
+ g_strfreev (uri_list);
+ g_key_file_free (state_file);
+ g_free (uri);
+
+ return FALSE;
+ }
+ g_free (uri);
+ g_strfreev (uri_list);
+ }
+ g_key_file_free (state_file);