diff options
author | ksooo <3226626+ksooo@users.noreply.github.com> | 2023-09-23 22:21:04 +0200 |
---|---|---|
committer | ksooo <3226626+ksooo@users.noreply.github.com> | 2023-09-24 21:47:59 +0200 |
commit | 5c9afe3990ab481825d36f1ed63af418ff3d2d82 (patch) | |
tree | 6aed6e54fcf58804da28ad9a3cea441e72853347 | |
parent | bddd6960f0588c74986c2a22d3fa6db2be182e4e (diff) |
[listproviders] Add attribute 'browse' to give skinners the possibility to control the 'more' button for a list.
-rw-r--r-- | addons/skin.estuary/xml/Home.xml | 5 | ||||
-rw-r--r-- | addons/skin.estuary/xml/Includes_Home.xml | 15 | ||||
-rw-r--r-- | xbmc/listproviders/DirectoryProvider.cpp | 45 | ||||
-rw-r--r-- | xbmc/listproviders/DirectoryProvider.h | 12 |
4 files changed, 66 insertions, 11 deletions
diff --git a/addons/skin.estuary/xml/Home.xml b/addons/skin.estuary/xml/Home.xml index cf89675000..66eab452da 100644 --- a/addons/skin.estuary/xml/Home.xml +++ b/addons/skin.estuary/xml/Home.xml @@ -80,6 +80,7 @@ <param name="content_path" value="special://skin/playlists/random_movies.xsp"/> <param name="widget_header" value="$LOCALIZE[31006]"/> <param name="widget_target" value="videos"/> + <param name="browse_mode" value="never"/> <param name="list_id" value="5400"/> </include> <include content="WidgetListCategories" condition="Library.HasContent(movies)"> @@ -214,6 +215,7 @@ <param name="content_path" value="special://skin/playlists/random_albums.xsp"/> <param name="widget_header" value="$LOCALIZE[31012]"/> <param name="widget_target" value="music"/> + <param name="browse_mode" value="never"/> <param name="list_id" value="7300"/> <param name="fallback_icon" value="DefaultMusicAlbums.png"/> <param name="onclick_condition" value="true"/> @@ -223,6 +225,7 @@ <param name="content_path" value="special://skin/playlists/random_artists.xsp"/> <param name="widget_header" value="$LOCALIZE[31013]"/> <param name="widget_target" value="music"/> + <param name="browse_mode" value="never"/> <param name="list_id" value="7400"/> <param name="fallback_icon" value="DefaultMusicArtists.png"/> </include> @@ -739,6 +742,7 @@ <param name="content_path" value="special://skin/playlists/random_musicvideo_artists.xsp"/> <param name="widget_header" value="$LOCALIZE[31013]"/> <param name="widget_target" value="music"/> + <param name="browse_mode" value="never"/> <param name="list_id" value="16200"/> <param name="widget_limit" value="10"/> </include> @@ -756,6 +760,7 @@ <param name="content_path" value="special://skin/playlists/random_musicvideos.xsp"/> <param name="widget_header" value="$LOCALIZE[31152]"/> <param name="widget_target" value="videos"/> + <param name="browse_mode" value="never"/> <param name="fallback_image" value="DefaultMusicSongs.png" /> <param name="list_id" value="16500"/> </include> diff --git a/addons/skin.estuary/xml/Includes_Home.xml b/addons/skin.estuary/xml/Includes_Home.xml index 7924a46f0e..753e184082 100644 --- a/addons/skin.estuary/xml/Includes_Home.xml +++ b/addons/skin.estuary/xml/Includes_Home.xml @@ -27,6 +27,7 @@ </include> <include name="WidgetListPoster"> <param name="onclick_condition">false</param> + <param name="browse_mode">auto</param> <definition> <include content="CategoryLabel"> <param name="label">$PARAM[widget_header]</param> @@ -71,7 +72,7 @@ </include> </control> </focusedlayout> - <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="15">$PARAM[content_path]</content> + <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="15" browse="$PARAM[browse_mode]">$PARAM[content_path]</content> </control> </definition> </include> @@ -154,6 +155,7 @@ <param name="visible">True</param> <param name="sortorder">ascending</param> <param name="widget_limit">15</param> + <param name="browse_mode">auto</param> <definition> <include content="CategoryLabel"> <param name="label">$PARAM[widget_header]</param> @@ -204,7 +206,7 @@ </include> </control> </focusedlayout> - <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[widget_limit]">$PARAM[content_path]</content> + <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[widget_limit]" browse="$PARAM[browse_mode]">$PARAM[content_path]</content> </control> </definition> </include> @@ -216,6 +218,7 @@ <param name="widget_limit">15</param> <param name="fallback_icon">DefaultAudio.png</param> <param name="onclick_condition">false</param> + <param name="browse_mode">auto</param> <definition> <include content="CategoryLabel"> <param name="label">$PARAM[widget_header]</param> @@ -267,7 +270,7 @@ </include> </control> </focusedlayout> - <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[widget_limit]">$PARAM[content_path]</content> + <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[widget_limit]" browse="$PARAM[browse_mode]">$PARAM[content_path]</content> </control> </definition> </include> @@ -278,6 +281,7 @@ <param name="additional_movie_items">false</param> <param name="additional_tvshow_items">false</param> <param name="visible">true</param> + <param name="browse">auto</param> <definition> <include content="CategoryLabel"> <param name="label">$PARAM[widget_header]</param> @@ -374,7 +378,7 @@ </control> </control> </focusedlayout> - <content target="$PARAM[widget_target]" limit="$PARAM[item_limit]">$PARAM[content_path]</content> + <content target="$PARAM[widget_target]" limit="$PARAM[item_limit]" browse="$PARAM[browse_mode]">$PARAM[content_path]</content> <include condition="$PARAM[additional_movie_items]" content="MovieSubmenuItems" /> <include condition="$PARAM[additional_tvshow_items]" content="TVShowSubmenuItems" /> </control> @@ -412,6 +416,7 @@ <param name="label">$INFO[ListItem.Label]</param> <param name="label2">$INFO[ListItem.Title]</param> <param name="info_update">0</param> + <param name="browse_mode">auto</param> <definition> <include content="CategoryLabel"> <param name="label">$PARAM[widget_header]</param> @@ -616,7 +621,7 @@ </control> </control> </focusedlayout> - <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[item_limit]">$PARAM[content_path]</content> + <content sortby="$PARAM[sortby]" sortorder="$PARAM[sortorder]" target="$PARAM[widget_target]" limit="$PARAM[item_limit]" browse="$PARAM[browse_mode]">$PARAM[content_path]</content> </control> </definition> </include> diff --git a/xbmc/listproviders/DirectoryProvider.cpp b/xbmc/listproviders/DirectoryProvider.cpp index 76135d4ac7..0062f82054 100644 --- a/xbmc/listproviders/DirectoryProvider.cpp +++ b/xbmc/listproviders/DirectoryProvider.cpp @@ -55,8 +55,14 @@ public: const std::string& target, SortDescription sort, int limit, + CDirectoryProvider::BrowseMode browse, int parentID) - : m_url(url), m_target(target), m_sort(sort), m_limit(limit), m_parentID(parentID) + : m_url(url), + m_target(target), + m_sort(sort), + m_limit(limit), + m_browse(browse), + m_parentID(parentID) { } ~CDirectoryJob() override = default; @@ -102,9 +108,10 @@ public: if (items.HasProperty("node.target")) m_target = items.GetProperty("node.target").asString(); - if (limit < items.Size()) + if ((m_browse == CDirectoryProvider::BrowseMode::ALWAYS && !items.IsEmpty()) || + (m_browse == CDirectoryProvider::BrowseMode::AUTO && limit < items.Size())) { - // Add a special item to the end of the limited list, which can be used to open the + // Add a special item to the end of the list, which can be used to open the // full listing containg all items in the given target window. if (!m_target.empty()) { @@ -174,6 +181,7 @@ private: std::string m_target; SortDescription m_sort; unsigned int m_limit; + CDirectoryProvider::BrowseMode m_browse{CDirectoryProvider::BrowseMode::AUTO}; int m_parentID; std::vector<CGUIStaticItemPtr> m_items; std::map<InfoTagType, std::shared_ptr<CThumbLoader> > m_thumbloaders; @@ -201,6 +209,10 @@ CDirectoryProvider::CDirectoryProvider(const TiXmlElement* element, int parentID if (limit) m_limit.SetLabel(limit, "", parentID); + const char* browse = element->Attribute("browse"); + if (browse) + m_browse.SetLabel(browse, "", parentID); + m_url.SetLabel(element->FirstChild()->ValueStr(), "", parentID); } } @@ -213,10 +225,12 @@ CDirectoryProvider::CDirectoryProvider(const CDirectoryProvider& other) m_sortMethod(other.m_sortMethod), m_sortOrder(other.m_sortOrder), m_limit(other.m_limit), + m_browse(other.m_browse), m_currentUrl(other.m_currentUrl), m_currentTarget(other.m_currentTarget), m_currentSort(other.m_currentSort), - m_currentLimit(other.m_currentLimit) + m_currentLimit(other.m_currentLimit), + m_currentBrowse(other.m_currentBrowse) { } @@ -240,6 +254,7 @@ bool CDirectoryProvider::Update(bool forceRefresh) fireJob |= UpdateURL(); fireJob |= UpdateSort(); fireJob |= UpdateLimit(); + fireJob |= UpdateBrowse(); fireJob &= !m_currentUrl.empty(); std::unique_lock<CCriticalSection> lock(m_section); @@ -257,7 +272,7 @@ bool CDirectoryProvider::Update(bool forceRefresh) CServiceBroker::GetJobManager()->CancelJob(m_jobID); m_jobID = CServiceBroker::GetJobManager()->AddJob( new CDirectoryJob(m_currentUrl, m_target.GetLabel(m_parentID, false), m_currentSort, - m_currentLimit, m_parentID), + m_currentLimit, m_currentBrowse, m_parentID), this); } @@ -387,6 +402,7 @@ void CDirectoryProvider::Reset() m_currentSort.sortBy = SortByNone; m_currentSort.sortOrder = SortOrderAscending; m_currentLimit = 0; + m_currentBrowse = BrowseMode::AUTO; m_updateState = OK; } @@ -588,6 +604,25 @@ bool CDirectoryProvider::UpdateLimit() return true; } +bool CDirectoryProvider::UpdateBrowse() +{ + std::unique_lock<CCriticalSection> lock(m_section); + const std::string stringValue{m_browse.GetLabel(m_parentID, false)}; + BrowseMode value{m_currentBrowse}; + if (StringUtils::EqualsNoCase(stringValue, "always")) + value = BrowseMode::ALWAYS; + else if (StringUtils::EqualsNoCase(stringValue, "auto")) + value = BrowseMode::AUTO; + else if (StringUtils::EqualsNoCase(stringValue, "never")) + value = BrowseMode::NEVER; + + if (value == m_currentBrowse) + return false; + + m_currentBrowse = value; + return true; +} + bool CDirectoryProvider::UpdateSort() { std::unique_lock<CCriticalSection> lock(m_section); diff --git a/xbmc/listproviders/DirectoryProvider.h b/xbmc/listproviders/DirectoryProvider.h index c32a0f189e..9a17aaae77 100644 --- a/xbmc/listproviders/DirectoryProvider.h +++ b/xbmc/listproviders/DirectoryProvider.h @@ -50,6 +50,13 @@ public: DONE } UpdateState; + enum class BrowseMode + { + NEVER, + AUTO, // add browse item if list is longer than given limit + ALWAYS + }; + CDirectoryProvider(const TiXmlElement *element, int parentID); explicit CDirectoryProvider(const CDirectoryProvider& other); ~CDirectoryProvider() override; @@ -80,10 +87,12 @@ private: KODI::GUILIB::GUIINFO::CGUIInfoLabel m_sortMethod; KODI::GUILIB::GUIINFO::CGUIInfoLabel m_sortOrder; KODI::GUILIB::GUIINFO::CGUIInfoLabel m_limit; + KODI::GUILIB::GUIINFO::CGUIInfoLabel m_browse; std::string m_currentUrl; std::string m_currentTarget; ///< \brief node.target property on the list as a whole SortDescription m_currentSort; - unsigned int m_currentLimit = 0; + unsigned int m_currentLimit{0}; + BrowseMode m_currentBrowse{BrowseMode::AUTO}; std::vector<CGUIStaticItemPtr> m_items; std::vector<InfoTagType> m_itemTypes; mutable CCriticalSection m_section; @@ -91,6 +100,7 @@ private: bool UpdateURL(); bool UpdateLimit(); bool UpdateSort(); + bool UpdateBrowse(); void OnAddonEvent(const ADDON::AddonEvent& event); void OnAddonRepositoryEvent(const ADDON::CRepositoryUpdater::RepositoryUpdated& event); void OnPVRManagerEvent(const PVR::PVREvent& event); |