diff --git a/ChangeLog b/ChangeLog index c3a22b94..8e21b00c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,292 +1,293 @@ ChangeLog Diff 0.10 to 0.11 - Retrieving favicons by evaluation online search's webpage instead of hard-coding favicon URLs Diff 0.9.2 to 0.10 - New online search: Semantic Scholar +- Refactoring NSA ADS to use official API - Use Qt's own QOAuth1 class instead of external library QOAuth - Providing .gitlab-ci.yml to enable continuous integration at GitLab (see https://gitlab.com/tfischer/kbibtex-ci/pipelines) - Greatly refactoring and modernizing CMakeLists.txt files, generation of camel-case headers, private/public linking to libraries, ... - Tabs in the entry editor can show short messages to use, e.g. in which tab DOIs or URLs are to be entered - Updating BibSearch code: cover page improved, preparing code for translations, adding progress bar - Refactoring most regular 'enum's to become 'enum class'es - Preferences class greatly refactored: Based on JSON description, a Python script will generate a C++ class/header pair providing all necessary functions and enums - Cleaning header includes and include guards - Preferring Qt classes over KDE counterparts, e.g. KLineEdit -> QLineEdit or KComboBox -> QComboBox - Migrating many old-style casts like '(int)' to new-style casts like 'static_cast<..>(..)' - Fixing missing tag in XML export - Fixing UI issues with ColorLabelWidget - Preferring QSignalBlocker over manually temporarily disconnecting/disabling signals - Refactoring QSignalMapper into many small lambda-based 'connect's - Refactoring small slot functions into lambda functions - Using KRatingPainter instead of home-made StarRating's paint function - Various improvements and refactoring when (PDF) files get associated with an entry - Having ICU as an optional dependency only, provide internal, static translation from Basic Multilingual Plane (BMP) characters to ASCII-only representations - Adding and extending numerous automated tests - Code modernizations such as using QFontMetrics' 'horizontalAdvance(..)' instead of 'width(..)' - Using QUrl's 'isValid()' instead of 'isEmpty()' - Cleaner code, e.g. using std::numeric_limits::max() instead of magic constant 0x00ffffff - QDebug output uses categories consistently - Across classes, moving code into private subclasses to minimize public interface - Updating translations (contributions by various authors) - Numerous other fixes, clean-ups, refactoring, ... Diff 0.9.1 to 0.9.2 - Updating favicon URLs - KDE Bug 414375, 414385: Fixing potential crash due to defining TRANSLATION_DOMAIN - KDE Bug 414195: Deselecting all fields on BibTeX Viewer hides the field sorting header - KDE Bug 417164: File URLs passed by command line preceed over LRU Diff 0.9 to 0.9.1 - Fixing GUI issues in preferences/settings - Fixing id extraction during duplicate search - Various minor fixes Diff 0.8.2 to 0.9 - Can be compiled under Windows via Craft - Integrating 'BibSearch', a mobile variant of KBibTeX using QML (Sailfish OS only as of now) - Refactoring of id suggestion editor - Making building Zotero support compile-time optional - Internal refactoring of singleton variables and configuration settings - Adding considerable number of QtText-based tests - Migrating from QRegExp to QRegularExpression class - Using Kate's text editor component for BibTeX sources - Validating user-entered BibTeX sources while typing - More verbose diagnostics while loading BibTeX or RIS data - Various bugfixes in Encoder and BibTeX import classes thanks to improved automated tests - Various small improvements for better robustness, performance, and memory efficiency - KDE Bug 392137: Make entry type (and more fields) available in entry id suggestion setup - KDE Bug 396597: BibLaTeX uses "file" instead of "localfile" - KDE Bugs 405504/406692: Correct handling of ligatures like "st" - Fixing resource leakage as identified by Coverity Scan: CID 325572, 325573 - Integrating commits by Alexander Dunlap, Antonio Rojas, Erik Quaeghebeur, Frederik Schwarzer, Pino Toscano, and Yuri Chornoivan Diff 0.8.1 to 0.8.2 - KDE Bug 388892: Formatting error when saving file ( switching " and } ) - KDE Bug 394659: Crash after compilation - KDE Bug 396343: When saving the file, I am always warned that file has changed in disk - KDE Bug 396598: Bibliography system options contains duplicates - KDE Bug 397027: ScienceDirect search broken - KDE Bug 397604: Untranslated strings from bibtexfields.cpp and bibtexentries.cpp - KDE Bug 398136: KBibTeX crashes when editing element - KDE Bug 401470: Don't remove leading whitespace in macros - Using official APIs for IEEE Xplore and ScienceDirect - Fixing resource leakage as identified by Coverity Scan: CID 287670, 287669 - Fixing issues as identified by clazy - Migrating from HTTP to HTTPS protocol in various places - In encoder classes, migrating away from raw char and char* to Qt classes - Various smaller fixes Diff 0.8 to 0.8.1 - Fixing incorrect version number computation Diff 0.7 to 0.8 Porting from Qt4 to Qt5, from KDE4 (kdelibs) to KDE Frameworks 5, as well as updating various dependencies in the process (e.g. Qt5-based poppler) - Removing old scripts and configuration files - Updating/adding translations - Removing dependency on Qxt as well as sources in src/3rdparty/libqxt - Refactoring various files' location - Various fundamental classes have only optional dependency on KDE Frameworks 5 (default for KDE-based builds, but allows using those classes in Qt5-only setups) - Various modernizations of C++ code towards C++11, including deprecation of SIGNAL/SLOT - Moving bibliography files that previously resided in testset/ into their own Git repository (kbibtex-testset) - Removing ISBNdb as it is no longer a free service - KDE Bug 393032: Updating list of journal abbreviations - KDE Bug 393224: LyX pipe detection (issues with Kile 3 fixed) - KDE Bug 391198: Preview image/vnd.djvu+multipage files - KDE Bug 389306: Removal of libQxt - KDE Bug 387638: Locating correct QtOAuth library fixed - KDE Bug 388688: Screenshots for appdata updated - KDE Bug 386226: Character '~' not recognized in localfile entry - KDE Bug 352517: Invalid report, but more verbose output will be logged - KDE Bug 384741: Wrong ID Reported in Duplicate Dialog - KDE Bug 381119: Do not refer to defunct Gna! anymore (note: Gna! infrastructure shut down before all materials (postings) could be retrieved) - KDE Bug 378497: Fixing crash when closing settings dialog - KDE Bug 368732: More options for ID generation: volume number, first page - Numerous small fixes and changes, run 'git diff v0.6.2..v0.7' for details Contributing authors include: Allen Winter, Andreas Sturmlechner, Andrius Štikonas, Antonio Rojas, Bastien Roucaries, Burkhard Lück, Christoph Feck, Frederik Schwarzer, Joao Carreira, Juergen Spitzmueller, Luigi Toscano, Pino Toscano, Raymond Wooninck, Thomas Fischer, and Yuri Chornoivan Diff 0.6.2 to 0.7 - Dependency on Qt WebKit can be disabled at compile time - New dependency on ICU, used to transliterate text to plain ASCII - Generally improved code quality as detected by code checkers such as Clazy or Coverity - New online search: bioRxiv - Various minor fixes - Search in Zotero is rate limited to avoid overloading server - Using KWallet to store Zotero credentials - Adding basic DBUS support to, for example, open files or paste text Diff 0.6.1 to 0.6.2 - KDE Bug 377401: https://bugs.kde.org/show_bug.cgi?id=377401 KBibTeX fails to load zotero bibliography Diff 0.6 to 0.6.1 - KDE Bug 351455: https://bugs.kde.org/show_bug.cgi?id=351455 Removing soversion from KBibTeX Part - KDE Bug 353898: https://bugs.kde.org/show_bug.cgi?id=353898 Fixing build issues on ARM architecture - KDE Bug 354785: https://bugs.kde.org/show_bug.cgi?id=354785 Using QTextDocument/QTextEdit instead of WebKit/WebEngine: more lightweight and supported on all platforms - Correcting choke on PubMed searches to 10 seconds - Fixing search issues for ACM, Google Scholar, JSTOR, and ScienceDirect - Setting foreground color of colored rows to either black or white for better readability - Disabling OCLC WorldCat (request for support denied by this organization) - Generally improved code quality as detected by code checkers such as Clazy or Coverity - Fixing handling of URLs and their protocols for local files - Fixing setting default id suggestion - Adding 'Keywords' field to .desktop file - Removing file that was licensed under CC BY-NC, but never got installed - Improved Unicode support - Better handling quotation marks and protective curly brackets around titles - Updating translations Diff 0.5.2 to 0.6 - Allowing "unity builds", i.e. merging source code files for faster compilation - Enabling BibUtils support to import/export exotic file formats - Entries can be rated with stars - Adding entry type for Master's thesis - Setting entry identifiers automatically if configured by user - Files (e.g. PDF) can be 'associated' with an entry, including moving/copying/renaming the file to match the bibliography's location and the entry's id - In the element editor, unused tabs are no longer just disabled, but hidden instead - Automatic column-resizing improved - Bibliographies can be imported from Zotero - Adding user interface translations to various languages - New online search engines: CERN Document Server, DOI, IDEAS (RePEc), MR Lookup; fixes to existing search engines - New dockets for file settings, file statistics, and browsing Zotero bibliographies - Value selected in the value list can be added or removed from selected entries - Enhancing the Id Suggestion system - Various fixes as suggested by KDE's code analysis tool Krazy - Numerous small fixes and changes, run 'git diff v0.5.2..v0.6' for details Diff 0.5.1 to 0.5.2 - Migrating to KDE's Git infrastructure - Gna Bug 22418: http://gna.org/bugs/?22418: Relative paths fail to get resolved - KDE Bug 339086: https://bugs.kde.org/show_bug.cgi?id=339086 Fixing ScienceDirect search - KDE Bug 343855: https://bugs.kde.org/show_bug.cgi?id=343855 'Copy Reference' setting in GUI correctly stored - KDE Bug 344495: https://bugs.kde.org/show_bug.cgi?id=344495 Uninitialized variable causes crash - KDE Bug 344497: https://bugs.kde.org/show_bug.cgi?id=344497 Message next to Import button in Search Results - Various minor changes and backports from 0.6.x Run git log v0.5.1..v0.5.2 for a more detailed change log Diff 0.5 to 0.5.1 - KDE Bug 329724: https://bugs.kde.org/show_bug.cgi?id=329724 Fixing sorting issue in main list - KDE Bug 329750: https://bugs.kde.org/show_bug.cgi?id=329750 KBibTeX will set itself as default bibliography editor in KDE - KDE Bug 330700: https://bugs.kde.org/show_bug.cgi?id=330700 Crash when finding PDFs - KDE Bug 332043: https://bugs.kde.org/show_bug.cgi?id=332043 Fixing crash in id suggestion editor - Gentoo Bug 498932: https://bugs.gentoo.org/show_bug.cgi?id=498932 Fixing compilation issue - Gna Bug 21581: http://gna.org/bugs/?21581 Restoring session state (1) - Gna Bug 21545: http://gna.org/bugs/?21545 Restoring session state (2) - Debian Bug 689310: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=689310 Correctly parsing command line arguments if relative paths are given - Various minor clean-ups and improvements Run git log v0.5..v0.5.1 for a more detailed change log Diff 0.4.1 to 0.5 - Initial support for BibLaTeX - Id Suggestion editor like available in old KDE3 version - "Find PDF" function to locate PDF files through web search engines - New online database searches: MathSciNet, Ingenta Connect, Inspire Hep, SAO/NASA ADS, ISBN DB, JStor - Improved memory management - Numerous bug fixes and improvements Diff 0.4 to 0.4.1 - Web searches: Improved support for user-triggered cancelling - SpringerLink search: GUI changes, using api.springer.com for search - PubMed: Limiting search requests per time - ACM Portal: Retrieving "month", fixing HTTP header - JSTOR: fixing HTTP header - Google Scholar: Updates to compensate for changes in Google's web layout; handling redirects - Science Direct: Updates to compensate for changes in Science Direct's web layout; handling redirects - arXiv: Trying to extract bibliographic information from journal strings - BibSonomy: Specifying number of hits to find - Minor changes in IEEExplore search; non-functional due to Qt bug? - Web search uses KDE's proxy settings - Using KDE subsystem to open external files (e.g. PDF files) - Adding preview for images (in addition to PDF or HTML files); handling references to arXiv - Squeezing long file names in user interface - Handling quit actions more gracefully - Improving interface to external programs such as pdflatex - More robust XSL transformations - BibTeX import: guessing encoding information left by JabRef, more informative debug output, improved handling of multiple fields with same name - Reference preview: supporting dark color schemes - Fixing sorting in value list - Fixes in setting color tag to entries - Fixes in name formatting - Keeping user interface read-only for read-only use cases - Numerous bug fixes, closing memory leaks, speed improvements - Fixes in duplicate merging code: remove fields user doesn't want to keep Diff 0.3 to 0.4 - Support for Windows (compiles out of the box) - Configuration file system refactored - Adding more online search engines: SpringerLink, PubMed, ACM Digital Library, JSTOR, IEEE Xplorer, Science Direct - Improving all other online search engines: Google Scholar, arXiv, BibSonomy - "List of Values" refactored, allows to search for items - Introducing preferences dialog to manage various settings - Improved support for drag'n'drop throughout the program - Improving tagging elements with color - Introducing global keyword list to select from - Editing widgets get "history" to select from - Widget for cross references allows to select from existing elements - Introducing duplicate finding and merging code and user interface - Improvements in usability of filter line edit - File view can resize and order columns, settings get stored - Improving file importer and exporter filters - BibTeX references can be sent to LyX via a pipe - Numerous bug fixes diff --git a/src/networking/onlinesearch/onlinesearchsoanasaads.cpp b/src/networking/onlinesearch/onlinesearchsoanasaads.cpp index 289ba471..fde0858c 100644 --- a/src/networking/onlinesearch/onlinesearchsoanasaads.cpp +++ b/src/networking/onlinesearch/onlinesearchsoanasaads.cpp @@ -1,91 +1,239 @@ /*************************************************************************** - * Copyright (C) 2004-2019 by Thomas Fischer * + * Copyright (C) 2004-2020 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #include "onlinesearchsoanasaads.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_KF5 #include +#endif // HAVE_KF5 -OnlineSearchSOANASAADS::OnlineSearchSOANASAADS(QObject *parent) - : OnlineSearchSimpleBibTeXDownload(parent) +#include +#include "internalnetworkaccessmanager.h" +#include "logging_networking.h" + +class OnlineSearchSOANASAADS::Private { - /// nothing -} +private: + static const QUrl apiSearchUrl; + +public: + static const QUrl apiExportUrl; + static const QByteArray apiKey; + + QUrl buildSearchUrl(const QMap &query, int numResults) + { + QUrl url(apiSearchUrl); + QUrlQuery urlQuery; + + QString q; + + /// Free text + const QStringList freeTextFragments = OnlineSearchAbstract::splitRespectingQuotationMarks(query[QueryKey::FreeText]); + if (!freeTextFragments.isEmpty()) + q.append(QStringLiteral("\"") + freeTextFragments.join(QStringLiteral("\" \"")) + QStringLiteral("\"")); + + if (!q.isEmpty()) q.append(' '); + + /// Title + const QStringList title = OnlineSearchAbstract::splitRespectingQuotationMarks(query[QueryKey::Title]); + if (!title.isEmpty()) { + q.append(QStringLiteral("title:\"") + title.join(QStringLiteral("\" title:\"")) + QStringLiteral("\"")); + } + + if (!q.isEmpty()) q.append(' '); + + /// Authors + const QStringList authors = OnlineSearchAbstract::splitRespectingQuotationMarks(query[QueryKey::Author]); + if (!authors.isEmpty()) { + q.append(QStringLiteral("author:\"") + authors.join(QStringLiteral("\" author:\"")) + QStringLiteral("\"")); + } + + if (!q.isEmpty()) q.append(' '); + + QString year = query[QueryKey::Year]; + if (!year.isEmpty()) { + static const QRegularExpression yearRegExp("\\b(18|19|20)[0-9]{2}\\b"); + const QRegularExpressionMatch yearRegExpMatch = yearRegExp.match(year); + if (yearRegExpMatch.hasMatch()) { + year = yearRegExpMatch.captured(0); + q.append(QStringLiteral(" year:") + year); + } + } + + urlQuery.addQueryItem(QStringLiteral("fl"), QStringLiteral("bibcode")); + urlQuery.addQueryItem(QStringLiteral("q"), q); + urlQuery.addQueryItem(QStringLiteral("rows"), QString::number(numResults)); + + url.setQuery(urlQuery); + return url; + } +}; -QString OnlineSearchSOANASAADS::label() const +const QUrl OnlineSearchSOANASAADS::Private::apiSearchUrl(QStringLiteral("https://api.adsabs.harvard.edu/v1/search/query")); +const QUrl OnlineSearchSOANASAADS::Private::apiExportUrl(QStringLiteral("https://api.adsabs.harvard.edu/v1/export/bibtexabs")); +const QByteArray OnlineSearchSOANASAADS::Private::apiKey(InternalNetworkAccessManager::reverseObfuscate("\xa3\xe4\xf4\x9b\xe9\xd8\xdb\xb3\x74\x3a\x28\x61\x1d\x51\x35\x6d\x7b\x48\xd0\x8a\xe4\xd7\x82\xfa\x1d\x4e\x33\x76\xca\x90\x65\x52\xd\x5e\x73\x1b\x94\xf7\x79\x49\xdf\xa6\xb0\xe4\x9c\xc6\x8a\xbc\x6e\x24\x56\x5\xa2\xd2\xaf\xf7\xc4\xf4\x8\x5a\x62\x54\x60\x21\x92\xf7\xc6\xa7\xe6\xaf\x68\x5b\x8c\xcb\xdd\xb1\x5c\x2a\xd\x5c").toLatin1()); + +OnlineSearchSOANASAADS::OnlineSearchSOANASAADS(QObject *parent) + : OnlineSearchAbstract(parent), d(new Private) { - return i18n("SAO/NASA Astrophysics Data System (ADS)"); + /// nothing } -QUrl OnlineSearchSOANASAADS::homepage() const +OnlineSearchSOANASAADS::~OnlineSearchSOANASAADS() { - return QUrl(QStringLiteral("http://adswww.harvard.edu/")); + delete d; } -QUrl OnlineSearchSOANASAADS::buildQueryUrl(const QMap &query, int numResults) +void OnlineSearchSOANASAADS::startSearch(const QMap &query, int numResults) { - static const QString globalSearch = QStringLiteral("\"%1\""); - static const QString rangeSearch = QStringLiteral("%1:\"%2\""); - - // TODO - /// http://adsabs.harvard.edu/cgi-bin/basic_connect?qsearch=Hansen&version=1&data_type=BIBTEXPLUS&type=FILE&sort=NDATE&nr_to_return=5 + emit progress(curStep = 0, numSteps = 2); - const QStringList freeTextWords = splitRespectingQuotationMarks(query[QueryKey::FreeText]); - const QStringList yearWords = splitRespectingQuotationMarks(query[QueryKey::Year]); - const QStringList titleWords = splitRespectingQuotationMarks(query[QueryKey::Title]); - const QStringList authorWords = splitRespectingQuotationMarks(query[QueryKey::Author]); + QUrl url = d->buildSearchUrl(query, numResults); + QNetworkRequest request(url); + request.setRawHeader(QByteArray("Authorization"), QByteArray("Bearer ") + Private::apiKey); - /// append search terms - QStringList queryFragments; - queryFragments.reserve(freeTextWords.size() + yearWords.size() + titleWords.size() + authorWords.size()); + QNetworkReply *reply = InternalNetworkAccessManager::instance().get(request); + InternalNetworkAccessManager::instance().setNetworkReplyTimeout(reply); + connect(reply, &QNetworkReply::finished, this, &OnlineSearchSOANASAADS::doneFetchingSearchJSON); - /// add words from "free text" field - for (const QString &word : freeTextWords) - queryFragments.append(globalSearch.arg(word)); - - /// add words from "year" field - for (const QString &word : yearWords) - queryFragments.append(word); ///< no quotation marks around years + refreshBusyProperty(); +} - /// add words from "title" field - for (const QString &word : titleWords) - queryFragments.append(rangeSearch.arg(QStringLiteral("intitle"), word)); +QString OnlineSearchSOANASAADS::label() const +{ + return i18n("NASA Astrophysics Data System (ADS)"); +} - /// add words from "author" field - for (const QString &word : authorWords) - queryFragments.append(rangeSearch.arg(QStringLiteral("author"), word)); +QUrl OnlineSearchSOANASAADS::homepage() const +{ + return QUrl(QStringLiteral("https://ui.adsabs.harvard.edu/")); +} - /// Build URL - QString urlText = QStringLiteral("http://adsabs.harvard.edu/cgi-bin/basic_connect?version=1&data_type=BIBTEXPLUS&type=FILE&sort=NDATE&qsearch="); - urlText.append(queryFragments.join(QStringLiteral("+")).replace(QLatin1Char('"'), QStringLiteral("%22"))); - /// set number of expected results - urlText.append(QString(QStringLiteral("&nr_to_return=%1")).arg(numResults)); +void OnlineSearchSOANASAADS::doneFetchingSearchJSON() +{ + emit progress(++curStep, numSteps); + + QNetworkReply *reply = static_cast(sender()); + + if (handleErrors(reply)) { + const QByteArray data = reply->readAll(); + QJsonParseError parseError; + const QJsonDocument document = QJsonDocument::fromJson(data, &parseError); + if (parseError.error == QJsonParseError::NoError) { + if (document.isObject()) { + const QJsonValue responseValue = document.object().value(QStringLiteral("response")); + if (responseValue.isObject()) { + const QJsonValue docsValue = responseValue.toObject().value(QStringLiteral("docs")); + if (docsValue.isArray()) { + const QJsonArray docsArray = docsValue.toArray(); + QStringList bibcodeList; + for (const QJsonValue &itemValue : docsArray) { + if (itemValue.isObject()) { + const QJsonValue bibcodeValue = itemValue.toObject().value(QString("bibcode")); + if (bibcodeValue.isString()) { + bibcodeList.append(bibcodeValue.toString()); + } + } else { + qCDebug(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: No 'bibcode' found"; + } + } + + if (bibcodeList.isEmpty()) { + qCInfo(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: No bibcode identifiers for query found"; + stopSearch(resultNoError); + } else { + const QString exportJson = QStringLiteral("{\"bibcode\":[\"") + bibcodeList.join(QStringLiteral("\",\"")) + QStringLiteral("\"]}"); + QNetworkRequest request(Private::apiExportUrl); + request.setRawHeader(QByteArray("Authorization"), QByteArray("Bearer ") + Private::apiKey); + request.setRawHeader(QByteArray("Content-Type"), QByteArray("application/json")); + QNetworkReply *newReply = InternalNetworkAccessManager::instance().post(request, exportJson.toUtf8()); + InternalNetworkAccessManager::instance().setNetworkReplyTimeout(newReply); + connect(newReply, &QNetworkReply::finished, this, &OnlineSearchSOANASAADS::doneFetchingExportBibTeX); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: No 'docs' found"; + stopSearch(resultNoError); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: No 'response' found"; + stopSearch(resultNoError); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: Document is not an object"; + stopSearch(resultUnspecifiedError); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: " << parseError.errorString(); + stopSearch(resultUnspecifiedError); + } + } - return QUrl(urlText); + refreshBusyProperty(); } -QString OnlineSearchSOANASAADS::processRawDownload(const QString &download) { - /// Skip HTML header and some other non-BibTeX content - const int p1 = download.indexOf(QStringLiteral("abstracts, starting")); - if (p1 > 1) { - const int p2 = download.indexOf(QStringLiteral("\n"), p1); - if (p2 > p1) - return download.mid(p2 + 1); +void OnlineSearchSOANASAADS::doneFetchingExportBibTeX() +{ + emit progress(++curStep, numSteps); + + QNetworkReply *reply = static_cast(sender()); + + if (handleErrors(reply)) { + const QByteArray data = reply->readAll(); + QJsonParseError parseError; + const QJsonDocument document = QJsonDocument::fromJson(data, &parseError); + if (parseError.error == QJsonParseError::NoError) { + if (document.isObject()) { + const QJsonValue exportValue = document.object().value(QStringLiteral("export")); + if (exportValue.isString()) { + FileImporterBibTeX importer(this); + File *bibtexFile = importer.fromString(exportValue.toString()); + + if (bibtexFile != nullptr) { + for (const auto &element : const_cast(*bibtexFile)) { + QSharedPointer entry = element.dynamicCast(); + if (!publishEntry(entry)) + qCWarning(LOG_KBIBTEX_NETWORKING) << "Failed to publish entry"; + } + delete bibtexFile; + } + stopSearch(resultNoError); + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: No 'export' found"; + stopSearch(resultUnspecifiedError); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: Document is not an object"; + stopSearch(resultUnspecifiedError); + } + } else { + qCWarning(LOG_KBIBTEX_NETWORKING) << "Problem with JSON data from Astrophysics Data System: " << parseError.errorString(); + stopSearch(resultUnspecifiedError); + } } - /// Skipping header failed, return input text as it was - return download; + refreshBusyProperty(); } diff --git a/src/networking/onlinesearch/onlinesearchsoanasaads.h b/src/networking/onlinesearch/onlinesearchsoanasaads.h index 766a72c5..5890bcde 100644 --- a/src/networking/onlinesearch/onlinesearchsoanasaads.h +++ b/src/networking/onlinesearch/onlinesearchsoanasaads.h @@ -1,45 +1,51 @@ /*************************************************************************** - * Copyright (C) 2004-2019 by Thomas Fischer * + * Copyright (C) 2004-2020 by Thomas Fischer * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, see . * ***************************************************************************/ #ifndef KBIBTEX_NETWORKING_ONLINESEARCHSOANASAADS_H #define KBIBTEX_NETWORKING_ONLINESEARCHSOANASAADS_H -#include +#include #ifdef HAVE_KF5 #include "kbibtexnetworking_export.h" #endif // HAVE_KF5 /** * @author Thomas Fischer */ -class KBIBTEXNETWORKING_EXPORT OnlineSearchSOANASAADS : public OnlineSearchSimpleBibTeXDownload +class KBIBTEXNETWORKING_EXPORT OnlineSearchSOANASAADS : public OnlineSearchAbstract { Q_OBJECT public: explicit OnlineSearchSOANASAADS(QObject *parent); + virtual ~OnlineSearchSOANASAADS() override; + void startSearch(const QMap &query, int numResults) override; QString label() const override; QUrl homepage() const override; -protected: - QUrl buildQueryUrl(const QMap &query, int numResults) override; - QString processRawDownload(const QString &download) override; +private slots: + void doneFetchingSearchJSON(); + void doneFetchingExportBibTeX(); + +private: + class Private; + Private *const d; }; #endif // KBIBTEX_NETWORKING_ONLINESEARCHSOANASAADS_H