1 /* Dia -- an diagram creation/manipulation program
2 * Copyright (C) 1998 Alexander Larsson
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 /* Automatically save a copy with the .autosave extension after idle time.
22 * Don't autosave unmodified diagrams, and remove the autosave file when
23 * the diagram is saved successfully. Also remove autosave file when the
24 * diagram is closed, even if it was modified.
25 * If (auto)saving crashes you, this will really fuck you over!
34 #include <sys/types.h>
43 #include "load_save.h"
47 gboolean
autosave_check_autosave(gpointer data
);
50 autosave_save_diagram(gpointer data
)
52 Diagram
*dia
= (Diagram
*)data
;
54 gtk_idle_remove_by_data(data
);
56 diagram_autosave(dia
);
59 /** Makes autosave copies of the diagrams in the appropriate directory
60 * This function will be called after a diagram is modified, and will
61 * only save documents that are modified and not already autosaved,
62 * and only at the next idle period.
65 autosave_check_autosave(gpointer data
)
67 GList
*diagrams
= dia_open_diagrams();
70 while (diagrams
!= NULL
) {
71 diagram
= (Diagram
*)diagrams
->data
;
72 if (diagram_is_modified(diagram
) &&
73 !diagram
->autosaved
) {
74 /* Diagram has been modified. At next idleness, save it */
75 gtk_idle_add((GtkFunction
)autosave_save_diagram
, diagram
);
77 diagrams
= g_list_next(diagrams
);
82 /* This is old stuff for a restore dialog */
84 /* Doesn't work with autosave files stored in the files dir */
86 /** Create a dialog that asks for files to be restore */
88 autosave_make_restore_dialog(GList
*files
)
90 GtkWidget
*ok
, *cancel
;
91 GtkWidget
*dialog
= dialog_make(_("Recovering autosaved diagrams"),
92 NULL
, NULL
, &ok
, &cancel
);
93 GtkWidget
*vbox
= GTK_DIALOG(dialog
)->vbox
;
94 GtkWidget
*selectarea
= gtk_clist_new(1);
96 gchar
**filearray
= (gchar
**)g_new(gchar
*, g_list_length(files
)+1);
99 gtk_box_pack_start_defaults(GTK_BOX(vbox
), gtk_label_new(_("Autosaved files exist.\nPlease select those you wish to recover.")));
101 for (i
= 0, iter
= files
; iter
!= NULL
; i
++, iter
= g_list_next(iter
)) {
102 filearray
[i
] = (gchar
*)iter
->data
;
105 gtk_clist_append(GTK_CLIST(selectarea
), filearray
);
107 gtk_box_pack_start_defaults(GTK_BOX(vbox
), selectarea
);
108 gtk_widget_show_all(dialog
);
111 /** If autosave files exist, ask the user if they should be restored
114 autosave_restore_documents(void)
116 gchar
*savedir
= dia_config_filename("autosave" G_DIR_SEPARATOR_S
);
117 GDir
*dir
= g_dir_open(savedir
, 0, NULL
);
121 if (dir
== NULL
) return;
122 while ((ent
= g_dir_read_name(dir
)) != NULL
) {
123 printf("Found autosave file %s\n", ent
);
124 files
= g_list_prepend(files
, g_strdup(ent
));
128 autosave_make_restore_dialog(files
);