2 * Copyright (C) 2005-2012 Team XBMC
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)
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.
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/>.
23 #include "BackgroundInfoLoader.h"
24 #include "utils/JobManager.h"
27 #define kJobTypeMediaFlags "mediaflags"
30 class IStreamDetailsObserver;
36 \brief Thumb extractor job class
38 Used by the CVideoThumbLoader to perform asynchronous generation of thumbs
40 \sa CVideoThumbLoader and CJob
42 class CThumbExtractor : public CJob
45 CThumbExtractor(const CFileItem& item, const CStdString& listpath, bool thumb, const CStdString& strTarget="");
46 virtual ~CThumbExtractor();
49 \brief Work function that extracts thumb.
51 virtual bool DoWork();
53 virtual const char* GetType() const
55 return kJobTypeMediaFlags;
58 virtual bool operator==(const CJob* job) const;
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
64 bool m_thumb; ///< extract thumb?
67 class CThumbLoader : public CBackgroundInfoLoader
70 CThumbLoader(int nThreads=-1);
71 virtual ~CThumbLoader();
73 virtual void Initialize() { };
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
79 virtual bool FillLibraryArt(CFileItem &item) { return false; }
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
86 static CStdString GetCachedImage(const CFileItem &item, const CStdString &type);
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
93 static void SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image);
96 class CVideoThumbLoader : public CThumbLoader, public CJobQueue
100 virtual ~CVideoThumbLoader();
102 virtual void Initialize();
103 virtual bool LoadItem(CFileItem* pItem);
104 void SetStreamDetailsObserver(IStreamDetailsObserver *pObs) { m_pStreamDetailsObs = pObs; }
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
112 static bool FillThumb(CFileItem &item);
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.
120 static std::string GetLocalArt(const CFileItem &item, const std::string &type, bool checkFolder = false);
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.
127 static std::vector<std::string> GetArtTypes(const std::string &type);
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.
133 static CStdString GetEmbeddedThumbURL(const CFileItem &item);
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
139 virtual bool FillLibraryArt(CFileItem &item);
142 \brief Callback from CThumbExtractor on completion of a generated image
144 Performs the callbacks and updates the GUI.
146 \sa CImageLoader, IJobCallback
148 virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
151 virtual void OnLoaderStart();
152 virtual void OnLoaderFinish();
154 IStreamDetailsObserver *m_pStreamDetailsObs;
155 CVideoDatabase *m_database;
158 class CProgramThumbLoader : public CThumbLoader
161 CProgramThumbLoader();
162 virtual ~CProgramThumbLoader();
163 virtual bool LoadItem(CFileItem* pItem);
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
172 static bool FillThumb(CFileItem &item);
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)
180 static CStdString GetLocalThumb(const CFileItem &item);
188 class CMusicThumbLoader : public CThumbLoader
192 virtual ~CMusicThumbLoader();
194 virtual void Initialize();
195 virtual bool LoadItem(CFileItem* pItem);
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
201 virtual bool FillLibraryArt(CFileItem &item);
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
209 static bool FillThumb(CFileItem &item);
211 static bool GetEmbeddedThumb(const std::string &path, MUSIC_INFO::EmbeddedArt &art);
214 virtual void OnLoaderStart();
215 virtual void OnLoaderFinish();
217 CMusicDatabase *m_database;