From 8d0d50514ea163dd6f465d37831979f0e0f73039 Mon Sep 17 00:00:00 2001 From: alwin Date: Thu, 17 Mar 2005 22:39:08 +0000 Subject: added datebook plugins for xml-configurable national holidays. may someone is needing it ;) --- (limited to 'core') 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 @@ -2,4 +2,5 @@ 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 + +#include + +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< + +#include +#include +#include +#include + +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 NationalHoliday::entries(const QDate&start,const QDate&end) +{ + load_days(); + QMap 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 NationalHoliday::events(const QDate&start,const QDate&end) +{ + QValueList ret; + QDate d = (start +#include + +#include +#include + +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 entries(const QDate&,const QDate&); + virtual QValueList events(const QDate&,const QDate&); + +protected: + void init(); + unsigned int _lastyear; + tholidaylist _days; + QStringList files; + bool init_done:1; + void load_days(); +}; + +#endif -- cgit v0.9.0.2