2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "TextureCacheJob.h"
12 #include "dbwrappers/Database.h"
13 #include "dbwrappers/DatabaseQuery.h"
20 class CTextureRule
: public CDatabaseQueryRule
23 CTextureRule() = default;
24 ~CTextureRule() override
= default;
26 static void GetAvailableFields(std::vector
<std::string
> &fieldList
);
28 int TranslateField(const char *field
) const override
;
29 std::string
TranslateField(int field
) const override
;
30 std::string
GetField(int field
, const std::string
& type
) const override
;
31 FIELD_TYPE
GetFieldType(int field
) const override
;
32 std::string
FormatParameter(const std::string
&negate
,
33 const std::string
&oper
,
35 const std::string
&type
) const override
;
41 /*! \brief retrieve a wrapped URL for a image file
42 \param image name of the file
43 \param type signifies a special type of image (eg embedded video thumb, picture folder thumb)
44 \param options which options we need (eg size=thumb)
45 \return full wrapped URL of the image file
47 static std::string
GetWrappedImageURL(const std::string
&image
, const std::string
&type
= "", const std::string
&options
= "");
48 static std::string
GetWrappedThumbURL(const std::string
&image
);
50 /*! \brief Unwrap an image://<url_encoded_path> style URL
51 Such urls are used for art over the webserver or other users of the VFS
52 \param image url of the image
53 \return the unwrapped URL, or the original URL if unwrapping is inappropriate.
55 static std::string
UnwrapImageURL(const std::string
&image
);
58 class CTextureDatabase
: public CDatabase
, public IDatabaseQueryRuleFactory
62 ~CTextureDatabase() override
;
65 bool GetCachedTexture(const std::string
&originalURL
, CTextureDetails
&details
);
66 bool AddCachedTexture(const std::string
&originalURL
, const CTextureDetails
&details
);
67 bool SetCachedTextureValid(const std::string
&originalURL
, bool updateable
);
68 bool ClearCachedTexture(const std::string
&originalURL
, std::string
&cacheFile
);
69 bool ClearCachedTexture(int textureID
, std::string
&cacheFile
);
70 bool IncrementUseCount(const CTextureDetails
&details
);
72 /*! \brief Invalidate a previously cached texture
73 Invalidates the texture hash, and sets the texture update time to the current time so that
74 next texture load it will be re-cached.
75 \param url texture path
77 bool InvalidateCachedTexture(const std::string
&originalURL
);
79 /*! \brief Get a texture associated with the given path
80 Used for retrieval of previously discovered images to save
81 stat() on the filesystem all the time
82 \param url path that may be associated with a texture
83 \param type type of image to look for
84 \return URL of the texture associated with the given path
86 std::string
GetTextureForPath(const std::string
&url
, const std::string
&type
);
88 /*! \brief Set a texture associated with the given path
89 Used for setting of previously discovered images to save
90 stat() on the filesystem all the time. Should be used to set
91 the actual image path, not the cached image path (the image will be
93 \param url path that was used to find the texture
94 \param type type of image to associate
95 \param texture URL of the texture to associate with the path
97 void SetTextureForPath(const std::string
&url
, const std::string
&type
, const std::string
&texture
);
99 /*! \brief Clear a texture associated with the given path
100 \param url path that was used to find the texture
101 \param type type of image to associate
102 \param texture URL of the texture to associate with the path
103 \sa GetTextureForPath, SetTextureForPath
105 void ClearTextureForPath(const std::string
&url
, const std::string
&type
);
107 bool GetTextures(CVariant
&items
, const Filter
&filter
);
110 CDatabaseQueryRule
*CreateRule() const override
;
111 CDatabaseQueryRuleCombination
*CreateCombination() const override
;
113 /*! \brief retrieve a hash for the given url
114 Computes a hash of the current url to use for lookups in the database
115 \param url url to hash
116 \return a hash for this url
118 unsigned int GetURLHash(const std::string
&url
) const;
120 void CreateTables() override
;
121 void CreateAnalytics() override
;
122 void UpdateTables(int version
) override
;
123 int GetSchemaVersion() const override
{ return 13; }
124 const char* GetBaseDBName() const override
{ return "Textures"; }