From a89d7ef8d0aeeb88323939ded54923a6ab8b9c53 Mon Sep 17 00:00:00 2001 From: AE Creations Date: Sat, 2 Jun 2018 23:17:36 -0700 Subject: [PATCH] Modified aeIClippingsService.flushDataSrc() so that it also saves a copy of the datasource to a Clippings 6 compatible JSON file --- src/chrome/content/clippingsMgr.js | 20 +++++++++++--------- src/chrome/content/options/datasource.js | 4 ++-- src/chrome/content/tbMessengerOverlay.js | 5 +++-- src/chrome/content/tbMsgComposeOverlay.js | 5 +++-- src/components/aeClippingsService.js | 13 +++++++++++-- src/components/aeIClippingsService.idl | 2 +- src/modules/aePackagedClippings.js | 2 +- 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/chrome/content/clippingsMgr.js b/src/chrome/content/clippingsMgr.js index a0bbc57..46ccdf9 100755 --- a/src/chrome/content/clippingsMgr.js +++ b/src/chrome/content/clippingsMgr.js @@ -1123,13 +1123,14 @@ function unload() gClippingsSvc.purgeDetachedItems(); - var retrySave; - var doBackup = true; + let retrySave; + let doBackup = true; + let saveJSON = this.aeUtils.getPref("clippings.datasource.wx_sync", false); do { retrySave = false; try { - gClippingsSvc.flushDataSrc(doBackup); + gClippingsSvc.flushDataSrc(doBackup, saveJSON); } catch (e) { if (e.result === undefined) { @@ -1776,7 +1777,7 @@ function commit() try { gSaveInProgress = true; - gClippingsSvc.flushDataSrc(false); + gClippingsSvc.flushDataSrc(false, false); gIsClippingsDirty = false; } catch (e) { @@ -1814,10 +1815,11 @@ function saveClippings(aSuppressStatusMsgs, aForceSave, aDoBackup) gStatusBar.label = gStrBundle.getString("saveProgress"); } - var msg = gStrBundle.getString("saveCompleted"); + let msg = gStrBundle.getString("saveCompleted"); + let saveJSON = this.aeUtils.getPref("clippings.datasource.wx_sync", false); try { gSaveInProgress = true; - gClippingsSvc.flushDataSrc(aDoBackup); + gClippingsSvc.flushDataSrc(aDoBackup, saveJSON); gIsClippingsDirty = false; if (aSuppressStatusMsgs) { @@ -2700,7 +2702,7 @@ function doImport() gStrBundle.getString("importBegin"), gStrBundle.getString("importDone")); try { - gClippingsSvc.flushDataSrc(true); + gClippingsSvc.flushDataSrc(true, false); } catch (e) { // Don't do anything for now - try again when closing Clippings Manager. @@ -2870,7 +2872,7 @@ function restoreBackup(aBackupFileURL) // Must flush changes, or else the original clippings data will persist. try { - gClippingsSvc.flushDataSrc(false); + gClippingsSvc.flushDataSrc(false, false); } catch (e) {} @@ -2921,7 +2923,7 @@ function restoreBackup(aBackupFileURL) gClippingsSvc.processEmptyFolders(); try { - gClippingsSvc.flushDataSrc(true); + gClippingsSvc.flushDataSrc(true, false); } catch (e) {} diff --git a/src/chrome/content/options/datasource.js b/src/chrome/content/options/datasource.js index 616824c..1e02641 100755 --- a/src/chrome/content/options/datasource.js +++ b/src/chrome/content/options/datasource.js @@ -170,10 +170,10 @@ function removeAllSourceURLs() if (confirmRemove) { // Do a backup of the datasource first - gClippingsSvc.flushDataSrc(true); + gClippingsSvc.flushDataSrc(true, false); gClippingsSvc.removeAllSourceURLs(); - gClippingsSvc.flushDataSrc(false); + gClippingsSvc.flushDataSrc(false, false); aeUtils.alertEx(document.title, gStrBundle.getString("removeAllSrcURLsFinish")); diff --git a/src/chrome/content/tbMessengerOverlay.js b/src/chrome/content/tbMessengerOverlay.js index 7d21f0f..a2896f4 100755 --- a/src/chrome/content/tbMessengerOverlay.js +++ b/src/chrome/content/tbMessengerOverlay.js @@ -145,9 +145,10 @@ window.aecreations.clippings = { saveClippings: function () { - var title = this.strBundle.getString("appName"); + let title = this.strBundle.getString("appName"); + let saveJSON = this.aeUtils.getPref("clippings.datasource.wx_sync", false); try { - this.clippingsSvc.flushDataSrc(true); + this.clippingsSvc.flushDataSrc(true, saveJSON); } catch (e) { if (e.result === undefined) { diff --git a/src/chrome/content/tbMsgComposeOverlay.js b/src/chrome/content/tbMsgComposeOverlay.js index 32088b8..60cb25d 100755 --- a/src/chrome/content/tbMsgComposeOverlay.js +++ b/src/chrome/content/tbMsgComposeOverlay.js @@ -488,9 +488,10 @@ window.aecreations.clippings = { saveClippings: function () { - var title = this.strBundle.getString("appName"); + let title = this.strBundle.getString("appName"); + let saveJSON = this.aeUtils.getPref("clippings.datasource.wx_sync", false); try { - this.clippingsSvc.flushDataSrc(true); + this.clippingsSvc.flushDataSrc(true, saveJSON); } catch (e) { if (e.result === undefined) { diff --git a/src/components/aeClippingsService.js b/src/components/aeClippingsService.js index 160392d..05bafd4 100755 --- a/src/components/aeClippingsService.js +++ b/src/components/aeClippingsService.js @@ -52,11 +52,12 @@ aeClippingsService.prototype = { _RDF_SEQ_URI: "http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq", _BACKUP_FILE_PREFIX: "clippings_", _BACKUP_FILE_EXTENSION: ".rdf", + _WX_SYNC_FILENAME: "clippings-sync.json", _CLIPPINGS_HTML_NS: "http://clippings.mozdev.org/ns/html#", _JSON_EXPORT_VER: "6.0", - _JSON_EXPORT_CREATED_BY: "Clippings for Thunderbird 5.6", + _JSON_EXPORT_CREATED_BY: "Clippings for Thunderbird 5.5.9", // Private member variables _dataSrc: null, @@ -1619,7 +1620,7 @@ aeClippingsService.prototype.changePosition = function (aParentFolderURI, aOldPo }; -aeClippingsService.prototype.flushDataSrc = function (aDoBackup) +aeClippingsService.prototype.flushDataSrc = function (aDoBackup, aSaveJSONCopy) { if (! this._dataSrc) { throw Components.Exception("Data source not initialized", @@ -1650,6 +1651,14 @@ aeClippingsService.prototype.flushDataSrc = function (aDoBackup) catch (e) { this._log("aeClippingsService.flushDataSrc(): WARNING: Cannot delete old backup file(s): " + e); } + + if (aSaveJSONCopy) { + let dsURLPrefix = this._dsFileURL.substring(0, this._dsFileURL.lastIndexOf("/") + 1); + let fileURL = dsURLPrefix + this._WX_SYNC_FILENAME; + this._log("aeClippingsService.flushDataSrc(): Saving copy of datasource to Clippings 6 sync file."); + + this.exportToFile(fileURL, this.FILETYPE_WX_JSON, false); + } }; diff --git a/src/components/aeIClippingsService.idl b/src/components/aeIClippingsService.idl index 9df11f4..7c2a459 100755 --- a/src/components/aeIClippingsService.idl +++ b/src/components/aeIClippingsService.idl @@ -219,7 +219,7 @@ interface aeIClippingsService : nsISupports void changePosition(in uri aParentFolder, in size_t aOldPos, in size_t aNewPos); - void flushDataSrc(in boolean aDoBackup); + void flushDataSrc(in boolean aDoBackup, in boolean aSaveJSONCopy); /* throws NS_ERROR_FAILURE - if datasource flush failed */ void refreshDataSrc(); diff --git a/src/modules/aePackagedClippings.js b/src/modules/aePackagedClippings.js index 434df74..83bc9c4 100755 --- a/src/modules/aePackagedClippings.js +++ b/src/modules/aePackagedClippings.js @@ -95,7 +95,7 @@ aePackagedClippings.import = function (aClippingsSvc) aeUtils.log(aeString.format("Successfully imported the packaged data into the Clippings data source\n%d item(s) imported", numImported)); try { - aClippingsSvc.flushDataSrc(true); + aClippingsSvc.flushDataSrc(true, false); } catch (e) { aeUtils.log(aeString.format("aePackagedClippings.import(): Exception thrown by aeIClippingsService.flushDataSrc():\n\n%s", e));