From c04dcc2e7d834218ef2d4194331e383402495ae1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 20:07:22 +0200 Subject: Adding upstream version 2:20.4+dfsg. Signed-off-by: Daniel Baumann --- xbmc/favourites/ContextMenus.cpp | 80 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 xbmc/favourites/ContextMenus.cpp (limited to 'xbmc/favourites/ContextMenus.cpp') diff --git a/xbmc/favourites/ContextMenus.cpp b/xbmc/favourites/ContextMenus.cpp new file mode 100644 index 0000000..821841f --- /dev/null +++ b/xbmc/favourites/ContextMenus.cpp @@ -0,0 +1,80 @@ +/* + * 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 "FileItem.h" +#include "ServiceBroker.h" +#include "favourites/FavouritesService.h" +#include "favourites/FavouritesUtils.h" +#include "utils/URIUtils.h" + +namespace CONTEXTMENU +{ + bool CFavouriteContextMenuAction::IsVisible(const CFileItem& item) const + { + return URIUtils::IsProtocol(item.GetPath(), "favourites"); + } + + bool CFavouriteContextMenuAction::Execute(const std::shared_ptr& item) const + { + CFileItemList items; + CServiceBroker::GetFavouritesService().GetAll(items); + for (const auto& favourite : items) + { + if (favourite->GetPath() == item->GetPath()) + { + if (DoExecute(items, favourite)) + return CServiceBroker::GetFavouritesService().Save(items); + } + } + return false; + } + + bool CMoveUpFavourite::DoExecute(CFileItemList& items, + const std::shared_ptr& item) const + { + return FAVOURITES_UTILS::MoveItem(items, item, -1); + } + + bool CMoveUpFavourite::IsVisible(const CFileItem& item) const + { + return CFavouriteContextMenuAction::IsVisible(item) && + FAVOURITES_UTILS::ShouldEnableMoveItems(); + } + + bool CMoveDownFavourite::DoExecute(CFileItemList& items, + const std::shared_ptr& item) const + { + return FAVOURITES_UTILS::MoveItem(items, item, +1); + } + + bool CMoveDownFavourite::IsVisible(const CFileItem& item) const + { + return CFavouriteContextMenuAction::IsVisible(item) && + FAVOURITES_UTILS::ShouldEnableMoveItems(); + } + + bool CRemoveFavourite::DoExecute(CFileItemList& items, + const std::shared_ptr& item) const + { + return FAVOURITES_UTILS::RemoveItem(items, item); + } + + bool CRenameFavourite::DoExecute(CFileItemList&, const std::shared_ptr& item) const + { + return FAVOURITES_UTILS::ChooseAndSetNewName(*item); + } + + bool CChooseThumbnailForFavourite::DoExecute(CFileItemList&, + const std::shared_ptr& item) const + { + return FAVOURITES_UTILS::ChooseAndSetNewThumbnail(*item); + } + +} // namespace CONTEXTMENU -- cgit v1.2.3