Subversion Repositories tpanel

Rev

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

Rev 21 Rev 75
Line 16... Line 16...
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
17
 */
18
 
18
 
19
#include "ticons.h"
19
#include "ticons.h"
20
#include "terror.h"
20
#include "terror.h"
21
#include "treadxml.h"
21
#include "texpat++.h"
22
#include "tconfig.h"
22
#include "tconfig.h"
23
 
23
 
24
using std::string;
24
using std::string;
-
 
25
using std::vector;
25
using std::map;
26
using std::map;
26
using std::pair;
27
using std::pair;
-
 
28
using namespace Expat;
27
 
29
 
28
TIcons::TIcons()
30
TIcons::TIcons()
29
{
31
{
30
    DECL_TRACER("TIcons::TIcons()");
32
    DECL_TRACER("TIcons::TIcons()");
31
 
33
 
Line 51... Line 53...
51
        MSG_ERROR("File " << path << " doesn't exist or is not readable!");
53
        MSG_ERROR("File " << path << " doesn't exist or is not readable!");
52
        TError::setError();
54
        TError::setError();
53
        return;
55
        return;
54
    }
56
    }
55
 
57
 
56
    TReadXML reader(path);
58
    TExpat xml(path);
-
 
59
    xml.setEncoding(ENC_CP1250);
57
 
60
 
58
    if (TError::isError())
61
    if (!xml.parse())
59
    {
-
 
60
        MSG_ERROR("Stopped scanning file " << path << " because of previous errors!");
-
 
61
        return;
62
        return;
62
    }
-
 
63
 
63
 
-
 
64
    int depth = 0;
64
    reader.findElement("iconList");
65
    size_t index = 0;
65
 
66
 
66
    if (!reader.success())
67
    if ((index = xml.getElementIndex("iconList", &depth)) == TExpat::npos)
67
    {
68
    {
68
        MSG_DEBUG("File does not contain the element \"iconList\"!");
69
        MSG_DEBUG("File does not contain the element \"iconList\"!");
69
        TError::setError();
70
        TError::setError();
70
        return;
71
        return;
71
    }
72
    }
72
 
73
 
-
 
74
    depth++;
-
 
75
    string name, content;
73
    mxml_node_t *node = reader.getFirstChild();
76
    vector<ATTRIBUTE_t> attrs;
74
 
77
 
75
    while (node)
78
    while ((index = xml.getNextElementFromIndex(index, &name, &content, &attrs)) != TExpat::npos)
76
    {
79
    {
77
        string ename = reader.getElementName(node);
-
 
78
 
-
 
79
        if (ename.compare("maxIcons") == 0)
80
        if (name.compare("maxIcons") == 0)
80
            mEntries = reader.getIntFromNode(node);
81
            mEntries = xml.convertElementToInt(content);
81
        else if (ename.compare("icon") == 0)
82
        else if (name.compare("icon") == 0)
82
        {
83
        {
83
            int number = atoi(reader.getAttributeFromNode(node, "number").c_str());
84
            int number = xml.getAttributeInt("number", attrs);
84
            mxml_node_t *n = reader.getFirstChild(node);
85
            index = xml.getNextElementFromIndex(index, &name, &content, nullptr);
85
 
86
 
86
            if (n)
87
            if (index != TExpat::npos)
87
            {
88
            {
88
                string e = reader.getElementName(n);
-
 
89
 
-
 
90
                if (e.compare("file") == 0)
89
                if (name.compare("file") == 0)
91
                {
90
                {
92
                    string file = reader.getTextFromNode(n);
91
                    string file = content;
93
 
92
 
94
                    if (number > 0 && !file.empty())
93
                    if (number > 0 && !file.empty())
95
                        mIcons.insert(pair<int, string>(number, file));
94
                        mIcons.insert(pair<int, string>(number, file));
96
                }
95
                }
97
            }
96
            }
98
        }
-
 
99
 
97
 
100
        node = reader.getNextChild();
98
            index++;
-
 
99
        }
101
    }
100
    }
102
}
101
}
103
 
102
 
104
string TIcons::getFile(int number)
103
string TIcons::getFile(int number)
105
{
104
{