File indexing completed on 2024-05-12 16:46:12
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 0031 #include <QNetworkInterface> 0032 #include <QStandardPaths> 0033 0034 AbstractFetcherTest::AbstractFetcherTest() : QObject(), m_loop(this), m_hasNetwork(false) { 0035 foreach(const QNetworkInterface& net, QNetworkInterface::allInterfaces()) { 0036 if(net.flags().testFlag(QNetworkInterface::IsUp) && !net.flags().testFlag(QNetworkInterface::IsLoopBack)) { 0037 m_hasNetwork = true; 0038 break; 0039 } 0040 } 0041 QStandardPaths::setTestModeEnabled(true); 0042 } 0043 0044 Tellico::Data::EntryList AbstractFetcherTest::doFetch(Tellico::Fetch::Fetcher::Ptr fetcher, 0045 const Tellico::Fetch::FetchRequest& request, 0046 int maxResults) { 0047 // don't use 'this' as job parent, it crashes 0048 Tellico::Fetch::FetcherJob* job = new Tellico::Fetch::FetcherJob(nullptr, fetcher, request); 0049 connect(job, &KJob::result, this, &AbstractFetcherTest::slotResult); 0050 0051 if(maxResults > 0) { 0052 job->setMaximumResults(maxResults); 0053 } 0054 0055 job->start(); 0056 m_loop.exec(); 0057 return m_results; 0058 } 0059 0060 void AbstractFetcherTest::slotResult(KJob* job_) { 0061 m_results = static_cast<Tellico::Fetch::FetcherJob*>(job_)->entries(); 0062 m_loop.quit(); 0063 } 0064 0065 QString AbstractFetcherTest::set(Tellico::Data::EntryPtr entry_, const char* field_) { 0066 return set(entry_->field(QLatin1String(field_))); 0067 } 0068 0069 QString AbstractFetcherTest::set(const char* value_) { 0070 return set(QLatin1String(value_)); 0071 } 0072 0073 QString AbstractFetcherTest::set(const QString& value_) { 0074 QStringList values = Tellico::FieldFormat::splitValue(value_); 0075 values.sort(); 0076 return values.join(QLatin1String("; ")); 0077 }