Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 andreas 1
/*
21 andreas 2
 * Copyright (C) 2020, 2021 by Andreas Theofilu <andreas@theosys.at>
3 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 <string>
20
#include "tpagelist.h"
21
#include "treadxml.h"
22
#include "tconfig.h"
23
#include "terror.h"
24
 
25
using std::string;
26
using std::vector;
27
 
28
TPageList::TPageList()
29
{
30
    DECL_TRACER("TPageList::TPageList(mxml_node_t *tree)");
31
    mProject = makeFileName(TConfig::getProjectPath(), "prj.xma");
32
    initialize();
33
}
34
 
35
TPageList::~TPageList()
36
{
37
    DECL_TRACER("TPageList::~TPageList()");
38
}
39
 
40
void TPageList::initialize()
41
{
42
    DECL_TRACER("TPageList::initialize()");
43
 
44
    TError::clear();
45
 
11 andreas 46
    if (mPageList.size() > 0)
47
        mPageList.clear();
48
 
49
    if (mSubPageList.size() > 0)
50
        mSubPageList.clear();
51
 
3 andreas 52
    if (mProject.empty() || !isValidFile(mProject))
53
    {
54
        TError::setErrorMsg("Empty or invalid project file! <" + mProject + ">");
55
        MSG_ERROR(TError::getErrorMsg());
56
        return;
57
    }
58
 
59
    TReadXML reader(mProject);
60
 
61
    if (TError::isError())
62
    {
63
        MSG_DEBUG("Stopped scanning the page list due to previous errors!");
64
        return;
65
    }
66
 
67
    string value = reader.findElement("pageList", "type");
68
    string attribute = reader.getAttribute();
69
 
70
    if (attribute.empty())
71
    {
72
        TError::setErrorMsg("Missing element \"pageList\" in file " + mProject);
73
        MSG_ERROR(TError::getErrorMsg());
74
        return;
75
    }
76
    else if (attribute.compare("page") != 0 && attribute.compare("subpage") != 0)
77
    {
78
        TError::setErrorMsg("Invalid page type " + attribute + " found!");
79
        MSG_ERROR(TError::getErrorMsg());
80
        return;
81
    }
82
 
83
    while (!attribute.empty())
84
    {
85
        mxml_node_t *nodeFirst = reader.getFirstChild();
86
        mxml_node_t *n = nodeFirst;
87
 
88
        while (n)
89
        {
90
            mxml_node_t *item = reader.getFirstChild(n);
91
            PAGELIST_T pl;
92
            SUBPAGELIST_T spl;
93
 
94
            pl.clear();
95
            spl.clear();
96
 
97
            while (item)
98
            {
99
                string e = reader.getElementName(item);
100
                MSG_DEBUG("Comparing " << e);
101
 
102
                if (attribute.compare("page") == 0)
103
                {
104
                    if (e.compare("name") == 0)
105
                        pl.name = reader.getTextFromNode(item);
106
                    else if (e.compare("pageID") == 0)
107
                        pl.pageID = reader.getIntFromNode(item);
108
                    else if (e.compare("file") == 0)
109
                        pl.file = reader.getTextFromNode(item);
110
                    else if (e.compare("isValid") == 0)
111
                        pl.isValid = reader.getIntFromNode(item);
112
                }
113
                else if (attribute.compare("subpage") == 0)
114
                {
115
                    if (e.compare("name") == 0)
116
                        spl.name = reader.getTextFromNode(item);
117
                    else if (e.compare("pageID") == 0)
118
                        spl.pageID = reader.getIntFromNode(item);
119
                    else if (e.compare("file") == 0)
120
                        spl.file = reader.getTextFromNode(item);
121
                    else if (e.compare("group") == 0)
122
                        spl.group = reader.getTextFromNode(item);
123
                    else if (e.compare("isValid") == 0)
124
                        spl.isValid = reader.getIntFromNode(item);
125
                    else if (e.compare("popupType") == 0)
126
                        spl.popupType = reader.getIntFromNode(item);
127
                }
128
 
129
                item = reader.getNextChild(item);
130
            }
131
 
132
            if (attribute.compare("page") == 0)
133
                mPageList.push_back(pl);
134
            else if (attribute.compare("subpage") == 0)
135
                mSubPageList.push_back(spl);
136
 
137
            n = reader.getNextChild();
138
        }
139
 
140
        value = reader.findNextElement("pageList", "type");
141
 
142
        if (reader.success())
143
        {
144
            attribute = reader.getAttribute();
145
            MSG_DEBUG("Found attribute " << attribute);
146
        }
147
        else
148
            attribute.clear();
149
    }
150
}
151
 
152
PAGELIST_T TPageList::findPage(const std::string& name)
153
{
154
    DECL_TRACER("TPageList::findPage(const std::string& name)");
155
 
156
    vector<PAGELIST_T>::iterator iter;
157
    PAGELIST_T page;
158
 
159
    for (iter = mPageList.begin(); iter != mPageList.end(); iter++)
160
    {
161
        if (iter->name.compare(name) == 0)
162
        {
163
            page = *iter;
164
            return page;
165
        }
166
    }
167
 
168
    TError::setErrorMsg("Page " + name + " not found!");
169
    TError::setError();
170
    return page;
171
}
172
 
173
PAGELIST_T TPageList::findPage(int pageID)
174
{
175
    DECL_TRACER("TPageList::findPage(int pageID)");
176
 
177
    vector<PAGELIST_T>::iterator iter;
178
    PAGELIST_T page;
179
 
180
    for (iter = mPageList.begin(); iter != mPageList.end(); iter++)
181
    {
182
        if (iter->pageID == pageID)
183
        {
184
            page = *iter;
185
            return page;
186
        }
187
    }
188
 
189
    TError::setErrorMsg("Page " + std::to_string(pageID) + " not found!");
190
    TError::setError();
191
    return page;
192
}
193
 
194
SUBPAGELIST_T TPageList::findSubPage(const std::string& name)
195
{
196
    DECL_TRACER("TPageList::findSubPage(const std::string& name)");
197
 
198
    vector<SUBPAGELIST_T>::iterator iter;
199
    SUBPAGELIST_T page;
200
 
201
    for (iter = mSubPageList.begin(); iter != mSubPageList.end(); iter++)
202
    {
203
        if (iter->name.compare(name) == 0)
204
        {
205
            page = *iter;
206
            return page;
207
        }
208
    }
209
 
210
    TError::setErrorMsg("Subpage " + name + " not found!");
211
    TError::setError();
212
    return page;
213
}
214
 
215
SUBPAGELIST_T TPageList::findSubPage(int pageID)
216
{
217
    DECL_TRACER("TPageList::findSubPage(int pageID)");
218
 
219
    vector<SUBPAGELIST_T>::iterator iter;
220
    SUBPAGELIST_T page;
221
 
222
    for (iter = mSubPageList.begin(); iter != mSubPageList.end(); iter++)
223
    {
224
        if (iter->pageID == pageID)
225
        {
226
            page = *iter;
227
            return page;
228
        }
229
    }
230
 
231
    TError::setErrorMsg("Subpage " + std::to_string(pageID) + " not found!");
232
    TError::setError();
233
    return page;
234
}