aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-shell-window.c
blob: 81d2b82f5fab31e231c158d5fca1fc59fb48f555 (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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell-window.c
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-shell-window-private.h"

#include "e-util/e-plugin-ui.h"
#include "e-util/e-util-private.h"
#include "e-util/gconf-bridge.h"
#include "widgets/misc/e-online-button.h"

#include "e-component-registry.h"
#include "e-shell-marshal.h"
#include "e-sidebar.h"
#include "es-menu.h"
#include "es-event.h"

#include <glib/gi18n.h>

#include <gconf/gconf-client.h>

#include <string.h>

static gpointer parent_class;

static void
shell_window_dispose (GObject *object)
{
    e_shell_window_private_dispose (E_SHELL_WINDOW (object));

    /* Chain up to parent's dispose() method. */
    G_OBJECT_CLASS (parent_class)->dispose (object);
}

static void
shell_window_finalize (GObject *object)
{
    e_shell_window_private_finalize (E_SHELL_WINDOW (object));

    /* Chain up to parent's finalize() method. */
    G_OBJECT_CLASS (parent_class)->finalize (object);
}

static void
shell_window_class_init (EShellWindowClass *class)
{
    GObjectClass *object_class;

    parent_class = g_type_class_peek_parent (class);
    g_type_class_add_private (class, sizeof (EShellWindowPrivate));

    object_class = G_OBJECT_CLASS (class);
    object_class->dispose = shell_window_dispose;
    object_class->finalize = shell_window_finalize;
}

static void
shell_window_init (EShellWindow *window)
{
    GtkUIManager *manager;

    window->priv = E_SHELL_WINDOW_GET_PRIVATE (window);

    e_shell_window_private_init (window);

    manager = e_shell_window_get_ui_manager (window);

    e_plugin_ui_register_manager (
        "org.gnome.evolution.shell", manager, window);
}

GType
e_shell_window_get_type (void)
{
    static GType type = 0;

    if (G_UNLIKELY (type == 0)) {
        const GTypeInfo type_info = {
            sizeof (EShellWindowClass),
            (GBaseInitFunc) NULL,
            (GBaseFinalizeFunc) NULL,
            (GClassInitFunc) shell_window_class_init,
            (GClassFinalizeFunc) NULL,
            NULL,  /* class_data */
            sizeof (EShellWindow),
            0,     /* n_preallocs */
            (GInstanceInitFunc) shell_window_init,
            NULL   /* value_table */
        };

        type = g_type_register_static (
            GTK_TYPE_WINDOW, "EShellWindow", &type_info, 0);
    }

    return type;
}

GtkWidget *
e_shell_window_new (void)
{
    return g_object_new (E_TYPE_SHELL_WINDOW, NULL);
}

GtkUIManager *
e_shell_window_get_ui_manager (EShellWindow *window)
{
    g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL);

    return window->priv->manager;
}

GtkAction *
e_shell_window_get_action (EShellWindow *window,
                           const gchar *action_name)
{
    GtkUIManager *manager;
    GtkAction *action = NULL;
    GList *iter;

    g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL);
    g_return_val_if_fail (action_name != NULL, NULL);

    manager = e_shell_window_get_ui_manager (window);
    iter = gtk_ui_manager_get_action_groups (manager);

    while (iter != NULL && action == NULL) {
        GtkActionGroup *action_group = iter->data;

        action = gtk_action_group_get_action (
            action_group, action_name);
        iter = g_list_next (iter);
    }

    g_return_val_if_fail (action != NULL, NULL);

    return action;
}

GtkActionGroup *
e_shell_window_get_action_group (EShellWindow *window,
                                 const gchar *group_name)
{
    GtkUIManager *manager;
    GList *iter;

    g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL);
    g_return_val_if_fail (group_name != NULL, NULL);

    manager = e_shell_window_get_ui_manager (window);
    iter = gtk_ui_manager_get_action_groups (manager);

    while (iter != NULL) {
        GtkActionGroup *action_group = iter->data;
        const gchar *name;

        name = gtk_action_group_get_name (action_group);
        if (strcmp (name, group_name) == 0)
            return action_group;

        iter = g_list_next (iter);
    }

    g_return_val_if_reached (NULL);
}

