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

No issues found

  1 /*
  2  * evolution-book-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-book-source-config.h>
 25 #include <misc/e-interval-chooser.h>
 26 #include <misc/e-source-config-backend.h>
 27 
 28 typedef ESourceConfigBackend EBookConfigGoogle;
 29 typedef ESourceConfigBackendClass EBookConfigGoogleClass;
 30 
 31 typedef struct _Context Context;
 32 
 33 struct _Context {
 34 	gint placeholder;
 35 };
 36 
 37 /* Module Entry Points */
 38 void e_module_load (GTypeModule *type_module);
 39 void e_module_unload (GTypeModule *type_module);
 40 
 41 /* Forward Declarations */
 42 GType e_book_config_google_get_type (void);
 43 
 44 G_DEFINE_DYNAMIC_TYPE (
 45 	EBookConfigGoogle,
 46 	e_book_config_google,
 47 	E_TYPE_SOURCE_CONFIG_BACKEND)
 48 
 49 static void
 50 book_config_google_context_free (Context *context)
 51 {
 52 	g_slice_free (Context, context);
 53 }
 54 
 55 static void
 56 book_config_google_insert_widgets (ESourceConfigBackend *backend,
 57                                    ESource *scratch_source)
 58 {
 59 	ESourceConfig *config;
 60 	Context *context;
 61 	const gchar *uid;
 62 
 63 	context = g_slice_new (Context);
 64 	uid = e_source_get_uid (scratch_source);
 65 	config = e_source_config_backend_get_config (backend);
 66 
 67 	g_object_set_data_full (
 68 		G_OBJECT (backend), uid, context,
 69 		(GDestroyNotify) book_config_google_context_free);
 70 
 71 	e_source_config_add_user_entry (config, scratch_source);
 72 
 73 	e_source_config_add_refresh_interval (config, scratch_source);
 74 }
 75 
 76 static gboolean
 77 book_config_google_check_complete (ESourceConfigBackend *backend,
 78                                    ESource *scratch_source)
 79 {
 80 	ESourceAuthentication *extension;
 81 	const gchar *extension_name;
 82 	const gchar *user;
 83 
 84 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
 85 	extension = e_source_get_extension (scratch_source, extension_name);
 86 	user = e_source_authentication_get_user (extension);
 87 
 88 	return (user != NULL && *user != '\0');
 89 }
 90 
 91 static void
 92 book_config_google_commit_changes (ESourceConfigBackend *backend,
 93                                    ESource *scratch_source)
 94 {
 95 	ESourceAuthentication *extension;
 96 	const gchar *extension_name;
 97 	const gchar *user;
 98 
 99 	extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
100 	extension = e_source_get_extension (scratch_source, extension_name);
101 
102 	/* The authentication method should match what the google backend
103 	 * returns for get_supported_auth_methods(), although in practice
104 	 * the value just needs to be something other than "none". */
105 	e_source_authentication_set_method (extension, "plain/password");
106 
107 	user = e_source_authentication_get_user (extension);
108 	g_return_if_fail (user != NULL);
109 
110 	/* A user name without a domain implies '<user>@gmail.com'. */
111 	if (strchr (user, '@') == NULL) {
112 		gchar *full_user;
113 
114 		full_user = g_strconcat (user, "@gmail.com", NULL);
115 		e_source_authentication_set_user (extension, full_user);
116 		g_free (full_user);
117 	}
118 }
119 
120 static void
121 e_book_config_google_class_init (ESourceConfigBackendClass *class)
122 {
123 	EExtensionClass *extension_class;
124 
125 	extension_class = E_EXTENSION_CLASS (class);
126 	extension_class->extensible_type = E_TYPE_BOOK_SOURCE_CONFIG;
127 
128 	class->parent_uid = "google-stub";
129 	class->backend_name = "google";
130 	class->insert_widgets = book_config_google_insert_widgets;
131 	class->check_complete = book_config_google_check_complete;
132 	class->commit_changes = book_config_google_commit_changes;
133 }
134 
135 static void
136 e_book_config_google_class_finalize (ESourceConfigBackendClass *class)
137 {
138 }
139 
140 static void
141 e_book_config_google_init (ESourceConfigBackend *backend)
142 {
143 }
144 
145 G_MODULE_EXPORT void
146 e_module_load (GTypeModule *type_module)
147 {
148 	e_book_config_google_register_type (type_module);
149 }
150 
151 G_MODULE_EXPORT void
152 e_module_unload (GTypeModule *type_module)
153 {
154 }