-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.cpp | 261 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.h | 48 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.cpp | 155 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.h | 11 |
4 files changed, 448 insertions, 27 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 | |||
@@ -3,53 +3,75 @@ | |||
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 _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() |
15 | :QXmlDefaultHandler(),err(""),_path("") | 28 | :QXmlDefaultHandler(),err(""),_path("") |
16 | { | 29 | { |
17 | } | 30 | } |
18 | 31 | ||
19 | NHcfg::~NHcfg() | 32 | NHcfg::~NHcfg() |
20 | { | 33 | { |
21 | } | 34 | } |
22 | 35 | ||
23 | bool NHcfg::load(const QString&aPath) | 36 | bool NHcfg::load(const QString&aPath) |
24 | { | 37 | { |
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) { |
30 | oerr << "Could not open file" << oendl; | 42 | oerr << "Could not open file" << oendl; |
31 | return false; | 43 | return false; |
32 | } | 44 | } |
33 | QXmlInputSource is(*f); | 45 | QXmlInputSource is(*f); |
34 | QXmlSimpleReader reader; | 46 | QXmlSimpleReader reader; |
35 | reader.setContentHandler(this); | 47 | reader.setContentHandler(this); |
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); |
40 | if (err.length()>0) | 57 | if (err.length()>0) |
41 | odebug << "Errors: " << err << oendl; | 58 | odebug << "Errors: " << err << oendl; |
42 | return ret; | 59 | return ret; |
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 | ||
50 | bool NHcfg::warning(const QXmlParseException& e) | 72 | bool NHcfg::warning(const QXmlParseException& e) |
51 | { | 73 | { |
52 | QString tmp; | 74 | QString tmp; |
53 | 75 | ||
54 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | 76 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), |
55 | (const char*) e.message().utf8()); | 77 | (const char*) e.message().utf8()); |
@@ -96,47 +118,254 @@ bool NHcfg::startElement(const QString&, const QString&,const QString& name, con | |||
96 | } | 118 | } |
97 | if (name==_key_desc) { | 119 | if (name==_key_desc) { |
98 | stage = 2; | 120 | stage = 2; |
99 | ret = setName(attr); | 121 | ret = setName(attr); |
100 | return ret; | 122 | return ret; |
101 | } | 123 | } |
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 | } |
123 | 258 | ||
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 | } |
128 | 278 | ||
129 | const QString&NHcfg::errorString()const | 279 | const QString&NHcfg::errorString()const |
130 | { | 280 | { |
131 | return err; | 281 | return err; |
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 | } |
diff --git a/core/pim/datebook/holiday/national/nationalcfg.h b/core/pim/datebook/holiday/national/nationalcfg.h index 8f15097..872df65 100644 --- a/core/pim/datebook/holiday/national/nationalcfg.h +++ b/core/pim/datebook/holiday/national/nationalcfg.h | |||
@@ -1,39 +1,75 @@ | |||
1 | #ifndef _NATIONAL_CFG_H | 1 | #ifndef _NATIONAL_CFG_H |
2 | #define _NATIONAL_CFG_H | 2 | #define _NATIONAL_CFG_H |
3 | 3 | ||
4 | #include <qxml.h> | 4 | #include <qxml.h> |
5 | #include <qstringlist.h> | 5 | #include <qstringlist.h> |
6 | #include <qvaluelist.h> | ||
6 | #include <qmap.h> | 7 | #include <qmap.h> |
7 | #include <qdatetime.h> | 8 | #include <qdatetime.h> |
8 | 9 | ||
9 | typedef QMap<QDate,QStringList> tholidaylist; | 10 | typedef QMap<QDate,QStringList> tholidaylist; |
10 | 11 | ||
12 | class NHentry | ||
13 | { | ||
14 | public: | ||
15 | enum entry_type{fix,floating}; | ||
16 | NHentry(); | ||
17 | virtual ~NHentry(); | ||
18 | |||
19 | void setName(const QString&); | ||
20 | const QString&name()const; | ||
21 | void setType(entry_type); | ||
22 | entry_type type()const; | ||
23 | void setDate(const QDate&); | ||
24 | const QDate&date()const; | ||
25 | void setWeekday(const QString&); | ||
26 | const QString&weekday()const; | ||
27 | void setDayofmonth(const QString&); | ||
28 | const QString&dayofmonth()const; | ||
29 | void setDaydep(const QString&); | ||
30 | const QString&daydep()const; | ||
31 | void setMonth(const QString&); | ||
32 | const QString&month()const; | ||
33 | void setOffet(int); | ||
34 | const int offset()const; | ||
35 | |||
36 | protected: | ||
37 | entry_type m_Type; | ||
38 | QString m_Name,m_Weekday,m_Dayofmonth,m_Depth,m_Month; | ||
39 | QDate m_Date; | ||
40 | int m_Offset; | ||
41 | }; | ||
42 | |||
43 | typedef QValueList<NHentry> tentrylist; | ||
44 | |||
11 | class NHcfg:public QXmlDefaultHandler | 45 | class NHcfg:public QXmlDefaultHandler |
12 | { | 46 | { |
13 | public: | 47 | public: |
14 | NHcfg(); | 48 | NHcfg(); |
15 | virtual ~NHcfg(); | 49 | virtual ~NHcfg(); |
16 | 50 | ||
17 | bool load(const QString&); | 51 | bool load(const QString&); |
18 | const tholidaylist&days()const; | 52 | const tentrylist&fixDates()const; |
53 | const tentrylist&floatingDates()const; | ||
19 | 54 | ||
20 | virtual bool warning(const QXmlParseException& e); | 55 | virtual bool warning(const QXmlParseException& e); |
21 | virtual bool error(const QXmlParseException& e); | 56 | virtual bool error(const QXmlParseException& e); |
22 | virtual bool fatalError(const QXmlParseException& e); | 57 | virtual bool fatalError(const QXmlParseException& e); |
23 | virtual bool startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr); | 58 | virtual bool startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr); |
24 | virtual bool endElement(const QString&, const QString&,const QString& name); | 59 | virtual bool endElement(const QString&, const QString&,const QString& name); |
25 | virtual const QString&errorString()const; | 60 | virtual const QString&errorString()const; |
26 | 61 | ||
27 | protected: | 62 | protected: |
28 | tholidaylist _content; | 63 | QString err,_contentname; |
29 | QString _contentname; | ||
30 | QString err; | ||
31 | QString _path; | 64 | QString _path; |
32 | 65 | ||
66 | NHentry m_currentEntry; | ||
67 | |||
33 | bool setName(const QXmlAttributes&); | 68 | bool setName(const QXmlAttributes&); |
34 | bool parsevalue(const QString&,const QXmlAttributes&); | 69 | bool parsevalue(const QString&,const QXmlAttributes&); |
35 | int stage; | 70 | bool parseCalc(const QString&,const QXmlAttributes&); |
36 | // int pos; | 71 | int stage,counter,level; |
72 | tentrylist currentFloatList,currentFixList; | ||
37 | }; | 73 | }; |
38 | 74 | ||
39 | #endif | 75 | #endif |
diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp index 52f3489..a7ab9a5 100644 --- a/core/pim/datebook/holiday/national/nationalholiday.cpp +++ b/core/pim/datebook/holiday/national/nationalholiday.cpp | |||
@@ -30,52 +30,197 @@ void NationalHoliday::init() | |||
30 | } | 30 | } |
31 | 31 | ||
32 | void NationalHoliday::load_days() | 32 | void NationalHoliday::load_days() |
33 | { | 33 | { |
34 | if (init_done) return; | 34 | if (init_done) return; |
35 | Config cfg("nationaldays"); | 35 | Config cfg("nationaldays"); |
36 | cfg.setGroup("entries"); | 36 | cfg.setGroup("entries"); |
37 | QStringList::ConstIterator it; | 37 | QStringList::ConstIterator it; |
38 | floatingDates.clear(); | ||
38 | NHcfg readit; | 39 | NHcfg readit; |
39 | for (it=files.begin();it!=files.end();++it) { | 40 | for (it=files.begin();it!=files.end();++it) { |
40 | if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) { | 41 | if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) { |
41 | continue; | 42 | continue; |
42 | } | 43 | } |
43 | tholidaylist::ConstIterator it; | ||
44 | for (it=readit.days().begin();it!=readit.days().end();++it) { | ||
45 | _days[it.key()]+=(it.data()); | ||
46 | } | ||
47 | 44 | ||
45 | tentrylist::ConstIterator it; | ||
46 | |||
47 | for (it=readit.fixDates().begin();it!=readit.fixDates().end();++it) { | ||
48 | _days[(*it).date()]+=(*it).name(); | ||
49 | } | ||
50 | floatingDates+=readit.floatingDates(); | ||
48 | } | 51 | } |
49 | init_done = true; | 52 | init_done = true; |
50 | } | 53 | } |
51 | 54 | ||
55 | void NationalHoliday::calc_easterDate() | ||
56 | { | ||
57 | unsigned long n = 0; | ||
58 | unsigned long p = 0; | ||
59 | |||
60 | if ( _lastyear > 1582 ) { | ||
61 | unsigned long a = _lastyear%19; | ||
62 | unsigned long b = _lastyear/100; | ||
63 | unsigned long c = _lastyear%100; | ||
64 | unsigned long d = b/4; | ||
65 | unsigned long e = b%4; | ||
66 | unsigned long f = (b+8)/25; | ||
67 | unsigned long g = (b+f+1)/3; | ||
68 | unsigned long h = (19*a+b-d-g+15)%30; | ||
69 | unsigned long i = c/4; | ||
70 | unsigned long j = c%4; | ||
71 | unsigned long k = j%100; | ||
72 | unsigned long l = (32+2*e+2*i-h-k)%7; | ||
73 | unsigned long m = (a+11*h+22*l)/451; | ||
74 | n = (h+l-7*m+114)/31; | ||
75 | p = (h+l-7*m+114)%31; | ||
76 | } else { | ||
77 | unsigned long a = _lastyear%4; | ||
78 | unsigned long b = _lastyear%7; | ||
79 | unsigned long c = _lastyear%19; | ||
80 | unsigned long d = (19*c+15)%30; | ||
81 | unsigned long e = (2*a+4*b-d+34)%7; | ||
82 | n = (d+e+114)/31; | ||
83 | p = (d+e+114)%31; | ||
84 | } | ||
85 | p++; | ||
86 | easterDate = QDate(_lastyear,n,p); | ||
87 | odebug << "Easterdate = " << easterDate << oendl; | ||
88 | } | ||
89 | |||
90 | |||
91 | void NationalHoliday::setyear(const QDate&aDate) | ||
92 | { | ||
93 | if (aDate.year()==_lastyear) return; | ||
94 | odebug << "calc year" << oendl; | ||
95 | _lastyear = aDate.year(); | ||
96 | _fdays.clear(); | ||
97 | calc_easterDate(); | ||
98 | tentrylist::ConstIterator it; | ||
99 | QDate tempdate,t; | ||
100 | |||
101 | for (it = floatingDates.begin();it!=floatingDates.end();++it) { | ||
102 | odebug << "Float day " << (*it).name() << oendl; | ||
103 | |||
104 | if ( (*it).date().year()==9999) { | ||
105 | tempdate = QDate(easterDate.year(),easterDate.month(),easterDate.day()); | ||
106 | } else { | ||
107 | tempdate = QDate(_lastyear,(*it).date().month(),(*it).date().day()); | ||
108 | } | ||
109 | |||
110 | odebug << "Start calc date: " << tempdate << oendl; | ||
111 | int weekday = weektonumber((*it).weekday()); | ||
112 | int mo; | ||
113 | |||
114 | if (weekday>0) { | ||
115 | /* specific weekday set */ | ||
116 | bool dir = true; | ||
117 | if (!(*it).daydep().isEmpty()) { | ||
118 | dir = ((*it).daydep()=="before"?true:false); | ||
119 | tempdate = movedateday(tempdate,weekday,dir); | ||
120 | } else if (!(*it).dayofmonth().isEmpty() && | ||
121 | (mo=monthtonumber((*it).month())) !=0 ) { | ||
122 | t = QDate(_lastyear,mo,1); | ||
123 | if ((*it).dayofmonth()=="last") { | ||
124 | int l = t.daysInMonth(); | ||
125 | tempdate.setYMD(_lastyear,mo,l); | ||
126 | tempdate = movedateday(tempdate,weekday,true); | ||
127 | } else { | ||
128 | tempdate = movedateday(t,weekday,false); | ||
129 | tempdate = tempdate.addDays(dayoftoint((*it).dayofmonth())); | ||
130 | } | ||
131 | } | ||
132 | |||
133 | } | ||
134 | tempdate = tempdate.addDays((*it).offset()); | ||
135 | odebug << "Moved date to " << tempdate << oendl; | ||
136 | _fdays[tempdate]+=(*it).name(); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | int NationalHoliday::dayoftoint(const QString&d) | ||
141 | { | ||
142 | if (d=="first") return 0; | ||
143 | else if (d=="second") return 7; | ||
144 | else if (d=="third") return 14; | ||
145 | else if (d=="fourth") return 21; | ||
146 | return 0; | ||
147 | } | ||
148 | |||
149 | int NationalHoliday::monthtonumber(const QString&m) | ||
150 | { | ||
151 | if (m=="january")return 1; | ||
152 | else if (m=="february")return 2; | ||
153 | else if (m=="march") return 3; | ||
154 | else if (m=="april") return 4; | ||
155 | else if (m=="may") return 5; | ||
156 | else if (m=="june") return 6; | ||
157 | else if (m=="july") return 7; | ||
158 | else if (m=="august") return 8; | ||
159 | else if (m=="september") return 9; | ||
160 | else if (m=="october") return 10; | ||
161 | else if (m=="november") return 11; | ||
162 | else if (m=="december") return 12; | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | QDate NationalHoliday::movedateday(const QDate&start,int weekday,bool direction) | ||
167 | { | ||
168 | QDate d = start; | ||
169 | if (weekday==0) return d; | ||
170 | int c = (direction?-1:1); | ||
171 | |||
172 | while (d.dayOfWeek()!=weekday) { | ||
173 | d = d.addDays(c); | ||
174 | } | ||
175 | return d; | ||
176 | } | ||
177 | |||
178 | int NationalHoliday::weektonumber(const QString&w) | ||
179 | { | ||
180 | if (w=="monday") return 1; | ||
181 | else if (w=="tuesday") return 2; | ||
182 | else if (w=="wednesday") return 3; | ||
183 | else if (w=="thursday" ) return 4; | ||
184 | else if (w=="friday") return 5; | ||
185 | else if (w=="saturday") return 6; | ||
186 | else if (w=="sunday") return 7; | ||
187 | return 0; | ||
188 | } | ||
189 | |||
52 | QStringList NationalHoliday::entries(const QDate&aDate) | 190 | QStringList NationalHoliday::entries(const QDate&aDate) |
53 | { | 191 | { |
54 | load_days(); | 192 | load_days(); |
193 | setyear(aDate); | ||
194 | |||
55 | QStringList ret; | 195 | QStringList ret; |
56 | QDate d(0,aDate.month(),aDate.day()); | 196 | QDate d(0,aDate.month(),aDate.day()); |
57 | 197 | ||
58 | tholidaylist::Iterator it = _days.find(d); | 198 | tholidaylist::Iterator it = _days.find(d); |
59 | if (it!=_days.end()) { | 199 | if (it!=_days.end()) { |
60 | ret+=*it; | 200 | ret+=*it; |
61 | } | 201 | } |
62 | 202 | QDate d2(_lastyear,d.month(),d.day()); | |
203 | it = _fdays.find(d2); | ||
204 | if (it!=_fdays.end()) { | ||
205 | ret+=*it; | ||
206 | } | ||
63 | return ret; | 207 | return ret; |
64 | } | 208 | } |
65 | 209 | ||
66 | QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) | 210 | QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) |
67 | { | 211 | { |
68 | return entries(QDate(0,month,day)); | 212 | return entries(QDate(0,month,day)); |
69 | } | 213 | } |
70 | 214 | ||
71 | QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end) | 215 | QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end) |
72 | { | 216 | { |
73 | load_days(); | 217 | load_days(); |
218 | setyear(start); | ||
74 | QMap<QDate,QStringList> ret; | 219 | QMap<QDate,QStringList> ret; |
75 | if (start==end) { | 220 | if (start==end) { |
76 | ret[start]=entries(start); | 221 | ret[start]=entries(start); |
77 | return ret; | 222 | return ret; |
78 | } | 223 | } |
79 | QDate d; | 224 | QDate d; |
80 | int daysto; | 225 | int daysto; |
81 | if (end < start) { | 226 | if (end < start) { |
diff --git a/core/pim/datebook/holiday/national/nationalholiday.h b/core/pim/datebook/holiday/national/nationalholiday.h index afce3f4..7f240e0 100644 --- a/core/pim/datebook/holiday/national/nationalholiday.h +++ b/core/pim/datebook/holiday/national/nationalholiday.h | |||
@@ -21,16 +21,27 @@ public: | |||
21 | virtual QStringList entries(const QDate&); | 21 | virtual QStringList entries(const QDate&); |
22 | virtual QStringList entries(unsigned year, unsigned month, unsigned day); | 22 | virtual QStringList entries(unsigned year, unsigned month, unsigned day); |
23 | virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); | 23 | virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); |
24 | virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&); | 24 | virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&); |
25 | virtual Opie::Datebook::HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0); | 25 | virtual Opie::Datebook::HolidayPluginConfigWidget*configWidget(QWidget *parent=0, const char *name = 0, QWidget::WFlags fl = 0); |
26 | 26 | ||
27 | protected: | 27 | protected: |
28 | void init(); | 28 | void init(); |
29 | void setyear(const QDate&); | ||
30 | void calc_easterDate(); | ||
31 | static int weektonumber(const QString&); | ||
32 | static QDate movedateday(const QDate&,int weekday,bool direction); | ||
33 | static int monthtonumber(const QString&m); | ||
34 | static int dayoftoint(const QString&d); | ||
35 | |||
29 | unsigned int _lastyear; | 36 | unsigned int _lastyear; |
30 | tholidaylist _days; | 37 | tholidaylist _days; |
38 | tholidaylist _fdays; | ||
39 | tentrylist floatingDates; | ||
40 | |||
31 | QStringList files; | 41 | QStringList files; |
32 | bool init_done:1; | 42 | bool init_done:1; |
33 | void load_days(); | 43 | void load_days(); |
44 | QDate easterDate; | ||
34 | }; | 45 | }; |
35 | 46 | ||
36 | #endif | 47 | #endif |