summaryrefslogtreecommitdiff
path: root/Config.cpp
blob: 2415e64c2998f1cbdbafe55b7aaf059887bf9385 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#include "Config.h"


const char* Config::viewModeNames[]
{
	"Cover",
	"List",
	"Detail"
};

Config::Config() {
	s_username = "username";
	s_password = "password";
	CoverGridColumns = 7;
	CoverGridRows = 2;
	ListGridColumns = 1;
	ListGridRows = 12;
	DetailGridColumns = 1;
	DetailGridRows = 4;
	
	UseMpv = false;
	ScrollByPage = true;
	ScrollAllAround = true;
	
	DefaultViewMode = ViewMode::Cover;
	
	ViewEntry en;
	en.Name = "Recently Added";
	en.PlexPath = "/library/recentlyAdded";
	m_viewentries.push_back(en);
	
	ViewEntry en2;
	en2.Name = "On Deck";
	en2.PlexPath = "/library/onDeck";
	m_viewentries.push_back(en2);
	
	ViewEntry en3;
	en3.Name = "Library";
	en3.PlexPath = "/library/sections";
	m_serverViewentries.push_back(en3);
	
	ViewEntry en4;
	en4.Name = "Video Channels";
	en4.PlexPath = "/video";
	m_serverViewentries.push_back(en4);
	
}

std::string Config::GetUUID() {
	if(s_uuid.empty()) {
		using Poco::UUIDGenerator;
		using Poco::UUID;
		UUIDGenerator &generator = UUIDGenerator::defaultGenerator();
		UUID uuid(generator.createRandom());
		s_uuid = uuid.toString();
	}
	return s_uuid;
}

void Config::SetUUID(const char* uuid) {
	if (uuid) s_uuid = std::string(uuid);
}


std::string Config::GetHostname() {
	if(s_hostname.empty()) {
		char hostname[1024];
		gethostname(hostname, 1024);
		s_hostname = std::string(hostname);
	}
	return s_hostname;
}

std::string Config::GetLanguage() {
	return "de";
}

std::string Config::GetUsername() {
	return s_username;
}

std::string Config::GetPassword() {
	return s_password;
}


bool Config::Parse(const char *name, const char *value)
{
	//dsyslog("[plex]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
	bool parsed = true;
	if (strcasecmp(name, "HideMainMenuEntry") == 0) 	Config::GetInstance().HideMainMenuEntry = atoi(value) ? true : false;
	else if (strcasecmp(name, "UsePlexAccount") == 0) 	Config::GetInstance().UsePlexAccount = atoi(value) ? true : false;
	else if (strcasecmp(name, "UseCustomTranscodeProfile") == 0) 	Config::GetInstance().UseCustomTranscodeProfile = atoi(value) ? true : false;
	else if (strcasecmp(name, "Username") == 0) 		Config::GetInstance().s_username = std::string(value);
	else if (strcasecmp(name, "Password") == 0) 		Config::GetInstance().s_password = std::string(value);
	else if (strcasecmp(name, "UUID") == 0) 			Config::GetInstance().SetUUID(value);
	else if (strcasecmp(name, "UseConfiguredServer") == 0) 	Config::GetInstance().UseConfiguredServer = atoi(value) ? true : false;
	else if (strcasecmp(name, "ServerHost") == 0) 		Config::GetInstance().s_serverHost = std::string(value);
	else if (strcasecmp(name, "ServerPort") == 0) 	Config::GetInstance().ServerPort = atoi(value);
	else if (strcasecmp(name, "CoverGridColumns") == 0) 	Config::GetInstance().CoverGridColumns = atoi(value);
	else if (strcasecmp(name, "CoverGridRows") == 0) 	Config::GetInstance().CoverGridRows = atoi(value);
	else if (strcasecmp(name, "DetailGridColumns") == 0) 	Config::GetInstance().DetailGridColumns = atoi(value);
	else if (strcasecmp(name, "DetailGridRows") == 0) 	Config::GetInstance().DetailGridRows = atoi(value);
	else if (strcasecmp(name, "ListGridColumns") == 0) 	Config::GetInstance().ListGridColumns = atoi(value);
	else if (strcasecmp(name, "ListGridRows") == 0) 	Config::GetInstance().ListGridRows = atoi(value);
	else if (strcasecmp(name, "UseMpv") == 0) 	Config::GetInstance().UseMpv = atoi(value) ? true : false;
	else if (strcasecmp(name, "ScrollByPage") == 0) 	Config::GetInstance().ScrollByPage = atoi(value) ? true : false;
	else if (strcasecmp(name, "ScrollAllAround") == 0) 	Config::GetInstance().ScrollAllAround = atoi(value) ? true : false;
	else parsed = false;

	if(!parsed) {
		// Parse ViewEntries
		
	}
	
	return parsed;
}


