| 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 "GUIWindowMusicPlaylist.h" |
| 10 |
|
| 11 |
#include "FileItem.h" |
| 12 |
#include "GUIUserMessages.h" |
| 13 |
#include "PartyModeManager.h" |
| 14 |
#include "PlayListPlayer.h" |
| 15 |
#include "ServiceBroker.h" |
| 16 |
#include "Util.h" |
| 17 |
#include "application/Application.h" |
| 18 |
#include "application/ApplicationComponents.h" |
| 19 |
#include "application/ApplicationPlayer.h" |
| 20 |
#include "dialogs/GUIDialogSmartPlaylistEditor.h" |
| 21 |
#include "guilib/GUIComponent.h" |
| 22 |
#include "guilib/GUIKeyboardFactory.h" |
| 23 |
#include "guilib/GUIWindowManager.h" |
| 24 |
#include "guilib/LocalizeStrings.h" |
| 25 |
#include "input/actions/Action.h" |
| 26 |
#include "input/actions/ActionIDs.h" |
| 27 |
#include "music/tags/MusicInfoTag.h" |
| 28 |
#include "playlists/PlayListM3U.h" |
| 29 |
#include "profiles/ProfileManager.h" |
| 30 |
#include "settings/MediaSettings.h" |
| 31 |
#include "settings/Settings.h" |
| 32 |
#include "settings/SettingsComponent.h" |
| 33 |
#include "utils/LabelFormatter.h" |
| 34 |
#include "utils/StringUtils.h" |
| 35 |
#include "utils/URIUtils.h" |
| 36 |
#include "utils/Variant.h" |
| 37 |
#include "utils/log.h" |
| 38 |
#include "view/GUIViewState.h" |
| 39 |
|
| 40 |
#define CONTROL_BTNVIEWASICONS 2 |
| 41 |
#define CONTROL_BTNSORTBY 3 |
| 42 |
#define CONTROL_BTNSORTASC 4 |
| 43 |
#define CONTROL_LABELFILES 12 |
| 44 |
|
| 45 |
#define CONTROL_BTNSHUFFLE 20 |
| 46 |
#define CONTROL_BTNSAVE 21 |
| 47 |
#define CONTROL_BTNCLEAR 22 |
| 48 |
|
| 49 |
#define CONTROL_BTNPLAY 23 |
| 50 |
#define CONTROL_BTNNEXT 24 |
| 51 |
#define CONTROL_BTNPREVIOUS 25 |
| 52 |
#define CONTROL_BTNREPEAT 26 |
| 53 |
|
| 54 |
CGUIWindowMusicPlayList::CGUIWindowMusicPlayList(void) |
| 55 |
: CGUIWindowMusicBase(WINDOW_MUSIC_PLAYLIST, "MyPlaylist.xml") |
| 56 |
{ |
| 57 |
m_musicInfoLoader.SetObserver(this); |
| 58 |
m_movingFrom = -1; |
| 59 |
} |
| 60 |
|
| 61 |
CGUIWindowMusicPlayList::~CGUIWindowMusicPlayList(void) = default; |
| 62 |
|
| 63 |
bool CGUIWindowMusicPlayList::OnMessage(CGUIMessage& message) |
| 64 |
{ |
| 65 |
switch (message.GetMessage()) |
| 66 |
{ |
| 67 |
case GUI_MSG_PLAYLISTPLAYER_REPEAT: |
| 68 |
{ |
| 69 |
UpdateButtons(); |
| 70 |
} |
| 71 |
break; |
| 72 |
|
| 73 |
case GUI_MSG_PLAYLISTPLAYER_RANDOM: |
| 74 |
case GUI_MSG_PLAYLIST_CHANGED: |
| 75 |
{ |
| 76 |
// global playlist changed outside playlist window |
| 77 |
UpdateButtons(); |
| 78 |
|
| 79 |
if (m_vecItemsUpdating) |
| 80 |
{ |
| 81 |
CLog::Log(LOGWARNING, "CGUIWindowMusicPlayList::OnMessage - updating in progress"); |
| 82 |
return true; |
| 83 |
} |
| 84 |
CUpdateGuard ug(m_vecItemsUpdating); |
| 85 |
|
| 86 |
Refresh(true); |
| 87 |
|
| 88 |
if (m_viewControl.HasControl(m_iLastControl) && m_vecItems->Size() <= 0) |
| 89 |
{ |
| 90 |
m_iLastControl = CONTROL_BTNVIEWASICONS; |
| 91 |
SET_CONTROL_FOCUS(m_iLastControl, 0); |
| 92 |
} |
| 93 |
} |
| 94 |
break; |
| 95 |
|
| 96 |
case GUI_MSG_WINDOW_DEINIT: |
| 97 |
{ |
| 98 |
if (m_musicInfoLoader.IsLoading()) |
| 99 |
m_musicInfoLoader.StopThread(); |
| 100 |
|
| 101 |
m_movingFrom = -1; |
| 102 |
} |
| 103 |
break; |
| 104 |
|
| 105 |
case GUI_MSG_WINDOW_INIT: |
| 106 |
{ |
| 107 |
// Setup item cache for tagloader |
| 108 |
m_musicInfoLoader.UseCacheOnHD("special://temp/archive_cache/MusicPlaylist.fi"); |
| 109 |
|
| 110 |
m_vecItems->SetPath("playlistmusic://"); |
| 111 |
|
| 112 |
// updatebuttons is called in here |
| 113 |
if (!CGUIWindowMusicBase::OnMessage(message)) |
| 114 |
return false; |
| 115 |
|
| 116 |
if (m_vecItems->Size() <= 0) |
| 117 |
{ |
| 118 |
m_iLastControl = CONTROL_BTNVIEWASICONS; |
| 119 |
SET_CONTROL_FOCUS(m_iLastControl, 0); |
| 120 |
} |
| 121 |
|
| 122 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 123 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 124 |
if (appPlayer->IsPlayingAudio() && |
| 125 |
CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 126 |
{ |
| 127 |
int iSong = CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 128 |
if (iSong >= 0 && iSong <= m_vecItems->Size()) |
| 129 |
m_viewControl.SetSelectedItem(iSong); |
| 130 |
} |
| 131 |
|
| 132 |
return true; |
| 133 |
} |
| 134 |
break; |
| 135 |
|
| 136 |
case GUI_MSG_CLICKED: |
| 137 |
{ |
| 138 |
int iControl = message.GetSenderId(); |
| 139 |
if (iControl == CONTROL_BTNSHUFFLE) |
| 140 |
{ |
| 141 |
if (!g_partyModeManager.IsEnabled()) |
| 142 |
{ |
| 143 |
CServiceBroker::GetPlaylistPlayer().SetShuffle( |
| 144 |
PLAYLIST::TYPE_MUSIC, |
| 145 |
!(CServiceBroker::GetPlaylistPlayer().IsShuffled(PLAYLIST::TYPE_MUSIC))); |
| 146 |
CMediaSettings::GetInstance().SetMusicPlaylistShuffled( |
| 147 |
CServiceBroker::GetPlaylistPlayer().IsShuffled(PLAYLIST::TYPE_MUSIC)); |
| 148 |
CServiceBroker::GetSettingsComponent()->GetSettings()->Save(); |
| 149 |
UpdateButtons(); |
| 150 |
Refresh(); |
| 151 |
} |
| 152 |
} |
| 153 |
else if (iControl == CONTROL_BTNSAVE) |
| 154 |
{ |
| 155 |
if (m_musicInfoLoader.IsLoading()) // needed since we destroy m_vecitems to save memory |
| 156 |
m_musicInfoLoader.StopThread(); |
| 157 |
|
| 158 |
SavePlayList(); |
| 159 |
} |
| 160 |
else if (iControl == CONTROL_BTNCLEAR) |
| 161 |
{ |
| 162 |
if (m_musicInfoLoader.IsLoading()) |
| 163 |
m_musicInfoLoader.StopThread(); |
| 164 |
|
| 165 |
ClearPlayList(); |
| 166 |
} |
| 167 |
else if (iControl == CONTROL_BTNPLAY) |
| 168 |
{ |
| 169 |
m_guiState->SetPlaylistDirectory("playlistmusic://"); |
| 170 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_MUSIC); |
| 171 |
CServiceBroker::GetPlaylistPlayer().Reset(); |
| 172 |
CServiceBroker::GetPlaylistPlayer().Play(m_viewControl.GetSelectedItem(), ""); |
| 173 |
UpdateButtons(); |
| 174 |
} |
| 175 |
else if (iControl == CONTROL_BTNNEXT) |
| 176 |
{ |
| 177 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_MUSIC); |
| 178 |
CServiceBroker::GetPlaylistPlayer().PlayNext(); |
| 179 |
} |
| 180 |
else if (iControl == CONTROL_BTNPREVIOUS) |
| 181 |
{ |
| 182 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_MUSIC); |
| 183 |
CServiceBroker::GetPlaylistPlayer().PlayPrevious(); |
| 184 |
} |
| 185 |
else if (iControl == CONTROL_BTNREPEAT) |
| 186 |
{ |
| 187 |
// increment repeat state |
| 188 |
PLAYLIST::RepeatState state = |
| 189 |
CServiceBroker::GetPlaylistPlayer().GetRepeat(PLAYLIST::TYPE_MUSIC); |
| 190 |
if (state == PLAYLIST::RepeatState::NONE) |
| 191 |
CServiceBroker::GetPlaylistPlayer().SetRepeat(PLAYLIST::TYPE_MUSIC, |
| 192 |
PLAYLIST::RepeatState::ALL); |
| 193 |
else if (state == PLAYLIST::RepeatState::ALL) |
| 194 |
CServiceBroker::GetPlaylistPlayer().SetRepeat(PLAYLIST::TYPE_MUSIC, |
| 195 |
PLAYLIST::RepeatState::ONE); |
| 196 |
else |
| 197 |
CServiceBroker::GetPlaylistPlayer().SetRepeat(PLAYLIST::TYPE_MUSIC, |
| 198 |
PLAYLIST::RepeatState::NONE); |
| 199 |
|
| 200 |
// save settings |
| 201 |
CMediaSettings::GetInstance().SetMusicPlaylistRepeat( |
| 202 |
CServiceBroker::GetPlaylistPlayer().GetRepeat(PLAYLIST::TYPE_MUSIC) == |
| 203 |
PLAYLIST::RepeatState::ALL); |
| 204 |
CServiceBroker::GetSettingsComponent()->GetSettings()->Save(); |
| 205 |
|
| 206 |
UpdateButtons(); |
| 207 |
} |
| 208 |
else if (m_viewControl.HasControl(iControl)) |
| 209 |
{ |
| 210 |
int iAction = message.GetParam1(); |
| 211 |
int iItem = m_viewControl.GetSelectedItem(); |
| 212 |
if (iAction == ACTION_DELETE_ITEM || iAction == ACTION_MOUSE_MIDDLE_CLICK) |
| 213 |
{ |
| 214 |
RemovePlayListItem(iItem); |
| 215 |
MarkPlaying(); |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
break; |
| 220 |
} |
| 221 |
return CGUIWindowMusicBase::OnMessage(message); |
| 222 |
} |
| 223 |
|
| 224 |
bool CGUIWindowMusicPlayList::OnAction(const CAction& action) |
| 225 |
{ |
| 226 |
if (action.GetID() == ACTION_PARENT_DIR) |
| 227 |
{ |
| 228 |
// Playlist has no parent dirs |
| 229 |
return true; |
| 230 |
} |
| 231 |
if (action.GetID() == ACTION_SHOW_PLAYLIST) |
| 232 |
{ |
| 233 |
CServiceBroker::GetGUI()->GetWindowManager().PreviousWindow(); |
| 234 |
return true; |
| 235 |
} |
| 236 |
if ((action.GetID() == ACTION_MOVE_ITEM_UP) || (action.GetID() == ACTION_MOVE_ITEM_DOWN)) |
| 237 |
{ |
| 238 |
int iItem = -1; |
| 239 |
int iFocusedControl = GetFocusedControlID(); |
| 240 |
if (m_viewControl.HasControl(iFocusedControl)) |
| 241 |
iItem = m_viewControl.GetSelectedItem(); |
| 242 |
OnMove(iItem, action.GetID()); |
| 243 |
return true; |
| 244 |
} |
| 245 |
return CGUIWindowMusicBase::OnAction(action); |
| 246 |
} |
| 247 |
|
| 248 |
bool CGUIWindowMusicPlayList::OnBack(int actionID) |
| 249 |
{ |
| 250 |
if (actionID == ACTION_NAV_BACK) |
| 251 |
return CGUIWindow::OnBack(actionID); // base class goes up a folder, but none to go up |
| 252 |
return CGUIWindowMusicBase::OnBack(actionID); |
| 253 |
} |
| 254 |
|
| 255 |
bool CGUIWindowMusicPlayList::MoveCurrentPlayListItem(int iItem, |
| 256 |
int iAction, |
| 257 |
bool bUpdate /* = true */) |
| 258 |
{ |
| 259 |
int iSelected = iItem; |
| 260 |
int iNew = iSelected; |
| 261 |
if (iAction == ACTION_MOVE_ITEM_UP) |
| 262 |
iNew--; |
| 263 |
else |
| 264 |
iNew++; |
| 265 |
|
| 266 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 267 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 268 |
|
| 269 |
// is the currently playing item affected? |
| 270 |
bool bFixCurrentSong = false; |
| 271 |
if ((CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) && |
| 272 |
appPlayer->IsPlayingAudio() && |
| 273 |
((CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx() == iSelected) || |
| 274 |
(CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx() == iNew))) |
| 275 |
bFixCurrentSong = true; |
| 276 |
|
| 277 |
PLAYLIST::CPlayList& playlist = |
| 278 |
CServiceBroker::GetPlaylistPlayer().GetPlaylist(PLAYLIST::TYPE_MUSIC); |
| 279 |
if (playlist.Swap(iSelected, iNew)) |
| 280 |
{ |
| 281 |
// Correct the current playing song in playlistplayer |
| 282 |
if (bFixCurrentSong) |
| 283 |
{ |
| 284 |
int iCurrentSong = CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 285 |
if (iSelected == iCurrentSong) |
| 286 |
iCurrentSong = iNew; |
| 287 |
else if (iNew == iCurrentSong) |
| 288 |
iCurrentSong = iSelected; |
| 289 |
CServiceBroker::GetPlaylistPlayer().SetCurrentItemIdx(iCurrentSong); |
| 290 |
} |
| 291 |
|
| 292 |
if (bUpdate) |
| 293 |
Refresh(); |
| 294 |
return true; |
| 295 |
} |
| 296 |
|
| 297 |
return false; |
| 298 |
} |
| 299 |
|
| 300 |
void CGUIWindowMusicPlayList::SavePlayList() |
| 301 |
{ |
| 302 |
std::string strNewFileName; |
| 303 |
if (CGUIKeyboardFactory::ShowAndGetInput(strNewFileName, CVariant{g_localizeStrings.Get(16012)}, |
| 304 |
false)) |
| 305 |
{ |
| 306 |
// need 2 rename it |
| 307 |
strNewFileName = CUtil::MakeLegalFileName(std::move(strNewFileName)); |
| 308 |
strNewFileName += ".m3u8"; |
| 309 |
std::string strPath = |
| 310 |
URIUtils::AddFileToFolder(CServiceBroker::GetSettingsComponent()->GetSettings()->GetString( |
| 311 |
CSettings::SETTING_SYSTEM_PLAYLISTSPATH), |
| 312 |
"music", strNewFileName); |
| 313 |
|
| 314 |
// get selected item |
| 315 |
int iItem = m_viewControl.GetSelectedItem(); |
| 316 |
std::string strSelectedItem = ""; |
| 317 |
if (iItem >= 0 && iItem < m_vecItems->Size()) |
| 318 |
{ |
| 319 |
CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 320 |
if (!pItem->IsParentFolder()) |
| 321 |
{ |
| 322 |
GetDirectoryHistoryString(pItem.get(), strSelectedItem); |
| 323 |
} |
| 324 |
} |
| 325 |
|
| 326 |
std::string strOldDirectory = m_vecItems->GetPath(); |
| 327 |
m_history.SetSelectedItem(strSelectedItem, strOldDirectory, iItem); |
| 328 |
|
| 329 |
PLAYLIST::CPlayListM3U playlist; |
| 330 |
for (int i = 0; i < m_vecItems->Size(); ++i) |
| 331 |
{ |
| 332 |
CFileItemPtr pItem = m_vecItems->Get(i); |
| 333 |
|
| 334 |
// Musicdatabase items should contain the real path instead of a musicdb url |
| 335 |
// otherwise the user can't save and reuse the playlist when the musicdb gets deleted |
| 336 |
if (pItem->IsMusicDb()) |
| 337 |
pItem->SetPath(pItem->GetMusicInfoTag()->GetURL()); |
| 338 |
|
| 339 |
playlist.Add(pItem); |
| 340 |
} |
| 341 |
CLog::Log(LOGDEBUG, "Saving music playlist: [{}]", strPath); |
| 342 |
playlist.Save(strPath); |
| 343 |
Refresh(); // need to update |
| 344 |
} |
| 345 |
} |
| 346 |
|
| 347 |
void CGUIWindowMusicPlayList::ClearPlayList() |
| 348 |
{ |
| 349 |
ClearFileItems(); |
| 350 |
CServiceBroker::GetPlaylistPlayer().ClearPlaylist(PLAYLIST::TYPE_MUSIC); |
| 351 |
if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 352 |
{ |
| 353 |
CServiceBroker::GetPlaylistPlayer().Reset(); |
| 354 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_NONE); |
| 355 |
} |
| 356 |
Refresh(); |
| 357 |
SET_CONTROL_FOCUS(CONTROL_BTNVIEWASICONS, 0); |
| 358 |
} |
| 359 |
|
| 360 |
void CGUIWindowMusicPlayList::RemovePlayListItem(int iItem) |
| 361 |
{ |
| 362 |
if (iItem < 0 || iItem > m_vecItems->Size()) |
| 363 |
return; |
| 364 |
|
| 365 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 366 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 367 |
// The current playing song can't be removed |
| 368 |
if (CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC && |
| 369 |
appPlayer->IsPlayingAudio() && |
| 370 |
CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx() == iItem) |
| 371 |
return; |
| 372 |
|
| 373 |
CServiceBroker::GetPlaylistPlayer().Remove(PLAYLIST::TYPE_MUSIC, iItem); |
| 374 |
|
| 375 |
Refresh(); |
| 376 |
|
| 377 |
if (m_vecItems->Size() <= 0) |
| 378 |
{ |
| 379 |
SET_CONTROL_FOCUS(CONTROL_BTNVIEWASICONS, 0); |
| 380 |
} |
| 381 |
else |
| 382 |
{ |
| 383 |
m_viewControl.SetSelectedItem(iItem); |
| 384 |
} |
| 385 |
|
| 386 |
g_partyModeManager.OnSongChange(); |
| 387 |
} |
| 388 |
|
| 389 |
void CGUIWindowMusicPlayList::UpdateButtons() |
| 390 |
{ |
| 391 |
CGUIWindowMusicBase::UpdateButtons(); |
| 392 |
|
| 393 |
// Update playlist buttons |
| 394 |
if (m_vecItems->Size() && !g_partyModeManager.IsEnabled()) |
| 395 |
{ |
| 396 |
CONTROL_ENABLE(CONTROL_BTNSHUFFLE); |
| 397 |
CONTROL_ENABLE(CONTROL_BTNSAVE); |
| 398 |
CONTROL_ENABLE(CONTROL_BTNCLEAR); |
| 399 |
CONTROL_ENABLE(CONTROL_BTNREPEAT); |
| 400 |
CONTROL_ENABLE(CONTROL_BTNPLAY); |
| 401 |
|
| 402 |
const auto& components = CServiceBroker::GetAppComponents(); |
| 403 |
const auto appPlayer = components.GetComponent<CApplicationPlayer>(); |
| 404 |
if (appPlayer->IsPlayingAudio() && |
| 405 |
CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == PLAYLIST::TYPE_MUSIC) |
| 406 |
{ |
| 407 |
CONTROL_ENABLE(CONTROL_BTNNEXT); |
| 408 |
CONTROL_ENABLE(CONTROL_BTNPREVIOUS); |
| 409 |
} |
| 410 |
else |
| 411 |
{ |
| 412 |
CONTROL_DISABLE(CONTROL_BTNNEXT); |
| 413 |
CONTROL_DISABLE(CONTROL_BTNPREVIOUS); |
| 414 |
} |
| 415 |
} |
| 416 |
else |
| 417 |
{ |
| 418 |
// disable buttons if party mode is enabled too |
| 419 |
CONTROL_DISABLE(CONTROL_BTNSHUFFLE); |
| 420 |
CONTROL_DISABLE(CONTROL_BTNSAVE); |
| 421 |
CONTROL_DISABLE(CONTROL_BTNCLEAR); |
| 422 |
CONTROL_DISABLE(CONTROL_BTNREPEAT); |
| 423 |
CONTROL_DISABLE(CONTROL_BTNPLAY); |
| 424 |
CONTROL_DISABLE(CONTROL_BTNNEXT); |
| 425 |
CONTROL_DISABLE(CONTROL_BTNPREVIOUS); |
| 426 |
} |
| 427 |
|
| 428 |
// update buttons |
| 429 |
CONTROL_DESELECT(CONTROL_BTNSHUFFLE); |
| 430 |
if (CServiceBroker::GetPlaylistPlayer().IsShuffled(PLAYLIST::TYPE_MUSIC)) |
| 431 |
CONTROL_SELECT(CONTROL_BTNSHUFFLE); |
| 432 |
|
| 433 |
// update repeat button |
| 434 |
int iLocalizedString; |
| 435 |
PLAYLIST::RepeatState repState = |
| 436 |
CServiceBroker::GetPlaylistPlayer().GetRepeat(PLAYLIST::TYPE_MUSIC); |
| 437 |
if (repState == PLAYLIST::RepeatState::NONE) |
| 438 |
iLocalizedString = 595; // Repeat: Off |
| 439 |
else if (repState == PLAYLIST::RepeatState::ONE) |
| 440 |
iLocalizedString = 596; // Repeat: One |
| 441 |
else |
| 442 |
iLocalizedString = 597; // Repeat: All |
| 443 |
|
| 444 |
SET_CONTROL_LABEL(CONTROL_BTNREPEAT, g_localizeStrings.Get(iLocalizedString)); |
| 445 |
|
| 446 |
// Update object count label |
| 447 |
std::string items = |
| 448 |
StringUtils::Format("{} {}", m_vecItems->GetObjectCount(), g_localizeStrings.Get(127)); |
| 449 |
SET_CONTROL_LABEL(CONTROL_LABELFILES, items); |
| 450 |
|
| 451 |
MarkPlaying(); |
| 452 |
} |
| 453 |
|
| 454 |
bool CGUIWindowMusicPlayList::OnPlayMedia(int iItem, const std::string& player) |
| 455 |
{ |
| 456 |
if (g_partyModeManager.IsEnabled()) |
| 457 |
g_partyModeManager.Play(iItem); |
| 458 |
else |
| 459 |
{ |
| 460 |
PLAYLIST::Id playlistId = m_guiState->GetPlaylist(); |
| 461 |
if (playlistId != PLAYLIST::TYPE_NONE) |
| 462 |
{ |
| 463 |
if (m_guiState) |
| 464 |
m_guiState->SetPlaylistDirectory(m_vecItems->GetPath()); |
| 465 |
|
| 466 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(playlistId); |
| 467 |
CServiceBroker::GetPlaylistPlayer().Play(iItem, player); |
| 468 |
} |
| 469 |
else |
| 470 |
{ |
| 471 |
// Reset Playlistplayer, playback started now does |
| 472 |
// not use the playlistplayer. |
| 473 |
CFileItemPtr pItem = m_vecItems->Get(iItem); |
| 474 |
CServiceBroker::GetPlaylistPlayer().Reset(); |
| 475 |
CServiceBroker::GetPlaylistPlayer().SetCurrentPlaylist(PLAYLIST::TYPE_NONE); |
| 476 |
g_application.PlayFile(*pItem, player); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
return true; |
| 481 |
} |
| 482 |
|
| 483 |
void CGUIWindowMusicPlayList::OnItemLoaded(CFileItem* pItem) |
| 484 |
{ |
| 485 |
if (pItem->HasMusicInfoTag() && pItem->GetMusicInfoTag()->Loaded()) |
| 486 |
{ // set label 1+2 from tags |
| 487 |
const std::shared_ptr<CSettings> settings = |
| 488 |
CServiceBroker::GetSettingsComponent()->GetSettings(); |
| 489 |
std::string strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_NOWPLAYINGTRACKFORMAT); |
| 490 |
if (strTrack.empty()) |
| 491 |
strTrack = settings->GetString(CSettings::SETTING_MUSICFILES_TRACKFORMAT); |
| 492 |
CLabelFormatter formatter(strTrack, "%D"); |
| 493 |
formatter.FormatLabels(pItem); |
| 494 |
} // if (pItem->m_musicInfoTag.Loaded()) |
| 495 |
else |
| 496 |
{ |
| 497 |
// Our tag may have a duration even if its not loaded |
| 498 |
if (pItem->HasMusicInfoTag() && pItem->GetMusicInfoTag()->GetDuration()) |
| 499 |
{ |
| 500 |
int nDuration = pItem->GetMusicInfoTag()->GetDuration(); |
| 501 |
if (nDuration > 0) |
| 502 |
pItem->SetLabel2(StringUtils::SecondsToTimeString(nDuration)); |
| 503 |
} |
| 504 |
else if (pItem->GetLabel() == "") // pls labels come in preformatted |
| 505 |
{ |
| 506 |
// FIXME: get the position of the item in the playlist |
| 507 |
// currently it is hacked into m_iprogramCount |
| 508 |
|
| 509 |
// No music info and it's not CDDA so we'll just show the filename |
| 510 |
std::string str; |
| 511 |
str = CUtil::GetTitleFromPath(pItem->GetPath()); |
| 512 |
str = StringUtils::Format("{:02}. {} ", pItem->m_iprogramCount, str); |
| 513 |
pItem->SetLabel(str); |
| 514 |
} |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
bool CGUIWindowMusicPlayList::Update(const std::string& strDirectory, |
| 519 |
bool updateFilterPath /* = true */) |
| 520 |
{ |
| 521 |
if (m_musicInfoLoader.IsLoading()) |
| 522 |
m_musicInfoLoader.StopThread(); |
| 523 |
|
| 524 |
if (!CGUIWindowMusicBase::Update(strDirectory, updateFilterPath)) |
| 525 |
return false; |
| 526 |
|
| 527 |
if (m_vecItems->GetContent().empty()) |
| 528 |
m_vecItems->SetContent("songs"); |
| 529 |
|
| 530 |
m_musicInfoLoader.Load(*m_vecItems); |
| 531 |
return true; |
| 532 |
} |
| 533 |
|
| 534 |
void CGUIWindowMusicPlayList::GetContextButtons(int itemNumber, CContextButtons& buttons) |
| 535 |
{ |
| 536 |
// is this playlist playing? |
| 537 |
int itemPlaying = CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 538 |
|
| 539 |
if (itemNumber >= 0 && itemNumber < m_vecItems->Size()) |
| 540 |
{ |
| 541 |
CFileItemPtr item; |
| 542 |
item = m_vecItems->Get(itemNumber); |
| 543 |
|
| 544 |
if (m_movingFrom >= 0) |
| 545 |
{ |
| 546 |
// we can move the item to any position not where we are, and any position not above currently |
| 547 |
// playing item in party mode |
| 548 |
if (itemNumber != m_movingFrom && |
| 549 |
(!g_partyModeManager.IsEnabled() || itemNumber > itemPlaying)) |
| 550 |
buttons.Add(CONTEXT_BUTTON_MOVE_HERE, 13252); // move item here |
| 551 |
buttons.Add(CONTEXT_BUTTON_CANCEL_MOVE, 13253); |
| 552 |
} |
| 553 |
else |
| 554 |
{ |
| 555 |
if (itemNumber > (g_partyModeManager.IsEnabled() ? 1 : 0)) |
| 556 |
buttons.Add(CONTEXT_BUTTON_MOVE_ITEM_UP, 13332); |
| 557 |
if (itemNumber + 1 < m_vecItems->Size()) |
| 558 |
buttons.Add(CONTEXT_BUTTON_MOVE_ITEM_DOWN, 13333); |
| 559 |
if (!g_partyModeManager.IsEnabled() || itemNumber != itemPlaying) |
| 560 |
buttons.Add(CONTEXT_BUTTON_MOVE_ITEM, 13251); |
| 561 |
if (itemNumber != itemPlaying) |
| 562 |
buttons.Add(CONTEXT_BUTTON_DELETE, 1210); // Remove |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
if (g_partyModeManager.IsEnabled()) |
| 567 |
{ |
| 568 |
buttons.Add(CONTEXT_BUTTON_EDIT_PARTYMODE, 21439); |
| 569 |
buttons.Add(CONTEXT_BUTTON_CANCEL_PARTYMODE, 588); // cancel party mode |
| 570 |
} |
| 571 |
} |
| 572 |
|
| 573 |
bool CGUIWindowMusicPlayList::OnContextButton(int itemNumber, CONTEXT_BUTTON button) |
| 574 |
{ |
| 575 |
switch (button) |
| 576 |
{ |
| 577 |
case CONTEXT_BUTTON_MOVE_ITEM: |
| 578 |
m_movingFrom = itemNumber; |
| 579 |
return true; |
| 580 |
|
| 581 |
case CONTEXT_BUTTON_MOVE_HERE: |
| 582 |
MoveItem(m_movingFrom, itemNumber); |
| 583 |
m_movingFrom = -1; |
| 584 |
return true; |
| 585 |
|
| 586 |
case CONTEXT_BUTTON_CANCEL_MOVE: |
| 587 |
m_movingFrom = -1; |
| 588 |
return true; |
| 589 |
|
| 590 |
case CONTEXT_BUTTON_MOVE_ITEM_UP: |
| 591 |
OnMove(itemNumber, ACTION_MOVE_ITEM_UP); |
| 592 |
return true; |
| 593 |
|
| 594 |
case CONTEXT_BUTTON_MOVE_ITEM_DOWN: |
| 595 |
OnMove(itemNumber, ACTION_MOVE_ITEM_DOWN); |
| 596 |
return true; |
| 597 |
|
| 598 |
case CONTEXT_BUTTON_DELETE: |
| 599 |
RemovePlayListItem(itemNumber); |
| 600 |
return true; |
| 601 |
|
| 602 |
case CONTEXT_BUTTON_CANCEL_PARTYMODE: |
| 603 |
g_partyModeManager.Disable(); |
| 604 |
return true; |
| 605 |
|
| 606 |
case CONTEXT_BUTTON_EDIT_PARTYMODE: |
| 607 |
{ |
| 608 |
const std::shared_ptr<CProfileManager> profileManager = |
| 609 |
CServiceBroker::GetSettingsComponent()->GetProfileManager(); |
| 610 |
|
| 611 |
std::string playlist = profileManager->GetUserDataItem("PartyMode.xsp"); |
| 612 |
if (CGUIDialogSmartPlaylistEditor::EditPlaylist(playlist)) |
| 613 |
{ |
| 614 |
// apply new rules |
| 615 |
g_partyModeManager.Disable(); |
| 616 |
g_partyModeManager.Enable(); |
| 617 |
} |
| 618 |
return true; |
| 619 |
} |
| 620 |
|
| 621 |
default: |
| 622 |
break; |
| 623 |
} |
| 624 |
return CGUIWindowMusicBase::OnContextButton(itemNumber, button); |
| 625 |
} |
| 626 |
|
| 627 |
void CGUIWindowMusicPlayList::OnMove(int iItem, int iAction) |
| 628 |
{ |
| 629 |
if (iItem < 0 || iItem >= m_vecItems->Size()) |
| 630 |
return; |
| 631 |
|
| 632 |
bool bRestart = m_musicInfoLoader.IsLoading(); |
| 633 |
if (bRestart) |
| 634 |
m_musicInfoLoader.StopThread(); |
| 635 |
|
| 636 |
MoveCurrentPlayListItem(iItem, iAction); |
| 637 |
|
| 638 |
if (bRestart) |
| 639 |
m_musicInfoLoader.Load(*m_vecItems); |
| 640 |
} |
| 641 |
|
| 642 |
void CGUIWindowMusicPlayList::MoveItem(int iStart, int iDest) |
| 643 |
{ |
| 644 |
if (iStart < 0 || iStart >= m_vecItems->Size()) |
| 645 |
return; |
| 646 |
if (iDest < 0 || iDest >= m_vecItems->Size()) |
| 647 |
return; |
| 648 |
|
| 649 |
// default to move up |
| 650 |
int iAction = ACTION_MOVE_ITEM_UP; |
| 651 |
int iDirection = -1; |
| 652 |
// are we moving down? |
| 653 |
if (iStart < iDest) |
| 654 |
{ |
| 655 |
iAction = ACTION_MOVE_ITEM_DOWN; |
| 656 |
iDirection = 1; |
| 657 |
} |
| 658 |
|
| 659 |
bool bRestart = m_musicInfoLoader.IsLoading(); |
| 660 |
if (bRestart) |
| 661 |
m_musicInfoLoader.StopThread(); |
| 662 |
|
| 663 |
// keep swapping until you get to the destination or you |
| 664 |
// hit the currently playing song |
| 665 |
int i = iStart; |
| 666 |
while (i != iDest) |
| 667 |
{ |
| 668 |
// try to swap adjacent items |
| 669 |
if (MoveCurrentPlayListItem(i, iAction, false)) |
| 670 |
i = i + (1 * iDirection); |
| 671 |
// we hit currently playing song, so abort |
| 672 |
else |
| 673 |
break; |
| 674 |
} |
| 675 |
Refresh(); |
| 676 |
|
| 677 |
if (bRestart) |
| 678 |
m_musicInfoLoader.Load(*m_vecItems); |
| 679 |
} |
| 680 |
|
| 681 |
void CGUIWindowMusicPlayList::MarkPlaying() |
| 682 |
{ |
| 683 |
/* // clear markings |
| 684 |
for (int i = 0; i < m_vecItems->Size(); i++) |
| 685 |
m_vecItems->Get(i)->Select(false); |
| 686 |
|
| 687 |
// mark the currently playing item |
| 688 |
if ((CServiceBroker::GetPlaylistPlayer().GetCurrentPlaylist() == TYPE_MUSIC) && (g_application.GetAppPlayer().IsPlayingAudio())) |
| 689 |
{ |
| 690 |
int iSong = CServiceBroker::GetPlaylistPlayer().GetCurrentItemIdx(); |
| 691 |
if (iSong >= 0 && iSong <= m_vecItems->Size()) |
| 692 |
m_vecItems->Get(iSong)->Select(true); |
| 693 |
}*/ |
| 694 |
} |