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
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell.c
*
* Copyright (C) 2000, 2001, 2002 Ximian, Inc.
*
* 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.
*
* Author: Ettore Perazzoli
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "e-shell.h"
#include "e-util/e-dialog-utils.h"
#include "e-setup.h"
#include "e-shell-constants.h"
#include "e-shell-settings-dialog.h"
#include "e-shell-startup-wizard.h"
#include "e-uri-schema-registry.h"
#include "e-shell-marshal.h"
#include "evolution-shell-component-client.h"
#include "evolution-shell-component-utils.h"
#include "importer/intelligent.h"
#include <glib.h>
#include <gtk/gtkmain.h>
#include <gtk/gtksignal.h>
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
/* (For the displayName stuff.) */
#include <gdk/gdkprivate.h>
#include <X11/Xlib.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-moniker-util.h>
#include <gal/util/e-util.h>
#include <gconf/gconf-client.h>
#include <string.h>
#include "Evolution.h"
#define PARENT_TYPE bonobo_object_get_type ()
static BonoboObjectClass *parent_class = NULL;
struct _EShellPrivate {
/* IID for registering the object on OAF. */
char *iid;
GList *windows;
EUriSchemaRegistry *uri_schema_registry;
/* Names for the types of the folders that have maybe crashed. */
/* FIXME TODO */
GList *crash_type_names; /* char * */
/* Line status. */
EShellLineStatus line_status;
/* Settings Dialog */
GtkWidget *settings_dialog;
/* Whether the shell is succesfully initialized. This is needed during
the start-up sequence, to avoid CORBA calls to do make wrong things
to happen while the shell is initializing. */
unsigned int is_initialized : 1;
/* Wether the shell is working in "interactive" mode or not.
(Currently, it's interactive IIF there is at least one active
view.) */
unsigned int is_interactive : 1;
/* Whether quit has been requested, and the shell is now waiting for
permissions from all the components to quit. */
unsigned int preparing_to_quit : 1;
};
/* Signals. */
enum {
NO_WINDOWS_LEFT,
LINE_STATUS_CHANGED,
NEW_WINDOW_CREATED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
/* Utility functions. */
static gboolean
get_config_start_offline (void)
{
GConfClient *client;
gboolean value;
client = gconf_client_get_default ();
value = gconf_client_get_bool (client, "/apps/evolution/shell/start_offline", NULL);
g_object_unref (client);
return value;
}
/* Interactivity handling. */
static void
set_interactive (EShell *shell,
gboolean interactive)
{
/* FIXME TODO */
}
/* CORBA interface implementation. */
static gboolean
raise_exception_if_not_ready (PortableServer_Servant servant,
CORBA_Environment *ev)
{
EShell *shell;
shell = E_SHELL (bonobo_object_from_servant (servant));
if (! shell->priv->is_initialized) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_NotReady, NULL);
return TRUE;
}
return FALSE;
}
static GNOME_Evolution_ShellView
impl_Shell_createNewView (PortableServer_Servant servant,
const CORBA_char *uri,
CORBA_Environment *ev)
{
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_InternalError, NULL);
return CORBA_OBJECT_NIL;
#if 0 /* FIXME */
BonoboObject *bonobo_object;
EShell *shell;
EShellWindow *shell_window;
GNOME_Evolution_ShellView shell_view_interface;
if (raise_exception_if_not_ready (servant, ev))
return CORBA_OBJECT_NIL;
bonobo_object = bonobo_object_from_servant (servant);
shell = E_SHELL (bonobo_object);
if (strncmp (uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) != 0) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_UnsupportedSchema,
NULL);
return CORBA_OBJECT_NIL;
}
shell_window = e_shell_create_window (shell, uri, NULL);
if (shell_window == NULL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_NotFound, NULL);
return CORBA_OBJECT_NIL;
}
shell_window_interface = e_shell_window_get_corba_interface (shell_window);
if (shell_window_interface == CORBA_OBJECT_NIL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_InternalError, NULL);
return CORBA_OBJECT_NIL;
}
Bonobo_Unknown_ref (shell_window_interface, ev);
return CORBA_Object_duplicate ((CORBA_Object) shell_window_interface, ev);
#endif
}
static void
impl_Shell_handleURI (PortableServer_Servant servant,
const CORBA_char *uri,
CORBA_Environment *ev)
{
EvolutionShellComponentClient *schema_handler;
EShell *shell;
EShellPrivate *priv;
const char *colon_p;
char *schema;
if (raise_exception_if_not_ready (servant, ev))
return;
shell = E_SHELL (bonobo_object_from_servant (servant));
priv = shell->priv;
if (strncmp (uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) == 0
|| strncmp (uri, E_SHELL_DEFAULTURI_PREFIX, E_SHELL_DEFAULTURI_PREFIX_LEN) == 0) {
e_shell_create_window (shell, NULL);
return;
}
/* Extract the schema. */
colon_p = strchr (uri, ':');
if (colon_p == NULL || colon_p == uri) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_InvalidURI, NULL);
return;
}
schema = g_strndup (uri, colon_p - uri);
schema_handler = e_uri_schema_registry_get_handler_for_schema (priv->uri_schema_registry, schema);
g_free (schema);
if (schema_handler == NULL) {
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_UnsupportedSchema, NULL);
return;
}
if (evolution_shell_component_client_handle_external_uri (schema_handler, uri)
!= EVOLUTION_SHELL_COMPONENT_OK) {
/* FIXME: Just a wild guess here. */
CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
ex_GNOME_Evolution_Shell_NotFound, NULL);
return;
}
}
static void
impl_Shell_setLineStatus (PortableServer_Servant servant,
CORBA_boolean online,
CORBA_Environment *ev)
{
BonoboObject *bonobo_object;
EShell *shell;
if (raise_exception_if_not_ready (servant, ev))
return;
bonobo_object = bonobo_object_from_servant (servant);
shell = E_SHELL (bonobo_object);
if (online)
e_shell_go_online (shell, NULL);
else
e_shell_go_offline (shell, NULL);
}
/* Initialization of the components. */
static void
setup_components (EShell *shell)
{
EShellPrivate *priv;
char *const selection_order[] = { "0-evolution:shell_component_launch_order", NULL };
Bonobo_ServerInfoList *info_list;
CORBA_Environment ev;
int i;
CORBA_exception_init (&ev);
priv = shell->priv;
#if 0 /* FIXME */
info_list = bonobo_activation_query ("repo_ids.has ('IDL:GNOME/Evolution/ShellComponent:1.0')", selection_order, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_error ("Eeek! Cannot perform OAF query for Evolution components.");
if (info_list->_length == 0)
g_warning ("No Evolution components installed.");
for (i = 0; i < info_list->_length; i++) {
const Bonobo_ServerInfo *info;
GdkPixbuf *icon_pixbuf;
char *icon_path;
info = info_list->_buffer + i;
icon_path = get_icon_path_for_component_info (info);
icon_pixbuf = gdk_pixbuf_new_from_file (icon_path, NULL);
if (splash != NULL)
e_splash_add_icon (splash, icon_pixbuf);
g_object_unref (icon_pixbuf);
g_free (icon_path);
}
while (gtk_events_pending ())
gtk_main_iteration ();
for (i = 0; i < info_list->_length; i++) {
const Bonobo_ServerInfo *info;
CORBA_Environment ev;
info = info_list->_buffer + i;
CORBA_exception_init (&ev);
if (! e_component_registry_register_component (priv->component_registry, info->iid, &ev))
pop_up_activation_error_dialog (splash, info->iid, &ev);
CORBA_exception_free (&ev);
if (splash != NULL)
e_splash_set_icon_highlight (splash, i, TRUE);
while (gtk_events_pending ())
gtk_main_iteration ();
}
CORBA_free (info_list);
#endif
CORBA_exception_free (&ev);
}
/* EShellWindow handling and bookkeeping. */
static int
window_delete_event_cb (GtkWidget *widget,
GdkEventAny *ev,
void *data)
{
EShell *shell;
g_assert (E_IS_SHELL_WINDOW (widget));
shell = E_SHELL (data);
return ! e_shell_request_close_window (shell, E_SHELL_WINDOW (widget));
}
static gboolean
notify_no_windows_left_idle_cb (void *data)
{
EShell *shell;
shell = E_SHELL (data);
set_interactive (shell, FALSE);
g_signal_emit (shell, signals [NO_WINDOWS_LEFT], 0);
bonobo_object_unref (BONOBO_OBJECT (shell));
return FALSE;
}
static void
window_weak_notify (void *data,
GObject *where_the_object_was)
{
EShell *shell;
int num_windows;
shell = E_SHELL (data);
num_windows = g_list_length (shell->priv->windows);
/* If this is our last window, save settings now because in the callback
for no_windows_left shell->priv->windows will be NULL and settings won't
be saved because of that. */
if (num_windows == 1)
e_shell_save_settings (shell);
shell->priv->windows = g_list_remove (shell->priv->windows, where_the_object_was);
if (shell->priv->windows == NULL) {
bonobo_object_ref (BONOBO_OBJECT (shell));
g_idle_add (notify_no_windows_left_idle_cb, shell);
}
}
static EShellWindow *
create_window (EShell *shell,
EShellWindow *template_window)
{
EShellPrivate *priv;
EShellWindow *window;
priv = shell->priv;
window = E_SHELL_WINDOW (e_shell_window_new (shell));
g_signal_connect (window, "delete_event", G_CALLBACK (window_delete_event_cb), shell);
g_object_weak_ref (G_OBJECT (window), window_weak_notify, shell);
shell->priv->windows = g_list_prepend (shell->priv->windows, window);
g_signal_emit (shell, signals[NEW_WINDOW_CREATED], 0, window);
return window;
}
/* GObject methods. */
static void
impl_dispose (GObject *object)
{
EShell *shell;
EShellPrivate *priv;
GList *p;
shell = E_SHELL (object);
priv = shell->priv;
priv->is_initialized = FALSE;
if (priv->uri_schema_registry != NULL) {
g_object_unref (priv->uri_schema_registry);
priv->uri_schema_registry = NULL;
}
for (p = priv->windows; p != NULL; p = p->next) {
EShellWindow *window;
window = E_SHELL_WINDOW (p->data);
g_signal_handlers_disconnect_by_func (window, G_CALLBACK (window_delete_event_cb), shell);
g_object_weak_unref (G_OBJECT (window), window_weak_notify, shell);
gtk_object_destroy (GTK_OBJECT (window));
}
g_list_free (priv->windows);
priv->windows = NULL;
/* No unreffing for these as they are aggregate. */
/* bonobo_object_unref (BONOBO_OBJECT (priv->corba_storage_registry)); */
if (priv->settings_dialog != NULL) {
gtk_widget_destroy (priv->settings_dialog);
priv->settings_dialog = NULL;
}
(* G_OBJECT_CLASS (parent_class)->dispose) (object);
}
static void
impl_finalize (GObject *object)
{
EShell *shell;
EShellPrivate *priv;
shell = E_SHELL (object);
priv = shell->priv;
if (priv->iid != NULL)
bonobo_activation_active_server_unregister (priv->iid,
bonobo_object_corba_objref (BONOBO_OBJECT (shell)));
e_free_string_list (priv->crash_type_names);
g_free (priv);
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
/* Initialization. */
static void
e_shell_class_init (EShellClass *klass)
{
GObjectClass *object_class;
POA_GNOME_Evolution_Shell__epv *epv;
parent_class = g_type_class_ref(PARENT_TYPE);
object_class = G_OBJECT_CLASS (klass);
object_class->dispose = impl_dispose;
object_class->finalize = impl_finalize;
signals[NO_WINDOWS_LEFT] =
g_signal_new ("no_windows_left",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EShellClass, no_windows_left),
NULL, NULL,
e_shell_marshal_NONE__NONE,
G_TYPE_NONE, 0);
signals[LINE_STATUS_CHANGED] =
g_signal_new ("line_status_changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EShellClass, line_status_changed),
NULL, NULL,
e_shell_marshal_NONE__INT,
G_TYPE_NONE, 1,
G_TYPE_INT);
signals[NEW_WINDOW_CREATED] =
g_signal_new ("new_window_created",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (EShellClass, new_window_created),
NULL, NULL,
e_shell_marshal_NONE__POINTER,
G_TYPE_NONE, 1,
G_TYPE_POINTER);
epv = & klass->epv;
epv->createNewView = impl_Shell_createNewView;
epv->handleURI = impl_Shell_handleURI;
epv->setLineStatus = impl_Shell_setLineStatus;
}
static void
e_shell_init (EShell *shell)
{
EShellPrivate *priv;
priv = g_new (EShellPrivate, 1);
priv->windows = NULL;
priv->iid = NULL;
priv->uri_schema_registry = NULL;
priv->crash_type_names = NULL;
priv->line_status = E_SHELL_LINE_STATUS_OFFLINE;
priv->settings_dialog = NULL;
priv->is_initialized = FALSE;
priv->is_interactive = FALSE;
priv->preparing_to_quit = FALSE;
shell->priv = priv;
}
/**
* e_shell_construct:
* @shell: An EShell object to construct
* @iid: OAFIID for registering the shell into the name server
* @startup_line_mode: How to set up the line mode (online or offline) initally.
*
* Construct @shell so that it uses the specified @corba_object.
*
* Return value: The result of the operation.
**/
EShellConstructResult
e_shell_construct (EShell *shell,
const char *iid,
EShellStartupLineMode startup_line_mode)
{
GtkWidget *splash = NULL;
EShellPrivate *priv;
CORBA_Object corba_object;
gboolean start_online;
g_return_val_if_fail (shell != NULL, E_SHELL_CONSTRUCT_RESULT_INVALIDARG);
g_return_val_if_fail (E_IS_SHELL (shell), E_SHELL_CONSTRUCT_RESULT_INVALIDARG);
g_return_val_if_fail (startup_line_mode == E_SHELL_STARTUP_LINE_MODE_CONFIG
|| startup_line_mode == E_SHELL_STARTUP_LINE_MODE_ONLINE
|| startup_line_mode == E_SHELL_STARTUP_LINE_MODE_OFFLINE,
E_SHELL_CONSTRUCT_RESULT_INVALIDARG);
priv = shell->priv;
priv->iid = g_strdup (iid);
/* Now we can register into OAF. Notice that we shouldn't be
registering into OAF until we are sure we can complete. */
/* FIXME: Multi-display stuff. */
corba_object = bonobo_object_corba_objref (BONOBO_OBJECT (shell));
if (bonobo_activation_active_server_register (iid, corba_object) != Bonobo_ACTIVATION_REG_SUCCESS)
return E_SHELL_CONSTRUCT_RESULT_CANNOTREGISTER;
while (gtk_events_pending ())
gtk_main_iteration ();
setup_components (shell);
if (splash)
gtk_widget_destroy (splash);
if (e_shell_startup_wizard_create () == FALSE) {
e_shell_unregister_all (shell);
bonobo_object_unref (BONOBO_OBJECT (shell));
exit (0);
}
priv->is_initialized = TRUE;
switch (startup_line_mode) {
case E_SHELL_STARTUP_LINE_MODE_CONFIG:
start_online = ! get_config_start_offline ();
break;
case E_SHELL_STARTUP_LINE_MODE_ONLINE:
start_online = TRUE;
break;
case E_SHELL_STARTUP_LINE_MODE_OFFLINE:
start_online = FALSE;
break;
default:
start_online = FALSE; /* Make compiler happy. */
g_assert_not_reached ();
}
if (start_online)
e_shell_go_online (shell, NULL);
return E_SHELL_CONSTRUCT_RESULT_OK;
}
/**
* e_shell_new:
* @start_online: Whether to start in on-line mode or not.
* @construct_result_return: A pointer to an EShellConstructResult variable into
* which the result of the operation will be stored.
*
* Create a new EShell.
*
* Return value:
**/
EShell *
e_shell_new (EShellStartupLineMode startup_line_mode,
EShellConstructResult *construct_result_return)
{
EShell *new;
EShellPrivate *priv;
EShellConstructResult construct_result;
new = g_object_new (e_shell_get_type (), NULL);
construct_result = e_shell_construct (new, E_SHELL_OAFIID, startup_line_mode);
if (construct_result != E_SHELL_CONSTRUCT_RESULT_OK) {
*construct_result_return = construct_result;
bonobo_object_unref (BONOBO_OBJECT (new));
return NULL;
}
priv = new->priv;
*construct_result_return = E_SHELL_CONSTRUCT_RESULT_OK;
return new;
}
/**
* e_shell_create_window:
* @shell: The shell for which to create a new window.
* @template_window: Window from which to copy the window settings (can be %NULL).
*
* Create a new window for @uri.
*
* Return value: The new window.
**/
EShellWindow *
e_shell_create_window (EShell *shell,
EShellWindow *template_window)
{
EShellWindow *window;
EShellPrivate *priv;
/* FIXME need to actually copy settings from template_window. */
g_return_val_if_fail (shell != NULL, NULL);
g_return_val_if_fail (E_IS_SHELL (shell), NULL);
priv = shell->priv;
window = create_window (shell, template_window);
gtk_widget_show (GTK_WIDGET (window));
set_interactive (shell, TRUE);
return window;
}
gboolean
e_shell_request_close_window (EShell *shell,
EShellWindow *shell_window)
{
g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), FALSE);
e_shell_save_settings (shell);
if (g_list_length (shell->priv->windows) != 1) {
/* Not the last window. */
return TRUE;
}
if (shell->priv->preparing_to_quit)
return FALSE;
/* If it's the last window, save settings and ask for confirmation before
quitting. */
e_shell_window_save_defaults (shell_window);
if (e_shell_prepare_for_quit (shell))
return TRUE;
else
return FALSE;
}
/**
* e_shell_get_uri_schema_registry:
* @shell: An EShell object.
*
* Get the schema registry associated to @shell.
*
* Return value: A pointer to the EUriSchemaRegistry associated to @shell.
**/
EUriSchemaRegistry *
e_shell_get_uri_schema_registry (EShell *shell)
{
g_return_val_if_fail (shell != NULL, NULL);
g_return_val_if_fail (E_IS_SHELL (shell), NULL);
return shell->priv->uri_schema_registry;
}
/**
* e_shell_save_settings:
* @shell:
*
* Save the settings for this shell.
*
* Return value: %TRUE if it worked, %FALSE otherwise. Even if %FALSE is
* returned, it is possible that at least part of the settings for the windows
* have been saved.
**/
gboolean
e_shell_save_settings (EShell *shell)
{
GConfClient *client;
EShellPrivate *priv;
gboolean is_offline;
priv = shell->priv;
is_offline = ( e_shell_get_line_status (shell) == E_SHELL_LINE_STATUS_OFFLINE );
client = gconf_client_get_default ();
gconf_client_set_bool (client, "/apps/evolution/shell/start_offline", is_offline, NULL);
g_object_unref (client);
return TRUE;
}
/**
* e_shell_close_all_windows:
* @shell:
*
* Destroy all the windows in @shell.
**/
void
e_shell_close_all_windows (EShell *shell)
{
EShellPrivate *priv;
GList *p, *pnext;
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
if (shell->priv->windows)
e_shell_save_settings (shell);
priv = shell->priv;
for (p = priv->windows; p != NULL; p = pnext) {
pnext = p->next;
/* Note that this will also remove the window from the list... Hence the
need for the pnext variable. */
gtk_widget_destroy (GTK_WIDGET (p->data));
}
}
/**
* e_shell_get_line_status:
* @shell: A pointer to an EShell object.
*
* Get the line status for @shell.
*
* Return value: The current line status for @shell.
**/
EShellLineStatus
e_shell_get_line_status (EShell *shell)
{
g_return_val_if_fail (shell != NULL, E_SHELL_LINE_STATUS_OFFLINE);
g_return_val_if_fail (E_IS_SHELL (shell), E_SHELL_LINE_STATUS_OFFLINE);
return shell->priv->line_status;
}
/**
* e_shell_go_offline:
* @shell:
* @action_window:
*
* Make the shell go into off-line mode.
**/
void
e_shell_go_offline (EShell *shell,
EShellWindow *action_window)
{
EShellPrivate *priv;
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
g_return_if_fail (action_window != NULL);
g_return_if_fail (action_window == NULL || E_IS_SHELL_WINDOW (action_window));
priv = shell->priv;
if (priv->line_status != E_SHELL_LINE_STATUS_ONLINE)
return;
#if 0
priv->offline_handler = e_shell_offline_handler_new (shell);
/* FIXME TODO */
g_signal_connect (priv->offline_handler, "offline_procedure_started",
G_CALLBACK (offline_procedure_started_cb), shell);
g_signal_connect (priv->offline_handler, "offline_procedure_finished",
G_CALLBACK (offline_procedure_finished_cb), shell);
e_shell_offline_handler_put_components_offline (priv->offline_handler, GTK_WINDOW (action_window));
#endif
}
/**
* e_shell_go_online:
* @shell:
* @action_window:
*
* Make the shell go into on-line mode.
**/
void
e_shell_go_online (EShell *shell,
EShellWindow *action_window)
{
#if 0 /* FIXME TODO */
EShellPrivate *priv;
GList *component_ids;
GList *p;
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
g_return_if_fail (action_window == NULL || E_IS_SHELL_WINDOW (action_window));
priv = shell->priv;
component_ids = e_component_registry_get_id_list (priv->component_registry);
for (p = component_ids; p != NULL; p = p->next) {
CORBA_Environment ev;
EvolutionShellComponentClient *client;
GNOME_Evolution_Offline offline_interface;
const char *id;
id = (const char *) p->data;
client = e_component_registry_get_component_by_id (priv->component_registry, id);
CORBA_exception_init (&ev);
offline_interface = evolution_shell_component_client_get_offline_interface (client);
if (CORBA_Object_is_nil (offline_interface, &ev) || ev._major != CORBA_NO_EXCEPTION) {
CORBA_exception_free (&ev);
continue;
}
GNOME_Evolution_Offline_goOnline (offline_interface, &ev);
if (ev._major != CORBA_NO_EXCEPTION)
g_warning ("Error putting component `%s' online.", id);
CORBA_exception_free (&ev);
}
e_free_string_list (component_ids);
priv->line_status = E_SHELL_LINE_STATUS_ONLINE;
g_signal_emit (shell, signals[LINE_STATUS_CHANGED], 0, priv->line_status);
#endif
}
void
e_shell_show_settings (EShell *shell,
const char *type,
EShellWindow *shell_window)
{
EShellPrivate *priv;
g_return_if_fail (shell != NULL);
g_return_if_fail (E_IS_SHELL (shell));
priv = shell->priv;
if (priv->settings_dialog != NULL) {
gdk_window_show (priv->settings_dialog->window);
gtk_widget_grab_focus (priv->settings_dialog);
return;
}
priv->settings_dialog = e_shell_settings_dialog_new ();
if (type != NULL)
e_shell_settings_dialog_show_type (E_SHELL_SETTINGS_DIALOG (priv->settings_dialog), type);
g_object_add_weak_pointer (G_OBJECT (priv->settings_dialog), (void **) & priv->settings_dialog);
gtk_widget_show (priv->settings_dialog);
}
EShellUserCreatableItemsHandler *
e_shell_get_user_creatable_items_handler (EShell *shell)
{
g_assert_not_reached (); /* FIXME */
return NULL;
}
/* FIXME: These are ugly hacks, they really should not be needed. */
void
e_shell_unregister_all (EShell *shell)
{
EShellPrivate *priv;
g_return_if_fail (E_IS_SHELL (shell));
/* FIXME: This really really sucks. */
priv = shell->priv;
priv->is_initialized = FALSE;
}
const char *
e_shell_construct_result_to_string (EShellConstructResult result)
{
switch (result) {
case E_SHELL_CONSTRUCT_RESULT_OK:
return _("OK");
case E_SHELL_CONSTRUCT_RESULT_INVALIDARG:
return _("Invalid arguments");
case E_SHELL_CONSTRUCT_RESULT_CANNOTREGISTER:
return _("Cannot register on OAF");
case E_SHELL_CONSTRUCT_RESULT_NOCONFIGDB:
return _("Configuration Database not found");
case E_SHELL_CONSTRUCT_RESULT_GENERICERROR:
return _("Generic error");
default:
return _("Unknown error");
}
}
gboolean
e_shell_prepare_for_quit (EShell *shell)
{
/* FIXME TODO */
return TRUE;
#if 0
EShellPrivate *priv;
GList *component_ids;
GList *p;
gboolean retval;
g_return_val_if_fail (E_IS_SHELL (shell), FALSE);
priv = shell->priv;
priv->preparing_to_quit = TRUE;
/* Make all the windows insensitive so we have some modal-like
behavior. */
for (p = priv->windows; p != NULL; p = p->next)
gtk_widget_set_sensitive (GTK_WIDGET (p->data), FALSE);
component_ids = e_component_registry_get_id_list (priv->component_registry);
for (p = component_ids; p != NULL; p = p->next) {
EvolutionShellComponentClient *client;
const char *id;
GNOME_Evolution_ShellComponentListener_Result result;
id = (const char *) p->data;
client = e_component_registry_get_component_by_id (priv->component_registry, id);
result = (GNOME_Evolution_ShellComponentListener_Result) -1;
evolution_shell_component_client_request_quit (client, prepare_for_quit_callback, &result);
while (result == (GNOME_Evolution_ShellComponentListener_Result) -1)
gtk_main_iteration ();
if (result == GNOME_Evolution_ShellComponentListener_CANCEL) {
retval = FALSE;
goto end;
}
}
retval = TRUE;
end:
/* Restore all the windows to be sensitive. */
for (p = priv->windows; p != NULL; p = p->next)
gtk_widget_set_sensitive (GTK_WIDGET (p->data), TRUE);
priv->preparing_to_quit = FALSE;
e_free_string_list (component_ids);
return retval;
#endif
}
/* URI parsing. */
static gboolean
parse_default_uri (EShell *shell,
const char *uri,
char **path_return,
char **extra_return)
{
GConfClient *client;
const char *component_start;
char *component;
const char *p;
char *config_path;
char *path;
component_start = uri + E_SHELL_DEFAULTURI_PREFIX_LEN;
p = strchr (uri, '#');
if (p == NULL)
component = g_strdup (component_start);
else
component = g_strndup (component_start, p - component_start);
if (strchr (component, '/') != NULL) {
g_free (component);
return FALSE;
}
client = gconf_client_get_default ();
config_path = g_strdup_printf ("/apps/evolution/shell/default_folders/%s_path", component);
path = gconf_client_get_string (client, config_path, NULL);
g_object_unref (client);
g_free (component);
g_free (config_path);
/* We expect an evolution: URI here, if we don't get it then something
is messed up. */
if (path == NULL || strncmp (path, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) != 0) {
g_free (path);
if (path_return != NULL)
*path_return = NULL;
if (extra_return != NULL)
*extra_return = NULL;
return FALSE;
}
if (path_return != NULL)
*path_return = g_strdup (path + E_SHELL_URI_PREFIX_LEN);
if (extra_return != NULL) {
if (p == NULL)
*extra_return = NULL;
else
*extra_return = g_strdup (p + 1);
}
g_free (path);
return TRUE;
}
static gboolean
parse_evolution_uri (EShell *shell,
const char *uri,
char **path_return,
char **extra_return)
{
const char *path_start;
const char *p;
path_start = uri + E_SHELL_URI_PREFIX_LEN;
p = strchr (path_start, '#');
if (p != NULL && path_return != NULL)
*path_return = g_strndup (path_start, p - path_start);
else
*path_return = g_strdup (path_start);
if (extra_return != NULL) {
if (p == NULL)
*extra_return = NULL;
else
*extra_return = g_strdup (p + 1);
}
return TRUE;
}
gboolean
e_shell_parse_uri (EShell *shell,
const char *uri,
char **path_return,
char **extra_return)
{
g_return_val_if_fail (uri != NULL, FALSE);
if (strncmp (uri, E_SHELL_DEFAULTURI_PREFIX, E_SHELL_DEFAULTURI_PREFIX_LEN) == 0)
return parse_default_uri (shell, uri, path_return, extra_return);
if (strncmp (uri, E_SHELL_URI_PREFIX, E_SHELL_URI_PREFIX_LEN) == 0)
return parse_evolution_uri (shell, uri, path_return, extra_return);
*path_return = NULL;
if (extra_return != NULL)
*extra_return = NULL;
return FALSE;
}
BONOBO_TYPE_FUNC_FULL (EShell, GNOME_Evolution_Shell, PARENT_TYPE, e_shell)
|