-rw-r--r-- | libkcal/calendarlocal.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 336c3e8..8c4dde1 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,272 +1,282 @@ | |||
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 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 71 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
72 | { | 72 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 73 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( id ); | 74 | calendar.setDefaultCalendar( id ); |
75 | if ( calendar.load( name ) ) { | 75 | if ( calendar.load( name ) ) { |
76 | addCalendar( &calendar ); | 76 | addCalendar( &calendar ); |
77 | return true; | 77 | return true; |
78 | } | 78 | } |
79 | return false; | 79 | return false; |
80 | } | 80 | } |
81 | void CalendarLocal::setSyncEventsReadOnly() | ||
82 | { | ||
83 | Event * ev; | ||
84 | ev = mEventList.first(); | ||
85 | while ( ev ) { | ||
86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | ||
87 | ev->setReadOnly( true ); | ||
88 | ev = mEventList.next(); | ||
89 | } | ||
90 | } | ||
81 | void CalendarLocal::addCalendar( Calendar* cal ) | 91 | void CalendarLocal::addCalendar( Calendar* cal ) |
82 | { | 92 | { |
83 | cal->setDontDeleteIncidencesOnClose(); | 93 | cal->setDontDeleteIncidencesOnClose(); |
84 | { | 94 | { |
85 | QPtrList<Event> EventList = cal->rawEvents(); | 95 | QPtrList<Event> EventList = cal->rawEvents(); |
86 | Event * ev = EventList.first(); | 96 | Event * ev = EventList.first(); |
87 | while ( ev ) { | 97 | while ( ev ) { |
88 | ev->unRegisterObserver( cal ); | 98 | ev->unRegisterObserver( cal ); |
89 | ev->registerObserver( this ); | 99 | ev->registerObserver( this ); |
90 | mEventList.append( ev ); | 100 | mEventList.append( ev ); |
91 | ev = EventList.next(); | 101 | ev = EventList.next(); |
92 | } | 102 | } |
93 | } | 103 | } |
94 | { | 104 | { |
95 | 105 | ||
96 | QPtrList<Todo> TodoList = cal->rawTodos(); | 106 | QPtrList<Todo> TodoList = cal->rawTodos(); |
97 | Todo * ev = TodoList.first(); | 107 | Todo * ev = TodoList.first(); |
98 | while ( ev ) { | 108 | while ( ev ) { |
99 | QString rel = ev->relatedToUid(); | 109 | QString rel = ev->relatedToUid(); |
100 | if ( !rel.isEmpty() ){ | 110 | if ( !rel.isEmpty() ){ |
101 | ev->setRelatedTo ( 0 ); | 111 | ev->setRelatedTo ( 0 ); |
102 | ev->setRelatedToUid( rel ); | 112 | ev->setRelatedToUid( rel ); |
103 | } | 113 | } |
104 | ev = TodoList.next(); | 114 | ev = TodoList.next(); |
105 | } | 115 | } |
106 | //TodoList = cal->rawTodos(); | 116 | //TodoList = cal->rawTodos(); |
107 | ev = TodoList.first(); | 117 | ev = TodoList.first(); |
108 | while ( ev ) { | 118 | while ( ev ) { |
109 | ev->unRegisterObserver( cal ); | 119 | ev->unRegisterObserver( cal ); |
110 | ev->registerObserver( this ); | 120 | ev->registerObserver( this ); |
111 | mTodoList.append( ev ); | 121 | mTodoList.append( ev ); |
112 | setupRelations( ev ); | 122 | setupRelations( ev ); |
113 | ev = TodoList.next(); | 123 | ev = TodoList.next(); |
114 | } | 124 | } |
115 | } | 125 | } |
116 | { | 126 | { |
117 | QPtrList<Journal> JournalList = cal->journals(); | 127 | QPtrList<Journal> JournalList = cal->journals(); |
118 | Journal * ev = JournalList.first(); | 128 | Journal * ev = JournalList.first(); |
119 | while ( ev ) { | 129 | while ( ev ) { |
120 | ev->unRegisterObserver( cal ); | 130 | ev->unRegisterObserver( cal ); |
121 | ev->registerObserver( this ); | 131 | ev->registerObserver( this ); |
122 | mJournalList.append( ev ); | 132 | mJournalList.append( ev ); |
123 | ev = JournalList.next(); | 133 | ev = JournalList.next(); |
124 | } | 134 | } |
125 | } | 135 | } |
126 | setModified( true ); | 136 | setModified( true ); |
127 | } | 137 | } |
128 | bool CalendarLocal::load( const QString &fileName ) | 138 | bool CalendarLocal::load( const QString &fileName ) |
129 | { | 139 | { |
130 | FileStorage storage( this, fileName ); | 140 | FileStorage storage( this, fileName ); |
131 | return storage.load(); | 141 | return storage.load(); |
132 | } | 142 | } |
133 | 143 | ||
134 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
135 | { | 145 | { |
136 | FileStorage storage( this, fileName, format ); | 146 | FileStorage storage( this, fileName, format ); |
137 | return storage.save(); | 147 | return storage.save(); |
138 | } | 148 | } |
139 | 149 | ||
140 | void CalendarLocal::close() | 150 | void CalendarLocal::close() |
141 | { | 151 | { |
142 | 152 | ||
143 | Todo * i; | 153 | Todo * i; |
144 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 154 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
145 | 155 | ||
146 | mEventList.setAutoDelete( true ); | 156 | mEventList.setAutoDelete( true ); |
147 | mTodoList.setAutoDelete( true ); | 157 | mTodoList.setAutoDelete( true ); |
148 | mJournalList.setAutoDelete( false ); | 158 | mJournalList.setAutoDelete( false ); |
149 | 159 | ||
150 | mEventList.clear(); | 160 | mEventList.clear(); |
151 | mTodoList.clear(); | 161 | mTodoList.clear(); |
152 | mJournalList.clear(); | 162 | mJournalList.clear(); |
153 | 163 | ||
154 | mEventList.setAutoDelete( false ); | 164 | mEventList.setAutoDelete( false ); |
155 | mTodoList.setAutoDelete( false ); | 165 | mTodoList.setAutoDelete( false ); |
156 | mJournalList.setAutoDelete( false ); | 166 | mJournalList.setAutoDelete( false ); |
157 | 167 | ||
158 | setModified( false ); | 168 | setModified( false ); |
159 | } | 169 | } |
160 | 170 | ||
161 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 171 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
162 | { | 172 | { |
163 | QString cat; | 173 | QString cat; |
164 | bool isBirthday = true; | 174 | bool isBirthday = true; |
165 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 175 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
166 | isBirthday = false; | 176 | isBirthday = false; |
167 | cat = i18n( "Anniversary" ); | 177 | cat = i18n( "Anniversary" ); |
168 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 178 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
169 | isBirthday = true; | 179 | isBirthday = true; |
170 | cat = i18n( "Birthday" ); | 180 | cat = i18n( "Birthday" ); |
171 | } else { | 181 | } else { |
172 | qDebug("addAnniversaryNoDup called without fitting category! "); | 182 | qDebug("addAnniversaryNoDup called without fitting category! "); |
173 | return false; | 183 | return false; |
174 | } | 184 | } |
175 | Event * eve; | 185 | Event * eve; |
176 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 186 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
177 | if ( !(eve->categories().contains( cat ) )) | 187 | if ( !(eve->categories().contains( cat ) )) |
178 | continue; | 188 | continue; |
179 | // now we have an event with fitting category | 189 | // now we have an event with fitting category |
180 | if ( eve->dtStart().date() != event->dtStart().date() ) | 190 | if ( eve->dtStart().date() != event->dtStart().date() ) |
181 | continue; | 191 | continue; |
182 | // now we have an event with fitting category+date | 192 | // now we have an event with fitting category+date |
183 | if ( eve->summary() != event->summary() ) | 193 | if ( eve->summary() != event->summary() ) |
184 | continue; | 194 | continue; |
185 | // now we have an event with fitting category+date+summary | 195 | // now we have an event with fitting category+date+summary |
186 | return false; | 196 | return false; |
187 | } | 197 | } |
188 | return addEvent( event ); | 198 | return addEvent( event ); |
189 | 199 | ||
190 | } | 200 | } |
191 | bool CalendarLocal::addEventNoDup( Event *event ) | 201 | bool CalendarLocal::addEventNoDup( Event *event ) |
192 | { | 202 | { |
193 | Event * eve; | 203 | Event * eve; |
194 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 204 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
195 | if ( *eve == *event ) { | 205 | if ( *eve == *event ) { |
196 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 206 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
197 | return false; | 207 | return false; |
198 | } | 208 | } |
199 | } | 209 | } |
200 | return addEvent( event ); | 210 | return addEvent( event ); |
201 | } | 211 | } |
202 | 212 | ||
203 | bool CalendarLocal::addEvent( Event *event ) | 213 | bool CalendarLocal::addEvent( Event *event ) |
204 | { | 214 | { |
205 | insertEvent( event ); | 215 | insertEvent( event ); |
206 | 216 | ||
207 | event->registerObserver( this ); | 217 | event->registerObserver( this ); |
208 | 218 | ||
209 | setModified( true ); | 219 | setModified( true ); |
210 | event->setCalID( mDefaultCalendar ); | 220 | event->setCalID( mDefaultCalendar ); |
211 | event->setCalEnabled( true ); | 221 | event->setCalEnabled( true ); |
212 | 222 | ||
213 | return true; | 223 | return true; |
214 | } | 224 | } |
215 | 225 | ||
216 | void CalendarLocal::deleteEvent( Event *event ) | 226 | void CalendarLocal::deleteEvent( Event *event ) |
217 | { | 227 | { |
218 | if ( mUndoIncidence ) delete mUndoIncidence; | 228 | if ( mUndoIncidence ) delete mUndoIncidence; |
219 | mUndoIncidence = event->clone(); | 229 | mUndoIncidence = event->clone(); |
220 | if ( mEventList.removeRef( event ) ) { | 230 | if ( mEventList.removeRef( event ) ) { |
221 | setModified( true ); | 231 | setModified( true ); |
222 | } | 232 | } |
223 | } | 233 | } |
224 | 234 | ||
225 | 235 | ||
226 | Event *CalendarLocal::event( const QString &uid ) | 236 | Event *CalendarLocal::event( const QString &uid ) |
227 | { | 237 | { |
228 | Event *event; | 238 | Event *event; |
229 | Event *retVal = 0; | 239 | Event *retVal = 0; |
230 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 240 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
231 | if ( event->calEnabled() && event->uid() == uid ) { | 241 | if ( event->calEnabled() && event->uid() == uid ) { |
232 | if ( retVal ) { | 242 | if ( retVal ) { |
233 | if ( retVal->calID() > event->calID() ) { | 243 | if ( retVal->calID() > event->calID() ) { |
234 | retVal = event; | 244 | retVal = event; |
235 | } | 245 | } |
236 | } else { | 246 | } else { |
237 | retVal = event; | 247 | retVal = event; |
238 | } | 248 | } |
239 | } | 249 | } |
240 | } | 250 | } |
241 | return retVal; | 251 | return retVal; |
242 | } | 252 | } |
243 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 253 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
244 | { | 254 | { |
245 | Todo * eve; | 255 | Todo * eve; |
246 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 256 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
247 | if ( *eve == *todo ) { | 257 | if ( *eve == *todo ) { |
248 | //qDebug("duplicate todo found! not inserted! "); | 258 | //qDebug("duplicate todo found! not inserted! "); |
249 | return false; | 259 | return false; |
250 | } | 260 | } |
251 | } | 261 | } |
252 | return addTodo( todo ); | 262 | return addTodo( todo ); |
253 | } | 263 | } |
254 | bool CalendarLocal::addTodo( Todo *todo ) | 264 | bool CalendarLocal::addTodo( Todo *todo ) |
255 | { | 265 | { |
256 | mTodoList.append( todo ); | 266 | mTodoList.append( todo ); |
257 | 267 | ||
258 | todo->registerObserver( this ); | 268 | todo->registerObserver( this ); |
259 | 269 | ||
260 | // Set up subtask relations | 270 | // Set up subtask relations |
261 | setupRelations( todo ); | 271 | setupRelations( todo ); |
262 | 272 | ||
263 | setModified( true ); | 273 | setModified( true ); |
264 | todo->setCalID( mDefaultCalendar ); | 274 | todo->setCalID( mDefaultCalendar ); |
265 | todo->setCalEnabled( true ); | 275 | todo->setCalEnabled( true ); |
266 | return true; | 276 | return true; |
267 | } | 277 | } |
268 | 278 | ||
269 | void CalendarLocal::deleteTodo( Todo *todo ) | 279 | void CalendarLocal::deleteTodo( Todo *todo ) |
270 | { | 280 | { |
271 | // Handle orphaned children | 281 | // Handle orphaned children |
272 | if ( mUndoIncidence ) delete mUndoIncidence; | 282 | if ( mUndoIncidence ) delete mUndoIncidence; |