Merge pull request #4057 from Karlson2k/win32_fix_nonutf8
[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   virtual CStdString          FormatParameter(const CStdString &negate, const CStdString &oper, const CDatabase &db, const CStdString &type) const;
42 };
43
44 class CTextureUtils
45 {
46 public:
47   /*! \brief retrieve a wrapped URL for a image file
48    \param image name of the file
49    \param type signifies a special type of image (eg embedded video thumb, picture folder thumb)
50    \param options which options we need (eg size=thumb)
51    \return full wrapped URL of the image file
52    */
53   static CStdString GetWrappedImageURL(const CStdString &image, const CStdString &type = "", const CStdString &options = "");
54   static CStdString GetWrappedThumbURL(const CStdString &image);
55
56   /*! \brief Unwrap an image://<url_encoded_path> style URL
57    Such urls are used for art over the webserver or other users of the VFS
58    \param image url of the image
59    \return the unwrapped URL, or the original URL if unwrapping is inappropriate.
60    */
61   static CStdString UnwrapImageURL(const CStdString &image);
62 };
63
64 class CTextureDatabase : public CDatabase, public IDatabaseQueryRuleFactory
65 {
66 public:
67   CTextureDatabase();
68   virtual ~CTextureDatabase();
69   virtual bool Open();
70
71   bool GetCachedTexture(const CStdString &originalURL, CTextureDetails &details);
72   bool AddCachedTexture(const CStdString &originalURL, const CTextureDetails &details);
73   bool SetCachedTextureValid(const CStdString &originalURL, bool updateable);
74   bool ClearCachedTexture(const CStdString &originalURL, CStdString &cacheFile);
75   bool ClearCachedTexture(int textureID, CStdString &cacheFile);
76   bool IncrementUseCount(const CTextureDetails &details);
77
78   /*! \brief Invalidate a previously cached texture
79    Invalidates the texture hash, and sets the texture update time to the current time so that
80    next texture load it will be re-cached.
81    \param url texture path
82    */
83   bool InvalidateCachedTexture(const CStdString &originalURL);
84
85   /*! \brief Get a texture associated with the given path
86    Used for retrieval of previously discovered images to save
87    stat() on the filesystem all the time
88    \param url path that may be associated with a texture
89    \param type type of image to look for
90    \return URL of the texture associated with the given path
91    */
92   CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
93
94   /*! \brief Set a texture associated with the given path
95    Used for setting of previously discovered images to save
96    stat() on the filesystem all the time. Should be used to set
97    the actual image path, not the cached image path (the image will be
98    cached at load time.)
99    \param url path that was used to find the texture
100    \param type type of image to associate
101    \param texture URL of the texture to associate with the path
102    */
103   void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
104
105   /*! \brief Clear a texture associated with the given path
106    \param url path that was used to find the texture
107    \param type type of image to associate
108    \param texture URL of the texture to associate with the path
109    \sa GetTextureForPath, SetTextureForPath
110    */
111   void ClearTextureForPath(const CStdString &url, const CStdString &type);
112
113   bool GetTextures(CVariant &items, const Filter &filter);
114
115   // rule creation
116   virtual CDatabaseQueryRule *CreateRule() const;
117   virtual CDatabaseQueryRuleCombination *CreateCombination() const;
118 protected:
119   /*! \brief retrieve a hash for the given url
120    Computes a hash of the current url to use for lookups in the database
121    \param url url to hash
122    \return a hash for this url
123    */
124   unsigned int GetURLHash(const CStdString &url) const;
125
126   virtual void CreateTables();
127   virtual void CreateAnalytics();
128   virtual void UpdateTables(int version);
129   virtual int GetSchemaVersion() const { return 13; };
130   const char *GetBaseDBName() const { return "Textures"; };
131 };