Skip to content

Commit

Permalink
Modified aeIClippingsService.flushDataSrc() so that it also saves
Browse files Browse the repository at this point in the history
a copy of the datasource to a Clippings 6 compatible JSON file
  • Loading branch information
aecreations committed Jun 3, 2018
1 parent 012737e commit a89d7ef
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 19 deletions.
20 changes: 11 additions & 9 deletions src/chrome/content/clippingsMgr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -1776,7 +1777,7 @@ function commit()

try {
gSaveInProgress = true;
gClippingsSvc.flushDataSrc(false);
gClippingsSvc.flushDataSrc(false, false);
gIsClippingsDirty = false;
}
catch (e) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {}

Expand Down Expand Up @@ -2921,7 +2923,7 @@ function restoreBackup(aBackupFileURL)
gClippingsSvc.processEmptyFolders();

try {
gClippingsSvc.flushDataSrc(true);
gClippingsSvc.flushDataSrc(true, false);
}
catch (e) {}

Expand Down
4 changes: 2 additions & 2 deletions src/chrome/content/options/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"));

Expand Down
5 changes: 3 additions & 2 deletions src/chrome/content/tbMessengerOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/chrome/content/tbMsgComposeOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 11 additions & 2 deletions src/components/aeClippingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
};


Expand Down
2 changes: 1 addition & 1 deletion src/components/aeIClippingsService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/modules/aePackagedClippings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a89d7ef

Please sign in to comment.