diff --git a/simgear/package/CatalogTest.cxx b/simgear/package/CatalogTest.cxx index 5fbf83ae..426bfd88 100644 --- a/simgear/package/CatalogTest.cxx +++ b/simgear/package/CatalogTest.cxx @@ -167,14 +167,10 @@ int parseTest() SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-panel.png"); SG_VERIFY(index->type == pkg::Package::Preview::Type::PANEL); -// old-style thumbnails - string_list oldThumbUrls = p2->thumbnailUrls(); - SG_CHECK_EQUAL(oldThumbUrls.size(), 1); - SG_CHECK_EQUAL(oldThumbUrls.at(0), "http://foo.bar.com/thumb-exterior.png"); - - string_list oldThumbPaths = p2->thumbnails(); - SG_CHECK_EQUAL(oldThumbPaths.size(), 1); - SG_CHECK_EQUAL(oldThumbPaths.at(0), "exterior.png"); +// thumbnails + const pkg::Package::Thumbnail& thumb = p2->thumbnailForVariant(0); + SG_CHECK_EQUAL(thumb.url, "http://foo.bar.com/thumb-exterior.png"); + SG_CHECK_EQUAL(thumb.path, "exterior.png"); // test variants try { @@ -215,6 +211,9 @@ int parseTest() SG_CHECK_EQUAL(index->url, "http://foo.bar.com/thumb-exterior-skis.png"); SG_VERIFY(index->type == pkg::Package::Preview::Type::EXTERIOR); + const pkg::Package::Thumbnail& thumb2 = p2->thumbnailForVariant(floatsVariant); + SG_CHECK_EQUAL(thumb2.url, "http://foo.bar.com/thumb-floats.png"); + SG_CHECK_EQUAL(thumb2.path, "thumb-floats.png"); // test filtering / searching too string_set tags(p2->tags()); diff --git a/simgear/package/Install.cxx b/simgear/package/Install.cxx index a365b46a..ed521066 100644 --- a/simgear/package/Install.cxx +++ b/simgear/package/Install.cxx @@ -455,33 +455,6 @@ void Install::cancelDownload() m_package->catalog()->root()->cancelDownload(this); } -struct PathAppender -{ - PathAppender(const SGPath& p) : m_path(p) {} - - SGPath operator()(const std::string& s) const - { - SGPath p(m_path); - p.append(s); - return p; - } - - SGPath m_path; -}; - -PathList Install::thumbnailPaths() const -{ - const string_list& thumbs(m_package->thumbnails()); - PathList result; - if (thumbs.empty()) - return result; - - std::transform(thumbs.begin(), thumbs.end(), - std::back_inserter(result), - PathAppender(m_path)); - return result; -} - SGPath Install::primarySetPath() const { SGPath setPath(m_path); diff --git a/simgear/package/Install.hxx b/simgear/package/Install.hxx index 4e198eba..fd4e5d8c 100644 --- a/simgear/package/Install.hxx +++ b/simgear/package/Install.hxx @@ -98,13 +98,6 @@ public: */ void cancelDownload(); - /** - * return the thumbnails associated with this install, but as locations - * on the file system, not URLs. It is assumed the order of thumbnails - * is consistent with the URLs returned from Package::thumbnailUrls() - */ - PathList thumbnailPaths() const; - /** * Set the handler to be called when the installation successfully * completes. diff --git a/simgear/package/Package.cxx b/simgear/package/Package.cxx index 9748d328..1556c4af 100644 --- a/simgear/package/Package.cxx +++ b/simgear/package/Package.cxx @@ -274,28 +274,12 @@ SGPropertyNode* Package::properties() const string_list Package::thumbnailUrls() const { - string_list r; - if (!m_props) { - return r; + string_list urls; + const Thumbnail& thumb(thumbnailForVariant(0)); + if (!thumb.url.empty()) { + urls.push_back(thumb.url); } - - BOOST_FOREACH(SGPropertyNode* dl, m_props->getChildren("thumbnail")) { - r.push_back(dl->getStringValue()); - } - return r; -} - -string_list Package::thumbnails() const -{ - string_list r; - if (!m_props) { - return r; - } - - BOOST_FOREACH(SGPropertyNode* dl, m_props->getChildren("thumbnail-path")) { - r.push_back(dl->getStringValue()); - } - return r; + return urls; } string_list Package::downloadUrls() const @@ -429,6 +413,17 @@ SGPropertyNode_ptr Package::propsForVariant(const unsigned int vIndex, const cha throw sg_exception("Unknow variant in package " + id()); } +Package::Thumbnail Package::thumbnailForVariant(unsigned int vIndex) const +{ + SGPropertyNode_ptr var = propsForVariant(vIndex); + // allow for variants without distinct thumbnails + if (!var->hasChild("thumbnail") || !var->hasChild("thumbnail-path")) { + var = m_props; + } + + return {var->getStringValue("thumbnail"), var->getStringValue("thumbnail-path")}; +} + Package::PreviewVec Package::previewsForVariant(unsigned int vIndex) const { SGPropertyNode_ptr var = propsForVariant(vIndex); diff --git a/simgear/package/Package.hxx b/simgear/package/Package.hxx index e4c0704b..54dd4667 100644 --- a/simgear/package/Package.hxx +++ b/simgear/package/Package.hxx @@ -131,13 +131,15 @@ public: * download URLs for the package */ string_list downloadUrls() const; - string_list thumbnailUrls() const; - - /** - * thumbnail file paths within the package on disk - */ - string_list thumbnails() const; + + struct Thumbnail + { + std::string url; + std::string path; + }; + + Thumbnail thumbnailForVariant(unsigned int vIndex) const; /** * information about a preview image diff --git a/simgear/package/catalogTest1/catalog.xml b/simgear/package/catalogTest1/catalog.xml index 3d811e86..b226ca3d 100644 --- a/simgear/package/catalogTest1/catalog.xml +++ b/simgear/package/catalogTest1/catalog.xml @@ -89,6 +89,9 @@ thumb-panel.png http://foo.bar.com/thumb-panel.png + + http://foo.bar.com/thumb-floats.png + thumb-floats.png @@ -112,7 +115,6 @@ ec0e2ffdf98d6a5c05c77445e5447ff5 http://localhost:2000/catalogTest1/c172p.zip - http://foo.bar.com/thumb-exterior.png exterior.png