blob: 4dacfda7a28ead7213da8b65c302a5a5f405fb34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* Copyright (C) 2016-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "ContextMenus.h"
#include "ServiceBroker.h"
#include "favourites/FavouritesService.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "input/WindowTranslator.h"
#include "storage/MediaManager.h"
#include "utils/StringUtils.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
namespace CONTEXTMENU
{
bool CEjectDisk::IsVisible(const CFileItem& item) const
{
#ifdef HAS_DVD_DRIVE
return item.IsRemovable() && (item.IsDVD() || item.IsCDDA());
#else
return false;
#endif
}
bool CEjectDisk::Execute(const std::shared_ptr<CFileItem>& item) const
{
#ifdef HAS_DVD_DRIVE
CServiceBroker::GetMediaManager().ToggleTray(
CServiceBroker::GetMediaManager().TranslateDevicePath(item->GetPath())[0]);
#endif
return true;
}
bool CEjectDrive::IsVisible(const CFileItem& item) const
{
// Must be HDD
return item.IsRemovable() && !item.IsDVD() && !item.IsCDDA();
}
bool CEjectDrive::Execute(const std::shared_ptr<CFileItem>& item) const
{
return CServiceBroker::GetMediaManager().Eject(item->GetPath());
}
namespace
{
int GetTargetWindowID(const CFileItem& item)
{
int iTargetWindow = WINDOW_INVALID;
const std::string targetWindow = item.GetProperty("targetwindow").asString();
if (targetWindow.empty())
iTargetWindow = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
else
iTargetWindow = CWindowTranslator::TranslateWindow(targetWindow);
return iTargetWindow;
}
} // unnamed namespace
std::string CAddRemoveFavourite::GetLabel(const CFileItem& item) const
{
return g_localizeStrings.Get(CServiceBroker::GetFavouritesService().IsFavourited(item, GetTargetWindowID(item))
? 14077 /* Remove from favourites */
: 14076); /* Add to favourites */
}
bool CAddRemoveFavourite::IsVisible(const CFileItem& item) const
{
return (!item.GetPath().empty() && !item.IsParentFolder() && !item.IsPath("add") &&
!item.IsPath("newplaylist://") && !URIUtils::IsProtocol(item.GetPath(), "favourites") &&
!URIUtils::IsProtocol(item.GetPath(), "newsmartplaylist") &&
!URIUtils::IsProtocol(item.GetPath(), "newtag") &&
!URIUtils::IsProtocol(item.GetPath(), "musicsearch") &&
// Hide this item for all PVR EPG/timers/search except EPG/timer/timer rules/search root
// folders.
!StringUtils::StartsWith(item.GetPath(), "pvr://guide/") &&
!StringUtils::StartsWith(item.GetPath(), "pvr://timers/") &&
!StringUtils::StartsWith(item.GetPath(), "pvr://search/")) ||
item.GetPath() == "pvr://guide/tv/" || item.GetPath() == "pvr://guide/radio/" ||
item.GetPath() == "pvr://timers/tv/timers/" ||
item.GetPath() == "pvr://timers/radio/timers/" ||
item.GetPath() == "pvr://timers/tv/rules/" ||
item.GetPath() == "pvr://timers/radio/rules/" || item.GetPath() == "pvr://search/tv/" ||
item.GetPath() == "pvr://search/radio/";
}
bool CAddRemoveFavourite::Execute(const std::shared_ptr<CFileItem>& item) const
{
return CServiceBroker::GetFavouritesService().AddOrRemove(*item.get(), GetTargetWindowID(*item));
}
} // namespace CONTEXTMENU
|