/usr/lib/thunderbird-addons/extensions/{e2fda1a4-762b-4020-b5ad-a41df1933103}/components/calMemoryCalendar.js 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 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 | /* 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://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://calendar/modules/calProviderUtils.jsm");
Components.utils.import("resource://calendar/modules/calUtils.jsm");
//
// calMemoryCalendar.js
//
const calCalendarManagerContractID = "@mozilla.org/calendar/manager;1";
const calICalendarManager = Components.interfaces.calICalendarManager;
const cICL = Components.interfaces.calIChangeLog;
function calMemoryCalendar() {
this.initProviderBase();
this.initMemoryCalendar();
}
const calMemoryCalendarClassID = Components.ID("{bda0dd7f-0a2f-4fcf-ba08-5517e6fbf133}");
const calMemoryCalendarInterfaces = [
Components.interfaces.calICalendar,
Components.interfaces.calISchedulingSupport,
Components.interfaces.calIOfflineStorage,
Components.interfaces.calISyncWriteCalendar,
Components.interfaces.calICalendarProvider
];
calMemoryCalendar.prototype = {
__proto__: cal.ProviderBase.prototype,
classID: calMemoryCalendarClassID,
QueryInterface: XPCOMUtils.generateQI(calMemoryCalendarInterfaces),
classInfo: XPCOMUtils.generateCI({
classID: calMemoryCalendarClassID,
contractID: "@mozilla.org/calendar/calendar;1?type=memory",
classDescription: "Calendar Memory Provider",
interfaces: calMemoryCalendarInterfaces
}),
mItems: null,
mOfflineFlags: null,
mObservers: null,
mMetaData: null,
initMemoryCalendar: function() {
this.mObservers = new cal.ObserverBag(Components.interfaces.calIObserver);
this.mItems = {};
this.mOfflineFlags = {};
this.mMetaData = new cal.calPropertyBag();
},
//
// calICalendarProvider interface
//
get prefChromeOverlay() {
return null;
},
get displayName() {
return cal.calGetString("calendar", "memoryName");
},
createCalendar: function mem_createCal() {
throw NS_ERROR_NOT_IMPLEMENTED;
},
deleteCalendar: function mem_deleteCal(calendar, listener) {
calendar = calendar.wrappedJSObject;
calendar.mItems = {};
calendar.mMetaData = new cal.calPropertyBag();
try {
listener.onDeleteCalendar(calendar, Components.results.NS_OK, null);
} catch(ex) {}
},
mRelaxedMode: undefined,
get relaxedMode() {
if (this.mRelaxedMode === undefined) {
this.mRelaxedMode = this.getProperty("relaxedMode");
}
return this.mRelaxedMode;
},
//
// calICalendar interface
//
getProperty: function calMemoryCalendar_getProperty(aName) {
switch (aName) {
case "cache.supported":
case "requiresNetwork":
return false;
}
return this.__proto__.__proto__.getProperty.apply(this, arguments);
},
// readonly attribute AUTF8String type;
get type() { return "memory"; },
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
addItem: function (aItem, aListener) {
var newItem = aItem.clone();
return this.adoptItem(newItem, aListener);
},
// void adoptItem( in calIItemBase aItem, in calIOperationListener aListener );
adoptItem: function (aItem, aListener) {
if (this.readOnly)
throw Components.interfaces.calIErrors.CAL_IS_READONLY;
if (aItem.id == null && aItem.isMutable)
aItem.id = cal.getUUID();
if (aItem.id == null) {
this.notifyOperationComplete(aListener,
Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.ADD,
aItem.id,
"Can't set ID on non-mutable item to addItem");
return;
}
//Lines below are commented because of the offline bug 380060
//Memory Calendar cannot assume that a new item should not have an ID.
//calCachedCalendar could send over an item with an id.
/*if (this.mItems[aItem.id] != null) {
if (this.relaxedMode) {
// we possibly want to interact with the user before deleting
delete this.mItems[aItem.id];
} else {
this.notifyOperationComplete(aListener,
Components.interfaces.calIErrors.DUPLICATE_ID,
Components.interfaces.calIOperationListener.ADD,
aItem.id,
"ID already exists for addItem");
return;
}
}*/
let parentItem = aItem.parentItem;
if (parentItem != aItem) {
parentItem = parentItem.clone();
parentItem.recurrenceInfo.modifyException(aItem, true);
}
parentItem.calendar = this.superCalendar;
parentItem.makeImmutable();
this.mItems[aItem.id] = parentItem;
// notify the listener
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.ADD,
aItem.id,
aItem);
// notify observers
this.mObservers.notify("onAddItem", [aItem]);
},
// void modifyItem( in calIItemBase aNewItem, in calIItemBase aOldItem, in calIOperationListener aListener );
modifyItem: function (aNewItem, aOldItem, aListener) {
if (this.readOnly)
throw Components.interfaces.calIErrors.CAL_IS_READONLY;
if (!aNewItem) {
throw Components.results.NS_ERROR_INVALID_ARG;
}
var this_ = this;
function reportError(errStr, errId) {
this_.notifyOperationComplete(aListener,
errId ? errId : Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.MODIFY,
aNewItem.id,
errStr);
return null;
}
if (!aNewItem.id) {
// this is definitely an error
return reportError(null, "ID for modifyItem item is null");
}
var modifiedItem = aNewItem.parentItem.clone();
if (aNewItem.parentItem != aNewItem) {
modifiedItem.recurrenceInfo.modifyException(aNewItem, false);
}
// If no old item was passed, then we should overwrite in any case.
// Pick up the old item from our items array and use this as an old item
// later on.
if (!aOldItem) {
aOldItem = this.mItems[aNewItem.id];
}
if (this.relaxedMode) {
// We've already filled in the old item above, if this doesn't exist
// then just take the current item as its old version
if (!aOldItem) {
aOldItem = modifiedItem;
}
aOldItem = aOldItem.parentItem;
} else if (!this.relaxedMode) {
if (!aOldItem || !this.mItems[aNewItem.id]) {
// no old item found? should be using addItem, then.
return reportError("ID for modifyItem doesn't exist, is null, or is from different calendar");
}
// do the old and new items match?
if (aOldItem.id != modifiedItem.id) {
return reportError("item ID mismatch between old and new items");
}
aOldItem = aOldItem.parentItem;
var storedOldItem = this.mItems[aOldItem.id];
// compareItems is not suitable here. See bug 418805.
// Cannot compare here due to bug 380060
if (!cal.compareItemContent(storedOldItem, aOldItem)) {
return reportError("old item mismatch in modifyItem" + " storedId:" + storedOldItem.icalComponent + " old item:" + aOldItem.icalComponent);
}
// offline bug
if (aOldItem.generation != storedOldItem.generation) {
return reportError("generation mismatch in modifyItem");
}
if (aOldItem.generation == modifiedItem.generation) { // has been cloned and modified
// Only take care of incrementing the generation if relaxed mode is
// off. Users of relaxed mode need to take care of this themselves.
modifiedItem.generation += 1;
}
}
modifiedItem.makeImmutable();
this.mItems[modifiedItem.id] = modifiedItem;
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.MODIFY,
modifiedItem.id,
modifiedItem);
// notify observers
this.mObservers.notify("onModifyItem", [modifiedItem, aOldItem]);
return null;
},
// void deleteItem( in calIItemBase aItem, in calIOperationListener aListener );
deleteItem: function (aItem, aListener) {
if (this.readOnly) {
this.notifyOperationComplete(aListener,
Components.interfaces.calIErrors.CAL_IS_READONLY,
Components.interfaces.calIOperationListener.DELETE,
aItem.id,
"Calendar is readonly");
return;
}
if (aItem.id == null) {
this.notifyOperationComplete(aListener,
Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.DELETE,
aItem.id,
"ID is null in deleteItem");
return;
}
var oldItem;
if (this.relaxedMode) {
oldItem = aItem;
} else {
oldItem = this.mItems[aItem.id];
if (oldItem.generation != aItem.generation) {
this.notifyOperationComplete(aListener,
Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.DELETE,
aItem.id,
"generation mismatch in deleteItem");
return;
}
}
delete this.mItems[aItem.id];
this.mMetaData.deleteProperty(aItem.id);
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.DELETE,
aItem.id,
aItem);
// notify observers
this.mObservers.notify("onDeleteItem", [oldItem]);
},
// void getItem( in string id, in calIOperationListener aListener );
getItem: function (aId, aListener) {
if (!aListener)
return;
if (aId == null || this.mItems[aId] == null) {
// querying by id is a valid use case, even if no item is returned:
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.GET,
aId,
null);
return;
}
var item = this.mItems[aId];
var iid = null;
if (cal.isEvent(item)) {
iid = Components.interfaces.calIEvent;
} else if (cal.isToDo(item)) {
iid = Components.interfaces.calITodo;
} else {
this.notifyOperationComplete(aListener,
Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.GET,
aId,
"Can't deduce item type based on QI");
return;
}
aListener.onGetResult (this.superCalendar,
Components.results.NS_OK,
iid,
null, 1, [item]);
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.GET,
aId,
null);
},
// void getItems( in unsigned long aItemFilter, in unsigned long aCount,
// in calIDateTime aRangeStart, in calIDateTime aRangeEnd,
// in calIOperationListener aListener );
getItems: function (aItemFilter, aCount,
aRangeStart, aRangeEnd, aListener) {
let this_ = this;
cal.postPone(function() {
this_.getItems_(aItemFilter, aCount, aRangeStart, aRangeEnd, aListener);
});
},
getItems_: function (aItemFilter, aCount,
aRangeStart, aRangeEnd, aListener)
{
if (!aListener)
return;
const calICalendar = Components.interfaces.calICalendar;
const calIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
var itemsFound = Array();
//
// filters
//
var wantUnrespondedInvitations = ((aItemFilter & calICalendar.ITEM_FILTER_REQUEST_NEEDS_ACTION) != 0);
var superCal;
try {
superCal = this.superCalendar.QueryInterface(Components.interfaces.calISchedulingSupport);
} catch (exc) {
wantUnrespondedInvitations = false;
}
function checkUnrespondedInvitation(item) {
var att = superCal.getInvitedAttendee(item);
return (att && (att.participationStatus == "NEEDS-ACTION"));
}
// item base type
var wantEvents = ((aItemFilter & calICalendar.ITEM_FILTER_TYPE_EVENT) != 0);
var wantTodos = ((aItemFilter & calICalendar.ITEM_FILTER_TYPE_TODO) != 0);
if(!wantEvents && !wantTodos) {
// bail.
this.notifyOperationComplete(aListener,
Components.results.NS_ERROR_FAILURE,
Components.interfaces.calIOperationListener.GET,
null,
"Bad aItemFilter passed to getItems");
return;
}
// completed?
var itemCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_YES) != 0);
var itemNotCompletedFilter = ((aItemFilter & calICalendar.ITEM_FILTER_COMPLETED_NO) != 0);
function checkCompleted(item) {
return (item.isCompleted ? itemCompletedFilter : itemNotCompletedFilter);
}
// return occurrences?
var itemReturnOccurrences = ((aItemFilter & calICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0);
// figure out the return interface type
var typeIID = null;
if (itemReturnOccurrences) {
typeIID = Components.interfaces.calIItemBase;
} else {
if (wantEvents && wantTodos) {
typeIID = Components.interfaces.calIItemBase;
} else if (wantEvents) {
typeIID = Components.interfaces.calIEvent;
} else if (wantTodos) {
typeIID = Components.interfaces.calITodo;
}
}
aRangeStart = cal.ensureDateTime(aRangeStart);
aRangeEnd = cal.ensureDateTime(aRangeEnd);
let offline_filter = aItemFilter &
(calICalendar.ITEM_FILTER_OFFLINE_DELETED |
calICalendar.ITEM_FILTER_OFFLINE_CREATED |
calICalendar.ITEM_FILTER_OFFLINE_MODIFIED);
for (let itemIndex in this.mItems) {
let item = this.mItems[itemIndex];
let isEvent_ = cal.isEvent(item);
if (isEvent_) {
if (!wantEvents) {
continue;
}
} else if (!wantTodos) {
continue;
}
let hasItemFlag = (item.id in this.mOfflineFlags);
let offlineFlag = (hasItemFlag ? this.mOfflineFlags[item.id] : null);
// If the offline flag doesn't match, skip the item
if ((hasItemFlag ||
(offline_filter != 0 && offlineFlag == cICL.OFFLINE_FLAG_DELETED_RECORD)) &&
(offlineFlag != offline_filter)) {
continue;
}
if (itemReturnOccurrences && item.recurrenceInfo) {
let startDate = aRangeStart;
if (!aRangeStart && cal.isToDo(item)) {
startDate = item.entryDate;
}
let occurrences = item.recurrenceInfo.getOccurrences(
startDate, aRangeEnd, aCount ? aCount - itemsFound.length : 0, {});
if (wantUnrespondedInvitations) {
occurrences = occurrences.filter(checkUnrespondedInvitation);
}
if (!isEvent_) {
occurrences = occurrences.filter(checkCompleted);
}
itemsFound = itemsFound.concat(occurrences);
} else if ((!wantUnrespondedInvitations || checkUnrespondedInvitation(item)) &&
(isEvent_ || checkCompleted(item)) &&
cal.checkIfInRange(item, aRangeStart, aRangeEnd)) {
// This needs fixing for recurring items, e.g. DTSTART of parent may occur before aRangeStart.
// This will be changed with bug 416975.
itemsFound.push(item);
}
if (aCount && itemsFound.length >= aCount) {
break;
}
}
aListener.onGetResult (this.superCalendar,
Components.results.NS_OK,
typeIID,
null,
itemsFound.length,
itemsFound);
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.GET,
null,
null);
},
//
// calIOfflineStorage interface
//
addOfflineItem: function addOfflineItem(aItem, aListener) {
this.mOfflineFlags[aItem.id] = cICL.OFFLINE_FLAG_CREATED_RECORD;
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.ADD,
aItem.id,
aItem);
},
modifyOfflineItem: function modifyOfflineItem(aItem, aListener) {
let oldFlag = this.mOfflineFlags[aItem.id];
if (oldFlag != cICL.OFFLINE_FLAG_CREATED_RECORD &&
oldFlag != cICL.OFFLINE_FLAG_DELETED_RECORD) {
this.mOfflineFlags[aItem.id] = cICL.OFFLINE_FLAG_MODIFIED_RECORD;
}
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.MODIFY,
aItem.id,
aItem);
},
deleteOfflineItem: function deleteOfflineItem(aItem, aListener) {
let oldFlag = this.mOfflineFlags[aItem.id];
if (oldFlag == cICL.OFFLINE_FLAG_CREATED_RECORD) {
delete this.mItems[aItem.id];
delete this.mOfflineFlags[aItem.id];
} else {
this.mOfflineFlags[aItem.id] = cICL.OFFLINE_FLAG_DELETED_RECORD;
}
this.notifyOperationComplete(aListener,
Components.results.NS_OK,
Components.interfaces.calIOperationListener.DELETE,
aItem.id,
aItem);
// notify observers
this.observers.notify("onDeleteItem", [aItem]);
},
getItemOfflineFlag: function getItemOfflineFlag(aItem, aListener) {
let flag = (aItem && aItem.id in this.mOfflineFlags ? this.mOfflineFlags[aItem.id] : null);
this.notifyOperationComplete(aListener, Components.results.NS_OK,
Components.interfaces.calIOperationListener.GET,
null, flag);
},
resetItemOfflineFlag: function resetItemOfflineFlag(aItem, aListener) {
delete this.mOfflineFlags[aItem.id];
this.notifyOperationComplete(aListener, Components.results.NS_OK,
Components.interfaces.calIOperationListener.MODIFY,
aItem.id, aItem);
},
//
// calISyncWriteCalendar interface
//
setMetaData: function memory_setMetaData(id, value) {
this.mMetaData.setProperty(id, value);
},
deleteMetaData: function memory_deleteMetaData(id) {
this.mMetaData.deleteProperty(id);
},
getMetaData: function memory_getMetaData(id) {
return this.mMetaData.getProperty(id);
},
getAllMetaData: function memory_getAllMetaData(out_count,
out_ids,
out_values) {
this.mMetaData.getAllProperties(out_ids, out_values);
out_count.value = out_ids.value.length;
}
};
/** Module Registration */
var NSGetFactory = XPCOMUtils.generateNSGetFactory([calMemoryCalendar]);
|