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
;
38 class CTextureDatabase
: public CDatabase
, public IDatabaseQueryRuleFactory
42 ~CTextureDatabase() override
;
45 bool GetCachedTexture(const std::string
&originalURL
, CTextureDetails
&details
);
46 bool AddCachedTexture(const std::string
&originalURL
, const CTextureDetails
&details
);
47 bool SetCachedTextureValid(const std::string
&originalURL
, bool updateable
);
48 bool ClearCachedTexture(const std::string
&originalURL
, std::string
&cacheFile
);
49 bool ClearCachedTexture(int textureID
, std::string
&cacheFile
);
50 bool IncrementUseCount(const CTextureDetails
&details
);
52 /*! \brief Invalidate a previously cached texture
53 Invalidates the texture hash, and sets the texture update time to the current time so that
54 next texture load it will be re-cached.
55 \param url texture path
57 bool InvalidateCachedTexture(const std::string
&originalURL
);
59 /*! \brief Get a texture associated with the given path
60 Used for retrieval of previously discovered images to save
61 stat() on the filesystem all the time
62 \param url path that may be associated with a texture
63 \param type type of image to look for
64 \return URL of the texture associated with the given path
66 std::string
GetTextureForPath(const std::string
&url
, const std::string
&type
);
68 /*! \brief Set a texture associated with the given path
69 Used for setting of previously discovered images to save
70 stat() on the filesystem all the time. Should be used to set
71 the actual image path, not the cached image path (the image will be
73 \param url path that was used to find the texture
74 \param type type of image to associate
75 \param texture URL of the texture to associate with the path
77 void SetTextureForPath(const std::string
&url
, const std::string
&type
, const std::string
&texture
);
79 /*! \brief Clear a texture associated with the given path
80 \param url path that was used to find the texture
81 \param type type of image to associate
82 \param texture URL of the texture to associate with the path
83 \sa GetTextureForPath, SetTextureForPath
85 void ClearTextureForPath(const std::string
&url
, const std::string
&type
);
87 bool GetTextures(CVariant
&items
, const Filter
&filter
);
90 * @brief Get a list of the oldest cached images eligible for cleaning.
91 * @param maxImages the maximum number of images to return
94 std::vector
<std::string
> GetOldestCachedImages(unsigned int maxImages
) const;
97 * @brief Set a list of images to be kept. Used to clean the image cache.
101 bool SetKeepCachedImages(const std::vector
<std::string
>& imagesToKeep
);
104 CDatabaseQueryRule
*CreateRule() const override
;
105 CDatabaseQueryRuleCombination
*CreateCombination() const override
;
107 /*! \brief retrieve a hash for the given url
108 Computes a hash of the current url to use for lookups in the database
109 \param url url to hash
110 \return a hash for this url
112 unsigned int GetURLHash(const std::string
&url
) const;
114 void CreateTables() override
;
115 void CreateAnalytics() override
;
116 void UpdateTables(int version
) override
;
117 int GetSchemaVersion() const override
{ return 14; }
118 const char* GetBaseDBName() const override
{ return "Textures"; }