File: ContextMenuManager.h

package info (click to toggle)
kodi 2%3A21.2%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 143,076 kB
  • sloc: cpp: 694,471; xml: 52,618; ansic: 38,300; python: 7,161; sh: 4,289; javascript: 2,325; makefile: 1,791; perl: 969; java: 513; cs: 390; objc: 340
file content (116 lines) | stat: -rw-r--r-- 3,426 bytes parent folder | download | duplicates (2)
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
105
106
107
108
109
110
111
112
113
114
115
116
/*
 *  Copyright (C) 2013-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.
 */

#pragma once

#include "ContextMenuItem.h"
#include "threads/CriticalSection.h"

#include <memory>
#include <utility>
#include <vector>

namespace ADDON
{
struct AddonEvent;
class CAddonMgr;
} // namespace ADDON

namespace PVR
{
  struct PVRContextMenuEvent;
}

using ContextMenuView = std::vector<std::shared_ptr<const IContextMenuItem>>;

class CContextMenuManager
{
public:
  static const CContextMenuItem MAIN;
  static const CContextMenuItem MANAGE;

  explicit CContextMenuManager(ADDON::CAddonMgr& addonMgr);
  ~CContextMenuManager();

  void Init();
  void Deinit();

  /*! \brief Checks whether context menu items are available for a file item.
   \param fileItem the file item
   \param root the root context menu item
   \return true if any items are present, false otherwise
   */
  bool HasItems(const CFileItem& fileItem, const CContextMenuItem& root) const;

  /*! \brief Gets the context menu items available for a file item.
   \param fileItem the file item
   \param root the root context menu item
   \return the items
   \sa ContextMenuView
   */
  ContextMenuView GetItems(const CFileItem& fileItem, const CContextMenuItem& root) const;

  /*! \brief Checks whether addon context menu items are available for a file item.
   \param fileItem the file item
   \param root the root context menu item
   \return true if any items are present, false otherwise
   */
  bool HasAddonItems(const CFileItem& fileItem, const CContextMenuItem& root) const;

  /*! \brief Gets the addon context menu items available for a file item.
   \param fileItem the file item
   \param root the root context menu item
   \return the items
   \sa ContextMenuView
   */
  ContextMenuView GetAddonItems(const CFileItem& fileItem, const CContextMenuItem& root) const;

private:
  CContextMenuManager(const CContextMenuManager&) = delete;
  CContextMenuManager& operator=(CContextMenuManager const&) = delete;

  bool IsVisible(
    const CContextMenuItem& menuItem,
    const CContextMenuItem& root,
    const CFileItem& fileItem) const;

  void ReloadAddonItems();
  void OnEvent(const ADDON::AddonEvent& event);

  void OnPVREvent(const PVR::PVRContextMenuEvent& event);

  ADDON::CAddonMgr& m_addonMgr;

  mutable CCriticalSection m_criticalSection;
  std::vector<CContextMenuItem> m_addonItems;
  std::vector<std::shared_ptr<IContextMenuItem>> m_items;
};

namespace CONTEXTMENU
{
/*! \brief Checks whether any context menu items are available for a file item.
 \param fileItem the file item
 \param root the root context menu item
 \return true if any items are present, false otherwise
 */
bool HasAnyMenuItemsFor(const std::shared_ptr<CFileItem>& fileItem, const CContextMenuItem& root);

/*! \brief Starts the context menu loop for a file item.
 \param fileItem the file item
 \param root the root context menu item
 \return true on success, false otherwise
 */
bool ShowFor(const std::shared_ptr<CFileItem>& fileItem, const CContextMenuItem& root);

/*! \brief Shortcut for continuing the context menu loop from an existing menu item.
 \param menu the menu item
 \param fileItem the file item
 \return true on success, false otherwise
 */
bool LoopFrom(const IContextMenuItem& menu, const std::shared_ptr<CFileItem>& fileItem);
}