updated changelog
[platform/upstream/evolution-data-server.git] / modules / yahoo-backend / module-yahoo-backend.c
index 78ff77c..521fbc6 100644 (file)
@@ -1,18 +1,17 @@
 /*
  * module-yahoo-backend.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 library 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.
  *
- * 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.
+ * This library 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 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/>
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  */
 
 #define YAHOO_CALENDAR_BACKEND_NAME    "caldav"
 #define YAHOO_CALENDAR_HOST            "caldav.calendar.yahoo.com"
 #define YAHOO_CALENDAR_CALDAV_PATH     "/dav/%s/Calendar/%s"
+#define YAHOO_CALENDAR_RESOURCE_ID     "Calendar"
+
+/* Tasks Configuration Details
+ * (mostly the same as calendar) */
+#define YAHOO_TASKS_RESOURCE_ID                "Tasks"
 
 typedef struct _EYahooBackend EYahooBackend;
 typedef struct _EYahooBackendClass EYahooBackendClass;
@@ -176,6 +180,7 @@ yahoo_backend_add_calendar (ECollectionBackend *backend)
        ESourceRegistryServer *server;
        const gchar *backend_name;
        const gchar *extension_name;
+       const gchar *resource_id;
 
        /* XXX We could just stick a [Calendar] and [Task List] extension
         *     into the same ESource since all other settings are exactly
@@ -189,13 +194,26 @@ yahoo_backend_add_calendar (ECollectionBackend *backend)
 
        /* Add Yahoo! Calendar */
 
-       source = e_collection_backend_new_child (backend, "Calendar");
+       resource_id = YAHOO_CALENDAR_RESOURCE_ID;
+       source = e_collection_backend_new_child (backend, resource_id);
        e_source_set_display_name (source, _("Calendar"));
 
        extension_name = E_SOURCE_EXTENSION_CALENDAR;
        extension = e_source_get_extension (source, extension_name);
        e_source_backend_set_backend_name (extension, backend_name);
 
+       extension_name = E_SOURCE_EXTENSION_ALARMS;
+       extension = e_source_get_extension (source, extension_name);
+       if (!e_source_alarms_get_last_notified (E_SOURCE_ALARMS (extension))) {
+               GTimeVal today_tv;
+               gchar *today;
+
+               g_get_current_time (&today_tv);
+               today = g_time_val_to_iso8601 (&today_tv);
+               e_source_alarms_set_last_notified (E_SOURCE_ALARMS (extension), today);
+               g_free (today);
+       }
+
        yahoo_backend_config_calendar_child (backend, source);
        e_source_registry_server_add_source (server, source);
 
@@ -203,7 +221,8 @@ yahoo_backend_add_calendar (ECollectionBackend *backend)
 
        /* Add Yahoo! Tasks */
 
-       source = e_collection_backend_new_child (backend, "Tasks");
+       resource_id = YAHOO_TASKS_RESOURCE_ID;
+       source = e_collection_backend_new_child (backend, resource_id);
        e_source_set_display_name (source, _("Tasks"));
 
        extension_name = E_SOURCE_EXTENSION_TASK_LIST;
@@ -234,6 +253,26 @@ yahoo_backend_populate (ECollectionBackend *backend)
        g_list_free_full (list, (GDestroyNotify) g_object_unref);
 }
 
+static gchar *
+yahoo_backend_dup_resource_id (ECollectionBackend *backend,
+                               ESource *child_source)
+{
+       const gchar *extension_name;
+
+       /* XXX This is trival for now since we only
+        *     add one calendar and one task list. */
+
+       extension_name = E_SOURCE_EXTENSION_CALENDAR;
+       if (e_source_has_extension (child_source, extension_name))
+               return g_strdup (YAHOO_CALENDAR_RESOURCE_ID);
+
+       extension_name = E_SOURCE_EXTENSION_TASK_LIST;
+       if (e_source_has_extension (child_source, extension_name))
+               return g_strdup (YAHOO_TASKS_RESOURCE_ID);
+
+       return NULL;
+}
+
 static void
 yahoo_backend_child_added (ECollectionBackend *backend,
                            ESource *child_source)
@@ -263,31 +302,33 @@ yahoo_backend_child_added (ECollectionBackend *backend,
        extension_name = E_SOURCE_EXTENSION_MAIL_TRANSPORT;
        is_mail |= e_source_has_extension (child_source, extension_name);
 
-       /* Synchronize mail-related display names with the collection. */
-       if (is_mail)
-               g_object_bind_property (
-                       collection_source, "display-name",
-                       child_source, "display-name",
-                       G_BINDING_SYNC_CREATE);
-
        /* Synchronize mail-related user with the collection identity. */
        extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
        if (is_mail && e_source_has_extension (child_source, extension_name)) {
                ESourceAuthentication *auth_child_extension;
                ESourceCollection *collection_extension;
+               const gchar *collection_identity;
+               const gchar *auth_child_user;
 
                extension_name = E_SOURCE_EXTENSION_COLLECTION;
                collection_extension = e_source_get_extension (
                        collection_source, extension_name);
+               collection_identity = e_source_collection_get_identity (
+                       collection_extension);
 
                extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
                auth_child_extension = e_source_get_extension (
                        child_source, extension_name);
-
-               g_object_bind_property (
-                       collection_extension, "identity",
-                       auth_child_extension, "user",
-                       G_BINDING_SYNC_CREATE);
+               auth_child_user = e_source_authentication_get_user (
+                       auth_child_extension);
+
+               /* XXX Do not override an existing user name setting.
+                *     The IMAP or (especially) SMTP configuration may
+                *     have been modified to use a non-Yahoo! server. */
+               if (auth_child_user == NULL)
+                       e_source_authentication_set_user (
+                               auth_child_extension,
+                               collection_identity);
        }
 
        /* Chain up to parent's child_added() method. */
@@ -302,6 +343,7 @@ e_yahoo_backend_class_init (EYahooBackendClass *class)
 
        backend_class = E_COLLECTION_BACKEND_CLASS (class);
        backend_class->populate = yahoo_backend_populate;
+       backend_class->dup_resource_id = yahoo_backend_dup_resource_id;
        backend_class->child_added = yahoo_backend_child_added;
 }