[gnome-shell] Calendar: only show events when configured in Evolution



commit ee509041476477f594e138d97cd586bbd4939614
Author: Giovanni Campagna <gcampagna src gnome org>
Date:   Mon Oct 29 16:37:07 2012 +0100

    Calendar: only show events when configured in Evolution
    
    When no calendars are enabled, hide the events pane completely instead
    of showing it empty.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=680083

 js/ui/calendar.js                                 |   17 ++++++-
 js/ui/dateMenu.js                                 |    9 +++-
 src/calendar-server/calendar-sources.c            |   48 +++++++++++++++-----
 src/calendar-server/calendar-sources.h            |    2 +
 src/calendar-server/gnome-shell-calendar-server.c |   31 +++++++++++++
 5 files changed, 91 insertions(+), 16 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index b3eef9c..c01cb1f 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -170,6 +170,7 @@ const EmptyEventSource = new Lang.Class({
     _init: function() {
         this.isLoading = false;
         this.isDummy = true;
+        this.hasCalendars = false;
     },
 
     destroy: function() {
@@ -196,6 +197,7 @@ const CalendarServerIface = <interface name="org.gnome.Shell.CalendarServer">
     <arg type="b" direction="in" />
     <arg type="a(sssbxxa{sv})" direction="out" />
 </method>
+<property name="HasCalendars" type="b" access="read" />
 <signal name="Changed" />
 </interface>;
 
@@ -206,8 +208,7 @@ function CalendarServer() {
                                g_interface_name: CalendarServerInfo.name,
                                g_interface_info: CalendarServerInfo,
                                g_name: 'org.gnome.Shell.CalendarServer',
-                               g_object_path: '/org/gnome/Shell/CalendarServer',
-                               g_flags: Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES });
+                               g_object_path: '/org/gnome/Shell/CalendarServer' });
 }
 
 function _datesEqual(a, b) {
@@ -256,7 +257,12 @@ const DBusEventSource = new Lang.Class({
                     this._onNameVanished();
             }));
 
+            this._dbusProxy.connect('g-properties-changed', Lang.bind(this, function() {
+                this.emit('notify::has-calendars');
+            }));
+
             this._initialized = true;
+            this.emit('notify::has-calendars');
             this._onNameAppeared();
         }));
     },
