Merge pull request #1593 from Karlson2k/AE_CH_add01
[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 Find a particular art type for a given item, optionally checking at the folder level
115    \param item the CFileItem to search.
116    \param type the type of art to look for.
117    \param checkFolder whether to also check the folder level for files. Defaults to false.
118    \return the art file (if found), else empty.
119    */
120   static std::string GetLocalArt(const CFileItem &item, const std::string &type, bool checkFolder = false);
121
122   /*! \brief return the available art types for a given media type
123    \param type the type of media.
124    \return a vector of art types.
125    \sa GetLocalArt
126    */
127   static std::vector<std::string> GetArtTypes(const std::string &type);
128
129   /*! \brief helper function to retrieve a thumb URL for embedded video thumbs
130    \param item a video CFileItem.
131    \return a URL for the embedded thumb.
132    */
133   static CStdString GetEmbeddedThumbURL(const CFileItem &item);
134
135   /*! \brief helper function to fill the art for a video library item
136    \param item a video CFileItem
137    \return true if we fill art, false otherwise
138    */
139  virtual bool FillLibraryArt(CFileItem &item);
140
141   /*!
142    \brief Callback from CThumbExtractor on completion of a generated image
143
144    Performs the callbacks and updates the GUI.
145
146    \sa CImageLoader, IJobCallback
147    */
148   virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
149
150 protected:
151   virtual void OnLoaderStart();
152   virtual void OnLoaderFinish();
153
154   IStreamDetailsObserver *m_pStreamDetailsObs;
155   CVideoDatabase *m_database;
156 };
157
158 class CProgramThumbLoader : public CThumbLoader
159 {
160 public:
161   CProgramThumbLoader();
162   virtual ~CProgramThumbLoader();
163   virtual bool LoadItem(CFileItem* pItem);
164
165   /*! \brief Fill the thumb of a programs item
166    First uses a cached thumb from a previous run, then checks for a local thumb
167    and caches it for the next run
168    \param item the CFileItem object to fill
169    \return true if we fill the thumb, false otherwise
170    \sa GetLocalThumb
171    */
172   static bool FillThumb(CFileItem &item);
173
174   /*! \brief Get a local thumb for a programs item
175    Shortcuts are checked, then we check for a file or folder thumb
176    \param item the CFileItem object to check
177    \return the local thumb (if it exists)
178    \sa FillThumb
179    */
180   static CStdString GetLocalThumb(const CFileItem &item);
181 };
182
183 namespace MUSIC_INFO
184 {
185   class EmbeddedArt;
186 };
187
188 class CMusicThumbLoader : public CThumbLoader
189 {
190 public:
191   CMusicThumbLoader();
192   virtual ~CMusicThumbLoader();
193
194   virtual void Initialize();
195   virtual bool LoadItem(CFileItem* pItem);
196
197   /*! \brief helper function to fill the art for a video library item
198    \param item a video CFileItem
199    \return true if we fill art, false otherwise
200    */
201   virtual bool FillLibraryArt(CFileItem &item);
202
203   /*! \brief Fill the thumb of a music file/folder item
204    First uses a cached thumb from a previous run, then checks for a local thumb
205    and caches it for the next run
206    \param item the CFileItem object to fill
207    \return true if we fill the thumb, false otherwise
208    */
209   static bool FillThumb(CFileItem &item);
210
211   static bool GetEmbeddedThumb(const std::string &path, MUSIC_INFO::EmbeddedArt &art);
212
213 protected:
214   virtual void OnLoaderStart();
215   virtual void OnLoaderFinish();
216
217   CMusicDatabase *m_database;
218 };
219 #endif