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  bool HasItems(const CFileItem& fileItem) const;
44  ContextMenuView GetItems(const CFileItem& item, const CContextMenuItem& root = MAIN) const;
45 
46  bool HasAddonItems(const CFileItem& fileItem) const;
47  ContextMenuView GetAddonItems(const CFileItem& item, const CContextMenuItem& root = MAIN) const;
48 
49 private:
51  CContextMenuManager& operator=(CContextMenuManager const&) = delete;
52 
53  bool IsVisible(
54  const CContextMenuItem& menuItem,
55  const CContextMenuItem& root,
56  const CFileItem& fileItem) const;
57 
58  void ReloadAddonItems();
59  void OnEvent(const ADDON::AddonEvent& event);
60 
61  void OnPVREvent(const PVR::PVRContextMenuEvent& event);
62 
63  ADDON::CAddonMgr& m_addonMgr;
64 
65  mutable CCriticalSection m_criticalSection;
66  std::vector<CContextMenuItem> m_addonItems;
67  std::vector<std::shared_ptr<IContextMenuItem>> m_items;
68 };
69 
70 namespace CONTEXTMENU
71 {
75 bool HasAnyMenuItemsFor(const std::shared_ptr<CFileItem>& fileItem);
76 
80 bool ShowFor(const std::shared_ptr<CFileItem>& fileItem,
81  const CContextMenuItem& root = CContextMenuManager::MAIN);
82 
86 bool LoopFrom(const IContextMenuItem& menu, const std::shared_ptr<CFileItem>& fileItem);
87 }
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