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
);
49 static void autosave_make_restore_dialog(GList
*files
);
50 static void autosave_restore_documents(void);
53 autosave_save_diagram(gpointer data
)
55 Diagram
*dia
= (Diagram
*)data
;
57 gtk_idle_remove_by_data(data
);
59 diagram_autosave(dia
);
62 /** Makes autosave copies of the diagrams in the appropriate directory
63 * This function will be called after a diagram is modified, and will
64 * only save documents that are modified and not already autosaved,
65 * and only at the next idle period.
68 autosave_check_autosave(gpointer data
)
70 GList
*diagrams
= dia_open_diagrams();
73 while (diagrams
!= NULL
) {
74 diagram
= (Diagram
*)diagrams
->data
;
75 if (diagram_is_modified(diagram
) &&
76 !diagram
->autosaved
) {
77 /* Diagram has been modified. At next idleness, save it */
78 gtk_idle_add((GtkFunction
)autosave_save_diagram
, diagram
);
80 diagrams
= g_list_next(diagrams
);
85 /* This is old stuff for a restore dialog */
86 /* Doesn't work with autosave files stored in the files dir */
88 /** Create a dialog that asks for files to be restore */
90 autosave_make_restore_dialog(GList
*files
)
92 GtkWidget
*ok
, *cancel
;
93 GtkWidget
*dialog
= dialog_make(_("Recovering autosaved diagrams"),
94 NULL
, NULL
, &ok
, &cancel
);
95 GtkWidget
*vbox
= GTK_DIALOG(dialog
)->vbox
;
96 GtkWidget
*selectarea
= gtk_clist_new(1);
98 gchar
**filearray
= (gchar
**)g_new(gchar
*, g_list_length(files
)+1);
101 gtk_box_pack_start_defaults(GTK_BOX(vbox
), gtk_label_new(_("Autosaved files exist.\nPlease select those you wish to recover.")));
103 for (i
= 0, iter
= files
; iter
!= NULL
; i
++, iter
= g_list_next(iter
)) {
104 filearray
[i
] = (gchar
*)iter
->data
;
107 gtk_clist_append(GTK_CLIST(selectarea
), filearray
);
109 gtk_box_pack_start_defaults(GTK_BOX(vbox
), selectarea
);
110 gtk_widget_show_all(dialog
);
113 /** If autosave files exist, ask the user if they should be restored
116 autosave_restore_documents(void)
118 gchar
*savedir
= dia_config_filename("autosave" G_DIR_SEPARATOR_S
);
119 GDir
*dir
= g_dir_open(savedir
, 0, NULL
);
123 if (dir
== NULL
) return;
124 while ((ent
= g_dir_read_name(dir
)) != NULL
) {
125 printf("Found autosave file %s\n", ent
);
126 files
= g_list_prepend(files
, g_strdup(ent
));
130 autosave_make_restore_dialog(files
);