[california/wip/725763-google] Finished -- subscribe to Google completed



commit ad9ab369220caf789fb384c6525e287b67f88c9c
Author: Jim Nelson <jim yorba org>
Date:   Thu Apr 3 17:07:25 2014 -0700

    Finished -- subscribe to Google completed

 src/Makefile.am                                    |    1 +
 .../activator-google-authenticating-pane.vala      |    2 +-
 .../activator-google-calendar-list-pane.vala       |   15 ++++++---
 src/activator/google/activator-google.vala         |    8 ++--
 src/activator/webcal/activator-webcal-pane.vala    |    2 +-
 src/backing/backing-caldav-subscribable.vala       |   30 +++++++++++++++++
 src/backing/backing-webcal-subscribable.vala       |    2 +-
 src/backing/eds/backing-eds-store.vala             |   34 +++++++++++++------
 8 files changed, 71 insertions(+), 23 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 45b4967..071c509 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,6 +26,7 @@ california_VALASOURCES = \
        application/main.vala \
        \
        backing/backing.vala \
+       backing/backing-caldav-subscribable.vala \
        backing/backing-calendar-source.vala \
        backing/backing-calendar-source-subscription.vala \
        backing/backing-calendar-subscription-manager.vala \
diff --git a/src/activator/google/activator-google-authenticating-pane.vala 
b/src/activator/google/activator-google-authenticating-pane.vala
index e2738b4..d4cbafe 100644
--- a/src/activator/google/activator-google-authenticating-pane.vala
+++ b/src/activator/google/activator-google-authenticating-pane.vala
@@ -132,7 +132,7 @@ public class GoogleAuthenticatingPane : Gtk.Grid, Card {
         // delay gives the user a chance to see what's transpired
         Timeout.add(SUCCESS_DELAY_MSEC, () => {
             jump_to_card_by_name(GoogleCalendarListPane.ID, new GoogleCalendarListPane.Message(
-                own_calendars, all_calendars));
+                credentials.username, own_calendars, all_calendars));
             
             return false;
         });
