[office/tellico] /: Add comic book to Colnect data source

Robby Stephenson null at kde.org
Fri Apr 21 02:45:25 BST 2023


Git commit 9047c96e620cf7b174fc6c38eb05a7a5370bce19 by Robby Stephenson.
Committed on 21/04/2023 at 01:45.
Pushed by rstephenson into branch 'master'.

Add comic book to Colnect data source

M  +4    -0    ChangeLog
M  +1    -1    doc/configuration.docbook
M  +98   -20   src/fetch/colnectfetcher.cpp
M  +30   -0    src/tests/colnectfetchertest.cpp
M  +1    -0    src/tests/colnectfetchertest.h

https://invent.kde.org/office/tellico/commit/9047c96e620cf7b174fc6c38eb05a7a5370bce19

diff --git a/ChangeLog b/ChangeLog
index 7a65bc01a..8b9cd433b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2023-04-20  Robby Stephenson  <robby at periapsis.org>
+
+	* Updated Colnect data source to include comic book collections.
+
 2023-04-19  Robby Stephenson  <robby at periapsis.org>
 
 	* Updated SRU and z39.50 server info for Library of Congress.
diff --git a/doc/configuration.docbook b/doc/configuration.docbook
index 9dbf8f693..d2dff5ba5 100644
--- a/doc/configuration.docbook
+++ b/doc/configuration.docbook
@@ -464,7 +464,7 @@ The <ulink url="http://www.imdb.com">Internet Movie Database</ulink> provides in
 <title>Colnect</title>
 <para>
 <ulink url="https://colnect.com">Colnect</ulink> is an online community for collectibles providing personal collection management.
-&tellico; can search Colnect for coin and stamp information.
+&tellico; can search Colnect for coin, stamp, and comic book information.
 </para>
 </sect3>
 
diff --git a/src/fetch/colnectfetcher.cpp b/src/fetch/colnectfetcher.cpp
index 5c95dd9ce..e2d6c5979 100644
--- a/src/fetch/colnectfetcher.cpp
+++ b/src/fetch/colnectfetcher.cpp
@@ -25,6 +25,7 @@
 #include "colnectfetcher.h"
 #include "../collections/coincollection.h"
 #include "../collections/stampcollection.h"
+#include "../collections/comicbookcollection.h"
 #include "../images/imagefactory.h"
 #include "../gui/combobox.h"
 #include "../utils/guiproxy.h"
