Merge pull request #1348 from SlrG/hddvdfix
[vuplus_xbmc] / xbmc / ThumbLoader.h
1 /*
2  *      Copyright (C) 2005-2012 Team XBMC
3  *      http://www.xbmc.org
4  *
5  *  This Program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2, or (at your option)
8  *  any later version.
9  *
10  *  This Program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with XBMC; see the file COPYING.  If not, see
17  *  <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #ifndef THUMBLOADER_H
22 #define THUMBLOADER_H
23 #include "BackgroundInfoLoader.h"
24 #include "utils/JobManager.h"
25 #include "FileItem.h"
26
27 #define kJobTypeMediaFlags "mediaflags"
28
29 class CStreamDetails;
30 class IStreamDetailsObserver;
31 class CVideoDatabase;
32 class CMusicDatabase;
33
34 /*!
35  \ingroup thumbs,jobs
36  \brief Thumb extractor job class
37
38  Used by the CVideoThumbLoader to perform asynchronous generation of thumbs
39
40  \sa CVideoThumbLoader and CJob
41  */
42 class CThumbExtractor : public CJob
43 {
44 public:
45   CThumbExtractor(const CFileItem& item, const CStdString& listpath, bool thumb, const CStdString& strTarget="");
46   virtual ~CThumbExtractor();
47
48   /*!
49    \brief Work function that extracts thumb.
50    */
51   virtual bool DoWork();
52
53   virtual const char* GetType() const
54   {
55     return kJobTypeMediaFlags;
56   }
57
58   virtual bool operator==(const CJob* job) const;
59
60   CStdString m_path; ///< path of video to extract thumb from
61   CStdString m_target; ///< thumbpath
62   CStdString m_listpath; ///< path used in fileitem list
63   CFileItem  m_item;
64   bool       m_thumb; ///< extract thumb?
65 };
66
67 class CThumbLoader : public CBackgroundInfoLoader
68 {
69 public:
70   CThumbLoader(int nThreads=-1);
71   virtual ~CThumbLoader();
72
73   virtual void Initialize() { };
74
75   /*! \brief helper function to fill the art for a library item
76    \param item a CFileItem
77    \return true if we fill art, false otherwise
78    */
79   virtual bool FillLibraryArt(CFileItem &item) { return false; }
80
81   /*! \brief Checks whether the given item has an image listed in the texture database
82    \param item CFileItem to check
83    \param type the type of image to retrieve
84    \return the image associated with this item
85    */
86   static CStdString GetCachedImage(const CFileItem &item, const CStdString &type);
87
88   /*! \brief Associate an image with the given item in the texture database
89    \param item CFileItem to associate the image with
90    \param type the type of image
91    \param image the URL of the image
92    */
93   static void SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image);
94 };
95
96 class CVideoThumbLoader : public CThumbLoader, public CJobQueue
97 {
98 public:
99   CVideoThumbLoader();
100   virtual ~CVideoThumbLoader();
101
102   virtual void Initialize();
103   virtual bool LoadItem(CFileItem* pItem);
104   void SetStreamDetailsObserver(IStreamDetailsObserver *pObs) { m_pStreamDetailsObs = pObs; }
105
106   /*! \brief Fill the thumb of a video item
107    First uses a cached thumb from a previous run, then checks for a local thumb
108    and caches it for the next run
109    \param item the CFileItem object to fill
110    \return true if we fill the thumb, false otherwise
111    */
112   static bool FillThumb(CFileItem &item);
113
114   /*! \brief helper function to retrieve a thumb URL for embedded video thumbs
115    \param item a video CFileItem.
116    \return a URL for the embedded thumb.
117    */
118   static CStdString GetEmbeddedThumbURL(const CFileItem &item);
119
120   /*! \brief helper function to fill the art for a video library item
121    \param item a video CFileItem
122    \return true if we fill art, false otherwise
123    */
124  virtual bool FillLibraryArt(CFileItem &item);
125
126   /*!
127    \brief Callback from CThumbExtractor on completion of a generated image
128
129    Performs the callbacks and updates the GUI.
130
131    \sa CImageLoader, IJobCallback
132    */
133   virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
134
135 protected:
136   virtual void OnLoaderStart();
137   virtual void OnLoaderFinish();
138
139   IStreamDetailsObserver *m_pStreamDetailsObs;
140   CVideoDatabase *m_database;
141 };
142
143 class CProgramThumbLoader : public CThumbLoader
144 {
145 public:
146   CProgramThumbLoader();
147   virtual ~CProgramThumbLoader();
148   virtual bool LoadItem(CFileItem* pItem);
149
150   /*! \brief Fill the thumb of a programs item
151    First uses a cached thumb from a previous run, then checks for a local thumb
152    and caches it for the next run
153    \param item the CFileItem object to fill
154    \return true if we fill the thumb, false otherwise
155    \sa GetLocalThumb
156    */
157   static bool FillThumb(CFileItem &item);
158
159   /*! \brief Get a local thumb for a programs item
160    Shortcuts are checked, then we check for a file or folder thumb
161    \param item the CFileItem object to check
162    \return the local thumb (if it exists)
163    \sa FillThumb
164    */
165   static CStdString GetLocalThumb(const CFileItem &item);
166 };
167
168 namespace MUSIC_INFO
169 {
170   class EmbeddedArt;
171 };
172
173 class CMusicThumbLoader : public CThumbLoader
174 {
175 public:
176   CMusicThumbLoader();
177   virtual ~CMusicThumbLoader();
178
179   virtual void Initialize();
180   virtual bool LoadItem(CFileItem* pItem);
181
182   /*! \brief helper function to fill the art for a video library item
183    \param item a video CFileItem
184    \return true if we fill art, false otherwise
185    */
186   virtual bool FillLibraryArt(CFileItem &item);
187
188   /*! \brief Fill the thumb of a music file/folder item
189    First uses a cached thumb from a previous run, then checks for a local thumb
190    and caches it for the next run
191    \param item the CFileItem object to fill
192    \return true if we fill the thumb, false otherwise
193    */
194   static bool FillThumb(CFileItem &item);
195
196   static bool GetEmbeddedThumb(const std::string &path, MUSIC_INFO::EmbeddedArt &art);
197
198 protected:
199   virtual void OnLoaderStart();
200   virtual void OnLoaderFinish();
201
202   CMusicDatabase *m_database;
203 };
204 #endif