summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp228
1 files changed, 88 insertions, 140 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
index f3b7b5f..73c7059 100644
--- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp
+++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp
@@ -36,118 +36,50 @@ using namespace Opie;
36 36
37namespace { 37namespace {
38/* a small helper to get all NonRepeating events for a range of time */ 38/* a small helper to get all NonRepeating events for a range of time */
39 void events( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& events, 39void events( OPimBackendOccurrence::List& tmpList,
40 const QDate& from, const QDate& to ) { 40 const OPimEvent::ValueList& events,
41 QDateTime dtStart, dtEnd; 41 const QDate& from, const QDate& to ) {
42 42 QDateTime dtStart, dtEnd;
43 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { 43
44 dtStart = (*it).startDateTime(); 44 for ( OPimEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
45 dtEnd = (*it).endDateTime(); 45 dtStart = (*it).startDateTime();
46 46 dtEnd = (*it).endDateTime();
47 /* 47
48 * If in range 48 /*
49 */ 49 * If in range
50 if (dtStart.date() >= from && dtEnd.date() <= to ) { 50 */
51 OEffectiveEvent eff; 51 if (dtStart.date() >= from && dtEnd.date() <= to ) {
52 eff.setEvent( (*it) ); 52 OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
53 eff.setDate( dtStart.date() ); 53 tmpList.append( eff );
54 eff.setStartTime( dtStart.time() );
55
56 /* if not on the same day */
57 if ( dtStart.date() != dtEnd.date() )
58 eff.setEndTime( QTime(23, 59, 0 ) );
59 else
60 eff.setEndTime( dtEnd.time() );
61
62 tmpList.append( eff );
63 }
64
65 /* we must also check for end date information... */
66 if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
67 QDateTime dt = dtStart.addDays( 1 );
68 dt.setTime( QTime(0, 0, 0 ) );
69 QDateTime dtStop;
70 if ( dtEnd > to )
71 dtStop = to;
72 else
73 dtStop = dtEnd;
74
75 while ( dt <= dtStop ) {
76 OEffectiveEvent eff;
77 eff.setEvent( (*it) );
78 eff.setDate( dt.date() );
79
80 if ( dt >= from ) {
81 eff.setStartTime( QTime(0, 0, 0 ) );
82 if ( dt.date() == dtEnd.date() )
83 eff.setEndTime( dtEnd.time() );
84 else
85 eff.setEndTime( QTime(23, 59, 0 ) );
86 tmpList.append( eff );
87 }
88 dt = dt.addDays( 1 );
89 }
90 }
91 } 54 }
92 } 55 }
56}
93 57
94 void repeat( OEffectiveEvent::ValueList& tmpList, const OPimEvent::ValueList& list, 58void repeat( OPimBackendOccurrence::List& tmpList, const OPimEvent::ValueList& list,
95 const QDate& from, const QDate& to ) { 59 const QDate& from, const QDate& to ) {
96 QDate repeat; 60 QDate repeat;
97 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) { 61 for ( OPimEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
98 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() ); 62 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
99 QDate itDate = from.addDays(-dur ); 63 QDate itDate = from.addDays(-dur );
100 OPimRecurrence rec = (*it).recurrence(); 64 OPimRecurrence rec = (*it).recurrence();
101 if ( !rec.hasEndDate() || rec.endDate() > to ) { 65 if ( !rec.hasEndDate() || rec.endDate() > to ) {
102 rec.setEndDate( to ); 66 rec.setEndDate( to );
103 rec.setHasEndDate( true ); 67 rec.setHasEndDate( true );
104 } 68 }
105 while (rec.nextOcurrence(itDate, repeat ) ) { 69
106 if (repeat > to ) break; 70 QDateTime start, end;
107 OEffectiveEvent eff; 71 while (rec.nextOcurrence(itDate, repeat ) ) {
108 eff.setDate( repeat ); 72 if (repeat > to ) break;
109 if ( (*it).isAllDay() ) { 73
110 eff.setStartTime( QTime(0, 0, 0 ) ); 74 OPimEvent event = *it;
111 eff.setEndTime( QTime(23, 59, 59 ) ); 75 start = QDateTime( repeat, event.startDateTime().time() );
112 }else { 76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
113 /* we only occur by days, not hours/minutes/seconds. Hence 77 OPimBackendOccurrence eff(start, end, event.uid() );
114 * the actual end and start times will be the same for 78 tmpList.append( eff );
115 * every repeated event. For multi day events this is
116 * fixed up later if on wronge day span
117 */
118 eff.setStartTime( (*it).startDateTime().time() );
119 eff.setEndTime( (*it).endDateTime().time() );
120 }
121 if ( dur != 0 ) {
122 // multi-day repeating events
123 QDate sub_it = QMAX( repeat, from );
124 QDate startDate = repeat;
125 QDate endDate = startDate.addDays( dur );
126
127 while ( sub_it <= endDate && sub_it <= to ) {
128 OEffectiveEvent tmpEff = eff;
129 tmpEff.setEvent( (*it) );
130 if ( sub_it != startDate )
131 tmpEff.setStartTime( QTime(0, 0, 0 ) );
132 if ( sub_it != endDate )
133 tmpEff.setEndTime( QTime( 23, 59, 59 ) );
134
135 tmpEff.setDate( sub_it );
136 tmpEff.setEffectiveDates( startDate, endDate );
137 tmpList.append( tmpEff );
138
139 sub_it = sub_it.addDays( 1 );
140 }
141 itDate = endDate;
142 }else {
143 eff.setEvent( (*it) );
144 tmpList.append( eff );
145 itDate = repeat.addDays( 1 );
146 }
147 }
148 } 79 }
149 } 80 }
150} 81}
82}
151 83
152namespace Opie { 84namespace Opie {
153 85
@@ -159,58 +91,74 @@ ODateBookAccessBackend::ODateBookAccessBackend()
159ODateBookAccessBackend::~ODateBookAccessBackend() { 91ODateBookAccessBackend::~ODateBookAccessBackend() {
160 92
161} 93}
162OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, 94OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDate& from,
163 const QDate& to ) { 95 const QDate& to )const {
164 OEffectiveEvent::ValueList tmpList; 96 OPimBackendOccurrence::List tmpList;
165 OPimEvent::ValueList list = directNonRepeats();
166 97
167 events( tmpList, list, from, to ); 98 events( tmpList, directNonRepeats(), from, to );
168 repeat( tmpList, directRawRepeats(),from,to ); 99 repeat( tmpList, directRawRepeats(),from,to );
169 100
170 list = directRawRepeats(); // Useless, isn't it ? (eilers)
171
172 qHeapSort( tmpList );
173 return tmpList; 101 return tmpList;
174} 102}
175OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { 103OPimBackendOccurrence::List ODateBookAccessBackend::occurrences( const QDateTime& dt )const {
176 OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); 104 OPimBackendOccurrence::List day = occurrences( dt.date(), dt.date() );
177 OEffectiveEvent::ValueList::Iterator it;
178
179 OEffectiveEvent::ValueList tmpList;
180 QDateTime dtTmp;
181 for ( it = day.begin(); it != day.end(); ++it ) {
182 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
183 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
184 tmpList.append( (*it) );
185 }
186 105
187 return tmpList; 106 return filterOccurrences( day, dt );
188} 107}
189 108
190OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from, 109OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
191 const QDate& to ) { 110 const QDate& to )const {
192 OEffectiveEvent::ValueList tmpList; 111 OPimBackendOccurrence::List tmpList;
193 OPimEvent::ValueList list = directNonRepeats(); 112 OPimEvent::ValueList list = directNonRepeats();
194 113
195 events( tmpList, list, from, to ); 114 events( tmpList, list, from, to );
196 115
197 qHeapSort( tmpList );
198 return tmpList; 116 return tmpList;
199} 117}
200 118
201OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { 119OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt )const {
202 OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); 120 OPimBackendOccurrence::List day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
203 OEffectiveEvent::ValueList::Iterator it; 121 return filterOccurrences( day,dt );
122}
123
124
125UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
126 const QDateTime& d )const {
127 return UIDArray();
128}
129
130UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
131 return UIDArray();
132}
204 133
205 OEffectiveEvent::ValueList tmpList; 134OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
206 QDateTime dtTmp; 135 const QDateTime& dt ) {
207 for ( it = day.begin(); it != day.end(); ++it ) { 136 OPimBackendOccurrence::List tmpList;
208 dtTmp = QDateTime( (*it).date(), (*it).startTime() ); 137 OPimBackendOccurrence::List::ConstIterator it;
209 if ( QABS(dt.secsTo(dtTmp) ) < 60 ) 138
210 tmpList.append( (*it) ); 139 for ( it = dayList.begin(); it != dayList.end(); ++it ) {
140 OPimBackendOccurrence occ = *it;
141
142 /*
143 * Let us find occurrences that are 'now'!
144 * If the dt.date() is on the same day as start or end of the Occurrence
145 * check how near start/end are.
146 * If it is in the middle of a multiday occurrence list it.
147 *
148 * We might want to 'lose' the sixty second offset and list
149 * all Events which are active at that time.
150 */
151 if ( dt.date() == occ.startDateTime().date() ) {
152 if ( QABS( dt.time().secsTo( occ.startDateTime().time() ) ) < 60 )
153 tmpList.append( occ );
154 }else if ( dt.date() == occ.endDateTime().date() ) {
155 if ( QABS( dt.time().secsTo( occ.endDateTime().time() ) ) < 60 )
156 tmpList.append( occ );
157 }else if ( dt.date() >= occ.startDateTime().date() &&
158 dt.date() >= occ.endDateTime().date() )
159 tmpList.append( occ );
211 } 160 }
212 161
213 return tmpList; 162 return tmpList;
214} 163}
215
216} 164}