diff --git a/js/ui/calendar.js b/js/ui/calendar.js index b3eef9c76..c01cb1fc3 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 = + ; @@ -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 54135603f..abd7da4f2 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 b0dbb2039..1cf4eb1eb 100644 --- a/src/calendar-server/calendar-sources.c +++ b/src/calendar-server/calendar-sources.c @@ -490,6 +490,17 @@ calendar_sources_registry_source_removed_cb (ESourceRegistry *registry, } } +static void +ensure_appointment_sources (CalendarSources *sources) +{ + 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) { @@ -497,12 +508,7 @@ calendar_sources_get_appointment_clients (CalendarSources *sources) 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; - } + ensure_appointment_sources (sources); list = g_hash_table_get_values (sources->priv->appointment_sources.clients); @@ -512,6 +518,17 @@ calendar_sources_get_appointment_clients (CalendarSources *sources) return list; } +static void +ensure_task_sources (CalendarSources *sources) +{ + 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) { @@ -519,12 +536,7 @@ calendar_sources_get_task_clients (CalendarSources *sources) 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; - } + 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 eed027001..1f442284a 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 e40740942..c2a76bc1c 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[] = " " " " " " + " " " " ""; 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 ();