Skip to content

Commit

Permalink
Added patch from #2393 and reorganized some files.
Browse files Browse the repository at this point in the history
  • Loading branch information
extrafu committed Feb 4, 2014
1 parent d1b32b9 commit 9bd4c5b
Show file tree
Hide file tree
Showing 23 changed files with 588 additions and 20 deletions.
File renamed without changes.
5 changes: 4 additions & 1 deletion RELEASE-NOTES
@@ -1,7 +1,10 @@
NEWS
====

For later changes see ChangeLog.
24.0.4 Improved etag handling (#1411 and #1624)
Handle periodic syncing of address books

For later changes see ChangeLog.old

0.92
Fixed unescaping of special characters (\r, \n, ...) from VCARD content
Expand Down
Expand Up @@ -579,7 +579,7 @@ function SCAbConfirmDeleteDirectory(selectedDir) {
}

function SCSynchronizeFromChildWindow(uri) {
this.setTimeout(SynchronizeGroupdavAddressbook, 1, uri, null);
this.setTimeout(SynchronizeGroupdavAddressbook, 1, uri, null, 1);
}

let groupdavSynchronizationObserver = {
Expand Down Expand Up @@ -847,7 +847,7 @@ function SCCommandSynchronize() {
SynchronizeGroupdavAddressbook(gSelectedDir, SCCommandSynchronizeCallback);
}

function SCCommandSynchronizeCallback(url, code, failures) {
function SCCommandSynchronizeCallback(url, code, failures, datas) {
dump("SCCommandSynchronizeCallback\n");
dump(" url: " + url + "\n");
dump(" code: " + code + "\n");
Expand Down
Expand Up @@ -44,6 +44,15 @@
<script type="application/x-javascript"
src="chrome://sogo-connector/content/addressbook/addressbook.groupdav.overlay.js"/>

<!--
MUST USE THE EXISTING id OF BUNDLESET OF ORIGINAL XUL FILE
===> it means we add the stringbundle to the existing stringbundleset
-->
<stringbundleset id="stringbundleset">
<stringbundle id="sogoStringBundle" src="chrome://sogo-connector/locale/addressbook/messenger.groupdav.overlay.properties"/>
</stringbundleset>


<commandset id="addressBook">
<command id="cmd_syncGroupdav" oncommand="SCCommandSynchronize();"/>
<command id="cmd_syncAbortGroupdav" oncommand="SCCommandSynchronizeAbort();"/>
Expand Down
Expand Up @@ -214,21 +214,59 @@ function _migrateOldCardDAVDirs(prefs, uniqueChildren) {
}
}

// TODO : better handling of that var
var SOGO_Timers = [];

function startFolderSync() {
let abManager = Components.classes["@mozilla.org/abmanager;1"]
.getService(Components.interfaces.nsIAbManager);

let children = abManager.directories;
while (children.hasMoreElements()) {
let ab = children.getNext().QueryInterface(Components.interfaces.nsIAbDirectory);
if (isGroupdavDirectory(ab.URI)) {
let synchronizer = new GroupDavSynchronizer(ab.URI, false);
synchronizer.start();
if (isGroupdavDirectory(ab.URI)) {
let dirPrefId = ab.dirPrefId;
let groupdavPrefService = new GroupdavPreferenceService(dirPrefId);
let periodicSync = false;
let periodicSyncInterval = 60;
let notifications = false;
let notificationsOnlyIfNotEmpty = false;
try {
periodicSync = groupdavPrefService.getPeriodicSync();
periodicSyncInterval = groupdavPrefService.getPeriodicSyncInterval();
notifications = groupdavPrefService.getNotifications();
notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty();
} catch(e) {
}


// handle startup sync
sync = GetSyncNotifyGroupdavAddressbook(ab.URI, ab, SOGOC_SYNC_STARTUP);
sync.notify();

if (periodicSync) {
// handle future periodic sync
psync = GetSyncNotifyGroupdavAddressbook(ab.URI, ab, SOGOC_SYNC_PERIODIC);

// TODO : handle syncInterval and Notifications in a dynamic way :
// today, we have to restart TB if we change those values.

// Now it is time to create the timer.
var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);

let delay = periodicSyncInterval;
delay = delay *60; // min --> sec
// delay = delay * 3; // min --> sec DEBUG
delay = delay * 1000; // sec --> ms
timer.initWithCallback(psync, delay, Components.interfaces.nsITimer.TYPE_REPEATING_PRECISE_CAN_SKIP);
SOGO_Timers.push(timer);
}
}
}
}

function SCSynchronizeFromChildWindow(uri) {
this.setTimeout(SynchronizeGroupdavAddressbook, 100, uri, null);
this.setTimeout(SynchronizeGroupdavAddressbook, 100, uri, null, SOGOC_SYNC_WRITE);
}

window.addEventListener("load", OnLoadMessengerOverlay, false);
Expand Up @@ -30,4 +30,13 @@
<overlay id="ca.inverse.messenger.groupdav" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/x-javascript"
src="chrome://sogo-connector/content/addressbook/messenger.groupdav.overlay.js"/>

<!--
MUST USE THE EXISTING id OF BUNDLESET OF ORIGINAL XUL FILE
===> it means we add the stringbundle to the existing stringbundleset
-->
<stringbundleset id="stringbundleset">
<stringbundle id="sogoStringBundle" src="chrome://sogo-connector/locale/addressbook/messenger.groupdav.overlay.properties"/>
</stringbundleset>

</overlay>
Expand Up @@ -108,11 +108,34 @@ function onAcceptWebDAV() {
done */);
}

let groupdavPrefService = new GroupdavPreferenceService(prefId);
groupdavPrefService.setURL(document.getElementById("groupdavURL").value);
try {
let groupdavPrefService = new GroupdavPreferenceService(prefId);
groupdavPrefService.setURL(document.getElementById("groupdavURL").value);

groupdavPrefService.setPeriodicSync(document.getElementById("periodicSync").checked);
groupdavPrefService.setPeriodicSyncInterval(document.getElementById("periodicSyncInterval").value);

groupdavPrefService.setNotifications(document.getElementById("notifications").checked);
groupdavPrefService.setNotificationsOnlyIfNotEmpty(document.getElementById("notificationsOnlyIfNotEmpty").checked);

groupdavPrefService.setNotificationsManual(document.getElementById("notificationsManual").checked);
groupdavPrefService.setNotificationsSave(document.getElementById("notificationsSave").checked);
groupdavPrefService.setNotificationsStart(document.getElementById("notificationsStart").checked);
} catch(e) {
}
}

function onLoad() {
let description = "";
let url = "";
let periodicSync = false;
let periodicSyncInterval = 15;
let notifications = true;
let notificationsOnlyIfNotEmpty = false;
let notificationsManual = true;
let notificationsSave = false;
let notificationsStart = true;

let directory = SCGetCurrentDirectory();
if (directory) {
let uri = directory.URI;
Expand All @@ -121,22 +144,58 @@ function onLoad() {
roElem.setAttribute("checked", readOnly);
roElem.disabled = true;

let description = "";
let url = "";


if (readOnly) {
description = directory.dirName;
directory = directory.wrappedJSObject;
url = directory.serverURL;
}
else {

try {
let groupdavPrefService = new GroupdavPreferenceService(directory.dirPrefId);
description = directory.dirName;
url = groupdavPrefService.getURL();

periodicSync = groupdavPrefService.getPeriodicSync();
periodicSyncInterval = groupdavPrefService.getPeriodicSyncInterval();

notifications = groupdavPrefService.getNotifications();
notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty();
notificationsManual = groupdavPrefService.getNotificationsManual();
notificationsSave = groupdavPrefService.getNotificationsSave();
notificationsStart = groupdavPrefService.getNotificationsStart();
} catch(e) {
}
document.getElementById("description").value = description;
document.getElementById("groupdavURL").value = url;

}

// always define values
document.getElementById("description").value = description;
document.getElementById("groupdavURL").value = url;

document.getElementById("periodicSync").checked = periodicSync;
document.getElementById("periodicSyncInterval").value = periodicSyncInterval;

document.getElementById("notifications").checked = notifications;
document.getElementById("notificationsOnlyIfNotEmpty").checked = notificationsOnlyIfNotEmpty;
document.getElementById("notificationsManual").checked = notificationsManual;
document.getElementById("notificationsSave").checked = notificationsSave;
document.getElementById("notificationsStart").checked = notificationsStart;

onUpdateCheck();
}

function onUpdateCheck() {
var psc = document.getElementById("periodicSync").checked;
var nc = document.getElementById("notifications").checked;
document.getElementById("periodicSyncInterval").disabled = !psc;
document.getElementById("notifications").disabled = !psc;
document.getElementById("notificationsOnlyIfNotEmpty").disabled = !nc || !psc;
}

function onShowRestart() {
// show the info about restart
document.getElementById("periodicSync_restart").hidden = false;
}

//TODO:catch the directory delete and delete preferences
Expand Down
Expand Up @@ -113,10 +113,65 @@ Modifications by
<textbox id="groupdavURL" flex="1" disableiflocked="true" class="uri-element"/>
<spacer flex="1"/>
</row>

</rows>
</grid>


<grid flex="1">
<columns>
<column/>
<column flex="1"/>
</columns>

<rows >
<separator/>
<row align="center" flex="1">
<checkbox id="periodicSync" label="&groupdavPeriodicSync.label;" oncommand="onUpdateCheck();onShowRestart()" />
<menulist id="periodicSyncInterval" oncommand="onShowRestart()" >
<menupopup>
<menuitem label="&groupdavPeriodicSync5m.label;" value="5"/>
<menuitem label="&groupdavPeriodicSync15m.label;" value="15"/>
<menuitem label="&groupdavPeriodicSync1h.label;" value="60"/>
<menuitem label="&groupdavPeriodicSync2h.label;" value="120"/>
</menupopup>
</menulist>
</row>
<row align="center" flex="1">
<spacer flex="1"/>
<hbox>
<checkbox id="notifications" label="&groupdavNotifications.label;" oncommand="onUpdateCheck()" />
<checkbox id="notificationsOnlyIfNotEmpty" label="&groupdavNotificationsOINE.label;" />
</hbox>
</row>

<row align="center" flex="1">
<spacer flex="1"/>
<label id="periodicSync_restart" hidden="true"
style="font-style:italic"
value="&groupdavNotificationsRestart.label;" />
</row>
</rows>
</grid>

<separator/>
<checkbox id="notificationsManual" label="&groupdavNotificationsManual.label;" />
<label style="font-style:italic"
value="&groupdavNotificationsManual.info;" />

<separator/>
<checkbox id="notificationsSave" label="&groupdavNotificationsSave.label;" />
<label style="font-style:italic"
value="&groupdavNotificationsSave.info;" />

<separator/>
<checkbox id="notificationsStart" label="&groupdavNotificationsStart.label;" />


<separator/>
<checkbox id="readOnly" label="&ReadOnly.label;" accesskey="&ReadOnly.accesskey;"/>


</vbox>
<!-- </tabpanel>
<tabpanel id="downloadPanel">
Expand Down
Expand Up @@ -127,8 +127,8 @@ GroupdavPreferenceService.prototype = {
value = this.mPreferencesService.getCharPref(this.prefPath + prefName);
}
catch(e) {
// dump("exception getting pref '" + this.prefPath + prefName
// + "': \n" + e + " (" + e.lineNumber + ")\n");
dump("exception getting pref '" + this.prefPath + prefName
+ "': \n" + e + " (" + e.lineNumber + ")\n");
// dump(" stack:\n" + backtrace() + "\n");
throw("unacceptable condition: " + e);
}
Expand Down Expand Up @@ -229,6 +229,57 @@ GroupdavPreferenceService.prototype = {
},
setWebdavSyncToken: function GdPSvc_setWebdavSyncToken(value) {
this._setPref("sync-token", value);
},


getPeriodicSync: function GdPSvc_getPeriodicSync() {
return this._getBoolPref("periodicSync");
},
setPeriodicSync: function GdPSvc_setPeriodicSync(value) {
this._setBoolPref("periodicSync", value);
},

getPeriodicSyncInterval: function GdPSvc_getPeriodicSyncInterval() {
return this._getPrefWithDefault("periodicSyncInterval", "15");
},
setPeriodicSyncInterval: function GdPSvc_setPeriodicSyncInterval(value) {
this._setPref("periodicSyncInterval", value);
},


getNotifications: function GdPSvc_getNotifications() {
return this._getBoolPref("notifications");
},
setNotifications: function GdPSvc_setNotifications(value) {
this._setBoolPref("notifications", value);
},

getNotificationsOnlyIfNotEmpty: function GdPSvc_getNotificationsOnlyIfNotEmpty() {
return this._getBoolPref("notificationsNotEmpty");
},
setNotificationsOnlyIfNotEmpty: function GdPSvc_setNotificationsOnlyIfNotEmpty(value) {
this._setBoolPref("notificationsNotEmpty", value);
},

getNotificationsManual: function GdPSvc_getNotificationsManual() {
return this._getBoolPref("notificationsManual");
},
setNotificationsManual: function GdPSvc_setNotificationsManual(value) {
this._setBoolPref("notificationsManual", value);
},

getNotificationsSave: function GdPSvc_getNotificationsSave() {
return this._getBoolPref("notificationsSave");
},
setNotificationsSave: function GdPSvc_setNotificationsSave(value) {
this._setBoolPref("notificationsSave", value);
},

getNotificationsStart: function GdPSvc_getNotificationsStart() {
return this._getBoolPref("notificationsStart");
},
setNotificationsStart: function GdPSvc_setNotificationsStart(value) {
this._setBoolPref("notificationsStart", value);
}
};

Expand Down

0 comments on commit 9bd4c5b

Please sign in to comment.