/usr/lib/thunderbird-addons/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}/modules/calAlarmUtils.jsm is in xul-ext-lightning 1:24.4.0+build1-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | /* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Components.utils.import("resource://calendar/modules/calUtils.jsm");
EXPORTED_SYMBOLS = ["cal"]; // even though it's defined in calUtils.jsm, import needs this
cal.alarms = {
/**
* Read default alarm settings from user preferences and apply them to the
* event/todo passed in. The item's calendar should be set to ensure the
* correct alarm type is set.
*
* @param aItem The item to apply the default alarm values to.
*/
setDefaultValues: function cal_alarm_setDefaultValues(aItem) {
let type = cal.isEvent(aItem) ? "event" : "todo";
if (cal.getPrefSafe("calendar.alarms.onfor" + type + "s", 0) == 1) {
let alarmOffset = cal.createDuration();
let alarm = cal.createAlarm();
let units = cal.getPrefSafe("calendar.alarms." + type + "alarmunit", "minutes");
// Make sure the alarm pref is valid, default to minutes otherwise
if (["weeks", "days", "hours", "minutes", "seconds"].indexOf(units) < 0) {
units = "minutes";
}
alarmOffset[units] = cal.getPrefSafe("calendar.alarms." + type + "alarmlen", 0);
alarmOffset.normalize();
alarmOffset.isNegative = true;
if (type == "todo" && !aItem.entryDate) {
// You can't have an alarm if the entryDate doesn't exist.
aItem.entryDate = cal.now();
}
alarm.related = Components.interfaces.calIAlarm.ALARM_RELATED_START;
alarm.offset = alarmOffset;
// Default to a display alarm, unless the calendar doesn't support
// it or we have no calendar yet. (Man this is hard to wrap)
let actionValues = ((aItem.calendar &&
aItem.calendar.getProperty("capabilities.alarms.actionValues")) ||
["DISPLAY"]);
alarm.action = (actionValues.indexOf("DISPLAY") < 0 ? actionValues[0] : "DISPLAY");
aItem.addAlarm(alarm);
}
},
/**
* Calculate the alarm date for a calIAlarm.
*
* @param aItem The item used to calculate the alarm date.
* @param aAlarm The alarm to calculate the date for.
* @return The alarm date.
*/
calculateAlarmDate: function cal_alarm_calculateAlarmDate(aItem, aAlarm) {
if (aAlarm.related == aAlarm.ALARM_RELATED_ABSOLUTE) {
return aAlarm.alarmDate;
} else {
let returnDate;
if (aAlarm.related == aAlarm.ALARM_RELATED_START) {
returnDate = aItem[cal.calGetStartDateProp(aItem)];
} else if (aAlarm.related == aAlarm.ALARM_RELATED_END) {
returnDate = aItem[cal.calGetEndDateProp(aItem)];
}
if (returnDate && aAlarm.offset) {
// Handle all day events. This is kinda weird, because they don't
// have a well defined startTime. We just consider the start/end
// to be midnight in the user's timezone.
if (returnDate.isDate) {
let tz = cal.calendarDefaultTimezone();
// This returns a copy, so no extra cloning needed.
returnDate = returnDate.getInTimezone(tz);
returnDate.isDate = false;
} else {
// Clone the date to correctly add the duration.
returnDate = returnDate.clone();
}
returnDate.addDuration(aAlarm.offset);
return returnDate;
}
}
return null;
},
/**
* Calculate the alarm offset for a calIAlarm. The resulting offset is
* related to either start or end of the event, depending on the aRelated
* parameter.
*
* @param aItem The item to calculate the offset for.
* @param aAlarm The alarm to calculate the offset for.
* @param aRelated (optional) A relation constant from calIAlarm. If not
* passed, ALARM_RELATED_START will be assumed.
* @return The alarm offset.
*/
calculateAlarmOffset: function cal_alarms_calculateAlarmOffset(aItem, aAlarm, aRelated) {
if (aAlarm.related == aAlarm.ALARM_RELATED_ABSOLUTE) {
let returnDate;
if (aRelated === undefined || aRelated == aAlarm.ALARM_RELATED_START) {
returnDate = aItem[cal.calGetStartDateProp(aItem)];
} else if (aRelated == aAlarm.ALARM_RELATED_END) {
returnDate = aItem[cal.calGetEndDateProp(aItem)];
}
if (returnDate && aAlarm.alarmDate) {
return returnDate.subtractDate(aAlarm.alarmDate);
}
return offset;
} else {
return aAlarm.offset;
}
},
/**
* Adds reminder images to a given node, making sure only one icon per alarm
* action is added.
*
* @param aElement The element to add the images to.
* @param aReminders The set of reminders to add images for.
*/
addReminderImages: function cal_alarms_addReminderImages(aElement, aReminders) {
function createOwnedXULNode(el) {
const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
return aElement.ownerDocument.createElementNS(XUL_NS, el);
}
function setupActionImage(node, reminder) {
let image = node || createOwnedXULNode("image");
image.setAttribute("class", "reminder-icon");
image.setAttribute("value", reminder.action);
return image;
}
// Fill up the icon box with the alarm icons, show max one icon per
// alarm type.
let countIconChildren = aElement.childNodes.length;
let actionMap = {};
let i, offset;
for (i = 0, offset = 0; i < aReminders.length; i++) {
var reminder = aReminders[i];
if (reminder.action in actionMap) {
// Only show one icon of each type;
offset++;
continue;
}
actionMap[reminder.action] = true;
if (i - offset >= countIconChildren) {
// Not enough nodes, append it.
aElement.appendChild(setupActionImage(null, reminder));
} else {
// There is already a node there, change its properties
setupActionImage(aElement.childNodes[i - offset], reminder);
}
}
// Remove unused image nodes
for (i -= offset; i < countIconChildren; i++) {
aElement.removeChild(aElement.childNodes[i]);
}
}
};
|