[gnome-shell] calendar: Factor out a proper EventMessage class
- From: Florian Müllner <fmuellner src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] calendar: Factor out a proper EventMessage class
- Date: Thu, 12 Mar 2015 16:33:21 +0000 (UTC)
commit d1efc274e5ee985a75e7b752fc2044a2ddcd3a4c
Author: Florian Müllner <fmuellner gnome org>
Date: Wed Mar 11 23:04:55 2015 +0100
calendar: Factor out a proper EventMessage class
While messages in the EventsSection are currently simple enough to
use the generic Message baseclass, the design calls for events to
only be dismissable on the current day. We will need a subclass to
implement this behavior cleanly, so add one.
https://bugzilla.gnome.org/show_bug.cgi?id=744927
js/ui/calendar.js | 77 +++++++++++++++++++++++++++++++---------------------
1 files changed, 46 insertions(+), 31 deletions(-)
---
diff --git a/js/ui/calendar.js b/js/ui/calendar.js
index dad8179..2f1fac0 100644
--- a/js/ui/calendar.js
+++ b/js/ui/calendar.js
@@ -72,21 +72,6 @@ function _getEndOfDay(date) {
return ret;
}
-function _formatEventTime(event, periodBegin, periodEnd) {
- let ret;
- let allDay = (event.allDay || (event.date <= periodBegin && event.end >= periodEnd));
- if (allDay) {
- /* Translators: Shown in calendar event list for all day events
- * Keep it short, best if you can use less then 10 characters
- */
- ret = C_("event list time", "All Day");
- } else {
- let date = event.date >= periodBegin ? event.date : event.end;
- ret = Util.formatTime(date, { timeOnly: true });
- }
- return ret;
-}
-
function _getCalendarDayAbbreviation(dayNumber) {
let abbreviations = [
/* Translators: Calendar grid abbreviation for Sunday.
@@ -1171,6 +1156,51 @@ const Message = new Lang.Class({
});
Signals.addSignalMethods(Message.prototype);
+const EventMessage = new Lang.Class({
+ Name: 'EventMessage',
+ Extends: Message,
+
+ _init: function(event, date) {
+ this._event = event;
+ this._date = date;
+
+ this.parent(this._formatEventTime(), event.summary);
+ },
+
+ _formatEventTime: function() {
+ let periodBegin = _getBeginningOfDay(this._date);
+ let periodEnd = _getEndOfDay(this._date);
+ let allDay = (this._event.allDay || (this._event.date <= periodBegin &&
+ this._event.end >= periodEnd));
+ let title;
+ if (allDay) {
+ /* Translators: Shown in calendar event list for all day events
+ * Keep it short, best if you can use less then 10 characters
+ */
+ title = C_("event list time", "All Day");
+ } else {
+ let date = this._event.date >= periodBegin ? this._event.date
+ : this._event.end;
+ title = Util.formatTime(date, { timeOnly: true });
+ }
+
+ let rtl = Clutter.get_default_text_direction() == Clutter.TextDirection.RTL;
+ if (this._event.date < periodBegin && !this._event.allDay) {
+ if (rtl)
+ title = title + ELLIPSIS_CHAR;
+ else
+ title = ELLIPSIS_CHAR + title;
+ }
+ if (this._event.end > periodEnd && !this._event.allDay) {
+ if (rtl)
+ title = ELLIPSIS_CHAR + title;
+ else
+ title = title + ELLIPSIS_CHAR;
+ }
+ return title;
+ }
+});
+
const NotificationMessage = new Lang.Class({
Name: 'NotificationMessage',
Extends: Message,
@@ -1492,22 +1522,7 @@ const EventsSection = new Lang.Class({
for (let i = 0; i < events.length; i++) {
let event = events[i];
- let title = _formatEventTime(event, periodBegin, periodEnd);
-
- let rtl = this.actor.get_text_direction() == Clutter.TextDirection.RTL;
- if (event.date < periodBegin && !event.allDay) {
- if (rtl)
- title = title + ELLIPSIS_CHAR;
- else
- title = ELLIPSIS_CHAR + title;
- }
- if (event.end > periodEnd && !event.allDay) {
- if (rtl)
- title = ELLIPSIS_CHAR + title;
- else
- title = title + ELLIPSIS_CHAR;
- }
- this.addMessage(new Message(title, event.summary), false);
+ this.addMessage(new EventMessage(event, this._date), false);
}
this._reloading = false;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]