GtkWidget *
e_shell_window_get_managed_widget (EShellWindow *window,
                                   const gchar *widget_path)
{
    GtkUIManager *manager;
    GtkWidget *widget;

    g_return_val_if_fail (E_IS_SHELL_WINDOW (window), NULL);
    g_return_val_if_fail (widget_path != NULL, NULL);

    manager = e_shell_window_get_ui_manager (window);
    widget = gtk_ui_manager_get_widget (manager, widget_path);

    g_return_val_if_fail (widget != NULL, NULL);

    return widget;
}

#if 0
static void
init_view (EShellWindow *window,
       ComponentView *view)
{
    EShellWindowPrivate *priv = window->priv;
    EComponentRegistry *registry = e_shell_peek_component_registry (window->priv->shell);
    GNOME_Evolution_Component component_iface;
    GNOME_Evolution_ComponentView component_view;
    Bonobo_UIContainer container;
    Bonobo_Control sidebar_control;
    Bonobo_Control view_control;
    Bonobo_Control statusbar_control;
    CORBA_Environment ev;
    int sidebar_notebook_page_num;
    int content_notebook_page_num;

    g_return_if_fail (view->view_widget == NULL);
    g_return_if_fail (view->sidebar_widget == NULL);
    g_return_if_fail (view->notebook_page_num == -1);

    CORBA_exception_init (&ev);

    /* 1. Activate component.  (FIXME: Shouldn't do this here.)  */

    component_iface = e_component_registry_activate (registry, view->component_id, &ev);
    if (BONOBO_EX (&ev) || component_iface == CORBA_OBJECT_NIL) {
        char *ex_text = bonobo_exception_get_text (&ev);
        g_warning ("Cannot activate component  %s: %s", view->component_id, ex_text);
        g_free (ex_text);
        CORBA_exception_free (&ev);
        return;
    }

    /* 2. Set up view.  */

    /* The rest of the code assumes that the component is valid and can create
       controls; if this fails something is really wrong in the component
       (e.g. methods not implemented)...  So handle it as if there was no
       component at all.  */

    component_view = GNOME_Evolution_Component_createView(component_iface, BONOBO_OBJREF(priv->shell_view), &ev);
    if (component_view == NULL || BONOBO_EX (&ev)) {
        g_warning ("Cannot create view for %s", view->component_id);
        bonobo_object_release_unref (component_iface, NULL);
        CORBA_exception_free (&ev);
        return;
    }

    GNOME_Evolution_ComponentView_getControls(component_view, &sidebar_control, &view_control, &statusbar_control, &ev);
    if (BONOBO_EX (&ev)) {
        g_warning ("Cannot create view for %s", view->component_id);
        bonobo_object_release_unref (component_iface, NULL);
        CORBA_exception_free (&ev);
        return;
    }

    view->component_view = component_view;

    CORBA_exception_free (&ev);

    container = bonobo_ui_component_get_container (priv->ui_component);

    view->sidebar_widget = bonobo_widget_new_control_from_objref (sidebar_control, container);
    gtk_widget_show (view->sidebar_widget);
    bonobo_object_release_unref (sidebar_control, NULL);

    view->view_widget = bonobo_widget_new_control_from_objref (view_control, container);
    gtk_widget_show (view->view_widget);
    bonobo_object_release_unref (view_control, NULL);

    view->statusbar_widget = bonobo_widget_new_control_from_objref (statusbar_control, container);
    gtk_widget_show (view->statusbar_widget);
    bonobo_object_release_unref (statusbar_control, NULL);

    gtk_notebook_append_page (GTK_NOTEBOOK (priv->sidebar_notebook), view->sidebar_widget, NULL);
    gtk_notebook_append_page (GTK_NOTEBOOK (priv->content_notebook), view->view_widget, NULL);
    gtk_notebook_append_page (GTK_NOTEBOOK (priv->statusbar_notebook), view->statusbar_widget, NULL);

    sidebar_notebook_page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->sidebar_notebook), view->sidebar_widget);
    content_notebook_page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->content_notebook), view->view_widget);

    /* Since we always add a view page and a sidebar page at the same time...  */
    g_return_if_fail (sidebar_notebook_page_num == content_notebook_page_num);

    view->notebook_page_num = content_notebook_page_num;

    /* 3. Switch to the new page.  */

    gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content_notebook), content_notebook_page_num);
    gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->sidebar_notebook), content_notebook_page_num);
    gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->statusbar_notebook), content_notebook_page_num);

    priv->current_view = view;

    bonobo_object_release_unref (component_iface, NULL);
}

