evolution-3.6.4/modules/cal-config-google/evolution-cal-config-google.c

No issues found

  1 /*
  2  * evolution-cal-config-google.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 <config.h>
 20 #include <glib/gi18n-lib.h>
 21 
 22 #include <libebackend/libebackend.h>
 23 
 24 #include <misc/e-cal-source-config.h>
 25 #include <misc/e-source-config-backend.h>
 26 
 27 #include "e-google-chooser-button.h"
 28 #include "e-google-chooser-dialog.h"
 29 
 30 typedef ESourceConfigBackend ECalConfigGoogle;
 31 typedef ESourceConfigBackendClass ECalConfigGoogleClass;
 32 
 33 typedef struct _Context Context;
 34 
 35 struct _Context {
 36 	GtkWidget *google_button;
 37 };
 38 
 39 /* Module Entry Points */
 40 void e_module_load (GTypeModule *type_module);
 41 void e_module_unload (GTypeModule *type_module);
 42 
 43 /* Forward Declarations */
 44 GType e_cal_config_google_get_type (void);
 45 
 46 G_DEFINE_DYNAMIC_TYPE (
 47 	ECalConfigGoogle,
 48 	e_cal_config_google,
 49 	E_TYPE_SOURCE_CONFIG_BACKEND)
 50 
 51 static void
 52 cal_config_google_context_free (Context *context)
 53 {
 54 	g_object_unref (context->google_button);
 55 
 56 	g_slice_free (Context, context);
 57 }
 58 
 59 static gboolean
 60 cal_config_google_allow_creation (ESourceConfigBackend *backend)
 61 {
 62 	ESourceConfig *config;
 63 	ECalClientSourceType source_type;
 64 
 65 	config = e_source_config_backend_get_config (backend);
 66 
 67 	source_type = e_cal_source_config_get_source_type (
 68 		E_CAL_SOURCE_CONFIG (config));
 69 
 70 	/* XXX Google's CalDAV interface doesn't support tasks. */
 71 	return (source_type == E_CAL_CLIENT_SOURCE_TYPE_EVENTS);
 72 }
 73 
 74 static void
 75 cal_config_google_insert_widgets (ESourceConfigBackend *backend,
 76                                   ESource *scratch_source)
 77 {
 78 	ESourceConfig *config;
 79 	GtkWidget *widget;
 80 	Context *context;
 81 	const gchar *uid;
 82 
 83 	context = g_slice_new0 (Context);
 84 	uid = e_source_get_uid (scratch_source);
 85 	config = e_source_config_backend_get_config (backend);
 86 
 87 	g_object_set_data_full (
 88 		G_OBJECT (backend), uid, context,
 89 		(GDestroyNotify) cal_config_google_context_free);
 90 
 91 	e_cal_source_config_add_offline_toggle (
 92 		E_CAL_SOURCE_CONFIG (config), scratch_source);
 93 
 94 	e_source_config_add_user_entry (config, scratch_source);
 95 
 96 	widget = e_google_chooser_button_new (scratch_source);
 97 	e_source_config_insert_widget (
 98 		config, scratch_source, _("Calendar:"), widget);
 99 	context->google_button = g_object_ref (widget);
100 	gtk_widget_show (widget);
101 
102 	e_source_config_add_refresh_interval (config, scratch_source);
103 }
104 
105 static void
106 cal_config_google_commit_changes (ESourceConfigBackend *backend,
107                                   ESource *scratch_source)
108 {
109 	ESourceBackend *calendar_extension;
110 	ESourceWebdav *webdav_extension;
111 	SoupURI *soup_uri;
112 
113 	/* We need to hard-code a few settings. */
114 
115 	calendar_extension = e_source_get_extension (
116 		scratch_source, E_SOURCE_EXTENSION_CALENDAR);
117 
118 	webdav_extension = e_source_get_extension (
119 		scratch_source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
120 
121 	/* The backend name is actually "caldav" even though the
122 	 * ESource is a child of the built-in "Google" source. */
123 	e_source_backend_set_backend_name (calendar_extension, "caldav");
124 
125 	soup_uri = e_source_webdav_dup_soup_uri (webdav_extension);
126 
127 	/* The host name is fixed, obviously. */
128 	soup_uri_set_host (soup_uri, "www.google.com");
129 
130 	/* Google's CalDAV interface requires a secure connection. */
131 	soup_uri_set_scheme (soup_uri, SOUP_URI_SCHEME_HTTPS);
132 
133 	e_source_webdav_set_soup_uri (webdav_extension, soup_uri);
134 
135 	soup_uri_free (soup_uri);
136 }
137 
138 static gboolean
139 cal_config_google_check_complete (ESourceConfigBackend *backend,
140                                   ESource *scratch_source)
141 {
142 	ESourceAuthentication *extension;
143 	const gchar *extension_name;
144 	const gchar *user;
145 
146 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
147 	extension = e_source_get_extension (scratch_source, extension_name);
148 	user = e_source_authentication_get_user (extension);
149 
150 	return (user != NULL);
151 }
152 
153 static void
154 e_cal_config_google_class_init (ESourceConfigBackendClass *class)
155 {
156 	EExtensionClass *extension_class;
157 
158 	extension_class = E_EXTENSION_CLASS (class);
159 	extension_class->extensible_type = E_TYPE_CAL_SOURCE_CONFIG;
160 
161 	class->parent_uid = "google-stub";
162 	class->backend_name = "google";
163 	class->allow_creation = cal_config_google_allow_creation;
164 	class->insert_widgets = cal_config_google_insert_widgets;
165 	class->check_complete = cal_config_google_check_complete;
166 	class->commit_changes = cal_config_google_commit_changes;
167 }
168 
169 static void
170 e_cal_config_google_class_finalize (ESourceConfigBackendClass *class)
171 {
172 }
173 
174 static void
175 e_cal_config_google_init (ESourceConfigBackend *backend)
176 {
177 }
178 
179 G_MODULE_EXPORT void
180 e_module_load (GTypeModule *type_module)
181 {
182 	e_google_chooser_type_register (type_module);
183 	e_google_chooser_button_type_register (type_module);
184 	e_google_chooser_dialog_type_register (type_module);
185 	e_cal_config_google_register_type (type_module);
186 }
187 
188 G_MODULE_EXPORT void
189 e_module_unload (GTypeModule *type_module)
190 {
191 }