@@ -83,7 +84,9 @@ bool ColnectFetcher::canSearch(Fetch::FetchKey k) const {
 }
 
 bool ColnectFetcher::canFetch(int type) const {
-  return type == Data::Collection::Coin || type == Data::Collection::Stamp;
+  return type == Data::Collection::Coin
+      || type == Data::Collection::Stamp
+      || type == Data::Collection::ComicBook;
 }
 
 void ColnectFetcher::readConfigHook(const KConfigGroup& config_) {
@@ -109,6 +112,9 @@ void ColnectFetcher::search() {
     case Data::Collection::Stamp:
       m_category = QStringLiteral("stamps");
       break;
+    case Data::Collection::ComicBook:
+      m_category = QStringLiteral("comics");
+      break;
     default:
       myWarning() << "Colnect category type not available for" << collectionType();
       stop();
@@ -240,6 +246,7 @@ Tellico::Data::EntryPtr ColnectFetcher::fetchEntryHook(uint uid_) {
   loadImage(entry, QStringLiteral("obverse"));
   loadImage(entry, QStringLiteral("reverse"));
   loadImage(entry, QStringLiteral("image")); // stamp image
+  loadImage(entry, QStringLiteral("cover"));
 
   // don't want to include id
   entry->setField(QStringLiteral("colnect-id"), QString());
@@ -302,10 +309,16 @@ void ColnectFetcher::slotComplete(KJob* job_) {
   m_hasMoreResults = false; // for now, no continued searches
 
   Data::CollPtr coll;
-  if(collectionType() == Data::Collection::Coin) {
-    coll = new Data::CoinCollection(true);
-  } else {
-    coll = new Data::StampCollection(true);
+  switch(collectionType()) {
+    case Data::Collection::Coin:
+      coll = new Data::CoinCollection(true);
+      break;
+    case Data::Collection::Stamp:
+      coll = new Data::StampCollection(true);
+      break;
+    case Data::Collection::ComicBook:
+      coll = new Data::ComicBookCollection(true);
+      break;
   }
   // placeholder for colnect id, to be removed later
   Data::FieldPtr f1(new Data::Field(QStringLiteral("colnect-id"), QString()));
@@ -375,7 +388,13 @@ void ColnectFetcher::slotComplete(KJob* job_) {
     if(optionalFields().contains(desc)) {
       entry->setField(desc, values.last().toString());
     }
-    entry->setField(QStringLiteral("year"), m_year);
+    if(!m_year.isEmpty()) {
+      if(collectionType() == Data::Collection::ComicBook) {
+        entry->setField(QStringLiteral("pub_year"), m_year);
+      } else {
+        entry->setField(QStringLiteral("year"), m_year);
+      }
+    }
 
     FetchResult* r = new FetchResult(this, entry);
     m_entries.insert(r->uid, entry);
@@ -388,8 +407,8 @@ void ColnectFetcher::slotComplete(KJob* job_) {
 void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& resultList_) {
   if(m_colnectFields.isEmpty()) {
     readDataList();
-    // set minimum size of list here
-    if(m_colnectFields.count() < 26) {
+    // set minimum size of list here (comics are 24)
+    if(m_colnectFields.count() < 24) {
       return;
     }
   }
@@ -398,11 +417,29 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
     return;
   }
 
+#if 0
+  auto i = m_colnectFields.constBegin();
+  while(i != m_colnectFields.constEnd()) {
+    myDebug() << i.key() << ": " << resultList_.at(i.value());
+    ++i;
+  }
+#endif
+
+  int idx = m_colnectFields.value(QStringLiteral("Series"), -1);
+  static const QString series(QStringLiteral("series"));
+  if(idx > -1 && optionalFields().contains(series)) {
+    entry_->setField(series, resultList_.at(idx).toString());
+  }
+
   // lookup the field name for the list index
-  int idx = m_colnectFields.value(QStringLiteral("Issued on"), -1);
+  idx = m_colnectFields.value(QStringLiteral("Issued on"), -1);
   // the year may have already been set in the query term
   if(m_year.isEmpty() && idx > -1) {
-    entry_->setField(QStringLiteral("year"), resultList_.at(idx).toString());
+    if(collectionType() == Data::Collection::ComicBook) {
+      entry_->setField(QStringLiteral("pub_year"), resultList_.at(idx).toString().left(4));
+    } else {
+      entry_->setField(QStringLiteral("year"), resultList_.at(idx).toString().left(4));
+    }
   }
 
   idx = m_colnectFields.value(QStringLiteral("Country"), -1);
@@ -411,12 +448,12 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
   }
 
   idx = m_colnectFields.value(QStringLiteral("Gum"), -1);
-  if(idx > -1) {
+  if(idx > -1 && collectionType() == Data::Collection::Stamp) {
     entry_->setField(QStringLiteral("gummed"), resultList_.at(idx).toString());
   }
 
   idx = m_colnectFields.value(QStringLiteral("Colors"), -1);
-  if(idx > -1) {
+  if(idx > -1 && collectionType() == Data::Collection::Stamp) {
     int colorId = resultList_.at(idx).toInt();
     if(colorId > 0) {
       if(m_stampColors.isEmpty()) {
@@ -427,7 +464,7 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
   }
 
   idx = m_colnectFields.value(QStringLiteral("Currency"), -1);
-  if(idx > -1) {
+  if(idx > -1 && collectionType() != Data::Collection::ComicBook) {
     entry_->setField(QStringLiteral("currency"), resultList_.at(idx).toString());
     idx = m_colnectFields.value(QStringLiteral("FaceValue"), -1);
     if(idx > -1) {
@@ -441,12 +478,6 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
     }
   }
 
-  idx = m_colnectFields.value(QStringLiteral("Series"), -1);
-  static const QString series(QStringLiteral("series"));
-  if(idx > -1 && optionalFields().contains(series)) {
-    entry_->setField(series, resultList_.at(idx).toString());
-  }
-
   idx = m_colnectFields.value(QStringLiteral("Known mintage"), -1);
   static const QString mintage(QStringLiteral("mintage"));
   if(idx > -1 && optionalFields().contains(mintage)) {
@@ -508,6 +539,10 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
       entry_->setField(QStringLiteral("image"),
                        imageUrl(resultList_.at(0).toString(),
                                 resultList_.at(idx).toString()));
+    } else if(collectionType() == Data::Collection::ComicBook) {
+      entry_->setField(QStringLiteral("cover"),
+                       imageUrl(resultList_.at(0).toString(),
+                                resultList_.at(idx).toString()));
     }
   }
 
@@ -517,6 +552,49 @@ void ColnectFetcher::populateEntry(Data::EntryPtr entry_, const QVariantList& re
                      imageUrl(resultList_.at(0).toString(),
                               resultList_.at(idx).toString()));
   }
+
+  // only comic book below here
+  if(collectionType() != Data::Collection::ComicBook) return;
+
+  idx = m_colnectFields.value(QStringLiteral("Name"), -1);
+  if(idx > -1 && collectionType() == Data::Collection::ComicBook) {
+    entry_->setField(QStringLiteral("title"), resultList_.at(idx).toString());
+  }
+
+  static const QRegularExpression spaceCommaRx(QLatin1String("\\s*,\\s*"));
+  idx = m_colnectFields.value(QStringLiteral("Writer"), -1);
+  if(idx > -1) {
+    QString writer = resultList_.at(idx).toString();
+    writer.replace(spaceCommaRx, FieldFormat::delimiterString());
+    entry_->setField(QStringLiteral("writer"), writer);
+  }
+
+  idx = m_colnectFields.value(QStringLiteral("CoverArtist"), -1);
+  if(idx > -1) {
+    QString artist = resultList_.at(idx).toString();
+    artist.replace(spaceCommaRx, FieldFormat::delimiterString());
+    entry_->setField(QStringLiteral("artist"), artist);
+  }
+
+  idx = m_colnectFields.value(QStringLiteral("Publisher"), -1);
+  if(idx > -1) {
+    entry_->setField(QStringLiteral("publisher"), resultList_.at(idx).toString());
+  }
+
+  idx = m_colnectFields.value(QStringLiteral("IssuingNumber"), -1);
+  if(idx > -1) {
+    entry_->setField(QStringLiteral("issue"), resultList_.at(idx).toString());
+  }
+
+  idx = m_colnectFields.value(QStringLiteral("Edition"), -1);
+  if(idx > -1) {
+    entry_->setField(QStringLiteral("edition"), resultList_.at(idx).toString());
+  }
+
+  idx = m_colnectFields.value(QStringLiteral("Genre"), -1);
+  if(idx > -1) {
+    entry_->setField(QStringLiteral("genre"), resultList_.at(idx).toString());
+  }
 }
 
 void ColnectFetcher::loadImage(Data::EntryPtr entry_, const QString& fieldName_) {
@@ -614,7 +692,7 @@ void ColnectFetcher::readDataList() {
     m_colnectFields.insert(resultList.at(i).toString(), i);
 //    if(i == 5) myDebug() << m_colnectFields;
   }
-//  myDebug() << "Number of Colnect fields:" << m_colnectFields.count();
+//  myDebug() << "Colnect fields:" << m_colnectFields;
 }
 
 void ColnectFetcher::readStampColors() {
diff --git a/src/tests/colnectfetchertest.cpp b/src/tests/colnectfetchertest.cpp
index a84cb9a3f..055f01b28 100644
--- a/src/tests/colnectfetchertest.cpp
+++ b/src/tests/colnectfetchertest.cpp
@@ -29,6 +29,7 @@
 #include "../fetch/colnectfetcher.h"
 #include "../entry.h"
 #include "../collections/coincollection.h"
+#include "../collections/comicbookcollection.h"
 #include "../collectionfactory.h"
 #include "../images/imagefactory.h"
 #include "../fieldformat.h"
@@ -46,6 +47,7 @@ ColnectFetcherTest::ColnectFetcherTest() : AbstractFetcherTest() {
 void ColnectFetcherTest::initTestCase() {
   Tellico::ImageFactory::init();
   Tellico::RegisterCollection<Tellico::Data::CoinCollection> registerMe(Tellico::Data::Collection::Coin, "coin");
+  Tellico::RegisterCollection<Tellico::Data::ComicBookCollection> registerComic(Tellico::Data::Collection::ComicBook, "comic");
 
   m_config = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect"));
   m_config.writeEntry("Custom Fields", QStringLiteral("obverse,reverse,series,mintage,description"));
@@ -145,3 +147,31 @@ void ColnectFetcherTest::testSkylab() {
   QVERIFY(!entry->field(QStringLiteral("image")).isEmpty());
   QVERIFY(!entry->field(QStringLiteral("image")).contains(QLatin1Char('/')));
 }
+
+void ColnectFetcherTest::testComic() {
+  KConfigGroup cg = KSharedConfig::openConfig(QString(), KConfig::SimpleConfig)->group(QStringLiteral("colnect comics"));
+  cg.writeEntry("Custom Fields", QStringLiteral("series"));
+
+  Tellico::Fetch::FetchRequest request(Tellico::Data::Collection::ComicBook,
+                                       Tellico::Fetch::Title,
+                                       QStringLiteral("Destiny's Hand: Finale"));
+  Tellico::Fetch::Fetcher::Ptr fetcher(new Tellico::Fetch::ColnectFetcher(this));
+  fetcher->readConfig(cg);
+
+  Tellico::Data::EntryList results = DO_FETCH1(fetcher, request, 1);
+
+  QCOMPARE(results.size(), 1);
+  Tellico::Data::EntryPtr entry = results.at(0);
+
+  QCOMPARE(entry->field(QStringLiteral("title")), QStringLiteral("Destiny's Hand: Finale"));
+  QCOMPARE(entry->field(QStringLiteral("pub_year")), QStringLiteral("1993"));
+  QCOMPARE(entry->field(QStringLiteral("series")), QStringLiteral("Justice League America (JLA)"));
+  QCOMPARE(entry->field(QStringLiteral("writer")), QStringLiteral("Jurgens Dan"));
+  QCOMPARE(entry->field(QStringLiteral("artist")), QStringLiteral("Jurgens Dan; Giordano Dick"));
+  QCOMPARE(entry->field(QStringLiteral("issue")), QStringLiteral("75"));
+  QCOMPARE(entry->field(QStringLiteral("publisher")), QStringLiteral("DC Comics"));
+  QCOMPARE(entry->field(QStringLiteral("edition")), QStringLiteral("First edition"));
+  QCOMPARE(entry->field(QStringLiteral("genre")), QStringLiteral("Superhero"));
+  QVERIFY(!entry->field(QStringLiteral("cover")).isEmpty());
+  QVERIFY(!entry->field(QStringLiteral("cover")).contains(QLatin1Char('/')));
+}
diff --git a/src/tests/colnectfetchertest.h b/src/tests/colnectfetchertest.h
index 43f5f0cbe..9a978f868 100644
--- a/src/tests/colnectfetchertest.h
+++ b/src/tests/colnectfetchertest.h
@@ -41,6 +41,7 @@ private Q_SLOTS:
   void testRaw();
   void testSacagawea();
   void testSkylab();
+  void testComic();
 
 private:
   KConfigGroup m_config;


More information about the kde-doc-english mailing list