2 |
andreas |
1 |
/*
|
193 |
andreas |
2 |
* Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
|
2 |
andreas |
3 |
*
|
|
|
4 |
* This program is free software; you can redistribute it and/or modify
|
|
|
5 |
* it under the terms of the GNU General Public License as published by
|
|
|
6 |
* the Free Software Foundation; either version 3 of the License, or
|
|
|
7 |
* (at your option) any later version.
|
|
|
8 |
*
|
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
* GNU General Public License for more details.
|
|
|
13 |
*
|
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
|
15 |
* along with this program; if not, write to the Free Software Foundation,
|
|
|
16 |
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
17 |
*/
|
|
|
18 |
|
|
|
19 |
#include <unistd.h>
|
|
|
20 |
#include "tsettings.h"
|
77 |
andreas |
21 |
#include "texpat++.h"
|
303 |
andreas |
22 |
#include "terror.h"
|
2 |
andreas |
23 |
|
186 |
andreas |
24 |
#if __cplusplus < 201402L
|
|
|
25 |
# error "This module requires at least C++14 standard!"
|
|
|
26 |
#else
|
|
|
27 |
# if __cplusplus < 201703L
|
|
|
28 |
# include <experimental/filesystem>
|
|
|
29 |
namespace fs = std::experimental::filesystem;
|
|
|
30 |
# warning "Support for C++14 and experimental filesystem will be removed in a future version!"
|
|
|
31 |
# else
|
|
|
32 |
# include <filesystem>
|
|
|
33 |
# ifdef __ANDROID__
|
|
|
34 |
namespace fs = std::__fs::filesystem;
|
|
|
35 |
# else
|
|
|
36 |
namespace fs = std::filesystem;
|
|
|
37 |
# endif
|
|
|
38 |
# endif
|
|
|
39 |
#endif
|
|
|
40 |
|
2 |
andreas |
41 |
using std::string;
|
8 |
andreas |
42 |
using std::vector;
|
77 |
andreas |
43 |
using namespace Expat;
|
2 |
andreas |
44 |
|
|
|
45 |
TSettings::TSettings(const string& path)
|
|
|
46 |
: mPath(path)
|
|
|
47 |
{
|
3 |
andreas |
48 |
DECL_TRACER("TSettings::TSettings(const string& path)");
|
186 |
andreas |
49 |
|
197 |
andreas |
50 |
MSG_DEBUG("Loading from path: " << path);
|
11 |
andreas |
51 |
loadSettings(true);
|
2 |
andreas |
52 |
}
|
|
|
53 |
|
11 |
andreas |
54 |
bool TSettings::loadSettings(bool initial)
|
2 |
andreas |
55 |
{
|
3 |
andreas |
56 |
DECL_TRACER("TSettings::loadSettings()");
|
2 |
andreas |
57 |
|
11 |
andreas |
58 |
if (!initial)
|
|
|
59 |
{
|
|
|
60 |
mResourceLists.clear();
|
|
|
61 |
}
|
|
|
62 |
|
3 |
andreas |
63 |
TError::clear();
|
|
|
64 |
string fname = makeFileName(mPath, "prj.xma");
|
2 |
andreas |
65 |
|
3 |
andreas |
66 |
if (!isValidFile())
|
|
|
67 |
{
|
122 |
andreas |
68 |
MSG_ERROR("Error: File " << fname << " doesn't exist or can't be opened!");
|
|
|
69 |
TError::setError();
|
|
|
70 |
return false;
|
3 |
andreas |
71 |
}
|
2 |
andreas |
72 |
|
77 |
andreas |
73 |
TExpat xml(fname);
|
|
|
74 |
xml.setEncoding(ENC_CP1250);
|
2 |
andreas |
75 |
|
77 |
andreas |
76 |
if (!xml.parse())
|
3 |
andreas |
77 |
return false;
|
2 |
andreas |
78 |
|
77 |
andreas |
79 |
int depth = 0;
|
|
|
80 |
size_t index = 0;
|
|
|
81 |
|
303 |
andreas |
82 |
if (xml.getElementIndex("projectInfo", &depth) == TExpat::npos)
|
178 |
andreas |
83 |
{
|
|
|
84 |
MSG_ERROR("Couldn't find the project information! Broken surface?");
|
|
|
85 |
TError::setError();
|
|
|
86 |
return false;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
depth++;
|
|
|
90 |
mProject.protection = xml.getElement("protection", depth);
|
|
|
91 |
mProject.password = xml.getElement("password", depth);
|
|
|
92 |
vector<Expat::ATTRIBUTE_t> attr = xml.getAttributes();
|
|
|
93 |
mProject.encrypted = xml.getAttributeInt("encrypted", attr);
|
|
|
94 |
mProject.panelType = xml.getElement("panelType", depth);
|
|
|
95 |
mProject.fileRevision = xml.getElement("fileRevision", depth);
|
|
|
96 |
mProject.dealerID = xml.getElement("dealerId", depth);
|
|
|
97 |
mProject.jobName = xml.getElement("jobName", depth);
|
|
|
98 |
mProject.salesOrder = xml.getElement("salesOrder", depth);
|
|
|
99 |
mProject.purchaseOrder = xml.getElement("purchaseOrder", depth);
|
|
|
100 |
mProject.jobComment = xml.getElement("jobComment", depth);
|
|
|
101 |
mProject.designerID = xml.getElement("designerId", depth);
|
|
|
102 |
mProject.creationDate = xml.getElement("creationDate", depth);
|
|
|
103 |
mProject.revisionDate = xml.getElement("revisionDate", depth);
|
|
|
104 |
mProject.lastSaveDate = xml.getElement("lastSaveDate", depth);
|
|
|
105 |
mProject.fileName = xml.getElement("fileName", depth);
|
|
|
106 |
mProject.colorChoice = xml.getElement("colorChoice", depth);
|
|
|
107 |
mProject.specifyPortCount = xml.getElementInt("specifyPortCount", depth);
|
|
|
108 |
mProject.specifyChanCount = xml.getElementInt("specifyChanCount", depth);
|
|
|
109 |
|
77 |
andreas |
110 |
if ((index = xml.getElementIndex("panelSetup", &depth)) == TExpat::npos)
|
|
|
111 |
{
|
|
|
112 |
MSG_ERROR("Couldn't find the section \"panelSetup\" in file!");
|
|
|
113 |
TError::setError();
|
|
|
114 |
return false;
|
|
|
115 |
}
|
|
|
116 |
|
78 |
andreas |
117 |
depth++;
|
3 |
andreas |
118 |
string value;
|
77 |
andreas |
119 |
mSetup.portCount = xml.getElementInt("portCount", depth);
|
|
|
120 |
mSetup.setupPort = xml.getElementInt("setupPort", depth);
|
|
|
121 |
mSetup.addressCount = xml.getElementInt("addressCount", depth);
|
|
|
122 |
mSetup.channelCount = xml.getElementInt("channelCount", depth);
|
|
|
123 |
mSetup.levelCount = xml.getElementInt("levelCount", depth);
|
|
|
124 |
mSetup.powerUpPage = xml.getElement("powerUpPage", depth);
|
2 |
andreas |
125 |
|
77 |
andreas |
126 |
value = xml.getElement("powerUpPopup", depth);
|
2 |
andreas |
127 |
|
5 |
andreas |
128 |
if (!value.empty())
|
7 |
andreas |
129 |
{
|
3 |
andreas |
130 |
mSetup.powerUpPopup.push_back(value);
|
77 |
andreas |
131 |
bool valid;
|
8 |
andreas |
132 |
|
|
|
133 |
do
|
|
|
134 |
{
|
77 |
andreas |
135 |
value = xml.getNextElement("powerUpPopup", depth, &valid);
|
8 |
andreas |
136 |
|
77 |
andreas |
137 |
if (valid)
|
78 |
andreas |
138 |
{
|
8 |
andreas |
139 |
mSetup.powerUpPopup.push_back(value);
|
78 |
andreas |
140 |
MSG_DEBUG("powerUpPopup: " << value);
|
|
|
141 |
}
|
8 |
andreas |
142 |
}
|
77 |
andreas |
143 |
while (valid);
|
7 |
andreas |
144 |
}
|
2 |
andreas |
145 |
|
78 |
andreas |
146 |
xml.setIndex(index);
|
77 |
andreas |
147 |
mSetup.feedbackBlinkRate = xml.getElementInt("feedbackBlinkRate", depth);
|
|
|
148 |
mSetup.startupString = xml.getElement("startupString", depth);
|
|
|
149 |
mSetup.wakeupString = xml.getElement("wakeupString", depth);
|
|
|
150 |
mSetup.sleepString = xml.getElement("sleepString", depth);
|
|
|
151 |
mSetup.standbyString = xml.getElement("standbyString", depth);
|
|
|
152 |
mSetup.shutdownString = xml.getElement("shutdownString", depth);
|
|
|
153 |
mSetup.idlePage = xml.getElement("idlePage", depth);
|
|
|
154 |
mSetup.idleTimeout = xml.getElementInt("idleTimeout", depth);
|
|
|
155 |
mSetup.extButtonsKey = xml.getElementInt("extButtonsKey", depth);
|
|
|
156 |
mSetup.screenWidth = xml.getElementInt("screenWidth", depth);
|
|
|
157 |
mSetup.screenHeight = xml.getElementInt("screenHeight", depth);
|
|
|
158 |
mSetup.screenRefresh = xml.getElementInt("screenRefresh", depth);
|
|
|
159 |
mSetup.screenRotate = xml.getElementInt("screenRotate", depth);
|
|
|
160 |
mSetup.screenDescription = xml.getElement("screenDescription", depth);
|
|
|
161 |
mSetup.pageTracking = xml.getElementInt("pageTracking", depth);
|
|
|
162 |
mSetup.cursor = xml.getElementInt("cursor", depth);
|
|
|
163 |
mSetup.brightness = xml.getElementInt("brightness", depth);
|
|
|
164 |
mSetup.lightSensorLevelPort = xml.getElementInt("lightSensorLevelPort", depth);
|
|
|
165 |
mSetup.lightSensorLevelCode = xml.getElementInt("lightSensorLevelCode", depth);
|
|
|
166 |
mSetup.lightSensorChannelPort = xml.getElementInt("lightSensorChannelPort", depth);
|
|
|
167 |
mSetup.lightSensorChannelCode = xml.getElementInt("lightSensorChannelCode", depth);
|
|
|
168 |
mSetup.motionSensorChannelPort = xml.getElementInt("motionSensorChannelPort", depth);
|
|
|
169 |
mSetup.motionSensorChannelCode = xml.getElementInt("motionSensorChannelCode", depth);
|
|
|
170 |
mSetup.batteryLevelPort = xml.getElementInt("batteryLevelPort", depth);
|
|
|
171 |
mSetup.batteryLevelCode = xml.getElementInt("batteryLevelCode", depth);
|
|
|
172 |
mSetup.irPortAMX38Emit = xml.getElementInt("irPortAMX38Emit", depth);
|
|
|
173 |
mSetup.irPortAMX455Emit = xml.getElementInt("irPortAMX455Emit", depth);
|
|
|
174 |
mSetup.irPortAMX38Recv = xml.getElementInt("irPortAMX38Recv", depth);
|
|
|
175 |
mSetup.irPortAMX455Recv = xml.getElementInt("irPortAMX455Recv", depth);
|
|
|
176 |
mSetup.irPortUser1 = xml.getElementInt("irPortUser1", depth);
|
|
|
177 |
mSetup.irPortUser2 = xml.getElementInt("irPortUser2", depth);
|
|
|
178 |
mSetup.cradleChannelPort = xml.getElementInt("cradleChannelPort", depth);
|
|
|
179 |
mSetup.cradleChannelCode = xml.getElementInt("cradleChannelCode", depth);
|
|
|
180 |
mSetup.uniqueID = xml.getElementInt("uniqueID", depth);
|
|
|
181 |
mSetup.appCreated = xml.getElementInt("appCreated", depth);
|
|
|
182 |
mSetup.buildNumber = xml.getElementInt("buildNumber", depth);
|
|
|
183 |
mSetup.appModified = xml.getElement("appModified", depth);
|
|
|
184 |
mSetup.buildNumberMod = xml.getElementInt("buildNumberMod", depth);
|
|
|
185 |
mSetup.buildStatusMod = xml.getElement("buildStatusMod", depth);
|
|
|
186 |
mSetup.activePalette = xml.getElementInt("activePalette", depth);
|
|
|
187 |
mSetup.marqueeSpeed = xml.getElementInt("marqueeSpeed", depth);
|
|
|
188 |
mSetup.setupPagesProject = xml.getElementInt("setupPagesProject", depth);
|
|
|
189 |
mSetup.voipCommandPort = xml.getElementInt("voipCommandPort", depth);
|
4 |
andreas |
190 |
|
77 |
andreas |
191 |
if ((index = xml.getElementIndex("resourceList", &depth)) == TExpat::npos)
|
|
|
192 |
{
|
84 |
andreas |
193 |
MSG_WARNING("Missing element \"resourceList\" in file!");
|
77 |
andreas |
194 |
}
|
8 |
andreas |
195 |
|
77 |
andreas |
196 |
string name, content;
|
|
|
197 |
vector<ATTRIBUTE_t> attrs;
|
|
|
198 |
|
84 |
andreas |
199 |
if (index != TExpat::npos)
|
8 |
andreas |
200 |
{
|
84 |
andreas |
201 |
depth++;
|
|
|
202 |
size_t oldIndex = 0;
|
|
|
203 |
MSG_DEBUG("Index " << index << " and depth " << depth << " and entity " << xml.getElementName());
|
8 |
andreas |
204 |
|
84 |
andreas |
205 |
do
|
8 |
andreas |
206 |
{
|
84 |
andreas |
207 |
attrs = xml.getAttributes();
|
|
|
208 |
string type = xml.getAttribute("type", attrs);
|
|
|
209 |
RESOURCE_LIST_T list = findResourceType(type);
|
|
|
210 |
MSG_DEBUG("resource type: " << type);
|
8 |
andreas |
211 |
|
84 |
andreas |
212 |
if (mResourceLists.size() == 0 || list.type.empty())
|
|
|
213 |
{
|
|
|
214 |
list.type = type;
|
|
|
215 |
list.ressource.clear();
|
|
|
216 |
mResourceLists.push_back(list);
|
|
|
217 |
}
|
78 |
andreas |
218 |
|
84 |
andreas |
219 |
RESOURCE_T resource;
|
|
|
220 |
|
|
|
221 |
while ((index = xml.getNextElementIndex("resource", depth)) != TExpat::npos)
|
8 |
andreas |
222 |
{
|
84 |
andreas |
223 |
while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
|
8 |
andreas |
224 |
{
|
84 |
andreas |
225 |
string e = name;
|
8 |
andreas |
226 |
|
84 |
andreas |
227 |
if (e.compare("name") == 0)
|
|
|
228 |
resource.name = content;
|
|
|
229 |
else if (e.compare("protocol") == 0)
|
|
|
230 |
resource.protocol = content;
|
|
|
231 |
else if (e.compare("host") == 0)
|
|
|
232 |
resource.host = content;
|
|
|
233 |
else if (e.compare("file") == 0)
|
|
|
234 |
resource.file = content;
|
|
|
235 |
else if (e.compare("password") == 0)
|
|
|
236 |
{
|
|
|
237 |
resource.password = content;
|
|
|
238 |
int enc = xml.getAttributeInt("encrypted", attrs);
|
|
|
239 |
|
|
|
240 |
if (enc != 0)
|
|
|
241 |
resource.encrypted = true;
|
|
|
242 |
else
|
|
|
243 |
resource.encrypted = false;
|
|
|
244 |
}
|
|
|
245 |
else if (e.compare("user") == 0)
|
|
|
246 |
resource.user = content;
|
|
|
247 |
else if (e.compare("path") == 0)
|
|
|
248 |
resource.path = content;
|
|
|
249 |
else if (e.compare("refresh") == 0)
|
|
|
250 |
resource.refresh = xml.convertElementToInt(content);
|
|
|
251 |
else if (e.compare("dynamo") == 0)
|
|
|
252 |
resource.dynamo = ((xml.convertElementToInt(content) == 0) ? false : true);
|
|
|
253 |
else if (e.compare("preserve") == 0)
|
|
|
254 |
resource.preserve = ((xml.convertElementToInt(content) == 0) ? false : true);
|
|
|
255 |
|
|
|
256 |
oldIndex = index;
|
8 |
andreas |
257 |
}
|
78 |
andreas |
258 |
|
84 |
andreas |
259 |
list.ressource.push_back(resource);
|
|
|
260 |
MSG_DEBUG("Scheme: " << resource.protocol << ", Host: " << resource.host << ", Path: " << resource.path << ", File: " << resource.file << ", Name: " << resource.name);
|
|
|
261 |
resource.clear();
|
|
|
262 |
|
|
|
263 |
if (index == TExpat::npos)
|
|
|
264 |
index = oldIndex + 2;
|
8 |
andreas |
265 |
}
|
|
|
266 |
|
84 |
andreas |
267 |
vector<RESOURCE_LIST_T>::iterator itResList;
|
78 |
andreas |
268 |
|
84 |
andreas |
269 |
for (itResList = mResourceLists.begin(); itResList != mResourceLists.end(); itResList++)
|
21 |
andreas |
270 |
{
|
84 |
andreas |
271 |
if (itResList->type.compare(type) == 0)
|
|
|
272 |
{
|
|
|
273 |
mResourceLists.erase(itResList);
|
|
|
274 |
mResourceLists.push_back(list);
|
|
|
275 |
break;
|
|
|
276 |
}
|
21 |
andreas |
277 |
}
|
|
|
278 |
}
|
84 |
andreas |
279 |
while ((index = xml.getNextElementIndex("resourceList", depth)) != TExpat::npos);
|
8 |
andreas |
280 |
}
|
|
|
281 |
|
156 |
andreas |
282 |
if (xml.getElementIndex("paletteList", &depth) == TExpat::npos)
|
4 |
andreas |
283 |
{
|
|
|
284 |
MSG_WARNING("There exists no color palette! There will be only the system colors available.");
|
|
|
285 |
return true;
|
|
|
286 |
}
|
|
|
287 |
|
77 |
andreas |
288 |
depth++;
|
4 |
andreas |
289 |
|
78 |
andreas |
290 |
while ((index = xml.getNextElementIndex("palette", depth)) != TExpat::npos)
|
4 |
andreas |
291 |
{
|
|
|
292 |
PALETTE_SETUP ps;
|
|
|
293 |
|
78 |
andreas |
294 |
while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
|
4 |
andreas |
295 |
{
|
78 |
andreas |
296 |
if (name.compare("name") == 0)
|
77 |
andreas |
297 |
ps.name = content;
|
78 |
andreas |
298 |
else if (name.compare("file") == 0)
|
77 |
andreas |
299 |
ps.file = content;
|
78 |
andreas |
300 |
else if (name.compare("paletteID") == 0)
|
77 |
andreas |
301 |
ps.paletteID = xml.convertElementToInt(content);
|
4 |
andreas |
302 |
}
|
|
|
303 |
|
|
|
304 |
mSetup.palettes.push_back(ps);
|
|
|
305 |
}
|
|
|
306 |
|
3 |
andreas |
307 |
return true;
|
2 |
andreas |
308 |
}
|
8 |
andreas |
309 |
|
|
|
310 |
RESOURCE_LIST_T TSettings::findResourceType(const string& type)
|
|
|
311 |
{
|
|
|
312 |
DECL_TRACER ("TSettings::findResourceType(const string& type)");
|
|
|
313 |
|
|
|
314 |
vector<RESOURCE_LIST_T>::iterator iter;
|
|
|
315 |
|
|
|
316 |
for (iter = mResourceLists.begin(); iter != mResourceLists.end(); iter++)
|
|
|
317 |
{
|
|
|
318 |
if (iter->type.compare(type) == 0)
|
|
|
319 |
return *iter;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
return RESOURCE_LIST_T();
|
|
|
323 |
}
|
151 |
andreas |
324 |
|
|
|
325 |
bool TSettings::isPortrait()
|
|
|
326 |
{
|
|
|
327 |
DECL_TRACER("TSettings::isPortrait()");
|
|
|
328 |
|
|
|
329 |
return mSetup.screenWidth < mSetup.screenHeight;
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
bool TSettings::isLandscape()
|
|
|
333 |
{
|
|
|
334 |
DECL_TRACER("TSettings::isLandscape()");
|
|
|
335 |
|
|
|
336 |
return mSetup.screenWidth > mSetup.screenHeight;
|
|
|
337 |
}
|