From e9bedc640b5eb30b954feea93d8bde6eebab9c6a Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 16 Sep 2010 06:22:39 +0000 Subject: [PATCH] complain regarding out-of-date Word plug-in --- chrome/content/zotero/xpcom/integration.js | 53 +++++++++++++++++++- chrome/locale/en-US/zotero/zotero.properties | 1 + 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index f5db9c01a..8d28ca2d2 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -28,10 +28,16 @@ const RESELECT_KEY_ITEM_KEY = 2; const RESELECT_KEY_ITEM_ID = 3; const DATA_VERSION = 3; +// this is used only for update checking +const INTEGRATION_PLUGINS = ["zoteroMacWordIntegration@zotero.org", + "zoteroOpenOfficeIntegration@zotero.org", "zoteroWinWordIntegration@zotero.org"]; +const INTEGRATION_MIN_VERSION = "3.1a0"; + Zotero.Integration = new function() { var _fifoFile = null; var _osascriptFile; var _inProgress = false; + var _integrationVersionsOK = null; this.sessions = {}; @@ -171,9 +177,31 @@ Zotero.Integration = new function() { } /** - * Executes an integration command. + * Executes an integration command, first checking to make sure that versions are compatible */ this.execCommand = function execCommand(agent, command, docId) { + var verComp = Components.classes["@mozilla.org/xpcom/version-comparator;1"] + .getService(Components.interfaces.nsIVersionComparator); + function _checkAddons(addons) { + for each(var addon in addons) { + if(!addon) continue; + + if(verComp.compare(INTEGRATION_MIN_VERSION, addon.version) > 0) { + _inProgress = false; + _integrationVersionsOK = false; + Zotero.Integration.activate(); + Components.classes["@mozilla.org/embedcomp/prompt-service;1"] + .getService(Components.interfaces.nsIPromptService) + .alert(null, Zotero.getString("integration.error.title"), + Zotero.getString("integration.error.incompatibleVersion2", [Zotero.version, + addon.name, INTEGRATION_MIN_VERSION])); + throw e; + } + } + _integrationVersionsOK = true; + _callIntegration(agent, command, docId); + } + if(_inProgress) { Zotero.Integration.activate(); Zotero.debug("Integration: Request already in progress; not executing "+agent+" "+command); @@ -181,6 +209,25 @@ Zotero.Integration = new function() { } _inProgress = true; + // Check integration component versions + if(!_integrationVersionsOK) { + if(Zotero.isFx4) { + Components.utils.import("resource://gre/modules/AddonManager.jsm"); + AddonManager.getAddonsByIDs(INTEGRATION_PLUGINS, _checkAddons); + } else { + var extMan = Components.classes['@mozilla.org/extensions/manager;1']. + getService(Components.interfaces.nsIExtensionManager); + _checkAddons([extMan.getItemForID(id) for each(id in INTEGRATION_PLUGINS)]); + } + } else { + _callIntegration(agent, command, docId); + } + } + + /** + * Calls the Integration applicatoon + */ + function _callIntegration(agent, command, docId) { // Try to load the appropriate Zotero component; otherwise display an error using the alert // service try { @@ -704,7 +751,7 @@ Zotero.Integration.Document.prototype._updateDocument = function(forceCitations, bibliographyText = bib[0].bibstart+bib[1].join("\\\r\n")+"\\\r\n"+bib[0].bibend; // if bibliography style not set, set it - if(!this._session.data.bibliographyStyleHasBeenSet) { + if(!this._session.data.bibliographyStyleHasBeenSet && this._doc.hasProperty("setBibliographyStyle")) { var bibStyle = Zotero.Cite.getBibliographyFormatParameters(bib); // set bibliography style @@ -736,6 +783,8 @@ Zotero.Integration.Document.prototype._updateDocument = function(forceCitations, for(var i=(this._removeCodeFields.length-1); i>=0; i--) { this._fields[this._removeCodeFields[i]].removeCode(); } + + Zotero.debug(this._session.citationsByIndex.toSource()); } /** diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index ed65c2924..2476b536e 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -567,6 +567,7 @@ integration.emptyCitationWarning.title = Blank Citation integration.emptyCitationWarning.body = The citation you have specified would be empty in the currently selected style. Are you sure you want to add it? integration.error.incompatibleVersion = This version of the Zotero word processor plugin ($INTEGRATION_VERSION) is incompatible with the currently installed version of the Zotero Firefox extension (%1$S). Please ensure you are using the latest versions of both components. +integration.error.incompatibleVersion2 = Zotero %1$S requires %2$S %3$S or later. Please download the latest version of %2$S from zotero.org. integration.error.title = Zotero Integration Error integration.error.notInstalled = Firefox could not load the component required to communicate with your word processor. Please ensure that the appropriate Firefox extension is installed and try again. integration.error.generic = Zotero experienced an error updating your document.