1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Authors:
* Jeffrey Stedfast <fejj@ximian.com>
* Dan Winship <danw@ximian.com>
* Iain Holmes <iain@ximian.com>
*
* Copyright 2001 Ximian, Inc. (www.ximian.com)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <sys/types.h>
#include <sys/utsname.h>
#include <string.h>
#include <unistd.h>
#include <glade/glade.h>
#include <gtkhtml/gtkhtml.h>
#include <libgnomeui/gnome-dialog.h>
#include <libgnomeui/gnome-dialog-util.h>
#include <libgnomeui/gnome-druid.h>
#include <libgnomeui/gnome-druid-page-standard.h>
#include <bonobo/bonobo-exception.h>
#include "mail-config-druid.h"
#include "mail-config.h"
#include "mail-ops.h"
#include "mail.h"
#include "mail-session.h"
#include <evolution-wizard.h>
#include <e-util/e-account.h>
static void mail_config_druid_class_init (MailConfigDruidClass *class);
static void mail_config_druid_destroy (GtkObject *obj);
static GtkWindowClass *parent_class;
/* These globals need fixed FIXME FIXME FIXME FIXME*/
static GHashTable *page_hash = NULL;
static GList *page_list = NULL;
static EvolutionWizard *account_wizard;
#define WIZARD_IID "OAFIID:GNOME_Evolution_Mail_Wizard_Factory"
typedef enum {
MAIL_CONFIG_WIZARD_PAGE_NONE = -1,
MAIL_CONFIG_WIZARD_PAGE_IDENTITY,
MAIL_CONFIG_WIZARD_PAGE_SOURCE,
MAIL_CONFIG_WIZARD_PAGE_EXTRA,
MAIL_CONFIG_WIZARD_PAGE_TRANSPORT,
MAIL_CONFIG_WIZARD_PAGE_MANAGEMENT,
} MailConfigWizardPage;
typedef struct {
MailAccountGui *gui;
EAccount *account;
EvolutionWizard *wizard;
gboolean identity_copied;
CamelProvider *last_source;
MailConfigWizardPage page;
} MailConfigWizard;
GtkType
mail_config_druid_get_type (void)
{
static GType type = 0;
if (!type) {
GTypeInfo type_info = {
sizeof (MailConfigDruidClass),
NULL, NULL,
(GClassInitFunc) mail_config_druid_class_init,
NULL, NULL,
sizeof (MailConfigDruid),
0,
(GInstanceInitFunc) NULL,
};
type = g_type_register_static (gtk_window_get_type (), "MailConfigDruid", &type_info, 0);
}
return type;
}
static void
mail_config_druid_class_init (MailConfigDruidClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass *) class;
parent_class = g_type_class_ref(gtk_window_get_type ());
/* override methods */
object_class->destroy = mail_config_druid_destroy;
}
static void
mail_config_druid_destroy (GtkObject *obj)
{
MailConfigDruid *druid = (MailConfigDruid *) obj;
CORBA_Environment ev;
if (druid->xml) {
g_object_unref(druid->xml);
druid->xml = NULL;
CORBA_exception_init (&ev);
Bonobo_EventSource_removeListener ((Bonobo_EventSource) druid->event_source,
bonobo_object_corba_objref(BONOBO_OBJECT(druid->listener)), &ev);
CORBA_exception_free (&ev);
bonobo_object_release_unref ((Bonobo_Unknown) druid->event_source, &ev);
bonobo_object_unref (BONOBO_OBJECT (druid->listener));
}
((GtkObjectClass *)(parent_class))->destroy(obj);
}
static struct {
char *name;
char *text;
} info[] = {
{ "identity_html",
N_("Please enter your name and email address below. The \"optional\" fields below do not need to be filled in, unless you wish to include this information in email you send.") },
{ "source_html",
N_("Please enter information about your incoming mail server below. If you are not sure, ask your system administrator or Internet Service Provider.") },
{ "extra_html",
N_("Please select among the following options") },
{ "transport_html",
N_("Please enter information about the way you will send mail. If you are not sure, ask your system administrator or Internet Service Provider.") },
{ "management_html",
N_("You are almost done with the mail configuration process. The identity, incoming mail server and outgoing mail transport method which you provided will be grouped together to make an Evolution mail account. Please enter a name for this account in the space below. This name will be used for display purposes only.") }
};
static int num_info = (sizeof (info) / sizeof (info[0]));
static GtkWidget *
create_label (const char *name)
{
GtkWidget *widget, *align;
int i;
for (i = 0; i < num_info; i++) {
if (!strcmp (name, info[i].name))
break;
}
g_return_val_if_fail (i != num_info, NULL);
widget = gtk_label_new (_(info[i].text));
gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_FILL);
gtk_widget_show (widget);
align = gtk_alignment_new (0.0, 0.5, 1.0, 1.0);
gtk_container_add (GTK_CONTAINER (align), widget);
gtk_widget_show (align);
return align;
}
static void
druid_cancel (GnomeDruid *druid, gpointer user_data)
{
MailConfigDruid *config = user_data;
GNOME_Evolution_Wizard wiz;
CORBA_Environment ev;
wiz = bonobo_object_corba_objref (BONOBO_OBJECT (account_wizard));
CORBA_exception_init (&ev);
GNOME_Evolution_Wizard_notifyAction (wiz, 0, GNOME_Evolution_Wizard_CANCEL, &ev);
CORBA_exception_free (&ev);
if (page_list != NULL) {
g_list_free (page_list);
page_list = NULL;
}
if (page_hash != NULL) {
g_hash_table_destroy (page_hash);
page_hash = NULL;
}
gtk_widget_destroy (GTK_WIDGET (config));
}
static void
druid_finish (GnomeDruidPage *page, gpointer arg1, gpointer user_data)
{
MailConfigDruid *druid = user_data;
g_object_set_data(G_OBJECT(account_wizard), "account-data", NULL);
if (page_list != NULL) {
g_list_free (page_list);
page_list = NULL;
}
if (page_hash != NULL) {
g_hash_table_destroy (page_hash);
page_hash = NULL;
}
gtk_widget_destroy (GTK_WIDGET (druid));
}
/* Identity Page */
static void
identity_changed (GtkWidget *widget, gpointer data)
{
MailConfigWizard *gui = data;
GtkWidget *incomplete;
gboolean next_sensitive;
if (gui->page != MAIL_CONFIG_WIZARD_PAGE_IDENTITY)
return;
next_sensitive = mail_account_gui_identity_complete (gui->gui, &incomplete);
evolution_wizard_set_buttons_sensitive (gui->wizard, TRUE, next_sensitive, TRUE, NULL);
if (!next_sensitive)
gtk_widget_grab_focus (incomplete);
}
static void
identity_prepare (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
const char *name;
gui->page = MAIL_CONFIG_WIZARD_PAGE_IDENTITY;
name = gtk_entry_get_text (gui->gui->full_name);
if (!name) {
name = g_get_real_name ();
gtk_entry_set_text (gui->gui->full_name, name ? name : "");
gtk_editable_select_region (GTK_EDITABLE (gui->gui->full_name), 0, -1);
}
gtk_widget_grab_focus (GTK_WIDGET (gui->gui->full_name));
identity_changed (NULL, data);
}
static gboolean
identity_next (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
if (!gui->identity_copied) {
char *username;
const char *user;
/* Copy the username part of the email address into
* the Username field of the source and transport pages.
*/
user = gtk_entry_get_text (gui->gui->email_address);
username = g_strndup (user, strcspn (user, "@"));
gtk_entry_set_text (gui->gui->source.username, username);
gtk_entry_set_text (gui->gui->transport.username, username);
g_free (username);
gui->identity_copied = TRUE;
}
return FALSE;
}
/* Incoming mail Page */
static void
source_changed (GtkWidget *widget, gpointer data)
{
MailConfigWizard *gui = data;
GtkWidget *incomplete;
gboolean next_sensitive;
if (gui->page != MAIL_CONFIG_WIZARD_PAGE_SOURCE)
return;
next_sensitive = mail_account_gui_source_complete (gui->gui, &incomplete);
evolution_wizard_set_buttons_sensitive (gui->wizard, TRUE, next_sensitive, TRUE, NULL);
if (!next_sensitive)
gtk_widget_grab_focus (incomplete);
}
static void
source_prepare (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
gui->page = MAIL_CONFIG_WIZARD_PAGE_SOURCE;
source_changed (NULL, gui);
}
static gboolean
source_next (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
/* FIXME: if online, check that the data is good. */
if (gui->gui->source.provider && gui->gui->source.provider->extra_conf)
return FALSE;
/* Otherwise, skip to transport page. */
evolution_wizard_set_page (gui->wizard, MAIL_CONFIG_WIZARD_PAGE_TRANSPORT, NULL);
return TRUE;
}
/* Extra Config Page */
static void
extra_prepare (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
gui->page = MAIL_CONFIG_WIZARD_PAGE_EXTRA;
if (gui->gui->source.provider != gui->last_source) {
gui->last_source = gui->gui->source.provider;
mail_account_gui_auto_detect_extra_conf (gui->gui);
}
}
/* Transport Page */
static gboolean
transport_next (EvolutionWizard *wizard, gpointer data)
{
/* FIXME: if online, check that the data is good. */
return FALSE;
}
static gboolean
transport_back (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
if (gui->gui->source.provider && gui->gui->source.provider->extra_conf)
return FALSE;
else {
evolution_wizard_set_page (wizard, MAIL_CONFIG_WIZARD_PAGE_SOURCE, NULL);
return TRUE;
}
}
static void
transport_changed (GtkWidget *widget, gpointer data)
{
MailConfigWizard *gui = data;
GtkWidget *incomplete;
gboolean next_sensitive;
if (gui->page != MAIL_CONFIG_WIZARD_PAGE_TRANSPORT)
return;
next_sensitive = mail_account_gui_transport_complete (gui->gui, &incomplete);
evolution_wizard_set_buttons_sensitive (gui->wizard, TRUE, next_sensitive, TRUE, NULL);
if (!next_sensitive)
gtk_widget_grab_focus (incomplete);
}
static void
transport_prepare (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
gui->page = MAIL_CONFIG_WIZARD_PAGE_TRANSPORT;
transport_changed (NULL, data);
}
/* Management page */
static gboolean
management_check (MailConfigWizard *wizard)
{
gboolean next_sensitive;
const char *text;
text = gtk_entry_get_text (wizard->gui->account_name);
next_sensitive = text && *text;
/* no accounts with the same name */
if (next_sensitive && mail_config_get_account_by_name (text))
next_sensitive = FALSE;
evolution_wizard_set_buttons_sensitive (wizard->wizard, TRUE,
next_sensitive, TRUE, NULL);
return next_sensitive;
}
static void
management_prepare (EvolutionWizard *wizard, gpointer data)
{
MailConfigWizard *gui = data;
const char *name, *text;
gui->page = MAIL_CONFIG_WIZARD_PAGE_MANAGEMENT;
text = gtk_entry_get_text (gui->gui->account_name);
if (!text || *text == '\0') {
name = gtk_entry_get_text(gui->gui->email_address);
if (name && *name) {
if (mail_config_get_account_by_name (name)) {
char *template;
unsigned int i = 1, len;
/* length of name + 1 char for ' ' + 1 char
for '(' + 10 chars for %d + 1 char for ')'
+ 1 char for nul */
len = strlen (name);
template = alloca (len + 14);
strcpy (template, name);
name = template;
do {
sprintf (template + len, " (%d)", i++);
} while (mail_config_get_account_by_name (name) && i != 0);
}
gtk_entry_set_text(gui->gui->account_name, name);
}
}
management_check (gui);
}
static void
management_changed (GtkWidget *widget, gpointer data)
{
MailConfigWizard *gui = data;
if (gui->page != MAIL_CONFIG_WIZARD_PAGE_MANAGEMENT)
return;
management_check (gui);
gtk_widget_grab_focus (GTK_WIDGET (gui->gui->account_name));
}
static EAccount *
make_account (void)
{
const char *name, *user;
EAccountService *xport;
struct utsname uts;
EAccount *account;
account = e_account_new ();
account->enabled = TRUE;
name = g_get_real_name ();
account->id->name = g_strdup (name);
user = g_get_user_name ();
if (user && !uname (&uts) && strchr (uts.nodename, '.'))
account->id->address = g_strdup_printf ("%s@%s", user, uts.nodename);
if ((xport = mail_config_get_default_transport ())) {
account->transport->url = g_strdup (xport->url);
account->transport->save_passwd = xport->save_passwd;
}
return account;
}
static const char *pages[] = {
"identity_page",
"source_page",
"extra_page",
"transport_page",
"management_page",
"finish_page",
"druidpagestart1",
NULL
};
static int
page_to_num (gpointer page)
{
gpointer r;
r = g_hash_table_lookup (page_hash, page);
if (r == NULL) {
return 0;
}
return GPOINTER_TO_INT (r);
}
static gboolean
next_func (GnomeDruidPage *page,
GnomeDruid *druid,
gpointer data)
{
GNOME_Evolution_Wizard wiz;
CORBA_Environment ev;
int pagenum;
wiz = bonobo_object_corba_objref (BONOBO_OBJECT (account_wizard));
CORBA_exception_init (&ev);
pagenum = page_to_num (page);
GNOME_Evolution_Wizard_notifyAction (wiz, pagenum, GNOME_Evolution_Wizard_NEXT, &ev);
CORBA_exception_free (&ev);
if (pagenum < 5-1)
return TRUE;
return FALSE;
}
static gboolean
prepare_func (GnomeDruidPage *page,
GnomeDruid *druid,
gpointer data)
{
GNOME_Evolution_Wizard wiz;
CORBA_Environment ev;
int pagenum;
wiz = bonobo_object_corba_objref (BONOBO_OBJECT (account_wizard));
CORBA_exception_init (&ev);
pagenum = page_to_num (page);
GNOME_Evolution_Wizard_notifyAction (wiz, pagenum, GNOME_Evolution_Wizard_PREPARE, &ev);
CORBA_exception_free (&ev);
return FALSE;
}
static gboolean
back_func (GnomeDruidPage *page,
GnomeDruid *druid,
gpointer data)
{
GNOME_Evolution_Wizard wiz;
CORBA_Environment ev;
int pagenum;
wiz = bonobo_object_corba_objref (BONOBO_OBJECT (account_wizard));
CORBA_exception_init (&ev);
pagenum = page_to_num (page);
GNOME_Evolution_Wizard_notifyAction (wiz, pagenum, GNOME_Evolution_Wizard_BACK, &ev);
CORBA_exception_free (&ev);
if (pagenum > 0)
return TRUE;
return FALSE;
}
static gboolean
finish_func (GnomeDruidPage *page,
GnomeDruid *druid,
gpointer data)
{
GNOME_Evolution_Wizard wiz;
CORBA_Environment ev;
int pagenum;
wiz = bonobo_object_corba_objref (BONOBO_OBJECT (account_wizard));
CORBA_exception_init (&ev);
pagenum = page_to_num (page);
GNOME_Evolution_Wizard_notifyAction (wiz, 0, GNOME_Evolution_Wizard_FINISH, &ev);
CORBA_exception_free (&ev);
druid_finish (page, druid, data);
return FALSE;
}
static void
wizard_listener_event (BonoboListener *listener,
char *event_name,
BonoboArg *event_data,
CORBA_Environment *ev,
MailConfigDruid *druid)
{
CORBA_short buttons, pagenum;
GnomeDruidPage *page;
if (strcmp (event_name, EVOLUTION_WIZARD_SET_BUTTONS_SENSITIVE) == 0) {
buttons = (int) *((CORBA_short *)event_data->_value);
gnome_druid_set_buttons_sensitive (GNOME_DRUID (druid->druid),
(buttons & 4) >> 2,
(buttons & 2) >> 1,
(buttons & 1),
FALSE);
} else if (strcmp (event_name, EVOLUTION_WIZARD_SET_SHOW_FINISH) == 0) {
gnome_druid_set_show_finish (GNOME_DRUID (druid->druid),
(gboolean) *((CORBA_boolean *)event_data->_value));
} else if (strcmp (event_name, EVOLUTION_WIZARD_SET_PAGE) == 0) {
pagenum = (int) *((CORBA_short *) event_data->_value);
page = g_list_nth_data (page_list, pagenum);
gnome_druid_set_page (GNOME_DRUID (druid->druid), page);
}
}
static void
construct (MailConfigDruid *druid)
{
GtkWidget *widget;
GNOME_Evolution_Wizard corba_wizard;
Bonobo_Listener corba_listener;
CORBA_Environment ev;
int i;
/* Start account wizard */
CORBA_exception_init (&ev);
corba_wizard = bonobo_activation_activate_from_id ("OAFIID:GNOME_Evolution_Mail_Wizard", 0, NULL, &ev);
CORBA_exception_free (&ev);
g_assert (account_wizard != NULL);
druid->xml = glade_xml_new (EVOLUTION_GLADEDIR "/mail-config.glade", NULL, NULL);
/* get our toplevel widget and reparent it */
widget = glade_xml_get_widget (druid->xml, "druid");
gtk_widget_reparent (widget, GTK_WIDGET (druid));
druid->druid = GNOME_DRUID (widget);
/* set window title */
gtk_window_set_title (GTK_WINDOW (druid), _("Evolution Account Assistant"));
gtk_window_set_resizable (GTK_WINDOW (druid), TRUE);
gtk_window_set_modal (GTK_WINDOW (druid), FALSE);
g_object_set (G_OBJECT (druid), "type", GTK_WINDOW_TOPLEVEL, NULL);
druid->listener = bonobo_listener_new (NULL, NULL);
g_signal_connect(druid->listener, "event-notify",
G_CALLBACK (wizard_listener_event), druid);
corba_listener = bonobo_object_corba_objref (BONOBO_OBJECT (druid->listener));
CORBA_exception_init (&ev);
druid->event_source = (Bonobo_Unknown) bonobo_object_query_interface (
BONOBO_OBJECT (account_wizard), "IDL:Bonobo/EventSource:1.0", NULL);
g_assert (druid->event_source != CORBA_OBJECT_NIL);
Bonobo_EventSource_addListener ((Bonobo_EventSource) druid->event_source, corba_listener, &ev);
if (BONOBO_EX (&ev)) {
g_warning ("Error adding listener (%s)",
CORBA_exception_id (&ev));
}
CORBA_exception_free (&ev);
if (page_hash != NULL) {
g_hash_table_destroy (page_hash);
}
page_hash = g_hash_table_new (NULL, NULL);
for (i = 0; pages[i] != NULL; i++) {
GtkWidget *page;
GnomeDruidPageStandard *dpage;
page = glade_xml_get_widget (druid->xml, pages[i]);
/* Store pages */
g_hash_table_insert (page_hash, page, GINT_TO_POINTER (i));
page_list = g_list_append (page_list, page);
g_signal_connect(page, "next", G_CALLBACK (next_func), druid);
g_signal_connect(page, "prepare", G_CALLBACK (prepare_func), druid);
g_signal_connect(page, "back", G_CALLBACK (back_func), druid);
g_signal_connect(page, "finish", G_CALLBACK (finish_func), druid);
if (i < 5) {
Bonobo_Control control;
GtkWidget *w;
CORBA_Environment ev;
dpage = GNOME_DRUID_PAGE_STANDARD (page);
CORBA_exception_init (&ev);
control = GNOME_Evolution_Wizard_getControl (corba_wizard, i, &ev);
if (BONOBO_EX (&ev)) {
g_warning ("Error getting page %d: %s", i, CORBA_exception_id (&ev));
CORBA_exception_free (&ev);
continue;
}
w = bonobo_widget_new_control_from_objref (control, CORBA_OBJECT_NIL);
gtk_box_pack_start (GTK_BOX (dpage->vbox), w, TRUE, TRUE, 0);
}
gtk_widget_show_all (page);
}
g_signal_connect(druid->druid, "cancel", G_CALLBACK(druid_cancel), druid);
gnome_druid_set_buttons_sensitive (druid->druid, FALSE, TRUE, TRUE, FALSE);
}
MailConfigDruid *
mail_config_druid_new (GNOME_Evolution_Shell shell)
{
MailConfigDruid *new;
new = (MailConfigDruid *) g_object_new(mail_config_druid_get_type(), NULL);
construct (new);
new->shell = shell;
return new;
}
static void wizard_next_cb (EvolutionWizard *wizard, int page_num, MailConfigWizard *gui);
static void
goto_next_page (MailConfigWizard *gui)
{
wizard_next_cb (gui->wizard, gui->page, gui);
}
static void
identity_activate_cb (GtkEntry *ent, gpointer user_data)
{
MailConfigWizard *gui = (MailConfigWizard *) user_data;
if (mail_account_gui_identity_complete (gui->gui, NULL))
goto_next_page (gui);
}
static void
source_activate_cb (GtkEntry *ent, gpointer user_data)
{
MailConfigWizard *gui = (MailConfigWizard *) user_data;
if (mail_account_gui_source_complete (gui->gui, NULL))
goto_next_page (gui);
}
static void
transport_activate_cb (GtkEntry *ent, gpointer user_data)
{
MailConfigWizard *gui = (MailConfigWizard *) user_data;
if (mail_account_gui_transport_complete (gui->gui, NULL))
goto_next_page (gui);
}
static void
management_activate_cb (GtkEntry *ent, gpointer user_data)
{
MailConfigWizard *gui = (MailConfigWizard *) user_data;
if (management_check (gui))
goto_next_page (gui);
}
static BonoboControl *
get_fn (EvolutionWizard *wizard,
int page_num,
void *closure)
{
MailConfigWizard *gui = closure;
BonoboControl *control;
GtkWidget *vbox, *widget;
static gboolean first_time = TRUE;
if (gui->gui == NULL) {
if (gui->account == NULL) {
gui->account = make_account ();
g_object_set_data ((GObject *) wizard, "account-data", gui->account);
}
gui->gui = mail_account_gui_new (gui->account, NULL);
/* set up signals, etc */
g_signal_connect (gui->gui->account_name, "changed",
G_CALLBACK (management_changed), gui);
g_signal_connect (gui->gui->full_name, "changed",
G_CALLBACK (identity_changed), gui);
g_signal_connect (gui->gui->email_address, "changed",
G_CALLBACK (identity_changed), gui);
g_signal_connect (gui->gui->reply_to,"changed",
G_CALLBACK (identity_changed), gui);
g_signal_connect (gui->gui->source.hostname, "changed",
G_CALLBACK (source_changed), gui);
g_signal_connect (gui->gui->source.username, "changed",
G_CALLBACK (source_changed), gui);
g_signal_connect (gui->gui->source.path, "changed",
G_CALLBACK (source_changed), gui);
g_signal_connect (gui->gui->transport.hostname, "changed",
G_CALLBACK (transport_changed), gui);
g_signal_connect (gui->gui->transport.username, "changed",
G_CALLBACK (transport_changed), gui);
g_signal_connect (gui->gui->transport_needs_auth, "toggled",
G_CALLBACK (transport_changed), gui);
g_signal_connect (gui->gui->account_name, "activate",
G_CALLBACK (management_activate_cb), gui);
g_signal_connect (gui->gui->full_name, "activate",
G_CALLBACK (identity_activate_cb), gui);
g_signal_connect (gui->gui->email_address, "activate",
G_CALLBACK (identity_activate_cb), gui);
g_signal_connect (gui->gui->reply_to,"activate",
G_CALLBACK (identity_activate_cb), gui);
g_signal_connect (gui->gui->organization, "activate",
G_CALLBACK (identity_activate_cb), gui);
g_signal_connect (gui->gui->source.hostname, "activate",
G_CALLBACK (source_activate_cb), gui);
g_signal_connect (gui->gui->source.username, "activate",
G_CALLBACK (source_activate_cb), gui);
g_signal_connect (gui->gui->source.path, "activate",
G_CALLBACK (source_activate_cb), gui);
g_signal_connect (gui->gui->transport.hostname, "activate",
G_CALLBACK (transport_activate_cb), gui);
g_signal_connect (gui->gui->transport.username, "activate",
G_CALLBACK (transport_activate_cb), gui);
first_time = TRUE;
}
/* Fill in the druid pages */
vbox = gtk_vbox_new (FALSE, 0);
switch (page_num) {
case 0:
widget = create_label ("identity_html");
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
widget = glade_xml_get_widget (gui->gui->xml, "identity_required_frame");
gtk_widget_reparent (widget, vbox);
gtk_box_set_child_packing (GTK_BOX (vbox), widget, FALSE, FALSE, 0, GTK_PACK_START);
widget = glade_xml_get_widget (gui->gui->xml, "identity_optional_frame");
gtk_widget_reparent (widget, vbox);
gtk_box_set_child_packing (GTK_BOX (vbox), widget, FALSE, FALSE, 0, GTK_PACK_START);
break;
case 1:
widget = create_label ("source_html");
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
widget = glade_xml_get_widget (gui->gui->xml, "source_vbox");
gtk_widget_reparent (widget, vbox);
gtk_widget_show (widget);
break;
case 2:
widget = create_label ("extra_html");
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
widget = glade_xml_get_widget (gui->gui->xml, "extra_vbox");
gtk_widget_reparent (widget, vbox);
break;
case 3:
widget = create_label ("transport_html");
gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0);
widget = glade_xml_get_widget (gui->gui->xml, "transport_vbox");
gtk_widget_reparent (widget, vbox);
gtk_widget_show (widget);
break;
case 4:
widget = glade_xml_get_widget (gui->gui->xml, "management_frame");
gtk_widget_reparent (widget, vbox);
break;
default:
return NULL;
}
gtk_widget_show (vbox);
control = bonobo_control_new (vbox);
if (first_time) {
mail_account_gui_setup (gui->gui, NULL);
first_time = FALSE;
}
return control;
}
typedef gboolean (*NextFunc)(EvolutionWizard *wizard, gpointer data);
typedef void (*PrepFunc)(EvolutionWizard *wizard, gpointer data);
static struct {
NextFunc next_func;
PrepFunc prepare_func;
NextFunc back_func;
GtkSignalFunc finish_func;
GtkSignalFunc help_func;
} wizard_pages[] = {
{ identity_next,
identity_prepare,
NULL,
G_CALLBACK (NULL),
G_CALLBACK (NULL) },
{ source_next,
source_prepare,
NULL,
G_CALLBACK (NULL),
G_CALLBACK (NULL) },
{ NULL,
extra_prepare,
NULL,
G_CALLBACK (NULL),
G_CALLBACK (NULL) },
{ transport_next,
transport_prepare,
transport_back,
G_CALLBACK (NULL),
G_CALLBACK (NULL) },
{ NULL,
management_prepare,
NULL,
G_CALLBACK (NULL),
G_CALLBACK (NULL) }
};
static void
wizard_next_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *gui)
{
if (wizard_pages[page_num].next_func == NULL
|| !(wizard_pages[page_num].next_func (wizard, gui))) {
if (page_num < 5-1) {
evolution_wizard_set_page(wizard, page_num+1, NULL);
}
}
}
static void
wizard_prepare_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *gui)
{
if (wizard_pages[page_num].prepare_func != NULL) {
wizard_pages[page_num].prepare_func (wizard, gui);
}
}
static void
wizard_back_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *gui)
{
if (page_num >= 5)
evolution_wizard_set_page(wizard, 4, NULL);
else if (wizard_pages[page_num].back_func == NULL
|| !(wizard_pages[page_num].back_func (wizard, gui))) {
if (page_num > 0)
evolution_wizard_set_page(wizard, page_num-1, NULL);
}
}
static void
wizard_finish_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *w)
{
MailAccountGui *gui = w->gui;
/* Save the settings for that account */
if (mail_account_gui_save (gui) == FALSE)
/* problem. Um, how to keep the druid alive? */
return;
/* Write out the config info */
mail_config_write ();
mail_account_gui_destroy (gui);
w->gui = NULL;
w->account = NULL;
}
static void
wizard_cancel_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *gui)
{
mail_account_gui_destroy (gui->gui);
gui->gui = NULL;
}
static void
wizard_help_cb (EvolutionWizard *wizard,
int page_num,
MailConfigWizard *gui)
{
}
static void
wizard_free (MailConfigWizard *wizard)
{
if (wizard->gui)
mail_account_gui_destroy (wizard->gui);
if (wizard->account)
g_object_unref (wizard->account);
g_free (wizard);
}
BonoboObject *
evolution_mail_config_wizard_new (void)
{
EvolutionWizard *wizard;
MailConfigWizard *gui;
EAccount *account;
account = make_account ();
gui = g_new (MailConfigWizard, 1);
gui->gui = NULL;
gui->account = account;
gui->identity_copied = FALSE;
gui->last_source = NULL;
gui->page = MAIL_CONFIG_WIZARD_PAGE_NONE;
wizard = evolution_wizard_new (get_fn, 5, gui);
account_wizard = wizard;
g_object_set_data_full ((GObject *) account_wizard, "account-data", gui,
(GDestroyNotify) wizard_free);
gui->wizard = wizard;
g_signal_connect (wizard, "next", G_CALLBACK (wizard_next_cb), gui);
g_signal_connect (wizard, "prepare", G_CALLBACK (wizard_prepare_cb), gui);
g_signal_connect (wizard, "back", G_CALLBACK (wizard_back_cb), gui);
g_signal_connect (wizard, "finish", G_CALLBACK (wizard_finish_cb), gui);
g_signal_connect (wizard, "cancel", G_CALLBACK (wizard_cancel_cb), gui);
g_signal_connect (wizard, "help", G_CALLBACK (wizard_help_cb), gui);
return BONOBO_OBJECT (wizard);
}
|