-static void
-save_session (EvApplication *application,
- GList *windows_list,
- GKeyFile *state_file)
-{
- GList *l;
- gint i;
- const gchar **uri_list;
- const gchar *empty = "empty-window";
-
- uri_list = g_new (const gchar *, g_list_length (windows_list));
- for (l = windows_list, i = 0; l != NULL; l = g_list_next (l), i++) {
- EvWindow *window = EV_WINDOW (l->data);
-
- if (ev_window_is_empty (window))
- uri_list[i] = empty;
- else
- uri_list[i] = ev_window_get_uri (window);
- }
- g_key_file_set_string_list (state_file,
- "Evince",
- "documents",
- (const char **)uri_list,
- i);
- g_free (uri_list);
-}
-
-#endif /* WITH_SMCLIENT || ENABLE_DBUS */
-
-#ifdef ENABLE_DBUS
-static void
-ev_application_save_session_crashed (EvApplication *application)
-{
- GList *windows;
-
- windows = ev_application_get_windows (application);
- if (windows) {
- GKeyFile *crashed_file;
- gchar *data;
- gssize data_length;
- GError *error = NULL;
-
- 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)
-{
- 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;
-}
-
-static gboolean
-is_in_command_line (GFile *file,
- const gchar **files)
-{
- gint i;
-
- if (!files)
- return FALSE;
-
- for (i = 0; files[i]; i++) {
- GFile *cfile;
-
- cfile = g_file_new_for_commandline_arg (files[i]);
- if (g_file_equal (cfile, file)) {
- g_object_unref (cfile);
- return TRUE;
- }
- g_object_unref (cfile);
- }
-
- return FALSE;
-}
-
-static GKeyFile *
-ev_application_get_files_to_recover (EvApplication *application,
- const gchar **files)
-{
- GKeyFile *state_file;
- gchar **uri_list;
- gchar **dest_list = NULL;
- gint i, j;
-
- 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_key_file_free (state_file);
- return NULL;
- }
-
- for (i = 0, j = 0; uri_list[i]; i++) {
- GFile *file = g_file_new_for_uri (uri_list[i]);
-
- if (!g_file_query_exists (file, NULL) ||
- is_in_command_line (file, files)) {
- g_object_unref (file);
- continue;
- }
-
- if (!dest_list)
- dest_list = g_new (gchar *, g_strv_length (uri_list) - i);
- dest_list[j++] = uri_list[i];
- }
-
- if (j > 0) {
- g_key_file_set_string_list (state_file,
- "Evince",
- "documents",
- (const gchar **)dest_list,
- j);
- } else {
- g_key_file_free (state_file);
- state_file = NULL;
- }
-
- g_free (dest_list);
- g_strfreev (uri_list);
-
- return state_file;
-}
-#endif /* ENABLE_DBUS */
-