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 | 261 |
1 files changed, 245 insertions, 16 deletions
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp index 52c453f..f71c833 100644 --- a/core/pim/datebook/holiday/national/nationalcfg.cpp +++ b/core/pim/datebook/holiday/national/nationalcfg.cpp | |||
@@ -9,6 +9,19 @@ 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 _key_calc="calculation"; | ||
12 | |||
13 | static QString _content_type="type"; | ||
14 | static QString _content_float="floating"; | ||
15 | static QString _content_fix="fix"; | ||
16 | |||
11 | static QString _content_name="name"; | 17 | static QString _content_name="name"; |
18 | static QString _content_value="value"; | ||
19 | |||
12 | static QString _content_date="date"; | 20 | static QString _content_date="date"; |
21 | static QString _content_weekd="weekday"; | ||
22 | static QString _content_offset="offset"; | ||
23 | static QString _content_dayofmonth="dayofmonth"; | ||
24 | static QString _content_datedep="datedep"; | ||
25 | static QString _content_month="month"; | ||
13 | 26 | ||
14 | NHcfg::NHcfg() | 27 | NHcfg::NHcfg() |
@@ -25,5 +38,4 @@ bool NHcfg::load(const QString&aPath) | |||
25 | _path=aPath; | 38 | _path=aPath; |
26 | stage = 0; | 39 | stage = 0; |
27 | _content.clear(); | ||
28 | QFile *f=new QFile(_path); | 40 | QFile *f=new QFile(_path); |
29 | if (!f) { | 41 | if (!f) { |
@@ -36,4 +48,9 @@ bool NHcfg::load(const QString&aPath) | |||
36 | reader.setErrorHandler(this); | 48 | reader.setErrorHandler(this); |
37 | 49 | ||
50 | currentFixList.clear(); | ||
51 | currentFloatList.clear(); | ||
52 | counter = 0; | ||
53 | level = 0; | ||
54 | |||
38 | err = ""; | 55 | err = ""; |
39 | bool ret = reader.parse(is); | 56 | bool ret = reader.parse(is); |
@@ -43,7 +60,12 @@ bool NHcfg::load(const QString&aPath) | |||
43 | } | 60 | } |
44 | 61 | ||
45 | const tholidaylist&NHcfg::days()const | 62 | const tentrylist&NHcfg::fixDates()const |
63 | { | ||
64 | return currentFixList; | ||
65 | } | ||
66 | |||
67 | const tentrylist&NHcfg::floatingDates()const | ||
46 | { | 68 | { |
47 | return _content; | 69 | return currentFloatList; |
48 | } | 70 | } |
49 | 71 | ||
@@ -102,21 +124,134 @@ bool NHcfg::startElement(const QString&, const QString&,const QString& name, con | |||
102 | if (stage<2) {return false;} | 124 | if (stage<2) {return false;} |
103 | if (name==_key_list) {stage=3;return true;} | 125 | if (name==_key_list) {stage=3;return true;} |
126 | |||
104 | if (stage<3) {return false;} | 127 | if (stage<3) {return false;} |
105 | return parsevalue(name,attr); | 128 | |
129 | if (name==_key_entry) { | ||
130 | ++level; | ||
131 | ++counter; | ||
132 | m_currentEntry = NHentry(); | ||
133 | // odebug << "Level == " << level << oendl; | ||
134 | } | ||
135 | if (name==_key_calc) { | ||
136 | ++level; | ||
137 | // odebug << "Level == " << level << oendl; | ||
138 | return true; | ||
139 | } | ||
140 | if (level == 1) { | ||
141 | return parsevalue(name,attr); | ||
142 | } else if (level >= 2) { | ||
143 | return parseCalc(name,attr); | ||
144 | } | ||
145 | } | ||
146 | |||
147 | bool NHcfg::setName(const QXmlAttributes&attr) | ||
148 | { | ||
149 | int nindx = attr.index("value"); | ||
150 | if (nindx==-1) { | ||
151 | return false; | ||
152 | } | ||
153 | _contentname = attr.value(nindx); | ||
154 | return true; | ||
106 | } | 155 | } |
107 | 156 | ||
108 | bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) | 157 | bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) |
109 | { | 158 | { |
159 | if (name != _key_entry && name != _key_calc) {err = QString("Not a valid entry (%1)").arg(name); return false;} | ||
160 | |||
110 | int nindex = attr.index(_content_name); | 161 | int nindex = attr.index(_content_name); |
111 | int dindex = attr.index(_content_date); | 162 | int dindex = attr.index(_content_date); |
112 | if (name != _key_entry) {err = "Not a valid entry"; return false;} | 163 | int tindex = attr.index(_content_type); |
113 | if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;} | 164 | |
165 | if (nindex == -1) { | ||
166 | err = QString("Listentry %1 is invalid (name missing)").arg(counter); | ||
167 | return false; | ||
168 | } | ||
169 | m_currentEntry.setName(attr.value(nindex)); | ||
170 | |||
171 | if (tindex != -1 && attr.value(tindex)==_content_float) { | ||
172 | m_currentEntry.setType(NHentry::floating); | ||
173 | return true; | ||
174 | } | ||
175 | |||
176 | if (dindex == -1) { | ||
177 | err = QString("Listentry %1 is invalid ").arg(counter);return false; | ||
178 | } | ||
179 | |||
114 | QString txt = attr.value(nindex); | 180 | QString txt = attr.value(nindex); |
115 | QString dstring = attr.value(dindex); | 181 | QString dstring = attr.value(dindex); |
116 | QStringList e = QStringList::split("-",dstring); | 182 | QStringList e = QStringList::split("-",dstring); |
117 | if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} | 183 | if (e.count()!=2){err=QString("Datestring %1 is invalid (entry %2)").arg(dstring).arg(counter);return false;} |
118 | QDate d(0,e[0].toInt(),e[1].toInt()); | 184 | QDate d(0,e[0].toInt(),e[1].toInt()); |
119 | odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; | 185 | m_currentEntry.setDate(d); |
120 | _content[d].append(txt); | 186 | return true; |
187 | } | ||
188 | |||
189 | bool NHcfg::parseCalc(const QString&name,const QXmlAttributes&attr) | ||
190 | { | ||
191 | ++level; | ||
192 | int vindex = attr.index(_content_value); | ||
193 | if (vindex == -1) { | ||
194 | err = QString("Value for element %1 on entry %2 is missing").arg(name).arg(counter); | ||
195 | return false; | ||
196 | } | ||
197 | int what_c =0; | ||
198 | QString what = name.lower(); | ||
199 | QString value; | ||
200 | if (what == _content_date) { | ||
201 | what_c = 1; | ||
202 | } else if (what == _content_weekd) { | ||
203 | what_c = 2; | ||
204 | } else if (what == _content_offset) { | ||
205 | what_c = 3; | ||
206 | } else if (what == _content_dayofmonth) { | ||
207 | what_c = 4; | ||
208 | } else if (what == _content_datedep) { | ||
209 | what_c = 5; | ||
210 | } else if (what == _content_month) { | ||
211 | what_c = 6; | ||
212 | } | ||
213 | if (what_c == 0) { | ||
214 | err = QString("Unknown element %1 on entry %2").arg(name).arg(counter); | ||
215 | return false; | ||
216 | } | ||
217 | value = attr.value(vindex).lower(); | ||
218 | QStringList e; | ||
219 | QDate d; | ||
220 | bool dotformat = false; | ||
221 | switch (what_c) { | ||
222 | case 1: | ||
223 | if (value != "easter") { | ||
224 | e = QStringList::split("-",value); | ||
225 | if (e.count()!=2) { | ||
226 | e = QStringList::split(".",value); | ||
227 | dotformat = true; | ||
228 | } | ||
229 | if (e.count()!=2){err=QString("Datestring %1 is invalid (entry %2)").arg(value).arg(counter);return false;} | ||
230 | if (!dotformat) { | ||
231 | d=QDate(0,e[0].toInt(),e[1].toInt()); | ||
232 | } else { | ||
233 | d=QDate(0,e[1].toInt(),e[0].toInt()); | ||
234 | } | ||
235 | } else { | ||
236 | d=QDate(9999,1,1); | ||
237 | } | ||
238 | m_currentEntry.setDate(d); | ||
239 | break; | ||
240 | case 2: | ||
241 | m_currentEntry.setWeekday(value); | ||
242 | break; | ||
243 | case 3: | ||
244 | m_currentEntry.setOffet(value.toInt()); | ||
245 | break; | ||
246 | case 4: | ||
247 | m_currentEntry.setDayofmonth(value); | ||
248 | break; | ||
249 | case 5: | ||
250 | m_currentEntry.setDaydep(value); | ||
251 | break; | ||
252 | case 6: | ||
253 | m_currentEntry.setMonth(value); | ||
254 | break; | ||
255 | } | ||
121 | return true; | 256 | return true; |
122 | } | 257 | } |
@@ -124,4 +259,19 @@ bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) | |||
124 | bool NHcfg::endElement(const QString&, const QString&,const QString& name) | 259 | bool NHcfg::endElement(const QString&, const QString&,const QString& name) |
125 | { | 260 | { |
261 | // odebug << "End element: " << name << oendl; | ||
262 | if (name==_key_entry) { | ||
263 | if (m_currentEntry.type()==NHentry::fix) { | ||
264 | currentFixList.append(m_currentEntry); | ||
265 | } else { | ||
266 | currentFloatList.append(m_currentEntry); | ||
267 | // odebug << "Floatlist count " << currentFloatList.count() << oendl; | ||
268 | } | ||
269 | } else if (name==_key_calc) { | ||
270 | |||
271 | } | ||
272 | if (stage>=3) { | ||
273 | --level; | ||
274 | } | ||
275 | // odebug << "Level == " << level << oendl; | ||
126 | return true; | 276 | return true; |
127 | } | 277 | } |
@@ -132,11 +282,90 @@ const QString&NHcfg::errorString()const | |||
132 | } | 282 | } |
133 | 283 | ||
134 | bool NHcfg::setName(const QXmlAttributes&attr) | 284 | NHentry::NHentry() |
285 | :m_Type(fix) | ||
135 | { | 286 | { |
136 | int nindx = attr.index("value"); | 287 | m_Offset=0; |
137 | if (nindx==-1) { | 288 | } |
138 | return false; | 289 | |
139 | } | 290 | NHentry::~NHentry() |
140 | _contentname = attr.value(nindx); | 291 | {} |
141 | return true; | 292 | |
293 | void NHentry::setName(const QString&aName) | ||
294 | { | ||
295 | m_Name = aName; | ||
296 | } | ||
297 | |||
298 | const QString&NHentry::name()const | ||
299 | { | ||
300 | return m_Name; | ||
301 | } | ||
302 | |||
303 | void NHentry::setType(NHentry::entry_type aType) | ||
304 | { | ||
305 | m_Type = aType; | ||
306 | } | ||
307 | |||
308 | NHentry::entry_type NHentry::type()const | ||
309 | { | ||
310 | return m_Type; | ||
311 | } | ||
312 | |||
313 | void NHentry::setDate(const QDate&aDate) | ||
314 | { | ||
315 | m_Date = aDate; | ||
316 | } | ||
317 | |||
318 | const QDate&NHentry::date()const | ||
319 | { | ||
320 | return m_Date; | ||
321 | } | ||
322 | |||
323 | void NHentry::setWeekday(const QString&aDay) | ||
324 | { | ||
325 | m_Weekday = aDay; | ||
326 | } | ||
327 | |||
328 | const QString&NHentry::weekday()const | ||
329 | { | ||
330 | return m_Weekday; | ||
331 | } | ||
332 | |||
333 | void NHentry::setDayofmonth(const QString&aDay) | ||
334 | { | ||
335 | m_Dayofmonth = aDay; | ||
336 | } | ||
337 | |||
338 | const QString&NHentry::dayofmonth()const | ||
339 | { | ||
340 | return m_Dayofmonth; | ||
341 | } | ||
342 | |||
343 | void NHentry::setDaydep(const QString&dep) | ||
344 | { | ||
345 | m_Depth = dep; | ||
346 | } | ||
347 | |||
348 | const QString&NHentry::daydep()const | ||
349 | { | ||
350 | return m_Depth; | ||
351 | } | ||
352 | |||
353 | void NHentry::setMonth(const QString&month) | ||
354 | { | ||
355 | m_Month = month; | ||
356 | } | ||
357 | |||
358 | const QString&NHentry::month()const | ||
359 | { | ||
360 | return m_Month; | ||
361 | } | ||
362 | |||
363 | void NHentry::setOffet(int aOffset) | ||
364 | { | ||
365 | m_Offset = aOffset; | ||
366 | } | ||
367 | |||
368 | const int NHentry::offset()const | ||
369 | { | ||
370 | return m_Offset; | ||
142 | } | 371 | } |