UserView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. using MediaBrowser.Controller.Playlists;
  2. using MediaBrowser.Controller.TV;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Model.Querying;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Runtime.Serialization;
  8. using System.Threading.Tasks;
  9. using System.Linq;
  10. namespace MediaBrowser.Controller.Entities
  11. {
  12. public class UserView : Folder
  13. {
  14. public string ViewType { get; set; }
  15. public Guid ParentId { get; set; }
  16. public Guid DisplayParentId { get; set; }
  17. public Guid? UserId { get; set; }
  18. public static ITVSeriesManager TVSeriesManager;
  19. public static IPlaylistManager PlaylistManager;
  20. public bool ContainsDynamicCategories(User user)
  21. {
  22. return true;
  23. }
  24. public override IEnumerable<Guid> GetIdsForAncestorQuery()
  25. {
  26. var list = new List<Guid>();
  27. if (DisplayParentId != Guid.Empty)
  28. {
  29. list.Add(DisplayParentId);
  30. }
  31. else if (ParentId != Guid.Empty)
  32. {
  33. list.Add(ParentId);
  34. }
  35. else
  36. {
  37. list.Add(Id);
  38. }
  39. return list;
  40. }
  41. public override Task<QueryResult<BaseItem>> GetItems(InternalItemsQuery query)
  42. {
  43. var parent = this as Folder;
  44. if (DisplayParentId != Guid.Empty)
  45. {
  46. parent = LibraryManager.GetItemById(DisplayParentId) as Folder ?? parent;
  47. }
  48. else if (ParentId != Guid.Empty)
  49. {
  50. parent = LibraryManager.GetItemById(ParentId) as Folder ?? parent;
  51. }
  52. return new UserViewBuilder(UserViewManager, LiveTvManager, ChannelManager, LibraryManager, Logger, UserDataManager, TVSeriesManager, CollectionManager, PlaylistManager)
  53. .GetUserItems(parent, this, ViewType, query);
  54. }
  55. public override IEnumerable<BaseItem> GetChildren(User user, bool includeLinkedChildren)
  56. {
  57. var result = GetItems(new InternalItemsQuery
  58. {
  59. User = user
  60. }).Result;
  61. return result.Items;
  62. }
  63. public override bool CanDelete()
  64. {
  65. return false;
  66. }
  67. public override bool IsSaveLocalMetadataEnabled()
  68. {
  69. return true;
  70. }
  71. public override IEnumerable<BaseItem> GetRecursiveChildren(User user, Func<BaseItem, bool> filter)
  72. {
  73. var result = GetItems(new InternalItemsQuery
  74. {
  75. User = user,
  76. Recursive = true,
  77. Filter = filter
  78. }).Result;
  79. return result.Items;
  80. }
  81. protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
  82. {
  83. return GetChildren(user, false);
  84. }
  85. public static bool IsExcludedFromGrouping(Folder folder)
  86. {
  87. var standaloneTypes = new List<string>
  88. {
  89. CollectionType.Books,
  90. CollectionType.HomeVideos,
  91. CollectionType.Photos,
  92. CollectionType.Playlists,
  93. CollectionType.BoxSets,
  94. CollectionType.MusicVideos,
  95. CollectionType.Games,
  96. CollectionType.Music
  97. };
  98. var collectionFolder = folder as ICollectionFolder;
  99. if (collectionFolder == null)
  100. {
  101. return false;
  102. }
  103. return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
  104. }
  105. public static bool IsUserSpecific(Folder folder)
  106. {
  107. var standaloneTypes = new List<string>
  108. {
  109. CollectionType.Playlists
  110. };
  111. if (!ConfigurationManager.Configuration.EnableSharedCollectionViewImage)
  112. {
  113. standaloneTypes.Add(CollectionType.BoxSets);
  114. }
  115. var collectionFolder = folder as ICollectionFolder;
  116. if (collectionFolder == null)
  117. {
  118. return false;
  119. }
  120. var supportsUserSpecific = folder as ISupportsUserSpecificView;
  121. if (supportsUserSpecific != null && supportsUserSpecific.EnableUserSpecificView)
  122. {
  123. return true;
  124. }
  125. return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
  126. }
  127. public static bool IsEligibleForEnhancedView(string viewType)
  128. {
  129. var types = new[]
  130. {
  131. CollectionType.Movies,
  132. CollectionType.TvShows
  133. };
  134. return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  135. }
  136. public static bool EnableOriginalFolder(string viewType)
  137. {
  138. var types = new[]
  139. {
  140. CollectionType.Games,
  141. CollectionType.Books,
  142. CollectionType.MusicVideos
  143. };
  144. return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  145. }
  146. protected override Task ValidateChildrenInternal(IProgress<double> progress, System.Threading.CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService)
  147. {
  148. return Task.FromResult(true);
  149. }
  150. [IgnoreDataMember]
  151. public override bool SupportsPeople
  152. {
  153. get
  154. {
  155. return false;
  156. }
  157. }
  158. }
  159. }