summaryrefslogtreecommitdiff
path: root/core/pim/datebook/holiday
Unidiff
Diffstat (limited to 'core/pim/datebook/holiday') (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/holiday/national/national-holidays.pro4
-rw-r--r--core/pim/datebook/holiday/national/nationalcfg.cpp11
-rw-r--r--core/pim/datebook/holiday/national/nationalcfgwidget.cpp99
-rw-r--r--core/pim/datebook/holiday/national/nationalcfgwidget.h39
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.cpp13
-rw-r--r--core/pim/datebook/holiday/national/nationalholiday.h2
6 files changed, 154 insertions, 14 deletions
diff --git a/core/pim/datebook/holiday/national/national-holidays.pro b/core/pim/datebook/holiday/national/national-holidays.pro
index 8b2b33e..3da9c3b 100644
--- a/core/pim/datebook/holiday/national/national-holidays.pro
+++ b/core/pim/datebook/holiday/national/national-holidays.pro
@@ -1,20 +1,20 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG -= moc 2CONFIG -= moc
3CONFIG += qt plugin 3CONFIG += qt plugin
4 4
5# Input 5# Input
6HEADERS = nationalholiday.h nationalcfg.h 6HEADERS = nationalholiday.h nationalcfg.h nationalcfgwidget.h
7SOURCES = nationalholiday.cpp nationalcfg.cpp 7SOURCES = nationalholiday.cpp nationalcfg.cpp nationalcfgwidget.cpp
8INTERFACES= 8INTERFACES=
9 9
10INCLUDEPATH += $(OPIEDIR)/include \ 10INCLUDEPATH += $(OPIEDIR)/include \
11 ../ ../library 11 ../ ../library
12DEPENDPATH += $(OPIEDIR)/include \ 12DEPENDPATH += $(OPIEDIR)/include \
13 ../ ../library 13 ../ ../library
14 14
15LIBS+= -lqpe -lopiecore2 -lopieui2 15LIBS+= -lqpe -lopiecore2 -lopieui2
16 16
17DESTDIR = $(OPIEDIR)/plugins/holidays 17DESTDIR = $(OPIEDIR)/plugins/holidays
18TARGET = nationaldayplugin 18TARGET = nationaldayplugin
19 19
20include( $(OPIEDIR)/include.pro ) 20include( $(OPIEDIR)/include.pro )
diff --git a/core/pim/datebook/holiday/national/nationalcfg.cpp b/core/pim/datebook/holiday/national/nationalcfg.cpp
index a293251..52c453f 100644
--- a/core/pim/datebook/holiday/national/nationalcfg.cpp
+++ b/core/pim/datebook/holiday/national/nationalcfg.cpp
@@ -4,115 +4,109 @@
4 4
5#include <qfile.h> 5#include <qfile.h>
6 6
7static QString _key_desc="description"; 7static QString _key_desc="description";
8static QString _key_doc="nationaldays"; 8static QString _key_doc="nationaldays";
9static QString _key_list="entries"; 9static QString _key_list="entries";
10static QString _key_entry="entry"; 10static QString _key_entry="entry";
11static QString _content_name="name"; 11static QString _content_name="name";
12static QString _content_date="date"; 12static QString _content_date="date";
13 13
14NHcfg::NHcfg() 14NHcfg::NHcfg()
15 :QXmlDefaultHandler(),err(""),_path("") 15 :QXmlDefaultHandler(),err(""),_path("")
16{ 16{
17} 17}
18 18
19NHcfg::~NHcfg() 19NHcfg::~NHcfg()
20{ 20{
21} 21}
22 22
23bool NHcfg::load(const QString&aPath) 23bool NHcfg::load(const QString&aPath)
24{ 24{
25 _path=aPath; 25 _path=aPath;
26 stage = 0; 26 stage = 0;
27 _content.clear(); 27 _content.clear();
28 odebug << "Start loading file "<<_path<<oendl;
29 QFile *f=new QFile(_path); 28 QFile *f=new QFile(_path);
30 if (!f) { 29 if (!f) {
31 oerr << "Could not open file" << oendl; 30 oerr << "Could not open file" << oendl;
32 return false; 31 return false;
33 } 32 }
34 odebug << "Source" << oendl;
35 QXmlInputSource is(*f); 33 QXmlInputSource is(*f);
36 odebug << "Reader" << oendl;
37 QXmlSimpleReader reader; 34 QXmlSimpleReader reader;
38 odebug << "Handler" << oendl;
39 reader.setContentHandler(this); 35 reader.setContentHandler(this);
40 odebug << "Error handler" << oendl;
41 reader.setErrorHandler(this); 36 reader.setErrorHandler(this);
42 37
43 err = ""; 38 err = "";
44 odebug << "parse it" << oendl;
45 bool ret = reader.parse(is); 39 bool ret = reader.parse(is);
46 odebug << "Errors: " << err << oendl; 40 if (err.length()>0)
41 odebug << "Errors: " << err << oendl;
47 return ret; 42 return ret;
48} 43}
49 44
50const tholidaylist&NHcfg::days()const 45const tholidaylist&NHcfg::days()const
51{ 46{
52 return _content; 47 return _content;
53} 48}
54 49
55bool NHcfg::warning(const QXmlParseException& e) 50bool NHcfg::warning(const QXmlParseException& e)
56{ 51{
57 QString tmp; 52 QString tmp;
58 53
59 tmp.sprintf("%d: warning: %s\n", e.lineNumber(), 54 tmp.sprintf("%d: warning: %s\n", e.lineNumber(),
60 (const char*) e.message().utf8()); 55 (const char*) e.message().utf8());
61 56
62 err += tmp; 57 err += tmp;
63 58
64 return true; 59 return true;
65} 60}
66 61
67bool NHcfg::error(const QXmlParseException& e) 62bool NHcfg::error(const QXmlParseException& e)
68{ 63{
69 QString tmp; 64 QString tmp;
70 65
71 tmp.sprintf("%d: error: %s\n", e.lineNumber(), 66 tmp.sprintf("%d: error: %s\n", e.lineNumber(),
72 (const char*) e.message().utf8()); 67 (const char*) e.message().utf8());
73 68
74 err += tmp; 69 err += tmp;
75 70
76 return true; 71 return true;
77} 72}
78 73
79bool NHcfg::fatalError(const QXmlParseException& e) 74bool NHcfg::fatalError(const QXmlParseException& e)
80{ 75{
81 QString tmp; 76 QString tmp;
82 77
83 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(), 78 tmp.sprintf("%d: fatal error: %s\n", e.lineNumber(),
84 (const char*) e.message().utf8()); 79 (const char*) e.message().utf8());
85 80
86 err += tmp; 81 err += tmp;
87 82
88 return false; 83 return false;
89} 84}
90 85
91bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr) 86bool NHcfg::startElement(const QString&, const QString&,const QString& name, const QXmlAttributes& attr)
92{ 87{
93 bool ret = false; 88 bool ret = false;
94 odebug << "startElement: " << name << oendl;
95 if (name==_key_doc) { 89 if (name==_key_doc) {
96 stage = 1; 90 stage = 1;
97 return true; 91 return true;
98 } 92 }
99 if (stage == 0) { 93 if (stage == 0) {
100 err = "This is not a national holiday config file"; 94 err = "This is not a national holiday config file";
101 return false; 95 return false;
102 } 96 }
103 if (name==_key_desc) { 97 if (name==_key_desc) {
104 stage = 2; 98 stage = 2;
105 ret = setName(attr); 99 ret = setName(attr);
106 return ret; 100 return ret;
107 } 101 }
108 if (stage<2) {return false;} 102 if (stage<2) {return false;}
109 if (name==_key_list) {stage=3;return true;} 103 if (name==_key_list) {stage=3;return true;}
110 if (stage<3) {return false;} 104 if (stage<3) {return false;}
111 return parsevalue(name,attr); 105 return parsevalue(name,attr);
112} 106}
113 107
114bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr) 108bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
115{ 109{
116 int nindex = attr.index(_content_name); 110 int nindex = attr.index(_content_name);
117 int dindex = attr.index(_content_date); 111 int dindex = attr.index(_content_date);
118 if (name != _key_entry) {err = "Not a valid entry"; return false;} 112 if (name != _key_entry) {err = "Not a valid entry"; return false;}
@@ -123,27 +117,26 @@ bool NHcfg::parsevalue(const QString&name,const QXmlAttributes&attr)
123 if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;} 117 if (e.count()!=2){err=QString("Datestring %1 is invalid").arg(dstring);return false;}
124 QDate d(0,e[0].toInt(),e[1].toInt()); 118 QDate d(0,e[0].toInt(),e[1].toInt());
125 odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl; 119 odebug << "Found entry \"" << txt<<"\" on "<<d<<oendl;
126 _content[d].append(txt); 120 _content[d].append(txt);
127 return true; 121 return true;
128} 122}
129 123
130bool NHcfg::endElement(const QString&, const QString&,const QString& name) 124bool NHcfg::endElement(const QString&, const QString&,const QString& name)
131{ 125{
132 return true; 126 return true;
133} 127}
134 128
135const QString&NHcfg::errorString()const 129const QString&NHcfg::errorString()const
136{ 130{
137 return err; 131 return err;
138} 132}
139 133
140bool NHcfg::setName(const QXmlAttributes&attr) 134bool NHcfg::setName(const QXmlAttributes&attr)
141{ 135{
142 int nindx = attr.index("value"); 136 int nindx = attr.index("value");
143 if (nindx==-1) { 137 if (nindx==-1) {
144 return false; 138 return false;
145 } 139 }
146 _contentname = attr.value(nindx); 140 _contentname = attr.value(nindx);
147 odebug << "Contentname = " << _contentname<<oendl;
148 return true; 141 return true;
149} 142}
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.cpp b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp
new file mode 100644
index 0000000..6e3dd7d
--- a/dev/null
+++ b/core/pim/datebook/holiday/national/nationalcfgwidget.cpp
@@ -0,0 +1,99 @@
1#include "nationalcfgwidget.h"
2
3#include <opie2/odebug.h>
4
5#include <qpe/config.h>
6#include <qpe/qpeapplication.h>
7
8#include <qheader.h>
9#include <qlabel.h>
10#include <qlistview.h>
11#include <qpushbutton.h>
12#include <qlayout.h>
13#include <qvariant.h>
14#include <qtooltip.h>
15#include <qwhatsthis.h>
16#include <qheader.h>
17#include <qdir.h>
18
19/*
20 * Constructs a NationalHolidayConfig which is a child of 'parent', with the
21 * name 'name' and widget flags set to 'f'
22 */
23NationalHolidayConfigWidget::NationalHolidayConfigWidget( QWidget* parent, const char* name, WFlags fl )
24 : Opie::Datebook::HolidayPluginConfigWidget( parent, name, fl )
25{
26 if ( !name )
27 setName( "NationalHolidayConfig" );
28 resize( 206, 210 );
29 setCaption( tr( "Select national config" ) );
30 NationalHolidayConfigLayout = new QVBoxLayout( this );
31 NationalHolidayConfigLayout->setSpacing( 2 );
32 NationalHolidayConfigLayout->setMargin( 2 );
33
34 m_headLabel = new QLabel( this, "m_headLabel" );
35 m_headLabel->setText( tr( "Select one or more configs to load" ) );
36 m_headLabel->setAlignment( int( QLabel::AlignCenter ) );
37 NationalHolidayConfigLayout->addWidget( m_headLabel );
38
39 m_Configlist = new QListView( this, "m_Configlist" );
40 m_Configlist->addColumn( tr( "configfiles" ) );
41 QWhatsThis::add( m_Configlist, tr( "List of found xml-files which may load." ) );
42 NationalHolidayConfigLayout->addWidget( m_Configlist );
43
44 // signals and slots connections
45 connect( m_Configlist, SIGNAL( clicked(QListViewItem*) ), this, SLOT( listItemClicked(QListViewItem*) ) );
46 init();
47}
48
49void NationalHolidayConfigWidget::init()
50{
51 m_Configlist->header()->hide();
52 m_Configlist->setSorting(-1);
53
54 QString path = QPEApplication::qpeDir() + "etc/nationaldays";
55 QDir dir( path, "*.xml" );
56 QStringList list = dir.entryList();
57 QStringList::Iterator it;
58 Config cfg("nationaldays");
59 cfg.setGroup("entries");
60 files = cfg.readListEntry("files");
61 QCheckListItem *pitem = 0;
62
63 for (it=list.begin();it!=list.end();++it) {
64 pitem = new QCheckListItem(m_Configlist,(*it),QCheckListItem::CheckBox);
65 if (files.find((*it)) != files.end()) {
66 pitem->setOn(true);
67 } else {
68 pitem->setOn(false);
69 }
70 }
71}
72
73/*
74 * Destroys the object and frees any allocated resources
75 */
76NationalHolidayConfigWidget::~NationalHolidayConfigWidget()
77{
78 // no need to delete child widgets, Qt does it all for us
79}
80
81void NationalHolidayConfigWidget::listItemClicked(QListViewItem*item)
82{
83 if (!item) return;
84 QCheckListItem*pitem = ((QCheckListItem*)item);
85 QStringList::Iterator it = files.find(pitem->text(0));
86 if (pitem->isOn()&&it==files.end()) {
87 files.append(pitem->text(0));
88 } else if (!pitem->isOn() && it!=files.end()) {
89 files.remove(it);
90 }
91}
92
93void NationalHolidayConfigWidget::saveConfig()
94{
95 Config cfg("nationaldays");
96 cfg.setGroup("entries");
97 cfg.writeEntry("files",files);
98}
99
diff --git a/core/pim/datebook/holiday/national/nationalcfgwidget.h b/core/pim/datebook/holiday/national/nationalcfgwidget.h
new file mode 100644
index 0000000..9f16aa4
--- a/dev/null
+++ b/core/pim/datebook/holiday/national/nationalcfgwidget.h
@@ -0,0 +1,39 @@
1#ifndef NATIONALHOLIDAYCONFIGWIDGET_H
2#define NATIONALHOLIDAYCONFIGWIDGET_H
3
4#include <opie2/oholidayplugincfgwidget.h>
5
6#include <qvariant.h>
7#include <qwidget.h>
8#include <qstringlist.h>
9
10class QVBoxLayout;
11class QHBoxLayout;
12class QGridLayout;
13class QLabel;
14class QListView;
15class QListViewItem;
16
17class NationalHolidayConfigWidget : public Opie::Datebook::HolidayPluginConfigWidget
18{
19 Q_OBJECT
20
21public:
22 NationalHolidayConfigWidget( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
23 virtual ~NationalHolidayConfigWidget();
24
25 virtual void saveConfig();
26
27protected slots:
28 virtual void listItemClicked(QListViewItem*);
29
30protected:
31 void init();
32
33 QVBoxLayout* NationalHolidayConfigLayout;
34 QLabel* m_headLabel;
35 QListView* m_Configlist;
36 QStringList files;
37};
38
39#endif // NATIONALHOLIDAYCONFIG_H
diff --git a/core/pim/datebook/holiday/national/nationalholiday.cpp b/core/pim/datebook/holiday/national/nationalholiday.cpp
index 26cd913..52f3489 100644
--- a/core/pim/datebook/holiday/national/nationalholiday.cpp
+++ b/core/pim/datebook/holiday/national/nationalholiday.cpp
@@ -1,64 +1,66 @@
1#include "nationalholiday.h" 1#include "nationalholiday.h"
2#include "nationalcfg.h" 2#include "nationalcfg.h"
3#include "nationalcfgwidget.h"
3 4
4#include <opie2/odebug.h> 5#include <opie2/odebug.h>
5 6
6#include <qobject.h> 7#include <qobject.h>
7#include <qpe/event.h> 8#include <qpe/event.h>
8#include <qpe/config.h> 9#include <qpe/config.h>
9#include <qpe/qpeapplication.h> 10#include <qpe/qpeapplication.h>
10 11
11NationalHoliday::NationalHoliday() 12NationalHoliday::NationalHoliday()
12 :Opie::Datebook::HolidayPlugin() 13 :Opie::Datebook::HolidayPlugin()
13{ 14{
14 _lastyear=0; 15 _lastyear=0;
15 init_done = false; 16 init_done = false;
16 init(); 17 init();
17} 18}
18 19
19QString NationalHoliday::description() 20QString NationalHoliday::description()
20{ 21{
21 return QObject::tr("National holidays","holidays"); 22 return QObject::tr("National holidays","holidays");
22} 23}
23 24
24void NationalHoliday::init() 25void NationalHoliday::init()
25{ 26{
26 Config cfg("nationaldays"); 27 Config cfg("nationaldays");
27 cfg.setGroup("entries"); 28 cfg.setGroup("entries");
28 files = cfg.readListEntry("files"); 29 files = cfg.readListEntry("files");
29 odebug << "Read " << files << oendl;
30} 30}
31 31
32void NationalHoliday::load_days() 32void NationalHoliday::load_days()
33{ 33{
34 if (init_done) return; 34 if (init_done) return;
35 Config cfg("nationaldays");
36 cfg.setGroup("entries");
35 QStringList::ConstIterator it; 37 QStringList::ConstIterator it;
36 NHcfg readit; 38 NHcfg readit;
37 for (it=files.begin();it!=files.end();++it) { 39 for (it=files.begin();it!=files.end();++it) {
38 odebug << QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it) << oendl; 40 if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it))) {
39 if (!readit.load(QPEApplication::qpeDir()+"/etc/nationaldays/"+(*it)))
40 continue; 41 continue;
42 }
41 tholidaylist::ConstIterator it; 43 tholidaylist::ConstIterator it;
42 for (it=readit.days().begin();it!=readit.days().end();++it) { 44 for (it=readit.days().begin();it!=readit.days().end();++it) {
43 _days[it.key()]+=(it.data()); 45 _days[it.key()]+=(it.data());
44 } 46 }
45 47
46 } 48 }
47 init_done = true; 49 init_done = true;
48} 50}
49 51
50QStringList NationalHoliday::entries(const QDate&aDate) 52QStringList NationalHoliday::entries(const QDate&aDate)
51{ 53{
52 load_days(); 54 load_days();
53 QStringList ret; 55 QStringList ret;
54 QDate d(0,aDate.month(),aDate.day()); 56 QDate d(0,aDate.month(),aDate.day());
55 57
56 tholidaylist::Iterator it = _days.find(d); 58 tholidaylist::Iterator it = _days.find(d);
57 if (it!=_days.end()) { 59 if (it!=_days.end()) {
58 ret+=*it; 60 ret+=*it;
59 } 61 }
60 62
61 return ret; 63 return ret;
62} 64}
63 65
64QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day) 66QStringList NationalHoliday::entries(unsigned year, unsigned month, unsigned day)
@@ -99,25 +101,30 @@ QValueList<EffectiveEvent> NationalHoliday::events(const QDate&start,const QDate
99 QDate d = (start<end?start:end); 101 QDate d = (start<end?start:end);
100 int daysto = start.daysTo(end); 102 int daysto = start.daysTo(end);
101 if (daysto < 0) { 103 if (daysto < 0) {
102 daysto = end.daysTo(start); 104 daysto = end.daysTo(start);
103 } 105 }
104 106
105 QStringList temp; 107 QStringList temp;
106 for (int i =0; i<=daysto;++i) { 108 for (int i =0; i<=daysto;++i) {
107 temp = entries(d.addDays(i)); 109 temp = entries(d.addDays(i));
108 if (temp.count()==0) { 110 if (temp.count()==0) {
109 continue; 111 continue;
110 } 112 }
111 for (unsigned j=0;j<temp.count();++j) { 113 for (unsigned j=0;j<temp.count();++j) {
112 Event ev; 114 Event ev;
113 ev.setDescription(temp[j]); 115 ev.setDescription(temp[j]);
114 ev.setStart(d.addDays(i)); 116 ev.setStart(d.addDays(i));
115 ev.setAllDay(true); 117 ev.setAllDay(true);
116 ret.append(EffectiveEvent(ev,d.addDays(i))); 118 ret.append(EffectiveEvent(ev,d.addDays(i)));
117 } 119 }
118 } 120 }
119 121
120 return ret; 122 return ret;
121} 123}
122 124
125Opie::Datebook::HolidayPluginConfigWidget*NationalHoliday::configWidget(QWidget *parent, const char *name, QWidget::WFlags fl)
126{
127 return new NationalHolidayConfigWidget(parent,name,fl);
128}
129
123EXPORT_HOLIDAY_PLUGIN(NationalHoliday); 130EXPORT_HOLIDAY_PLUGIN(NationalHoliday);
diff --git a/core/pim/datebook/holiday/national/nationalholiday.h b/core/pim/datebook/holiday/national/nationalholiday.h
index 6581263..afce3f4 100644
--- a/core/pim/datebook/holiday/national/nationalholiday.h
+++ b/core/pim/datebook/holiday/national/nationalholiday.h
@@ -1,34 +1,36 @@
1#ifndef __NATIONAL_HOLIDAY_H 1#ifndef __NATIONAL_HOLIDAY_H
2#define __NATIONAL_HOLIDAY_H 2#define __NATIONAL_HOLIDAY_H
3 3
4#include "nationalcfg.h" 4#include "nationalcfg.h"
5 5
6#include <opie2/oholidayplugin.h> 6#include <opie2/oholidayplugin.h>
7#include <opie2/oholidaypluginif.h> 7#include <opie2/oholidaypluginif.h>
8#include <opie2/oholidayplugincfgwidget.h>
8 9
9#include <qmap.h> 10#include <qmap.h>
10#include <qstringlist.h> 11#include <qstringlist.h>
11 12
12class NationalHoliday:public Opie::Datebook::HolidayPlugin 13class NationalHoliday:public Opie::Datebook::HolidayPlugin
13{ 14{
14 15
15public: 16public:
16 NationalHoliday(); 17 NationalHoliday();
17 virtual ~NationalHoliday(){} 18 virtual ~NationalHoliday(){}
18 19
19 virtual QString description(); 20 virtual QString description();
20 virtual QStringList entries(const QDate&); 21 virtual QStringList entries(const QDate&);
21 virtual QStringList entries(unsigned year, unsigned month, unsigned day); 22 virtual QStringList entries(unsigned year, unsigned month, unsigned day);
22 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); 23 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&);
23 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);
24 26
25protected: 27protected:
26 void init(); 28 void init();
27 unsigned int _lastyear; 29 unsigned int _lastyear;
28 tholidaylist _days; 30 tholidaylist _days;
29 QStringList files; 31 QStringList files;
30 bool init_done:1; 32 bool init_done:1;
31 void load_days(); 33 void load_days();
32}; 34};
33 35
34#endif 36#endif