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.
9 #include "ContextMenus.h"
11 #include "ServiceBroker.h"
12 #include "favourites/FavouritesService.h"
13 #include "guilib/GUIComponent.h"
14 #include "guilib/GUIWindowManager.h"
15 #include "guilib/LocalizeStrings.h"
16 #include "input/WindowTranslator.h"
17 #include "music/MusicFileItemClassify.h"
18 #include "storage/MediaManager.h"
19 #include "utils/StringUtils.h"
20 #include "utils/URIUtils.h"
21 #include "utils/Variant.h"
28 bool CEjectDisk::IsVisible(const CFileItem
& item
) const
30 #ifdef HAS_OPTICAL_DRIVE
31 return item
.IsRemovable() && (item
.IsDVD() || MUSIC::IsCDDA(item
));
37 bool CEjectDisk::Execute(const std::shared_ptr
<CFileItem
>& item
) const
39 #ifdef HAS_OPTICAL_DRIVE
40 CServiceBroker::GetMediaManager().ToggleTray(
41 CServiceBroker::GetMediaManager().TranslateDevicePath(item
->GetPath())[0]);
46 bool CEjectDrive::IsVisible(const CFileItem
& item
) const
49 return item
.IsRemovable() && !item
.IsDVD() && !MUSIC::IsCDDA(item
);
52 bool CEjectDrive::Execute(const std::shared_ptr
<CFileItem
>& item
) const
54 return CServiceBroker::GetMediaManager().Eject(item
->GetPath());
60 int GetTargetWindowID(const CFileItem
& item
)
62 int iTargetWindow
= WINDOW_INVALID
;
64 const std::string targetWindow
= item
.GetProperty("targetwindow").asString();
65 if (targetWindow
.empty())
66 iTargetWindow
= CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
68 iTargetWindow
= CWindowTranslator::TranslateWindow(targetWindow
);
73 } // unnamed namespace
75 std::string
CAddRemoveFavourite::GetLabel(const CFileItem
& item
) const
77 return g_localizeStrings
.Get(CServiceBroker::GetFavouritesService().IsFavourited(item
, GetTargetWindowID(item
))
78 ? 14077 /* Remove from favourites */
79 : 14076); /* Add to favourites */
82 bool CAddRemoveFavourite::IsVisible(const CFileItem
& item
) const
84 if (item
.GetProperty("hide_add_remove_favourite").asBoolean())
87 return (!item
.GetPath().empty() && !item
.IsParentFolder() && !item
.IsPath("add") &&
88 !item
.IsPath("newplaylist://") && !URIUtils::IsProtocol(item
.GetPath(), "favourites") &&
89 !URIUtils::IsProtocol(item
.GetPath(), "newsmartplaylist") &&
90 !URIUtils::IsProtocol(item
.GetPath(), "newtag") &&
91 !URIUtils::IsProtocol(item
.GetPath(), "musicsearch") &&
92 // Hide this item for all PVR EPG/timers/search except EPG/timer/timer rules/search root
94 !StringUtils::StartsWith(item
.GetPath(), "pvr://guide/") &&
95 !StringUtils::StartsWith(item
.GetPath(), "pvr://timers/") &&
96 !StringUtils::StartsWith(item
.GetPath(), "pvr://search/")) ||
97 item
.GetPath() == "pvr://guide/tv/" || item
.GetPath() == "pvr://guide/radio/" ||
98 item
.GetPath() == "pvr://timers/tv/timers/" ||
99 item
.GetPath() == "pvr://timers/radio/timers/" ||
100 item
.GetPath() == "pvr://timers/tv/rules/" ||
101 item
.GetPath() == "pvr://timers/radio/rules/" || item
.GetPath() == "pvr://search/tv/" ||
102 item
.GetPath() == "pvr://search/radio/";
105 bool CAddRemoveFavourite::Execute(const std::shared_ptr
<CFileItem
>& item
) const
107 return CServiceBroker::GetFavouritesService().AddOrRemove(*item
.get(), GetTargetWindowID(*item
));
110 } // namespace CONTEXTMENU