summaryrefslogtreecommitdiff
path: root/pictureCache.h
blob: 51398e85d7fee35f83b10db555007c3fa81686c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef CPICTURECACHE_H
#define CPICTURECACHE_H

#include <memory>
#include <iostream>
#include <fstream>
#include <deque>
#include <string>

#include <vdr/thread.h>
#include <vdr/plugin.h>

#include "viewGridNavigator.h"

enum ImageResolution {
	SD384,
	SD480,
	HD720,
	HD1080
};

class cPictureCache : public cThread
{
private:
	struct CacheInfo {
		CacheInfo(std::string Uri, int Width, int Height, std::function<void(cGridElement*)> OnCached, cGridElement* Calle) {
			uri = Uri;
			width = Width;
			height = Height;
			onCached = OnCached;
			calle = Calle;
		};
		std::string uri;
		int width;
		int height;
		std::function<void(cGridElement*)> onCached;
		cGridElement* calle;
	};
	cPictureCache();
	std::deque<CacheInfo> m_qImagesToLoad;
	volatile bool m_bAllInvalidated;

	std::string FileName(std::string uri, int width);
	std::string TranscodeUri(std::string uri, int width, int height);

	bool DownloadFileAndSave(std::string uri, std::string localFile);

	std::string m_cacheDir;

protected:
	virtual void Action();

public:
	static cPictureCache& GetInstance() {
		static cPictureCache instance;
		return instance;
	}
	void Stop();

	bool Cached(std::string uri, int width);
	std::string GetPath(std::string uri, int width, int height, bool& cached, std::function<void(cGridElement*)> OnCached = NULL, cGridElement* calle = NULL);
	void Remove(cGridElement* element);
	void Remove(std::string uri);
	void RemoveAll();
};

#endif // CPICTURECACHE_H