| 1 |
/* |
| 2 |
* Copyright (C) 2016-2018 Team Kodi |
| 3 |
* This file is part of Kodi - https://kodi.tv |
| 4 |
* |
| 5 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 6 |
* See LICENSES/README.md for more information. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "MusicFileItemListModifier.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "ServiceBroker.h" |
| 13 |
#include "filesystem/MusicDatabaseDirectory/DirectoryNode.h" |
| 14 |
#include "guilib/LocalizeStrings.h" |
| 15 |
#include "music/MusicDbUrl.h" |
| 16 |
#include "settings/AdvancedSettings.h" |
| 17 |
#include "settings/Settings.h" |
| 18 |
#include "settings/SettingsComponent.h" |
| 19 |
|
| 20 |
#include <memory> |
| 21 |
|
| 22 |
using namespace XFILE::MUSICDATABASEDIRECTORY; |
| 23 |
|
| 24 |
bool CMusicFileItemListModifier::CanModify(const CFileItemList &items) const |
| 25 |
{ |
| 26 |
if (items.IsMusicDb()) |
| 27 |
return true; |
| 28 |
|
| 29 |
return false; |
| 30 |
} |
| 31 |
|
| 32 |
bool CMusicFileItemListModifier::Modify(CFileItemList &items) const |
| 33 |
{ |
| 34 |
AddQueuingFolder(items); |
| 35 |
return true; |
| 36 |
} |
| 37 |
|
| 38 |
// Add an "* All ..." folder to the CFileItemList |
| 39 |
// depending on the child node |
| 40 |
void CMusicFileItemListModifier::AddQueuingFolder(CFileItemList& items) |
| 41 |
{ |
| 42 |
if (!items.IsMusicDb()) |
| 43 |
return; |
| 44 |
|
| 45 |
auto directoryNode = CDirectoryNode::ParseURL(items.GetPath()); |
| 46 |
|
| 47 |
CFileItemPtr pItem; |
| 48 |
|
| 49 |
CMusicDbUrl musicUrl; |
| 50 |
if (!musicUrl.FromString(directoryNode->BuildPath())) |
| 51 |
return; |
| 52 |
|
| 53 |
// always show "all" items by default |
| 54 |
if (!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICLIBRARY_SHOWALLITEMS)) |
| 55 |
return; |
| 56 |
|
| 57 |
// no need for "all" item when only one item |
| 58 |
if (items.GetObjectCount() <= 1) |
| 59 |
return; |
| 60 |
|
| 61 |
auto nodeChildType = directoryNode->GetChildType(); |
| 62 |
|
| 63 |
// No need for "*all" when overview node and child node is "albums" or "artists" |
| 64 |
// without options (hence all albums or artists unfiltered). |
| 65 |
if (directoryNode->GetType() == NODE_TYPE_OVERVIEW && |
| 66 |
(nodeChildType == NODE_TYPE_ARTIST || nodeChildType == NODE_TYPE_ALBUM) && |
| 67 |
musicUrl.GetOptions().empty()) |
| 68 |
return; |
| 69 |
// Smart playlist rules on parent node do not get applied to child nodes so no "*all" |
| 70 |
// ! @Todo: Remove this allowing "*all" once rules do get applied to child nodes. |
| 71 |
if (directoryNode->GetType() == NODE_TYPE_OVERVIEW && |
| 72 |
(nodeChildType == NODE_TYPE_ARTIST || nodeChildType == NODE_TYPE_ALBUM) && |
| 73 |
musicUrl.HasOption("xsp")) |
| 74 |
return; |
| 75 |
|
| 76 |
switch (nodeChildType) |
| 77 |
{ |
| 78 |
case NODE_TYPE_ARTIST: |
| 79 |
pItem = std::make_shared<CFileItem>(g_localizeStrings.Get(15103)); // "All Artists" |
| 80 |
musicUrl.AppendPath("-1/"); |
| 81 |
pItem->SetPath(musicUrl.ToString()); |
| 82 |
break; |
| 83 |
|
| 84 |
// All album related nodes |
| 85 |
case NODE_TYPE_ALBUM: |
| 86 |
case NODE_TYPE_ALBUM_RECENTLY_PLAYED: |
| 87 |
case NODE_TYPE_ALBUM_RECENTLY_ADDED: |
| 88 |
case NODE_TYPE_ALBUM_TOP100: |
| 89 |
pItem = std::make_shared<CFileItem>(g_localizeStrings.Get(15102)); // "All Albums" |
| 90 |
musicUrl.AppendPath("-1/"); |
| 91 |
pItem->SetPath(musicUrl.ToString()); |
| 92 |
break; |
| 93 |
|
| 94 |
// Disc node |
| 95 |
case NODE_TYPE_DISC: |
| 96 |
pItem = std::make_shared<CFileItem>(g_localizeStrings.Get(38075)); // "All Discs" |
| 97 |
musicUrl.AppendPath("-1/"); |
| 98 |
pItem->SetPath(musicUrl.ToString()); |
| 99 |
break; |
| 100 |
|
| 101 |
default: |
| 102 |
break; |
| 103 |
} |
| 104 |
|
| 105 |
if (pItem) |
| 106 |
{ |
| 107 |
pItem->m_bIsFolder = true; |
| 108 |
pItem->SetSpecialSort(CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bMusicLibraryAllItemsOnBottom ? SortSpecialOnBottom : SortSpecialOnTop); |
| 109 |
pItem->SetCanQueue(false); |
| 110 |
pItem->SetLabelPreformatted(true); |
| 111 |
if (CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_bMusicLibraryAllItemsOnBottom) |
| 112 |
items.Add(pItem); |
| 113 |
else |
| 114 |
items.AddFront(pItem, (items.Size() > 0 && items[0]->IsParentFolder()) ? 1 : 0); |
| 115 |
} |
| 116 |
} |