Packages allows thumbnails per variant.
Change API for thumbnail access, so each variant can have a unique thumbnail alongside other data. Map existing catalog XML format to this system.
This commit is contained in:
parent
b88aa46e1c
commit
9c9e4e86e7
@ -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());
|
||||
|
@ -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);
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -89,6 +89,9 @@
|
||||
<path>thumb-panel.png</path>
|
||||
<url>http://foo.bar.com/thumb-panel.png</url>
|
||||
</preview>
|
||||
|
||||
<thumbnail>http://foo.bar.com/thumb-floats.png</thumbnail>
|
||||
<thumbnail-path>thumb-floats.png</thumbnail-path>
|
||||
</variant>
|
||||
|
||||
<variant>
|
||||
@ -112,7 +115,6 @@
|
||||
<md5>ec0e2ffdf98d6a5c05c77445e5447ff5</md5>
|
||||
<url>http://localhost:2000/catalogTest1/c172p.zip</url>
|
||||
|
||||
<!-- legacy thumbnails also supported -->
|
||||
<thumbnail>http://foo.bar.com/thumb-exterior.png</thumbnail>
|
||||
<thumbnail-path>exterior.png</thumbnail-path>
|
||||
</package>
|
||||
|
Loading…
Reference in New Issue
Block a user