[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / ContextMenus.cpp
blob215545eda33e4701ba1d4810b07f8b00fc6b278a
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 "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 "storage/MediaManager.h"
18 #include "utils/StringUtils.h"
19 #include "utils/URIUtils.h"
20 #include "utils/Variant.h"
22 namespace CONTEXTMENU
25 bool CEjectDisk::IsVisible(const CFileItem& item) const
27 #ifdef HAS_OPTICAL_DRIVE
28 return item.IsRemovable() && (item.IsDVD() || item.IsCDDA());
29 #else
30 return false;
31 #endif
34 bool CEjectDisk::Execute(const std::shared_ptr<CFileItem>& item) const
36 #ifdef HAS_OPTICAL_DRIVE
37 CServiceBroker::GetMediaManager().ToggleTray(
38 CServiceBroker::GetMediaManager().TranslateDevicePath(item->GetPath())[0]);
39 #endif
40 return true;
43 bool CEjectDrive::IsVisible(const CFileItem& item) const
45 // Must be HDD
46 return item.IsRemovable() && !item.IsDVD() && !item.IsCDDA();
49 bool CEjectDrive::Execute(const std::shared_ptr<CFileItem>& item) const
51 return CServiceBroker::GetMediaManager().Eject(item->GetPath());
54 namespace
57 int GetTargetWindowID(const CFileItem& item)
59 int iTargetWindow = WINDOW_INVALID;
61 const std::string targetWindow = item.GetProperty("targetwindow").asString();
62 if (targetWindow.empty())
63 iTargetWindow = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
64 else
65 iTargetWindow = CWindowTranslator::TranslateWindow(targetWindow);
67 return iTargetWindow;
70 } // unnamed namespace
72 std::string CAddRemoveFavourite::GetLabel(const CFileItem& item) const
74 return g_localizeStrings.Get(CServiceBroker::GetFavouritesService().IsFavourited(item, GetTargetWindowID(item))
75 ? 14077 /* Remove from favourites */
76 : 14076); /* Add to favourites */
79 bool CAddRemoveFavourite::IsVisible(const CFileItem& item) const
81 if (item.GetProperty("hide_add_remove_favourite").asBoolean())
82 return false;
84 return (!item.GetPath().empty() && !item.IsParentFolder() && !item.IsPath("add") &&
85 !item.IsPath("newplaylist://") && !URIUtils::IsProtocol(item.GetPath(), "favourites") &&
86 !URIUtils::IsProtocol(item.GetPath(), "newsmartplaylist") &&
87 !URIUtils::IsProtocol(item.GetPath(), "newtag") &&
88 !URIUtils::IsProtocol(item.GetPath(), "musicsearch") &&
89 // Hide this item for all PVR EPG/timers/search except EPG/timer/timer rules/search root
90 // folders.
91 !StringUtils::StartsWith(item.GetPath(), "pvr://guide/") &&
92 !StringUtils::StartsWith(item.GetPath(), "pvr://timers/") &&
93 !StringUtils::StartsWith(item.GetPath(), "pvr://search/")) ||
94 item.GetPath() == "pvr://guide/tv/" || item.GetPath() == "pvr://guide/radio/" ||
95 item.GetPath() == "pvr://timers/tv/timers/" ||
96 item.GetPath() == "pvr://timers/radio/timers/" ||
97 item.GetPath() == "pvr://timers/tv/rules/" ||
98 item.GetPath() == "pvr://timers/radio/rules/" || item.GetPath() == "pvr://search/tv/" ||
99 item.GetPath() == "pvr://search/radio/";
102 bool CAddRemoveFavourite::Execute(const std::shared_ptr<CFileItem>& item) const
104 return CServiceBroker::GetFavouritesService().AddOrRemove(*item.get(), GetTargetWindowID(*item));
107 } // namespace CONTEXTMENU