[california/wip/733760-caldav: 1/3] First stab, this is pretty close



commit f714d61691479688f6822f17461dcc8cfaad8a50
Author: Jim Nelson <jim yorba org>
Date:   Wed Aug 6 19:22:36 2014 -0700

    First stab, this is pretty close
    
    For some reason, Yahoo! was added but didn't appear in calendar
    manager until California restarted.

 src/Makefile.am                                 |    4 +
 src/activator/activator.vala                    |    1 +
 src/activator/caldav/activator-caldav-pane.vala |  101 +++++++++++++
 src/activator/caldav/activator-caldav.vala      |   27 ++++
 src/california-resources.xml                    |    3 +
 src/rc/caldav-subscribe.ui                      |  174 +++++++++++++++++++++++
 6 files changed, 310 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2f1d536..cb63ee0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -14,6 +14,9 @@ california_VALASOURCES = \
        activator/activator-instance-list.vala \
        activator/activator-window.vala \
        \
+       activator/caldav/activator-caldav.vala \
+       activator/caldav/activator-caldav-pane.vala \
+       \
        activator/google/activator-google.vala \
        activator/google/activator-google-authenticating-pane.vala \
        activator/google/activator-google-calendar-list-pane.vala \
@@ -179,6 +182,7 @@ california_SOURCES = \
 california_RC = \
        rc/activator-list.ui \
        rc/app-menu.interface \
+       rc/caldav-subscribe.ui \
        rc/calendar-import.ui \
        rc/calendar-list-item.ui \
        rc/calendar-manager-list.ui \
