author | zautrix <zautrix> | 2005-11-28 05:15:27 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 05:15:27 (UTC) |
commit | 1267a02fc23575f82247f8bd8449dc70dab62d44 (patch) (unidiff) | |
tree | fda71877c6b590a3a5035e310c03950e1081b06f | |
parent | b7522a13b64225bb91bdab4a21b44282f8c3e3b4 (diff) | |
download | kdepimpi-1267a02fc23575f82247f8bd8449dc70dab62d44.zip kdepimpi-1267a02fc23575f82247f8bd8449dc70dab62d44.tar.gz kdepimpi-1267a02fc23575f82247f8bd8449dc70dab62d44.tar.bz2 |
sync
-rw-r--r-- | libkcal/calendarlocal.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 8a5a76f..ce3cd09 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,1149 +1,1149 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | registerObserver( 0 ); | 68 | registerObserver( 0 ); |
69 | if ( mDeleteIncidencesOnClose ) | 69 | if ( mDeleteIncidencesOnClose ) |
70 | close(); | 70 | close(); |
71 | } | 71 | } |
72 | bool CalendarLocal::mergeCalendarFile( QString name ) | 72 | bool CalendarLocal::mergeCalendarFile( QString name ) |
73 | { | 73 | { |
74 | CalendarLocal calendar( timeZoneId() ); | 74 | CalendarLocal calendar( timeZoneId() ); |
75 | calendar.setDefaultCalendar( 1 ); | 75 | calendar.setDefaultCalendar( 1 ); |
76 | if ( calendar.load( name ) ) { | 76 | if ( calendar.load( name ) ) { |
77 | mergeCalendar( &calendar ); | 77 | mergeCalendar( &calendar ); |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) | 83 | Todo* CalendarLocal::todoForUid( const QString& uid, bool doNotCheckDuplicates, bool enabledOnly,int * isDup ) |
84 | { | 84 | { |
85 | 85 | ||
86 | int calID = 0; | 86 | int calID = 0; |
87 | if ( isDup && *isDup > 0 ) | 87 | if ( isDup && *isDup > 0 ) |
88 | calID = *isDup; | 88 | calID = *isDup; |
89 | Todo *todo;; | 89 | Todo *todo;; |
90 | Todo *retVal = 0; | 90 | Todo *retVal = 0; |
91 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 91 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
92 | if ( todo->uid() == uid ) { | 92 | if ( todo->uid() == uid ) { |
93 | if( calID ) { | 93 | if( calID ) { |
94 | if ( todo->calID() != calID ) | 94 | if ( todo->calID() != calID ) |
95 | continue; | 95 | continue; |
96 | } | 96 | } |
97 | else { | 97 | else { |
98 | if ( enabledOnly ) { | 98 | if ( enabledOnly ) { |
99 | if ( !todo->calEnabled() ) { | 99 | if ( !todo->calEnabled() ) { |
100 | if ( isDup ) | 100 | if ( isDup ) |
101 | *isDup = todo->calID(); | 101 | *isDup = todo->calID(); |
102 | continue; | 102 | continue; |
103 | } | 103 | } |
104 | } | 104 | } |
105 | } | 105 | } |
106 | if ( doNotCheckDuplicates ) return todo; | 106 | if ( doNotCheckDuplicates ) return todo; |
107 | if ( retVal ) { | 107 | if ( retVal ) { |
108 | if ( retVal->calID() > todo->calID() ) { | 108 | if ( retVal->calID() > todo->calID() ) { |
109 | if ( isDup ) | 109 | if ( isDup ) |
110 | *isDup = retVal->calID(); | 110 | *isDup = retVal->calID(); |
111 | retVal = todo; | 111 | retVal = todo; |
112 | } | 112 | } |
113 | } else { | 113 | } else { |
114 | retVal = todo; | 114 | retVal = todo; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | } | 117 | } |
118 | return retVal; | 118 | return retVal; |
119 | } | 119 | } |
120 | //if ( isDup) and * isDup == 0: store duplicate found cal id in isDup | 120 | //if ( isDup) and * isDup == 0: store duplicate found cal id in isDup |
121 | //if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly | 121 | //if ( isDup) and * isDup > 0: search only in calendar with ID *isDup, ignore enabledOnly |
122 | 122 | ||
123 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) | 123 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly, int * isDup ) |
124 | { | 124 | { |
125 | int calID = 0; | 125 | int calID = 0; |
126 | if ( isDup && *isDup > 0 ) | 126 | if ( isDup && *isDup > 0 ) |
127 | calID = *isDup; | 127 | calID = *isDup; |
128 | Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); | 128 | Incidence *retVal = todoForUid( uid , doNotCheckDuplicates,enabledOnly, isDup ); |
129 | if ( retVal ) return retVal; | 129 | if ( retVal ) return retVal; |
130 | Event *event; | 130 | Event *event; |
131 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 131 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
132 | if ( event->uid() == uid ) { | 132 | if ( event->uid() == uid ) { |
133 | if( calID ) { | 133 | if( calID ) { |
134 | if ( event->calID() != calID ) | 134 | if ( event->calID() != calID ) |
135 | continue; | 135 | continue; |
136 | } | 136 | } |
137 | else { | 137 | else { |
138 | if ( enabledOnly ) { | 138 | if ( enabledOnly ) { |
139 | if ( !event->calEnabled() ) { | 139 | if ( !event->calEnabled() ) { |
140 | if ( isDup ) | 140 | if ( isDup ) |
141 | *isDup =event->calID() ; | 141 | *isDup =event->calID() ; |
142 | continue; | 142 | continue; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | } | 145 | } |
146 | if ( doNotCheckDuplicates ) return event; | 146 | if ( doNotCheckDuplicates ) return event; |
147 | if ( retVal ) { | 147 | if ( retVal ) { |
148 | if ( retVal->calID() > event->calID() ) { | 148 | if ( retVal->calID() > event->calID() ) { |
149 | if ( isDup ) | 149 | if ( isDup ) |
150 | *isDup = retVal->calID(); | 150 | *isDup = retVal->calID(); |
151 | retVal = event; | 151 | retVal = event; |
152 | } | 152 | } |
153 | } else { | 153 | } else { |
154 | retVal = event; | 154 | retVal = event; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | } | 157 | } |
158 | if ( retVal ) return retVal; | 158 | if ( retVal ) return retVal; |
159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 159 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
160 | if ( it->uid() == uid ) { | 160 | if ( it->uid() == uid ) { |
161 | if( calID ) { | 161 | if( calID ) { |
162 | if ( event->calID() != calID ) | 162 | if ( event->calID() != calID ) |
163 | continue; | 163 | continue; |
164 | } | 164 | } |
165 | else { | 165 | else { |
166 | if ( enabledOnly ) { | 166 | if ( enabledOnly ) { |
167 | if ( !it->calEnabled() ) { | 167 | if ( !it->calEnabled() ) { |
168 | if ( isDup ) | 168 | if ( isDup ) |
169 | *isDup = it->calID(); | 169 | *isDup = it->calID(); |
170 | continue; | 170 | continue; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | } | 173 | } |
174 | if ( doNotCheckDuplicates ) return it; | 174 | if ( doNotCheckDuplicates ) return it; |
175 | if ( retVal ) { | 175 | if ( retVal ) { |
176 | if ( retVal->calID() > it->calID() ) { | 176 | if ( retVal->calID() > it->calID() ) { |
177 | if ( isDup ) | 177 | if ( isDup ) |
178 | *isDup = retVal->calID(); | 178 | *isDup = retVal->calID(); |
179 | retVal = it; | 179 | retVal = it; |
180 | } | 180 | } |
181 | } else { | 181 | } else { |
182 | retVal = it; | 182 | retVal = it; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | return retVal; | 185 | return retVal; |
186 | } | 186 | } |
187 | 187 | ||
188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 188 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
189 | { | 189 | { |
190 | // 1 look for raw inc in local | 190 | // 1 look for raw inc in local |
191 | // if inc not in remote, delete in local | 191 | // if inc not in remote, delete in local |
192 | // 2 look for raw inc in remote | 192 | // 2 look for raw inc in remote |
193 | // if inc in local, replace it | 193 | // if inc in local, replace it |
194 | // if not in local, add it to default calendar | 194 | // if not in local, add it to default calendar |
195 | QPtrList<Incidence> localInc = rawIncidences(); | 195 | QPtrList<Incidence> localInc = rawIncidences(); |
196 | Incidence* inL = localInc.first(); | 196 | Incidence* inL = localInc.first(); |
197 | while ( inL ) { | 197 | while ( inL ) { |
198 | if ( ! inL->isReadOnly () ) | 198 | if ( ! inL->isReadOnly () ) |
199 | if ( !remote->incidenceForUid( inL->uid(), true )) | 199 | if ( !remote->incidenceForUid( inL->uid(), true )) |
200 | deleteIncidence( inL ); | 200 | deleteIncidence( inL ); |
201 | inL = localInc.next(); | 201 | inL = localInc.next(); |
202 | } | 202 | } |
203 | QPtrList<Incidence> er = remote->rawIncidences(); | 203 | QPtrList<Incidence> er = remote->rawIncidences(); |
204 | Incidence* inR = er.first(); | 204 | Incidence* inR = er.first(); |
205 | while ( inR ) { | 205 | while ( inR ) { |
206 | inL = incidenceForUid( inR->uid(),false ); | 206 | inL = incidenceForUid( inR->uid(),false ); |
207 | if ( inL ) { | 207 | if ( inL ) { |
208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 208 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
209 | int calID = inL->calID(); | 209 | int calID = inL->calID(); |
210 | deleteIncidence( inL ); | 210 | deleteIncidence( inL ); |
211 | inL = inR->clone(); | 211 | inL = inR->clone(); |
212 | inL->setCalID_block( calID ); | 212 | inL->setCalID_block( calID ); |
213 | addIncidence( inL ); | 213 | addIncidence( inL ); |
214 | } | 214 | } |
215 | } else { | 215 | } else { |
216 | inL = inR->clone(); | 216 | inL = inR->clone(); |
217 | inL->setCalID_block( 0 );// add to default cal | 217 | inL->setCalID_block( 0 );// add to default cal |
218 | addIncidence( inL ); | 218 | addIncidence( inL ); |
219 | } | 219 | } |
220 | inR = er.next(); | 220 | inR = er.next(); |
221 | } | 221 | } |
222 | return true; | 222 | return true; |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 226 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
227 | { | 227 | { |
228 | CalendarLocal calendar( timeZoneId() ); | 228 | CalendarLocal calendar( timeZoneId() ); |
229 | calendar.setDefaultCalendar( id ); | 229 | calendar.setDefaultCalendar( id ); |
230 | if ( calendar.load( name ) ) { | 230 | if ( calendar.load( name ) ) { |
231 | addCalendar( &calendar ); | 231 | addCalendar( &calendar ); |
232 | return true; | 232 | return true; |
233 | } | 233 | } |
234 | return false; | 234 | return false; |
235 | } | 235 | } |
236 | void CalendarLocal::setSyncEventsEnabled() | 236 | void CalendarLocal::setSyncEventsEnabled() |
237 | { | 237 | { |
238 | Event * ev; | 238 | Event * ev; |
239 | ev = mEventList.first(); | 239 | ev = mEventList.first(); |
240 | while ( ev ) { | 240 | while ( ev ) { |
241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 241 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
242 | ev->setCalEnabled( true ); | 242 | ev->setCalEnabled( true ); |
243 | ev = mEventList.next(); | 243 | ev = mEventList.next(); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | void CalendarLocal::setSyncEventsReadOnly() | 246 | void CalendarLocal::setSyncEventsReadOnly() |
247 | { | 247 | { |
248 | Event * ev; | 248 | Event * ev; |
249 | ev = mEventList.first(); | 249 | ev = mEventList.first(); |
250 | while ( ev ) { | 250 | while ( ev ) { |
251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 251 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
252 | ev->setReadOnly( true ); | 252 | ev->setReadOnly( true ); |
253 | } | 253 | } |
254 | ev = mEventList.next(); | 254 | ev = mEventList.next(); |
255 | } | 255 | } |
256 | } | 256 | } |
257 | 257 | ||
258 | void CalendarLocal::addCalendar( Calendar* cal ) | 258 | void CalendarLocal::addCalendar( Calendar* cal ) |
259 | { | 259 | { |
260 | cal->setDontDeleteIncidencesOnClose(); | 260 | cal->setDontDeleteIncidencesOnClose(); |
261 | setSyncEventsEnabled(); | 261 | setSyncEventsEnabled(); |
262 | QPtrList<Incidence> incList; | 262 | QPtrList<Incidence> incList; |
263 | { | 263 | { |
264 | QPtrList<Event> EventList = cal->rawEvents(); | 264 | QPtrList<Event> EventList = cal->rawEvents(); |
265 | Event * ev = EventList.first(); | 265 | Event * ev = EventList.first(); |
266 | while ( ev ) { | 266 | while ( ev ) { |
267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | 267 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { |
268 | ev->setCalID_block( 1 ); | 268 | ev->setCalID_block( 1 ); |
269 | } | 269 | } |
270 | Event * se = event( ev->uid() ); | 270 | Event * se = event( ev->uid() ); |
271 | if ( se ) | 271 | if ( se ) |
272 | incList.append( se ); | 272 | incList.append( se ); |
273 | ev->unRegisterObserver( cal ); | 273 | ev->unRegisterObserver( cal ); |
274 | ev->registerObserver( this ); | 274 | ev->registerObserver( this ); |
275 | mEventList.append( ev ); | 275 | mEventList.append( ev ); |
276 | ev = EventList.next(); | 276 | ev = EventList.next(); |
277 | } | 277 | } |
278 | 278 | ||
279 | } | 279 | } |
280 | { | 280 | { |
281 | 281 | ||
282 | QPtrList<Todo> TodoList = cal->rawTodos(); | 282 | QPtrList<Todo> TodoList = cal->rawTodos(); |
283 | Todo * ev = TodoList.first(); | 283 | Todo * ev = TodoList.first(); |
284 | while ( ev ) { | 284 | while ( ev ) { |
285 | ev->resetRelatedTo(); | 285 | ev->resetRelatedTo(); |
286 | ev = TodoList.next(); | 286 | Todo * se = todo( ev->uid() ); |
287 | if ( se ) | ||
288 | deleteTodo( se ); | ||
289 | ev = TodoList.next(); | ||
287 | } | 290 | } |
288 | //TodoList = cal->rawTodos(); | 291 | //TodoList = cal->rawTodos(); |
289 | ev = TodoList.first(); | 292 | ev = TodoList.first(); |
290 | while ( ev ) { | 293 | while ( ev ) { |
291 | Todo * se = todo( ev->uid() ); | ||
292 | if ( se ) | ||
293 | incList.append( se ); | ||
294 | ev->unRegisterObserver( cal ); | 294 | ev->unRegisterObserver( cal ); |
295 | ev->registerObserver( this ); | 295 | ev->registerObserver( this ); |
296 | mTodoList.append( ev ); | 296 | mTodoList.append( ev ); |
297 | setupRelations( ev ); | 297 | setupRelations( ev ); |
298 | ev = TodoList.next(); | 298 | ev = TodoList.next(); |
299 | } | 299 | } |
300 | } | 300 | } |
301 | { | 301 | { |
302 | QPtrList<Journal> JournalList = cal->journals(); | 302 | QPtrList<Journal> JournalList = cal->journals(); |
303 | Journal * ev = JournalList.first(); | 303 | Journal * ev = JournalList.first(); |
304 | while ( ev ) { | 304 | while ( ev ) { |
305 | Journal * se = journal( ev->uid() ); | 305 | Journal * se = journal( ev->uid() ); |
306 | if ( se ) | 306 | if ( se ) |
307 | incList.append( se ); | 307 | incList.append( se ); |
308 | ev->unRegisterObserver( cal ); | 308 | ev->unRegisterObserver( cal ); |
309 | ev->registerObserver( this ); | 309 | ev->registerObserver( this ); |
310 | mJournalList.append( ev ); | 310 | mJournalList.append( ev ); |
311 | ev = JournalList.next(); | 311 | ev = JournalList.next(); |
312 | } | 312 | } |
313 | } | 313 | } |
314 | { | 314 | { |
315 | for (Incidence * ev = incList.first(); ev; ev = incList.next() ) { | 315 | for (Incidence * inc = incList.first(); inc; inc = incList.next() ) { |
316 | deleteIncidence ( ev ); | 316 | deleteIncidence ( inc ); |
317 | } | 317 | } |
318 | } | 318 | } |
319 | setModified( true ); | 319 | setModified( true ); |
320 | } | 320 | } |
321 | bool CalendarLocal::load( const QString &fileName ) | 321 | bool CalendarLocal::load( const QString &fileName ) |
322 | { | 322 | { |
323 | FileStorage storage( this, fileName ); | 323 | FileStorage storage( this, fileName ); |
324 | return storage.load(); | 324 | return storage.load(); |
325 | } | 325 | } |
326 | 326 | ||
327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
328 | { | 328 | { |
329 | FileStorage storage( this, fileName, format ); | 329 | FileStorage storage( this, fileName, format ); |
330 | return storage.save(); | 330 | return storage.save(); |
331 | } | 331 | } |
332 | 332 | ||
333 | void CalendarLocal::stopAllTodos() | 333 | void CalendarLocal::stopAllTodos() |
334 | { | 334 | { |
335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
336 | it->setRunning( false ); | 336 | it->setRunning( false ); |
337 | 337 | ||
338 | } | 338 | } |
339 | void CalendarLocal::close() | 339 | void CalendarLocal::close() |
340 | { | 340 | { |
341 | 341 | ||
342 | Todo * i; | 342 | Todo * i; |
343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
344 | 344 | ||
345 | mEventList.setAutoDelete( true ); | 345 | mEventList.setAutoDelete( true ); |
346 | mTodoList.setAutoDelete( true ); | 346 | mTodoList.setAutoDelete( true ); |
347 | mJournalList.setAutoDelete( true ); | 347 | mJournalList.setAutoDelete( true ); |
348 | 348 | ||
349 | mEventList.clear(); | 349 | mEventList.clear(); |
350 | mTodoList.clear(); | 350 | mTodoList.clear(); |
351 | mJournalList.clear(); | 351 | mJournalList.clear(); |
352 | 352 | ||
353 | mEventList.setAutoDelete( false ); | 353 | mEventList.setAutoDelete( false ); |
354 | mTodoList.setAutoDelete( false ); | 354 | mTodoList.setAutoDelete( false ); |
355 | mJournalList.setAutoDelete( false ); | 355 | mJournalList.setAutoDelete( false ); |
356 | 356 | ||
357 | setModified( false ); | 357 | setModified( false ); |
358 | } | 358 | } |
359 | 359 | ||
360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
361 | { | 361 | { |
362 | QString cat; | 362 | QString cat; |
363 | bool isBirthday = true; | 363 | bool isBirthday = true; |
364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
365 | isBirthday = false; | 365 | isBirthday = false; |
366 | cat = i18n( "Anniversary" ); | 366 | cat = i18n( "Anniversary" ); |
367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
368 | isBirthday = true; | 368 | isBirthday = true; |
369 | cat = i18n( "Birthday" ); | 369 | cat = i18n( "Birthday" ); |
370 | } else { | 370 | } else { |
371 | qDebug("addAnniversaryNoDup called without fitting category! "); | 371 | qDebug("addAnniversaryNoDup called without fitting category! "); |
372 | return false; | 372 | return false; |
373 | } | 373 | } |
374 | Event * eve; | 374 | Event * eve; |
375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
376 | if ( !(eve->categories().contains( cat ) )) | 376 | if ( !(eve->categories().contains( cat ) )) |
377 | continue; | 377 | continue; |
378 | // now we have an event with fitting category | 378 | // now we have an event with fitting category |
379 | if ( eve->dtStart().date() != event->dtStart().date() ) | 379 | if ( eve->dtStart().date() != event->dtStart().date() ) |
380 | continue; | 380 | continue; |
381 | // now we have an event with fitting category+date | 381 | // now we have an event with fitting category+date |
382 | if ( eve->summary() != event->summary() ) | 382 | if ( eve->summary() != event->summary() ) |
383 | continue; | 383 | continue; |
384 | // now we have an event with fitting category+date+summary | 384 | // now we have an event with fitting category+date+summary |
385 | return false; | 385 | return false; |
386 | } | 386 | } |
387 | return addEvent( event ); | 387 | return addEvent( event ); |
388 | 388 | ||
389 | } | 389 | } |
390 | bool CalendarLocal::addEventNoDup( Event *event ) | 390 | bool CalendarLocal::addEventNoDup( Event *event ) |
391 | { | 391 | { |
392 | Event * eve; | 392 | Event * eve; |
393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
394 | if ( *eve == *event ) { | 394 | if ( *eve == *event ) { |
395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
396 | return false; | 396 | return false; |
397 | } | 397 | } |
398 | } | 398 | } |
399 | return addEvent( event ); | 399 | return addEvent( event ); |
400 | } | 400 | } |
401 | 401 | ||
402 | bool CalendarLocal::addEvent( Event *event ) | 402 | bool CalendarLocal::addEvent( Event *event ) |
403 | { | 403 | { |
404 | insertEvent( event ); | 404 | insertEvent( event ); |
405 | 405 | ||
406 | event->registerObserver( this ); | 406 | event->registerObserver( this ); |
407 | 407 | ||
408 | setModified( true ); | 408 | setModified( true ); |
409 | if ( event->calID() == 0 ) | 409 | if ( event->calID() == 0 ) |
410 | event->setCalID_block( mDefaultCalendar ); | 410 | event->setCalID_block( mDefaultCalendar ); |
411 | event->setCalEnabled( true ); | 411 | event->setCalEnabled( true ); |
412 | 412 | ||
413 | return true; | 413 | return true; |
414 | } | 414 | } |
415 | 415 | ||
416 | void CalendarLocal::deleteEvent( Event *event ) | 416 | void CalendarLocal::deleteEvent( Event *event ) |
417 | { | 417 | { |
418 | clearUndo(event); | 418 | clearUndo(event); |
419 | if ( mEventList.removeRef( event ) ) { | 419 | if ( mEventList.removeRef( event ) ) { |
420 | setModified( true ); | 420 | setModified( true ); |
421 | } | 421 | } |
422 | } | 422 | } |
423 | 423 | ||
424 | 424 | ||
425 | Event *CalendarLocal::event( const QString &uid ) | 425 | Event *CalendarLocal::event( const QString &uid ) |
426 | { | 426 | { |
427 | Event *event; | 427 | Event *event; |
428 | Event *retVal = 0; | 428 | Event *retVal = 0; |
429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
430 | if ( event->calEnabled() && event->uid() == uid ) { | 430 | if ( event->calEnabled() && event->uid() == uid ) { |
431 | if ( retVal ) { | 431 | if ( retVal ) { |
432 | if ( retVal->calID() > event->calID() ) { | 432 | if ( retVal->calID() > event->calID() ) { |
433 | retVal = event; | 433 | retVal = event; |
434 | } | 434 | } |
435 | } else { | 435 | } else { |
436 | retVal = event; | 436 | retVal = event; |
437 | } | 437 | } |
438 | } | 438 | } |
439 | } | 439 | } |
440 | return retVal; | 440 | return retVal; |
441 | } | 441 | } |
442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
443 | { | 443 | { |
444 | Todo * eve; | 444 | Todo * eve; |
445 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 445 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
446 | if ( *eve == *todo ) { | 446 | if ( *eve == *todo ) { |
447 | //qDebug("duplicate todo found! not inserted! "); | 447 | //qDebug("duplicate todo found! not inserted! "); |
448 | return false; | 448 | return false; |
449 | } | 449 | } |
450 | } | 450 | } |
451 | return addTodo( todo ); | 451 | return addTodo( todo ); |
452 | } | 452 | } |
453 | bool CalendarLocal::addTodo( Todo *todo ) | 453 | bool CalendarLocal::addTodo( Todo *todo ) |
454 | { | 454 | { |
455 | mTodoList.append( todo ); | 455 | mTodoList.append( todo ); |
456 | 456 | ||
457 | todo->registerObserver( this ); | 457 | todo->registerObserver( this ); |
458 | 458 | ||
459 | // Set up subtask relations | 459 | // Set up subtask relations |
460 | setupRelations( todo ); | 460 | setupRelations( todo ); |
461 | 461 | ||
462 | setModified( true ); | 462 | setModified( true ); |
463 | if ( todo->calID() == 0 ) | 463 | if ( todo->calID() == 0 ) |
464 | todo->setCalID_block( mDefaultCalendar ); | 464 | todo->setCalID_block( mDefaultCalendar ); |
465 | todo->setCalEnabled( true ); | 465 | todo->setCalEnabled( true ); |
466 | return true; | 466 | return true; |
467 | } | 467 | } |
468 | 468 | ||
469 | void CalendarLocal::deleteTodo( Todo *todo ) | 469 | void CalendarLocal::deleteTodo( Todo *todo ) |
470 | { | 470 | { |
471 | QString uid = todo->uid(); | 471 | QString uid = todo->uid(); |
472 | // Handle orphaned children | 472 | // Handle orphaned children |
473 | removeRelations( todo ); | 473 | removeRelations( todo ); |
474 | clearUndo(todo); | 474 | clearUndo(todo); |
475 | 475 | ||
476 | if ( mTodoList.removeRef( todo ) ) { | 476 | if ( mTodoList.removeRef( todo ) ) { |
477 | setModified( true ); | 477 | setModified( true ); |
478 | } | 478 | } |
479 | Todo* dup = todoForUid( uid ); | 479 | Todo* dup = todoForUid( uid ); |
480 | if ( dup ) | 480 | if ( dup ) |
481 | setupRelations( dup ); | 481 | setupRelations( dup ); |
482 | } | 482 | } |
483 | 483 | ||
484 | QPtrList<Todo> CalendarLocal::rawTodos() | 484 | QPtrList<Todo> CalendarLocal::rawTodos() |
485 | { | 485 | { |
486 | QPtrList<Todo> el; | 486 | QPtrList<Todo> el; |
487 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 487 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
488 | if ( it->calEnabled() ) el.append( it ); | 488 | if ( it->calEnabled() ) el.append( it ); |
489 | return el; | 489 | return el; |
490 | } | 490 | } |
491 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 491 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
492 | { | 492 | { |
493 | Todo *todo; | 493 | Todo *todo; |
494 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 494 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
495 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 495 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
496 | } | 496 | } |
497 | 497 | ||
498 | return 0; | 498 | return 0; |
499 | } | 499 | } |
500 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 500 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
501 | { | 501 | { |
502 | QPtrList<Incidence> all = rawIncidences() ; | 502 | QPtrList<Incidence> all = rawIncidences() ; |
503 | Incidence *inc; | 503 | Incidence *inc; |
504 | for ( inc = all.first(); inc; inc = all.next() ) { | 504 | for ( inc = all.first(); inc; inc = all.next() ) { |
505 | inc->removeID( syncProfile ); | 505 | inc->removeID( syncProfile ); |
506 | } | 506 | } |
507 | if ( syncProfile.isEmpty() ) { | 507 | if ( syncProfile.isEmpty() ) { |
508 | QPtrList<Event> el; | 508 | QPtrList<Event> el; |
509 | Event *todo; | 509 | Event *todo; |
510 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 510 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
511 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 511 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
512 | el.append( todo ); | 512 | el.append( todo ); |
513 | } | 513 | } |
514 | for ( todo = el.first(); todo; todo = el.next() ) { | 514 | for ( todo = el.first(); todo; todo = el.next() ) { |
515 | deleteIncidence ( todo ); | 515 | deleteIncidence ( todo ); |
516 | } | 516 | } |
517 | } else { | 517 | } else { |
518 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 518 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
519 | if ( lse ) | 519 | if ( lse ) |
520 | deleteIncidence ( lse ); | 520 | deleteIncidence ( lse ); |
521 | } | 521 | } |
522 | } | 522 | } |
523 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 523 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
524 | { | 524 | { |
525 | QPtrList<Event> el; | 525 | QPtrList<Event> el; |
526 | Event *todo; | 526 | Event *todo; |
527 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 527 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
528 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 528 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
529 | if ( todo->summary().left(3) == "E: " ) | 529 | if ( todo->summary().left(3) == "E: " ) |
530 | el.append( todo ); | 530 | el.append( todo ); |
531 | } | 531 | } |
532 | 532 | ||
533 | return el; | 533 | return el; |
534 | 534 | ||
535 | } | 535 | } |
536 | Event *CalendarLocal::event( QString syncProf, QString id ) | 536 | Event *CalendarLocal::event( QString syncProf, QString id ) |
537 | { | 537 | { |
538 | Event *todo; | 538 | Event *todo; |
539 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 539 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
540 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 540 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
541 | } | 541 | } |
542 | 542 | ||
543 | return 0; | 543 | return 0; |
544 | } | 544 | } |
545 | Todo *CalendarLocal::todo( const QString &uid ) | 545 | Todo *CalendarLocal::todo( const QString &uid ) |
546 | { | 546 | { |
547 | Todo *todo; | 547 | Todo *todo; |
548 | Todo *retVal = 0; | 548 | Todo *retVal = 0; |
549 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 549 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
550 | if ( todo->calEnabled() && todo->uid() == uid ) { | 550 | if ( todo->calEnabled() && todo->uid() == uid ) { |
551 | if ( retVal ) { | 551 | if ( retVal ) { |
552 | if ( retVal->calID() > todo->calID() ) { | 552 | if ( retVal->calID() > todo->calID() ) { |
553 | retVal = todo; | 553 | retVal = todo; |
554 | } | 554 | } |
555 | } else { | 555 | } else { |
556 | retVal = todo; | 556 | retVal = todo; |
557 | } | 557 | } |
558 | } | 558 | } |
559 | } | 559 | } |
560 | return retVal; | 560 | return retVal; |
561 | } | 561 | } |
562 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | 562 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) |
563 | { | 563 | { |
564 | events = 0; | 564 | events = 0; |
565 | todos = 0; | 565 | todos = 0; |
566 | journals = 0; | 566 | journals = 0; |
567 | { | 567 | { |
568 | Todo *todo; | 568 | Todo *todo; |
569 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 569 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
570 | if ( todo->calID() == calId ) | 570 | if ( todo->calID() == calId ) |
571 | ++todos; | 571 | ++todos; |
572 | } | 572 | } |
573 | } | 573 | } |
574 | { | 574 | { |
575 | Event *todo; | 575 | Event *todo; |
576 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 576 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
577 | if ( todo->calID() == calId ) | 577 | if ( todo->calID() == calId ) |
578 | ++events; | 578 | ++events; |
579 | 579 | ||
580 | } | 580 | } |
581 | } | 581 | } |
582 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 582 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
583 | if ( it->calID() == calId ) ++journals; | 583 | if ( it->calID() == calId ) ++journals; |
584 | 584 | ||
585 | } | 585 | } |
586 | QString CalendarLocal::nextSummary() const | 586 | QString CalendarLocal::nextSummary() const |
587 | { | 587 | { |
588 | return mNextSummary; | 588 | return mNextSummary; |
589 | } | 589 | } |
590 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 590 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
591 | { | 591 | { |
592 | return mNextAlarmEventDateTime; | 592 | return mNextAlarmEventDateTime; |
593 | } | 593 | } |
594 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 594 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
595 | { | 595 | { |
596 | //mNextAlarmIncidence | 596 | //mNextAlarmIncidence |
597 | //mNextAlarmDateTime | 597 | //mNextAlarmDateTime |
598 | //return mNextSummary; | 598 | //return mNextSummary; |
599 | //return mNextAlarmEventDateTime; | 599 | //return mNextAlarmEventDateTime; |
600 | bool newNextAlarm = false; | 600 | bool newNextAlarm = false; |
601 | bool computeNextAlarm = false; | 601 | bool computeNextAlarm = false; |
602 | bool ok; | 602 | bool ok; |
603 | int offset; | 603 | int offset; |
604 | QDateTime nextA; | 604 | QDateTime nextA; |
605 | // QString nextSum; | 605 | // QString nextSum; |
606 | //QDateTime nextEvent; | 606 | //QDateTime nextEvent; |
607 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 607 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
608 | computeNextAlarm = true; | 608 | computeNextAlarm = true; |
609 | } else { | 609 | } else { |
610 | if ( ! deleted ) { | 610 | if ( ! deleted ) { |
611 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 611 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
612 | if ( ok ) { | 612 | if ( ok ) { |
613 | if ( nextA < mNextAlarmDateTime ) { | 613 | if ( nextA < mNextAlarmDateTime ) { |
614 | deRegisterAlarm(); | 614 | deRegisterAlarm(); |
615 | mNextAlarmDateTime = nextA; | 615 | mNextAlarmDateTime = nextA; |
616 | mNextSummary = incidence->summary(); | 616 | mNextSummary = incidence->summary(); |
617 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 617 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
618 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 618 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
619 | newNextAlarm = true; | 619 | newNextAlarm = true; |
620 | mNextAlarmIncidence = incidence; | 620 | mNextAlarmIncidence = incidence; |
621 | } else { | 621 | } else { |
622 | if ( incidence == mNextAlarmIncidence ) { | 622 | if ( incidence == mNextAlarmIncidence ) { |
623 | computeNextAlarm = true; | 623 | computeNextAlarm = true; |
624 | } | 624 | } |
625 | } | 625 | } |
626 | } else { | 626 | } else { |
627 | if ( mNextAlarmIncidence == incidence ) { | 627 | if ( mNextAlarmIncidence == incidence ) { |
628 | computeNextAlarm = true; | 628 | computeNextAlarm = true; |
629 | } | 629 | } |
630 | } | 630 | } |
631 | } else { // deleted | 631 | } else { // deleted |
632 | if ( incidence == mNextAlarmIncidence ) { | 632 | if ( incidence == mNextAlarmIncidence ) { |
633 | computeNextAlarm = true; | 633 | computeNextAlarm = true; |
634 | } | 634 | } |
635 | } | 635 | } |
636 | } | 636 | } |
637 | if ( computeNextAlarm ) { | 637 | if ( computeNextAlarm ) { |
638 | deRegisterAlarm(); | 638 | deRegisterAlarm(); |
639 | nextA = nextAlarm( 1000 ); | 639 | nextA = nextAlarm( 1000 ); |
640 | if (! mNextAlarmIncidence ) { | 640 | if (! mNextAlarmIncidence ) { |
641 | return; | 641 | return; |
642 | } | 642 | } |
643 | newNextAlarm = true; | 643 | newNextAlarm = true; |
644 | } | 644 | } |
645 | if ( newNextAlarm ) | 645 | if ( newNextAlarm ) |
646 | registerAlarm(); | 646 | registerAlarm(); |
647 | } | 647 | } |
648 | QString CalendarLocal:: getAlarmNotification() | 648 | QString CalendarLocal:: getAlarmNotification() |
649 | { | 649 | { |
650 | QString ret; | 650 | QString ret; |
651 | // this should not happen | 651 | // this should not happen |
652 | if (! mNextAlarmIncidence ) | 652 | if (! mNextAlarmIncidence ) |
653 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 653 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
654 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 654 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
655 | if ( alarm->type() == Alarm::Procedure ) { | 655 | if ( alarm->type() == Alarm::Procedure ) { |
656 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 656 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
657 | } else { | 657 | } else { |
658 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 658 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
659 | } | 659 | } |
660 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 660 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
661 | if ( mNextSummary.length() > 25 ) | 661 | if ( mNextSummary.length() > 25 ) |
662 | ret += "\n" + mNextSummary.mid(25, 25 ); | 662 | ret += "\n" + mNextSummary.mid(25, 25 ); |
663 | ret+= "\n"+mNextAlarmEventDateTimeString; | 663 | ret+= "\n"+mNextAlarmEventDateTimeString; |
664 | return ret; | 664 | return ret; |
665 | } | 665 | } |
666 | void CalendarLocal::registerAlarm() | 666 | void CalendarLocal::registerAlarm() |
667 | { | 667 | { |
668 | mLastAlarmNotificationString = getAlarmNotification(); | 668 | mLastAlarmNotificationString = getAlarmNotification(); |
669 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 669 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
670 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 670 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
671 | // #ifndef DESKTOP_VERSION | 671 | // #ifndef DESKTOP_VERSION |
672 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 672 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
673 | // #endif | 673 | // #endif |
674 | } | 674 | } |
675 | void CalendarLocal::deRegisterAlarm() | 675 | void CalendarLocal::deRegisterAlarm() |
676 | { | 676 | { |
677 | if ( mLastAlarmNotificationString.isNull() ) | 677 | if ( mLastAlarmNotificationString.isNull() ) |
678 | return; | 678 | return; |
679 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 679 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
680 | 680 | ||
681 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 681 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
682 | mNextAlarmEventDateTime = QDateTime(); | 682 | mNextAlarmEventDateTime = QDateTime(); |
683 | // #ifndef DESKTOP_VERSION | 683 | // #ifndef DESKTOP_VERSION |
684 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 684 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
685 | // #endif | 685 | // #endif |
686 | } | 686 | } |
687 | 687 | ||
688 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 688 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
689 | { | 689 | { |
690 | QPtrList<Todo> todos; | 690 | QPtrList<Todo> todos; |
691 | 691 | ||
692 | Todo *todo; | 692 | Todo *todo; |
693 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 693 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
694 | if ( !todo->calEnabled() ) continue; | 694 | if ( !todo->calEnabled() ) continue; |
695 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 695 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
696 | todos.append( todo ); | 696 | todos.append( todo ); |
697 | } | 697 | } |
698 | } | 698 | } |
699 | 699 | ||
700 | filter()->apply( &todos ); | 700 | filter()->apply( &todos ); |
701 | return todos; | 701 | return todos; |
702 | } | 702 | } |
703 | void CalendarLocal::reInitAlarmSettings() | 703 | void CalendarLocal::reInitAlarmSettings() |
704 | { | 704 | { |
705 | if ( !mNextAlarmIncidence ) { | 705 | if ( !mNextAlarmIncidence ) { |
706 | nextAlarm( 1000 ); | 706 | nextAlarm( 1000 ); |
707 | } | 707 | } |
708 | deRegisterAlarm(); | 708 | deRegisterAlarm(); |
709 | mNextAlarmIncidence = 0; | 709 | mNextAlarmIncidence = 0; |
710 | checkAlarmForIncidence( 0, false ); | 710 | checkAlarmForIncidence( 0, false ); |
711 | 711 | ||
712 | } | 712 | } |
713 | 713 | ||
714 | 714 | ||
715 | 715 | ||
716 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 716 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
717 | { | 717 | { |
718 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 718 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
719 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 719 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
720 | QDateTime next; | 720 | QDateTime next; |
721 | Event *e; | 721 | Event *e; |
722 | bool ok; | 722 | bool ok; |
723 | bool found = false; | 723 | bool found = false; |
724 | int offset; | 724 | int offset; |
725 | mNextAlarmIncidence = 0; | 725 | mNextAlarmIncidence = 0; |
726 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 726 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
727 | if ( !e->calEnabled() ) continue; | 727 | if ( !e->calEnabled() ) continue; |
728 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 728 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
729 | if ( ok ) { | 729 | if ( ok ) { |
730 | if ( next < nextA ) { | 730 | if ( next < nextA ) { |
731 | nextA = next; | 731 | nextA = next; |
732 | found = true; | 732 | found = true; |
733 | mNextSummary = e->summary(); | 733 | mNextSummary = e->summary(); |
734 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 734 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
735 | mNextAlarmIncidence = (Incidence *) e; | 735 | mNextAlarmIncidence = (Incidence *) e; |
736 | } | 736 | } |
737 | } | 737 | } |
738 | } | 738 | } |
739 | Todo *t; | 739 | Todo *t; |
740 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 740 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
741 | if ( !t->calEnabled() ) continue; | 741 | if ( !t->calEnabled() ) continue; |
742 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 742 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
743 | if ( ok ) { | 743 | if ( ok ) { |
744 | if ( next < nextA ) { | 744 | if ( next < nextA ) { |
745 | nextA = next; | 745 | nextA = next; |
746 | found = true; | 746 | found = true; |
747 | mNextSummary = t->summary(); | 747 | mNextSummary = t->summary(); |
748 | mNextAlarmEventDateTime = next.addSecs(offset ); | 748 | mNextAlarmEventDateTime = next.addSecs(offset ); |
749 | mNextAlarmIncidence = (Incidence *) t; | 749 | mNextAlarmIncidence = (Incidence *) t; |
750 | } | 750 | } |
751 | } | 751 | } |
752 | } | 752 | } |
753 | if ( mNextAlarmIncidence ) { | 753 | if ( mNextAlarmIncidence ) { |
754 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 754 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
755 | mNextAlarmDateTime = nextA; | 755 | mNextAlarmDateTime = nextA; |
756 | } | 756 | } |
757 | return nextA; | 757 | return nextA; |
758 | } | 758 | } |
759 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 759 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
760 | { | 760 | { |
761 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 761 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
762 | } | 762 | } |
763 | 763 | ||
764 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 764 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
765 | { | 765 | { |
766 | 766 | ||
767 | Alarm::List alarms; | 767 | Alarm::List alarms; |
768 | 768 | ||
769 | Event *e; | 769 | Event *e; |
770 | 770 | ||
771 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 771 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
772 | if ( !e->calEnabled() ) continue; | 772 | if ( !e->calEnabled() ) continue; |
773 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 773 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
774 | else appendAlarms( alarms, e, from, to ); | 774 | else appendAlarms( alarms, e, from, to ); |
775 | } | 775 | } |
776 | 776 | ||
777 | Todo *t; | 777 | Todo *t; |
778 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 778 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
779 | if ( !t->calEnabled() ) continue; | 779 | if ( !t->calEnabled() ) continue; |
780 | appendAlarms( alarms, t, from, to ); | 780 | appendAlarms( alarms, t, from, to ); |
781 | } | 781 | } |
782 | 782 | ||
783 | return alarms; | 783 | return alarms; |
784 | } | 784 | } |
785 | 785 | ||
786 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 786 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
787 | const QDateTime &from, const QDateTime &to ) | 787 | const QDateTime &from, const QDateTime &to ) |
788 | { | 788 | { |
789 | QPtrList<Alarm> alarmList = incidence->alarms(); | 789 | QPtrList<Alarm> alarmList = incidence->alarms(); |
790 | Alarm *alarm; | 790 | Alarm *alarm; |
791 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 791 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
792 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 792 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
793 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 793 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
794 | if ( alarm->enabled() ) { | 794 | if ( alarm->enabled() ) { |
795 | if ( alarm->time() >= from && alarm->time() <= to ) { | 795 | if ( alarm->time() >= from && alarm->time() <= to ) { |
796 | alarms.append( alarm ); | 796 | alarms.append( alarm ); |
797 | } | 797 | } |
798 | } | 798 | } |
799 | } | 799 | } |
800 | } | 800 | } |
801 | 801 | ||
802 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 802 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
803 | Incidence *incidence, | 803 | Incidence *incidence, |
804 | const QDateTime &from, | 804 | const QDateTime &from, |
805 | const QDateTime &to ) | 805 | const QDateTime &to ) |
806 | { | 806 | { |
807 | 807 | ||
808 | QPtrList<Alarm> alarmList = incidence->alarms(); | 808 | QPtrList<Alarm> alarmList = incidence->alarms(); |
809 | Alarm *alarm; | 809 | Alarm *alarm; |
810 | QDateTime qdt; | 810 | QDateTime qdt; |
811 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 811 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
812 | if (incidence->recursOn(from.date())) { | 812 | if (incidence->recursOn(from.date())) { |
813 | qdt.setTime(alarm->time().time()); | 813 | qdt.setTime(alarm->time().time()); |
814 | qdt.setDate(from.date()); | 814 | qdt.setDate(from.date()); |
815 | } | 815 | } |
816 | else qdt = alarm->time(); | 816 | else qdt = alarm->time(); |
817 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 817 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
818 | if ( alarm->enabled() ) { | 818 | if ( alarm->enabled() ) { |
819 | if ( qdt >= from && qdt <= to ) { | 819 | if ( qdt >= from && qdt <= to ) { |
820 | alarms.append( alarm ); | 820 | alarms.append( alarm ); |
821 | } | 821 | } |
822 | } | 822 | } |
823 | } | 823 | } |
824 | } | 824 | } |
825 | 825 | ||
826 | 826 | ||
827 | /****************************** PROTECTED METHODS ****************************/ | 827 | /****************************** PROTECTED METHODS ****************************/ |
828 | 828 | ||
829 | // after changes are made to an event, this should be called. | 829 | // after changes are made to an event, this should be called. |
830 | void CalendarLocal::update( IncidenceBase *incidence ) | 830 | void CalendarLocal::update( IncidenceBase *incidence ) |
831 | { | 831 | { |
832 | incidence->setSyncStatus( Event::SYNCMOD ); | 832 | incidence->setSyncStatus( Event::SYNCMOD ); |
833 | incidence->setLastModified( QDateTime::currentDateTime() ); | 833 | incidence->setLastModified( QDateTime::currentDateTime() ); |
834 | // we should probably update the revision number here, | 834 | // we should probably update the revision number here, |
835 | // or internally in the Event itself when certain things change. | 835 | // or internally in the Event itself when certain things change. |
836 | // need to verify with ical documentation. | 836 | // need to verify with ical documentation. |
837 | 837 | ||
838 | setModified( true ); | 838 | setModified( true ); |
839 | } | 839 | } |
840 | 840 | ||
841 | void CalendarLocal::insertEvent( Event *event ) | 841 | void CalendarLocal::insertEvent( Event *event ) |
842 | { | 842 | { |
843 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 843 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
844 | } | 844 | } |
845 | 845 | ||
846 | 846 | ||
847 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 847 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
848 | { | 848 | { |
849 | QPtrList<Event> eventList; | 849 | QPtrList<Event> eventList; |
850 | 850 | ||
851 | Event *event; | 851 | Event *event; |
852 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 852 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
853 | if ( !event->calEnabled() ) continue; | 853 | if ( !event->calEnabled() ) continue; |
854 | if ( event->doesRecur() ) { | 854 | if ( event->doesRecur() ) { |
855 | if ( event->isMultiDay() ) { | 855 | if ( event->isMultiDay() ) { |
856 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 856 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
857 | int i; | 857 | int i; |
858 | for ( i = 0; i <= extraDays; i++ ) { | 858 | for ( i = 0; i <= extraDays; i++ ) { |
859 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 859 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
860 | eventList.append( event ); | 860 | eventList.append( event ); |
861 | break; | 861 | break; |
862 | } | 862 | } |
863 | } | 863 | } |
864 | } else { | 864 | } else { |
865 | if ( event->recursOn( qd ) ) | 865 | if ( event->recursOn( qd ) ) |
866 | eventList.append( event ); | 866 | eventList.append( event ); |
867 | } | 867 | } |
868 | } else { | 868 | } else { |
869 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 869 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
870 | eventList.append( event ); | 870 | eventList.append( event ); |
871 | } | 871 | } |
872 | } | 872 | } |
873 | } | 873 | } |
874 | 874 | ||
875 | if ( !sorted ) { | 875 | if ( !sorted ) { |
876 | return eventList; | 876 | return eventList; |
877 | } | 877 | } |
878 | 878 | ||
879 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 879 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
880 | // now, we have to sort it based on dtStart.time() | 880 | // now, we have to sort it based on dtStart.time() |
881 | QPtrList<Event> eventListSorted; | 881 | QPtrList<Event> eventListSorted; |
882 | Event *sortEvent; | 882 | Event *sortEvent; |
883 | for ( event = eventList.first(); event; event = eventList.next() ) { | 883 | for ( event = eventList.first(); event; event = eventList.next() ) { |
884 | sortEvent = eventListSorted.first(); | 884 | sortEvent = eventListSorted.first(); |
885 | int i = 0; | 885 | int i = 0; |
886 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 886 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
887 | { | 887 | { |
888 | i++; | 888 | i++; |
889 | sortEvent = eventListSorted.next(); | 889 | sortEvent = eventListSorted.next(); |
890 | } | 890 | } |
891 | eventListSorted.insert( i, event ); | 891 | eventListSorted.insert( i, event ); |
892 | } | 892 | } |
893 | return eventListSorted; | 893 | return eventListSorted; |
894 | } | 894 | } |
895 | 895 | ||
896 | 896 | ||
897 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 897 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
898 | bool inclusive ) | 898 | bool inclusive ) |
899 | { | 899 | { |
900 | Event *event = 0; | 900 | Event *event = 0; |
901 | 901 | ||
902 | QPtrList<Event> eventList; | 902 | QPtrList<Event> eventList; |
903 | 903 | ||
904 | // Get non-recurring events | 904 | // Get non-recurring events |
905 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 905 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
906 | if ( !event->calEnabled() ) continue; | 906 | if ( !event->calEnabled() ) continue; |
907 | if ( event->doesRecur() ) { | 907 | if ( event->doesRecur() ) { |
908 | QDate rStart = event->dtStart().date(); | 908 | QDate rStart = event->dtStart().date(); |
909 | bool found = false; | 909 | bool found = false; |
910 | if ( inclusive ) { | 910 | if ( inclusive ) { |
911 | if ( rStart >= start && rStart <= end ) { | 911 | if ( rStart >= start && rStart <= end ) { |
912 | // Start date of event is in range. Now check for end date. | 912 | // Start date of event is in range. Now check for end date. |
913 | // if duration is negative, event recurs forever, so do not include it. | 913 | // if duration is negative, event recurs forever, so do not include it. |
914 | if ( event->recurrence()->duration() == 0 ) { // End date set | 914 | if ( event->recurrence()->duration() == 0 ) { // End date set |
915 | QDate rEnd = event->recurrence()->endDate(); | 915 | QDate rEnd = event->recurrence()->endDate(); |
916 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 916 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
917 | found = true; | 917 | found = true; |
918 | } | 918 | } |
919 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 919 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
920 | // TODO: Calculate end date from duration. Should be done in Event | 920 | // TODO: Calculate end date from duration. Should be done in Event |
921 | // For now exclude all events with a duration. | 921 | // For now exclude all events with a duration. |
922 | } | 922 | } |
923 | } | 923 | } |
924 | } else { | 924 | } else { |
925 | bool founOne; | 925 | bool founOne; |
926 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 926 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
927 | if ( founOne ) { | 927 | if ( founOne ) { |
928 | if ( next <= end ) { | 928 | if ( next <= end ) { |
929 | found = true; | 929 | found = true; |
930 | } | 930 | } |
931 | } | 931 | } |
932 | 932 | ||
933 | /* | 933 | /* |
934 | // crap !!! | 934 | // crap !!! |
935 | if ( rStart <= end ) { // Start date not after range | 935 | if ( rStart <= end ) { // Start date not after range |
936 | if ( rStart >= start ) { // Start date within range | 936 | if ( rStart >= start ) { // Start date within range |
937 | found = true; | 937 | found = true; |
938 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 938 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
939 | found = true; | 939 | found = true; |
940 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 940 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
941 | QDate rEnd = event->recurrence()->endDate(); | 941 | QDate rEnd = event->recurrence()->endDate(); |
942 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 942 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
943 | found = true; | 943 | found = true; |
944 | } | 944 | } |
945 | } else { // Duration set | 945 | } else { // Duration set |
946 | // TODO: Calculate end date from duration. Should be done in Event | 946 | // TODO: Calculate end date from duration. Should be done in Event |
947 | // For now include all events with a duration. | 947 | // For now include all events with a duration. |
948 | found = true; | 948 | found = true; |
949 | } | 949 | } |
950 | } | 950 | } |
951 | */ | 951 | */ |
952 | 952 | ||
953 | } | 953 | } |
954 | 954 | ||
955 | if ( found ) eventList.append( event ); | 955 | if ( found ) eventList.append( event ); |
956 | } else { | 956 | } else { |
957 | QDate s = event->dtStart().date(); | 957 | QDate s = event->dtStart().date(); |
958 | QDate e = event->dtEnd().date(); | 958 | QDate e = event->dtEnd().date(); |
959 | 959 | ||
960 | if ( inclusive ) { | 960 | if ( inclusive ) { |
961 | if ( s >= start && e <= end ) { | 961 | if ( s >= start && e <= end ) { |
962 | eventList.append( event ); | 962 | eventList.append( event ); |
963 | } | 963 | } |
964 | } else { | 964 | } else { |
965 | if ( ( e >= start && s <= end ) ) { | 965 | if ( ( e >= start && s <= end ) ) { |
966 | eventList.append( event ); | 966 | eventList.append( event ); |
967 | } | 967 | } |
968 | } | 968 | } |
969 | } | 969 | } |
970 | } | 970 | } |
971 | 971 | ||
972 | return eventList; | 972 | return eventList; |
973 | } | 973 | } |
974 | 974 | ||
975 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 975 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
976 | { | 976 | { |
977 | return rawEventsForDate( qdt.date() ); | 977 | return rawEventsForDate( qdt.date() ); |
978 | } | 978 | } |
979 | 979 | ||
980 | QPtrList<Event> CalendarLocal::rawEvents() | 980 | QPtrList<Event> CalendarLocal::rawEvents() |
981 | { | 981 | { |
982 | QPtrList<Event> el; | 982 | QPtrList<Event> el; |
983 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 983 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
984 | if ( it->calEnabled() ) el.append( it ); | 984 | if ( it->calEnabled() ) el.append( it ); |
985 | return el; | 985 | return el; |
986 | } | 986 | } |
987 | 987 | ||
988 | bool CalendarLocal::addJournal(Journal *journal) | 988 | bool CalendarLocal::addJournal(Journal *journal) |
989 | { | 989 | { |
990 | mJournalList.append(journal); | 990 | mJournalList.append(journal); |
991 | 991 | ||
992 | journal->registerObserver( this ); | 992 | journal->registerObserver( this ); |
993 | 993 | ||
994 | setModified( true ); | 994 | setModified( true ); |
995 | if ( journal->calID() == 0 ) | 995 | if ( journal->calID() == 0 ) |
996 | journal->setCalID_block( mDefaultCalendar ); | 996 | journal->setCalID_block( mDefaultCalendar ); |
997 | journal->setCalEnabled( true ); | 997 | journal->setCalEnabled( true ); |
998 | return true; | 998 | return true; |
999 | } | 999 | } |
1000 | 1000 | ||
1001 | void CalendarLocal::deleteJournal( Journal *journal ) | 1001 | void CalendarLocal::deleteJournal( Journal *journal ) |
1002 | { | 1002 | { |
1003 | clearUndo(journal); | 1003 | clearUndo(journal); |
1004 | if ( mJournalList.removeRef(journal) ) { | 1004 | if ( mJournalList.removeRef(journal) ) { |
1005 | setModified( true ); | 1005 | setModified( true ); |
1006 | } | 1006 | } |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 1009 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
1010 | { | 1010 | { |
1011 | QPtrList<Journal> el; | 1011 | QPtrList<Journal> el; |
1012 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1012 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1013 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 1013 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
1014 | return el; | 1014 | return el; |
1015 | } | 1015 | } |
1016 | Journal *CalendarLocal::journal( const QDate &date ) | 1016 | Journal *CalendarLocal::journal( const QDate &date ) |
1017 | { | 1017 | { |
1018 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 1018 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
1019 | 1019 | ||
1020 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1020 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1021 | if ( it->calEnabled() && it->dtStart().date() == date ) | 1021 | if ( it->calEnabled() && it->dtStart().date() == date ) |
1022 | return it; | 1022 | return it; |
1023 | 1023 | ||
1024 | return 0; | 1024 | return 0; |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | Journal *CalendarLocal::journal( const QString &uid ) | 1027 | Journal *CalendarLocal::journal( const QString &uid ) |
1028 | { | 1028 | { |
1029 | Journal * retVal = 0; | 1029 | Journal * retVal = 0; |
1030 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1030 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1031 | if ( it->calEnabled() && it->uid() == uid ) { | 1031 | if ( it->calEnabled() && it->uid() == uid ) { |
1032 | if ( retVal ) { | 1032 | if ( retVal ) { |
1033 | if ( retVal->calID() > it->calID() ) { | 1033 | if ( retVal->calID() > it->calID() ) { |
1034 | retVal = it; | 1034 | retVal = it; |
1035 | } | 1035 | } |
1036 | } else { | 1036 | } else { |
1037 | retVal = it; | 1037 | retVal = it; |
1038 | } | 1038 | } |
1039 | } | 1039 | } |
1040 | return retVal; | 1040 | return retVal; |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | QPtrList<Journal> CalendarLocal::journals() | 1043 | QPtrList<Journal> CalendarLocal::journals() |
1044 | { | 1044 | { |
1045 | QPtrList<Journal> el; | 1045 | QPtrList<Journal> el; |
1046 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1046 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1047 | if ( it->calEnabled() ) el.append( it ); | 1047 | if ( it->calEnabled() ) el.append( it ); |
1048 | return el; | 1048 | return el; |
1049 | } | 1049 | } |
1050 | void CalendarLocal::setCalendarRemove( int id ) | 1050 | void CalendarLocal::setCalendarRemove( int id ) |
1051 | { | 1051 | { |
1052 | 1052 | ||
1053 | { | 1053 | { |
1054 | QPtrList<Event> EventList = mEventList; | 1054 | QPtrList<Event> EventList = mEventList; |
1055 | Event * ev = EventList.first(); | 1055 | Event * ev = EventList.first(); |
1056 | while ( ev ) { | 1056 | while ( ev ) { |
1057 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) | 1057 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) |
1058 | deleteEvent( ev ); | 1058 | deleteEvent( ev ); |
1059 | ev = EventList.next(); | 1059 | ev = EventList.next(); |
1060 | } | 1060 | } |
1061 | } | 1061 | } |
1062 | { | 1062 | { |
1063 | 1063 | ||
1064 | QPtrList<Todo> TodoList = mTodoList; | 1064 | QPtrList<Todo> TodoList = mTodoList; |
1065 | Todo * ev = TodoList.first(); | 1065 | Todo * ev = TodoList.first(); |
1066 | while ( ev ) { | 1066 | while ( ev ) { |
1067 | if ( ev->calID() == id ) | 1067 | if ( ev->calID() == id ) |
1068 | deleteTodo( ev ); | 1068 | deleteTodo( ev ); |
1069 | ev = TodoList.next(); | 1069 | ev = TodoList.next(); |
1070 | } | 1070 | } |
1071 | } | 1071 | } |
1072 | { | 1072 | { |
1073 | QPtrList<Journal> JournalList = mJournalList; | 1073 | QPtrList<Journal> JournalList = mJournalList; |
1074 | Journal * ev = JournalList.first(); | 1074 | Journal * ev = JournalList.first(); |
1075 | while ( ev ) { | 1075 | while ( ev ) { |
1076 | if ( ev->calID() == id ) | 1076 | if ( ev->calID() == id ) |
1077 | deleteJournal( ev ); | 1077 | deleteJournal( ev ); |
1078 | ev = JournalList.next(); | 1078 | ev = JournalList.next(); |
1079 | } | 1079 | } |
1080 | } | 1080 | } |
1081 | 1081 | ||
1082 | clearUndo(0); | 1082 | clearUndo(0); |
1083 | 1083 | ||
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | void CalendarLocal::setAllCalendarEnabled( bool enable ) | 1086 | void CalendarLocal::setAllCalendarEnabled( bool enable ) |
1087 | { | 1087 | { |
1088 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1088 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1089 | it->setCalEnabled( enable ); | 1089 | it->setCalEnabled( enable ); |
1090 | 1090 | ||
1091 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1091 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1092 | it->setCalEnabled( enable ); | 1092 | it->setCalEnabled( enable ); |
1093 | 1093 | ||
1094 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1094 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1095 | it->setCalEnabled( enable ); | 1095 | it->setCalEnabled( enable ); |
1096 | 1096 | ||
1097 | 1097 | ||
1098 | } | 1098 | } |
1099 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 1099 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
1100 | { | 1100 | { |
1101 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1101 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1102 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1102 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1103 | 1103 | ||
1104 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1104 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1105 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1105 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1106 | 1106 | ||
1107 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1107 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1108 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1108 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1109 | 1109 | ||
1110 | } | 1110 | } |
1111 | 1111 | ||
1112 | void CalendarLocal::setReadOnly( int id, bool enable ) | 1112 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1113 | { | 1113 | { |
1114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1115 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1115 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1116 | 1116 | ||
1117 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1117 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1118 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1118 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1119 | 1119 | ||
1120 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1120 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1121 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1121 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1122 | 1122 | ||
1123 | } | 1123 | } |
1124 | 1124 | ||
1125 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1125 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1126 | { | 1126 | { |
1127 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1127 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1128 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1128 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1129 | 1129 | ||
1130 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1130 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1131 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1131 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1132 | 1132 | ||
1133 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1133 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1134 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1134 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1135 | reInitAlarmSettings(); | 1135 | reInitAlarmSettings(); |
1136 | 1136 | ||
1137 | } | 1137 | } |
1138 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1138 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1139 | { | 1139 | { |
1140 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1140 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1141 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1141 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1142 | 1142 | ||
1143 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1143 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1144 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1144 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1145 | 1145 | ||
1146 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1146 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1147 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1147 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1148 | 1148 | ||
1149 | } | 1149 | } |