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
|
/*
* e-startup-assistant.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include "e-startup-assistant.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <mail/e-mail-config-welcome-page.h>
#include "e-mail-config-import-page.h"
#include "e-mail-config-import-progress-page.h"
#define E_STARTUP_ASSISTANT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_STARTUP_ASSISTANT, EStartupAssistantPrivate))
struct _EStartupAssistantPrivate {
EActivity *import_activity;
EMailConfigImportPage *import_page;
EMailConfigImportProgressPage *progress_page;
};
G_DEFINE_DYNAMIC_TYPE (
EStartupAssistant,
e_startup_assistant,
E_TYPE_MAIL_CONFIG_ASSISTANT)
static void
startup_assistant_import_done (GObject *source_object,
GAsyncResult *result,
gpointer user_data)
{
EMailConfigImportPage *page;
EStartupAssistant *assistant;
EActivity *activity;
GError *error = NULL;
page = E_MAIL_CONFIG_IMPORT_PAGE (source_object);
assistant = E_STARTUP_ASSISTANT (user_data);
activity = assistant->priv->import_activity;
e_mail_config_import_page_import_finish (page, result, &error);
if (e_activity_handle_cancellation (activity, error)) {
g_error_free (error);
} else {
/* XXX The current EImport API does not allow importers to
* report errors. Once we have a better importing API
* we'll have to figure out how to show import errors,
* but for now just emit a runtime warning. */
if (error != NULL) {
g_warning ("%s: %s", G_STRFUNC, error->message);
g_error_free (error);
}
e_activity_set_percent (activity, 100.0);
e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
}
g_object_unref (assistant);
}
static void
startup_assistant_dispose (GObject *object)
{
EStartupAssistantPrivate *priv;
priv = E_STARTUP_ASSISTANT_GET_PRIVATE (object);
if (priv->import_activity != NULL) {
g_object_unref (priv->import_activity);
priv->import_activity = NULL;
}
if (priv->import_page != NULL) {
g_object_unref (priv->import_page);
priv->import_page = NULL;
}
if (priv->progress_page != NULL) {
g_object_unref (priv->progress_page);
priv->progress_page = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_startup_assistant_parent_class)->dispose (object);
}
static void
startup_assistant_constructed (GObject *object)
{
EStartupAssistant *assistant;
EMailConfigPage *page;
gint n_pages, ii;
assistant = E_STARTUP_ASSISTANT (object);
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_startup_assistant_parent_class)->constructed (object);
/* Note: We exclude this page if there is no application data
* to import, but we don't know that until we create it. */
page = e_mail_config_import_page_new ();
if (e_mail_config_import_page_get_n_importers (
E_MAIL_CONFIG_IMPORT_PAGE (page)) == 0) {
g_object_unref (g_object_ref_sink (page));
} else {
e_mail_config_assistant_add_page (
E_MAIL_CONFIG_ASSISTANT (assistant), page);
assistant->priv->import_page = g_object_ref (page);
/* Obviously we only need an import progress page if
* there's a chance we may be importing something. */
page = e_mail_config_import_progress_page_new (
assistant->priv->import_activity);
e_mail_config_assistant_add_page (
E_MAIL_CONFIG_ASSISTANT (assistant), page);
}
/* Additional tweaks. */
n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT (assistant));
for (ii = 0; ii < n_pages; ii++) {
GtkWidget *nth_page;
nth_page = gtk_assistant_get_nth_page (
GTK_ASSISTANT (assistant), ii);
if (!E_IS_MAIL_CONFIG_WELCOME_PAGE (nth_page))
continue;
gtk_assistant_set_page_title (
GTK_ASSISTANT (assistant), nth_page, _("Welcome"));
e_mail_config_welcome_page_set_text (
E_MAIL_CONFIG_WELCOME_PAGE (nth_page),
_("Welcome to Evolution.\n\nThe next few screens will "
"allow Evolution to connect to your email accounts, "
"and to import files from other applications."));
}
}
static void
startup_assistant_prepare (GtkAssistant *assistant,
GtkWidget *page)
{
EStartupAssistantPrivate *priv;
priv = E_STARTUP_ASSISTANT_GET_PRIVATE (assistant);
/* Chain up to parent's prepare() method. */
GTK_ASSISTANT_CLASS (e_startup_assistant_parent_class)->
prepare (assistant, page);
if (E_IS_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (page)) {
EActivity *activity;
activity = priv->import_activity;
e_activity_set_state (activity, E_ACTIVITY_RUNNING);
e_mail_config_import_page_import (
priv->import_page, activity,
startup_assistant_import_done,
g_object_ref (assistant));
}
}
static void
e_startup_assistant_class_init (EStartupAssistantClass *class)
{
GObjectClass *object_class;
GtkAssistantClass *assistant_class;
g_type_class_add_private (class, sizeof (EStartupAssistantPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->dispose = startup_assistant_dispose;
object_class->constructed = startup_assistant_constructed;
assistant_class = GTK_ASSISTANT_CLASS (class);
assistant_class->prepare = startup_assistant_prepare;
}
static void
e_startup_assistant_class_finalize (EStartupAssistantClass *class)
{
}
static void
e_startup_assistant_init (EStartupAssistant *assistant)
{
EActivity *activity;
GCancellable *cancellable;
assistant->priv = E_STARTUP_ASSISTANT_GET_PRIVATE (assistant);
cancellable = g_cancellable_new ();
activity = e_activity_new ();
e_activity_set_cancellable (activity, cancellable);
e_activity_set_state (activity, E_ACTIVITY_WAITING);
assistant->priv->import_activity = activity;
g_object_unref (cancellable);
}
void
e_startup_assistant_type_register (GTypeModule *type_module)
{
/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
* function, so we have to wrap it with a public function in
* order to register types from a separate compilation unit. */
e_startup_assistant_register_type (type_module);
}
GtkWidget *
e_startup_assistant_new (EMailSession *session)
{
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
return g_object_new (
E_TYPE_STARTUP_ASSISTANT,
"session", session, NULL);
}
|