Merge pull request #4222 from Montellese/jsonrpc_audiolibrary_fixes
[vuplus_xbmc] / xbmc / video / VideoThumbLoader.h
1 #pragma once
2 /*
3  *      Copyright (C) 2012-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include <map>
23 #include "ThumbLoader.h"
24 #include "utils/JobManager.h"
25 #include "FileItem.h"
26
27 class CStreamDetails;
28 class CVideoDatabase;
29
30 /*!
31  \ingroup thumbs,jobs
32  \brief Thumb extractor job class
33
34  Used by the CVideoThumbLoader to perform asynchronous generation of thumbs
35
36  \sa CVideoThumbLoader and CJob
37  */
38 class CThumbExtractor : public CJob
39 {
40 public:
41   CThumbExtractor(const CFileItem& item, const CStdString& listpath, bool thumb, const CStdString& strTarget="");
42   virtual ~CThumbExtractor();
43
44   /*!
45    \brief Work function that extracts thumb.
46    */
47   virtual bool DoWork();
48
49   virtual const char* GetType() const
50   {
51     return kJobTypeMediaFlags;
52   }
53
54   virtual bool operator==(const CJob* job) const;
55
56   CStdString m_target; ///< thumbpath
57   CStdString m_listpath; ///< path used in fileitem list
58   CFileItem  m_item;
59   bool       m_thumb; ///< extract thumb?
60 };
61
62 class CVideoThumbLoader : public CThumbLoader, public CJobQueue
63 {
64 public:
65   CVideoThumbLoader();
66   virtual ~CVideoThumbLoader();
67
68   virtual void OnLoaderStart();
69   virtual void OnLoaderFinish();
70
71   virtual bool LoadItem(CFileItem* pItem);
72   virtual bool LoadItemCached(CFileItem* pItem);
73   virtual bool LoadItemLookup(CFileItem* pItem);
74
75   /*! \brief Fill the thumb of a video item
76    First uses a cached thumb from a previous run, then checks for a local thumb
77    and caches it for the next run
78    \param item the CFileItem object to fill
79    \return true if we fill the thumb, false otherwise
80    */
81   virtual bool FillThumb(CFileItem &item);
82
83   /*! \brief Find a particular art type for a given item, optionally checking at the folder level
84    \param item the CFileItem to search.
85    \param type the type of art to look for.
86    \param checkFolder whether to also check the folder level for files. Defaults to false.
87    \return the art file (if found), else empty.
88    */
89   static std::string GetLocalArt(const CFileItem &item, const std::string &type, bool checkFolder = false);
90
91   /*! \brief return the available art types for a given media type
92    \param type the type of media.
93    \return a vector of art types.
94    \sa GetLocalArt
95    */
96   static std::vector<std::string> GetArtTypes(const std::string &type);
97
98   /*! \brief helper function to retrieve a thumb URL for embedded video thumbs
99    \param item a video CFileItem.
100    \return a URL for the embedded thumb.
101    */
102   static CStdString GetEmbeddedThumbURL(const CFileItem &item);
103
104   /*! \brief helper function to fill the art for a video library item
105    \param item a video CFileItem
106    \return true if we fill art, false otherwise
107    */
108  virtual bool FillLibraryArt(CFileItem &item);
109
110   /*!
111    \brief Callback from CThumbExtractor on completion of a generated image
112
113    Performs the callbacks and updates the GUI.
114
115    \sa CImageLoader, IJobCallback
116    */
117   virtual void OnJobComplete(unsigned int jobID, bool success, CJob *job);
118
119   /*! \brief set the artwork map for an item
120    In addition, sets the standard fallbacks.
121    \param item the item on which to set art.
122    \param artwork the artwork map.
123    */
124   static void SetArt(CFileItem &item, const std::map<std::string, std::string> &artwork);
125
126 protected:
127   CVideoDatabase *m_videoDatabase;
128   typedef std::map<int, std::map<std::string, std::string> > ArtCache;
129   ArtCache m_showArt;
130
131   /*! \brief Tries to detect missing data/info from a file and adds those
132    \param item The CFileItem to process
133    \return void
134    */
135   void DetectAndAddMissingItemData(CFileItem &item);
136 };