| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "iprofileiconcache.h" |
| 7 | #include <filesystem> |
| 8 | #include <memory> |
| 9 | #include <optional> |
| 10 | #include <vector> |
| 11 | |
| 12 | class IFileCache; |
| 13 | |
| 14 | class ProfileIconCache final : public IProfileIconCache |
| 15 | { |
| 16 | public: |
| 17 | ProfileIconCache(std::unique_ptr<IFileCache> &&cache) noexcept; |
| 18 | |
| 19 | void init() override; |
| 20 | |
| 21 | bool tryOrCache(IProfile::Info &info, |
| 22 | std::vector<char> const &fallbackIcon) override; |
| 23 | |
| 24 | bool cache(IProfile::Info &info, std::vector<char> const &iconData) override; |
| 25 | |
| 26 | std::pair<bool, bool> syncCache(IProfile::Info &info) override; |
| 27 | |
| 28 | void clean(IProfile::Info &info) override; |
| 29 | |
| 30 | private: |
| 31 | std::optional<std::filesystem::path> |
| 32 | cacheIconFromData(std::vector<char> const &iconData, |
| 33 | IProfile::Info const &info) const; |
| 34 | |
| 35 | std::unique_ptr<IFileCache> const cache_; |
| 36 | }; |