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