| 1 |
/* |
| 2 |
* Copyright (C) 2005-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 "GUIWindowMusicNav.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "GUIPassword.h" |
| 13 |
#include "GUIUserMessages.h" |
| 14 |
#include "PartyModeManager.h" |
| 15 |
#include "ServiceBroker.h" |
| 16 |
#include "URL.h" |
| 17 |
#include "Util.h" |
| 18 |
#include "addons/AddonSystemSettings.h" |
| 19 |
#include "dialogs/GUIDialogYesNo.h" |
| 20 |
#include "filesystem/MusicDatabaseDirectory.h" |
| 21 |
#include "filesystem/VideoDatabaseDirectory.h" |
| 22 |
#include "guilib/GUIComponent.h" |
| 23 |
#include "guilib/GUIEditControl.h" |
| 24 |
#include "guilib/GUIKeyboardFactory.h" |
| 25 |
#include "guilib/GUIWindowManager.h" |
| 26 |
#include "guilib/LocalizeStrings.h" |
| 27 |
#include "input/actions/Action.h" |
| 28 |
#include "input/actions/ActionIDs.h" |
| 29 |
#include "messaging/ApplicationMessenger.h" |
| 30 |
#include "messaging/helpers/DialogOKHelper.h" |
| 31 |
#include "music/MusicLibraryQueue.h" |
| 32 |
#include "music/dialogs/GUIDialogInfoProviderSettings.h" |
| 33 |
#include "music/tags/MusicInfoTag.h" |
| 34 |
#include "playlists/PlayList.h" |
| 35 |
#include "playlists/PlayListFactory.h" |
| 36 |
#include "profiles/ProfileManager.h" |
| 37 |
#include "settings/AdvancedSettings.h" |
| 38 |
#include "settings/Settings.h" |
| 39 |
#include "settings/SettingsComponent.h" |
| 40 |
#include "storage/MediaManager.h" |
| 41 |
#include "utils/FileUtils.h" |
| 42 |
#include "utils/LegacyPathTranslation.h" |
| 43 |
#include "utils/StringUtils.h" |
| 44 |
#include "utils/URIUtils.h" |
| 45 |
#include "utils/Variant.h" |
| 46 |
#include "utils/log.h" |
| 47 |
#include "video/VideoDatabase.h" |
| 48 |
#include "video/dialogs/GUIDialogVideoInfo.h" |
| 49 |
#include "video/windows/GUIWindowVideoNav.h" |
| 50 |
#include "view/GUIViewState.h" |
| 51 |
|
| 52 |
using namespace XFILE; |
| 53 |
using namespace PLAYLIST; |
| 54 |
using namespace MUSICDATABASEDIRECTORY; |
| 55 |
using namespace KODI::MESSAGING; |
| 56 |
|
| 57 |
#define CONTROL_BTNVIEWASICONS 2 |
| 58 |
#define CONTROL_BTNSORTBY 3 |
| 59 |
#define CONTROL_BTNSORTASC 4 |
| 60 |
#define CONTROL_BTNTYPE 5 |
| 61 |
#define CONTROL_LABELFILES 12 |
| 62 |
|
| 63 |
#define CONTROL_SEARCH 8 |
| 64 |
#define CONTROL_FILTER 15 |
| 65 |
#define CONTROL_BTNPARTYMODE 16 |
| 66 |
#define CONTROL_BTNMANUALINFO 17 |
| 67 |
#define CONTROL_BTN_FILTER 19 |
| 68 |
|
| 69 |
#define CONTROL_UPDATE_LIBRARY 20 |
| 70 |
|
| 71 |
CGUIWindowMusicNav::CGUIWindowMusicNav(void) |
| 72 |
: CGUIWindowMusicBase(WINDOW_MUSIC_NAV, "MyMusicNav.xml") |
| 73 |
{ |
| 74 |
m_vecItems->SetPath("?"); |
| 75 |
m_searchWithEdit = false; |
| 76 |
} |
| 77 |
|
| 78 |
CGUIWindowMusicNav::~CGUIWindowMusicNav(void) = default; |
| 79 |
|
| 80 |
bool CGUIWindowMusicNav::OnMessage(CGUIMessage& message) |
| 81 |
{ |
| 82 |
switch (message.GetMessage()) |
| 83 |
{ |
| 84 |
case GUI_MSG_WINDOW_RESET: |
| 85 |
m_vecItems->SetPath("?"); |
| 86 |
break; |
| 87 |
case GUI_MSG_WINDOW_INIT: |
| 88 |
{ |
| 89 |
/* We don't want to show Autosourced items (ie removable pendrives, memorycards) in Library mode */ |
| 90 |
m_rootDir.AllowNonLocalSources(false); |
| 91 |
|
| 92 |
// is this the first time the window is opened? |
| 93 |
if (m_vecItems->GetPath() == "?" && message.GetStringParam().empty()) |
| 94 |
message.SetStringParam(CServiceBroker::GetSettingsComponent()->GetSettings()->GetString(CSettings::SETTING_MYMUSIC_DEFAULTLIBVIEW)); |
| 95 |
|
| 96 |
if (!CGUIWindowMusicBase::OnMessage(message)) |
| 97 |
return false; |
| 98 |
|
| 99 |
if (message.GetStringParam(0) != "") |
| 100 |
{ |
| 101 |
CURL url(message.GetStringParam(0)); |
| 102 |
|
| 103 |
int i = 0; |
| 104 |
for (; i < m_vecItems->Size(); i++) |
| 105 |
{ |
| 106 |
CFileItemPtr pItem = m_vecItems->Get(i); |
| 107 |
|
| 108 |
// skip ".." |
| 109 |
if (pItem->IsParentFolder()) |
| 110 |
continue; |
| 111 |
|
| 112 |
if (URIUtils::PathEquals(pItem->GetPath(), message.GetStringParam(0), true, true)) |
| 113 |
{ |
| 114 |
m_viewControl.SetSelectedItem(i); |
| 115 |
i = -1; |
| 116 |
if (url.GetOption("showinfo") == "true") |
| 117 |
OnItemInfo(i); |
| 118 |
break; |
| 119 |
} |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
return true; |
| 124 |
} |
| 125 |
break; |
| 126 |
|
| 127 |
case GUI_MSG_CLICKED: |
| 128 |
{ |
| 129 |
int iControl = message.GetSenderId(); |
| 130 |
if (iControl == CONTROL_BTNPARTYMODE) |
| 131 |
{ |
| 132 |
if (g_partyModeManager.IsEnabled()) |
| 133 |
g_partyModeManager.Disable(); |
| 134 |
else |
| 135 |
{ |
| 136 |
if (!g_partyModeManager.Enable()) |
| 137 |
{ |
| 138 |
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE,false); |
| 139 |
return false; |
| 140 |
} |
| 141 |
|
| 142 |
// Playlist directory is the root of the playlist window |
| 143 |
if (m_guiState) |
| 144 |
m_guiState->SetPlaylistDirectory("playlistmusic://"); |
| 145 |
|
| 146 |
return true; |
| 147 |
} |
| 148 |
UpdateButtons(); |
| 149 |
} |
| 150 |
else if (iControl == CONTROL_SEARCH) |
| 151 |
{ |
| 152 |
if (m_searchWithEdit) |
| 153 |
{ |
| 154 |
// search updated - reset timer |
| 155 |
m_searchTimer.StartZero(); |
| 156 |
// grab our search string |
| 157 |
CGUIMessage selected(GUI_MSG_ITEM_SELECTED, GetID(), CONTROL_SEARCH); |
| 158 |
OnMessage(selected); |
| 159 |
SetProperty("search", selected.GetLabel()); |
| 160 |
return true; |
| 161 |
} |
| 162 |
std::string search(GetProperty("search").asString()); |
| 163 |
CGUIKeyboardFactory::ShowAndGetFilter(search, true); |
| 164 |
SetProperty("search", search); |
| 165 |
return true; |
| 166 |
} |
| 167 |
else if (iControl == CONTROL_UPDATE_LIBRARY) |
| 168 |
{ |
| 169 |
if (!CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 170 |
CMusicLibraryQueue::GetInstance().ScanLibrary(""); |
| 171 |
else |
| 172 |
CMusicLibraryQueue::GetInstance().StopLibraryScanning(); |
| 173 |
return true; |
| 174 |
} |
| 175 |
} |
| 176 |
break; |
| 177 |
case GUI_MSG_PLAYBACK_STOPPED: |
| 178 |
case GUI_MSG_PLAYBACK_ENDED: |
| 179 |
case GUI_MSG_PLAYLISTPLAYER_STOPPED: |
| 180 |
case GUI_MSG_PLAYBACK_STARTED: |
| 181 |
{ |
| 182 |
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE, g_partyModeManager.IsEnabled()); |
| 183 |
} |
| 184 |
break; |
| 185 |
case GUI_MSG_NOTIFY_ALL: |
| 186 |
{ |
| 187 |
if (message.GetParam1() == GUI_MSG_SEARCH_UPDATE && IsActive()) |
| 188 |
{ |
| 189 |
// search updated - reset timer |
| 190 |
m_searchTimer.StartZero(); |
| 191 |
SetProperty("search", message.GetStringParam()); |
| 192 |
} |
| 193 |
} |
| 194 |
} |
| 195 |
return CGUIWindowMusicBase::OnMessage(message); |
| 196 |
} |
| 197 |
|
| 198 |
bool CGUIWindowMusicNav::OnAction(const CAction& action) |
| 199 |
{ |
| 200 |
if (action.GetID() == ACTION_SCAN_ITEM) |
| 201 |
{ |
| 202 |
int item = m_viewControl.GetSelectedItem(); |
| 203 |
CMusicDatabaseDirectory dir; |
| 204 |
if (item > -1 && m_vecItems->Get(item)->m_bIsFolder |
| 205 |
&& (m_vecItems->Get(item)->IsAlbum()|| |
| 206 |
dir.IsArtistDir(m_vecItems->Get(item)->GetPath()))) |
| 207 |
{ |
| 208 |
OnContextButton(item,CONTEXT_BUTTON_INFO); |
| 209 |
return true; |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
return CGUIWindowMusicBase::OnAction(action); |
| 214 |
} |
| 215 |
|
| 216 |
bool CGUIWindowMusicNav::ManageInfoProvider(const CFileItemPtr& item) |
| 217 |
{ |
| 218 |
CQueryParams params; |
| 219 |
CDirectoryNode::GetDatabaseInfo(item->GetPath(), params); |
| 220 |
// Management of Info provider only valid for specific artist or album items |
| 221 |
if (params.GetAlbumId() == -1 && params.GetArtistId() == -1) |
| 222 |
return false; |
| 223 |
|
| 224 |
// Set things up for processing artist or albums |
| 225 |
CONTENT_TYPE content = CONTENT_ALBUMS; |
| 226 |
int id = params.GetAlbumId(); |
| 227 |
if (id == -1) |
| 228 |
{ |
| 229 |
content = CONTENT_ARTISTS; |
| 230 |
id = params.GetArtistId(); |
| 231 |
} |
| 232 |
|
| 233 |
ADDON::ScraperPtr scraper; |
| 234 |
// Get specific scraper and settings for current item or use default |
| 235 |
if (!m_musicdatabase.GetScraper(id, content, scraper)) |
| 236 |
{ |
| 237 |
ADDON::AddonPtr defaultScraper; |
| 238 |
if (ADDON::CAddonSystemSettings::GetInstance().GetActive( |
| 239 |
ADDON::ScraperTypeFromContent(content), defaultScraper)) |
| 240 |
{ |
| 241 |
scraper = std::dynamic_pointer_cast<ADDON::CScraper>(defaultScraper); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
// Set Information provider and settings |
| 246 |
int applyto = CGUIDialogInfoProviderSettings::Show(scraper); |
| 247 |
if (applyto >= 0) |
| 248 |
{ |
| 249 |
bool result = false; |
| 250 |
CVariant msgctxt; |
| 251 |
switch (applyto) |
| 252 |
{ |
| 253 |
case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_THISITEM: // Change information provider for specific item |
| 254 |
result = m_musicdatabase.SetScraper(id, content, scraper); |
| 255 |
break; |
| 256 |
case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_ALLVIEW: // Change information provider for the filtered items shown on this node |
| 257 |
{ |
| 258 |
msgctxt = 38069; |
| 259 |
if (content == CONTENT_ARTISTS) |
| 260 |
msgctxt = 38068; |
| 261 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{ 20195 }, msgctxt)) // Change information provider, confirm for all shown |
| 262 |
{ |
| 263 |
// Set scraper for all items on current view. |
| 264 |
std::string strPath = "musicdb://"; |
| 265 |
if (content == CONTENT_ARTISTS) |
| 266 |
strPath += "artists"; |
| 267 |
else |
| 268 |
strPath += "albums"; |
| 269 |
URIUtils::AddSlashAtEnd(strPath); |
| 270 |
// Items on view could be limited by navigation criteria, smart playlist rules or a filter. |
| 271 |
// Get these options, except ID, from item path |
| 272 |
CURL musicUrl(item->GetPath()); //Use CURL, as CMusicDbUrl removes "filter" option |
| 273 |
if (content == CONTENT_ARTISTS) |
| 274 |
musicUrl.RemoveOption("artistid"); |
| 275 |
else |
| 276 |
musicUrl.RemoveOption("albumid"); |
| 277 |
strPath += musicUrl.GetOptions(); |
| 278 |
result = m_musicdatabase.SetScraperAll(strPath, scraper); |
| 279 |
} |
| 280 |
} |
| 281 |
break; |
| 282 |
case INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_DEFAULT: // Change information provider for all items |
| 283 |
{ |
| 284 |
msgctxt = 38071; |
| 285 |
if (content == CONTENT_ARTISTS) |
| 286 |
msgctxt = 38070; |
| 287 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, msgctxt)) // Change information provider, confirm default and clear |
| 288 |
{ |
| 289 |
// Save scraper addon default setting values |
| 290 |
scraper->SaveSettings(); |
| 291 |
// Set default scraper |
| 292 |
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 293 |
if (content == CONTENT_ARTISTS) |
| 294 |
settings->SetString(CSettings::SETTING_MUSICLIBRARY_ARTISTSSCRAPER, scraper->ID()); |
| 295 |
else |
| 296 |
settings->SetString(CSettings::SETTING_MUSICLIBRARY_ALBUMSSCRAPER, scraper->ID()); |
| 297 |
settings->Save(); |
| 298 |
// Clear all item specific settings |
| 299 |
if (content == CONTENT_ARTISTS) |
| 300 |
result = m_musicdatabase.SetScraperAll("musicdb://artists/", nullptr); |
| 301 |
else |
| 302 |
result = m_musicdatabase.SetScraperAll("musicdb://albums/", nullptr); |
| 303 |
} |
| 304 |
} |
| 305 |
default: |
| 306 |
break; |
| 307 |
} |
| 308 |
if (!result) |
| 309 |
return false; |
| 310 |
|
| 311 |
// Refresh additional information using the new settings |
| 312 |
if (applyto == INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_ALLVIEW || applyto == INFOPROVIDERAPPLYOPTIONS::INFOPROVIDER_DEFAULT) |
| 313 |
{ |
| 314 |
// Change information provider, all artists or albums |
| 315 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, CVariant{38072})) |
| 316 |
OnItemInfoAll(m_vecItems->GetPath(), true); |
| 317 |
} |
| 318 |
else |
| 319 |
{ |
| 320 |
// Change information provider, selected artist or album |
| 321 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{20195}, CVariant{38073})) |
| 322 |
{ |
| 323 |
std::string itempath = StringUtils::Format("musicdb://albums/{}/", id); |
| 324 |
if (content == CONTENT_ARTISTS) |
| 325 |
itempath = StringUtils::Format("musicdb://artists/{}/", id); |
| 326 |
OnItemInfoAll(itempath, true); |
| 327 |
} |
| 328 |
} |
| 329 |
} |
| 330 |
return true; |
| 331 |
} |
| 332 |
|
| 333 |
bool CGUIWindowMusicNav::OnClick(int iItem, const std::string &player /* = "" */) |
| 334 |
{ |
| 335 |
if (iItem < 0 || iItem >= m_vecItems->Size()) return false; |
| 336 |
|
| 337 |
CFileItemPtr item = m_vecItems->Get(iItem); |
| 338 |
if (StringUtils::StartsWith(item->GetPath(), "musicsearch://")) |
| 339 |
{ |
| 340 |
if (m_searchWithEdit) |
| 341 |
OnSearchUpdate(); |
| 342 |
else |
| 343 |
{ |
| 344 |
std::string search(GetProperty("search").asString()); |
| 345 |
CGUIKeyboardFactory::ShowAndGetFilter(search, true); |
| 346 |
SetProperty("search", search); |
| 347 |
} |
| 348 |
return true; |
| 349 |
} |
| 350 |
if (item->IsMusicDb() && !item->m_bIsFolder) |
| 351 |
m_musicdatabase.SetPropertiesForFileItem(*item); |
| 352 |
|
| 353 |
if (item->IsPlayList() && |
| 354 |
!CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_playlistAsFolders) |
| 355 |
{ |
| 356 |
PlayItem(iItem); |
| 357 |
return true; |
| 358 |
} |
| 359 |
return CGUIWindowMusicBase::OnClick(iItem, player); |
| 360 |
} |
| 361 |
|
| 362 |
bool CGUIWindowMusicNav::Update(const std::string &strDirectory, bool updateFilterPath /* = true */) |
| 363 |
{ |
| 364 |
if (m_thumbLoader.IsLoading()) |
| 365 |
m_thumbLoader.StopThread(); |
| 366 |
|
| 367 |
if (CGUIWindowMusicBase::Update(strDirectory, updateFilterPath)) |
| 368 |
{ |
| 369 |
m_thumbLoader.Load(*m_unfilteredItems); |
| 370 |
return true; |
| 371 |
} |
| 372 |
|
| 373 |
return false; |
| 374 |
} |
| 375 |
|
| 376 |
bool CGUIWindowMusicNav::GetDirectory(const std::string &strDirectory, CFileItemList &items) |
| 377 |
{ |
| 378 |
if (strDirectory.empty()) |
| 379 |
AddSearchFolder(); |
| 380 |
|
| 381 |
bool bResult = CGUIWindowMusicBase::GetDirectory(strDirectory, items); |
| 382 |
if (bResult) |
| 383 |
{ |
| 384 |
if (items.IsPlayList()) |
| 385 |
OnRetrieveMusicInfo(items); |
| 386 |
} |
| 387 |
|
| 388 |
// update our content in the info manager |
| 389 |
if (StringUtils::StartsWithNoCase(strDirectory, "videodb://") || items.IsVideoDb()) |
| 390 |
{ |
| 391 |
CVideoDatabaseDirectory dir; |
| 392 |
VIDEODATABASEDIRECTORY::NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath()); |
| 393 |
switch (node) |
| 394 |
{ |
| 395 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_TITLE_MUSICVIDEOS: |
| 396 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_RECENTLY_ADDED_MUSICVIDEOS: |
| 397 |
items.SetContent("musicvideos"); |
| 398 |
break; |
| 399 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_GENRE: |
| 400 |
items.SetContent("genres"); |
| 401 |
break; |
| 402 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_COUNTRY: |
| 403 |
items.SetContent("countries"); |
| 404 |
break; |
| 405 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_ACTOR: |
| 406 |
items.SetContent("artists"); |
| 407 |
break; |
| 408 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_DIRECTOR: |
| 409 |
items.SetContent("directors"); |
| 410 |
break; |
| 411 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_STUDIO: |
| 412 |
items.SetContent("studios"); |
| 413 |
break; |
| 414 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_YEAR: |
| 415 |
items.SetContent("years"); |
| 416 |
break; |
| 417 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_MUSICVIDEOS_ALBUM: |
| 418 |
items.SetContent("albums"); |
| 419 |
break; |
| 420 |
case VIDEODATABASEDIRECTORY::NODE_TYPE_TAGS: |
| 421 |
items.SetContent("tags"); |
| 422 |
break; |
| 423 |
default: |
| 424 |
items.SetContent(""); |
| 425 |
break; |
| 426 |
} |
| 427 |
} |
| 428 |
else if (StringUtils::StartsWithNoCase(strDirectory, "musicdb://") || items.IsMusicDb()) |
| 429 |
{ |
| 430 |
CMusicDatabaseDirectory dir; |
| 431 |
NODE_TYPE node = dir.GetDirectoryChildType(items.GetPath()); |
| 432 |
switch (node) |
| 433 |
{ |
| 434 |
case NODE_TYPE_ALBUM: |
| 435 |
case NODE_TYPE_ALBUM_RECENTLY_ADDED: |
| 436 |
case NODE_TYPE_ALBUM_RECENTLY_PLAYED: |
| 437 |
case NODE_TYPE_ALBUM_TOP100: |
| 438 |
case NODE_TYPE_DISC: // ! @todo: own content type "discs"?? |
| 439 |
items.SetContent("albums"); |
| 440 |
break; |
| 441 |
case NODE_TYPE_ARTIST: |
| 442 |
items.SetContent("artists"); |
| 443 |
break; |
| 444 |
case NODE_TYPE_SONG: |
| 445 |
case NODE_TYPE_SONG_TOP100: |
| 446 |
case NODE_TYPE_SINGLES: |
| 447 |
case NODE_TYPE_ALBUM_RECENTLY_ADDED_SONGS: |
| 448 |
case NODE_TYPE_ALBUM_RECENTLY_PLAYED_SONGS: |
| 449 |
case NODE_TYPE_ALBUM_TOP100_SONGS: |
| 450 |
items.SetContent("songs"); |
| 451 |
break; |
| 452 |
case NODE_TYPE_GENRE: |
| 453 |
items.SetContent("genres"); |
| 454 |
break; |
| 455 |
case NODE_TYPE_SOURCE: |
| 456 |
items.SetContent("sources"); |
| 457 |
break; |
| 458 |
case NODE_TYPE_ROLE: |
| 459 |
items.SetContent("roles"); |
| 460 |
break; |
| 461 |
case NODE_TYPE_YEAR: |
| 462 |
items.SetContent("years"); |
| 463 |
break; |
| 464 |
default: |
| 465 |
items.SetContent(""); |
| 466 |
break; |
| 467 |
} |
| 468 |
} |
| 469 |
else if (items.IsPlayList()) |
| 470 |
items.SetContent("songs"); |
| 471 |
else if (URIUtils::PathEquals(strDirectory, "special://musicplaylists/") || |
| 472 |
URIUtils::PathEquals(strDirectory, "library://music/playlists.xml/")) |
| 473 |
items.SetContent("playlists"); |
| 474 |
else if (URIUtils::PathEquals(strDirectory, "plugin://music/")) |
| 475 |
items.SetContent("plugins"); |
| 476 |
else if (items.IsAddonsPath()) |
| 477 |
items.SetContent("addons"); |
| 478 |
else if (!items.IsSourcesPath() && !items.IsVirtualDirectoryRoot() && |
| 479 |
!items.IsLibraryFolder() && !items.IsPlugin() && !items.IsSmartPlayList()) |
| 480 |
items.SetContent("files"); |
| 481 |
|
| 482 |
return bResult; |
| 483 |
} |
| 484 |
|
| 485 |
void CGUIWindowMusicNav::UpdateButtons() |
| 486 |
{ |
| 487 |
CGUIWindowMusicBase::UpdateButtons(); |
| 488 |
|
| 489 |
// Update object count |
| 490 |
int iItems = m_vecItems->Size(); |
| 491 |
if (iItems) |
| 492 |
{ |
| 493 |
// check for parent dir and "all" items |
| 494 |
// should always be the first two items |
| 495 |
for (int i = 0; i <= (iItems>=2 ? 1 : 0); i++) |
| 496 |
{ |
| 497 |
CFileItemPtr pItem = m_vecItems->Get(i); |
| 498 |
if (pItem->IsParentFolder()) iItems--; |
| 499 |
if (StringUtils::StartsWith(pItem->GetPath(), "/-1/")) iItems--; |
| 500 |
} |
| 501 |
// or the last item |
| 502 |
if (m_vecItems->Size() > 2 && |
| 503 |
StringUtils::StartsWith(m_vecItems->Get(m_vecItems->Size()-1)->GetPath(), "/-1/")) |
| 504 |
iItems--; |
| 505 |
} |
| 506 |
std::string items = StringUtils::Format("{} {}", iItems, g_localizeStrings.Get(127)); |
| 507 |
SET_CONTROL_LABEL(CONTROL_LABELFILES, items); |
| 508 |
|
| 509 |
// set the filter label |
| 510 |
std::string strLabel; |
| 511 |
|
| 512 |
// "Playlists" |
| 513 |
if (m_vecItems->IsPath("special://musicplaylists/")) |
| 514 |
strLabel = g_localizeStrings.Get(136); |
| 515 |
// "{Playlist Name}" |
| 516 |
else if (m_vecItems->IsPlayList()) |
| 517 |
{ |
| 518 |
// get playlist name from path |
| 519 |
std::string strDummy; |
| 520 |
URIUtils::Split(m_vecItems->GetPath(), strDummy, strLabel); |
| 521 |
} |
| 522 |
// everything else is from a musicdb:// path |
| 523 |
else |
| 524 |
{ |
| 525 |
CMusicDatabaseDirectory dir; |
| 526 |
dir.GetLabel(m_vecItems->GetPath(), strLabel); |
| 527 |
} |
| 528 |
|
| 529 |
SET_CONTROL_LABEL(CONTROL_FILTER, strLabel); |
| 530 |
|
| 531 |
SET_CONTROL_SELECTED(GetID(),CONTROL_BTNPARTYMODE, g_partyModeManager.IsEnabled()); |
| 532 |
|
| 533 |
CONTROL_ENABLE_ON_CONDITION(CONTROL_UPDATE_LIBRARY, !m_vecItems->IsAddonsPath() && !m_vecItems->IsPlugin() && !m_vecItems->IsScript()); |
| 534 |
} |
| 535 |
|
| 536 |
void CGUIWindowMusicNav::PlayItem(int iItem) |
| 537 |
{ |
| 538 |
// unlike additemtoplaylist, we need to check the items here |
| 539 |
// before calling it since the current playlist will be stopped |
| 540 |
// and cleared! |
| 541 |
|
| 542 |
// root is not allowed |
| 543 |
if (m_vecItems->IsVirtualDirectoryRoot() && !m_vecItems->Get(iItem)->IsDVD()) |
| 544 |
return; |
| 545 |
|
| 546 |
CGUIWindowMusicBase::PlayItem(iItem); |
| 547 |
} |
| 548 |
|
| 549 |
void CGUIWindowMusicNav::OnWindowLoaded() |
| 550 |
{ |
| 551 |
const CGUIControl *control = GetControl(CONTROL_SEARCH); |
| 552 |
m_searchWithEdit = (control && control->GetControlType() == CGUIControl::GUICONTROL_EDIT); |
| 553 |
|
| 554 |
CGUIWindowMusicBase::OnWindowLoaded(); |
| 555 |
|
| 556 |
if (m_searchWithEdit) |
| 557 |
{ |
| 558 |
SendMessage(GUI_MSG_SET_TYPE, CONTROL_SEARCH, CGUIEditControl::INPUT_TYPE_SEARCH); |
| 559 |
SET_CONTROL_LABEL2(CONTROL_SEARCH, GetProperty("search").asString()); |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
void CGUIWindowMusicNav::GetContextButtons(int itemNumber, CContextButtons &buttons) |
| 564 |
{ |
| 565 |
CFileItemPtr item; |
| 566 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 567 |
item = m_vecItems->Get(itemNumber); |
| 568 |
if (item) |
| 569 |
{ |
| 570 |
const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 571 |
|
| 572 |
// are we in the playlists location? |
| 573 |
bool inPlaylists = m_vecItems->IsPath(CUtil::MusicPlaylistsLocation()) || |
| 574 |
m_vecItems->IsPath("special://musicplaylists/"); |
| 575 |
|
| 576 |
if (m_vecItems->IsPath("sources://music/")) |
| 577 |
{ |
| 578 |
// get the usual music shares, and anything for all media windows |
| 579 |
CGUIDialogContextMenu::GetContextButtons("music", item, buttons); |
| 580 |
#ifdef HAS_OPTICAL_DRIVE |
| 581 |
// enable Rip CD an audio disc |
| 582 |
if (CServiceBroker::GetMediaManager().IsDiscInDrive() && item->IsCDDA()) |
| 583 |
{ |
| 584 |
// those cds can also include Audio Tracks: CDExtra and MixedMode! |
| 585 |
MEDIA_DETECT::CCdInfo* pCdInfo = CServiceBroker::GetMediaManager().GetCdInfo(); |
| 586 |
if (pCdInfo->IsAudio(1) || pCdInfo->IsCDExtra(1) || pCdInfo->IsMixedMode(1)) |
| 587 |
{ |
| 588 |
if (CServiceBroker::GetJobManager()->IsProcessing("cdrip")) |
| 589 |
buttons.Add(CONTEXT_BUTTON_CANCEL_RIP_CD, 14100); |
| 590 |
else |
| 591 |
buttons.Add(CONTEXT_BUTTON_RIP_CD, 600); |
| 592 |
} |
| 593 |
} |
| 594 |
#endif |
| 595 |
// Scan button for music sources except ".." and "Add music source" items |
| 596 |
if (!item->IsPath("add") && !item->IsParentFolder() && |
| 597 |
(profileManager->GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser)) |
| 598 |
{ |
| 599 |
buttons.Add(CONTEXT_BUTTON_SCAN, 13352); |
| 600 |
} |
| 601 |
CGUIMediaWindow::GetContextButtons(itemNumber, buttons); |
| 602 |
} |
| 603 |
else |
| 604 |
{ |
| 605 |
CGUIWindowMusicBase::GetContextButtons(itemNumber, buttons); |
| 606 |
|
| 607 |
// Scan button for real folders containing files when navigating within music sources. |
| 608 |
// Blacklist the bespoke Kodi protocols as to many valid external protocols to whitelist |
| 609 |
if (m_vecItems->GetContent() == "files" && // Other content not scanned to library |
| 610 |
!inPlaylists && !m_vecItems->IsInternetStream() && // Not playlists locations or streams |
| 611 |
!item->IsPath("add") && !item->IsParentFolder() && // Not ".." and "Add items |
| 612 |
item->m_bIsFolder && // Folders only, but playlists can be folders too |
| 613 |
!URIUtils::IsLibraryContent(item->GetPath()) && // database folder or .xsp files |
| 614 |
!URIUtils::IsSpecial(item->GetPath()) && !item->IsPlugin() && !item->IsScript() && |
| 615 |
!item->IsPlayList() && // .m3u etc. that as flagged as folders when playlistasfolders |
| 616 |
!StringUtils::StartsWithNoCase(item->GetPath(), "addons://") && |
| 617 |
(profileManager->GetCurrentProfile().canWriteDatabases() || |
| 618 |
g_passwordManager.bMasterUser)) |
| 619 |
{ |
| 620 |
buttons.Add(CONTEXT_BUTTON_SCAN, 13352); |
| 621 |
} |
| 622 |
|
| 623 |
CMusicDatabaseDirectory dir; |
| 624 |
|
| 625 |
if (!item->IsParentFolder() && !dir.IsAllItem(item->GetPath())) |
| 626 |
{ |
| 627 |
if (item->m_bIsFolder && !item->IsVideoDb() && |
| 628 |
!item->IsPlugin() && !StringUtils::StartsWithNoCase(item->GetPath(), "musicsearch://")) |
| 629 |
{ |
| 630 |
if (item->IsAlbum()) |
| 631 |
// enable query all albums button only in album view |
| 632 |
buttons.Add(CONTEXT_BUTTON_INFO_ALL, 20059); |
| 633 |
else if (dir.IsArtistDir(item->GetPath())) |
| 634 |
// enable query all artist button only in artist view |
| 635 |
buttons.Add(CONTEXT_BUTTON_INFO_ALL, 21884); |
| 636 |
|
| 637 |
//Set default or clear default |
| 638 |
NODE_TYPE nodetype = dir.GetDirectoryType(item->GetPath()); |
| 639 |
if (!inPlaylists && |
| 640 |
(nodetype == NODE_TYPE_ROOT || |
| 641 |
nodetype == NODE_TYPE_OVERVIEW || |
| 642 |
nodetype == NODE_TYPE_TOP100)) |
| 643 |
{ |
| 644 |
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 645 |
if (!item->IsPath(settings->GetString(CSettings::SETTING_MYMUSIC_DEFAULTLIBVIEW))) |
| 646 |
buttons.Add(CONTEXT_BUTTON_SET_DEFAULT, 13335); // set default |
| 647 |
if (!settings->GetString(CSettings::SETTING_MYMUSIC_DEFAULTLIBVIEW).empty()) |
| 648 |
buttons.Add(CONTEXT_BUTTON_CLEAR_DEFAULT, 13403); // clear default |
| 649 |
} |
| 650 |
|
| 651 |
//Change information provider |
| 652 |
if (StringUtils::EqualsNoCase(m_vecItems->GetContent(), "albums") || |
| 653 |
StringUtils::EqualsNoCase(m_vecItems->GetContent(), "artists")) |
| 654 |
{ |
| 655 |
// we allow the user to set information provider for albums and artists |
| 656 |
buttons.Add(CONTEXT_BUTTON_SET_CONTENT, 20195); |
| 657 |
} |
| 658 |
} |
| 659 |
if (item->HasMusicInfoTag() && !item->GetMusicInfoTag()->GetArtistString().empty()) |
| 660 |
{ |
| 661 |
CVideoDatabase database; |
| 662 |
database.Open(); |
| 663 |
if (database.GetMatchingMusicVideo(item->GetMusicInfoTag()->GetArtistString()) > -1) |
| 664 |
buttons.Add(CONTEXT_BUTTON_GO_TO_ARTIST, 20400); |
| 665 |
} |
| 666 |
if (item->HasMusicInfoTag() && !item->GetMusicInfoTag()->GetArtistString().empty() && |
| 667 |
!item->GetMusicInfoTag()->GetAlbum().empty() && |
| 668 |
!item->GetMusicInfoTag()->GetTitle().empty()) |
| 669 |
{ |
| 670 |
CVideoDatabase database; |
| 671 |
database.Open(); |
| 672 |
if (database.GetMatchingMusicVideo(item->GetMusicInfoTag()->GetArtistString(), item->GetMusicInfoTag()->GetAlbum(), item->GetMusicInfoTag()->GetTitle()) > -1) |
| 673 |
buttons.Add(CONTEXT_BUTTON_PLAY_OTHER, 20401); |
| 674 |
} |
| 675 |
if (item->HasVideoInfoTag() && !item->m_bIsFolder) |
| 676 |
{ |
| 677 |
if ((profileManager->GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser) && !item->IsPlugin()) |
| 678 |
{ |
| 679 |
buttons.Add(CONTEXT_BUTTON_RENAME, 16105); |
| 680 |
buttons.Add(CONTEXT_BUTTON_DELETE, 646); |
| 681 |
} |
| 682 |
} |
| 683 |
if (inPlaylists && URIUtils::GetFileName(item->GetPath()) != "PartyMode.xsp" |
| 684 |
&& (item->IsPlayList() || item->IsSmartPlayList())) |
| 685 |
buttons.Add(CONTEXT_BUTTON_DELETE, 117); |
| 686 |
|
| 687 |
if (!item->IsReadOnly() && CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool("filelists.allowfiledeletion")) |
| 688 |
{ |
| 689 |
buttons.Add(CONTEXT_BUTTON_DELETE, 117); |
| 690 |
buttons.Add(CONTEXT_BUTTON_RENAME, 118); |
| 691 |
} |
| 692 |
} |
| 693 |
} |
| 694 |
} |
| 695 |
// noncontextual buttons |
| 696 |
|
| 697 |
CGUIWindowMusicBase::GetNonContextButtons(buttons); |
| 698 |
} |
| 699 |
|
| 700 |
bool CGUIWindowMusicNav::OnPopupMenu(int iItem) |
| 701 |
{ |
| 702 |
if (iItem >= 0 && iItem < m_vecItems->Size()) |
| 703 |
{ |
| 704 |
const auto item = m_vecItems->Get(iItem); |
| 705 |
item->SetProperty("CheckAutoPlayNextItem", true); |
| 706 |
} |
| 707 |
|
| 708 |
return CGUIWindowMusicBase::OnPopupMenu(iItem); |
| 709 |
} |
| 710 |
|
| 711 |
bool CGUIWindowMusicNav::OnContextButton(int itemNumber, CONTEXT_BUTTON button) |
| 712 |
{ |
| 713 |
CFileItemPtr item; |
| 714 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 715 |
item = m_vecItems->Get(itemNumber); |
| 716 |
|
| 717 |
switch (button) |
| 718 |
{ |
| 719 |
case CONTEXT_BUTTON_INFO: |
| 720 |
{ |
| 721 |
if (!item->IsVideoDb()) |
| 722 |
return CGUIWindowMusicBase::OnContextButton(itemNumber,button); |
| 723 |
|
| 724 |
// music videos - artists |
| 725 |
if (StringUtils::StartsWithNoCase(item->GetPath(), "videodb://musicvideos/artists/")) |
| 726 |
{ |
| 727 |
int idArtist = m_musicdatabase.GetArtistByName(item->GetLabel()); |
| 728 |
if (idArtist == -1) |
| 729 |
return false; |
| 730 |
std::string path = StringUtils::Format("musicdb://artists/{}/", idArtist); |
| 731 |
CArtist artist; |
| 732 |
m_musicdatabase.GetArtist(idArtist, artist, false); |
| 733 |
*item = CFileItem(artist); |
| 734 |
item->SetPath(path); |
| 735 |
CGUIWindowMusicBase::OnContextButton(itemNumber,button); |
| 736 |
Refresh(); |
| 737 |
m_viewControl.SetSelectedItem(itemNumber); |
| 738 |
return true; |
| 739 |
} |
| 740 |
|
| 741 |
// music videos - albums |
| 742 |
if (StringUtils::StartsWithNoCase(item->GetPath(), "videodb://musicvideos/albums/")) |
| 743 |
{ |
| 744 |
int idAlbum = m_musicdatabase.GetAlbumByName(item->GetLabel()); |
| 745 |
if (idAlbum == -1) |
| 746 |
return false; |
| 747 |
std::string path = StringUtils::Format("musicdb://albums/{}/", idAlbum); |
| 748 |
CAlbum album; |
| 749 |
m_musicdatabase.GetAlbum(idAlbum, album, false); |
| 750 |
*item = CFileItem(path,album); |
| 751 |
item->SetPath(path); |
| 752 |
CGUIWindowMusicBase::OnContextButton(itemNumber,button); |
| 753 |
Refresh(); |
| 754 |
m_viewControl.SetSelectedItem(itemNumber); |
| 755 |
return true; |
| 756 |
} |
| 757 |
|
| 758 |
if (item->HasVideoInfoTag() && !item->GetVideoInfoTag()->m_strTitle.empty()) |
| 759 |
{ |
| 760 |
CGUIDialogVideoInfo::ShowFor(*item); |
| 761 |
Refresh(); |
| 762 |
} |
| 763 |
return true; |
| 764 |
} |
| 765 |
|
| 766 |
case CONTEXT_BUTTON_INFO_ALL: |
| 767 |
OnItemInfoAll(m_vecItems->GetPath()); |
| 768 |
return true; |
| 769 |
|
| 770 |
case CONTEXT_BUTTON_SET_DEFAULT: |
| 771 |
{ |
| 772 |
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 773 |
settings->SetString(CSettings::SETTING_MYMUSIC_DEFAULTLIBVIEW, item->GetPath()); |
| 774 |
settings->Save(); |
| 775 |
return true; |
| 776 |
} |
| 777 |
|
| 778 |
case CONTEXT_BUTTON_CLEAR_DEFAULT: |
| 779 |
{ |
| 780 |
const std::shared_ptr<CSettings> settings = CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 781 |
settings->SetString(CSettings::SETTING_MYMUSIC_DEFAULTLIBVIEW, ""); |
| 782 |
settings->Save(); |
| 783 |
return true; |
| 784 |
} |
| 785 |
|
| 786 |
case CONTEXT_BUTTON_GO_TO_ARTIST: |
| 787 |
{ |
| 788 |
std::string strPath; |
| 789 |
CVideoDatabase database; |
| 790 |
database.Open(); |
| 791 |
strPath = StringUtils::Format( |
| 792 |
"videodb://musicvideos/artists/{}/", |
| 793 |
database.GetMatchingMusicVideo(item->GetMusicInfoTag()->GetArtistString())); |
| 794 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_VIDEO_NAV,strPath); |
| 795 |
return true; |
| 796 |
} |
| 797 |
|
| 798 |
case CONTEXT_BUTTON_PLAY_OTHER: |
| 799 |
{ |
| 800 |
CVideoDatabase database; |
| 801 |
database.Open(); |
| 802 |
CVideoInfoTag details; |
| 803 |
database.GetMusicVideoInfo("", details, database.GetMatchingMusicVideo(item->GetMusicInfoTag()->GetArtistString(), item->GetMusicInfoTag()->GetAlbum(), item->GetMusicInfoTag()->GetTitle())); |
| 804 |
CServiceBroker::GetAppMessenger()->PostMsg(TMSG_MEDIA_PLAY, 0, 0, |
| 805 |
static_cast<void*>(new CFileItem(details))); |
| 806 |
return true; |
| 807 |
} |
| 808 |
|
| 809 |
case CONTEXT_BUTTON_RENAME: |
| 810 |
if (!item->IsVideoDb() && !item->IsReadOnly()) |
| 811 |
OnRenameItem(itemNumber); |
| 812 |
|
| 813 |
CGUIDialogVideoInfo::UpdateVideoItemTitle(item); |
| 814 |
CUtil::DeleteVideoDatabaseDirectoryCache(); |
| 815 |
Refresh(); |
| 816 |
return true; |
| 817 |
|
| 818 |
case CONTEXT_BUTTON_DELETE: |
| 819 |
if (item->IsPlayList() || item->IsSmartPlayList()) |
| 820 |
{ |
| 821 |
item->m_bIsFolder = false; |
| 822 |
CGUIComponent *gui = CServiceBroker::GetGUI(); |
| 823 |
if (gui && gui->ConfirmDelete(item->GetPath())) |
| 824 |
CFileUtils::DeleteItem(item); |
| 825 |
} |
| 826 |
else if (!item->IsVideoDb()) |
| 827 |
OnDeleteItem(itemNumber); |
| 828 |
else |
| 829 |
{ |
| 830 |
CGUIDialogVideoInfo::DeleteVideoItemFromDatabase(item); |
| 831 |
CUtil::DeleteVideoDatabaseDirectoryCache(); |
| 832 |
} |
| 833 |
Refresh(); |
| 834 |
return true; |
| 835 |
|
| 836 |
case CONTEXT_BUTTON_SET_CONTENT: |
| 837 |
return ManageInfoProvider(item); |
| 838 |
|
| 839 |
default: |
| 840 |
break; |
| 841 |
} |
| 842 |
|
| 843 |
return CGUIWindowMusicBase::OnContextButton(itemNumber, button); |
| 844 |
} |
| 845 |
|
| 846 |
bool CGUIWindowMusicNav::GetSongsFromPlayList(const std::string& strPlayList, CFileItemList &items) |
| 847 |
{ |
| 848 |
std::string strParentPath=m_history.GetParentPath(); |
| 849 |
|
| 850 |
if (m_guiState.get() && !m_guiState->HideParentDirItems()) |
| 851 |
{ |
| 852 |
CFileItemPtr pItem(new CFileItem("..")); |
| 853 |
pItem->SetPath(strParentPath); |
| 854 |
items.Add(pItem); |
| 855 |
} |
| 856 |
|
| 857 |
items.SetPath(strPlayList); |
| 858 |
CLog::Log(LOGDEBUG, "CGUIWindowMusicNav, opening playlist [{}]", strPlayList); |
| 859 |
|
| 860 |
std::unique_ptr<CPlayList> pPlayList (CPlayListFactory::Create(strPlayList)); |
| 861 |
if (nullptr != pPlayList) |
| 862 |
{ |
| 863 |
// load it |
| 864 |
if (!pPlayList->Load(strPlayList)) |
| 865 |
{ |
| 866 |
HELPERS::ShowOKDialogText(CVariant{6}, CVariant{477}); |
| 867 |
return false; //hmmm unable to load playlist? |
| 868 |
} |
| 869 |
CPlayList playlist = *pPlayList; |
| 870 |
// convert playlist items to songs |
| 871 |
for (int i = 0; i < playlist.size(); ++i) |
| 872 |
{ |
| 873 |
items.Add(playlist[i]); |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
return true; |
| 878 |
} |
| 879 |
|
| 880 |
void CGUIWindowMusicNav::OnSearchUpdate() |
| 881 |
{ |
| 882 |
std::string search(CURL::Encode(GetProperty("search").asString())); |
| 883 |
if (!search.empty()) |
| 884 |
{ |
| 885 |
std::string path = "musicsearch://" + search + "/"; |
| 886 |
m_history.ClearSearchHistory(); |
| 887 |
Update(path); |
| 888 |
} |
| 889 |
else if (m_vecItems->IsVirtualDirectoryRoot()) |
| 890 |
{ |
| 891 |
Update(""); |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
void CGUIWindowMusicNav::FrameMove() |
| 896 |
{ |
| 897 |
static const int search_timeout = 2000; |
| 898 |
// update our searching |
| 899 |
if (m_searchTimer.IsRunning() && m_searchTimer.GetElapsedMilliseconds() > search_timeout) |
| 900 |
{ |
| 901 |
m_searchTimer.Stop(); |
| 902 |
OnSearchUpdate(); |
| 903 |
} |
| 904 |
CGUIWindowMusicBase::FrameMove(); |
| 905 |
} |
| 906 |
|
| 907 |
void CGUIWindowMusicNav::AddSearchFolder() |
| 908 |
{ |
| 909 |
// we use a general viewstate (and not our member) here as our |
| 910 |
// current viewstate may be specific to some other folder, and |
| 911 |
// we know we're in the root here |
| 912 |
CFileItemList items; |
| 913 |
CGUIViewState* viewState = CGUIViewState::GetViewState(GetID(), items); |
| 914 |
if (viewState) |
| 915 |
{ |
| 916 |
// add our remove the musicsearch source |
| 917 |
VECSOURCES &sources = viewState->GetSources(); |
| 918 |
bool haveSearchSource = false; |
| 919 |
bool needSearchSource = !GetProperty("search").empty() || !m_searchWithEdit; // we always need it if we don't have the edit control |
| 920 |
for (IVECSOURCES it = sources.begin(); it != sources.end(); ++it) |
| 921 |
{ |
| 922 |
CMediaSource& share = *it; |
| 923 |
if (share.strPath == "musicsearch://") |
| 924 |
{ |
| 925 |
haveSearchSource = true; |
| 926 |
if (!needSearchSource) |
| 927 |
{ // remove it |
| 928 |
sources.erase(it); |
| 929 |
break; |
| 930 |
} |
| 931 |
} |
| 932 |
} |
| 933 |
if (!haveSearchSource && needSearchSource) |
| 934 |
{ |
| 935 |
// add search share |
| 936 |
CMediaSource share; |
| 937 |
share.strName=g_localizeStrings.Get(137); // Search |
| 938 |
share.strPath = "musicsearch://"; |
| 939 |
share.m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL; |
| 940 |
sources.push_back(share); |
| 941 |
} |
| 942 |
m_rootDir.SetSources(sources); |
| 943 |
delete viewState; |
| 944 |
} |
| 945 |
} |
| 946 |
|
| 947 |
std::string CGUIWindowMusicNav::GetStartFolder(const std::string &dir) |
| 948 |
{ |
| 949 |
static const auto map = std::map<std::string, std::string>{ |
| 950 |
{"albums", "musicdb://albums/"}, |
| 951 |
{"artists", "musicdb://artists/"}, |
| 952 |
{"boxsets", "musicdb://boxsets/"}, |
| 953 |
{"compilations", "musicdb://compilations/"}, |
| 954 |
{"files", "sources://music/"}, |
| 955 |
{"genres", "musicdb://genres/"}, |
| 956 |
{"recentlyaddedalbums", "musicdb://recentlyaddedalbums/"}, |
| 957 |
{"recentlyplayedalbums", "musicdb://recentlyplayedalbums/"}, |
| 958 |
{"singles", "musicdb://singles/"}, |
| 959 |
{"songs", "musicdb://songs/"}, |
| 960 |
{"top100", "musicdb://top100/"}, |
| 961 |
{"top100albums", "musicdb://top100/albums/"}, |
| 962 |
{"top100songs", "musicdb://top100/songs/"}, |
| 963 |
{"years", "musicdb://years/"}, |
| 964 |
}; |
| 965 |
|
| 966 |
const auto it = map.find(StringUtils::ToLower(dir)); |
| 967 |
if (it == map.end()) |
| 968 |
return CGUIWindowMusicBase::GetStartFolder(dir); |
| 969 |
else |
| 970 |
return it->second; |
| 971 |
} |