[textures] Adds GetTextures() to return textures with filtering ability.
[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 CTextureDatabase : public CDatabase, public IDatabaseQueryRuleFactory
44 {
45 public:
46   CTextureDatabase();
47   virtual ~CTextureDatabase();
48   virtual bool Open();
49
50   bool GetCachedTexture(const CStdString &originalURL, CTextureDetails &details);
51   bool AddCachedTexture(const CStdString &originalURL, const CTextureDetails &details);
52   bool SetCachedTextureValid(const CStdString &originalURL, bool updateable);
53   bool ClearCachedTexture(const CStdString &originalURL, CStdString &cacheFile);
54   bool ClearCachedTexture(int textureID, CStdString &cacheFile);
55   bool IncrementUseCount(const CTextureDetails &details);
56
57   /*! \brief Invalidate a previously cached texture
58    Invalidates the texture hash, and sets the texture update time to the current time so that
59    next texture load it will be re-cached.
60    \param url texture path
61    */
62   bool InvalidateCachedTexture(const CStdString &originalURL);
63
64   /*! \brief Get a texture associated with the given path
65    Used for retrieval of previously discovered images to save
66    stat() on the filesystem all the time
67    \param url path that may be associated with a texture
68    \param type type of image to look for
69    \return URL of the texture associated with the given path
70    */
71   CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
72
73   /*! \brief Set a texture associated with the given path
74    Used for setting of previously discovered images to save
75    stat() on the filesystem all the time. Should be used to set
76    the actual image path, not the cached image path (the image will be
77    cached at load time.)
78    \param url path that was used to find the texture
79    \param type type of image to associate
80    \param texture URL of the texture to associate with the path
81    */
82   void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
83
84   /*! \brief Clear a texture associated with the given path
85    \param url path that was used to find the texture
86    \param type type of image to associate
87    \param texture URL of the texture to associate with the path
88    \sa GetTextureForPath, SetTextureForPath
89    */
90   void ClearTextureForPath(const CStdString &url, const CStdString &type);
91
92   bool GetTextures(CVariant &items, const Filter &filter);
93
94   // rule creation
95   virtual CDatabaseQueryRule *CreateRule() const;
96   virtual CDatabaseQueryRuleCombination *CreateCombination() const;
97 protected:
98   /*! \brief retrieve a hash for the given url
99    Computes a hash of the current url to use for lookups in the database
100    \param url url to hash
101    \return a hash for this url
102    */
103   unsigned int GetURLHash(const CStdString &url) const;
104
105   virtual bool CreateTables();
106   virtual bool UpdateOldVersion(int version);
107   virtual int GetMinVersion() const { return 13; };
108   const char *GetBaseDBName() const { return "Textures"; };
109 };