2 * Copyright (C) 2005-2013 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 "dbwrappers/Database.h"
24 #include "TextureCacheJob.h"
25 #include "playlists/SmartPlayList.h"
29 class CTextureRule : public CDatabaseQueryRule
33 virtual ~CTextureRule() {};
35 static void GetAvailableFields(std::vector<std::string> &fieldList);
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;
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
52 static CStdString GetWrappedImageURL(const CStdString &image, const CStdString &type = "", const CStdString &options = "");
53 static CStdString GetWrappedThumbURL(const CStdString &image);
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.
60 static CStdString UnwrapImageURL(const CStdString &image);
63 class CTextureDatabase : public CDatabase, public IDatabaseQueryRuleFactory
67 virtual ~CTextureDatabase();
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);
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
82 bool InvalidateCachedTexture(const CStdString &originalURL);
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
91 CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
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
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
102 void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
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
110 void ClearTextureForPath(const CStdString &url, const CStdString &type);
112 bool GetTextures(CVariant &items, const Filter &filter);
115 virtual CDatabaseQueryRule *CreateRule() const;
116 virtual CDatabaseQueryRuleCombination *CreateCombination() const;
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
123 unsigned int GetURLHash(const CStdString &url) const;
125 virtual bool CreateTables();
126 virtual bool UpdateOldVersion(int version);
127 virtual int GetMinVersion() const { return 13; };
128 const char *GetBaseDBName() const { return "Textures"; };