Permalink
Browse files

Merge pull request #1418 from Montellese/grouping

grouping by movie set outside of the database
  • Loading branch information...
2 parents 158aac0 + 8c517ac commit fc0d58b64dc753121c50598b8312bd8ca611b71e Arne Morten Kvarving committed Nov 12, 2012
@@ -1249,6 +1249,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Testsuite|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release (DirectX)|Win32'">true</ExcludedFromBuild>
</ClCompile>
+ <ClCompile Include="..\..\xbmc\utils\GroupUtils.cpp" />
<ClCompile Include="..\..\xbmc\utils\HTMLTable.cpp" />
<ClCompile Include="..\..\xbmc\utils\HTMLUtil.cpp" />
<ClCompile Include="..\..\xbmc\utils\HttpHeader.cpp" />
@@ -2395,6 +2396,7 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug Testsuite|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release (DirectX)|Win32'">true</ExcludedFromBuild>
</ClInclude>
+ <ClInclude Include="..\..\xbmc\utils\GroupUtils.h" />
<ClInclude Include="..\..\xbmc\utils\HTMLTable.h" />
<ClInclude Include="..\..\xbmc\utils\HTMLUtil.h" />
<ClInclude Include="..\..\xbmc\utils\HttpHeader.h" />
@@ -2942,6 +2942,9 @@
<ClCompile Include="..\..\xbmc\filesystem\HTTPFile.cpp">
<Filter>filesystem</Filter>
</ClCompile>
+ <ClCompile Include="..\..\xbmc\utils\GroupUtils.cpp">
+ <Filter>utils</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\xbmc\win32\pch.h">
@@ -5749,6 +5752,9 @@
<ClInclude Include="..\..\xbmc\filesystem\HTTPFile.h">
<Filter>filesystem</Filter>
</ClInclude>
+ <ClInclude Include="..\..\xbmc\utils\GroupUtils.h">
+ <Filter>utils</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\xbmc\win32\XBMC_PC.rc">
@@ -114,7 +114,7 @@ namespace XFILE
videoUrl.AddOption(option, xsp);
CDatabase::Filter dbfilter;
- success = db.GetSortedVideos(mediaType, videoUrl.ToString(), sorting, items, dbfilter, true);
+ success = db.GetSortedVideos(mediaType, videoUrl.ToString(), sorting, items, dbfilter);
db.Close();
// if we retrieve a list of episodes and we didn't receive
@@ -76,7 +76,7 @@ void CEdenVideoArtUpdater::Process()
handle->SetTitle(g_localizeStrings.Get(12349));
// movies
- db.GetMoviesByWhere("videodb://1/2/", CDatabase::Filter(), items, false);
+ db.GetMoviesByWhere("videodb://1/2/", CDatabase::Filter(), items);
for (int i = 0; i < items.Size(); i++)
{
CFileItemPtr item = items[i];
View
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <map>
+#include <set>
+
+#include "GroupUtils.h"
+#include "FileItem.h"
+#include "utils/StringUtils.h"
+#include "utils/Variant.h"
+#include "video/VideoInfoTag.h"
+
+using namespace std;
+
+typedef map<int, set<CFileItemPtr> > SetMap;
+
+bool GroupUtils::Group(GroupBy groupBy, const CFileItemList &items, CFileItemList &groupedItems, GroupAttribute groupAttributes /* = GroupAttributeNone */)
+{
+ if (items.Size() <= 0 || groupBy == GroupByNone)
+ return false;
+
+ SetMap setMap;
+ for (int index = 0; index < items.Size(); index++)
+ {
+ bool add = true;
+ const CFileItemPtr item = items.Get(index);
+
+ // group by sets
+ if ((groupBy & GroupBySet) &&
+ item->HasVideoInfoTag() && item->GetVideoInfoTag()->m_iSetId > 0)
+ {
+ add = false;
+ setMap[item->GetVideoInfoTag()->m_iSetId].insert(item);
+ }
+
+ if (add)
+ groupedItems.Add(item);
+ }
+
+ if ((groupBy & GroupBySet) && setMap.size() > 0)
+ {
+ for (SetMap::const_iterator set = setMap.begin(); set != setMap.end(); set++)
+ {
+ // only one item in the set, so just re-add it
+ if (set->second.size() == 1 && (groupAttributes & GroupAttributeIgnoreSingleItems))
+ {
+ groupedItems.Add(*set->second.begin());
+ continue;
+ }
+
+ CFileItemPtr pItem(new CFileItem((*set->second.begin())->GetVideoInfoTag()->m_strSet));
+ pItem->GetVideoInfoTag()->m_iDbId = set->first;
+ pItem->GetVideoInfoTag()->m_type = "set";
+ pItem->SetPath(StringUtils::Format("videodb://1/7/%ld/", set->first));
+ pItem->m_bIsFolder = true;
+
+ CVideoInfoTag* setInfo = pItem->GetVideoInfoTag();
+ setInfo->m_strPath = pItem->GetPath();
+ setInfo->m_strTitle = pItem->GetLabel();
+
+ int ratings = 0;
+ int iWatched = 0; // have all the movies been played at least once?
+ for (std::set<CFileItemPtr>::const_iterator movie = set->second.begin(); movie != set->second.end(); movie++)
+ {
+ CVideoInfoTag* movieInfo = (*movie)->GetVideoInfoTag();
+ // handle rating
+ if (movieInfo->m_fRating > 0.0f)
+ {
+ ratings++;
+ setInfo->m_fRating += movieInfo->m_fRating;
+ }
+
+ // handle year
+ if (movieInfo->m_iYear > setInfo->m_iYear)
+ setInfo->m_iYear = movieInfo->m_iYear;
+
+ // handle lastplayed
+ if (movieInfo->m_lastPlayed.IsValid() && movieInfo->m_lastPlayed > setInfo->m_lastPlayed)
+ setInfo->m_lastPlayed = movieInfo->m_lastPlayed;
+
+ // handle dateadded
+ if (movieInfo->m_dateAdded.IsValid() && movieInfo->m_dateAdded > setInfo->m_dateAdded)
+ setInfo->m_dateAdded = movieInfo->m_dateAdded;
+
+ // handle playcount/watched
+ setInfo->m_playCount += movieInfo->m_playCount;
+ if (movieInfo->m_playCount > 0)
+ iWatched++;
+ }
+
+ if (ratings > 1)
+ pItem->GetVideoInfoTag()->m_fRating /= ratings;
+
+ setInfo->m_playCount = iWatched >= (int)set->second.size() ? (setInfo->m_playCount / set->second.size()) : 0;
+ pItem->SetProperty("total", (int)set->second.size());
+ pItem->SetProperty("watched", iWatched);
+ pItem->SetProperty("unwatched", (int)set->second.size() - iWatched);
+ pItem->SetOverlayImage(CGUIListItem::ICON_OVERLAY_UNWATCHED, setInfo->m_playCount > 0);
+
+ groupedItems.Add(pItem);
+ }
+ }
+
+ return true;
+}
+
+bool GroupUtils::GroupAndSort(GroupBy groupBy, const CFileItemList &items, const SortDescription &sortDescription, CFileItemList &groupedItems, GroupAttribute groupAttributes /* = GroupAttributeNone */)
+{
+ if (!Group(groupBy, items, groupedItems, groupAttributes))
+ return false;
+
+ groupedItems.Sort(sortDescription);
+ return true;
+}
View
@@ -0,0 +1,42 @@
+#pragma once
+/*
+ * Copyright (C) 2012 Team XBMC
+ * http://www.xbmc.org
+ *
+ * This Program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This Program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with XBMC; see the file COPYING. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "SortUtils.h"
+
+class CFileItemList;
+
+// can be used as a flag
+typedef enum {
+ GroupByNone = 0x0,
+ GroupBySet = 0x1
+} GroupBy;
+
+typedef enum {
+ GroupAttributeNone = 0x0,
+ GroupAttributeIgnoreSingleItems = 0x1
+} GroupAttribute;
+
+class GroupUtils
+{
+public:
+ static bool Group(GroupBy groupBy, const CFileItemList &items, CFileItemList &groupedItems, GroupAttribute groupAttributes = GroupAttributeNone);
+ static bool GroupAndSort(GroupBy groupBy, const CFileItemList &items, const SortDescription &sortDescription, CFileItemList &groupedItems, GroupAttribute groupAttributes = GroupAttributeNone);
+};
View
@@ -23,6 +23,7 @@ SRCS=AlarmClock.cpp \
fstrcmp.c \
fft.cpp \
GLUtils.cpp \
+ GroupUtils.cpp \
HTMLTable.cpp \
HTMLUtil.cpp \
HttpHeader.cpp \
Oops, something went wrong.

0 comments on commit fc0d58b

Please sign in to comment.