Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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"
21
#include "treadxml.h"
22
 
23
using std::string;
8 andreas 24
using std::vector;
2 andreas 25
 
26
TSettings::TSettings(const string& path)
27
    : mPath(path)
28
{
3 andreas 29
    DECL_TRACER("TSettings::TSettings(const string& path)");
11 andreas 30
    loadSettings(true);
2 andreas 31
}
32
 
11 andreas 33
bool TSettings::loadSettings(bool initial)
2 andreas 34
{
3 andreas 35
    DECL_TRACER("TSettings::loadSettings()");
2 andreas 36
 
11 andreas 37
    if (!initial)
38
    {
39
        mResourceLists.clear();
40
    }
41
 
3 andreas 42
    TError::clear();
43
    string fname = makeFileName(mPath, "prj.xma");
2 andreas 44
 
3 andreas 45
    if (!isValidFile())
46
    {
47
        MSG_ERROR("Error: File " << fname << " doesn't exist or can't be opened!");
48
        TError::setError();
49
        return false;
50
    }
2 andreas 51
 
3 andreas 52
    TReadXML txml(fname);
2 andreas 53
 
3 andreas 54
    if (TError::isError())
55
        return false;
2 andreas 56
 
3 andreas 57
    string value;
58
    mSetup.portCount = atoi(txml.findElement("portCount").c_str());
59
    mSetup.setupPort = atoi(txml.findElement("setupPort").c_str());
60
    mSetup.addressCount = atoi(txml.findElement("addressCount").c_str());
61
    mSetup.channelCount = atoi(txml.findElement("channelCount").c_str());
62
    mSetup.levelCount = atoi(txml.findElement("levelCount").c_str());
63
    mSetup.powerUpPage = txml.findElement("powerUpPage");
2 andreas 64
 
3 andreas 65
    value = txml.findElement("powerUpPopup");
2 andreas 66
 
5 andreas 67
    if (!value.empty())
7 andreas 68
    {
3 andreas 69
        mSetup.powerUpPopup.push_back(value);
8 andreas 70
 
71
        do
72
        {
73
            value = txml.findNextElement("powerUpPopup");
74
 
75
            if (txml.success())
76
                mSetup.powerUpPopup.push_back(value);
77
        }
78
        while (txml.success());
7 andreas 79
    }
2 andreas 80
 
3 andreas 81
    mSetup.feedbackBlinkRate = atoi(txml.findElement("feedbackBlinkRate").c_str());
82
    mSetup.startupString = txml.findElement("startupString");
83
    mSetup.wakeupString = txml.findElement("wakeupString");
84
    mSetup.sleepString = txml.findElement("sleepString");
85
    mSetup.standbyString = txml.findElement("standbyString");
86
    mSetup.shutdownString = txml.findElement("shutdownString");
87
    mSetup.idlePage = txml.findElement("idlePage");
88
    mSetup.idleTimeout = atoi(txml.findElement("idleTimeout").c_str());
89
    mSetup.extButtonsKey = atoi(txml.findElement("extButtonsKey").c_str());
90
    mSetup.screenWidth = atoi(txml.findElement("screenWidth").c_str());
91
    mSetup.screenHeight = atoi(txml.findElement("screenHeight").c_str());
92
    mSetup.screenRefresh = atoi(txml.findElement("screenRefresh").c_str());
93
    mSetup.screenRotate = atoi(txml.findElement("screenRotate").c_str());
94
    mSetup.screenDescription = txml.findElement("screenDescription");
95
    mSetup.pageTracking = atoi(txml.findElement("pageTracking").c_str());
96
    mSetup.cursor = atoi(txml.findElement("cursor").c_str());
97
    mSetup.brightness = atoi(txml.findElement("brightness").c_str());
98
    mSetup.lightSensorLevelPort = atoi(txml.findElement("lightSensorLevelPort").c_str());
99
    mSetup.lightSensorLevelCode = atoi(txml.findElement("lightSensorLevelCode").c_str());
100
    mSetup.lightSensorChannelPort = atoi(txml.findElement("lightSensorChannelPort").c_str());
101
    mSetup.lightSensorChannelCode = atoi(txml.findElement("lightSensorChannelCode").c_str());
102
    mSetup.motionSensorChannelPort = atoi(txml.findElement("motionSensorChannelPort").c_str());
103
    mSetup.motionSensorChannelCode = atoi(txml.findElement("motionSensorChannelCode").c_str());
104
    mSetup.batteryLevelPort = atoi(txml.findElement("batteryLevelPort").c_str());
105
    mSetup.batteryLevelCode = atoi(txml.findElement("batteryLevelCode").c_str());
106
    mSetup.irPortAMX38Emit = atoi(txml.findElement("irPortAMX38Emit").c_str());
107
    mSetup.irPortAMX455Emit = atoi(txml.findElement("irPortAMX455Emit").c_str());
108
    mSetup.irPortAMX38Recv = atoi(txml.findElement("irPortAMX38Recv").c_str());
109
    mSetup.irPortAMX455Recv = atoi(txml.findElement("irPortAMX455Recv").c_str());
110
    mSetup.irPortUser1 = atoi(txml.findElement("irPortUser1").c_str());
111
    mSetup.irPortUser2 = atoi(txml.findElement("irPortUser2").c_str());
112
    mSetup.cradleChannelPort = atoi(txml.findElement("cradleChannelPort").c_str());
113
    mSetup.cradleChannelCode = atoi(txml.findElement("cradleChannelCode").c_str());
114
    mSetup.uniqueID = atoi(txml.findElement("uniqueID").c_str());
115
    mSetup.appCreated = txml.findElement("appCreated");
116
    mSetup.buildNumber = atoi(txml.findElement("buildNumber").c_str());
117
    mSetup.appModified = txml.findElement("appModified");
118
    mSetup.buildNumberMod = atoi(txml.findElement("buildNumberMod").c_str());
119
    mSetup.buildStatusMod = txml.findElement("buildStatusMod");
120
    mSetup.activePalette = atoi(txml.findElement("activePalette").c_str());
121
    mSetup.marqueeSpeed = atoi(txml.findElement("marqueeSpeed").c_str());
122
    mSetup.setupPagesProject = atoi(txml.findElement("setupPagesProject").c_str());
123
    mSetup.voipCommandPort = atoi(txml.findElement("voipCommandPort").c_str());
4 andreas 124
 
8 andreas 125
    txml.findElement("resourceList");
126
 
127
    while (txml.success())
128
    {
129
        string type = txml.getAttribute("type");
130
        RESOURCE_LIST_T list = findResourceType(type);
131
 
132
        if (mResourceLists.size() == 0 || list.type.empty())
133
        {
134
            list.type = type;
135
            list.ressource.clear();
136
            mResourceLists.push_back(list);
137
        }
138
 
139
        mxml_node_t *node = txml.getFirstChild();
140
        RESOURCE_T resource;
141
 
142
        while (node)
143
        {
144
            mxml_node_t *n = txml.getFirstChild(node);
145
 
146
            while (n)
147
            {
148
                string e = txml.getElementName(n);
149
 
150
                if (e.compare("name") == 0)
151
                    resource.name = txml.getTextFromNode(n);
152
                else if (e.compare("protocol") == 0)
153
                    resource.protocol = txml.getTextFromNode(n);
154
                else if (e.compare("host") == 0)
155
                    resource.host = txml.getTextFromNode(n);
156
                else if (e.compare("file") == 0)
157
                    resource.file = txml.getTextFromNode(n);
158
                else if (e.compare("password") == 0)
159
                {
160
                    resource.password = txml.getTextFromNode(n);
161
                    int enc = atoi(txml.getAttributeFromNode(n, "encrypted").c_str());
162
 
163
                    if (enc != 0)
164
                        resource.encrypted = true;
165
                    else
166
                        resource.encrypted = false;
167
                }
168
                else if (e.compare("user") == 0)
169
                    resource.user = txml.getTextFromNode(n);
170
                else if (e.compare("path") == 0)
171
                    resource.path = txml.getTextFromNode(n);
172
                else if (e.compare("refresh") == 0)
173
                    resource.refresh = txml.getIntFromNode(n);
21 andreas 174
                else if (e.compare("dynamo") == 0)
175
                    resource.dynamo = ((txml.getIntFromNode(n) == 0) ? false : true);
176
                else if (e.compare("preserve") == 0)
177
                    resource.preserve = ((txml.getIntFromNode(n) == 0) ? false : true);
8 andreas 178
 
179
                n = txml.getNextChild(n);
180
            }
181
 
182
            list.ressource.push_back(resource);
183
            node = txml.getNextChild();
184
        }
185
 
21 andreas 186
        vector<RESOURCE_LIST_T>::iterator itResList;
187
 
188
        for (itResList = mResourceLists.begin(); itResList != mResourceLists.end(); itResList++)
189
        {
190
            if (itResList->type.compare(type) == 0)
191
            {
192
                mResourceLists.erase(itResList);
193
                mResourceLists.push_back(list);
194
                break;
195
            }
196
        }
197
 
8 andreas 198
        txml.findNextElement("resourceList");
199
    }
200
 
4 andreas 201
    txml.findElement("paletteList");
202
 
203
    if (!txml.success())
204
    {
205
        MSG_WARNING("There exists no color palette! There will be only the system colors available.");
206
        return true;
207
    }
208
 
209
    mxml_node_t *node = txml.getFirstChild();
210
 
211
    while (node)
212
    {
213
        PALETTE_SETUP ps;
214
        mxml_node_t *n = txml.getFirstChild(node);
215
 
216
        while (n)
217
        {
218
            string e = txml.getElementName(n);
219
 
220
            if (e.compare("name") == 0)
221
                ps.name = txml.getTextFromNode(n);
222
            else if (e.compare("file") == 0)
223
                ps.file = txml.getTextFromNode(n);
224
            else if (e.compare("paletteID") == 0)
225
                ps.paletteID = txml.getIntFromNode(n);
226
 
227
            n = txml.getNextChild(n);
228
        }
229
 
230
        mSetup.palettes.push_back(ps);
231
        node = txml.getNextChild();
232
    }
233
 
3 andreas 234
    return true;
2 andreas 235
}
8 andreas 236
 
237
RESOURCE_LIST_T TSettings::findResourceType(const string& type)
238
{
239
    DECL_TRACER ("TSettings::findResourceType(const string& type)");
240
 
241
    vector<RESOURCE_LIST_T>::iterator iter;
242
 
243
    for (iter = mResourceLists.begin(); iter != mResourceLists.end(); iter++)
244
    {
245
        if (iter->type.compare(type) == 0)
246
            return *iter;
247
    }
248
 
249
    return RESOURCE_LIST_T();
250
}