Diffstat (limited to 'libopie2/opiepim/backend/odatebookaccessbackend.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/backend/odatebookaccessbackend.cpp | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/libopie2/opiepim/backend/odatebookaccessbackend.cpp b/libopie2/opiepim/backend/odatebookaccessbackend.cpp index f0c5d65..9bf4bf0 100644 --- a/libopie2/opiepim/backend/odatebookaccessbackend.cpp +++ b/libopie2/opiepim/backend/odatebookaccessbackend.cpp | |||
@@ -1,29 +1,59 @@ | |||
1 | /* | ||
2 | This file is part of the Opie Project | ||
3 | Copyright (C) Stefan Eilers (Eilers.Stefan@epost.de) | ||
4 | =. Copyright (C) The Opie Team <opie-devel@handhelds.org> | ||
5 | .=l. | ||
6 | .>+-= | ||
7 | _;:, .> :=|. This program is free software; you can | ||
8 | .> <`_, > . <= redistribute it and/or modify it under | ||
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | ||
10 | .="- .-=="i, .._ License as published by the Free Software | ||
11 | - . .-<_> .<> Foundation; either version 2 of the License, | ||
12 | ._= =} : or (at your option) any later version. | ||
13 | .%`+i> _;_. | ||
14 | .i_,=:_. -<s. This program is distributed in the hope that | ||
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | ||
16 | : .. .:, . . . without even the implied warranty of | ||
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | ||
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | ||
19 | ..}^=.= = ; Library General Public License for more | ||
20 | ++= -. .` .: details. | ||
21 | : = ...= . :.=- | ||
22 | -. .:....=;==+<; You should have received a copy of the GNU | ||
23 | -_. . . )=. = Library General Public License along with | ||
24 | -- :-=` this library; see the file COPYING.LIB. | ||
25 | If not, write to the Free Software Foundation, | ||
26 | Inc., 59 Temple Place - Suite 330, | ||
27 | Boston, MA 02111-1307, USA. | ||
28 | */ | ||
1 | #include <qtl.h> | 29 | #include <qtl.h> |
2 | 30 | ||
3 | #include "orecur.h" | 31 | #include <opie2/orecur.h> |
32 | |||
33 | #include <opie2/odatebookaccessbackend.h> | ||
4 | 34 | ||
5 | #include "odatebookaccessbackend.h" | 35 | using namespace Opie; |
6 | 36 | ||
7 | namespace { | 37 | namespace { |
8 | /* 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 */ |
9 | void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events, | 39 | void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events, |
10 | const QDate& from, const QDate& to ) { | 40 | const QDate& from, const QDate& to ) { |
11 | QDateTime dtStart, dtEnd; | 41 | QDateTime dtStart, dtEnd; |
12 | 42 | ||
13 | for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { | 43 | for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) { |
14 | dtStart = (*it).startDateTime(); | 44 | dtStart = (*it).startDateTime(); |
15 | dtEnd = (*it).endDateTime(); | 45 | dtEnd = (*it).endDateTime(); |
16 | 46 | ||
17 | /* | 47 | /* |
18 | * If in range | 48 | * If in range |
19 | */ | 49 | */ |
20 | if (dtStart.date() >= from && dtEnd.date() <= to ) { | 50 | if (dtStart.date() >= from && dtEnd.date() <= to ) { |
21 | OEffectiveEvent eff; | 51 | OEffectiveEvent eff; |
22 | eff.setEvent( (*it) ); | 52 | eff.setEvent( (*it) ); |
23 | eff.setDate( dtStart.date() ); | 53 | eff.setDate( dtStart.date() ); |
24 | eff.setStartTime( dtStart.time() ); | 54 | eff.setStartTime( dtStart.time() ); |
25 | 55 | ||
26 | /* if not on the same day */ | 56 | /* if not on the same day */ |
27 | if ( dtStart.date() != dtEnd.date() ) | 57 | if ( dtStart.date() != dtEnd.date() ) |
28 | eff.setEndTime( QTime(23, 59, 0 ) ); | 58 | eff.setEndTime( QTime(23, 59, 0 ) ); |
29 | else | 59 | else |
@@ -98,48 +128,50 @@ namespace { | |||
98 | OEffectiveEvent tmpEff = eff; | 128 | OEffectiveEvent tmpEff = eff; |
99 | tmpEff.setEvent( (*it) ); | 129 | tmpEff.setEvent( (*it) ); |
100 | if ( sub_it != startDate ) | 130 | if ( sub_it != startDate ) |
101 | tmpEff.setStartTime( QTime(0, 0, 0 ) ); | 131 | tmpEff.setStartTime( QTime(0, 0, 0 ) ); |
102 | if ( sub_it != endDate ) | 132 | if ( sub_it != endDate ) |
103 | tmpEff.setEndTime( QTime( 23, 59, 59 ) ); | 133 | tmpEff.setEndTime( QTime( 23, 59, 59 ) ); |
104 | 134 | ||
105 | tmpEff.setDate( sub_it ); | 135 | tmpEff.setDate( sub_it ); |
106 | tmpEff.setEffectiveDates( startDate, endDate ); | 136 | tmpEff.setEffectiveDates( startDate, endDate ); |
107 | tmpList.append( tmpEff ); | 137 | tmpList.append( tmpEff ); |
108 | 138 | ||
109 | sub_it = sub_it.addDays( 1 ); | 139 | sub_it = sub_it.addDays( 1 ); |
110 | } | 140 | } |
111 | itDate = endDate; | 141 | itDate = endDate; |
112 | }else { | 142 | }else { |
113 | eff.setEvent( (*it) ); | 143 | eff.setEvent( (*it) ); |
114 | tmpList.append( eff ); | 144 | tmpList.append( eff ); |
115 | itDate = repeat.addDays( 1 ); | 145 | itDate = repeat.addDays( 1 ); |
116 | } | 146 | } |
117 | } | 147 | } |
118 | } | 148 | } |
119 | } | 149 | } |
120 | } | 150 | } |
121 | 151 | ||
152 | namespace Opie { | ||
153 | |||
122 | ODateBookAccessBackend::ODateBookAccessBackend() | 154 | ODateBookAccessBackend::ODateBookAccessBackend() |
123 | : OPimAccessBackend<OEvent>() | 155 | : OPimAccessBackend<OEvent>() |
124 | { | 156 | { |
125 | 157 | ||
126 | } | 158 | } |
127 | ODateBookAccessBackend::~ODateBookAccessBackend() { | 159 | ODateBookAccessBackend::~ODateBookAccessBackend() { |
128 | 160 | ||
129 | } | 161 | } |
130 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, | 162 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from, |
131 | const QDate& to ) { | 163 | const QDate& to ) { |
132 | OEffectiveEvent::ValueList tmpList; | 164 | OEffectiveEvent::ValueList tmpList; |
133 | OEvent::ValueList list = directNonRepeats(); | 165 | OEvent::ValueList list = directNonRepeats(); |
134 | 166 | ||
135 | events( tmpList, list, from, to ); | 167 | events( tmpList, list, from, to ); |
136 | repeat( tmpList, directRawRepeats(),from,to ); | 168 | repeat( tmpList, directRawRepeats(),from,to ); |
137 | 169 | ||
138 | list = directRawRepeats(); // Useless, isn't it ? (eilers) | 170 | list = directRawRepeats(); // Useless, isn't it ? (eilers) |
139 | 171 | ||
140 | qHeapSort( tmpList ); | 172 | qHeapSort( tmpList ); |
141 | return tmpList; | 173 | return tmpList; |
142 | } | 174 | } |
143 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { | 175 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) { |
144 | OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); | 176 | OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() ); |
145 | OEffectiveEvent::ValueList::Iterator it; | 177 | OEffectiveEvent::ValueList::Iterator it; |
@@ -159,24 +191,26 @@ OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( | |||
159 | const QDate& to ) { | 191 | const QDate& to ) { |
160 | OEffectiveEvent::ValueList tmpList; | 192 | OEffectiveEvent::ValueList tmpList; |
161 | OEvent::ValueList list = directNonRepeats(); | 193 | OEvent::ValueList list = directNonRepeats(); |
162 | 194 | ||
163 | events( tmpList, list, from, to ); | 195 | events( tmpList, list, from, to ); |
164 | 196 | ||
165 | qHeapSort( tmpList ); | 197 | qHeapSort( tmpList ); |
166 | return tmpList; | 198 | return tmpList; |
167 | } | 199 | } |
168 | 200 | ||
169 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { | 201 | OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) { |
170 | OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); | 202 | OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() ); |
171 | OEffectiveEvent::ValueList::Iterator it; | 203 | OEffectiveEvent::ValueList::Iterator it; |
172 | 204 | ||
173 | OEffectiveEvent::ValueList tmpList; | 205 | OEffectiveEvent::ValueList tmpList; |
174 | QDateTime dtTmp; | 206 | QDateTime dtTmp; |
175 | for ( it = day.begin(); it != day.end(); ++it ) { | 207 | for ( it = day.begin(); it != day.end(); ++it ) { |
176 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); | 208 | dtTmp = QDateTime( (*it).date(), (*it).startTime() ); |
177 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) | 209 | if ( QABS(dt.secsTo(dtTmp) ) < 60 ) |
178 | tmpList.append( (*it) ); | 210 | tmpList.append( (*it) ); |
179 | } | 211 | } |
180 | 212 | ||
181 | return tmpList; | 213 | return tmpList; |
182 | } | 214 | } |
215 | |||
216 | } | ||