Merge pull request #3819 from arnova/subtitles_for_stacks
[vuplus_xbmc] / xbmc / windows / GUIMediaWindow.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include "guilib/GUIWindow.h"
24 #include "filesystem/VirtualDirectory.h"
25 #include "filesystem/DirectoryHistory.h"
26 #include "view/GUIViewControl.h"
27 #include "view/GUIViewState.h"
28 #include "dialogs/GUIDialogContextMenu.h"
29 #include "playlists/SmartPlayList.h"
30
31 class CFileItemList;
32
33 // base class for all media windows
34 class CGUIMediaWindow : public CGUIWindow
35 {
36 public:
37   CGUIMediaWindow(int id, const char *xmlFile);
38   virtual ~CGUIMediaWindow(void);
39   virtual bool OnMessage(CGUIMessage& message);
40   virtual bool OnAction(const CAction &action);
41   virtual bool OnBack(int actionID);
42   virtual void OnWindowLoaded();
43   virtual void OnWindowUnload();
44   virtual void OnInitWindow();
45   virtual bool IsMediaWindow() const { return true; };
46   const CFileItemList &CurrentDirectory() const;
47   int GetViewContainerID() const { return m_viewControl.GetCurrentControl(); };
48   virtual bool HasListItems() const { return true; };
49   virtual CFileItemPtr GetCurrentListItem(int offset = 0);
50   const CGUIViewState *GetViewState() const;
51
52   virtual bool CanFilterAdvanced() { return m_canFilterAdvanced; }
53   virtual bool IsFiltered();
54
55 protected:
56   virtual void LoadAdditionalTags(TiXmlElement *root);
57   CGUIControl *GetFirstFocusableControl(int id);
58   virtual void SetupShares();
59   virtual void GoParentFolder();
60   virtual bool OnClick(int iItem);
61
62   /* \brief React to a "Select" action on an item in a view.
63    \param item selected item.
64    \return true if the action is handled, false otherwise.
65    */
66   virtual bool OnSelect(int item);
67   virtual bool OnPopupMenu(int iItem);
68   virtual void GetContextButtons(int itemNumber, CContextButtons &buttons);
69   virtual bool OnContextButton(int itemNumber, CONTEXT_BUTTON button);
70   virtual void FormatItemLabels(CFileItemList &items, const LABEL_MASKS &labelMasks);
71   virtual void UpdateButtons();
72   virtual bool GetDirectory(const CStdString &strDirectory, CFileItemList &items);
73   /*! \brief Retrieves the items from the given path and updates the list
74    \param strDirectory The path to the directory to get the items from
75    \param updateFilterPath Whether to update the filter path in m_strFilterPath or not
76    \return true if the list was successfully updated otherwise false
77    \sa GetDirectory
78    \sa m_vecItems
79    \sa m_strFilterPath
80    */
81   virtual bool Update(const CStdString &strDirectory, bool updateFilterPath = true);
82   /*! \brief Refreshes the current list by retrieving the lists's path
83    \return true if the list was successfully refreshed otherwise false
84    \sa Update
85    \sa GetDirectory
86    */
87   virtual bool Refresh(bool clearCache = false);
88   virtual void FormatAndSort(CFileItemList &items);
89   virtual void OnPrepareFileItems(CFileItemList &items);
90   virtual void OnCacheFileItems(CFileItemList &items);
91   virtual void OnFinalizeFileItems(CFileItemList &items);
92   virtual void GetGroupedItems(CFileItemList &items) { }
93
94   void ClearFileItems();
95   virtual void SortItems(CFileItemList &items);
96
97   /*! \brief Check if the given list can be advance filtered or not
98    \param items List of items to check
99    \return true if the list can be advance filtered otherwise false
100    */
101   virtual bool CheckFilterAdvanced(CFileItemList &items) const { return false; }
102   /*! \brief Check if the given path can contain a "filter" parameter
103    \param strDirectory Path to check
104    \return true if the given path can contain a "filter" parameter otherwise false
105    */
106   virtual bool CanContainFilter(const CStdString &strDirectory) const { return false; }
107   virtual void UpdateFilterPath(const CStdString &strDirector, const CFileItemList &items, bool updateFilterPath);
108   virtual bool Filter(bool advanced = true);
109
110   /* \brief Called on response to a GUI_MSG_FILTER_ITEMS message
111    Filters the current list with the given filter using FilterItems()
112    \param filter the filter to use.
113    \sa FilterItems
114    */
115   void OnFilterItems(const CStdString &filter);
116
117   /* \brief Retrieve the filtered item list
118    \param filter filter to apply
119    \param items CFileItemList to filter
120    \sa OnFilterItems
121    */
122   virtual bool GetFilteredItems(const CStdString &filter, CFileItemList &items);
123
124   /* \brief Retrieve the advance filtered item list
125   \param items CFileItemList to filter
126   \param hasNewItems Whether the filtered item list contains new items
127                      which were not present in the original list
128   \sa GetFilteredItems
129   */
130   virtual bool GetAdvanceFilteredItems(CFileItemList &items);
131
132   // check for a disc or connection
133   virtual bool HaveDiscOrConnection(const CStdString& strPath, int iDriveType);
134   void ShowShareErrorMessage(CFileItem* pItem);
135
136   void GetDirectoryHistoryString(const CFileItem* pItem, CStdString& strHistoryString);
137   void SetHistoryForPath(const CStdString& strDirectory);
138   virtual void LoadPlayList(const CStdString& strFileName) {}
139   virtual bool OnPlayMedia(int iItem);
140   virtual bool OnPlayAndQueueMedia(const CFileItemPtr &item);
141   void UpdateFileList();
142   virtual void OnDeleteItem(int iItem);
143   void OnRenameItem(int iItem);
144
145 protected:
146   bool WaitForNetwork() const;
147
148   /*! \brief Translate the folder to start in from the given quick path
149    \param dir the folder the user wants
150    \return the resulting path */
151   virtual CStdString GetStartFolder(const CStdString &url);
152
153   /*! \brief Utility method to remove the given parameter from a path/URL
154    \param strDirectory Path/URL from which to remove the given parameter
155    \param strParameter Parameter to remove from the given path/URL
156    \return Path/URL without the given parameter
157    */
158   static CStdString RemoveParameterFromPath(const CStdString &strDirectory, const CStdString &strParameter);
159
160   XFILE::CVirtualDirectory m_rootDir;
161   CGUIViewControl m_viewControl;
162
163   // current path and history
164   CFileItemList* m_vecItems;
165   CFileItemList* m_unfilteredItems;        ///< \brief items prior to filtering using FilterItems()
166   CDirectoryHistory m_history;
167   std::auto_ptr<CGUIViewState> m_guiState;
168
169   // save control state on window exit
170   int m_iLastControl;
171   int m_iSelectedItem;
172   CStdString m_startDirectory;
173
174   CSmartPlaylist m_filter;
175   bool m_canFilterAdvanced;
176   /*! \brief Contains the path used for filtering (including any active filter)
177
178    When Update() is called with a path to e.g. a smartplaylist or
179    a library node filter, that "original" path will be stored in
180    m_vecItems->m_strPath. But the path used by XBMC to retrieve
181    those items from the database (Videodb:// or musicdb://)
182    is stored in this member variable to still have access to it
183    because it is used for filtering by appending the currently active
184    filter as a "filter" parameter to the filter path/URL.
185
186    \sa Update
187    */
188   CStdString m_strFilterPath;
189 };