2 |
andreas |
1 |
/*
|
21 |
andreas |
2 |
* Copyright (C) 2020, 2021 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"
|
22 |
andreas |
22 |
#include "tconfig.h"
|
|
|
23 |
#include "ttpinit.h"
|
2 |
andreas |
24 |
|
|
|
25 |
using std::string;
|
8 |
andreas |
26 |
using std::vector;
|
77 |
andreas |
27 |
using namespace Expat;
|
2 |
andreas |
28 |
|
|
|
29 |
TSettings::TSettings(const string& path)
|
|
|
30 |
: mPath(path)
|
|
|
31 |
{
|
3 |
andreas |
32 |
DECL_TRACER("TSettings::TSettings(const string& path)");
|
11 |
andreas |
33 |
loadSettings(true);
|
2 |
andreas |
34 |
}
|
|
|
35 |
|
11 |
andreas |
36 |
bool TSettings::loadSettings(bool initial)
|
2 |
andreas |
37 |
{
|
3 |
andreas |
38 |
DECL_TRACER("TSettings::loadSettings()");
|
2 |
andreas |
39 |
|
11 |
andreas |
40 |
if (!initial)
|
|
|
41 |
{
|
|
|
42 |
mResourceLists.clear();
|
|
|
43 |
}
|
|
|
44 |
|
3 |
andreas |
45 |
TError::clear();
|
|
|
46 |
string fname = makeFileName(mPath, "prj.xma");
|
2 |
andreas |
47 |
|
3 |
andreas |
48 |
if (!isValidFile())
|
|
|
49 |
{
|
22 |
andreas |
50 |
TTPInit init(TConfig::getProjectPath());
|
|
|
51 |
|
|
|
52 |
if (!isValidFile())
|
|
|
53 |
{
|
|
|
54 |
MSG_ERROR("Error: File " << fname << " doesn't exist or can't be opened!");
|
|
|
55 |
TError::setError();
|
|
|
56 |
return false;
|
|
|
57 |
}
|
3 |
andreas |
58 |
}
|
2 |
andreas |
59 |
|
77 |
andreas |
60 |
TExpat xml(fname);
|
|
|
61 |
xml.setEncoding(ENC_CP1250);
|
2 |
andreas |
62 |
|
77 |
andreas |
63 |
if (!xml.parse())
|
3 |
andreas |
64 |
return false;
|
2 |
andreas |
65 |
|
77 |
andreas |
66 |
int depth = 0;
|
|
|
67 |
size_t index = 0;
|
|
|
68 |
|
|
|
69 |
if ((index = xml.getElementIndex("panelSetup", &depth)) == TExpat::npos)
|
|
|
70 |
{
|
|
|
71 |
MSG_ERROR("Couldn't find the section \"panelSetup\" in file!");
|
|
|
72 |
TError::setError();
|
|
|
73 |
return false;
|
|
|
74 |
}
|
|
|
75 |
|
78 |
andreas |
76 |
depth++;
|
3 |
andreas |
77 |
string value;
|
77 |
andreas |
78 |
mSetup.portCount = xml.getElementInt("portCount", depth);
|
|
|
79 |
mSetup.setupPort = xml.getElementInt("setupPort", depth);
|
|
|
80 |
mSetup.addressCount = xml.getElementInt("addressCount", depth);
|
|
|
81 |
mSetup.channelCount = xml.getElementInt("channelCount", depth);
|
|
|
82 |
mSetup.levelCount = xml.getElementInt("levelCount", depth);
|
|
|
83 |
mSetup.powerUpPage = xml.getElement("powerUpPage", depth);
|
2 |
andreas |
84 |
|
77 |
andreas |
85 |
value = xml.getElement("powerUpPopup", depth);
|
2 |
andreas |
86 |
|
5 |
andreas |
87 |
if (!value.empty())
|
7 |
andreas |
88 |
{
|
3 |
andreas |
89 |
mSetup.powerUpPopup.push_back(value);
|
77 |
andreas |
90 |
bool valid;
|
8 |
andreas |
91 |
|
|
|
92 |
do
|
|
|
93 |
{
|
77 |
andreas |
94 |
value = xml.getNextElement("powerUpPopup", depth, &valid);
|
8 |
andreas |
95 |
|
77 |
andreas |
96 |
if (valid)
|
78 |
andreas |
97 |
{
|
8 |
andreas |
98 |
mSetup.powerUpPopup.push_back(value);
|
78 |
andreas |
99 |
MSG_DEBUG("powerUpPopup: " << value);
|
|
|
100 |
}
|
8 |
andreas |
101 |
}
|
77 |
andreas |
102 |
while (valid);
|
7 |
andreas |
103 |
}
|
2 |
andreas |
104 |
|
78 |
andreas |
105 |
xml.setIndex(index);
|
77 |
andreas |
106 |
mSetup.feedbackBlinkRate = xml.getElementInt("feedbackBlinkRate", depth);
|
|
|
107 |
mSetup.startupString = xml.getElement("startupString", depth);
|
|
|
108 |
mSetup.wakeupString = xml.getElement("wakeupString", depth);
|
|
|
109 |
mSetup.sleepString = xml.getElement("sleepString", depth);
|
|
|
110 |
mSetup.standbyString = xml.getElement("standbyString", depth);
|
|
|
111 |
mSetup.shutdownString = xml.getElement("shutdownString", depth);
|
|
|
112 |
mSetup.idlePage = xml.getElement("idlePage", depth);
|
|
|
113 |
mSetup.idleTimeout = xml.getElementInt("idleTimeout", depth);
|
|
|
114 |
mSetup.extButtonsKey = xml.getElementInt("extButtonsKey", depth);
|
|
|
115 |
mSetup.screenWidth = xml.getElementInt("screenWidth", depth);
|
|
|
116 |
mSetup.screenHeight = xml.getElementInt("screenHeight", depth);
|
|
|
117 |
mSetup.screenRefresh = xml.getElementInt("screenRefresh", depth);
|
|
|
118 |
mSetup.screenRotate = xml.getElementInt("screenRotate", depth);
|
|
|
119 |
mSetup.screenDescription = xml.getElement("screenDescription", depth);
|
|
|
120 |
mSetup.pageTracking = xml.getElementInt("pageTracking", depth);
|
|
|
121 |
mSetup.cursor = xml.getElementInt("cursor", depth);
|
|
|
122 |
mSetup.brightness = xml.getElementInt("brightness", depth);
|
|
|
123 |
mSetup.lightSensorLevelPort = xml.getElementInt("lightSensorLevelPort", depth);
|
|
|
124 |
mSetup.lightSensorLevelCode = xml.getElementInt("lightSensorLevelCode", depth);
|
|
|
125 |
mSetup.lightSensorChannelPort = xml.getElementInt("lightSensorChannelPort", depth);
|
|
|
126 |
mSetup.lightSensorChannelCode = xml.getElementInt("lightSensorChannelCode", depth);
|
|
|
127 |
mSetup.motionSensorChannelPort = xml.getElementInt("motionSensorChannelPort", depth);
|
|
|
128 |
mSetup.motionSensorChannelCode = xml.getElementInt("motionSensorChannelCode", depth);
|
|
|
129 |
mSetup.batteryLevelPort = xml.getElementInt("batteryLevelPort", depth);
|
|
|
130 |
mSetup.batteryLevelCode = xml.getElementInt("batteryLevelCode", depth);
|
|
|
131 |
mSetup.irPortAMX38Emit = xml.getElementInt("irPortAMX38Emit", depth);
|
|
|
132 |
mSetup.irPortAMX455Emit = xml.getElementInt("irPortAMX455Emit", depth);
|
|
|
133 |
mSetup.irPortAMX38Recv = xml.getElementInt("irPortAMX38Recv", depth);
|
|
|
134 |
mSetup.irPortAMX455Recv = xml.getElementInt("irPortAMX455Recv", depth);
|
|
|
135 |
mSetup.irPortUser1 = xml.getElementInt("irPortUser1", depth);
|
|
|
136 |
mSetup.irPortUser2 = xml.getElementInt("irPortUser2", depth);
|
|
|
137 |
mSetup.cradleChannelPort = xml.getElementInt("cradleChannelPort", depth);
|
|
|
138 |
mSetup.cradleChannelCode = xml.getElementInt("cradleChannelCode", depth);
|
|
|
139 |
mSetup.uniqueID = xml.getElementInt("uniqueID", depth);
|
|
|
140 |
mSetup.appCreated = xml.getElementInt("appCreated", depth);
|
|
|
141 |
mSetup.buildNumber = xml.getElementInt("buildNumber", depth);
|
|
|
142 |
mSetup.appModified = xml.getElement("appModified", depth);
|
|
|
143 |
mSetup.buildNumberMod = xml.getElementInt("buildNumberMod", depth);
|
|
|
144 |
mSetup.buildStatusMod = xml.getElement("buildStatusMod", depth);
|
|
|
145 |
mSetup.activePalette = xml.getElementInt("activePalette", depth);
|
|
|
146 |
mSetup.marqueeSpeed = xml.getElementInt("marqueeSpeed", depth);
|
|
|
147 |
mSetup.setupPagesProject = xml.getElementInt("setupPagesProject", depth);
|
|
|
148 |
mSetup.voipCommandPort = xml.getElementInt("voipCommandPort", depth);
|
4 |
andreas |
149 |
|
77 |
andreas |
150 |
if ((index = xml.getElementIndex("resourceList", &depth)) == TExpat::npos)
|
|
|
151 |
{
|
84 |
andreas |
152 |
MSG_WARNING("Missing element \"resourceList\" in file!");
|
|
|
153 |
// TError::setError();
|
|
|
154 |
// return false;
|
77 |
andreas |
155 |
}
|
8 |
andreas |
156 |
|
77 |
andreas |
157 |
string name, content;
|
|
|
158 |
vector<ATTRIBUTE_t> attrs;
|
|
|
159 |
|
84 |
andreas |
160 |
if (index != TExpat::npos)
|
8 |
andreas |
161 |
{
|
84 |
andreas |
162 |
depth++;
|
|
|
163 |
size_t oldIndex = 0;
|
|
|
164 |
MSG_DEBUG("Index " << index << " and depth " << depth << " and entity " << xml.getElementName());
|
8 |
andreas |
165 |
|
84 |
andreas |
166 |
do
|
8 |
andreas |
167 |
{
|
84 |
andreas |
168 |
attrs = xml.getAttributes();
|
|
|
169 |
string type = xml.getAttribute("type", attrs);
|
|
|
170 |
RESOURCE_LIST_T list = findResourceType(type);
|
|
|
171 |
MSG_DEBUG("resource type: " << type);
|
8 |
andreas |
172 |
|
84 |
andreas |
173 |
if (mResourceLists.size() == 0 || list.type.empty())
|
|
|
174 |
{
|
|
|
175 |
list.type = type;
|
|
|
176 |
list.ressource.clear();
|
|
|
177 |
mResourceLists.push_back(list);
|
|
|
178 |
}
|
78 |
andreas |
179 |
|
84 |
andreas |
180 |
RESOURCE_T resource;
|
|
|
181 |
|
|
|
182 |
while ((index = xml.getNextElementIndex("resource", depth)) != TExpat::npos)
|
8 |
andreas |
183 |
{
|
84 |
andreas |
184 |
while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
|
8 |
andreas |
185 |
{
|
84 |
andreas |
186 |
string e = name;
|
8 |
andreas |
187 |
|
84 |
andreas |
188 |
if (e.compare("name") == 0)
|
|
|
189 |
resource.name = content;
|
|
|
190 |
else if (e.compare("protocol") == 0)
|
|
|
191 |
resource.protocol = content;
|
|
|
192 |
else if (e.compare("host") == 0)
|
|
|
193 |
resource.host = content;
|
|
|
194 |
else if (e.compare("file") == 0)
|
|
|
195 |
resource.file = content;
|
|
|
196 |
else if (e.compare("password") == 0)
|
|
|
197 |
{
|
|
|
198 |
resource.password = content;
|
|
|
199 |
int enc = xml.getAttributeInt("encrypted", attrs);
|
|
|
200 |
|
|
|
201 |
if (enc != 0)
|
|
|
202 |
resource.encrypted = true;
|
|
|
203 |
else
|
|
|
204 |
resource.encrypted = false;
|
|
|
205 |
}
|
|
|
206 |
else if (e.compare("user") == 0)
|
|
|
207 |
resource.user = content;
|
|
|
208 |
else if (e.compare("path") == 0)
|
|
|
209 |
resource.path = content;
|
|
|
210 |
else if (e.compare("refresh") == 0)
|
|
|
211 |
resource.refresh = xml.convertElementToInt(content);
|
|
|
212 |
else if (e.compare("dynamo") == 0)
|
|
|
213 |
resource.dynamo = ((xml.convertElementToInt(content) == 0) ? false : true);
|
|
|
214 |
else if (e.compare("preserve") == 0)
|
|
|
215 |
resource.preserve = ((xml.convertElementToInt(content) == 0) ? false : true);
|
|
|
216 |
|
|
|
217 |
oldIndex = index;
|
8 |
andreas |
218 |
}
|
78 |
andreas |
219 |
|
84 |
andreas |
220 |
list.ressource.push_back(resource);
|
|
|
221 |
MSG_DEBUG("Scheme: " << resource.protocol << ", Host: " << resource.host << ", Path: " << resource.path << ", File: " << resource.file << ", Name: " << resource.name);
|
|
|
222 |
resource.clear();
|
|
|
223 |
|
|
|
224 |
if (index == TExpat::npos)
|
|
|
225 |
index = oldIndex + 2;
|
8 |
andreas |
226 |
}
|
|
|
227 |
|
84 |
andreas |
228 |
vector<RESOURCE_LIST_T>::iterator itResList;
|
78 |
andreas |
229 |
|
84 |
andreas |
230 |
for (itResList = mResourceLists.begin(); itResList != mResourceLists.end(); itResList++)
|
21 |
andreas |
231 |
{
|
84 |
andreas |
232 |
if (itResList->type.compare(type) == 0)
|
|
|
233 |
{
|
|
|
234 |
mResourceLists.erase(itResList);
|
|
|
235 |
mResourceLists.push_back(list);
|
|
|
236 |
break;
|
|
|
237 |
}
|
21 |
andreas |
238 |
}
|
|
|
239 |
}
|
84 |
andreas |
240 |
while ((index = xml.getNextElementIndex("resourceList", depth)) != TExpat::npos);
|
8 |
andreas |
241 |
}
|
|
|
242 |
|
77 |
andreas |
243 |
if ((index = xml.getElementIndex("paletteList", &depth)) == TExpat::npos)
|
4 |
andreas |
244 |
{
|
|
|
245 |
MSG_WARNING("There exists no color palette! There will be only the system colors available.");
|
|
|
246 |
return true;
|
|
|
247 |
}
|
|
|
248 |
|
77 |
andreas |
249 |
depth++;
|
4 |
andreas |
250 |
|
78 |
andreas |
251 |
while ((index = xml.getNextElementIndex("palette", depth)) != TExpat::npos)
|
4 |
andreas |
252 |
{
|
|
|
253 |
PALETTE_SETUP ps;
|
|
|
254 |
|
78 |
andreas |
255 |
while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
|
4 |
andreas |
256 |
{
|
78 |
andreas |
257 |
if (name.compare("name") == 0)
|
77 |
andreas |
258 |
ps.name = content;
|
78 |
andreas |
259 |
else if (name.compare("file") == 0)
|
77 |
andreas |
260 |
ps.file = content;
|
78 |
andreas |
261 |
else if (name.compare("paletteID") == 0)
|
77 |
andreas |
262 |
ps.paletteID = xml.convertElementToInt(content);
|
4 |
andreas |
263 |
}
|
|
|
264 |
|
|
|
265 |
mSetup.palettes.push_back(ps);
|
|
|
266 |
}
|
|
|
267 |
|
3 |
andreas |
268 |
return true;
|
2 |
andreas |
269 |
}
|
8 |
andreas |
270 |
|
|
|
271 |
RESOURCE_LIST_T TSettings::findResourceType(const string& type)
|
|
|
272 |
{
|
|
|
273 |
DECL_TRACER ("TSettings::findResourceType(const string& type)");
|
|
|
274 |
|
|
|
275 |
vector<RESOURCE_LIST_T>::iterator iter;
|
|
|
276 |
|
|
|
277 |
for (iter = mResourceLists.begin(); iter != mResourceLists.end(); iter++)
|
|
|
278 |
{
|
|
|
279 |
if (iter->type.compare(type) == 0)
|
|
|
280 |
return *iter;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
return RESOURCE_LIST_T();
|
|
|
284 |
}
|