[evolution-data-server/account-mgmt: 40/42] Add 'yahoo-accounts' module.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server/account-mgmt: 40/42] Add 'yahoo-accounts' module.
- Date: Tue, 10 Apr 2012 14:28:39 +0000 (UTC)
commit 71c2ebbb258e16a32548f81e3b9fc4012e6e6d2b
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Apr 6 12:41:57 2012 -0400
Add 'yahoo-accounts' module.
configure.ac | 1 +
modules/Makefile.am | 1 +
modules/yahoo-accounts/Makefile.am | 29 ++
modules/yahoo-accounts/module-yahoo-accounts.c | 539 ++++++++++++++++++++++++
4 files changed, 570 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1bb86b9..9b6c957 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1653,6 +1653,7 @@ libedataserverui/libedataserverui.pc
modules/Makefile
modules/google-accounts/Makefile
modules/online-accounts/Makefile
+modules/yahoo-accounts/Makefile
services/Makefile
services/evolution-addressbook-factory/Makefile
services/evolution-calendar-factory/Makefile
diff --git a/modules/Makefile.am b/modules/Makefile.am
index eda9fb4..9ab4b01 100644
--- a/modules/Makefile.am
+++ b/modules/Makefile.am
@@ -6,6 +6,7 @@ endif
SUBDIRS = \
google-accounts \
+ yahoo-accounts \
$(ONLINE_ACCOUNTS_DIR) \
$(NULL)
diff --git a/modules/yahoo-accounts/Makefile.am b/modules/yahoo-accounts/Makefile.am
new file mode 100644
index 0000000..e747b91
--- /dev/null
+++ b/modules/yahoo-accounts/Makefile.am
@@ -0,0 +1,29 @@
+NULL =
+
+module_LTLIBRARIES = module-yahoo-accounts.la
+
+module_yahoo_accounts_la_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ -I$(top_srcdir) \
+ -DG_LOG_DOMAIN=\"module-yahoo-accounts\" \
+ $(E_BACKEND_CFLAGS) \
+ $(E_DATA_SERVER_CFLAGS) \
+ $(NULL)
+
+module_yahoo_accounts_la_SOURCES = \
+ module-yahoo-accounts.c \
+ $(NULL)
+
+module_yahoo_accounts_la_LIBADD = \
+ $(top_builddir)/libebackend/libebackend-1.2.la \
+ $(top_builddir)/libedataserver/libedataserver-1.2.la \
+ $(top_builddir)/camel/libcamel-1.2.la \
+ $(E_BACKEND_LIBS) \
+ $(E_DATA_SERVER_LIBS) \
+ $(NULL)
+
+module_yahoo_accounts_la_LDFLAGS = \
+ -module -avoid-version $(NO_UNDEFINED) \
+ $(NULL)
+
+-include $(top_srcdir)/git.mk
diff --git a/modules/yahoo-accounts/module-yahoo-accounts.c b/modules/yahoo-accounts/module-yahoo-accounts.c
new file mode 100644
index 0000000..02927a6
--- /dev/null
+++ b/modules/yahoo-accounts/module-yahoo-accounts.c
@@ -0,0 +1,539 @@
+/*
+ * module-yahoo-accounts.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include <config.h>
+#include <glib/gi18n-lib.h>
+
+#include <libedataserver/e-uid.h>
+#include <libedataserver/e-source-address-book.h>
+#include <libedataserver/e-source-authentication.h>
+#include <libedataserver/e-source-calendar.h>
+#include <libedataserver/e-source-camel.h>
+#include <libedataserver/e-source-collection.h>
+#include <libedataserver/e-source-mail-account.h>
+#include <libedataserver/e-source-mail-identity.h>
+#include <libedataserver/e-source-mail-transport.h>
+#include <libedataserver/e-source-security.h>
+#include <libedataserver/e-source-webdav.h>
+
+#include <libebackend/e-extension.h>
+#include <libebackend/e-dbus-source-server.h>
+#include <libebackend/e-server-side-source.h>
+
+/* Standard GObject macros */
+#define E_TYPE_YAHOO_ACCOUNTS \
+ (e_yahoo_accounts_get_type ())
+#define E_YAHOO_ACCOUNTS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), E_TYPE_YAHOO_ACCOUNTS, EYahooAccounts))
+
+/* Just for readability... */
+#define METHOD(x) (CAMEL_NETWORK_SECURITY_METHOD_##x)
+
+/* IMAP Configuration Details */
+#define YAHOO_IMAP_BACKEND_NAME "imapx"
+#define YAHOO_IMAP_HOST "imap.mail.yahoo.com"
+#define YAHOO_IMAP_PORT 993
+#define YAHOO_IMAP_SECURITY_METHOD METHOD (SSL_ON_ALTERNATE_PORT)
+
+/* SMTP Configuration Details */
+#define YAHOO_SMTP_BACKEND_NAME "smtp"
+#define YAHOO_SMTP_HOST "smtp.mail.yahoo.com"
+#define YAHOO_SMTP_PORT 465
+#define YAHOO_SMTP_SECURITY_METHOD METHOD (SSL_ON_ALTERNATE_PORT)
+
+/* Calendar Configuration Details */
+#define YAHOO_CALENDAR_BACKEND_NAME "caldav"
+#define YAHOO_CALENDAR_HOST "caldav.calendar.yahoo.com"
+#define YAHOO_CALENDAR_CALDAV_PATH "/dav/%s/Calendar/%s"
+
+typedef struct _EYahooAccounts EYahooAccounts;
+typedef struct _EYahooAccountsClass EYahooAccountsClass;
+
+typedef struct _Closure Closure;
+
+struct _EYahooAccounts {
+ EExtension parent;
+};
+
+struct _EYahooAccountsClass {
+ EExtensionClass parent_class;
+};
+
+struct _Closure {
+ EYahooAccounts *extension;
+ gchar *uid;
+};
+
+/* Module Entry Points */
+void e_module_load (GTypeModule *type_module);
+void e_module_unload (GTypeModule *type_module);
+
+/* Forward Declarations */
+GType e_yahoo_accounts_get_type (void);
+
+G_DEFINE_DYNAMIC_TYPE (
+ EYahooAccounts,
+ e_yahoo_accounts,
+ E_TYPE_EXTENSION)
+
+static Closure *
+closure_new (EYahooAccounts *extension,
+ ESource *source)
+{
+ Closure *closure;
+
+ closure = g_slice_new0 (Closure);
+ closure->extension = g_object_ref (extension);
+ closure->uid = g_strdup (e_source_get_uid (source));
+
+ return closure;
+}
+
+static void
+closure_free (Closure *closure)
+{
+ g_object_unref (closure->extension);
+ g_free (closure->uid);
+
+ g_slice_free (Closure, closure);
+}
+
+static EDBusSourceServer *
+yahoo_accounts_get_server (EYahooAccounts *extension)
+{
+ EExtensible *extensible;
+
+ extensible = e_extension_get_extensible (E_EXTENSION (extension));
+
+ return E_DBUS_SOURCE_SERVER (extensible);
+}
+
+static ESource *
+yahoo_accounts_new_source (EYahooAccounts *extension)
+{
+ EDBusSourceServer *server;
+ ESource *source;
+ GFile *file;
+ gchar *new_uid;
+ gchar *filename;
+ const gchar *user_dir;
+ GError *error = NULL;
+
+ user_dir = e_server_side_source_get_user_dir ();
+
+ new_uid = e_uid_new ();
+ filename = g_build_filename (user_dir, new_uid, NULL);
+ file = g_file_new_for_path (filename);
+
+ /* This being a brand new data source, creating the instance
+ * should never fail but we'll check for errors just the same. */
+ server = yahoo_accounts_get_server (extension);
+ source = e_server_side_source_new (server, file, &error);
+
+ g_object_unref (file);
+ g_free (filename);
+ g_free (new_uid);
+
+ if (error != NULL) {
+ g_warn_if_fail (source == NULL);
+ g_warning ("%s: %s", G_STRFUNC, error->message);
+ g_error_free (error);
+ }
+
+ return source;
+}
+
+static ESource *
+yahoo_accounts_find_child_source (ESource *parent_source,
+ const gchar *extension_name)
+{
+ GNode *node;
+
+ node = e_server_side_source_get_node (
+ E_SERVER_SIDE_SOURCE (parent_source));
+
+ node = g_node_first_child (node);
+
+ while (node != NULL) {
+ ESource *child_source = E_SOURCE (node->data);
+
+ if (e_source_has_extension (child_source, extension_name))
+ return g_object_ref (child_source);
+
+ node = g_node_next_sibling (node);
+ }
+
+ return NULL;
+}
+
+static void
+yahoo_accounts_config_mail_account (EYahooAccounts *extension,
+ ESource *collection_source)
+{
+ ESource *source;
+ ESourceCamel *camel_extension;
+ ESourceExtension *source_extension;
+ ESourceCollection *collection_extension;
+ CamelSettings *settings;
+ const gchar *backend_name;
+ const gchar *extension_name;
+
+ /* The mail account source should be present and partially
+ * configured already. XXX Need to clarify which parts are
+ * expected to be configured. */
+
+ source = yahoo_accounts_find_child_source (
+ collection_source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ /* Add the mail account source to the collection. */
+ collection_extension = e_source_get_extension (
+ collection_source, E_SOURCE_EXTENSION_COLLECTION);
+ e_source_collection_add_mail_source (collection_extension, source);
+
+ /* Configure the mail account source. */
+
+ backend_name = YAHOO_IMAP_BACKEND_NAME;
+
+ g_object_bind_property (
+ collection_source, "display-name",
+ source, "display-name",
+ G_BINDING_SYNC_CREATE);
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_MAIL_ACCOUNT);
+
+ e_source_backend_set_backend_name (
+ E_SOURCE_BACKEND (source_extension), backend_name);
+
+ extension_name = e_source_camel_get_extension_name (backend_name);
+ camel_extension = e_source_get_extension (source, extension_name);
+ settings = e_source_camel_get_settings (camel_extension);
+
+ /* The "auth-mechanism" should already be set. */
+
+ camel_network_settings_set_host (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_IMAP_HOST);
+
+ camel_network_settings_set_port (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_IMAP_PORT);
+
+ camel_network_settings_set_security_method (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_IMAP_SECURITY_METHOD);
+
+ g_object_bind_property (
+ collection_extension, "identity",
+ settings, "user",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_unref (source);
+}
+
+static void
+yahoo_accounts_config_mail_identity (EYahooAccounts *extension,
+ ESource *collection_source)
+{
+ ESource *source;
+ ESourceCollection *collection_extension;
+
+ /* The mail identity source should be present and partially
+ * configured already. XXX Need to clarify which parts are
+ * expected to be configured. */
+
+ source = yahoo_accounts_find_child_source (
+ collection_source, E_SOURCE_EXTENSION_MAIL_IDENTITY);
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ /* Add the mail identity source to the collection. */
+ collection_extension = e_source_get_extension (
+ collection_source, E_SOURCE_EXTENSION_COLLECTION);
+ e_source_collection_add_mail_source (collection_extension, source);
+
+ /* Configure the mail identity source. */
+
+ g_object_bind_property (
+ collection_source, "display-name",
+ source, "display-name",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_unref (source);
+}
+
+static void
+yahoo_accounts_config_mail_transport (EYahooAccounts *extension,
+ ESource *collection_source)
+{
+ ESource *source;
+ ESourceCamel *camel_extension;
+ ESourceExtension *source_extension;
+ ESourceCollection *collection_extension;
+ CamelSettings *settings;
+ const gchar *backend_name;
+ const gchar *extension_name;
+
+ /* The mail transport source should be present and partially
+ * configured already. XXX Need to clarify which parts are
+ * expected to be configured. */
+
+ source = yahoo_accounts_find_child_source (
+ collection_source, E_SOURCE_EXTENSION_MAIL_TRANSPORT);
+ g_return_if_fail (E_IS_SOURCE (source));
+
+ /* Add the mail transport source to the collection. */
+ collection_extension = e_source_get_extension (
+ collection_source, E_SOURCE_EXTENSION_COLLECTION);
+ e_source_collection_add_mail_source (collection_extension, source);
+
+ /* Configure the mail transport source. */
+
+ backend_name = YAHOO_SMTP_BACKEND_NAME;
+
+ g_object_bind_property (
+ collection_source, "display-name",
+ source, "display-name",
+ G_BINDING_SYNC_CREATE);
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_MAIL_TRANSPORT);
+
+ e_source_backend_set_backend_name (
+ E_SOURCE_BACKEND (source_extension), backend_name);
+
+ extension_name = e_source_camel_get_extension_name (backend_name);
+ camel_extension = e_source_get_extension (source, extension_name);
+ settings = e_source_camel_get_settings (camel_extension);
+
+ /* The "auth-mechanism" should already be set. */
+
+ camel_network_settings_set_host (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_SMTP_HOST);
+
+ camel_network_settings_set_port (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_SMTP_PORT);
+
+ camel_network_settings_set_security_method (
+ CAMEL_NETWORK_SETTINGS (settings),
+ YAHOO_SMTP_SECURITY_METHOD);
+
+ g_object_bind_property (
+ collection_extension, "identity",
+ settings, "user",
+ G_BINDING_SYNC_CREATE);
+
+ g_object_unref (source);
+}
+
+static void
+yahoo_accounts_config_calendar (EYahooAccounts *extension,
+ ESource *collection_source)
+{
+ ESource *source;
+ EDBusSourceServer *server;
+ ESourceExtension *source_extension;
+ ESourceCollection *collection_extension;
+ const gchar *backend_name;
+ const gchar *display_name;
+ const gchar *identity;
+ gchar *path;
+
+ /* FIXME As a future enhancement, we should query Yahoo!
+ * for a list of user calendars and add them to the
+ * collection with matching display names and colors. */
+
+ source = yahoo_accounts_find_child_source (
+ collection_source, E_SOURCE_EXTENSION_CALENDAR);
+ if (source == NULL) {
+ const gchar *collection_uid;
+ source = yahoo_accounts_new_source (extension);
+ e_source_set_display_name (source, _("Calendar"));
+ collection_uid = e_source_get_uid (collection_source);
+ e_source_set_parent (source, collection_uid);
+ }
+
+ /* Add the calendar source to the collection. */
+ collection_extension = e_source_get_extension (
+ collection_source, E_SOURCE_EXTENSION_COLLECTION);
+ e_source_collection_add_calendar_source (collection_extension, source);
+
+ /* Configure the calendar source. */
+
+ backend_name = YAHOO_CALENDAR_BACKEND_NAME;
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_CALENDAR);
+
+ e_source_backend_set_backend_name (
+ E_SOURCE_BACKEND (source_extension), backend_name);
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_AUTHENTICATION);
+
+ e_source_authentication_set_host (
+ E_SOURCE_AUTHENTICATION (source_extension),
+ YAHOO_CALENDAR_HOST);
+
+ g_object_bind_property (
+ collection_extension, "identity",
+ source_extension, "user",
+ G_BINDING_SYNC_CREATE);
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_SECURITY);
+
+ e_source_security_set_secure (
+ E_SOURCE_SECURITY (source_extension), TRUE);
+
+ source_extension = e_source_get_extension (
+ source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
+
+ display_name = e_source_webdav_get_display_name (
+ E_SOURCE_WEBDAV (source_extension));
+
+ identity = e_source_collection_get_identity (collection_extension);
+ path = g_strdup_printf (
+ YAHOO_CALENDAR_CALDAV_PATH, identity, display_name);
+ e_source_webdav_set_resource_path (
+ E_SOURCE_WEBDAV (source_extension), path);
+ g_free (path);
+
+ server = yahoo_accounts_get_server (extension);
+ e_dbus_source_server_add_source (server, source);
+
+ g_object_unref (source);
+}
+
+static gboolean
+yahoo_accounts_populate (gpointer user_data)
+{
+ Closure *closure = user_data;
+ EDBusSourceServer *server;
+ ESource *source;
+
+ /* Because the closure struct holds a reference to the EExtension
+ * until this callback finishes, it's possible that we may outlive
+ * the EDBusSourceServer instance we're extending. The EExtension
+ * only keeps a weak pointer to it. So just return immediately if
+ * the server instance is gone. */
+ server = yahoo_accounts_get_server (closure->extension);
+ if (server == NULL)
+ return FALSE;
+
+ /* Now try to fetch the Yahoo! account from the EDBusSourceServer.
+ * It's possible it got removed already, so check for that too. */
+ source = e_dbus_source_server_ref_source (server, closure->uid);
+ if (source == NULL)
+ return FALSE;
+
+ yahoo_accounts_config_mail_account (closure->extension, source);
+ yahoo_accounts_config_mail_identity (closure->extension, source);
+ yahoo_accounts_config_mail_transport (closure->extension, source);
+ yahoo_accounts_config_calendar (closure->extension, source);
+
+ g_object_unref (source);
+
+ return FALSE;
+}
+
+static void
+yahoo_accounts_source_added_cb (EDBusSourceServer *server,
+ ESource *source,
+ EYahooAccounts *extension)
+{
+ ESourceBackend *backend_extension;
+ const gchar *backend_name;
+ const gchar *extension_name;
+
+ /* Determine if this is a Yahoo! account by looking for
+ * a collection extension with a "yahoo" backend name. */
+
+ extension_name = E_SOURCE_EXTENSION_COLLECTION;
+ if (!e_source_has_extension (source, extension_name))
+ return;
+
+ backend_extension = e_source_get_extension (source, extension_name);
+ backend_name = e_source_backend_get_backend_name (backend_extension);
+
+ if (g_strcmp0 (backend_name, "yahoo") != 0)
+ return;
+
+ /* We act on the newly-added Yahoo! account from an idle callback
+ * so child sources for the account have a chance to be added first. */
+ g_idle_add_full (
+ G_PRIORITY_DEFAULT_IDLE,
+ yahoo_accounts_populate,
+ closure_new (extension, source),
+ (GDestroyNotify) closure_free);
+}
+
+static void
+yahoo_accounts_constructed (GObject *object)
+{
+ EExtension *extension;
+ EExtensible *extensible;
+
+ extension = E_EXTENSION (object);
+ extensible = e_extension_get_extensible (extension);
+
+ g_signal_connect (
+ extensible, "source-added",
+ G_CALLBACK (yahoo_accounts_source_added_cb), extension);
+
+ /* Chain up to parent's constructed() method. */
+ G_OBJECT_CLASS (e_yahoo_accounts_parent_class)->constructed (object);
+}
+
+static void
+e_yahoo_accounts_class_init (EYahooAccountsClass *class)
+{
+ GObjectClass *object_class;
+ EExtensionClass *extension_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->constructed = yahoo_accounts_constructed;
+
+ extension_class = E_EXTENSION_CLASS (class);
+ extension_class->extensible_type = E_TYPE_DBUS_SOURCE_SERVER;
+}
+
+static void
+e_yahoo_accounts_class_finalize (EYahooAccountsClass *class)
+{
+}
+
+static void
+e_yahoo_accounts_init (EYahooAccounts *extension)
+{
+}
+
+G_MODULE_EXPORT void
+e_module_load (GTypeModule *type_module)
+{
+ e_yahoo_accounts_register_type (type_module);
+}
+
+G_MODULE_EXPORT void
+e_module_unload (GTypeModule *type_module)
+{
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]