summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--core/pim/datebook/holiday/config.in1
-rw-r--r--core/pim/datebook/holiday/national/config.in4
-rw-r--r--core/pim/datebook/holiday/national/national-holidays.pro20
-rw-r--r--core/pim/datebook/holiday/national/nationalcfg.cpp149
-rw-r--r--core/pim/datebook/holiday/national/nationalcfg.h39
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.cpp123
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.h34
-rw-r--r--etc/nationaldays/german.xml8
-rw-r--r--packages1
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 @@
menu "Holiday Plugins"
source core/pim/datebook/holiday/birthday/config.in
source core/pim/datebook/holiday/christian/config.in
source core/pim/datebook/holiday/dummy/config.in
+ source core/pim/datebook/holiday/national/config.in
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 @@
+ config DATEBOOK_NATIONAL_HOLIDAY
+ boolean "opie-datebook-national-holidays"
+ default "y"
+ 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 @@
+TEMPLATE = lib
+CONFIG -= moc
+CONFIG += qt plugin
+
+# Input
+HEADERS = nationalholiday.h nationalcfg.h
+SOURCES = nationalholiday.cpp nationalcfg.cpp
+INTERFACES=
+
+INCLUDEPATH += $(OPIEDIR)/include \
+ ../ ../library
+DEPENDPATH += $(OPIEDIR)/include \
+ ../ ../library
+
+LIBS+= -lqpe -lopiecore2 -lopieui2
+
+DESTDIR = $(OPIEDIR)/plugins/datebook/holiday
+TARGET = nationaldayplugin
+
+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 @@
+#include "nationalcfg.h"
+
+#include <opie2/odebug.h>
+
+#include <qfile.h>
+
+static QString _key_desc="description";
+static QString _key_doc="nationaldays";
+static QString _key_list="entries";
+static QString _key_entry="entry";
+static QString _content_name="name";
+static QString _content_date="date";
+
+NHcfg::NHcfg()
+ :QXmlDefaultHandler(),err(""),_path("")
+{
+}
+
+NHcfg::~NHcfg()
+{
+}
+
+bool NHcfg::load(const QString&aPath)
+{
+ _path=aPath;
+ stage = 0;
+ _content.clear();
+ odebug << "Start loading file "<<_path<<oendl;
+ QFile *f=new QFile(_path);
+ if (!f) {
+ oerr << "Could not open file" << oendl;
+ return false;
+ }
+ odebug << "Source" << oendl;
+ QXmlInputSource is(*f);
+ odebug << "Reader" << oendl;
+ QXmlSimpleReader reader;
+ odebug << "Handler" << oendl;
+ reader.setContentHandler(this);
+ odebug << "Error handler" << oendl;
+ reader.setErrorHandler(this);
+
+ err = "";
+ odebug << "parse it" << oendl;
+ bool ret = reader.parse(is);
+ odebug << "Errors: " << err << oendl;
+ return ret;
+}
+
+const tholidaylist&NHcfg::days()const
+{
+ return _content;
+}
+
+bool NHcfg::warning(const QXmlParseException& e)
+{
+ QString tmp;
+
+ tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
+
+ err += tmp;
+
+ return true;
+}
+
+bool NHcfg::error(const QXmlParseException& e)
+{
+ QString tmp;
+
+ tmp.sprintf("%d: error: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
+
+ err += tmp;
+
+ return true;
+}
+
+bool NHcfg::fatalError(const QXmlParseException& e)
+{
+ QString tmp;
+
+ tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
+ (const char*) e.message().utf8());
+
+ err += tmp;
+
+ return false;
+}
+
+bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr)
+{
+ bool ret = false;
+ odebug << "startElement: " << name << oendl;
+ if (name==_key_doc) {
+ stage = 1;
+ return true;
+ }
+ if (stage == 0) {
+ err = "This is not a national holiday config file";
+ return false;
+ }
+ if (name==_key_desc) {
+ stage = 2;
+ ret = setName(attr);
+ return ret;
+ }
+ if (stage<2) {return false;}
+ if (name==_key_list) {stage=3;return true;}
+ if (stage<3) {return false;}
+ return parsevalue(name,attr);
+}
+
+bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
+{
+ int nindex = attr.index(_content_name);
+ int dindex = attr.index(_content_date);
+ if (name != _key_entry) {err = "Not a valid entry"; return false;}
+ if (dindex == -1 || nindex == -1) {err = QString("Listentry %i is invalid").arg(1);return false;}
+ QString txt = attr.value(nindex);
+ QString dstring = attr.value(dindex);
+ QStringList e = QStringList::split("-",dstring);
+ if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;}
+ QDate d(0,e[0].toInt(),e[1].toInt());
+ odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl;
+ _content[d].append(txt);
+ return true;
+}
+
+bool NHcfg::endElement(const QString&, const QString&,const QString& name)
+{
+ return true;
+}
+
+const QString&NHcfg::errorString()const
+{
+ return err;
+}
+
+bool NHcfg::setName(const QXmlAttributes&attr)
+{
+ int nindx = attr.index("value");
+ if (nindx==-1) {
+ return false;
+ }
+ _contentname = attr.value(nindx);
+ odebug << "Contentname = " << _contentname<<oendl;
+ return true;
+}
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 @@
+#ifndef _NATIONAL_CFG_H
+#define _NATIONAL_CFG_H
+
+#include <qxml.h>
+#include <qstringlist.h>
+#include <qmap.h>
+#include <qdatetime.h>
+
+typedef QMap<QDate,QStringList> tholidaylist;
+
+class NHcfg:public QXmlDefaultHandler
+{
+public:
+ NHcfg();
+ virtual ~NHcfg();
+
+ bool load(const QString&);
+ const tholidaylist&days()const;
+
+ virtual bool warning(const QXmlParseException& e);
+ virtual bool error(const QXmlParseException& e);
+ virtual bool fatalError(const QXmlParseException& e);
+ virtual bool startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr);
+ virtual bool endElement(const QString&, const QString&,const QString& name);
+ virtual const QString&errorString()const;
+
+protected:
+ tholidaylist _content;
+ QString _contentname;
+ QString err;
+ QString _path;
+
+ bool setName(const QXmlAttributes&);
+ bool parsevalue(const QString&,const QXmlAttributes&);
+ int stage;
+// int pos;
+};
+
+#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 @@
+#include "nationalholiday.h"
+#include "nationalcfg.h"
+
+#include <opie2/odebug.h>
+
+#include <qobject.h>
+#include <qpe/event.h>
+#include <qpe/config.h>
+#include <qpe/qpeapplication.h>
+
+NationalHoliday::NationalHoliday()
+ :Opie::Datebook::HolidayPlugin()
+{
+ _lastyear=0;
+ init_done = false;
+ init();
+}
+
+QString NationalHoliday::description()
+{
+ return QObject::tr("National holidays","holidays");
+}
+
+void NationalHoliday::init()
+{
+ Config cfg("nationaldays");
+ cfg.setGroup("entries");
+ files = cfg.readListEntry("files");
+ odebug << "Read " << files << oendl;
+}
+
+void NationalHoliday::load_days()
+{
+ if (init_done) return;
+ QStringList::ConstIterator it;
+ NHcfg readit;
+ for (it=files.begin();it!=files.end();++it) {
+ odebug << QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it) << oendl;
+ if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it)))
+ continue;
+ tholidaylist::ConstIterator it;
+ for (it=readit.days().begin();it!=readit.days().end();++it) {
+ _days[it.key()]+=(it.data());
+ }
+
+ }
+ init_done = true;
+}
+
+QStringList NationalHoliday::entries(const QDate&aDate)
+{
+ load_days();
+ QStringList ret;
+ QDate d(0,aDate.month(),aDate.day());
+
+ tholidaylist::Iterator it = _days.find(d);
+ if (it!=_days.end()) {
+ ret+=*it;
+ }
+
+ return ret;
+}
+
+QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day)
+{
+ return entries(QDate(0,month,day));
+}
+
+QMap<QDate,QStringList> NationalHoliday::entries(const QDate&start,const QDate&end)
+{
+ load_days();
+ QMap<QDate,QStringList> ret;
+ if (start==end) {
+ ret[start]=entries(start);
+ return ret;
+ }
+ QDate d;
+ int daysto;
+ if (end < start) {
+ d = end;
+ daysto = end.daysTo(start);
+ } else {
+ d = start;
+ daysto = start.daysTo(end);
+ }
+ QStringList temp;
+ for (int i=0;i<=daysto;++i) {
+ temp = entries(d.addDays(i));
+ if (temp.count()==0) continue;
+ ret[d.addDays(i)]+=temp;
+ temp.clear();
+ }
+ return ret;
+}
+
+QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate&end)
+{
+ QValueList<EffectiveEvent> ret;
+ QDate d = (start<end?start:end);
+ int daysto = start.daysTo(end);
+ if (daysto < 0) {
+ daysto = end.daysTo(start);
+ }
+
+ QStringList temp;
+ for (int i =0; i<=daysto;++i) {
+ temp = entries(d.addDays(i));
+ if (temp.count()==0) {
+ continue;
+ }
+ for (unsigned j=0;j<temp.count();++j) {
+ Event ev;
+ ev.setDescription(temp[j]);
+ ev.setStart(d.addDays(i));
+ ev.setAllDay(true);
+ ret.append(EffectiveEvent(ev,d.addDays(i)));
+ }
+ }
+
+ return ret;
+}
+
+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 @@
+#ifndef __NATIONAL_HOLIDAY_H
+#define __NATIONAL_HOLIDAY_H
+
+#include "nationalcfg.h"
+
+#include <opie2/oholidayplugin.h>
+#include <opie2/oholidaypluginif.h>
+
+#include <qmap.h>
+#include <qstringlist.h>
+
+class NationalHoliday:public Opie::Datebook::HolidayPlugin
+{
+
+public:
+ NationalHoliday();
+ virtual ~NationalHoliday(){}
+
+ virtual QString description();
+ virtual QStringList entries(const QDate&);
+ virtual QStringList entries(unsigned year, unsigned month, unsigned day);
+ virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&);
+ virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&);
+
+protected:
+ void init();
+ unsigned int _lastyear;
+ tholidaylist _days;
+ QStringList files;
+ bool init_done:1;
+ void load_days();
+};
+
+#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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<nationaldays>
+<description value="German holidays"/>
+<entries>
+<entry name="Maifeiertag" date="05-01"/>
+<entry name="Tag der dt. Einheit" date="10-3"/>
+</entries>
+</nationaldays>
diff --git a/packages b/packages
index 6181b00..c4b1942 100644
--- a/packages
+++ b/packages
@@ -26,24 +26,25 @@ CONFIG_CHECKBOOK noncore/apps/checkbook checkbook.pro
CONFIG_CITYTIME core/settings/citytime citytime.pro
CONFIG_CLIPBOARDAPPLET core/applets/clipboardapplet clipboardapplet.pro
CONFIG_CLOCKAPPLET core/applets/clockapplet clockapplet.pro
CONFIG_CLOCK noncore/tools/clock clock.pro
CONFIG_CONFEDIT noncore/apps/confedit confedit.pro
CONFIG_DAGGER noncore/apps/dagger dagger.pro
CONFIG_DASHER inputmethods/dasher dasher.pro
CONFIG_DATEBOOK2 core/pim/datebook2 datebook2.pro
CONFIG_DATEBOOK core/pim/datebook datebook.pro
CONFIG_DATEBOOK_BIRTHDAYS_HOLIDAY core/pim/datebook/holiday/birthday birthdays.pro
CONFIG_DATEBOOK_CHRISTIAN_HOLIDAY core/pim/datebook/holiday/christian christian-holidays.pro
CONFIG_DATEBOOK_DUMMY_HOLIDAY core/pim/datebook/holiday/dummy dummy.pro
+CONFIG_DATEBOOK_NATIONAL_HOLIDAY core/pim/datebook/holiday/national national-holidays.pro
CONFIG_DECO_FLAT noncore/decorations/flat flat.pro
CONFIG_DECO_LIQUID noncore/decorations/liquid liquid.pro
CONFIG_DECO_POLISHED noncore/decorations/polished polished.pro
CONFIG_DICTIONARY noncore/apps/dictionary dictionary.pro
CONFIG_DOCTAB noncore/settings/doctab doctab.pro
CONFIG_DRAWPAD noncore/graphics/drawpad drawpad.pro
CONFIG_DVORAK inputmethods/dvorak dvorak.pro
CONFIG_EMBEDDEDKONSOLE core/apps/embeddedkonsole embeddedkonsole.pro
CONFIG_EUROCONV noncore/tools/euroconv/ euroconv.pro
CONFIG_EXAMPLE_APPLET examples/applet applet.pro
CONFIG_EXAMPLE_BOARD examples/inputmethod inputmethod.pro
CONFIG_EXAMPLE_LIBOPIE2CORE examples/opiecore opiecore.pro