[california/wip/725763-manager] Refinements, the visible checkbox is hooked up



commit 6172e357bca29d2f96cad9976d789c9562ad69d8
Author: Jim Nelson <jim yorba org>
Date:   Wed Mar 12 19:39:11 2014 -0700

    Refinements, the visible checkbox is hooked up

 src/Makefile.am                                  |    2 +-
 src/application/california-application.vala      |   18 +++++++-
 src/backing/backing-manager.vala                 |    2 +-
 src/backing/backing-source.vala                  |   14 ++++++
 src/backing/eds/backing-eds-calendar-source.vala |    8 ++++
 src/california-resources.xml                     |    3 -
 src/host/host-create-update-event.vala           |    3 +
 src/host/host-main-window.vala                   |    6 +++
 src/host/host-modal-window.vala                  |   26 ++++++++++++
 src/host/host-popup.vala                         |    2 +-
 src/manager/manager-calendar-list-item.vala      |    8 ++-
 src/manager/manager-calendar-list.vala           |    5 --
 src/manager/manager-controller.vala              |    2 +-
 src/manager/manager-dialog.vala                  |   32 ++++++++++-----
 src/rc/app-menu.interface                        |    6 ++-
 src/rc/calendar-manager-dialog.ui                |   47 ----------------------
 src/rc/calendar-manager-list-item.ui             |    5 +-
 src/rc/calendar-manager-list.ui                  |   18 --------
 src/util/util-string.vala                        |    4 ++
 src/view/month/month-cell.vala                   |    3 +
 src/view/month/month-controllable.vala           |    1 +
 21 files changed, 118 insertions(+), 97 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2c41ca1..805c404 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -65,6 +65,7 @@ california_VALASOURCES = \
        host/host-create-update-event.vala \
        host/host-interaction.vala \
        host/host-main-window.vala \
+       host/host-modal-window.vala \
        host/host-popup.vala \
        host/host-show-event.vala \
        \
@@ -93,7 +94,6 @@ california_SOURCES = \
 
 california_RC = \
        rc/app-menu.interface \
-       rc/calendar-manager-dialog.ui \
        rc/calendar-manager-list.ui \
        rc/calendar-manager-list-item.ui \
        rc/create-update-event.ui \
diff --git a/src/application/california-application.vala b/src/application/california-application.vala
index 4e60429..d42d122 100644
--- a/src/application/california-application.vala
+++ b/src/application/california-application.vala
@@ -29,7 +29,13 @@ public class Application : Gtk.Application {
         null
     };
     
