evolution-3.6.4/modules/mail-config/e-mail-config-google-summary.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-config-google-summary.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-config-google-summary.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-config-google-summary.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-mail-config-google-summary.h"
 20 
 21 #include <config.h>
 22 #include <glib/gi18n-lib.h>
 23 
 24 #include <mail/e-mail-config-summary-page.h>
 25 
 26 #define E_MAIL_CONFIG_GOOGLE_SUMMARY_GET_PRIVATE(obj) \
 27 	(G_TYPE_INSTANCE_GET_PRIVATE \
 28 	((obj), E_TYPE_MAIL_CONFIG_GOOGLE_SUMMARY, EMailConfigGoogleSummaryPrivate))
 29 
 30 #define GOOGLE_HELP_URI \
 31 	"http://support.google.com/mail/bin/answer.py?hl=en&answer=77695"
 32 
 33 struct _EMailConfigGoogleSummaryPrivate {
 34 	ESource *collection_source;
 35 
 36 	/* Widgets (not referenced) */
 37 	GtkWidget *calendar_toggle;
 38 	GtkWidget *contacts_toggle;
 39 
 40 	gboolean applicable;
 41 };
 42 
 43 enum {
 44 	PROP_0,
 45 	PROP_APPLICABLE
 46 };
 47 
 48 G_DEFINE_DYNAMIC_TYPE (
 49 	EMailConfigGoogleSummary,
 50 	e_mail_config_google_summary,
 51 	E_TYPE_EXTENSION)
 52 
 53 static EMailConfigSummaryPage *
 54 mail_config_google_summary_get_summary_page (EMailConfigGoogleSummary *extension)
 55 {
 56 	EExtensible *extensible;
 57 
 58 	extensible = e_extension_get_extensible (E_EXTENSION (extension));
 59 
 60 	return E_MAIL_CONFIG_SUMMARY_PAGE (extensible);
 61 }
 62 
 63 static gboolean
 64 mail_config_google_summary_is_applicable (EMailConfigSummaryPage *page)
 65 {
 66 	ESource *source;
 67 	const gchar *extension_name;
 68 	const gchar *host = NULL;
 69 
 70 	/* FIXME We should tie this into EMailAutoconfig to avoid
 71 	 *       hard-coding Google domain names.  Maybe retain the
 72 	 *       <emailProvider id="..."> it matched so we can just
 73 	 *       check for, in this case, "googlemail.com".
 74 	 *
 75 	 *       Source:
 76 	 *       http://api.gnome.org/evolution/autoconfig/1.1/google.com
 77 	 */
 78 
 79 	source = e_mail_config_summary_page_get_account_source (page);
 80 
 81 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
 82 	if (e_source_has_extension (source, extension_name)) {
 83 		ESourceAuthentication *extension;
 84 		extension = e_source_get_extension (source, extension_name);
 85 		host = e_source_authentication_get_host (extension);
 86 	}
 87 
 88 	if (host == NULL)
 89 		return FALSE;
 90 
 91 	if (e_util_utf8_strstrcase (host, "gmail.com") != NULL)
 92 		return TRUE;
 93 
 94 	if (e_util_utf8_strstrcase (host, "googlemail.com") != NULL)
 95 		return TRUE;
 96 
 97 	return FALSE;
 98 }
 99 
