From e67db436c63482df38d7cff0c226f04f2d0fe487 Mon Sep 17 00:00:00 2001 From: Dan Stillman <dstillman@zotero.org> Date: Tue, 12 Jun 2018 06:15:45 -0400 Subject: [PATCH] Mendeley import: Add link to support page on encrypted DB Also localize the name of the collection created during import --- chrome/content/zotero/fileInterface.js | 28 ++++++------- chrome/content/zotero/import/importWizard.js | 39 ++++++++++++++++--- chrome/content/zotero/import/importWizard.xul | 2 + chrome/locale/en-US/zotero/zotero.properties | 1 + chrome/skin/default/zotero/importWizard.css | 6 ++- 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 9530d63a77..2d4d9f2e22 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -330,27 +330,27 @@ var Zotero_File_Interface = new function() { var translation; // Check if the file is an SQLite database var sample = yield Zotero.File.getSample(file.path); - if (Zotero.MIME.sniffForMIMEType(sample) == 'application/x-sqlite3' - // Blacklist the current Zotero database, which would cause a hang - && file.path != Zotero.DataDirectory.getDatabase()) { + if (file.path == Zotero.DataDirectory.getDatabase()) { + // Blacklist the current Zotero database, which would cause a hang + } + else if (Zotero.MIME.sniffForMIMEType(sample) == 'application/x-sqlite3') { // Mendeley import doesn't use the real translation architecture, but we create a // translation object with the same interface translation = yield _getMendeleyTranslation(); translation.createNewCollection = createNewCollection; - defaultNewCollectionPrefix = "Mendeley Import"; + defaultNewCollectionPrefix = Zotero.getString( + 'fileInterface.appImportCollection', 'Mendeley' + ); } - else { - // TEMP - if (file.path.endsWith('.sqlite')) { - let codes = []; - for (let i = 0; i < sample.length; i++) { - codes.push(sample.charCodeAt(i)); - } - Zotero.debug(codes.join(' ')); - } - translation = new Zotero.Translate.Import(); + else if (file.path.endsWith('@www.mendeley.com.sqlite') + || file.path.endsWith('online.sqlite')) { + // Keep in sync with importWizard.js + throw new Error('Encrypted Mendeley database'); } + if (!translation) { + translation = new Zotero.Translate.Import(); + } translation.setLocation(file); return _finishImport({ translation, diff --git a/chrome/content/zotero/import/importWizard.js b/chrome/content/zotero/import/importWizard.js index 4e6fca748e..ccc86de34e 100644 --- a/chrome/content/zotero/import/importWizard.js +++ b/chrome/content/zotero/import/importWizard.js @@ -217,11 +217,23 @@ var Zotero_Import_Wizard = { ); } catch (e) { - this._onDone( - Zotero.getString('general.error'), - Zotero.getString('fileInterface.importError'), - true - ); + if (e.message == 'Encrypted Mendeley database') { + let url = 'https://www.zotero.org/support/kb/mendeley_import'; + this._onDone( + Zotero.getString('general.error'), + // TODO: Localize + `The selected Mendeley database cannot be read, likely because it is encrypted. ` + + `See <a href="${url}" class="text-link">How do I import a Mendeley library ` + + `into Zotero?</a> for more information.` + ); + } + else { + this._onDone( + Zotero.getString('general.error'), + Zotero.getString('fileInterface.importError'), + true + ); + } throw e; } }, @@ -289,7 +301,22 @@ var Zotero_Import_Wizard = { _onDone: function (label, description, showReportErrorButton) { var wizard = this._wizard; wizard.getPageById('page-done').setAttribute('label', label); - document.getElementById('result-description').textContent = description; + + var xulElem = document.getElementById('result-description'); + var htmlElem = document.getElementById('result-description-html'); + + if (description.includes('href')) { + htmlElem.innerHTML = description; + Zotero.Utilities.Internal.updateHTMLInXUL(htmlElem); + xulElem.hidden = true; + htmlElem.setAttribute('display', 'block'); + } + else { + xulElem.textContent = description; + xulElem.hidden = false; + htmlElem.setAttribute('display', 'none'); + } + document.getElementById('result-description') if (showReportErrorButton) { let button = document.getElementById('result-report-error'); diff --git a/chrome/content/zotero/import/importWizard.xul b/chrome/content/zotero/import/importWizard.xul index 2e6115a654..c4e6240a28 100644 --- a/chrome/content/zotero/import/importWizard.xul +++ b/chrome/content/zotero/import/importWizard.xul @@ -7,6 +7,7 @@ <wizard id="import-wizard" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" + xmlns:html="http://www.w3.org/1999/xhtml" title="&zotero.import;" onload="Zotero_Import_Wizard.init()"> @@ -64,6 +65,7 @@ <wizardpage pageid="page-done"> <description id="result-description"/> + <html:div id="result-description-html"/> <hbox> <button id="result-report-error" oncommand="Zotero_Import_Wizard.reportError()" diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties index 57656b5557..5b6b1a3cac 100644 --- a/chrome/locale/en-US/zotero/zotero.properties +++ b/chrome/locale/en-US/zotero/zotero.properties @@ -695,6 +695,7 @@ fileInterface.exportedItems = Exported Items fileInterface.imported = Imported fileInterface.unsupportedFormat = The selected file is not in a supported format. fileInterface.appDatabase = %S Database +fileInterface.appImportCollection = %S Import fileInterface.viewSupportedFormats = View Supported Formats… fileInterface.untitledBibliography = Untitled Bibliography fileInterface.bibliographyHTMLTitle = Bibliography diff --git a/chrome/skin/default/zotero/importWizard.css b/chrome/skin/default/zotero/importWizard.css index 78abdb3fc5..ecc432fd7b 100644 --- a/chrome/skin/default/zotero/importWizard.css +++ b/chrome/skin/default/zotero/importWizard.css @@ -33,10 +33,14 @@ wizard[currentpageid="page-file-list"] .wizard-header { margin-bottom: 6px; } -listbox, #result-description { +listbox, #result-description, #result-description-html { font-size: 13px; } +#result-description-html a { + text-decoration: underline; +} + button, checkbox { font-size: 13px; }