[droid] splash: adjust progressbar color
[vuplus_xbmc] / xbmc / FileItem.h
1 /*!
2  \file FileItem.h
3  \brief
4  */
5 #pragma once
6
7 /*
8  *      Copyright (C) 2005-2012 Team XBMC
9  *      http://www.xbmc.org
10  *
11  *  This Program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2, or (at your option)
14  *  any later version.
15  *
16  *  This Program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with XBMC; see the file COPYING.  If not, see
23  *  <http://www.gnu.org/licenses/>.
24  *
25  */
26
27 #include "guilib/GUIListItem.h"
28 #include "utils/Archive.h"
29 #include "utils/ISerializable.h"
30 #include "utils/ISortable.h"
31 #include "XBDateTime.h"
32 #include "utils/SortUtils.h"
33 #include "utils/LabelFormatter.h"
34 #include "GUIPassword.h"
35 #include "threads/CriticalSection.h"
36
37 #include <vector>
38 #include "boost/shared_ptr.hpp"
39
40 namespace MUSIC_INFO
41 {
42   class CMusicInfoTag;
43 }
44 class CVideoInfoTag;
45 namespace EPG
46 {
47   class CEpgInfoTag;
48 }
49 namespace PVR
50 {
51   class CPVRChannel;
52   class CPVRRecording;
53   class CPVRTimerInfoTag;
54 }
55 class CPictureInfoTag;
56
57 class CAlbum;
58 class CArtist;
59 class CSong;
60 class CGenre;
61
62 class CURL;
63
64 /* special startoffset used to indicate that we wish to resume */
65 #define STARTOFFSET_RESUME (-1)
66
67 class CMediaSource;
68
69 /*!
70   \brief Represents a file on a share
71   \sa CFileItemList
72   */
73 class CFileItem :
74   public CGUIListItem, public IArchivable, public ISerializable, public ISortable
75 {
76 public:
77   CFileItem(void);
78   CFileItem(const CFileItem& item);
79   CFileItem(const CGUIListItem& item);
80   CFileItem(const CStdString& strLabel);
81   CFileItem(const CStdString& strPath, bool bIsFolder);
82   CFileItem(const CSong& song);
83   CFileItem(const CStdString &path, const CAlbum& album);
84   CFileItem(const CArtist& artist);
85   CFileItem(const CGenre& genre);
86   CFileItem(const MUSIC_INFO::CMusicInfoTag& music);
87   CFileItem(const CVideoInfoTag& movie);
88   CFileItem(const EPG::CEpgInfoTag& tag);
89   CFileItem(const PVR::CPVRChannel& channel);
90   CFileItem(const PVR::CPVRRecording& record);
91   CFileItem(const PVR::CPVRTimerInfoTag& timer);
92   CFileItem(const CMediaSource& share);
93   virtual ~CFileItem(void);
94   virtual CGUIListItem *Clone() const { return new CFileItem(*this); };
95
96   const CStdString &GetPath() const { return m_strPath; };
97   void SetPath(const CStdString &path) { m_strPath = path; };
98
99   void Reset();
100   const CFileItem& operator=(const CFileItem& item);
101   virtual void Archive(CArchive& ar);
102   virtual void Serialize(CVariant& value) const;
103   virtual void ToSortable(SortItem &sortable);
104   virtual bool IsFileItem() const { return true; };
105
106   bool Exists(bool bUseCache = true) const;
107   bool IsVideo() const;
108   bool IsDiscStub() const;
109   bool IsPicture() const;
110   bool IsLyrics() const;
111   bool IsAudio() const;
112   bool IsKaraoke() const;
113   bool IsCUESheet() const;
114   bool IsLastFM() const;
115   bool IsInternetStream(const bool bStrictCheck = false) const;
116   bool IsPlayList() const;
117   bool IsSmartPlayList() const;
118   bool IsPythonScript() const;
119   bool IsPlugin() const;
120   bool IsScript() const;
121   bool IsAddonsPath() const;
122   bool IsSourcesPath() const;
123   bool IsNFO() const;
124   bool IsDVDImage() const;
125   bool IsOpticalMediaFile() const;
126   bool IsDVDFile(bool bVobs = true, bool bIfos = true) const;
127   bool IsBDFile() const;
128   bool IsRAR() const;
129   bool IsAPK() const;
130   bool IsZIP() const;
131   bool IsCBZ() const;
132   bool IsCBR() const;
133   bool IsISO9660() const;
134   bool IsCDDA() const;
135   bool IsDVD() const;
136   bool IsOnDVD() const;
137   bool IsOnLAN() const;
138   bool IsHD() const;
139   bool IsNfs() const;  
140   bool IsAfp() const;    
141   bool IsRemote() const;
142   bool IsSmb() const;
143   bool IsURL() const;
144   bool IsDAAP() const;
145   bool IsStack() const;
146   bool IsMultiPath() const;
147   bool IsMusicDb() const;
148   bool IsVideoDb() const;
149   bool IsEPG() const;
150   bool IsPVRChannel() const;
151   bool IsPVRRecording() const;
152   bool IsPVRTimer() const;
153   bool IsType(const char *ext) const;
154   bool IsVirtualDirectoryRoot() const;
155   bool IsReadOnly() const;
156   bool CanQueue() const;
157   void SetCanQueue(bool bYesNo);
158   bool IsParentFolder() const;
159   bool IsFileFolder() const;
160   bool IsRemovable() const;
161   bool IsTuxBox() const;
162   bool IsMythTV() const;
163   bool IsHDHomeRun() const;
164   bool IsSlingbox() const;
165   bool IsVTP() const;
166   bool IsPVR() const;
167   bool IsLiveTV() const;
168   bool IsRSS() const;
169   bool IsAndroidApp() const;
170
171   void RemoveExtension();
172   void CleanString();
173   void FillInDefaultIcon();
174   void SetFileSizeLabel();
175   virtual void SetLabel(const CStdString &strLabel);
176   CURL GetAsUrl() const;
177   int GetVideoContentType() const; /* return VIDEODB_CONTENT_TYPE, but don't want to include videodb in this header */
178   bool IsLabelPreformated() const { return m_bLabelPreformated; }
179   void SetLabelPreformated(bool bYesNo) { m_bLabelPreformated=bYesNo; }
180   bool SortsOnTop() const { return m_specialSort == SortSpecialOnTop; }
181   bool SortsOnBottom() const { return m_specialSort == SortSpecialOnBottom; }
182   void SetSpecialSort(SortSpecial sort) { m_specialSort = sort; }
183
184   inline bool HasMusicInfoTag() const
185   {
186     return m_musicInfoTag != NULL;
187   }
188
189   MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag();
190
191   inline const MUSIC_INFO::CMusicInfoTag* GetMusicInfoTag() const
192   {
193     return m_musicInfoTag;
194   }
195
196   inline bool HasVideoInfoTag() const
197   {
198     return m_videoInfoTag != NULL;
199   }
200
201   CVideoInfoTag* GetVideoInfoTag();
202
203   inline const CVideoInfoTag* GetVideoInfoTag() const
204   {
205     return m_videoInfoTag;
206   }
207
208   inline bool HasEPGInfoTag() const
209   {
210     return m_epgInfoTag != NULL;
211   }
212
213   EPG::CEpgInfoTag* GetEPGInfoTag();
214
215   inline const EPG::CEpgInfoTag* GetEPGInfoTag() const
216   {
217     return m_epgInfoTag;
218   }
219
220   inline bool HasPVRChannelInfoTag() const
221   {
222     return m_pvrChannelInfoTag != NULL;
223   }
224
225   PVR::CPVRChannel* GetPVRChannelInfoTag();
226
227   inline const PVR::CPVRChannel* GetPVRChannelInfoTag() const
228   {
229     return m_pvrChannelInfoTag;
230   }
231
232   inline bool HasPVRRecordingInfoTag() const
233   {
234     return m_pvrRecordingInfoTag != NULL;
235   }
236
237   PVR::CPVRRecording* GetPVRRecordingInfoTag();
238
239   inline const PVR::CPVRRecording* GetPVRRecordingInfoTag() const
240   {
241     return m_pvrRecordingInfoTag;
242   }
243
244   inline bool HasPVRTimerInfoTag() const
245   {
246     return m_pvrTimerInfoTag != NULL;
247   }
248
249   PVR::CPVRTimerInfoTag* GetPVRTimerInfoTag();
250
251   inline const PVR::CPVRTimerInfoTag* GetPVRTimerInfoTag() const
252   {
253     return m_pvrTimerInfoTag;
254   }
255
256   inline bool HasPictureInfoTag() const
257   {
258     return m_pictureInfoTag != NULL;
259   }
260
261   inline const CPictureInfoTag* GetPictureInfoTag() const
262   {
263     return m_pictureInfoTag;
264   }
265
266   CPictureInfoTag* GetPictureInfoTag();
267
268   /*!
269    \brief Get the local fanart for this item if it exists
270    \return path to the local fanart for this item, or empty if none exists
271    \sa GetFolderThumb, GetTBNFile
272    */
273   CStdString GetLocalFanart() const;
274
275   /*! \brief Assemble the filename of a particular piece of local artwork for an item.
276              No file existence check is typically performed.
277    \param artFile the art file to search for.
278    \param useFolder whether to look in the folder for the art file. Defaults to false.
279    \return the path to the local artwork.
280    \sa FindLocalArt
281    */
282   CStdString GetLocalArt(const std::string &artFile, bool useFolder = false) const;
283
284   /*! \brief Assemble the filename of a particular piece of local artwork for an item,
285              and check for file existence.
286    \param artFile the art file to search for.
287    \param useFolder whether to look in the folder for the art file. Defaults to false.
288    \return the path to the local artwork if it exists, empty otherwise.
289    \sa GetLocalArt
290    */
291   CStdString FindLocalArt(const std::string &artFile, bool useFolder) const;
292
293   // Gets the .tbn file associated with this item
294   CStdString GetTBNFile() const;
295   // Gets the folder image associated with this item (defaults to folder.jpg)
296   CStdString GetFolderThumb(const CStdString &folderJPG = "folder.jpg") const;
297   // Gets the correct movie title
298   CStdString GetMovieName(bool bUseFolderNames = false) const;
299
300   /*! \brief Find the base movie path (i.e. the item the user expects us to use to lookup the movie)
301    For folder items, with "use foldernames for lookups" it returns the folder.
302    Regardless of settings, for VIDEO_TS/BDMV it returns the parent of the VIDEO_TS/BDMV folder (if present)
303
304    \param useFolderNames whether we're using foldernames for lookups
305    \return the base movie folder
306    */
307   CStdString GetBaseMoviePath(bool useFolderNames) const;
308
309   // Gets the user thumb, if it exists
310   CStdString GetUserMusicThumb(bool alwaysCheckRemote = false, bool fallbackToFolder = false) const;
311
312   /*! \brief Get the path where we expect local metadata to reside.
313    For a folder, this is just the existing path (eg tvshow folder)
314    For a file, this is the parent path, with exceptions made for VIDEO_TS and BDMV files
315
316    Three cases are handled:
317
318      /foo/bar/movie_name/file_name          -> /foo/bar/movie_name/
319      /foo/bar/movie_name/VIDEO_TS/file_name -> /foo/bar/movie_name/
320      /foo/bar/movie_name/BDMV/file_name     -> /foo/bar/movie_name/
321
322      \sa URIUtils::GetParentPath
323    */
324   CStdString GetLocalMetadataPath() const;
325
326   // finds a matching local trailer file
327   CStdString FindTrailer() const;
328
329   virtual bool LoadMusicTag();
330
331   /* returns the content type of this item if known. will lookup for http streams */
332   const CStdString& GetMimeType(bool lookup = true) const;
333
334   /* sets the mime-type if known beforehand */
335   void SetMimeType(const CStdString& mimetype) { m_mimetype = mimetype; } ;
336
337   /* general extra info about the contents of the item, not for display */
338   void SetExtraInfo(const CStdString& info) { m_extrainfo = info; };
339   const CStdString& GetExtraInfo() const { return m_extrainfo; };
340
341   /*! \brief Update an item with information from another item
342    We take metadata information from the given item and supplement the current item
343    with that info.  If tags exist in the new item we use the entire tag information.
344    Properties are appended, and labels, thumbnail and icon are updated if non-empty
345    in the given item.
346    \param item the item used to supplement information
347    \param replaceLabels whether to replace labels (defaults to true)
348    */
349   void UpdateInfo(const CFileItem &item, bool replaceLabels = true);
350
351   bool IsSamePath(const CFileItem *item) const;
352
353   bool IsAlbum() const;
354
355   /*! \brief Sets details using the information from the CVideoInfoTag object
356    Sets the videoinfotag and uses its information to set the label and path.
357    \param video video details to use and set
358    */
359   void SetFromVideoInfoTag(const CVideoInfoTag &video);
360   /*! \brief Sets details using the information from the CAlbum object
361    Sets the album in the music info tag and uses its information to set the
362    label and album-specific properties.
363    \param album album details to use and set
364    */
365   void SetFromAlbum(const CAlbum &album);
366   /*! \brief Sets details using the information from the CSong object
367    Sets the song in the music info tag and uses its information to set the
368    label, path, song-specific properties and artwork.
369    \param song song details to use and set
370    */
371   void SetFromSong(const CSong &song);
372
373   bool m_bIsShareOrDrive;    ///< is this a root share/drive
374   int m_iDriveType;     ///< If \e m_bIsShareOrDrive is \e true, use to get the share type. Types see: CMediaSource::m_iDriveType
375   CDateTime m_dateTime;             ///< file creation date & time
376   int64_t m_dwSize;             ///< file size (0 for folders)
377   CStdString m_strDVDLabel;
378   CStdString m_strTitle;
379   int m_iprogramCount;
380   int m_idepth;
381   int m_lStartOffset;
382   int m_lStartPartNumber;
383   int m_lEndOffset;
384   LockType m_iLockMode;
385   CStdString m_strLockCode;
386   int m_iHasLock; // 0 - no lock 1 - lock, but unlocked 2 - locked
387   int m_iBadPwdCount;
388
389 private:
390   CStdString m_strPath;            ///< complete path to item
391
392   SortSpecial m_specialSort;
393   bool m_bIsParentFolder;
394   bool m_bCanQueue;
395   bool m_bLabelPreformated;
396   CStdString m_mimetype;
397   CStdString m_extrainfo;
398   MUSIC_INFO::CMusicInfoTag* m_musicInfoTag;
399   CVideoInfoTag* m_videoInfoTag;
400   EPG::CEpgInfoTag* m_epgInfoTag;
401   PVR::CPVRChannel* m_pvrChannelInfoTag;
402   PVR::CPVRRecording* m_pvrRecordingInfoTag;
403   PVR::CPVRTimerInfoTag * m_pvrTimerInfoTag;
404   CPictureInfoTag* m_pictureInfoTag;
405   bool m_bIsAlbum;
406 };
407
408 /*!
409   \brief A shared pointer to CFileItem
410   \sa CFileItem
411   */
412 typedef boost::shared_ptr<CFileItem> CFileItemPtr;
413
414 /*!
415   \brief A vector of pointer to CFileItem
416   \sa CFileItem
417   */
418 typedef std::vector< CFileItemPtr > VECFILEITEMS;
419
420 /*!
421   \brief Iterator for VECFILEITEMS
422   \sa CFileItemList
423   */
424 typedef std::vector< CFileItemPtr >::iterator IVECFILEITEMS;
425
426 /*!
427   \brief A map of pointers to CFileItem
428   \sa CFileItem
429   */
430 typedef std::map<CStdString, CFileItemPtr > MAPFILEITEMS;
431
432 /*!
433   \brief Iterator for MAPFILEITEMS
434   \sa MAPFILEITEMS
435   */
436 typedef std::map<CStdString, CFileItemPtr >::iterator IMAPFILEITEMS;
437
438 /*!
439   \brief Pair for MAPFILEITEMS
440   \sa MAPFILEITEMS
441   */
442 typedef std::pair<CStdString, CFileItemPtr > MAPFILEITEMSPAIR;
443
444 typedef bool (*FILEITEMLISTCOMPARISONFUNC) (const CFileItemPtr &pItem1, const CFileItemPtr &pItem2);
445 typedef void (*FILEITEMFILLFUNC) (CFileItemPtr &item);
446
447 /*!
448   \brief Represents a list of files
449   \sa CFileItemList, CFileItem
450   */
451 class CFileItemList : public CFileItem
452 {
453 public:
454   enum CACHE_TYPE { CACHE_NEVER = 0, CACHE_IF_SLOW, CACHE_ALWAYS };
455
456   CFileItemList();
457   CFileItemList(const CStdString& strPath);
458   virtual ~CFileItemList();
459   virtual void Archive(CArchive& ar);
460   CFileItemPtr operator[] (int iItem);
461   const CFileItemPtr operator[] (int iItem) const;
462   CFileItemPtr operator[] (const CStdString& strPath);
463   const CFileItemPtr operator[] (const CStdString& strPath) const;
464   void Clear();
465   void ClearItems();
466   void Add(const CFileItemPtr &pItem);
467   void AddFront(const CFileItemPtr &pItem, int itemPosition);
468   void Remove(CFileItem* pItem);
469   void Remove(int iItem);
470   CFileItemPtr Get(int iItem);
471   const CFileItemPtr Get(int iItem) const;
472   CFileItemPtr Get(const CStdString& strPath);
473   const CFileItemPtr Get(const CStdString& strPath) const;
474   int Size() const;
475   bool IsEmpty() const;
476   void Append(const CFileItemList& itemlist);
477   void Assign(const CFileItemList& itemlist, bool append = false);
478   bool Copy  (const CFileItemList& item);
479   void Reserve(int iCount);
480   void Sort(SORT_METHOD sortMethod, SortOrder sortOrder);
481   /* \brief Sorts the items based on the given sorting options
482
483   In contrast to Sort (see above) this does not change the internal
484   state by storing the sorting method and order used and therefore
485   will always execute the sorting even if the list of items has
486   already been sorted with the same options before.
487   */
488   void Sort(SortDescription sortDescription);
489   void Randomize();
490   void FillInDefaultIcons();
491   int GetFolderCount() const;
492   int GetFileCount() const;
493   int GetSelectedCount() const;
494   int GetObjectCount() const;
495   void FilterCueItems();
496   void RemoveExtensions();
497   void SetFastLookup(bool fastLookup);
498   bool Contains(const CStdString& fileName) const;
499   bool GetFastLookup() const { return m_fastLookup; };
500
501   /*! \brief stack a CFileItemList
502    By default we stack all items (files and folders) in a CFileItemList
503    \param stackFiles whether to stack all items or just collapse folders (defaults to true)
504    \sa StackFiles,StackFolders
505    */
506   void Stack(bool stackFiles = true);
507
508   SortOrder GetSortOrder() const { return m_sortOrder; }
509   SORT_METHOD GetSortMethod() const { return m_sortMethod; }
510   /*! \brief load a CFileItemList out of the cache
511
512    The file list may be cached based on which window we're viewing in, as different
513    windows will be listing different portions of the same URL (eg viewing music files
514    versus viewing video files)
515    
516    \param windowID id of the window that's loading this list (defaults to 0)
517    \return true if we loaded from the cache, false otherwise.
518    \sa Save,RemoveDiscCache
519    */
520   bool Load(int windowID = 0);
521
522   /*! \brief save a CFileItemList to the cache
523    
524    The file list may be cached based on which window we're viewing in, as different
525    windows will be listing different portions of the same URL (eg viewing music files
526    versus viewing video files)
527    
528    \param windowID id of the window that's saving this list (defaults to 0)
529    \return true if successful, false otherwise.
530    \sa Load,RemoveDiscCache
531    */
532   bool Save(int windowID = 0);
533   void SetCacheToDisc(CACHE_TYPE cacheToDisc) { m_cacheToDisc = cacheToDisc; }
534   bool CacheToDiscAlways() const { return m_cacheToDisc == CACHE_ALWAYS; }
535   bool CacheToDiscIfSlow() const { return m_cacheToDisc == CACHE_IF_SLOW; }
536   /*! \brief remove a previously cached CFileItemList from the cache
537    
538    The file list may be cached based on which window we're viewing in, as different
539    windows will be listing different portions of the same URL (eg viewing music files
540    versus viewing video files)
541    
542    \param windowID id of the window whose cache we which to remove (defaults to 0)
543    \sa Save,Load
544    */
545   void RemoveDiscCache(int windowID = 0) const;
546   bool AlwaysCache() const;
547
548   void Swap(unsigned int item1, unsigned int item2);
549
550   /*! \brief Update an item in the item list
551    \param item the new item, which we match based on path to an existing item in the list
552    \return true if the item exists in the list (and was thus updated), false otherwise.
553    */
554   bool UpdateItem(const CFileItem *item);
555
556   void AddSortMethod(SORT_METHOD method, int buttonLabel, const LABEL_MASKS &labelMasks);
557   bool HasSortDetails() const { return m_sortDetails.size() != 0; };
558   const std::vector<SORT_METHOD_DETAILS> &GetSortDetails() const { return m_sortDetails; };
559
560   /*! \brief Specify whether this list should be sorted with folders separate from files
561    By default we sort with folders listed (and sorted separately) except for those sort modes
562    which should be explicitly sorted with folders interleaved with files (eg SORT_METHOD_FILES).
563    With this set the folder state will be ignored, allowing folders and files to sort interleaved.
564    \param sort whether to ignore the folder state.
565    */
566   void SetSortIgnoreFolders(bool sort) { m_sortIgnoreFolders = sort; };
567   bool GetReplaceListing() const { return m_replaceListing; };
568   void SetReplaceListing(bool replace);
569   void SetContent(const CStdString &content) { m_content = content; };
570   const CStdString &GetContent() const { return m_content; };
571
572   void ClearSortState();
573 private:
574   void Sort(FILEITEMLISTCOMPARISONFUNC func);
575   void FillSortFields(FILEITEMFILLFUNC func);
576   CStdString GetDiscFileCache(int windowID) const;
577
578   /*!
579    \brief stack files in a CFileItemList
580    \sa Stack
581    */
582   void StackFiles();
583
584   /*!
585    \brief stack folders in a CFileItemList
586    \sa Stack
587    */
588   void StackFolders();
589
590   VECFILEITEMS m_items;
591   MAPFILEITEMS m_map;
592   bool m_fastLookup;
593   SORT_METHOD m_sortMethod;
594   SortOrder m_sortOrder;
595   bool m_sortIgnoreFolders;
596   CACHE_TYPE m_cacheToDisc;
597   bool m_replaceListing;
598   CStdString m_content;
599
600   std::vector<SORT_METHOD_DETAILS> m_sortDetails;
601
602   CCriticalSection m_lock;
603 };