[california] Move Activators from Backing to their own unit



commit 648a99ebe7540df462421fee8cb2c632913c2649
Author: Jim Nelson <jim yorba org>
Date:   Mon Mar 31 19:09:30 2014 -0700

    Move Activators from Backing to their own unit

 po/POTFILES.in                                     |    2 +-
 src/Makefile.am                                    |   13 +++--
 .../activator-instance-list.vala}                  |   20 ++++----
 .../activator-instance.vala}                       |   15 +++---
 src/activator/activator-window.vala                |   49 ++++++++++++++++++
 src/activator/activator.vala                       |   52 ++++++++++++++++++++
 .../webcal/activator-webcal-pane.vala}             |    6 +-
 .../webcal/activator-webcal.vala}                  |    8 ++--
 src/application/california-application.vala        |   18 +------
 src/backing/backing-manager.vala                   |   36 +++++--------
 src/backing/backing.vala                           |    6 +--
 src/rc/activator-list.ui                           |    8 ++--
 src/rc/webcal-subscribe.ui                         |    6 +-
 13 files changed, 161 insertions(+), 78 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index a5969b5..7fbe95b 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,7 +1,7 @@
 [encoding: UTF-8]
 # List of source files which contain translatable strings.
+src/activator/activator.vala
 src/application/california-application.vala
-src/backing/backing.vala
 src/calendar/calendar.vala
 src/calendar/calendar-date.vala
 src/host/host-create-update-event.vala
diff --git a/src/Makefile.am b/src/Makefile.am
index 9f3fbca..fad4e73 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,12 +8,19 @@ AM_CPPFLAGS = \
 bin_PROGRAMS = california
 
 california_VALASOURCES = \
+       activator/activator.vala \
+       activator/activator-instance.vala \
+       activator/activator-instance-list.vala \
+       activator/activator-window.vala \
+       \
+       activator/webcal/activator-webcal.vala \
+       activator/webcal/activator-webcal-pane.vala \
+       \
        application/california-application.vala \
        application/california-resource.vala \
        application/main.vala \
        \
        backing/backing.vala \
-       backing/backing-activator.vala \
        backing/backing-calendar-source.vala \
        backing/backing-calendar-source-subscription.vala \
        backing/backing-calendar-subscription-manager.vala \
@@ -27,9 +34,6 @@ california_VALASOURCES = \
        backing/eds/backing-eds-calendar-source-subscription.vala \
        backing/eds/backing-eds-store.vala \
        \
-       backing/webcal/backing-webcal-activator.vala \
-       backing/webcal/backing-webcal-activator-pane.vala \
-       \
        base/base-object.vala \
        base/base-unit.vala \
        \
@@ -67,7 +71,6 @@ california_VALASOURCES = \
        component/component-vtype.vala \
        \
        host/host.vala \
-       host/host-activator-list.vala \
        host/host-calendar-popup.vala \
        host/host-color-chooser-popup.vala \
        host/host-create-update-event.vala \
