File indexing completed on 2024-05-12 05:09:53
0001 /*************************************************************************** 0002 Copyright (C) 2011 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #undef QT_NO_CAST_FROM_ASCII 0026 0027 #include "abstractfetchertest.h" 0028 0029 #include "../fetch/fetcherjob.h" 0030 #include "../tellico_debug.h" 0031 0032 #include <KLocalizedString> 0033 0034 #include <QNetworkInterface> 0035 #include <QStandardPaths> 0036 0037 AbstractFetcherTest::AbstractFetcherTest() : QObject(), m_loop(this), m_hasNetwork(false) { 0038 foreach(const QNetworkInterface& net, QNetworkInterface::allInterfaces()) { 0039 if(net.flags().testFlag(QNetworkInterface::IsUp) && !net.flags().testFlag(QNetworkInterface::IsLoopBack)) { 0040 m_hasNetwork = true; 0041 break; 0042 } 0043 } 0044 QStandardPaths::setTestModeEnabled(true); 0045 KLocalizedString::setApplicationDomain("tellico"); 0046 QLoggingCategory::setFilterRules(QStringLiteral("tellico.debug = true\ntellico.info = false")); 0047 } 0048 0049 Tellico::Data::EntryList AbstractFetcherTest::doFetch(Tellico::Fetch::Fetcher::Ptr fetcher, 0050 const Tellico::Fetch::FetchRequest& request, 0051 int maxResults) { 0052 // don't use 'this' as job parent, it crashes 0053 Tellico::Fetch::FetcherJob* job = new Tellico::Fetch::FetcherJob(nullptr, fetcher, request); 0054 connect(job, &KJob::result, this, &AbstractFetcherTest::slotResult); 0055 0056 if(maxResults > 0) { 0057 job->setMaximumResults(maxResults); 0058 } 0059 0060 job->start(); 0061 m_loop.exec(); 0062 return m_results; 0063 } 0064 0065 void AbstractFetcherTest::slotResult(KJob* job_) { 0066 auto job = static_cast<Tellico::Fetch::FetcherJob*>(job_); 0067 Q_FOREACH(auto result, job->results()) { 0068 if(result->title.isEmpty() && result->desc.isEmpty()) { 0069 myDebug() << "AbstractFetcherTest::slotResult() - FetchResult has empty title and description"; 0070 } 0071 } 0072 m_results = job->entries(); 0073 m_loop.quit(); 0074 } 0075 0076 QString AbstractFetcherTest::set(Tellico::Data::EntryPtr entry_, const char* field_) { 0077 return set(entry_->field(QLatin1String(field_))); 0078 } 0079 0080 QString AbstractFetcherTest::set(const char* value_) { 0081 return set(QLatin1String(value_)); 0082 } 0083 0084 QString AbstractFetcherTest::set(const QString& value_) { 0085 QStringList values = Tellico::FieldFormat::splitValue(value_); 0086 values.sort(); 0087 return values.join(QLatin1String("; ")); 0088 }