-rw-r--r-- | libkcal/calendarlocal.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index b02f706..ad8ace3 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,499 +1,508 @@ | |||
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 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) | 83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates, bool enabledOnly ) |
84 | { | 84 | { |
85 | Todo *todo;; | 85 | Todo *todo;; |
86 | Incidence *retVal = 0; | 86 | Incidence *retVal = 0; |
87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
88 | if ( todo->uid() == uid ) { | 88 | if ( todo->uid() == uid ) { |
89 | if ( enabledOnly ) | ||
90 | if ( !todo->calEnabled() ) | ||
91 | continue; | ||
89 | if ( doNotCheckDuplicates ) return todo; | 92 | if ( doNotCheckDuplicates ) return todo; |
90 | if ( retVal ) { | 93 | if ( retVal ) { |
91 | if ( retVal->calID() > todo->calID() ) { | 94 | if ( retVal->calID() > todo->calID() ) { |
92 | retVal = todo; | 95 | retVal = todo; |
93 | } | 96 | } |
94 | } else { | 97 | } else { |
95 | retVal = todo; | 98 | retVal = todo; |
96 | } | 99 | } |
97 | } | 100 | } |
98 | } | 101 | } |
99 | if ( retVal ) return retVal; | 102 | if ( retVal ) return retVal; |
100 | Event *event; | 103 | Event *event; |
101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 104 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
102 | if ( event->uid() == uid ) { | 105 | if ( event->uid() == uid ) { |
106 | if ( enabledOnly ) | ||
107 | if ( !event->calEnabled() ) | ||
108 | continue; | ||
103 | if ( doNotCheckDuplicates ) return event; | 109 | if ( doNotCheckDuplicates ) return event; |
104 | if ( retVal ) { | 110 | if ( retVal ) { |
105 | if ( retVal->calID() > event->calID() ) { | 111 | if ( retVal->calID() > event->calID() ) { |
106 | retVal = event; | 112 | retVal = event; |
107 | } | 113 | } |
108 | } else { | 114 | } else { |
109 | retVal = event; | 115 | retVal = event; |
110 | } | 116 | } |
111 | } | 117 | } |
112 | } | 118 | } |
113 | if ( retVal ) return retVal; | 119 | if ( retVal ) return retVal; |
114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 120 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
115 | if ( it->uid() == uid ) { | 121 | if ( it->uid() == uid ) { |
122 | if ( enabledOnly ) | ||
123 | if ( !it->calEnabled() ) | ||
124 | continue; | ||
116 | if ( doNotCheckDuplicates ) return it; | 125 | if ( doNotCheckDuplicates ) return it; |
117 | if ( retVal ) { | 126 | if ( retVal ) { |
118 | if ( retVal->calID() > it->calID() ) { | 127 | if ( retVal->calID() > it->calID() ) { |
119 | retVal = it; | 128 | retVal = it; |
120 | } | 129 | } |
121 | } else { | 130 | } else { |
122 | retVal = it; | 131 | retVal = it; |
123 | } | 132 | } |
124 | } | 133 | } |
125 | return retVal; | 134 | return retVal; |
126 | } | 135 | } |
127 | 136 | ||
128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 137 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
129 | { | 138 | { |
130 | // 1 look for raw inc in local | 139 | // 1 look for raw inc in local |
131 | // if inc not in remote, delete in local | 140 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 141 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 142 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 143 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 144 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 145 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 146 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 147 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 148 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 149 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 150 | inL = localInc.next(); |
142 | } | 151 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 152 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 153 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 154 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 155 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 156 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 157 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 158 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 159 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 160 | inL = inR->clone(); |
152 | inL->setCalID_block( calID ); | 161 | inL->setCalID_block( calID ); |
153 | addIncidence( inL ); | 162 | addIncidence( inL ); |
154 | } | 163 | } |
155 | } else { | 164 | } else { |
156 | inL = inR->clone(); | 165 | inL = inR->clone(); |
157 | inL->setCalID_block( 0 );// add to default cal | 166 | inL->setCalID_block( 0 );// add to default cal |
158 | addIncidence( inL ); | 167 | addIncidence( inL ); |
159 | } | 168 | } |
160 | inR = er.next(); | 169 | inR = er.next(); |
161 | } | 170 | } |
162 | return true; | 171 | return true; |
163 | } | 172 | } |
164 | 173 | ||
165 | 174 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 175 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 176 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 177 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 178 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 179 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 180 | addCalendar( &calendar ); |
172 | return true; | 181 | return true; |
173 | } | 182 | } |
174 | return false; | 183 | return false; |
175 | } | 184 | } |
176 | void CalendarLocal::setSyncEventsEnabled() | 185 | void CalendarLocal::setSyncEventsEnabled() |
177 | { | 186 | { |
178 | Event * ev; | 187 | Event * ev; |
179 | ev = mEventList.first(); | 188 | ev = mEventList.first(); |
180 | while ( ev ) { | 189 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 190 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setCalEnabled( true ); | 191 | ev->setCalEnabled( true ); |
183 | ev = mEventList.next(); | 192 | ev = mEventList.next(); |
184 | } | 193 | } |
185 | } | 194 | } |
186 | void CalendarLocal::setSyncEventsReadOnly() | 195 | void CalendarLocal::setSyncEventsReadOnly() |
187 | { | 196 | { |
188 | Event * ev; | 197 | Event * ev; |
189 | ev = mEventList.first(); | 198 | ev = mEventList.first(); |
190 | while ( ev ) { | 199 | while ( ev ) { |
191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 200 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
192 | ev->setReadOnly( true ); | 201 | ev->setReadOnly( true ); |
193 | } | 202 | } |
194 | ev = mEventList.next(); | 203 | ev = mEventList.next(); |
195 | } | 204 | } |
196 | } | 205 | } |
197 | 206 | ||
198 | void CalendarLocal::addCalendar( Calendar* cal ) | 207 | void CalendarLocal::addCalendar( Calendar* cal ) |
199 | { | 208 | { |
200 | cal->setDontDeleteIncidencesOnClose(); | 209 | cal->setDontDeleteIncidencesOnClose(); |
201 | setSyncEventsEnabled(); | 210 | setSyncEventsEnabled(); |
202 | { | 211 | { |
203 | QPtrList<Event> EventList = cal->rawEvents(); | 212 | QPtrList<Event> EventList = cal->rawEvents(); |
204 | QPtrList<Event> el; | 213 | QPtrList<Event> el; |
205 | Event * ev = EventList.first(); | 214 | Event * ev = EventList.first(); |
206 | while ( ev ) { | 215 | while ( ev ) { |
207 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | 216 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { |
208 | Event * se = event( ev->uid() ); | 217 | Event * se = event( ev->uid() ); |
209 | if ( se ) | 218 | if ( se ) |
210 | el.append( se ); | 219 | el.append( se ); |
211 | ev->setCalID_block( 1 ); | 220 | ev->setCalID_block( 1 ); |
212 | } | 221 | } |
213 | ev->unRegisterObserver( cal ); | 222 | ev->unRegisterObserver( cal ); |
214 | ev->registerObserver( this ); | 223 | ev->registerObserver( this ); |
215 | mEventList.append( ev ); | 224 | mEventList.append( ev ); |
216 | ev = EventList.next(); | 225 | ev = EventList.next(); |
217 | } | 226 | } |
218 | for ( ev = el.first(); ev; ev = el.next() ) { | 227 | for ( ev = el.first(); ev; ev = el.next() ) { |
219 | deleteIncidence ( ev ); | 228 | deleteIncidence ( ev ); |
220 | } | 229 | } |
221 | } | 230 | } |
222 | { | 231 | { |
223 | 232 | ||
224 | QPtrList<Todo> TodoList = cal->rawTodos(); | 233 | QPtrList<Todo> TodoList = cal->rawTodos(); |
225 | Todo * ev = TodoList.first(); | 234 | Todo * ev = TodoList.first(); |
226 | while ( ev ) { | 235 | while ( ev ) { |
227 | QString rel = ev->relatedToUid(); | 236 | QString rel = ev->relatedToUid(); |
228 | if ( !rel.isEmpty() ){ | 237 | if ( !rel.isEmpty() ){ |
229 | ev->setRelatedTo ( 0 ); | 238 | ev->setRelatedTo ( 0 ); |
230 | ev->setRelatedToUid( rel ); | 239 | ev->setRelatedToUid( rel ); |
231 | } | 240 | } |
232 | ev = TodoList.next(); | 241 | ev = TodoList.next(); |
233 | } | 242 | } |
234 | //TodoList = cal->rawTodos(); | 243 | //TodoList = cal->rawTodos(); |
235 | ev = TodoList.first(); | 244 | ev = TodoList.first(); |
236 | while ( ev ) { | 245 | while ( ev ) { |
237 | ev->unRegisterObserver( cal ); | 246 | ev->unRegisterObserver( cal ); |
238 | ev->registerObserver( this ); | 247 | ev->registerObserver( this ); |
239 | mTodoList.append( ev ); | 248 | mTodoList.append( ev ); |
240 | setupRelations( ev ); | 249 | setupRelations( ev ); |
241 | ev = TodoList.next(); | 250 | ev = TodoList.next(); |
242 | } | 251 | } |
243 | } | 252 | } |
244 | { | 253 | { |
245 | QPtrList<Journal> JournalList = cal->journals(); | 254 | QPtrList<Journal> JournalList = cal->journals(); |
246 | Journal * ev = JournalList.first(); | 255 | Journal * ev = JournalList.first(); |
247 | while ( ev ) { | 256 | while ( ev ) { |
248 | ev->unRegisterObserver( cal ); | 257 | ev->unRegisterObserver( cal ); |
249 | ev->registerObserver( this ); | 258 | ev->registerObserver( this ); |
250 | mJournalList.append( ev ); | 259 | mJournalList.append( ev ); |
251 | ev = JournalList.next(); | 260 | ev = JournalList.next(); |
252 | } | 261 | } |
253 | } | 262 | } |
254 | setModified( true ); | 263 | setModified( true ); |
255 | } | 264 | } |
256 | bool CalendarLocal::load( const QString &fileName ) | 265 | bool CalendarLocal::load( const QString &fileName ) |
257 | { | 266 | { |
258 | FileStorage storage( this, fileName ); | 267 | FileStorage storage( this, fileName ); |
259 | return storage.load(); | 268 | return storage.load(); |
260 | } | 269 | } |
261 | 270 | ||
262 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 271 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
263 | { | 272 | { |
264 | FileStorage storage( this, fileName, format ); | 273 | FileStorage storage( this, fileName, format ); |
265 | return storage.save(); | 274 | return storage.save(); |
266 | } | 275 | } |
267 | 276 | ||
268 | void CalendarLocal::stopAllTodos() | 277 | void CalendarLocal::stopAllTodos() |
269 | { | 278 | { |
270 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 279 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
271 | it->setRunning( false ); | 280 | it->setRunning( false ); |
272 | 281 | ||
273 | } | 282 | } |
274 | void CalendarLocal::close() | 283 | void CalendarLocal::close() |
275 | { | 284 | { |
276 | 285 | ||
277 | Todo * i; | 286 | Todo * i; |
278 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 287 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
279 | 288 | ||
280 | mEventList.setAutoDelete( true ); | 289 | mEventList.setAutoDelete( true ); |
281 | mTodoList.setAutoDelete( true ); | 290 | mTodoList.setAutoDelete( true ); |
282 | mJournalList.setAutoDelete( true ); | 291 | mJournalList.setAutoDelete( true ); |
283 | 292 | ||
284 | mEventList.clear(); | 293 | mEventList.clear(); |
285 | mTodoList.clear(); | 294 | mTodoList.clear(); |
286 | mJournalList.clear(); | 295 | mJournalList.clear(); |
287 | 296 | ||
288 | mEventList.setAutoDelete( false ); | 297 | mEventList.setAutoDelete( false ); |
289 | mTodoList.setAutoDelete( false ); | 298 | mTodoList.setAutoDelete( false ); |
290 | mJournalList.setAutoDelete( false ); | 299 | mJournalList.setAutoDelete( false ); |
291 | 300 | ||
292 | setModified( false ); | 301 | setModified( false ); |
293 | } | 302 | } |
294 | 303 | ||
295 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 304 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
296 | { | 305 | { |
297 | QString cat; | 306 | QString cat; |
298 | bool isBirthday = true; | 307 | bool isBirthday = true; |
299 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 308 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
300 | isBirthday = false; | 309 | isBirthday = false; |
301 | cat = i18n( "Anniversary" ); | 310 | cat = i18n( "Anniversary" ); |
302 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 311 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
303 | isBirthday = true; | 312 | isBirthday = true; |
304 | cat = i18n( "Birthday" ); | 313 | cat = i18n( "Birthday" ); |
305 | } else { | 314 | } else { |
306 | qDebug("addAnniversaryNoDup called without fitting category! "); | 315 | qDebug("addAnniversaryNoDup called without fitting category! "); |
307 | return false; | 316 | return false; |
308 | } | 317 | } |
309 | Event * eve; | 318 | Event * eve; |
310 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 319 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
311 | if ( !(eve->categories().contains( cat ) )) | 320 | if ( !(eve->categories().contains( cat ) )) |
312 | continue; | 321 | continue; |
313 | // now we have an event with fitting category | 322 | // now we have an event with fitting category |
314 | if ( eve->dtStart().date() != event->dtStart().date() ) | 323 | if ( eve->dtStart().date() != event->dtStart().date() ) |
315 | continue; | 324 | continue; |
316 | // now we have an event with fitting category+date | 325 | // now we have an event with fitting category+date |
317 | if ( eve->summary() != event->summary() ) | 326 | if ( eve->summary() != event->summary() ) |
318 | continue; | 327 | continue; |
319 | // now we have an event with fitting category+date+summary | 328 | // now we have an event with fitting category+date+summary |
320 | return false; | 329 | return false; |
321 | } | 330 | } |
322 | return addEvent( event ); | 331 | return addEvent( event ); |
323 | 332 | ||
324 | } | 333 | } |
325 | bool CalendarLocal::addEventNoDup( Event *event ) | 334 | bool CalendarLocal::addEventNoDup( Event *event ) |
326 | { | 335 | { |
327 | Event * eve; | 336 | Event * eve; |
328 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 337 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
329 | if ( *eve == *event ) { | 338 | if ( *eve == *event ) { |
330 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 339 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
331 | return false; | 340 | return false; |
332 | } | 341 | } |
333 | } | 342 | } |
334 | return addEvent( event ); | 343 | return addEvent( event ); |
335 | } | 344 | } |
336 | 345 | ||
337 | bool CalendarLocal::addEvent( Event *event ) | 346 | bool CalendarLocal::addEvent( Event *event ) |
338 | { | 347 | { |
339 | insertEvent( event ); | 348 | insertEvent( event ); |
340 | 349 | ||
341 | event->registerObserver( this ); | 350 | event->registerObserver( this ); |
342 | 351 | ||
343 | setModified( true ); | 352 | setModified( true ); |
344 | if ( event->calID() == 0 ) | 353 | if ( event->calID() == 0 ) |
345 | event->setCalID_block( mDefaultCalendar ); | 354 | event->setCalID_block( mDefaultCalendar ); |
346 | event->setCalEnabled( true ); | 355 | event->setCalEnabled( true ); |
347 | 356 | ||
348 | return true; | 357 | return true; |
349 | } | 358 | } |
350 | 359 | ||
351 | void CalendarLocal::deleteEvent( Event *event ) | 360 | void CalendarLocal::deleteEvent( Event *event ) |
352 | { | 361 | { |
353 | clearUndo(event); | 362 | clearUndo(event); |
354 | if ( mEventList.removeRef( event ) ) { | 363 | if ( mEventList.removeRef( event ) ) { |
355 | setModified( true ); | 364 | setModified( true ); |
356 | } | 365 | } |
357 | } | 366 | } |
358 | 367 | ||
359 | 368 | ||
360 | Event *CalendarLocal::event( const QString &uid ) | 369 | Event *CalendarLocal::event( const QString &uid ) |
361 | { | 370 | { |
362 | Event *event; | 371 | Event *event; |
363 | Event *retVal = 0; | 372 | Event *retVal = 0; |
364 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 373 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
365 | if ( event->calEnabled() && event->uid() == uid ) { | 374 | if ( event->calEnabled() && event->uid() == uid ) { |
366 | if ( retVal ) { | 375 | if ( retVal ) { |
367 | if ( retVal->calID() > event->calID() ) { | 376 | if ( retVal->calID() > event->calID() ) { |
368 | retVal = event; | 377 | retVal = event; |
369 | } | 378 | } |
370 | } else { | 379 | } else { |
371 | retVal = event; | 380 | retVal = event; |
372 | } | 381 | } |
373 | } | 382 | } |
374 | } | 383 | } |
375 | return retVal; | 384 | return retVal; |
376 | } | 385 | } |
377 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 386 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
378 | { | 387 | { |
379 | Todo * eve; | 388 | Todo * eve; |
380 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 389 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
381 | if ( *eve == *todo ) { | 390 | if ( *eve == *todo ) { |
382 | //qDebug("duplicate todo found! not inserted! "); | 391 | //qDebug("duplicate todo found! not inserted! "); |
383 | return false; | 392 | return false; |
384 | } | 393 | } |
385 | } | 394 | } |
386 | return addTodo( todo ); | 395 | return addTodo( todo ); |
387 | } | 396 | } |
388 | bool CalendarLocal::addTodo( Todo *todo ) | 397 | bool CalendarLocal::addTodo( Todo *todo ) |
389 | { | 398 | { |
390 | mTodoList.append( todo ); | 399 | mTodoList.append( todo ); |
391 | 400 | ||
392 | todo->registerObserver( this ); | 401 | todo->registerObserver( this ); |
393 | 402 | ||
394 | // Set up subtask relations | 403 | // Set up subtask relations |
395 | setupRelations( todo ); | 404 | setupRelations( todo ); |
396 | 405 | ||
397 | setModified( true ); | 406 | setModified( true ); |
398 | if ( todo->calID() == 0 ) | 407 | if ( todo->calID() == 0 ) |
399 | todo->setCalID_block( mDefaultCalendar ); | 408 | todo->setCalID_block( mDefaultCalendar ); |
400 | todo->setCalEnabled( true ); | 409 | todo->setCalEnabled( true ); |
401 | return true; | 410 | return true; |
402 | } | 411 | } |
403 | 412 | ||
404 | void CalendarLocal::deleteTodo( Todo *todo ) | 413 | void CalendarLocal::deleteTodo( Todo *todo ) |
405 | { | 414 | { |
406 | // Handle orphaned children | 415 | // Handle orphaned children |
407 | removeRelations( todo ); | 416 | removeRelations( todo ); |
408 | clearUndo(todo); | 417 | clearUndo(todo); |
409 | 418 | ||
410 | if ( mTodoList.removeRef( todo ) ) { | 419 | if ( mTodoList.removeRef( todo ) ) { |
411 | setModified( true ); | 420 | setModified( true ); |
412 | } | 421 | } |
413 | } | 422 | } |
414 | 423 | ||
415 | QPtrList<Todo> CalendarLocal::rawTodos() | 424 | QPtrList<Todo> CalendarLocal::rawTodos() |
416 | { | 425 | { |
417 | QPtrList<Todo> el; | 426 | QPtrList<Todo> el; |
418 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 427 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
419 | if ( it->calEnabled() ) el.append( it ); | 428 | if ( it->calEnabled() ) el.append( it ); |
420 | return el; | 429 | return el; |
421 | } | 430 | } |
422 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 431 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
423 | { | 432 | { |
424 | Todo *todo; | 433 | Todo *todo; |
425 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 434 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
426 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 435 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
427 | } | 436 | } |
428 | 437 | ||
429 | return 0; | 438 | return 0; |
430 | } | 439 | } |
431 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 440 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
432 | { | 441 | { |
433 | QPtrList<Incidence> all = rawIncidences() ; | 442 | QPtrList<Incidence> all = rawIncidences() ; |
434 | Incidence *inc; | 443 | Incidence *inc; |
435 | for ( inc = all.first(); inc; inc = all.next() ) { | 444 | for ( inc = all.first(); inc; inc = all.next() ) { |
436 | inc->removeID( syncProfile ); | 445 | inc->removeID( syncProfile ); |
437 | } | 446 | } |
438 | if ( syncProfile.isEmpty() ) { | 447 | if ( syncProfile.isEmpty() ) { |
439 | QPtrList<Event> el; | 448 | QPtrList<Event> el; |
440 | Event *todo; | 449 | Event *todo; |
441 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 450 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
442 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 451 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
443 | el.append( todo ); | 452 | el.append( todo ); |
444 | } | 453 | } |
445 | for ( todo = el.first(); todo; todo = el.next() ) { | 454 | for ( todo = el.first(); todo; todo = el.next() ) { |
446 | deleteIncidence ( todo ); | 455 | deleteIncidence ( todo ); |
447 | } | 456 | } |
448 | } else { | 457 | } else { |
449 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 458 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
450 | if ( lse ) | 459 | if ( lse ) |
451 | deleteIncidence ( lse ); | 460 | deleteIncidence ( lse ); |
452 | } | 461 | } |
453 | } | 462 | } |
454 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 463 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
455 | { | 464 | { |
456 | QPtrList<Event> el; | 465 | QPtrList<Event> el; |
457 | Event *todo; | 466 | Event *todo; |
458 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 467 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
459 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 468 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
460 | if ( todo->summary().left(3) == "E: " ) | 469 | if ( todo->summary().left(3) == "E: " ) |
461 | el.append( todo ); | 470 | el.append( todo ); |
462 | } | 471 | } |
463 | 472 | ||
464 | return el; | 473 | return el; |
465 | 474 | ||
466 | } | 475 | } |
467 | Event *CalendarLocal::event( QString syncProf, QString id ) | 476 | Event *CalendarLocal::event( QString syncProf, QString id ) |
468 | { | 477 | { |
469 | Event *todo; | 478 | Event *todo; |
470 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 479 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
471 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 480 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
472 | } | 481 | } |
473 | 482 | ||
474 | return 0; | 483 | return 0; |
475 | } | 484 | } |
476 | Todo *CalendarLocal::todo( const QString &uid ) | 485 | Todo *CalendarLocal::todo( const QString &uid ) |
477 | { | 486 | { |
478 | Todo *todo; | 487 | Todo *todo; |
479 | Todo *retVal = 0; | 488 | Todo *retVal = 0; |
480 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 489 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
481 | if ( todo->calEnabled() && todo->uid() == uid ) { | 490 | if ( todo->calEnabled() && todo->uid() == uid ) { |
482 | if ( retVal ) { | 491 | if ( retVal ) { |
483 | if ( retVal->calID() > todo->calID() ) { | 492 | if ( retVal->calID() > todo->calID() ) { |
484 | retVal = todo; | 493 | retVal = todo; |
485 | } | 494 | } |
486 | } else { | 495 | } else { |
487 | retVal = todo; | 496 | retVal = todo; |
488 | } | 497 | } |
489 | } | 498 | } |
490 | } | 499 | } |
491 | return retVal; | 500 | return retVal; |
492 | } | 501 | } |
493 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) | 502 | void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals) |
494 | { | 503 | { |
495 | events = 0; | 504 | events = 0; |
496 | todos = 0; | 505 | todos = 0; |
497 | journals = 0; | 506 | journals = 0; |
498 | { | 507 | { |
499 | Todo *todo; | 508 | Todo *todo; |