-rw-r--r-- | libkcal/calendarlocal.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 45e3128..2a57724 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -65,273 +65,283 @@ void CalendarLocal::init() | |||
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) |
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 ( doNotCheckDuplicates ) return todo; | 89 | if ( doNotCheckDuplicates ) return todo; |
90 | if ( retVal ) { | 90 | if ( retVal ) { |
91 | if ( retVal->calID() > todo->calID() ) { | 91 | if ( retVal->calID() > todo->calID() ) { |
92 | retVal = todo; | 92 | retVal = todo; |
93 | } | 93 | } |
94 | } else { | 94 | } else { |
95 | retVal = todo; | 95 | retVal = todo; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | if ( retVal ) return retVal; | 99 | if ( retVal ) return retVal; |
100 | Event *event; | 100 | Event *event; |
101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
102 | if ( event->uid() == uid ) { | 102 | if ( event->uid() == uid ) { |
103 | if ( doNotCheckDuplicates ) return event; | 103 | if ( doNotCheckDuplicates ) return event; |
104 | if ( retVal ) { | 104 | if ( retVal ) { |
105 | if ( retVal->calID() > event->calID() ) { | 105 | if ( retVal->calID() > event->calID() ) { |
106 | retVal = event; | 106 | retVal = event; |
107 | } | 107 | } |
108 | } else { | 108 | } else { |
109 | retVal = event; | 109 | retVal = event; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | } | 112 | } |
113 | if ( retVal ) return retVal; | 113 | if ( retVal ) return retVal; |
114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
115 | if ( it->uid() == uid ) { | 115 | if ( it->uid() == uid ) { |
116 | if ( doNotCheckDuplicates ) return it; | 116 | if ( doNotCheckDuplicates ) return it; |
117 | if ( retVal ) { | 117 | if ( retVal ) { |
118 | if ( retVal->calID() > it->calID() ) { | 118 | if ( retVal->calID() > it->calID() ) { |
119 | retVal = it; | 119 | retVal = it; |
120 | } | 120 | } |
121 | } else { | 121 | } else { |
122 | retVal = it; | 122 | retVal = it; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | return retVal; | 125 | return retVal; |
126 | } | 126 | } |
127 | 127 | ||
128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
129 | { | 129 | { |
130 | // 1 look for raw inc in local | 130 | // 1 look for raw inc in local |
131 | // if inc not in remote, delete in local | 131 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 132 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 133 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 134 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 135 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 136 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 137 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 138 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 139 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 140 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 141 | inL = localInc.next(); |
142 | } | 142 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 143 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 144 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 145 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 146 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 147 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 149 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 150 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 151 | inL = inR->clone(); |
152 | inL->setCalID( calID ); | 152 | inL->setCalID( calID ); |
153 | addIncidence( inL ); | 153 | addIncidence( inL ); |
154 | } | 154 | } |
155 | } else { | 155 | } else { |
156 | inL = inR->clone(); | 156 | inL = inR->clone(); |
157 | inL->setCalID( 0 );// add to default cal | 157 | inL->setCalID( 0 );// add to default cal |
158 | addIncidence( inL ); | 158 | addIncidence( inL ); |
159 | } | 159 | } |
160 | inR = er.next(); | 160 | inR = er.next(); |
161 | } | 161 | } |
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 166 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 167 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 168 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 169 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 170 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 171 | addCalendar( &calendar ); |
172 | return true; | 172 | return true; |
173 | } | 173 | } |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | void CalendarLocal::setSyncEventsEnabled() | 176 | void CalendarLocal::setSyncEventsEnabled() |
177 | { | 177 | { |
178 | Event * ev; | 178 | Event * ev; |
179 | ev = mEventList.first(); | 179 | ev = mEventList.first(); |
180 | while ( ev ) { | 180 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setCalEnabled( true ); | 182 | ev->setCalEnabled( true ); |
183 | ev = mEventList.next(); | 183 | ev = mEventList.next(); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | void CalendarLocal::setSyncEventsReadOnly() | 186 | void CalendarLocal::setSyncEventsReadOnly() |
187 | { | 187 | { |
188 | Event * ev; | 188 | Event * ev; |
189 | ev = mEventList.first(); | 189 | ev = mEventList.first(); |
190 | while ( ev ) { | 190 | while ( ev ) { |
191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | 191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { |
192 | ev->setReadOnly( true ); | 192 | ev->setReadOnly( true ); |
193 | ev->setCalID( 1 ); | ||
194 | } | 193 | } |
195 | ev = mEventList.next(); | 194 | ev = mEventList.next(); |
196 | } | 195 | } |
197 | } | 196 | } |
197 | |||
198 | void CalendarLocal::addCalendar( Calendar* cal ) | 198 | void CalendarLocal::addCalendar( Calendar* cal ) |
199 | { | 199 | { |
200 | cal->setDontDeleteIncidencesOnClose(); | 200 | cal->setDontDeleteIncidencesOnClose(); |
201 | setSyncEventsEnabled(); | ||
201 | { | 202 | { |
202 | QPtrList<Event> EventList = cal->rawEvents(); | 203 | QPtrList<Event> EventList = cal->rawEvents(); |
204 | QPtrList<Event> el; | ||
203 | Event * ev = EventList.first(); | 205 | Event * ev = EventList.first(); |
204 | while ( ev ) { | 206 | while ( ev ) { |
207 | if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { | ||
208 | Event * se = event( ev->uid() ); | ||
209 | if ( se ) | ||
210 | el.append( se ); | ||
211 | } | ||
205 | ev->unRegisterObserver( cal ); | 212 | ev->unRegisterObserver( cal ); |
206 | ev->registerObserver( this ); | 213 | ev->registerObserver( this ); |
207 | mEventList.append( ev ); | 214 | mEventList.append( ev ); |
208 | ev = EventList.next(); | 215 | ev = EventList.next(); |
209 | } | 216 | } |
217 | for ( ev = el.first(); ev; ev = el.next() ) { | ||
218 | deleteIncidence ( ev ); | ||
219 | } | ||
210 | } | 220 | } |
211 | { | 221 | { |
212 | 222 | ||
213 | QPtrList<Todo> TodoList = cal->rawTodos(); | 223 | QPtrList<Todo> TodoList = cal->rawTodos(); |
214 | Todo * ev = TodoList.first(); | 224 | Todo * ev = TodoList.first(); |
215 | while ( ev ) { | 225 | while ( ev ) { |
216 | QString rel = ev->relatedToUid(); | 226 | QString rel = ev->relatedToUid(); |
217 | if ( !rel.isEmpty() ){ | 227 | if ( !rel.isEmpty() ){ |
218 | ev->setRelatedTo ( 0 ); | 228 | ev->setRelatedTo ( 0 ); |
219 | ev->setRelatedToUid( rel ); | 229 | ev->setRelatedToUid( rel ); |
220 | } | 230 | } |
221 | ev = TodoList.next(); | 231 | ev = TodoList.next(); |
222 | } | 232 | } |
223 | //TodoList = cal->rawTodos(); | 233 | //TodoList = cal->rawTodos(); |
224 | ev = TodoList.first(); | 234 | ev = TodoList.first(); |
225 | while ( ev ) { | 235 | while ( ev ) { |
226 | ev->unRegisterObserver( cal ); | 236 | ev->unRegisterObserver( cal ); |
227 | ev->registerObserver( this ); | 237 | ev->registerObserver( this ); |
228 | mTodoList.append( ev ); | 238 | mTodoList.append( ev ); |
229 | setupRelations( ev ); | 239 | setupRelations( ev ); |
230 | ev = TodoList.next(); | 240 | ev = TodoList.next(); |
231 | } | 241 | } |
232 | } | 242 | } |
233 | { | 243 | { |
234 | QPtrList<Journal> JournalList = cal->journals(); | 244 | QPtrList<Journal> JournalList = cal->journals(); |
235 | Journal * ev = JournalList.first(); | 245 | Journal * ev = JournalList.first(); |
236 | while ( ev ) { | 246 | while ( ev ) { |
237 | ev->unRegisterObserver( cal ); | 247 | ev->unRegisterObserver( cal ); |
238 | ev->registerObserver( this ); | 248 | ev->registerObserver( this ); |
239 | mJournalList.append( ev ); | 249 | mJournalList.append( ev ); |
240 | ev = JournalList.next(); | 250 | ev = JournalList.next(); |
241 | } | 251 | } |
242 | } | 252 | } |
243 | setModified( true ); | 253 | setModified( true ); |
244 | } | 254 | } |
245 | bool CalendarLocal::load( const QString &fileName ) | 255 | bool CalendarLocal::load( const QString &fileName ) |
246 | { | 256 | { |
247 | FileStorage storage( this, fileName ); | 257 | FileStorage storage( this, fileName ); |
248 | return storage.load(); | 258 | return storage.load(); |
249 | } | 259 | } |
250 | 260 | ||
251 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 261 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
252 | { | 262 | { |
253 | FileStorage storage( this, fileName, format ); | 263 | FileStorage storage( this, fileName, format ); |
254 | return storage.save(); | 264 | return storage.save(); |
255 | } | 265 | } |
256 | 266 | ||
257 | void CalendarLocal::stopAllTodos() | 267 | void CalendarLocal::stopAllTodos() |
258 | { | 268 | { |
259 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 269 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
260 | it->setRunning( false ); | 270 | it->setRunning( false ); |
261 | 271 | ||
262 | } | 272 | } |
263 | void CalendarLocal::close() | 273 | void CalendarLocal::close() |
264 | { | 274 | { |
265 | 275 | ||
266 | Todo * i; | 276 | Todo * i; |
267 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 277 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
268 | 278 | ||
269 | mEventList.setAutoDelete( true ); | 279 | mEventList.setAutoDelete( true ); |
270 | mTodoList.setAutoDelete( true ); | 280 | mTodoList.setAutoDelete( true ); |
271 | mJournalList.setAutoDelete( true ); | 281 | mJournalList.setAutoDelete( true ); |
272 | 282 | ||
273 | mEventList.clear(); | 283 | mEventList.clear(); |
274 | mTodoList.clear(); | 284 | mTodoList.clear(); |
275 | mJournalList.clear(); | 285 | mJournalList.clear(); |
276 | 286 | ||
277 | mEventList.setAutoDelete( false ); | 287 | mEventList.setAutoDelete( false ); |
278 | mTodoList.setAutoDelete( false ); | 288 | mTodoList.setAutoDelete( false ); |
279 | mJournalList.setAutoDelete( false ); | 289 | mJournalList.setAutoDelete( false ); |
280 | 290 | ||
281 | setModified( false ); | 291 | setModified( false ); |
282 | } | 292 | } |
283 | 293 | ||
284 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 294 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
285 | { | 295 | { |
286 | QString cat; | 296 | QString cat; |
287 | bool isBirthday = true; | 297 | bool isBirthday = true; |
288 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 298 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
289 | isBirthday = false; | 299 | isBirthday = false; |
290 | cat = i18n( "Anniversary" ); | 300 | cat = i18n( "Anniversary" ); |
291 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 301 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
292 | isBirthday = true; | 302 | isBirthday = true; |
293 | cat = i18n( "Birthday" ); | 303 | cat = i18n( "Birthday" ); |
294 | } else { | 304 | } else { |
295 | qDebug("addAnniversaryNoDup called without fitting category! "); | 305 | qDebug("addAnniversaryNoDup called without fitting category! "); |
296 | return false; | 306 | return false; |
297 | } | 307 | } |
298 | Event * eve; | 308 | Event * eve; |
299 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 309 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
300 | if ( !(eve->categories().contains( cat ) )) | 310 | if ( !(eve->categories().contains( cat ) )) |
301 | continue; | 311 | continue; |
302 | // now we have an event with fitting category | 312 | // now we have an event with fitting category |
303 | if ( eve->dtStart().date() != event->dtStart().date() ) | 313 | if ( eve->dtStart().date() != event->dtStart().date() ) |
304 | continue; | 314 | continue; |
305 | // now we have an event with fitting category+date | 315 | // now we have an event with fitting category+date |
306 | if ( eve->summary() != event->summary() ) | 316 | if ( eve->summary() != event->summary() ) |
307 | continue; | 317 | continue; |
308 | // now we have an event with fitting category+date+summary | 318 | // now we have an event with fitting category+date+summary |
309 | return false; | 319 | return false; |
310 | } | 320 | } |
311 | return addEvent( event ); | 321 | return addEvent( event ); |
312 | 322 | ||
313 | } | 323 | } |
314 | bool CalendarLocal::addEventNoDup( Event *event ) | 324 | bool CalendarLocal::addEventNoDup( Event *event ) |
315 | { | 325 | { |
316 | Event * eve; | 326 | Event * eve; |
317 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 327 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
318 | if ( *eve == *event ) { | 328 | if ( *eve == *event ) { |
319 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 329 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
320 | return false; | 330 | return false; |
321 | } | 331 | } |
322 | } | 332 | } |
323 | return addEvent( event ); | 333 | return addEvent( event ); |
324 | } | 334 | } |
325 | 335 | ||
326 | bool CalendarLocal::addEvent( Event *event ) | 336 | bool CalendarLocal::addEvent( Event *event ) |
327 | { | 337 | { |
328 | insertEvent( event ); | 338 | insertEvent( event ); |
329 | 339 | ||
330 | event->registerObserver( this ); | 340 | event->registerObserver( this ); |
331 | 341 | ||
332 | setModified( true ); | 342 | setModified( true ); |
333 | if ( event->calID() == 0 ) | 343 | if ( event->calID() == 0 ) |
334 | event->setCalID( mDefaultCalendar ); | 344 | event->setCalID( mDefaultCalendar ); |
335 | event->setCalEnabled( true ); | 345 | event->setCalEnabled( true ); |
336 | 346 | ||
337 | return true; | 347 | return true; |
@@ -878,179 +888,192 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | |||
878 | QDate e = event->dtEnd().date(); | 888 | QDate e = event->dtEnd().date(); |
879 | 889 | ||
880 | if ( inclusive ) { | 890 | if ( inclusive ) { |
881 | if ( s >= start && e <= end ) { | 891 | if ( s >= start && e <= end ) { |
882 | eventList.append( event ); | 892 | eventList.append( event ); |
883 | } | 893 | } |
884 | } else { | 894 | } else { |
885 | if ( ( e >= start && s <= end ) ) { | 895 | if ( ( e >= start && s <= end ) ) { |
886 | eventList.append( event ); | 896 | eventList.append( event ); |
887 | } | 897 | } |
888 | } | 898 | } |
889 | } | 899 | } |
890 | } | 900 | } |
891 | 901 | ||
892 | return eventList; | 902 | return eventList; |
893 | } | 903 | } |
894 | 904 | ||
895 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 905 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
896 | { | 906 | { |
897 | return rawEventsForDate( qdt.date() ); | 907 | return rawEventsForDate( qdt.date() ); |
898 | } | 908 | } |
899 | 909 | ||
900 | QPtrList<Event> CalendarLocal::rawEvents() | 910 | QPtrList<Event> CalendarLocal::rawEvents() |
901 | { | 911 | { |
902 | QPtrList<Event> el; | 912 | QPtrList<Event> el; |
903 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 913 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
904 | if ( it->calEnabled() ) el.append( it ); | 914 | if ( it->calEnabled() ) el.append( it ); |
905 | return el; | 915 | return el; |
906 | } | 916 | } |
907 | 917 | ||
908 | bool CalendarLocal::addJournal(Journal *journal) | 918 | bool CalendarLocal::addJournal(Journal *journal) |
909 | { | 919 | { |
910 | mJournalList.append(journal); | 920 | mJournalList.append(journal); |
911 | 921 | ||
912 | journal->registerObserver( this ); | 922 | journal->registerObserver( this ); |
913 | 923 | ||
914 | setModified( true ); | 924 | setModified( true ); |
915 | if ( journal->calID() == 0 ) | 925 | if ( journal->calID() == 0 ) |
916 | journal->setCalID( mDefaultCalendar ); | 926 | journal->setCalID( mDefaultCalendar ); |
917 | journal->setCalEnabled( true ); | 927 | journal->setCalEnabled( true ); |
918 | return true; | 928 | return true; |
919 | } | 929 | } |
920 | 930 | ||
921 | void CalendarLocal::deleteJournal( Journal *journal ) | 931 | void CalendarLocal::deleteJournal( Journal *journal ) |
922 | { | 932 | { |
923 | clearUndo(journal); | 933 | clearUndo(journal); |
924 | if ( mJournalList.removeRef(journal) ) { | 934 | if ( mJournalList.removeRef(journal) ) { |
925 | setModified( true ); | 935 | setModified( true ); |
926 | } | 936 | } |
927 | } | 937 | } |
928 | 938 | ||
929 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 939 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
930 | { | 940 | { |
931 | QPtrList<Journal> el; | 941 | QPtrList<Journal> el; |
932 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 942 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
933 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 943 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
934 | return el; | 944 | return el; |
935 | } | 945 | } |
936 | Journal *CalendarLocal::journal( const QDate &date ) | 946 | Journal *CalendarLocal::journal( const QDate &date ) |
937 | { | 947 | { |
938 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 948 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
939 | 949 | ||
940 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 950 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
941 | if ( it->calEnabled() && it->dtStart().date() == date ) | 951 | if ( it->calEnabled() && it->dtStart().date() == date ) |
942 | return it; | 952 | return it; |
943 | 953 | ||
944 | return 0; | 954 | return 0; |
945 | } | 955 | } |
946 | 956 | ||
947 | Journal *CalendarLocal::journal( const QString &uid ) | 957 | Journal *CalendarLocal::journal( const QString &uid ) |
948 | { | 958 | { |
949 | Journal * retVal = 0; | 959 | Journal * retVal = 0; |
950 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 960 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
951 | if ( it->calEnabled() && it->uid() == uid ) { | 961 | if ( it->calEnabled() && it->uid() == uid ) { |
952 | if ( retVal ) { | 962 | if ( retVal ) { |
953 | if ( retVal->calID() > it->calID() ) { | 963 | if ( retVal->calID() > it->calID() ) { |
954 | retVal = it; | 964 | retVal = it; |
955 | } | 965 | } |
956 | } else { | 966 | } else { |
957 | retVal = it; | 967 | retVal = it; |
958 | } | 968 | } |
959 | } | 969 | } |
960 | return retVal; | 970 | return retVal; |
961 | } | 971 | } |
962 | 972 | ||
963 | QPtrList<Journal> CalendarLocal::journals() | 973 | QPtrList<Journal> CalendarLocal::journals() |
964 | { | 974 | { |
965 | QPtrList<Journal> el; | 975 | QPtrList<Journal> el; |
966 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 976 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
967 | if ( it->calEnabled() ) el.append( it ); | 977 | if ( it->calEnabled() ) el.append( it ); |
968 | return el; | 978 | return el; |
969 | } | 979 | } |
970 | void CalendarLocal::setCalendarRemove( int id ) | 980 | void CalendarLocal::setCalendarRemove( int id ) |
971 | { | 981 | { |
972 | 982 | ||
973 | { | 983 | { |
974 | QPtrList<Event> EventList = mEventList; | 984 | QPtrList<Event> EventList = mEventList; |
975 | Event * ev = EventList.first(); | 985 | Event * ev = EventList.first(); |
976 | while ( ev ) { | 986 | while ( ev ) { |
977 | if ( ev->calID() == id ) | 987 | if ( ev->calID() == id ) |
978 | deleteEvent( ev ); | 988 | deleteEvent( ev ); |
979 | ev = EventList.next(); | 989 | ev = EventList.next(); |
980 | } | 990 | } |
981 | } | 991 | } |
982 | { | 992 | { |
983 | 993 | ||
984 | QPtrList<Todo> TodoList = mTodoList; | 994 | QPtrList<Todo> TodoList = mTodoList; |
985 | Todo * ev = TodoList.first(); | 995 | Todo * ev = TodoList.first(); |
986 | while ( ev ) { | 996 | while ( ev ) { |
987 | if ( ev->calID() == id ) | 997 | if ( ev->calID() == id ) |
988 | deleteTodo( ev ); | 998 | deleteTodo( ev ); |
989 | ev = TodoList.next(); | 999 | ev = TodoList.next(); |
990 | } | 1000 | } |
991 | } | 1001 | } |
992 | { | 1002 | { |
993 | QPtrList<Journal> JournalList = mJournalList; | 1003 | QPtrList<Journal> JournalList = mJournalList; |
994 | Journal * ev = JournalList.first(); | 1004 | Journal * ev = JournalList.first(); |
995 | while ( ev ) { | 1005 | while ( ev ) { |
996 | if ( ev->calID() == id ) | 1006 | if ( ev->calID() == id ) |
997 | deleteJournal( ev ); | 1007 | deleteJournal( ev ); |
998 | ev = JournalList.next(); | 1008 | ev = JournalList.next(); |
999 | } | 1009 | } |
1000 | } | 1010 | } |
1001 | 1011 | ||
1002 | clearUndo(0); | 1012 | clearUndo(0); |
1003 | 1013 | ||
1004 | } | 1014 | } |
1005 | 1015 | ||
1016 | void CalendarLocal::setAllCalendarEnabled( bool enable ) | ||
1017 | { | ||
1018 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
1019 | it->setCalEnabled( enable ); | ||
1020 | |||
1021 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
1022 | it->setCalEnabled( enable ); | ||
1023 | |||
1024 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
1025 | it->setCalEnabled( enable ); | ||
1026 | |||
1027 | |||
1028 | } | ||
1006 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 1029 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
1007 | { | 1030 | { |
1008 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1031 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1009 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1032 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1010 | 1033 | ||
1011 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1034 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1012 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1035 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1013 | 1036 | ||
1014 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1037 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1015 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 1038 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
1016 | 1039 | ||
1017 | } | 1040 | } |
1018 | 1041 | ||
1019 | void CalendarLocal::setReadOnly( int id, bool enable ) | 1042 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1020 | { | 1043 | { |
1021 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1044 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1022 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1045 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1023 | 1046 | ||
1024 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1047 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1025 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1048 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1026 | 1049 | ||
1027 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1050 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1028 | if ( it->calID() == id ) it->setReadOnly( enable ); | 1051 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1029 | 1052 | ||
1030 | } | 1053 | } |
1031 | 1054 | ||
1032 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 1055 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1033 | { | 1056 | { |
1034 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1057 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1035 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1058 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1036 | 1059 | ||
1037 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1060 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1038 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1061 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1039 | 1062 | ||
1040 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1063 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1041 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1064 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1042 | reInitAlarmSettings(); | 1065 | reInitAlarmSettings(); |
1043 | 1066 | ||
1044 | } | 1067 | } |
1045 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1068 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1046 | { | 1069 | { |
1047 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1070 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1048 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1071 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1049 | 1072 | ||
1050 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1073 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1051 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1074 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1052 | 1075 | ||
1053 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1076 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1054 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1077 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1055 | 1078 | ||
1056 | } | 1079 | } |