Bug 340949: fixing sync, minor

This commit is contained in:
daniel.boelzle%sun.com 2006-09-09 14:06:16 +00:00
Родитель 8152d2651a
Коммит 6e5b7b6b63
5 изменённых файлов: 136 добавлений и 133 удалений

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

@ -54,6 +54,7 @@ function calWcapCachedCalendar() {
calWcapCachedCalendar.prototype = {
m_ifaces: [ Components.interfaces.calIWcapCalendar,
Components.interfaces.calICalendar,
Components.interfaces.calICalendarProvider,
Components.interfaces.nsIInterfaceRequestor,
Components.interfaces.nsIClassInfo,
Components.interfaces.nsISupports ],
@ -190,6 +191,22 @@ calWcapCachedCalendar.prototype = {
? [err.result, err.message] : [-1, msg] );
},
// calICalendarProvider:
get prefChromeOverlay() {
return this.remoteCal.prefChromeOverlay;
},
// displayName attribute already part of calIWcapCalendar
createCalendar:
function( name, url, listener ) {
this.remoteCal.createCalendar( name, url, listener );
},
deleteCalendar: function( calendar, listener ) {
this.remoteCal.deleteCalendar( calendar, listener );
},
getCalendar: function( url ) {
return this.remoteCal.getCalendar( url );
},
// calIWcapCalendar:
// xxx todo: generic facade helpers for most function delegates

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

@ -60,8 +60,8 @@ function calWcapCalendar( calId, session ) {
}
calWcapCalendar.prototype = {
m_ifaces: [ Components.interfaces.calIWcapCalendar,
Components.interfaces.calICalendarProvider,
Components.interfaces.calICalendar,
Components.interfaces.calICalendarProvider,
Components.interfaces.nsIInterfaceRequestor,
Components.interfaces.nsIClassInfo,
Components.interfaces.nsISupports ],
@ -143,24 +143,28 @@ calWcapCalendar.prototype = {
err instanceof Components.interfaces.nsIException
? [err.result, err.message] : [-1, msg] );
},
// calICalendarProvider:
get prefChromeOverlay() {
return null;
},
get displayName() {
return calGetString("wcap", "wcapName");
},
createCalendar: function wcap_createCal() {
// displayName attribute already part of calIWcapCalendar
createCalendar:
function( name, url, listener )
{
throw NS_ERROR_NOT_IMPLEMENTED;
},
deleteCalendar: function wcap_deleteCal(cal, listener) {
deleteCalendar:
function( calendar, listener )
{
throw NS_ERROR_NOT_IMPLEMENTED;
},
getCalendar:
function( url )
{
throw NS_ERROR_NOT_IMPLEMENTED;
},
// calICalendar:
get name() {
return getCalendarManager().getCalendarPref( this, "NAME" );
@ -230,7 +234,7 @@ calWcapCalendar.prototype = {
// like a subscribed one...
m_calId: null,
get calId() {
var userId = this.session.userId; // assure being logged in
var userId = this.session.defaultCalId; // assure being logged in
return this.m_calId || userId;
},
set calId( id ) {

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

@ -1309,140 +1309,113 @@ calWcapCalendar.prototype.syncChangesTo = function(
},
// abortFunc:
function( exc ) {
// if (listener != null) {
// listener.onOperationComplete(
// this_.superCalendar,
// Components.results.NS_ERROR_FAILURE,
// SYNC, null, exc );
// }
if (listener != null) {
listener.onOperationComplete(
this_.superCalendar,
Components.results.NS_ERROR_FAILURE,
SYNC, null, exc );
}
this_.logError( exc );
} );
var addItemListener = new FinishListener(
Components.interfaces.calIOperationListener.ADD, syncState );
if (dtFrom == null) {
this.log( "syncChangesTo(): doing initial sync." );
syncState.acquire();
var url = this.session.getCommandUrl( "fetchcomponents_by_range" );
url += ("&relativealarm=1&compressed=1&recurring=1" +
"&fmt-out=text%2Fcalendar&calid=" +
encodeURIComponent(this.calId));
url += getItemFilterUrlPortions(itemFilter);
this.session.issueAsyncRequest(
url, stringToIcal,
function( wcapResponse ) {
this_.syncChangesTo_resp(
wcapResponse, syncState, listener,
function( item ) {
var modifiedItems = [];
this.log( "syncChangesTo(): getting last modifications..." );
var modifyItemListener = new FinishListener(
Components.interfaces.calIOperationListener.MODIFY, syncState );
var params = ("&relativealarm=1&compressed=1&recurring=1&calid=" +
encodeURIComponent(this.calId));
params += ("&fmt-out=text%2Fcalendar&dtstart=" + zdtFrom);
params += ("&dtend=" + getIcalUTC(now));
syncState.acquire();
this.session.issueAsyncRequest(
this.session.getCommandUrl("fetchcomponents_by_lastmod") +
params + getItemFilterUrlPortions(itemFilter),
stringToIcal,
function( wcapResponse ) {
this_.syncChangesTo_resp(
wcapResponse, syncState, listener,
function( item ) {
var dtCreated = item.getProperty("CREATED");
var bAdd = (dtCreated == null || dtFrom == null ||
dtCreated.compare(dtFrom) >= 0);
modifiedItems.push( item.id );
if (bAdd) {
// xxx todo: verify whether exceptions
// have been written
this_.log( "new item: " + item.id );
if (destCal) {
syncState.acquire();
// xxx todo: verify whether exceptions have been
// written
destCal.addItem( item, addItemListener );
}
if (calObserver)
calObserver.onAddItem( item );
} );
} );
}
else {
var modifiedItems = [];
this.log( "syncChangesTo(): getting last modifications..." );
var modifyItemListener = new FinishListener(
Components.interfaces.calIOperationListener.MODIFY, syncState );
var params = ("&relativealarm=1&compressed=1&recurring=1&calid=" +
encodeURIComponent(this.calId));
params += ("&fmt-out=text%2Fcalendar&dtstart=" + zdtFrom);
syncState.acquire();
this.session.issueAsyncRequest(
this.session.getCommandUrl("fetchcomponents_by_lastmod") +
params + getItemFilterUrlPortions(itemFilter),
stringToIcal,
function( wcapResponse ) {
this_.syncChangesTo_resp(
wcapResponse, syncState, listener,
function( item ) {
var dtCreated = item.getProperty("CREATED");
var bAdd = (dtCreated == null ||
dtCreated.compare(dtFrom) >= 0);
modifiedItems.push( item.id );
if (bAdd) {
// xxx todo: verify whether exceptions
// have been written
this_.log( "new item: " + item.id );
if (destCal) {
syncState.acquire();
destCal.addItem( item, addItemListener );
}
if (calObserver)
calObserver.onAddItem( item );
}
else {
this_.log( "modified item: " + item.id );
if (destCal) {
syncState.acquire();
destCal.modifyItem( item, null,
modifyItemListener );
}
else {
this_.log( "modified item: " + item.id );
if (destCal) {
syncState.acquire();
destCal.modifyItem( item, null,
modifyItemListener );
}
if (calObserver)
calObserver.onModifyItem( item, null );
if (calObserver)
calObserver.onModifyItem( item, null );
}
} );
} );
this.log( "syncChangesTo(): getting deleted items..." );
var deleteItemListener = new FinishListener(
Components.interfaces.calIOperationListener.DELETE, syncState );
syncState.acquire();
this.session.issueAsyncRequest(
this.session.getCommandUrl("fetch_deletedcomponents") + params +
getItemFilterUrlPortions( itemFilter & // only component-type
Components.interfaces.calICalendar
.ITEM_FILTER_TYPE_ALL ),
stringToIcal,
function( wcapResponse ) {
this_.syncChangesTo_resp(
wcapResponse, syncState, listener,
function( item ) {
// don't delete anything that has been touched
// by lastmods:
for each ( var mid in modifiedItems ) {
if (item.id == mid) {
this_.log( "skipping deletion of " + item.id );
return;
}
} );
} );
this.log( "syncChangesTo(): getting deleted items..." );
var deleteItemListener = new FinishListener(
Components.interfaces.calIOperationListener.DELETE, syncState );
syncState.acquire();
this.session.issueAsyncRequest(
this.session.getCommandUrl("fetch_deletedcomponents") + params +
getItemFilterUrlPortions( itemFilter & // only component-type
Components.interfaces.calICalendar
.ITEM_FILTER_TYPE_ALL ),
stringToIcal,
function( wcapResponse ) {
this_.syncChangesTo_resp(
wcapResponse, syncState, listener,
function( item ) {
// don't delete anything that has been touched
// by lastmods:
for each ( var mid in modifiedItems ) {
if (item.id == mid) {
this_.log(
"skipping deletion of " + item.id );
return;
}
}
if (isParent(item)) {
this_.log( "deleted item: " + item.id );
if (destCal) {
syncState.acquire();
destCal.deleteItem(
item, deleteItemListener );
}
if (isParent(item)) {
this_.log( "deleted item: " + item.id );
if (destCal) {
syncState.acquire();
destCal.deleteItem( item,
deleteItemListener );
}
if (calObserver)
calObserver.onDeleteItem( item );
if (calObserver)
calObserver.onDeleteItem( item );
}
else {
// modify parent instead of
// straight-forward deleteItem(). WTF.
var parent = item.parentItem.clone();
parent.recurrenceInfo.removeOccurrenceAt(
item.recurrenceId );
this_.log( "modified parent: " + parent.id );
if (destCal) {
syncState.acquire();
destCal.modifyItem( parent, item,
deleteItemListener );
}
else {
// modify parent instead of
// straight-forward deleteItem(). WTF.
var parent = item.parentItem.clone();
parent.recurrenceInfo.removeOccurrenceAt(
item.recurrenceId );
this_.log( "modified parent: " + parent.id );
if (destCal) {
syncState.acquire();
destCal.modifyItem( parent, item,
deleteItemListener );
}
if (calObserver)
calObserver.onModifyItem( parent, item );
}
} );
} );
}
if (calObserver)
calObserver.onModifyItem( parent, item );
}
} );
} );
}
catch (exc) {
if (listener != null) {

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

@ -335,6 +335,9 @@ function errorToString( err )
return err;
if (err instanceof Error)
return err.message;
if (err instanceof Components.interfaces.nsIException)
return err.toString(); // xxx todo: or just message?
// numeric codes:
switch (err) {
case Components.results.NS_ERROR_INVALID_ARG:
return "NS_ERROR_INVALID_ARG";

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

@ -692,6 +692,8 @@ calWcapSession.prototype = {
var nColon = username.indexOf(':');
this.m_userId =
(nColon >= 0 ? username.substr(0, nColon) : username);
if (this.m_userId.length > 0)
this.m_defaultCalId = this.m_userId;
}
this.m_uri = thatUri.clone();
this.log( "setting uri to " + this.uri.spec );
@ -705,6 +707,9 @@ calWcapSession.prototype = {
m_userId: null,
get userId() { return this.m_userId; },
m_defaultCalId: null,
get defaultCalId() { return this.m_defaultCalId || this.userId; },
get isLoggedIn() { return this.m_sessionId != null; },
login:
@ -736,6 +741,7 @@ calWcapSession.prototype = {
}
this.m_userId = null;
this.m_userPrefs = null; // reread prefs
this.m_defaultCalId = null;
this.m_bNoLoginsAnymore = false;
},
@ -1011,7 +1017,7 @@ function confirmInsecureLogin( uri )
if (g_confirmedHttpLogins == null) {
g_confirmedHttpLogins = {};
var confirmedHttpLogins = getPref(
"calendar.wcap.confirmedHttpLogins", "");
"calendar.wcap.confirmed_http_logins", "");
var tuples = confirmedHttpLogins.split(',');
for each ( var tuple in tuples ) {
var ar = tuple.split(':');
@ -1037,12 +1043,12 @@ function confirmInsecureLogin( uri )
if (dontAskAgain.value) {
// save decision for all running calendars and all future confirmations:
var confirmedHttpLogins = getPref(
"calendar.wcap.confirmedHttpLogins", "");
"calendar.wcap.confirmed_http_logins", "");
if (confirmedHttpLogins.length > 0)
confirmedHttpLogins += ",";
confirmedEntry = (bConfirmed ? "1" : "0");
confirmedHttpLogins += (encodedHost + ":" + confirmedEntry);
setPref("calendar.wcap.confirmedHttpLogins", confirmedHttpLogins);
setPref("calendar.wcap.confirmed_http_logins", confirmedHttpLogins);
g_confirmedHttpLogins[encodedHost] = confirmedEntry;
}