[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / windows / GUIMediaWindow.h
blob6de5e2b3206795456482b607bad5503bf38b029f
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 namespace
24 class CGetDirectoryItems;
27 // base class for all media windows
28 class CGUIMediaWindow : public CGUIWindow
30 public:
31 CGUIMediaWindow(int id, const char *xmlFile);
32 ~CGUIMediaWindow(void) override;
34 // specializations of CGUIControl
35 bool OnAction(const CAction &action) override;
36 bool OnBack(int actionID) override;
37 bool OnMessage(CGUIMessage& message) override;
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;
49 // custom methods
50 virtual bool CanFilterAdvanced() { return m_canFilterAdvanced; }
51 virtual bool IsFiltered();
52 virtual bool IsSameStartFolder(const std::string &dir);
54 virtual std::string GetRootPath() const { return ""; }
56 const CFileItemList &CurrentDirectory() const;
57 const CGUIViewState *GetViewState() const;
58 virtual bool UseFileDirectories() { return true; }
60 protected:
61 // specializations of CGUIControlGroup
62 CGUIControl *GetFirstFocusableControl(int id) override;
64 bool Load(TiXmlElement *pRootElement) override;
66 // custom methods
67 virtual void SetupShares();
68 virtual bool GoParentFolder();
69 virtual bool OnClick(int iItem, const std::string &player = "");
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.
75 virtual bool OnSelect(int item);
76 virtual bool OnPopupMenu(int iItem);
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; }
82 virtual void FormatItemLabels(CFileItemList &items, const LABEL_MASKS &labelMasks);
83 virtual void UpdateButtons();
84 void SaveControlStates() override;
85 void RestoreControlStates() override;
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
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
102 virtual bool Refresh(bool clearCache = false);
104 virtual void FormatAndSort(CFileItemList &items);
105 virtual void OnPrepareFileItems(CFileItemList &items);
106 virtual void OnCacheFileItems(CFileItemList &items);
107 virtual void GetGroupedItems(CFileItemList &items) { }
109 void ClearFileItems();
110 virtual void SortItems(CFileItemList &items);
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
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
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);
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
130 void OnFilterItems(const std::string &filter);
132 /* \brief Retrieve the filtered item list
133 \param filter filter to apply
134 \param items CFileItemList to filter
135 \sa OnFilterItems
137 virtual bool GetFilteredItems(const std::string &filter, CFileItemList &items);
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
145 virtual bool GetAdvanceFilteredItems(CFileItemList &items);
147 // check for a disc or connection
148 virtual bool HaveDiscOrConnection(const std::string& strPath, int iDriveType);
149 void ShowShareErrorMessage(CFileItem* pItem) const;
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 bool WaitGetDirectoryItems(CGetDirectoryItems &items);
164 void CancelUpdateItems();
166 /*! \brief Translate the folder to start in from the given quick path
167 \param url the folder the user wants
168 \return the resulting path */
169 virtual std::string GetStartFolder(const std::string &url);
171 /*! \brief Utility method to remove the given parameter from a path/URL
172 \param strDirectory Path/URL from which to remove the given parameter
173 \param strParameter Parameter to remove from the given path/URL
174 \return Path/URL without the given parameter
176 static std::string RemoveParameterFromPath(const std::string &strDirectory, const std::string &strParameter);
178 bool ProcessRenderLoop(bool renderOnly);
180 XFILE::CVirtualDirectory m_rootDir;
181 CGUIViewControl m_viewControl;
183 // current path and history
184 CFileItemList* m_vecItems;
185 CFileItemList* m_unfilteredItems; ///< \brief items prior to filtering using FilterItems()
186 CDirectoryHistory m_history;
187 std::unique_ptr<CGUIViewState> m_guiState;
188 std::atomic_bool m_vecItemsUpdating = {false};
189 class CUpdateGuard
191 public:
192 CUpdateGuard(std::atomic_bool &update) : m_update(update)
194 m_update = true;
196 ~CUpdateGuard()
198 m_update = false;
200 protected:
201 std::atomic_bool &m_update;
203 CEvent m_updateEvent;
204 std::atomic_bool m_updateAborted = {false};
205 std::atomic_bool m_updateJobActive = {false};
207 // save control state on window exit
208 int m_iLastControl;
209 std::string m_startDirectory;
211 CSmartPlaylist m_filter;
212 bool m_canFilterAdvanced;
213 /*! \brief Contains the path used for filtering (including any active filter)
215 When Update() is called with a path to e.g. a smartplaylist or
216 a library node filter, that "original" path will be stored in
217 m_vecItems->m_strPath. But the path used by XBMC to retrieve
218 those items from the database (Videodb:// or musicdb://)
219 is stored in this member variable to still have access to it
220 because it is used for filtering by appending the currently active
221 filter as a "filter" parameter to the filter path/URL.
223 \sa Update
225 std::string m_strFilterPath;
226 bool m_backgroundLoad = false;