Merge pull request #24470 from fuzzard/release_20.3
[xbmc.git] / xbmc / dialogs / GUIDialogContextMenu.h
blob420e458b82a0f6cbd422aed38fc873c20d22e58d
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #pragma once
11 #include "guilib/GUIDialog.h"
13 #include <string>
14 #include <utility>
15 #include <vector>
18 class CMediaSource;
20 enum CONTEXT_BUTTON { CONTEXT_BUTTON_CANCELLED = 0,
21 CONTEXT_BUTTON_RENAME,
22 CONTEXT_BUTTON_DELETE,
23 CONTEXT_BUTTON_MOVE,
24 CONTEXT_BUTTON_SETTINGS,
25 CONTEXT_BUTTON_RIP_CD,
26 CONTEXT_BUTTON_CANCEL_RIP_CD,
27 CONTEXT_BUTTON_RIP_TRACK,
28 CONTEXT_BUTTON_EJECT_DRIVE,
29 CONTEXT_BUTTON_EDIT_SOURCE,
30 CONTEXT_BUTTON_REMOVE_SOURCE,
31 CONTEXT_BUTTON_SET_DEFAULT,
32 CONTEXT_BUTTON_CLEAR_DEFAULT,
33 CONTEXT_BUTTON_SET_THUMB,
34 CONTEXT_BUTTON_ADD_LOCK,
35 CONTEXT_BUTTON_REMOVE_LOCK,
36 CONTEXT_BUTTON_CHANGE_LOCK,
37 CONTEXT_BUTTON_RESET_LOCK,
38 CONTEXT_BUTTON_REACTIVATE_LOCK,
39 CONTEXT_BUTTON_VIEW_SLIDESHOW,
40 CONTEXT_BUTTON_RECURSIVE_SLIDESHOW,
41 CONTEXT_BUTTON_REFRESH_THUMBS,
42 CONTEXT_BUTTON_SWITCH_MEDIA,
43 CONTEXT_BUTTON_MOVE_ITEM,
44 CONTEXT_BUTTON_MOVE_HERE,
45 CONTEXT_BUTTON_CANCEL_MOVE,
46 CONTEXT_BUTTON_MOVE_ITEM_UP,
47 CONTEXT_BUTTON_MOVE_ITEM_DOWN,
48 CONTEXT_BUTTON_CLEAR,
49 CONTEXT_BUTTON_QUEUE_ITEM,
50 CONTEXT_BUTTON_PLAY_ITEM,
51 CONTEXT_BUTTON_PLAY_WITH,
52 CONTEXT_BUTTON_PLAY_PARTYMODE,
53 CONTEXT_BUTTON_PLAY_PART,
54 CONTEXT_BUTTON_RESUME_ITEM,
55 CONTEXT_BUTTON_EDIT,
56 CONTEXT_BUTTON_EDIT_SMART_PLAYLIST,
57 CONTEXT_BUTTON_INFO,
58 CONTEXT_BUTTON_INFO_ALL,
59 CONTEXT_BUTTON_CDDB,
60 CONTEXT_BUTTON_SCAN,
61 CONTEXT_BUTTON_SCAN_TO_LIBRARY,
62 CONTEXT_BUTTON_SET_ARTIST_THUMB,
63 CONTEXT_BUTTON_SET_SEASON_ART,
64 CONTEXT_BUTTON_CANCEL_PARTYMODE,
65 CONTEXT_BUTTON_MARK_WATCHED,
66 CONTEXT_BUTTON_MARK_UNWATCHED,
67 CONTEXT_BUTTON_SET_CONTENT,
68 CONTEXT_BUTTON_EDIT_PARTYMODE,
69 CONTEXT_BUTTON_LINK_MOVIE,
70 CONTEXT_BUTTON_UNLINK_MOVIE,
71 CONTEXT_BUTTON_GO_TO_ARTIST,
72 CONTEXT_BUTTON_GO_TO_ALBUM,
73 CONTEXT_BUTTON_PLAY_OTHER,
74 CONTEXT_BUTTON_SET_ACTOR_THUMB,
75 CONTEXT_BUTTON_UNLINK_BOOKMARK,
76 CONTEXT_BUTTON_ACTIVATE,
77 CONTEXT_BUTTON_GROUP_MANAGER,
78 CONTEXT_BUTTON_CHANNEL_MANAGER,
79 CONTEXT_BUTTON_SET_MOVIESET_ART,
80 CONTEXT_BUTTON_PLAY_AND_QUEUE,
81 CONTEXT_BUTTON_PLAY_ONLY_THIS,
82 CONTEXT_BUTTON_UPDATE_EPG,
83 CONTEXT_BUTTON_TAGS_ADD_ITEMS,
84 CONTEXT_BUTTON_TAGS_REMOVE_ITEMS,
85 CONTEXT_BUTTON_SET_MOVIESET,
86 CONTEXT_BUTTON_MOVIESET_ADD_REMOVE_ITEMS,
87 CONTEXT_BUTTON_BROWSE_INTO,
88 CONTEXT_BUTTON_EDIT_SORTTITLE,
89 CONTEXT_BUTTON_DELETE_ALL,
90 CONTEXT_BUTTON_HELP,
91 CONTEXT_BUTTON_PLAY_NEXT,
92 CONTEXT_BUTTON_NAVIGATE,
95 class CContextButtons : public std::vector< std::pair<size_t, std::string> >
97 public:
98 void Add(unsigned int, const std::string &label);
99 void Add(unsigned int, int label);
102 class CGUIDialogContextMenu :
103 public CGUIDialog
105 public:
106 CGUIDialogContextMenu(void);
107 ~CGUIDialogContextMenu(void) override;
108 bool OnMessage(CGUIMessage &message) override;
109 bool OnAction(const CAction& action) override;
110 void SetPosition(float posX, float posY) override;
112 static bool SourcesMenu(const std::string &strType, const CFileItemPtr& item, float posX, float posY);
113 static void SwitchMedia(const std::string& strType, const std::string& strPath);
115 static void GetContextButtons(const std::string &type, const CFileItemPtr& item, CContextButtons &buttons);
116 static bool OnContextButton(const std::string &type, const CFileItemPtr& item, CONTEXT_BUTTON button);
118 /*! Show the context menu with the given choices and return the index of the selected item,
119 or -1 if cancelled.
121 static int Show(const CContextButtons& choices, int focusedButton = 0);
123 /*! Legacy method that returns the context menu id, or -1 on cancel */
124 static int ShowAndGetChoice(const CContextButtons &choices);
126 protected:
127 void SetupButtons();
129 /*! \brief Position the context menu in the middle of the focused control.
130 If no control is available it is positioned in the middle of the screen.
132 void PositionAtCurrentFocus();
134 float GetWidth() const override;
135 float GetHeight() const override;
136 void OnInitWindow() override;
137 void OnWindowLoaded() override;
138 void OnDeinitWindow(int nextWindowID) override;
139 static std::string GetDefaultShareNameByType(const std::string &strType);
140 static void SetDefault(const std::string &strType, const std::string &strDefault);
141 static void ClearDefault(const std::string &strType);
142 static CMediaSource *GetShare(const std::string &type, const CFileItem *item);
144 private:
145 float m_coordX, m_coordY;
146 /// \brief Stored size of background image (height or width depending on grouplist orientation)
147 float m_backgroundImageSize;
148 int m_initiallyFocusedButtonIdx = 0;
149 int m_clickedButton;
150 CContextButtons m_buttons;
151 const CGUIControl *m_backgroundImage = nullptr;