xbmc
ContextMenuItem.h
1 /*
2  * Copyright (C) 2015-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 <map>
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 class CFileItem;
17 
18 namespace ADDON
19 {
20  class CContextMenuAddon;
21 }
22 
23 namespace INFO
24 {
25 class InfoBool;
26 }
27 
29 {
30 public:
31  virtual ~IContextMenuItem() = default;
32  virtual bool IsVisible(const CFileItem& item) const = 0;
33  virtual bool Execute(const std::shared_ptr<CFileItem>& item) const = 0;
34  virtual std::string GetLabel(const CFileItem& item) const = 0;
35  virtual bool IsGroup() const { return false; }
36 };
37 
38 
40 {
41 public:
42  explicit CStaticContextMenuAction(uint32_t label) : m_label(label) {}
43  std::string GetLabel(const CFileItem& item) const final;
44  bool IsGroup() const final { return false; }
45 private:
46  const uint32_t m_label;
47 };
48 
49 
51 {
52 public:
53  CContextMenuItem() = default;
54 
55  std::string GetLabel(const CFileItem& item) const override { return m_label; }
56  bool IsVisible(const CFileItem& item) const override ;
57  bool IsParentOf(const CContextMenuItem& menuItem) const;
58  bool IsGroup() const override ;
59  bool Execute(const std::shared_ptr<CFileItem>& item) const override;
60  bool operator==(const CContextMenuItem& other) const;
61  std::string ToString() const;
62 
63  static CContextMenuItem CreateGroup(
64  const std::string& label,
65  const std::string& parent,
66  const std::string& groupId,
67  const std::string& addonId);
68 
69  static CContextMenuItem CreateItem(
70  const std::string& label,
71  const std::string& parent,
72  const std::string& library,
73  const std::string& condition,
74  const std::string& addonId,
75  const std::vector<std::string>& args = std::vector<std::string>());
76 
77  friend class ADDON::CContextMenuAddon;
78 
79 private:
80  std::string m_label;
81  std::string m_parent;
82  std::string m_groupId;
83  std::string m_library;
84  std::string m_addonId; // The owner of this menu item
85  std::vector<std::string> m_args;
86 
87  std::string m_visibilityCondition;
88  mutable std::shared_ptr<INFO::InfoBool> m_infoBool;
89  mutable bool m_infoBoolRegistered{false};
90 };
Definition: ContextMenuAddon.h:24
Definition: ContextMenuItem.h:50
Definition: ContextMenuItem.h:23
Definition: ContextMenuItem.h:28
Definition: ContextMenuItem.h:39
Definition: Addon.cpp:39
Represents a file on a share.
Definition: FileItem.h:102