author | alwin <alwin> | 2005-03-17 22:39:08 (UTC) |
---|---|---|
committer | alwin <alwin> | 2005-03-17 22:39:08 (UTC) |
commit | 8d0d50514ea163dd6f465d37831979f0e0f73039 (patch) (unidiff) | |
tree | f19f0acc02e6605674cb301a3b7892f9f0dcce87 | |
parent | 65b5d22571cdc6ef3967005ed831376466bdf5bd (diff) | |
download | opie-8d0d50514ea163dd6f465d37831979f0e0f73039.zip opie-8d0d50514ea163dd6f465d37831979f0e0f73039.tar.gz opie-8d0d50514ea163dd6f465d37831979f0e0f73039.tar.bz2 |
added datebook plugins for xml-configurable national holidays.
may someone is needing it ;)
-rw-r--r-- | core/pim/datebook/holiday/config.in | 1 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/config.in | 4 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/national-holidays.pro | 20 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.cpp | 149 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalcfg.h | 39 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.cpp | 123 | ||||
-rw-r--r-- | core/pim/datebook/holiday/national/nationalholiday.h | 34 | ||||
-rw-r--r-- | etc/nationaldays/german.xml | 8 | ||||
-rw-r--r-- | packages | 1 |
9 files changed, 379 insertions, 0 deletions
diff --git a/core/pim/datebook/holiday/config.in b/core/pim/datebook/holiday/config.in index 1912dbe..a3ecd7b 100644 --- a/core/pim/datebook/holiday/config.in +++ b/core/pim/datebook/holiday/config.in | |||
@@ -1,5 +1,6 @@ | |||
1 | menu "Holiday Plugins" | 1 | menu "Holiday Plugins" |
2 | source core/pim/datebook/holiday/birthday/config.in | 2 | source core/pim/datebook/holiday/birthday/config.in |
3 | source core/pim/datebook/holiday/christian/config.in | 3 | source core/pim/datebook/holiday/christian/config.in |
4 | source core/pim/datebook/holiday/dummy/config.in | 4 | source core/pim/datebook/holiday/dummy/config.in |
5 | source core/pim/datebook/holiday/national/config.in | ||
5 | endmenu | 6 | endmenu |
diff --git a/core/pim/datebook/holiday/national/config.in b/core/pim/datebook/holiday/national/config.in new file mode 100644 index 0000000..c286626 --- a/dev/null +++ b/core/pim/datebook/holiday/national/config.in | |||
@@ -0,0 +1,4 @@ | |||
1 | config DATEBOOK_NATIONAL_HOLIDAY | ||
2 | boolean "opie-datebook-national-holidays" | ||
3 | default "y" | ||
4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE && LIBOPIE2UI && LIBOPIE2PIM | ||
diff --git a/core/pim/datebook/holiday/national/national-holidays.pro b/core/pim/datebook/holiday/national/national-holidays.pro new file mode 100644 index 0000000..5e7ec2c --- a/dev/null +++ b/core/pim/datebook/holiday/national/national-holidays.pro | |||
@@ -0,0 +1,20 @@ | |||
1 | TEMPLATE = lib | ||
2 | CONFIG -= moc | ||
3 | CONFIG += qt plugin | ||
4 | |||
5 | # Input | ||
6 | HEADERS = nationalholiday.h nationalcfg.h | ||
7 | SOURCES = nationalholiday.cpp nationalcfg.cpp | ||
8 | INTERFACES= | ||
9 | |||
10 | INCLUDEPATH += $(OPIEDIR)/include \ | ||
11 | ../ ../library | ||
12 | DEPENDPATH += $(OPIEDIR)/include \ | ||
13 | ../ ../library | ||
14 | |||
15 | LIBS+= -lqpe -lopiecore2 -lopieui2 | ||
16 | |||
17 | DESTDIR = $(OPIEDIR)/plugins/datebook/holiday | ||
18 | TARGET = nationaldayplugin | ||
19 | |||
20 | include( $(OPIEDIR)/include.pro ) | ||
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp new file mode 100644 index 0000000..a293251 --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalcfg.cpp | |||
@@ -0,0 +1,149 @@ | |||
1 | #include "nationalcfg.h" | ||
2 | |||
3 | #include <opie2/odebug.h> | ||
4 | |||
5 | #include <qfile.h> | ||
6 | |||
7 | static QString _key_desc="description"; | ||
8 | static QString _key_doc="nationaldays"; | ||
9 | static QString _key_list="entries"; | ||
10 | static QString _key_entry="entry"; | ||
11 | static QString _content_name="name"; | ||
12 | static QString _content_date="date"; | ||
13 | |||
14 | NHcfg::NHcfg() | ||
15 | :QXmlDefaultHandler(),err(""),_path("") | ||
16 | { | ||
17 | } | ||
18 | |||
19 | NHcfg::~NHcfg() | ||
20 | { | ||
21 | } | ||
22 | |||
23 | bool NHcfg::load(const QString&aPath) | ||
24 | { | ||
25 | _path=aPath; | ||
26 | stage = 0; | ||
27 | _content.clear(); | ||
28 | odebug << "Start loading file "<<_path<<oendl; | ||
29 | QFile *f=new QFile(_path); | ||
30 | if (!f) { | ||
31 | oerr << "Could not open file" << oendl; | ||
32 | return false; | ||
33 | } | ||
34 | odebug << "Source" << oendl; | ||
35 | QXmlInputSource is(*f); | ||
36 | odebug << "Reader" << oendl; | ||
37 | QXmlSimpleReader reader; | ||
38 | odebug << "Handler" << oendl; | ||
39 | reader.setContentHandler(this); | ||
40 | odebug << "Error handler" << oendl; | ||
41 | reader.setErrorHandler(this); | ||
42 | |||
43 | err = ""; | ||
44 | odebug << "parse it" << oendl; | ||
45 | bool ret = reader.parse(is); | ||
46 | odebug << "Errors: " << err << oendl; | ||
47 | return ret; | ||
48 | } | ||
49 | |||
50 | const tholidaylist&NHcfg::days()const | ||
51 | { | ||
52 | return _content; | ||
53 | } | ||
54 | |||
55 | bool NHcfg::warning(const QXmlParseException& e) | ||
56 | { | ||
57 | QString tmp; | ||
58 | |||
59 | tmp.sprintf("%d: warning: %s\n", e.lineNumber(), | ||
60 | (const char*) e.message().utf8()); | ||
61 | |||
62 | err += tmp; | ||
63 | |||
64 | return true; | ||
65 | } | ||
66 | |||
67 | bool NHcfg::error(const QXmlParseException& e) | ||
68 | { | ||
69 | QString tmp; | ||
70 | |||
71 | tmp.sprintf("%d: error: %s\n", e.lineNumber(), | ||
72 | (const char*) e.message().utf8()); | ||
73 | |||
74 | err += tmp; | ||
75 | |||
76 | return true; | ||
77 | } | ||
78 | |||
79 | bool NHcfg::fatalError(const QXmlParseException& e) | ||
80 | { | ||
81 | QString tmp; | ||
82 | |||
83 | tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), | ||
84 | (const char*) e.message().utf8()); | ||
85 | |||
86 | err += tmp; | ||
87 | |||
88 | return false; | ||
89 | } | ||
90 | |||
91 | bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr) | ||
92 | { | ||
93 | bool ret = false; | ||
94 | odebug << "startElement: " << name << oendl; | ||
95 | if (name==_key_doc) { | ||
96 | stage = 1; | ||
97 | return true; | ||
98 | } | ||
99 | if (stage == 0) { | ||
100 | err = "This is not a national holiday config file"; | ||
101 | return false; | ||
102 | } | ||
103 | if (name==_key_desc) { | ||
104 | stage = 2; | ||
105 | ret = setName(attr); | ||
106 | return ret; | ||
107 | } | ||
108 | if (stage<2) {return false;} | ||
109 | if (name==_key_list) {stage=3;return true;} | ||
110 | if (stage<3) {return false;} | ||
111 | return parsevalue(name,attr); | ||
112 | } | ||
113 | |||
114 | bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) | ||
115 | { | ||
116 | int nindex = attr.index(_content_name); | ||
117 | int dindex = attr.index(_content_date); | ||
118 | 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;} | ||
120 | QString txt = attr.value(nindex); | ||
121 | QString dstring = attr.value(dindex); | ||
122 | QStringList e = QStringList::split("-",dstring); | ||
123 | if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} | ||
124 | QDate d(0,e[0].toInt(),e[1].toInt()); | ||
125 | odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; | ||
126 | _content[d].append(txt); | ||
127 | return true; | ||
128 | } | ||
129 | |||
130 | bool NHcfg::endElement(const QString&, const QString&,const QString& name) | ||
131 | { | ||
132 | return true; | ||
133 | } | ||
134 | |||
135 | const QString&NHcfg::errorString()const | ||
136 | { | ||
137 | return err; | ||
138 | } | ||
139 | |||
140 | bool NHcfg::setName(const QXmlAttributes&attr) | ||
141 | { | ||
142 | int nindx = attr.index("value"); | ||
143 | if (nindx==-1) { | ||
144 | return false; | ||
145 | } | ||
146 | _contentname = attr.value(nindx); | ||
147 | odebug << "Contentname = " << _contentname<<oendl; | ||
148 | return true; | ||
149 | } | ||
diff --git a/core/pim/datebook/holiday/national/nationalcfg.h b/core/pim/datebook/holiday/national/nationalcfg.h new file mode 100644 index 0000000..8f15097 --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalcfg.h | |||
@@ -0,0 +1,39 @@ | |||
1 | #ifndef _NATIONAL_CFG_H | ||
2 | #define _NATIONAL_CFG_H | ||
3 | |||
4 | #include <qxml.h> | ||
5 | #include <qstringlist.h> | ||
6 | #include <qmap.h> | ||
7 | #include <qdatetime.h> | ||
8 | |||
9 | typedef QMap<QDate,QStringList> tholidaylist; | ||
10 | |||
11 | class NHcfg:public QXmlDefaultHandler | ||
12 | { | ||
13 | public: | ||
14 | NHcfg(); | ||
15 | virtual ~NHcfg(); | ||
16 | |||
17 | bool load(const QString&); | ||
18 | const tholidaylist&days()const; | ||
19 | |||
20 | virtual bool warning(const QXmlParseException& e); | ||
21 | virtual bool error(const QXmlParseException& e); | ||
22 | virtual bool fatalError(const QXmlParseException& e); | ||
23 | virtual bool startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr); | ||
24 | virtual bool endElement(const QString&, const QString&,const QString& name); | ||
25 | virtual const QString&errorString()const; | ||
26 | |||
27 | protected: | ||
28 | tholidaylist _content; | ||
29 | QString _contentname; | ||
30 | QString err; | ||
31 | QString _path; | ||
32 | |||
33 | bool setName(const QXmlAttributes&); | ||
34 | bool parsevalue(const QString&,const QXmlAttributes&); | ||
35 | int stage; | ||
36 | // int pos; | ||
37 | }; | ||
38 | |||
39 | #endif | ||
diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp new file mode 100644 index 0000000..26cd913 --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalholiday.cpp | |||
@@ -0,0 +1,123 @@ | |||
1 | #include "nationalholiday.h" | ||
2 | #include "nationalcfg.h" | ||
3 | |||
4 | #include <opie2/odebug.h> | ||
5 | |||
6 | #include <qobject.h> | ||
7 | #include <qpe/event.h> | ||
8 | #include <qpe/config.h> | ||
9 | #include <qpe/qpeapplication.h> | ||
10 | |||
11 | NationalHoliday::NationalHoliday() | ||
12 | :Opie::Datebook::HolidayPlugin() | ||
13 | { | ||
14 | _lastyear=0; | ||
15 | init_done = false; | ||
16 | init(); | ||
17 | } | ||
18 | |||
19 | QString NationalHoliday::description() | ||
20 | { | ||
21 | return QObject::tr("National holidays","holidays"); | ||
22 | } | ||
23 | |||
24 | void NationalHoliday::init() | ||
25 | { | ||
26 | Config cfg("nationaldays"); | ||
27 | cfg.setGroup("entries"); | ||
28 | files = cfg.readListEntry("files"); | ||
29 | odebug << "Read " << files << oendl; | ||
30 | } | ||
31 | |||
32 | void NationalHoliday::load_days() | ||
33 | { | ||
34 | if (init_done) return; | ||
35 | QStringList::ConstIterator it; | ||
36 | NHcfg readit; | ||
37 | for (it=files.begin();it!=files.end();++it) { | ||
38 | odebug << QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it) << oendl; | ||
39 | if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) | ||
40 | continue; | ||
41 | tholidaylist::ConstIterator it; | ||
42 | for (it=readit.days().begin();it!=readit.days().end();++it) { | ||
43 | _days[it.key()]+=(it.data()); | ||
44 | } | ||
45 | |||
46 | } | ||
47 | init_done = true; | ||
48 | } | ||
49 | |||
50 | QStringList NationalHoliday::entries(const QDate&aDate) | ||
51 | { | ||
52 | load_days(); | ||
53 | QStringList ret; | ||
54 | QDate d(0,aDate.month(),aDate.day()); | ||
55 | |||
56 | tholidaylist::Iterator it = _days.find(d); | ||
57 | if (it!=_days.end()) { | ||
58 | ret+=*it; | ||
59 | } | ||
60 | |||
61 | return ret; | ||
62 | } | ||
63 | |||
64 | QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) | ||
65 | { | ||
66 | return entries(QDate(0,month,day)); | ||
67 | } | ||
68 | |||
69 | QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end) | ||
70 | { | ||
71 | load_days(); | ||
72 | QMap<QDate,QStringList> ret; | ||
73 | if (start==end) { | ||
74 | ret[start]=entries(start); | ||
75 | return ret; | ||
76 | } | ||
77 | QDate d; | ||
78 | int daysto; | ||
79 | if (end < start) { | ||
80 | d = end; | ||
81 | daysto = end.daysTo(start); | ||
82 | } else { | ||
83 | d = start; | ||
84 | daysto = start.daysTo(end); | ||
85 | } | ||
86 | QStringList temp; | ||
87 | for (int i=0;i<=daysto;++i) { | ||
88 | temp = entries(d.addDays(i)); | ||
89 | if (temp.count()==0) continue; | ||
90 | ret[d.addDays(i)]+=temp; | ||
91 | temp.clear(); | ||
92 | } | ||
93 | return ret; | ||
94 | } | ||
95 | |||
96 | QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate&end) | ||
97 | { | ||
98 | QValueList<EffectiveEvent> ret; | ||
99 | QDate d = (start<end?start:end); | ||
100 | int daysto = start.daysTo(end); | ||
101 | if (daysto < 0) { | ||
102 | daysto = end.daysTo(start); | ||
103 | } | ||
104 | |||
105 | QStringList temp; | ||
106 | for (int i =0; i<=daysto;++i) { | ||
107 | temp = entries(d.addDays(i)); | ||
108 | if (temp.count()==0) { | ||
109 | continue; | ||
110 | } | ||
111 | for (unsigned j=0;j<temp.count();++j) { | ||
112 | Event ev; | ||
113 | ev.setDescription(temp[j]); | ||
114 | ev.setStart(d.addDays(i)); | ||
115 | ev.setAllDay(true); | ||
116 | ret.append(EffectiveEvent(ev,d.addDays(i))); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | EXPORT_HOLIDAY_PLUGIN(NationalHoliday); | ||
diff --git a/core/pim/datebook/holiday/national/nationalholiday.h b/core/pim/datebook/holiday/national/nationalholiday.h new file mode 100644 index 0000000..6581263 --- a/dev/null +++ b/core/pim/datebook/holiday/national/nationalholiday.h | |||
@@ -0,0 +1,34 @@ | |||
1 | #ifndef __NATIONAL_HOLIDAY_H | ||
2 | #define __NATIONAL_HOLIDAY_H | ||
3 | |||
4 | #include "nationalcfg.h" | ||
5 | |||
6 | #include <opie2/oholidayplugin.h> | ||
7 | #include <opie2/oholidaypluginif.h> | ||
8 | |||
9 | #include <qmap.h> | ||
10 | #include <qstringlist.h> | ||
11 | |||
12 | class NationalHoliday:public Opie::Datebook::HolidayPlugin | ||
13 | { | ||
14 | |||
15 | public: | ||
16 | NationalHoliday(); | ||
17 | virtual ~NationalHoliday(){} | ||
18 | |||
19 | virtual QString description(); | ||
20 | virtual QStringList entries(const QDate&); | ||
21 | virtual QStringList entries(unsigned year, unsigned month, unsigned day); | ||
22 | virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); | ||
23 | virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&); | ||
24 | |||
25 | protected: | ||
26 | void init(); | ||
27 | unsigned int _lastyear; | ||
28 | tholidaylist _days; | ||
29 | QStringList files; | ||
30 | bool init_done:1; | ||
31 | void load_days(); | ||
32 | }; | ||
33 | |||
34 | #endif | ||
diff --git a/etc/nationaldays/german.xml b/etc/nationaldays/german.xml new file mode 100644 index 0000000..cf0b2e5 --- a/dev/null +++ b/etc/nationaldays/german.xml | |||
@@ -0,0 +1,8 @@ | |||
1 | <?xml version="1.0" encoding="UTF-8"?> | ||
2 | <nationaldays> | ||
3 | <description value="German holidays"/> | ||
4 | <entries> | ||
5 | <entry name="Maifeiertag" date="05-01"/> | ||
6 | <entry name="Tag der dt. Einheit" date="10-3"/> | ||
7 | </entries> | ||
8 | </nationaldays> | ||
@@ -32,12 +32,13 @@ CONFIG_DAGGER noncore/apps/dagger dagger.pro | |||
32 | CONFIG_DASHER inputmethods/dasherdasher.pro | 32 | CONFIG_DASHER inputmethods/dasherdasher.pro |
33 | CONFIG_DATEBOOK2 core/pim/datebook2datebook2.pro | 33 | CONFIG_DATEBOOK2 core/pim/datebook2datebook2.pro |
34 | CONFIG_DATEBOOK core/pim/datebookdatebook.pro | 34 | CONFIG_DATEBOOK core/pim/datebookdatebook.pro |
35 | CONFIG_DATEBOOK_BIRTHDAYS_HOLIDAY core/pim/datebook/holiday/birthday birthdays.pro | 35 | CONFIG_DATEBOOK_BIRTHDAYS_HOLIDAY core/pim/datebook/holiday/birthday birthdays.pro |
36 | CONFIG_DATEBOOK_CHRISTIAN_HOLIDAY core/pim/datebook/holiday/christian christian-holidays.pro | 36 | CONFIG_DATEBOOK_CHRISTIAN_HOLIDAY core/pim/datebook/holiday/christian christian-holidays.pro |
37 | CONFIG_DATEBOOK_DUMMY_HOLIDAY core/pim/datebook/holiday/dummy dummy.pro | 37 | CONFIG_DATEBOOK_DUMMY_HOLIDAY core/pim/datebook/holiday/dummy dummy.pro |
38 | CONFIG_DATEBOOK_NATIONAL_HOLIDAY core/pim/datebook/holiday/national national-holidays.pro | ||
38 | CONFIG_DECO_FLAT noncore/decorations/flatflat.pro | 39 | CONFIG_DECO_FLAT noncore/decorations/flatflat.pro |
39 | CONFIG_DECO_LIQUID noncore/decorations/liquidliquid.pro | 40 | CONFIG_DECO_LIQUID noncore/decorations/liquidliquid.pro |
40 | CONFIG_DECO_POLISHED noncore/decorations/polishedpolished.pro | 41 | CONFIG_DECO_POLISHED noncore/decorations/polishedpolished.pro |
41 | CONFIG_DICTIONARY noncore/apps/dictionarydictionary.pro | 42 | CONFIG_DICTIONARY noncore/apps/dictionarydictionary.pro |
42 | CONFIG_DOCTAB noncore/settings/doctab doctab.pro | 43 | CONFIG_DOCTAB noncore/settings/doctab doctab.pro |
43 | CONFIG_DRAWPAD noncore/graphics/drawpaddrawpad.pro | 44 | CONFIG_DRAWPAD noncore/graphics/drawpaddrawpad.pro |