diff --git a/src/activator/google/activator-google-calendar-list-pane.vala 
b/src/activator/google/activator-google-calendar-list-pane.vala
index 343bb6e..954a858 100644
--- a/src/activator/google/activator-google-calendar-list-pane.vala
+++ b/src/activator/google/activator-google-calendar-list-pane.vala
@@ -11,10 +11,12 @@ public class GoogleCalendarListPane : Gtk.Grid, Card {
     public const string ID = "GoogleCalendarListPane";
     
     public class Message : BaseObject {
+        public string username { get; private set; }
         public GData.Feed own_calendars { get; private set; }
         public GData.Feed all_calendars { get; private set; }
         
-        public Message(GData.Feed own_calendars, GData.Feed all_calendars) {
+        public Message(string username, GData.Feed own_calendars, GData.Feed all_calendars) {
+            this.username = username;
             this.own_calendars = own_calendars;
             this.all_calendars = all_calendars;
         }
@@ -41,11 +43,12 @@ public class GoogleCalendarListPane : Gtk.Grid, Card {
     [GtkChild]
     private Gtk.Button subscribe_button;
     
-    private Backing.WebCalSubscribable store;
+    private Backing.CalDAVSubscribable store;
+    private string? username = null;
     private ListBoxModel<GData.CalendarCalendar> own_calendars_model;
     private ListBoxModel<GData.CalendarCalendar> unowned_calendars_model;
     
-    public GoogleCalendarListPane(Backing.WebCalSubscribable store) {
+    public GoogleCalendarListPane(Backing.CalDAVSubscribable store) {
         this.store = store;
         
         own_calendars_listbox.set_placeholder(create_placeholder());
@@ -72,6 +75,8 @@ public class GoogleCalendarListPane : Gtk.Grid, Card {
         unowned_calendars_model.clear();
         subscribe_button.sensitive = false;
         
+        username = feeds.username;
+        
         // add all "own" calendars, keeping track of id to not add them when traversing all calendars
         Gee.HashSet<string> own_ids = new Gee.HashSet<string>();
         foreach (GData.Entry entry in feeds.own_calendars.get_entries()) {
@@ -168,8 +173,8 @@ public class GoogleCalendarListPane : Gtk.Grid, Card {
         
         debug("Subscribing to %s", uri.to_string(false));
         try {
-            yield store.subscribe_webcal_async(calendar.title, uri,calendar.color.to_hexadecimal(),
-                null);
+            yield store.subscribe_caldav_async(calendar.title, uri, username,
+                calendar.color.to_hexadecimal(), null);
             completed();
         } catch (Error err) {
             debug("Unable to create subscription to %s: %s", calendar.content_uri, err.message);
diff --git a/src/activator/google/activator-google.vala b/src/activator/google/activator-google.vala
index 5c8a3ba..973c3aa 100644
--- a/src/activator/google/activator-google.vala
+++ b/src/activator/google/activator-google.vala
@@ -9,19 +9,19 @@ namespace California.Activator {
 internal class GoogleActivator : Instance {
     public override string first_card_id { get { return GoogleLoginPane.ID; } }
     
-    private Backing.WebCalSubscribable webcal_store;
+    private Backing.CalDAVSubscribable caldav_store;
     
-    public GoogleActivator(string title, Backing.WebCalSubscribable store) {
+    public GoogleActivator(string title, Backing.CalDAVSubscribable store) {
         base (title, store);
         
-        webcal_store = store;
+        caldav_store = store;
     }
     
     public override Gee.List<Card> create_cards(Soup.URI? supplied_uri) {
         Gee.List<Card> cards = new Gee.ArrayList<Card>();
         cards.add(new GoogleLoginPane());
         cards.add(new GoogleAuthenticatingPane());
-        cards.add(new GoogleCalendarListPane(webcal_store));
+        cards.add(new GoogleCalendarListPane(caldav_store));
         
         return cards;
     }
diff --git a/src/activator/webcal/activator-webcal-pane.vala b/src/activator/webcal/activator-webcal-pane.vala
index b2ebc65..b1cb10e 100644
--- a/src/activator/webcal/activator-webcal-pane.vala
+++ b/src/activator/webcal/activator-webcal-pane.vala
@@ -76,7 +76,7 @@ internal class WebCalActivatorPane : Gtk.Grid, Card {
         
         try {
             yield store.subscribe_webcal_async(name_entry.text, URI.parse(url_entry.text),
-                Gfx.rgb_to_uint8_rgb_string(color), null);
+                null, Gfx.rgb_to_uint8_rgb_string(color), null);
             completed();
         } catch (Error err) {
             debug("Unable to create subscription to %s: %s", url_entry.text, err.message);
diff --git a/src/backing/backing-caldav-subscribable.vala b/src/backing/backing-caldav-subscribable.vala
new file mode 100644
index 0000000..e876281
--- /dev/null
+++ b/src/backing/backing-caldav-subscribable.vala
@@ -0,0 +1,30 @@
+/* Copyright 2014 Yorba Foundation
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+namespace California.Backing {
+
+/**
+ * Interface allowing for a { link Store} to subscribe to CalDAV calendars.
+ *
+ * See [[http://caldav.calconnect.org/]] for more information about CalDAV.
+ */
+
+public interface CalDAVSubscribable : Store {
+    /**
+     * Subscribe to a CalDAV link, creating a new { link CalendarSource} in the process.
+     *
+     * "title" is the display name of the new subscription and should probably be supplied by the
+     * user.
+     *
+     * The CalendarSource is not returned; rather, callers should be subscribed to the
+     * { link Store.added} signal for notification.
+     */
+    public abstract async void subscribe_caldav_async(string title, Soup.URI uri, string? username,
+        string color, Cancellable? cancellable) throws Error;
+}
+
+}
+
diff --git a/src/backing/backing-webcal-subscribable.vala b/src/backing/backing-webcal-subscribable.vala
index 970d119..6b029e0 100644
--- a/src/backing/backing-webcal-subscribable.vala
+++ b/src/backing/backing-webcal-subscribable.vala
@@ -23,7 +23,7 @@ public interface WebCalSubscribable : Store {
      * The CalendarSource is not returned; rather, callers should be subscribed to the
      * { link Store.added} signal for notification.
      */
-    public abstract async void subscribe_webcal_async(string title, Soup.URI uri,
+    public abstract async void subscribe_webcal_async(string title, Soup.URI uri, string? username,
         string color, Cancellable? cancellable) throws Error;
 }
 
diff --git a/src/backing/eds/backing-eds-store.vala b/src/backing/eds/backing-eds-store.vala
index 3631fff..2b6efaf 100644
--- a/src/backing/eds/backing-eds-store.vala
+++ b/src/backing/eds/backing-eds-store.vala
@@ -4,13 +4,15 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
+extern void e_source_webdav_set_soup_uri(E.SourceWebdav webdav, Soup.URI uri);
+
 namespace California.Backing {
 
 /**
  * An interface to the EDS source registry.
  */
 
-internal class EdsStore : Store, WebCalSubscribable {
+internal class EdsStore : Store, WebCalSubscribable, CalDAVSubscribable {
     private E.SourceRegistry? registry = null;
     private Gee.HashMap<E.Source, Source> sources = new Gee.HashMap<E.Source, Source>();
     
@@ -43,16 +45,28 @@ internal class EdsStore : Store, WebCalSubscribable {
     
     /**
      * @inheritDoc
-     *
-     * TODO: Authentication is not properly handled.
      */
-    public async void subscribe_webcal_async(string title, Soup.URI uri, string color,
+    public async void subscribe_webcal_async(string title, Soup.URI uri, string? username, string color,
         Cancellable? cancellable) throws Error {
+        yield subscribe_eds_async(title, uri, username, color, "webcal", cancellable);
+    }
+    
+    /**
+     * @inheritDoc
+     */
+    public async void subscribe_caldav_async(string title, Soup.URI uri, string? username, string color,
+        Cancellable? cancellable) throws Error {
+        yield subscribe_eds_async(title, uri, username, color, "caldav", cancellable);
+    }
+    
+    private async void subscribe_eds_async(string title, Soup.URI uri, string? username, string color,
+        string backend_name, Cancellable? cancellable) throws Error {
         if (!is_open)
             throw new BackingError.UNAVAILABLE("EDS not open");
         
         E.Source scratch = new E.Source(null, null);
-        scratch.parent = "google-stub";
+        // Surprise -- Google gets special treatment
+        scratch.parent = uri.host.has_suffix("google.com") ? "google-stub" : "webcal-stub";
         scratch.enabled = true;
         scratch.display_name = title;
         
@@ -61,7 +75,7 @@ internal class EdsStore : Store, WebCalSubscribable {
             as E.SourceCalendar;
         if (calendar == null)
             throw new BackingError.UNAVAILABLE("No SourceCalendar extension for scratch source");
-        calendar.backend_name = "webcal";
+        calendar.backend_name = backend_name;
         calendar.selected = true;
         calendar.color = color;
         
@@ -70,17 +84,15 @@ internal class EdsStore : Store, WebCalSubscribable {
             as E.SourceWebdav;
         if (webdav == null)
             throw new BackingError.UNAVAILABLE("No SourceWebdav extension for scratch source");
-        webdav.resource_path = uri.path;
-        webdav.resource_query = uri.query;
+        // nice method that takes care of setting things correctly in a lot of other extensions
+        e_source_webdav_set_soup_uri(webdav, uri);
         
         // required
         E.SourceAuthentication? auth = scratch.get_extension(E.SOURCE_EXTENSION_AUTHENTICATION)
             as E.SourceAuthentication;
         if (auth == null)
             throw new BackingError.UNAVAILABLE("No SourceAuthentication extension for scratch source");
-        auth.host = uri.host;
-        auth.port = uri.port;
-        auth.method = "none";
+        auth.user = username;
         
         // optional w/ baked-in defaults
         E.SourceOffline? offline = scratch.get_extension(E.SOURCE_EXTENSION_OFFLINE)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]