From b6c2399a17ae88dc840fa27b14d2b06462920c79 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 22 Aug 2011 14:21:51 -0400 Subject: [PATCH] dateMenu: Make events list optional Right now, when a user clicks on the panel clock, a menu pops up with a calendar and a list of events from the user's schedule. The list of events only makes sense from within a user's session, however. As part of the prep work for making the shell a platform for the login screen, this commit makes the events list optional. https://bugzilla.gnome.org/show_bug.cgi?id=657082 --- js/ui/calendar.js | 23 ++++++++++++++------ js/ui/dateMenu.js | 54 +++++++++++++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 27 deletions(-) diff --git a/js/ui/calendar.js b/js/ui/calendar.js index f5448f07b..612c90381 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -351,12 +351,14 @@ function Calendar(eventSource) { Calendar.prototype = { _init: function(eventSource) { - this._eventSource = eventSource; + if (eventSource) { + this._eventSource = eventSource; - this._eventSource.connect('changed', Lang.bind(this, - function() { - this._update(false); - })); + this._eventSource.connect('changed', Lang.bind(this, + function() { + this._update(false); + })); + } this._weekStart = Shell.util_get_week_start(); this._weekdate = NaN; @@ -554,13 +556,16 @@ Calendar.prototype = { while (true) { let button = new St.Button({ label: iter.getDate().toString() }); + if (!this._eventSource) + button.reactive = false; + let iterStr = iter.toUTCString(); button.connect('clicked', Lang.bind(this, function() { let newlySelectedDate = new Date(iterStr); this.setDate(newlySelectedDate, false); })); - let hasEvents = this._eventSource.hasEvents(iter); + let hasEvents = this._eventSource && this._eventSource.hasEvents(iter); let styleClass = 'calendar-day-base calendar-day'; if (_isWorkDay(iter)) styleClass += ' calendar-work-day' @@ -607,7 +612,8 @@ Calendar.prototype = { } // Signal to the event source that we are interested in events // only from this date range - this._eventSource.requestRange(beginDate, iter, forceReload); + if (this._eventSource) + this._eventSource.requestRange(beginDate, iter, forceReload); } }; @@ -644,6 +650,9 @@ EventsList.prototype = { }, _addPeriod: function(header, begin, end, includeDayName, showNothingScheduled) { + if (!this._eventSource) + return; + let events = this._eventSource.getEvents(begin, end); let clockFormat = this._desktopSettings.get_string(CLOCK_FORMAT_KEY);; diff --git a/js/ui/dateMenu.js b/js/ui/dateMenu.js index 1855c3a54..dbab33648 100644 --- a/js/ui/dateMenu.js +++ b/js/ui/dateMenu.js @@ -9,6 +9,7 @@ const Clutter = imports.gi.Clutter; const Shell = imports.gi.Shell; const St = imports.gi.St; +const Params = imports.misc.params; const Util = imports.misc.util; const Main = imports.ui.main; const PanelMenu = imports.ui.panelMenu; @@ -40,19 +41,19 @@ function _onVertSepRepaint (area) }; function DateMenuButton() { - this._init(); + this._init.apply(this, arguments); } DateMenuButton.prototype = { __proto__: PanelMenu.Button.prototype, - _init: function() { + _init: function(params) { + params = Params.parse(params, { showEvents: true }); + let item; let hbox; let vbox; - this._eventSource = new Calendar.DBusEventSource(); - let menuAlignment = 0.25; if (St.Widget.get_default_direction() == St.TextDirection.RTL) menuAlignment = 1.0 - menuAlignment; @@ -74,12 +75,23 @@ DateMenuButton.prototype = { this._date.style_class = 'datemenu-date-label'; vbox.add(this._date); - this._eventList = new Calendar.EventsList(this._eventSource); + if (params.showEvents) { + this._eventSource = new Calendar.DBusEventSource(); + this._eventList = new Calendar.EventsList(this._eventSource); + } else { + this._eventSource = null; + this._eventList = null; + } // Calendar this._calendar = new Calendar.Calendar(this._eventSource); + this._calendar.connect('selected-date-changed', Lang.bind(this, function(calendar, date) { + // we know this._eventList is defined here, because selected-data-changed + // only gets emitted when the user clicks a date in the calendar, + // and the calender makes those dates unclickable when instantiated with + // a null event source this._eventList.setDate(date); })); vbox.add(this._calendar.actor); @@ -93,25 +105,27 @@ DateMenuButton.prototype = { item.actor.can_focus = false; item.actor.reparent(vbox); - // Add vertical separator + if (params.showEvents) { + // Add vertical separator - item = new St.DrawingArea({ style_class: 'calendar-vertical-separator', - pseudo_class: 'highlighted' }); - item.connect('repaint', Lang.bind(this, _onVertSepRepaint)); - hbox.add(item); + item = new St.DrawingArea({ style_class: 'calendar-vertical-separator', + pseudo_class: 'highlighted' }); + item.connect('repaint', Lang.bind(this, _onVertSepRepaint)); + hbox.add(item); - // Fill up the second column - vbox = new St.BoxLayout({name: 'calendarEventsArea', - vertical: true}); - hbox.add(vbox, { expand: true }); + // Fill up the second column + vbox = new St.BoxLayout({name: 'calendarEventsArea', + vertical: true}); + hbox.add(vbox, { expand: true }); - // Event list - vbox.add(this._eventList.actor, { expand: true }); + // Event list + vbox.add(this._eventList.actor, { expand: true }); - item = new PopupMenu.PopupMenuItem(_("Open Calendar")); - item.connect('activate', Lang.bind(this, this._onOpenCalendarActivate)); - item.actor.can_focus = false; - vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false}); + item = new PopupMenu.PopupMenuItem(_("Open Calendar")); + item.connect('activate', Lang.bind(this, this._onOpenCalendarActivate)); + item.actor.can_focus = false; + vbox.add(item.actor, {y_align: St.Align.END, expand: true, y_fill: false}); + } // Whenever the menu is opened, select today this.menu.connect('open-state-changed', Lang.bind(this, function(menu, isOpen) {