Diffstat (limited to 'core/pim/datebook/holiday/national/nationalcfg.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.cpp | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp index a293251..52c453f 100644 --- a/core/pim/datebook/holiday/national/nationalcfg.cpp +++ b/core/pim/datebook/holiday/national/nationalcfg.cpp | |||
@@ -1,149 +1,142 @@ | |||
1 | #include "nationalcfg.h" | 1 | #include "nationalcfg.h" |
2 | 2 | ||
3 | #include <opie2/odebug.h> | 3 | #include <opie2/odebug.h> |
4 | 4 | ||
5 | #include <qfile.h> | 5 | #include <qfile.h> |
6 | 6 | ||
7 | static QString _key_desc="description"; | 7 | static QString _key_desc="description"; |
8 | static QString _key_doc="nationaldays"; | 8 | static QString _key_doc="nationaldays"; |
9 | static QString _key_list="entries"; | 9 | static QString _key_list="entries"; |
10 | static QString _key_entry="entry"; | 10 | static QString _key_entry="entry"; |
11 | static QString _content_name="name"; | 11 | static QString _content_name="name"; |
12 | static QString _content_date="date"; | 12 | static QString _content_date="date"; |
13 | 13 | ||
14 | NHcfg::NHcfg() | 14 | NHcfg::NHcfg() |
15 | :QXmlDefaultHandler(),err(""),_path("") | 15 | :QXmlDefaultHandler(),err(""),_path("") |
16 | { | 16 | { |
17 | } | 17 | } |
18 | 18 | ||
19 | NHcfg::~NHcfg() | 19 | NHcfg::~NHcfg() |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
23 | bool NHcfg::load(const QString&aPath) | 23 | bool NHcfg::load(const QString&aPath) |
24 | { | 24 | { |
25 | _path=aPath; | 25 | _path=aPath; |
26 | stage = 0; | 26 | stage = 0; |
27 | _content.clear(); | 27 | _content.clear(); |
28 | odebug << "Start loading file "<<_path<<oendl; | ||
29 | QFile *f=new QFile(_path); | 28 | QFile *f=new QFile(_path); |
30 | if (!f) { | 29 | if (!f) { |
31 | oerr << "Could not open file" << oendl; | 30 | oerr << "Could not open file" << oendl; |
32 | return false; | 31 | return false; |
33 | } | 32 | } |
34 | odebug << "Source" << oendl; | ||
35 | QXmlInputSource is(*f); | 33 | QXmlInputSource is(*f); |
36 | odebug << "Reader" << oendl; | ||
37 | QXmlSimpleReader reader; | 34 | QXmlSimpleReader reader; |
38 | odebug << "Handler" << oendl; | ||
39 | reader.setContentHandler(this); | 35 | reader.setContentHandler(this); |
40 | odebug << "Error handler" << oendl; | ||
41 | reader.setErrorHandler(this); | 36 | reader.setErrorHandler(this); |
42 | 37 | ||
43 | err = ""; | 38 | err = ""; |
44 | odebug << "parse it" << oendl; | ||
45 | bool ret = reader.parse(is); | 39 | bool ret = reader.parse(is); |
46 | odebug << "Errors: " << err << oendl; | 40 | if (err.length()>0) |
41 | odebug << "Errors: " << err << oendl; | ||
47 | return ret; | 42 | return ret; |
48 | } | 43 | } |
49 | 44 | ||
50 | const tholidaylist&NHcfg::days()const | 45 | const tholidaylist&NHcfg::days()const |
51 | { | 46 | { |
52 | return _content; | 47 | return _content; |
53 | } | 48 | } |
54 | 49 | ||
55 | bool NHcfg::warning(const QXmlParseException& e) | 50 | bool NHcfg::warning(const QXmlParseException& e) |
56 | { | 51 | { |
57 | QString tmp; | 52 | QString tmp; |
58 | 53 | ||
59 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | 54 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), |
60 | (const char*) e.message().utf8()); | 55 | (const char*) e.message().utf8()); |
61 | 56 | ||
62 | err += tmp; | 57 | err += tmp; |
63 | 58 | ||
64 | return true; | 59 | return true; |
65 | } | 60 | } |
66 | 61 | ||
67 | bool NHcfg::error(const QXmlParseException& e) | 62 | bool NHcfg::error(const QXmlParseException& e) |
68 | { | 63 | { |
69 | QString tmp; | 64 | QString tmp; |
70 | 65 | ||
71 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), | 66 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), |
72 | (const char*) e.message().utf8()); | 67 | (const char*) e.message().utf8()); |
73 | 68 | ||
74 | err += tmp; | 69 | err += tmp; |
75 | 70 | ||
76 | return true; | 71 | return true; |
77 | } | 72 | } |
78 | 73 | ||
79 | bool NHcfg::fatalError(const QXmlParseException& e) | 74 | bool NHcfg::fatalError(const QXmlParseException& e) |
80 | { | 75 | { |
81 | QString tmp; | 76 | QString tmp; |
82 | 77 | ||
83 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), | 78 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), |
84 | (const char*) e.message().utf8()); | 79 | (const char*) e.message().utf8()); |
85 | 80 | ||
86 | err += tmp; | 81 | err += tmp; |
87 | 82 | ||
88 | return false; | 83 | return false; |
89 | } | 84 | } |
90 | 85 | ||
91 | bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr) | 86 | bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr) |
92 | { | 87 | { |
93 | bool ret = false; | 88 | bool ret = false; |
94 | odebug << "startElement: " << name << oendl; | ||
95 | if (name==_key_doc) { | 89 | if (name==_key_doc) { |
96 | stage = 1; | 90 | stage = 1; |
97 | return true; | 91 | return true; |
98 | } | 92 | } |
99 | if (stage == 0) { | 93 | if (stage == 0) { |
100 | err = "This is not a national holiday config file"; | 94 | err = "This is not a national holiday config file"; |
101 | return false; | 95 | return false; |
102 | } | 96 | } |
103 | if (name==_key_desc) { | 97 | if (name==_key_desc) { |
104 | stage = 2; | 98 | stage = 2; |
105 | ret = setName(attr); | 99 | ret = setName(attr); |
106 | return ret; | 100 | return ret; |
107 | } | 101 | } |
108 | if (stage<2) {return false;} | 102 | if (stage<2) {return false;} |
109 | if (name==_key_list) {stage=3;return true;} | 103 | if (name==_key_list) {stage=3;return true;} |
110 | if (stage<3) {return false;} | 104 | if (stage<3) {return false;} |
111 | return parsevalue(name,attr); | 105 | return parsevalue(name,attr); |
112 | } | 106 | } |
113 | 107 | ||
114 | bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) | 108 | bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) |
115 | { | 109 | { |
116 | int nindex = attr.index(_content_name); | 110 | int nindex = attr.index(_content_name); |
117 | int dindex = attr.index(_content_date); | 111 | int dindex = attr.index(_content_date); |
118 | if (name != _key_entry) {err = "Not a valid entry"; return false;} | 112 | if (name != _key_entry) {err = "Not a valid entry"; return false;} |
119 | if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;} | 113 | if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;} |
120 | QString txt = attr.value(nindex); | 114 | QString txt = attr.value(nindex); |
121 | QString dstring = attr.value(dindex); | 115 | QString dstring = attr.value(dindex); |
122 | QStringList e = QStringList::split("-",dstring); | 116 | QStringList e = QStringList::split("-",dstring); |
123 | if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} | 117 | if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} |
124 | QDate d(0,e[0].toInt(),e[1].toInt()); | 118 | QDate d(0,e[0].toInt(),e[1].toInt()); |
125 | odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; | 119 | odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; |
126 | _content[d].append(txt); | 120 | _content[d].append(txt); |
127 | return true; | 121 | return true; |
128 | } | 122 | } |
129 | 123 | ||
130 | bool NHcfg::endElement(const QString&, const QString&,const QString& name) | 124 | bool NHcfg::endElement(const QString&, const QString&,const QString& name) |
131 | { | 125 | { |
132 | return true; | 126 | return true; |
133 | } | 127 | } |
134 | 128 | ||
135 | const QString&NHcfg::errorString()const | 129 | const QString&NHcfg::errorString()const |
136 | { | 130 | { |
137 | return err; | 131 | return err; |
138 | } | 132 | } |
139 | 133 | ||
140 | bool NHcfg::setName(const QXmlAttributes&attr) | 134 | bool NHcfg::setName(const QXmlAttributes&attr) |
141 | { | 135 | { |
142 | int nindx = attr.index("value"); | 136 | int nindx = attr.index("value"); |
143 | if (nindx==-1) { | 137 | if (nindx==-1) { |
144 | return false; | 138 | return false; |
145 | } | 139 | } |
146 | _contentname = attr.value(nindx); | 140 | _contentname = attr.value(nindx); |
147 | odebug << "Contentname = " << _contentname<<oendl; | ||
148 | return true; | 141 | return true; |
149 | } | 142 | } |