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;
41 virtual CStdString FormatParameter(const CStdString &negate, const CStdString &oper, const CDatabase &db, const CStdString &type) const;
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
53 static CStdString GetWrappedImageURL(const CStdString &image, const CStdString &type = "", const CStdString &options = "");
54 static CStdString GetWrappedThumbURL(const CStdString &image);
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.
61 static CStdString UnwrapImageURL(const CStdString &image);
64 class CTextureDatabase : public CDatabase, public IDatabaseQueryRuleFactory
68 virtual ~CTextureDatabase();
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);
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
83 bool InvalidateCachedTexture(const CStdString &originalURL);
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
92 CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
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
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
103 void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
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
111 void ClearTextureForPath(const CStdString &url, const CStdString &type);
113 bool GetTextures(CVariant &items, const Filter &filter);
116 virtual CDatabaseQueryRule *CreateRule() const;
117 virtual CDatabaseQueryRuleCombination *CreateCombination() const;
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
124 unsigned int GetURLHash(const CStdString &url) const;
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"; };