diff --git a/src/fetch/allocinefetcher.h b/src/fetch/allocinefetcher.h index d01f7118..ebe36673 100644 --- a/src/fetch/allocinefetcher.h +++ b/src/fetch/allocinefetcher.h @@ -1,132 +1,133 @@ /*************************************************************************** Copyright (C) 2012 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 TELLICO_ALLOCINEFETCHER_H #define TELLICO_ALLOCINEFETCHER_H #include "xmlfetcher.h" #include "configwidget.h" #include "../datavectors.h" #include class QSpinBox; class KJob; namespace KIO { class StoredTransferJob; } namespace Tellico { namespace Fetch { /** * An abstract fetcher for the Allocine family of web sites * * @author Robby Stephenson */ class AbstractAllocineFetcher : public Fetcher { Q_OBJECT public: /** */ AbstractAllocineFetcher(QObject* parent, const QString& baseUrl); /** */ virtual ~AbstractAllocineFetcher(); virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; virtual void stop() Q_DECL_OVERRIDE; virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; virtual bool canFetch(int type) const Q_DECL_OVERRIDE; + virtual bool needsUserAgent() const Q_DECL_OVERRIDE { return true; } virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; class ConfigWidget : public Fetch::ConfigWidget { public: explicit ConfigWidget(QWidget* parent_, const AbstractAllocineFetcher* fetcher = nullptr); virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; virtual QString preferredName() const Q_DECL_OVERRIDE = 0; private: QSpinBox* m_numCast; }; friend class ConfigWidget; private Q_SLOTS: void slotComplete(KJob* job); private: static QByteArray calculateSignature(const QList >& params); virtual void search() Q_DECL_OVERRIDE; virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; Data::CollPtr createCollection() const; void populateEntry(Data::EntryPtr entry, const QVariantMap& resultMap); QHash m_entries; QPointer m_job; bool m_started; QString m_apiKey; QString m_baseUrl; int m_numCast; }; /** * A fetcher for allocine.fr * * @author Robby Stephenson */ class AllocineFetcher : public AbstractAllocineFetcher { Q_OBJECT public: /** */ AllocineFetcher(QObject* parent); virtual QString source() const Q_DECL_OVERRIDE; virtual Type type() const Q_DECL_OVERRIDE { return Allocine; } /** * Returns a widget for modifying the fetcher's config. */ virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; class ConfigWidget : public AbstractAllocineFetcher::ConfigWidget { public: explicit ConfigWidget(QWidget* parent_, const AbstractAllocineFetcher* fetcher = nullptr); virtual QString preferredName() const Q_DECL_OVERRIDE; }; static QString defaultName(); static QString defaultIcon(); static StringHash allOptionalFields(); }; } // end namespace } // end namespace #endif diff --git a/src/fetch/discogsfetcher.h b/src/fetch/discogsfetcher.h index daf21ff5..d2891b81 100644 --- a/src/fetch/discogsfetcher.h +++ b/src/fetch/discogsfetcher.h @@ -1,111 +1,112 @@ /*************************************************************************** Copyright (C) 2008-2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 TELLICO_DISCOGSFETCHER_H #define TELLICO_DISCOGSFETCHER_H #include "fetcher.h" #include "configwidget.h" #include "../datavectors.h" #include class QLineEdit; class KJob; namespace KIO { class StoredTransferJob; } namespace Tellico { namespace Fetch { /** * A fetcher for discogs.com * * @author Robby Stephenson */ class DiscogsFetcher : public Fetcher { Q_OBJECT public: /** */ DiscogsFetcher(QObject* parent); /** */ virtual ~DiscogsFetcher(); /** */ virtual QString source() const Q_DECL_OVERRIDE; virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; virtual Type type() const Q_DECL_OVERRIDE { return Discogs; } virtual void stop() Q_DECL_OVERRIDE; virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; virtual bool canFetch(int type) const Q_DECL_OVERRIDE; + virtual bool needsUserAgent() const Q_DECL_OVERRIDE { return true; } virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; void setLimit(int limit); /** * Returns a widget for modifying the fetcher's config. */ virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; class ConfigWidget : public Fetch::ConfigWidget { public: explicit ConfigWidget(QWidget* parent_, const DiscogsFetcher* fetcher = nullptr); virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; virtual QString preferredName() const Q_DECL_OVERRIDE; private: QLineEdit* m_apiKeyEdit; }; friend class ConfigWidget; static QString defaultName(); static QString defaultIcon(); static StringHash allOptionalFields(); private Q_SLOTS: void slotComplete(KJob* job); private: virtual void search() Q_DECL_OVERRIDE; virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; void populateEntry(Data::EntryPtr entry, const QVariantMap& resultMap, bool fullData); int m_limit; bool m_started; QString m_apiKey; QHash m_entries; QPointer m_job; }; } // end namespace } // end namespace #endif diff --git a/src/fetch/fetcher.cpp b/src/fetch/fetcher.cpp index cca3e6f6..4710a029 100644 --- a/src/fetch/fetcher.cpp +++ b/src/fetch/fetcher.cpp @@ -1,196 +1,217 @@ /*************************************************************************** Copyright (C) 2005-2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 "fetcher.h" #include "fetchmanager.h" // for calling static optional fields #include "../collection.h" #include "../entry.h" #include "../tellico_debug.h" #include #include #include #include +#include #include #if KIO_VERSION >= QT_VERSION_CHECK(5,19,0) #include #endif #include #include #include using namespace Tellico::Fetch; using Tellico::Fetch::Fetcher; Fetcher::Fetcher(QObject* parent) : QObject(parent) , QSharedData() , m_updateOverwrite(false) , m_hasMoreResults(false) , m_messager(nullptr) { } Fetcher::~Fetcher() { saveConfig(); } int Fetcher::collectionType() const { return m_request.collectionType; } /// virtual, overridden by subclasses bool Fetcher::canUpdate() const { return true; } bool Fetcher::updateOverwrite() const { return m_updateOverwrite; } const Tellico::Fetch::FetchRequest& Fetcher::request() const { return m_request; } void Fetcher::startSearch(const FetchRequest& request_) { m_request = request_; if(!canFetch(m_request.collectionType)) { - message(i18n("%1 does not allow searching for this collection type.", source()), MessageHandler::Warning); + message(i18n("%1 does not allow searching for this collection type.", source()), + MessageHandler::Warning); emit signalDone(this); return; } + if(needsUserAgent()) { + // copied from KProtocolManager::userAgentForHost + const QString sendUserAgent = KIO::SlaveConfig::self()->configData(QStringLiteral("http"), + QString(), // host name + QStringLiteral("SendUserAgent")).toLower(); + if(sendUserAgent == QLatin1String("false")) { + myDebug() << "Fetcher - Need user agent for" << source(); + // TODO: I'd like to link to kcmshell5 useragent as th eKonqueror about page does + // but KIO complains about unable to open exec links +// message(i18n("%1 requires the network request to include identification.\n" +// "Check the network configuration in KDE System Settings.", source(), QStringLiteral("exec:/kcmshell5 useragent")), + message(i18n("%1 requires the network request to include identification.\n" + "Check the network configuration in KDE System Settings.", source()), + MessageHandler::Error); + emit signalDone(this); + return; + } + } + m_entries.clear(); search(); } void Fetcher::startUpdate(Tellico::Data::EntryPtr entry_) { Q_ASSERT(entry_); Q_ASSERT(entry_->collection()); m_request = updateRequest(entry_); m_request.collectionType = entry_->collection()->type(); if(!m_request.isNull()) { search(); } else { myDebug() << "insufficient info to search"; emit signalDone(this); // always need to emit this if not continuing with the search } // updateEntry(entry_); } void Fetcher::readConfig(const KConfigGroup& config_, const QString& groupName_) { Q_ASSERT(config_.name() == groupName_); m_configGroup = groupName_; QString s = config_.readEntry("Name"); if(!s.isEmpty()) { m_name = s; } m_updateOverwrite = config_.readEntry("UpdateOverwrite", false); // it's called custom fields here, but it's really optional lists m_fields = config_.readEntry("Custom Fields", QStringList()); s = config_.readEntry("Uuid"); if(s.isEmpty()) { s = QUuid::createUuid().toString(); } m_uuid = s; // be sure to read config for subclass readConfigHook(config_); } void Fetcher::saveConfig() { if(m_configGroup.isEmpty()) { return; } KConfigGroup config(KSharedConfig::openConfig(), m_configGroup); config.writeEntry("Uuid", m_uuid); saveConfigHook(config); } void Fetcher::setConfigGroup(const QString& group_) { m_configGroup = group_; } Tellico::Data::EntryPtr Fetcher::fetchEntry(uint uid_) { // check if already fetched this entry if(m_entries.contains(uid_)) { return m_entries[uid_]; } QPointer ptr(this); Data::EntryPtr entry = fetchEntryHook(uid_); // could be cancelled and killed after fetching entry, check ptr if(ptr && entry) { // iterate over list of possible optional fields // and if the field is not included in the user-configured list // remove the field from the entry QHashIterator i(Manager::optionalFields(type())); while(i.hasNext()) { i.next(); if(!m_fields.contains(i.key())) { entry->collection()->removeField(i.key()); } } } m_entries.insert(uid_, entry); return entry; } void Fetcher::message(const QString& message_, int type_) const { if(m_messager) { m_messager->send(message_, static_cast(type_)); } } void Fetcher::infoList(const QString& message_, const QStringList& list_) const { if(m_messager) { m_messager->infoList(message_, list_); } } QString Fetcher::favIcon(const char* url_) { return favIcon(QUrl(QString::fromLatin1(url_))); } QString Fetcher::favIcon(const QUrl& url_) { if(!url_.isValid()) { return QString(); } #if KIO_VERSION >= QT_VERSION_CHECK(5,19,0) KIO::FavIconRequestJob* job = new KIO::FavIconRequestJob(url_); Q_UNUSED(job); #endif QString name = KIO::favIconForUrl(url_); // favIcons start with "/". being an absolute file path from FavIconFetchJob // but KIconLoader still expects them to start with "favicons/" and appends ".png" // since the rest of Tellico assumes KDE4 behavior, adjust here if(name.startsWith(QLatin1Char('/'))) { int pos = name.indexOf(QLatin1String("favicons/")); if(pos > -1) { name = name.mid(pos); name.chop(4); // remove ".png"; } } return name; } diff --git a/src/fetch/fetcher.h b/src/fetch/fetcher.h index 3514474e..10498877 100644 --- a/src/fetch/fetcher.h +++ b/src/fetch/fetcher.h @@ -1,171 +1,175 @@ /*************************************************************************** Copyright (C) 2003-2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 TELLICO_FETCHER_H #define TELLICO_FETCHER_H #include "fetch.h" #include "fetchrequest.h" #include "fetchresult.h" #include "messagehandler.h" #include "../datavectors.h" #include #include #include #include class KConfigGroup; class QUrl; namespace Tellico { namespace Fetch { class ConfigWidget; /** * The top-level abstract class for fetching data. * * @author Robby Stephenson */ class Fetcher : public QObject, public QSharedData { Q_OBJECT public: typedef QExplicitlySharedDataPointer Ptr; /** */ Fetcher(QObject* parent); /** */ virtual ~Fetcher(); /** * Returns true if the fetcher might return entries from a certain collection type. */ virtual bool canFetch(int type) const = 0; /** * Returns true if the fetcher can search using a certain key. */ virtual bool canSearch(FetchKey key) const = 0; virtual bool canUpdate() const; + /** + * Returns true if the fetcher requires a user agent to be sent + */ + virtual bool needsUserAgent() const { return false; } /** * Returns the type of the data source. */ virtual Type type() const = 0; /** * Returns the name of the data source, as defined by the user. */ virtual QString source() const = 0; virtual QString attribution() const { return QString(); } /** * Returns the collection type of the most recent search */ int collectionType() const; /** * Returns whether the fetcher will overwite existing info when updating */ bool updateOverwrite() const; const FetchRequest& request() const; QStringList optionalFields() const { return m_fields; } QString uuid() const { return m_uuid; } /** * Starts a search, using a key and value. Calls search() */ void startSearch(const FetchRequest& request); virtual void continueSearch() {} void startUpdate(Data::EntryPtr entry); /** * Returns true if the fetcher is currently searching. */ virtual bool isSearching() const = 0; /** * Returns true if the fetcher can continue and fetch more results * The fetcher is responsible for remembering state. */ virtual bool hasMoreResults() const { return m_hasMoreResults; } /** * Stops the fetcher. */ virtual void stop() = 0; /** * Fetches an entry, given the uid of the search result. */ Data::EntryPtr fetchEntry(uint uid); void setMessageHandler(MessageHandler* handler) { m_messager = handler; } MessageHandler* messageHandler() const { return m_messager; } /** */ void message(const QString& message, int type) const; void infoList(const QString& message, const QStringList& list) const; /** * Reads the config for the widget, given a config group. */ void readConfig(const KConfigGroup& config, const QString& groupName); void saveConfig(); void setConfigGroup(const QString& group); /** * Returns a widget for modifying the fetcher's config. */ virtual ConfigWidget* configWidget(QWidget* parent) const = 0; static QString favIcon(const char* url); static QString favIcon(const QUrl& url); Q_SIGNALS: // void signalStatus(const QString& status); void signalResultFound(Tellico::Fetch::FetchResult* result); void signalDone(Tellico::Fetch::Fetcher* fetcher); protected: QString m_name; FetchRequest m_request; bool m_updateOverwrite : 1; bool m_hasMoreResults : 1; private: /** * Starts a search, using a key and value. */ virtual void search() = 0; virtual FetchRequest updateRequest(Data::EntryPtr entry) = 0; virtual void readConfigHook(const KConfigGroup&) = 0; virtual void saveConfigHook(KConfigGroup&) {} virtual Data::EntryPtr fetchEntryHook(uint uid) = 0; MessageHandler* m_messager; QString m_configGroup; QStringList m_fields; QString m_uuid; QHash m_entries; }; } // end namespace } // end namespace #endif diff --git a/src/fetch/messagehandler.cpp b/src/fetch/messagehandler.cpp index 43da8ace..b67fc255 100644 --- a/src/fetch/messagehandler.cpp +++ b/src/fetch/messagehandler.cpp @@ -1,50 +1,52 @@ /*************************************************************************** Copyright (C) 2005-2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 "messagehandler.h" #include "fetchmanager.h" #include "../utils/guiproxy.h" #include "../utils/cursorsaver.h" #include using Tellico::Fetch::ManagerMessage; // all messages go to manager void ManagerMessage::send(const QString& message_, Type type_) { GUI::CursorSaver cs(Qt::ArrowCursor); // plus errors get a message box if(type_ == Error) { KMessageBox::sorry(GUI::Proxy::widget(), message_); +// QString(), // caption +// KMessageBox::Options(KMessageBox::Notify | KMessageBox::AllowLink)); } else if(type_ == Warning) { KMessageBox::information(GUI::Proxy::widget(), message_); } else { Fetch::Manager::self()->updateStatus(message_); } } void ManagerMessage::infoList(const QString& message_, const QStringList& list_) { GUI::CursorSaver cs(Qt::ArrowCursor); KMessageBox::informationList(GUI::Proxy::widget(), message_, list_); } diff --git a/src/fetch/musicbrainzfetcher.h b/src/fetch/musicbrainzfetcher.h index 0c9dac0b..22294a50 100644 --- a/src/fetch/musicbrainzfetcher.h +++ b/src/fetch/musicbrainzfetcher.h @@ -1,116 +1,117 @@ /*************************************************************************** Copyright (C) 2009 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 TELLICO_MUSICBRAINZFETCHER_H #define TELLICO_MUSICBRAINZFETCHER_H #include "fetcher.h" #include "configwidget.h" #include "../datavectors.h" #include #include class KJob; namespace KIO { class StoredTransferJob; } namespace Tellico { class XSLTHandler; namespace Fetch { /** * A fetcher for discogs.com * * @author Robby Stephenson */ class MusicBrainzFetcher : public Fetcher { Q_OBJECT public: /** */ MusicBrainzFetcher(QObject* parent); /** */ virtual ~MusicBrainzFetcher(); /** */ virtual QString source() const Q_DECL_OVERRIDE; virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } virtual void continueSearch() Q_DECL_OVERRIDE; // amazon can search title or person virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE { return k == Title || k == Person || k == Keyword; } virtual void stop() Q_DECL_OVERRIDE; virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; virtual Type type() const Q_DECL_OVERRIDE { return MusicBrainz; } virtual bool canFetch(int type) const Q_DECL_OVERRIDE; + virtual bool needsUserAgent() const Q_DECL_OVERRIDE { return true; } virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; void setLimit(int limit); /** * Returns a widget for modifying the fetcher's config. */ virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; class ConfigWidget : public Fetch::ConfigWidget { public: explicit ConfigWidget(QWidget* parent_, const MusicBrainzFetcher* fetcher = nullptr); virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; virtual QString preferredName() const Q_DECL_OVERRIDE; }; friend class ConfigWidget; static QString defaultName(); static QString defaultIcon(); static StringHash allOptionalFields() { return StringHash(); } private Q_SLOTS: void slotComplete(KJob* job); private: virtual void search() Q_DECL_OVERRIDE; virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; void initXSLTHandler(); void doSearch(); XSLTHandler* m_xsltHandler; int m_limit; int m_total; int m_offset; QElapsedTimer m_requestTimer; QHash m_entries; QPointer m_job; bool m_started; }; } // end namespace } // end namespace #endif diff --git a/src/tests/crossreffetchertest.cpp b/src/tests/crossreffetchertest.cpp index 14f4d33f..95e031ca 100644 --- a/src/tests/crossreffetchertest.cpp +++ b/src/tests/crossreffetchertest.cpp @@ -1,82 +1,85 @@ /*************************************************************************** Copyright (C) 2015 Robby Stephenson ***************************************************************************/ /*************************************************************************** * * * 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) version 3 or any later version * * accepted by the membership of KDE e.V. (or its successor approved * * by the membership of KDE e.V.), which shall act as a proxy * * defined in Section 14 of version 3 of the license. * * * * 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 . * * * ***************************************************************************/ #undef QT_NO_CAST_FROM_ASCII #include "crossreffetchertest.h" #include "../fetch/crossreffetcher.h" #include "../collections/bibtexcollection.h" #include "../collectionfactory.h" #include "../entry.h" #include "../utils/datafileregistry.h" #include #include #include QTEST_GUILESS_MAIN( CrossRefFetcherTest ) CrossRefFetcherTest::CrossRefFetcherTest() : AbstractFetcherTest() { } void CrossRefFetcherTest::initTestCase() { Tellico::DataFileRegistry::self()->addDataLocation(QFINDTESTDATA("../../xslt/unixref2tellico.xsl")); Tellico::RegisterCollection registerBibtex(Tellico::Data::Collection::Bibtex, "bibtex"); m_fieldValues.insert(QStringLiteral("doi"), QStringLiteral("10.2514/1.G000894")); m_fieldValues.insert(QStringLiteral("entry-type"), QStringLiteral("article")); m_fieldValues.insert(QStringLiteral("title"), QStringLiteral("Robustness and Efficiency Improvements for Star Tracker Attitude Estimation")); m_fieldValues.insert(QStringLiteral("author"), QStringLiteral("Tjorven Delabie; Joris De Schutter; Bart Vandenbussche")); m_fieldValues.insert(QStringLiteral("pages"), QStringLiteral("2108-2121")); m_fieldValues.insert(QStringLiteral("journal"), QStringLiteral("Journal of Guidance, Control, and Dynamics")); m_fieldValues.insert(QStringLiteral("year"), QStringLiteral("2015")); m_fieldValues.insert(QStringLiteral("month"), QStringLiteral("11")); } void CrossRefFetcherTest::testDOI() { KConfig config(QFINDTESTDATA("tellicotest.config"), KConfig::SimpleConfig); QString groupName = QStringLiteral("crossref"); if(!config.hasGroup(groupName)) { QSKIP("This test requires a config file.", SkipAll); } KConfigGroup cg(&config, groupName); Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::Bibtex, Tellico::Fetch::DOI, m_fieldValues.value(QStringLiteral("doi"))); Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::CrossRefFetcher(this)); fetcher->readConfig(cg, cg.name()); + // easy place to check whether the user agent setting is correct + QCOMPARE(fetcher->needsUserAgent(), false); + Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1); QCOMPARE(results.size(), 1); Tellico::Data::EntryPtr entry = results.at(0); QHashIterator i(m_fieldValues); while(i.hasNext()) { i.next(); QCOMPARE(entry->field(i.key()), i.value()); } }