5 * Jukka-Pekka Iivonen (jiivonen@hutcs.cs.hut.fi)
6 * Miguel de Icaza (miguel@kernel.org)
8 * (C) Copyright 2000, 2001 by Jukka-Pekka Iivonen (jiivonen@hutcs.cs.hut.fi)
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <https://www.gnu.org/licenses/>.
23 #include <gnumeric-config.h>
25 #include <dialogs/dialogs.h>
26 #include <dialogs/help.h>
28 #include <workbook-control.h>
32 #include <goffice/goffice.h>
33 #include <glib/gi18n-lib.h>
38 GtkWidget
*minutes_entry
;
40 GtkWidget
*autosave_on_off
;
42 GtkWidget
*cancel_button
;
47 #define AUTOSAVE_KEY "autosave-setup-dialog"
50 autosave_set_sensitivity (G_GNUC_UNUSED GtkWidget
*widget
,
53 gboolean active
= gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state
->autosave_on_off
));
55 gboolean minutes_err
= entry_to_int (GTK_ENTRY (state
->minutes_entry
), &minutes
, FALSE
);
57 gtk_widget_set_sensitive (state
->minutes_entry
, active
);
58 gtk_widget_set_sensitive (state
->prompt_cb
, active
);
60 gtk_widget_set_sensitive (state
->ok_button
,
61 !active
|| (!minutes_err
&& minutes
> 0));
65 dialog_autosave_prompt (WBCGtk
*wbcg
)
67 char const *uri
= go_doc_get_uri (
68 wb_control_get_doc (GNM_WBC (wbcg
)));
69 GtkWidget
*dialog
= gtk_message_dialog_new (wbcg_toplevel (wbcg
),
70 GTK_DIALOG_DESTROY_WITH_PARENT
,
73 _("Do you want to save the workbook %s?"),
75 gint result
= gtk_dialog_run (GTK_DIALOG (dialog
));
77 gtk_widget_destroy (dialog
);
79 return result
== GTK_RESPONSE_YES
;
83 cb_autosave_cancel (G_GNUC_UNUSED GtkWidget
*button
,
86 gtk_widget_destroy (state
->dialog
);
90 cb_autosave_ok (G_GNUC_UNUSED GtkWidget
*button
, autosave_t
*state
)
92 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (state
->autosave_on_off
))) {
93 gboolean prompt
= gtk_toggle_button_get_active
94 (GTK_TOGGLE_BUTTON (state
->prompt_cb
));
96 gboolean minutes_err
= entry_to_int (GTK_ENTRY (state
->minutes_entry
),
99 g_return_if_fail (!minutes_err
); /* Why is ok active? */
101 secs
= 60 * MIN (minutes
, G_MAXINT
/ 60);
102 g_object_set (state
->wbcg
,
103 "autosave-time", secs
,
104 "autosave-prompt", prompt
,
107 g_object_set (state
->wbcg
, "autosave-time", 0, NULL
);
109 gtk_widget_destroy (state
->dialog
);
113 dialog_autosave (WBCGtk
*wbcg
)
120 g_return_if_fail (wbcg
!= NULL
);
122 if (gnm_dialog_raise_if_exists (wbcg
, AUTOSAVE_KEY
))
124 gui
= gnm_gtk_builder_load ("res:ui/autosave.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
129 "autosave-time", &secs
,
130 "autosave-prompt", &prompt
,
133 state
= g_new (autosave_t
, 1);
135 state
->wb
= wb_control_get_workbook (GNM_WBC (wbcg
));
137 state
->dialog
= go_gtk_builder_get_widget (gui
, "AutoSave");
138 state
->minutes_entry
= go_gtk_builder_get_widget (gui
, "minutes");
139 state
->prompt_cb
= go_gtk_builder_get_widget (gui
, "prompt_on_off");
140 state
->autosave_on_off
= go_gtk_builder_get_widget (gui
, "autosave_on_off");
141 state
->ok_button
= go_gtk_builder_get_widget (gui
, "button1");
142 state
->cancel_button
= go_gtk_builder_get_widget (gui
, "button2");
144 if (!state
->dialog
|| !state
->minutes_entry
|| !state
->prompt_cb
||
145 !state
->autosave_on_off
) {
146 go_gtk_notice_dialog (wbcg_toplevel (wbcg
), GTK_MESSAGE_ERROR
,
147 _("Could not create the autosave dialog."));
152 float_to_entry (GTK_ENTRY (state
->minutes_entry
),
155 gnm_editable_enters (GTK_WINDOW (state
->dialog
),
156 state
->minutes_entry
);
158 g_signal_connect (G_OBJECT (state
->autosave_on_off
),
160 G_CALLBACK (autosave_set_sensitivity
), state
);
161 g_signal_connect (G_OBJECT (state
->minutes_entry
),
163 G_CALLBACK (autosave_set_sensitivity
), state
);
164 g_signal_connect (G_OBJECT (state
->ok_button
),
166 G_CALLBACK (cb_autosave_ok
), state
);
167 g_signal_connect (G_OBJECT (state
->cancel_button
),
169 G_CALLBACK (cb_autosave_cancel
), state
);
171 g_object_set_data_full (G_OBJECT (state
->dialog
),
172 "state", state
, (GDestroyNotify
)g_free
);
173 gnm_init_help_button (
174 go_gtk_builder_get_widget (gui
, "button3"),
175 GNUMERIC_HELP_LINK_AUTOSAVE
);
177 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->autosave_on_off
),
179 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->prompt_cb
),
182 autosave_set_sensitivity (NULL
, state
);
183 gnm_keyed_dialog (state
->wbcg
, GTK_WINDOW (state
->dialog
),
185 gtk_widget_show (state
->dialog
);
187 g_object_unref (gui
);