Permalink
Browse files

media library: integrate grouping by sets

  • Loading branch information...
Montellese committed Sep 12, 2012
1 parent a88a8e7 commit fc44e6f9914231e013ba2799ddbc512de0145fd3
@@ -71,6 +71,7 @@
#include "URL.h"
#include "utils/EdenVideoArtUpdater.h"
#include "GUIInfoManager.h"
+#include "utils/GroupUtils.h"
using namespace std;
using namespace XFILE;
@@ -1839,8 +1840,24 @@ bool CGUIWindowVideoBase::StackingAvailable(const CFileItemList &items) const
url.GetProtocol() == "playlistvideo");
}
-void CGUIWindowVideoBase::OnPrepareFileItems(CFileItemList &items)
+void CGUIWindowVideoBase::GetGroupedItems(CFileItemList &items)
{
+ CGUIMediaWindow::GetGroupedItems(items);
+
+ CQueryParams params;
+ CVideoDatabaseDirectory dir;
+ dir.GetQueryParams(items.GetPath(), params);
+ if (items.GetContent().Equals("movies") && params.GetSetId() <= 0 &&
+ CVideoDatabaseDirectory::GetDirectoryChildType(items.GetPath()) != NODE_TYPE_RECENTLY_ADDED_MOVIES &&
+ g_guiSettings.GetBool("videolibrary.groupmoviesets"))
+ {
+ CFileItemList groupedItems;
+ if (GroupUtils::Group(GroupBySet, items, groupedItems, GroupAttributeIgnoreSingleItems))
+ {
+ items.ClearItems();
+ items.Append(groupedItems);
+ }
+ }
}
bool CGUIWindowVideoBase::CheckFilterAdvanced(CFileItemList &items) const
@@ -88,7 +88,7 @@ class CGUIWindowVideoBase : public CGUIMediaWindow, public IBackgroundLoaderObse
virtual bool Update(const CStdString &strDirectory, bool updateFilterPath = true);
virtual bool GetDirectory(const CStdString &strDirectory, CFileItemList &items);
virtual void OnItemLoaded(CFileItem* pItem) {};
- virtual void OnPrepareFileItems(CFileItemList &items);
+ virtual void GetGroupedItems(CFileItemList &items);
virtual bool CheckFilterAdvanced(CFileItemList &items) const;
virtual bool CanContainFilter(const CStdString &strDirectory) const;
@@ -537,23 +537,14 @@ void CGUIWindowVideoNav::UpdateButtons()
bool CGUIWindowVideoNav::GetFilteredItems(const CStdString &filter, CFileItemList &items)
{
- bool listchanged = false;
- bool updateItems = false;
- if (!m_canFilterAdvanced)
- listchanged = CGUIMediaWindow::GetFilteredItems(filter, items);
- else
- listchanged = CGUIMediaWindow::GetAdvanceFilteredItems(items, updateItems);
-
+ bool listchanged = CGUIMediaWindow::GetFilteredItems(filter, items);
listchanged |= ApplyWatchedFilter(items);
// there are new items so we need to run the thumbloader
- if (updateItems)
- {
- if (m_thumbLoader.IsLoading())
- m_thumbLoader.StopThread();
+ if (m_thumbLoader.IsLoading())
+ m_thumbLoader.StopThread();
- m_thumbLoader.Load(items);
- }
+ m_thumbLoader.Load(items);
return listchanged;
}
@@ -617,10 +617,6 @@ void CGUIMediaWindow::SortItems(CFileItemList &items)
if (!sorted)
items.Sort(sortMethod, guiState->GetDisplaySortOrder());
-
- // Should these items be saved to the hdd
- if (items.CacheToDiscAlways() && !IsFiltered())
- items.Save(GetID());
}
}
@@ -657,8 +653,9 @@ void CGUIMediaWindow::FormatAndSort(CFileItemList &items)
LABEL_MASKS labelMasks;
viewState->GetSortMethodLabelMasks(labelMasks);
FormatItemLabels(items, labelMasks);
+
+ items.Sort(viewState->GetSortMethod(), viewState->GetDisplaySortOrder());
}
- SortItems(items);
}
/*!
@@ -892,7 +889,16 @@ bool CGUIMediaWindow::Update(const CStdString &strDirectory, bool updateFilterPa
m_guiState.reset(CGUIViewState::GetViewState(GetID(), *m_vecItems));
- FormatAndSort(*m_vecItems);
+ // remember the original (untouched) list of items (for filtering etc)
+ m_unfilteredItems->SetPath(m_vecItems->GetPath()); // use the original path - it'll likely be relied on for other things later.
+ m_unfilteredItems->Append(*m_vecItems);
+
+ // Cache the list of items if possible
+ OnCacheFileItems(*m_vecItems);
+
+ // Filter and group the items if necessary
+ CStdString titleFilter = GetProperty("filter").asString();
+ OnFilterItems(titleFilter);
// Ask the devived class if it wants to do custom list operations,
// eg. changing the label
@@ -968,17 +974,22 @@ void CGUIMediaWindow::OnPrepareFileItems(CFileItemList &items)
}
+// \brief This function will be called by Update() before
+// any additional formatting, filtering or sorting is applied.
+// Override this function to define a custom caching behaviour.
+void CGUIMediaWindow::OnCacheFileItems(CFileItemList &items)
+{
+ // Should these items be saved to the hdd
+ if (items.CacheToDiscAlways() && !IsFiltered())
+ items.Save(GetID());
+}
+
// \brief This function will be called by Update() after the
// labels of the fileitems are formatted. Override this function
// to modify the fileitems. Eg. to modify the item label
void CGUIMediaWindow::OnFinalizeFileItems(CFileItemList &items)
{
- m_unfilteredItems->SetPath(items.GetPath()); // use the original path - it'll likely be relied on for other things later.
- m_unfilteredItems->Append(items);
-
- CStdString filter(GetProperty("filter").asString());
- OnFilterItems(filter);
}
// \brief With this function you can react on a users click in the list/thumb panel.
@@ -1695,24 +1706,52 @@ void CGUIMediaWindow::OnFilterItems(const CStdString &filter)
CFileItemList items(m_vecItems->GetPath()); // use the original path - it'll likely be relied on for other things later.
items.Append(*m_unfilteredItems);
- if (GetFilteredItems(filter, items) || m_vecItems->Size() != items.Size())
+ bool filtered = GetFilteredItems(filter, items);
+
+ m_vecItems->ClearItems();
+ // we need to clear the sort state and re-sort the items
+ m_vecItems->ClearSortState();
+ m_vecItems->Append(items);
+
+ // if the filter has changed, get the new filter path
+ if (filtered && m_canFilterAdvanced)
{
- m_vecItems->ClearItems();
- m_vecItems->Append(items);
+ if (items.HasProperty(PROPERTY_PATH_DB))
+ m_strFilterPath = items.GetProperty(PROPERTY_PATH_DB).asString();
+ else
+ m_strFilterPath = items.GetPath();
+ }
+
+ GetGroupedItems(*m_vecItems);
+ FormatAndSort(*m_vecItems);
- // we need to clear the sort state and re-sort the items
- m_vecItems->ClearSortState();
- SortItems(*m_vecItems);
+ // get the "filter" option
+ CStdString filterOption;
+ CURL filterUrl(m_strFilterPath);
+ if (filterUrl.HasOption("filter"))
+ filterOption = filterUrl.GetOption("filter");
+
+ // apply the "filter" option to any folder item so that
+ // the filter can be passed down to the sub-directory
+ for (int index = 0; index < m_vecItems->Size(); index++)
+ {
+ CFileItemPtr pItem = m_vecItems->Get(index);
+ // if the item is a folder we need to copy the path of
+ // the filtered item to be able to keep the applied filters
+ if (pItem->m_bIsFolder)
+ {
+ CURL itemUrl(pItem->GetPath());
+ itemUrl.SetOption("filter", filterOption);
+ pItem->SetPath(itemUrl.Get());
+ }
+ }
+ if (filtered)
+ {
if (!m_canFilterAdvanced)
SetProperty("filter", filter);
else
{
- if (items.HasProperty(PROPERTY_PATH_DB))
- m_strFilterPath = items.GetProperty(PROPERTY_PATH_DB).asString();
- else
- m_strFilterPath = items.GetPath();
-
// to be able to select the same item as before we need to adjust
// the path of the item i.e. add or remove the "filter=" URL option
// but that's only necessary for folder items
@@ -1738,10 +1777,7 @@ void CGUIMediaWindow::OnFilterItems(const CStdString &filter)
bool CGUIMediaWindow::GetFilteredItems(const CStdString &filter, CFileItemList &items)
{
if (m_canFilterAdvanced)
- {
- bool hasNewItems;
- return GetAdvanceFilteredItems(items, hasNewItems);
- }
+ return GetAdvanceFilteredItems(items);
CStdString trimmedFilter(filter);
trimmedFilter.TrimLeft().ToLower();
@@ -1786,10 +1822,8 @@ bool CGUIMediaWindow::GetFilteredItems(const CStdString &filter, CFileItemList &
return items.GetObjectCount() > 0;
}
-bool CGUIMediaWindow::GetAdvanceFilteredItems(CFileItemList &items, bool &hasNewItems)
+bool CGUIMediaWindow::GetAdvanceFilteredItems(CFileItemList &items)
{
- hasNewItems = false;
-
// don't run the advanced filter if the filter is empty
// and there hasn't been a filter applied before which
// would have to be removed
@@ -1831,11 +1865,6 @@ bool CGUIMediaWindow::GetAdvanceFilteredItems(CFileItemList &items, bool &hasNew
map<CStdString, CFileItemPtr>::iterator itItem = lookup.find(path);
if (itItem != lookup.end())
{
- // if the item is a folder we need to copy the path of
- // the filtered item to be able to keep the applied filters
- if (item->m_bIsFolder)
- item->SetPath(itItem->second->GetPath());
-
// add the item to the list of filtered items
filteredItems.Add(item);
@@ -1846,10 +1875,7 @@ bool CGUIMediaWindow::GetAdvanceFilteredItems(CFileItemList &items, bool &hasNew
}
if (resultItems.Size() > 0)
- {
- filteredItems.Append(resultItems);
- hasNewItems = true;
- }
+ CLog::Log(LOGWARNING, "CGUIMediaWindow::GetAdvanceFilteredItems(): %d unknown items", resultItems.Size());
items.ClearItems();
items.Append(filteredItems);
@@ -86,7 +86,9 @@ class CGUIMediaWindow : public CGUIWindow
virtual bool Refresh(bool clearCache = false);
virtual void FormatAndSort(CFileItemList &items);
virtual void OnPrepareFileItems(CFileItemList &items);
+ virtual void OnCacheFileItems(CFileItemList &items);
virtual void OnFinalizeFileItems(CFileItemList &items);
+ virtual void GetGroupedItems(CFileItemList &items) { }
void ClearFileItems();
virtual void SortItems(CFileItemList &items);
@@ -123,7 +125,7 @@ class CGUIMediaWindow : public CGUIWindow
which were not present in the original list
\sa GetFilteredItems
*/
- virtual bool GetAdvanceFilteredItems(CFileItemList &items, bool &hasNewItems);
+ virtual bool GetAdvanceFilteredItems(CFileItemList &items);
// check for a disc or connection
virtual bool HaveDiscOrConnection(const CStdString& strPath, int iDriveType);

0 comments on commit fc44e6f

Please sign in to comment.