View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002393 | SOGo Connector | with SOGo | public | 2013-08-15 12:58 | 2014-02-04 18:43 |
Reporter | MichelR | Assigned To | ludovic | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Fixed in Version | 24.0.4 | ||||
Summary | 0002393: handle periodic sync | ||||
Description | Sogo Connector for Thunderbird v17.0.5 Sogo Connector should handle periodic sync. Otherwise, it's up to users to manually perform sync. | ||||
Tags | No tags attached. | ||||
2013-08-15 12:59
|
periodic_sync_1_michelr.diff (33,030 bytes)
diff --git a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js index a45a405..b9fe3f3 100644 --- a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js +++ b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js @@ -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 = { @@ -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"); diff --git a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js index c6a2ef1..5a9d626 100644 --- a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js +++ b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js @@ -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, 3); + sync.notify(); + + if (periodicSync) { + // handle future periodic sync + psync = GetSyncNotifyGroupdavAddressbook(ab.URI, ab, 2); + + // 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, 1); } window.addEventListener("load", OnLoadMessengerOverlay, false); diff --git a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js index 6988848..cad7ee0 100644 --- a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js @@ -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; @@ -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 diff --git a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul index b372ea3..598986c 100644 --- a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul +++ b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul @@ -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"> diff --git a/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js b/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js index de90195..0dd7782 100644 --- a/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js @@ -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); } @@ -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); } }; diff --git a/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js b/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js index 848c38b..836fc25 100644 --- a/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js @@ -1505,7 +1505,171 @@ new: } }; -function SynchronizeGroupdavAddressbook(uri, callback, callbackData) { + +function GetSyncNotifyGroupdavAddressbook(uri, ab, origin) { + /* + * Returns an timer object that handle syncs. + * He can be used in a timer or as a one-call sync. + * + * params : + * uri : text, the URI of CardDAV addressbook. + * ab : object, the (OPTIONAL) addressbook object. + * Depending on the calling chain, it is defined + * only for periodic sync. + * origin : int + * 0 : manual sync + * 1 : manual save in card from addressbook + * 2 : periodic sync + * 3 : startup + */ + let notifications = false; + let notificationsOnlyIfNotEmpty = false; + let notificationsManual = true; + let notificationsSave = false; + let notificationsStart = true; + let dirName = uri; + if(typeof(ab) === 'undefined' || ab === null) { + ab = false; + + // search addressbook with URI : + // needed to get : + // - ab dirName + // - notification prefs + 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 (ab.URI === uri) { + dirName = ab.dirName; + let dirPrefId = ab.dirPrefId; + let groupdavPrefService = new GroupdavPreferenceService(dirPrefId); + try { + notifications = groupdavPrefService.getNotifications(); + notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty(); + notificationsManual = groupdavPrefService.getNotificationsManual(); + notificationsSave = groupdavPrefService.getNotificationsSave(); + notificationsStart = groupdavPrefService.getNotificationsStart(); + } catch(e) { + } + } + } + + } else { + dirName = ab.dirName; + let dirPrefId = ab.dirPrefId; + let groupdavPrefService = new GroupdavPreferenceService(dirPrefId); + try { + notifications = groupdavPrefService.getNotifications(); + notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty(); + notificationsManual = groupdavPrefService.getNotificationsManual(); + notificationsSave = groupdavPrefService.getNotificationsSave(); + notificationsStart = groupdavPrefService.getNotificationsStart(); + } catch(e) { + } + } + if(typeof(origin) === 'undefined') { + origin = 0; // manual sync + } + + var sync = { + URI : uri, + dirName : dirName, + origin : origin, + notifications : notifications, + notificationsOnlyIfNotEmpty : notificationsOnlyIfNotEmpty, + notificationsManual : notificationsManual, + notificationsSave : notificationsSave, + notificationsStart : notificationsStart, + + notify: function(timer) { + this.synchronizer = new GroupDavSynchronizer(this.URI); + this.synchronizer.callback = this.cbSynchronize; + this.synchronizer.callbackData = this; + this.synchronizer.start(); + }, + + cbSynchronize: function (cbURL, cbCode, cbFailures, cbData) { + // + // Can't use 'this' because it is a callback. + // + // TODO : l10n of text + let title = "SOGO : "+cbData.dirName; + let texte = "Sync done."; + let total = (cbData.synchronizer.localUploads + + cbData.synchronizer.serverDownloadsCount + + cbData.synchronizer.serverDeletes.length); + if (total > 0) { + texte = ""; + if( cbData.synchronizer.localUploads == 1) + texte += cbData.synchronizer.localUploads+" upload, "; + if( cbData.synchronizer.localUploads > 1) + texte += cbData.synchronizer.localUploads+" uploads, "; + + if( cbData.synchronizer.serverDownloadsCount == 1) + texte += cbData.synchronizer.serverDownloadsCount+" download, "; + if( cbData.synchronizer.serverDownloadsCount > 1) + texte += cbData.synchronizer.serverDownloadsCount+" downloads, "; + + if( cbData.synchronizer.serverDeletes == 1) + texte += cbData.synchronizer.serverDeletes.length+" delete."; + if( cbData.synchronizer.serverDeletes > 1) + texte += cbData.synchronizer.serverDeletes.length+" deletes."; + + } else { + texte = "No changes."; + } + + switch (cbData.origin) { + case (0): + // manual + if(cbData.notificationsManual) + cbData.notifyUser(title, texte); + break; + + case 1: + // save of card + if(cbData.notificationsSave) + cbData.notifyUser(title, texte); + break; + + case 2: + // periodic sync + if (cbData.notifications) { + if (cbData.notificationsOnlyIfNotEmpty) { + if (total > 0) { + cbData.notifyUser(title, texte); + } + } else { + cbData.notifyUser(title, texte); + } + } + break; + + case 3: + // startup + if (cbData.notificationsStart) + cbData.notifyUser(title, texte); + break; + } + }, + + notifyUser: function(atitle, atexte) { + Components.classes['@mozilla.org/alerts-service;1'] + .getService(Components.interfaces.nsIAlertsService) + .showAlertNotification(null, atitle, atexte, false, '', null); + } + } + + return sync; +} + + +function SynchronizeGroupdavAddressbook(uri, callback, origin) { + /* + * old version + * // dump("sync uri: " + uri + "\n"); let synchronizer = new GroupDavSynchronizer(uri); // dump("callback:" + callback + "\n"); @@ -1513,6 +1677,12 @@ function SynchronizeGroupdavAddressbook(uri, callback, callbackData) { synchronizer.callback = callback; synchronizer.callbackData = callbackData; synchronizer.start(); + */ + + // new version with sync + var sync = GetSyncNotifyGroupdavAddressbook(uri, null, origin); + sync.notify(); + } function SynchronizeGroupdavAddressbookAbort(uri) { diff --git a/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd index daaa120..05016b9 100644 --- a/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Typ vzdáleného serveru:"> <!ENTITY groupDavServerType.accesskey "T"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Obecný"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd index 5720b91..6ffb50b 100644 --- a/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd @@ -41,6 +41,20 @@ <!ENTITY groupDavServerType.label "GroupDAV Server Typ:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Allgemein"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd index f26ea59..284375a 100644 --- a/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Remote Server Type:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "General"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd index a1f2440..3145b7b 100644 --- a/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Type de serveur GroupDAV:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Synchronisation Périodique" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Afficher les Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notifier seulement si des données synchronisées" > +<!ENTITY groupdavNotificationsRestart.label "Les changements d'options pour 'Synchronisation Périodique' nécessitent un redémarrage de Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Afficher les Notifications pour les synchronisations manuelles" > +<!ENTITY groupdavNotificationsManual.info "Quand vous choisissez 'Synchroniser' depuis la barre d'outils ou le menu contextuel." > +<!ENTITY groupdavNotificationsSave.label "Afficher les Notifications lors de l'enregistrement d'une fiche" > +<!ENTITY groupdavNotificationsSave.info "La notification par défaut est une barre de progression dans la barre de statut. Si cochée, une notification générale sera affichée." > +<!ENTITY groupdavNotificationsStart.label "Afficher les Notifications au démarrage" > <!ENTITY General.tab "Général"> <!ENTITY Offline.tab "Hors-ligne"> @@ -88,4 +102,4 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY newDirectoryWidth "36em"> <!ENTITY ReadOnly.label "En lecture seulement"> -<!ENTITY ReadOnly.accesskey "L"> \ No newline at end of file +<!ENTITY ReadOnly.accesskey "L"> diff --git a/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd index 6106fc5..c00e8bf 100644 --- a/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd @@ -39,6 +39,20 @@ <!ENTITY groupDavServerType.label "Tipo del server remoto:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Generale"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd index 2c61cae..60f817c 100644 --- a/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Soort server:"> <!ENTITY groupDavServerType.accesskey "S"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Algemeen"> <!ENTITY Offline.tab "Offline"> |
2013-08-15 13:00
|
|
I worked on this feature and here are the results :
You can see a screenshot of all options available in attached file. What remains to be done :
|
|
Can you fix the string bundle issue, do also the French translation and resubmit a patch? |
|
2013-08-18 18:46
|
periodic_sync_2_michelr.diff (41,239 bytes)
diff --git a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js index a45a405..b9fe3f3 100644 --- a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js +++ b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.js @@ -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 = { @@ -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"); diff --git a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.xul b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.xul index d29d5c3..366f5d3 100644 --- a/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.xul +++ b/chrome/content/sogo-connector/addressbook/addressbook.groupdav.overlay.xul @@ -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();"/> diff --git a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js index c6a2ef1..df12da7 100644 --- a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js +++ b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.js @@ -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); diff --git a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.xul b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.xul index 065dae4..30b92a7 100644 --- a/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.xul +++ b/chrome/content/sogo-connector/addressbook/messenger.groupdav.overlay.xul @@ -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> diff --git a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js index 6988848..cad7ee0 100644 --- a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.js @@ -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; @@ -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 diff --git a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul index b372ea3..598986c 100644 --- a/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul +++ b/chrome/content/sogo-connector/addressbook/preferences.addressbook.groupdav.xul @@ -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"> diff --git a/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js b/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js index de90195..0dd7782 100644 --- a/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/general/preference.service.addressbook.groupdav.js @@ -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); } @@ -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); } }; diff --git a/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js b/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js index 848c38b..d1c9335 100644 --- a/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js +++ b/chrome/content/sogo-connector/general/sync.addressbook.groupdav.js @@ -56,6 +56,50 @@ let SOGOC_PROCESS_CARDS = 0; let SOGOC_PROCESS_LISTS = 1; let SOGOC_PROCESS_FINALIZE = 2; + +let SOGOC_SYNC_MANUAL = 0; // manual sync +let SOGOC_SYNC_WRITE = 1; // manual save in card from addressbook +let SOGOC_SYNC_PERIODIC = 2; // periodic sync +let SOGOC_SYNC_STARTUP = 3; // startup + +function loadNotificationsStrings() { + var SOGO_Notifications_Strings = {}; + + let keys = ['notificationsTitle', 'notificationsUpload', 'notificationsUploads', + 'notificationsDownload', 'notificationsDownloads', 'notificationsDelete', + 'notificationsDeletes', 'notificationsNoChanges' ]; + for (let i in keys) { + key = keys[i]; + SOGO_Notifications_Strings[key] = SOGO_GetString(key); + } + return SOGO_Notifications_Strings; +} + +function SOGO_GetString(key) { + /* + * wrapper for localization + * + * params : + * key : the name of the property + * return : + * the value of property in the current language + */ + let bundle = document.getElementById("sogoStringBundle"); + dump("Bundle="+bundle); + if (bundle) + return bundle.getString(key); + else + return key; + /* + * Alternate way + * + let bundleService = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService); + let bundle = bundleService.createBundle("chrome://mrc_compose/locale/mrc_compose.properties"); + let str = bundle.GetStringFromName(key); + return str; + */ +} + let sCounter = 0; function GroupDavSynchronizer(uri) { if (typeof uri == "undefined" || !uri) @@ -1505,7 +1549,169 @@ new: } }; -function SynchronizeGroupdavAddressbook(uri, callback, callbackData) { + +function GetSyncNotifyGroupdavAddressbook(uri, ab, origin) { + /* + * Returns an timer object that handle syncs. + * He can be used in a timer or as a one-call sync. + * + * params : + * uri : text, the URI of CardDAV addressbook. + * ab : object, the (OPTIONAL) addressbook object. + * Depending on the calling chain, it is defined + * only for periodic sync. + * origin : int + * 0 : manual sync + * 1 : manual save in card from addressbook + * 2 : periodic sync + * 3 : startup + */ + let notifications = false; + let notificationsOnlyIfNotEmpty = false; + let notificationsManual = true; + let notificationsSave = false; + let notificationsStart = true; + let dirName = uri; + if(typeof(ab) === 'undefined' || ab === null) { + ab = false; + + // search addressbook with URI : + // needed to get : + // - ab dirName + // - notification prefs + 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 (ab.URI === uri) { + dirName = ab.dirName; + let dirPrefId = ab.dirPrefId; + let groupdavPrefService = new GroupdavPreferenceService(dirPrefId); + try { + notifications = groupdavPrefService.getNotifications(); + notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty(); + notificationsManual = groupdavPrefService.getNotificationsManual(); + notificationsSave = groupdavPrefService.getNotificationsSave(); + notificationsStart = groupdavPrefService.getNotificationsStart(); + } catch(e) { + } + } + } + + } else { + dirName = ab.dirName; + let dirPrefId = ab.dirPrefId; + let groupdavPrefService = new GroupdavPreferenceService(dirPrefId); + try { + notifications = groupdavPrefService.getNotifications(); + notificationsOnlyIfNotEmpty = groupdavPrefService.getNotificationsOnlyIfNotEmpty(); + notificationsManual = groupdavPrefService.getNotificationsManual(); + notificationsSave = groupdavPrefService.getNotificationsSave(); + notificationsStart = groupdavPrefService.getNotificationsStart(); + } catch(e) { + } + } + if(typeof(origin) === 'undefined') { + origin = SOGOC_SYNC_MANUAL; + } + + var sync = { + URI : uri, + dirName : dirName, + origin : origin, + notifications : notifications, + notificationsOnlyIfNotEmpty : notificationsOnlyIfNotEmpty, + notificationsManual : notificationsManual, + notificationsSave : notificationsSave, + notificationsStart : notificationsStart, + notificationsStrings : loadNotificationsStrings(), + + notify: function(timer) { + this.synchronizer = new GroupDavSynchronizer(this.URI); + this.synchronizer.callback = this.cbSynchronize; + this.synchronizer.callbackData = this; + this.synchronizer.start(); + }, + + cbSynchronize: function (cbURL, cbCode, cbFailures, cbData) { + // + // Can't use 'this' because it is a callback. + // + let title = cbData.notificationsStrings['notificationsTitle']+cbData.dirName; + let texte = ""; + let total = (cbData.synchronizer.localUploads + + cbData.synchronizer.serverDownloadsCount + + cbData.synchronizer.serverDeletes.length); + if (total > 0) { + texte = ""; + if( cbData.synchronizer.localUploads <= 1) + texte += cbData.synchronizer.localUploads+cbData.notificationsStrings['notificationsUpload']; + if( cbData.synchronizer.localUploads > 1) + texte += cbData.synchronizer.localUploads+cbData.notificationsStrings['notificationsUploads']; + + if( cbData.synchronizer.serverDownloadsCount <= 1) + texte += cbData.synchronizer.serverDownloadsCount+cbData.notificationsStrings['notificationsDownload']; + if( cbData.synchronizer.serverDownloadsCount > 1) + texte += cbData.synchronizer.serverDownloadsCount+cbData.notificationsStrings['notificationsDownloads']; + + if( cbData.synchronizer.serverDeletes <= 1) + texte += cbData.synchronizer.serverDeletes.length+cbData.notificationsStrings['notificationsDelete']; + if( cbData.synchronizer.serverDeletes > 1) + texte += cbData.synchronizer.serverDeletes.length+cbData.notificationsStrings['notificationsDeletes']; + + } else { + texte = cbData.notificationsStrings['notificationsNoChanges']; + } + switch (cbData.origin) { + case (SOGOC_SYNC_MANUAL): + // manual + if(cbData.notificationsManual) + cbData.notifyUser(title, texte); + break; + + case SOGOC_SYNC_WRITE: + // save of card + if(cbData.notificationsSave) + cbData.notifyUser(title, texte); + break; + + case SOGOC_SYNC_PERIODIC: + // periodic sync + if (cbData.notifications) { + if (cbData.notificationsOnlyIfNotEmpty) { + if (total > 0) { + cbData.notifyUser(title, texte); + } + } else { + cbData.notifyUser(title, texte); + } + } + break; + + case SOGOC_SYNC_STARTUP: + // startup + if (cbData.notificationsStart) + cbData.notifyUser(title, texte); + break; + } + }, + + notifyUser: function(atitle, atexte) { + Components.classes['@mozilla.org/alerts-service;1'] + .getService(Components.interfaces.nsIAlertsService) + .showAlertNotification(null, atitle, atexte, false, '', null); + } + } + + return sync; +} + +function SynchronizeGroupdavAddressbook(uri, callback, origin) { + /* + * old version + * // dump("sync uri: " + uri + "\n"); let synchronizer = new GroupDavSynchronizer(uri); // dump("callback:" + callback + "\n"); @@ -1513,6 +1719,12 @@ function SynchronizeGroupdavAddressbook(uri, callback, callbackData) { synchronizer.callback = callback; synchronizer.callbackData = callbackData; synchronizer.start(); + */ + + // new version with sync + var sync = GetSyncNotifyGroupdavAddressbook(uri, null, origin); + sync.notify(); + } function SynchronizeGroupdavAddressbookAbort(uri) { diff --git a/chrome/locale/cs-CZ/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/cs-CZ/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..86d91a2 --- /dev/null +++ b/chrome/locale/cs-CZ/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020upload,\u0020 +notificationsUploads=\u0020uploads,\u0020 +notificationsDownload=\u0020download,\u0020 +notificationsDownloads=\u0020downloads,\u0020 +notificationsDelete=\u0020delete. +notificationsDeletes=\u0020deletes. +notificationsNoChanges=No changes. diff --git a/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd index daaa120..05016b9 100644 --- a/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/cs-CZ/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Typ vzdáleného serveru:"> <!ENTITY groupDavServerType.accesskey "T"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Obecný"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/de-DE/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/de-DE/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..86d91a2 --- /dev/null +++ b/chrome/locale/de-DE/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020upload,\u0020 +notificationsUploads=\u0020uploads,\u0020 +notificationsDownload=\u0020download,\u0020 +notificationsDownloads=\u0020downloads,\u0020 +notificationsDelete=\u0020delete. +notificationsDeletes=\u0020deletes. +notificationsNoChanges=No changes. diff --git a/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd index 5720b91..6ffb50b 100644 --- a/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/de-DE/sogo-connector/addressbook/pref-directory-add.dtd @@ -41,6 +41,20 @@ <!ENTITY groupDavServerType.label "GroupDAV Server Typ:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Allgemein"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/en-US/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/en-US/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..86d91a2 --- /dev/null +++ b/chrome/locale/en-US/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020upload,\u0020 +notificationsUploads=\u0020uploads,\u0020 +notificationsDownload=\u0020download,\u0020 +notificationsDownloads=\u0020downloads,\u0020 +notificationsDelete=\u0020delete. +notificationsDeletes=\u0020deletes. +notificationsNoChanges=No changes. diff --git a/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd index f26ea59..284375a 100644 --- a/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/en-US/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Remote Server Type:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "General"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/fr-FR/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/fr-FR/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..f84ba35 --- /dev/null +++ b/chrome/locale/fr-FR/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020envoi,\u0020 +notificationsUploads=\u0020envois,\u0020 +notificationsDownload=\u0020téléchargement,\u0020 +notificationsDownloads=\u0020téléchargements,\u0020 +notificationsDelete=\u0020suppression. +notificationsDeletes=\u0020suppressions. +notificationsNoChanges=Aucun changement. diff --git a/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd index a1f2440..3145b7b 100644 --- a/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/fr-FR/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Type de serveur GroupDAV:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Synchronisation Périodique" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Afficher les Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notifier seulement si des données synchronisées" > +<!ENTITY groupdavNotificationsRestart.label "Les changements d'options pour 'Synchronisation Périodique' nécessitent un redémarrage de Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Afficher les Notifications pour les synchronisations manuelles" > +<!ENTITY groupdavNotificationsManual.info "Quand vous choisissez 'Synchroniser' depuis la barre d'outils ou le menu contextuel." > +<!ENTITY groupdavNotificationsSave.label "Afficher les Notifications lors de l'enregistrement d'une fiche" > +<!ENTITY groupdavNotificationsSave.info "La notification par défaut est une barre de progression dans la barre de statut. Si cochée, une notification générale sera affichée." > +<!ENTITY groupdavNotificationsStart.label "Afficher les Notifications au démarrage" > <!ENTITY General.tab "Général"> <!ENTITY Offline.tab "Hors-ligne"> @@ -88,4 +102,4 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY newDirectoryWidth "36em"> <!ENTITY ReadOnly.label "En lecture seulement"> -<!ENTITY ReadOnly.accesskey "L"> \ No newline at end of file +<!ENTITY ReadOnly.accesskey "L"> diff --git a/chrome/locale/it-IT/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/it-IT/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..86d91a2 --- /dev/null +++ b/chrome/locale/it-IT/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020upload,\u0020 +notificationsUploads=\u0020uploads,\u0020 +notificationsDownload=\u0020download,\u0020 +notificationsDownloads=\u0020downloads,\u0020 +notificationsDelete=\u0020delete. +notificationsDeletes=\u0020deletes. +notificationsNoChanges=No changes. diff --git a/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd index 6106fc5..c00e8bf 100644 --- a/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/it-IT/sogo-connector/addressbook/pref-directory-add.dtd @@ -39,6 +39,20 @@ <!ENTITY groupDavServerType.label "Tipo del server remoto:"> <!ENTITY groupDavServerType.accesskey "G"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Generale"> <!ENTITY Offline.tab "Offline"> diff --git a/chrome/locale/nl-NL/sogo-connector/addressbook/messenger.groupdav.overlay.properties b/chrome/locale/nl-NL/sogo-connector/addressbook/messenger.groupdav.overlay.properties new file mode 100644 index 0000000..86d91a2 --- /dev/null +++ b/chrome/locale/nl-NL/sogo-connector/addressbook/messenger.groupdav.overlay.properties @@ -0,0 +1,8 @@ +notificationsTitle=SOGO :\u0020 +notificationsUpload=\u0020upload,\u0020 +notificationsUploads=\u0020uploads,\u0020 +notificationsDownload=\u0020download,\u0020 +notificationsDownloads=\u0020downloads,\u0020 +notificationsDelete=\u0020delete. +notificationsDeletes=\u0020deletes. +notificationsNoChanges=No changes. diff --git a/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd b/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd index 2c61cae..60f817c 100644 --- a/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd +++ b/chrome/locale/nl-NL/sogo-connector/addressbook/pref-directory-add.dtd @@ -74,6 +74,20 @@ Modifications to original file pref-directory-add.xul by: <!ENTITY groupDavServerType.label "Soort server:"> <!ENTITY groupDavServerType.accesskey "S"> +<!ENTITY groupdavPeriodicSync.label "Periodic sync" > +<!ENTITY groupdavPeriodicSync5m.label "5 min" > +<!ENTITY groupdavPeriodicSync15m.label "15 min" > +<!ENTITY groupdavPeriodicSync1h.label "1 h" > +<!ENTITY groupdavPeriodicSync2h.label "2 h" > +<!ENTITY groupdavNotifications.label "Show Notifications" > + +<!ENTITY groupdavNotificationsOINE.label "Notify only if data synchronized" > +<!ENTITY groupdavNotificationsRestart.label "Changes in options for 'Periodic sync' need a restart of Thunderbird." > +<!ENTITY groupdavNotificationsManual.label "Show Notifications for manual synchronizations" > +<!ENTITY groupdavNotificationsManual.info "When select 'Synchronize' from toolbar or context menu." > +<!ENTITY groupdavNotificationsSave.label "Show Notifications when saving a card" > +<!ENTITY groupdavNotificationsSave.info "The default notification is a progress bar in the status bar. If checked, a general notification will be displayed." > +<!ENTITY groupdavNotificationsStart.label "Show Notifications on startup" > <!ENTITY General.tab "Algemeen"> <!ENTITY Offline.tab "Offline"> |
I added a new version of patch ("periodic_sync_2_michelr.diff")
|
|
This is a great feature! Thanks MichelR! |
|
Great feature. I use it in prod since 3 months and it work great. Why not pushed it upstream yet ? Thanks for your work MichelR |
|
We'll integrate it for the upcoming SOGo 2.2 release. |
|
https://github.com/inverse-inc/sogo-connector.tb24/commit/9bd4c5b7359a6c8a5edd5ee47a1b8170eb8a1fe5 |
|
Date Modified | Username | Field | Change |
---|---|---|---|
2013-08-15 12:58 | MichelR | New Issue | |
2013-08-15 12:59 | MichelR | File Added: periodic_sync_1_michelr.diff | |
2013-08-15 13:00 | MichelR | File Added: Remote Address Book Properties_049.png | |
2013-08-15 13:09 | MichelR | Note Added: 0005897 | |
2013-08-16 12:36 | ludovic | Note Added: 0005900 | |
2013-08-18 18:46 | MichelR | File Added: periodic_sync_2_michelr.diff | |
2013-08-18 18:49 | MichelR | Note Added: 0005903 | |
2013-09-17 19:37 |
|
Status | new => assigned |
2013-09-17 19:37 |
|
Assigned To | => jraby |
2014-01-04 20:03 | Yannik | Note Added: 0006379 | |
2014-02-04 17:03 | Pi3R1k | Note Added: 0006488 | |
2014-02-04 17:07 | ludovic | Assigned To | jraby => ludovic |
2014-02-04 17:07 | ludovic | Note Added: 0006489 | |
2014-02-04 18:43 | ludovic | Note Added: 0006490 | |
2014-02-04 18:43 | ludovic | Status | assigned => closed |
2014-02-04 18:43 | ludovic | Resolution | open => fixed |
2014-02-04 18:43 | ludovic | Fixed in Version | => 24.0.4 |