summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/pim/datebook/holiday/birthday/birthday.cpp90
-rw-r--r--core/pim/datebook/holiday/birthday/birthday.h2
-rw-r--r--core/pim/datebook/holiday/christian/chrisholiday.cpp50
-rw-r--r--core/pim/datebook/holiday/christian/chrisholiday.h2
4 files changed, 142 insertions, 2 deletions
diff --git a/core/pim/datebook/holiday/birthday/birthday.cpp b/core/pim/datebook/holiday/birthday/birthday.cpp
index 98e2d40..74bcf8b 100644
--- a/core/pim/datebook/holiday/birthday/birthday.cpp
+++ b/core/pim/datebook/holiday/birthday/birthday.cpp
@@ -1,71 +1,159 @@
1#include "birthday.h" 1#include "birthday.h"
2 2
3#include <opie2/ocontactaccess.h> 3#include <opie2/ocontactaccess.h>
4#include <qpe/event.h>
4 5
5#include <qobject.h> 6#include <qobject.h>
6 7
7Birthday::Birthday() 8Birthday::Birthday()
8 :Opie::Datebook::HolidayPlugin() 9 :Opie::Datebook::HolidayPlugin()
9{ 10{
10 m_contactdb = new Opie::OPimContactAccess("addressplugin"); 11 m_contactdb = new Opie::OPimContactAccess("addressplugin");
11/* 12/*
12 connect( m_contactdb, SIGNAL( signalChanged(const Opie::OPimContactAccess*) ), 13 connect( m_contactdb, SIGNAL( signalChanged(const Opie::OPimContactAccess*) ),
13 this, SLOT( refresh(const Opie::OPimContactAccess*) ) ); 14 this, SLOT( refresh(const Opie::OPimContactAccess*) ) );
14*/ 15*/
15} 16}
16 17
17QString Birthday::description() 18QString Birthday::description()
18{ 19{
19 return QObject::tr("Birthdays","holidays"); 20 return QObject::tr("Birthdays","holidays");
20} 21}
21 22
22QStringList Birthday::entries(const QDate&aDate) 23QStringList Birthday::entries(const QDate&aDate)
23{ 24{
24 QStringList ret; 25 QStringList ret;
25 if ( m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDay ) ){ 26 if ( m_contactdb->hasQuerySettings( Opie::OPimContactAccess::DateDay ) ){
26 Opie::OPimContact querybirthdays,queryanniversary; 27 Opie::OPimContact querybirthdays,queryanniversary;
27 QString pre; 28 QString pre;
28 querybirthdays.setBirthday(aDate); 29 querybirthdays.setBirthday(aDate);
29 queryanniversary.setAnniversary(aDate); 30 queryanniversary.setAnniversary(aDate);
30 m_list = m_contactdb->queryByExample( querybirthdays,Opie::OPimContactAccess::DateDay| Opie::OPimContactAccess::DateMonth); 31 m_list = m_contactdb->queryByExample( querybirthdays,Opie::OPimContactAccess::DateDay| Opie::OPimContactAccess::DateMonth);
31 if ( m_list.count() > 0 ){ 32 if ( m_list.count() > 0 ){
32 pre = QObject::tr("Birthday","holidays")+" "; 33 pre = QObject::tr("Birthday","holidays")+" ";
33 int z = 0; 34 int z = 0;
34 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 35 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
35 if (z) { 36 if (z) {
36 pre+=", "; 37 pre+=", ";
37 } 38 }
38 pre+=((*m_it).fullName()); 39 pre+=((*m_it).fullName());
39 ++z; 40 ++z;
40 } 41 }
41 ret.append(pre); 42 ret.append(pre);
42 } 43 }
43 m_list = m_contactdb->queryByExample( queryanniversary,Opie::OPimContactAccess::DateDay| Opie::OPimContactAccess::DateMonth); 44 m_list = m_contactdb->queryByExample( queryanniversary,Opie::OPimContactAccess::DateDay| Opie::OPimContactAccess::DateMonth);
44 if ( m_list.count() > 0 ){ 45 if ( m_list.count() > 0 ){
45 pre = QObject::tr("Anniversary","holidays")+" "; 46 pre = QObject::tr("Anniversary","holidays")+" ";
46 int z = 0; 47 int z = 0;
47 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) { 48 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
48 if (z) { 49 if (z) {
49 pre+=", "; 50 pre+=", ";
50 } 51 }
51 pre+=((*m_it).fullName()); 52 pre+=((*m_it).fullName());
52 ++z; 53 ++z;
53 } 54 }
54 ret.append(pre); 55 ret.append(pre);
55 } 56 }
56 } 57 }
57 return ret; 58 return ret;
58} 59}
59 60
60QStringList Birthday::entries(unsigned year, unsigned month, unsigned day) 61QStringList Birthday::entries(unsigned year, unsigned month, unsigned day)
61{ 62{
62 return entries(QDate(year,month,day)); 63 return entries(QDate(year,month,day));
63} 64}
64 65
65QMap<QDate,QStringList> Birthday::entries(const QDate&,const QDate&) 66QMap<QDate,QString> Birthday::_entries(const QDate&start,const QDate&end,bool anniversary)
67{
68 QMap<QDate,QString> ret;
69 QDate s = (start<end?start:end);
70 QDate e = (start<end?end:start);
71
72 int daysto = start.daysTo(end);
73 if (daysto < 0) {
74 daysto = end.daysTo(start);
75 }
76 if ( m_contactdb->hasQuerySettings(Opie::OPimContactAccess::DateDiff ) ){
77 Opie::OPimContact querybirthdays;
78 QString pre;
79 if (anniversary) {
80 querybirthdays.setAnniversary(e);
81 } else {
82 querybirthdays.setBirthday(e);
83 }
84 QMap<QDate,QString> collector;
85 QMap<QDate,QString>::ConstIterator sit;
86 m_list = m_contactdb->queryByExample( querybirthdays,Opie::OPimContactAccess::DateDiff,s);
87 QDate t;
88 if ( m_list.count() > 0 ){
89 if (anniversary) {
90 pre = QObject::tr("Anniversary","holidays");
91 } else {
92 pre = QObject::tr("Birthday","holidays");
93 }
94 for ( m_it = m_list.begin(); m_it != m_list.end(); ++m_it ) {
95 if (!anniversary) {
96 t.setYMD(e.year(),(*m_it).birthday().month(),(*m_it).birthday().day());
97 } else {
98 t.setYMD(e.year(),(*m_it).anniversary().month(),(*m_it).anniversary().day());
99 }
100 if (ret[t].isEmpty()) {
101 ret[t]=pre;
102 }
103 ret[t]+=" "+(*m_it).fullName();
104 }
105 }
106 }
107 return ret;
108}
109
110QMap<QDate,QStringList> Birthday::entries(const QDate&start,const QDate&end)
66{ 111{
67 QMap<QDate,QStringList> ret; 112 QMap<QDate,QStringList> ret;
113 QMap<QDate,QString> collector;
114 QMap<QDate,QString>::ConstIterator sit;
115
116 collector = _entries(start,end,false);
117 for (sit=collector.begin();sit!=collector.end();++sit) {
118 ret[sit.key()].append(sit.data());
119 }
120 collector = _entries(start,end,true);
121 for (sit=collector.begin();sit!=collector.end();++sit) {
122 ret[sit.key()].append(sit.data());
123 }
124 return ret;
125}
126
127QValueList<EffectiveEvent> Birthday::events(const QDate&start,const QDate&end)
128{
129 QValueList<EffectiveEvent> ret;
130 QMap<QDate,QString> collector;
131 QMap<QDate,QString>::ConstIterator sit;
132
133 collector = _entries(start,end,false);
134
135 for (sit=collector.begin();sit!=collector.end();++sit) {
136 Event ev;
137 ev.setAllDay(true);
138 ev.setStart(sit.key());
139 ev.setEnd(sit.key());
140 ev.setDescription(sit.data());
141 odebug << sit.key() << oendl;
142 ret.append(EffectiveEvent(ev,sit.key()));
143 }
144
145 collector = _entries(start,end,true);
146
147 for (sit=collector.begin();sit!=collector.end();++sit) {
148 Event ev;
149 ev.setAllDay(true);
150 ev.setStart(sit.key());
151 ev.setEnd(sit.key());
152 ev.setDescription(sit.data());
153 odebug << sit.key() << oendl;
154 ret.append(EffectiveEvent(ev,sit.key()));
155 }
68 return ret; 156 return ret;
69} 157}
70 158
71EXPORT_HOLIDAY_PLUGIN(Birthday); 159EXPORT_HOLIDAY_PLUGIN(Birthday);
diff --git a/core/pim/datebook/holiday/birthday/birthday.h b/core/pim/datebook/holiday/birthday/birthday.h
index 5c9aacd..c308dd0 100644
--- a/core/pim/datebook/holiday/birthday/birthday.h
+++ b/core/pim/datebook/holiday/birthday/birthday.h
@@ -1,28 +1,30 @@
1#ifndef __DUMMY_HOLIDAY_H 1#ifndef __DUMMY_HOLIDAY_H
2#define __DUMMY_HOLIDAY_H 2#define __DUMMY_HOLIDAY_H
3 3
4#include <opie2/oholidayplugin.h> 4#include <opie2/oholidayplugin.h>
5#include <opie2/oholidaypluginif.h> 5#include <opie2/oholidaypluginif.h>
6#include <opie2/ocontactaccess.h> 6#include <opie2/ocontactaccess.h>
7 7
8#include <qmap.h> 8#include <qmap.h>
9 9
10class Birthday:public Opie::Datebook::HolidayPlugin 10class Birthday:public Opie::Datebook::HolidayPlugin
11{ 11{
12typedef QMap<QDate,QStringList> tDayMap; 12typedef QMap<QDate,QStringList> tDayMap;
13 13
14public: 14public:
15 Birthday(); 15 Birthday();
16 virtual ~Birthday(){} 16 virtual ~Birthday(){}
17 17
18 virtual QString description(); 18 virtual QString description();
19 virtual QStringList entries(const QDate&); 19 virtual QStringList entries(const QDate&);
20 virtual QStringList entries(unsigned year, unsigned month, unsigned day); 20 virtual QStringList entries(unsigned year, unsigned month, unsigned day);
21 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); 21 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&);
22 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&);
22protected: 23protected:
23 Opie::OPimContactAccess * m_contactdb; 24 Opie::OPimContactAccess * m_contactdb;
24 Opie::OPimContactAccess::List m_list; 25 Opie::OPimContactAccess::List m_list;
25 Opie::OPimContactAccess::List::Iterator m_it; 26 Opie::OPimContactAccess::List::Iterator m_it;
27 virtual QMap<QDate,QString> _entries(const QDate&,const QDate&,bool anniversary);
26}; 28};
27 29
28#endif 30#endif
diff --git a/core/pim/datebook/holiday/christian/chrisholiday.cpp b/core/pim/datebook/holiday/christian/chrisholiday.cpp
index ef6516e..f8e310f 100644
--- a/core/pim/datebook/holiday/christian/chrisholiday.cpp
+++ b/core/pim/datebook/holiday/christian/chrisholiday.cpp
@@ -1,35 +1,36 @@
1#include "chrisholiday.h" 1#include "chrisholiday.h"
2 2
3#include <qobject.h> 3#include <qobject.h>
4#include <qpe/event.h>
4 5
5QString ChrisHoliday::description() 6QString ChrisHoliday::description()
6{ 7{
7 return QObject::tr("Christian holidays","holidays"); 8 return QObject::tr("Christian holidays","holidays");
8} 9}
9 10
10QStringList ChrisHoliday::entries(const QDate&aDate) 11QStringList ChrisHoliday::entries(const QDate&aDate)
11{ 12{
12 QStringList ret; 13 QStringList ret;
13 ret+=_internallist.entries(aDate); 14 ret+=_internallist.entries(aDate);
14 calcit(aDate.year()); 15 calcit(aDate.year());
15 tDayMap::Iterator it = _days.find(aDate); 16 tDayMap::Iterator it = _days.find(aDate);
16 if (it!=_days.end()) { 17 if (it!=_days.end()) {
17 ret+=*it; 18 ret+=*it;
18 } 19 }
19 20
20 return ret; 21 return ret;
21} 22}
22 23
23QStringList ChrisHoliday::entries(unsigned year, unsigned month, unsigned day) 24QStringList ChrisHoliday::entries(unsigned year, unsigned month, unsigned day)
24{ 25{
25 return entries(QDate(year,month,day)); 26 return entries(QDate(year,month,day));
26} 27}
27 28
28void ChrisHoliday::calcit(int year) 29void ChrisHoliday::calcit(int year)
29{ 30{
30 if (year==_lastyear) return; 31 if (year==_lastyear) return;
31 _lastyear = year; 32 _lastyear = year;
32 _days.clear(); 33 _days.clear();
33 calc_easter(); 34 calc_easter();
34 calc_christmas(); 35 calc_christmas();
35} 36}
@@ -58,39 +59,86 @@ void ChrisHoliday::calc_easter()
58 unsigned long c = _lastyear%100; 59 unsigned long c = _lastyear%100;
59 unsigned long d = b/4; 60 unsigned long d = b/4;
60 unsigned long e = b%4; 61 unsigned long e = b%4;
61 unsigned long f = (b+8)/25; 62 unsigned long f = (b+8)/25;
62 unsigned long g = (b+f+1)/3; 63 unsigned long g = (b+f+1)/3;
63 unsigned long h = (19*a+b-d-g+15)%30; 64 unsigned long h = (19*a+b-d-g+15)%30;
64 unsigned long i = c/4; 65 unsigned long i = c/4;
65 unsigned long j = c%4; 66 unsigned long j = c%4;
66 unsigned long k = j%100; 67 unsigned long k = j%100;
67 unsigned long l = (32+2*e+2*i-h-k)%7; 68 unsigned long l = (32+2*e+2*i-h-k)%7;
68 unsigned long m = (a+11*h+22*l)/451; 69 unsigned long m = (a+11*h+22*l)/451;
69 n = (h+l-7*m+114)/31; 70 n = (h+l-7*m+114)/31;
70 p = (h+l-7*m+114)%31; 71 p = (h+l-7*m+114)%31;
71 } else { 72 } else {
72 unsigned long a = _lastyear%4; 73 unsigned long a = _lastyear%4;
73 unsigned long b = _lastyear%7; 74 unsigned long b = _lastyear%7;
74 unsigned long c = _lastyear%19; 75 unsigned long c = _lastyear%19;
75 unsigned long d = (19*c+15)%30; 76 unsigned long d = (19*c+15)%30;
76 unsigned long e = (2*a+4*b-d+34)%7; 77 unsigned long e = (2*a+4*b-d+34)%7;
77 n = (d+e+114)/31; 78 n = (d+e+114)/31;
78 p = (d+e+114)%31; 79 p = (d+e+114)%31;
79 } 80 }
80 p++; 81 p++;
81 QDate d(_lastyear,n,p); 82 QDate d(_lastyear,n,p);
82 _days[d].append(QObject::tr("Eastersunday","holidays")); 83 _days[d].append(QObject::tr("Eastersunday","holidays"));
83 _days[d.addDays(49)].append(QObject::tr("Whitsunday","holidays")); 84 _days[d.addDays(49)].append(QObject::tr("Whitsunday","holidays"));
84 _days[d.addDays(50)].append(QObject::tr("Whitmonday","holidays")); 85 _days[d.addDays(50)].append(QObject::tr("Whitmonday","holidays"));
85 _days[d.addDays(39)].append(QObject::tr("Ascension Day","holidays")); 86 _days[d.addDays(39)].append(QObject::tr("Ascension Day","holidays"));
86 _days[d.addDays(-46)].append(QObject::tr("Ash Wednesday","holidays")); 87 _days[d.addDays(-46)].append(QObject::tr("Ash Wednesday","holidays"));
87 _days[d.addDays(60)].append(QObject::tr("Corpus Christi","holidays")); 88 _days[d.addDays(60)].append(QObject::tr("Corpus Christi","holidays"));
88} 89}
89 90
90QMap<QDate,QStringList> ChrisHoliday::entries(const QDate&,const QDate&) 91QMap<QDate,QStringList> ChrisHoliday::entries(const QDate&start,const QDate&end)
91{ 92{
92 QMap<QDate,QStringList> ret; 93 QMap<QDate,QStringList> ret;
94 if (start==end) {
95 ret[start]=entries(start);
96 return ret;
97 }
98 QDate d;
99 int daysto;
100 if (end < start) {
101 d = end;
102 daysto = end.daysTo(start);
103 } else {
104 d = start;
105 daysto = start.daysTo(end);
106 }
107 QStringList temp;
108 for (int i=0;i<daysto;++i) {
109 temp = entries(d.addDays(i));
110 if (temp.count()==0) continue;
111 ret[d.addDays(i)]+=temp;
112 temp.clear();
113 }
114 return ret;
115}
116
117QValueList<EffectiveEvent> ChrisHoliday::events(const QDate&start,const QDate&end)
118{
119 QValueList<EffectiveEvent> ret;
120 QDate d = (start<end?start:end);
121 int daysto = start.daysTo(end);
122 if (daysto < 0) {
123 daysto = end.daysTo(start);
124 }
125
126 QStringList temp;
127 for (int i =0; i<daysto;++i) {
128 temp = entries(d.addDays(i));
129 if (temp.count()==0) {
130 continue;
131 }
132 for (unsigned j=0;j<temp.count();++j) {
133 Event ev;
134 ev.setDescription(temp[j]);
135 ev.setStart(d.addDays(i));
136 ev.setAllDay(true);
137 ret.append(EffectiveEvent(ev,d.addDays(i)));
138 }
139 }
140
93 return ret; 141 return ret;
94} 142}
95 143
96EXPORT_HOLIDAY_PLUGIN(ChrisHoliday); 144EXPORT_HOLIDAY_PLUGIN(ChrisHoliday);
diff --git a/core/pim/datebook/holiday/christian/chrisholiday.h b/core/pim/datebook/holiday/christian/chrisholiday.h
index 9ae500e..1ecb813 100644
--- a/core/pim/datebook/holiday/christian/chrisholiday.h
+++ b/core/pim/datebook/holiday/christian/chrisholiday.h
@@ -1,33 +1,35 @@
1#ifndef __DUMMY_HOLIDAY_H 1#ifndef __DUMMY_HOLIDAY_H
2#define __DUMMY_HOLIDAY_H 2#define __DUMMY_HOLIDAY_H
3 3
4#include "hlist.h" 4#include "hlist.h"
5 5
6#include <opie2/oholidayplugin.h> 6#include <opie2/oholidayplugin.h>
7#include <opie2/oholidaypluginif.h> 7#include <opie2/oholidaypluginif.h>
8 8
9#include <qmap.h> 9#include <qmap.h>
10 10
11class ChrisHoliday:public Opie::Datebook::HolidayPlugin 11class ChrisHoliday:public Opie::Datebook::HolidayPlugin
12{ 12{
13typedef QMap<QDate,QStringList> tDayMap; 13typedef QMap<QDate,QStringList> tDayMap;
14 14
15public: 15public:
16 ChrisHoliday():Opie::Datebook::HolidayPlugin(){_lastyear=0;} 16 ChrisHoliday():Opie::Datebook::HolidayPlugin(){_lastyear=0;}
17 virtual ~ChrisHoliday(){} 17 virtual ~ChrisHoliday(){}
18 18
19 virtual QString description(); 19 virtual QString description();
20 virtual QStringList entries(const QDate&); 20 virtual QStringList entries(const QDate&);
21 virtual QStringList entries(unsigned year, unsigned month, unsigned day); 21 virtual QStringList entries(unsigned year, unsigned month, unsigned day);
22 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&); 22 virtual QMap<QDate,QStringList> entries(const QDate&,const QDate&);
23 virtual QValueList<EffectiveEvent> events(const QDate&,const QDate&);
24
23protected: 25protected:
24 HList _internallist; 26 HList _internallist;
25 unsigned int _lastyear; 27 unsigned int _lastyear;
26 tDayMap _days; 28 tDayMap _days;
27 29
28 void calcit(int year); 30 void calcit(int year);
29 void calc_easter(); 31 void calc_easter();
30 void calc_christmas(); 32 void calc_christmas();
31}; 33};
32 34
33#endif 35#endif