| 1 |
/* |
| 2 |
* Copyright (C) 2015-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 "MediaLibraryEvent.h" |
| 10 |
|
| 11 |
#include "ServiceBroker.h" |
| 12 |
#include "guilib/GUIComponent.h" |
| 13 |
#include "guilib/GUIWindowManager.h" |
| 14 |
#include "guilib/LocalizeStrings.h" |
| 15 |
#include "guilib/WindowIDs.h" |
| 16 |
#include "utils/URIUtils.h" |
| 17 |
|
| 18 |
CMediaLibraryEvent::CMediaLibraryEvent(const MediaType& mediaType, const std::string& mediaPath, const CVariant& label, const CVariant& description, EventLevel level /* = EventLevel::Information */) |
| 19 |
: CUniqueEvent(label, description, level), |
| 20 |
m_mediaType(mediaType), |
| 21 |
m_mediaPath(mediaPath) |
| 22 |
{ } |
| 23 |
|
| 24 |
CMediaLibraryEvent::CMediaLibraryEvent(const MediaType& mediaType, const std::string& mediaPath, const CVariant& label, const CVariant& description, const std::string& icon, EventLevel level /* = EventLevel::Information */) |
| 25 |
: CUniqueEvent(label, description, icon, level), |
| 26 |
m_mediaType(mediaType), |
| 27 |
m_mediaPath(mediaPath) |
| 28 |
{ } |
| 29 |
|
| 30 |
CMediaLibraryEvent::CMediaLibraryEvent(const MediaType& mediaType, const std::string& mediaPath, const CVariant& label, const CVariant& description, const std::string& icon, const CVariant& details, EventLevel level /* = EventLevel::Information */) |
| 31 |
: CUniqueEvent(label, description, icon, details, level), |
| 32 |
m_mediaType(mediaType), |
| 33 |
m_mediaPath(mediaPath) |
| 34 |
{ } |
| 35 |
|
| 36 |
CMediaLibraryEvent::CMediaLibraryEvent(const MediaType& mediaType, const std::string& mediaPath, const CVariant& label, const CVariant& description, const std::string& icon, const CVariant& details, const CVariant& executionLabel, EventLevel level /* = EventLevel::Information */) |
| 37 |
: CUniqueEvent(label, description, icon, details, executionLabel, level), |
| 38 |
m_mediaType(mediaType), |
| 39 |
m_mediaPath(mediaPath) |
| 40 |
{ } |
| 41 |
|
| 42 |
std::string CMediaLibraryEvent::GetExecutionLabel() const |
| 43 |
{ |
| 44 |
std::string executionLabel = CUniqueEvent::GetExecutionLabel(); |
| 45 |
if (!executionLabel.empty()) |
| 46 |
return executionLabel; |
| 47 |
|
| 48 |
return g_localizeStrings.Get(24140); |
| 49 |
} |
| 50 |
|
| 51 |
bool CMediaLibraryEvent::Execute() const |
| 52 |
{ |
| 53 |
if (!CanExecute()) |
| 54 |
return false; |
| 55 |
|
| 56 |
int windowId = -1; |
| 57 |
std::string path = m_mediaPath; |
| 58 |
if (m_mediaType == MediaTypeVideo || m_mediaType == MediaTypeMovie || m_mediaType == MediaTypeVideoCollection || |
| 59 |
m_mediaType == MediaTypeTvShow || m_mediaType == MediaTypeSeason || m_mediaType == MediaTypeEpisode || |
| 60 |
m_mediaType == MediaTypeMusicVideo) |
| 61 |
{ |
| 62 |
if (path.empty()) |
| 63 |
{ |
| 64 |
if (m_mediaType == MediaTypeVideo) |
| 65 |
path = "sources://video/"; |
| 66 |
else if (m_mediaType == MediaTypeMovie) |
| 67 |
path = "videodb://movies/titles/"; |
| 68 |
else if (m_mediaType == MediaTypeVideoCollection) |
| 69 |
path = "videodb://movies/sets/"; |
| 70 |
else if (m_mediaType == MediaTypeMusicVideo) |
| 71 |
path = "videodb://musicvideos/titles/"; |
| 72 |
else if (m_mediaType == MediaTypeTvShow || m_mediaType == MediaTypeSeason || m_mediaType == MediaTypeEpisode) |
| 73 |
path = "videodb://tvshows/titles/"; |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
//! @todo remove the filename for now as CGUIMediaWindow::GetDirectory() can't handle it |
| 78 |
if (m_mediaType == MediaTypeMovie || m_mediaType == MediaTypeMusicVideo || m_mediaType == MediaTypeEpisode) |
| 79 |
path = URIUtils::GetDirectory(path); |
| 80 |
} |
| 81 |
|
| 82 |
windowId = WINDOW_VIDEO_NAV; |
| 83 |
} |
| 84 |
else if (m_mediaType == MediaTypeMusic || m_mediaType == MediaTypeArtist || |
| 85 |
m_mediaType == MediaTypeAlbum || m_mediaType == MediaTypeSong) |
| 86 |
{ |
| 87 |
if (path.empty()) |
| 88 |
{ |
| 89 |
if (m_mediaType == MediaTypeMusic) |
| 90 |
path = "sources://music/"; |
| 91 |
else if (m_mediaType == MediaTypeArtist) |
| 92 |
path = "musicdb://artists/"; |
| 93 |
else if (m_mediaType == MediaTypeAlbum) |
| 94 |
path = "musicdb://albums/"; |
| 95 |
else if (m_mediaType == MediaTypeSong) |
| 96 |
path = "musicdb://songs/"; |
| 97 |
} |
| 98 |
else |
| 99 |
{ |
| 100 |
//! @todo remove the filename for now as CGUIMediaWindow::GetDirectory() can't handle it |
| 101 |
if (m_mediaType == MediaTypeSong) |
| 102 |
path = URIUtils::GetDirectory(path); |
| 103 |
} |
| 104 |
|
| 105 |
windowId = WINDOW_MUSIC_NAV; |
| 106 |
} |
| 107 |
|
| 108 |
if (windowId < 0) |
| 109 |
return false; |
| 110 |
|
| 111 |
std::vector<std::string> params; |
| 112 |
params.push_back(path); |
| 113 |
params.emplace_back("return"); |
| 114 |
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowId, params); |
| 115 |
return true; |
| 116 |
} |