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