aboutsummaryrefslogtreecommitdiff
path: root/src/permissionmanager.cpp
blob: 22a71106584d67a18e6ec10b679488e5c9c96ba9 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "permissionmanager.hpp"
#include <iostream>

PermissionManager::PermissionManager(std::string path)
	: path(path)
{
	if (std::filesystem::exists(this->path)) {
		std::ifstream in(path);
		std::string content;
		in >> this->lock_mouse;
		in >> this->location;
		in >> this->notification;
		in >> this->media_audio_capture;
		in >> this->media_video_capture;
		in >> this->desktop_audio_video_capture;
	}
}

PermissionManager::~PermissionManager()
{
	this->save();
}

void
PermissionManager::save()
{
	std::ofstream out(this->path);
	out << this->lock_mouse;
	out << " ";
	out << this->location;
	out << " ";
	out << this->notification;
	out << " ";
	out << this->media_audio_capture;
	out << " ";
	out << this->media_video_capture;
	out << " ";
	out << this->desktop_audio_video_capture;
}

bool
PermissionManager::get(QWebEnginePage::Feature feature)
{
	switch (feature) {
		case QWebEnginePage::Feature::MouseLock:
			return this->lock_mouse;
		case QWebEnginePage::Feature::Geolocation:
			return this->location;
		case QWebEnginePage::Feature::Notifications:
			return this->notification;
		case QWebEnginePage::Feature::MediaAudioCapture:
			return this->media_audio_capture;
		case QWebEnginePage::Feature::MediaVideoCapture:
			return this->media_video_capture;
		case QWebEnginePage::Feature::MediaAudioVideoCapture:
			return this->media_video_capture && this->media_audio_capture;
		case QWebEnginePage::Feature::DesktopVideoCapture:
			return this->desktop_audio_video_capture;
		case QWebEnginePage::Feature::DesktopAudioVideoCapture:
			return this->desktop_audio_video_capture;
		default:
			/* unreachable except QWebEnginePage::Feature gets new entries */
			return false;
	}
}

void
PermissionManager::set(QWebEnginePage::Feature feature, bool value)
{
	switch (feature) {
		case QWebEnginePage::Feature::MouseLock:
			this->lock_mouse = value;
			break;
		case QWebEnginePage::Feature::Geolocation:
			this->location = value;
			break;
		case QWebEnginePage::Feature::Notifications:
			this->notification = value;
			break;
		case QWebEnginePage::Feature::MediaAudioCapture:
			this->media_audio_capture = value;
			break;
		case QWebEnginePage::Feature::MediaVideoCapture:
			this->media_video_capture = value;
			break;
		case QWebEnginePage::Feature::MediaAudioVideoCapture:
			this->media_audio_capture = value;
			this->media_video_capture = value;
			break;
		case QWebEnginePage::Feature::DesktopVideoCapture:
			this->desktop_audio_video_capture = value;
			break;
		case QWebEnginePage::Feature::DesktopAudioVideoCapture:
			this->desktop_audio_video_capture = value;
			break;
	}
}