/****************************************************************************** Copyright (C) 2025 by Taylor Giampaolo Lain Bailey This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ******************************************************************************/ #pragma once #include #include #include #include #include #include #include #include #include #include class ThumbnailItem; class ThumbnailView; class ThumbnailManager : public QObject { Q_OBJECT std::vector signalHandlers; static void obsSourceRemoved(void *data, calldata_t *params); struct ThumbnailCache { size_t maxSize; using CacheEntry = std::pair; std::list cacheList; std::unordered_map::iterator> cacheMap; explicit ThumbnailCache(size_t maxSize) : maxSize(maxSize) {} void put(const std::string &key, const QPixmap &value); std::optional get(const std::string &key); }; std::deque priorityQueue; std::deque updateQueue; std::unordered_map thumbnailList; static constexpr int kMaxThumbnails = 64; ThumbnailCache thumbnailCache{kMaxThumbnails}; QTimer updateTimer; QElapsedTimer elapsedTimer; public: explicit ThumbnailManager(QObject *parent = nullptr); ~ThumbnailManager() = default; ThumbnailView *createView(QWidget *parent, obs_source_t *source); std::optional getCachedPixmap(const std::string &uuid); private: Q_DISABLE_COPY_MOVE(ThumbnailManager); void updateNextItem(size_t cycleDepth = 0); void removeIdFromQueues(const std::string &uuid); void updateTickInterval(int newInterval); void createThumbnailItem(const std::string &uuid); ThumbnailItem *getThumbnailItem(const std::string &uuid); private slots: void updateTick(); void addToPriorityQueue(const std::string &uuid, bool immediate = false); void addItemToCache(std::string &uuid, QPixmap &pixmap); void deleteItem(ThumbnailItem *item); void deleteItemById(const std::string &uuid); };