summaryrefslogtreecommitdiffstats
path: root/xbmc/favourites/ContextMenus.cpp
blob: 821841f7a75801e9fad20006d277af19fb633210 (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
/*
 *  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<CFileItem>& 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<CFileItem>& 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<CFileItem>& 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<CFileItem>& item) const
  {
    return FAVOURITES_UTILS::RemoveItem(items, item);
  }

  bool CRenameFavourite::DoExecute(CFileItemList&, const std::shared_ptr<CFileItem>& item) const
  {
    return FAVOURITES_UTILS::ChooseAndSetNewName(*item);
  }

  bool CChooseThumbnailForFavourite::DoExecute(CFileItemList&,
                                               const std::shared_ptr<CFileItem>& item) const
  {
    return FAVOURITES_UTILS::ChooseAndSetNewThumbnail(*item);
  }

} // namespace CONTEXTMENU