Permalink
Browse files

[art] use a fallback map for art to generalise the fallback for the '…

…thumb' type, and set outside of CGUIListItem
  • Loading branch information...
1 parent 084d061 commit 49a3662df9d7ec7fcefbb89b675a93cd0a198a23 Jonathan Marshall committed Nov 10, 2012
@@ -119,24 +119,21 @@ void CGUIListItem::SetArt(const std::string &type, const std::string &url)
}
}
-void CGUIListItem::SetArt(const ArtMap &art, bool setFallback /* = true */)
+void CGUIListItem::SetArt(const ArtMap &art)
{
m_art = art;
- // ensure that the fallback "thumb" is available
- if (setFallback && m_art.find("thumb") == m_art.end())
- {
- if (HasArt("poster"))
- m_art["thumb"] = m_art["poster"];
- else if (HasArt("banner"))
- m_art["thumb"] = m_art["banner"];
- }
-
SetInvalid();
}
+void CGUIListItem::SetArtFallback(const std::string &from, const std::string &to)
+{
+ m_artFallbacks[from] = to;
+}
+
void CGUIListItem::ClearArt()
{
m_art.clear();
+ m_artFallbacks.clear();
}
void CGUIListItem::AppendArt(const ArtMap &art)
@@ -150,6 +147,13 @@ std::string CGUIListItem::GetArt(const std::string &type) const
ArtMap::const_iterator i = m_art.find(type);
if (i != m_art.end())
return i->second;
+ i = m_artFallbacks.find(type);
+ if (i != m_artFallbacks.end())
+ {
+ ArtMap::const_iterator j = m_art.find(i->second);
+ if (j != m_art.end())
+ return j->second;
+ }
return "";
}
@@ -160,8 +164,7 @@ const CGUIListItem::ArtMap &CGUIListItem::GetArt() const
bool CGUIListItem::HasArt(const std::string &type) const
{
- ArtMap::const_iterator i = m_art.find(type);
- return (i != m_art.end() && !i->second.empty());
+ return !GetArt(type).empty();
}
void CGUIListItem::SetIconImage(const CStdString& strIcon)
@@ -244,6 +247,7 @@ const CGUIListItem& CGUIListItem::operator =(const CGUIListItem& item)
m_bIsFolder = item.m_bIsFolder;
m_mapProperties = item.m_mapProperties;
m_art = item.m_art;
+ m_artFallbacks = item.m_artFallbacks;
SetInvalid();
return *this;
}
@@ -271,6 +275,12 @@ void CGUIListItem::Archive(CArchive &ar)
ar << i->first;
ar << i->second;
}
+ ar << (int)m_artFallbacks.size();
@jmarshallnz

jmarshallnz Nov 12, 2012

Owner

Yeah - I always say the same thing and never get around to it :p

+ for (ArtMap::const_iterator i = m_artFallbacks.begin(); i != m_artFallbacks.end(); i++)
+ {
+ ar << i->first;
+ ar << i->second;
+ }
}
else
{
@@ -303,6 +313,14 @@ void CGUIListItem::Archive(CArchive &ar)
ar >> value;
m_art.insert(make_pair(key, value));
}
+ ar >> mapSize;
+ for (int i = 0; i < mapSize; i++)
+ {
+ std::string key, value;
+ ar >> key;
+ ar >> value;
+ m_artFallbacks.insert(make_pair(key, value));
+ }
}
}
void CGUIListItem::Serialize(CVariant &value)
View
@@ -85,17 +85,23 @@ class CGUIListItem
/*! \brief set artwork for an item
\param art a type:url map for artwork
- \param setFallback whether to set the "thumb" fallback, defaults to true.
\sa GetArt
*/
- void SetArt(const ArtMap &art, bool setFallback = true);
+ void SetArt(const ArtMap &art);
/*! \brief append artwork to an item
\param art a type:url map for artwork
\sa GetArt
*/
void AppendArt(const ArtMap &art);
+ /*! \brief set a fallback image for art
+ \param from the type to fallback from
+ \param to the type to fallback to
+ \sa SetArt
+ */
+ void SetArtFallback(const std::string &from, const std::string &to);
+
/*! \brief clear art on an item
\sa SetArt
*/
@@ -191,6 +197,7 @@ class CGUIListItem
CStdString m_strLabel; // text of column1
ArtMap m_art;
+ ArtMap m_artFallbacks;
};
#endif
@@ -1239,7 +1239,7 @@ namespace VIDEO
for (CGUIListItem::ArtMap::const_iterator i = art.begin(); i != art.end(); ++i)
CTextureCache::Get().BackgroundCacheImage(i->second);
- pItem->SetArt(art, false); // don't set fallbacks
+ pItem->SetArt(art);
// parent folder to apply the thumb to and to search for local actor thumbs
CStdString parentDir = GetParentDir(*pItem);
@@ -248,7 +248,7 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
artwork.insert(make_pair(type, art));
}
}
- pItem->SetArt(artwork);
+ SetArt(*pItem, artwork);
}
// thumbnails are special-cased due to auto-generation
@@ -298,6 +298,18 @@ bool CVideoThumbLoader::LoadItem(CFileItem* pItem)
return true;
}
+void CVideoThumbLoader::SetArt(CFileItem &item, const map<string, string> &artwork)
+{
+ item.SetArt(artwork);
+ if (artwork.find("thumb") == artwork.end())
+ { // set fallback for "thumb"
+ if (artwork.find("poster") != artwork.end())
+ item.SetArtFallback("thumb", "poster");
+ else if (artwork.find("poster") != artwork.end())
+ item.SetArtFallback("thumb", "banner");
+ }
+}
+
bool CVideoThumbLoader::FillLibraryArt(CFileItem &item)
{
CVideoInfoTag &tag = *item.GetVideoInfoTag();
@@ -306,7 +318,7 @@ bool CVideoThumbLoader::FillLibraryArt(CFileItem &item)
map<string, string> artwork;
m_database->Open();
if (m_database->GetArtForItem(tag.m_iDbId, tag.m_type, artwork))
- item.SetArt(artwork);
+ SetArt(item, artwork);
else if (tag.m_type == "artist")
{ // we retrieve music video art from the music database (no backward compat)
CMusicDatabase database;
@@ -121,6 +121,8 @@ class CVideoThumbLoader : public CThumbLoader, public CJobQueue
virtual void OnLoaderStart();
virtual void OnLoaderFinish();
+ void SetArt(CFileItem &item, const std::map<std::string, std::string> &artwork);
+
IStreamDetailsObserver *m_pStreamDetailsObs;
CVideoDatabase *m_database;
typedef std::map<int, std::map<std::string, std::string> > ArtCache;

0 comments on commit 49a3662

Please sign in to comment.