xbmc
ContextMenuManager.h
1 /*
2  * Copyright (C) 2013-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "ContextMenuItem.h"
12 #include "threads/CriticalSection.h"
13 
14 #include <memory>
15 #include <utility>
16 #include <vector>
17 
18 namespace ADDON
19 {
20 struct AddonEvent;
21 class CAddonMgr;
22 } // namespace ADDON
23 
24 namespace PVR
25 {
26  struct PVRContextMenuEvent;
27 }
28 
29 using ContextMenuView = std::vector<std::shared_ptr<const IContextMenuItem>>;
30 
32 {
33 public:
34  static const CContextMenuItem MAIN;
35  static const CContextMenuItem MANAGE;
36 
37  explicit CContextMenuManager(ADDON::CAddonMgr& addonMgr);
39 
40  void Init();
41  void Deinit();
42 
43  ContextMenuView GetItems(const CFileItem& item, const CContextMenuItem& root = MAIN) const;
44 
45  ContextMenuView GetAddonItems(const CFileItem& item, const CContextMenuItem& root = MAIN) const;
46 
47 private:
49  CContextMenuManager& operator=(CContextMenuManager const&) = delete;
50 
51  bool IsVisible(
52  const CContextMenuItem& menuItem,
53  const CContextMenuItem& root,
54  const CFileItem& fileItem) const;
55 
56  void ReloadAddonItems();
57  void OnEvent(const ADDON::AddonEvent& event);
58 
59  void OnPVREvent(const PVR::PVRContextMenuEvent& event);
60 
61  ADDON::CAddonMgr& m_addonMgr;
62 
63  mutable CCriticalSection m_criticalSection;
64  std::vector<CContextMenuItem> m_addonItems;
65  std::vector<std::shared_ptr<IContextMenuItem>> m_items;
66 };
67 
68 namespace CONTEXTMENU
69 {
73 bool ShowFor(const std::shared_ptr<CFileItem>& fileItem,
74  const CContextMenuItem& root = CContextMenuManager::MAIN);
75 
79 bool LoopFrom(const IContextMenuItem& menu, const std::shared_ptr<CFileItem>& fileItem);
80 }
Class - CAddonMgr Holds references to all addons, enabled or otherwise.
Definition: AddonManager.h:79
Definition: ContextMenuManager.h:24
Definition: ContextMenus.cpp:21
Definition: ContextMenuItem.h:50
Definition: ContextMenuItem.h:28
Definition: AddonEvents.h:18
Definition: ContextMenuManager.h:31
Definition: Addon.cpp:39
Definition: PVRContextMenus.h:26
Represents a file on a share.
Definition: FileItem.h:102