static void
switch_view (EShellWindow *window, ComponentView *component_view)
{
    EShellWindowPrivate *priv = window->priv;
    GConfClient *gconf_client = gconf_client_get_default ();
    EComponentRegistry *registry = e_shell_peek_component_registry (window->priv->shell);
    EComponentInfo *info = e_component_registry_peek_info (registry,
                                   ECR_FIELD_ID,
                                   component_view->component_id);
    char *title;

    if (component_view->sidebar_widget == NULL) {
        init_view (window, component_view);
    } else {
        priv->current_view = component_view;

        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->content_notebook), component_view->notebook_page_num);
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->sidebar_notebook), component_view->notebook_page_num);
        gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->statusbar_notebook), component_view->notebook_page_num);
    }

    if (component_view->title == NULL) {
        /* To translators: This is the window title and %s is the 
        component name. Most translators will want to keep it as is. */
        title = g_strdup_printf (_("%s - Evolution"), info->button_label);
        gtk_window_set_title (GTK_WINDOW (window), title);
        g_free (title);
    } else
        gtk_window_set_title (GTK_WINDOW (window), component_view->title);

    if (info->icon_name)
        gtk_window_set_icon_name (GTK_WINDOW (window), info->icon_name);

    gconf_client_set_string (gconf_client, "/apps/evolution/shell/view_defaults/component_id",
                 (component_view->component_alias != NULL
                  ? component_view->component_alias
                  : component_view->component_id),
                 NULL);

    g_object_unref (gconf_client);

    /** @Event: Shell component activated or switched to.
     * @Id: component.activated
     * @Target: ESEventTargetComponent
     * 
     * This event is emitted whenever the shell successfully activates component
     * view.
     */
    e_event_emit ((EEvent *) es_event_peek (), "component.activated", (EEventTarget *) es_event_target_new_component (es_event_peek (), component_view->component_id));

    g_object_notify (G_OBJECT (window), "current-view");
}
#endif


/* Functions to update the sensitivity of buttons and menu items depending on the status.  */

#if 0
static void
update_offline_toggle_status (EShellWindow *window)
{
    EShellWindowPrivate *priv;
    GtkWidget *widget;
    const gchar *tooltip;
    gboolean online;
    gboolean sensitive;
    guint32 flags = 0;

    priv = window->priv;

    switch (e_shell_get_line_status ()) {
    case E_SHELL_LINE_STATUS_ONLINE:
        online      = TRUE;
        sensitive   = TRUE;
        tooltip     = _("Evolution is currently online.\n"
                "Click on this button to work offline.");
        flags = ES_MENU_SHELL_ONLINE;
        break;
    case E_SHELL_LINE_STATUS_GOING_OFFLINE:
        online      = TRUE;
        sensitive   = FALSE;
        tooltip     = _("Evolution is in the process of going offline.");
        flags = ES_MENU_SHELL_OFFLINE;
        break;
    case E_SHELL_LINE_STATUS_OFFLINE:
    case E_SHELL_LINE_STATUS_FORCED_OFFLINE:
        online      = FALSE;
        sensitive   = TRUE;
        tooltip     = _("Evolution is currently offline.\n"
                "Click on this button to work online.");
        flags = ES_MENU_SHELL_OFFLINE;
        break;
    default:
        g_return_if_reached ();
    }

    widget = window->priv->online_button;
    gtk_widget_set_sensitive (widget, sensitive);
    gtk_widget_set_tooltip_text (widget, tooltip);
    e_online_button_set_online (E_ONLINE_BUTTON (widget), online);
}
#endif