adding calendar manager. bug 289189 r=vlad

This commit is contained in:
pavlov%pavlov.net 2005-01-29 01:51:04 +00:00
parent dd66f98c9b
commit e4c33752df
10 changed files with 301 additions and 1 deletions

View File

@ -49,6 +49,7 @@ XPIDL_MODULE = calbase
XPIDLSRCS = calIAttachment.idl \
calIAttendee.idl \
calICalendar.idl \
calICalendarManager.idl \
calIDateTime.idl \
calIEvent.idl \
calIICSService.idl \

View File

@ -53,9 +53,20 @@ interface calIOperationListener;
interface calIRange;
interface calIDateTime;
[scriptable, uuid(4c352774-2c4f-11d9-9c63-00045ace3b8d)]
[scriptable, uuid(2ab0652d-9a66-43db-b481-fe77a53eb4ea)]
interface calICalendar : nsISupports
{
/**
* Name of the calendar
*/
attribute AUTF8String name;
/**
* Type of the calendar
* 'memory', 'storage', 'caldav', etc
*/
readonly attribute AUTF8String type;
/**
* Setting this URI causes the calendar to be (re)loaded.
*/

View File

@ -0,0 +1,65 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <stuart.parmenter@oracle.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
interface calICalendar;
interface nsIURI;
[scriptable, uuid(43a71d40-7807-4e2f-b741-2926ee73f89a)]
interface calICalendarManager : nsISupports
{
/*
* create a new calendar
* aName is the display name of the calendar
* aType is the type ("caldav", "storage", etc)
*/
calICalendar createCalendar(in AUTF8String aName, in AUTF8String aType, in nsIURI aURL);
/* register a newly created calendar with the calendar service */
void registerCalendar(in calICalendar aCalendar);
/* unregister a calendar */
void unregisterCalendar(in calICalendar aCalendar);
/* delete a calendar for good */
void deleteCalendar(in calICalendar aCalendar);
/* return a list of all calendars currently registered */
void getCalendars(out PRUint32 count,
[array, size_is(count), retval] out calICalendar aCalendars);
};

View File

@ -72,6 +72,7 @@ CPPSRCS = calDateTime.cpp \
EXTRA_COMPONENTS = \
calAttachment.js \
calAttendee.js \
calCalendarManager.js \
calEvent.js \
calItemBase.js \
calItemModule.js \

View File

@ -0,0 +1,195 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Oracle Corporation code.
*
* The Initial Developer of the Original Code is Oracle Corporation
* Portions created by the Initial Developer are Copyright (C) 2005
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <stuart.parmenter@oracle.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
const kStorageServiceContractID = "@mozilla.org/storage/service;1";
const kStorageServiceIID = Components.interfaces.mozIStorageService;
const kMozStorageStatementWrapperContractID = "@mozilla.org/storage/statement-wrapper;1";
const kMozStorageStatementWrapperIID = Components.interfaces.mozIStorageStatementWrapper;
const MozStorageStatementWrapper = new Components.Constructor(kMozStorageStatementWrapperContractID, kMozStorageStatementWrapperIID);
function createStatement (dbconn, sql) {
var stmt = dbconn.createStatement(sql);
var wrapper = MozStorageStatementWrapper();
wrapper.initialize(stmt);
return wrapper;
}
function calCalendarManager() {
this.wrappedJSObject = this;
this.initDB();
this.mCache = {};
}
function makeURI(uriString)
{
var ioservice = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
return ioservice.newURI(uriString, null, null);
}
calCalendarManager.prototype = {
QueryInterface: function (aIID) {
if (!aIID.equals(Components.interfaces.nsISupports) &&
!aIID.equals(Components.interfaces.calICalendarManager))
{
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
findDB: function() {
var pathString = "c:\\builds\\mozilla\\objdir-sunbird\\dist\\bin\\calendar.db";
var dbFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
dbFile.initWithPath(pathString);
var ioservice = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
uri = ioservice.newFileURI(dbFile);
return uri.QueryInterface(Components.interfaces.nsIFileURL);
},
initDB: function() {
var calendarTable = "id INTEGER PRIMARY KEY, name STRING, type STRING, uri STRING";
var dbService = Components.classes[kStorageServiceContractID].getService(kStorageServiceIID);
this.mDB = dbService.getProfileStorage("profile");
// this.mDB = dbService.openDatabase(this.findDB().file);
try {
this.mDB.createTable("cal_calendars", calendarTable);
} catch (e) {
dump("error creating table cal_calendars -- probably already exists\n");
}
this.mSelectCalendars = createStatement (
this.mDB,
"SELECT oid,* FROM cal_calendars");
this.mFindCalendar = createStatement (
this.mDB,
"SELECT id FROM cal_calendars WHERE name = :name AND type = :type AND uri = :uri");
this.mRegisterCalendar = createStatement (
this.mDB,
"INSERT INTO cal_calendars (name, type, uri) " +
"VALUES (:name, :type, :uri)"
);
this.mUnregisterCalendar = createStatement (
this.mDB,
"DELETE FROM cal_calendars WHERE id = :id"
);
},
findCalendarID: function(calendar) {
var stmt = this.mFindCalendar;
stmt.reset();
var pp = stmt.params;
pp.name = calendar.name;
pp.type = calendar.type;
pp.uri = calendar.uri.spec;
var id = -1;
if (stmt.step()) {
id = stmt.row.id;
}
stmt.reset();
return id;
},
/**
* calICalendarManager interface
*/
createCalendar: function(name, type, uri) {
var calendar = Components.classes["@mozilla.org/calendar/calendar;1?type=" + type].createInstance(Components.interfaces.calICalendar);
calendar.uri = uri;
return calendar;
},
registerCalendar: function(calendar) {
// bail if this calendar (or one that looks identical to it) is already registered
if (this.findCalendarID(calendar) > 0)
throw Components.results.NS_ERROR_FAILURE;
var pp = this.mRegisterCalendar.params;
pp.name = calendar.name;
pp.type = calendar.type;
pp.uri = calendar.uri.spec;
this.mRegisterCalendar.step();
this.mRegisterCalendar.reset();
//dump("adding [" + this.mDB.lastInsertRowID + "]\n");
//this.mCache[this.mDB.lastInsertRowID] = calendar;
this.mCache[this.findCalendarID(calendar)] = calendar;
},
unregisterCalendar: function(calendar) {
var pp = this.mUnregisterCalendar.params;
pp.id = this.findCalendarID(calendar);
this.mUnregisterCalendar.step();
this.mUnregisterCalendar.reset();
},
deleteCalendar: function(calendar) {
/* check to see if calendar is unregistered first... */
/* delete the calendar for good */
},
getCalendars: function(count) {
var calendars = [];
var stmt = this.mSelectCalendars;
stmt.reset();
while (stmt.step()) {
var id = stmt.row.id;
if (!this.mCache[id]) {
this.mCache[id] = this.createCalendar(stmt.row.name, stmt.row.type, makeURI(stmt.row.uri));
}
calendars.push(this.mCache[id]);
}
stmt.reset();
count.value = calendars.length;
return calendars;
},
};

View File

@ -46,6 +46,11 @@ const componentData =
script: "calItemBase.js",
constructor: null},
{cid: Components.ID("{f42585e7-e736-4600-985d-9624c1c51992}"),
contractid: "@mozilla.org/calendar/manager;1",
script: "calCalendarManager.js",
constructor: "calCalendarManager"},
{cid: Components.ID("{974339d5-ab86-4491-aaaf-2b2ca177c12b}"),
contractid: "@mozilla.org/calendar/event;1",
script: "calEvent.js",

View File

@ -101,6 +101,12 @@ calDavCalendar.prototype = {
// nsICalendar interface
//
// attribute AUTF8String name;
name: "",
// readonly attribute AUTF8String type;
get type() { return "caldav"; },
// attribute nsIURI uri;
mUri: null,
get uri() { return this.mUri },

View File

@ -80,6 +80,10 @@ calICSCalendar.prototype = {
this.addObserver(this.mObserver, calICalendar.ITEM_FILTER_TYPE_ALL);
},
name: "",
get type() { return "ics"; },
mUri: null,
get uri() { return this.mUri },
set uri(aUri) {

View File

@ -82,6 +82,12 @@ calMemoryCalendar.prototype = {
// nsICalendar interface
//
// attribute AUTF8String name;
name: "",
// readonly attribute AUTF8String type;
get type() { return "memory"; },
// attribute nsIURI uri;
mUri: null,
get uri() { return this.mUri; },

View File

@ -202,6 +202,12 @@ calStorageCalendar.prototype = {
// calICalendar interface
//
// attribute AUTF8String name;
name: "",
// readonly attribute AUTF8String type;
get type() { return "storage"; },
mURI: null,
// attribute nsIURI uri;
get uri() { return this.mURI; },