зеркало из https://github.com/mozilla/gecko-dev.git
Bug 345119: Set up and use architecture for helper functions in components, r=dmose
This commit is contained in:
Родитель
341097b456
Коммит
ab82bd8760
|
@ -87,6 +87,7 @@ EXTRA_COMPONENTS = \
|
|||
calTodo.js \
|
||||
calDateTimeFormatter.js \
|
||||
calWeekTitleService.js \
|
||||
calUtils.js \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
/* ***** 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 Calendar component utils.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Joey Minta <jminta@gmail.com>
|
||||
* Portions created by the Initial Developer are Copyright (C) 2006
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
/* This file contains commonly used functions in a centralized place so that
|
||||
* various components (and other js scopes) don't need to replicate them. Note
|
||||
* that loading this file twice in the same scope will throw errors.
|
||||
*/
|
||||
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
const Cr = Components.results;
|
||||
|
||||
/* Returns a clean new calIEvent */
|
||||
function createEvent() {
|
||||
return Cc["@mozilla.org/calendar/event;1"].createInstance(Ci.calIEvent);
|
||||
}
|
||||
|
||||
/* Returns a clean new calITodo */
|
||||
function createTodo() {
|
||||
return Cc["@mozilla.org/calendar/todo;1"].createInstance(Ci.calITodo);
|
||||
}
|
||||
|
||||
/* Returns a clean new calIDateTime */
|
||||
function createDateTime() {
|
||||
return Cc["@mozilla.org/calendar/datetime;1"].
|
||||
createInstance(Ci.calIDateTime);
|
||||
}
|
||||
|
||||
/* Shortcut to the calendar-manager service */
|
||||
function getCalendarManager() {
|
||||
return Components.classes["@mozilla.org/calendar/manager;1"].
|
||||
getService(Ci.calICalendarManager);
|
||||
}
|
||||
|
||||
/****
|
||||
**** debug code
|
||||
****/
|
||||
|
||||
/**
|
||||
* Logs a string or an object to both stderr and the js-console only in the case
|
||||
* where the calendar.debug.log pref is set to true.
|
||||
*
|
||||
* @param aArg either a string to log or an object whose entire set of
|
||||
* properties should be logged.
|
||||
*/
|
||||
function LOG(aArg) {
|
||||
var prefB = Cc["@mozilla.org/preferences-service;1"].
|
||||
getService(Ci.nsIPrefBranch);
|
||||
var shouldLog = false;
|
||||
try {
|
||||
shouldLog = prefB.getBoolPref("calendar.debug.log");
|
||||
} catch(ex) {}
|
||||
|
||||
if (!shouldLog) {
|
||||
return;
|
||||
}
|
||||
ASSERT(aArg, "Bad log argument.", false);
|
||||
var string;
|
||||
if (!(aArg instanceof String)) {
|
||||
var string = "Logging object...\n";
|
||||
for (var prop in aArg) {
|
||||
string += prop + ': ' + aArg[prop] + '\n';
|
||||
}
|
||||
string += "End object\n";
|
||||
} else {
|
||||
string = aArg;
|
||||
}
|
||||
|
||||
dump(string + '\n');
|
||||
var consoleSvc = Cc["@mozilla.org/consoleservice;1"].
|
||||
getService(Ci.nsIConsoleService);
|
||||
consoleSvc.logStringMessage(string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string describing the current js-stack. Note that this is
|
||||
* different than Components.stack, in that STACK just returns that js
|
||||
* functions that were called on the way to this function.
|
||||
*
|
||||
* @param aDepth (optional) The number of frames to include
|
||||
*/
|
||||
function STACK(aDepth) {
|
||||
var depth = aDepth || 5;
|
||||
var stack = "";
|
||||
var frame = arguments.callee.caller;
|
||||
for (var i = 1; i <= depth; i++) {
|
||||
stack += i+": "+ frame.name+ "\n";
|
||||
frame = frame.arguments.callee.caller;
|
||||
if (!frame) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs a message and the current js-stack, if aCondition fails
|
||||
*
|
||||
* @param aCondition the condition to test for
|
||||
* @param aMessage the message to report in the case the assert fails
|
||||
* @param aCritical if true, throw an error to stop current code execution
|
||||
* if false, code flow will continue
|
||||
*/
|
||||
function ASSERT(aCondition, aMessage, aCritical) {
|
||||
if (aCondition) {
|
||||
return;
|
||||
}
|
||||
|
||||
var string = "Assert failed: " + aMessage + '\n' + STACK();
|
||||
if (aCritical) {
|
||||
throw new Error(string);
|
||||
} else {
|
||||
Components.utils.reportError(string);
|
||||
}
|
||||
}
|
|
@ -58,13 +58,6 @@
|
|||
|
||||
const xmlHeader = '<?xml version="1.0" encoding="UTF-8"?>\n';
|
||||
|
||||
function debug(s) {
|
||||
const debugging = true;
|
||||
if (debugging) {
|
||||
dump(s);
|
||||
}
|
||||
}
|
||||
|
||||
function calDavCalendar() {
|
||||
this.wrappedJSObject = this;
|
||||
this.mObservers = Array();
|
||||
|
@ -75,14 +68,6 @@ const nsIWebDAVOperationListener =
|
|||
Components.interfaces.nsIWebDAVOperationListener;
|
||||
const calICalendar = Components.interfaces.calICalendar;
|
||||
const nsISupportsCString = Components.interfaces.nsISupportsCString;
|
||||
const calIEvent = Components.interfaces.calIEvent;
|
||||
const calIItemBase = Components.interfaces.calIItemBase;
|
||||
const calITodo = Components.interfaces.calITodo;
|
||||
const calEventClass = Components.classes["@mozilla.org/calendar/event;1"];
|
||||
|
||||
const kCalCalendarManagerContractID = "@mozilla.org/calendar/manager;1";
|
||||
const kCalICalendarManager = Components.interfaces.calICalendarManager;
|
||||
|
||||
|
||||
function makeOccurrence(item, start, end)
|
||||
{
|
||||
|
@ -93,16 +78,6 @@ function makeOccurrence(item, start, end)
|
|||
|
||||
return occ;
|
||||
}
|
||||
|
||||
var activeCalendarManager = null;
|
||||
function getCalendarManager()
|
||||
{
|
||||
if (!activeCalendarManager) {
|
||||
activeCalendarManager =
|
||||
Components.classes[kCalCalendarManagerContractID].getService(kCalICalendarManager);
|
||||
}
|
||||
return activeCalendarManager;
|
||||
}
|
||||
|
||||
// END_OF_TIME needs to be the max value a PRTime can be
|
||||
const START_OF_TIME = -0x7fffffffffffffff;
|
||||
|
@ -219,7 +194,7 @@ calDavCalendar.prototype = {
|
|||
var locationPath = aItem.id + ".ics";
|
||||
var itemUri = this.mCalendarUri.clone();
|
||||
itemUri.spec = itemUri.spec + locationPath;
|
||||
debug("itemUri.spec = " + itemUri.spec + "\n");
|
||||
LOG("itemUri.spec = " + itemUri.spec);
|
||||
var eventResource = new WebDavResource(itemUri);
|
||||
|
||||
var listener = new WebDavListener();
|
||||
|
@ -230,16 +205,16 @@ calDavCalendar.prototype = {
|
|||
// 201 = HTTP "Created"
|
||||
//
|
||||
if (aStatusCode == 201) {
|
||||
debug("Item added successfully\n");
|
||||
LOG("Item added successfully");
|
||||
|
||||
var retVal = Components.results.NS_OK;
|
||||
|
||||
} else if (aStatusCode == 200) {
|
||||
// XXXdmose once we get etag stuff working, this should
|
||||
//
|
||||
debug("200 received from clients, until we have etags working"
|
||||
LOG("200 received from clients, until we have etags working"
|
||||
+ " this probably means a collision; after that it'll"
|
||||
+ " mean server malfunction/n");
|
||||
+ " mean server malfunction");
|
||||
retVal = Components.results.NS_ERROR_FAILURE;
|
||||
} else {
|
||||
if (aStatusCode > 999) {
|
||||
|
@ -247,7 +222,7 @@ calDavCalendar.prototype = {
|
|||
}
|
||||
|
||||
// XXX real error handling
|
||||
debug("Error adding item: " + aStatusCode + "\n");
|
||||
LOG("Error adding item: " + aStatusCode);
|
||||
retVal = Components.results.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
@ -260,8 +235,8 @@ calDavCalendar.prototype = {
|
|||
aItem.id,
|
||||
aItem);
|
||||
} catch (ex) {
|
||||
debug("addItem's onOperationComplete threw an exception "
|
||||
+ ex + "; ignoring\n");
|
||||
LOG("addItem's onOperationComplete threw an exception "
|
||||
+ ex + "; ignoring");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -276,7 +251,7 @@ calDavCalendar.prototype = {
|
|||
aItem.setProperty("X-MOZ-LOCATIONPATH", locationPath);
|
||||
aItem.makeImmutable();
|
||||
|
||||
debug("icalString = " + aItem.icalString + "\n");
|
||||
LOG("icalString = " + aItem.icalString);
|
||||
|
||||
// XXX use if not exists
|
||||
// do WebDAV put
|
||||
|
@ -306,8 +281,8 @@ calDavCalendar.prototype = {
|
|||
aItem.id,
|
||||
"ID for modifyItem doesn't exist or is null");
|
||||
} catch (ex) {
|
||||
debug("modifyItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring\n");
|
||||
LOG("modifyItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -317,7 +292,7 @@ calDavCalendar.prototype = {
|
|||
var eventUri = this.mCalendarUri.clone();
|
||||
try {
|
||||
eventUri.spec = this.mCalendarUri.spec + aNewItem.getProperty("X-MOZ-LOCATIONPATH");
|
||||
debug("using X-MOZ-LOCATIONPATH: " + eventUri.spec + "\n");
|
||||
LOG("using X-MOZ-LOCATIONPATH: " + eventUri.spec);
|
||||
} catch (ex) {
|
||||
// XXX how are we REALLY supposed to figure this out?
|
||||
eventUri.spec = eventUri.spec + aNewItem.id + ".ics";
|
||||
|
@ -334,14 +309,14 @@ calDavCalendar.prototype = {
|
|||
// 204 = HTTP "No Content"
|
||||
//
|
||||
if (aStatusCode == 204 || aStatusCode == 201) {
|
||||
debug("Item modified successfully.\n");
|
||||
LOG("Item modified successfully.");
|
||||
var retVal = Components.results.NS_OK;
|
||||
|
||||
} else {
|
||||
if (aStatusCode > 999) {
|
||||
aStatusCode = "0x " + aStatusCode.toString(16);
|
||||
}
|
||||
debug("Error modifying item: " + aStatusCode + "\n");
|
||||
LOG("Error modifying item: " + aStatusCode);
|
||||
|
||||
// XXX deal with non-existent item here, other
|
||||
// real error handling
|
||||
|
@ -360,8 +335,8 @@ calDavCalendar.prototype = {
|
|||
aListener.MODIFY,
|
||||
aNewItem.id, aNewItem);
|
||||
} catch (ex) {
|
||||
debug("modifyItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring\n");
|
||||
LOG("modifyItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,8 +351,7 @@ calDavCalendar.prototype = {
|
|||
// XXX use if-exists stuff here
|
||||
// XXX use etag as generation
|
||||
// do WebDAV put
|
||||
debug("modifyItem: aNewItem.icalString = " + aNewItem.icalString
|
||||
+ "\n");
|
||||
LOG("modifyItem: aNewItem.icalString = " + aNewItem.icalString);
|
||||
var webSvc = Components.classes['@mozilla.org/webdav/service;1']
|
||||
.getService(Components.interfaces.nsIWebDAVService);
|
||||
webSvc.putFromString(eventResource, "text/calendar",
|
||||
|
@ -418,10 +392,10 @@ calDavCalendar.prototype = {
|
|||
// 204 = HTTP "No content"
|
||||
//
|
||||
if (aStatusCode == 204) {
|
||||
debug("Item deleted successfully.\n");
|
||||
LOG("Item deleted successfully.");
|
||||
var retVal = Components.results.NS_OK;
|
||||
} else {
|
||||
debug("Error deleting item: " + aStatusCode + "\n");
|
||||
LOG("Error deleting item: " + aStatusCode);
|
||||
// XXX real error handling here
|
||||
retVal = Components.results.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -435,8 +409,8 @@ calDavCalendar.prototype = {
|
|||
aItem.id,
|
||||
null);
|
||||
} catch (ex) {
|
||||
debug("deleteItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring\n");
|
||||
LOG("deleteItem's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -548,7 +522,7 @@ calDavCalendar.prototype = {
|
|||
|
||||
// create a local event item
|
||||
// XXX not just events
|
||||
var item = calEventClass.createInstance(calIEvent);
|
||||
var item = createEvent();
|
||||
|
||||
// cause returned data to be parsed into the event item
|
||||
var calData = responseElement..C::["calendar-data"];
|
||||
|
@ -559,7 +533,7 @@ calDavCalendar.prototype = {
|
|||
">; ignoring");
|
||||
return;
|
||||
}
|
||||
debug("item result = \n" + calData + "\n");
|
||||
LOG("item result = \n" + calData);
|
||||
// XXX try-catch
|
||||
item.icalString = calData;
|
||||
item.calendar = thisCalendar;
|
||||
|
@ -568,16 +542,16 @@ calDavCalendar.prototype = {
|
|||
var locationPath = decodeURIComponent(aResource.path)
|
||||
.substr(thisCalendar.mCalendarUri.path.length);
|
||||
item.setProperty("X-MOZ-LOCATIONPATH", locationPath);
|
||||
debug("X-MOZ-LOCATIONPATH = " + locationPath + "\n");
|
||||
LOG("X-MOZ-LOCATIONPATH = " + locationPath);
|
||||
item.makeImmutable();
|
||||
|
||||
// figure out what type of item to return
|
||||
var iid;
|
||||
if(aOccurrences) {
|
||||
iid = calIItemBase;
|
||||
iid = Ci.calIItemBase;
|
||||
if (item.recurrenceInfo) {
|
||||
debug("ITEM has recurrence: " + item + " (" + item.title + ")\n");
|
||||
debug("rangestart: " + aRangeStart.jsDate + " -> " + aRangeEnd.jsDate + "\n");
|
||||
LOG("ITEM has recurrence: " + item + " (" + item.title + ")");
|
||||
LOG("rangestart: " + aRangeStart.jsDate + " -> " + aRangeEnd.jsDate);
|
||||
// XXX does getOcc call makeImmutable?
|
||||
items = item.recurrenceInfo.getOccurrences(aRangeStart,
|
||||
aRangeEnd,
|
||||
|
@ -587,12 +561,12 @@ calDavCalendar.prototype = {
|
|||
items = [ item ];
|
||||
}
|
||||
rv = Components.results.NS_OK;
|
||||
} else if (item.QueryInterface(calIEvent)) {
|
||||
iid = calIEvent;
|
||||
} else if (item.QueryInterface(Ci.calIEvent)) {
|
||||
iid = Ci.calIEvent;
|
||||
rv = Components.results.NS_OK;
|
||||
items = [ item ];
|
||||
} else if (item.QueryInterface(calITodo)) {
|
||||
iid = calITodo;
|
||||
} else if (item.QueryInterface(Ci.calITodo)) {
|
||||
iid = Ci.calITodo;
|
||||
rv = Components.results.NS_OK;
|
||||
items = [ item ];
|
||||
} else {
|
||||
|
@ -602,14 +576,14 @@ calDavCalendar.prototype = {
|
|||
|
||||
} else {
|
||||
// XXX
|
||||
debug("aStatusCode = " + aStatusCode + "\n");
|
||||
LOG("aStatusCode = " + aStatusCode);
|
||||
errString = "XXX";
|
||||
rv = Components.results.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// XXX handle aCount
|
||||
if (errString) {
|
||||
debug("errString = " + errString + "\n");
|
||||
LOG("errString = " + errString);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -617,8 +591,8 @@ calDavCalendar.prototype = {
|
|||
items ? items.length : 0,
|
||||
errString ? errString : items);
|
||||
} catch (ex) {
|
||||
debug("reportInternal's onGetResult threw an"
|
||||
+ " exception " + ex + "; ignoring\n");
|
||||
LOG("reportInternal's onGetResult threw an"
|
||||
+ " exception " + ex + "; ignoring");
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
@ -648,8 +622,8 @@ calDavCalendar.prototype = {
|
|||
errString);
|
||||
}
|
||||
} catch (ex) {
|
||||
debug("reportInternal's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring\n");
|
||||
LOG("reportInternal's onOperationComplete threw an"
|
||||
+ " exception " + ex + "; ignoring");
|
||||
}
|
||||
|
||||
return;
|
||||
|
@ -662,7 +636,7 @@ calDavCalendar.prototype = {
|
|||
|
||||
// construct the resource we want to search against
|
||||
var calendarDirUri = this.mCalendarUri.clone();
|
||||
debug("report uri = " + calendarDirUri.spec + "\n");
|
||||
LOG("report uri = " + calendarDirUri.spec);
|
||||
var calendarDirResource = new WebDavResource(calendarDirUri);
|
||||
|
||||
var webSvc = Components.classes['@mozilla.org/webdav/service;1']
|
||||
|
@ -720,7 +694,7 @@ calDavCalendar.prototype = {
|
|||
}
|
||||
|
||||
if (filterTypes < 1) {
|
||||
debug("No item types specified\n");
|
||||
LOG("No item types specified");
|
||||
// XXX should we just quietly call back the completion method?
|
||||
throw NS_ERROR_FAILURE;
|
||||
}
|
||||
|
@ -749,8 +723,7 @@ calDavCalendar.prototype = {
|
|||
}
|
||||
|
||||
var queryString = xmlHeader + queryXml.toXMLString();
|
||||
debug("getItems(): querying CalDAV server for events: \n" +
|
||||
queryString + "\n");
|
||||
LOG("getItems(): querying CalDAV server for events: \n" + queryString);
|
||||
|
||||
var occurrences = (aItemFilter &
|
||||
calICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0;
|
||||
|
@ -793,15 +766,15 @@ calDavCalendar.prototype = {
|
|||
try {
|
||||
obs.onStartBatch();
|
||||
} catch (ex) {
|
||||
debug("observer's onStartBatch threw an exception " + ex
|
||||
+ "; ignoring\n");
|
||||
LOG("observer's onStartBatch threw an exception " + ex
|
||||
+ "; ignoring");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
obs.onEndBatch();
|
||||
} catch (ex) {
|
||||
debug("observer's onEndBatch threw an exception " + ex
|
||||
+ "; ignoring\n");
|
||||
LOG("observer's onEndBatch threw an exception " + ex
|
||||
+ "; ignoring");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -814,8 +787,8 @@ calDavCalendar.prototype = {
|
|||
try {
|
||||
obs.onAddItem(aItem);
|
||||
} catch (ex) {
|
||||
debug("observer's onAddItem threw an exception " + ex
|
||||
+ "; ignoring\n");
|
||||
LOG("observer's onAddItem threw an exception " + ex
|
||||
+ "; ignoring");
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -827,8 +800,8 @@ calDavCalendar.prototype = {
|
|||
try {
|
||||
obs.onModifyItem(aNewItem, aOldItem);
|
||||
} catch (ex) {
|
||||
debug("observer's onModifyItem threw an exception " + ex
|
||||
+ "; ignoring\n");
|
||||
LOG("observer's onModifyItem threw an exception " + ex
|
||||
+ "; ignoring");
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -840,8 +813,8 @@ calDavCalendar.prototype = {
|
|||
try {
|
||||
obs.onDeleteItem(aDeletedItem);
|
||||
} catch (ex) {
|
||||
debug("observer's onDeleteItem threw an exception " + ex
|
||||
+ "; ignoring\n");
|
||||
LOG("observer's onDeleteItem threw an exception " + ex
|
||||
+ "; ignoring");
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
@ -888,13 +861,13 @@ WebDavListener.prototype = {
|
|||
// aClosure is the listener
|
||||
aClosure.onOperationComplete(this, aStatusCode, 0, null, null);
|
||||
|
||||
debug("WebDavListener.onOperationComplete() called\n");
|
||||
LOG("WebDavListener.onOperationComplete() called");
|
||||
return;
|
||||
},
|
||||
|
||||
onOperationDetail: function(aStatusCode, aResource, aOperation, aDetail,
|
||||
aClosure) {
|
||||
debug("WebDavListener.onOperationDetail() called\n");
|
||||
LOG("WebDavListener.onOperationDetail() called");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -906,6 +879,37 @@ WebDavListener.prototype = {
|
|||
var calDavCalendarModule = {
|
||||
mCID: Components.ID("{a35fc6ea-3d92-11d9-89f9-00045ace3b8d}"),
|
||||
mContractID: "@mozilla.org/calendar/calendar;1?type=caldav",
|
||||
|
||||
mUtilsLoaded: false,
|
||||
loadUtils: function storageLoadUtils() {
|
||||
if (this.mUtilsLoaded)
|
||||
return;
|
||||
|
||||
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
const iosvcContractID = "@mozilla.org/network/io-service;1";
const iosvcIID = Components.interfaces.nsIIOService;
|
||||
|
||||
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
||||
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
||||
|
||||
// Utils lives in the same directory we're in
|
||||
var appdir = __LOCATION__.parent;
|
||||
var scriptName = "calUtils.js";
|
||||
|
||||
var f = appdir.clone();
|
||||
f.append(scriptName);
|
||||
|
||||
try {
|
||||
var fileurl = iosvc.newFileURI(f);
|
||||
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
||||
} catch (e) {
|
||||
dump("Error while loading " + fileurl.spec + "\n");
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.mUtilsLoaded = true;
|
||||
},
|
||||
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
|
@ -924,6 +928,8 @@ var calDavCalendarModule = {
|
|||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
this.loadUtils();
|
||||
|
||||
return this.mFactory;
|
||||
},
|
||||
|
||||
|
|
|
@ -130,15 +130,6 @@ calCompositeCalendar.prototype = {
|
|||
mPrefPrefix: null,
|
||||
mDefaultPref: null,
|
||||
mActivePref: null,
|
||||
_mCalMgr: null,
|
||||
get mCalMgr () {
|
||||
if (!this._mCalMgr) {
|
||||
this._mCalMgr = Components.
|
||||
classes["@mozilla.org/calendar/manager;1"].
|
||||
getService(Components.interfaces.calICalendarManager);
|
||||
}
|
||||
return this._mCalMgr;
|
||||
},
|
||||
|
||||
set prefPrefix (aPrefPrefix) {
|
||||
if (this.mPrefPrefix) {
|
||||
|
@ -147,7 +138,7 @@ calCompositeCalendar.prototype = {
|
|||
this.mPrefPrefix = aPrefPrefix;
|
||||
this.mActivePref = aPrefPrefix + "-in-composite";
|
||||
this.mDefaultPref = aPrefPrefix + "-default";
|
||||
var mgr = this.mCalMgr;
|
||||
var mgr = getCalendarManager();
|
||||
var cals = mgr.getCalendars({});
|
||||
|
||||
cals.forEach(function (c) {
|
||||
|
@ -176,7 +167,7 @@ calCompositeCalendar.prototype = {
|
|||
|
||||
this.mCalendars.push(aCalendar);
|
||||
if (this.mPrefPrefix) {
|
||||
this.mCalMgr.setCalendarPref(aCalendar, this.mActivePref,
|
||||
getCalendarManager().setCalendarPref(aCalendar, this.mActivePref,
|
||||
"true");
|
||||
}
|
||||
this.notifyObservers("onCalendarAdded", [aCalendar]);
|
||||
|
@ -199,9 +190,9 @@ calCompositeCalendar.prototype = {
|
|||
if (calToRemove) {
|
||||
this.mCalendars = newCalendars;
|
||||
if (this.mPrefPrefix) {
|
||||
this.mCalMgr.deleteCalendarPref(calToRemove,
|
||||
getCalendarManager().deleteCalendarPref(calToRemove,
|
||||
this.mActivePref);
|
||||
this.mCalMgr.deleteCalendarPref(calToRemove,
|
||||
getCalendarManager().deleteCalendarPref(calToRemove,
|
||||
this.mDefaultPref);
|
||||
}
|
||||
calToRemove.removeObserver(this.mObserverHelper);
|
||||
|
@ -233,10 +224,10 @@ calCompositeCalendar.prototype = {
|
|||
return;
|
||||
if (usePref && this.mPrefPrefix) {
|
||||
if (this.mDefaultCalendar) {
|
||||
this.mCalMgr.deleteCalendarPref(this.mDefaultCalendar,
|
||||
getCalendarManager().deleteCalendarPref(this.mDefaultCalendar,
|
||||
this.mDefaultPref);
|
||||
}
|
||||
this.mCalMgr.setCalendarPref(cal, this.mDefaultPref,
|
||||
getCalendarManager().setCalendarPref(cal, this.mDefaultPref,
|
||||
"true");
|
||||
}
|
||||
this.mDefaultCalendar = cal;
|
||||
|
@ -469,6 +460,37 @@ calCompositeGetListenerHelper.prototype = {
|
|||
var calCompositeCalendarModule = {
|
||||
mCID: Components.ID("{aeff788d-63b0-4996-91fb-40a7654c6224}"),
|
||||
mContractID: "@mozilla.org/calendar/calendar;1?type=composite",
|
||||
|
||||
mUtilsLoaded: false,
|
||||
loadUtils: function compositeLoadUtils() {
|
||||
if (this.mUtilsLoaded)
|
||||
return;
|
||||
|
||||
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
const iosvcContractID = "@mozilla.org/network/io-service;1";
const iosvcIID = Components.interfaces.nsIIOService;
|
||||
|
||||
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
||||
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
||||
|
||||
// Utils lives in the same directory we're in
|
||||
var appdir = __LOCATION__.parent;
|
||||
var scriptName = "calUtils.js";
|
||||
|
||||
var f = appdir.clone();
|
||||
f.append(scriptName);
|
||||
|
||||
try {
|
||||
var fileurl = iosvc.newFileURI(f);
|
||||
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
||||
} catch (e) {
|
||||
dump("Error while loading " + fileurl.spec + "\n");
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.mUtilsLoaded = true;
|
||||
},
|
||||
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
|
@ -487,6 +509,8 @@ var calCompositeCalendarModule = {
|
|||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
this.loadUtils();
|
||||
|
||||
return this.mFactory;
|
||||
},
|
||||
|
||||
|
|
|
@ -50,26 +50,12 @@
|
|||
const CI = Components.interfaces;
|
||||
const calIOperationListener = Components.interfaces.calIOperationListener;
|
||||
const calICalendar = Components.interfaces.calICalendar;
|
||||
const calCalendarManagerContractID = "@mozilla.org/calendar/manager;1";
|
||||
const calICalendarManager = Components.interfaces.calICalendarManager;
|
||||
const calIErrors = Components.interfaces.calIErrors;
|
||||
|
||||
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].
|
||||
getService(Components.interfaces.nsIXULAppInfo);
|
||||
var isOnBranch = appInfo.platformVersion.indexOf("1.8") == 0;
|
||||
|
||||
|
||||
var activeCalendarManager = null;
|
||||
function getCalendarManager()
|
||||
{
|
||||
if (!activeCalendarManager) {
|
||||
activeCalendarManager =
|
||||
Components.classes[calCalendarManagerContractID].getService(calICalendarManager);
|
||||
}
|
||||
return activeCalendarManager;
|
||||
}
|
||||
|
||||
|
||||
function calICSCalendar () {
|
||||
this.wrappedJSObject = this;
|
||||
this.initICSCalendar();
|
||||
|
@ -252,7 +238,7 @@ calICSCalendar.prototype = {
|
|||
while (prop) {
|
||||
if (!this.calendarPromotedProps[prop.propertyName]) {
|
||||
this.unmappedProperties.push(prop);
|
||||
dump(prop.propertyName+"\n");
|
||||
LOG(prop.propertyName);
|
||||
}
|
||||
prop = calComp.getNextProperty("ANY");
|
||||
}
|
||||
|
@ -265,12 +251,10 @@ calICSCalendar.prototype = {
|
|||
var item = null;
|
||||
switch (subComp.componentType) {
|
||||
case "VEVENT":
|
||||
item = Components.classes["@mozilla.org/calendar/event;1"]
|
||||
.createInstance(Components.interfaces.calIEvent);
|
||||
item = createEvent();
|
||||
break;
|
||||
case "VTODO":
|
||||
item = Components.classes["@mozilla.org/calendar/todo;1"]
|
||||
.createInstance(Components.interfaces.calITodo);
|
||||
item = createTodo();
|
||||
break;
|
||||
case "VTIMEZONE":
|
||||
// this should already be attached to the relevant
|
||||
|
@ -279,7 +263,7 @@ calICSCalendar.prototype = {
|
|||
break;
|
||||
default:
|
||||
this.unmappedComponents.push(subComp);
|
||||
dump(subComp.componentType+"\n");
|
||||
LOG(subComp.componentType);
|
||||
}
|
||||
if (item != null) {
|
||||
item.icalComponent = subComp;
|
||||
|
@ -323,7 +307,7 @@ calICSCalendar.prototype = {
|
|||
}
|
||||
|
||||
} catch(e) {
|
||||
dump("Parsing the file failed:"+e+"\n");
|
||||
LOG("Parsing the file failed:"+e);
|
||||
this.mObserver.onError(e.result, e.toString());
|
||||
}
|
||||
this.mObserver.onEndBatch();
|
||||
|
@ -405,11 +389,11 @@ calICSCalendar.prototype = {
|
|||
|
||||
var i;
|
||||
for (i in this.unmappedComponents) {
|
||||
dump("Adding a "+this.unmappedComponents[i].componentType+"\n");
|
||||
LOG("Adding a "+this.unmappedComponents[i].componentType);
|
||||
calComp.addSubcomponent(this.unmappedComponents[i]);
|
||||
}
|
||||
for (i in this.unmappedProperties) {
|
||||
dump("Adding "+this.unmappedProperties[i].propertyName+"\n");
|
||||
LOG("Adding "+this.unmappedProperties[i].propertyName);
|
||||
calComp.addProperty(this.unmappedProperties[i]);
|
||||
}
|
||||
|
||||
|
@ -427,7 +411,7 @@ calICSCalendar.prototype = {
|
|||
var channel;
|
||||
try {
|
||||
channel = request.QueryInterface(Components.interfaces.nsIHttpChannel);
|
||||
dump(channel.requestSucceeded+"\n");
|
||||
LOG(channel.requestSucceeded);
|
||||
} catch(e) {
|
||||
}
|
||||
|
||||
|
@ -682,7 +666,7 @@ calICSCalendar.prototype = {
|
|||
} catch(e) {
|
||||
// Backup dir wasn't found. Likely because we are running in
|
||||
// xpcshell. Don't die, but continue the upload.
|
||||
dump("Backup failed, no backupdir:"+e+"\n");
|
||||
LOG("Backup failed, no backupdir:"+e);
|
||||
aCallback.call(this);
|
||||
return;
|
||||
}
|
||||
|
@ -696,7 +680,7 @@ calICSCalendar.prototype = {
|
|||
} catch(e) {
|
||||
// calendarmgr not found. Likely because we are running in
|
||||
// xpcshell. Don't die, but continue the upload.
|
||||
dump("Backup failed, no calendarmanager:"+e+"\n");
|
||||
LOG("Backup failed, no calendarmanager:"+e);
|
||||
aCallback.call(this);
|
||||
return;
|
||||
}
|
||||
|
@ -757,7 +741,7 @@ calICSCalendar.prototype = {
|
|||
} catch(e) {
|
||||
// For local files, asyncOpen throws on new (calendar) files
|
||||
// No problem, go and upload something
|
||||
dump("Backup failed in asyncOpen:"+e+"\n");
|
||||
LOG("Backup failed in asyncOpen:"+e);
|
||||
aCallback.call(this);
|
||||
return;
|
||||
}
|
||||
|
@ -1011,6 +995,37 @@ var calICSCalendarModule = {
|
|||
|
||||
mCID: Components.ID("{f8438bff-a3c9-4ed5-b23f-2663b5469abf}"),
|
||||
mContractID: "@mozilla.org/calendar/calendar;1?type=ics",
|
||||
|
||||
mUtilsLoaded: false,
|
||||
loadUtils: function icsLoadUtils() {
|
||||
if (this.mUtilsLoaded)
|
||||
return;
|
||||
|
||||
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
const iosvcContractID = "@mozilla.org/network/io-service;1";
const iosvcIID = Components.interfaces.nsIIOService;
|
||||
|
||||
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
||||
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
||||
|
||||
// Utils lives in the same directory we're in
|
||||
var appdir = __LOCATION__.parent;
|
||||
var scriptName = "calUtils.js";
|
||||
|
||||
var f = appdir.clone();
|
||||
f.append(scriptName);
|
||||
|
||||
try {
|
||||
var fileurl = iosvc.newFileURI(f);
|
||||
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
||||
} catch (e) {
|
||||
dump("Error while loading " + fileurl.spec + "\n");
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.mUtilsLoaded = true;
|
||||
},
|
||||
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
|
@ -1029,6 +1044,8 @@ var calICSCalendarModule = {
|
|||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
this.loadUtils();
|
||||
|
||||
return this.mFactory;
|
||||
},
|
||||
|
||||
|
|
|
@ -45,16 +45,6 @@ const calICalendarManager = Components.interfaces.calICalendarManager;
|
|||
|
||||
const USECS_PER_SECOND = 1000000;
|
||||
|
||||
var activeCalendarManager = null;
|
||||
function getCalendarManager()
|
||||
{
|
||||
if (!activeCalendarManager) {
|
||||
activeCalendarManager =
|
||||
Components.classes[calCalendarManagerContractID].getService(calICalendarManager);
|
||||
}
|
||||
return activeCalendarManager;
|
||||
}
|
||||
|
||||
function calMemoryCalendar() {
|
||||
this.wrappedJSObject = this;
|
||||
this.calendarToReturn = this,
|
||||
|
@ -319,10 +309,10 @@ calMemoryCalendar.prototype = {
|
|||
var item = this.mItems[aId];
|
||||
var iid = null;
|
||||
|
||||
if (item instanceof Components.interfaces.calIEvent) {
|
||||
iid = Components.interfaces.calIEvent;
|
||||
} else if (item instanceof Components.interfaces.calITodo) {
|
||||
iid = Components.interfaces.calITodo;
|
||||
if (item instanceof Ci.calIEvent) {
|
||||
iid = Ci.calIEvent;
|
||||
} else if (item instanceof Ci.calITodo) {
|
||||
iid = Ci.calITodo;
|
||||
} else {
|
||||
aListener.onOperationComplete (this.calendarToReturn,
|
||||
Components.results.NS_ERROR_FAILURE,
|
||||
|
@ -355,9 +345,6 @@ calMemoryCalendar.prototype = {
|
|||
return;
|
||||
|
||||
const calICalendar = Components.interfaces.calICalendar;
|
||||
const calIItemBase = Components.interfaces.calIItemBase;
|
||||
const calIEvent = Components.interfaces.calIEvent;
|
||||
const calITodo = Components.interfaces.calITodo;
|
||||
const calIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
|
||||
|
||||
var itemsFound = Array();
|
||||
|
@ -395,14 +382,14 @@ calMemoryCalendar.prototype = {
|
|||
// figure out the return interface type
|
||||
var typeIID = null;
|
||||
if (itemReturnOccurrences) {
|
||||
typeIID = calIItemBase;
|
||||
typeIID = Ci.calIItemBase;
|
||||
} else {
|
||||
if (wantEvents && wantTodos) {
|
||||
typeIID = calIItemBase;
|
||||
typeIID = Ci.calIItemBase;
|
||||
} else if (wantEvents) {
|
||||
typeIID = calIEvent;
|
||||
typeIID = Ci.calIEvent;
|
||||
} else if (wantTodos) {
|
||||
typeIID = calITodo;
|
||||
typeIID = Ci.calITodo;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -417,15 +404,15 @@ calMemoryCalendar.prototype = {
|
|||
var itemEndTime = 0;
|
||||
|
||||
var tmpitem = item;
|
||||
if (wantEvents && (item instanceof calIEvent)) {
|
||||
tmpitem = item.QueryInterface(calIEvent);
|
||||
if (wantEvents && (item instanceof Ci.calIEvent)) {
|
||||
tmpitem = item.QueryInterface(Ci.calIEvent);
|
||||
itemStartTime = (item.startDate
|
||||
? item.startDate.nativeTime
|
||||
: START_OF_TIME);
|
||||
itemEndTime = (item.endDate
|
||||
? item.endDate.nativeTime
|
||||
: END_OF_TIME);
|
||||
} else if (wantTodos && (item instanceof calITodo)) {
|
||||
} else if (wantTodos && (item instanceof Ci.calITodo)) {
|
||||
// if it's a todo, also filter based on completeness
|
||||
if (item.isCompleted && !itemCompletedFilter)
|
||||
continue;
|
||||
|
@ -509,7 +496,7 @@ calMemoryCalendar.prototype = {
|
|||
observeDeleteItem: function (aDeletedItem) {
|
||||
for each (obs in this.mObservers)
|
||||
obs.onDeleteItem (aDeletedItem);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/****
|
||||
|
@ -519,6 +506,38 @@ calMemoryCalendar.prototype = {
|
|||
var calMemoryCalendarModule = {
|
||||
mCID: Components.ID("{bda0dd7f-0a2f-4fcf-ba08-5517e6fbf133}"),
|
||||
mContractID: "@mozilla.org/calendar/calendar;1?type=memory",
|
||||
|
||||
mUtilsLoaded: false,
|
||||
loadUtils: function memoryLoadUtils() {
|
||||
if (this.mUtilsLoaded)
|
||||
return;
|
||||
|
||||
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
const iosvcContractID = "@mozilla.org/network/io-service;1";
const iosvcIID = Components.interfaces.nsIIOService;
|
||||
|
||||
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
||||
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
||||
|
||||
// Utils lives in the same directory we're in
|
||||
var appdir = __LOCATION__.parent;
|
||||
var scriptName = "calUtils.js";
|
||||
|
||||
var f = appdir.clone();
|
||||
f.append(scriptName);
|
||||
|
||||
try {
|
||||
var fileurl = iosvc.newFileURI(f);
|
||||
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
||||
} catch (e) {
|
||||
dump("Error while loading " + fileurl.spec + "\n");
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.mUtilsLoaded = true;
|
||||
},
|
||||
|
||||
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
|
@ -537,6 +556,8 @@ var calMemoryCalendarModule = {
|
|||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
this.loadUtils();
|
||||
|
||||
return this.mFactory;
|
||||
},
|
||||
|
||||
|
|
|
@ -48,21 +48,6 @@ const kStorageServiceIID = Components.interfaces.mozIStorageService;
|
|||
|
||||
const kCalICalendar = Components.interfaces.calICalendar;
|
||||
|
||||
const kCalCalendarManagerContractID = "@mozilla.org/calendar/manager;1";
|
||||
const kCalICalendarManager = Components.interfaces.calICalendarManager;
|
||||
|
||||
const kCalEventContractID = "@mozilla.org/calendar/event;1";
|
||||
const kCalIEvent = Components.interfaces.calIEvent;
|
||||
var CalEvent;
|
||||
|
||||
const kCalTodoContractID = "@mozilla.org/calendar/todo;1";
|
||||
const kCalITodo = Components.interfaces.calITodo;
|
||||
var CalTodo;
|
||||
|
||||
const kCalDateTimeContractID = "@mozilla.org/calendar/datetime;1";
|
||||
const kCalIDateTime = Components.interfaces.calIDateTime;
|
||||
var CalDateTime;
|
||||
|
||||
const kCalAttendeeContractID = "@mozilla.org/calendar/attendee;1";
|
||||
const kCalIAttendee = Components.interfaces.calIAttendee;
|
||||
var CalAttendee;
|
||||
|
@ -105,9 +90,6 @@ const CAL_ITEM_FLAG_HAS_EXCEPTIONS = 32;
|
|||
const USECS_PER_SECOND = 1000000;
|
||||
|
||||
function initCalStorageCalendarComponent() {
|
||||
CalEvent = new Components.Constructor(kCalEventContractID, kCalIEvent);
|
||||
CalTodo = new Components.Constructor(kCalTodoContractID, kCalITodo);
|
||||
CalDateTime = new Components.Constructor(kCalDateTimeContractID, kCalIDateTime);
|
||||
CalAttendee = new Components.Constructor(kCalAttendeeContractID, kCalIAttendee);
|
||||
CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
|
||||
CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
|
||||
|
@ -196,7 +178,7 @@ function dateToText(d) {
|
|||
//
|
||||
|
||||
function newDateTime(aNativeTime, aTimezone) {
|
||||
var t = new CalDateTime();
|
||||
var t = createDateTime();
|
||||
t.nativeTime = aNativeTime;
|
||||
if (aTimezone && aTimezone != "floating") {
|
||||
t = t.getInTimezone(aTimezone);
|
||||
|
@ -211,16 +193,6 @@ function newDateTime(aNativeTime, aTimezone) {
|
|||
// calStorageCalendar
|
||||
//
|
||||
|
||||
var activeCalendarManager = null;
|
||||
function getCalendarManager()
|
||||
{
|
||||
if (!activeCalendarManager) {
|
||||
activeCalendarManager =
|
||||
Components.classes[kCalCalendarManagerContractID].getService(kCalICalendarManager);
|
||||
}
|
||||
return activeCalendarManager;
|
||||
}
|
||||
|
||||
function calStorageCalendar() {
|
||||
this.wrappedJSObject = this;
|
||||
this.mObservers = new Array();
|
||||
|
@ -518,10 +490,10 @@ calStorageCalendar.prototype = {
|
|||
}
|
||||
|
||||
var item_iid = null;
|
||||
if (item instanceof kCalIEvent)
|
||||
item_iid = kCalIEvent;
|
||||
else if (item instanceof kCalITodo)
|
||||
item_iid = kCalITodo;
|
||||
if (item instanceof Ci.calIEvent)
|
||||
item_iid = Ci.calIEvent;
|
||||
else if (item instanceof Ci.calITodo)
|
||||
item_iid = Ci.calITodo;
|
||||
else {
|
||||
aListener.onOperationComplete (this,
|
||||
Components.results.NS_ERROR_FAILURE,
|
||||
|
@ -707,7 +679,7 @@ calStorageCalendar.prototype = {
|
|||
|
||||
// process the events
|
||||
for each (var evitem in resultItems) {
|
||||
count += handleResultItem(evitem.item, evitem.flags, kCalIEvent);
|
||||
count += handleResultItem(evitem.item, evitem.flags, Ci.calIEvent);
|
||||
if (checkCount())
|
||||
return;
|
||||
}
|
||||
|
@ -765,7 +737,7 @@ calStorageCalendar.prototype = {
|
|||
var itemIsCompleted = false;
|
||||
if (item.todo_complete == 100 ||
|
||||
item.todo_completed != null ||
|
||||
item.ical_status == kCalITodo.CAL_TODO_STATUS_COMPLETED)
|
||||
item.ical_status == Ci.calITodo.CAL_TODO_STATUS_COMPLETED)
|
||||
itemIsCompleted = true;
|
||||
|
||||
if (!itemIsCompleted && !wantNotCompletedItems)
|
||||
|
@ -780,7 +752,7 @@ calStorageCalendar.prototype = {
|
|||
|
||||
// process the todos
|
||||
for each (var todoitem in resultItems) {
|
||||
count += handleResultItem(todoitem.item, todoitem.flags, kCalITodo);
|
||||
count += handleResultItem(todoitem.item, todoitem.flags, Ci.calITodo);
|
||||
if (checkCount())
|
||||
return;
|
||||
}
|
||||
|
@ -1296,7 +1268,7 @@ calStorageCalendar.prototype = {
|
|||
},
|
||||
|
||||
getEventFromRow: function (row, flags) {
|
||||
var item = new CalEvent();
|
||||
var item = createEvent();
|
||||
|
||||
this.getItemBaseFromRow (row, flags, item);
|
||||
|
||||
|
@ -1315,7 +1287,7 @@ calStorageCalendar.prototype = {
|
|||
},
|
||||
|
||||
getTodoFromRow: function (row, flags) {
|
||||
var item = new CalTodo();
|
||||
var item = createTodo();
|
||||
|
||||
this.getItemBaseFromRow (row, flags, item);
|
||||
|
||||
|
@ -1466,7 +1438,7 @@ calStorageCalendar.prototype = {
|
|||
|
||||
var exceptions = [];
|
||||
|
||||
if (item instanceof kCalIEvent) {
|
||||
if (item instanceof Ci.calIEvent) {
|
||||
this.mSelectEventExceptions.params.id = item.id;
|
||||
while (this.mSelectEventExceptions.step()) {
|
||||
var row = this.mSelectEventExceptions.row;
|
||||
|
@ -1475,7 +1447,7 @@ calStorageCalendar.prototype = {
|
|||
exceptions.push({item: exc, flags: flags.value});
|
||||
}
|
||||
this.mSelectEventExceptions.reset();
|
||||
} else if (item instanceof kCalITodo) {
|
||||
} else if (item instanceof Ci.calITodo) {
|
||||
this.mSelectTodoExceptions.params.id = item.id;
|
||||
while (this.mSelectTodoExceptions.step()) {
|
||||
var row = this.mSelectTodoExceptions.row;
|
||||
|
@ -1589,9 +1561,9 @@ calStorageCalendar.prototype = {
|
|||
deleteOldItem: function (item, olditem) {
|
||||
if (olditem) {
|
||||
var oldItemDeleteStmt;
|
||||
if (olditem instanceof kCalIEvent)
|
||||
if (olditem instanceof Ci.calIEvent)
|
||||
oldItemDeleteStmt = this.mDeleteEvent;
|
||||
else if (olditem instanceof kCalITodo)
|
||||
else if (olditem instanceof Ci.calITodo)
|
||||
oldItemDeleteStmt = this.mDeleteTodo;
|
||||
|
||||
oldItemDeleteStmt.params.id = olditem.id;
|
||||
|
@ -1623,9 +1595,9 @@ calStorageCalendar.prototype = {
|
|||
flags |= this.writeProperties(item, olditem);
|
||||
flags |= this.writeAttachments(item, olditem);
|
||||
|
||||
if (item instanceof kCalIEvent)
|
||||
if (item instanceof Ci.calIEvent)
|
||||
this.writeEvent(item, olditem, flags);
|
||||
else if (item instanceof kCalITodo)
|
||||
else if (item instanceof Ci.calITodo)
|
||||
this.writeTodo(item, olditem, flags);
|
||||
else
|
||||
throw Components.results.NS_ERROR_UNEXPECTED;
|
||||
|
@ -1875,6 +1847,37 @@ calStorageCalendar.prototype = {
|
|||
var calStorageCalendarModule = {
|
||||
mCID: Components.ID("{b3eaa1c4-5dfe-4c0a-b62a-b3a514218461}"),
|
||||
mContractID: "@mozilla.org/calendar/calendar;1?type=storage",
|
||||
|
||||
mUtilsLoaded: false,
|
||||
loadUtils: function storageLoadUtils() {
|
||||
if (this.mUtilsLoaded)
|
||||
return;
|
||||
|
||||
const jssslContractID = "@mozilla.org/moz/jssubscript-loader;1";
|
||||
const jssslIID = Components.interfaces.mozIJSSubScriptLoader;
|
||||
|
||||
const iosvcContractID = "@mozilla.org/network/io-service;1";
const iosvcIID = Components.interfaces.nsIIOService;
|
||||
|
||||
var loader = Components.classes[jssslContractID].getService(jssslIID);
|
||||
var iosvc = Components.classes[iosvcContractID].getService(iosvcIID);
|
||||
|
||||
// Utils lives in the same directory we're in
|
||||
var appdir = __LOCATION__.parent;
|
||||
var scriptName = "calUtils.js";
|
||||
|
||||
var f = appdir.clone();
|
||||
f.append(scriptName);
|
||||
|
||||
try {
|
||||
var fileurl = iosvc.newFileURI(f);
|
||||
loader.loadSubScript(fileurl.spec, this.__parent__.__parent__);
|
||||
} catch (e) {
|
||||
dump("Error while loading " + fileurl.spec + "\n");
|
||||
throw e;
|
||||
}
|
||||
|
||||
this.mUtilsLoaded = true;
|
||||
},
|
||||
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
||||
|
@ -1896,7 +1899,9 @@ var calStorageCalendarModule = {
|
|||
if (!kStorageServiceIID)
|
||||
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
if (!CalEvent) {
|
||||
this.loadUtils();
|
||||
|
||||
if (!CalAttendee) {
|
||||
initCalStorageCalendarComponent();
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче