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

No issues found

Incomplete coverage

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