mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-12 21:05:36 +00:00
hooking up new alarm framework and hooking it in to lightning bug 292704 r=shaver
This commit is contained in:
parent
fe2a42819a
commit
388da891d7
84
calendar/base/content/calendar-alarm-dialog.js
Normal file
84
calendar/base/content/calendar-alarm-dialog.js
Normal file
@ -0,0 +1,84 @@
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart.parmenter@oracle.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
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
function addAlarm(event)
|
||||
{
|
||||
var alarmList = document.getElementById("alarmlist");
|
||||
|
||||
var alarmWidget = document.createElement("calendar-alarm-widget");
|
||||
alarmWidget.setAttribute("title", event.title);
|
||||
alarmWidget.setAttribute("time", event.alarmTime.toString());
|
||||
alarmWidget.addEventListener("snooze", onSnoozeAlarm, false);
|
||||
alarmWidget.addEventListener("dismiss", onDismissAlarm, false);
|
||||
alarmWidget.item = event;
|
||||
|
||||
alarmList.appendChild(alarmWidget);
|
||||
}
|
||||
|
||||
function removeAlarm(event)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function onDismissAll()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
function onSnoozeAlarm(event)
|
||||
{
|
||||
// i hate xbl..
|
||||
var alarmWidget = event.target;
|
||||
|
||||
var alarmService = Components.classes["@mozilla.org/calendar/alarm-service;1"].getService(Components.interfaces.calIAlarmService);
|
||||
|
||||
var duration = Components.classes["@mozilla.org/calendar/datetime;1"].createInstance(Components.interfaces.calIDateTime);
|
||||
duration.minute = 5;
|
||||
duration.normalize()
|
||||
|
||||
alarmService.snoozeEvent(alarmWidget.item, duration);
|
||||
|
||||
alarmWidget.parentNode.removeChild(alarmWidget);
|
||||
}
|
||||
|
||||
function onDismissAlarm(event)
|
||||
{
|
||||
// everything is just visual at this point. we don't need to do anything special.
|
||||
var alarmWidget = event.target;
|
||||
alarmWidget.parentNode.removeChild(alarmWidget);
|
||||
|
||||
}
|
||||
|
34
calendar/base/content/calendar-alarm-dialog.xul
Normal file
34
calendar/base/content/calendar-alarm-dialog.xul
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<?xml-stylesheet href="chrome://global/skin/global.css" type="text/css"?>
|
||||
<?xml-stylesheet href="chrome://calendar/content/calendar-alarm-widget.css" type="text/css"?>
|
||||
|
||||
<!-- DTD File with all strings specific to the calendar -->
|
||||
<!DOCTYPE dialog
|
||||
[
|
||||
<!ENTITY % dtd1 SYSTEM "chrome://calendar/locale/global.dtd" > %dtd1;
|
||||
<!ENTITY % dtd2 SYSTEM "chrome://calendar/locale/calendar.dtd" > %dtd2;
|
||||
<!ENTITY % dtd3 SYSTEM "chrome://branding/locale/brand.dtd" > %dtd3;
|
||||
]>
|
||||
|
||||
<dialog xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
id="calendar-alarmwindow"
|
||||
title="Calendar Alarm"
|
||||
windowtype="calendarAlarmWindow"
|
||||
persist="screenX screenY"
|
||||
buttons="accept"
|
||||
buttonlabelaccept="Dismiss All"
|
||||
ondialogaccept="return onDismissAll();"
|
||||
width="400"
|
||||
height="200">
|
||||
|
||||
<!-- Javascript includes -->
|
||||
<script type="application/x-javascript" src="chrome://calendar/content/calendar-alarm-dialog.js"/>
|
||||
|
||||
<!-- STRING BUNDLE for calendar properties -->
|
||||
|
||||
<!-- The dialog -->
|
||||
<vbox id="alarmlist" flex="1" style="overflow: auto;">
|
||||
</vbox>
|
||||
|
||||
</dialog>
|
4
calendar/base/content/calendar-alarm-widget.css
Normal file
4
calendar/base/content/calendar-alarm-widget.css
Normal file
@ -0,0 +1,4 @@
|
||||
calendar-alarm-widget {
|
||||
-moz-binding: url(chrome://calendar/content/calendar-alarm-widget.xml#calendar-alarm-widget);
|
||||
-moz-user-focus: normal;
|
||||
}
|
26
calendar/base/content/calendar-alarm-widget.xml
Normal file
26
calendar/base/content/calendar-alarm-widget.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<bindings id="testcases"
|
||||
xmlns="http://www.mozilla.org/xbl"
|
||||
xmlns:xbl="http://www.mozilla.org/xbl"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<binding id="calendar-alarm-widget">
|
||||
<content>
|
||||
<xul:hbox flex="1">
|
||||
<xul:vbox pack="start">
|
||||
<xul:image/>
|
||||
</xul:vbox>
|
||||
<xul:vbox pack="start" flex="1">
|
||||
<xul:label xbl:inherits="value=title"/>
|
||||
<xul:label xbl:inherits="value=time"/>
|
||||
</xul:vbox>
|
||||
<xul:vbox pack="start">
|
||||
<xul:button label="snooze" oncommand="var event = document.createEvent('Events'); event.initEvent('snooze', false, false); this.dispatchEvent(event);"/>
|
||||
<xul:button label="dismiss" oncommand="var event = document.createEvent('Events'); event.initEvent('dismiss', false, false); this.dispatchEvent(event);"/>
|
||||
</xul:vbox>
|
||||
</xul:hbox>
|
||||
</content>
|
||||
</binding>
|
||||
</bindings>
|
@ -46,7 +46,8 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = calbase
|
||||
XPIDL_MODULE = calbase
|
||||
|
||||
XPIDLSRCS = calIAttachment.idl \
|
||||
XPIDLSRCS = calIAlarmService.idl \
|
||||
calIAttachment.idl \
|
||||
calIAttendee.idl \
|
||||
calICalendar.idl \
|
||||
calICalendarManager.idl \
|
||||
|
71
calendar/base/public/calIAlarmService.idl
Normal file
71
calendar/base/public/calIAlarmService.idl
Normal file
@ -0,0 +1,71 @@
|
||||
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart.parmenter@oracle.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
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface calIItemBase;
|
||||
interface calIDateTime;
|
||||
|
||||
[scriptable,uuid(c9c97643-db45-4790-9441-05384ae5c272)]
|
||||
interface calIAlarmServiceObserver : nsISupports
|
||||
{
|
||||
/* Alarm has fired -- Bring up a dialog or play a sound */
|
||||
void onAlarm(in calIItemBase item);
|
||||
};
|
||||
|
||||
[scriptable,uuid(03669cf3-bf4f-4692-97a1-cca891964a1d)]
|
||||
interface calIAlarmService : nsISupports
|
||||
{
|
||||
/* add and remove observers that will be notified when an
|
||||
alarm has gone off. It is up to the application to display
|
||||
the alarm.
|
||||
*/
|
||||
void addObserver(in calIAlarmServiceObserver observer);
|
||||
void removeObserver(in calIAlarmServiceObserver observer);
|
||||
|
||||
/* Call to reschedule an alarm to be notified at a later point.
|
||||
This will _not_ modify the event's alarmTime and will not
|
||||
persist between sessions.
|
||||
|
||||
The alarm will instead fire at "now + duration"
|
||||
|
||||
This will cause an event to be scheduled even if it was not
|
||||
previously scheduled.
|
||||
*/
|
||||
void snoozeEvent(in calIItemBase item, in calIDateTime duration);
|
||||
};
|
||||
|
@ -71,6 +71,7 @@ CPPSRCS = calDateTime.cpp \
|
||||
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
calAlarmService.js \
|
||||
calAttachment.js \
|
||||
calAttendee.js \
|
||||
calCalendarManager.js \
|
||||
|
365
calendar/base/src/calAlarmService.js
Normal file
365
calendar/base/src/calAlarmService.js
Normal file
@ -0,0 +1,365 @@
|
||||
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart.parmenter@oracle.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
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const kHoursBetweenUpdates = 6;
|
||||
|
||||
function newTimerWithCallback(callback, delay, repeating)
|
||||
{
|
||||
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
|
||||
|
||||
timer.initWithCallback(callback,
|
||||
delay,
|
||||
(repeating) ? timer.TYPE_REPEATING_PRECISE : timer.TYPE_ONE_SHOT);
|
||||
return timer;
|
||||
}
|
||||
|
||||
function jsDateToDateTime(date)
|
||||
{
|
||||
var newDate = Components.classes["@mozilla.org/calendar/datetime;1"].createInstance(Components.interfaces.calIDateTime);
|
||||
newDate.jsDate = date;
|
||||
return newDate;
|
||||
}
|
||||
|
||||
/*
|
||||
var testalarmnumber = 0;
|
||||
function testAlarm(name) {
|
||||
this.title = name;
|
||||
this.alarmTime = jsDateToDateTime(new Date());
|
||||
this.alarmTime.second += 5;
|
||||
this.alarmTime.normalize();
|
||||
this.parent = new Object();
|
||||
this.parent.suppressAlarms = false;
|
||||
this.id = testalarmnumber++;
|
||||
}
|
||||
testAlarm.prototype = {
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
function calAlarmService() {
|
||||
this.wrappedJSObject = this;
|
||||
|
||||
this.calendarObserver = {
|
||||
alarmService: this,
|
||||
|
||||
onStartBatch: function() { },
|
||||
onEndBatch: function() { },
|
||||
onLoad: function() { },
|
||||
onAddItem: function(aItem) {
|
||||
if (aItem.hasAlarm)
|
||||
this.alarmService.addAlarm(aItem, false);
|
||||
},
|
||||
onModifyItem: function(aNewItem, aOldItem) {
|
||||
this.alarmService.removeAlarm(aOldItem);
|
||||
|
||||
if (aNewItem.hasAlarm)
|
||||
this.alarmService.addAlarm(aNewItem, false);
|
||||
},
|
||||
onDeleteItem: function(aDeletedItem) {
|
||||
this.alarmService.removeAlarm(aDeletedItem);
|
||||
},
|
||||
onAlarm: function(aAlarmItem) { },
|
||||
onError: function(aErrNo, aMessage) { }
|
||||
};
|
||||
|
||||
|
||||
this.calendarManagerObserver = {
|
||||
alarmService: this,
|
||||
|
||||
onCalendarRegistered: function(aCalendar) {
|
||||
this.alarmService.observeCalendar(aCalendar);
|
||||
},
|
||||
onCalendarUnregistering: function(aCalendar) {
|
||||
this.alarmService.unobserveCalendar(aCalendar);
|
||||
},
|
||||
onCalendarDeleting: function(aCalendar) {},
|
||||
onCalendarPrefSet: function(aCalendar, aName, aValue) {},
|
||||
onCalendarPrefDeleting: function(aCalendar, aName) {}
|
||||
};
|
||||
}
|
||||
|
||||
calAlarmServiceClassInfo = {
|
||||
getInterfaces: function (count) {
|
||||
var ifaces = [
|
||||
Components.interfaces.nsISupports,
|
||||
Components.interfaces.calIAlarmService,
|
||||
Components.interfaces.calIObserver
|
||||
];
|
||||
count.value = ifaces.length;
|
||||
return ifaces;
|
||||
},
|
||||
|
||||
getHelperForLanguage: function (language) {
|
||||
return null;
|
||||
},
|
||||
|
||||
contractID: "@mozilla.org/calendar/alarm-service;1",
|
||||
classDescription: "Calendar Alarm Service",
|
||||
classID: Components.ID("{7a9200dd-6a64-4fff-a798-c5802186e2cc}"),
|
||||
implementationLanguage: Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT,
|
||||
flags: 0
|
||||
};
|
||||
|
||||
calAlarmService.prototype = {
|
||||
mRangeStart: null,
|
||||
mRangeEnd: null,
|
||||
mEvents: {},
|
||||
mObservers: [],
|
||||
mUpdateTimer: null,
|
||||
mStarted: false,
|
||||
|
||||
QueryInterface: function (aIID) {
|
||||
if (aIID.equals(Components.interfaces.nsIClassInfo))
|
||||
return calAlarmServiceClassInfo;
|
||||
|
||||
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
||||
!aIID.equals(Components.interfaces.calIAlarmService) &&
|
||||
!aIID.equals(Components.interfaces.nsIObserver))
|
||||
{
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
/* nsIObserver */
|
||||
observe: function (subject, topic, data) {
|
||||
observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
|
||||
|
||||
if (topic == "app-startup") {
|
||||
observerService.addObserver(this, "profile-after-change", false);
|
||||
observerService.addObserver(this, "xpcom-shutdown", false);
|
||||
}
|
||||
if (topic == "profile-after-change") {
|
||||
this.startup();
|
||||
}
|
||||
if (topic == "xpcom-shutdown") {
|
||||
this.shutdown();
|
||||
}
|
||||
},
|
||||
|
||||
/* calIAlarmService APIs */
|
||||
snoozeEvent: function(event, duration) {
|
||||
if (event in this.mEvents) {
|
||||
this.removeAlarm(event);
|
||||
}
|
||||
var alarmTime = jsDateToDateTime((new Date())).getInTimezone(null);
|
||||
alarmTime.addDuration(duration);
|
||||
this.addAlarm(event, alarmTime);
|
||||
},
|
||||
|
||||
addObserver: function(aObserver) {
|
||||
dump("observer added\n");
|
||||
if (this.mObservers.indexOf(aObserver) != -1)
|
||||
return;
|
||||
|
||||
this.mObservers.push(aObserver);
|
||||
},
|
||||
|
||||
removeObserver: function(aObserver) {
|
||||
dump("observer removed\n");
|
||||
function notThis(v) {
|
||||
return v != aObserver;
|
||||
}
|
||||
|
||||
this.mObservers = this.mObservers.filter(notThis);
|
||||
},
|
||||
|
||||
|
||||
/* helper functions */
|
||||
notifyObservers: function(functionName, args) {
|
||||
function notify(obs) {
|
||||
try { obs[functionName].apply(obs, args); }
|
||||
catch (e) { }
|
||||
}
|
||||
this.mObservers.forEach(notify);
|
||||
},
|
||||
|
||||
startup: function() {
|
||||
if (this.mStarted)
|
||||
return;
|
||||
|
||||
dump("Starting calendar alarm service\n");
|
||||
this.mStarted = true;
|
||||
|
||||
var calendarManager = Components.classes["@mozilla.org/calendar/manager;1"].getService(Components.interfaces.calICalendarManager);
|
||||
calendarManager.addObserver(this.calendarManagerObserver);
|
||||
|
||||
var calendars = calendarManager.getCalendars({});
|
||||
for each(var calendar in calendars) {
|
||||
this.observeCalendar(calendar);
|
||||
}
|
||||
|
||||
this.findAlarms();
|
||||
|
||||
/* set up a timer to update alarms every N hours */
|
||||
var timerCallback = {
|
||||
alarmService: this,
|
||||
notify: function(timer) {
|
||||
this.alarmService.findAlarms();
|
||||
}
|
||||
};
|
||||
|
||||
this.mUpdateTimer = newTimerWithCallback(timerCallback, kHoursBetweenUpdates * 3600000, true);
|
||||
|
||||
/* tell people that we're alive so they can start monitoring alarms */
|
||||
var notifier = Components.classes["@mozilla.org/embedcomp/appstartup-notifier;1"].getService(Components.interfaces.nsIObserver);
|
||||
notifier.observe(null, "alarm-service-startup", null);
|
||||
|
||||
|
||||
/* Test Code
|
||||
this.addAlarm(new testAlarm("Meeting with Mr. T"));
|
||||
this.addAlarm(new testAlarm("Blah blah"));
|
||||
*/
|
||||
},
|
||||
|
||||
shutdown: function() {
|
||||
/* tell people that we're no longer running */
|
||||
var notifier = Components.classes["@mozilla.org/embedcomp/appstartup-notifier;1"].getService(Components.interfaces.nsIObserver);
|
||||
notifier.observe(null, "alarm-service-shutdown", null);
|
||||
|
||||
if (this.mUpdateTimer) {
|
||||
this.mUpdateTimer.cancel();
|
||||
this.mUpdateTimer = null;
|
||||
}
|
||||
|
||||
var calendarManager = Components.classes["@mozilla.org/calendar/manager;1"].getService(Components.interfaces.calICalendarManager);
|
||||
calendarManager.removeObserver(this.calendarManagerObserver);
|
||||
|
||||
for each(var timer in this.mEvents) {
|
||||
timer.cancel();
|
||||
}
|
||||
this.mEvents = {};
|
||||
|
||||
var calendars = calendarManager.getCalendars({});
|
||||
for each(var calendar in calendars) {
|
||||
this.unobserveCalendar(calendar);
|
||||
}
|
||||
|
||||
this.mRangeStart = null;
|
||||
this.mRangeEnd = null;
|
||||
|
||||
this.mStarted = false;
|
||||
},
|
||||
|
||||
|
||||
observeCalendar: function(calendar) {
|
||||
calendar.addObserver(this.calendarObserver);
|
||||
},
|
||||
|
||||
unobserveCalendar: function(calendar) {
|
||||
calendar.removeObserver(this.calendarObserver);
|
||||
},
|
||||
|
||||
addAlarm: function(aItem, skipCheck, alarmTime) {
|
||||
// if aItem.alarmTime >= 'now' && aItem.alarmTime <= gAlarmEndTime
|
||||
if (!alarmTime)
|
||||
alarmTime = aItem.alarmTime.getInTimezone(null);
|
||||
|
||||
var now = jsDateToDateTime((new Date())).getInTimezone(null);
|
||||
|
||||
var callbackObj = {
|
||||
alarmService: this,
|
||||
item: aItem,
|
||||
notify: function(timer) {
|
||||
this.alarmService.alarmFired(this.item);
|
||||
delete this.alarmService.mEvents[this.item];
|
||||
}
|
||||
};
|
||||
|
||||
if ((alarmTime.compare(now) >= 0 && alarmTime.compare(this.mRangeEnd) <= 0) || skipCheck) {
|
||||
var timeout = alarmTime.jsDate - Date.now();
|
||||
this.mEvents[aItem.id] = newTimerWithCallback(callbackObj, timeout, false);
|
||||
dump("adding alarm timeout (" + timeout + ") for " + aItem + " at " + aItem.alarmTime + "\n");
|
||||
}
|
||||
},
|
||||
|
||||
removeAlarm: function(aItem) {
|
||||
if (aItem.id in this.mEvents) {
|
||||
this.mEvents[aItem.id].cancel();
|
||||
delete this.mEvents[aItem.id];
|
||||
}
|
||||
},
|
||||
|
||||
findAlarms: function() {
|
||||
if (this.mEvents.length > 0) {
|
||||
// This may happen if an alarm is snoozed over the time range mark
|
||||
var err = new Error();
|
||||
var debug = Components.classes["@mozilla.org/xpcom/debug;1"].getService(Components.interfaces.nsIDebug);
|
||||
debug.warning("mEvents.length should always be 0 when we enter findAlarms",
|
||||
err.fileName, err.lineNumber);
|
||||
}
|
||||
|
||||
var getListener = {
|
||||
alarmService: this,
|
||||
onOperationComplete: function(aCalendar, aStatus, aOperationType, aId, aDetail) {
|
||||
},
|
||||
onGetResult: function(aCalendar, aStatus, aItemType, aDetail, aCount, aItems) {
|
||||
for (var i = 0; i < aCount; ++i) {
|
||||
var item = aItems[i];
|
||||
if (item.hasAlarm) {
|
||||
this.alarmService.addAlarm(item, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// figure out the 'now' and 6 hours from now and look for events
|
||||
// between then with alarms
|
||||
this.mRangeStart = jsDateToDateTime((new Date())).getInTimezone(null);
|
||||
|
||||
var until = this.mRangeStart.clone();
|
||||
until.hour += kHoursBetweenUpdates;
|
||||
until.normalize();
|
||||
this.mRangeEnd = until.getInTimezone(null);
|
||||
|
||||
var calendarManager = Components.classes["@mozilla.org/calendar/manager;1"].getService(Components.interfaces.calICalendarManager);
|
||||
var calendars = calendarManager.getCalendars({});
|
||||
for each(var calendar in calendars) {
|
||||
calendar.getItems(calendar.ITEM_FILTER_TYPE_EVENT,
|
||||
0, this.mRangeStart, this.mRangeEnd, getListener);
|
||||
}
|
||||
},
|
||||
|
||||
alarmFired: function(event) {
|
||||
if (event.parent.suppressAlarms)
|
||||
return;
|
||||
|
||||
this.notifyObservers("onAlarm", [event]);
|
||||
}
|
||||
};
|
@ -87,6 +87,14 @@ const componentData =
|
||||
constructor: "calCalendarManager",
|
||||
onComponentLoad: "onCalCalendarManagerLoad()"},
|
||||
|
||||
{cid: Components.ID("{7a9200dd-6a64-4fff-a798-c5802186e2cc}"),
|
||||
contractid: "@mozilla.org/calendar/alarm-service;1",
|
||||
script: "calAlarmService.js",
|
||||
constructor: "calAlarmService",
|
||||
category: "app-startup",
|
||||
categoryEntry: "alarm-service-startup",
|
||||
service: true},
|
||||
|
||||
{cid: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
|
||||
contractid: "@mozilla.org/calendar/event;1",
|
||||
script: "calEvent.js",
|
||||
@ -168,8 +176,14 @@ var calItemModule = {
|
||||
type);
|
||||
|
||||
if (comp.category) {
|
||||
var contractid;
|
||||
if (comp.service)
|
||||
contractid = "service," + comp.contractid;
|
||||
else
|
||||
contractid = comp.contractid;
|
||||
catman.addCategoryEntry(comp.category, comp.categoryEntry,
|
||||
comp.contractid, true, true);
|
||||
contractid, true, true);
|
||||
dump("registering for category stuff\n");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -46,6 +46,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = lightning
|
||||
|
||||
EXTRA_COMPONENTS = \
|
||||
lightningAlarmMonitor.js \
|
||||
lightningTextCalendarConverter.js \
|
||||
calItipProtocolHandler.js \
|
||||
$(NULL)
|
||||
|
147
calendar/lightning/components/lightningAlarmMonitor.js
Normal file
147
calendar/lightning/components/lightningAlarmMonitor.js
Normal file
@ -0,0 +1,147 @@
|
||||
/* -*- Mode: javascript; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is Oracle Corporation code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Oracle Corporation
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Stuart Parmenter <stuart.parmenter@oracle.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
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
const CI = Components.interfaces;
|
||||
|
||||
function getAlarmService()
|
||||
{
|
||||
return Components.classes["@mozilla.org/calendar/alarm-service;1"].getService(Components.interfaces.calIAlarmService);
|
||||
}
|
||||
|
||||
var gAlarmWindow = null;
|
||||
|
||||
var alarmServiceObserver = {
|
||||
onAlarm: function(event) {
|
||||
|
||||
if (!gAlarmWindow) {
|
||||
var windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
|
||||
gAlarmWindow = windowWatcher.openWindow(null,
|
||||
"chrome://calendar/content/calendar-alarm-dialog.xul",
|
||||
"_blank",
|
||||
"chrome,dialog=yes,all",
|
||||
null);
|
||||
}
|
||||
|
||||
if ("addAlarm" in gAlarmWindow) {
|
||||
gAlarmWindow.addAlarm(event);
|
||||
} else {
|
||||
var addAlarm = function() {
|
||||
gAlarmWindow.addAlarm(event);
|
||||
}
|
||||
gAlarmWindow.addEventListener("load", addAlarm, false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function ltnAlarmMonitor() { }
|
||||
|
||||
ltnAlarmMonitor.prototype = {
|
||||
QueryInterface: function (aIID) {
|
||||
if (!aIID.equals(CI.nsISupports) &&
|
||||
!aIID.equals(CI.nsIObserver))
|
||||
throw Components.interfaces.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
/* nsIObserver */
|
||||
observe: function (subject, topic, data) {
|
||||
switch (topic) {
|
||||
case "alarm-service-startup":
|
||||
getAlarmService().addObserver(alarmServiceObserver);
|
||||
break;
|
||||
|
||||
case "alarm-service-shutdown":
|
||||
getAlarmService().removeObserver(alarmServiceObserver);
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
var myModule = {
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
debug("*** Registering Lightning alarm monitor\n");
|
||||
compMgr = compMgr.QueryInterface(CI.nsIComponentRegistrar);
|
||||
compMgr.registerFactoryLocation(this.myCID,
|
||||
"Lightning Alarm Monitor",
|
||||
this.myContractID,
|
||||
fileSpec,
|
||||
location,
|
||||
type);
|
||||
|
||||
var catman = Components.classes["@mozilla.org/categorymanager;1"]
|
||||
.getService(CI.nsICategoryManager);
|
||||
|
||||
catman.addCategoryEntry("alarm-service-startup", "lightning",
|
||||
"service," + this.myContractID, true, true);
|
||||
catman.addCategoryEntry("alarm-service-shutdown", "lightning",
|
||||
"service," + this.myContractID, true, true);
|
||||
},
|
||||
|
||||
getClassObject: function (compMgr, cid, iid) {
|
||||
if (!cid.equals(this.myCID))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return this.myFactory;
|
||||
},
|
||||
|
||||
myCID: Components.ID("{70fc36e6-2658-4999-9754-49d84cfb83a1}"),
|
||||
|
||||
myContractID: "@mozilla.org/lightning/alarm-monitor;1",
|
||||
|
||||
myFactory: {
|
||||
createInstance: function (outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
return (new ltnAlarmMonitor()).QueryInterface(iid);
|
||||
}
|
||||
},
|
||||
|
||||
canUnload: function(compMgr) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return myModule;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,10 @@ calendar.jar:
|
||||
content/calendar/calendar-multiday-view.css (/calendar/base/content/calendar-multiday-view.css)
|
||||
content/calendar/calendar-multiday-view.xml (/calendar/base/content/calendar-multiday-view.xml)
|
||||
content/calendar/calendar-item-editing.js (/calendar/base/content/calendar-item-editing.js)
|
||||
content/calendar/calendar-alarm-dialog.xul (/calendar/base/content/calendar-alarm-dialog.xul)
|
||||
content/calendar/calendar-alarm-dialog.js (/calendar/base/content/calendar-alarm-dialog.js)
|
||||
content/calendar/calendar-alarm-widget.css (/calendar/base/content/calendar-alarm-widget.css)
|
||||
content/calendar/calendar-alarm-widget.xml (/calendar/base/content/calendar-alarm-widget.xml)
|
||||
|
||||
calendar-en-US.jar:
|
||||
locale/en-US/calendar/global.dtd (/calendar/resources/locale/en-US/global.dtd)
|
||||
|
Loading…
Reference in New Issue
Block a user