diff --git a/src/host/host-activator-list.vala b/src/activator/activator-instance-list.vala
similarity index 64%
rename from src/host/host-activator-list.vala
rename to src/activator/activator-instance-list.vala
index 85ed143..2c94778 100644
--- a/src/host/host-activator-list.vala
+++ b/src/activator/activator-instance-list.vala
@@ -4,14 +4,14 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace California.Host {
+namespace California.Activator {
 
 [GtkTemplate (ui = "/org/yorba/california/rc/activator-list.ui")]
-public class ActivatorList : Gtk.Grid, Host.Interaction {
-    private class ActivatorListItem : Gtk.Label {
-        public Backing.Activator activator;
+public class InstanceList : Gtk.Grid, Host.Interaction {
+    private class Item : Gtk.Label {
+        public Activator.Instance activator;
         
-        public ActivatorListItem(Backing.Activator activator) {
+        public Item(Activator.Instance activator) {
             this.activator = activator;
             
             label = activator.title;
@@ -28,11 +28,11 @@ public class ActivatorList : Gtk.Grid, Host.Interaction {
     [GtkChild]
     private Gtk.Button add_button;
     
-    public signal void selected(Backing.Activator activator);
+    public signal void selected(Activator.Instance activator);
     
-    public ActivatorList() {
-        foreach (Backing.Activator activator in Backing.Manager.instance.get_activators())
-            listbox.add(new ActivatorListItem(activator));
+    public InstanceList() {
+        foreach (Activator.Instance activator in activators)
+            listbox.add(new Item(activator));
         
         show_all();
     }
@@ -40,7 +40,7 @@ public class ActivatorList : Gtk.Grid, Host.Interaction {
     [GtkCallback]
     private void on_listbox_row_activated(Gtk.ListBoxRow? row) {
         if (row != null)
-            selected(((ActivatorListItem) row.get_child()).activator);
+            selected(((Item) row.get_child()).activator);
     }
     
     [GtkCallback]
diff --git a/src/backing/backing-activator.vala b/src/activator/activator-instance.vala
similarity index 75%
rename from src/backing/backing-activator.vala
rename to src/activator/activator-instance.vala
index ff6c60d..01d84e0 100644
--- a/src/backing/backing-activator.vala
+++ b/src/activator/activator-instance.vala
@@ -4,10 +4,10 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace California.Backing {
+namespace California.Activator {
 
 /**
- * Locates, validates, and authorizes access to a { link Source}.
+ * Locates, validates, and authorizes access to a { link Backing.Source}.
  *
  * Actovators are decoupled from the Backing.Source itself because it's possible for Activators
  * to be used for multiple backings.  For example, a Google Calendar Activator can be used to
@@ -15,7 +15,7 @@ namespace California.Backing {
  * backing.
  */
 
-public abstract class Activator : BaseObject {
+public abstract class Instance : BaseObject {
     public const string PROP_TITLE = "title";
     public const string PROP_STORE = "store";
     
@@ -26,20 +26,21 @@ public abstract class Activator : BaseObject {
     public string title { get; private set; }
     
     /**
-     * The { link Store} this { link Activator} will create the new { link Source} in.
+     * The { link Backing.Store} this { link Instance} will create the new { link Backing.Source}
+     * in.
      *
      * It's up to the subclass to determine which Stores will work with its information.
      */
-    public Store store { get; private set; }
+    public Backing.Store store { get; private set; }
     
-    protected Activator(string title, Store store) {
+    protected Instance(string title, Backing.Store store) {
         this.title = title;
         this.store = store;
     }
     
     /**
      * Return a { link Host.Interaction} that guides the user through the steps to create a
-     * { link Source}.
+     * { link Backing.Source}.
      */
     public abstract Host.Interaction create_interaction(Soup.URI? supplied_uri);
     
diff --git a/src/activator/activator-window.vala b/src/activator/activator-window.vala
new file mode 100644
index 0000000..89fdea7
--- /dev/null
+++ b/src/activator/activator-window.vala
@@ -0,0 +1,49 @@
+/* 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 {
+
+/**
+ * A modal window for selecting and managing { link Activator.Instance} workflows.
+ */
+
+public class Window : Host.ModalWindow {
+    private static Activator.Window? instance = null;
+    
+    private Window(Gtk.Window? parent) {
+        base (parent);
+        
+        InstanceList list = new InstanceList();
+        
+        // when an Activator instance is selected from the list, swap out the list for the
+        // Activator's own interaction
+        list.selected.connect(activator => {
+            content_area.remove(list);
+            content_area.add(activator.create_interaction(null));
+        });
+        
+        content_area.add(list);
+    }
+    
+    public static void display(Gtk.Window? parent) {
+        // only allow one instance at a time
+        if (instance != null) {
+            instance.present_with_time(Gdk.CURRENT_TIME);
+            
+            return;
+        }
+        
+        instance = new Activator.Window(parent);
+        instance.show_all();
+        instance.run();
+        instance.destroy();
+        
+        instance = null;
+    }
+}
+
+}
+
diff --git a/src/activator/activator.vala b/src/activator/activator.vala
new file mode 100644
index 0000000..2ab4c2d
--- /dev/null
+++ b/src/activator/activator.vala
@@ -0,0 +1,52 @@
+/* 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.
+ */
+
+/**
+ * Activators are front-ends (both UI and transport logic) to the various ways a calendar may be
+ * located or discovered and subscribed to.
+ *
+ * Because locating the calendar is a different task than managing a calendar subscription, and
+ * because the same Activator can work with multiple { link Backing.Store}s, they are decoupled
+ * from the { link Backing} unit.  For example, a Google Activator could locate the user's account
+ * calendar and hand it off to EDS or a GData back-end.
+ */
+
+namespace California.Activator {
+
+private int init_count = 0;
+
+private Gee.TreeSet<Instance> activators;
+
+public void init() throws Error {
+    if (!Unit.do_init(ref init_count))
+        return;
+    
+    Backing.init();
+    
+    activators = new Gee.TreeSet<Instance>(activator_comparator);
+    
+    // All Instances that work with EDS
+    Backing.EdsStore? eds_store = Backing.Manager.instance.get_store_of_type<Backing.EdsStore>()
+        as Backing.EdsStore;
+    assert(eds_store != null);
+    activators.add(new WebCalActivator(_("Web calendar (.ics)"), eds_store));
+}
+
+public void terminate() {
+    if (!Unit.do_terminate(ref init_count))
+        return;
+    
+    activators = null;
+    
+    Backing.terminate();
+}
+
+private int activator_comparator(Instance a, Instance b) {
+    return String.stricmp(a.title, b.title);
+}
+
+}
+
diff --git a/src/backing/webcal/backing-webcal-activator-pane.vala 
b/src/activator/webcal/activator-webcal-pane.vala
similarity index 92%
rename from src/backing/webcal/backing-webcal-activator-pane.vala
rename to src/activator/webcal/activator-webcal-pane.vala
index e942344..500794c 100644
--- a/src/backing/webcal/backing-webcal-activator-pane.vala
+++ b/src/activator/webcal/activator-webcal-pane.vala
@@ -4,7 +4,7 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace California.Backing {
+namespace California.Activator {
 
 [GtkTemplate (ui = "/org/yorba/california/rc/webcal-subscribe.ui")]
 internal class WebCalActivatorPane : Gtk.Grid, Host.Interaction {
@@ -22,9 +22,9 @@ internal class WebCalActivatorPane : Gtk.Grid, Host.Interaction {
     [GtkChild]
     private Gtk.Button subscribe_button;
     
-    private WebCalSubscribable store;
+    private Backing.WebCalSubscribable store;
     
-    public WebCalActivatorPane(WebCalSubscribable store, Soup.URI? supplied_url) {
+    public WebCalActivatorPane(Backing.WebCalSubscribable store, Soup.URI? supplied_url) {
         this.store = store;
         
         if (supplied_url != null) {
diff --git a/src/backing/webcal/backing-webcal-activator.vala b/src/activator/webcal/activator-webcal.vala
similarity index 67%
rename from src/backing/webcal/backing-webcal-activator.vala
rename to src/activator/webcal/activator-webcal.vala
index 8423c88..c232adb 100644
--- a/src/backing/webcal/backing-webcal-activator.vala
+++ b/src/activator/webcal/activator-webcal.vala
@@ -4,12 +4,12 @@
  * (version 2.1 or later).  See the COPYING file in this distribution.
  */
 
-namespace California.Backing {
+namespace California.Activator {
 
-internal class WebCalActivator : Activator {
-    private WebCalSubscribable webcal_store;
+internal class WebCalActivator : Instance {
+    private Backing.WebCalSubscribable webcal_store;
     
-    public WebCalActivator(string title, WebCalSubscribable store) {
+    public WebCalActivator(string title, Backing.WebCalSubscribable store) {
         base (title, store);
         
         webcal_store = store;
diff --git a/src/application/california-application.vala b/src/application/california-application.vala
index 13e9924..85e8efc 100644
--- a/src/application/california-application.vala
+++ b/src/application/california-application.vala
@@ -87,7 +87,7 @@ public class Application : Gtk.Application {
         try {
             Host.init();
             Manager.init();
-            Backing.init();
+            Activator.init();
         } catch (Error err) {
             error_message(_("Unable to open California: %s").printf(err.message));
             quit();
@@ -103,7 +103,7 @@ public class Application : Gtk.Application {
         main_window = null;
         
         // unit termination
-        Backing.terminate();
+        Activator.terminate();
         Manager.terminate();
         Host.terminate();
         
@@ -132,19 +132,7 @@ public class Application : Gtk.Application {
     }
     
     private void on_new_calendar() {
-        Host.ModalWindow modal = new Host.ModalWindow(main_window);
-        Host.ActivatorList list = new Host.ActivatorList();
-        modal.content_area.add(list);
-        
-        // when a Backing.Activator is selected from the list, swap out the list for the
-        // Activator's own interaction
-        list.selected.connect(activator => {
-            modal.content_area.remove(list);
-            modal.content_area.add(activator.create_interaction(null));
-        });
-        
-        modal.run();
-        modal.destroy();
+        Activator.Window.display(main_window);
     }
     
     private void on_calendar_manager() {
diff --git a/src/backing/backing-manager.vala b/src/backing/backing-manager.vala
index b54a3be..68b38d6 100644
--- a/src/backing/backing-manager.vala
+++ b/src/backing/backing-manager.vala
@@ -18,7 +18,6 @@ public class Manager : BaseObject {
     public bool is_open { get; private set; default = false; }
     
     private Gee.List<Store> stores = new Gee.ArrayList<Store>();
-    private Gee.List<Activator> activators = new Gee.ArrayList<Activator>();
     
     /**
      * Fired when a { link Store} cannot be opened.
@@ -43,24 +42,12 @@ public class Manager : BaseObject {
      *
      * TODO: A plugin system may make sense here.
      */
-    internal void register_store(Store store) {
+    internal void register(Store store) {
         if (!stores.contains(store))
             stores.add(store);
     }
     
     /**
-     * The various { link Activators} are registered in { link Backing.init}.
-     *
-     * This *must* be called prior to { link open_async} for them to be opened properly.
-     *
-     * TODO: A plugin system may make sense here.
-     */
-    internal void register_activator(Activator activator) {
-        if (!activators.contains(activator))
-            activators.add(activator);
-    }
-    
-    /**
      * Asynchronously open the { link Manager}.
      *
      * This must be called before any other operation on the Manager (unless noted).
@@ -116,21 +103,26 @@ public class Manager : BaseObject {
     }
     
     /**
-     * Returns a read-only list of all available { link Activator}s.
+     * Returns a read-only list of all available { link Store}s.
      *
-     * Must only be called wheil the { link Manager} is open.
+     * Must only be called while the { link Manager} is open.
      */
-    public Gee.List<Activator> get_activators() {
-        return activators.read_only_view;
+    public Gee.List<Store> get_stores() {
+        return stores.read_only_view;
     }
     
     /**
-     * Returns a read-only list of all available { link Store}s.
+     * Return a specific { link Store}.
      *
-     * Must only be called while the { link Manager} is open.
+     * This should only be used internally, specifically for { link Activator}s.
      */
-    public Gee.List<Store> get_stores() {
-        return stores.read_only_view;
+    internal Store? get_store_of_type<G>() {
+        foreach (Store store in stores) {
+            if (store.get_type().is_a(typeof(G)))
+                return store;
+        }
+        
+        return null;
     }
     
     /**
diff --git a/src/backing/backing.vala b/src/backing/backing.vala
index 14f833e..d5c5e9d 100644
--- a/src/backing/backing.vala
+++ b/src/backing/backing.vala
@@ -39,10 +39,8 @@ public void init() throws Error {
     // internal class init
     Manager.init();
     
-    // Register all Stores and Activators here
-    EdsStore eds_store = new EdsStore();
-    Manager.instance.register_store(eds_store);
-    Manager.instance.register_activator(new WebCalActivator(_("Web calendar (.ics)"), eds_store));
+    // Register all Stores here
+    Manager.instance.register(new EdsStore());
     
     // open Manager, pumping event loop until it completes (possibly w/ error)
     Manager.instance.open_async.begin(null, on_backing_manager_opened);
diff --git a/src/rc/activator-list.ui b/src/rc/activator-list.ui
index bb76ada..da0d3bc 100644
--- a/src/rc/activator-list.ui
+++ b/src/rc/activator-list.ui
@@ -2,7 +2,7 @@
 <!-- Generated with glade 3.16.1 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="CaliforniaHostActivatorList" parent="GtkGrid">
+  <template class="CaliforniaActivatorInstanceList" parent="GtkGrid">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="row_spacing">8</property>
@@ -21,7 +21,7 @@
             <property name="hexpand">True</property>
             <property name="vexpand">True</property>
             <property name="activate_on_single_click">False</property>
-            <signal name="row-activated" handler="on_listbox_row_activated" 
object="CaliforniaHostActivatorList" swapped="no"/>
+            <signal name="row-activated" handler="on_listbox_row_activated" 
object="CaliforniaActivatorInstanceList" swapped="no"/>
           </object>
         </child>
       </object>
@@ -48,7 +48,7 @@
             <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="CaliforniaHostActivatorList" 
swapped="no"/>
+            <signal name="clicked" handler="on_cancel_button_clicked" 
object="CaliforniaActivatorInstanceList" swapped="no"/>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -65,7 +65,7 @@
             <property name="has_default">True</property>
             <property name="receives_default">True</property>
             <property name="use_underline">True</property>
-            <signal name="clicked" handler="on_add_button_clicked" object="CaliforniaHostActivatorList" 
swapped="no"/>
+            <signal name="clicked" handler="on_add_button_clicked" object="CaliforniaActivatorInstanceList" 
swapped="no"/>
             <style>
               <class name="suggested-action"/>
             </style>
diff --git a/src/rc/webcal-subscribe.ui b/src/rc/webcal-subscribe.ui
index 5d1692b..a20ddd1 100644
--- a/src/rc/webcal-subscribe.ui
+++ b/src/rc/webcal-subscribe.ui
@@ -2,7 +2,7 @@
 <!-- Generated with glade 3.16.1 -->
 <interface>
   <requires lib="gtk+" version="3.10"/>
-  <template class="CaliforniaBackingWebCalActivatorPane" parent="GtkGrid">
+  <template class="CaliforniaActivatorWebCalActivatorPane" parent="GtkGrid">
     <property name="visible">True</property>
     <property name="can_focus">False</property>
     <property name="row_spacing">8</property>
@@ -128,7 +128,7 @@
             <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="CaliforniaBackingWebCalActivatorPane" swapped="no"/>
+            <signal name="clicked" handler="on_cancel_button_clicked" 
object="CaliforniaActivatorWebCalActivatorPane" swapped="no"/>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -145,7 +145,7 @@
             <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="CaliforniaBackingWebCalActivatorPane" swapped="no"/>
+            <signal name="clicked" handler="on_subscribe_button_clicked" 
object="CaliforniaActivatorWebCalActivatorPane" swapped="no"/>
             <style>
               <class name="suggested-action"/>
             </style>


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