diff --git a/src/activator/activator.vala b/src/activator/activator.vala
index e32d619..c89ec25 100644
--- a/src/activator/activator.vala
+++ b/src/activator/activator.vala
@@ -35,6 +35,7 @@ public void init() throws Error {
     assert(eds_store != null);
     activators.add(new WebCalActivator(_("Web calendar (.ics)"), eds_store));
     activators.add(new GoogleActivator(_("Google Calendar"), eds_store));
+    activators.add(new CalDAVActivator(_("CalDAV server"), eds_store));
 }
 
 public void terminate() {
diff --git a/src/activator/caldav/activator-caldav-pane.vala b/src/activator/caldav/activator-caldav-pane.vala
new file mode 100644
index 0000000..370fd97
--- /dev/null
+++ b/src/activator/caldav/activator-caldav-pane.vala
@@ -0,0 +1,101 @@
+/* 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.Activator {
+
+[GtkTemplate (ui = "/org/yorba/california/rc/caldav-subscribe.ui")]
+internal class CalDAVActivatorPane : Gtk.Grid, Toolkit.Card {
+    public const string ID = "CalDAVActivatorPane";
+    
+    public string card_id { get { return ID; } }
+    
+    public string? title { get { return null; } }
+    
+    public Gtk.Widget? default_widget { get { return subscribe_button; } }
+    
+    public Gtk.Widget? initial_focus { get { return name_entry; } }
+    
+    [GtkChild]
+    private Gtk.ColorButton color_button;
+    
+    [GtkChild]
+    private Gtk.Entry name_entry;
+    
+    [GtkChild]
+    private Gtk.Entry url_entry;
+    
+    [GtkChild]
+    private Gtk.Button subscribe_button;
+    
+    private Backing.CalDAVSubscribable store;
+    private Toolkit.EntryClearTextConnector name_clear_text_connector;
+    private Toolkit.EntryClearTextConnector url_clear_text_connector;
+    
+    public CalDAVActivatorPane(Backing.CalDAVSubscribable store, Soup.URI? supplied_url) {
+        this.store = store;
+        
+        if (supplied_url != null) {
+            url_entry.text = supplied_url.to_string(false);
+            url_entry.sensitive = false;
+        }
+        
+        name_clear_text_connector = new Toolkit.EntryClearTextConnector(name_entry);
+        name_entry.bind_property("text-length", subscribe_button, "sensitive",
+            BindingFlags.SYNC_CREATE, on_entry_changed);
+        
+        url_clear_text_connector = new Toolkit.EntryClearTextConnector(url_entry);
+        url_entry.bind_property("text-length", subscribe_button, "sensitive",
+            BindingFlags.SYNC_CREATE, on_entry_changed);
+    }
+    
+    public void jumped_to(Toolkit.Card? from, Toolkit.Card.Jump reason, Value? message) {
+    }
+    
+    private bool on_entry_changed(Binding binding, Value source_value, ref Value target_value) {
+        target_value =
+            name_entry.text_length > 0 
+            && url_entry.text_length > 0
+            && URI.is_valid(url_entry.text, { "http://";, "https://";, });
+        
+        return true;
+    }
+    
+    [GtkCallback]
+    private void on_cancel_button_clicked() {
+        jump_home();
+    }
+    
+    [GtkCallback]
+    private void on_subscribe_button_clicked() {
+        sensitive = false;
+        
+        subscribe_async.begin();
+    }
+    
+    private async void subscribe_async() {
+        Gdk.Cursor? cursor = Toolkit.set_busy(this);
+        
+        Error? subscribe_err = null;
+        try {
+            yield store.subscribe_caldav_async(name_entry.text, URI.parse(url_entry.text),
+                null, Gfx.rgba_to_uint8_rgb_string(color_button.rgba), null);
+        } catch (Error err) {
+            subscribe_err = err;
+        }
+        
+        Toolkit.set_unbusy(this, cursor);
+        
+        if (subscribe_err == null) {
+            notify_success();
+        } else {
+            notify_failure(_("Unable to subscribe to CalDAV calendar at %s: %s").printf(url_entry.text,
+                subscribe_err.message));
+        }
+    }
+}
+
+}
+
diff --git a/src/activator/caldav/activator-caldav.vala b/src/activator/caldav/activator-caldav.vala
new file mode 100644
index 0000000..230f799
--- /dev/null
+++ b/src/activator/caldav/activator-caldav.vala
@@ -0,0 +1,27 @@
+/* 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.Activator {
+
+internal class CalDAVActivator : Instance {
+    public override string first_card_id { get { return CalDAVActivatorPane.ID; } }
+    
+    private Backing.CalDAVSubscribable caldav_store;
+    
+    public CalDAVActivator(string title, Backing.CalDAVSubscribable store) {
+        base (title, store);
+        
+        caldav_store = store;
+    }
+    
+    public override Gee.List<Toolkit.Card> create_cards(Soup.URI? supplied_uri) {
+        return iterate<Toolkit.Card>(new CalDAVActivatorPane(caldav_store, supplied_uri))
+            .to_array_list();
+    }
+}
+
+}
+
diff --git a/src/california-resources.xml b/src/california-resources.xml
index 6d65154..7a1cc62 100644
--- a/src/california-resources.xml
+++ b/src/california-resources.xml
@@ -7,6 +7,9 @@
         <file compressed="true">rc/app-menu.interface</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
+        <file compressed="true">rc/caldav-subscribe.ui</file>
+    </gresource>
+    <gresource prefix="/org/yorba/california">
         <file compressed="true">rc/calendar-import.ui</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
diff --git a/src/rc/caldav-subscribe.ui b/src/rc/caldav-subscribe.ui
new file mode 100644
index 0000000..d308113
--- /dev/null
+++ b/src/rc/caldav-subscribe.ui
@@ -0,0 +1,174 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.16.1 -->
+<interface>
+  <requires lib="gtk+" version="3.10"/>
+  <template class="CaliforniaActivatorCalDAVActivatorPane" parent="GtkGrid">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="row_spacing">8</property>
+    <property name="column_spacing">8</property>
+    <child>
+      <object class="GtkLabel" id="name_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">end</property>
+        <property name="label" translatable="yes">_Name</property>
+        <property name="use_underline">True</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="url_label">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="halign">end</property>
+        <property name="label" translatable="yes">_URL</property>
+        <property name="use_underline">True</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="box2">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="spacing">8</property>
+        <child>
+          <object class="GtkEntry" id="name_entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="activates_default">True</property>
+            <property name="width_chars">40</property>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkColorButton" id="color_button">
+            <property name="width_request">16</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="halign">end</property>
+            <property name="valign">end</property>
+            <property name="title" translatable="yes">Select a color for the Web calendar</property>
+            <property name="rgba">rgb(32,32,204)</property>
+            <style>
+              <class name="image-button"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkBox" id="box3">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GtkEntry" id="url_entry">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hexpand">True</property>
+            <property name="activates_default">True</property>
+            <property name="width_chars">40</property>
+            <property name="input_purpose">url</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">1</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkButtonBox" id="button_box">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="valign">end</property>
+        <property name="margin_top">8</property>
+        <property name="vexpand">True</property>
+        <property name="spacing">8</property>
+        <property name="homogeneous">True</property>
+        <property name="baseline_position">bottom</property>
+        <property name="layout_style">end</property>
+        <child>
+          <object class="GtkButton" id="cancel_button">
+            <property name="label" translatable="yes">_Cancel</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <signal name="clicked" handler="on_cancel_button_clicked" 
object="CaliforniaActivatorCalDAVActivatorPane" swapped="no"/>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButton" id="subscribe_button">
+            <property name="label" translatable="yes">_Subscribe</property>
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="can_default">True</property>
+            <property name="has_default">True</property>
+            <property name="receives_default">True</property>
+            <property name="use_underline">True</property>
+            <signal name="clicked" handler="on_subscribe_button_clicked" 
object="CaliforniaActivatorCalDAVActivatorPane" swapped="no"/>
+            <style>
+              <class name="suggested-action"/>
+            </style>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">2</property>
+        <property name="width">2</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>


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