b=289439, lightning and calendar update stuff

This commit is contained in:
vladimir%pobox.com 2005-04-08 20:57:34 +00:00
Родитель 2c46990d85
Коммит 9ca19b78d3
9 изменённых файлов: 306 добавлений и 42 удалений

Просмотреть файл

@ -281,6 +281,13 @@ interface calICompositeCalendar : calICalendar
* @param aServer URI of the server to be removed
*/
void removeCalendar( in nsIURI aServer );
/**
* If a calendar for the given URI exists in the CompositeCalendar,
* return it; otherwise return null.
*
* @param aServer URI of the server whose calendar to return
* @return calendar for aServer, or null if none
*/
calICalendar getCalendar( in nsIURI aServer );
/**

Просмотреть файл

@ -1,4 +1,4 @@
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: javascript; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
@ -40,6 +40,8 @@
interface calICalendar;
interface nsIURI;
interface calICalendarManagerObserver;
[scriptable, uuid(43a71d40-7807-4e2f-b741-2926ee73f89a)]
interface calICalendarManager : nsISupports
{
@ -67,4 +69,26 @@ interface calICalendarManager : nsISupports
AUTF8String getCalendarPref(in calICalendar aCalendar, in AUTF8String aName);
void setCalendarPref(in calICalendar aCalendar, in AUTF8String aName, in AUTF8String aValue);
void deleteCalendarPref(in calICalendar aCalendar, in AUTF8String aName);
void addObserver(in calICalendarManagerObserver aObserver);
void removeObserver(in calICalendarManagerObserver aObserver);
};
[scriptable, uuid(383f36f1-e669-4ca4-be7f-06b43910f44a)]
interface calICalendarManagerObserver : nsISupports
{
// called after the calendar is registered
void onCalendarRegistered(in calICalendar aCalendar);
// called before the unregister actually takes place
void onCalendarUnregistering(in calICalendar aCalendar);
// called before the delete actually takes place
void onCalendarDeleting(in calICalendar aCalendar);
// called after the pref is set
void onCalendarPrefSet(in calICalendar aCalendar, in AUTF8String aName, in AUTF8String aValue);
// called before the pref is deleted
void onCalendarPrefDeleting(in calICalendar aCalendar, in AUTF8String aName);
};

Просмотреть файл

@ -171,9 +171,15 @@ calCalendarManager.prototype = {
//dump("adding [" + this.mDB.lastInsertRowID + "]\n");
//this.mCache[this.mDB.lastInsertRowID] = calendar;
this.mCache[this.findCalendarID(calendar)] = calendar;
for each (obs in this.mObservers)
obs.onCalendarRegistered(calendar);
},
unregisterCalendar: function(calendar) {
for each (obs in this.mObservers)
obs.onCalendarUnregistering(calendar);
var pp = this.mUnregisterCalendar.params;
pp.id = this.findCalendarID(calendar);
this.mUnregisterCalendar.step();
@ -184,6 +190,8 @@ calCalendarManager.prototype = {
/* check to see if calendar is unregistered first... */
/* delete the calendar for good */
for each (obs in this.mObservers)
obs.onCalendarDeleting(calendar);
},
getCalendars: function(count) {
@ -239,14 +247,41 @@ calCalendarManager.prototype = {
this.mInsertPref.reset();
this.mDB.commitTransaction();
for each (obs in this.mObservers)
obs.onCalendarPrefSet(calendar, name, value);
},
deleteCalendarPref: function(calendar, name) {
for each (obs in this.mObservers)
obs.onCalendarPrefDeleting(calendar, name);
var calendarID = this.findCalendarID(calendar);
var pp = this.mDeletePref.params;
pp.calendar = calendarID;
this.mDeletePref.step();
this.mDeletePref.reset();
},
mObservers: Array(),
addObserver: function(aObserver) {
for each (obs in this.mObservers) {
if (obs == aObserver)
return;
}
this.mObservers.push(aObserver);
},
removeObserver: function(aObserver) {
var newObs = Array();
for each (obs in this.mObservers) {
if (obs != aObserver)
newObs.push(obs);
}
this.mObservers = newObs;
}
};

