Subversion Repositories tpanel

Rev

Rev 480 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 480 Rev 486
Line 1... Line 1...
1
/*
1
/*
2
 * Copyright (C) 2024 by Andreas Theofilu <andreas@theosys.at>
2
 * Copyright (C) 2024, 2025 by Andreas Theofilu <andreas@theosys.at>
3
 *
3
 *
4
 * This program is free software; you can redistribute it and/or modify
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
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
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
7
 * (at your option) any later version.
Line 57... Line 57...
57
 
57
 
58
bool TApps::parseApps()
58
bool TApps::parseApps()
59
{
59
{
60
    DECL_TRACER("TApps::parseApps()");
60
    DECL_TRACER("TApps::parseApps()");
61
 
61
 
62
    if (!TTPInit::getTP5())
62
    if (!TTPInit::isTP5())
63
    {
63
    {
64
        MSG_WARNING("Can't read app configs because it's not a TP5 format!");
64
        MSG_WARNING("Can't read app configs because it's not a TP5 format!");
65
        return false;
65
        return false;
66
    }
66
    }
67
 
67
 
Line 81... Line 81...
81
        TError::setError();
81
        TError::setError();
82
        return false;
82
        return false;
83
    }
83
    }
84
 
84
 
85
    TExpat xml(path);
85
    TExpat xml(path);
-
 
86
 
-
 
87
    if (!TTPInit::isTP5())
86
    xml.setEncoding(ENC_UTF8);
88
        xml.setEncoding(ENC_UTF8);
87
 
89
 
88
    if (!xml.parse())
90
    if (!xml.parse())
89
        return false;
91
        return false;
90
 
92
 
91
    int depth = 0;
93
    int depth = 0;
92
    size_t index = 0;
94
    size_t index = 0;
-
 
95
    size_t oldIndex = 0;
93
 
96
 
94
    if ((index = xml.getElementIndex("Apps", &depth)) == TExpat::npos)
97
    if ((index = xml.getElementIndex("Apps", &depth)) == TExpat::npos)
95
    {
98
    {
96
        MSG_DEBUG("File does not contain the element \"Apps\"!");
99
        MSG_WARNING("File does not contain the element \"Apps\"!");
97
        TError::setError();
100
        TError::setError();
98
        return false;
101
        return false;
99
    }
102
    }
100
 
103
 
101
    depth++;
104
    depth++;
Line 137... Line 140...
137
                                    ar.percent = xml.getAttributeDouble("percent", attrs);
140
                                    ar.percent = xml.getAttributeDouble("percent", attrs);
138
                                    ar.ratioWidth = xml.getAttributeInt("ratioWidth", attrs);
141
                                    ar.ratioWidth = xml.getAttributeInt("ratioWidth", attrs);
139
                                    ar.ratioHeight = xml.getAttributeInt("ratioHeight", attrs);
142
                                    ar.ratioHeight = xml.getAttributeInt("ratioHeight", attrs);
140
                                    app.appWindow.aspectRatios.push_back(ar);
143
                                    app.appWindow.aspectRatios.push_back(ar);
141
                                }
144
                                }
-
 
145
 
-
 
146
                                oldIndex = index;
142
                            }
147
                            }
-
 
148
 
-
 
149
                            index = oldIndex + 1;
143
                        }
150
                        }
144
                        else if (s.compare("AspectRatioLimits") == 0)
151
                        else if (s.compare("AspectRatioLimits") == 0)
145
                        {
152
                        {
146
                            app.appWindow.aspectRatioLimits.minWidth = xml.getAttributeInt("minWidth", attrs);
153
                            app.appWindow.aspectRatioLimits.minWidth = xml.getAttributeInt("minWidth", attrs);
147
                            app.appWindow.aspectRatioLimits.minHeight = xml.getAttributeInt("minHeight", attrs);
154
                            app.appWindow.aspectRatioLimits.minHeight = xml.getAttributeInt("minHeight", attrs);
148
                        }
155
                        }
-
 
156
 
-
 
157
                        oldIndex = index;
149
                    }
158
                    }
-
 
159
 
-
 
160
                    index = oldIndex + 1;
150
                }
161
                }
151
                else if (a.compare("Images") == 0)
162
                else if (a.compare("Images") == 0)
152
                {
163
                {
153
                    string i;
164
                    string i;
154
 
165
 
Line 156... Line 167...
156
                    {
167
                    {
157
                        if (i.compare("ThumbImage") == 0)
168
                        if (i.compare("ThumbImage") == 0)
158
                            app.appImages.thumbImage = content;
169
                            app.appImages.thumbImage = content;
159
                        else if (i.compare("WindowImage") == 0)
170
                        else if (i.compare("WindowImage") == 0)
160
                            app.appImages.windowImage = content;
171
                            app.appImages.windowImage = content;
-
 
172
 
-
 
173
                        oldIndex = index;
161
                    }
174
                    }
-
 
175
 
-
 
176
                    index = oldIndex + 1;
162
                }
177
                }
163
                else if (name.compare("Parameters") == 0)
178
                else if (a.compare("Parameters") == 0)
164
                {
179
                {
165
                    string p;
180
                    string p;
166
                    APP_PARAMETER_t par;
181
                    MSG_DEBUG("Section \"" << name << "\" entered");
167
 
182
 
168
                    while ((index = xml.getNextElementFromIndex(index, &p, &content, &attrs)) != TExpat::npos)
183
                    while ((index = xml.getNextElementFromIndex(index, &p, &content, &attrs)) != TExpat::npos)
169
                    {
184
                    {
170
                        if (p.compare("Parameter") == 0)
185
                        if (p.compare("Parameter") == 0)
171
                        {
186
                        {
-
 
187
                            APP_PARAMETER_t par;
-
 
188
 
172
                            par.name = xml.getAttribute("name", attrs);
189
                            par.name = xml.getAttribute("name", attrs);
-
 
190
                            par.fullName = xml.getAttribute("fullName", attrs);
173
                            par.eDataType = xml.getAttribute("eDataType", attrs);
191
                            par.eDataType = xml.getAttribute("eDataType", attrs);
174
                            par.value = xml.getAttribute("value", attrs);
192
                            par.value = xml.getAttribute("value", attrs);
175
                            par.info = xml.getAttribute("info", attrs);
193
                            par.info = xml.getAttribute("info", attrs);
176
                            APP_PAR_STRINGS_t val;
194
                            par.valueRequired = xml.getAttributeBool("valueRequired", attrs);
177
                            string v;
-
 
178
 
195
 
179
                            while ((index = xml.getNextElementFromIndex(index, &v, &content, &attrs)) != TExpat::npos)
196
                            if (!xml.isElementTypeAtomic(index))
180
                            {
197
                            {
181
                                if (v.compare("StringValues") == 0)
-
 
182
                                {
198
                                APP_PAR_STRINGS_t val;
183
                                    string sv;
199
                                string v;
184
 
200
 
185
                                    while ((index = xml.getNextElementFromIndex(index, &sv, &content, &attrs)) != TExpat::npos)
201
                                while ((index = xml.getNextElementFromIndex(index, &v, &content, &attrs)) != TExpat::npos)
-
 
202
                                {
-
 
203
                                    if (v.compare("StringValues") == 0)
186
                                    {
204
                                    {
187
                                        if (sv.compare("StringValue") == 0)
205
                                        string sv;
-
 
206
 
-
 
207
                                        while ((index = xml.getNextElementFromIndex(index, &sv, &content, &attrs)) != TExpat::npos)
188
                                        {
208
                                        {
-
 
209
                                            if (sv.compare("StringValue") == 0)
-
 
210
                                            {
189
                                            val.key = xml.getAttribute("key", attrs);
211
                                                val.key = xml.getAttribute("key", attrs);
190
                                            val.value = content;
212
                                                val.value = content;
191
                                            par.stringValues.push_back(val);
213
                                                par.stringValues.push_back(val);
-
 
214
                                            }
-
 
215
 
-
 
216
                                            oldIndex = index;
192
                                        }
217
                                        }
-
 
218
 
-
 
219
                                        index = oldIndex + 1;
193
                                    }
220
                                    }
-
 
221
 
-
 
222
                                    oldIndex = index;
194
                                }
223
                                }
-
 
224
 
-
 
225
                                index = oldIndex + 1;
195
                            }
226
                            }
-
 
227
 
-
 
228
                            app.parameters.push_back(par);
196
                        }
229
                        }
-
 
230
 
-
 
231
                        oldIndex = index;
197
                    }
232
                    }
198
 
233
 
199
                    app.parameters.push_back(par);
234
                    index = oldIndex + 1;
200
                }
235
                }
-
 
236
 
-
 
237
                oldIndex = index;
201
            }
238
            }
202
 
239
 
203
            mAppSettings.push_back(app);
240
            mAppSettings.push_back(app);
-
 
241
            index = oldIndex + 1;
204
        }
242
        }
-
 
243
    }
-
 
244
 
-
 
245
    if ((index = xml.getElementIndex("WindowFrames", &depth)) == TExpat::npos)
-
 
246
    {
-
 
247
        MSG_WARNING("File does not contain the element \"WindowFrames\"!");
-
 
248
        TError::setError();
-
 
249
        return false;
-
 
250
    }
-
 
251
 
-
 
252
    string w;
-
 
253
    APP_WINDOW_FRAME_t wf;
-
 
254
    depth++;
-
 
255
    oldIndex = 0;
-
 
256
 
-
 
257
    while ((index = xml.getNextElementFromIndex(index, &w, &content, &attrs)) != TExpat::npos)
-
 
258
    {
205
        else if (name.compare("WindowFrames") == 0)
259
        if (w.compare("WindowFrame") == 0)
206
        {
260
        {
207
            string w;
261
            wf.eType = xml.getAttribute("eType", attrs);
-
 
262
            wf.edgeSize = xml.getAttributeInt("edgeSize", attrs);
-
 
263
            wf.barSize = xml.getAttributeInt("barSize", attrs);
208
            APP_WINDOW_FRAME_t wf;
264
            string b;
209
 
265
 
210
            while ((index = xml.getNextElementFromIndex(index, &w, &content, &attrs)) != TExpat::npos)
266
            while ((index = xml.getNextElementFromIndex(index, &b, &content, &attrs)) != TExpat::npos)
211
            {
267
            {
-
 
268
                APP_BUTTON_t button;
-
 
269
 
212
                if (w.compare("WindowFrame") == 0)
270
                if (b.compare("Buttons") == 0)
213
                {
271
                {
214
                    wf.eType = xml.getAttribute("eType", attrs);
-
 
215
                    wf.edgeSize = xml.getAttributeInt("edgeSize", attrs);
-
 
216
                    wf.barSize = xml.getAttributeInt("barSize", attrs);
-
 
217
                    string b;
272
                    string a;
218
 
273
 
219
                    while ((index = xml.getNextElementFromIndex(index, &b, &content, &attrs)) != TExpat::npos)
274
                    while ((index = xml.getNextElementFromIndex(index, &a, &content, &attrs)) != TExpat::npos)
220
                    {
275
                    {
221
                        APP_BUTTON_t button;
-
 
222
 
-
 
223
                        if (b.compare("Buttons") == 0)
276
                        if (a.compare("Button") == 0)
224
                        {
277
                        {
-
 
278
                            button.eLocation = xml.getAttribute("eLocation", attrs);
-
 
279
                            button.order = xml.getAttributeInt("order", attrs);
-
 
280
                            button.spacing = xml.getAttributeInt("spacing", attrs);
225
                            string a;
281
                            string i;
226
 
282
 
227
                            while ((index = xml.getNextElementFromIndex(index, &a, &content, &attrs)) != TExpat::npos)
283
                            while ((index = xml.getNextElementFromIndex(index, &i, &content, &attrs)) != TExpat::npos)
228
                            {
284
                            {
229
                                if (a.compare("Button") == 0)
285
                                if (i.compare("ButtonImage") == 0)
230
                                {
-
 
231
                                    button.eLocation = xml.getAttribute("eLocation", attrs);
286
                                    button.buttonImage.push_back(content);
232
                                    button.order = xml.getAttributeInt("order", attrs);
-
 
233
                                    button.spacing = xml.getAttributeInt("spacing", attrs);
-
 
234
                                    string i;
-
 
235
 
287
 
236
                                    while ((index = xml.getNextElementFromIndex(index, &i, &content, &attrs)) != TExpat::npos)
-
 
237
                                    {
288
                                oldIndex = index;
238
                                        if (i.compare("ButtonImage") == 0)
-
 
239
                                            button.buttonImage.push_back(content);
-
 
240
                                    }
-
 
241
                                }
-
 
242
                            }
289
                            }
243
 
290
 
244
                            wf.buttons.push_back(button);
291
                            index = oldIndex + 1;
245
                        }
292
                        }
-
 
293
 
-
 
294
                        oldIndex = index;
246
                    }
295
                    }
247
 
296
 
248
                    mWindowFrames.push_back(wf);
297
                    wf.buttons.push_back(button);
-
 
298
                    index = oldIndex + 1;
249
                }
299
                }
-
 
300
 
-
 
301
                oldIndex = index;
-
 
302
            }
-
 
303
 
-
 
304
            mWindowFrames.push_back(wf);
-
 
305
            index = oldIndex + 1;
-
 
306
        }
-
 
307
    }
-
 
308
 
-
 
309
    if (TStreamError::checkFilter(HLOG_DEBUG))
-
 
310
    {
-
 
311
        MSG_DEBUG("Supported apps:");
-
 
312
 
-
 
313
        std::vector<APP_SETTINGS_t>::iterator iter;
-
 
314
 
-
 
315
        for (iter = mAppSettings.begin(); iter != mAppSettings.end(); ++iter)
-
 
316
        {
-
 
317
            MSG_DEBUG("     Application:   " << iter->appName);
-
 
318
            MSG_DEBUG("     App ID:        " << iter->appID);
-
 
319
            MSG_DEBUG("     App info:      " << iter->appInfo);
-
 
320
            MSG_DEBUG("     Parameters:    " << iter->parameters.size());
-
 
321
            MSG_DEBUG("     Thumb image:   " << iter->appImages.thumbImage);
-
 
322
            MSG_DEBUG("     Wind. image:   " << iter->appImages.windowImage);
-
 
323
            MSG_DEBUG("     Wind. aspect:  " << (iter->appWindow.aspectFixed ? "TRUE" : "FALSE"));
-
 
324
            MSG_DEBUG("     Aspect ratios: " << iter->appWindow.aspectRatios.size());
-
 
325
            MSG_DEBUG("     Aspect limits: " << iter->appWindow.aspectRatioLimits.minWidth << " x " << iter->appWindow.aspectRatioLimits.minHeight << "\n");
-
 
326
        }
-
 
327
 
-
 
328
        MSG_DEBUG("Defined window frames: ");
-
 
329
 
-
 
330
        std::vector<APP_WINDOW_FRAME_t>::iterator witer;
-
 
331
 
-
 
332
        for (witer = mWindowFrames.begin(); witer != mWindowFrames.end(); ++witer)
-
 
333
        {
-
 
334
            MSG_DEBUG("     Frame type: " << witer->eType);
-
 
335
            std::vector<APP_BUTTON_t>::iterator biter;
-
 
336
 
-
 
337
            for (biter = witer->buttons.begin(); biter != witer->buttons.end(); ++biter)
-
 
338
            {
-
 
339
                MSG_DEBUG("         Button order:    " << biter->order);
-
 
340
                MSG_DEBUG("         Button location: " << biter->eLocation);
250
            }
341
            }
251
        }
342
        }
252
    }
343
    }
253
 
344
 
254
    return true;
345
    return true;