| 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 "GUIWindowMusicBase.h" |
| 10 |
|
| 11 |
#include "Autorun.h" |
| 12 |
#include "FileItem.h" |
| 13 |
#include "GUIInfoManager.h" |
| 14 |
#include "GUIPassword.h" |
| 15 |
#include "GUIUserMessages.h" |
| 16 |
#include "PartyModeManager.h" |
| 17 |
#include "PlayListPlayer.h" |
| 18 |
#include "ServiceBroker.h" |
| 19 |
#include "URL.h" |
| 20 |
#include "Util.h" |
| 21 |
#include "addons/gui/GUIDialogAddonInfo.h" |
| 22 |
#include "application/Application.h" |
| 23 |
#include "application/ApplicationComponents.h" |
| 24 |
#include "application/ApplicationPlayer.h" |
| 25 |
#ifdef HAS_CDDA_RIPPER |
| 26 |
#include "cdrip/CDDARipper.h" |
| 27 |
#endif |
| 28 |
#include "dialogs/GUIDialogMediaSource.h" |
| 29 |
#include "dialogs/GUIDialogProgress.h" |
| 30 |
#include "dialogs/GUIDialogSmartPlaylistEditor.h" |
| 31 |
#include "dialogs/GUIDialogYesNo.h" |
| 32 |
#include "filesystem/Directory.h" |
| 33 |
#include "filesystem/MusicDatabaseDirectory.h" |
| 34 |
#include "guilib/GUIComponent.h" |
| 35 |
#include "guilib/GUIWindowManager.h" |
| 36 |
#include "guilib/LocalizeStrings.h" |
| 37 |
#include "guilib/guiinfo/GUIInfoLabels.h" |
| 38 |
#include "input/actions/Action.h" |
| 39 |
#include "input/actions/ActionIDs.h" |
| 40 |
#include "messaging/helpers/DialogHelper.h" |
| 41 |
#include "messaging/helpers/DialogOKHelper.h" |
| 42 |
#include "music/MusicDbUrl.h" |
| 43 |
#include "music/MusicLibraryQueue.h" |
| 44 |
#include "music/MusicUtils.h" |
| 45 |
#include "music/dialogs/GUIDialogInfoProviderSettings.h" |
| 46 |
#include "music/dialogs/GUIDialogMusicInfo.h" |
| 47 |
#include "music/infoscanner/MusicInfoScanner.h" |
| 48 |
#include "music/tags/MusicInfoTag.h" |
| 49 |
#include "playlists/PlayList.h" |
| 50 |
#include "playlists/PlayListFactory.h" |
| 51 |
#include "profiles/ProfileManager.h" |
| 52 |
#include "settings/AdvancedSettings.h" |
| 53 |
#include "settings/MediaSourceSettings.h" |
| 54 |
#include "settings/Settings.h" |
| 55 |
#include "settings/SettingsComponent.h" |
| 56 |
#include "storage/MediaManager.h" |
| 57 |
#include "utils/FileUtils.h" |
| 58 |
#include "utils/StringUtils.h" |
| 59 |
#include "utils/URIUtils.h" |
| 60 |
#include "utils/Variant.h" |
| 61 |
#include "utils/XTimeUtils.h" |
| 62 |
#include "utils/log.h" |
| 63 |
#include "video/VideoInfoTag.h" |
| 64 |
#include "video/dialogs/GUIDialogVideoInfo.h" |
| 65 |
#include "view/GUIViewState.h" |
| 66 |
|
| 67 |
#include <algorithm> |
| 68 |
#include <memory> |
| 69 |
|
| 70 |
using namespace XFILE; |
| 71 |
using namespace MUSICDATABASEDIRECTORY; |
| 72 |
using namespace MUSIC_GRABBER; |
| 73 |
using namespace MUSIC_INFO; |
| 74 |
using namespace KODI::MESSAGING; |
| 75 |
using KODI::MESSAGING::HELPERS::DialogResponse; |
| 76 |
|
| 77 |
using namespace std::chrono_literals; |
| 78 |
|
| 79 |
#define CONTROL_BTNVIEWASICONS 2 |
| 80 |
#define CONTROL_BTNSORTBY 3 |
| 81 |
#define CONTROL_BTNSORTASC 4 |
| 82 |
#define CONTROL_BTNPLAYLISTS 7 |
| 83 |
#define CONTROL_BTNSCAN 9 |
| 84 |
#define CONTROL_BTNRIP 11 |
| 85 |
|
| 86 |
CGUIWindowMusicBase::CGUIWindowMusicBase(int id, const std::string &xmlFile) |
| 87 |
: CGUIMediaWindow(id, xmlFile.c_str()) |
| 88 |
{ |
| 89 |
m_dlgProgress = NULL; |
| 90 |
m_thumbLoader.SetObserver(this); |
| 91 |
} |
| 92 |
|
| 93 |
CGUIWindowMusicBase::~CGUIWindowMusicBase () = default; |
| 94 |
|
| 95 |
bool CGUIWindowMusicBase::OnBack(int actionID) |
| 96 |
{ |
| 97 |
if (!CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 98 |
{ |
| 99 |
CUtil::RemoveTempFiles(); |
| 100 |
} |
| 101 |
return CGUIMediaWindow::OnBack(actionID); |
| 102 |
} |
| 103 |
|
| 104 |
/*! |
| 105 |
\brief Handle messages on window. |
| 106 |
\param message GUI Message that can be reacted on. |
| 107 |
\return if a message can't be processed, return \e false |
| 108 |
|
| 109 |
On these messages this class reacts.\n |
| 110 |
When retrieving... |
| 111 |
- #GUI_MSG_WINDOW_DEINIT\n |
| 112 |
...the last focused control is saved to m_iLastControl. |
| 113 |
- #GUI_MSG_WINDOW_INIT\n |
| 114 |
...the musicdatabase is opend and the music extensions and shares are set. |
| 115 |
The last focused control is set. |
| 116 |
- #GUI_MSG_CLICKED\n |
| 117 |
... the base class reacts on the following controls:\n |
| 118 |
Buttons:\n |
| 119 |
- #CONTROL_BTNVIEWASICONS - switch between list, thumb and with large items |
| 120 |
- #CONTROL_BTNSEARCH - Search for items\n |
| 121 |
Other Controls: |
| 122 |
- The container controls\n |
| 123 |
Have the following actions in message them clicking on them. |
| 124 |
- #ACTION_QUEUE_ITEM - add selected item to end of playlist |
| 125 |
- #ACTION_QUEUE_ITEM_NEXT - add selected item to next pos in playlist |
| 126 |
- #ACTION_SHOW_INFO - retrieve album info from the internet |
| 127 |
- #ACTION_SELECT_ITEM - Item has been selected. Overwrite OnClick() to react on it |
| 128 |
*/ |
| 129 |
bool CGUIWindowMusicBase::OnMessage(CGUIMessage& message) |
| 130 |
{ |
| 131 |
switch ( message.GetMessage() ) |
| 132 |
{ |
| 133 |
case GUI_MSG_WINDOW_DEINIT: |
| 134 |
{ |
| 135 |
if (m_thumbLoader.IsLoading()) |
| 136 |
m_thumbLoader.StopThread(); |
| 137 |
m_musicdatabase.Close(); |
| 138 |
} |
| 139 |
break; |
| 140 |
|
| 141 |
case GUI_MSG_WINDOW_INIT: |
| 142 |
{ |
| 143 |
m_dlgProgress = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogProgress>(WINDOW_DIALOG_PROGRESS); |
| 144 |
|
| 145 |
m_musicdatabase.Open(); |
| 146 |
|
| 147 |
if (!CGUIMediaWindow::OnMessage(message)) |
| 148 |
return false; |
| 149 |
|
| 150 |
return true; |
| 151 |
} |
| 152 |
break; |
| 153 |
case GUI_MSG_DIRECTORY_SCANNED: |
| 154 |
{ |
| 155 |
CFileItem directory(message.GetStringParam(), true); |
| 156 |
|
| 157 |
// Only update thumb on a local drive |
| 158 |
if (directory.IsHD()) |
| 159 |
{ |
| 160 |
std::string strParent; |
| 161 |
URIUtils::GetParentPath(directory.GetPath(), strParent); |
| 162 |
if (directory.GetPath() == m_vecItems->GetPath() || strParent == m_vecItems->GetPath()) |
| 163 |
Refresh(); |
| 164 |
} |
| 165 |
} |
| 166 |
break; |
| 167 |
|
| 168 |
// update the display |
| 169 |
case GUI_MSG_SCAN_FINISHED: |
| 170 |
case GUI_MSG_REFRESH_THUMBS: // Never called as is secondary msg sent as GUI_MSG_NOTIFY_ALL |
| 171 |
Refresh(); |
| 172 |
break; |
| 173 |
|
| 174 |
case GUI_MSG_CLICKED: |
| 175 |
{ |
| 176 |
int iControl = message.GetSenderId(); |
| 177 |
if (iControl == CONTROL_BTNRIP) |
| 178 |
{ |
| 179 |
OnRipCD(); |
| 180 |
} |
| 181 |
else if (iControl == CONTROL_BTNPLAYLISTS) |
| 182 |
{ |
| 183 |
if (!m_vecItems->IsPath("special://musicplaylists/")) |
| 184 |
Update("special://musicplaylists/"); |
| 185 |
} |
| 186 |
else if (iControl == CONTROL_BTNSCAN) |
| 187 |
{ |
| 188 |
OnScan(-1); |
| 189 |
} |
| 190 |
else if (m_viewControl.HasControl(iControl)) // list/thumb control |
| 191 |
{ |
| 192 |
int iItem = m_viewControl.GetSelectedItem(); |
| 193 |
int iAction = message.GetParam1(); |
| 194 |
|
| 195 |
// iItem is checked for validity inside these routines |
| 196 |
if (iAction == ACTION_QUEUE_ITEM || iAction == ACTION_MOUSE_MIDDLE_CLICK) |
| 197 |
{ |
| 198 |
OnQueueItem(iItem); |
| 199 |
} |
| 200 |
else if (iAction == ACTION_QUEUE_ITEM_NEXT) |
| 201 |
{ |
| 202 |
OnQueueItem(iItem, true); |
| 203 |
} |
| 204 |
else if (iAction == ACTION_SHOW_INFO) |
| 205 |
{ |
| 206 |
OnItemInfo(iItem); |
| 207 |
} |
| 208 |
else if (iAction == ACTION_DELETE_ITEM) |
| 209 |
{ |
| 210 |
// is delete allowed? |
| 211 |
// must be at the playlists directory |
| 212 |
if (m_vecItems->IsPath("special://musicplaylists/")) |
| 213 |
OnDeleteItem(iItem); |
| 214 |
|
| 215 |
else |
| 216 |
return false; |
| 217 |
} |
| 218 |
// use play button to add folders of items to temp playlist |
| 219 |
else if (iAction == ACTION_PLAYER_PLAY) |
| 220 |
{ |
| 221 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 222 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 223 |
// if playback is paused or playback speed != 1, return |
| 224 |
if (appPlayer->IsPlayingAudio()) |
| 225 |
{ |
| 226 |
if (appPlayer->IsPausedPlayback()) |
| 227 |
return false; |
| 228 |
if (appPlayer->GetPlaySpeed() != 1) |
| 229 |
return false; |
| 230 |
} |
| 231 |
|
| 232 |
// not playing audio, or playback speed == 1 |
| 233 |
PlayItem(iItem); |
| 234 |
|
| 235 |
return true; |
| 236 |
} |
| 237 |
} |
| 238 |
} |
| 239 |
break; |
| 240 |
case GUI_MSG_NOTIFY_ALL: |
| 241 |
{ |
| 242 |
if (message.GetParam1()==GUI_MSG_REMOVED_MEDIA) |
| 243 |
CUtil::DeleteDirectoryCache("r-"); |
| 244 |
} |
| 245 |
break; |
| 246 |
} |
| 247 |
return CGUIMediaWindow::OnMessage(message); |
| 248 |
} |
| 249 |
|
| 250 |
bool CGUIWindowMusicBase::OnAction(const CAction &action) |
| 251 |
{ |
| 252 |
if (action.GetID() == ACTION_SHOW_PLAYLIST) |
| 253 |
{ |
| 254 |
if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC || |
| 255 |
CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_MUSIC).size() > 0) |
| 256 |
{ |
| 257 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_PLAYLIST); |
| 258 |
return true; |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
if (action.GetID() == ACTION_SCAN_ITEM) |
| 263 |
{ |
| 264 |
int item = m_viewControl.GetSelectedItem(); |
| 265 |
if (item > -1 && m_vecItems->Get(item)->m_bIsFolder) |
| 266 |
OnScan(item); |
| 267 |
|
| 268 |
return true; |
| 269 |
} |
| 270 |
|
| 271 |
return CGUIMediaWindow::OnAction(action); |
| 272 |
} |
| 273 |
|
| 274 |
void CGUIWindowMusicBase::OnItemInfoAll(const std::string& strPath, bool refresh) |
| 275 |
{ |
| 276 |
if (StringUtils::EqualsNoCase(m_vecItems->GetContent(), "albums")) |
| 277 |
{ |
| 278 |
if (CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 279 |
return; |
| 280 |
|
| 281 |
CMusicLibraryQueue::GetInstance().StartAlbumScan(strPath, refresh); |
| 282 |
} |
| 283 |
else if (StringUtils::EqualsNoCase(m_vecItems->GetContent(), "artists")) |
| 284 |
{ |
| 285 |
if (CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 286 |
return; |
| 287 |
|
| 288 |
CMusicLibraryQueue::GetInstance().StartArtistScan(strPath, refresh); |
| 289 |
} |
| 290 |
} |
| 291 |
|
| 292 |
void CGUIWindowMusicBase::OnItemInfo(int iItem) |
| 293 |
{ |
| 294 |
if ( iItem < 0 || iItem >= m_vecItems->Size() ) |
| 295 |
return; |
| 296 |
|
| 297 |
CFileItemPtr item = m_vecItems->Get(iItem); |
| 298 |
|
| 299 |
// Match visibility test of CMusicInfo::IsVisible |
| 300 |
if (item->IsVideoDb() && item->HasVideoInfoTag() && |
| 301 |
(item->HasProperty("artist_musicid") || item->HasProperty("album_musicid"))) |
| 302 |
{ |
| 303 |
// Music video artist or album (navigation by music > music video > artist)) |
| 304 |
CGUIDialogMusicInfo::ShowFor(item.get()); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
if (item->IsVideo() && item->HasVideoInfoTag() && |
| 309 |
item->GetVideoInfoTag()->m_type == MediaTypeMusicVideo) |
| 310 |
{ // Music video on a mixed current playlist or navigation by music > music video > artist > video |
| 311 |
CGUIDialogVideoInfo::ShowFor(*item); |
| 312 |
return; |
| 313 |
} |
| 314 |
|
| 315 |
if (!m_vecItems->IsPlugin() && (item->IsPlugin() || item->IsScript())) |
| 316 |
{ |
| 317 |
CGUIDialogAddonInfo::ShowForItem(item); |
| 318 |
return; |
| 319 |
} |
| 320 |
|
| 321 |
// Match visibility test of CMusicInfo::IsVisible |
| 322 |
if (item->HasMusicInfoTag() && (item->GetMusicInfoTag()->GetType() == MediaTypeSong || |
| 323 |
item->GetMusicInfoTag()->GetType() == MediaTypeAlbum || |
| 324 |
item->GetMusicInfoTag()->GetType() == MediaTypeArtist)) |
| 325 |
CGUIDialogMusicInfo::ShowFor(item.get()); |
| 326 |
} |
| 327 |
|
| 328 |
void CGUIWindowMusicBase::RefreshContent(const std::string& strContent) |
| 329 |
{ |
| 330 |
if ( CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_MUSIC_NAV && |
| 331 |
m_vecItems->GetContent() == strContent && |
| 332 |
m_vecItems->GetSortMethod() == SortByUserRating) |
| 333 |
// When music library window is active and showing songs or albums sorted |
| 334 |
// by userrating refresh the list to resort items and show new userrating |
| 335 |
Refresh(true); |
| 336 |
} |
| 337 |
|
| 338 |
/// \brief Retrieve tag information for \e m_vecItems |
| 339 |
void CGUIWindowMusicBase::RetrieveMusicInfo() |
| 340 |
{ |
| 341 |
auto start = std::chrono::steady_clock::now(); |
| 342 |
|
| 343 |
OnRetrieveMusicInfo(*m_vecItems); |
| 344 |
|
| 345 |
//! @todo Scan for multitrack items here... |
| 346 |
std::vector<std::string> itemsForRemove; |
| 347 |
CFileItemList itemsForAdd; |
| 348 |
for (int i = 0; i < m_vecItems->Size(); ++i) |
| 349 |
{ |
| 350 |
CFileItemPtr pItem = (*m_vecItems)[i]; |
| 351 |
if (pItem->m_bIsFolder || pItem->IsPlayList() || pItem->IsPicture() || pItem->IsLyrics() || pItem->IsVideo()) |
| 352 |
continue; |
| 353 |
|
| 354 |
CMusicInfoTag& tag = *pItem->GetMusicInfoTag(); |
| 355 |
if (tag.Loaded() && !tag.GetCueSheet().empty()) |
| 356 |
pItem->LoadEmbeddedCue(); |
| 357 |
|
| 358 |
if (pItem->HasCueDocument() |
| 359 |
&& pItem->LoadTracksFromCueDocument(itemsForAdd)) |
| 360 |
{ |
| 361 |
itemsForRemove.push_back(pItem->GetPath()); |
| 362 |
} |
| 363 |
} |
| 364 |
for (size_t i = 0; i < itemsForRemove.size(); ++i) |
| 365 |
{ |
| 366 |
for (int j = 0; j < m_vecItems->Size(); ++j) |
| 367 |
{ |
| 368 |
if ((*m_vecItems)[j]->GetPath() == itemsForRemove[i]) |
| 369 |
{ |
| 370 |
m_vecItems->Remove(j); |
| 371 |
break; |
| 372 |
} |
| 373 |
} |
| 374 |
} |
| 375 |
m_vecItems->Append(itemsForAdd); |
| 376 |
|
| 377 |
auto end = std::chrono::steady_clock::now(); |
| 378 |
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); |
| 379 |
|
| 380 |
CLog::Log(LOGDEBUG, "RetrieveMusicInfo() took {} ms", duration.count()); |
| 381 |
} |
| 382 |
|
| 383 |
/// \brief Add selected list/thumb control item to playlist and start playing |
| 384 |
/// \param iItem Selected Item in list/thumb control |
| 385 |
void CGUIWindowMusicBase::OnQueueItem(int iItem, bool first) |
| 386 |
{ |
| 387 |
// don't re-queue items from playlist window |
| 388 |
if (iItem < 0 || iItem >= m_vecItems->Size() || GetID() == WINDOW_MUSIC_PLAYLIST) |
| 389 |
return; |
| 390 |
|
| 391 |
// add item 2 playlist |
| 392 |
const auto item = m_vecItems->Get(iItem); |
| 393 |
|
| 394 |
if (item->IsRAR() || item->IsZIP()) |
| 395 |
return; |
| 396 |
|
| 397 |
MUSIC_UTILS::QueueItem(item, first ? MUSIC_UTILS::QueuePosition::POSITION_BEGIN |
| 398 |
: MUSIC_UTILS::QueuePosition::POSITION_END); |
| 399 |
|
| 400 |
// select next item |
| 401 |
m_viewControl.SetSelectedItem(iItem + 1); |
| 402 |
} |
| 403 |
|
| 404 |
void CGUIWindowMusicBase::UpdateButtons() |
| 405 |
{ |
| 406 |
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTNRIP, CServiceBroker::GetMediaManager().IsAudio()); |
| 407 |
|
| 408 |
CONTROL_ENABLE_ON_CONDITION(CONTROL_BTNSCAN, |
| 409 |
!(m_vecItems->IsVirtualDirectoryRoot() || |
| 410 |
m_vecItems->IsMusicDb())); |
| 411 |
|
| 412 |
if (CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 413 |
SET_CONTROL_LABEL(CONTROL_BTNSCAN, 14056); // Stop Scan |
| 414 |
else |
| 415 |
SET_CONTROL_LABEL(CONTROL_BTNSCAN, 102); // Scan |
| 416 |
|
| 417 |
CGUIMediaWindow::UpdateButtons(); |
| 418 |
} |
| 419 |
|
| 420 |
void CGUIWindowMusicBase::GetContextButtons(int itemNumber, CContextButtons &buttons) |
| 421 |
{ |
| 422 |
CFileItemPtr item; |
| 423 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 424 |
item = m_vecItems->Get(itemNumber); |
| 425 |
|
| 426 |
if (item) |
| 427 |
{ |
| 428 |
const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 429 |
|
| 430 |
// Check for the partymode playlist item. |
| 431 |
// When "PartyMode.xsp" not exist, only context menu button is edit |
| 432 |
if (item->IsSmartPlayList() && |
| 433 |
(item->GetPath() == profileManager->GetUserDataItem("PartyMode.xsp")) && |
| 434 |
!CFileUtils::Exists(item->GetPath())) |
| 435 |
{ |
| 436 |
buttons.Add(CONTEXT_BUTTON_EDIT_SMART_PLAYLIST, 586); |
| 437 |
return; |
| 438 |
} |
| 439 |
|
| 440 |
if (!item->IsParentFolder()) |
| 441 |
{ |
| 442 |
//! @todo get rid of IsAddonsPath and IsScript check. CanQueue should be enough! |
| 443 |
if (item->CanQueue() && !item->IsAddonsPath() && !item->IsScript()) |
| 444 |
{ |
| 445 |
if (item->IsSmartPlayList()) |
| 446 |
buttons.Add(CONTEXT_BUTTON_PLAY_PARTYMODE, 15216); // Play in Partymode |
| 447 |
|
| 448 |
if (item->IsSmartPlayList() || m_vecItems->IsSmartPlayList()) |
| 449 |
buttons.Add(CONTEXT_BUTTON_EDIT_SMART_PLAYLIST, 586); |
| 450 |
else if (item->IsPlayList() || m_vecItems->IsPlayList()) |
| 451 |
buttons.Add(CONTEXT_BUTTON_EDIT, 586); |
| 452 |
} |
| 453 |
#ifdef HAS_OPTICAL_DRIVE |
| 454 |
// enable Rip CD Audio or Track button if we have an audio disc |
| 455 |
if (CServiceBroker::GetMediaManager().IsDiscInDrive() && m_vecItems->IsCDDA()) |
| 456 |
{ |
| 457 |
// those cds can also include Audio Tracks: CDExtra and MixedMode! |
| 458 |
MEDIA_DETECT::CCdInfo* pCdInfo = CServiceBroker::GetMediaManager().GetCdInfo(); |
| 459 |
if (pCdInfo->IsAudio(1) || pCdInfo->IsCDExtra(1) || pCdInfo->IsMixedMode(1)) |
| 460 |
buttons.Add(CONTEXT_BUTTON_RIP_TRACK, 610); |
| 461 |
} |
| 462 |
#endif |
| 463 |
} |
| 464 |
|
| 465 |
// enable CDDB lookup if the current dir is CDDA |
| 466 |
if (CServiceBroker::GetMediaManager().IsDiscInDrive() && m_vecItems->IsCDDA() && |
| 467 |
(profileManager->GetCurrentProfile().canWriteDatabases() || g_passwordManager.bMasterUser)) |
| 468 |
{ |
| 469 |
buttons.Add(CONTEXT_BUTTON_CDDB, 16002); |
| 470 |
} |
| 471 |
} |
| 472 |
CGUIMediaWindow::GetContextButtons(itemNumber, buttons); |
| 473 |
} |
| 474 |
|
| 475 |
void CGUIWindowMusicBase::GetNonContextButtons(CContextButtons &buttons) |
| 476 |
{ |
| 477 |
} |
| 478 |
|
| 479 |
bool CGUIWindowMusicBase::OnContextButton(int itemNumber, CONTEXT_BUTTON button) |
| 480 |
{ |
| 481 |
CFileItemPtr item; |
| 482 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 483 |
item = m_vecItems->Get(itemNumber); |
| 484 |
|
| 485 |
if (CGUIDialogContextMenu::OnContextButton("music", item, button)) |
| 486 |
{ |
| 487 |
if (button == CONTEXT_BUTTON_REMOVE_SOURCE) |
| 488 |
OnRemoveSource(itemNumber); |
| 489 |
|
| 490 |
Update(m_vecItems->GetPath()); |
| 491 |
return true; |
| 492 |
} |
| 493 |
|
| 494 |
switch (button) |
| 495 |
{ |
| 496 |
case CONTEXT_BUTTON_INFO: |
| 497 |
OnItemInfo(itemNumber); |
| 498 |
return true; |
| 499 |
|
| 500 |
case CONTEXT_BUTTON_EDIT: |
| 501 |
{ |
| 502 |
std::string playlist = item->IsPlayList() ? item->GetPath() : m_vecItems->GetPath(); // save path as activatewindow will destroy our items |
| 503 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_PLAYLIST_EDITOR, playlist); |
| 504 |
// need to update |
| 505 |
m_vecItems->RemoveDiscCache(GetID()); |
| 506 |
return true; |
| 507 |
} |
| 508 |
|
| 509 |
case CONTEXT_BUTTON_EDIT_SMART_PLAYLIST: |
| 510 |
{ |
| 511 |
std::string playlist = item->IsSmartPlayList() ? item->GetPath() : m_vecItems->GetPath(); // save path as activatewindow will destroy our items |
| 512 |
if (CGUIDialogSmartPlaylistEditor::EditPlaylist(playlist, "music")) |
| 513 |
Refresh(true); // need to update |
| 514 |
return true; |
| 515 |
} |
| 516 |
|
| 517 |
case CONTEXT_BUTTON_PLAY_PARTYMODE: |
| 518 |
g_partyModeManager.Enable(PARTYMODECONTEXT_MUSIC, item->GetPath()); |
| 519 |
return true; |
| 520 |
|
| 521 |
case CONTEXT_BUTTON_RIP_CD: |
| 522 |
OnRipCD(); |
| 523 |
return true; |
| 524 |
|
| 525 |
#ifdef HAS_CDDA_RIPPER |
| 526 |
case CONTEXT_BUTTON_CANCEL_RIP_CD: |
| 527 |
KODI::CDRIP::CCDDARipper::GetInstance().CancelJobs(); |
| 528 |
return true; |
| 529 |
#endif |
| 530 |
|
| 531 |
case CONTEXT_BUTTON_RIP_TRACK: |
| 532 |
OnRipTrack(itemNumber); |
| 533 |
return true; |
| 534 |
|
| 535 |
case CONTEXT_BUTTON_SCAN: |
| 536 |
// Check if scanning already and inform user |
| 537 |
if (CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 538 |
HELPERS::ShowOKDialogText(CVariant{ 189 }, CVariant{ 14057 }); |
| 539 |
else |
| 540 |
OnScan(itemNumber, true); |
| 541 |
return true; |
| 542 |
|
| 543 |
case CONTEXT_BUTTON_CDDB: |
| 544 |
if (m_musicdatabase.LookupCDDBInfo(true)) |
| 545 |
Refresh(); |
| 546 |
return true; |
| 547 |
|
| 548 |
default: |
| 549 |
break; |
| 550 |
} |
| 551 |
|
| 552 |
return CGUIMediaWindow::OnContextButton(itemNumber, button); |
| 553 |
} |
| 554 |
|
| 555 |
bool CGUIWindowMusicBase::OnAddMediaSource() |
| 556 |
{ |
| 557 |
return CGUIDialogMediaSource::ShowAndAddMediaSource("music"); |
| 558 |
} |
| 559 |
|
| 560 |
void CGUIWindowMusicBase::OnRipCD() |
| 561 |
{ |
| 562 |
if (CServiceBroker::GetMediaManager().IsAudio()) |
| 563 |
{ |
| 564 |
if (!g_application.CurrentFileItem().IsCDDA()) |
| 565 |
{ |
| 566 |
#ifdef HAS_CDDA_RIPPER |
| 567 |
KODI::CDRIP::CCDDARipper::GetInstance().RipCD(); |
| 568 |
#endif |
| 569 |
} |
| 570 |
else |
| 571 |
HELPERS::ShowOKDialogText(CVariant{257}, CVariant{20099}); |
| 572 |
} |
| 573 |
} |
| 574 |
|
| 575 |
void CGUIWindowMusicBase::OnRipTrack(int iItem) |
| 576 |
{ |
| 577 |
if (CServiceBroker::GetMediaManager().IsAudio()) |
| 578 |
{ |
| 579 |
if (!g_application.CurrentFileItem().IsCDDA()) |
| 580 |
{ |
| 581 |
#ifdef HAS_CDDA_RIPPER |
| 582 |
CFileItemPtr item = m_vecItems->Get(iItem); |
| 583 |
KODI::CDRIP::CCDDARipper::GetInstance().RipTrack(item.get()); |
| 584 |
#endif |
| 585 |
} |
| 586 |
else |
| 587 |
HELPERS::ShowOKDialogText(CVariant{257}, CVariant{20099}); |
| 588 |
} |
| 589 |
} |
| 590 |
|
| 591 |
void CGUIWindowMusicBase::PlayItem(int iItem) |
| 592 |
{ |
| 593 |
// restrictions should be placed in the appropriate window code |
| 594 |
// only call the base code if the item passes since this clears |
| 595 |
// the current playlist |
| 596 |
|
| 597 |
const CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 598 |
#ifdef HAS_OPTICAL_DRIVE |
| 599 |
if (pItem->IsDVD()) |
| 600 |
{ |
| 601 |
MEDIA_DETECT::CAutorun::PlayDiscAskResume(pItem->GetPath()); |
| 602 |
return; |
| 603 |
} |
| 604 |
#endif |
| 605 |
|
| 606 |
// Check for the partymode playlist item, do nothing when "PartyMode.xsp" not exist |
| 607 |
if (pItem->IsSmartPlayList()) |
| 608 |
{ |
| 609 |
const std::shared_ptr<CProfileManager> profileManager = |
| 610 |
CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 611 |
if ((pItem->GetPath() == profileManager->GetUserDataItem("PartyMode.xsp")) && |
| 612 |
!CFileUtils::Exists(pItem->GetPath())) |
| 613 |
return; |
| 614 |
} |
| 615 |
|
| 616 |
// if its a folder, build a playlist |
| 617 |
if (pItem->m_bIsFolder && !pItem->IsPlugin()) |
| 618 |
{ |
| 619 |
// make a copy so that we can alter the queue state |
| 620 |
CFileItemPtr item(new CFileItem(*m_vecItems->Get(iItem))); |
| 621 |
|
| 622 |
// Allow queuing of unqueueable items |
| 623 |
// when we try to queue them directly |
| 624 |
if (!item->CanQueue()) |
| 625 |
item->SetCanQueue(true); |
| 626 |
|
| 627 |
// skip ".." |
| 628 |
if (item->IsParentFolder()) |
| 629 |
return; |
| 630 |
|
| 631 |
CFileItemList queuedItems; |
| 632 |
MUSIC_UTILS::GetItemsForPlayList(item, queuedItems); |
| 633 |
if (g_partyModeManager.IsEnabled()) |
| 634 |
{ |
| 635 |
g_partyModeManager.AddUserSongs(queuedItems, true); |
| 636 |
return; |
| 637 |
} |
| 638 |
|
| 639 |
/* |
| 640 |
std::string strPlayListDirectory = m_vecItems->GetPath(); |
| 641 |
URIUtils::RemoveSlashAtEnd(strPlayListDirectory); |
| 642 |
*/ |
| 643 |
|
| 644 |
CServiceBroker::GetPlaylistPlayer().ClearPlaylist(PLAYLIST::TYPE_MUSIC); |
| 645 |
CServiceBroker::GetPlaylistPlayer().Reset(); |
| 646 |
CServiceBroker::GetPlaylistPlayer().Add(PLAYLIST::TYPE_MUSIC, queuedItems); |
| 647 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_MUSIC); |
| 648 |
|
| 649 |
// play! |
| 650 |
CServiceBroker::GetPlaylistPlayer().Play(); |
| 651 |
} |
| 652 |
else if (pItem->IsPlayList()) |
| 653 |
{ |
| 654 |
// load the playlist the old way |
| 655 |
LoadPlayList(pItem->GetPath()); |
| 656 |
} |
| 657 |
else |
| 658 |
{ |
| 659 |
// just a single item, play it |
| 660 |
//! @todo Add music-specific code for single playback of an item here (See OnClick in MediaWindow, and OnPlayMedia below) |
| 661 |
OnClick(iItem); |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
void CGUIWindowMusicBase::LoadPlayList(const std::string& strPlayList) |
| 666 |
{ |
| 667 |
// if partymode is active, we disable it |
| 668 |
if (g_partyModeManager.IsEnabled()) |
| 669 |
g_partyModeManager.Disable(); |
| 670 |
|
| 671 |
// load a playlist like .m3u, .pls |
| 672 |
// first get correct factory to load playlist |
| 673 |
std::unique_ptr<PLAYLIST::CPlayList> pPlayList(PLAYLIST::CPlayListFactory::Create(strPlayList)); |
| 674 |
if (pPlayList) |
| 675 |
{ |
| 676 |
// load it |
| 677 |
if (!pPlayList->Load(strPlayList)) |
| 678 |
{ |
| 679 |
HELPERS::ShowOKDialogText(CVariant{6}, CVariant{477}); |
| 680 |
return; //hmmm unable to load playlist? |
| 681 |
} |
| 682 |
} |
| 683 |
|
| 684 |
int iSize = pPlayList->size(); |
| 685 |
if (g_application.ProcessAndStartPlaylist(strPlayList, *pPlayList, PLAYLIST::TYPE_MUSIC)) |
| 686 |
{ |
| 687 |
if (m_guiState) |
| 688 |
m_guiState->SetPlaylistDirectory("playlistmusic://"); |
| 689 |
// activate the playlist window if its not activated yet |
| 690 |
if (GetID() == CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() && iSize > 1) |
| 691 |
{ |
| 692 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(WINDOW_MUSIC_PLAYLIST); |
| 693 |
} |
| 694 |
} |
| 695 |
} |
| 696 |
|
| 697 |
bool CGUIWindowMusicBase::OnPlayMedia(int iItem, const std::string &player) |
| 698 |
{ |
| 699 |
CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 700 |
|
| 701 |
// party mode |
| 702 |
if (g_partyModeManager.IsEnabled()) |
| 703 |
{ |
| 704 |
PLAYLIST::CPlayList playlistTemp; |
| 705 |
playlistTemp.Add(pItem); |
| 706 |
g_partyModeManager.AddUserSongs(playlistTemp, !CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICPLAYER_QUEUEBYDEFAULT)); |
| 707 |
return true; |
| 708 |
} |
| 709 |
else if (!pItem->IsPlayList() && !pItem->IsInternetStream()) |
| 710 |
{ // single music file - if we get here then we have autoplaynextitem turned off or queuebydefault |
| 711 |
// turned on, but we still want to use the playlist player in order to handle more queued items |
| 712 |
// following etc. |
| 713 |
if ( (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICPLAYER_QUEUEBYDEFAULT) && CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() != WINDOW_MUSIC_PLAYLIST_EDITOR) ) |
| 714 |
{ |
| 715 |
//! @todo Should the playlist be cleared if nothing is already playing? |
| 716 |
OnQueueItem(iItem); |
| 717 |
return true; |
| 718 |
} |
| 719 |
pItem->SetProperty("playlist_type_hint", m_guiState->GetPlaylist()); |
| 720 |
CServiceBroker::GetPlaylistPlayer().Play(pItem, player); |
| 721 |
return true; |
| 722 |
} |
| 723 |
return CGUIMediaWindow::OnPlayMedia(iItem, player); |
| 724 |
} |
| 725 |
|
| 726 |
/// \brief Can be overwritten to implement an own tag filling function. |
| 727 |
/// \param items File items to fill |
| 728 |
void CGUIWindowMusicBase::OnRetrieveMusicInfo(CFileItemList& items) |
| 729 |
{ |
| 730 |
// No need to attempt to read music file tags for music videos |
| 731 |
if (items.IsVideoDb()) |
| 732 |
return; |
| 733 |
if (items.GetFolderCount()==items.Size() || items.IsMusicDb() || |
| 734 |
(!CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICFILES_USETAGS) && !items.IsCDDA())) |
| 735 |
{ |
| 736 |
return; |
| 737 |
} |
| 738 |
// Start the music info loader thread |
| 739 |
m_musicInfoLoader.SetProgressCallback(m_dlgProgress); |
| 740 |
m_musicInfoLoader.Load(items); |
| 741 |
|
| 742 |
bool bShowProgress = !CServiceBroker::GetGUI()->GetWindowManager().HasModalDialog(true); |
| 743 |
bool bProgressVisible = false; |
| 744 |
|
| 745 |
auto start = std::chrono::steady_clock::now(); |
| 746 |
|
| 747 |
while (m_musicInfoLoader.IsLoading()) |
| 748 |
{ |
| 749 |
if (bShowProgress) |
| 750 |
{ // Do we have to init a progress dialog? |
| 751 |
auto end = std::chrono::steady_clock::now(); |
| 752 |
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); |
| 753 |
|
| 754 |
if (!bProgressVisible && duration.count() > 1500 && m_dlgProgress) |
| 755 |
{ // tag loading takes more then 1.5 secs, show a progress dialog |
| 756 |
CURL url(items.GetPath()); |
| 757 |
m_dlgProgress->SetHeading(CVariant{189}); |
| 758 |
m_dlgProgress->SetLine(0, CVariant{505}); |
| 759 |
m_dlgProgress->SetLine(1, CVariant{""}); |
| 760 |
m_dlgProgress->SetLine(2, CVariant{url.GetWithoutUserDetails()}); |
| 761 |
m_dlgProgress->Open(); |
| 762 |
m_dlgProgress->ShowProgressBar(true); |
| 763 |
bProgressVisible = true; |
| 764 |
} |
| 765 |
|
| 766 |
if (bProgressVisible && m_dlgProgress && !m_dlgProgress->IsCanceled()) |
| 767 |
{ // keep GUI alive |
| 768 |
m_dlgProgress->Progress(); |
| 769 |
} |
| 770 |
} // if (bShowProgress) |
| 771 |
KODI::TIME::Sleep(1ms); |
| 772 |
} // while (m_musicInfoLoader.IsLoading()) |
| 773 |
|
| 774 |
if (bProgressVisible && m_dlgProgress) |
| 775 |
m_dlgProgress->Close(); |
| 776 |
} |
| 777 |
|
| 778 |
bool CGUIWindowMusicBase::GetDirectory(const std::string &strDirectory, CFileItemList &items) |
| 779 |
{ |
| 780 |
items.ClearArt(); |
| 781 |
bool bResult = CGUIMediaWindow::GetDirectory(strDirectory, items); |
| 782 |
if (bResult) |
| 783 |
{ |
| 784 |
// We want to expand disc images when browsing in file view but not on library, smartplaylist |
| 785 |
// or node menu music windows |
| 786 |
if (!items.GetPath().empty() && !StringUtils::StartsWithNoCase(items.GetPath(), "musicdb://") && |
| 787 |
!StringUtils::StartsWithNoCase(items.GetPath(), "special://") && |
| 788 |
!StringUtils::StartsWithNoCase(items.GetPath(), "library://")) |
| 789 |
CDirectory::FilterFileDirectories(items, ".iso", true); |
| 790 |
|
| 791 |
CMusicThumbLoader loader; |
| 792 |
loader.FillThumb(items); |
| 793 |
|
| 794 |
CQueryParams params; |
| 795 |
CDirectoryNode::GetDatabaseInfo(items.GetPath(), params); |
| 796 |
|
| 797 |
// Get art for directory when album or artist |
| 798 |
bool artfound = false; |
| 799 |
std::vector<ArtForThumbLoader> art; |
| 800 |
if (params.GetAlbumId() > 0) |
| 801 |
{ // Get album and related artist(s) art |
| 802 |
artfound = m_musicdatabase.GetArtForItem(-1, params.GetAlbumId(), -1, false, art); |
| 803 |
} |
| 804 |
else if (params.GetArtistId() > 0) |
| 805 |
{ // get artist art |
| 806 |
artfound = m_musicdatabase.GetArtForItem(-1, -1, params.GetArtistId(), true, art); |
| 807 |
} |
| 808 |
if (artfound) |
| 809 |
{ |
| 810 |
std::string dirType = MediaTypeArtist; |
| 811 |
if (params.GetAlbumId() > 0) |
| 812 |
dirType = MediaTypeAlbum; |
| 813 |
std::map<std::string, std::string> artmap; |
| 814 |
for (auto artitem : art) |
| 815 |
{ |
| 816 |
std::string artname; |
| 817 |
if (dirType == artitem.mediaType) |
| 818 |
artname = artitem.artType; |
| 819 |
else if (artitem.prefix.empty()) |
| 820 |
artname = artitem.mediaType + "." + artitem.artType; |
| 821 |
else |
| 822 |
{ |
| 823 |
if (dirType == MediaTypeAlbum) |
| 824 |
StringUtils::Replace(artitem.prefix, "albumartist", "artist"); |
| 825 |
artname = artitem.prefix + "." + artitem.artType; |
| 826 |
} |
| 827 |
artmap.insert(std::make_pair(artname, artitem.url)); |
| 828 |
} |
| 829 |
items.SetArt(artmap); |
| 830 |
} |
| 831 |
|
| 832 |
int iWindow = GetID(); |
| 833 |
// Add "New Playlist" items when in the playlists folder, except on playlist editor screen |
| 834 |
if ((iWindow != WINDOW_MUSIC_PLAYLIST_EDITOR) && |
| 835 |
(items.GetPath() == "special://musicplaylists/") && !items.Contains("newplaylist://")) |
| 836 |
{ |
| 837 |
const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 838 |
|
| 839 |
CFileItemPtr newPlaylist(new CFileItem(profileManager->GetUserDataItem("PartyMode.xsp"),false)); |
| 840 |
newPlaylist->SetLabel(g_localizeStrings.Get(16035)); |
| 841 |
newPlaylist->SetLabelPreformatted(true); |
| 842 |
newPlaylist->SetArt("icon", "DefaultPartyMode.png"); |
| 843 |
newPlaylist->m_bIsFolder = true; |
| 844 |
items.Add(newPlaylist); |
| 845 |
|
| 846 |
newPlaylist = std::make_shared<CFileItem>("newplaylist://", false); |
| 847 |
newPlaylist->SetLabel(g_localizeStrings.Get(525)); |
| 848 |
newPlaylist->SetArt("icon", "DefaultAddSource.png"); |
| 849 |
newPlaylist->SetLabelPreformatted(true); |
| 850 |
newPlaylist->SetSpecialSort(SortSpecialOnBottom); |
| 851 |
newPlaylist->SetCanQueue(false); |
| 852 |
items.Add(newPlaylist); |
| 853 |
|
| 854 |
newPlaylist = std::make_shared<CFileItem>("newsmartplaylist://music", false); |
| 855 |
newPlaylist->SetLabel(g_localizeStrings.Get(21437)); |
| 856 |
newPlaylist->SetArt("icon", "DefaultAddSource.png"); |
| 857 |
newPlaylist->SetLabelPreformatted(true); |
| 858 |
newPlaylist->SetSpecialSort(SortSpecialOnBottom); |
| 859 |
newPlaylist->SetCanQueue(false); |
| 860 |
items.Add(newPlaylist); |
| 861 |
} |
| 862 |
|
| 863 |
// check for .CUE files here. |
| 864 |
items.FilterCueItems(); |
| 865 |
|
| 866 |
std::string label; |
| 867 |
if (items.GetLabel().empty() && m_rootDir.IsSource(items.GetPath(), CMediaSourceSettings::GetInstance().GetSources("music"), &label)) |
| 868 |
items.SetLabel(label); |
| 869 |
} |
| 870 |
|
| 871 |
return bResult; |
| 872 |
} |
| 873 |
|
| 874 |
bool CGUIWindowMusicBase::CheckFilterAdvanced(CFileItemList &items) const |
| 875 |
{ |
| 876 |
const std::string& content = items.GetContent(); |
| 877 |
if ((items.IsMusicDb() || CanContainFilter(m_strFilterPath)) && |
| 878 |
(StringUtils::EqualsNoCase(content, "artists") || |
| 879 |
StringUtils::EqualsNoCase(content, "albums") || |
| 880 |
StringUtils::EqualsNoCase(content, "songs"))) |
| 881 |
return true; |
| 882 |
|
| 883 |
return false; |
| 884 |
} |
| 885 |
|
| 886 |
bool CGUIWindowMusicBase::CanContainFilter(const std::string &strDirectory) const |
| 887 |
{ |
| 888 |
return URIUtils::IsProtocol(strDirectory, "musicdb"); |
| 889 |
} |
| 890 |
|
| 891 |
bool CGUIWindowMusicBase::OnSelect(int iItem) |
| 892 |
{ |
| 893 |
auto item = m_vecItems->Get(iItem); |
| 894 |
if (item->IsAudioBook()) |
| 895 |
{ |
| 896 |
int bookmark; |
| 897 |
if (m_musicdatabase.GetResumeBookmarkForAudioBook(*item, bookmark) && bookmark > 0) |
| 898 |
{ |
| 899 |
// find which chapter the bookmark belongs to |
| 900 |
auto itemIt = |
| 901 |
std::find_if(m_vecItems->cbegin(), m_vecItems->cend(), |
| 902 |
[&](const CFileItemPtr& item) { return bookmark < item->GetEndOffset(); }); |
| 903 |
|
| 904 |
if (itemIt != m_vecItems->cend()) |
| 905 |
{ |
| 906 |
// ask the user if they want to play or resume |
| 907 |
CContextButtons choices; |
| 908 |
choices.Add(MUSIC_SELECT_ACTION_PLAY, 208); // 208 = Play |
| 909 |
choices.Add(MUSIC_SELECT_ACTION_RESUME, |
| 910 |
StringUtils::Format(g_localizeStrings.Get(12022), // 12022 = Resume from ... |
| 911 |
(*itemIt)->GetMusicInfoTag()->GetTitle())); |
| 912 |
|
| 913 |
auto choice = CGUIDialogContextMenu::Show(choices); |
| 914 |
if (choice == MUSIC_SELECT_ACTION_RESUME) |
| 915 |
{ |
| 916 |
(*itemIt)->SetProperty("audiobook_bookmark", bookmark); |
| 917 |
return CGUIMediaWindow::OnSelect(static_cast<int>(itemIt - m_vecItems->cbegin())); |
| 918 |
} |
| 919 |
else if (choice < 0) |
| 920 |
return true; |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
|
| 925 |
return CGUIMediaWindow::OnSelect(iItem); |
| 926 |
} |
| 927 |
|
| 928 |
void CGUIWindowMusicBase::OnInitWindow() |
| 929 |
{ |
| 930 |
CGUIMediaWindow::OnInitWindow(); |
| 931 |
// Prompt for rescan of library to read music file tags that were not processed by previous versions |
| 932 |
// and accommodate any changes to the way some tags are processed |
| 933 |
if (m_musicdatabase.GetMusicNeedsTagScan() != 0) |
| 934 |
{ |
| 935 |
if (CServiceBroker::GetGUI() |
| 936 |
->GetInfoManager() |
| 937 |
.GetInfoProviders() |
| 938 |
.GetLibraryInfoProvider() |
| 939 |
.GetLibraryBool(LIBRARY_HAS_MUSIC) && |
| 940 |
!CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 941 |
{ |
| 942 |
// rescan of music library required |
| 943 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{799}, CVariant{38060})) |
| 944 |
{ |
| 945 |
int flags = CMusicInfoScanner::SCAN_RESCAN; |
| 946 |
// When set to fetch information on update enquire about scraping that as well |
| 947 |
// It may take some time, so the user may want to do it later by "Query Info For All" |
| 948 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICLIBRARY_DOWNLOADINFO)) |
| 949 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{799}, CVariant{38061})) |
| 950 |
flags |= CMusicInfoScanner::SCAN_ONLINE; |
| 951 |
|
| 952 |
CMusicLibraryQueue::GetInstance().ScanLibrary("", flags, true); |
| 953 |
|
| 954 |
m_musicdatabase.SetMusicTagScanVersion(); // once is enough (user may interrupt, but that's up to them) |
| 955 |
} |
| 956 |
} |
| 957 |
else |
| 958 |
{ |
| 959 |
// no need to force a rescan if there's no music in the library or if a library scan is already active |
| 960 |
m_musicdatabase.SetMusicTagScanVersion(); |
| 961 |
} |
| 962 |
} |
| 963 |
} |
| 964 |
|
| 965 |
std::string CGUIWindowMusicBase::GetStartFolder(const std::string &dir) |
| 966 |
{ |
| 967 |
std::string lower(dir); StringUtils::ToLower(lower); |
| 968 |
if (lower == "plugins" || lower == "addons") |
| 969 |
return "addons://sources/audio/"; |
| 970 |
else if (lower == "$playlists" || lower == "playlists") |
| 971 |
return "special://musicplaylists/"; |
| 972 |
return CGUIMediaWindow::GetStartFolder(dir); |
| 973 |
} |
| 974 |
|
| 975 |
void CGUIWindowMusicBase::OnScan(int iItem, bool bPromptRescan /*= false*/) |
| 976 |
{ |
| 977 |
std::string strPath; |
| 978 |
if (iItem < 0 || iItem >= m_vecItems->Size()) |
| 979 |
strPath = m_vecItems->GetPath(); |
| 980 |
else if (m_vecItems->Get(iItem)->m_bIsFolder) |
| 981 |
strPath = m_vecItems->Get(iItem)->GetPath(); |
| 982 |
else |
| 983 |
{ //! @todo MUSICDB - should we allow scanning a single item into the database? |
| 984 |
//! This will require changes to the info scanner, which assumes we're running on a folder |
| 985 |
strPath = m_vecItems->GetPath(); |
| 986 |
} |
| 987 |
// Ask for full rescan of music files when scan item from file view context menu |
| 988 |
bool doRescan = false; |
| 989 |
if (bPromptRescan) |
| 990 |
doRescan = CGUIDialogYesNo::ShowAndGetInput(CVariant{ 799 }, CVariant{ 38062 }); |
| 991 |
|
| 992 |
DoScan(strPath, doRescan); |
| 993 |
} |
| 994 |
|
| 995 |
void CGUIWindowMusicBase::DoScan(const std::string &strPath, bool bRescan /*= false*/) |
| 996 |
{ |
| 997 |
if (CMusicLibraryQueue::GetInstance().IsScanningLibrary()) |
| 998 |
{ |
| 999 |
CMusicLibraryQueue::GetInstance().StopLibraryScanning(); |
| 1000 |
return; |
| 1001 |
} |
| 1002 |
|
| 1003 |
// Start background loader |
| 1004 |
int iControl=GetFocusedControlID(); |
| 1005 |
int flags = 0; |
| 1006 |
if (bRescan) |
| 1007 |
flags = CMusicInfoScanner::SCAN_RESCAN; |
| 1008 |
if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(CSettings::SETTING_MUSICLIBRARY_DOWNLOADINFO)) |
| 1009 |
flags |= CMusicInfoScanner::SCAN_ONLINE; |
| 1010 |
|
| 1011 |
CMusicLibraryQueue::GetInstance().ScanLibrary(strPath, flags, true); |
| 1012 |
|
| 1013 |
SET_CONTROL_FOCUS(iControl, 0); |
| 1014 |
UpdateButtons(); |
| 1015 |
} |
| 1016 |
|
| 1017 |
void CGUIWindowMusicBase::OnRemoveSource(int iItem) |
| 1018 |
{ |
| 1019 |
|
| 1020 |
//Remove music source from library, even when leaving songs |
| 1021 |
CMusicDatabase database; |
| 1022 |
database.Open(); |
| 1023 |
database.RemoveSource(m_vecItems->Get(iItem)->GetLabel()); |
| 1024 |
|
| 1025 |
bool bCanceled; |
| 1026 |
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{522}, CVariant{20340}, bCanceled, CVariant{""}, CVariant{""}, CGUIDialogYesNo::NO_TIMEOUT)) |
| 1027 |
{ |
| 1028 |
MAPSONGS songs; |
| 1029 |
database.RemoveSongsFromPath(m_vecItems->Get(iItem)->GetPath(), songs, false); |
| 1030 |
database.CleanupOrphanedItems(); |
| 1031 |
database.CheckArtistLinksChanged(); |
| 1032 |
CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetLibraryInfoProvider().ResetLibraryBools(); |
| 1033 |
m_vecItems->RemoveDiscCache(GetID()); |
| 1034 |
} |
| 1035 |
database.Close(); |
| 1036 |
} |
| 1037 |
|
| 1038 |
void CGUIWindowMusicBase::OnPrepareFileItems(CFileItemList &items) |
| 1039 |
{ |
| 1040 |
CGUIMediaWindow::OnPrepareFileItems(items); |
| 1041 |
|
| 1042 |
if (!items.IsMusicDb() && !items.IsSmartPlayList()) |
| 1043 |
RetrieveMusicInfo(); |
| 1044 |
} |
| 1045 |
|
| 1046 |
void CGUIWindowMusicBase::OnAssignContent(const std::string& oldName, const CMediaSource& source) |
| 1047 |
{ |
| 1048 |
// Music scrapers are not source specific, so unlike video there is no content selection logic here. |
| 1049 |
// Called on having added or edited a music source, this starts scanning items into library when required |
| 1050 |
|
| 1051 |
//! @todo: do async as updating sources for all albums could be slow?? |
| 1052 |
//Store music source in the music library, even those not scanned |
| 1053 |
CMusicDatabase database; |
| 1054 |
database.Open(); |
| 1055 |
database.UpdateSource(oldName, source.strName, source.strPath, source.vecPaths); |
| 1056 |
database.Close(); |
| 1057 |
|
| 1058 |
// "Add to library" yes/no dialog with additional "settings" custom button |
| 1059 |
// "Do you want to add the media from this source to your library?" |
| 1060 |
DialogResponse rep = DialogResponse::CHOICE_CUSTOM; |
| 1061 |
while (rep == DialogResponse::CHOICE_CUSTOM) |
| 1062 |
{ |
| 1063 |
rep = HELPERS::ShowYesNoCustomDialog(CVariant{20444}, CVariant{20447}, CVariant{106}, CVariant{107}, CVariant{10004}); |
| 1064 |
if (rep == DialogResponse::CHOICE_CUSTOM) |
| 1065 |
// Edit default info provider settings so can be applied during scan |
| 1066 |
CGUIDialogInfoProviderSettings::Show(); |
| 1067 |
} |
| 1068 |
if (rep == DialogResponse::CHOICE_YES) |
| 1069 |
CMusicLibraryQueue::GetInstance().ScanLibrary(source.strPath, |
| 1070 |
MUSIC_INFO::CMusicInfoScanner::SCAN_NORMAL, true); |
| 1071 |
} |
| 1072 |
|