Fix bug 780990 - Give providers a way to not support uncached mode. r=redDragon

--HG--
extra : rebase_source : fb594ca5bc333f1f8bfb467139f2d774702a7282
This commit is contained in:
Philipp Kewisch 2012-08-16 15:20:00 +02:00
Родитель 6716c250b7
Коммит 4a7b5984fa
10 изменённых файлов: 74 добавлений и 22 удалений

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

@ -462,7 +462,8 @@ var calendarController = {
selected_events_readonly++;
}
if (item.calendar.getProperty("requiresNetwork") &&
!item.calendar.getProperty("cache.enabled")) {
!item.calendar.getProperty("cache.enabled") &&
!item.calendar.getProperty("cache.always")) {
selected_events_requires_network++;
}
@ -556,7 +557,7 @@ var calendarController = {
let calMgr = getCalendarManager();
let calendars = calMgr.getCalendars({});
for each (let calendar in calendars) {
if (calendar.getProperty("cache.enabled")) {
if (calendar.getProperty("cache.enabled") || calendar.getProperty("cache.always")) {
return true;
}
}

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

@ -8,7 +8,7 @@ Components.utils.import("resource://gre/modules/PluralForm.jsm");
/**
* The calendar to modify, is retrieved from window.arguments[0].calendar
*/
var gCalendar;
let gCalendar;
/**
* This function gets called when the calendar properties dialog gets opened. To
@ -19,7 +19,7 @@ function onLoad() {
gCalendar = window.arguments[0].calendar;
document.getElementById("calendar-name").value = gCalendar.name;
var calColor = gCalendar.getProperty('color');
let calColor = gCalendar.getProperty('color');
if (calColor) {
document.getElementById("calendar-color").color = calColor;
}
@ -30,17 +30,19 @@ function onLoad() {
initRefreshInterval();
// Set up the cache field
var cacheBox = document.getElementById("cache");
var canCache = (gCalendar.getProperty("cache.supported") !== false);
if (!canCache) {
let cacheBox = document.getElementById("cache");
let canCache = (gCalendar.getProperty("cache.supported") !== false);
let alwaysCache = (gCalendar.getProperty("cache.always"))
if (!canCache || alwaysCache) {
cacheBox.setAttribute("disable-capability", "true");
cacheBox.hidden = true;
cacheBox.disabled = true;
}
cacheBox.checked = (canCache && gCalendar.getProperty("cache.enabled"));
cacheBox.checked = (alwaysCache || (canCache && gCalendar.getProperty("cache.enabled")));
// Set up the show alarms row and checkbox
var suppressAlarmsRow = document.getElementById("calendar-suppressAlarms-row");
var suppressAlarms = gCalendar.getProperty('suppressAlarms');
let suppressAlarmsRow = document.getElementById("calendar-suppressAlarms-row");
let suppressAlarms = gCalendar.getProperty('suppressAlarms');
document.getElementById("fire-alarms").checked = !suppressAlarms;
suppressAlarmsRow.hidden =
@ -91,7 +93,10 @@ function onAcceptDialog() {
}
// Save cache options
gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
let alwaysCache = (gCalendar.getProperty("cache.always"))
if (!alwaysCache) {
gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
}
if (!gCalendar.getProperty("force-disabled")) {
// Save disabled option (should do this last), remove auto-enabled
@ -107,9 +112,9 @@ function onAcceptDialog() {
* When the calendar is disabled, we need to disable a number of other elements
*/
function setupEnabledCheckbox() {
var isEnabled = document.getElementById("calendar-enabled-checkbox").checked;
var els = document.getElementsByAttribute("disable-with-calendar", "true");
for (var i = 0; i < els.length; i++) {
let isEnabled = document.getElementById("calendar-enabled-checkbox").checked;
let els = document.getElementsByAttribute("disable-with-calendar", "true");
for (let i = 0; i < els.length; i++) {
els[i].disabled = !isEnabled || (els[i].getAttribute("disable-capability") == "true");
}
}

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

@ -106,7 +106,7 @@
align="center">
<spacer/>
<checkbox id="cache"
label="&calendarproperties.cache2.label;"
label="&calendarproperties.cache3.label;"
disable-with-calendar="true"/>
</row>
<spacer/>

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

@ -122,6 +122,10 @@ interface calICalendar : nsISupports
* e.g. this generally applies to network calendars;
* default is true (if not present).
* [boolean] cache.enabled If true, the calendar is cached; default is false.
* [boolean] cache.always If true, the cache will always be enabled
* and the user cannot turn it off. For
* backward compatibility, return true for
* cache.enabled too.
*
* [nsresult] currentStatus The current error status of the calendar (transient).
*

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

@ -675,6 +675,18 @@ calCachedCalendar.prototype = {
get canRefresh() { // enable triggering sync using the reload button
return true;
},
getProperty: function(aName) {
switch (aName) {
case "cache.enabled":
if (this.mUncachedCalendar.getProperty("cache.always")) {
return true;
}
break;
}
return this.mUncachedCalendar.getProperty(aName);
},
refresh: function() {
if (this.offline) {
this.downstreamRefresh();
@ -942,7 +954,7 @@ calCachedCalendar.prototype = {
}
defineForwards(calCachedCalendar.prototype, "mUncachedCalendar",
["getProperty", "setProperty", "deleteProperty",
["setProperty", "deleteProperty",
"isInvitation", "getInvitedAttendee", "canNotify"],
["type", "aclManager", "aclEntry"],
["id", "name", "uri", "readOnly"]);

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

@ -549,7 +549,8 @@ calCalendarManager.prototype = {
cal.setPref(getPrefBranchFor(calendar.id) + "uri", calendar.uri.spec);
if ((calendar.getProperty("cache.supported") !== false) &&
calendar.getProperty("cache.enabled")) {
(calendar.getProperty("cache.enabled") ||
calendar.getProperty("cache.always"))) {
calendar = new calCachedCalendar(calendar);
}
@ -716,7 +717,8 @@ calCalendarManager.prototype = {
}
if ((calendar.getProperty("cache.supported") !== false) &&
calendar.getProperty("cache.enabled")) {
(calendar.getProperty("cache.enabled") ||
calendar.getProperty("cache.always"))) {
calendar = new calCachedCalendar(calendar);
}
} else { // create dummy calendar that stays disabled for this run:

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

@ -315,6 +315,7 @@ function isCalendarWritable(aCalendar) {
!aCalendar.readOnly &&
(!getIOService().offline ||
aCalendar.getProperty("cache.enabled") ||
aCalendar.getProperty("cache.always") ||
aCalendar.getProperty("requiresNetwork") === false));
}

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

@ -308,7 +308,7 @@
<!ENTITY calendarproperties.name.label "Name:">
<!ENTITY calendarproperties.readonly.label "Read Only">
<!ENTITY calendarproperties.firealarms.label "Show Reminders">
<!ENTITY calendarproperties.cache2.label "Cache">
<!ENTITY calendarproperties.cache3.label "Offline Support">
<!ENTITY calendarproperties.enabled.label "Switch this calendar on">
<!ENTITY calendarproperties.forceDisabled.label "The provider for this calendar could not be found. This often happens if you have disabled or uninstalled certain addons.">
<!ENTITY calendarproperties.unsubscribe.label "Unsubscribe">

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

@ -62,6 +62,31 @@ function setNotification(aReason) {
}
}
/**
* Called when a provider is selected in the network calendar list. Makes sure
* the page is set up for the provider.
*
* @param type The provider type selected
*/
function onSelectProvider(type) {
let cache = document.getElementById("cache");
let tempCal;
try {
tempCal = Components.classes["@mozilla.org/calendar/calendar;1?type=" + type]
.createInstance(Components.interfaces.calICalendar);
} catch (e) {}
if (tempCal && tempCal.getProperty("cache.always")) {
cache.oldValue = cache.checked;
cache.checked = true;
cache.disabled = true;
} else {
cache.checked = cache.oldValue || false;
cache.oldValue = null;
cache.disabled = false;
}
}
/**
* Checks if the required information is set so that the wizard can advance. On
* an error, notifications are shown and the wizard can not be advanced.
@ -145,7 +170,9 @@ function doCreateCalendar() {
gCalendar.name = cal_name;
gCalendar.setProperty('color', cal_color);
gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
if (!gCalendar.getProperty("cache.always")) {
gCalendar.setProperty("cache.enabled", document.getElementById("cache").checked);
}
if (!document.getElementById("fire-alarms").checked) {
gCalendar.setProperty('suppressAlarms', true);

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

@ -49,7 +49,7 @@
<rows>
<row>
<label value="&calendarproperties.format.label;" control="calendar-format"/>
<radiogroup id="calendar-format">
<radiogroup id="calendar-format" onselect="onSelectProvider(this.value)">
<radio value="ics" label="&calendarproperties.webdav.label;" selected="true" />
<radio value="caldav" label="&calendarproperties.caldav.label;"/>
<radio id="wcap-radio" value="wcap" label="&calendarproperties.wcap.label;"/>
@ -70,7 +70,7 @@
<row>
<label/>
<checkbox id="cache"
label="&calendarproperties.cache2.label;"/>
label="&calendarproperties.cache3.label;"/>
</row>
<notificationbox id="location-notifications" flex="1"/>
<!--