No issues found
1 /*
2 * e-startup-assistant.c
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) version 3.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with the program; if not, see <http://www.gnu.org/licenses/>
16 *
17 */
18
19 #include "e-startup-assistant.h"
20
21 #include <config.h>
22 #include <glib/gi18n-lib.h>
23
24 #include <mail/e-mail-config-welcome-page.h>
25
26 #include "e-mail-config-import-page.h"
27 #include "e-mail-config-import-progress-page.h"
28
29 #define E_STARTUP_ASSISTANT_GET_PRIVATE(obj) \
30 (G_TYPE_INSTANCE_GET_PRIVATE \
31 ((obj), E_TYPE_STARTUP_ASSISTANT, EStartupAssistantPrivate))
32
33 struct _EStartupAssistantPrivate {
34 EActivity *import_activity;
35 EMailConfigImportPage *import_page;
36 EMailConfigImportProgressPage *progress_page;
37 };
38
39 G_DEFINE_DYNAMIC_TYPE (
40 EStartupAssistant,
41 e_startup_assistant,
42 E_TYPE_MAIL_CONFIG_ASSISTANT)
43
44 static void
45 startup_assistant_import_done (GObject *source_object,
46 GAsyncResult *result,
47 gpointer user_data)
48 {
49 EMailConfigImportPage *page;
50 EStartupAssistant *assistant;
51 EActivity *activity;
52 GError *error = NULL;
53
54 page = E_MAIL_CONFIG_IMPORT_PAGE (source_object);
55 assistant = E_STARTUP_ASSISTANT (user_data);
56 activity = assistant->priv->import_activity;
57
58 e_mail_config_import_page_import_finish (page, result, &error);
59
60 if (e_activity_handle_cancellation (activity, error)) {
61 g_error_free (error);
62
63 } else {
64 /* XXX The current EImport API does not allow importers to
65 * report errors. Once we have a better importing API
66 * we'll have to figure out how to show import errors,
67 * but for now just emit a runtime warning. */
68 if (error != NULL) {
69 g_warning ("%s: %s", G_STRFUNC, error->message);
70 g_error_free (error);
71 }
72
73 e_activity_set_percent (activity, 100.0);
74 e_activity_set_state (activity, E_ACTIVITY_COMPLETED);
75 }
76
77 g_object_unref (assistant);
78 }
79
80 static void
81 startup_assistant_dispose (GObject *object)
82 {
83 EStartupAssistantPrivate *priv;
84
85 priv = E_STARTUP_ASSISTANT_GET_PRIVATE (object);
86
87 if (priv->import_activity != NULL) {
88 g_object_unref (priv->import_activity);
89 priv->import_activity = NULL;
90 }
91
92 if (priv->import_page != NULL) {
93 g_object_unref (priv->import_page);
94 priv->import_page = NULL;
95 }
96
97 if (priv->progress_page != NULL) {
98 g_object_unref (priv->progress_page);
99 priv->progress_page = NULL;
100 }
101
102 /* Chain up to parent's dispose() method. */
103 G_OBJECT_CLASS (e_startup_assistant_parent_class)->dispose (object);
104 }
105
106 static void
107 startup_assistant_constructed (GObject *object)
108 {
109 EStartupAssistant *assistant;
110 EMailConfigPage *page;
111 gint n_pages, ii;
112
113 assistant = E_STARTUP_ASSISTANT (object);
114
115 /* Chain up to parent's constructed() method. */
116 G_OBJECT_CLASS (e_startup_assistant_parent_class)->constructed (object);
117
118 /* Note: We exclude this page if there is no application data
119 * to import, but we don't know that until we create it. */
120 page = e_mail_config_import_page_new ();
121 if (e_mail_config_import_page_get_n_importers (
122 E_MAIL_CONFIG_IMPORT_PAGE (page)) == 0) {
123 g_object_unref (g_object_ref_sink (page));
124 } else {
125 e_mail_config_assistant_add_page (
126 E_MAIL_CONFIG_ASSISTANT (assistant), page);
127 assistant->priv->import_page = g_object_ref (page);
128
129 /* Obviously we only need an import progress page if
130 * there's a chance we may be importing something. */
131 page = e_mail_config_import_progress_page_new (
132 assistant->priv->import_activity);
133 e_mail_config_assistant_add_page (
134 E_MAIL_CONFIG_ASSISTANT (assistant), page);
135 }
136
137 /* Additional tweaks. */
138
139 n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT (assistant));
140 for (ii = 0; ii < n_pages; ii++) {
141 GtkWidget *nth_page;
142
143 nth_page = gtk_assistant_get_nth_page (
144 GTK_ASSISTANT (assistant), ii);
145
146 if (!E_IS_MAIL_CONFIG_WELCOME_PAGE (nth_page))
147 continue;
148
149 gtk_assistant_set_page_title (
150 GTK_ASSISTANT (assistant), nth_page, _("Welcome"));
151
152 e_mail_config_welcome_page_set_text (
153 E_MAIL_CONFIG_WELCOME_PAGE (nth_page),
154 _("Welcome to Evolution.\n\nThe next few screens will "
155 "allow Evolution to connect to your email accounts, "
156 "and to import files from other applications."));
157 }
158 }
159
160 static void
161 startup_assistant_prepare (GtkAssistant *assistant,
162 GtkWidget *page)
163 {
164 EStartupAssistantPrivate *priv;
165
166 priv = E_STARTUP_ASSISTANT_GET_PRIVATE (assistant);
167
168 /* Chain up to parent's prepare() method. */
169 GTK_ASSISTANT_CLASS (e_startup_assistant_parent_class)->
170 prepare (assistant, page);
171
172 if (E_IS_MAIL_CONFIG_IMPORT_PROGRESS_PAGE (page)) {
173 EActivity *activity;
174
175 activity = priv->import_activity;
176 e_activity_set_state (activity, E_ACTIVITY_RUNNING);
177
178 e_mail_config_import_page_import (
179 priv->import_page, activity,
180 startup_assistant_import_done,
181 g_object_ref (assistant));
182 }
183 }
184
185 static void
186 e_startup_assistant_class_init (EStartupAssistantClass *class)
187 {
188 GObjectClass *object_class;
189 GtkAssistantClass *assistant_class;
190
191 g_type_class_add_private (class, sizeof (EStartupAssistantPrivate));
192
193 object_class = G_OBJECT_CLASS (class);
194 object_class->dispose = startup_assistant_dispose;
195 object_class->constructed = startup_assistant_constructed;
196
197 assistant_class = GTK_ASSISTANT_CLASS (class);
198 assistant_class->prepare = startup_assistant_prepare;
199 }
200
201 static void
202 e_startup_assistant_class_finalize (EStartupAssistantClass *class)
203 {
204 }
205
206 static void
207 e_startup_assistant_init (EStartupAssistant *assistant)
208 {
209 EActivity *activity;
210 GCancellable *cancellable;
211
212 assistant->priv = E_STARTUP_ASSISTANT_GET_PRIVATE (assistant);
213
214 cancellable = g_cancellable_new ();
215
216 activity = e_activity_new ();
217 e_activity_set_cancellable (activity, cancellable);
218 e_activity_set_state (activity, E_ACTIVITY_WAITING);
219 assistant->priv->import_activity = activity;
220
221 g_object_unref (cancellable);
222 }
223
224 void
225 e_startup_assistant_type_register (GTypeModule *type_module)
226 {
227 /* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
228 * function, so we have to wrap it with a public function in
229 * order to register types from a separate compilation unit. */
230 e_startup_assistant_register_type (type_module);
231 }
232
233 GtkWidget *
234 e_startup_assistant_new (EMailSession *session)
235 {
236 g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
237
238 return g_object_new (
239 E_TYPE_STARTUP_ASSISTANT,
240 "session", session, NULL);
241 }