UserView.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 IsUserSpecific(Folder folder)
  86. {
  87. var standaloneTypes = new List<string>
  88. {
  89. CollectionType.Playlists
  90. };
  91. var collectionFolder = folder as ICollectionFolder;
  92. if (collectionFolder == null)
  93. {
  94. return false;
  95. }
  96. var supportsUserSpecific = folder as ISupportsUserSpecificView;
  97. if (supportsUserSpecific != null && supportsUserSpecific.EnableUserSpecificView)
  98. {
  99. return true;
  100. }
  101. return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
  102. }
  103. public static bool IsEligibleForGrouping(Folder folder)
  104. {
  105. var collectionFolder = folder as ICollectionFolder;
  106. return collectionFolder != null && IsEligibleForGrouping(collectionFolder.CollectionType);
  107. }
  108. public static bool IsEligibleForGrouping(string viewType)
  109. {
  110. var types = new[]
  111. {
  112. CollectionType.Movies,
  113. CollectionType.TvShows,
  114. string.Empty
  115. };
  116. return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  117. }
  118. public static bool IsEligibleForEnhancedView(string viewType)
  119. {
  120. var types = new[]
  121. {
  122. CollectionType.Movies,
  123. CollectionType.TvShows
  124. };
  125. return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  126. }
  127. public static bool EnableOriginalFolder(string viewType)
  128. {
  129. var types = new[]
  130. {
  131. CollectionType.Games,
  132. CollectionType.Books,
  133. CollectionType.MusicVideos,
  134. CollectionType.HomeVideos,
  135. CollectionType.Photos,
  136. CollectionType.Music,
  137. CollectionType.BoxSets
  138. };
  139. return types.Contains(viewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
  140. }
  141. protected override Task ValidateChildrenInternal(IProgress<double> progress, System.Threading.CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService)
  142. {
  143. return Task.FromResult(true);
  144. }
  145. [IgnoreDataMember]
  146. public override bool SupportsPeople
  147. {
  148. get
  149. {
  150. return false;
  151. }
  152. }
  153. }
  154. }