No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-config-restore-page.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-config-restore-page.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-config-restore-page.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include "e-mail-config-restore-page.h"
20
21 #include <config.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <sys/types.h>
25 #ifdef HAVE_SYS_WAIT_H
26 # include <sys/wait.h>
27 #endif
28 #include <glib/gi18n-lib.h>
29
30 #include <libevolution-utils/e-alert-sink.h>
31 #include <libevolution-utils/e-alert-dialog.h>
32 #include <misc/e-alert-bar.h>
33
34 #define E_MAIL_CONFIG_RESTORE_PAGE_GET_PRIVATE(obj) \
35 (G_TYPE_INSTANCE_GET_PRIVATE \
36 ((obj), E_TYPE_MAIL_CONFIG_RESTORE_PAGE, EMailConfigRestorePagePrivate))
37
38 struct _EMailConfigRestorePagePrivate {
39 GtkWidget *toggle_button; /* not referenced */
40 GtkWidget *file_chooser; /* not referenced */
41 GtkWidget *alert_bar; /* not referenced */
42 gchar *filename;
43 };
44
45 enum {
46 PROP_0,
47 PROP_FILENAME
48 };
49
50 /* Forward Declarations */
51 static void e_mail_config_restore_page_alert_sink_init
52 (EAlertSinkInterface *interface);
53 static void e_mail_config_restore_page_interface_init
54 (EMailConfigPageInterface *interface);
55
56 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
57 EMailConfigRestorePage,
58 e_mail_config_restore_page,
59 GTK_TYPE_BOX,
60 0,
61 G_IMPLEMENT_INTERFACE_DYNAMIC (
62 E_TYPE_ALERT_SINK,
63 e_mail_config_restore_page_alert_sink_init)
64 G_IMPLEMENT_INTERFACE_DYNAMIC (
65 E_TYPE_MAIL_CONFIG_PAGE,
66 e_mail_config_restore_page_interface_init))
67
68 static void
69 mail_config_restore_page_update_filename (EMailConfigRestorePage *page)
70 {
71 GtkToggleButton *toggle_button;
72 GtkFileChooser *file_chooser;
73 gchar *filename = NULL;
74
75 file_chooser = GTK_FILE_CHOOSER (page->priv->file_chooser);
76 toggle_button = GTK_TOGGLE_BUTTON (page->priv->toggle_button);
77
78 e_alert_bar_clear (E_ALERT_BAR (page->priv->alert_bar));
79
80 if (gtk_toggle_button_get_active (toggle_button))
81 filename = gtk_file_chooser_get_filename (file_chooser);
82
83 if (!evolution_backup_restore_validate_backup_file (filename)) {
84 if (filename != NULL) {
85 e_alert_submit (
86 E_ALERT_SINK (page),
87 "org.gnome.backup-restore:invalid-backup",
88 NULL);
89 g_free (filename);
90 filename = NULL;
91 }
92 }
93
94 g_free (page->priv->filename);
95 page->priv->filename = filename;
96
97 g_object_notify (G_OBJECT (page), "filename");
98
99 e_mail_config_page_changed (E_MAIL_CONFIG_PAGE (page));
100 }
101
102 static void
103 mail_config_restore_page_toggled_cb (GtkToggleButton *toggle_button,
104 EMailConfigRestorePage *page)
105 {
106 mail_config_restore_page_update_filename (page);
107 }
108
109 static void
110 mail_config_restore_page_file_set_cb (GtkFileChooser *file_chooser,
111 EMailConfigRestorePage *page)
112 {
113 mail_config_restore_page_update_filename (page);
114 }
115
116 static void
117 mail_config_restore_page_get_property (GObject *object,
118 guint property_id,
119 GValue *value,
120 GParamSpec *pspec)
121 {
122 switch (property_id) {
123 case PROP_FILENAME:
124 g_value_set_string (
125 value,
126 e_mail_config_restore_page_get_filename (
127 E_MAIL_CONFIG_RESTORE_PAGE (object)));
128 return;
129 }
130
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
132 }
133
134 static void
135 mail_config_restore_page_finalize (GObject *object)
136 {
137 EMailConfigRestorePagePrivate *priv;
138
139 priv = E_MAIL_CONFIG_RESTORE_PAGE_GET_PRIVATE (object);
140
141 g_free (priv->filename);
142
143 /* Chain up to parent's finalize() method. */
144 G_OBJECT_CLASS (e_mail_config_restore_page_parent_class)->
145 finalize (object);
146 }
147
148 static void
149 mail_config_restore_page_constructed (GObject *object)
150 {
151 EMailConfigRestorePage *page;
152 GtkWidget *widget;
153 GtkWidget *container;
154 const gchar *text;
155
156 page = E_MAIL_CONFIG_RESTORE_PAGE (object);
157
158 /* Chain up to parent's constructed() method. */
159 G_OBJECT_CLASS (e_mail_config_restore_page_parent_class)->
160 constructed (object);
161
162 gtk_orientable_set_orientation (
163 GTK_ORIENTABLE (page), GTK_ORIENTATION_VERTICAL);
164
165 gtk_box_set_spacing (GTK_BOX (page), 24);
166
167 text = _("You can restore Evolution from a backup file.\n\n"
168 "This will restore all your personal data, settings "
169 "mail filters, etc.");
170 widget = gtk_label_new (text);
171 gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
172 gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
173 gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
174 gtk_widget_show (widget);
175
176 widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
177 gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
178 gtk_widget_show (widget);
179
180 container = widget;
181
182 text = _("_Restore from a backup file:");
183 widget = gtk_check_button_new_with_mnemonic (text);
184 gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
185 page->priv->toggle_button = widget; /* not referenced */
186 gtk_widget_show (widget);
187
188 g_signal_connect (
189 widget, "toggled",
190 G_CALLBACK (mail_config_restore_page_toggled_cb), page);
191
192 widget = gtk_file_chooser_button_new (
193 _("Choose a backup file to restore"),
194 GTK_FILE_CHOOSER_ACTION_OPEN);
195 gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (widget), TRUE);
196 gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
197 page->priv->file_chooser = widget; /* not referenced */
198 gtk_widget_show (widget);
199
200 g_signal_connect (
201 widget, "file-set",
202 G_CALLBACK (mail_config_restore_page_file_set_cb), page);
203
204 widget = gtk_frame_new (NULL);
205 gtk_frame_set_shadow_type (GTK_FRAME (widget), GTK_SHADOW_IN);
206 gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
207 /* Visibility is bound to the EActivityBar. */
208
209 container = widget;
210
211 widget = e_alert_bar_new ();
212 gtk_container_add (GTK_CONTAINER (container), widget);
213 page->priv->alert_bar = widget; /* not referenced */
214 /* EActivityBar controls its own visibility. */
215
216 g_object_bind_property (
217 widget, "visible",
218 container, "visible",
219 G_BINDING_SYNC_CREATE);
220
221 g_object_bind_property (
222 page->priv->toggle_button, "active",
223 page->priv->file_chooser, "sensitive",
224 G_BINDING_SYNC_CREATE);
225 }
226
227 static void
228 mail_config_restore_page_submit_alert (EAlertSink *alert_sink,
229 EAlert *alert)
230 {
231 EMailConfigRestorePagePrivate *priv;
232 EAlertBar *alert_bar;
233 GtkWidget *dialog;
234 gpointer parent;
235
236 priv = E_MAIL_CONFIG_RESTORE_PAGE_GET_PRIVATE (alert_sink);
237
238 parent = gtk_widget_get_toplevel (GTK_WIDGET (alert_sink));
239 parent = gtk_widget_is_toplevel (parent) ? parent : NULL;
240
241 switch (e_alert_get_message_type (alert)) {
242 case GTK_MESSAGE_INFO:
243 case GTK_MESSAGE_WARNING:
244 case GTK_MESSAGE_ERROR:
245 alert_bar = E_ALERT_BAR (priv->alert_bar);
246 e_alert_bar_add_alert (alert_bar, alert);
247 break;
248
249 default:
250 dialog = e_alert_dialog_new (parent, alert);
251 gtk_dialog_run (GTK_DIALOG (dialog));
252 gtk_widget_destroy (dialog);
253 break;
254 }
255 }
256
257 static gboolean
258 mail_config_restore_page_check_complete (EMailConfigPage *page)
259 {
260 EMailConfigRestorePagePrivate *priv;
261 GtkToggleButton *toggle_button;
262 gboolean complete;
263
264 priv = E_MAIL_CONFIG_RESTORE_PAGE_GET_PRIVATE (page);
265
266 toggle_button = GTK_TOGGLE_BUTTON (priv->toggle_button);
267
268 complete =
269 !gtk_toggle_button_get_active (toggle_button) ||
270 (priv->filename != NULL && *priv->filename != '\0');
271
272 return complete;
273 }
274
275 static void
276 e_mail_config_restore_page_class_init (EMailConfigRestorePageClass *class)
277 {
278 GObjectClass *object_class;
279
280 g_type_class_add_private (
281 class, sizeof (EMailConfigRestorePagePrivate));
282
283 object_class = G_OBJECT_CLASS (class);
284 object_class->get_property = mail_config_restore_page_get_property;
285 object_class->finalize = mail_config_restore_page_finalize;
286 object_class->constructed = mail_config_restore_page_constructed;
287
288 g_object_class_install_property (
289 object_class,
290 PROP_FILENAME,
291 g_param_spec_string (
292 "filename",
293 "Filename",
294 "Selected filename to restore from",
295 NULL,
296 G_PARAM_READABLE));
297 }
298
299 static void
300 e_mail_config_restore_page_class_finalize (EMailConfigRestorePageClass *class)
301 {
302 }
303
304 static void
305 e_mail_config_restore_page_alert_sink_init (EAlertSinkInterface *interface)
306 {
307 interface->submit_alert = mail_config_restore_page_submit_alert;
308 }
309
310 static void
311 e_mail_config_restore_page_interface_init (EMailConfigPageInterface *interface)
312 {
313 interface->title = _("Restore from Backup");
314 interface->sort_order = E_MAIL_CONFIG_RESTORE_PAGE_SORT_ORDER;
315 interface->check_complete = mail_config_restore_page_check_complete;
316 }
317
318 static void
319 e_mail_config_restore_page_init (EMailConfigRestorePage *page)
320 {
321 page->priv = E_MAIL_CONFIG_RESTORE_PAGE_GET_PRIVATE (page);
322 }
323
324 void
325 e_mail_config_restore_page_type_register (GTypeModule *type_module)
326 {
327 /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
328 * function, so we have to wrap it with a public function in
329 * order to register types from a separate compilation unit. */
330 e_mail_config_restore_page_register_type (type_module);
331 }
332
333 EMailConfigPage *
334 e_mail_config_restore_page_new (void)
335 {
336 return g_object_new (E_TYPE_MAIL_CONFIG_RESTORE_PAGE, NULL);
337 }
338
339 const gchar *
340 e_mail_config_restore_page_get_filename (EMailConfigRestorePage *page)
341 {
342 g_return_val_if_fail (E_IS_MAIL_CONFIG_RESTORE_PAGE (page), NULL);
343
344 return page->priv->filename;
345 }
346
347 gboolean
348 evolution_backup_restore_validate_backup_file (const gchar *filename)
349 {
350 gchar *command;
351 gint result;
352 gchar *quotedfname;
353 gchar *toolfname;
354 const gchar *basedir;
355
356 if (filename == NULL || *filename == '\0')
357 return FALSE;
358
359 /* FIXME We should be using g_spawn_command_line_sync() here. */
360
361 basedir = EVOLUTION_TOOLSDIR;
362 quotedfname = g_shell_quote (filename);
363 toolfname = g_build_filename (basedir, "evolution-backup", NULL);
364
365 command = g_strdup_printf ("%s --check %s", toolfname, quotedfname);
366 result = system (command);
367
368 g_free (command);
369 g_free (quotedfname);
370 g_free (toolfname);
371
372 #ifdef HAVE_SYS_WAIT_H
373 g_message (
374 "Sanity check result %d:%d %d",
375 WIFEXITED (result), WEXITSTATUS (result), result);
376
377 return WIFEXITED (result) && (WEXITSTATUS (result) == 0);
378 #else
379 return (result == 0);
380 #endif
381 }