aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell.c
blob: e69b04a0a35699a241399a1b3df7d4f16750aaa0 (plain) (blame)
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
/* -*- 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-activation/bonobo-activation.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;

    EUserCreatableItemsHandler *user_creatable_items_handler;
    EUriSchemaRegistry *uri_schema_registry;
    EComponentRegistry *component_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 void
impl_Shell_createNewWindow (PortableServer_Servant servant,
                const CORBA_char *component_id,
                CORBA_Environment *ev)
{
    BonoboObject *bonobo_object;
    EShell *shell;
    EShellWindow *shell_window;

    if (raise_exception_if_not_ready (servant, ev))
        return;

    bonobo_object = bonobo_object_from_servant (servant);
    shell = E_SHELL (bonobo_object);

    shell_window = e_shell_create_window (shell, component_id, NULL);
    if (shell_window == NULL) {
        CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
                     ex_GNOME_Evolution_Shell_ComponentNotFound, NULL);
        return;
    }
}

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, 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);
}


/* 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,
           const char *component_id,
           EShellWindow *template_window)
{
    EShellPrivate *priv;
    EShellWindow *window;

    priv = shell->priv;

    window = E_SHELL_WINDOW (e_shell_window_new (shell, component_id));

    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->user_creatable_items_handler != NULL) {
        g_object_unref (priv->user_creatable_items_handler);
        priv->user_creatable_items_handler = NULL;
    }

    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->createNewWindow = impl_Shell_createNewWindow;
    epv->handleURI       = impl_Shell_handleURI;
    epv->setLineStatus   = impl_Shell_setLineStatus;
}

static void
e_shell_init (EShell *shell)
{
    EShellPrivate *priv;

    priv = g_new0 (EShellPrivate, 1);
    priv->line_status                  = E_SHELL_LINE_STATUS_OFFLINE;
    priv->component_registry           = e_component_registry_new ();
    priv->user_creatable_items_handler = e_user_creatable_items_handler_new (priv->component_registry);

    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 ();
    
    if (splash)
        gtk_widget_destroy (splash);
    
    if (e_shell_startup_wizard_create () == FALSE) {
        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.
 * @component_id: Id or alias of the component to display in the 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,
               const char *component_id,
               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, component_id, 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_peek_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_peek_uri_schema_registry (EShell *shell)
{
    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    return shell->priv->uri_schema_registry;
}

/**
 * e_shell_peek_component_registry:
 * @shell: 
 * 
 * Get the component registry associated to @shell.
 * 
 * Return value: 
 **/
EComponentRegistry *
e_shell_peek_component_registry (EShell *shell)
{
    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    return shell->priv->component_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);
}


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
}


EUserCreatableItemsHandler *
e_shell_peek_user_creatable_items_handler (EShell *shell)
{
    g_return_val_if_fail (E_IS_SHELL (shell), NULL);

    return shell->priv->user_creatable_items_handler;
}


BONOBO_TYPE_FUNC_FULL (EShell, GNOME_Evolution_Shell, PARENT_TYPE, e_shell)