summaryrefslogtreecommitdiff
path: root/libopie2/opiepim/backend/odatebookaccessbackend.cpp
Unidiff
Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/opiepim/backend/odatebookaccessbackend.cpp174
1 files changed, 61 insertions, 113 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,7 +36,8 @@ 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 OPimEvent::ValueList& events,
40 const QDate& from, const QDate& to ) { 41 const QDate& from, const QDate& to ) {
41 QDateTime dtStart, dtEnd; 42 QDateTime dtStart, dtEnd;
42 43
@@ -48,50 +49,13 @@ namespace {
48 * If in range 49 * If in range
49 */ 50 */
50 if (dtStart.date() >= from && dtEnd.date() <= to ) { 51 if (dtStart.date() >= from && dtEnd.date() <= to ) {
51 OEffectiveEvent eff; 52 OPimBackendOccurrence eff( dtStart, dtEnd, (*it).uid() );;
52 eff.setEvent( (*it) );
53 eff.setDate( dtStart.date() );
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 ); 53 tmpList.append( eff );
63 } 54 }
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 } 55 }
92 } 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 ) {
@@ -102,48 +66,16 @@ namespace {
102 rec.setEndDate( to ); 66 rec.setEndDate( to );
103 rec.setHasEndDate( true ); 67 rec.setHasEndDate( true );
104 } 68 }
69
70 QDateTime start, end;
105 while (rec.nextOcurrence(itDate, repeat ) ) { 71 while (rec.nextOcurrence(itDate, repeat ) ) {
106 if (repeat > to ) break; 72 if (repeat > to ) break;
107 OEffectiveEvent eff; 73
108 eff.setDate( repeat ); 74 OPimEvent event = *it;
109 if ( (*it).isAllDay() ) { 75 start = QDateTime( repeat, event.startDateTime().time() );
110 eff.setStartTime( QTime(0, 0, 0 ) ); 76 end = QDateTime( repeat.addDays(dur), event.endDateTime().time() );
111 eff.setEndTime( QTime(23, 59, 59 ) ); 77 OPimBackendOccurrence eff(start, end, event.uid() );
112 }else {
113 /* we only occur by days, not hours/minutes/seconds. Hence
114 * the actual end and start times will be the same for
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 ); 78 tmpList.append( eff );
145 itDate = repeat.addDays( 1 );
146 }
147 } 79 }
148 } 80 }
149 } 81 }
@@ -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 105
179 OEffectiveEvent::ValueList tmpList; 106 return filterOccurrences( day, dt );
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 } 107 }
186 108
187 return tmpList; 109OPimBackendOccurrence::List ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
188} 110 const QDate& to )const {
189 111 OPimBackendOccurrence::List tmpList;
190OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
191 const QDate& to ) {
192 OEffectiveEvent::ValueList 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}
204 123
205 OEffectiveEvent::ValueList tmpList; 124
206 QDateTime dtTmp; 125UIDArray ODateBookAccessBackend::queryByExample( const OPimEvent&, int settings,
207 for ( it = day.begin(); it != day.end(); ++it ) { 126 const QDateTime& d )const {
208 dtTmp = QDateTime( (*it).date(), (*it).startTime() ); 127 return UIDArray();
209 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
210 tmpList.append( (*it) );
211 } 128 }
212 129
213 return tmpList; 130UIDArray ODateBookAccessBackend::sorted( const UIDArray&, bool asc, int, int, const QArray<int>& )const {
131 return UIDArray();
132}
133
134OPimBackendOccurrence::List ODateBookAccessBackend::filterOccurrences( const OPimBackendOccurrence::List dayList,
135 const QDateTime& dt ) {
136 OPimBackendOccurrence::List tmpList;
137 OPimBackendOccurrence::List::ConstIterator it;
138
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 );
214} 160}
215 161
162 return tmpList;
163}
216} 164}