summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index e37a7ad..eef8327 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -1,323 +1,324 @@
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
46using namespace KCal; 46using namespace KCal;
47 47
48CalendarLocal::CalendarLocal() 48CalendarLocal::CalendarLocal()
49 : Calendar() 49 : Calendar()
50{ 50{
51 init(); 51 init();
52} 52}
53 53
54CalendarLocal::CalendarLocal(const QString &timeZoneId) 54CalendarLocal::CalendarLocal(const QString &timeZoneId)
55 : Calendar(timeZoneId) 55 : Calendar(timeZoneId)
56{ 56{
57 init(); 57 init();
58} 58}
59 59
60void CalendarLocal::init() 60void CalendarLocal::init()
61{ 61{
62 mNextAlarmIncidence = 0; 62 mNextAlarmIncidence = 0;
63} 63}
64 64
65 65
66CalendarLocal::~CalendarLocal() 66CalendarLocal::~CalendarLocal()
67{ 67{
68 registerObserver( 0 );
68 if ( mDeleteIncidencesOnClose ) 69 if ( mDeleteIncidencesOnClose )
69 close(); 70 close();
70} 71}
71bool CalendarLocal::mergeCalendarFile( QString name ) 72bool CalendarLocal::mergeCalendarFile( QString name )
72{ 73{
73 CalendarLocal calendar( timeZoneId() ); 74 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 75 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 76 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 77 mergeCalendar( &calendar );
77 return true; 78 return true;
78 } 79 }
79 return false; 80 return false;
80} 81}
81 82
82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) 83Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 84{
84 Todo *todo;; 85 Todo *todo;;
85 Incidence *retVal = 0; 86 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 87 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 88 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo; 89 if ( doNotCheckDuplicates ) return todo;
89 if ( retVal ) { 90 if ( retVal ) {
90 if ( retVal->calID() > todo->calID() ) { 91 if ( retVal->calID() > todo->calID() ) {
91 retVal = todo; 92 retVal = todo;
92 } 93 }
93 } else { 94 } else {
94 retVal = todo; 95 retVal = todo;
95 } 96 }
96 } 97 }
97 } 98 }
98 if ( retVal ) return retVal; 99 if ( retVal ) return retVal;
99 Event *event; 100 Event *event;
100 for ( event = mEventList.first(); event; event = mEventList.next() ) { 101 for ( event = mEventList.first(); event; event = mEventList.next() ) {
101 if ( event->uid() == uid ) { 102 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event; 103 if ( doNotCheckDuplicates ) return event;
103 if ( retVal ) { 104 if ( retVal ) {
104 if ( retVal->calID() > event->calID() ) { 105 if ( retVal->calID() > event->calID() ) {
105 retVal = event; 106 retVal = event;
106 } 107 }
107 } else { 108 } else {
108 retVal = event; 109 retVal = event;
109 } 110 }
110 } 111 }
111 } 112 }
112 if ( retVal ) return retVal; 113 if ( retVal ) return retVal;
113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 114 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
114 if ( it->uid() == uid ) { 115 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it; 116 if ( doNotCheckDuplicates ) return it;
116 if ( retVal ) { 117 if ( retVal ) {
117 if ( retVal->calID() > it->calID() ) { 118 if ( retVal->calID() > it->calID() ) {
118 retVal = it; 119 retVal = it;
119 } 120 }
120 } else { 121 } else {
121 retVal = it; 122 retVal = it;
122 } 123 }
123 } 124 }
124 return retVal; 125 return retVal;
125} 126}
126 127
127bool CalendarLocal::mergeCalendar( Calendar* remote ) 128bool CalendarLocal::mergeCalendar( Calendar* remote )
128{ 129{
129 // 1 look for raw inc in local 130 // 1 look for raw inc in local
130 // if inc not in remote, delete in local 131 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote 132 // 2 look for raw inc in remote
132 // if inc in local, replace it 133 // if inc in local, replace it
133 // if not in local, add it to default calendar 134 // if not in local, add it to default calendar
134 QPtrList<Incidence> localInc = rawIncidences(); 135 QPtrList<Incidence> localInc = rawIncidences();
135 Incidence* inL = localInc.first(); 136 Incidence* inL = localInc.first();
136 while ( inL ) { 137 while ( inL ) {
137 if ( ! inL->isReadOnly () ) 138 if ( ! inL->isReadOnly () )
138 if ( !remote->incidenceForUid( inL->uid(), true )) 139 if ( !remote->incidenceForUid( inL->uid(), true ))
139 deleteIncidence( inL ); 140 deleteIncidence( inL );
140 inL = localInc.next(); 141 inL = localInc.next();
141 } 142 }
142 QPtrList<Incidence> er = remote->rawIncidences(); 143 QPtrList<Incidence> er = remote->rawIncidences();
143 Incidence* inR = er.first(); 144 Incidence* inR = er.first();
144 while ( inR ) { 145 while ( inR ) {
145 inL = incidenceForUid( inR->uid(),false ); 146 inL = incidenceForUid( inR->uid(),false );
146 if ( inL ) { 147 if ( inL ) {
147 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 148 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
148 int calID = inL->calID(); 149 int calID = inL->calID();
149 deleteIncidence( inL ); 150 deleteIncidence( inL );
150 inL = inR->clone(); 151 inL = inR->clone();
151 inL->setCalID( calID ); 152 inL->setCalID( calID );
152 addIncidence( inL ); 153 addIncidence( inL );
153 } 154 }
154 } else { 155 } else {
155 inL = inR->clone(); 156 inL = inR->clone();
156 inL->setCalID( 0 );// add to default cal 157 inL->setCalID( 0 );// add to default cal
157 addIncidence( inL ); 158 addIncidence( inL );
158 } 159 }
159 inR = er.next(); 160 inR = er.next();
160 } 161 }
161 return true; 162 return true;
162} 163}
163 164
164 165
165bool CalendarLocal::addCalendarFile( QString name, int id ) 166bool CalendarLocal::addCalendarFile( QString name, int id )
166{ 167{
167 CalendarLocal calendar( timeZoneId() ); 168 CalendarLocal calendar( timeZoneId() );
168 calendar.setDefaultCalendar( id ); 169 calendar.setDefaultCalendar( id );
169 if ( calendar.load( name ) ) { 170 if ( calendar.load( name ) ) {
170 addCalendar( &calendar ); 171 addCalendar( &calendar );
171 return true; 172 return true;
172 } 173 }
173 return false; 174 return false;
174} 175}
175void CalendarLocal::setSyncEventsReadOnly() 176void CalendarLocal::setSyncEventsReadOnly()
176{ 177{
177 Event * ev; 178 Event * ev;
178 ev = mEventList.first(); 179 ev = mEventList.first();
179 while ( ev ) { 180 while ( ev ) {
180 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 181 if ( ev->uid().left(15) == QString("last-syncEvent-") )
181 ev->setReadOnly( true ); 182 ev->setReadOnly( true );
182 ev = mEventList.next(); 183 ev = mEventList.next();
183 } 184 }
184} 185}
185void CalendarLocal::addCalendar( Calendar* cal ) 186void CalendarLocal::addCalendar( Calendar* cal )
186{ 187{
187 cal->setDontDeleteIncidencesOnClose(); 188 cal->setDontDeleteIncidencesOnClose();
188 { 189 {
189 QPtrList<Event> EventList = cal->rawEvents(); 190 QPtrList<Event> EventList = cal->rawEvents();
190 Event * ev = EventList.first(); 191 Event * ev = EventList.first();
191 while ( ev ) { 192 while ( ev ) {
192 ev->unRegisterObserver( cal ); 193 ev->unRegisterObserver( cal );
193 ev->registerObserver( this ); 194 ev->registerObserver( this );
194 mEventList.append( ev ); 195 mEventList.append( ev );
195 ev = EventList.next(); 196 ev = EventList.next();
196 } 197 }
197 } 198 }
198 { 199 {
199 200
200 QPtrList<Todo> TodoList = cal->rawTodos(); 201 QPtrList<Todo> TodoList = cal->rawTodos();
201 Todo * ev = TodoList.first(); 202 Todo * ev = TodoList.first();
202 while ( ev ) { 203 while ( ev ) {
203 QString rel = ev->relatedToUid(); 204 QString rel = ev->relatedToUid();
204 if ( !rel.isEmpty() ){ 205 if ( !rel.isEmpty() ){
205 ev->setRelatedTo ( 0 ); 206 ev->setRelatedTo ( 0 );
206 ev->setRelatedToUid( rel ); 207 ev->setRelatedToUid( rel );
207 } 208 }
208 ev = TodoList.next(); 209 ev = TodoList.next();
209 } 210 }
210 //TodoList = cal->rawTodos(); 211 //TodoList = cal->rawTodos();
211 ev = TodoList.first(); 212 ev = TodoList.first();
212 while ( ev ) { 213 while ( ev ) {
213 ev->unRegisterObserver( cal ); 214 ev->unRegisterObserver( cal );
214 ev->registerObserver( this ); 215 ev->registerObserver( this );
215 mTodoList.append( ev ); 216 mTodoList.append( ev );
216 setupRelations( ev ); 217 setupRelations( ev );
217 ev = TodoList.next(); 218 ev = TodoList.next();
218 } 219 }
219 } 220 }
220 { 221 {
221 QPtrList<Journal> JournalList = cal->journals(); 222 QPtrList<Journal> JournalList = cal->journals();
222 Journal * ev = JournalList.first(); 223 Journal * ev = JournalList.first();
223 while ( ev ) { 224 while ( ev ) {
224 ev->unRegisterObserver( cal ); 225 ev->unRegisterObserver( cal );
225 ev->registerObserver( this ); 226 ev->registerObserver( this );
226 mJournalList.append( ev ); 227 mJournalList.append( ev );
227 ev = JournalList.next(); 228 ev = JournalList.next();
228 } 229 }
229 } 230 }
230 setModified( true ); 231 setModified( true );
231} 232}
232bool CalendarLocal::load( const QString &fileName ) 233bool CalendarLocal::load( const QString &fileName )
233{ 234{
234 FileStorage storage( this, fileName ); 235 FileStorage storage( this, fileName );
235 return storage.load(); 236 return storage.load();
236} 237}
237 238
238bool CalendarLocal::save( const QString &fileName, CalFormat *format ) 239bool CalendarLocal::save( const QString &fileName, CalFormat *format )
239{ 240{
240 FileStorage storage( this, fileName, format ); 241 FileStorage storage( this, fileName, format );
241 return storage.save(); 242 return storage.save();
242} 243}
243 244
244void CalendarLocal::stopAllTodos() 245void CalendarLocal::stopAllTodos()
245{ 246{
246 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 247 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
247 it->setRunning( false ); 248 it->setRunning( false );
248 249
249} 250}
250void CalendarLocal::close() 251void CalendarLocal::close()
251{ 252{
252 253
253 Todo * i; 254 Todo * i;
254 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); 255 for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
255 256
256 mEventList.setAutoDelete( true ); 257 mEventList.setAutoDelete( true );
257 mTodoList.setAutoDelete( true ); 258 mTodoList.setAutoDelete( true );
258 mJournalList.setAutoDelete( false ); 259 mJournalList.setAutoDelete( false );
259 260
260 mEventList.clear(); 261 mEventList.clear();
261 mTodoList.clear(); 262 mTodoList.clear();
262 mJournalList.clear(); 263 mJournalList.clear();
263 264
264 mEventList.setAutoDelete( false ); 265 mEventList.setAutoDelete( false );
265 mTodoList.setAutoDelete( false ); 266 mTodoList.setAutoDelete( false );
266 mJournalList.setAutoDelete( false ); 267 mJournalList.setAutoDelete( false );
267 268
268 setModified( false ); 269 setModified( false );
269} 270}
270 271
271bool CalendarLocal::addAnniversaryNoDup( Event *event ) 272bool CalendarLocal::addAnniversaryNoDup( Event *event )
272{ 273{
273 QString cat; 274 QString cat;
274 bool isBirthday = true; 275 bool isBirthday = true;
275 if( event->categoriesStr() == i18n( "Anniversary" ) ) { 276 if( event->categoriesStr() == i18n( "Anniversary" ) ) {
276 isBirthday = false; 277 isBirthday = false;
277 cat = i18n( "Anniversary" ); 278 cat = i18n( "Anniversary" );
278 } else if( event->categoriesStr() == i18n( "Birthday" ) ) { 279 } else if( event->categoriesStr() == i18n( "Birthday" ) ) {
279 isBirthday = true; 280 isBirthday = true;
280 cat = i18n( "Birthday" ); 281 cat = i18n( "Birthday" );
281 } else { 282 } else {
282 qDebug("addAnniversaryNoDup called without fitting category! "); 283 qDebug("addAnniversaryNoDup called without fitting category! ");
283 return false; 284 return false;
284 } 285 }
285 Event * eve; 286 Event * eve;
286 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 287 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
287 if ( !(eve->categories().contains( cat ) )) 288 if ( !(eve->categories().contains( cat ) ))
288 continue; 289 continue;
289 // now we have an event with fitting category 290 // now we have an event with fitting category
290 if ( eve->dtStart().date() != event->dtStart().date() ) 291 if ( eve->dtStart().date() != event->dtStart().date() )
291 continue; 292 continue;
292 // now we have an event with fitting category+date 293 // now we have an event with fitting category+date
293 if ( eve->summary() != event->summary() ) 294 if ( eve->summary() != event->summary() )
294 continue; 295 continue;
295 // now we have an event with fitting category+date+summary 296 // now we have an event with fitting category+date+summary
296 return false; 297 return false;
297 } 298 }
298 return addEvent( event ); 299 return addEvent( event );
299 300
300} 301}
301bool CalendarLocal::addEventNoDup( Event *event ) 302bool CalendarLocal::addEventNoDup( Event *event )
302{ 303{
303 Event * eve; 304 Event * eve;
304 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { 305 for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) {
305 if ( *eve == *event ) { 306 if ( *eve == *event ) {
306 //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); 307 //qDebug("CalendarLocal::Duplicate event found! Not inserted! ");
307 return false; 308 return false;
308 } 309 }
309 } 310 }
310 return addEvent( event ); 311 return addEvent( event );
311} 312}
312 313
313bool CalendarLocal::addEvent( Event *event ) 314bool CalendarLocal::addEvent( Event *event )
314{ 315{
315 insertEvent( event ); 316 insertEvent( event );
316 317
317 event->registerObserver( this ); 318 event->registerObserver( this );
318 319
319 setModified( true ); 320 setModified( true );
320 if ( event->calID() == 0 ) 321 if ( event->calID() == 0 )
321 event->setCalID( mDefaultCalendar ); 322 event->setCalID( mDefaultCalendar );
322 event->setCalEnabled( true ); 323 event->setCalEnabled( true );
323 324