[textures] move image wrapping functions into a separate class
[vuplus_xbmc] / xbmc / TextureDatabase.h
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://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 #pragma once
22
23 #include "dbwrappers/Database.h"
24 #include "TextureCacheJob.h"
25 #include "playlists/SmartPlayList.h"
26
27 class CVariant;
28
29 class CTextureRule : public CDatabaseQueryRule
30 {
31 public:
32   CTextureRule() {};
33   virtual ~CTextureRule() {};
34
35   static void GetAvailableFields(std::vector<std::string> &fieldList);
36 protected:
37   virtual int                 TranslateField(const char *field) const;
38   virtual CStdString          TranslateField(int field) const;
39   virtual CStdString          GetField(int field, const CStdString& type) const;
40   virtual FIELD_TYPE          GetFieldType(int field) const;
41 };
42
43 class CTextureUtils
44 {
45 public:
46   /*! \brief retrieve a wrapped URL for a image file
47    \param image name of the file
48    \param type signifies a special type of image (eg embedded video thumb, picture folder thumb)
49    \param options which options we need (eg size=thumb)
50    \return full wrapped URL of the image file
51    */
52   static CStdString GetWrappedImageURL(const CStdString &image, const CStdString &type = "", const CStdString &options = "");
53   static CStdString GetWrappedThumbURL(const CStdString &image);
54
55   /*! \brief Unwrap an image://<url_encoded_path> style URL
56    Such urls are used for art over the webserver or other users of the VFS
57    \param image url of the image
58    \return the unwrapped URL, or the original URL if unwrapping is inappropriate.
59    */
60   static CStdString UnwrapImageURL(const CStdString &image);
61 };
62
63 class CTextureDatabase : public CDatabase, public IDatabaseQueryRuleFactory
64 {
65 public:
66   CTextureDatabase();
67   virtual ~CTextureDatabase();
68   virtual bool Open();
69
70   bool GetCachedTexture(const CStdString &originalURL, CTextureDetails &details);
71   bool AddCachedTexture(const CStdString &originalURL, const CTextureDetails &details);
72   bool SetCachedTextureValid(const CStdString &originalURL, bool updateable);
73   bool ClearCachedTexture(const CStdString &originalURL, CStdString &cacheFile);
74   bool ClearCachedTexture(int textureID, CStdString &cacheFile);
75   bool IncrementUseCount(const CTextureDetails &details);
76
77   /*! \brief Invalidate a previously cached texture
78    Invalidates the texture hash, and sets the texture update time to the current time so that
79    next texture load it will be re-cached.
80    \param url texture path
81    */
82   bool InvalidateCachedTexture(const CStdString &originalURL);
83
84   /*! \brief Get a texture associated with the given path
85    Used for retrieval of previously discovered images to save
86    stat() on the filesystem all the time
87    \param url path that may be associated with a texture
88    \param type type of image to look for
89    \return URL of the texture associated with the given path
90    */
91   CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
92
93   /*! \brief Set a texture associated with the given path
94    Used for setting of previously discovered images to save
95    stat() on the filesystem all the time. Should be used to set
96    the actual image path, not the cached image path (the image will be
97    cached at load time.)
98    \param url path that was used to find the texture
99    \param type type of image to associate
100    \param texture URL of the texture to associate with the path
101    */
102   void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
103
104   /*! \brief Clear a texture associated with the given path
105    \param url path that was used to find the texture
106    \param type type of image to associate
107    \param texture URL of the texture to associate with the path
108    \sa GetTextureForPath, SetTextureForPath
109    */
110   void ClearTextureForPath(const CStdString &url, const CStdString &type);
111
112   bool GetTextures(CVariant &items, const Filter &filter);
113
114   // rule creation
115   virtual CDatabaseQueryRule *CreateRule() const;
116   virtual CDatabaseQueryRuleCombination *CreateCombination() const;
117 protected:
118   /*! \brief retrieve a hash for the given url
119    Computes a hash of the current url to use for lookups in the database
120    \param url url to hash
121    \return a hash for this url
122    */
123   unsigned int GetURLHash(const CStdString &url) const;
124
125   virtual bool CreateTables();
126   virtual bool UpdateOldVersion(int version);
127   virtual int GetMinVersion() const { return 13; };
128   const char *GetBaseDBName() const { return "Textures"; };
129 };