@@ -265,6 +271,13 @@ const DBusEventSource = new Lang.Class({
         this._dbusProxy.run_dispose();
     },
 
+    get hasCalendars() {
+        if (this._initialized)
+            return this._dbusProxy.HasCalendars;
+        else
+            return false;
+    },
+
     _resetCache: function() {
         this._events = [];
         this._lastRequestBegin = null;
diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js
index 5413560..abd7da4 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -161,8 +161,10 @@ const DateMenuButton = new Lang.Class({
         this._openClocksItem.actor.visible = app !== null;
     },
 
-    _setEventsVisibility: function(visible) {
+    _updateEventsVisibility: function() {
+        let visible = this._eventSource.hasCalendars;
         this._openCalendarItem.actor.visible = visible;
+        this._openClocksItem.actor.visible = visible;
         this._separator.visible = visible;
         if (visible) {
           let alignment = 0.25;
@@ -184,6 +186,9 @@ const DateMenuButton = new Lang.Class({
         this._eventList.setEventSource(eventSource);
 
         this._eventSource = eventSource;
+        this._eventSource.connect('notify::has-calendars', Lang.bind(this, function() {
+            this._updateEventsVisibility();
+        }));
     },
 
     _sessionUpdated: function() {
@@ -195,7 +200,7 @@ const DateMenuButton = new Lang.Class({
             eventSource = new Calendar.EmptyEventSource();
         }
         this._setEventSource(eventSource);
-        this._setEventsVisibility(showEvents);
+        this._updateEventsVisibility();
 
         // This needs to be handled manually, as the code to
         // autohide separators doesn't work across the vbox
diff --git a/src/calendar-server/calendar-sources.c b/src/calendar-server/calendar-sources.c
index b0dbb20..1cf4eb1 100644
--- a/src/calendar-server/calendar-sources.c
+++ b/src/calendar-server/calendar-sources.c
@@ -490,19 +490,25 @@ calendar_sources_registry_source_removed_cb (ESourceRegistry *registry,
     }
 }
 
-GList *
-calendar_sources_get_appointment_clients (CalendarSources *sources)
+static void
+ensure_appointment_sources (CalendarSources *sources)
 {
-  GList *list, *link;
-
-  g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
-
   if (!sources->priv->appointment_sources.loaded)
     {
       calendar_sources_load_esource_list (sources->priv->registry,
                                           &sources->priv->appointment_sources);
       sources->priv->appointment_sources.loaded = TRUE;
     }
+}
+
+GList *
+calendar_sources_get_appointment_clients (CalendarSources *sources)
+{
+  GList *list, *link;
+
+  g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
+
+  ensure_appointment_sources (sources);
 
   list = g_hash_table_get_values (sources->priv->appointment_sources.clients);
 
@@ -512,19 +518,25 @@ calendar_sources_get_appointment_clients (CalendarSources *sources)
   return list;
 }
 
-GList *
-calendar_sources_get_task_clients (CalendarSources *sources)
+static void
+ensure_task_sources (CalendarSources *sources)
 {
-  GList *list, *link;
-
-  g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
-
   if (!sources->priv->task_sources.loaded)
     {
       calendar_sources_load_esource_list (sources->priv->registry,
                                           &sources->priv->task_sources);
       sources->priv->task_sources.loaded = TRUE;
     }
+}
+
+GList *
+calendar_sources_get_task_clients (CalendarSources *sources)
+{
+  GList *list, *link;
+
+  g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), NULL);
+
+  ensure_task_sources (sources);
 
   list = g_hash_table_get_values (sources->priv->task_sources.clients);
 
@@ -533,3 +545,15 @@ calendar_sources_get_task_clients (CalendarSources *sources)
 
   return list;
 }
+
+gboolean
+calendar_sources_has_sources (CalendarSources *sources)
+{
+  g_return_val_if_fail (CALENDAR_IS_SOURCES (sources), FALSE);
+
+  ensure_appointment_sources (sources);
+  ensure_task_sources (sources);
+
+  return g_hash_table_size (sources->priv->appointment_sources.clients) > 0 ||
+    g_hash_table_size (sources->priv->task_sources.clients) > 0;
+}
diff --git a/src/calendar-server/calendar-sources.h b/src/calendar-server/calendar-sources.h
index eed0270..1f44228 100644
--- a/src/calendar-server/calendar-sources.h
+++ b/src/calendar-server/calendar-sources.h
@@ -61,6 +61,8 @@ CalendarSources *calendar_sources_get                     (void);
 GList           *calendar_sources_get_appointment_clients (CalendarSources *sources);
 GList           *calendar_sources_get_task_clients        (CalendarSources *sources);
 
+gboolean         calendar_sources_has_sources             (CalendarSources *sources);
+
 G_END_DECLS
 
 #endif /* __CALENDAR_SOURCES_H__ */
diff --git a/src/calendar-server/gnome-shell-calendar-server.c 
b/src/calendar-server/gnome-shell-calendar-server.c
index e407409..c2a76bc 100644
--- a/src/calendar-server/gnome-shell-calendar-server.c
+++ b/src/calendar-server/gnome-shell-calendar-server.c
@@ -57,6 +57,7 @@ static const gchar introspection_xml[] =
   "    <signal name='Changed'/>"
   "    <property name='Since' type='x' access='read'/>"
   "    <property name='Until' type='x' access='read'/>"
+  "    <property name='HasCalendars' type='b' access='read'/>"
   "  </interface>"
   "</node>";
 static GDBusNodeInfo *introspection_data = NULL;
@@ -726,6 +727,12 @@ app_load_events (App *app)
   app->cache_invalid = FALSE;
 }
 
+static gboolean
+app_has_calendars (App *app)
+{
+  return calendar_sources_has_sources (app->sources);
+}
+
 static void
 on_appointment_sources_changed (CalendarSources *sources,
                                 gpointer         user_data)
@@ -734,6 +741,26 @@ on_appointment_sources_changed (CalendarSources *sources,
 
   print_debug ("Sources changed\n");
   app_load_events (app);
+
+  /* Notify the HasCalendars property */
+  {
+    GVariantBuilder dict_builder;
+
+    g_variant_builder_init (&dict_builder, G_VARIANT_TYPE ("a{sv}"));
+    g_variant_builder_add (&dict_builder, "{sv}", "HasCalendars",
+                           g_variant_new_boolean (app_has_calendars (app)));
+
+    g_dbus_connection_emit_signal (g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL),
+                                   NULL,
+                                   "/org/gnome/Shell/CalendarServer",
+                                   "org.freedesktop.DBus.Properties",
+                                   "PropertiesChanged",
+                                   g_variant_new ("(sa{sv}as)",
+                                                  "org.gnome.Shell.CalendarServer",
+                                                  &dict_builder,
+                                                  NULL),
+                                   NULL);
+  }
 }
 
 static App *
@@ -933,6 +960,10 @@ handle_get_property (GDBusConnection *connection,
     {
       ret = g_variant_new_int64 (app->until);
     }
+  else if (g_strcmp0 (property_name, "HasCalendars") == 0)
+    {
+      ret = g_variant_new_boolean (app_has_calendars (app));
+    }
   else
     {
       g_assert_not_reached ();


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