100 static void
101 mail_config_google_summary_refresh_cb (EMailConfigSummaryPage *page,
102                                        EMailConfigGoogleSummary *extension)
103 {
104 	extension->priv->applicable =
105 		mail_config_google_summary_is_applicable (page);
106 
107 	g_object_notify (G_OBJECT (extension), "applicable");
108 }
109 
110 static void
111 mail_config_google_summary_commit_changes_cb (EMailConfigSummaryPage *page,
112                                               GQueue *source_queue,
113                                               EMailConfigGoogleSummary *extension)
114 {
115 	ESource *source;
116 	ESourceCollection *collection_extension;
117 	ESourceAuthentication *auth_extension;
118 	GtkToggleButton *toggle_button;
119 	GList *head, *link;
120 	const gchar *user;
121 	const gchar *parent_uid;
122 	const gchar *display_name;
123 	const gchar *extension_name;
124 	gboolean calendar_active;
125 	gboolean contacts_active;
126 
127 	/* If this is not a Google account, do nothing (obviously). */
128 	if (!e_mail_config_google_summary_get_applicable (extension))
129 		return;
130 
131 	toggle_button = GTK_TOGGLE_BUTTON (extension->priv->calendar_toggle);
132 	calendar_active = gtk_toggle_button_get_active (toggle_button);
133 
134 	toggle_button = GTK_TOGGLE_BUTTON (extension->priv->contacts_toggle);
135 	contacts_active = gtk_toggle_button_get_active (toggle_button);
136 
137 	/* If the user declined both Calendar and Contacts, do nothing. */
138 	if (!calendar_active && !contacts_active)
139 		return;
140 
141 	source = e_mail_config_summary_page_get_account_source (page);
142 	display_name = e_source_get_display_name (source);
143 
144 	/* The collection identity is the mail account user name. */
145 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
146 	auth_extension = e_source_get_extension (source, extension_name);
147 	user = e_source_authentication_get_user (auth_extension);
148 
149 	source = extension->priv->collection_source;
150 	e_source_set_display_name (source, display_name);
151 
152 	extension_name = E_SOURCE_EXTENSION_COLLECTION;
153 	collection_extension = e_source_get_extension (source, extension_name);
154 	e_source_collection_set_identity (collection_extension, user);
155 
156 	/* All queued sources become children of the collection source. */
157 	parent_uid = e_source_get_uid (source);
158 	head = g_queue_peek_head_link (source_queue);
159 	for (link = head; link != NULL; link = g_list_next (link))
160 		e_source_set_parent (E_SOURCE (link->data), parent_uid);
161 
162 	/* Push this AFTER iterating over the source queue. */
163 	g_queue_push_head (source_queue, g_object_ref (source));
164 
165 	/* The "google-backend" module in E-D-S will handle the rest. */
166 }
167 
168 static void
169 mail_config_google_summary_get_property (GObject *object,
170                                          guint property_id,
171                                          GValue *value,
172                                          GParamSpec *pspec)
173 {
174 	switch (property_id) {
175 		case PROP_APPLICABLE:
176 			g_value_set_boolean (
177 				value,
178 				e_mail_config_google_summary_get_applicable (
179 				E_MAIL_CONFIG_GOOGLE_SUMMARY (object)));
180 			return;
181 	}
182 
183 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
184 }
185 
186 static void
187 mail_config_google_summary_dispose (GObject *object)
188 {
189 	EMailConfigGoogleSummaryPrivate *priv;
190 
191 	priv = E_MAIL_CONFIG_GOOGLE_SUMMARY_GET_PRIVATE (object);
192 
193 	if (priv->collection_source != NULL) {
194 		g_object_unref (priv->collection_source);
195 		priv->collection_source = NULL;
196 	}
197 
198 	/* Chain up to parent's dispose() method. */
199 	G_OBJECT_CLASS (e_mail_config_google_summary_parent_class)->
200 		dispose (object);
201 }
202 
203 static void
204 mail_config_google_summary_constructed (GObject *object)
205 {
206 	EMailConfigGoogleSummary *extension;
207 	EMailConfigSummaryPage *page;
208 	ESourceCollection *collection_extension;
209 	ESource *source;
210 	GtkWidget *container;
211 	GtkWidget *widget;
212 	const gchar *extension_name;
213 	const gchar *text;
214 	gchar *markup;
215 
216 	extension = E_MAIL_CONFIG_GOOGLE_SUMMARY (object);
217 
218 	/* Chain up to parent's constructed() method. */
219 	G_OBJECT_CLASS (e_mail_config_google_summary_parent_class)->
220 		constructed (object);
221 
222 	page = mail_config_google_summary_get_summary_page (extension);
223 
224 	/* Use g_signal_connect_after() so the EMailConfigSummaryPage
225 	 * class methods run first.  They make changes to the sources
226 	 * the we either want to utilize or override. */
227 
228 	g_signal_connect_after (
229 		page, "refresh",
230 		G_CALLBACK (mail_config_google_summary_refresh_cb),
231 		extension);
232 
233 	g_signal_connect_after (
234 		page, "commit-changes",
235 		G_CALLBACK (mail_config_google_summary_commit_changes_cb),
236 		extension);
237 
238 	container = GTK_WIDGET (page);
239 
240 	widget = gtk_grid_new ();
241 	gtk_grid_set_row_spacing (GTK_GRID (widget), 6);
242 	gtk_grid_set_column_spacing (GTK_GRID (widget), 6);
243 	gtk_box_pack_start (GTK_BOX (page), widget, FALSE, FALSE, 0);
244 
245 	g_object_bind_property (
246 		extension, "applicable",
247 		widget, "visible",
248 		G_BINDING_SYNC_CREATE);
249 
250 	container = widget;
251 
252 	text = _("Google Features");
253 	markup = g_markup_printf_escaped ("<b>%s</b>", text);
254 	widget = gtk_label_new (markup);
255 	gtk_label_set_use_markup (GTK_LABEL (widget), TRUE);
256 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
257 	gtk_grid_attach (GTK_GRID (container), widget, 0, 0, 1, 1);
258 	gtk_widget_show (widget);
259 	g_free (markup);
260 
261 	text = _("Add Google Ca_lendar to this account");
262 	widget = gtk_check_button_new_with_mnemonic (text);
263 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
264 	gtk_widget_set_margin_left (widget, 12);
265 	gtk_grid_attach (GTK_GRID (container), widget, 0, 1, 1, 1);
266 	extension->priv->calendar_toggle = widget;  /* not referenced */
267 	gtk_widget_show (widget);
268 
269 	text = _("Add Google Con_tacts to this account");
270 	widget = gtk_check_button_new_with_mnemonic (text);
271 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
272 	gtk_widget_set_margin_left (widget, 12);
273 	gtk_grid_attach (GTK_GRID (container), widget, 0, 2, 1, 1);
274 	extension->priv->contacts_toggle = widget;  /* not referenced */
275 	gtk_widget_show (widget);
276 
277 	text = _("You may need to enable IMAP access");
278 	widget = gtk_link_button_new_with_label (GOOGLE_HELP_URI, text);
279 	gtk_widget_set_margin_left (widget, 12);
280 	gtk_grid_attach (GTK_GRID (container), widget, 0, 3, 1, 1);
281 	gtk_widget_show (widget);
282 
283 	source = extension->priv->collection_source;
284 	extension_name = E_SOURCE_EXTENSION_COLLECTION;
285 	collection_extension = e_source_get_extension (source, extension_name);
286 
287 	/* Can't bind the collection's display name here because
288 	 * the Summary Page has no sources yet.  Set the display
289 	 * name while committing instead. */
290 
291 	g_object_bind_property (
292 		extension->priv->calendar_toggle, "active",
293 		collection_extension, "calendar-enabled",
294 		G_BINDING_SYNC_CREATE);
295 
296 	g_object_bind_property (
297 		extension->priv->contacts_toggle, "active",
298 		collection_extension, "contacts-enabled",
299 		G_BINDING_SYNC_CREATE);
300 }
301 
302 static void
303 e_mail_config_google_summary_class_init (EMailConfigGoogleSummaryClass *class)
304 {
305 	GObjectClass *object_class;
306 	EExtensionClass *extension_class;
307 
308 	g_type_class_add_private (
309 		class, sizeof (EMailConfigGoogleSummaryPrivate));
310 
311 	object_class = G_OBJECT_CLASS (class);
312 	object_class->get_property = mail_config_google_summary_get_property;
313 	object_class->dispose = mail_config_google_summary_dispose;
314 	object_class->constructed = mail_config_google_summary_constructed;
315 
316 	extension_class = E_EXTENSION_CLASS (class);
317 	extension_class->extensible_type = E_TYPE_MAIL_CONFIG_SUMMARY_PAGE;
318 
319 	g_object_class_install_property (
320 		object_class,
321 		PROP_APPLICABLE,
322 		g_param_spec_boolean (
323 			"applicable",
324 			"Applicable",
325 			"Whether this extension is applicable "
326 			"to the current mail account settings",
327 			FALSE,
328 			G_PARAM_READABLE));
329 }
330 
331 static void
332 e_mail_config_google_summary_class_finalize (EMailConfigGoogleSummaryClass *class)
333 {
334 }
335 
336 static void
337 e_mail_config_google_summary_init (EMailConfigGoogleSummary *extension)
338 {
339 	ESource *source;
340 	ESourceBackend *backend_extension;
341 	const gchar *extension_name;
342 
343 	extension->priv = E_MAIL_CONFIG_GOOGLE_SUMMARY_GET_PRIVATE (extension);
344 
345 	source = e_source_new (NULL, NULL, NULL);
346 	extension_name = E_SOURCE_EXTENSION_COLLECTION;
347 	backend_extension = e_source_get_extension (source, extension_name);
348 	e_source_backend_set_backend_name (backend_extension, "google");
349 	extension->priv->collection_source = source;
350 }
351 
352 void
353 e_mail_config_google_summary_type_register (GTypeModule *type_module)
354 {
355 	/* XXX G_DEFINE_DYNAMIC_TYPE declares a static type registration
356 	 *     function, so we have to wrap it with a public function in
357 	 *     order to register types from a separate compilation unit. */
358 	e_mail_config_google_summary_register_type (type_module);
359 }
360 
361 gboolean
362 e_mail_config_google_summary_get_applicable (EMailConfigGoogleSummary *extension)
363 {
364 	g_return_val_if_fail (
365 		E_IS_MAIL_CONFIG_GOOGLE_SUMMARY (extension), FALSE);
366 
367 	return extension->priv->applicable;
368 }