author | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 03:27:16 (UTC) |
commit | b7522a13b64225bb91bdab4a21b44282f8c3e3b4 (patch) (unidiff) | |
tree | 3aa005036dd83f3d0e5f57dd398dc260666daea1 /libkcal | |
parent | 084180efc1bccba341bf3f2f718fd10cdfdaf18e (diff) | |
download | kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.zip kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.gz kdepimpi-b7522a13b64225bb91bdab4a21b44282f8c3e3b4.tar.bz2 |
sync
-rw-r--r-- | libkcal/calendarlocal.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 980663f..8a5a76f 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,1140 +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 | { | 263 | { |
263 | QPtrList<Event> EventList = cal->rawEvents(); | 264 | QPtrList<Event> EventList = cal->rawEvents(); |
264 | QPtrList<Event> el; | ||
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 | Event * se = event( ev->uid() ); | ||
269 | if ( se ) | ||
270 | el.append( se ); | ||
271 | ev->setCalID_block( 1 ); | 268 | ev->setCalID_block( 1 ); |
272 | } | 269 | } |
270 | Event * se = event( ev->uid() ); | ||
271 | if ( 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 | for ( ev = el.first(); ev; ev = el.next() ) { | 278 | |
279 | deleteIncidence ( ev ); | ||
280 | } | ||
281 | } | 279 | } |
282 | { | 280 | { |
283 | 281 | ||
284 | QPtrList<Todo> TodoList = cal->rawTodos(); | 282 | QPtrList<Todo> TodoList = cal->rawTodos(); |
285 | Todo * ev = TodoList.first(); | 283 | Todo * ev = TodoList.first(); |
286 | while ( ev ) { | 284 | while ( ev ) { |
287 | ev->resetRelatedTo(); | 285 | ev->resetRelatedTo(); |
288 | ev = TodoList.next(); | 286 | ev = TodoList.next(); |
289 | } | 287 | } |
290 | //TodoList = cal->rawTodos(); | 288 | //TodoList = cal->rawTodos(); |
291 | ev = TodoList.first(); | 289 | ev = TodoList.first(); |
292 | while ( ev ) { | 290 | while ( ev ) { |
291 | Todo * se = todo( ev->uid() ); | ||
292 | if ( se ) | ||
293 | incList.append( se ); | ||
293 | ev->unRegisterObserver( cal ); | 294 | ev->unRegisterObserver( cal ); |
294 | ev->registerObserver( this ); | 295 | ev->registerObserver( this ); |
295 | mTodoList.append( ev ); | 296 | mTodoList.append( ev ); |
296 | setupRelations( ev ); | 297 | setupRelations( ev ); |
297 | ev = TodoList.next(); | 298 | ev = TodoList.next(); |
298 | } | 299 | } |
299 | } | 300 | } |
300 | { | 301 | { |
301 | QPtrList<Journal> JournalList = cal->journals(); | 302 | QPtrList<Journal> JournalList = cal->journals(); |
302 | Journal * ev = JournalList.first(); | 303 | Journal * ev = JournalList.first(); |
303 | while ( ev ) { | 304 | while ( ev ) { |
305 | Journal * se = journal( ev->uid() ); | ||
306 | if ( se ) | ||
307 | incList.append( se ); | ||
304 | ev->unRegisterObserver( cal ); | 308 | ev->unRegisterObserver( cal ); |
305 | ev->registerObserver( this ); | 309 | ev->registerObserver( this ); |
306 | mJournalList.append( ev ); | 310 | mJournalList.append( ev ); |
307 | ev = JournalList.next(); | 311 | ev = JournalList.next(); |
308 | } | 312 | } |
309 | } | 313 | } |
314 | { | ||
315 | for (Incidence * ev = incList.first(); ev; ev = incList.next() ) { | ||
316 | deleteIncidence ( ev ); | ||
317 | } | ||
318 | } | ||
310 | setModified( true ); | 319 | setModified( true ); |
311 | } | 320 | } |
312 | bool CalendarLocal::load( const QString &fileName ) | 321 | bool CalendarLocal::load( const QString &fileName ) |
313 | { | 322 | { |
314 | FileStorage storage( this, fileName ); | 323 | FileStorage storage( this, fileName ); |
315 | return storage.load(); | 324 | return storage.load(); |
316 | } | 325 | } |
317 | 326 | ||
318 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 327 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
319 | { | 328 | { |
320 | FileStorage storage( this, fileName, format ); | 329 | FileStorage storage( this, fileName, format ); |
321 | return storage.save(); | 330 | return storage.save(); |
322 | } | 331 | } |
323 | 332 | ||
324 | void CalendarLocal::stopAllTodos() | 333 | void CalendarLocal::stopAllTodos() |
325 | { | 334 | { |
326 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 335 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
327 | it->setRunning( false ); | 336 | it->setRunning( false ); |
328 | 337 | ||
329 | } | 338 | } |
330 | void CalendarLocal::close() | 339 | void CalendarLocal::close() |
331 | { | 340 | { |
332 | 341 | ||
333 | Todo * i; | 342 | Todo * i; |
334 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 343 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
335 | 344 | ||
336 | mEventList.setAutoDelete( true ); | 345 | mEventList.setAutoDelete( true ); |
337 | mTodoList.setAutoDelete( true ); | 346 | mTodoList.setAutoDelete( true ); |
338 | mJournalList.setAutoDelete( true ); | 347 | mJournalList.setAutoDelete( true ); |
339 | 348 | ||
340 | mEventList.clear(); | 349 | mEventList.clear(); |
341 | mTodoList.clear(); | 350 | mTodoList.clear(); |
342 | mJournalList.clear(); | 351 | mJournalList.clear(); |
343 | 352 | ||
344 | mEventList.setAutoDelete( false ); | 353 | mEventList.setAutoDelete( false ); |
345 | mTodoList.setAutoDelete( false ); | 354 | mTodoList.setAutoDelete( false ); |
346 | mJournalList.setAutoDelete( false ); | 355 | mJournalList.setAutoDelete( false ); |
347 | 356 | ||
348 | setModified( false ); | 357 | setModified( false ); |
349 | } | 358 | } |
350 | 359 | ||
351 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 360 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
352 | { | 361 | { |
353 | QString cat; | 362 | QString cat; |
354 | bool isBirthday = true; | 363 | bool isBirthday = true; |
355 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 364 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
356 | isBirthday = false; | 365 | isBirthday = false; |
357 | cat = i18n( "Anniversary" ); | 366 | cat = i18n( "Anniversary" ); |
358 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 367 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
359 | isBirthday = true; | 368 | isBirthday = true; |
360 | cat = i18n( "Birthday" ); | 369 | cat = i18n( "Birthday" ); |
361 | } else { | 370 | } else { |
362 | qDebug("addAnniversaryNoDup called without fitting category! "); | 371 | qDebug("addAnniversaryNoDup called without fitting category! "); |
363 | return false; | 372 | return false; |
364 | } | 373 | } |
365 | Event * eve; | 374 | Event * eve; |
366 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 375 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
367 | if ( !(eve->categories().contains( cat ) )) | 376 | if ( !(eve->categories().contains( cat ) )) |
368 | continue; | 377 | continue; |
369 | // now we have an event with fitting category | 378 | // now we have an event with fitting category |
370 | if ( eve->dtStart().date() != event->dtStart().date() ) | 379 | if ( eve->dtStart().date() != event->dtStart().date() ) |
371 | continue; | 380 | continue; |
372 | // now we have an event with fitting category+date | 381 | // now we have an event with fitting category+date |
373 | if ( eve->summary() != event->summary() ) | 382 | if ( eve->summary() != event->summary() ) |
374 | continue; | 383 | continue; |
375 | // now we have an event with fitting category+date+summary | 384 | // now we have an event with fitting category+date+summary |
376 | return false; | 385 | return false; |
377 | } | 386 | } |
378 | return addEvent( event ); | 387 | return addEvent( event ); |
379 | 388 | ||
380 | } | 389 | } |
381 | bool CalendarLocal::addEventNoDup( Event *event ) | 390 | bool CalendarLocal::addEventNoDup( Event *event ) |
382 | { | 391 | { |
383 | Event * eve; | 392 | Event * eve; |
384 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 393 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
385 | if ( *eve == *event ) { | 394 | if ( *eve == *event ) { |
386 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 395 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
387 | return false; | 396 | return false; |
388 | } | 397 | } |
389 | } | 398 | } |
390 | return addEvent( event ); | 399 | return addEvent( event ); |
391 | } | 400 | } |
392 | 401 | ||
393 | bool CalendarLocal::addEvent( Event *event ) | 402 | bool CalendarLocal::addEvent( Event *event ) |
394 | { | 403 | { |
395 | insertEvent( event ); | 404 | insertEvent( event ); |
396 | 405 | ||
397 | event->registerObserver( this ); | 406 | event->registerObserver( this ); |
398 | 407 | ||
399 | setModified( true ); | 408 | setModified( true ); |
400 | if ( event->calID() == 0 ) | 409 | if ( event->calID() == 0 ) |
401 | event->setCalID_block( mDefaultCalendar ); | 410 | event->setCalID_block( mDefaultCalendar ); |
402 | event->setCalEnabled( true ); | 411 | event->setCalEnabled( true ); |
403 | 412 | ||
404 | return true; | 413 | return true; |
405 | } | 414 | } |
406 | 415 | ||
407 | void CalendarLocal::deleteEvent( Event *event ) | 416 | void CalendarLocal::deleteEvent( Event *event ) |
408 | { | 417 | { |
409 | clearUndo(event); | 418 | clearUndo(event); |
410 | if ( mEventList.removeRef( event ) ) { | 419 | if ( mEventList.removeRef( event ) ) { |
411 | setModified( true ); | 420 | setModified( true ); |
412 | } | 421 | } |
413 | } | 422 | } |
414 | 423 | ||
415 | 424 | ||
416 | Event *CalendarLocal::event( const QString &uid ) | 425 | Event *CalendarLocal::event( const QString &uid ) |
417 | { | 426 | { |
418 | Event *event; | 427 | Event *event; |
419 | Event *retVal = 0; | 428 | Event *retVal = 0; |
420 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 429 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
421 | if ( event->calEnabled() && event->uid() == uid ) { | 430 | if ( event->calEnabled() && event->uid() == uid ) { |
422 | if ( retVal ) { | 431 | if ( retVal ) { |
423 | if ( retVal->calID() > event->calID() ) { | 432 | if ( retVal->calID() > event->calID() ) { |
424 | retVal = event; | 433 | retVal = event; |
425 | } | 434 | } |
426 | } else { | 435 | } else { |
427 | retVal = event; | 436 | retVal = event; |
428 | } | 437 | } |
429 | } | 438 | } |
430 | } | 439 | } |
431 | return retVal; | 440 | return retVal; |
432 | } | 441 | } |
433 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 442 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
434 | { | 443 | { |
435 | Todo * eve; | 444 | Todo * eve; |
436 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 445 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
437 | if ( *eve == *todo ) { | 446 | if ( *eve == *todo ) { |
438 | //qDebug("duplicate todo found! not inserted! "); | 447 | //qDebug("duplicate todo found! not inserted! "); |
439 | return false; | 448 | return false; |
440 | } | 449 | } |
441 | } | 450 | } |
442 | return addTodo( todo ); | 451 | return addTodo( todo ); |
443 | } | 452 | } |
444 | bool CalendarLocal::addTodo( Todo *todo ) | 453 | bool CalendarLocal::addTodo( Todo *todo ) |
445 | { | 454 | { |
446 | mTodoList.append( todo ); | 455 | mTodoList.append( todo ); |
447 | 456 | ||
448 | todo->registerObserver( this ); | 457 | todo->registerObserver( this ); |
449 | 458 | ||
450 | // Set up subtask relations | 459 | // Set up subtask relations |
451 | setupRelations( todo ); | 460 | setupRelations( todo ); |
452 | 461 | ||
453 | setModified( true ); | 462 | setModified( true ); |
454 | if ( todo->calID() == 0 ) | 463 | if ( todo->calID() == 0 ) |
455 | todo->setCalID_block( mDefaultCalendar ); | 464 | todo->setCalID_block( mDefaultCalendar ); |
456 | todo->setCalEnabled( true ); | 465 | todo->setCalEnabled( true ); |
457 | return true; | 466 | return true; |
458 | } | 467 | } |
459 | 468 | ||
460 | void CalendarLocal::deleteTodo( Todo *todo ) | 469 | void CalendarLocal::deleteTodo( Todo *todo ) |
461 | { | 470 | { |
462 | QString uid = todo->uid(); | 471 | QString uid = todo->uid(); |
463 | // Handle orphaned children | 472 | // Handle orphaned children |
464 | removeRelations( todo ); | 473 | removeRelations( todo ); |
465 | clearUndo(todo); | 474 | clearUndo(todo); |
466 | 475 | ||
467 | if ( mTodoList.removeRef( todo ) ) { | 476 | if ( mTodoList.removeRef( todo ) ) { |
468 | setModified( true ); | 477 | setModified( true ); |
469 | } | 478 | } |
470 | Todo* dup = todoForUid( uid ); | 479 | Todo* dup = todoForUid( uid ); |
471 | if ( dup ) | 480 | if ( dup ) |
472 | setupRelations( dup ); | 481 | setupRelations( dup ); |
473 | } | 482 | } |
474 | 483 | ||
475 | QPtrList<Todo> CalendarLocal::rawTodos() | 484 | QPtrList<Todo> CalendarLocal::rawTodos() |
476 | { | 485 | { |
477 | QPtrList<Todo> el; | 486 | QPtrList<Todo> el; |
478 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 487 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
479 | if ( it->calEnabled() ) el.append( it ); | 488 | if ( it->calEnabled() ) el.append( it ); |
480 | return el; | 489 | return el; |
481 | } | 490 | } |
482 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 491 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
483 | { | 492 | { |
484 | Todo *todo; | 493 | Todo *todo; |
485 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 494 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
486 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 495 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
487 | } | 496 | } |
488 | 497 | ||
489 | return 0; | 498 | return 0; |
490 | } | 499 | } |
491 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 500 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
492 | { | 501 | { |
493 | QPtrList<Incidence> all = rawIncidences() ; | 502 | QPtrList<Incidence> all = rawIncidences() ; |
494 | Incidence *inc; | 503 | Incidence *inc; |
495 | for ( inc = all.first(); inc; inc = all.next() ) { | 504 | for ( inc = all.first(); inc; inc = all.next() ) { |
496 | inc->removeID( syncProfile ); | 505 | inc->removeID( syncProfile ); |
497 | } | 506 | } |
498 | if ( syncProfile.isEmpty() ) { | 507 | if ( syncProfile.isEmpty() ) { |
499 | QPtrList<Event> el; | 508 | QPtrList<Event> el; |
500 | Event *todo; | 509 | Event *todo; |
501 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 510 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
502 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 511 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
503 | el.append( todo ); | 512 | el.append( todo ); |
504 | } | 513 | } |
505 | for ( todo = el.first(); todo; todo = el.next() ) { | 514 | for ( todo = el.first(); todo; todo = el.next() ) { |
506 | deleteIncidence ( todo ); | 515 | deleteIncidence ( todo ); |
507 | } | 516 | } |
508 | } else { | 517 | } else { |
509 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 518 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
510 | if ( lse ) | 519 | if ( lse ) |
511 | deleteIncidence ( lse ); | 520 | deleteIncidence ( lse ); |
512 | } | 521 | } |
513 | } | 522 | } |
514 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 523 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
515 | { | 524 | { |
516 | QPtrList<Event> el; | 525 | QPtrList<Event> el; |
517 | Event *todo; | 526 | Event *todo; |
518 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 527 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
519 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 528 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
520 | if ( todo->summary().left(3) == "E: " ) | 529 | if ( todo->summary().left(3) == "E: " ) |
521 | el.append( todo ); | 530 | el.append( todo ); |
522 | } | 531 | } |
523 | 532 | ||
524 | return el; | 533 | return el; |
525 | 534 | ||
526 | } | 535 | } |
527 | Event *CalendarLocal::event( QString syncProf, QString id ) | 536 | Event *CalendarLocal::event( QString syncProf, QString id ) |
528 | { | 537 | { |
529 | Event *todo; | 538 | Event *todo; |
530 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 539 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
531 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 540 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
532 | } | 541 | } |
533 | 542 | ||
534 | return 0; | 543 | return 0; |
535 | } | 544 | } |
536 | Todo *CalendarLocal::todo( const QString &uid ) | 545 | Todo *CalendarLocal::todo( const QString &uid ) |
537 | { | 546 | { |
538 | Todo *todo; | 547 | Todo *todo; |
539 | Todo *retVal = 0; | 548 | Todo *retVal = 0; |
540 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 549 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
541 | if ( todo->calEnabled() && todo->uid() == uid ) { | 550 | if ( todo->calEnabled() && todo->uid() == uid ) { |
542 | if ( retVal ) { | 551 | if ( retVal ) { |
543 | if ( retVal->calID() > todo->calID() ) { | 552 | if ( retVal->calID() > todo->calID() ) { |
544 | retVal = todo; | 553 | retVal = todo; |
545 | } | 554 | } |
546 | } else { | 555 | } else { |
547 | retVal = todo; | 556 | retVal = todo; |
548 | } | 557 | } |
549 | } | 558 | } |
550 | } | 559 | } |
551 | return retVal; | 560 | return retVal; |
552 | } | 561 | } |
553 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | 562 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) |
554 | { | 563 | { |
555 | events = 0; | 564 | events = 0; |
556 | todos = 0; | 565 | todos = 0; |
557 | journals = 0; | 566 | journals = 0; |
558 | { | 567 | { |
559 | Todo *todo; | 568 | Todo *todo; |
560 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 569 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
561 | if ( todo->calID() == calId ) | 570 | if ( todo->calID() == calId ) |
562 | ++todos; | 571 | ++todos; |
563 | } | 572 | } |
564 | } | 573 | } |
565 | { | 574 | { |
566 | Event *todo; | 575 | Event *todo; |
567 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 576 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
568 | if ( todo->calID() == calId ) | 577 | if ( todo->calID() == calId ) |
569 | ++events; | 578 | ++events; |
570 | 579 | ||
571 | } | 580 | } |
572 | } | 581 | } |
573 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 582 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
574 | if ( it->calID() == calId ) ++journals; | 583 | if ( it->calID() == calId ) ++journals; |
575 | 584 | ||
576 | } | 585 | } |
577 | QString CalendarLocal::nextSummary() const | 586 | QString CalendarLocal::nextSummary() const |
578 | { | 587 | { |
579 | return mNextSummary; | 588 | return mNextSummary; |
580 | } | 589 | } |
581 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 590 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
582 | { | 591 | { |
583 | return mNextAlarmEventDateTime; | 592 | return mNextAlarmEventDateTime; |
584 | } | 593 | } |
585 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 594 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
586 | { | 595 | { |
587 | //mNextAlarmIncidence | 596 | //mNextAlarmIncidence |
588 | //mNextAlarmDateTime | 597 | //mNextAlarmDateTime |
589 | //return mNextSummary; | 598 | //return mNextSummary; |
590 | //return mNextAlarmEventDateTime; | 599 | //return mNextAlarmEventDateTime; |
591 | bool newNextAlarm = false; | 600 | bool newNextAlarm = false; |
592 | bool computeNextAlarm = false; | 601 | bool computeNextAlarm = false; |
593 | bool ok; | 602 | bool ok; |
594 | int offset; | 603 | int offset; |
595 | QDateTime nextA; | 604 | QDateTime nextA; |
596 | // QString nextSum; | 605 | // QString nextSum; |
597 | //QDateTime nextEvent; | 606 | //QDateTime nextEvent; |
598 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 607 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
599 | computeNextAlarm = true; | 608 | computeNextAlarm = true; |
600 | } else { | 609 | } else { |
601 | if ( ! deleted ) { | 610 | if ( ! deleted ) { |
602 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 611 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
603 | if ( ok ) { | 612 | if ( ok ) { |
604 | if ( nextA < mNextAlarmDateTime ) { | 613 | if ( nextA < mNextAlarmDateTime ) { |
605 | deRegisterAlarm(); | 614 | deRegisterAlarm(); |
606 | mNextAlarmDateTime = nextA; | 615 | mNextAlarmDateTime = nextA; |
607 | mNextSummary = incidence->summary(); | 616 | mNextSummary = incidence->summary(); |
608 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 617 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
609 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 618 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
610 | newNextAlarm = true; | 619 | newNextAlarm = true; |
611 | mNextAlarmIncidence = incidence; | 620 | mNextAlarmIncidence = incidence; |
612 | } else { | 621 | } else { |
613 | if ( incidence == mNextAlarmIncidence ) { | 622 | if ( incidence == mNextAlarmIncidence ) { |
614 | computeNextAlarm = true; | 623 | computeNextAlarm = true; |
615 | } | 624 | } |
616 | } | 625 | } |
617 | } else { | 626 | } else { |
618 | if ( mNextAlarmIncidence == incidence ) { | 627 | if ( mNextAlarmIncidence == incidence ) { |
619 | computeNextAlarm = true; | 628 | computeNextAlarm = true; |
620 | } | 629 | } |
621 | } | 630 | } |
622 | } else { // deleted | 631 | } else { // deleted |
623 | if ( incidence == mNextAlarmIncidence ) { | 632 | if ( incidence == mNextAlarmIncidence ) { |
624 | computeNextAlarm = true; | 633 | computeNextAlarm = true; |
625 | } | 634 | } |
626 | } | 635 | } |
627 | } | 636 | } |
628 | if ( computeNextAlarm ) { | 637 | if ( computeNextAlarm ) { |
629 | deRegisterAlarm(); | 638 | deRegisterAlarm(); |
630 | nextA = nextAlarm( 1000 ); | 639 | nextA = nextAlarm( 1000 ); |
631 | if (! mNextAlarmIncidence ) { | 640 | if (! mNextAlarmIncidence ) { |
632 | return; | 641 | return; |
633 | } | 642 | } |
634 | newNextAlarm = true; | 643 | newNextAlarm = true; |
635 | } | 644 | } |
636 | if ( newNextAlarm ) | 645 | if ( newNextAlarm ) |
637 | registerAlarm(); | 646 | registerAlarm(); |
638 | } | 647 | } |
639 | QString CalendarLocal:: getAlarmNotification() | 648 | QString CalendarLocal:: getAlarmNotification() |
640 | { | 649 | { |
641 | QString ret; | 650 | QString ret; |
642 | // this should not happen | 651 | // this should not happen |
643 | if (! mNextAlarmIncidence ) | 652 | if (! mNextAlarmIncidence ) |
644 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 653 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
645 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 654 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
646 | if ( alarm->type() == Alarm::Procedure ) { | 655 | if ( alarm->type() == Alarm::Procedure ) { |
647 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 656 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
648 | } else { | 657 | } else { |
649 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 658 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
650 | } | 659 | } |
651 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 660 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
652 | if ( mNextSummary.length() > 25 ) | 661 | if ( mNextSummary.length() > 25 ) |
653 | ret += "\n" + mNextSummary.mid(25, 25 ); | 662 | ret += "\n" + mNextSummary.mid(25, 25 ); |
654 | ret+= "\n"+mNextAlarmEventDateTimeString; | 663 | ret+= "\n"+mNextAlarmEventDateTimeString; |
655 | return ret; | 664 | return ret; |
656 | } | 665 | } |
657 | void CalendarLocal::registerAlarm() | 666 | void CalendarLocal::registerAlarm() |
658 | { | 667 | { |
659 | mLastAlarmNotificationString = getAlarmNotification(); | 668 | mLastAlarmNotificationString = getAlarmNotification(); |
660 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 669 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
661 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 670 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
662 | // #ifndef DESKTOP_VERSION | 671 | // #ifndef DESKTOP_VERSION |
663 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 672 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
664 | // #endif | 673 | // #endif |
665 | } | 674 | } |
666 | void CalendarLocal::deRegisterAlarm() | 675 | void CalendarLocal::deRegisterAlarm() |
667 | { | 676 | { |
668 | if ( mLastAlarmNotificationString.isNull() ) | 677 | if ( mLastAlarmNotificationString.isNull() ) |
669 | return; | 678 | return; |
670 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 679 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
671 | 680 | ||
672 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 681 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
673 | mNextAlarmEventDateTime = QDateTime(); | 682 | mNextAlarmEventDateTime = QDateTime(); |
674 | // #ifndef DESKTOP_VERSION | 683 | // #ifndef DESKTOP_VERSION |
675 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 684 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
676 | // #endif | 685 | // #endif |
677 | } | 686 | } |
678 | 687 | ||
679 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 688 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
680 | { | 689 | { |
681 | QPtrList<Todo> todos; | 690 | QPtrList<Todo> todos; |
682 | 691 | ||
683 | Todo *todo; | 692 | Todo *todo; |
684 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 693 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
685 | if ( !todo->calEnabled() ) continue; | 694 | if ( !todo->calEnabled() ) continue; |
686 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 695 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
687 | todos.append( todo ); | 696 | todos.append( todo ); |
688 | } | 697 | } |
689 | } | 698 | } |
690 | 699 | ||
691 | filter()->apply( &todos ); | 700 | filter()->apply( &todos ); |
692 | return todos; | 701 | return todos; |
693 | } | 702 | } |
694 | void CalendarLocal::reInitAlarmSettings() | 703 | void CalendarLocal::reInitAlarmSettings() |
695 | { | 704 | { |
696 | if ( !mNextAlarmIncidence ) { | 705 | if ( !mNextAlarmIncidence ) { |
697 | nextAlarm( 1000 ); | 706 | nextAlarm( 1000 ); |
698 | } | 707 | } |
699 | deRegisterAlarm(); | 708 | deRegisterAlarm(); |
700 | mNextAlarmIncidence = 0; | 709 | mNextAlarmIncidence = 0; |
701 | checkAlarmForIncidence( 0, false ); | 710 | checkAlarmForIncidence( 0, false ); |
702 | 711 | ||
703 | } | 712 | } |
704 | 713 | ||
705 | 714 | ||
706 | 715 | ||
707 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 716 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
708 | { | 717 | { |
709 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 718 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
710 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 719 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
711 | QDateTime next; | 720 | QDateTime next; |
712 | Event *e; | 721 | Event *e; |
713 | bool ok; | 722 | bool ok; |
714 | bool found = false; | 723 | bool found = false; |
715 | int offset; | 724 | int offset; |
716 | mNextAlarmIncidence = 0; | 725 | mNextAlarmIncidence = 0; |
717 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 726 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
718 | if ( !e->calEnabled() ) continue; | 727 | if ( !e->calEnabled() ) continue; |
719 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 728 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
720 | if ( ok ) { | 729 | if ( ok ) { |
721 | if ( next < nextA ) { | 730 | if ( next < nextA ) { |
722 | nextA = next; | 731 | nextA = next; |
723 | found = true; | 732 | found = true; |
724 | mNextSummary = e->summary(); | 733 | mNextSummary = e->summary(); |
725 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 734 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
726 | mNextAlarmIncidence = (Incidence *) e; | 735 | mNextAlarmIncidence = (Incidence *) e; |
727 | } | 736 | } |
728 | } | 737 | } |
729 | } | 738 | } |
730 | Todo *t; | 739 | Todo *t; |
731 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 740 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
732 | if ( !t->calEnabled() ) continue; | 741 | if ( !t->calEnabled() ) continue; |
733 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 742 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
734 | if ( ok ) { | 743 | if ( ok ) { |
735 | if ( next < nextA ) { | 744 | if ( next < nextA ) { |
736 | nextA = next; | 745 | nextA = next; |
737 | found = true; | 746 | found = true; |
738 | mNextSummary = t->summary(); | 747 | mNextSummary = t->summary(); |
739 | mNextAlarmEventDateTime = next.addSecs(offset ); | 748 | mNextAlarmEventDateTime = next.addSecs(offset ); |
740 | mNextAlarmIncidence = (Incidence *) t; | 749 | mNextAlarmIncidence = (Incidence *) t; |
741 | } | 750 | } |
742 | } | 751 | } |
743 | } | 752 | } |
744 | if ( mNextAlarmIncidence ) { | 753 | if ( mNextAlarmIncidence ) { |
745 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 754 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
746 | mNextAlarmDateTime = nextA; | 755 | mNextAlarmDateTime = nextA; |
747 | } | 756 | } |
748 | return nextA; | 757 | return nextA; |
749 | } | 758 | } |
750 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 759 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
751 | { | 760 | { |
752 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 761 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
753 | } | 762 | } |
754 | 763 | ||
755 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 764 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
756 | { | 765 | { |
757 | 766 | ||
758 | Alarm::List alarms; | 767 | Alarm::List alarms; |
759 | 768 | ||
760 | Event *e; | 769 | Event *e; |
761 | 770 | ||
762 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 771 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
763 | if ( !e->calEnabled() ) continue; | 772 | if ( !e->calEnabled() ) continue; |
764 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 773 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
765 | else appendAlarms( alarms, e, from, to ); | 774 | else appendAlarms( alarms, e, from, to ); |
766 | } | 775 | } |
767 | 776 | ||
768 | Todo *t; | 777 | Todo *t; |
769 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 778 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
770 | if ( !t->calEnabled() ) continue; | 779 | if ( !t->calEnabled() ) continue; |
771 | appendAlarms( alarms, t, from, to ); | 780 | appendAlarms( alarms, t, from, to ); |
772 | } | 781 | } |
773 | 782 | ||
774 | return alarms; | 783 | return alarms; |
775 | } | 784 | } |
776 | 785 | ||
777 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 786 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
778 | const QDateTime &from, const QDateTime &to ) | 787 | const QDateTime &from, const QDateTime &to ) |
779 | { | 788 | { |
780 | QPtrList<Alarm> alarmList = incidence->alarms(); | 789 | QPtrList<Alarm> alarmList = incidence->alarms(); |
781 | Alarm *alarm; | 790 | Alarm *alarm; |
782 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 791 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
783 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 792 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
784 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 793 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
785 | if ( alarm->enabled() ) { | 794 | if ( alarm->enabled() ) { |
786 | if ( alarm->time() >= from && alarm->time() <= to ) { | 795 | if ( alarm->time() >= from && alarm->time() <= to ) { |
787 | alarms.append( alarm ); | 796 | alarms.append( alarm ); |
788 | } | 797 | } |
789 | } | 798 | } |
790 | } | 799 | } |
791 | } | 800 | } |
792 | 801 | ||
793 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 802 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
794 | Incidence *incidence, | 803 | Incidence *incidence, |
795 | const QDateTime &from, | 804 | const QDateTime &from, |
796 | const QDateTime &to ) | 805 | const QDateTime &to ) |
797 | { | 806 | { |
798 | 807 | ||
799 | QPtrList<Alarm> alarmList = incidence->alarms(); | 808 | QPtrList<Alarm> alarmList = incidence->alarms(); |
800 | Alarm *alarm; | 809 | Alarm *alarm; |
801 | QDateTime qdt; | 810 | QDateTime qdt; |
802 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 811 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
803 | if (incidence->recursOn(from.date())) { | 812 | if (incidence->recursOn(from.date())) { |
804 | qdt.setTime(alarm->time().time()); | 813 | qdt.setTime(alarm->time().time()); |
805 | qdt.setDate(from.date()); | 814 | qdt.setDate(from.date()); |
806 | } | 815 | } |
807 | else qdt = alarm->time(); | 816 | else qdt = alarm->time(); |
808 | // 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()); |
809 | if ( alarm->enabled() ) { | 818 | if ( alarm->enabled() ) { |
810 | if ( qdt >= from && qdt <= to ) { | 819 | if ( qdt >= from && qdt <= to ) { |
811 | alarms.append( alarm ); | 820 | alarms.append( alarm ); |
812 | } | 821 | } |
813 | } | 822 | } |
814 | } | 823 | } |
815 | } | 824 | } |
816 | 825 | ||
817 | 826 | ||
818 | /****************************** PROTECTED METHODS ****************************/ | 827 | /****************************** PROTECTED METHODS ****************************/ |
819 | 828 | ||
820 | // after changes are made to an event, this should be called. | 829 | // after changes are made to an event, this should be called. |
821 | void CalendarLocal::update( IncidenceBase *incidence ) | 830 | void CalendarLocal::update( IncidenceBase *incidence ) |
822 | { | 831 | { |
823 | incidence->setSyncStatus( Event::SYNCMOD ); | 832 | incidence->setSyncStatus( Event::SYNCMOD ); |
824 | incidence->setLastModified( QDateTime::currentDateTime() ); | 833 | incidence->setLastModified( QDateTime::currentDateTime() ); |
825 | // we should probably update the revision number here, | 834 | // we should probably update the revision number here, |
826 | // or internally in the Event itself when certain things change. | 835 | // or internally in the Event itself when certain things change. |
827 | // need to verify with ical documentation. | 836 | // need to verify with ical documentation. |
828 | 837 | ||
829 | setModified( true ); | 838 | setModified( true ); |
830 | } | 839 | } |
831 | 840 | ||
832 | void CalendarLocal::insertEvent( Event *event ) | 841 | void CalendarLocal::insertEvent( Event *event ) |
833 | { | 842 | { |
834 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 843 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
835 | } | 844 | } |
836 | 845 | ||
837 | 846 | ||
838 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 847 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
839 | { | 848 | { |
840 | QPtrList<Event> eventList; | 849 | QPtrList<Event> eventList; |
841 | 850 | ||
842 | Event *event; | 851 | Event *event; |
843 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 852 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
844 | if ( !event->calEnabled() ) continue; | 853 | if ( !event->calEnabled() ) continue; |
845 | if ( event->doesRecur() ) { | 854 | if ( event->doesRecur() ) { |
846 | if ( event->isMultiDay() ) { | 855 | if ( event->isMultiDay() ) { |
847 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 856 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
848 | int i; | 857 | int i; |
849 | for ( i = 0; i <= extraDays; i++ ) { | 858 | for ( i = 0; i <= extraDays; i++ ) { |
850 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 859 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
851 | eventList.append( event ); | 860 | eventList.append( event ); |
852 | break; | 861 | break; |
853 | } | 862 | } |
854 | } | 863 | } |
855 | } else { | 864 | } else { |
856 | if ( event->recursOn( qd ) ) | 865 | if ( event->recursOn( qd ) ) |
857 | eventList.append( event ); | 866 | eventList.append( event ); |
858 | } | 867 | } |
859 | } else { | 868 | } else { |
860 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 869 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
861 | eventList.append( event ); | 870 | eventList.append( event ); |
862 | } | 871 | } |
863 | } | 872 | } |
864 | } | 873 | } |
865 | 874 | ||
866 | if ( !sorted ) { | 875 | if ( !sorted ) { |
867 | return eventList; | 876 | return eventList; |
868 | } | 877 | } |
869 | 878 | ||
870 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 879 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
871 | // now, we have to sort it based on dtStart.time() | 880 | // now, we have to sort it based on dtStart.time() |
872 | QPtrList<Event> eventListSorted; | 881 | QPtrList<Event> eventListSorted; |
873 | Event *sortEvent; | 882 | Event *sortEvent; |
874 | for ( event = eventList.first(); event; event = eventList.next() ) { | 883 | for ( event = eventList.first(); event; event = eventList.next() ) { |
875 | sortEvent = eventListSorted.first(); | 884 | sortEvent = eventListSorted.first(); |
876 | int i = 0; | 885 | int i = 0; |
877 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 886 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
878 | { | 887 | { |
879 | i++; | 888 | i++; |
880 | sortEvent = eventListSorted.next(); | 889 | sortEvent = eventListSorted.next(); |
881 | } | 890 | } |
882 | eventListSorted.insert( i, event ); | 891 | eventListSorted.insert( i, event ); |
883 | } | 892 | } |
884 | return eventListSorted; | 893 | return eventListSorted; |
885 | } | 894 | } |
886 | 895 | ||
887 | 896 | ||
888 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 897 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
889 | bool inclusive ) | 898 | bool inclusive ) |
890 | { | 899 | { |
891 | Event *event = 0; | 900 | Event *event = 0; |
892 | 901 | ||
893 | QPtrList<Event> eventList; | 902 | QPtrList<Event> eventList; |
894 | 903 | ||
895 | // Get non-recurring events | 904 | // Get non-recurring events |
896 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 905 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
897 | if ( !event->calEnabled() ) continue; | 906 | if ( !event->calEnabled() ) continue; |
898 | if ( event->doesRecur() ) { | 907 | if ( event->doesRecur() ) { |
899 | QDate rStart = event->dtStart().date(); | 908 | QDate rStart = event->dtStart().date(); |
900 | bool found = false; | 909 | bool found = false; |
901 | if ( inclusive ) { | 910 | if ( inclusive ) { |
902 | if ( rStart >= start && rStart <= end ) { | 911 | if ( rStart >= start && rStart <= end ) { |
903 | // 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. |
904 | // 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. |
905 | if ( event->recurrence()->duration() == 0 ) { // End date set | 914 | if ( event->recurrence()->duration() == 0 ) { // End date set |
906 | QDate rEnd = event->recurrence()->endDate(); | 915 | QDate rEnd = event->recurrence()->endDate(); |
907 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 916 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
908 | found = true; | 917 | found = true; |
909 | } | 918 | } |
910 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 919 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
911 | // TODO: Calculate end date from duration. Should be done in Event | 920 | // TODO: Calculate end date from duration. Should be done in Event |
912 | // For now exclude all events with a duration. | 921 | // For now exclude all events with a duration. |
913 | } | 922 | } |
914 | } | 923 | } |
915 | } else { | 924 | } else { |
916 | bool founOne; | 925 | bool founOne; |
917 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 926 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
918 | if ( founOne ) { | 927 | if ( founOne ) { |
919 | if ( next <= end ) { | 928 | if ( next <= end ) { |
920 | found = true; | 929 | found = true; |
921 | } | 930 | } |
922 | } | 931 | } |
923 | 932 | ||
924 | /* | 933 | /* |
925 | // crap !!! | 934 | // crap !!! |
926 | if ( rStart <= end ) { // Start date not after range | 935 | if ( rStart <= end ) { // Start date not after range |
927 | if ( rStart >= start ) { // Start date within range | 936 | if ( rStart >= start ) { // Start date within range |
928 | found = true; | 937 | found = true; |
929 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 938 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
930 | found = true; | 939 | found = true; |
931 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 940 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
932 | QDate rEnd = event->recurrence()->endDate(); | 941 | QDate rEnd = event->recurrence()->endDate(); |
933 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 942 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
934 | found = true; | 943 | found = true; |
935 | } | 944 | } |
936 | } else { // Duration set | 945 | } else { // Duration set |
937 | // TODO: Calculate end date from duration. Should be done in Event | 946 | // TODO: Calculate end date from duration. Should be done in Event |
938 | // For now include all events with a duration. | 947 | // For now include all events with a duration. |
939 | found = true; | 948 | found = true; |
940 | } | 949 | } |
941 | } | 950 | } |
942 | */ | 951 | */ |
943 | 952 | ||
944 | } | 953 | } |
945 | 954 | ||
946 | if ( found ) eventList.append( event ); | 955 | if ( found ) eventList.append( event ); |
947 | } else { | 956 | } else { |
948 | QDate s = event->dtStart().date(); | 957 | QDate s = event->dtStart().date(); |
949 | QDate e = event->dtEnd().date(); | 958 | QDate e = event->dtEnd().date(); |
950 | 959 | ||
951 | if ( inclusive ) { | 960 | if ( inclusive ) { |
952 | if ( s >= start && e <= end ) { | 961 | if ( s >= start && e <= end ) { |
953 | eventList.append( event ); | 962 | eventList.append( event ); |
954 | } | 963 | } |
955 | } else { | 964 | } else { |
956 | if ( ( e >= start && s <= end ) ) { | 965 | if ( ( e >= start && s <= end ) ) { |
957 | eventList.append( event ); | 966 | eventList.append( event ); |
958 | } | 967 | } |
959 | } | 968 | } |
960 | } | 969 | } |
961 | } | 970 | } |
962 | 971 | ||
963 | return eventList; | 972 | return eventList; |
964 | } | 973 | } |
965 | 974 | ||
966 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 975 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
967 | { | 976 | { |
968 | return rawEventsForDate( qdt.date() ); | 977 | return rawEventsForDate( qdt.date() ); |
969 | } | 978 | } |
970 | 979 | ||
971 | QPtrList<Event> CalendarLocal::rawEvents() | 980 | QPtrList<Event> CalendarLocal::rawEvents() |
972 | { | 981 | { |
973 | QPtrList<Event> el; | 982 | QPtrList<Event> el; |
974 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 983 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
975 | if ( it->calEnabled() ) el.append( it ); | 984 | if ( it->calEnabled() ) el.append( it ); |
976 | return el; | 985 | return el; |
977 | } | 986 | } |
978 | 987 | ||
979 | bool CalendarLocal::addJournal(Journal *journal) | 988 | bool CalendarLocal::addJournal(Journal *journal) |
980 | { | 989 | { |
981 | mJournalList.append(journal); | 990 | mJournalList.append(journal); |
982 | 991 | ||
983 | journal->registerObserver( this ); | 992 | journal->registerObserver( this ); |
984 | 993 | ||
985 | setModified( true ); | 994 | setModified( true ); |
986 | if ( journal->calID() == 0 ) | 995 | if ( journal->calID() == 0 ) |
987 | journal->setCalID_block( mDefaultCalendar ); | 996 | journal->setCalID_block( mDefaultCalendar ); |
988 | journal->setCalEnabled( true ); | 997 | journal->setCalEnabled( true ); |
989 | return true; | 998 | return true; |
990 | } | 999 | } |
991 | 1000 | ||
992 | void CalendarLocal::deleteJournal( Journal *journal ) | 1001 | void CalendarLocal::deleteJournal( Journal *journal ) |
993 | { | 1002 | { |
994 | clearUndo(journal); | 1003 | clearUndo(journal); |
995 | if ( mJournalList.removeRef(journal) ) { | 1004 | if ( mJournalList.removeRef(journal) ) { |
996 | setModified( true ); | 1005 | setModified( true ); |
997 | } | 1006 | } |
998 | } | 1007 | } |
999 | 1008 | ||
1000 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 1009 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
1001 | { | 1010 | { |
1002 | QPtrList<Journal> el; | 1011 | QPtrList<Journal> el; |
1003 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1012 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1004 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 1013 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
1005 | return el; | 1014 | return el; |
1006 | } | 1015 | } |
1007 | Journal *CalendarLocal::journal( const QDate &date ) | 1016 | Journal *CalendarLocal::journal( const QDate &date ) |
1008 | { | 1017 | { |
1009 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 1018 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
1010 | 1019 | ||
1011 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1020 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1012 | if ( it->calEnabled() && it->dtStart().date() == date ) | 1021 | if ( it->calEnabled() && it->dtStart().date() == date ) |
1013 | return it; | 1022 | return it; |
1014 | 1023 | ||
1015 | return 0; | 1024 | return 0; |
1016 | } | 1025 | } |
1017 | 1026 | ||
1018 | Journal *CalendarLocal::journal( const QString &uid ) | 1027 | Journal *CalendarLocal::journal( const QString &uid ) |
1019 | { | 1028 | { |
1020 | Journal * retVal = 0; | 1029 | Journal * retVal = 0; |
1021 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1030 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1022 | if ( it->calEnabled() && it->uid() == uid ) { | 1031 | if ( it->calEnabled() && it->uid() == uid ) { |
1023 | if ( retVal ) { | 1032 | if ( retVal ) { |
1024 | if ( retVal->calID() > it->calID() ) { | 1033 | if ( retVal->calID() > it->calID() ) { |
1025 | retVal = it; | 1034 | retVal = it; |
1026 | } | 1035 | } |
1027 | } else { | 1036 | } else { |
1028 | retVal = it; | 1037 | retVal = it; |
1029 | } | 1038 | } |
1030 | } | 1039 | } |
1031 | return retVal; | 1040 | return retVal; |
1032 | } | 1041 | } |
1033 | 1042 | ||
1034 | QPtrList<Journal> CalendarLocal::journals() | 1043 | QPtrList<Journal> CalendarLocal::journals() |
1035 | { | 1044 | { |
1036 | QPtrList<Journal> el; | 1045 | QPtrList<Journal> el; |
1037 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1046 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1038 | if ( it->calEnabled() ) el.append( it ); | 1047 | if ( it->calEnabled() ) el.append( it ); |
1039 | return el; | 1048 | return el; |
1040 | } | 1049 | } |
1041 | void CalendarLocal::setCalendarRemove( int id ) | 1050 | void CalendarLocal::setCalendarRemove( int id ) |
1042 | { | 1051 | { |
1043 | 1052 | ||
1044 | { | 1053 | { |
1045 | QPtrList<Event> EventList = mEventList; | 1054 | QPtrList<Event> EventList = mEventList; |
1046 | Event * ev = EventList.first(); | 1055 | Event * ev = EventList.first(); |
1047 | while ( ev ) { | 1056 | while ( ev ) { |
1048 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) | 1057 | if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) |
1049 | deleteEvent( ev ); | 1058 | deleteEvent( ev ); |
1050 | ev = EventList.next(); | 1059 | ev = EventList.next(); |
1051 | } | 1060 | } |
1052 | } | 1061 | } |
1053 | { | 1062 | { |
1054 | 1063 | ||
1055 | QPtrList<Todo> TodoList = mTodoList; | 1064 | QPtrList<Todo> TodoList = mTodoList; |
1056 | Todo * ev = TodoList.first(); | 1065 | Todo * ev = TodoList.first(); |
1057 | while ( ev ) { | 1066 | while ( ev ) { |
1058 | if ( ev->calID() == id ) | 1067 | if ( ev->calID() == id ) |
1059 | deleteTodo( ev ); | 1068 | deleteTodo( ev ); |
1060 | ev = TodoList.next(); | 1069 | ev = TodoList.next(); |
1061 | } | 1070 | } |
1062 | } | 1071 | } |
1063 | { | 1072 | { |
1064 | QPtrList<Journal> JournalList = mJournalList; | 1073 | QPtrList<Journal> JournalList = mJournalList; |
1065 | Journal * ev = JournalList.first(); | 1074 | Journal * ev = JournalList.first(); |
1066 | while ( ev ) { | 1075 | while ( ev ) { |
1067 | if ( ev->calID() == id ) | 1076 | if ( ev->calID() == id ) |
1068 | deleteJournal( ev ); | 1077 | deleteJournal( ev ); |
1069 | ev = JournalList.next(); | 1078 | ev = JournalList.next(); |
1070 | } | 1079 | } |
1071 | } | 1080 | } |
1072 | 1081 | ||
1073 | clearUndo(0); | 1082 | clearUndo(0); |
1074 | 1083 | ||
1075 | } | 1084 | } |
1076 | 1085 | ||
1077 | void CalendarLocal::setAllCalendarEnabled( bool enable ) | 1086 | void CalendarLocal::setAllCalendarEnabled( bool enable ) |
1078 | { | 1087 | { |
1079 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1088 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1080 | it->setCalEnabled( enable ); | 1089 | it->setCalEnabled( enable ); |
1081 | 1090 | ||
1082 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1091 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1083 | it->setCalEnabled( enable ); | 1092 | it->setCalEnabled( enable ); |
1084 | 1093 | ||
1085 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1094 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1086 | it->setCalEnabled( enable ); | 1095 | it->setCalEnabled( enable ); |
1087 | 1096 | ||
1088 | 1097 | ||
1089 | } | 1098 | } |
1090 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 1099 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
1091 | { | 1100 | { |
1092 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1101 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1093 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1102 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1094 | 1103 | ||
1095 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1104 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1096 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1105 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1097 | 1106 | ||
1098 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1107 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1099 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1108 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1100 | 1109 | ||
1101 | } | 1110 | } |
1102 | 1111 | ||
1103 | void CalendarLocal::setReadOnly( int id, bool enable ) | 1112 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1104 | { | 1113 | { |
1105 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1106 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1115 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1107 | 1116 | ||
1108 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1117 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1109 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1118 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1110 | 1119 | ||
1111 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1120 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1112 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1121 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1113 | 1122 | ||
1114 | } | 1123 | } |
1115 | 1124 | ||
1116 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1125 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1117 | { | 1126 | { |
1118 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1127 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1119 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1128 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1120 | 1129 | ||
1121 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1130 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1122 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1131 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1123 | 1132 | ||
1124 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1133 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1125 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1134 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1126 | reInitAlarmSettings(); | 1135 | reInitAlarmSettings(); |
1127 | 1136 | ||
1128 | } | 1137 | } |
1129 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1138 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1130 | { | 1139 | { |
1131 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1140 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1132 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1141 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1133 | 1142 | ||
1134 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1143 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1135 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1144 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1136 | 1145 | ||
1137 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1146 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1138 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1147 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1139 | 1148 | ||
1140 | } | 1149 | } |