aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Entities/BaseItem.cs
diff options
context:
space:
mode:
authorLuke <luke.pulverenti@gmail.com>2017-05-31 15:40:34 -0400
committerGitHub <noreply@github.com>2017-05-31 15:40:34 -0400
commit91176d9ccc1dde8155c10411c70e62a9f4b059d5 (patch)
tree21365f5a8dd09534a53d9f88d2a7a3116f3f3f98 /MediaBrowser.Controller/Entities/BaseItem.cs
parentc37c9a75073b1b9caa3af2c3bc62abd837bd630e (diff)
parent4e10daf646e0788409f2bc52ef70effa2616e3f3 (diff)
Merge pull request #2677 from MediaBrowser/beta
Beta
Diffstat (limited to 'MediaBrowser.Controller/Entities/BaseItem.cs')
-rw-r--r--MediaBrowser.Controller/Entities/BaseItem.cs118
1 files changed, 90 insertions, 28 deletions
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 999f6db3f..346442f59 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -21,7 +21,8 @@ using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using MediaBrowser.Common.IO;
+
+using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Extensions;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Sorting;
@@ -186,10 +187,15 @@ namespace MediaBrowser.Controller.Entities
}
set
{
+ var isSortNameDefault = IsSortNameDefault(SortName);
+
_name = value;
- // lazy load this again
- _sortName = null;
+ if (isSortNameDefault)
+ {
+ // lazy load this again
+ SortName = null;
+ }
}
}
@@ -580,7 +586,6 @@ namespace MediaBrowser.Controller.Entities
}
}
- private string _forcedSortName;
/// <summary>
/// Gets or sets the name of the forced sort.
/// </summary>
@@ -588,8 +593,42 @@ namespace MediaBrowser.Controller.Entities
[IgnoreDataMember]
public string ForcedSortName
{
- get { return _forcedSortName; }
- set { _forcedSortName = value; _sortName = null; }
+ get
+ {
+ var sortName = SortName;
+
+ if (string.IsNullOrWhiteSpace(sortName))
+ {
+ return null;
+ }
+
+ if (string.Equals(sortName, CreateSortName(), StringComparison.OrdinalIgnoreCase))
+ {
+ return null;
+ }
+
+ return sortName;
+ }
+ set
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ SortName = null;
+ }
+ else
+ {
+ var newValue = CreateSortNameFromCustomValue(value);
+
+ if (string.Equals(newValue, CreateSortName(), StringComparison.OrdinalIgnoreCase))
+ {
+ SortName = null;
+ }
+ else
+ {
+ SortName = newValue;
+ }
+ }
+ }
}
private string _sortName;
@@ -604,15 +643,7 @@ namespace MediaBrowser.Controller.Entities
{
if (_sortName == null)
{
- if (!string.IsNullOrWhiteSpace(ForcedSortName))
- {
- // Need the ToLower because that's what CreateSortName does
- _sortName = ModifySortChunks(ForcedSortName).ToLower();
- }
- else
- {
- _sortName = CreateSortName();
- }
+ _sortName = CreateSortName();
}
return _sortName;
}
@@ -622,6 +653,31 @@ namespace MediaBrowser.Controller.Entities
}
}
+ private string CreateSortNameFromCustomValue(string value)
+ {
+ return string.IsNullOrWhiteSpace(value) ? null : NormalizeCustomSortName(value);
+ }
+
+ protected virtual string NormalizeCustomSortName(string value)
+ {
+ if (ConfigurationManager.Configuration.EnableSimpleSortNameHandling)
+ {
+ return value.RemoveDiacritics().ToLower();
+ }
+
+ return ModifySortChunks(value).ToLower();
+ }
+
+ public bool IsSortNameDefault(string value)
+ {
+ if (string.IsNullOrWhiteSpace(value))
+ {
+ return true;
+ }
+
+ return string.Equals(CreateSortNameFromCustomValue(value), CreateSortName(), StringComparison.OrdinalIgnoreCase);
+ }
+
public string GetInternalMetadataPath()
{
var basePath = ConfigurationManager.ApplicationPaths.InternalMetadataPath;
@@ -643,14 +699,22 @@ namespace MediaBrowser.Controller.Entities
return System.IO.Path.Combine(basePath, idString.Substring(0, 2), idString);
}
+ protected string CreateSortName()
+ {
+ if (string.IsNullOrWhiteSpace(Name))
+ {
+ return null;
+ }
+
+ return CreateSortNameInternal();
+ }
+
/// <summary>
/// Creates the name of the sort.
/// </summary>
/// <returns>System.String.</returns>
- protected virtual string CreateSortName()
+ protected virtual string CreateSortNameInternal()
{
- if (Name == null) return null; //some items may not have name filled in properly
-
if (!EnableAlphaNumericSorting)
{
return Name.TrimStart();
@@ -1303,7 +1367,6 @@ namespace MediaBrowser.Controller.Entities
public void AfterMetadataRefresh()
{
- _sortName = null;
}
/// <summary>
@@ -1680,7 +1743,7 @@ namespace MediaBrowser.Controller.Entities
private BaseItem FindLinkedChild(LinkedChild info)
{
- if (!string.IsNullOrEmpty(info.Path))
+ if (!string.IsNullOrWhiteSpace(info.Path))
{
var itemByPath = LibraryManager.FindByPath(info.Path, null);
@@ -1809,10 +1872,13 @@ namespace MediaBrowser.Controller.Entities
/// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
/// </summary>
/// <returns>Task.</returns>
- public virtual Task ChangedExternally()
+ public virtual void ChangedExternally()
{
- ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(FileSystem), RefreshPriority.High);
- return Task.FromResult(true);
+ ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(FileSystem)
+ {
+ ValidateChildren = true,
+
+ }, RefreshPriority.High);
}
/// <summary>
@@ -2187,8 +2253,6 @@ namespace MediaBrowser.Controller.Entities
/// </summary>
public virtual bool BeforeMetadataRefresh()
{
- _sortName = null;
-
var hasChanges = false;
if (string.IsNullOrEmpty(Name) && !string.IsNullOrEmpty(Path))
@@ -2210,7 +2274,7 @@ namespace MediaBrowser.Controller.Entities
return path;
}
- public virtual Task FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user, List<ItemFields> itemFields)
+ public virtual void FillUserDataDtoValues(UserItemDataDto dto, UserItemData userData, BaseItemDto itemDto, User user, List<ItemFields> fields)
{
if (RunTimeTicks.HasValue)
{
@@ -2226,8 +2290,6 @@ namespace MediaBrowser.Controller.Entities
}
}
}
-
- return Task.FromResult(true);
}
protected Task RefreshMetadataForOwnedItem(BaseItem ownedItem, bool copyTitleMetadata, MetadataRefreshOptions options, CancellationToken cancellationToken)