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
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-shell.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.
*/
#include "e-shell.h"
#include <glib/gi18n.h>
#include <e-preferences-window.h>
#include "e-shell-module.h"
#include "e-shell-registry.h"
#define SHUTDOWN_TIMEOUT 500 /* milliseconds */
static GList *active_windows;
static gboolean
shell_window_delete_event_cb (EShellWindow *shell_window)
{
/* If other windows are open we can safely close this one. */
if (g_list_length (active_windows) > 1)
return FALSE;
/* Otherwise we initiate application shutdown. */
return !e_shell_quit ();
}
static void
shell_window_weak_notify_cb (gpointer unused,
GObject *where_the_object_was)
{
active_windows = g_list_remove (active_windows, where_the_object_was);
/* If that was the last window, we're done. */
if (active_windows == NULL)
gtk_main_quit ();
}
static gboolean
shell_shutdown_timeout (void)
{
GList *list, *iter;
gboolean proceed = TRUE;
static guint source_id = 0;
static guint message_timer = 1;
list = e_shell_registry_list_modules ();
/* Any module can defer shutdown if it's still busy. */
for (iter = list; proceed && iter != NULL; iter = iter->next) {
EShellModule *shell_module = iter->data;
proceed = e_shell_module_shutdown (shell_module);
/* Emit a message every few seconds to indicate
* which module(s) we're still waiting on. */
if (proceed || message_timer == 0)
continue;
g_message (
_("Waiting for the \"%s\" module to finish..."),
G_TYPE_MODULE (shell_module)->name);
}
message_timer = (message_timer + 1) % 10;
g_list_free (list);
/* If we're go for shutdown, destroy all shell windows. Note,
* we iterate over a /copy/ of the active windows list because
* the act of destroying a shell window will modify the active
* windows list, which would otherwise derail the iteration. */
if (proceed) {
list = g_list_copy (active_windows);
g_list_foreach (list, (GFunc) gtk_widget_destroy, NULL);
g_list_free (list);
/* If a module is still busy, try again after a short delay. */
} else if (source_id == 0)
source_id = g_timeout_add (
SHUTDOWN_TIMEOUT, (GSourceFunc)
shell_shutdown_timeout, NULL);
/* Return TRUE to repeat the timeout, FALSE to stop it. This
* may seem backwards if the function was called directly. */
return !proceed;
}
EShellWindow *
e_shell_create_window (void)
{
GtkWidget *shell_window;
shell_window = e_shell_window_new ();
active_windows = g_list_prepend (active_windows, shell_window);
g_signal_connect (
shell_window, "delete-event",
G_CALLBACK (shell_window_delete_event_cb), NULL);
g_object_weak_ref (
G_OBJECT (shell_window), (GWeakNotify)
shell_window_weak_notify_cb, NULL);
gtk_widget_show (shell_window);
return E_SHELL_WINDOW (shell_window);
}
gboolean
e_shell_handle_uri (const gchar *uri)
{
EShellModule *shell_module;
GFile *file;
gchar *scheme;
g_return_val_if_fail (uri != NULL, FALSE);
file = g_file_new_for_uri (uri);
scheme = g_file_get_uri_scheme (file);
g_object_unref (file);
if (scheme == NULL)
return FALSE;
shell_module = e_shell_registry_get_module_by_scheme (scheme);
/* Scheme lookup failed so try looking up the shell module by
* name. Note, we only open a shell window if the URI refers
* to a shell module by name, not by scheme. */
if (shell_module == NULL) {
EShellWindow *shell_window;
shell_module = e_shell_registry_get_module_by_name (scheme);
if (shell_module == NULL)
return FALSE;
shell_window = e_shell_create_window ();
/* FIXME Set window to appropriate view. */
}
return e_shell_module_handle_uri (shell_module, uri);
}
void
e_shell_send_receive (GtkWindow *parent)
{
/* FIXME */
}
void
e_shell_go_offline (void)
{
/* FIXME */
}
void
e_shell_go_online (void)
{
/* FIXME */
}
EShellLineStatus
e_shell_get_line_status (void)
{
/* FIXME */
return E_SHELL_LINE_STATUS_ONLINE;
}
GtkWidget *
e_shell_get_preferences_window (void)
{
static GtkWidget *preferences_window = NULL;
if (G_UNLIKELY (preferences_window == NULL))
preferences_window = e_preferences_window_new ();
return preferences_window;
}
gboolean
e_shell_is_busy (void)
{
/* FIXME */
return FALSE;
}
gboolean
e_shell_do_quit (void)
{
/* FIXME */
return TRUE;
}
gboolean
e_shell_quit (void)
{
/* FIXME */
return TRUE;
}
|