Просмотреть файл

@ -1,11 +1,97 @@
function ltnNewCalendar()
//
// calendar-management.js
//
var ltnCalendarManagerObserver = {
QueryInterface: function(aIID) {
if (!aIID.equals(Components.interfaces.calICalendarManagerObserver) ||
!aIID.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
onCalendarRegistered: function(aCalendar) {
document.getElementById("calendarTree").boxObject.invalidate();
},
onCalendarUnregistering: function(aCalendar) {
document.getElementById("calendarTree").boxObject.invalidate();
},
onCalendarDeleting: function(aCalendar) {
document.getElementById("calendarTree").boxObject.invalidate();
},
onCalendarPrefSet: function(aCalendar, aName, aValue) {
},
onCalendarPrefDeleting: function(aCalendar, aName) {
}
};
var ltnCompositeCalendarObserver = {
QueryInterface: function(aIID) {
// I almost wish that calICompositeObserver did not inherit from calIObserver,
// and that the composite calendar maintined its own observer list
if (!aIID.equals(Components.interfaces.calIObserver) ||
!aIID.equals(Components.interfaces.calICompositeObserver) ||
!aIID.equals(Components.interfaces.nsISupports)) {
throw Components.results.NS_ERROR_NO_INTERFACE;
}
return this;
},
// calICompositeObserver
onCalendarAdded: function (aCalendar) {
document.getElementById("calendarTree").boxObject.invalidate();
},
onCalendarRemoved: function (aCalendar) {
document.getElementById("calendarTree").boxObject.invalidate();
},
onDefaultCalendarChanged: function (aNewDefaultCalendar) {
// make the calendar bold in the tree
},
// calIObserver
onStartBatch: function() { },
onEndBatch: function() { },
onLoad: function() { },
onAddItem: function(aItem) { },
onModifyItem: function(aNewItem, aOldItem) { },
onDeleteItem: function(aDeletedItem) { },
onAlarm: function(aAlarmItem) { },
onError: function(aErrNo, aMessage) { }
};
var activeCompositeCalendar = null;
function getCompositeCalendar()
{
openCalendarWizard(ltnSetTreeView);
if (activeCompositeCalendar == null) {
activeCompositeCalendar =
ltnCreateInstance("@mozilla.org/calendar/calendar;1?type=composite",
"calICompositeCalendar");
activeCompositeCalendar.addObserver(ltnCompositeCalendarObserver, 0);
}
return activeCompositeCalendar;
}
var activeCalendarManager;
function getCalendarManager()
{
return Components.classes["@mozilla.org/calendar/manager;1"].getService(Components.interfaces.calICalendarManager);
if (!activeCalendarManager) {
activeCalendarManager = ltnGetService("@mozilla.org/calendar/manager;1",
"calICalendarManager");
activeCalendarManager.addObserver(ltnCalendarManagerObserver);
}
return activeCalendarManager;
}
function getCalendars()
@ -13,6 +99,11 @@ function getCalendars()
return getCalendarManager().getCalendars({});
}
function ltnNewCalendar()
{
openCalendarWizard(ltnSetTreeView);
}
var ltnCalendarTreeView = {
get rowCount()
{
@ -22,14 +113,79 @@ var ltnCalendarTreeView = {
return 0;
}
},
getCellText: function (row, col)
getCellProperties: function (row, col, properties)
{
try {
return getCalendars()[row].name;
} catch (e) {
return "<Unknown " + row + ">";
if (col.id == "col-calendar-Checkbox") {
var cal = getCalendars()[row];
if (getCompositeCalendar().getCalendar(cal.uri)) {
properties.AppendElement(ltnGetAtom("checked"));
}
}
},
cycleCell: function (row, col)
{
var cal = getCalendars()[row];
if (getCompositeCalendar().getCalendar(cal.uri)) {
// need to remove it
getCompositeCalendar().removeCalendar(cal.uri);
dump ("calendar removed\n");
} else {
// need to add it
getCompositeCalendar().addCalendar(cal);
dump ("calendar added\n");
}
document.getElementById("calendarTree").boxObject.invalidateRow(row);
},
getCellValue: function (row, col)
{
if (col.id == "col-calendar-Checkbox") {
var cal = getCalendars()[row];
if (getCompositeCalendar().getCalendar(cal.uri))
return "true";
return "false";
}
dump ("*** Bad getCellValue (row: " + row + " col id: " + col.id + ")\n");
return null;
},
setCellValue: function (row, col, value)
{
if (col.id == "col-calendar-Checkbox") {
var cal = getCellValue()[row];
if (value == "true") {
getCompositeCalendar().addCalendar(cal);
} else {
getCompositeCalendar().removeCalendar(cal.uri);
}
return;
}
dump ("*** Bad setCellText (row: " + row + " col id: " + col.id + " val: " + value + ")\n");
},
getCellText: function (row, col)
{
if (col.id == "col-calendar-Checkbox") {
return ""; // tooltip
}
if (col.id == "col-calendar-Calendar") {
try {
return getCalendars()[row].name;
} catch (e) {
return "<Unknown " + row + ">";
}
}
dump ("*** Bad getCellText (row: " + row + " col id: " + col.id + ")\n");
return null;
},
isEditable: function(row, col) { return false; },
setTree: function(treebox) { this.treebox = treebox; },
isContainer: function(row) { return false; },
isSeparator: function(row) { return false; },
@ -37,7 +193,6 @@ var ltnCalendarTreeView = {
getLevel: function(row) { return 0; },
getImageSrc: function(row, col) { return null; },
getRowProperties: function(row, props) { },
getCellProperties: function(row, col, props) { },
getColumnProperties: function(colid, col, props) { }
};

Просмотреть файл

@ -0,0 +1,21 @@
function ltnCreateInstance(cid, iface) {
if (!iface)
iface = "nsISupports";
return Components.classes[cid].createInstance(Components.interfaces[iface]);
}
function ltnGetService(cid, iface) {
if (!iface)
iface = "nsISupports";
return Components.classes[cid].getService(Components.interfaces[iface]);
}
var atomSvc;
function ltnGetAtom(str) {
if (!atomSvc) {
atomSvc = ltnGetService("@mozilla.org/atom-service;1", "nsIAtomService");
}
return atomSvc.getAtom(str);
}

Просмотреть файл

@ -2,10 +2,13 @@
<!-- DOCTYPE overlay SYSTEM "chrome://lightning/locale/lightning.dtd" -->
<?xml-stylesheet href="chrome://lightning/skin/lightning.css" type="text/css"?>
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript" src="chrome://calendar/content/calendarUtils.js"/>
<script type="application/x-javascript" src="chrome://calendar/content/calendarCreation.js"/>
<script type="application/x-javascript" src="chrome://lightning/content/lightning-utils.js"/>
<script type="application/x-javascript" src="chrome://lightning/content/calendar-management.js"/>
<script type="application/x-javascript" src="chrome://lightning/content/messenger-overlay-sidebar.js"/>
@ -25,7 +28,8 @@
<tree id="calendarTree" onfocus="selectedCalendarPane(event)" flex="1"
context="ltnCalendarTreeContext">
<treecols>
<treecol label="Calendar" id="col-calendar-Calendar" flex="1"/>
<treecol id="col-calendar-Checkbox" cycler="true" fixed="true" />
<treecol id="col-calendar-Calendar" label="Calendar" flex="1"/>
</treecols>
<treechildren>
</treechildren>

Просмотреть файл

@ -1,4 +1,5 @@
lightning.jar:
content/lightning/lightning-utils.js (content/lightning-utils.js)
content/lightning/messenger-overlay-sidebar.xul (content/messenger-overlay-sidebar.xul)
content/lightning/messenger-overlay-sidebar.js (content/messenger-overlay-sidebar.js)
content/lightning/calendar-management.js (content/calendar-management.js)

Просмотреть файл

@ -76,8 +76,8 @@ calCompositeCalendar.prototype = {
addCalendar: function (aCalendar) {
// check if the calendar already exists
for (cal in this.mCalendars) {
if (cal.uri == aCalendar.uri) {
for each (cal in this.mCalendars) {
if (aCalendar.uri.equals(cal.uri)) {
// throw exception if calendar already exists?
return;
}
@ -97,8 +97,8 @@ calCompositeCalendar.prototype = {
removeCalendar: function (aServer) {
var newCalendars = Array();
var calToRemove = null;
for (cal in this.mCalendars) {
if (cal.uri != aServer)
for each (cal in this.mCalendars) {
if (!aServer.equals(cal.uri))
newCalendars.push(cal);
else
calToRemove = cal;
@ -109,8 +109,8 @@ calCompositeCalendar.prototype = {
},
getCalendar: function (aServer) {
for (cal in this.mCalendars) {
if (cal.uri == aServer)
for each (cal in this.mCalendars) {
if (aServer.equals(cal.uri))
return cal;
}
@ -157,15 +157,15 @@ calCompositeCalendar.prototype = {
const calICompositeObserver = Components.interfaces.calICompositeObserver;
if (aObserver instanceof calICompositeObserver) {
var compobs = aObserver.QueryInterface (calICompositeObserver);
for (var i = 0; i < this.mCompositeObservers.length; i++) {
if (this.mCompositeObservers[i] == aObserver)
for each (obs in this.mCompositeObservers) {
if (obs == aObserver)
return;
}
this.mCompositeObservers.push(compobs);
}
for (cal in this.mCalendars) {
this.mCalendars[cal].addObserver(aObserver, aItemFilter);
for each (cal in this.mCalendars) {
cal.addObserver(aObserver, aItemFilter);
}
},
@ -175,15 +175,15 @@ calCompositeCalendar.prototype = {
var compobs = aObserver.QueryInterface (calICompositeObserver);
if (compobs) {
var newCompObs = Array ();
for (var i = 0; i < this.mCompositeObservers.length; i++) {
if (this.mCompositeObservers[i] != compobs)
for each (obs in this.mCompositeObservers) {
if (obs != compobs)
newCompObs.push(this.mCompositeObservers[i]);
}
this.mCompositeObservers = newCompObs;
}
for (cal in this.mCalendars) {
this.mCalendars[cal].removeObserver(aObserver);
for each (cal in this.mCalendars) {
cal.removeObserver(aObserver);
}
},
@ -215,7 +215,7 @@ calCompositeCalendar.prototype = {
// void getItem( in string aId, in calIOperationListener aListener );
getItem: function (aId, aListener) {
var cmpListener = new calCompositeGetListenerHelper(this.mCalendars.length, aListener);
for (cal in this.mCalendars) {
for each (cal in this.mCalendars) {
cal.getItem (aId, cmpListener);
}
},
@ -234,17 +234,17 @@ calCompositeCalendar.prototype = {
// observer helpers
//
observeCalendarAdded: function (aCalendar) {
for (obs in this.mCompositeObservers)
for each (obs in this.mCompositeObservers)
obs.onCalendarAdded (aCalendar);
},
observeCalendarRemoved: function (aCalendar) {
for (obs in this.mCompositeObservers)
for each (obs in this.mCompositeObservers)
obs.onCalendarRemoved (aCalendar);
},
observeDefaultCalendarChanged: function (aCalendar) {
for (obs in this.mCompositeObservers)
for each (obs in this.mCompositeObservers)
obs.onDefaultCalendarChanged (aCalendar);
}
};

Просмотреть файл

@ -47,47 +47,47 @@ const kCalICalendar = Components.interfaces.calICalendar;
const kCalEventContractID = "@mozilla.org/calendar/event;1";
const kCalIEvent = Components.interfaces.calIEvent;
const CalEvent = new Components.Constructor(kCalEventContractID, kCalIEvent);
var CalEvent;
const kCalTodoContractID = "@mozilla.org/calendar/todo;1";
const kCalITodo = Components.interfaces.calITodo;
const CalTodo = new Components.Constructor(kCalTodoContractID, kCalITodo);
var CalTodo;
const kCalDateTimeContractID = "@mozilla.org/calendar/datetime;1";
const kCalIDateTime = Components.interfaces.calIDateTime;
const CalDateTime = new Components.Constructor(kCalDateTimeContractID, kCalIDateTime);
var CalDateTime;
const kCalAttendeeContractID = "@mozilla.org/calendar/attendee;1";
const kCalIAttendee = Components.interfaces.calIAttendee;
const CalAttendee = new Components.Constructor(kCalAttendeeContractID, kCalIAttendee);
var CalAttendee;
const kCalItemOccurrenceContractID = "@mozilla.org/calendar/item-occurrence;1";
const kCalIItemOccurrence = Components.interfaces.calIItemOccurrence;
const CalItemOccurrence = new Components.Constructor(kCalItemOccurrenceContractID, kCalIItemOccurrence);
var CalItemOccurrence;
const kCalRecurrenceInfoContractID = "@mozilla.org/calendar/recurrence-info;1";
const kCalIRecurrenceInfo = Components.interfaces.calIRecurrenceInfo;
const CalRecurrenceInfo = new Components.Constructor(kCalRecurrenceInfoContractID, kCalIRecurrenceInfo);
var CalRecurrenceInfo;
const kCalRecurrenceRuleContractID = "@mozilla.org/calendar/recurrence-rule;1";
const kCalIRecurrenceRule = Components.interfaces.calIRecurrenceRule;
const CalRecurrenceRule = new Components.Constructor(kCalRecurrenceRuleContractID, kCalIRecurrenceRule);
var CalRecurrenceRule;
const kCalRecurrenceDateSetContractID = "@mozilla.org/calendar/recurrence-date-set;1";
const kCalIRecurrenceDateSet = Components.interfaces.calIRecurrenceDateSet;
const CalRecurrenceDateSet = new Components.Constructor(kCalRecurrenceDateSetContractID, kCalIRecurrenceDateSet);
var CalRecurrenceDateSet;
const kCalRecurrenceDateContractID = "@mozilla.org/calendar/recurrence-date;1";
const kCalIRecurrenceDate = Components.interfaces.calIRecurrenceDate;
const CalRecurrenceDate = new Components.Constructor(kCalRecurrenceDateContractID, kCalIRecurrenceDate);
var CalRecurrenceDate;
const kMozStorageStatementWrapperContractID = "@mozilla.org/storage/statement-wrapper;1";
const kMozStorageStatementWrapperIID = Components.interfaces.mozIStorageStatementWrapper;
if (kMozStorageStatementWrapperIID) {
const MozStorageStatementWrapper = new Components.Constructor(kMozStorageStatementWrapperContractID, kMozStorageStatementWrapperIID);
} else {
var MozStorageStatementWrapper;
if (!kMozStorageStatementWrapperIID) {
dump("*** mozStorage not available, calendar/storage provider will not function\n");
}
}
const CAL_ITEM_TYPE_EVENT = 0;
const CAL_ITEM_TYPE_TODO = 1;
@ -99,6 +99,19 @@ const CAL_ITEM_FLAG_HAS_PROPERTIES = 4;
const CAL_ITEM_FLAG_EVENT_ALLDAY = 8;
const CAL_ITEM_FLAG_HAS_RECURRENCE = 16;
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);
}
//
// Storage helpers
//
@ -1163,6 +1176,10 @@ var calStorageCalendarModule = {
if (!kStorageServiceIID)
throw Components.results.NS_ERROR_NOT_INITIALIZED;
if (!CalEvent) {
initCalStorageCalendarComponent();
}
return this.mFactory;
},