[filesystem][SpecialProtocol] Removed assert from GetPath
[xbmc.git] / xbmc / music / ContextMenus.cpp
blob4c26ad374ac1333c5a3d9508e9c8dd663ce18734
1 /*
2 * Copyright (C) 2016-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "ContextMenus.h"
11 #include "FileItem.h"
12 #include "GUIUserMessages.h"
13 #include "ServiceBroker.h"
14 #include "guilib/GUIComponent.h"
15 #include "guilib/GUIWindowManager.h"
16 #include "music/MusicUtils.h"
17 #include "music/dialogs/GUIDialogMusicInfo.h"
18 #include "playlists/PlayListTypes.h"
19 #include "tags/MusicInfoTag.h"
20 #include "utils/Variant.h"
22 #include <utility>
24 using namespace CONTEXTMENU;
26 CMusicInfo::CMusicInfo(MediaType mediaType)
27 : CStaticContextMenuAction(19033), m_mediaType(std::move(mediaType))
31 bool CMusicInfo::IsVisible(const CFileItem& item) const
33 return (item.HasMusicInfoTag() && item.GetMusicInfoTag()->GetType() == m_mediaType) ||
34 (m_mediaType == MediaTypeArtist && item.IsVideoDb() && item.HasProperty("artist_musicid")) ||
35 (m_mediaType == MediaTypeAlbum && item.IsVideoDb() && item.HasProperty("album_musicid"));
38 bool CMusicInfo::Execute(const std::shared_ptr<CFileItem>& item) const
40 CGUIDialogMusicInfo::ShowFor(item.get());
41 return true;
44 bool CMusicBrowse::IsVisible(const CFileItem& item) const
46 if (item.IsFileFolder(EFILEFOLDER_MASK_ONBROWSE))
47 return false; // handled by CMediaWindow
49 return item.m_bIsFolder && MUSIC_UTILS::IsItemPlayable(item);
52 bool CMusicBrowse::Execute(const std::shared_ptr<CFileItem>& item) const
54 auto& windowMgr = CServiceBroker::GetGUI()->GetWindowManager();
55 if (windowMgr.GetActiveWindow() == WINDOW_MUSIC_NAV)
57 CGUIMessage msg(GUI_MSG_NOTIFY_ALL, WINDOW_MUSIC_NAV, 0, GUI_MSG_UPDATE);
58 msg.SetStringParam(item->GetPath());
59 windowMgr.SendMessage(msg);
61 else
63 windowMgr.ActivateWindow(WINDOW_MUSIC_NAV, {item->GetPath(), "return"});
65 return true;
68 bool CMusicPlay::IsVisible(const CFileItem& item) const
70 return MUSIC_UTILS::IsItemPlayable(item);
73 bool CMusicPlay::Execute(const std::shared_ptr<CFileItem>& item) const
75 const ContentUtils::PlayMode mode = item->GetProperty("CheckAutoPlayNextItem").asBoolean()
76 ? ContentUtils::PlayMode::CHECK_AUTO_PLAY_NEXT_ITEM
77 : ContentUtils::PlayMode::PLAY_ONLY_THIS;
78 MUSIC_UTILS::PlayItem(item, mode);
80 item->SetProperty("playlist_type_hint", PLAYLIST::TYPE_MUSIC);
81 return true;
84 bool CMusicPlayNext::IsVisible(const CFileItem& item) const
86 if (!item.CanQueue())
87 return false;
89 return MUSIC_UTILS::IsItemPlayable(item);
92 bool CMusicPlayNext::Execute(const std::shared_ptr<CFileItem>& item) const
94 MUSIC_UTILS::QueueItem(item, MUSIC_UTILS::QueuePosition::POSITION_BEGIN);
95 return true;
98 bool CMusicQueue::IsVisible(const CFileItem& item) const
100 if (!item.CanQueue())
101 return false;
103 return MUSIC_UTILS::IsItemPlayable(item);
106 namespace
108 void SelectNextItem(int windowID)
110 auto& windowMgr = CServiceBroker::GetGUI()->GetWindowManager();
111 CGUIWindow* window = windowMgr.GetWindow(windowID);
112 if (window)
114 const int viewContainerID = window->GetViewContainerID();
115 if (viewContainerID > 0)
117 CGUIMessage msg1(GUI_MSG_ITEM_SELECTED, windowID, viewContainerID);
118 windowMgr.SendMessage(msg1, windowID);
120 CGUIMessage msg2(GUI_MSG_ITEM_SELECT, windowID, viewContainerID, msg1.GetParam1() + 1);
121 windowMgr.SendMessage(msg2, windowID);
125 } // unnamed namespace
127 bool CMusicQueue::Execute(const std::shared_ptr<CFileItem>& item) const
129 MUSIC_UTILS::QueueItem(item, MUSIC_UTILS::QueuePosition::POSITION_END);
131 // Set selection to next item in active window's view.
132 const int windowID = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
133 SelectNextItem(windowID);
135 return true;