bug 298358 - Adds snooze to alarm dialog. patch by jminta and ssitter, r1=lilmatt, r2=mvl

This commit is contained in:
mattwillis%gmail.com 2006-09-01 01:52:13 +00:00
Родитель cdbb436000
Коммит 3bde5d687a
4 изменённых файлов: 105 добавлений и 29 удалений

Просмотреть файл

@ -82,15 +82,10 @@ function onDismissAll()
now = now.getInTimezone("UTC");
var box = document.getElementById("alarmlist");
for each (kid in box.childNodes) {
if (!kid.item) {
if (!kid || !kid.item) {
continue;
}
// We want the parent item, otherwise we're going to accidentally create an
// exception. We've relnoted (for 0.1) the slightly odd behavior this can
// cause if you move an event after dismissing an alarm
var item = kid.item.parentItem.clone();
item.alarmLastAck = now;
item.calendar.modifyItem(item, kid.item, null);
onDismissWidget(kid);
}
return true;
}
@ -104,8 +99,8 @@ function onSnoozeAlarm(event)
var duration = Components.classes["@mozilla.org/calendar/duration;1"]
.createInstance(Components.interfaces.calIDuration);
//XXX figure out a nice UI way to offer other length options
duration.minutes = 5;
duration.minutes = event.detail;
duration.normalize();
alarmService.snoozeEvent(alarmWidget.item, duration);
@ -119,13 +114,26 @@ function onSnoozeAlarm(event)
function onDismissAlarm(event)
{
var alarmWidget = event.target;
onDismissWidget(event.target);
}
function onDismissWidget(alarmWidget) {
var now = Components.classes["@mozilla.org/calendar/datetime;1"]
.createInstance(Components.interfaces.calIDateTime);
now.jsDate = new Date();
now = now.getInTimezone("UTC");
var item = alarmWidget.item.clone();
// We want the parent item, otherwise we're going to accidentally create an
// exception. We've relnoted (for 0.1) the slightly odd behavior this can
// cause if you move an event after dismissing an alarm
var item = alarmWidget.item.parentItem.clone();
item.alarmLastAck = now;
// Make sure to clear out any snoozes that were here.
if (item.recurrenceInfo) {
item.deleteProperty("X-MOZ-SNOOZE-TIME-"+alarmWidget.item.recurrenceId.nativeTime);
} else {
item.deleteProperty("X-MOZ-SNOOZE-TIME");
}
item.calendar.modifyItem(item, alarmWidget.item, null);
var parent = alarmWidget.parentNode;

Просмотреть файл

@ -22,6 +22,8 @@
- Contributor(s):
- Stuart Parmenter <stuart.parmenter@oracle.com>
- Simon Paquet <bugzilla@babylonsounds.com>
- Joey Minta <jminta@gmail.com>
- Stefan Sitter <ssitter@googlemail.com>
-
- Alternatively, the contents of this file may be used under the terms of
- either the GNU General Public License Version 2 or later (the "GPL"), or
@ -47,6 +49,7 @@
<binding id="calendar-alarm-widget">
<content>
<xul:groupbox flex="1">
<xul:hbox flex="1">
<xul:vbox pack="start">
<xul:image/>
@ -55,14 +58,43 @@
<xul:label xbl:inherits="value=title"/>
<xul:label xbl:inherits="value=time"/>
<xul:label xbl:inherits="value=location"/>
</xul:vbox>
<xul:vbox pack="start">
<!-- Snooze button hidden for Lightning 0.1. Most likely we need to
introduce calIAlarm properly before it can work without dataloss
<xul:button label="&calendar.alarm.snooze.label;" oncommand="var snoozeEvent = document.createEvent('Events'); snoozeEvent.initEvent('snooze', true, false); this.dispatchEvent(snoozeEvent);"/>-->
<xul:button label="&calendar.alarm.dismiss.label;" oncommand="var dismissEvent = document.createEvent('Events'); dismissEvent.initEvent('dismiss', true, false); this.dispatchEvent(dismissEvent);"/>
<xul:hbox flex="1" align="center">
<xul:button label="&calendar.alarm.snooze.label;" oncommand="snoozeAlarm();"/>
<xul:label value="&calendar.alarm.for.label;"/>
<xul:menulist anonid="alarm-widget-snooze-value">
<xul:menupopup>
<xul:menuitem label="&calendar.alarm.5minutes;" value="5"/>
<xul:menuitem label="&calendar.alarm.15minutes;" value="15"/>
<xul:menuitem label="&calendar.alarm.30minutes;" value="30"/>
<xul:menuitem label="&calendar.alarm.1hour;" value="60"/>
<xul:menuitem label="&calendar.alarm.1day;" value="1440"/>
</xul:menupopup>
</xul:menulist>
<xul:spacer flex="1"/>
<xul:button label="&calendar.alarm.dismiss.label;" oncommand="dismissAlarm();"/>
</xul:hbox>
</xul:vbox>
</xul:hbox>
</xul:groupbox>
</content>
<implementation>
<method name="snoozeAlarm">
<body><![CDATA[
var snoozeValue = document.getAnonymousElementByAttribute(this,
"anonid", "alarm-widget-snooze-value").value;
var snoozeEvent = document.createEvent('Events');
snoozeEvent.initEvent('snooze', true, false);
snoozeEvent.detail = snoozeValue;
this.dispatchEvent(snoozeEvent);
]]></body>
</method>
<method name="dismissAlarm">
<body><![CDATA[
var dismissEvent = document.createEvent('Events');
dismissEvent.initEvent('dismiss', true, false);
this.dispatchEvent(dismissEvent);
]]></body>
</method>
</implementation>
</binding>
</bindings>

Просмотреть файл

@ -194,25 +194,29 @@ calAlarmService.prototype = {
snoozeEvent: function(event, duration) {
/* modify the event for a new alarm time */
var newEvent = event.clone();
// Make sure we're working with the parent, otherwise we'll accidentally
// create an exception
var newEvent = event.parentItem.clone();
var alarmTime = jsDateToDateTime((new Date())).getInTimezone("UTC");
// Set the last acknowledged time to now.
newEvent.alarmLastAck = alarmTime;
alarmTime = alarmTime.clone();
alarmTime.addDuration(duration);
var datetime;
if (newEvent.alarmRelated == Components.interfaces.calIItemBase.ALARM_RELATED_START) {
datetime = newEvent.startDate || newEvent.entryDate;
if (event.parentItem != event) {
// This is the *really* hard case where we've snoozed a single
// instance of a recurring event. We need to not only know that
// there was a snooze, but also which occurrence was snoozed. Part
// of me just wants to create a local db of snoozes here...
newEvent.setProperty("X-MOZ-SNOOZE-TIME-"+event.recurrenceId.nativeTime, alarmTime);
} else {
datetime = newEvent.endDate || newEvent.dueDate;
newEvent.setProperty("X-MOZ-SNOOZE-TIME", alarmTime);
}
var offset = datetime.subtractDate(alarmTime);
newEvent.alarmOffset = offset;
// calling modifyItem will cause us to get the right callback
// and update the alarm properly
newEvent.calendar.modifyItem(newEvent, event, null);
newEvent.calendar.modifyItem(newEvent, event.parentItem, null);
},
addObserver: function(aObserver) {
@ -242,6 +246,17 @@ calAlarmService.prototype = {
this.mObservers.forEach(notify);
},
hasAlarm: function almSvc_hasAlarm(aItem) {
var hasSnooze;
if (aItem.parentItem != aItem) {
hasSnooze = aItem.parentItem.hasProperty("X-MOZ-SNOOZE-TIME-"+aItem.recurrenceId.nativeTime);
} else {
hasSnooze = aItem.hasProperty("X-MOZ-SNOOZE-TIME");
}
return aItem.alarmOffset || aItem.parentItem.alarmOffset || hasSnooze;
},
startup: function() {
if (this.mStarted)
return;
@ -344,6 +359,22 @@ calAlarmService.prototype = {
alarmTime = aItem.endDate || aItem.dueDate;
}
// Check for snooze
var snoozeTime;
if (aItem.parentItem != aItem) {
snoozeTime = aItem.parentItem.getProperty("X-MOZ-SNOOZE-TIME-"+aItem.recurrenceId.nativeTime)
} else {
snoozeTime = aItem.getProperty("X-MOZ-SNOOZE-TIME");
}
const calIDateTime = Components.interfaces.calIDateTime;
if (snoozeTime && !(snoozeTime instanceof calIDateTime)) {
var time = Components.classes["@mozilla.org/calendar/datetime;1"]
.createInstance(calIDateTime);
time.nativeTime = snoozeTime;
snoozeTime = time;
}
dump("snooze time is:"+snoozeTime+'\n');
alarmTime = alarmTime.clone();
// Handle all day events. This is kinda weird, because they don't have
@ -358,6 +389,7 @@ calAlarmService.prototype = {
alarmTime.addDuration(offset);
alarmTime = alarmTime.getInTimezone("UTC");
alarmTime = snoozeTime || alarmTime;
dump("considering alarm for item:"+aItem.title+'\n offset:'+offset+', which makes alarm time:'+alarmTime+'\n');
var now;
// XXX When the item is floating, should use the default timezone
@ -422,8 +454,7 @@ dump("alarm is in the past, and unack'd, firing now!\n");
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
for (var i = 0; i < aCount; ++i) {
var item = aItems[i];
if (item.alarmOffset ||
(item.parentItem && item.parentItem.alarmOffset)) {
if (this.alarmService.hasAlarm(item)) {
this.alarmService.addAlarm(item);
}
}

Просмотреть файл

@ -489,7 +489,12 @@
<!ENTITY calendar.alarm.title.label "Calendar Alarm" >
<!ENTITY calendar.alarm.dismiss.label "Dismiss" >
<!ENTITY calendar.alarm.dismissall.label "Dismiss All" >
<!ENTITY calendar.alarm.for.label "for" >
<!ENTITY calendar.alarm.5minutes "5 minutes" >
<!ENTITY calendar.alarm.15minutes "15 minutes" >
<!ENTITY calendar.alarm.30minutes "30 minutes" >
<!ENTITY calendar.alarm.1hour "1 hour" >
<!ENTITY calendar.alarm.1day "1 day" >
<!-- Calendar Server Dialog -->
<!ENTITY calendar.server.dialog.title.new "New Calendar File">