author | zecke <zecke> | 2003-02-21 20:08:44 (UTC) |
---|---|---|
committer | zecke <zecke> | 2003-02-21 20:08:44 (UTC) |
commit | e09381c4b3d482c6b553a61c5fb0502a089dcc5f (patch) (unidiff) | |
tree | c336a21f6b00e09989de5309ca8bb933c9494b09 /libopie/pim | |
parent | 3b37e71ad7dd41555763d15a16c691b503780de8 (diff) | |
download | opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.zip opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.gz opie-e09381c4b3d482c6b553a61c5fb0502a089dcc5f.tar.bz2 |
-Fix hasRecurrence()
-Add the Access(Backend) of DateBook
-rw-r--r-- | libopie/pim/odatebookaccess.cpp | 37 | ||||
-rw-r--r-- | libopie/pim/odatebookaccess.h | 32 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend.cpp | 156 | ||||
-rw-r--r-- | libopie/pim/odatebookaccessbackend.h | 32 | ||||
-rw-r--r-- | libopie/pim/oevent.cpp | 13 | ||||
-rw-r--r-- | libopie/pim/oevent.h | 6 |
6 files changed, 266 insertions, 10 deletions
diff --git a/libopie/pim/odatebookaccess.cpp b/libopie/pim/odatebookaccess.cpp new file mode 100644 index 0000000..5f97e7c --- a/dev/null +++ b/libopie/pim/odatebookaccess.cpp | |||
@@ -0,0 +1,37 @@ | |||
1 | #include "obackendfactory.h" | ||
2 | #include "odatebookaccess.h" | ||
3 | |||
4 | ODateBookAccess::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 | } | ||
12 | ODateBookAccess::~ODateBookAccess() { | ||
13 | } | ||
14 | ODateBookAccess::List ODateBookAccess::rawEvents()const { | ||
15 | QArray<int> ints = m_backEnd->rawEvents(); | ||
16 | |||
17 | List lis( ints, this ); | ||
18 | return lis; | ||
19 | } | ||
20 | ODateBookAccess::List ODateBookAccess::rawRepeats()const { | ||
21 | QArray<int> ints = m_backEnd->rawRepeats(); | ||
22 | |||
23 | List lis( ints, this ); | ||
24 | return lis; | ||
25 | } | ||
26 | ODateBookAccess::List ODateBookAccess::nonRepeats()const { | ||
27 | QArray<int> ints = m_backEnd->nonRepeats(); | ||
28 | |||
29 | List lis( ints, this ); | ||
30 | return lis; | ||
31 | } | ||
32 | OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDate& from, const QDate& to ) { | ||
33 | return m_backEnd->effecticeEvents( from, to ); | ||
34 | } | ||
35 | OEffectiveEvent::ValueList ODateBookAccess::effecticeEvents( const QDateTime& start ) { | ||
36 | return m_backEnd->effecticeEvents( start ); | ||
37 | } | ||
diff --git a/libopie/pim/odatebookaccess.h b/libopie/pim/odatebookaccess.h new file mode 100644 index 0000000..3f2c728 --- a/dev/null +++ b/libopie/pim/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 | |||
9 | class ODateBookAccess : public OPimAccessTemplate<OEvent> { | ||
10 | public: | ||
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 | |||
26 | private: | ||
27 | ODateBookAccessBackend* m_backEnd; | ||
28 | class Private; | ||
29 | Private* d; | ||
30 | }; | ||
31 | |||
32 | #endif | ||
diff --git a/libopie/pim/odatebookaccessbackend.cpp b/libopie/pim/odatebookaccessbackend.cpp new file mode 100644 index 0000000..8fa1a68 --- a/dev/null +++ b/libopie/pim/odatebookaccessbackend.cpp | |||
@@ -0,0 +1,156 @@ | |||
1 | #include <qtl.h> | ||
2 | |||
3 | #include "orecur.h" | ||
4 | |||
5 | #include "odatebookaccessbackend.h" | ||
6 | |||
7 | namespace { | ||
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 | |||
122 | ODateBookAccessBackend::ODateBookAccessBackend() | ||
123 | : OPimAccessBackend<OEvent>() | ||
124 | { | ||
125 | |||
126 | } | ||
127 | ODateBookAccessBackend::~ODateBookAccessBackend() { | ||
128 | |||
129 | } | ||
130 | OEffectiveEvent::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 | } | ||
143 | OEffectiveEvent::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/libopie/pim/odatebookaccessbackend.h b/libopie/pim/odatebookaccessbackend.h new file mode 100644 index 0000000..eb6e8fb --- a/dev/null +++ b/libopie/pim/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 | |||
9 | class ODateBookAccessBackend : public OPimAccessBackend<OEvent> { | ||
10 | public: | ||
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/libopie/pim/oevent.cpp b/libopie/pim/oevent.cpp index 71b9441..aaae3b2 100644 --- a/libopie/pim/oevent.cpp +++ b/libopie/pim/oevent.cpp | |||
@@ -11,4 +11,3 @@ | |||
11 | 11 | ||
12 | namespace OCalendarHelper { | 12 | int OCalendarHelper::week( const QDate& date) { |
13 | static int week( const QDate& date) { | ||
14 | // Calculates the week this date is in within that | 13 | // Calculates the week this date is in within that |
@@ -24,3 +23,3 @@ namespace OCalendarHelper { | |||
24 | } | 23 | } |
25 | static int occurence( const QDate& date) { | 24 | int 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 |
@@ -29,3 +28,3 @@ namespace OCalendarHelper { | |||
29 | } | 28 | } |
30 | static int dayOfWeek( char day ) { | 29 | int OCalendarHelper::dayOfWeek( char day ) { |
31 | int dayOfWeek = 1; | 30 | int dayOfWeek = 1; |
@@ -38,3 +37,3 @@ namespace OCalendarHelper { | |||
38 | } | 37 | } |
39 | static int monthDiff( const QDate& first, const QDate& second ) { | 38 | int OCalendarHelper::monthDiff( const QDate& first, const QDate& second ) { |
40 | return ( second.year() - first.year() ) * 12 + | 39 | return ( second.year() - first.year() ) * 12 + |
@@ -42,3 +41,2 @@ namespace OCalendarHelper { | |||
42 | } | 41 | } |
43 | } | ||
44 | 42 | ||
@@ -132,3 +130,4 @@ void OEvent::setRecurrence( const ORecur& rec) { | |||
132 | bool OEvent::hasRecurrence()const { | 130 | bool OEvent::hasRecurrence()const { |
133 | return data->recur; | 131 | if (!data->recur ) return false; |
132 | return data->recur->doesRecur(); | ||
134 | } | 133 | } |
diff --git a/libopie/pim/oevent.h b/libopie/pim/oevent.h index 4489be7..c718e2e 100644 --- a/libopie/pim/oevent.h +++ b/libopie/pim/oevent.h | |||
@@ -15,3 +15,3 @@ | |||
15 | 15 | ||
16 | namespace OCalendarHelper { | 16 | struct OCalendarHelper { |
17 | /** calculate the week number of the date */ | 17 | /** calculate the week number of the date */ |
@@ -28,3 +28,3 @@ namespace OCalendarHelper { | |||
28 | 28 | ||
29 | } | 29 | }; |
30 | 30 | ||
@@ -141,3 +141,3 @@ class OEffectiveEvent { | |||
141 | public: | 141 | public: |
142 | QValueList<OEffectiveEvent> ValueList; | 142 | typedef QValueList<OEffectiveEvent> ValueList; |
143 | enum Position { MidWay, Start, End, StartEnd }; | 143 | enum Position { MidWay, Start, End, StartEnd }; |