summaryrefslogtreecommitdiff
path: root/libopie2/opiepim
authorzecke <zecke>2003-02-21 20:08:44 (UTC)
committer zecke <zecke>2003-02-21 20:08:44 (UTC)
commite09381c4b3d482c6b553a61c5fb0502a089dcc5f (patch) (unidiff)
treec336a21f6b00e09989de5309ca8bb933c9494b09 /libopie2/opiepim
parent3b37e71ad7dd41555763d15a16c691b503780de8 (diff)
downloadopie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.zip
opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.gz
opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.bz2
-Fix hasRecurrence()
-Add the Access(Backend) of DateBook
Diffstat (limited to 'libopie2/opiepim') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp156
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.h32
-rw-r--r--libopie2/opiepim/core/odatebookaccess.cpp37
-rw-r--r--libopie2/opiepim/core/odatebookaccess.h32
-rw-r--r--libopie2/opiepim/oevent.cpp57
-rw-r--r--libopie2/opiepim/oevent.h6
6 files changed, 288 insertions, 32 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
new file mode 100644
index 0000000..8fa1a68
--- a/dev/null
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -0,0 +1,156 @@
1#include <qtl.h>
2
3#include "orecur.h"
4
5#include "odatebookaccessbackend.h"
6
7namespace {
8/* a small helper to get all NonRepeating events for a range of time */
9 void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events,
10 const QDate& from, const QDate& to ) {
11 QDateTime dtStart, dtEnd;
12
13 for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
14 dtStart = (*it).startDateTime();
15 dtEnd = (*it).endDateTime();
16
17 /*
18 * If in range
19 */
20 if (dtStart.date() >= from && dtEnd.date() <= to ) {
21 OEffectiveEvent eff;
22 eff.setEvent( (*it) );
23 eff.setDate( dtStart.date() );
24 eff.setStartTime( dtStart.time() );
25
26 /* if not on the same day */
27 if ( dtStart.date() != dtEnd.date() )
28 eff.setEndTime( QTime(23, 59, 0 ) );
29 else
30 eff.setEndTime( dtEnd.time() );
31
32 tmpList.append( eff );
33 }
34
35 /* we must also check for end date information... */
36 if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
37 QDateTime dt = dtStart.addDays( 1 );
38 dt.setTime( QTime(0, 0, 0 ) );
39 QDateTime dtStop;
40 if ( dtEnd > to )
41 dtStop = to;
42 else
43 dtStop = dtEnd;
44
45 while ( dt <= dtStop ) {
46 OEffectiveEvent eff;
47 eff.setEvent( (*it) );
48 eff.setDate( dt.date() );
49
50 if ( dt >= from ) {
51 eff.setStartTime( QTime(0, 0, 0 ) );
52 if ( dt.date() == dtEnd.date() )
53 eff.setEndTime( dtEnd.time() );
54 else
55 eff.setEndTime( QTime(23, 59, 0 ) );
56 tmpList.append( eff );
57 }
58 dt = dt.addDays( 1 );
59 }
60 }
61 }
62 }
63
64 void repeat( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& list,
65 const QDate& from, const QDate& to ) {
66 QDate repeat;
67 for ( OEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
68 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
69 QDate itDate = from.addDays(-dur );
70 ORecur rec = (*it).recurrence();
71 if ( !rec.hasEndDate() || rec.endDate() > to ) {
72 rec.setEndDate( to );
73 rec.setHasEndDate( true );
74 }
75 while (rec.nextOcurrence(itDate, repeat ) ) {
76 if (repeat > to ) break;
77 OEffectiveEvent eff;
78 eff.setDate( repeat );
79 if ( (*it).isAllDay() ) {
80 eff.setStartTime( QTime(0, 0, 0 ) );
81 eff.setEndTime( QTime(23, 59, 59 ) );
82 }else {
83 /* we only occur by days, not hours/minutes/seconds. Hence
84 * the actual end and start times will be the same for
85 * every repeated event. For multi day events this is
86 * fixed up later if on wronge day span
87 */
88 eff.setStartTime( (*it).startDateTime().time() );
89 eff.setEndTime( (*it).endDateTime().time() );
90 }
91 if ( dur != 0 ) {
92 // multi-day repeating events
93 QDate sub_it = QMAX( repeat, from );
94 QDate startDate = repeat;
95 QDate endDate = startDate.addDays( dur );
96
97 while ( sub_it <= endDate && sub_it <= to ) {
98 OEffectiveEvent tmpEff = eff;
99 tmpEff.setEvent( (*it) );
100 if ( sub_it != startDate )
101 tmpEff.setStartTime( QTime(0, 0, 0 ) );
102 if ( sub_it != endDate )
103 tmpEff.setEndTime( QTime( 23, 59, 59 ) );
104
105 tmpEff.setDate( sub_it );
106 tmpEff.setEffectiveDates( startDate, endDate );
107 tmpList.append( tmpEff );
108
109 sub_it = sub_it.addDays( 1 );
110 }
111 itDate = endDate;
112 }else {
113 eff.setEvent( (*it) );
114 tmpList.append( eff );
115 itDate = repeat.addDays( 1 );
116 }
117 }
118 }
119 }
120}
121
122ODateBookAccessBackend::ODateBookAccessBackend()
123 : OPimAccessBackend<OEvent>()
124{
125
126}
127ODateBookAccessBackend::~ODateBookAccessBackend() {
128
129}
130OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDate& from,
131 const QDate& to ) {
132 OEffectiveEvent::ValueList tmpList;
133 OEvent::ValueList list = directNonRepeats();
134
135 events( tmpList, list, from, to );
136 repeat( tmpList, directRawRepeats(),from,to );
137
138 list = directRawRepeats();
139
140 qHeapSort( tmpList );
141 return tmpList;
142}
143OEffectiveEvent::ValueList ODateBookAccessBackend::effecticeEvents( const QDateTime& dt ) {
144 OEffectiveEvent::ValueList day = effecticeEvents( dt.date(), dt.date() );
145 OEffectiveEvent::ValueList::Iterator it;
146
147 OEffectiveEvent::ValueList tmpList;
148 QDateTime dtTmp;
149 for ( it = day.begin(); it != day.end(); ++it ) {
150 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
151 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
152 tmpList.append( (*it) );
153 }
154
155 return tmpList;
156}
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.h b/libopie2/opiepim/backend/odatebookaccessbackend.h
new file mode 100644
index 0000000..eb6e8fb
--- a/dev/null
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.h
@@ -0,0 +1,32 @@
1#ifndef OPIE_DATE_BOOK_ACCESS_BACKEND_H
2#define OPIE_DATE_BOOK_ACCESS_BACKEND_H
3
4#include <qarray.h>
5
6#include "opimaccessbackend.h"
7#include "oevent.h"
8
9class ODateBookAccessBackend : public OPimAccessBackend<OEvent> {
10public:
11 typedef int UID;
12 ODateBookAccessBackend();
13 ~ODateBookAccessBackend();
14
15 virtual QArray<UID> rawEvents()const = 0;
16 virtual QArray<UID> rawRepeats()const = 0;
17 virtual QArray<UID> nonRepeats() const = 0;
18
19 /**
20 * these two methods are used if you do not implement
21 * effectiveEvents...
22 */
23 virtual OEvent::ValueList directNonRepeats() = 0;
24 virtual OEvent::ValueList directRawRepeats() = 0;
25
26 /* is implemented by default but you can reimplement it*/
27 virtual OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
28 virtual OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
29
30};
31
32#endif
diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp
new file mode 100644
index 0000000..5f97e7c
--- a/dev/null
+++ b/libopie2/opiepim/core/odatebookaccess.cpp
@@ -0,0 +1,37 @@
1#include "obackendfactory.h"
2#include "odatebookaccess.h"
3
4ODateBookAccess::ODateBookAccess( ODateBookAccessBackend* back, enum Access ac )
5 : OPimAccessTemplate<OEvent>( back )
6{
7 if (!back )
8 back = OBackendFactory<ODateBookAccessBackend>::Default("datebook", QString::null );
9
10 m_backEnd = back;
11}
12ODateBookAccess::~ODateBookAccess() {
13}
14ODateBookAccess::List ODateBookAccess::rawEvents()const {
15 QArray<int> ints = m_backEnd->rawEvents();
16
17 List lis( ints, this );
18 return lis;
19}
20ODateBookAccess::List ODateBookAccess::rawRepeats()const {
21 QArray<int> ints = m_backEnd->rawRepeats();
22
23 List lis( ints, this );
24 return lis;
25}
26ODateBookAccess::List ODateBookAccess::nonRepeats()const {
27 QArray<int> ints = m_backEnd->nonRepeats();
28
29 List lis( ints, this );
30 return lis;
31}
32OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDate& from, const QDate& to ) {
33 return m_backEnd->effecticeEvents( from, to );
34}
35OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDateTime& start ) {
36 return m_backEnd->effecticeEvents( start );
37}
diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h
new file mode 100644
index 0000000..3f2c728
--- a/dev/null
+++ b/libopie2/opiepim/core/odatebookaccess.h
@@ -0,0 +1,32 @@
1#ifndef OPIE_DATE_BOOK_ACCESS_H
2#define OPIE_DATE_BOOK_ACCESS_H
3
4#include "odatebookaccessbackend.h"
5#include "opimaccesstemplate.h"
6
7#include "oevent.h"
8
9class ODateBookAccess : public OPimAccessTemplate<OEvent> {
10public:
11 ODateBookAccess( ODateBookAccessBackend* = 0l, enum Access acc = Random );
12 ~ODateBookAccess();
13
14 /** return all events */
15 List rawEvents()const;
16
17 /** return repeating events */
18 List rawRepeats()const;
19
20 /** return non repeating events */
21 List nonRepeats()const;
22
23 OEffectiveEvent::ValueList effecticeEvents( const QDate& from, const QDate& to );
24 OEffectiveEvent::ValueList effecticeEvents( const QDateTime& start );
25
26private:
27 ODateBookAccessBackend* m_backEnd;
28 class Private;
29 Private* d;
30};
31
32#endif
diff --git a/libopie2/opiepim/oevent.cpp b/libopie2/opiepim/oevent.cpp
index 71b9441..aaae3b2 100644
--- a/libopie2/opiepim/oevent.cpp
+++ b/libopie2/opiepim/oevent.cpp
@@ -1,54 +1,52 @@
1#include <qshared.h> 1#include <qshared.h>
2 2
3#include <qpe/palmtopuidgen.h> 3#include <qpe/palmtopuidgen.h>
4#include <qpe/categories.h> 4#include <qpe/categories.h>
5 5
6#include "orecur.h" 6#include "orecur.h"
7#include "opimresolver.h" 7#include "opimresolver.h"
8#include "opimnotifymanager.h" 8#include "opimnotifymanager.h"
9 9
10#include "oevent.h" 10#include "oevent.h"
11 11
12namespace OCalendarHelper { 12int OCalendarHelper::week( const QDate& date) {
13 static int week( const QDate& date) { 13 // Calculates the week this date is in within that
14 // Calculates the week this date is in within that 14 // month. Equals the "row" is is in in the month view
15 // month. Equals the "row" is is in in the month view 15 int week = 1;
16 int week = 1; 16 QDate tmp( date.year(), date.month(), 1 );
17 QDate tmp( date.year(), date.month(), 1 ); 17 if ( date.dayOfWeek() < tmp.dayOfWeek() )
18 if ( date.dayOfWeek() < tmp.dayOfWeek() ) 18 ++week;
19 ++week;
20 19
21 week += ( date.day() - 1 ) / 7; 20 week += ( date.day() - 1 ) / 7;
22 21
23 return week; 22 return week;
24 } 23}
25 static int occurence( const QDate& date) { 24int OCalendarHelper::ocurrence( const QDate& date) {
26 // calculates the number of occurrances of this day of the 25 // calculates the number of occurrances of this day of the
27 // week till the given date (e.g 3rd Wednesday of the month) 26 // week till the given date (e.g 3rd Wednesday of the month)
28 return ( date.day() - 1 ) / 7 + 1; 27 return ( date.day() - 1 ) / 7 + 1;
29 } 28}
30 static int dayOfWeek( char day ) { 29int OCalendarHelper::dayOfWeek( char day ) {
31 int dayOfWeek = 1; 30 int dayOfWeek = 1;
32 char i = ORecur::MON; 31 char i = ORecur::MON;
33 while ( !( i & day ) && i <= ORecur::SUN ) { 32 while ( !( i & day ) && i <= ORecur::SUN ) {
34 i <<= 1; 33 i <<= 1;
35 ++dayOfWeek; 34 ++dayOfWeek;
36 }
37 return dayOfWeek;
38 }
39 static int monthDiff( const QDate& first, const QDate& second ) {
40 return ( second.year() - first.year() ) * 12 +
41 second.month() - first.month();
42 } 35 }
36 return dayOfWeek;
37}
38int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) {
39 return ( second.year() - first.year() ) * 12 +
40 second.month() - first.month();
43} 41}
44 42
45struct OEvent::Data : public QShared { 43struct OEvent::Data : public QShared {
46 Data() : QShared() { 44 Data() : QShared() {
47 recur = 0; 45 recur = 0;
48 manager = 0; 46 manager = 0;
49 isAllDay = false; 47 isAllDay = false;
50 } 48 }
51 ~Data() { 49 ~Data() {
52 delete manager; 50 delete manager;
53 delete recur; 51 delete recur;
54 } 52 }
@@ -121,25 +119,26 @@ ORecur OEvent::recurrence()const {
121 data->recur = new ORecur; 119 data->recur = new ORecur;
122 120
123 return *data->recur; 121 return *data->recur;
124} 122}
125void OEvent::setRecurrence( const ORecur& rec) { 123void OEvent::setRecurrence( const ORecur& rec) {
126 changeOrModify(); 124 changeOrModify();
127 if (data->recur ) 125 if (data->recur )
128 (*data->recur) = rec; 126 (*data->recur) = rec;
129 else 127 else
130 data->recur = new ORecur( rec ); 128 data->recur = new ORecur( rec );
131} 129}
132bool OEvent::hasRecurrence()const { 130bool OEvent::hasRecurrence()const {
133 return data->recur; 131 if (!data->recur ) return false;
132 return data->recur->doesRecur();
134} 133}
135QString OEvent::note()const { 134QString OEvent::note()const {
136 return data->note; 135 return data->note;
137} 136}
138void OEvent::setNote( const QString& note ) { 137void OEvent::setNote( const QString& note ) {
139 changeOrModify(); 138 changeOrModify();
140 data->note = note; 139 data->note = note;
141} 140}
142QDateTime OEvent::createdDateTime()const { 141QDateTime OEvent::createdDateTime()const {
143 return data->created; 142 return data->created;
144} 143}
145void OEvent::setCreatedDateTime( const QDateTime& time ) { 144void OEvent::setCreatedDateTime( const QDateTime& time ) {
diff --git a/libopie2/opiepim/oevent.h b/libopie2/opiepim/oevent.h
index 4489be7..c718e2e 100644
--- a/libopie2/opiepim/oevent.h
+++ b/libopie2/opiepim/oevent.h
@@ -4,38 +4,38 @@
4#define OPIE_PIM_EVENT_H 4#define OPIE_PIM_EVENT_H
5 5
6#include <qstring.h> 6#include <qstring.h>
7#include <qdatetime.h> 7#include <qdatetime.h>
8#include <qvaluelist.h> 8#include <qvaluelist.h>
9 9
10#include <qpe/recordfields.h> 10#include <qpe/recordfields.h>
11#include <qpe/palmtopuidgen.h> 11#include <qpe/palmtopuidgen.h>
12 12
13#include "otimezone.h" 13#include "otimezone.h"
14#include "opimrecord.h" 14#include "opimrecord.h"
15 15
16namespace OCalendarHelper { 16struct OCalendarHelper {
17 /** calculate the week number of the date */ 17 /** calculate the week number of the date */
18 static int week( const QDate& ); 18 static int week( const QDate& );
19 /** calculate the occurence of week days since the start of the month */ 19 /** calculate the occurence of week days since the start of the month */
20 static int ocurrence( const QDate& ); 20 static int ocurrence( const QDate& );
21 21
22 // returns the dayOfWeek for the *first* day it finds (ignores 22 // returns the dayOfWeek for the *first* day it finds (ignores
23 // any further days!). Returns 1 (Monday) if there isn't any day found 23 // any further days!). Returns 1 (Monday) if there isn't any day found
24 static int dayOfWeek( char day ); 24 static int dayOfWeek( char day );
25 25
26 /** returns the diff of month */ 26 /** returns the diff of month */
27 static int monthDiff( const QDate& first, const QDate& second ); 27 static int monthDiff( const QDate& first, const QDate& second );
28 28
29} 29};
30 30
31class OPimNotifyManager; 31class OPimNotifyManager;
32class ORecur; 32class ORecur;
33class OEvent : public OPimRecord { 33class OEvent : public OPimRecord {
34public: 34public:
35 typedef QValueList<OEvent> ValueList; 35 typedef QValueList<OEvent> ValueList;
36 enum RecordFields { 36 enum RecordFields {
37 Uid = Qtopia::UID_ID, 37 Uid = Qtopia::UID_ID,
38 Category = Qtopia::CATEGORY_ID, 38 Category = Qtopia::CATEGORY_ID,
39 Description, 39 Description,
40 Location, 40 Location,
41 Alarm, 41 Alarm,
@@ -130,25 +130,25 @@ private:
130 Data* data; 130 Data* data;
131 class Private; 131 class Private;
132 Private* priv; 132 Private* priv;
133 133
134}; 134};
135 135
136/** 136/**
137 * AN Event can span through multiple days. We split up a multiday eve 137 * AN Event can span through multiple days. We split up a multiday eve
138 */ 138 */
139 139
140class OEffectiveEvent { 140class OEffectiveEvent {
141public: 141public:
142 QValueList<OEffectiveEvent> ValueList; 142 typedef QValueList<OEffectiveEvent> ValueList;
143 enum Position { MidWay, Start, End, StartEnd }; 143 enum Position { MidWay, Start, End, StartEnd };
144 // If we calculate the effective event of a multi-day event 144 // If we calculate the effective event of a multi-day event
145 // we have to figure out whether we are at the first day, 145 // we have to figure out whether we are at the first day,
146 // at the end, or anywhere else ("middle"). This is important 146 // at the end, or anywhere else ("middle"). This is important
147 // for the start/end times (00:00/23:59) 147 // for the start/end times (00:00/23:59)
148 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi- 148 // MidWay: 00:00 -> 23:59, as we are "in the middle" of a multi-
149 // day event 149 // day event
150 // Start: start time -> 23:59 150 // Start: start time -> 23:59
151 // End: 00:00 -> end time 151 // End: 00:00 -> end time
152 // Start | End == StartEnd: for single-day events (default) 152 // Start | End == StartEnd: for single-day events (default)
153 // here we draw start time -> end time 153 // here we draw start time -> end time
154 OEffectiveEvent(); 154 OEffectiveEvent();