1 | /* |
---|
2 | * e-shell-startup-wizard.c |
---|
3 | * |
---|
4 | * Copyright (C) 2001 Ximian, Inc. |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of version 2 of the GNU General Public |
---|
8 | * License as published by the Free Software Foundation. |
---|
9 | * |
---|
10 | * This program is distributed in the hope that it will be useful, |
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | * General Public License for more details. |
---|
14 | * |
---|
15 | * You should have received a copy of the GNU General Public |
---|
16 | * License along with this program; if not, write to the |
---|
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
18 | * Boston, MA 02111-1307, USA. |
---|
19 | * |
---|
20 | * Authors: Iain Holmes <iain@ximian.com> |
---|
21 | */ |
---|
22 | |
---|
23 | #ifdef HAVE_CONFIG_H |
---|
24 | #include <config.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #include "e-shell-startup-wizard.h" |
---|
28 | |
---|
29 | #include <errno.h> |
---|
30 | |
---|
31 | #include <glib.h> |
---|
32 | #include <gtk/gtk.h> |
---|
33 | #include <gnome.h> |
---|
34 | #include <glade/glade.h> |
---|
35 | #include <liboaf/liboaf.h> |
---|
36 | |
---|
37 | #include <bonobo/bonobo-object.h> |
---|
38 | #include <bonobo/bonobo-widget.h> |
---|
39 | #include <bonobo/bonobo-exception.h> |
---|
40 | #include <bonobo/bonobo-moniker-util.h> |
---|
41 | #include <bonobo-conf/bonobo-config-database.h> |
---|
42 | |
---|
43 | #include <gal/widgets/e-gui-utils.h> |
---|
44 | |
---|
45 | #include <widgets/e-timezone-dialog/e-timezone-dialog.h> |
---|
46 | |
---|
47 | #include "importer/GNOME_Evolution_Importer.h" |
---|
48 | |
---|
49 | #include "e-timezone-dialog/e-timezone-dialog.h" |
---|
50 | #include "e-util/e-gtk-utils.h" |
---|
51 | |
---|
52 | #include <evolution-wizard.h> |
---|
53 | #include "Evolution.h" |
---|
54 | |
---|
55 | typedef struct _TimezoneDialogPage { |
---|
56 | GtkWidget *page; |
---|
57 | GtkWidget *vbox; |
---|
58 | GtkObject *etd; |
---|
59 | } TimezoneDialogPage; |
---|
60 | |
---|
61 | typedef struct _ImportDialogPage { |
---|
62 | GtkWidget *page; |
---|
63 | GtkWidget *vbox; |
---|
64 | |
---|
65 | GList *importers; |
---|
66 | |
---|
67 | int running; |
---|
68 | gboolean prepared; |
---|
69 | } ImportDialogPage; |
---|
70 | |
---|
71 | typedef struct _MailDialogPage { |
---|
72 | GtkWidget *page; |
---|
73 | GtkWidget *vbox; |
---|
74 | GtkWidget *widget; |
---|
75 | |
---|
76 | Bonobo_Control control; |
---|
77 | } MailDialogPage; |
---|
78 | |
---|
79 | typedef struct _SWData { |
---|
80 | GladeXML *wizard; |
---|
81 | GtkWidget *dialog; |
---|
82 | GtkWidget *druid; |
---|
83 | |
---|
84 | GtkWidget *start, *finish; |
---|
85 | |
---|
86 | MailDialogPage *id_page; |
---|
87 | MailDialogPage *source_page; |
---|
88 | MailDialogPage *extra_page; |
---|
89 | MailDialogPage *transport_page; |
---|
90 | MailDialogPage *management_page; |
---|
91 | |
---|
92 | TimezoneDialogPage *timezone_page; |
---|
93 | ImportDialogPage *import_page; |
---|
94 | |
---|
95 | gboolean cancel; |
---|
96 | CORBA_Object mailer; |
---|
97 | Bonobo_EventSource event_source; |
---|
98 | BonoboListener *listener; |
---|
99 | int id; |
---|
100 | |
---|
101 | Bonobo_ConfigDatabase db; |
---|
102 | } SWData; |
---|
103 | |
---|
104 | typedef struct _IntelligentImporterData { |
---|
105 | CORBA_Object object; |
---|
106 | Bonobo_Control control; |
---|
107 | GtkWidget *widget; |
---|
108 | |
---|
109 | char *name; |
---|
110 | char *blurb; |
---|
111 | char *iid; |
---|
112 | } IntelligentImporterData; |
---|
113 | |
---|
114 | typedef struct _SelectedImporterData{ |
---|
115 | CORBA_Object importer; |
---|
116 | char *iid; |
---|
117 | } SelectedImporterData; |
---|
118 | |
---|
119 | static GHashTable *page_hash; |
---|
120 | static GList *page_list = NULL; |
---|
121 | |
---|
122 | static void |
---|
123 | druid_event_notify_cb (BonoboListener *listener, |
---|
124 | const char *name, |
---|
125 | BonoboArg *arg, |
---|
126 | CORBA_Environment *ev, |
---|
127 | SWData *data) |
---|
128 | { |
---|
129 | int buttons, pagenum; |
---|
130 | GnomeDruidPage *page; |
---|
131 | |
---|
132 | if (strcmp (name, EVOLUTION_WIZARD_SET_BUTTONS_SENSITIVE) == 0) { |
---|
133 | buttons = (int) *((CORBA_short *)arg->_value); |
---|
134 | gnome_druid_set_buttons_sensitive (GNOME_DRUID (data->druid), |
---|
135 | (buttons & 4) >> 2, |
---|
136 | (buttons & 2) >> 1, |
---|
137 | (buttons & 1)); |
---|
138 | } else if (strcmp (name, EVOLUTION_WIZARD_SET_SHOW_FINISH) == 0) { |
---|
139 | gnome_druid_set_show_finish (GNOME_DRUID (data->druid), |
---|
140 | (gboolean) *((CORBA_boolean *) arg->_value)); |
---|
141 | } else if (strcmp (name, EVOLUTION_WIZARD_SET_PAGE) == 0) { |
---|
142 | pagenum = (int) *((CORBA_short *) arg->_value); |
---|
143 | |
---|
144 | page = g_list_nth_data (page_list, pagenum); |
---|
145 | gnome_druid_set_page (GNOME_DRUID (data->druid), page); |
---|
146 | } |
---|
147 | } |
---|
148 | |
---|
149 | static void |
---|
150 | make_mail_dialog_pages (SWData *data) |
---|
151 | { |
---|
152 | CORBA_Environment ev; |
---|
153 | CORBA_Object object; |
---|
154 | |
---|
155 | CORBA_exception_init (&ev); |
---|
156 | data->mailer = oaf_activate_from_id ("OAFIID:GNOME_Evolution_Mail_Wizard", 0, NULL, &ev); |
---|
157 | if (BONOBO_EX (&ev)) { |
---|
158 | e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, |
---|
159 | _("Could not start the Evolution Mailer Assistant interface\n(%s)"), CORBA_exception_id (&ev)); |
---|
160 | g_warning ("Could not start mailer (%s)", CORBA_exception_id (&ev)); |
---|
161 | CORBA_exception_free (&ev); |
---|
162 | data->mailer = CORBA_OBJECT_NIL; |
---|
163 | return; |
---|
164 | } |
---|
165 | |
---|
166 | CORBA_exception_free (&ev); |
---|
167 | if (data->mailer == CORBA_OBJECT_NIL) { |
---|
168 | e_notice (NULL, GNOME_MESSAGE_BOX_ERROR, |
---|
169 | _("Could not start the Evolution Mailer Assistant interface\n")); |
---|
170 | return; |
---|
171 | } |
---|
172 | |
---|
173 | CORBA_exception_init (&ev); |
---|
174 | data->event_source = Bonobo_Unknown_queryInterface (data->mailer, "IDL:Bonobo/EventSource:1.0", &ev); |
---|
175 | CORBA_exception_free (&ev); |
---|
176 | data->listener = bonobo_listener_new (NULL, NULL); |
---|
177 | gtk_signal_connect (GTK_OBJECT (data->listener), "event-notify", |
---|
178 | GTK_SIGNAL_FUNC (druid_event_notify_cb), data); |
---|
179 | object = bonobo_object_corba_objref (BONOBO_OBJECT (data->listener)); |
---|
180 | CORBA_exception_init (&ev); |
---|
181 | data->id = Bonobo_EventSource_addListener (data->event_source, object, &ev); |
---|
182 | CORBA_exception_free (&ev); |
---|
183 | } |
---|
184 | |
---|
185 | static int |
---|
186 | page_to_num (GnomeDruidPage *page) |
---|
187 | { |
---|
188 | return GPOINTER_TO_INT (g_hash_table_lookup (page_hash, page)); |
---|
189 | } |
---|
190 | |
---|
191 | static gboolean |
---|
192 | next_func (GnomeDruidPage *page, |
---|
193 | GnomeDruid *druid, |
---|
194 | SWData *data) |
---|
195 | { |
---|
196 | CORBA_Environment ev; |
---|
197 | int pagenum; |
---|
198 | |
---|
199 | CORBA_exception_init (&ev); |
---|
200 | pagenum = page_to_num (page); |
---|
201 | GNOME_Evolution_Wizard_notifyAction (data->mailer, pagenum, GNOME_Evolution_Wizard_NEXT, &ev); |
---|
202 | CORBA_exception_free (&ev); |
---|
203 | |
---|
204 | /* If on last page we own, let druid goto next page */ |
---|
205 | if (pagenum == g_list_length(page_list)-1) |
---|
206 | return FALSE; |
---|
207 | |
---|
208 | return TRUE; |
---|
209 | } |
---|
210 | |
---|
211 | static gboolean |
---|
212 | prepare_func (GnomeDruidPage *page, |
---|
213 | GnomeDruid *druid, |
---|
214 | SWData *data) |
---|
215 | { |
---|
216 | CORBA_Environment ev; |
---|
217 | int pagenum; |
---|
218 | |
---|
219 | CORBA_exception_init (&ev); |
---|
220 | pagenum = page_to_num (page); |
---|
221 | GNOME_Evolution_Wizard_notifyAction (data->mailer, pagenum, GNOME_Evolution_Wizard_PREPARE, &ev); |
---|
222 | CORBA_exception_free (&ev); |
---|
223 | return FALSE; |
---|
224 | } |
---|
225 | |
---|
226 | static gboolean |
---|
227 | back_func (GnomeDruidPage *page, |
---|
228 | GnomeDruid *druid, |
---|
229 | SWData *data) |
---|
230 | { |
---|
231 | CORBA_Environment ev; |
---|
232 | int pagenum; |
---|
233 | |
---|
234 | CORBA_exception_init (&ev); |
---|
235 | pagenum = page_to_num (page); |
---|
236 | GNOME_Evolution_Wizard_notifyAction (data->mailer, pagenum, GNOME_Evolution_Wizard_BACK, &ev); |
---|
237 | CORBA_exception_free (&ev); |
---|
238 | |
---|
239 | /* if we're on page 0, let the druid go back to the start page, if we have one */ |
---|
240 | if (pagenum == 0) |
---|
241 | return FALSE; |
---|
242 | |
---|
243 | return TRUE; |
---|
244 | } |
---|
245 | |
---|
246 | static void |
---|
247 | free_importers (SWData *data) |
---|
248 | { |
---|
249 | GList *l; |
---|
250 | |
---|
251 | for (l = data->import_page->importers; l; l = l->next) { |
---|
252 | IntelligentImporterData *iid; |
---|
253 | |
---|
254 | iid = l->data; |
---|
255 | if (iid->object != CORBA_OBJECT_NIL) { |
---|
256 | bonobo_object_release_unref (iid->object, NULL); |
---|
257 | } |
---|
258 | } |
---|
259 | |
---|
260 | g_list_free (data->import_page->importers); |
---|
261 | } |
---|
262 | |
---|
263 | static void |
---|
264 | start_importers (GList *p) |
---|
265 | { |
---|
266 | CORBA_Environment ev; |
---|
267 | |
---|
268 | for (; p; p = p->next) { |
---|
269 | SelectedImporterData *sid = p->data; |
---|
270 | |
---|
271 | CORBA_exception_init (&ev); |
---|
272 | GNOME_Evolution_IntelligentImporter_importData (sid->importer, &ev); |
---|
273 | if (BONOBO_EX (&ev)) { |
---|
274 | g_warning ("Error importing %s\n%s", sid->iid, |
---|
275 | CORBA_exception_id (&ev)); |
---|
276 | } |
---|
277 | CORBA_exception_free (&ev); |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | static void |
---|
282 | do_import (SWData *data) |
---|
283 | { |
---|
284 | CORBA_Environment ev; |
---|
285 | GList *l, *selected = NULL; |
---|
286 | |
---|
287 | for (l = data->import_page->importers; l; l = l->next) { |
---|
288 | IntelligentImporterData *importer_data; |
---|
289 | SelectedImporterData *sid; |
---|
290 | char *iid; |
---|
291 | |
---|
292 | importer_data = l->data; |
---|
293 | iid = g_strdup (importer_data->iid); |
---|
294 | |
---|
295 | sid = g_new (SelectedImporterData, 1); |
---|
296 | sid->iid = iid; |
---|
297 | |
---|
298 | CORBA_exception_init (&ev); |
---|
299 | sid->importer = bonobo_object_dup_ref (importer_data->object, &ev); |
---|
300 | if (BONOBO_EX (&ev)) { |
---|
301 | g_warning ("Error duplication %s\n(%s)", iid, |
---|
302 | CORBA_exception_id (&ev)); |
---|
303 | g_free (iid); |
---|
304 | CORBA_exception_free (&ev); |
---|
305 | g_free (sid); |
---|
306 | continue; |
---|
307 | } |
---|
308 | CORBA_exception_free (&ev); |
---|
309 | |
---|
310 | selected = g_list_prepend (selected, sid); |
---|
311 | } |
---|
312 | |
---|
313 | free_importers (data); |
---|
314 | |
---|
315 | if (selected != NULL) { |
---|
316 | start_importers (selected); |
---|
317 | |
---|
318 | for (l = selected; l; l = l->next) { |
---|
319 | SelectedImporterData *sid = l->data; |
---|
320 | |
---|
321 | CORBA_exception_init (&ev); |
---|
322 | bonobo_object_release_unref (sid->importer, &ev); |
---|
323 | CORBA_exception_free (&ev); |
---|
324 | |
---|
325 | g_free (sid->iid); |
---|
326 | g_free (sid); |
---|
327 | } |
---|
328 | g_list_free (selected); |
---|
329 | } |
---|
330 | } |
---|
331 | |
---|
332 | static gboolean |
---|
333 | finish_func (GnomeDruidPage *page, |
---|
334 | GnomeDruid *druid, |
---|
335 | SWData *data) |
---|
336 | { |
---|
337 | CORBA_Environment ev; |
---|
338 | char *displayname, *tz; |
---|
339 | icaltimezone *zone; |
---|
340 | |
---|
341 | /* Notify mailer */ |
---|
342 | CORBA_exception_init (&ev); |
---|
343 | GNOME_Evolution_Wizard_notifyAction (data->mailer, 0, GNOME_Evolution_Wizard_FINISH, &ev); |
---|
344 | CORBA_exception_free (&ev); |
---|
345 | |
---|
346 | /* Set Timezone */ |
---|
347 | CORBA_exception_init (&ev); |
---|
348 | |
---|
349 | e_timezone_dialog_get_timezone (E_TIMEZONE_DIALOG (data->timezone_page->etd), &displayname); |
---|
350 | /* We know it is a builtin timezone, as that is all the user can change |
---|
351 | it to. */ |
---|
352 | zone = e_timezone_dialog_get_builtin_timezone (displayname); |
---|
353 | if (zone == NULL) |
---|
354 | tz = g_strdup ("UTC"); |
---|
355 | else |
---|
356 | tz = g_strdup (icaltimezone_get_location (zone)); |
---|
357 | |
---|
358 | bonobo_config_set_string (data->db, "/Calendar/Display/Timezone", tz, &ev); |
---|
359 | g_free (tz); |
---|
360 | CORBA_exception_free (&ev); |
---|
361 | |
---|
362 | do_import (data); |
---|
363 | |
---|
364 | /* Free data */ |
---|
365 | data->cancel = FALSE; |
---|
366 | |
---|
367 | /* Need to do this otherwise the timezone widget gets destroyed but the |
---|
368 | timezone object isn't, and we can get a crash like #22047. */ |
---|
369 | gtk_object_unref (GTK_OBJECT (data->timezone_page->etd)); |
---|
370 | data->timezone_page->etd = NULL; |
---|
371 | |
---|
372 | gtk_widget_destroy (data->dialog); |
---|
373 | gtk_main_quit (); |
---|
374 | |
---|
375 | return TRUE; |
---|
376 | } |
---|
377 | |
---|
378 | static void |
---|
379 | connect_page (GtkWidget *page, |
---|
380 | SWData *data) |
---|
381 | { |
---|
382 | gtk_signal_connect (GTK_OBJECT (page), "next", |
---|
383 | GTK_SIGNAL_FUNC (next_func), data); |
---|
384 | gtk_signal_connect (GTK_OBJECT (page), "prepare", |
---|
385 | GTK_SIGNAL_FUNC (prepare_func), data); |
---|
386 | gtk_signal_connect (GTK_OBJECT (page), "back", |
---|
387 | GTK_SIGNAL_FUNC (back_func), data); |
---|
388 | gtk_signal_connect (GTK_OBJECT (page), "finish", |
---|
389 | GTK_SIGNAL_FUNC (finish_func), data); |
---|
390 | } |
---|
391 | |
---|
392 | static MailDialogPage * |
---|
393 | make_identity_page (SWData *data) |
---|
394 | { |
---|
395 | MailDialogPage *page; |
---|
396 | CORBA_Environment ev; |
---|
397 | |
---|
398 | g_return_val_if_fail (data != NULL, NULL); |
---|
399 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, NULL); |
---|
400 | |
---|
401 | page = g_new0 (MailDialogPage, 1); |
---|
402 | page->page = glade_xml_get_widget (data->wizard, "identity-page"); |
---|
403 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
404 | |
---|
405 | connect_page (page->page, data); |
---|
406 | g_hash_table_insert (page_hash, page->page, GINT_TO_POINTER (0)); |
---|
407 | page_list = g_list_append (page_list, page->page); |
---|
408 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
409 | |
---|
410 | CORBA_exception_init (&ev); |
---|
411 | page->control = GNOME_Evolution_Wizard_getControl (data->mailer, 0, &ev); |
---|
412 | if (BONOBO_EX (&ev) || page->control == CORBA_OBJECT_NIL) { |
---|
413 | g_warning ("Error creating page: %s", CORBA_exception_id (&ev)); |
---|
414 | g_free (page); |
---|
415 | CORBA_exception_free (&ev); |
---|
416 | |
---|
417 | return NULL; |
---|
418 | } |
---|
419 | |
---|
420 | CORBA_exception_free (&ev); |
---|
421 | |
---|
422 | page->widget = bonobo_widget_new_control_from_objref (page->control, CORBA_OBJECT_NIL); |
---|
423 | gtk_box_pack_start (GTK_BOX (page->vbox), page->widget, TRUE, TRUE, 0); |
---|
424 | gtk_widget_show_all (page->widget); |
---|
425 | |
---|
426 | return page; |
---|
427 | } |
---|
428 | |
---|
429 | static MailDialogPage * |
---|
430 | make_receive_page (SWData *data) |
---|
431 | { |
---|
432 | MailDialogPage *page; |
---|
433 | CORBA_Environment ev; |
---|
434 | |
---|
435 | g_return_val_if_fail (data != NULL, NULL); |
---|
436 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, NULL); |
---|
437 | |
---|
438 | page = g_new0 (MailDialogPage, 1); |
---|
439 | page->page = glade_xml_get_widget (data->wizard, "receive-page"); |
---|
440 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
441 | |
---|
442 | connect_page (page->page, data); |
---|
443 | g_hash_table_insert (page_hash, page->page, GINT_TO_POINTER (1)); |
---|
444 | page_list = g_list_append (page_list, page->page); |
---|
445 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
446 | |
---|
447 | CORBA_exception_init (&ev); |
---|
448 | page->control = GNOME_Evolution_Wizard_getControl (data->mailer, 1, &ev); |
---|
449 | if (BONOBO_EX (&ev) || page->control == CORBA_OBJECT_NIL) { |
---|
450 | g_warning ("Error creating page: %s", CORBA_exception_id (&ev)); |
---|
451 | g_free (page); |
---|
452 | CORBA_exception_free (&ev); |
---|
453 | |
---|
454 | return NULL; |
---|
455 | } |
---|
456 | |
---|
457 | CORBA_exception_free (&ev); |
---|
458 | |
---|
459 | page->widget = bonobo_widget_new_control_from_objref (page->control, CORBA_OBJECT_NIL); |
---|
460 | gtk_box_pack_start (GTK_BOX (page->vbox), page->widget, TRUE, TRUE, 0); |
---|
461 | gtk_widget_show_all (page->widget); |
---|
462 | |
---|
463 | return page; |
---|
464 | } |
---|
465 | |
---|
466 | static MailDialogPage * |
---|
467 | make_extra_page (SWData *data) |
---|
468 | { |
---|
469 | MailDialogPage *page; |
---|
470 | CORBA_Environment ev; |
---|
471 | |
---|
472 | g_return_val_if_fail (data != NULL, NULL); |
---|
473 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, NULL); |
---|
474 | |
---|
475 | page = g_new0 (MailDialogPage, 1); |
---|
476 | page->page = glade_xml_get_widget (data->wizard, "extra-page"); |
---|
477 | page_list = g_list_append (page_list, page->page); |
---|
478 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
479 | |
---|
480 | connect_page (page->page, data); |
---|
481 | g_hash_table_insert (page_hash, page->page, GINT_TO_POINTER (2)); |
---|
482 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
483 | |
---|
484 | CORBA_exception_init (&ev); |
---|
485 | page->control = GNOME_Evolution_Wizard_getControl (data->mailer, 2, &ev); |
---|
486 | if (BONOBO_EX (&ev) || page->control == CORBA_OBJECT_NIL) { |
---|
487 | g_warning ("Error creating page: %s", CORBA_exception_id (&ev)); |
---|
488 | g_free (page); |
---|
489 | CORBA_exception_free (&ev); |
---|
490 | |
---|
491 | return NULL; |
---|
492 | } |
---|
493 | |
---|
494 | CORBA_exception_free (&ev); |
---|
495 | |
---|
496 | page->widget = bonobo_widget_new_control_from_objref (page->control, CORBA_OBJECT_NIL); |
---|
497 | gtk_box_pack_start (GTK_BOX (page->vbox), page->widget, TRUE, TRUE, 0); |
---|
498 | gtk_widget_show_all (page->widget); |
---|
499 | |
---|
500 | return page; |
---|
501 | } |
---|
502 | |
---|
503 | static MailDialogPage * |
---|
504 | make_transport_page (SWData *data) |
---|
505 | { |
---|
506 | MailDialogPage *page; |
---|
507 | CORBA_Environment ev; |
---|
508 | |
---|
509 | g_return_val_if_fail (data != NULL, NULL); |
---|
510 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, NULL); |
---|
511 | |
---|
512 | page = g_new0 (MailDialogPage, 1); |
---|
513 | page->page = glade_xml_get_widget (data->wizard, "send-page"); |
---|
514 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
515 | |
---|
516 | connect_page (page->page, data); |
---|
517 | g_hash_table_insert (page_hash, page->page, GINT_TO_POINTER (3)); |
---|
518 | page_list = g_list_append (page_list, page->page); |
---|
519 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
520 | |
---|
521 | CORBA_exception_init (&ev); |
---|
522 | page->control = GNOME_Evolution_Wizard_getControl (data->mailer, 3, &ev); |
---|
523 | if (BONOBO_EX (&ev) || page->control == CORBA_OBJECT_NIL) { |
---|
524 | g_warning ("Error creating page: %s", CORBA_exception_id (&ev)); |
---|
525 | g_free (page); |
---|
526 | CORBA_exception_free (&ev); |
---|
527 | |
---|
528 | return NULL; |
---|
529 | } |
---|
530 | |
---|
531 | CORBA_exception_free (&ev); |
---|
532 | |
---|
533 | page->widget = bonobo_widget_new_control_from_objref (page->control, CORBA_OBJECT_NIL); |
---|
534 | gtk_box_pack_start (GTK_BOX (page->vbox), page->widget, TRUE, TRUE, 0); |
---|
535 | gtk_widget_show_all (page->widget); |
---|
536 | |
---|
537 | return page; |
---|
538 | } |
---|
539 | |
---|
540 | static MailDialogPage * |
---|
541 | make_management_page (SWData *data) |
---|
542 | { |
---|
543 | MailDialogPage *page; |
---|
544 | CORBA_Environment ev; |
---|
545 | |
---|
546 | g_return_val_if_fail (data != NULL, NULL); |
---|
547 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, NULL); |
---|
548 | |
---|
549 | page = g_new0 (MailDialogPage, 1); |
---|
550 | page->page = glade_xml_get_widget (data->wizard, "management-page"); |
---|
551 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
552 | |
---|
553 | connect_page (page->page, data); |
---|
554 | g_hash_table_insert (page_hash, page->page, GINT_TO_POINTER (4)); |
---|
555 | page_list = g_list_append (page_list, page->page); |
---|
556 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
557 | |
---|
558 | CORBA_exception_init (&ev); |
---|
559 | page->control = GNOME_Evolution_Wizard_getControl (data->mailer, 4, &ev); |
---|
560 | if (BONOBO_EX (&ev) || page->control == CORBA_OBJECT_NIL) { |
---|
561 | g_warning ("Error creating page: %s", CORBA_exception_id (&ev)); |
---|
562 | g_free (page); |
---|
563 | CORBA_exception_free (&ev); |
---|
564 | |
---|
565 | return NULL; |
---|
566 | } |
---|
567 | |
---|
568 | CORBA_exception_free (&ev); |
---|
569 | |
---|
570 | page->widget = bonobo_widget_new_control_from_objref (page->control, CORBA_OBJECT_NIL); |
---|
571 | gtk_box_pack_start (GTK_BOX (page->vbox), page->widget, TRUE, TRUE, 0); |
---|
572 | gtk_widget_show_all (page->widget); |
---|
573 | |
---|
574 | return page; |
---|
575 | } |
---|
576 | |
---|
577 | static TimezoneDialogPage * |
---|
578 | make_timezone_page (SWData *data) |
---|
579 | { |
---|
580 | TimezoneDialogPage *page; |
---|
581 | ETimezoneDialog *etd; |
---|
582 | |
---|
583 | g_return_val_if_fail (data != NULL, NULL); |
---|
584 | |
---|
585 | page = g_new0 (TimezoneDialogPage, 1); |
---|
586 | page->page = glade_xml_get_widget (data->wizard, "timezone-page"); |
---|
587 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
588 | |
---|
589 | page->vbox = GTK_WIDGET (GNOME_DRUID_PAGE_STANDARD (page->page)->vbox); |
---|
590 | |
---|
591 | etd = e_timezone_dialog_new (); |
---|
592 | page->etd = GTK_OBJECT (etd); |
---|
593 | e_timezone_dialog_reparent (E_TIMEZONE_DIALOG (page->etd), page->vbox); |
---|
594 | |
---|
595 | return page; |
---|
596 | } |
---|
597 | |
---|
598 | static GList * |
---|
599 | get_intelligent_importers (void) |
---|
600 | { |
---|
601 | OAF_ServerInfoList *info_list; |
---|
602 | GList *iids_ret = NULL; |
---|
603 | CORBA_Environment ev; |
---|
604 | int i; |
---|
605 | |
---|
606 | CORBA_exception_init (&ev); |
---|
607 | info_list = oaf_query ("repo_ids.has ('IDL:GNOME/Evolution/IntelligentImporter:1.0')", NULL, &ev); |
---|
608 | CORBA_exception_free (&ev); |
---|
609 | |
---|
610 | for (i = 0; i < info_list->_length; i++) { |
---|
611 | const OAF_ServerInfo *info; |
---|
612 | |
---|
613 | info = info_list->_buffer + i; |
---|
614 | iids_ret = g_list_prepend (iids_ret, g_strdup (info->iid)); |
---|
615 | } |
---|
616 | |
---|
617 | return iids_ret; |
---|
618 | } |
---|
619 | |
---|
620 | static gboolean |
---|
621 | prepare_importer_page (GnomeDruidPage *page, |
---|
622 | |
---|
623 | GnomeDruid *druid, |
---|
624 | SWData *data) |
---|
625 | { |
---|
626 | GtkWidget *dialog; |
---|
627 | ImportDialogPage *import; |
---|
628 | GList *l, *importers; |
---|
629 | GtkWidget *table; |
---|
630 | int running = 0; |
---|
631 | |
---|
632 | if (data->import_page->prepared == TRUE) { |
---|
633 | return TRUE; |
---|
634 | } |
---|
635 | |
---|
636 | data->import_page->prepared = TRUE; |
---|
637 | |
---|
638 | dialog = gnome_message_box_new (_("Please wait...\nScanning for existing setups"), GNOME_MESSAGE_BOX_INFO, NULL); |
---|
639 | e_make_widget_backing_stored (dialog); |
---|
640 | |
---|
641 | gtk_window_set_title (GTK_WINDOW (dialog), _("Starting Intelligent Importers")); |
---|
642 | gtk_widget_show_all (dialog); |
---|
643 | gtk_widget_show_now (dialog); |
---|
644 | |
---|
645 | gtk_widget_queue_draw (dialog); |
---|
646 | gdk_flush (); |
---|
647 | |
---|
648 | while (gtk_events_pending ()) { |
---|
649 | gtk_main_iteration (); |
---|
650 | } |
---|
651 | |
---|
652 | import = data->import_page; |
---|
653 | importers = get_intelligent_importers (); |
---|
654 | if (importers == NULL) { |
---|
655 | /* No importers, go directly to finish, do not pass go |
---|
656 | Do not collect $200 */ |
---|
657 | gnome_druid_set_page (druid, GNOME_DRUID_PAGE (data->finish)) |
---|
658 | ; |
---|
659 | gtk_widget_destroy (dialog); |
---|
660 | return TRUE; |
---|
661 | } |
---|
662 | |
---|
663 | table = gtk_table_new (g_list_length (importers), 2, FALSE); |
---|
664 | for (l = importers; l; l = l->next) { |
---|
665 | GtkWidget *label; |
---|
666 | IntelligentImporterData *id; |
---|
667 | CORBA_Environment ev; |
---|
668 | gboolean can_run; |
---|
669 | char *str; |
---|
670 | |
---|
671 | id = g_new0 (IntelligentImporterData, 1); |
---|
672 | id->iid = g_strdup (l->data); |
---|
673 | |
---|
674 | CORBA_exception_init (&ev); |
---|
675 | id->object = oaf_activate_from_id ((char *) id->iid, 0, NULL, &ev); |
---|
676 | if (BONOBO_EX (&ev)) { |
---|
677 | g_warning ("Could not start %s:%s", id->iid, |
---|
678 | CORBA_exception_id (&ev)); |
---|
679 | |
---|
680 | CORBA_exception_free (&ev); |
---|
681 | /* Clean up the IID */ |
---|
682 | g_free (id->iid); |
---|
683 | g_free (id); |
---|
684 | continue; |
---|
685 | } |
---|
686 | |
---|
687 | if (id->object == CORBA_OBJECT_NIL) { |
---|
688 | g_warning ("Could not activate component %s", id->iid); |
---|
689 | CORBA_exception_free (&ev); |
---|
690 | |
---|
691 | g_free (id->iid); |
---|
692 | g_free (id); |
---|
693 | continue; |
---|
694 | } |
---|
695 | |
---|
696 | can_run = GNOME_Evolution_IntelligentImporter_canImport (id->object, &ev); |
---|
697 | if (BONOBO_EX (&ev)) { |
---|
698 | g_warning ("Could not call canImport(%s): %s", id->iid, |
---|
699 | CORBA_exception_id (&ev)); |
---|
700 | bonobo_object_release_unref (id->object, &ev); |
---|
701 | CORBA_exception_free (&ev); |
---|
702 | |
---|
703 | g_free (id->iid); |
---|
704 | g_free (id); |
---|
705 | continue; |
---|
706 | } |
---|
707 | |
---|
708 | if (can_run == FALSE) { |
---|
709 | bonobo_object_release_unref (id->object, &ev); |
---|
710 | CORBA_exception_free (&ev); |
---|
711 | g_free (id->iid); |
---|
712 | g_free (id); |
---|
713 | continue; |
---|
714 | } |
---|
715 | |
---|
716 | running++; |
---|
717 | id->name = GNOME_Evolution_IntelligentImporter__get_importername (id->object, &ev); |
---|
718 | if (BONOBO_EX (&ev)) { |
---|
719 | g_warning ("Could not get name(%s): %s", id->iid, |
---|
720 | CORBA_exception_id (&ev)); |
---|
721 | bonobo_object_release_unref (id->object, &ev); |
---|
722 | CORBA_exception_free (&ev); |
---|
723 | g_free (id->iid); |
---|
724 | g_free (id); |
---|
725 | continue; |
---|
726 | } |
---|
727 | |
---|
728 | id->blurb = GNOME_Evolution_IntelligentImporter__get_message (id->object, &ev); |
---|
729 | if (BONOBO_EX (&ev)) { |
---|
730 | g_warning ("Could not get message(%s): %s", |
---|
731 | id->iid, CORBA_exception_id (&ev)); |
---|
732 | bonobo_object_release_unref (id->object, &ev); |
---|
733 | CORBA_exception_free (&ev); |
---|
734 | g_free (id->iid); |
---|
735 | CORBA_free (id->name); |
---|
736 | g_free (id); |
---|
737 | continue; |
---|
738 | } |
---|
739 | |
---|
740 | id->control = Bonobo_Unknown_queryInterface (id->object, |
---|
741 | "IDL:Bonobo/Control:1.0", &ev); |
---|
742 | if (BONOBO_EX (&ev)) { |
---|
743 | g_warning ("Could not QI for Bonobo/Control:1.0 %s:%s", |
---|
744 | id->iid, CORBA_exception_id (&ev)); |
---|
745 | bonobo_object_release_unref (id->object, &ev); |
---|
746 | CORBA_exception_free (&ev); |
---|
747 | g_free (id->iid); |
---|
748 | CORBA_free (id->name); |
---|
749 | CORBA_free (id->blurb); |
---|
750 | continue; |
---|
751 | } |
---|
752 | |
---|
753 | if (id->control != CORBA_OBJECT_NIL) { |
---|
754 | id->widget = bonobo_widget_new_control_from_objref (id->control, CORBA_OBJECT_NIL); |
---|
755 | gtk_widget_show (id->widget); |
---|
756 | } else { |
---|
757 | id->widget = gtk_label_new (""); |
---|
758 | gtk_widget_show (id->widget); |
---|
759 | } |
---|
760 | |
---|
761 | CORBA_exception_free (&ev); |
---|
762 | |
---|
763 | import->importers = g_list_prepend (import->importers, id); |
---|
764 | str = g_strdup_printf (_("From %s:"), id->name); |
---|
765 | label = gtk_label_new (str); |
---|
766 | g_free (str); |
---|
767 | |
---|
768 | gtk_misc_set_alignment (GTK_MISC (label), 0, .5); |
---|
769 | |
---|
770 | gtk_table_attach (GTK_TABLE (table), label, 0, 1, running - 1, |
---|
771 | running, GTK_FILL, 0, 0, 0); |
---|
772 | gtk_table_attach (GTK_TABLE (table), id->widget, 1, 2, |
---|
773 | running - 1, running, GTK_FILL, 0, 3, 0); |
---|
774 | gtk_widget_show_all (table); |
---|
775 | |
---|
776 | gtk_box_pack_start (GTK_BOX (data->import_page->vbox), table, |
---|
777 | FALSE, FALSE, 0); |
---|
778 | } |
---|
779 | |
---|
780 | if (running == 0) { |
---|
781 | gnome_druid_set_page (druid, GNOME_DRUID_PAGE (data->finish)); |
---|
782 | gtk_widget_destroy (dialog); |
---|
783 | return TRUE; |
---|
784 | } |
---|
785 | |
---|
786 | import->running = running; |
---|
787 | gtk_widget_destroy (dialog); |
---|
788 | |
---|
789 | return FALSE; |
---|
790 | } |
---|
791 | |
---|
792 | static ImportDialogPage * |
---|
793 | make_importer_page (SWData *data) |
---|
794 | { |
---|
795 | ImportDialogPage *page; |
---|
796 | GtkWidget *label, *sep; |
---|
797 | |
---|
798 | g_return_val_if_fail (data != NULL, NULL); |
---|
799 | |
---|
800 | page = g_new0 (ImportDialogPage, 1); |
---|
801 | page->page = glade_xml_get_widget (data->wizard, "import-page"); |
---|
802 | g_return_val_if_fail (page->page != NULL, NULL); |
---|
803 | |
---|
804 | gtk_signal_connect (GTK_OBJECT (page->page), "prepare", |
---|
805 | GTK_SIGNAL_FUNC (prepare_importer_page), data); |
---|
806 | page->vbox = GNOME_DRUID_PAGE_STANDARD (page->page)->vbox; |
---|
807 | gtk_container_set_border_width (GTK_CONTAINER (page->vbox), 4); |
---|
808 | |
---|
809 | label = gtk_label_new (_("Please select the information that you would like to import:")); |
---|
810 | gtk_box_pack_start (GTK_BOX (page->vbox), label, FALSE, FALSE, 3); |
---|
811 | |
---|
812 | sep = gtk_hseparator_new (); |
---|
813 | gtk_box_pack_start (GTK_BOX (page->vbox), sep, FALSE, FALSE, 3); |
---|
814 | |
---|
815 | page->prepared = FALSE; |
---|
816 | return page; |
---|
817 | } |
---|
818 | |
---|
819 | static void |
---|
820 | startup_wizard_cancel (GnomeDruid *druid, |
---|
821 | SWData *data) |
---|
822 | { |
---|
823 | /* Free data */ |
---|
824 | data->cancel = TRUE; |
---|
825 | |
---|
826 | if (data->timezone_page->etd != NULL) { |
---|
827 | /* Need to do this otherwise the timezone widget gets destroyed but the |
---|
828 | timezone object isn't, and we can get a crash like #22047. */ |
---|
829 | gtk_object_unref (GTK_OBJECT (data->timezone_page->etd)); |
---|
830 | data->timezone_page->etd = NULL; |
---|
831 | } |
---|
832 | |
---|
833 | gtk_widget_destroy (data->dialog); |
---|
834 | gtk_main_quit (); |
---|
835 | } |
---|
836 | |
---|
837 | gboolean |
---|
838 | e_shell_startup_wizard_create (void) |
---|
839 | { |
---|
840 | SWData *data; |
---|
841 | CORBA_Environment ev; |
---|
842 | int num_accounts; |
---|
843 | |
---|
844 | data = g_new0 (SWData, 1); |
---|
845 | |
---|
846 | CORBA_exception_init (&ev); |
---|
847 | data->db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev); |
---|
848 | if (BONOBO_EX (&ev) || data->db == CORBA_OBJECT_NIL) { |
---|
849 | g_warning ("Error starting wombat: (%s)", CORBA_exception_id (&ev)); |
---|
850 | CORBA_exception_free (&ev); |
---|
851 | g_free (data); |
---|
852 | |
---|
853 | return FALSE; |
---|
854 | } |
---|
855 | |
---|
856 | num_accounts = bonobo_config_get_long_with_default (data->db, "/Mail/Accounts/num", 0, NULL); |
---|
857 | CORBA_exception_free (&ev); |
---|
858 | |
---|
859 | if (num_accounts != 0) { |
---|
860 | bonobo_object_release_unref (data->db, NULL); |
---|
861 | g_free (data); |
---|
862 | return TRUE; |
---|
863 | } |
---|
864 | |
---|
865 | /* Local Athena hack: we don't want to inflict the startup |
---|
866 | wizard on new users. Set up the time zone here (why can't |
---|
867 | Evolution use the system time zone?) and handle mail |
---|
868 | accounts in evolution-mail. */ |
---|
869 | bonobo_config_set_string(data->db, "/Calendar/Display/Timezone", |
---|
870 | "America/New_York", NULL); |
---|
871 | return TRUE; |
---|
872 | |
---|
873 | data->wizard = glade_xml_new (EVOLUTION_GLADEDIR "/evolution-startup-wizard.glade", NULL); |
---|
874 | g_return_val_if_fail (data->wizard != NULL, FALSE); |
---|
875 | data->dialog = glade_xml_get_widget (data->wizard, "startup-wizard"); |
---|
876 | g_return_val_if_fail (data->dialog != NULL, FALSE); |
---|
877 | gtk_window_set_wmclass (GTK_WINDOW (data->dialog), "startup-wizard", |
---|
878 | "Evolution:shell"); |
---|
879 | |
---|
880 | page_hash = g_hash_table_new (NULL, NULL); |
---|
881 | data->druid = glade_xml_get_widget (data->wizard, "startup-druid"); |
---|
882 | g_return_val_if_fail (data->druid != NULL, FALSE); |
---|
883 | gnome_druid_set_buttons_sensitive (GNOME_DRUID (data->druid), |
---|
884 | FALSE, TRUE, FALSE); |
---|
885 | |
---|
886 | gtk_signal_connect (GTK_OBJECT (data->druid), "cancel", |
---|
887 | GTK_SIGNAL_FUNC (startup_wizard_cancel), data); |
---|
888 | |
---|
889 | data->start = glade_xml_get_widget (data->wizard, "start-page"); |
---|
890 | data->finish = glade_xml_get_widget (data->wizard, "done-page"); |
---|
891 | g_return_val_if_fail (data->start != NULL, FALSE); |
---|
892 | g_return_val_if_fail (data->finish != NULL, FALSE); |
---|
893 | gtk_signal_connect (GTK_OBJECT (data->finish), "finish", |
---|
894 | GTK_SIGNAL_FUNC (finish_func), data); |
---|
895 | |
---|
896 | make_mail_dialog_pages (data); |
---|
897 | g_return_val_if_fail (data->mailer != CORBA_OBJECT_NIL, TRUE); |
---|
898 | |
---|
899 | data->id_page = make_identity_page (data); |
---|
900 | data->source_page = make_receive_page (data); |
---|
901 | data->extra_page = make_extra_page (data); |
---|
902 | data->transport_page = make_transport_page (data); |
---|
903 | data->management_page = make_management_page (data); |
---|
904 | |
---|
905 | data->timezone_page = make_timezone_page (data); |
---|
906 | data->import_page = make_importer_page (data); |
---|
907 | |
---|
908 | g_return_val_if_fail (data->id_page != NULL, TRUE); |
---|
909 | g_return_val_if_fail (data->source_page != NULL, TRUE); |
---|
910 | g_return_val_if_fail (data->extra_page != NULL, TRUE); |
---|
911 | g_return_val_if_fail (data->transport_page != NULL, TRUE); |
---|
912 | g_return_val_if_fail (data->management_page != NULL, TRUE); |
---|
913 | g_return_val_if_fail (data->timezone_page != NULL, TRUE); |
---|
914 | g_return_val_if_fail (data->import_page != NULL, TRUE); |
---|
915 | |
---|
916 | gnome_druid_set_buttons_sensitive (GNOME_DRUID (data->druid), FALSE, TRUE, TRUE); |
---|
917 | gtk_widget_show_all (data->dialog); |
---|
918 | |
---|
919 | gtk_main (); |
---|
920 | |
---|
921 | /* Sync database */ |
---|
922 | Bonobo_ConfigDatabase_sync (data->db, &ev); |
---|
923 | bonobo_object_release_unref (data->db, NULL); |
---|
924 | CORBA_exception_free (&ev); |
---|
925 | |
---|
926 | return !data->cancel; |
---|
927 | } |
---|