+    public const string ACTION_ADD_CALENDAR = "app.add-calendar";
+    public const string ACTION_CALENDAR_MANAGER = "app.calendar-manager";
+    public const string ACTION_ABOUT = "app.about";
+    public const string ACTION_QUIT = "app.quit";
+    
     private static const ActionEntry[] action_entries = {
+        { "add-calendar", on_add_calendar },
         { "calendar-manager", on_calendar_manager },
         { "about", on_about },
         { "quit", on_quit }
@@ -116,10 +122,16 @@ public class Application : Gtk.Application {
         dialog.destroy();
     }
     
+    private void on_add_calendar() {
+        show_calendar_manager(true);
+    }
+    
     private void on_calendar_manager() {
-        Manager.Dialog dialog = new Manager.Dialog(main_window);
-        dialog.run();
-        dialog.destroy();
+        show_calendar_manager(false);
+    }
+    
+    private void show_calendar_manager(bool show_add_calendar) {
+        Manager.Dialog.display(main_window, show_add_calendar);
     }
     
     private void on_about() {
diff --git a/src/backing/backing-manager.vala b/src/backing/backing-manager.vala
index 99478b1..4ce555b 100644
--- a/src/backing/backing-manager.vala
+++ b/src/backing/backing-manager.vala
@@ -126,7 +126,7 @@ public class Manager : BaseObject {
             sources.add_all(store.get_sources_of_type<G>());
         
         sources.sort((a, b) => {
-            return strcmp(((Source) a).title, ((Source) b).title);
+            return String.stricmp(((Source) a).title, ((Source) b).title);
         });
         
         return sources;
diff --git a/src/backing/backing-source.vala b/src/backing/backing-source.vala
index 4517c92..022c9c6 100644
--- a/src/backing/backing-source.vala
+++ b/src/backing/backing-source.vala
@@ -18,6 +18,8 @@ namespace California.Backing {
 
 public abstract class Source : BaseObject {
     public const string PROP_IS_AVAILABLE = "is-available";
+    public const string PROP_TITLE = "title";
+    public const string PROP_VISIBLE = "visible";
     
     /**
      * True if the { link Source} is unavailable for use due to being removed from it's
@@ -35,6 +37,18 @@ public abstract class Source : BaseObject {
      */
     public string title { get; private set; }
     
+    /**
+     * Whether the { link Source} should be visible to the user.
+     *
+     * The caller should monitor this setting to decide whether or not to display the Source's
+     * associated inforamtion.  Hiding a Source does not mean that a Source subscription won't
+     * continue generating information.  Likewise, a hidden Source can still accept operations
+     * like adding and removing objects.
+     *
+     * @see CalendarSourceSubscription
+     */
+    public bool visible { get; set; }
+    
     protected Source(string title) {
         this.title = title;
     }
diff --git a/src/backing/eds/backing-eds-calendar-source.vala 
b/src/backing/eds/backing-eds-calendar-source.vala
index d4e6ecc..197f686 100644
--- a/src/backing/eds/backing-eds-calendar-source.vala
+++ b/src/backing/eds/backing-eds-calendar-source.vala
@@ -20,6 +20,14 @@ internal class EdsCalendarSource : CalendarSource {
         
         this.eds_source = eds_source;
         this.eds_calendar = eds_calendar;
+        
+        visible = eds_calendar.selected;
+        
+        notify[PROP_VISIBLE].connect(on_visible_changed);
+    }
+    
+    private void on_visible_changed() {
+        debug("%s visible=%s", to_string(), visible.to_string());
     }
     
     // Invoked by EdsStore prior to making it available outside of unit
diff --git a/src/california-resources.xml b/src/california-resources.xml
index 4c390e8..3a514fb 100644
--- a/src/california-resources.xml
+++ b/src/california-resources.xml
@@ -4,9 +4,6 @@
         <file compressed="true">rc/app-menu.interface</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
-        <file compressed="false">rc/calendar-manager-dialog.ui</file>
-    </gresource>
-    <gresource prefix="/org/yorba/california">
         <file compressed="false">rc/calendar-manager-list.ui</file>
     </gresource>
     <gresource prefix="/org/yorba/california">
diff --git a/src/host/host-create-update-event.vala b/src/host/host-create-update-event.vala
index 4e350d8..55606ac 100644
--- a/src/host/host-create-update-event.vala
+++ b/src/host/host-create-update-event.vala
@@ -168,6 +168,9 @@ public class CreateUpdateEvent : Gtk.Grid, Interaction {
         index = 0;
         int calendar_source_index = 0;
         foreach (Backing.Source source in calendar_sources) {
+            if (!source.visible)
+                continue;
+            
             calendar_combo.append_text(source.title);
             if (source == event.calendar_source)
                 calendar_source_index = index;
diff --git a/src/host/host-main-window.vala b/src/host/host-main-window.vala
index c4d7619..25d427e 100644
--- a/src/host/host-main-window.vala
+++ b/src/host/host-main-window.vala
@@ -60,8 +60,14 @@ public class MainWindow : Gtk.ApplicationWindow {
         new_event.tooltip_text = _("Create a new event for today");
         new_event.clicked.connect(on_new_event);
         
+        Gtk.Button calendars = new Gtk.Button.from_icon_name("x-office-calendar-symbolic",
+            Gtk.IconSize.MENU);
+        calendars.tooltip_text = _("Calendars (Ctrl+L)");
+        calendars.set_action_name(Application.ACTION_CALENDAR_MANAGER);
+        
         // pack right-side of window
         headerbar.pack_end(new_event);
+        headerbar.pack_end(calendars);
         
         Gtk.Box layout = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
         layout.pack_end(month_view, true, true, 0);
diff --git a/src/host/host-modal-window.vala b/src/host/host-modal-window.vala
new file mode 100644
index 0000000..6596feb
--- /dev/null
+++ b/src/host/host-modal-window.vala
@@ -0,0 +1,26 @@
+/* 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.Host {
+
+public class ModalWindow : Gtk.Dialog {
+    public Gtk.Box content_area { get; private set; }
+    
+    public ModalWindow(Gtk.Window? parent, string? title) {
+        transient_for = parent;
+        this.title = title;
+        modal = true;
+        
+        content_area = (Gtk.Box) get_content_area();
+        content_area.margin = 4;
+        
+        get_action_area().visible = false;
+        get_action_area().no_show_all = true;
+    }
+}
+
+}
+
diff --git a/src/host/host-popup.vala b/src/host/host-popup.vala
index b40dd54..5219753 100644
--- a/src/host/host-popup.vala
+++ b/src/host/host-popup.vala
@@ -30,7 +30,7 @@ public class Popup : Gtk.Window {
      * The GtkWidget must be realized when this is invoked.
      */
     public Popup(Gtk.Widget relative_to) {
-        Object (type:Gtk.WindowType.TOPLEVEL);
+        Object(type:Gtk.WindowType.TOPLEVEL);
         
         assert(relative_to.get_realized());
         this.relative_to = relative_to;
diff --git a/src/manager/manager-calendar-list-item.vala b/src/manager/manager-calendar-list-item.vala
index 856c8f8..df78ad8 100644
--- a/src/manager/manager-calendar-list-item.vala
+++ b/src/manager/manager-calendar-list-item.vala
@@ -11,7 +11,7 @@ public class CalendarListItem : Gtk.Grid {
     public Backing.CalendarSource source { get; private set; }
     
     [GtkChild]
-    private Gtk.CheckButton enabled_check_button;
+    private Gtk.CheckButton visible_check_button;
     
     [GtkChild]
     private Gtk.Label title_label;
@@ -19,8 +19,10 @@ public class CalendarListItem : Gtk.Grid {
     public CalendarListItem(Backing.CalendarSource source) {
         this.source = source;
         
-        enabled_check_button.active = source.is_available;
-        title_label.label = source.title;
+        source.bind_property(Backing.Source.PROP_TITLE, title_label, "label",
+            BindingFlags.SYNC_CREATE);
+        source.bind_property(Backing.Source.PROP_VISIBLE, visible_check_button, "active",
+            BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
     }
 }
 
diff --git a/src/manager/manager-calendar-list.vala b/src/manager/manager-calendar-list.vala
index 8da3a0f..ba8309c 100644
--- a/src/manager/manager-calendar-list.vala
+++ b/src/manager/manager-calendar-list.vala
@@ -42,11 +42,6 @@ public class CalendarList : Gtk.Grid {
     }
     
     [GtkCallback]
-    private void on_new_button_clicked() {
-        debug("new");
-    }
-    
-    [GtkCallback]
     private void on_calendar_list_box_row_activated(Gtk.ListBoxRow row) {
         CalendarListItem item = (CalendarListItem) row.get_child();
         debug("activated %s", item.source.to_string());
diff --git a/src/manager/manager-controller.vala b/src/manager/manager-controller.vala
index 0c18da3..9f918e0 100644
--- a/src/manager/manager-controller.vala
+++ b/src/manager/manager-controller.vala
@@ -9,7 +9,7 @@ namespace California.Manager {
 public class Controller : Gtk.Stack {
     private CalendarList calendar_list = new CalendarList();
     
-    public Controller() {
+    public Controller(bool show_add_calendar) {
         add(calendar_list);
         
         set_visible_child(calendar_list);
diff --git a/src/manager/manager-dialog.vala b/src/manager/manager-dialog.vala
index 4d533c2..9c6e3d6 100644
--- a/src/manager/manager-dialog.vala
+++ b/src/manager/manager-dialog.vala
@@ -6,20 +6,32 @@
 
 namespace California.Manager {
 
-[GtkTemplate (ui = "/org/yorba/california/rc/calendar-manager-dialog.ui")]
-public class Dialog : Gtk.Dialog {
-    private Manager.Controller controller = new Manager.Controller();
+public class Dialog : Host.ModalWindow {
+    private static Manager.Dialog? instance = null;
     
-    public Dialog(Gtk.Window? parent) {
-        transient_for = parent;
+    private Manager.Controller controller;
+    
+    private Dialog(Gtk.Window? parent, bool show_add_calendar) {
+        base (parent, _("Calendar Manager"));
         
-        ((Gtk.Box) get_content_area()).pack_start(controller, true, true, 8);
-        show_all();
+        controller = new Controller(show_add_calendar);
+        content_area.add(controller);
     }
     
-    [GtkCallback]
-    private void on_close_button_clicked() {
-        response(Gtk.ResponseType.CLOSE);
+    public static void display(Gtk.Window? parent, bool show_add_calendar) {
+        // only allow one instance at a time
+        if (instance != null) {
+            instance.present_with_time(Gdk.CURRENT_TIME);
+            
+            return;
+        }
+        
+        instance = new Manager.Dialog(parent, show_add_calendar);
+        instance.show_all();
+        instance.run();
+        instance.destroy();
+        
+        instance = null;
     }
 }
 
diff --git a/src/rc/app-menu.interface b/src/rc/app-menu.interface
index 386e414..e73539a 100644
--- a/src/rc/app-menu.interface
+++ b/src/rc/app-menu.interface
@@ -3,9 +3,13 @@
     <menu id="app-menu">
         <section>
             <item>
+                <attribute name="label" translatable="yes">A_dd or create calendar...</attribute>
+                <attribute name="action">app.add-calendar</attribute>
+            </item>
+            <item>
                 <attribute name="label" translatable="yes">_Calendars</attribute>
                 <attribute name="action">app.calendar-manager</attribute>
-                <attribute name="accel">&lt;Primary&gt;m</attribute>
+                <attribute name="accel">&lt;Primary&gt;l</attribute>
             </item>
         </section>
         <section>
diff --git a/src/rc/calendar-manager-list-item.ui b/src/rc/calendar-manager-list-item.ui
index a65688d..b081b42 100644
--- a/src/rc/calendar-manager-list-item.ui
+++ b/src/rc/calendar-manager-list-item.ui
@@ -7,14 +7,13 @@
     <property name="can_focus">False</property>
     <property name="column_spacing">4</property>
     <child>
-      <object class="GtkCheckButton" id="enabled_check_button">
+      <object class="GtkCheckButton" id="visible_check_button">
         <property name="visible">True</property>
         <property name="can_focus">True</property>
         <property name="receives_default">False</property>
         <property name="halign">start</property>
         <property name="valign">center</property>
-        <property name="xalign">0</property>
-        <property name="yalign">0.50999999046325684</property>
+        <property name="xalign">0.50999999046325684</property>
         <property name="draw_indicator">True</property>
         <child>
           <placeholder/>
diff --git a/src/rc/calendar-manager-list.ui b/src/rc/calendar-manager-list.ui
index 3727c21..62dbe1b 100644
--- a/src/rc/calendar-manager-list.ui
+++ b/src/rc/calendar-manager-list.ui
@@ -20,23 +20,5 @@
         <property name="height">1</property>
       </packing>
     </child>
-    <child>
-      <object class="GtkButton" id="new_button">
-        <property name="label" translatable="yes">_New calendar...</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="margin_top">8</property>
-        <property name="use_underline">True</property>
-        <signal name="clicked" handler="on_new_button_clicked" object="CaliforniaManagerCalendarList" 
swapped="no"/>
-      </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>
   </template>
 </interface>
diff --git a/src/util/util-string.vala b/src/util/util-string.vala
index af7c6b9..070c9d3 100644
--- a/src/util/util-string.vala
+++ b/src/util/util-string.vala
@@ -12,5 +12,9 @@ public inline bool is_empty(string? str) {
     return (str == null) || (str[0] == NUL);
 }
 
+public int stricmp(string a, string b) {
+    return strcmp(a.casefold(), b.casefold());
+}
+
 }
 
diff --git a/src/view/month/month-cell.vala b/src/view/month/month-cell.vala
index ff7e0d9..80e01de 100644
--- a/src/view/month/month-cell.vala
+++ b/src/view/month/month-cell.vala
@@ -243,6 +243,9 @@ public class Cell : Gtk.EventBox {
         // draw all events in chronological order, all-day events first, storing lookup data
         // as the "lines" are drawn ... make sure to convert them all to local timezone
         foreach (Component.Event event in days_events) {
+            if (!event.calendar_source.visible)
+                continue;
+            
             string text;
             if (event.is_all_day) {
                 text = event.summary;
diff --git a/src/view/month/month-controllable.vala b/src/view/month/month-controllable.vala
index a1a0e74..bff8f18 100644
--- a/src/view/month/month-controllable.vala
+++ b/src/view/month/month-controllable.vala
@@ -265,6 +265,7 @@ public class Controllable : Gtk.Grid, View.Controllable {
         foreach (Backing.Store store in Backing.Manager.instance.get_stores()) {
             foreach (Backing.Source source in store.get_sources_of_type<Backing.CalendarSource>()) {
                 Backing.CalendarSource calendar = (Backing.CalendarSource) source;
+                calendar.notify[Backing.Source.PROP_VISIBLE].connect(queue_draw);
                 calendar.subscribe_async.begin(time_window, null, on_subscribed);
             }
         }


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