[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [tellico/frameworks] src: update moviemeterfetcher
From:       Robby Stephenson <robby () periapsis ! org>
Date:       2015-06-01 1:06:46
Message-ID: E1YzEBi-0008KJ-Lq () scm ! kde ! org
[Download RAW message or body]

Git commit 1328254c056974c18f2c610069851cfe8b195488 by Robby Stephenson.
Committed on 31/05/2015 at 20:20.
Pushed by rstephenson into branch 'frameworks'.

update moviemeterfetcher

M  +10   -27   src/fetch/moviemeterfetcher.cpp
M  +4    -2    src/tests/CMakeLists.txt
M  +2    -3    src/tests/moviemeterfetchertest.cpp

http://commits.kde.org/tellico/1328254c056974c18f2c610069851cfe8b195488

diff --git a/src/fetch/moviemeterfetcher.cpp b/src/fetch/moviemeterfetcher.cpp
index 7f31e95..9bab810 100644
--- a/src/fetch/moviemeterfetcher.cpp
+++ b/src/fetch/moviemeterfetcher.cpp
@@ -22,7 +22,6 @@
  *                                                                         *
  ***************************************************************************/
 
-#include <config.h>
 #include "moviemeterfetcher.h"
 #include "../collections/videocollection.h"
 #include "../utils/guiproxy.h"
@@ -32,7 +31,7 @@
 
 #include <KLocalizedString>
 #include <kio/job.h>
-#include <kio/jobuidelegate.h>
+#include <KJobUiDelegate>
 #include <KJobWidgets/KJobWidgets>
 
 #include <QLabel>
@@ -40,11 +39,9 @@
 #include <QTextStream>
 #include <QGridLayout>
 #include <QTextCodec>
-
-#ifdef HAVE_QJSON
-#include <qjson/serializer.h>
-#include <qjson/parser.h>
-#endif
+#include <QJsonDocument>
+#include <QJsonObject>
+#include <QJsonArray>
 
 namespace {
   static const char* MOVIEMETER_API_KEY = "t80a06uf736d0yd00jpynpdsgea255yk";
@@ -71,11 +68,7 @@ QString MovieMeterFetcher::attribution() const {
 }
 
 bool MovieMeterFetcher::canSearch(FetchKey k) const {
-#ifdef HAVE_QJSON
   return k == Keyword;
-#else
-  return false;
-#endif
 }
 
 bool MovieMeterFetcher::canFetch(int type) const {
@@ -86,7 +79,6 @@ void MovieMeterFetcher::readConfigHook(const KConfigGroup&) {
 }
 
 void MovieMeterFetcher::search() {
-#ifdef HAVE_QJSON
   m_started = true;
 
   QUrl u(QString::fromLatin1(MOVIEMETER_API_URL));
@@ -113,9 +105,6 @@ void MovieMeterFetcher::search() {
   m_job = KIO::storedGet(u, KIO::NoReload, KIO::HideProgressInfo);
   KJobWidgets::setWindow(m_job, GUI::Proxy::widget());
   connect(m_job, SIGNAL(result(KJob*)), SLOT(slotComplete(KJob*)));
-#else
-  stop();
-#endif
 }
 
 void MovieMeterFetcher::stop() {
@@ -137,7 +126,6 @@ Tellico::Data::EntryPtr MovieMeterFetcher::fetchEntryHook(uint uid_) {
     return Data::EntryPtr();
   }
 
-#ifdef HAVE_QJSON
   QString id = entry->field(QLatin1String("moviemeter-id"));
   if(!id.isEmpty()) {
     QUrl u(QString::fromLatin1(MOVIEMETER_API_URL));
@@ -157,10 +145,9 @@ Tellico::Data::EntryPtr MovieMeterFetcher::fetchEntryHook(uint uid_) {
     f.close();
 #endif
 
-    QJson::Parser parser;
-    populateEntry(entry, parser.parse(data).toMap(), true);
+    QJsonDocument doc = QJsonDocument::fromJson(data);
+    populateEntry(entry, doc.object().toVariantMap(), true);
   }
-#endif
 
   // don't want to include ID field
   entry->setField(QLatin1String("moviemeter-id"), QString());
@@ -178,7 +165,6 @@ Tellico::Fetch::FetchRequest MovieMeterFetcher::updateRequest(Data::EntryPtr ent
 
 void MovieMeterFetcher::slotComplete(KJob* job_) {
   KIO::StoredTransferJob* job = static_cast<KIO::StoredTransferJob*>(job_);
-#ifdef HAVE_QJSON
 //  myDebug();
 
   if(job->error()) {
@@ -225,21 +211,19 @@ void MovieMeterFetcher::slotComplete(KJob* job_) {
     coll->addField(field);
   }
 
-  QJson::Parser parser;
-  const QVariant result = parser.parse(data);
-
-  foreach(const QVariant& result, result.toList()) {
+  QJsonDocument doc = QJsonDocument::fromJson(data);
+  QJsonArray array = doc.array();
+  for(int i = 0; i < array.count(); i++) {
   //  myDebug() << "found result:" << result;
 
     Data::EntryPtr entry(new Data::Entry(coll));
-    populateEntry(entry, result.toMap(), false);
+    populateEntry(entry, array.at(i).toObject().toVariantMap(), false);
 
     FetchResult* r = new FetchResult(Fetcher::Ptr(this), entry);
     m_entries.insert(r->uid, entry);
     emit signalResultFound(r);
   }
 
-#endif
   stop();
 }
 
@@ -326,4 +310,3 @@ QString MovieMeterFetcher::value(const QVariantMap& map, const char* name) {
     return QString();
   }
 }
-
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 58ea051..55f574d 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -544,11 +544,13 @@ add_test(isbndbfetchertest isbndbfetchertest)
 ecm_mark_as_test(isbndbfetchertest)
 TARGET_LINK_LIBRARIES(isbndbfetchertest fetcherstest ${TELLICO2_TEST_LIBS})
 
-add_executable(moviemeterfetchertest moviemeterfetchertest.cpp abstractfetchertest.cpp)
+add_executable(moviemeterfetchertest moviemeterfetchertest.cpp abstractfetchertest.cpp
+  ../fetch/moviemeterfetcher.cpp
+)
 ecm_mark_nongui_executable(moviemeterfetchertest)
 add_test(moviemeterfetchertest moviemeterfetchertest)
 ecm_mark_as_test(moviemeterfetchertest)
-TARGET_LINK_LIBRARIES(moviemeterfetchertest fetch ${TELLICO_TEST_LIBS})
+TARGET_LINK_LIBRARIES(moviemeterfetchertest fetcherstest ${TELLICO2_TEST_LIBS})
 
 add_executable(mrlookupfetchertest mrlookupfetchertest.cpp abstractfetchertest.cpp)
 ecm_mark_nongui_executable(mrlookupfetchertest)
diff --git a/src/tests/moviemeterfetchertest.cpp b/src/tests/moviemeterfetchertest.cpp
index 7d365de..017180f 100644
--- a/src/tests/moviemeterfetchertest.cpp
+++ b/src/tests/moviemeterfetchertest.cpp
@@ -25,7 +25,6 @@
 #undef QT_NO_CAST_FROM_ASCII
 
 #include "moviemeterfetchertest.h"
-#include "qtest_kde.h"
 
 #include "../fetch/moviemeterfetcher.h"
 #include "../collections/videocollection.h"
@@ -33,9 +32,9 @@
 #include "../entry.h"
 #include "../images/imagefactory.h"
 
-#include <KStandardDirs>
+#include <QTest>
 
-QTEST_KDEMAIN( MovieMeterFetcherTest, GUI )
+QTEST_GUILESS_MAIN( MovieMeterFetcherTest )
 
 MovieMeterFetcherTest::MovieMeterFetcherTest() : AbstractFetcherTest() {
 }

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic