1 /* 2 * Copyright 2024, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef SCREENSHOT_REPOSITORY_H 6 #define SCREENSHOT_REPOSITORY_H 7 8 9 #include <Bitmap.h> 10 #include <Path.h> 11 #include <String.h> 12 13 #include "BitmapHolder.h" 14 #include "ScreenshotCoordinate.h" 15 16 17 class WebAppInterface; 18 19 20 class PackageScreenshotRepositoryListener : public BReferenceable { 21 public: 22 virtual void ScreenshotCached(const ScreenshotCoordinate& coord) = 0; 23 }; 24 25 26 typedef BReference<PackageScreenshotRepositoryListener> PackageScreenshotRepositoryListenerRef; 27 28 29 /*! This object manages a disk and in-memory cache of screenshots for the 30 system. It will keep a few screenshots in memory, but will generally load 31 them as required from local disk. 32 */ 33 34 class PackageScreenshotRepository { 35 public: 36 37 PackageScreenshotRepository( 38 PackageScreenshotRepositoryListenerRef listener, 39 WebAppInterface* webAppInterface); 40 ~PackageScreenshotRepository(); 41 42 status_t LoadScreenshot(const ScreenshotCoordinate& coord, 43 BitmapHolderRef& bitmapHolderRef); 44 status_t CacheAndLoadScreenshot(const ScreenshotCoordinate& coord, 45 BitmapHolderRef& bitmapHolderRef); 46 47 status_t HasCachedScreenshot(const ScreenshotCoordinate& coord, bool* value); 48 status_t CacheScreenshot(const ScreenshotCoordinate& coord); 49 50 private: 51 status_t _Init(); 52 53 status_t _CleanCache(); 54 55 status_t _DownloadToLocalFile(const ScreenshotCoordinate& coord, 56 const BPath& path); 57 BPath _DeriveCachePath(const ScreenshotCoordinate& coord) const; 58 status_t _CreateCachedData(const ScreenshotCoordinate& coord, 59 BPositionIO** data); 60 61 private: 62 PackageScreenshotRepositoryListenerRef 63 fListener; 64 WebAppInterface* fWebAppInterface; 65 BPath fBaseDirectory; 66 }; 67 68 69 #endif // SCREENSHOT_REPOSITORY_H 70