kodi
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 
48  bool HasItems(const CFileItem& fileItem, const CContextMenuItem& root) const;
49 
56  ContextMenuView GetItems(const CFileItem& fileItem, const CContextMenuItem& root) const;
57 
63  bool HasAddonItems(const CFileItem& fileItem, const CContextMenuItem& root) const;
64 
71  ContextMenuView GetAddonItems(const CFileItem& fileItem, const CContextMenuItem& root) const;
72 
73 private:
75  CContextMenuManager& operator=(CContextMenuManager const&) = delete;
76 
77  bool IsVisible(
78  const CContextMenuItem& menuItem,
79  const CContextMenuItem& root,
80  const CFileItem& fileItem) const;
81 
82  void ReloadAddonItems();
83  void OnEvent(const ADDON::AddonEvent& event);
84 
85  void OnPVREvent(const PVR::PVRContextMenuEvent& event);
86 
87  ADDON::CAddonMgr& m_addonMgr;
88 
89  mutable CCriticalSection m_criticalSection;
90  std::vector<CContextMenuItem> m_addonItems;
91  std::vector<std::shared_ptr<IContextMenuItem>> m_items;
92 };
93 
94 namespace CONTEXTMENU
95 {
101 bool HasAnyMenuItemsFor(const std::shared_ptr<CFileItem>& fileItem, const CContextMenuItem& root);
102 
108 bool ShowFor(const std::shared_ptr<CFileItem>& fileItem, const CContextMenuItem& root);
109 
115 bool LoopFrom(const IContextMenuItem& menu, const std::shared_ptr<CFileItem>& fileItem);
116 }
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:51
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