Debian Codegraph @

xbmc/windows/GUIMediaWindow.h

raw
1 /*
2 * Copyright (C) 2005-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 "dialogs/GUIDialogContextMenu.h"
12 #include "filesystem/DirectoryHistory.h"
13 #include "filesystem/VirtualDirectory.h"
14 #include "guilib/GUIWindow.h"
15 #include "playlists/SmartPlayList.h"
16 #include "view/GUIViewControl.h"
17
18 #include <atomic>
19
20 class CFileItemList;
21 class CGUIViewState;
22 namespace
23 {
24 class CGetDirectoryItems;
25 }
26
27 // base class for all media windows
28 class CGUIMediaWindow : public CGUIWindow
29 {
30 public:
31 CGUIMediaWindow(int id, const char *xmlFile);
32 ~CGUIMediaWindow(void) override;
33
34 // specializations of CGUIControl
35 bool OnAction(const CAction &action) override;
36 bool OnBack(int actionID) override;
37 bool OnMessage(CGUIMessage& message) override;
38
39 // specializations of CGUIWindow
40 void OnWindowLoaded() override;
41 void OnWindowUnload() override;
42 void OnInitWindow() override;
43 bool IsMediaWindow() const override { return true; }
44 int GetViewContainerID() const override { return m_viewControl.GetCurrentControl(); }
45 int GetViewCount() const override { return m_viewControl.GetViewModeCount(); }
46 bool HasListItems() const override { return true; }
47 CFileItemPtr GetCurrentListItem(int offset = 0) override;
48
49 // custom methods
50 virtual bool CanFilterAdvanced() { return m_canFilterAdvanced; }
51 virtual bool IsFiltered();
52 virtual bool IsSameStartFolder(const std::string &dir);
53
54 virtual std::string GetRootPath() const { return ""; }
55
56 const CFileItemList &CurrentDirectory() const;
57 const CGUIViewState *GetViewState() const;
58 virtual bool UseFileDirectories() { return true; }
59
60 protected:
61 // specializations of CGUIControlGroup
62 CGUIControl *GetFirstFocusableControl(int id) override;
63
64 bool Load(TiXmlElement *pRootElement) override;
65
66 // custom methods
67 virtual void SetupShares();
68 virtual bool GoParentFolder();
69 virtual bool OnClick(int iItem, const std::string &player = "");
70
71 /* \brief React to a "Select" action on an item in a view.
72 \param item selected item.
73 \return true if the action is handled, false otherwise.
74 */
75 virtual bool OnSelect(int item);
76 virtual bool OnPopupMenu(int iItem);
77
78 virtual void GetContextButtons(int itemNumber, CContextButtons& buttons) {}
79 virtual bool OnContextButton(int itemNumber, CONTEXT_BUTTON button) { return false; }
80 virtual bool OnAddMediaSource() { return false; }
81
82 virtual void FormatItemLabels(CFileItemList &items, const LABEL_MASKS &labelMasks);
83 virtual void UpdateButtons();
84 void SaveControlStates() override;
85 void RestoreControlStates() override;
86
87 virtual bool GetDirectory(const std::string &strDirectory, CFileItemList &items);
88 /*! \brief Retrieves the items from the given path and updates the list
89 \param strDirectory The path to the directory to get the items from
90 \param updateFilterPath Whether to update the filter path in m_strFilterPath or not
91 \return true if the list was successfully updated otherwise false
92 \sa GetDirectory
93 \sa m_vecItems
94 \sa m_strFilterPath
95 */
96 virtual bool Update(const std::string &strDirectory, bool updateFilterPath = true);
97 /*! \brief Refreshes the current list by retrieving the lists's path
98 \return true if the list was successfully refreshed otherwise false
99 \sa Update
100 \sa GetDirectory
101 */
102 virtual bool Refresh(bool clearCache = false);
103
104 virtual void FormatAndSort(CFileItemList &items);
105 virtual void OnPrepareFileItems(CFileItemList &items);
106 virtual void OnCacheFileItems(CFileItemList &items);
107 virtual void GetGroupedItems(CFileItemList &items) { }
108
109 void ClearFileItems();
110 virtual void SortItems(CFileItemList &items);
111
112 /*! \brief Check if the given list can be advance filtered or not
113 \param items List of items to check
114 \return true if the list can be advance filtered otherwise false
115 */
116 virtual bool CheckFilterAdvanced(CFileItemList &items) const { return false; }
117 /*! \brief Check if the given path can contain a "filter" parameter
118 \param strDirectory Path to check
119 \return true if the given path can contain a "filter" parameter otherwise false
120 */
121 virtual bool CanContainFilter(const std::string &strDirectory) const { return false; }
122 virtual void UpdateFilterPath(const std::string &strDirector, const CFileItemList &items, bool updateFilterPath);
123 virtual bool Filter(bool advanced = true);
124
125 /* \brief Called on response to a GUI_MSG_FILTER_ITEMS message
126 Filters the current list with the given filter using FilterItems()
127 \param filter the filter to use.
128 \sa FilterItems
129 */
130 void OnFilterItems(const std::string &filter);
131
132 /* \brief Retrieve the filtered item list
133 \param filter filter to apply
134 \param items CFileItemList to filter
135 \sa OnFilterItems
136 */
137 virtual bool GetFilteredItems(const std::string &filter, CFileItemList &items);
138
139 /* \brief Retrieve the advance filtered item list
140 \param items CFileItemList to filter
141 \param hasNewItems Whether the filtered item list contains new items
142 which were not present in the original list
143 \sa GetFilteredItems
144 */
145 virtual bool GetAdvanceFilteredItems(CFileItemList &items);
146
147 // check for a disc or connection
148 virtual bool HaveDiscOrConnection(const std::string& strPath, int iDriveType);
149 void ShowShareErrorMessage(CFileItem* pItem) const;
150
151 void SaveSelectedItemInHistory();
152 void RestoreSelectedItemFromHistory();
153 void GetDirectoryHistoryString(const CFileItem* pItem, std::string& strHistoryString) const;
154 void SetHistoryForPath(const std::string& strDirectory);
155 virtual void LoadPlayList(const std::string& strFileName) {}
156 virtual bool OnPlayMedia(int iItem, const std::string &player = "");
157 virtual bool OnPlayAndQueueMedia(const CFileItemPtr& item, const std::string& player = "");
158 void UpdateFileList();
159 virtual void OnDeleteItem(int iItem);
160 void OnRenameItem(int iItem);
161 bool WaitForNetwork() const;
162 bool GetDirectoryItems(CURL& url, CFileItemList& items, bool useDir);
163
164 /*! \brief Translate the folder to start in from the given quick path
165 \param url the folder the user wants
166 \return the resulting path */
167 virtual std::string GetStartFolder(const std::string &url);
168
169 /*! \brief Utility method to remove the given parameter from a path/URL
170 \param strDirectory Path/URL from which to remove the given parameter
171 \param strParameter Parameter to remove from the given path/URL
172 \return Path/URL without the given parameter
173 */
174 static std::string RemoveParameterFromPath(const std::string &strDirectory, const std::string &strParameter);
175
176 bool ProcessRenderLoop(bool renderOnly);
177
178 XFILE::CVirtualDirectory m_rootDir;
179 CGUIViewControl m_viewControl;
180
181 // current path and history
182 CFileItemList* m_vecItems;
183 CFileItemList* m_unfilteredItems; ///< \brief items prior to filtering using FilterItems()
184 CDirectoryHistory m_history;
185 std::unique_ptr<CGUIViewState> m_guiState;
186 std::atomic_bool m_vecItemsUpdating = {false};
187 class CUpdateGuard
188 {
189 public:
190 CUpdateGuard(std::atomic_bool &update) : m_update(update)
191 {
192 m_update = true;
193 }
194 ~CUpdateGuard()
195 {
196 m_update = false;
197 }
198 protected:
199 std::atomic_bool &m_update;
200 };
201
202 // save control state on window exit
203 int m_iLastControl;
204 std::string m_startDirectory;
205
206 CSmartPlaylist m_filter;
207 bool m_canFilterAdvanced;
208 /*! \brief Contains the path used for filtering (including any active filter)
209
210 When Update() is called with a path to e.g. a smartplaylist or
211 a library node filter, that "original" path will be stored in
212 m_vecItems->m_strPath. But the path used by XBMC to retrieve
213 those items from the database (Videodb:// or musicdb://)
214 is stored in this member variable to still have access to it
215 because it is used for filtering by appending the currently active
216 filter as a "filter" parameter to the filter path/URL.
217
218 \sa Update
219 */
220 std::string m_strFilterPath;
221 bool m_backgroundLoad = false;
222 };