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.
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"
24 class CGetDirectoryItems
;
28 // base class for all media windows
29 class CGUIMediaWindow
: public CGUIWindow
32 CGUIMediaWindow(int id
, const char *xmlFile
);
33 ~CGUIMediaWindow(void) override
;
35 // specializations of CGUIControl
36 bool OnAction(const CAction
&action
) override
;
37 bool OnBack(int actionID
) override
;
38 bool OnMessage(CGUIMessage
& message
) override
;
40 // specializations of CGUIWindow
41 void OnWindowLoaded() override
;
42 void OnWindowUnload() override
;
43 void OnInitWindow() override
;
44 bool IsMediaWindow() const override
{ return true; }
45 int GetViewContainerID() const override
{ return m_viewControl
.GetCurrentControl(); }
46 int GetViewCount() const override
{ return m_viewControl
.GetViewModeCount(); }
47 bool HasListItems() const override
{ return true; }
48 CFileItemPtr
GetCurrentListItem(int offset
= 0) override
;
51 virtual bool CanFilterAdvanced() { return m_canFilterAdvanced
; }
52 virtual bool IsFiltered();
53 virtual bool IsSameStartFolder(const std::string
&dir
);
55 virtual std::string
GetRootPath() const { return ""; }
57 const CFileItemList
&CurrentDirectory() const;
58 const CGUIViewState
*GetViewState() const;
59 virtual bool UseFileDirectories() { return true; }
62 // specializations of CGUIControlGroup
63 CGUIControl
*GetFirstFocusableControl(int id
) override
;
65 bool Load(TiXmlElement
*pRootElement
) override
;
68 virtual void SetupShares();
69 virtual bool GoParentFolder();
70 virtual bool OnClick(int iItem
, const std::string
&player
= "");
72 /* \brief React to a "Select" action on an item in a view.
73 \param item selected item.
74 \return true if the action is handled, false otherwise.
76 virtual bool OnSelect(int item
);
77 virtual bool OnPopupMenu(int iItem
);
79 virtual void GetContextButtons(int itemNumber
, CContextButtons
& buttons
) {}
80 virtual bool OnContextButton(int itemNumber
, CONTEXT_BUTTON button
) { return false; }
81 virtual bool OnAddMediaSource() { return false; }
83 virtual void FormatItemLabels(CFileItemList
&items
, const LABEL_MASKS
&labelMasks
);
84 virtual void UpdateButtons();
85 void SaveControlStates() override
;
86 void RestoreControlStates() override
;
88 virtual bool GetDirectory(const std::string
&strDirectory
, CFileItemList
&items
);
89 /*! \brief Retrieves the items from the given path and updates the list
90 \param strDirectory The path to the directory to get the items from
91 \param updateFilterPath Whether to update the filter path in m_strFilterPath or not
92 \return true if the list was successfully updated otherwise false
97 virtual bool Update(const std::string
&strDirectory
, bool updateFilterPath
= true);
98 /*! \brief Refreshes the current list by retrieving the lists's path
99 \return true if the list was successfully refreshed otherwise false
103 virtual bool Refresh(bool clearCache
= false);
105 virtual void FormatAndSort(CFileItemList
&items
);
106 virtual void OnPrepareFileItems(CFileItemList
&items
);
107 virtual void OnCacheFileItems(CFileItemList
&items
);
108 virtual void GetGroupedItems(CFileItemList
&items
) { }
110 void ClearFileItems();
111 virtual void SortItems(CFileItemList
&items
);
113 /*! \brief Check if the given list can be advance filtered or not
114 \param items List of items to check
115 \return true if the list can be advance filtered otherwise false
117 virtual bool CheckFilterAdvanced(CFileItemList
&items
) const { return false; }
118 /*! \brief Check if the given path can contain a "filter" parameter
119 \param strDirectory Path to check
120 \return true if the given path can contain a "filter" parameter otherwise false
122 virtual bool CanContainFilter(const std::string
&strDirectory
) const { return false; }
123 virtual void UpdateFilterPath(const std::string
&strDirector
, const CFileItemList
&items
, bool updateFilterPath
);
124 virtual bool Filter(bool advanced
= true);
126 /* \brief Called on response to a GUI_MSG_FILTER_ITEMS message
127 Filters the current list with the given filter using FilterItems()
128 \param filter the filter to use.
131 void OnFilterItems(const std::string
&filter
);
133 /* \brief Retrieve the filtered item list
134 \param filter filter to apply
135 \param items CFileItemList to filter
138 virtual bool GetFilteredItems(const std::string
&filter
, CFileItemList
&items
);
140 /* \brief Retrieve the advance filtered item list
141 \param items CFileItemList to filter
142 \param hasNewItems Whether the filtered item list contains new items
143 which were not present in the original list
146 virtual bool GetAdvanceFilteredItems(CFileItemList
&items
);
148 // check for a disc or connection
149 virtual bool HaveDiscOrConnection(const std::string
& strPath
, int iDriveType
);
150 void ShowShareErrorMessage(CFileItem
* pItem
) const;
152 void SaveSelectedItemInHistory();
153 void RestoreSelectedItemFromHistory();
154 void GetDirectoryHistoryString(const CFileItem
* pItem
, std::string
& strHistoryString
) const;
155 void SetHistoryForPath(const std::string
& strDirectory
);
156 virtual void LoadPlayList(const std::string
& strFileName
) {}
157 virtual bool OnPlayMedia(int iItem
, const std::string
&player
= "");
158 virtual bool OnPlayAndQueueMedia(const CFileItemPtr
& item
, const std::string
& player
= "");
159 void UpdateFileList();
160 virtual void OnDeleteItem(int iItem
);
161 void OnRenameItem(int iItem
);
162 bool WaitForNetwork() const;
163 bool GetDirectoryItems(CURL
&url
, CFileItemList
&items
, bool useDir
);
164 bool WaitGetDirectoryItems(CGetDirectoryItems
&items
);
165 void CancelUpdateItems();
167 /*! \brief Translate the folder to start in from the given quick path
168 \param url the folder the user wants
169 \return the resulting path */
170 virtual std::string
GetStartFolder(const std::string
&url
);
172 /*! \brief Utility method to remove the given parameter from a path/URL
173 \param strDirectory Path/URL from which to remove the given parameter
174 \param strParameter Parameter to remove from the given path/URL
175 \return Path/URL without the given parameter
177 static std::string
RemoveParameterFromPath(const std::string
&strDirectory
, const std::string
&strParameter
);
179 bool ProcessRenderLoop(bool renderOnly
);
181 XFILE::CVirtualDirectory m_rootDir
;
182 CGUIViewControl m_viewControl
;
184 // current path and history
185 CFileItemList
* m_vecItems
;
186 CFileItemList
* m_unfilteredItems
; ///< \brief items prior to filtering using FilterItems()
187 CDirectoryHistory m_history
;
188 std::unique_ptr
<CGUIViewState
> m_guiState
;
189 std::atomic_bool m_vecItemsUpdating
= {false};
193 CUpdateGuard(std::atomic_bool
&update
) : m_update(update
)
202 std::atomic_bool
&m_update
;
204 CEvent m_updateEvent
;
205 std::atomic_bool m_updateAborted
= {false};
206 std::atomic_bool m_updateJobActive
= {false};
208 // save control state on window exit
210 std::string m_startDirectory
;
212 KODI::PLAYLIST::CSmartPlaylist m_filter
;
213 bool m_canFilterAdvanced
;
214 /*! \brief Contains the path used for filtering (including any active filter)
216 When Update() is called with a path to e.g. a smartplaylist or
217 a library node filter, that "original" path will be stored in
218 m_vecItems->m_strPath. But the path used by XBMC to retrieve
219 those items from the database (Videodb:// or musicdb://)
220 is stored in this member variable to still have access to it
221 because it is used for filtering by appending the currently active
222 filter as a "filter" parameter to the filter path/URL.
226 std::string m_strFilterPath
;
227 bool m_backgroundLoad
= false;