diff --git a/src/networking/CMakeLists.txt b/src/networking/CMakeLists.txt index 23aa1c01..a44fee85 100644 --- a/src/networking/CMakeLists.txt +++ b/src/networking/CMakeLists.txt @@ -1,160 +1,157 @@ set( kbibtexnetworking_LIB_SRCS onlinesearch/onlinesearchabstract.cpp onlinesearch/onlinesearchbibsonomy.cpp onlinesearch/onlinesearcharxiv.cpp onlinesearch/onlinesearchsciencedirect.cpp onlinesearch/onlinesearchgooglescholar.cpp onlinesearch/onlinesearchieeexplore.cpp onlinesearch/onlinesearchpubmed.cpp onlinesearch/onlinesearchacmportal.cpp onlinesearch/onlinesearchspringerlink.cpp onlinesearch/onlinesearchjstor.cpp onlinesearch/onlinesearchmathscinet.cpp onlinesearch/onlinesearchmrlookup.cpp onlinesearch/onlinesearchinspirehep.cpp onlinesearch/onlinesearchcernds.cpp onlinesearch/onlinesearchingentaconnect.cpp onlinesearch/onlinesearchsimplebibtexdownload.cpp onlinesearch/onlinesearchgeneral.cpp onlinesearch/onlinesearchsoanasaads.cpp - # onlinesearch/onlinesearchisbndb.cpp # disabled as provider switched to a paid model on 2017-12-26 onlinesearch/onlinesearchideasrepec.cpp onlinesearch/onlinesearchdoi.cpp onlinesearch/onlinesearchbiorxiv.cpp onlinesearch/onlinesearchsemanticscholar.cpp zotero/api.cpp zotero/collectionmodel.cpp zotero/collection.cpp zotero/items.cpp zotero/groups.cpp zotero/oauthwizard.cpp zotero/tags.cpp zotero/tagmodel.cpp associatedfiles.cpp findpdf.cpp internalnetworkaccessmanager.cpp logging_networking.cpp ) if(UNITY_BUILD) enable_unity_build(kbibtexnetworking kbibtexnetworking_LIB_SRCS) endif(UNITY_BUILD) add_library(kbibtexnetworking SHARED ${kbibtexnetworking_LIB_SRCS} ) generate_export_header(kbibtexnetworking) add_library(KBibTeX::Networking ALIAS kbibtexnetworking) set_target_properties(kbibtexnetworking PROPERTIES EXPORT_NAME "kbibtexnetworking" VERSION ${KBIBTEX_RELEASE_VERSION} SOVERSION ${KBIBTEX_SOVERSION} ) target_include_directories(kbibtexnetworking INTERFACE $ ) target_link_libraries(kbibtexnetworking PUBLIC Qt5::Core Qt5::Gui Qt5::Network Qt5::Widgets # TODO refactor code to not expose config interface KF5::ConfigCore KF5::ConfigGui KBibTeX::Data PRIVATE Poppler::Qt5 Qt5::DBus Qt5::NetworkAuth KF5::WidgetsAddons KF5::I18n KF5::KIOCore KF5::KIOFileWidgets KBibTeX::Config KBibTeX::Global KBibTeX::IO ) install( TARGETS kbibtexnetworking EXPORT kbibtexnetworking-targets LIBRARY NAMELINK_SKIP ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) set_target_properties(kbibtexnetworking PROPERTIES EXPORT_NAME "Networking" ) ecm_generate_headers(kbibtexnetworking_HEADERS HEADER_NAMES AssociatedFiles FindPDF InternalNetworkAccessManager onlinesearch/OnlineSearchAbstract onlinesearch/OnlineSearchGeneral onlinesearch/OnlineSearchAcmPortal onlinesearch/OnlineSearchArXiv onlinesearch/OnlineSearchBibsonomy onlinesearch/OnlineSearchBioRxiv onlinesearch/OnlineSearchCERNDS onlinesearch/OnlineSearchDOI onlinesearch/OnlineSearchGoogleScholar onlinesearch/OnlineSearchIDEASRePEc onlinesearch/OnlineSearchIEEEXplore onlinesearch/OnlineSearchIngentaConnect onlinesearch/OnlineSearchInspireHep - onlinesearch/OnlineSearchIsbnDB onlinesearch/OnlineSearchJStor onlinesearch/OnlineSearchMathSciNet onlinesearch/OnlineSearchMRLookup - onlinesearch/OnlineSearchOCLCWorldCat onlinesearch/OnlineSearchPubMed onlinesearch/OnlineSearchScienceDirect onlinesearch/OnlineSearchSemanticScholar onlinesearch/OnlineSearchSimpleBibTeXDownload onlinesearch/OnlineSearchSOANASAADS onlinesearch/OnlineSearchSpringerLink zotero/API zotero/Collection zotero/CollectionModel zotero/Groups zotero/Items zotero/OAuthWizard zotero/TagModel zotero/Tags REQUIRED_HEADERS kbibtexnetworking_HEADERS ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/kbibtexnetworking_export.h ${kbibtexnetworking_HEADERS} DESTINATION ${KDE_INSTALL_INCLUDEDIR}/KBibTeX/networking COMPONENT Devel ) include(CMakePackageConfigHelpers) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/KBibTeXNetworking-configVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY ExactVersion ) configure_package_config_file(${CMAKE_CURRENT_LIST_DIR}/cmake/KBibTeXNetworking-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/KBibTeXNetworking-config.cmake INSTALL_DESTINATION ${KDE_INSTALL_LIBDIR}/cmake/KBibTeX ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/KBibTeXNetworking-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/KBibTeXNetworking-configVersion.cmake DESTINATION ${KDE_INSTALL_LIBDIR}/cmake/KBibTeX ) diff --git a/src/networking/onlinesearch/onlinesearchisbndb.cpp b/src/networking/onlinesearch/onlinesearchisbndb.cpp deleted file mode 100644 index 8ee9c556..00000000 --- a/src/networking/onlinesearch/onlinesearchisbndb.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2017 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 "onlinesearchisbndb.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include "internalnetworkaccessmanager.h" -#include "logging_networking.h" - -class OnlineSearchIsbnDB::OnlineSearchIsbnDBPrivate -{ -private: - static const QString accessKey; - static const QString booksUrl, authorsUrl; - -public: - const XSLTransform xslt; - QUrl queryUrl; - - OnlineSearchIsbnDBPrivate(OnlineSearchIsbnDB *) - : xslt(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QCoreApplication::instance()->applicationName().remove(QStringLiteral("test")) + QStringLiteral("/isbndb2bibtex.xsl"))) - { - /// nothing - } - - QUrl buildBooksUrl(const QMap &query) { - queryUrl = QUrl(booksUrl); - QUrlQuery q(queryUrl); - q.addQueryItem(QStringLiteral("access_key"), accessKey); - q.addQueryItem(QStringLiteral("results"), QStringLiteral("texts,authors")); - - QString index1, value1; - if (query[queryKeyFreeText].isEmpty() && query[queryKeyAuthor].isEmpty() && !query[queryKeyTitle].isEmpty()) { - /// only searching for title - index1 = QStringLiteral("title"); - value1 = query[queryKeyTitle]; - } else { - /// multiple different values given - index1 = QStringLiteral("full"); - value1 = query[queryKeyFreeText] + QLatin1Char(' ') + query[queryKeyAuthor] + QLatin1Char(' ') + query[queryKeyTitle]; - } - q.addQueryItem(QStringLiteral("index1"), index1); - q.addQueryItem(QStringLiteral("value1"), value1); - - queryUrl.setQuery(q); - return queryUrl; - } -}; - -const QString OnlineSearchIsbnDB::OnlineSearchIsbnDBPrivate::accessKey = QStringLiteral("NBTD24WJ"); -const QString OnlineSearchIsbnDB::OnlineSearchIsbnDBPrivate::booksUrl = QStringLiteral("http://isbndb.com/api/books.xml"); -const QString OnlineSearchIsbnDB::OnlineSearchIsbnDBPrivate::authorsUrl = QStringLiteral("http://isbndb.com/api/authors.xml"); - -OnlineSearchIsbnDB::OnlineSearchIsbnDB(QWidget *parent) - : OnlineSearchAbstract(parent), d(new OnlineSearchIsbnDBPrivate(this)) -{ - /// nothing -} - -OnlineSearchIsbnDB::~OnlineSearchIsbnDB() -{ - delete d; -} - -void OnlineSearchIsbnDB::startSearch(const QMap &query, int numResults) -{ - m_hasBeenCanceled = false; - - emit progress(curStep = 0, numSteps = (numResults + 9) / 10); - - QNetworkRequest request(d->buildBooksUrl(query)); - QNetworkReply *reply = InternalNetworkAccessManager::instance().get(request); - InternalNetworkAccessManager::instance().setNetworkReplyTimeout(reply); - connect(reply, &QNetworkReply::finished, this, &OnlineSearchIsbnDB::downloadDone); -} - -QString OnlineSearchIsbnDB::label() const -{ - return i18n("ISBNdb.com"); -} - -QString OnlineSearchIsbnDB::favIconUrl() const -{ - return QStringLiteral("http://isbndb.com/favicon.ico"); -} - -QUrl OnlineSearchIsbnDB::homepage() const -{ - return QUrl(QStringLiteral("http://isbndb.com/")); -} - -void OnlineSearchIsbnDB::downloadDone() -{ - emit progress(++curStep, numSteps); - - QNetworkReply *reply = static_cast(sender()); - - if (handleErrors(reply)) { - /// ensure proper treatment of UTF-8 characters - const QString xmlCode = QString::fromUtf8(reply->readAll().constData()); - - /// use XSL transformation to get BibTeX document from XML result - const QString bibTeXcode = d->xslt.transform(xmlCode).remove(QStringLiteral("")).replace(QStringLiteral("&"), QStringLiteral("&")); - if (bibTeXcode.isEmpty()) { - qCWarning(LOG_KBIBTEX_NETWORKING) << "XSL tranformation failed for data from " << reply->url().toDisplayString(); - stopSearch(resultInvalidArguments); - } else { - FileImporterBibTeX importer(this); - File *bibtexFile = importer.fromString(bibTeXcode); - - bool hasEntries = false; - if (bibtexFile != nullptr) { - for (const auto &element : const_cast(*bibtexFile)) { - QSharedPointer entry = element.dynamicCast(); - hasEntries |= publishEntry(entry); - } - delete bibtexFile; - - if (!hasEntries) { - stopSearch(resultNoError); - } else if (curStep >= numSteps) - stopSearch(resultNoError); - else { - QUrl nextUrl = d->queryUrl; - QUrlQuery query(nextUrl); - query.addQueryItem(QStringLiteral("page_number"), QString::number(curStep /** FIXME? + 1 */)); - nextUrl.setQuery(query); - QNetworkRequest request(nextUrl); - QNetworkReply *nextReply = InternalNetworkAccessManager::instance().get(request); - InternalNetworkAccessManager::instance().setNetworkReplyTimeout(nextReply); - connect(nextReply, &QNetworkReply::finished, this, &OnlineSearchIsbnDB::downloadDone); - return; - } - } else { - qCWarning(LOG_KBIBTEX_NETWORKING) << "No valid BibTeX file results returned on request on" << reply->url().toDisplayString(); - stopSearch(resultUnspecifiedError); - } - } - } -} diff --git a/src/networking/onlinesearch/onlinesearchisbndb.h b/src/networking/onlinesearch/onlinesearchisbndb.h deleted file mode 100644 index b14ea448..00000000 --- a/src/networking/onlinesearch/onlinesearchisbndb.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2019 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_ONLINESEARCH_ISBNDB_H -#define KBIBTEX_ONLINESEARCH_ISBNDB_H - -#include - -#ifdef HAVE_KF5 -#include "kbibtexnetworking_export.h" -#endif // HAVE_KF5 - -/** - * @author Thomas Fischer - */ -class KBIBTEXNETWORKING_EXPORT OnlineSearchIsbnDB : public OnlineSearchAbstract -{ - Q_OBJECT - -public: - explicit OnlineSearchIsbnDB(QWidget *parent); - ~OnlineSearchIsbnDB() override; - - void startSearch(const QMap &query, int numResults) override; - QString label() const override; - QUrl homepage() const override; - -protected: - QString favIconUrl() const override; - -private: - class OnlineSearchIsbnDBPrivate; - OnlineSearchIsbnDBPrivate *d; - -private slots: - void downloadDone(); -}; - -#endif // KBIBTEX_ONLINESEARCH_ISBNDB_H diff --git a/src/networking/onlinesearch/onlinesearchoclcworldcat.cpp b/src/networking/onlinesearch/onlinesearchoclcworldcat.cpp deleted file mode 100644 index 2923afe5..00000000 --- a/src/networking/onlinesearch/onlinesearchoclcworldcat.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2017 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 "onlinesearchoclcworldcat.h" - -#include -#include -#include -#include - -#include - -#include "fileimporterbibtex.h" -#include "xsltransform.h" -#include "internalnetworkaccessmanager.h" -#include "logging_networking.h" - -class OnlineSearchOCLCWorldCat::Private -{ -private: - static const QString APIkey; - - OnlineSearchOCLCWorldCat *p; -public: - static const int countPerStep; - int maxSteps, curStep; - - QUrl baseUrl; - - XSLTransform *xslt; - - Private(OnlineSearchOCLCWorldCat *parent) - : p(parent), maxSteps(0), curStep(0) { - const QString xsltFilename = QStringLiteral("kbibtex/worldcatdc2bibtex.xsl"); - xslt = XSLTransform::createXSLTransform(QStandardPaths::locate(QStandardPaths::GenericDataLocation, xsltFilename)); - if (xslt == NULL) - qCWarning(LOG_KBIBTEX_NETWORKING) << "Could not create XSLT transformation for" << xsltFilename; - } - - ~Private() { - delete xslt; - } - - void setBaseUrl(const QMap &query) { - QStringList queryFragments; - - /// Add words from "free text" field - /// WorldCat's Open Search does not support "free" search, - /// instead, title, keyword, subject etc are searched OR-connected - const QStringList freeTextWords = p->splitRespectingQuotationMarks(query[queryKeyFreeText]); - for (const QString &text : freeTextWords) { - static const QString freeWorldTemplate = QStringLiteral("(+srw.ti+all+\"%1\"+or+srw.kw+all+\"%1\"+or+srw.au+all+\"%1\"+or+srw.bn+all+\"%1\"+or+srw.su+all+\"%1\"+)"); - queryFragments.append(freeWorldTemplate.arg(text)); - } - /// Add words from "title" field - const QStringList titleWords = p->splitRespectingQuotationMarks(query[queryKeyTitle]); - for (const QString &text : titleWords) { - static const QString titleTemplate = QStringLiteral("srw.ti+all+\"%1\""); - queryFragments.append(titleTemplate.arg(text)); - } - /// Add words from "author" field - const QStringList authorWords = p->splitRespectingQuotationMarks(query[queryKeyAuthor]); - for (const QString &text : authorWords) { - static const QString authorTemplate = QStringLiteral("srw.au+all+\"%1\""); - queryFragments.append(authorTemplate.arg(text)); - } - - /// Field year cannot stand alone, therefore if no query fragments - /// have been assembled yet, no valid search will be possible. - /// Invalidate base URL and return in this case. - if (queryFragments.isEmpty()) { - qCWarning(LOG_KBIBTEX_NETWORKING) << "For WorldCat OCLC search to work, either a title or an author has get specified; free text or year only is not sufficient"; - baseUrl.clear(); - return; - } - - /// Add words from "year" field - const QStringList yearWords = p->splitRespectingQuotationMarks(query[queryKeyYear]); - for (const QString &text : yearWords) { - static const QString yearTemplate = QStringLiteral("srw.yr+any+\"%1\""); - queryFragments.append(yearTemplate.arg(text)); - } - - const QString queryString = queryFragments.join(QStringLiteral("+and+")); - baseUrl = QUrl(QString(QStringLiteral("http://www.worldcat.org/webservices/catalog/search/worldcat/sru?query=%1&recordSchema=%3&wskey=%2&maximumRecords=%4")).arg(queryString).arg(OnlineSearchOCLCWorldCat::Private::APIkey).arg(QStringLiteral("info%3Asrw%2Fschema%2F1%2Fdc")).arg(OnlineSearchOCLCWorldCat::Private::countPerStep)); - } -}; - -const int OnlineSearchOCLCWorldCat::Private::countPerStep = 11; /// pseudo-randomly chosen prime number between 10 and 20 -const QString OnlineSearchOCLCWorldCat::Private::APIkey = QStringLiteral("Bt6h4KIHrfbSXEahwUzpFQD6SNjQZfQUG3W2LN9oNEB5tROFGeRiDVntycEEyBe0aH17sH4wrNlnVANH"); - -OnlineSearchOCLCWorldCat::OnlineSearchOCLCWorldCat(QWidget *parent) - : OnlineSearchAbstract(parent), d(new OnlineSearchOCLCWorldCat::Private(this)) { - // TODO -} - -OnlineSearchOCLCWorldCat::~OnlineSearchOCLCWorldCat() { - delete d; -} - -void OnlineSearchOCLCWorldCat::startSearch() { - m_hasBeenCanceled = false; - delayedStoppedSearch(resultNoError); -} - -void OnlineSearchOCLCWorldCat::startSearch(const QMap &query, int numResults) { - if (d->xslt == NULL) { - /// Don't allow searches if xslt is not defined - qCWarning(LOG_KBIBTEX_NETWORKING) << "Cannot allow searching" << label() << "if XSL Transformation not available"; - delayedStoppedSearch(resultUnspecifiedError); - return; - } - - m_hasBeenCanceled = false; - - d->maxSteps = (numResults + OnlineSearchOCLCWorldCat::Private::countPerStep - 1) / OnlineSearchOCLCWorldCat::Private::countPerStep; - d->curStep = 0; - emit progress(d->curStep, d->maxSteps); - - d->setBaseUrl(query); - if (d->baseUrl.isEmpty()) { - /// No base URL set for some reason, no search possible - m_hasBeenCanceled = false; - delayedStoppedSearch(resultInvalidArguments); - return; - } - QUrl startUrl = d->baseUrl; - QNetworkRequest request(startUrl); - QNetworkReply *reply = InternalNetworkAccessManager::self()->get(request); - InternalNetworkAccessManager::self()->setNetworkReplyTimeout(reply); - connect(reply, &QNetworkReply::finished, this, SLOT(downloadDone())); -} - -QString OnlineSearchOCLCWorldCat::label() const { - return i18n("OCLC WorldCat"); -} - -OnlineSearchQueryFormAbstract *OnlineSearchOCLCWorldCat::customWidget(QWidget *) { - return NULL; -} - -QUrl OnlineSearchOCLCWorldCat::homepage() const { - return QUrl(QStringLiteral("http://www.worldcat.org/")); -} - -void OnlineSearchOCLCWorldCat::cancel() { - OnlineSearchAbstract::cancel(); -} - -QString OnlineSearchOCLCWorldCat::favIconUrl() const { - return QStringLiteral("http://www.worldcat.org/favicon.ico"); -} - -void OnlineSearchOCLCWorldCat::downloadDone() { - emit progress(++d->curStep, d->maxSteps); - - QNetworkReply *reply = static_cast(sender()); - - if (handleErrors(reply)) { - /// Ensure proper treatment of UTF-8 characters - const QString atomCode = QString::fromUtf8(reply->readAll().constData()).remove(QStringLiteral("xmlns=\"http://www.w3.org/2005/Atom\"")).remove(QStringLiteral(" xmlns=\"http://www.loc.gov/zing/srw/\"")); // FIXME fix worldcatdc2bibtex.xsl to handle namespace - - /// Use XSL transformation to get BibTeX document from XML result - const QString bibTeXcode = d->xslt->transform(atomCode).remove(QStringLiteral("")); - - FileImporterBibTeX importer; - File *bibtexFile = importer.fromString(bibTeXcode); - - bool hasEntries = false; - if (bibtexFile != NULL) { - for (const auto &element : const_cast(*bibtexFile)) { - QSharedPointer entry = element.dynamicCast(); - hasEntries |= publishEntry(entry); - } - delete bibtexFile; - - if (!hasEntries) { - emit progress(d->maxSteps, d->maxSteps); - stopSearch(resultNoError); - } else if (d->curStep < d->maxSteps) { - QUrl nextUrl = d->baseUrl; - QUrlQuery query(nextUrl); - query.addQueryItem(QStringLiteral("start"), QString::number(d->curStep * - OnlineSearchOCLCWorldCat::Private::countPerStep + 1)); - nextUrl.setQuery(query); - QNetworkRequest request(nextUrl); - QNetworkReply *newReply = InternalNetworkAccessManager::self()->get(request); - InternalNetworkAccessManager::self()->setNetworkReplyTimeout(newReply); - connect(newReply, &QNetworkReply::finished, this, SLOT(downloadDone())); - } else { - emit progress(d->maxSteps, d->maxSteps); - stopSearch(resultNoError); - } - } else { - qCWarning(LOG_KBIBTEX_NETWORKING) << "No valid BibTeX file results returned on request on" << reply->url().toDisplayString(); - stopSearch(resultUnspecifiedError); - } - } else - qCWarning(LOG_KBIBTEX_NETWORKING) << "url was" << reply->url().toDisplayString(); -} diff --git a/src/networking/onlinesearch/onlinesearchoclcworldcat.h b/src/networking/onlinesearch/onlinesearchoclcworldcat.h deleted file mode 100644 index adc0c781..00000000 --- a/src/networking/onlinesearch/onlinesearchoclcworldcat.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2004-2019 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_ONLINESEARCHOCLCWORLDCAT_H -#define KBIBTEX_NETWORKING_ONLINESEARCHOCLCWORLDCAT_H - -#include - -/** - * According to its own description at oclc.org, "OCLC is a worldwide library - * cooperative, providing services and research to improve access to the - * world's information." - * Access to their services is available through the developers' portal at - * https://oclc.org/developer/ - * WorldCat, according to OCLC's description, "connects library users to - * hundreds of millions of electronic resources, including e-books, licensed - * databases, online periodicals and collections of digital items." - * - * @author Thomas Fischer - */ -class KBIBTEXNETWORKING_EXPORT OnlineSearchOCLCWorldCat : public OnlineSearchAbstract -{ - Q_OBJECT - -public: - explicit OnlineSearchOCLCWorldCat(QWidget *parent); - ~OnlineSearchOCLCWorldCat(); - - virtual void startSearch(); - virtual void startSearch(const QMap &query, int numResults); - virtual QString label() const; - virtual OnlineSearchQueryFormAbstract *customWidget(QWidget *parent); - virtual QUrl homepage() const; - -public slots: - void cancel(); - -protected: - virtual QString favIconUrl() const; - -private slots: - void downloadDone(); - -private: - class Private; - Private *const d; -}; - -#endif // KBIBTEX_NETWORKING_ONLINESEARCHOCLCWORLDCAT_H diff --git a/src/test/kbibtextest.cpp b/src/test/kbibtextest.cpp index 9d75460f..0b8775ca 100644 --- a/src/test/kbibtextest.cpp +++ b/src/test/kbibtextest.cpp @@ -1,277 +1,275 @@ /*************************************************************************** * Copyright (C) 2004-2019 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 "kbibtextest.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include #include #include int filenameCounter = 0; static QColor blendColors(const QColor &color1, const QColor &color2, const qreal ratio) { const int r = color1.red() * (1 - ratio) + color2.red() * ratio; const int g = color1.green() * (1 - ratio) + color2.green() * ratio; const int b = color1.blue() * (1 - ratio) + color2.blue() * ratio; return QColor(r, g, b, 255); } class TestWidget : public QWidget { Q_OBJECT private: KBibTeXTest *m_parent; QPushButton *buttonStartTest; QProgressBar *progressBar; QAction *actionStartOnlineSearchTests; public: QListWidget *messageList; TestWidget(KBibTeXTest *parent) : QWidget(parent), m_parent(parent) { QGridLayout *layout = new QGridLayout(this); buttonStartTest = new QPushButton(QIcon::fromTheme(QStringLiteral("application-x-executable")), QStringLiteral("Start Tests"), this); layout->addWidget(buttonStartTest, 0, 0, 1, 1); progressBar = new QProgressBar(this); layout->addWidget(progressBar, 0, 1, 1, 3); progressBar->setVisible(false); messageList = new QListWidget(this); layout->addWidget(messageList, 1, 0, 4, 4); setupMenus(); } void setProgress(int pos, int total) { if (pos < 0 || total < 0) { progressBar->setVisible(false); progressBar->setMaximum(1); progressBar->setValue(0); } else { progressBar->setVisible(true); progressBar->setMaximum(total); progressBar->setValue(pos); } } void setupMenus() { QMenu *menu = new QMenu(buttonStartTest); buttonStartTest->setMenu(menu); /// ** Online Search ** actionStartOnlineSearchTests = new QAction(QStringLiteral("Online Search"), m_parent); connect(actionStartOnlineSearchTests, &QAction::triggered, m_parent, &KBibTeXTest::startOnlineSearchTests); menu->addAction(actionStartOnlineSearchTests); } void setBusy(bool isBusy) { buttonStartTest->setEnabled(!isBusy); actionStartOnlineSearchTests->setEnabled(!isBusy); } }; KBibTeXTest::KBibTeXTest(QWidget *parent) : QDialog(parent), m_running(false), m_isBusy(false) { m_onlineSearchList << new OnlineSearchAcmPortal(this); m_onlineSearchList << new OnlineSearchArXiv(this); m_onlineSearchList << new OnlineSearchBibsonomy(this); m_onlineSearchList << new OnlineSearchCERNDS(this); m_onlineSearchList << new OnlineSearchGoogleScholar(this); m_onlineSearchList << new OnlineSearchIDEASRePEc(this); m_onlineSearchList << new OnlineSearchIEEEXplore(this); m_onlineSearchList << new OnlineSearchIngentaConnect(this); m_onlineSearchList << new OnlineSearchInspireHep(this); - /// m_onlineSearchList << new OnlineSearchIsbnDB(this); /// disabled as provider switched to a paid model on 2017-12-26 m_onlineSearchList << new OnlineSearchJStor(this); m_onlineSearchList << new OnlineSearchMathSciNet(this); m_onlineSearchList << new OnlineSearchMRLookup(this); m_onlineSearchList << new OnlineSearchPubMed(this); m_onlineSearchList << new OnlineSearchScienceDirect(this); m_onlineSearchList << new OnlineSearchSOANASAADS(this); m_onlineSearchList << new OnlineSearchSpringerLink(this); m_onlineSearchList << new OnlineSearchBioRxiv(this); m_onlineSearchList << new OnlineSearchSemanticScholar(this); m_currentOnlineSearch = m_onlineSearchList.constBegin(); setWindowTitle(QStringLiteral("KBibTeX Test Suite")); m_testWidget = new TestWidget(this); const int fontSize = m_testWidget->fontMetrics().width(QLatin1Char('a')); m_testWidget->setMinimumSize(fontSize * 96, fontSize * 48); QBoxLayout *boxLayout = new QVBoxLayout(this); boxLayout->addWidget(m_testWidget); connect(this, &KBibTeXTest::rejected, this, &KBibTeXTest::aboutToQuit); addMessage(QString(QStringLiteral("Compiled for %1")).arg(KAboutData::applicationData().version()), statusInfo); } void KBibTeXTest::addMessage(const QString &message, const MessageStatus messageStatus) { static const QIcon iconINFO = QIcon::fromTheme(QStringLiteral("dialog-information")); static const QIcon iconOK = QIcon::fromTheme(QStringLiteral("dialog-ok-apply")); static const QIcon iconERROR = QIcon::fromTheme(QStringLiteral("dialog-cancel")); static const QIcon iconAUTH = QIcon::fromTheme(QStringLiteral("dialog-cancel")); // FIXME "dialog-cancel" should be overlay on "dialog-password" static const QIcon iconNETWORK = QIcon::fromTheme(QStringLiteral("dialog-cancel")); // FIXME "dialog-cancel" should be overlay on "network-wired" QIcon icon; switch (messageStatus) { case statusInfo: icon = iconINFO; break; case statusOk: icon = iconOK; break; case statusError: icon = iconERROR; break; case statusAuth: icon = iconAUTH; break; case statusNetwork: icon = iconNETWORK; break; } QListWidgetItem *item = icon.isNull() ? new QListWidgetItem(message) : new QListWidgetItem(icon, message); item->setToolTip(item->text()); const QColor originalBgColor = QGuiApplication::palette().color(QPalette::Base); switch (messageStatus) { case statusInfo: break; ///< nothing to do case statusOk: item->setBackgroundColor(blendColors(originalBgColor, Qt::green, .1)); break; case statusError: item->setBackgroundColor(blendColors(originalBgColor, Qt::red, .1)); break; case statusAuth: item->setBackgroundColor(blendColors(originalBgColor, Qt::yellow, .1)); break; case statusNetwork: item->setBackgroundColor(blendColors(originalBgColor, Qt::yellow, .1)); break; } m_testWidget->messageList->addItem(item); m_testWidget->messageList->scrollToBottom(); qApp->processEvents(); } void KBibTeXTest::setBusy(bool isBusy) { m_testWidget->setBusy(isBusy); if (isBusy && !m_isBusy) { /// changing to busy state QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); } else if (!isBusy && m_isBusy) { /// changing to idle state QApplication::restoreOverrideCursor(); } m_isBusy = isBusy; } void KBibTeXTest::aboutToQuit() { m_running = false; QTimer::singleShot(500, qApp, &QApplication::quit); } void KBibTeXTest::startOnlineSearchTests() { m_running = true; setBusy(true); m_testWidget->messageList->clear(); qApp->processEvents(); processNextSearch(); } void KBibTeXTest::onlineSearchStoppedSearch(int searchResult) { if (searchResult == OnlineSearchAbstract::resultNoError) { if (m_currentOnlineSearchNumFoundEntries == 0) addMessage(QString(QStringLiteral("Got no error message searching '%1', but found NO entries")).arg((*m_currentOnlineSearch)->label()), statusError); else addMessage(QString(QStringLiteral("No error searching '%1', found %2 entries")).arg((*m_currentOnlineSearch)->label()).arg(m_currentOnlineSearchNumFoundEntries), statusOk); } else if (searchResult == OnlineSearchAbstract::resultAuthorizationRequired) { addMessage(QString(QStringLiteral("Authorization required for '%1'")).arg((*m_currentOnlineSearch)->label()), statusAuth); } else if (searchResult == OnlineSearchAbstract::resultNetworkError) { addMessage(QString(QStringLiteral("Network error for '%1'")).arg((*m_currentOnlineSearch)->label()), statusNetwork); } else { addMessage(QString(QStringLiteral("Error searching '%1'")).arg((*m_currentOnlineSearch)->label()), statusError); } m_currentOnlineSearch++; progress(-1, -1); processNextSearch(); } void KBibTeXTest::onlineSearchFoundEntry() { ++m_currentOnlineSearchNumFoundEntries; } void KBibTeXTest::progress(int pos, int total) { m_testWidget->setProgress(pos, total); } void KBibTeXTest::resetProgress() { m_testWidget->setProgress(-1, -1); } void KBibTeXTest::processNextSearch() { if (m_running && m_currentOnlineSearch != m_onlineSearchList.constEnd()) { setBusy(true); m_currentOnlineSearchNumFoundEntries = 0; addMessage(QString(QStringLiteral("Searching '%1'")).arg((*m_currentOnlineSearch)->label()), statusInfo); QMap query; query.insert(OnlineSearchAbstract::queryKeyAuthor, QStringLiteral("smith")); connect(*m_currentOnlineSearch, &OnlineSearchAbstract::stoppedSearch, this, &KBibTeXTest::onlineSearchStoppedSearch); connect(*m_currentOnlineSearch, &OnlineSearchAbstract::foundEntry, this, &KBibTeXTest::onlineSearchFoundEntry); connect(*m_currentOnlineSearch, &OnlineSearchAbstract::progress, this, &KBibTeXTest::progress); (*m_currentOnlineSearch)->startSearch(query, 3); } else { addMessage(QStringLiteral("Done testing"), statusInfo); setBusy(false); m_running = false; QTimer::singleShot(500, this, &KBibTeXTest::resetProgress); } } #include "kbibtextest.moc"