//////////////////////////////////////////////////////////////////////////////
//	cMenuSetupPage
//////////////////////////////////////////////////////////////////////////////

/**
**	Process key for setup menu.
*/
eOSState cMyMenuSetupPage::ProcessKey(eKeys key)
{
	return cMenuSetupPage::ProcessKey(key);
}

/**
**	Constructor setup menu.
**
**	Import global config variables into setup.
*/
cMyMenuSetupPage::cMyMenuSetupPage(void)
{
	strn0cpy(Username, Config::GetInstance().s_username.c_str(), STRING_SIZE);
	strn0cpy(Password, Config::GetInstance().s_password.c_str(), STRING_SIZE);
	strn0cpy(Uuid, Config::GetInstance().GetUUID().c_str(), STRING_SIZE);
	strn0cpy(ServerHost, Config::GetInstance().s_serverHost.c_str(), STRING_SIZE);
	ServerPort = Config::GetInstance().ServerPort;
	UseConfiguredServer = Config::GetInstance().UseConfiguredServer;
	HideMainMenuEntry = Config::GetInstance().HideMainMenuEntry;
	UseCustomTranscodeProfile = Config::GetInstance().UseCustomTranscodeProfile;
	UsePlexAccount = Config::GetInstance().UsePlexAccount;
	CoverGridColumns = Config::GetInstance().CoverGridColumns;
	CoverGridRows = Config::GetInstance().CoverGridRows;
	DetailGridColumns = Config::GetInstance().DetailGridColumns;
	DetailGridRows = Config::GetInstance().DetailGridRows;
	ListGridColumns = Config::GetInstance().ListGridColumns;
	ListGridRows = Config::GetInstance().ListGridRows;
	UseMpv = Config::GetInstance().UseMpv;
	ScrollByPage = Config::GetInstance().ScrollByPage;
	ScrollAllAround = Config::GetInstance().ScrollAllAround;
	DefaultViewMode = Config::GetInstance().DefaultViewMode;
	
	
	Add(new cMenuEditBoolItem(tr("Hide main menu entry"), (int*)&HideMainMenuEntry, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditBoolItem(tr("Use Mpv Plugin (If Availiable)"), (int*)&UseMpv, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditBoolItem(tr("Scroll by Page"), (int*)&ScrollByPage, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditBoolItem(tr("Scroll all around"), (int*)&ScrollAllAround, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditBoolItem(tr("Use custom transcoding profile"), (int*)&UseCustomTranscodeProfile, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditBoolItem(tr("Use Plex account"), (int*)&UsePlexAccount, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditStrItem(tr("Plex Username"), Username, STRING_SIZE));
	Add(new cMenuEditStrItem(tr("Plex Password"), Password, STRING_SIZE));
	
	Add(new cMenuEditBoolItem(tr("Use Custom Server"), (int*)&UseConfiguredServer, trVDR("no"), trVDR("yes")));
	Add(new cMenuEditStrItem(tr("Server Host"), ServerHost, STRING_SIZE));
	Add(new cMenuEditIntItem(tr("Server Port"), &ServerPort));
	
	Add(new cMenuEditStraItem(tr("Default View Mode"), &DefaultViewMode, 3, Config::viewModeNames));
	
	Add(new cMenuEditIntItem(tr("Cover Grid Columns"), &CoverGridColumns));
	Add(new cMenuEditIntItem(tr("Cover Grid Rows"), &CoverGridRows));
	
	Add(new cMenuEditIntItem(tr("Detail Grid Columns"), &DetailGridColumns));
	Add(new cMenuEditIntItem(tr("Detail Grid Rows"), &DetailGridRows));
	
	Add(new cMenuEditIntItem(tr("List Grid Columns"), &ListGridColumns));
	Add(new cMenuEditIntItem(tr("List Grid Rows"), &ListGridRows));
	
	cMenuEditStrItem* devUUID = new cMenuEditStrItem(tr("Current UUID"), Uuid, STRING_SIZE);
	devUUID->SetSelectable(false);
	Add(devUUID);
}

/**
**	Store setup.
*/
void cMyMenuSetupPage::Store(void)
{
	Config::GetInstance().s_username = std::string(Username);
	Config::GetInstance().s_password = std::string(Password);
	Config::GetInstance().HideMainMenuEntry = HideMainMenuEntry;
	Config::GetInstance().UseCustomTranscodeProfile = UseCustomTranscodeProfile;
	Config::GetInstance().UsePlexAccount = UsePlexAccount;
	Config::GetInstance().UseConfiguredServer = UseConfiguredServer;
	Config::GetInstance().s_serverHost = std::string(ServerHost);
	Config::GetInstance().ServerPort = ServerPort;
	Config::GetInstance().CoverGridColumns = CoverGridColumns;
	Config::GetInstance().CoverGridRows = CoverGridRows;
	Config::GetInstance().DetailGridColumns = DetailGridColumns;
	Config::GetInstance().DetailGridRows = DetailGridRows;
	Config::GetInstance().ListGridColumns = ListGridColumns;
	Config::GetInstance().ListGridRows = ListGridRows;
	Config::GetInstance().DefaultViewMode = (ViewMode)DefaultViewMode;
	Config::GetInstance().UseMpv = UseMpv;
	Config::GetInstance().ScrollByPage = ScrollByPage;
	Config::GetInstance().ScrollAllAround = ScrollAllAround;
	
	SetupStore("UseCustomTranscodeProfile", Config::GetInstance().UseCustomTranscodeProfile);
	SetupStore("HideMainMenuEntry", Config::GetInstance().HideMainMenuEntry);
	SetupStore("UsePlexAccount", Config::GetInstance().UsePlexAccount);
	SetupStore("Username", Config::GetInstance().s_username.c_str());
	SetupStore("Password", Config::GetInstance().s_password.c_str());
	SetupStore("UUID", Config::GetInstance().GetUUID().c_str());
	SetupStore("UseConfiguredServer", Config::GetInstance().UseConfiguredServer);
	SetupStore("ServerHost", Config::GetInstance().s_serverHost.c_str());
	SetupStore("ServerPort", Config::GetInstance().ServerPort);
	SetupStore("CoverGridColumns", Config::GetInstance().CoverGridColumns);
	SetupStore("CoverGridRows", Config::GetInstance().CoverGridRows);
	SetupStore("DetailGridColumns", Config::GetInstance().DetailGridColumns);
	SetupStore("DetailGridRows", Config::GetInstance().DetailGridRows);
	SetupStore("ListGridColumns", Config::GetInstance().ListGridColumns);
	SetupStore("ListGridRows", Config::GetInstance().ListGridRows);
	SetupStore("DefaultViewMode", Config::GetInstance().DefaultViewMode);
	SetupStore("UseMpv", Config::GetInstance().UseMpv);
	SetupStore("ScrollByPage", Config::GetInstance().ScrollByPage);
	SetupStore("ScrollAllAround", Config::GetInstance().ScrollAllAround);
}