2004-11-11 00:25:38 +03:00
|
|
|
/* -*- 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) 2004
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir.vukicevic@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 ***** */
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// calStorageCalendar.js
|
|
|
|
//
|
|
|
|
|
|
|
|
const kStorageServiceContractID = "@mozilla.org/storage/service;1";
|
|
|
|
const kStorageServiceIID = Components.interfaces.mozIStorageService;
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
const kCalICalendar = Components.interfaces.calICalendar;
|
|
|
|
|
2005-04-28 01:13:48 +04:00
|
|
|
const kCalCalendarManagerContractID = "@mozilla.org/calendar/manager;1";
|
|
|
|
const kCalICalendarManager = Components.interfaces.calICalendarManager;
|
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
const kCalEventContractID = "@mozilla.org/calendar/event;1";
|
2004-12-09 02:16:51 +03:00
|
|
|
const kCalIEvent = Components.interfaces.calIEvent;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalEvent;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
const kCalTodoContractID = "@mozilla.org/calendar/todo;1";
|
2004-12-09 02:16:51 +03:00
|
|
|
const kCalITodo = Components.interfaces.calITodo;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalTodo;
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
const kCalDateTimeContractID = "@mozilla.org/calendar/datetime;1";
|
2004-12-09 02:16:51 +03:00
|
|
|
const kCalIDateTime = Components.interfaces.calIDateTime;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalDateTime;
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
const kCalAttendeeContractID = "@mozilla.org/calendar/attendee;1";
|
|
|
|
const kCalIAttendee = Components.interfaces.calIAttendee;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalAttendee;
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
const kCalItemOccurrenceContractID = "@mozilla.org/calendar/item-occurrence;1";
|
|
|
|
const kCalIItemOccurrence = Components.interfaces.calIItemOccurrence;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalItemOccurrence;
|
2004-12-09 02:16:51 +03:00
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
const kCalRecurrenceInfoContractID = "@mozilla.org/calendar/recurrence-info;1";
|
|
|
|
const kCalIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalRecurrenceInfo;
|
2004-12-14 06:27:32 +03:00
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
const kCalRecurrenceRuleContractID = "@mozilla.org/calendar/recurrence-rule;1";
|
|
|
|
const kCalIRecurrenceRule = Components.interfaces.calIRecurrenceRule;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalRecurrenceRule;
|
2004-12-18 04:54:30 +03:00
|
|
|
|
|
|
|
const kCalRecurrenceDateSetContractID = "@mozilla.org/calendar/recurrence-date-set;1";
|
|
|
|
const kCalIRecurrenceDateSet = Components.interfaces.calIRecurrenceDateSet;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalRecurrenceDateSet;
|
2004-12-18 04:54:30 +03:00
|
|
|
|
2005-01-04 02:32:28 +03:00
|
|
|
const kCalRecurrenceDateContractID = "@mozilla.org/calendar/recurrence-date;1";
|
|
|
|
const kCalIRecurrenceDate = Components.interfaces.calIRecurrenceDate;
|
2005-04-09 00:57:34 +04:00
|
|
|
var CalRecurrenceDate;
|
2005-01-04 02:32:28 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
const kMozStorageStatementWrapperContractID = "@mozilla.org/storage/statement-wrapper;1";
|
|
|
|
const kMozStorageStatementWrapperIID = Components.interfaces.mozIStorageStatementWrapper;
|
2005-04-09 00:57:34 +04:00
|
|
|
var MozStorageStatementWrapper;
|
|
|
|
|
|
|
|
if (!kMozStorageStatementWrapperIID) {
|
2004-12-09 06:09:31 +03:00
|
|
|
dump("*** mozStorage not available, calendar/storage provider will not function\n");
|
2005-04-09 00:57:34 +04:00
|
|
|
}
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
const CAL_ITEM_TYPE_EVENT = 0;
|
|
|
|
const CAL_ITEM_TYPE_TODO = 1;
|
|
|
|
|
|
|
|
// bitmasks
|
|
|
|
const CAL_ITEM_FLAG_PRIVATE = 1;
|
|
|
|
const CAL_ITEM_FLAG_HAS_ATTENDEES = 2;
|
|
|
|
const CAL_ITEM_FLAG_HAS_PROPERTIES = 4;
|
|
|
|
const CAL_ITEM_FLAG_EVENT_ALLDAY = 8;
|
2004-12-14 03:25:58 +03:00
|
|
|
const CAL_ITEM_FLAG_HAS_RECURRENCE = 16;
|
2004-12-09 02:16:51 +03:00
|
|
|
|
2005-04-09 00:57:34 +04:00
|
|
|
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);
|
|
|
|
CalItemOccurrence = new Components.Constructor(kCalItemOccurrenceContractID, kCalIItemOccurrence);
|
|
|
|
CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
|
|
|
|
CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
|
|
|
|
CalRecurrenceDateSet = new Components.Constructor(kCalRecurrenceDateSetContractID, kCalIRecurrenceDateSet);
|
|
|
|
CalRecurrenceDate = new Components.Constructor(kCalRecurrenceDateContractID, kCalIRecurrenceDate);
|
|
|
|
MozStorageStatementWrapper = new Components.Constructor(kMozStorageStatementWrapperContractID, kMozStorageStatementWrapperIID);
|
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
//
|
|
|
|
// Storage helpers
|
|
|
|
//
|
|
|
|
|
|
|
|
function createStatement (dbconn, sql) {
|
|
|
|
var stmt = dbconn.createStatement(sql);
|
|
|
|
var wrapper = MozStorageStatementWrapper();
|
|
|
|
wrapper.initialize(stmt);
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
2005-01-04 02:32:28 +03:00
|
|
|
function textToDate(d) {
|
|
|
|
var dval = parseInt(d.substr(2));
|
|
|
|
var date;
|
|
|
|
if (d[0] == 'U') {
|
|
|
|
// isutc
|
|
|
|
date = newDateTime(dval);
|
|
|
|
} else if (d[0] == 'L') {
|
|
|
|
// is local time
|
|
|
|
date = newDateTime(dval, true);
|
|
|
|
}
|
|
|
|
if (d[1] == 'D')
|
|
|
|
date.isDate = true;
|
|
|
|
return date;
|
|
|
|
}
|
|
|
|
|
|
|
|
function dateToText(d) {
|
|
|
|
var datestr;
|
|
|
|
if (d.isUtc) {
|
|
|
|
datestr = "U";
|
|
|
|
} else {
|
|
|
|
datestr = "L";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d.isDate) {
|
|
|
|
datestr += "D";
|
|
|
|
} else {
|
|
|
|
datestr += "T";
|
|
|
|
}
|
|
|
|
|
|
|
|
datestr += d.nativeTime;
|
|
|
|
return datestr;
|
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
//
|
|
|
|
// other helpers
|
|
|
|
//
|
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
function newDateTime(aPRTime, isLocalTime) {
|
2004-12-09 02:16:51 +03:00
|
|
|
var t = CalDateTime();
|
2004-12-18 04:54:30 +03:00
|
|
|
if (!isLocalTime)
|
|
|
|
t.isUtc = true;
|
|
|
|
else
|
|
|
|
t.isUtc = false;
|
2004-11-19 04:01:40 +03:00
|
|
|
t.nativeTime = aPRTime;
|
2004-11-08 02:48:13 +03:00
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
function makeOccurrence(item, start, end)
|
|
|
|
{
|
|
|
|
var occ = CalItemOccurrence();
|
|
|
|
// XXX poor form
|
|
|
|
occ.wrappedJSObject.item = item;
|
2004-12-14 06:27:32 +03:00
|
|
|
occ.wrappedJSObject.occurrenceStartDate = start;
|
|
|
|
occ.wrappedJSObject.occurrenceEndDate = end;
|
2004-12-09 02:16:51 +03:00
|
|
|
return occ;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// calStorageCalendar
|
|
|
|
//
|
|
|
|
|
2005-04-28 01:13:48 +04:00
|
|
|
var activeCalendarManager = null;
|
|
|
|
function getCalendarManager()
|
|
|
|
{
|
|
|
|
if (!activeCalendarManager) {
|
|
|
|
activeCalendarManager =
|
|
|
|
Components.classes[kCalCalendarManagerContractID].getService(kCalICalendarManager);
|
|
|
|
}
|
|
|
|
return activeCalendarManager;
|
|
|
|
}
|
|
|
|
|
2005-01-29 03:55:52 +03:00
|
|
|
function calStorageCalendar() {
|
2004-11-11 00:25:38 +03:00
|
|
|
this.wrappedJSObject = this;
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
calStorageCalendar.prototype = {
|
|
|
|
//
|
|
|
|
// private members
|
|
|
|
//
|
|
|
|
mObservers: Array(),
|
|
|
|
mDB: null,
|
2004-12-09 02:16:51 +03:00
|
|
|
mDBTwo: null,
|
2004-11-08 02:48:13 +03:00
|
|
|
mItemCache: Array(),
|
2004-12-09 02:16:51 +03:00
|
|
|
mCalId: 0,
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
//
|
|
|
|
// nsISupports interface
|
|
|
|
//
|
|
|
|
QueryInterface: function (aIID) {
|
|
|
|
if (!aIID.equals(Components.interfaces.nsISupports) &&
|
|
|
|
!aIID.equals(Components.interfaces.calICalendar))
|
|
|
|
{
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
//
|
2004-12-09 02:16:51 +03:00
|
|
|
// calICalendar interface
|
2004-11-08 02:48:13 +03:00
|
|
|
//
|
|
|
|
|
2005-01-29 04:51:04 +03:00
|
|
|
// attribute AUTF8String name;
|
2005-04-28 01:13:48 +04:00
|
|
|
get name() {
|
|
|
|
return getCalendarManager().getCalendarPref(this, "NAME");
|
|
|
|
},
|
|
|
|
set name(name) {
|
|
|
|
getCalendarManager().setCalendarPref(this, "NAME", name);
|
|
|
|
},
|
2005-01-29 04:51:04 +03:00
|
|
|
// readonly attribute AUTF8String type;
|
|
|
|
get type() { return "storage"; },
|
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
mURI: null,
|
|
|
|
// attribute nsIURI uri;
|
|
|
|
get uri() { return this.mURI; },
|
|
|
|
set uri(aURI) {
|
|
|
|
// we can only load once
|
|
|
|
if (this.mURI)
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
|
2005-01-29 03:55:52 +03:00
|
|
|
var id = 0;
|
|
|
|
|
|
|
|
// check if there's a ?id=
|
|
|
|
var path = aURI.path;
|
|
|
|
var pos = path.indexOf("?id=");
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2005-01-29 03:55:52 +03:00
|
|
|
if (pos != -1) {
|
|
|
|
id = parseInt(path.substr(pos+4));
|
|
|
|
path = path.substr(0, pos);
|
|
|
|
}
|
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
var dbService;
|
2005-01-29 03:55:52 +03:00
|
|
|
if (aURI.scheme == "file") {
|
|
|
|
var fileURL = aURI.QueryInterface(Components.interfaces.nsIFileURL);
|
|
|
|
if (!fileURL)
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
// open the database
|
2005-04-14 02:09:54 +04:00
|
|
|
dbService = Components.classes[kStorageServiceContractID].getService(kStorageServiceIID);
|
2005-01-29 03:55:52 +03:00
|
|
|
this.mDB = dbService.openDatabase (fileURL.file);
|
|
|
|
this.mDBTwo = dbService.openDatabase (fileURL.file);
|
|
|
|
} else if (aURI.scheme == "moz-profile-calendar") {
|
2005-04-14 02:09:54 +04:00
|
|
|
dbService = Components.classes[kStorageServiceContractID].getService(kStorageServiceIID);
|
2005-01-29 03:55:52 +03:00
|
|
|
this.mDB = dbService.getProfileStorage("profile");
|
|
|
|
this.mDBTwo = dbService.getProfileStorage("profile");
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
this.initDB();
|
2004-12-10 01:34:59 +03:00
|
|
|
|
2005-01-29 03:55:52 +03:00
|
|
|
this.mCalId = id;
|
2004-12-10 01:34:59 +03:00
|
|
|
this.mURI = aURI;
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// attribute boolean readOnly;
|
|
|
|
get readOnly() { return false; },
|
|
|
|
set readOnly() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
// attribute boolean suppressAlarms;
|
|
|
|
get suppressAlarms() { return false; },
|
|
|
|
set suppressAlarms(aSuppressAlarms) { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
|
|
|
|
|
2005-04-15 22:51:47 +04:00
|
|
|
// void addObserver( in calIObserver observer );
|
2004-11-08 02:48:13 +03:00
|
|
|
addObserver: function (aObserver, aItemFilter) {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers) {
|
|
|
|
if (obs == aObserver)
|
2004-11-08 02:48:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-15 22:51:47 +04:00
|
|
|
this.mObservers.push(aObserver);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void removeObserver( in calIObserver observer );
|
|
|
|
removeObserver: function (aObserver) {
|
|
|
|
var newObservers = Array();
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers) {
|
|
|
|
if (obs != aObserver)
|
|
|
|
newObservers.push(obs);
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
|
|
|
this.mObservers = newObservers;
|
|
|
|
},
|
|
|
|
|
|
|
|
// void addItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
addItem: function (aItem, aListener) {
|
|
|
|
if (aItem.id == null) {
|
|
|
|
// is this an error? Or should we generate an IID?
|
2004-11-19 04:01:40 +03:00
|
|
|
aItem.id = "uuid:" + (new Date()).getTime();
|
2004-11-08 02:48:13 +03:00
|
|
|
} else {
|
2004-12-09 02:16:51 +03:00
|
|
|
var olditem = this.getItemById(aItem.id);
|
|
|
|
if (olditem) {
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.ADD,
|
|
|
|
aItem.id,
|
|
|
|
"ID already exists for addItem");
|
|
|
|
return;
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
var newItem = aItem.clone();
|
2004-12-09 03:51:27 +03:00
|
|
|
newItem.parent = this;
|
|
|
|
newItem.generation = 1;
|
|
|
|
newItem.makeImmutable();
|
|
|
|
|
|
|
|
this.flushItem (newItem, null);
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
// notify the listener
|
|
|
|
if (aListener)
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-08 02:48:13 +03:00
|
|
|
aListener.ADD,
|
2004-12-09 03:51:27 +03:00
|
|
|
newItem.id,
|
|
|
|
newItem);
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
// notify observers
|
2004-12-09 03:51:27 +03:00
|
|
|
this.observeAddItem(newItem);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void modifyItem( in calIItemBase aItem, in calIOperationListener aListener );
|
|
|
|
modifyItem: function (aItem, aListener) {
|
2004-12-09 02:16:51 +03:00
|
|
|
if (aItem.id == null) {
|
2004-11-08 02:48:13 +03:00
|
|
|
// this is definitely an error
|
|
|
|
if (aListener)
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-08 02:48:13 +03:00
|
|
|
aListener.MODIFY,
|
2004-11-23 04:37:43 +03:00
|
|
|
aItem.id,
|
2004-11-08 02:48:13 +03:00
|
|
|
"ID for modifyItem item is null");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// get the old item
|
|
|
|
var olditem = this.getItemById(aItem.id);
|
|
|
|
if (!olditem) {
|
|
|
|
// no old item found? should be using addItem, then.
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.MODIFY,
|
|
|
|
aItem.id,
|
|
|
|
"ID does not already exit for modifyItem");
|
2004-11-08 02:48:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
if (olditem.generation != aItem.generation) {
|
|
|
|
if (aListener)
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.MODIFY,
|
|
|
|
aItem.id,
|
|
|
|
"generation too old for for modifyItem");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-09 03:51:27 +03:00
|
|
|
var newItem = aItem.clone();
|
|
|
|
newItem.generation += 1;
|
|
|
|
newItem.makeImmutable();
|
|
|
|
|
|
|
|
this.flushItem (newItem, olditem);
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
if (aListener)
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-08 02:48:13 +03:00
|
|
|
aListener.MODIFY,
|
2004-12-09 03:51:27 +03:00
|
|
|
newItem.id,
|
|
|
|
newItem);
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
// notify observers
|
2004-12-10 23:55:51 +03:00
|
|
|
this.observeModifyItem(newItem, olditem);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void deleteItem( in string id, in calIOperationListener aListener );
|
2004-12-09 02:16:51 +03:00
|
|
|
deleteItem: function (aItem, aListener) {
|
|
|
|
if (aItem.id == null) {
|
2004-11-08 02:48:13 +03:00
|
|
|
if (aListener)
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-08 02:48:13 +03:00
|
|
|
aListener.DELETE,
|
2005-03-14 23:09:25 +03:00
|
|
|
null,
|
2004-11-08 02:48:13 +03:00
|
|
|
"ID is null for deleteItem");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-11 01:16:30 +03:00
|
|
|
this.deleteItemById(aItem.id);
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
if (aListener)
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-08 02:48:13 +03:00
|
|
|
aListener.DELETE,
|
2004-12-09 02:16:51 +03:00
|
|
|
aItem.id,
|
2004-11-08 02:48:13 +03:00
|
|
|
null);
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// notify observers
|
|
|
|
this.observeDeleteItem(aItem);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// void getItem( in string id, in calIOperationListener aListener );
|
|
|
|
getItem: function (aId, aListener) {
|
|
|
|
if (!aListener)
|
|
|
|
return;
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
var item = this.getItemById (aId);
|
2004-11-23 04:37:43 +03:00
|
|
|
if (!item) {
|
2004-12-09 02:16:51 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
|
|
|
aListener.GET,
|
2005-03-14 23:09:25 +03:00
|
|
|
aId,
|
2004-12-09 02:16:51 +03:00
|
|
|
"ID doesn't exist for getItem");
|
2004-11-23 04:37:43 +03:00
|
|
|
}
|
2004-11-19 04:01:40 +03:00
|
|
|
|
2004-11-23 04:37:43 +03:00
|
|
|
var item_iid = null;
|
2004-12-10 04:45:20 +03:00
|
|
|
if (item instanceof kCalIEvent)
|
2004-12-09 02:16:51 +03:00
|
|
|
item_iid = kCalIEvent;
|
2004-12-10 04:45:20 +03:00
|
|
|
else if (item instanceof kCalITodo)
|
2004-12-09 02:16:51 +03:00
|
|
|
item_iid = kCalITodo;
|
|
|
|
else {
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_ERROR_FAILURE,
|
2004-11-23 04:37:43 +03:00
|
|
|
aListener.GET,
|
|
|
|
aId,
|
|
|
|
"Can't deduce item type based on QI");
|
|
|
|
return;
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
2004-11-23 04:37:43 +03:00
|
|
|
|
2005-03-14 23:09:25 +03:00
|
|
|
aListener.onGetResult (this,
|
|
|
|
Components.results.NS_OK,
|
2004-12-09 02:16:51 +03:00
|
|
|
item_iid, null,
|
|
|
|
1, [item]);
|
2004-11-23 04:37:43 +03:00
|
|
|
|
2004-11-24 02:40:06 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
2004-11-23 04:37:43 +03:00
|
|
|
aListener.GET,
|
|
|
|
aId,
|
|
|
|
null);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
2004-11-23 04:37:43 +03:00
|
|
|
// void getItems( in unsigned long aItemFilter, in unsigned long aCount,
|
|
|
|
// in calIDateTime aRangeStart, in calIDateTime aRangeEnd,
|
2004-11-08 02:48:13 +03:00
|
|
|
// in calIOperationListener aListener );
|
2004-11-23 04:37:43 +03:00
|
|
|
getItems: function (aItemFilter, aCount,
|
2004-11-08 02:48:13 +03:00
|
|
|
aRangeStart, aRangeEnd, aListener)
|
|
|
|
{
|
|
|
|
if (!aListener)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var itemsFound = Array();
|
2004-12-18 00:29:23 +03:00
|
|
|
var startTime = -0x7fffffffffffffff;
|
2004-11-08 02:48:13 +03:00
|
|
|
// endTime needs to be the max value a PRTime can be
|
|
|
|
var endTime = 0x7fffffffffffffff;
|
|
|
|
if (aRangeStart)
|
2004-12-09 02:16:51 +03:00
|
|
|
startTime = aRangeStart.nativeTime;
|
2004-11-08 02:48:13 +03:00
|
|
|
if (aRangeEnd)
|
2004-12-09 02:16:51 +03:00
|
|
|
endTime = aRangeEnd.nativeTime;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-11-23 04:37:43 +03:00
|
|
|
// only events for now
|
2004-12-09 02:16:51 +03:00
|
|
|
var wantEvents = ((aItemFilter & kCalICalendar.ITEM_FILTER_TYPE_EVENT) != 0);
|
|
|
|
var wantTodos = ((aItemFilter & kCalICalendar.ITEM_FILTER_TYPE_TODO) != 0);
|
|
|
|
var asOccurrences = ((aItemFilter & kCalICalendar.ITEM_FILTER_CLASS_OCCURRENCES) != 0);
|
|
|
|
|
|
|
|
if (!wantEvents && !wantTodos) {
|
|
|
|
// nothing to do
|
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
|
|
|
aListener.GET,
|
|
|
|
null,
|
|
|
|
null);
|
2004-11-08 02:48:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
var stmt;
|
|
|
|
if (asOccurrences)
|
|
|
|
stmt = this.mSelectItemsByRangeWithRecurrence;
|
|
|
|
else
|
|
|
|
stmt = this.mSelectItemsByRange;
|
|
|
|
stmt.reset();
|
2004-12-09 02:16:51 +03:00
|
|
|
var sp = stmt.params;
|
|
|
|
sp.cal_id = this.mCalId;
|
|
|
|
sp.event_start = startTime;
|
|
|
|
sp.event_end = endTime;
|
|
|
|
sp.todo_start = startTime;
|
|
|
|
sp.todo_end = endTime;
|
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
/*
|
2004-12-14 03:25:58 +03:00
|
|
|
if (asOccurrences) {
|
|
|
|
sp.event_start2 = startTime;
|
|
|
|
sp.event_end2 = endTime;
|
|
|
|
}
|
2004-12-14 06:27:32 +03:00
|
|
|
*/
|
2004-12-09 02:16:51 +03:00
|
|
|
var count = 0;
|
|
|
|
while (stmt.step()) {
|
|
|
|
var iid;
|
|
|
|
if (stmt.row.item_type == CAL_ITEM_TYPE_EVENT) {
|
|
|
|
if (!wantEvents)
|
|
|
|
continue;
|
|
|
|
iid = kCalIEvent;
|
|
|
|
} else if (stmt.row.item_type == CAL_ITEM_TYPE_TODO) {
|
|
|
|
if (!wantTodos)
|
|
|
|
continue;
|
|
|
|
iid = kCalITodo;
|
|
|
|
} else {
|
|
|
|
// errrr..
|
|
|
|
dump ("***** Unknown item type in db: " + stmt.row.item_type + "\n");
|
|
|
|
continue;
|
|
|
|
}
|
2004-12-14 06:27:32 +03:00
|
|
|
var flags = {};
|
|
|
|
var item = this.getItemFromRow(stmt.row, flags);
|
2004-12-09 02:16:51 +03:00
|
|
|
// uses mDBTwo, so can be interleaved
|
2004-12-14 06:27:32 +03:00
|
|
|
this.getAdditionalDataForItem(item, flags.value);
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
item.makeImmutable();
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
var items = null;
|
|
|
|
|
2005-03-14 23:09:25 +03:00
|
|
|
if (asOccurrences && item.recurrenceInfo) {
|
2004-12-14 06:27:32 +03:00
|
|
|
iid = kCalIItemOccurrence;
|
2004-12-18 04:54:30 +03:00
|
|
|
items = item.recurrenceInfo.getOccurrences (aRangeStart, aRangeEnd, 0, {});
|
2004-12-14 03:25:58 +03:00
|
|
|
} else {
|
|
|
|
if (asOccurrences) {
|
|
|
|
if (iid == kCalIEvent) {
|
2004-12-14 06:27:32 +03:00
|
|
|
item = makeOccurrence(item, item.startDate, item.endDate);
|
2004-12-14 03:25:58 +03:00
|
|
|
} else if (iid == kCalITodo) {
|
2005-01-04 02:32:28 +03:00
|
|
|
item = makeOccurrence(item, item.entryDate, item.entryDate);
|
2004-12-14 03:25:58 +03:00
|
|
|
}
|
|
|
|
iid = kCalIItemOccurrence;
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
2004-12-14 03:25:58 +03:00
|
|
|
items = [ item ];
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
aListener.onGetResult (this,
|
|
|
|
Components.results.NS_OK,
|
|
|
|
iid, null,
|
2004-12-14 03:25:58 +03:00
|
|
|
items.length, items);
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
count++;
|
|
|
|
if (aCount && count == aCount)
|
|
|
|
break;
|
|
|
|
}
|
2004-11-23 04:37:43 +03:00
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
stmt.reset();
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
aListener.onOperationComplete (this,
|
|
|
|
Components.results.NS_OK,
|
|
|
|
aListener.GET,
|
|
|
|
null,
|
|
|
|
null);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// Helper functions
|
|
|
|
//
|
|
|
|
observeLoad: function () {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers)
|
|
|
|
obs.onLoad ();
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
observeBatchChange: function (aNewBatchMode) {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers) {
|
2004-11-08 02:48:13 +03:00
|
|
|
if (aNewBatchMode)
|
2005-04-15 22:51:47 +04:00
|
|
|
obs.onStartBatch ();
|
2004-11-08 02:48:13 +03:00
|
|
|
else
|
2005-04-15 22:51:47 +04:00
|
|
|
obs.onEndBatch ();
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
observeAddItem: function (aItem) {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers)
|
|
|
|
obs.onAddItem (aItem);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
observeModifyItem: function (aOldItem, aNewItem) {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers)
|
|
|
|
obs.onModifyItem (aOldItem, aNewItem);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
observeDeleteItem: function (aDeletedItem) {
|
2005-04-15 22:51:47 +04:00
|
|
|
for each (obs in this.mObservers)
|
|
|
|
obs.onDeleteItem (aDeletedItem);
|
2004-12-09 02:16:51 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
|
|
|
// database handling
|
|
|
|
//
|
|
|
|
|
|
|
|
// initialize the database schema.
|
|
|
|
// needs to do some version checking
|
|
|
|
initDBSchema: function () {
|
2004-12-18 04:54:30 +03:00
|
|
|
for (table in sqlTables) {
|
|
|
|
dump (table + "\n");
|
|
|
|
try {
|
|
|
|
this.mDB.executeSimpleSQL("DROP TABLE " + table);
|
|
|
|
} catch (e) { }
|
|
|
|
this.mDB.createTable(table, sqlTables[table]);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.mDB.executeSimpleSQL("INSERT INTO cal_calendar_schema_version VALUES(" + this.DB_SCHEMA_VERSION + ")");
|
|
|
|
},
|
|
|
|
|
|
|
|
// check db version
|
|
|
|
DB_SCHEMA_VERSION: 2,
|
|
|
|
versionCheck: function () {
|
|
|
|
var version = -1;
|
|
|
|
|
|
|
|
try {
|
|
|
|
var selectSchemaVersion = createStatement (this.mDB, "SELECT version FROM cal_calendar_schema_version LIMIT 1");
|
|
|
|
if (selectSchemaVersion.step()) {
|
|
|
|
version = selectSchemaVersion.row.version;
|
|
|
|
}
|
2005-04-26 23:59:34 +04:00
|
|
|
selectSchemaVersion.reset();
|
2004-12-18 04:54:30 +03:00
|
|
|
} catch (e) {
|
|
|
|
// either the cal_calendar_schema_version table is not
|
|
|
|
// found, or something else happened
|
|
|
|
version = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// database initialization
|
|
|
|
// assumes mDB is valid
|
2004-12-18 04:54:30 +03:00
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
initDB: function () {
|
2004-12-18 04:54:30 +03:00
|
|
|
var version = this.versionCheck();
|
|
|
|
dump ("*** Calendar schema version is: " + version + "\n");
|
|
|
|
if (version == -1) {
|
2004-12-09 02:16:51 +03:00
|
|
|
this.initDBSchema();
|
2004-12-18 04:54:30 +03:00
|
|
|
} else if (version != this.DB_SCHEMA_VERSION) {
|
|
|
|
this.upgradeDB();
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mSelectItem = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"SELECT * FROM cal_items " +
|
|
|
|
"WHERE id = :id AND cal_id = :cal_id "+
|
|
|
|
"LIMIT 1"
|
|
|
|
);
|
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
// XXX rewrite this to use UNION ALL instead of OR!
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mSelectItemsByRange = createStatement(
|
|
|
|
this.mDB,
|
|
|
|
"SELECT * FROM cal_items " +
|
2005-04-22 01:03:12 +04:00
|
|
|
"WHERE (item_type = 0 AND (event_end >= :event_start AND event_start < :event_end)) " +
|
|
|
|
" OR (item_type = 1 AND (todo_entry >= :todo_start AND todo_entry < :todo_end)) " +
|
2004-12-14 03:25:58 +03:00
|
|
|
" AND cal_id = :cal_id"
|
|
|
|
);
|
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
// XXX rewrite this to use UNION ALL instead of OR!
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mSelectItemsByRangeWithRecurrence = createStatement(
|
|
|
|
this.mDB,
|
|
|
|
"SELECT * FROM cal_items " +
|
2004-12-18 04:54:30 +03:00
|
|
|
"WHERE ((flags & 16 == 16) " +
|
2005-04-22 01:03:12 +04:00
|
|
|
" OR (item_type = 0 AND (flags & 16 == 0) AND (event_end >= :event_start AND event_start < :event_end)) " +
|
|
|
|
" OR (item_type = 1 AND (flags & 16 == 0) AND todo_entry >= :todo_start AND todo_entry < :todo_end)) " +
|
2004-12-09 02:16:51 +03:00
|
|
|
" AND cal_id = :cal_id"
|
|
|
|
);
|
|
|
|
|
|
|
|
// For the extra-item data, note that we use mDBTwo, so that
|
|
|
|
// these can be executed while a selectItems is running!
|
|
|
|
this.mSelectAttendeesForItem = createStatement(
|
|
|
|
this.mDBTwo,
|
|
|
|
"SELECT * FROM cal_attendees " +
|
|
|
|
"WHERE item_id = :item_id"
|
|
|
|
);
|
|
|
|
|
|
|
|
this.mSelectPropertiesForItem = createStatement(
|
|
|
|
this.mDBTwo,
|
|
|
|
"SELECT * FROM cal_properties " +
|
|
|
|
"WHERE item_id = :item_id"
|
|
|
|
);
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mSelectRecurrenceForItem = createStatement(
|
|
|
|
this.mDBTwo,
|
|
|
|
"SELECT * FROM cal_recurrence " +
|
2004-12-18 04:54:30 +03:00
|
|
|
"WHERE item_id = :item_id " +
|
|
|
|
"ORDER BY recur_index"
|
2004-12-14 03:25:58 +03:00
|
|
|
);
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// insert statements
|
|
|
|
this.mInsertItem = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"INSERT INTO cal_items " +
|
|
|
|
" (cal_id, item_type, id, time_created, last_modified, " +
|
2004-12-14 03:25:58 +03:00
|
|
|
" title, priority, privacy, ical_status, flags, " +
|
2004-12-09 02:16:51 +03:00
|
|
|
" event_start, event_end, event_stamp, todo_entry, todo_due, " +
|
2004-12-18 04:54:30 +03:00
|
|
|
" todo_completed, todo_complete) " +
|
2004-12-09 02:16:51 +03:00
|
|
|
"VALUES (:cal_id, :item_type, :id, :time_created, :last_modified, " +
|
2004-12-14 03:25:58 +03:00
|
|
|
" :title, :priority, :privacy, :ical_status, :flags, " +
|
2004-12-09 02:16:51 +03:00
|
|
|
" :event_start, :event_end, :event_stamp, :todo_entry, :todo_due, " +
|
2004-12-18 04:54:30 +03:00
|
|
|
" :todo_completed, :todo_complete)"
|
2004-12-09 02:16:51 +03:00
|
|
|
);
|
|
|
|
this.mInsertAlarm = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"INSERT INTO cal_alarms (alarm_data) " +
|
|
|
|
"VALUES (:alarm_data)"
|
|
|
|
);
|
|
|
|
this.mInsertProperty = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"INSERT INTO cal_properties (item_id, key, value) " +
|
|
|
|
"VALUES (:item_id, :key, :value)"
|
|
|
|
);
|
|
|
|
this.mInsertAttendee = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"INSERT INTO cal_attendees " +
|
|
|
|
" (item_id, attendee_id, common_name, rsvp, role, status, type) " +
|
|
|
|
"VALUES (:item_id, :attendee_id, :common_name, :rsvp, :role, :status, :type)"
|
|
|
|
);
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mInsertRecurrence = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"INSERT INTO cal_recurrence " +
|
2004-12-18 04:54:30 +03:00
|
|
|
" (item_id, recur_index, recur_type, is_negative, dates, count, end_date, interval, second, minute, hour, day, monthday, yearday, weekno, month, setpos) " +
|
|
|
|
"VALUES (:item_id, :recur_index, :recur_type, :is_negative, :dates, :count, :end_date, :interval, :second, :minute, :hour, :day, :monthday, :yearday, :weekno, :month, :setpos)"
|
2004-12-14 03:25:58 +03:00
|
|
|
);
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
// delete statements
|
|
|
|
this.mDeleteItem = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"DELETE FROM cal_items WHERE id = :id AND cal_id = :cal_id"
|
|
|
|
);
|
|
|
|
this.mDeleteAttendees = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"DELETE FROM cal_attendees WHERE item_id = :item_id"
|
|
|
|
);
|
|
|
|
this.mDeleteProperties = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"DELETE FROM cal_properties WHERE item_id = :item_id"
|
|
|
|
);
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence = createStatement (
|
|
|
|
this.mDB,
|
|
|
|
"DELETE FROM cal_recurrence WHERE item_id = :item_id"
|
|
|
|
);
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
// database helper functions
|
2004-11-11 00:25:38 +03:00
|
|
|
|
|
|
|
// read in the common ItemBase attributes from aDBRow, and stick
|
|
|
|
// them on aItemBase
|
2004-12-14 06:27:32 +03:00
|
|
|
getItemFromRow: function (row, flags) {
|
2004-12-09 02:16:51 +03:00
|
|
|
var item;
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
if (row.cal_id != this.mCalId) {
|
|
|
|
// the row selected doesn't belong to this calendar, hmm.
|
|
|
|
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// create a new item based on the type from the db
|
|
|
|
if (row.item_type == CAL_ITEM_TYPE_EVENT)
|
|
|
|
item = CalEvent();
|
|
|
|
else if (row.item_type == CAL_ITEM_TYPE_TODO)
|
|
|
|
item = CalTodo();
|
|
|
|
else
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
// fill in common bits
|
|
|
|
item.creationDate = newDateTime(row.time_created);
|
2004-12-10 14:27:48 +03:00
|
|
|
item.lastModifiedTime = newDateTime(row.last_modified);
|
2004-12-09 02:16:51 +03:00
|
|
|
item.parent = this;
|
|
|
|
item.id = row.id;
|
|
|
|
item.title = row.title;
|
|
|
|
item.priority = row.priority;
|
2004-12-14 03:25:58 +03:00
|
|
|
item.privacy = row.privacy;
|
2004-12-09 02:16:51 +03:00
|
|
|
item.status = row.ical_status;
|
|
|
|
|
|
|
|
if (row.item_type == CAL_ITEM_TYPE_EVENT) {
|
|
|
|
item.startDate = newDateTime(row.event_start);
|
|
|
|
item.endDate = newDateTime(row.event_end);
|
2004-12-21 02:32:03 +03:00
|
|
|
item.stampTime = newDateTime(row.event_stamp);
|
2004-12-09 02:16:51 +03:00
|
|
|
item.isAllDay = ((row.flags & CAL_ITEM_FLAG_EVENT_ALLDAY) != 0);
|
|
|
|
} else if (row.item_type == CAL_ITEM_TYPE_TODO) {
|
2005-01-04 02:32:28 +03:00
|
|
|
item.entryDate = newDateTime(row.todo_entry);
|
2004-12-09 02:16:51 +03:00
|
|
|
item.dueDate = newDateTime(row.todo_due);
|
|
|
|
item.completedDate = newDateTime(row.todo_complete);
|
|
|
|
item.percentComplete = row.todo_complete;
|
|
|
|
}
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// we need a way to do this without using wrappedJSObject
|
|
|
|
item.wrappedJSObject.storage_calendar_id = row.id;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
if (flags)
|
|
|
|
flags.value = row.flags;
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
return item;
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// after we get the base item, we need to check if we need to pull in
|
|
|
|
// any extra data from other tables. We do that here.
|
|
|
|
|
|
|
|
// note that we use mDBTwo for this, so this can be run while a
|
|
|
|
// select is executing; don't use any statements that aren't
|
|
|
|
// against mDBTwo in here!
|
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
getAdditionalDataForItem: function (item, flags) {
|
|
|
|
if (flags & CAL_ITEM_FLAG_HAS_ATTENDEES) {
|
2004-12-21 02:32:03 +03:00
|
|
|
this.mSelectAttendeesForItem.params.item_id = item.id;
|
2004-12-09 02:16:51 +03:00
|
|
|
while (this.mSelectAttendeesForItem.step()) {
|
2004-12-21 02:32:03 +03:00
|
|
|
var attendee = this.newAttendeeFromRow(this.mSelectAttendeesForItem.row);
|
2004-12-09 02:16:51 +03:00
|
|
|
item.addAttendee(attendee);
|
|
|
|
}
|
2004-12-10 23:55:51 +03:00
|
|
|
this.mSelectAttendeesForItem.reset();
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
var row;
|
2004-12-14 06:27:32 +03:00
|
|
|
if (flags & CAL_ITEM_FLAG_HAS_PROPERTIES) {
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mSelectPropertiesForItem.params.item_id = item.id;
|
2004-12-21 02:32:03 +03:00
|
|
|
while (this.mSelectPropertiesForItem.step()) {
|
2005-04-14 02:09:54 +04:00
|
|
|
row = this.mSelectPropertiesForItem.row;
|
2004-12-21 02:32:03 +03:00
|
|
|
item.setProperty (row.key, row.value);
|
|
|
|
}
|
|
|
|
this.mSelectPropertiesForItem.reset();
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
2004-12-14 03:25:58 +03:00
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
var i;
|
2004-12-14 06:27:32 +03:00
|
|
|
if (flags & CAL_ITEM_FLAG_HAS_RECURRENCE) {
|
2004-12-18 04:54:30 +03:00
|
|
|
var rec = null;
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mSelectRecurrenceForItem.params.item_id = item.id;
|
2004-12-18 04:54:30 +03:00
|
|
|
while (this.mSelectRecurrenceForItem.step()) {
|
2005-04-14 02:09:54 +04:00
|
|
|
row = this.mSelectRecurrenceForItem.row;
|
2004-12-14 03:25:58 +03:00
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
var ritem = null;
|
|
|
|
|
2005-01-04 02:32:28 +03:00
|
|
|
if (row.recur_type == null ||
|
|
|
|
row.recur_type == "x-dateset")
|
|
|
|
{
|
2004-12-18 04:54:30 +03:00
|
|
|
ritem = new CalRecurrenceDateSet();
|
|
|
|
|
|
|
|
var dates = row.dates.split(",");
|
2005-04-14 02:09:54 +04:00
|
|
|
for (i = 0; i < dates.length; i++) {
|
2005-01-04 02:32:28 +03:00
|
|
|
var date = textToDate(dates[i]);
|
2004-12-18 04:54:30 +03:00
|
|
|
ritem.addDate(date);
|
|
|
|
}
|
2005-01-04 02:32:28 +03:00
|
|
|
} else if (row.recur_type == "x-date") {
|
|
|
|
ritem = new CalRecurrenceDate();
|
|
|
|
var d = row.dates;
|
|
|
|
ritem.date = textToDate(d);
|
2004-12-18 04:54:30 +03:00
|
|
|
} else {
|
|
|
|
ritem = new CalRecurrenceRule();
|
|
|
|
|
|
|
|
ritem.type = row.recur_type;
|
|
|
|
if (row.count) {
|
|
|
|
ritem.count = row.count;
|
|
|
|
} else {
|
|
|
|
ritem.endDate = newDateTime(row.end_date);
|
|
|
|
}
|
|
|
|
ritem.interval = row.interval;
|
|
|
|
|
|
|
|
var rtypes = ["second",
|
|
|
|
"minute",
|
|
|
|
"hour",
|
|
|
|
"day",
|
|
|
|
"monthday",
|
|
|
|
"yearday",
|
|
|
|
"weekno",
|
|
|
|
"month",
|
|
|
|
"setpos"];
|
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
for (i = 0; i < rtypes.length; i++) {
|
2004-12-18 04:54:30 +03:00
|
|
|
var comp = "BY" + rtypes[i].toUpperCase();
|
|
|
|
if (row[rtypes[i]]) {
|
2005-01-06 02:54:06 +03:00
|
|
|
var rstr = row[rtypes[i]].split(",");
|
2004-12-18 04:54:30 +03:00
|
|
|
var rarray = [];
|
|
|
|
for (var j = 0; j < rstr.length; j++) {
|
|
|
|
rarray[j] = parseInt(rstr[j]);
|
|
|
|
}
|
|
|
|
|
2005-01-06 02:54:06 +03:00
|
|
|
ritem.setComponent (comp, rarray.length, rarray);
|
2004-12-18 04:54:30 +03:00
|
|
|
}
|
2004-12-14 03:25:58 +03:00
|
|
|
}
|
|
|
|
}
|
2004-12-14 06:27:32 +03:00
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
if (row.is_negative)
|
|
|
|
ritem.isNegative = true;
|
|
|
|
if (rec == null) {
|
|
|
|
rec = new CalRecurrenceInfo();
|
|
|
|
rec.initialize(item);
|
|
|
|
}
|
|
|
|
rec.appendRecurrenceItem(ritem);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rec == null) {
|
|
|
|
dump ("XXXX Expected to find recurrence, but got no items!\n");
|
2004-12-14 03:25:58 +03:00
|
|
|
}
|
2004-12-18 04:54:30 +03:00
|
|
|
item.recurrenceInfo = rec;
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mSelectRecurrenceForItem.reset();
|
|
|
|
}
|
2004-12-09 02:16:51 +03:00
|
|
|
},
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
newAttendeeFromRow: function (row) {
|
|
|
|
var a = CalAttendee();
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
a.id = row.attendee_id;
|
|
|
|
a.commonName = row.common_name;
|
|
|
|
a.rsvp = (row.rsvp != 0);
|
|
|
|
a.role = row.role;
|
|
|
|
a.participationStatus = row.status;
|
|
|
|
a.userType = row.type;
|
2004-11-11 00:25:38 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
return a;
|
2004-11-11 00:25:38 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
//
|
2004-12-09 02:16:51 +03:00
|
|
|
// get item from db or from cache with given iid
|
2004-11-11 00:25:38 +03:00
|
|
|
//
|
2004-12-09 02:16:51 +03:00
|
|
|
getItemById: function (aID) {
|
2004-11-08 02:48:13 +03:00
|
|
|
// cached?
|
2004-12-09 02:16:51 +03:00
|
|
|
if (this.mItemCache[aID] != null)
|
|
|
|
return this.mItemCache[aID];
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-11-11 00:25:38 +03:00
|
|
|
var retval = null;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
// not cached; need to read from the db
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mSelectItem.params.id = aID;
|
|
|
|
this.mSelectItem.params.cal_id = this.mCalId;
|
|
|
|
if (!this.mSelectItem.step()) {
|
|
|
|
// not found
|
|
|
|
return null;
|
2004-11-11 00:25:38 +03:00
|
|
|
}
|
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
var flags = {};
|
|
|
|
var item = this.getItemFromRow(this.mSelectItem.row, flags);
|
2004-12-10 23:55:51 +03:00
|
|
|
this.mSelectItem.reset();
|
|
|
|
|
2004-12-14 06:27:32 +03:00
|
|
|
this.getAdditionalDataForItem(item, flags.value);
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
item.makeImmutable();
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// cache it
|
|
|
|
this.mItemCache[aID] = item;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
return item;
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// write this item's changed data to the db. olditem may be null
|
|
|
|
flushItem: function (item, olditem) {
|
|
|
|
// for now, we just delete and insert
|
|
|
|
// set up params before transaction
|
2004-12-11 00:32:08 +03:00
|
|
|
|
|
|
|
if (olditem) {
|
|
|
|
this.mDeleteItem.params.id = olditem.id;
|
|
|
|
this.mDeleteItem.params.cal_id = this.mCalId;
|
|
|
|
this.mDeleteAttendees.params.item_id = olditem.id;
|
|
|
|
this.mDeleteProperties.params.item_id = olditem.id;
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.params.item_id = olditem.id;
|
2004-12-11 00:32:08 +03:00
|
|
|
}
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
var ip = this.mInsertItem.params;
|
|
|
|
ip.cal_id = this.mCalId;
|
|
|
|
ip.id = item.id;
|
|
|
|
ip.time_created = item.creationDate.jsDate;
|
2004-12-10 14:27:48 +03:00
|
|
|
ip.last_modified = item.lastModifiedTime.jsDate;
|
2004-12-09 02:16:51 +03:00
|
|
|
ip.title = item.title;
|
|
|
|
ip.priority = item.priority;
|
2004-12-14 03:25:58 +03:00
|
|
|
ip.privacy = item.privacy;
|
2004-12-09 02:16:51 +03:00
|
|
|
ip.ical_status = item.status;
|
|
|
|
|
|
|
|
var flags = 0;
|
2004-12-10 04:45:20 +03:00
|
|
|
if (item instanceof kCalIEvent) {
|
2004-12-09 02:16:51 +03:00
|
|
|
ip.item_type = CAL_ITEM_TYPE_EVENT;
|
|
|
|
|
2004-12-10 04:45:20 +03:00
|
|
|
if (item.isAllDay)
|
2004-12-09 02:16:51 +03:00
|
|
|
flags |= CAL_ITEM_FLAG_EVENT_ALLDAY;
|
|
|
|
|
2004-12-10 04:45:20 +03:00
|
|
|
ip.event_start = item.startDate.jsDate;
|
|
|
|
ip.event_end = item.endDate.jsDate;
|
2004-12-21 02:32:03 +03:00
|
|
|
ip.event_stamp = item.stampTime.jsDate;
|
2004-12-10 04:45:20 +03:00
|
|
|
} else if (item instanceof kCalITodo) {
|
2004-12-09 02:16:51 +03:00
|
|
|
ip.item_type = CAL_ITEM_TYPE_TODO;
|
|
|
|
|
2005-01-04 02:32:28 +03:00
|
|
|
ip.todo_entry = item.entryDate.jsDate;
|
2004-12-10 04:45:20 +03:00
|
|
|
ip.todo_due = item.dueDate.jsDate;
|
|
|
|
ip.todo_completed = item.completedDate.jsDate;
|
|
|
|
ip.todo_complete = item.percentComplete;
|
2004-12-09 02:16:51 +03:00
|
|
|
} else {
|
|
|
|
// XXX fixme error
|
|
|
|
throw Components.results.NS_ERROR_FAILURE;
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
// start the transaction
|
|
|
|
this.mDB.beginTransaction();
|
|
|
|
try {
|
2004-12-11 00:32:08 +03:00
|
|
|
if (olditem) {
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.step();
|
2004-12-11 00:32:08 +03:00
|
|
|
this.mDeleteAttendees.step();
|
|
|
|
this.mDeleteProperties.step();
|
|
|
|
this.mDeleteItem.step();
|
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.reset();
|
2004-12-11 00:32:08 +03:00
|
|
|
this.mDeleteAttendees.reset();
|
|
|
|
this.mDeleteProperties.reset();
|
|
|
|
this.mDeleteItem.reset();
|
|
|
|
}
|
2004-12-09 02:16:51 +03:00
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
var ap;
|
|
|
|
var i;
|
|
|
|
var j;
|
2004-12-09 02:16:51 +03:00
|
|
|
var attendees = item.getAttendees({});
|
|
|
|
if (attendees && attendees.length > 0) {
|
|
|
|
flags |= CAL_ITEM_FLAG_HAS_ATTENDEES;
|
2005-04-14 02:09:54 +04:00
|
|
|
for (i = 0; i < attendees.length; i++) {
|
2004-12-09 02:16:51 +03:00
|
|
|
var a = attendees[i];
|
2005-04-14 02:09:54 +04:00
|
|
|
ap = this.mInsertAttendee.params;
|
2004-12-09 02:16:51 +03:00
|
|
|
ap.item_id = item.id;
|
|
|
|
ap.attendee_id = a.id;
|
|
|
|
ap.common_name = a.commonName;
|
|
|
|
ap.rsvp = a.rsvp;
|
|
|
|
ap.role = a.role;
|
2004-12-14 03:25:58 +03:00
|
|
|
ap.status = a.participationStatus;
|
|
|
|
ap.type = a.userType;
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
this.mInsertAttendee.step();
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mInsertAttendee.reset();
|
2004-12-09 02:16:51 +03:00
|
|
|
}
|
|
|
|
}
|
2004-12-21 02:32:03 +03:00
|
|
|
var propEnumerator = item.propertyEnumerator;
|
|
|
|
while (propEnumerator.hasMoreElements()) {
|
|
|
|
flags |= CAL_ITEM_FLAG_HAS_PROPERTIES;
|
|
|
|
|
|
|
|
var prop = propEnumerator.getNext().QueryInterface(Components.interfaces.nsIProperty);
|
|
|
|
|
|
|
|
var pp = this.mInsertProperty.params;
|
|
|
|
pp.item_id = item.id;
|
|
|
|
pp.key = prop.name;
|
|
|
|
pp.value = prop.value;
|
|
|
|
|
|
|
|
this.mInsertProperty.step();
|
|
|
|
this.mInsertProperty.reset();
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-14 03:25:58 +03:00
|
|
|
var rec = item.recurrenceInfo;
|
2004-12-18 04:54:30 +03:00
|
|
|
if (rec) {
|
2004-12-14 03:25:58 +03:00
|
|
|
flags |= CAL_ITEM_FLAG_HAS_RECURRENCE;
|
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
var ritems = rec.getRecurrenceItems ({});
|
|
|
|
for (i in ritems) {
|
|
|
|
var ritem = ritems[i];
|
|
|
|
|
2005-04-14 02:09:54 +04:00
|
|
|
ap = this.mInsertRecurrence.params;
|
2004-12-18 04:54:30 +03:00
|
|
|
ap.item_id = item.id;
|
|
|
|
ap.recur_index = i;
|
|
|
|
ap.is_negative = ritem.isNegative;
|
2005-01-04 02:32:28 +03:00
|
|
|
if (ritem instanceof kCalIRecurrenceDate) {
|
|
|
|
ritem = ritem.QueryInterface(kCalIRecurrenceDate);
|
|
|
|
ap.recur_type = "x-date";
|
|
|
|
ap.dates = dateToText(ritem.date);
|
|
|
|
|
|
|
|
} else if (ritem instanceof kCalIRecurrenceDateSet) {
|
2004-12-18 04:54:30 +03:00
|
|
|
ritem = ritem.QueryInterface(kCalIRecurrenceDateSet);
|
2005-01-04 02:32:28 +03:00
|
|
|
ap.recur_type = "x-dateset";
|
2004-12-18 04:54:30 +03:00
|
|
|
|
|
|
|
var rdates = ritem.getDates({});
|
|
|
|
var datestr = "";
|
|
|
|
for (j in rdates) {
|
|
|
|
if (j != 0)
|
|
|
|
datestr += ",";
|
|
|
|
|
2005-01-04 02:32:28 +03:00
|
|
|
datestr += dateToText(rdates[j]);
|
2004-12-18 04:54:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ap.dates = datestr;
|
|
|
|
|
|
|
|
} else if (ritem instanceof kCalIRecurrenceRule) {
|
|
|
|
ritem = ritem.QueryInterface(kCalIRecurrenceRule);
|
|
|
|
ap.recur_type = ritem.type;
|
|
|
|
|
|
|
|
if (ritem.isByCount)
|
|
|
|
ap.count = ritem.count;
|
|
|
|
else
|
|
|
|
ap.end_date = ritem.endDate.nativeTime;
|
|
|
|
|
|
|
|
ap.interval = ritem.interval;
|
|
|
|
|
|
|
|
var rtypes = ["second",
|
|
|
|
"minute",
|
|
|
|
"hour",
|
|
|
|
"day",
|
|
|
|
"monthday",
|
|
|
|
"yearday",
|
|
|
|
"weekno",
|
|
|
|
"month",
|
|
|
|
"setpos"];
|
2005-04-14 02:09:54 +04:00
|
|
|
for (j = 0; j < rtypes.length; j++) {
|
2004-12-18 04:54:30 +03:00
|
|
|
var comp = "BY" + rtypes[i].toUpperCase();
|
|
|
|
var comps = ritem.getComponent(comp, {});
|
|
|
|
if (comps && comps.length > 0) {
|
|
|
|
var compstr = comps.join(",");
|
2005-04-14 02:09:54 +04:00
|
|
|
ap[rtypes[j]] = compstr;
|
2004-12-18 04:54:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dump ("XXX Don't know how to serialize recurrence item " + ritem + "!\n");
|
|
|
|
}
|
2004-12-14 03:25:58 +03:00
|
|
|
|
2004-12-18 04:54:30 +03:00
|
|
|
this.mInsertRecurrence.step();
|
|
|
|
this.mInsertRecurrence.reset();
|
|
|
|
}
|
2004-12-14 03:25:58 +03:00
|
|
|
}
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
ip.flags = flags;
|
|
|
|
this.mInsertItem.step();
|
2004-12-10 01:34:59 +03:00
|
|
|
this.mDB.commitTransaction();
|
2004-12-09 02:16:51 +03:00
|
|
|
} catch (e) {
|
2004-12-10 01:34:59 +03:00
|
|
|
dump ("EXCEPTION; error is: " + this.mDB.lastErrorString + "\n");
|
2004-12-09 02:16:51 +03:00
|
|
|
dump (e);
|
|
|
|
this.mDB.rollbackTransaction();
|
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mItemCache[item.id] = item;
|
2004-11-08 02:48:13 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
// delete the event with the given uid
|
2004-12-11 01:16:30 +03:00
|
|
|
deleteItemById: function (aID) {
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mDeleteItem.params.id = aID;
|
|
|
|
this.mDeleteItem.params.cal_id = this.mCalId;
|
|
|
|
this.mDeleteAttendees.params.item_id = aID;
|
2004-12-11 01:25:27 +03:00
|
|
|
this.mDeleteProperties.params.item_id = aID;
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.params.item_id = aID;
|
2004-11-08 02:48:13 +03:00
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mDB.beginTransaction();
|
|
|
|
try {
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.step();
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mDeleteAttendees.step();
|
|
|
|
this.mDeleteProperties.step();
|
|
|
|
this.mDeleteItem.step();
|
2004-12-10 01:34:59 +03:00
|
|
|
this.mDB.commitTransaction();
|
2004-12-09 02:16:51 +03:00
|
|
|
} catch (e) {
|
2004-12-10 01:34:59 +03:00
|
|
|
dump ("EXCEPTION; error is: " + this.mDB.lastErrorString + "\n");
|
|
|
|
dump (e);
|
2004-12-09 02:16:51 +03:00
|
|
|
this.mDB.rollbackTransaction();
|
|
|
|
}
|
|
|
|
|
2004-12-11 00:32:08 +03:00
|
|
|
this.mDeleteAttendees.reset();
|
|
|
|
this.mDeleteProperties.reset();
|
2004-12-14 03:25:58 +03:00
|
|
|
this.mDeleteRecurrence.reset();
|
2004-12-11 00:32:08 +03:00
|
|
|
this.mDeleteItem.reset();
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
delete this.mItemCache[aID];
|
2005-04-14 02:09:54 +04:00
|
|
|
}
|
2004-11-08 02:48:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****
|
|
|
|
**** module registration
|
|
|
|
****/
|
|
|
|
|
|
|
|
var calStorageCalendarModule = {
|
|
|
|
mCID: Components.ID("{b3eaa1c4-5dfe-4c0a-b62a-b3a514218461}"),
|
2004-11-24 02:40:06 +03:00
|
|
|
mContractID: "@mozilla.org/calendar/calendar;1?type=storage",
|
2004-11-08 02:48:13 +03:00
|
|
|
|
|
|
|
registerSelf: function (compMgr, fileSpec, location, type) {
|
|
|
|
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
|
|
|
|
compMgr.registerFactoryLocation(this.mCID,
|
|
|
|
"Calendar mozStorage/SQL back-end",
|
|
|
|
this.mContractID,
|
|
|
|
fileSpec,
|
|
|
|
location,
|
|
|
|
type);
|
|
|
|
},
|
|
|
|
|
|
|
|
getClassObject: function (compMgr, cid, iid) {
|
|
|
|
if (!cid.equals(this.mCID))
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
if (!iid.equals(Components.interfaces.nsIFactory))
|
|
|
|
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2004-12-09 06:09:31 +03:00
|
|
|
if (!kStorageServiceIID)
|
|
|
|
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2005-04-09 00:57:34 +04:00
|
|
|
if (!CalEvent) {
|
|
|
|
initCalStorageCalendarComponent();
|
|
|
|
}
|
|
|
|
|
2004-11-08 02:48:13 +03:00
|
|
|
return this.mFactory;
|
|
|
|
},
|
|
|
|
|
|
|
|
mFactory: {
|
|
|
|
createInstance: function (outer, iid) {
|
|
|
|
if (outer != null)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return (new calStorageCalendar()).QueryInterface(iid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
canUnload: function(compMgr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2004-11-11 00:25:38 +03:00
|
|
|
|
|
|
|
function NSGetModule(compMgr, fileSpec) {
|
|
|
|
return calStorageCalendarModule;
|
|
|
|
}
|
2004-12-09 02:16:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// sqlTables generated from schema.sql via makejsschema.pl
|
|
|
|
//
|
|
|
|
|
|
|
|
var sqlTables = {
|
2004-12-18 04:54:30 +03:00
|
|
|
cal_calendar_schema_version:
|
|
|
|
" version INTEGER" +
|
|
|
|
"",
|
|
|
|
|
2004-12-09 02:16:51 +03:00
|
|
|
cal_items:
|
2004-12-18 04:54:30 +03:00
|
|
|
/* REFERENCES cal_calendars.id, */
|
2004-12-09 02:16:51 +03:00
|
|
|
" cal_id INTEGER, " +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* 0: event, 1: todo */
|
2004-12-09 02:16:51 +03:00
|
|
|
" item_type INTEGER," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* ItemBase bits */
|
2004-12-09 02:16:51 +03:00
|
|
|
" id STRING," +
|
|
|
|
" time_created INTEGER," +
|
|
|
|
" last_modified INTEGER," +
|
|
|
|
" title STRING," +
|
|
|
|
" priority INTEGER," +
|
2004-12-14 03:25:58 +03:00
|
|
|
" privacy STRING," +
|
|
|
|
" ical_status STRING," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* CAL_ITEM_FLAG_PRIVATE = 1 */
|
|
|
|
/* CAL_ITEM_FLAG_HAS_ATTENDEES = 2 */
|
|
|
|
/* CAL_ITEM_FLAG_HAS_PROPERTIES = 4 */
|
|
|
|
/* CAL_ITEM_FLAG_EVENT_ALLDAY = 8 */
|
|
|
|
/* CAL_ITEM_FLAG_HAS_RECURRENCE = 16 */
|
2004-12-09 02:16:51 +03:00
|
|
|
" flags INTEGER," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* Event bits */
|
2004-12-09 02:16:51 +03:00
|
|
|
" event_start INTEGER," +
|
|
|
|
" event_end INTEGER," +
|
|
|
|
" event_stamp INTEGER," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* Todo bits */
|
2004-12-09 02:16:51 +03:00
|
|
|
" todo_entry INTEGER," +
|
|
|
|
" todo_due INTEGER," +
|
|
|
|
" todo_completed INTEGER," +
|
|
|
|
" todo_complete INTEGER," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* internal bits */
|
|
|
|
/* REFERENCES cal_alarms.id ON DELETE CASCADE */
|
|
|
|
" alarm_id INTEGER " +
|
2004-12-09 02:16:51 +03:00
|
|
|
"",
|
|
|
|
|
|
|
|
cal_attendees:
|
|
|
|
" item_id STRING," +
|
|
|
|
" attendee_id STRING," +
|
|
|
|
" common_name STRING," +
|
|
|
|
" rsvp INTEGER," +
|
2004-12-14 03:25:58 +03:00
|
|
|
" role STRING," +
|
|
|
|
" status STRING," +
|
|
|
|
" type STRING" +
|
2004-12-09 02:16:51 +03:00
|
|
|
"",
|
|
|
|
|
|
|
|
cal_alarms:
|
|
|
|
" id INTEGER PRIMARY KEY," +
|
|
|
|
" alarm_data BLOB" +
|
|
|
|
"",
|
|
|
|
|
|
|
|
cal_recurrence:
|
2004-12-14 03:25:58 +03:00
|
|
|
" item_id STRING," +
|
2004-12-18 04:54:30 +03:00
|
|
|
/* the index in the recurrence array of this thing */
|
|
|
|
" recur_index INTEGER, " +
|
|
|
|
/* values from calIRecurrenceInfo; if null, date-based. */
|
|
|
|
" recur_type STRING, " +
|
|
|
|
" is_negative BOOLEAN," +
|
|
|
|
/* */
|
|
|
|
/* these are for date-based recurrence */
|
|
|
|
/* */
|
|
|
|
/* comma-separated list of dates */
|
|
|
|
" dates STRING," +
|
|
|
|
/* */
|
|
|
|
/* these are for rule-based recurrence */
|
|
|
|
/* */
|
2004-12-14 03:25:58 +03:00
|
|
|
" count INTEGER," +
|
2004-12-18 04:54:30 +03:00
|
|
|
" end_date INTEGER," +
|
|
|
|
" interval INTEGER," +
|
|
|
|
/* components, comma-separated list or null */
|
2004-12-14 03:25:58 +03:00
|
|
|
" second STRING," +
|
|
|
|
" minute STRING," +
|
|
|
|
" hour STRING," +
|
|
|
|
" day STRING," +
|
|
|
|
" monthday STRING," +
|
|
|
|
" yearday STRING," +
|
|
|
|
" weekno STRING," +
|
|
|
|
" month STRING," +
|
2004-12-18 04:54:30 +03:00
|
|
|
" setpos STRING" +
|
2004-12-09 02:16:51 +03:00
|
|
|
"",
|
|
|
|
|
|
|
|
cal_properties:
|
|
|
|
" item_id STRING," +
|
|
|
|
" key STRING," +
|
|
|
|
" value BLOB" +
|
|
|
|
"",
|
|
|
|
|
|
|
|
};
|