[gnome-shell] Calendar: clean up code by always having an event source
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] Calendar: clean up code by always having an event source
- Date: Mon, 4 Mar 2013 17:59:50 +0000 (UTC)
commit beb0fdf4b86e87cffdf856b86b5f16482075941e
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Mon Mar 4 17:04:28 2013 +0100
Calendar: clean up code by always having an event source
Instead of sometimes having an event source and sometimes not, use
the empty event source when the session mode says the calendar is
disabled. This way, the code can assume an event source object and
avoid checks.
https://bugzilla.gnome.org/show_bug.cgi?id=641383
js/ui/calendar.js | 45 +++++++++++++++++----------------------------
js/ui/dateMenu.js | 7 ++++++-
2 files changed, 23 insertions(+), 29 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index 4606ed6..b3eef9c 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -169,6 +169,10 @@ const EmptyEventSource = new Lang.Class({
_init: function() {
this.isLoading = false;
+ this.isDummy = true;
+ },
+
+ destroy: function() {
},
requestRange: function(begin, end) {
@@ -231,6 +235,7 @@ const DBusEventSource = new Lang.Class({
_init: function() {
this._resetCache();
this.isLoading = false;
+ this.isDummy = false;
this._initialized = false;
this._dbusProxy = new CalendarServer();
@@ -256,6 +261,10 @@ const DBusEventSource = new Lang.Class({
}));
},
+ destroy: function() {
+ this._dbusProxy.run_dispose();
+ },
+
_resetCache: function() {
this._events = [];
this._lastRequestBegin = null;
@@ -393,19 +402,11 @@ const Calendar = new Lang.Class({
// @eventSource: is an object implementing the EventSource API, e.g. the
// requestRange(), getEvents(), hasEvents() methods and the ::changed signal.
setEventSource: function(eventSource) {
- if (this._eventSource) {
- this._eventSource.disconnect(this._eventSourceChangedId);
- this._eventSource = null;
- }
-
this._eventSource = eventSource;
-
- if (this._eventSource) {
- this._eventSourceChangedId = this._eventSource.connect('changed', Lang.bind(this, function() {
- this._update(false);
- }));
- this._update(true);
- }
+ this._eventSource.connect('changed', Lang.bind(this, function() {
+ this._update(false);
+ }));
+ this._update(true);
},
// Sets the calendar to show a specific date
@@ -579,7 +580,7 @@ const Calendar = new Lang.Class({
let button = new St.Button({ label: iter.getDate().toString() });
let rtl = button.get_text_direction() == Clutter.TextDirection.RTL;
- if (!this._eventSource)
+ if (this._eventSource.isDummy)
button.reactive = false;
let iterStr = iter.toUTCString();
@@ -588,7 +589,7 @@ const Calendar = new Lang.Class({
this.setDate(newlySelectedDate, false);
}));
- let hasEvents = this._eventSource && this._eventSource.hasEvents(iter);
+ let hasEvents = this._eventSource.hasEvents(iter);
let styleClass = 'calendar-day-base calendar-day';
if (_isWorkDay(iter))
@@ -636,8 +637,7 @@ const Calendar = new Lang.Class({
}
// Signal to the event source that we are interested in events
// only from this date range
- if (this._eventSource)
- this._eventSource.requestRange(beginDate, iter, forceReload);
+ this._eventSource.requestRange(beginDate, iter, forceReload);
}
});
@@ -655,16 +655,8 @@ const EventsList = new Lang.Class({
},
setEventSource: function(eventSource) {
- if (this._eventSource) {
- this._eventSource.disconnect(this._eventSourceChangedId);
- this._eventSource = null;
- }
-
this._eventSource = eventSource;
-
- if (this._eventSource) {
- this._eventSourceChangedId = this._eventSource.connect('changed', Lang.bind(this, this._update));
- }
+ this._eventSource.connect('changed', Lang.bind(this, this._update));
},
_addEvent: function(dayNameBox, timeBox, eventTitleBox, includeDayName, day, time, desc) {
@@ -681,9 +673,6 @@ const EventsList = new Lang.Class({
},
_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 0529b30..5413560 100644
--- a/js/ui/dateMenu.js
+++ b/js/ui/dateMenu.js
@@ -177,8 +177,13 @@ const DateMenuButton = new Lang.Class({
},
_setEventSource: function(eventSource) {
+ if (this._eventSource)
+ this._eventSource.destroy();
+
this._calendar.setEventSource(eventSource);
this._eventList.setEventSource(eventSource);
+
+ this._eventSource = eventSource;
},
_sessionUpdated: function() {
@@ -187,7 +192,7 @@ const DateMenuButton = new Lang.Class({
if (showEvents) {
eventSource = new Calendar.DBusEventSource();
} else {
- eventSource = null;
+ eventSource = new Calendar.EmptyEventSource();
}
this._setEventSource(eventSource);
this._setEventsVisibility(showEvents);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]