bug 455837 - Support for re-enabling disabled calendars. r=philipp
--- a/calendar/base/content/calendar-properties-dialog.js
+++ b/calendar/base/content/calendar-properties-dialog.js
@@ -101,18 +101,19 @@ function onAcceptDialog() {
gCalendar.readOnly = document.getElementById("read-only").checked;
// Save supressAlarms
gCalendar.setProperty("suppressAlarms", !document.getElementById("fire-alarms").checked);
// Save cache options
gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
- // Save disabled option (should do this last)
+ // Save disabled option (should do this last), remove auto-enabled
gCalendar.setProperty("disabled", !document.getElementById("calendar-enabled-checkbox").checked);
+ gCalendar.deleteProperty("auto-enabled");
// tell standard dialog stuff to close the dialog
return true;
}
/**
* When the calendar is disabled, we need to disable a number of other elements
*/
--- a/calendar/base/public/calICalendar.idl
+++ b/calendar/base/public/calICalendar.idl
@@ -122,16 +122,17 @@ interface calICalendar : nsISupports
* The call returns null in case the property is not known;
* callers should use a sensible default in that case.
*
* It's up to the provider where to store properties,
* e.g. on the server or in local prefs.
*
* Currently known properties are:
* [boolean] disabled
+ * [boolean] auto-enabled If true, the calendar will be enabled on next startup.
* [boolean] calendar-main-in-composite
* [string] name
* [boolean] readOnly
* [boolean] requiresNetwork If false, the calendar does not require
* network access at all. This is mainy used
* as a UI hint.
* [boolean] suppressAlarms If true, alarms of this calendar are not minded.
* [boolean] cache.supported If true, the calendar should to be cached,
--- a/calendar/base/src/calCalendarManager.js
+++ b/calendar/base/src/calCalendarManager.js
@@ -579,48 +579,50 @@ calCalendarManager.prototype = {
// bail if this calendar (or one that looks identical to it) is already registered
if (calendar.id > 0) {
dump ("registerCalendar: calendar already registered\n");
throw Components.results.NS_ERROR_FAILURE;
}
this.assureCache();
- // Add an observer to track readonly-mode triggers
- var newObserver = new calMgrCalendarObserver(calendar, this);
- calendar.addObserver(newObserver);
-
var pp = this.mRegisterCalendar.params;
pp.type = calendar.type;
pp.uri = calendar.uri.spec;
this.mRegisterCalendar.step();
this.mRegisterCalendar.reset();
calendar.id = this.mDB.lastInsertRowID;
-
- //dump("adding [" + this.mDB.lastInsertRowID + "]\n");
- //this.mCache[this.mDB.lastInsertRowID] = calendar;
+
+ this.setupCalendar(calendar);
+
+ this.notifyObservers("onCalendarRegistered", [calendar]);
+ },
+
+ setupCalendar: function cmgr_setupCalendar(calendar) {
this.mCache[calendar.id] = calendar;
+
+ // Add an observer to track readonly-mode triggers
+ var newObserver = new calMgrCalendarObserver(calendar, this);
+ calendar.addObserver(newObserver);
this.mCalObservers[calendar.id] = newObserver;
// Set up statistics
if (calendar.getProperty("requiresNetwork") !== false) {
this.mNetworkCalendarCount++;
}
if (calendar.readOnly) {
this.mReadonlyCalendarCount++;
}
this.mCalendarCount++;
if (!calendar.getProperty("disabled") && calendar.canRefresh) {
calendar.refresh();
}
-
- this.notifyObservers("onCalendarRegistered", [calendar]);
},
unregisterCalendar: function(calendar) {
this.notifyObservers("onCalendarUnregistering", [calendar]);
// calendar may be a calICalendar wrapper:
if (calendar.wrappedJSObject instanceof calCachedCalendar) {
calendar.wrappedJSObject.onCalendarUnregistering();
@@ -705,37 +707,27 @@ calCalendarManager.prototype = {
for each (var caldata in newCalendarData) {
try {
var cal = this.createCalendar(caldata.type, makeURL(caldata.uri));
if (!cal) {
continue;
}
cal.id = caldata.id;
+
+ if (cal.getProperty("auto-enabled") === true) {
+ cal.deleteProperty("disabled");
+ cal.deleteProperty("auto-enabled");
+ }
+
if ((cal.getProperty("cache.supported") !== false) && cal.getProperty("cache.enabled")) {
cal = new calCachedCalendar(cal);
}
- var newObserver = new calMgrCalendarObserver(cal, this);
- cal.addObserver(newObserver);
- this.mCalObservers[caldata.id] = newObserver;
- this.mCache[caldata.id] = cal;
-
- // Set up statistics
- if (cal.getProperty("requiresNetwork") !== false) {
- this.mNetworkCalendarCount++;
- }
- if (cal.readOnly) {
- this.mReadonlyCalendarCount++;
- }
- this.mCalendarCount++;
-
- if (!cal.getProperty("disabled") && cal.canRefresh) {
- cal.refresh();
- }
+ this.setupCalendar(cal);
} catch (exc) {
Components.utils.reportError(
"Can't create calendar for " + caldata.id +
" (" + caldata.type + ", " + caldata.uri + "): " + exc);
}
}
}
},
--- a/calendar/providers/base/calProviderBase.js
+++ b/calendar/providers/base/calProviderBase.js
@@ -345,16 +345,17 @@ calProviderBase.prototype = {
// If popup alarms are not supported,
// automatically suppress alarms
ret = true;
break;
}
// Otherwise fall through to fix the type
case "readOnly":
case "disabled":
+ case "auto-enabled":
case "relaxedMode":
case "cache.supported":
case "cache.enabled":
case "calendar-main-in-composite":
case "calendar-main-default":
ret = (ret == "true");
break;
case "backup-time":
--- a/calendar/providers/gdata/components/calGoogleSession.js
+++ b/calendar/providers/gdata/components/calGoogleSession.js
@@ -314,16 +314,17 @@ calGoogleSession.prototype = {
LOG("Could not get any credentials for " +
calendarName + " (" +
this.mGoogleUser + ")");
if (aCalendar) {
// First of all, disable the calendar so no further login
// dialogs show up.
aCalendar.setProperty("disabled", true);
+ aCalendar.setProperty("auto-enabled", true);
// Unset the session in the requesting calendar, if the user
// canceled the login dialog that also asks for the
// username, then the session is not valid. This also
// prevents multiple login windows.
aCalendar.session = null;
}
--- a/calendar/providers/wcap/calWcapSession.js
+++ b/calendar/providers/wcap/calWcapSession.js
@@ -283,16 +283,17 @@ calWcapSession.prototype = {
outPW,
outSavePW,
this_.credentials.userId != null)) {
this_.login(request, promptAndLoginLoop_resp,
outUser.value, outPW.value);
} else {
log("login prompt cancelled.", this_);
this_.defaultCalendar.setProperty("disabled", true);
+ this_.defaultCalendar.setProperty("auto-enabled", true);
respFunc(new Components.Exception(errorToString(calIWcapErrors.WCAP_LOGIN_FAILED),
calIWcapErrors.WCAP_LOGIN_FAILED));
}
} else if (err) {
respFunc(err);
} else {
if (outSavePW.value) {
// so try to remove old pw from db first: