/* * Copyright 2023, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef SCREENSHOT_REPOSITORY_H #define SCREENSHOT_REPOSITORY_H #include #include #include "ScreenshotCoordinate.h" #include "SharedBitmap.h" class WebAppInterface; class PackageScreenshotRepositoryListener : public BReferenceable { public: virtual void ScreenshotCached(const ScreenshotCoordinate& coord) = 0; }; typedef BReference PackageScreenshotRepositoryListenerRef; /*! This object manages a disk and in-memory cache of screenshots for the system. It will keep a few screenshots in memory, but will generally load them as required from local disk. */ class PackageScreenshotRepository { public: PackageScreenshotRepository( PackageScreenshotRepositoryListenerRef listener, WebAppInterface* webAppInterface); ~PackageScreenshotRepository(); status_t LoadScreenshot(const ScreenshotCoordinate& coord, BitmapRef* bitmap); status_t CacheAndLoadScreenshot(const ScreenshotCoordinate& coord, BitmapRef* bitmap); status_t HasCachedScreenshot(const ScreenshotCoordinate& coord, bool* value); status_t CacheScreenshot(const ScreenshotCoordinate& coord); private: status_t _Init(); status_t _CleanCache(); status_t _DownloadToLocalFile(const ScreenshotCoordinate& coord, const BPath& path); BPath _DeriveCachePath(const ScreenshotCoordinate& coord) const; status_t _CreateCachedData(const ScreenshotCoordinate& coord, BPositionIO** data); private: PackageScreenshotRepositoryListenerRef fListener; WebAppInterface* fWebAppInterface; BPath fBaseDirectory; }; #endif // SCREENSHOT_REPOSITORY_H