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