author | zautrix <zautrix> | 2005-07-30 14:43:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-30 14:43:57 (UTC) |
commit | 9ca2cd947f22d33543e065f54c6487e86d80befa (patch) (unidiff) | |
tree | 549192e9e27e8972e2b48cf40e1599118df12da5 | |
parent | 055928e26613f4ab249bd82be86890ed278372f6 (diff) | |
download | kdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.zip kdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.tar.gz kdepimpi-9ca2cd947f22d33543e065f54c6487e86d80befa.tar.bz2 |
fixxx
-rw-r--r-- | libkcal/calendar.cpp | 42 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 26 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.h | 1 |
6 files changed, 50 insertions, 27 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index b7990d4..b1806ee 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,489 +1,523 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | 33 | #include "syncdefines.h" |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | Calendar::Calendar() | 37 | Calendar::Calendar() |
38 | { | 38 | { |
39 | 39 | ||
40 | init(); | 40 | init(); |
41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
42 | } | 42 | } |
43 | 43 | ||
44 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
45 | { | 45 | { |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mDeleteIncidencesOnClose = true; | 56 | mDeleteIncidencesOnClose = true; |
57 | mModified = false; | 57 | mModified = false; |
58 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
59 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
60 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
61 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
62 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
63 | 63 | ||
64 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
65 | // even that good of one at that. | 65 | // even that good of one at that. |
66 | // srandom(time(0)); | 66 | // srandom(time(0)); |
67 | 67 | ||
68 | // user information... | 68 | // user information... |
69 | setOwner(i18n("Unknown Name")); | 69 | setOwner(i18n("Unknown Name")); |
70 | setEmail(i18n("unknown@nowhere")); | 70 | setEmail(i18n("unknown@nowhere")); |
71 | 71 | ||
72 | #if 0 | 72 | #if 0 |
73 | tmpStr = KOPrefs::instance()->mTimeZone; | 73 | tmpStr = KOPrefs::instance()->mTimeZone; |
74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
76 | extern long int timezone; | 76 | extern long int timezone; |
77 | struct tm *now; | 77 | struct tm *now; |
78 | time_t curtime; | 78 | time_t curtime; |
79 | curtime = time(0); | 79 | curtime = time(0); |
80 | now = localtime(&curtime); | 80 | now = localtime(&curtime); |
81 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
82 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
83 | hourOff += 1; | 83 | hourOff += 1; |
84 | QString tzStr; | 84 | QString tzStr; |
85 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
86 | hourOff, | 86 | hourOff, |
87 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
88 | 88 | ||
89 | // if no time zone was in the config file, write what we just discovered. | 89 | // if no time zone was in the config file, write what we just discovered. |
90 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
91 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
92 | } else { | 92 | } else { |
93 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
94 | } | 94 | } |
95 | 95 | ||
96 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
97 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
98 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
99 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
100 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
102 | } | 102 | } |
103 | 103 | ||
104 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
105 | #endif | 105 | #endif |
106 | 106 | ||
107 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
108 | } | 108 | } |
109 | 109 | ||
110 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
111 | { | 111 | { |
112 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
113 | if ( mUndoIncidence ) | 113 | clearUndo( 0 ); |
114 | delete mUndoIncidence; | 114 | } |
115 | } | 115 | void Calendar::clearUndo( Incidence * newUndo ) |
116 | { | ||
117 | |||
118 | if ( mUndoIncidence ) { | ||
119 | if ( mUndoIncidence->typeID() == eventID ) | ||
120 | delete ((Event*) mUndoIncidence) ; | ||
121 | else if ( mUndoIncidence->typeID() == todoID ) | ||
122 | delete ( (Todo*) mUndoIncidence ); | ||
123 | else if ( mUndoIncidence->typeID() == journalID ) | ||
124 | delete ( (Journal*) mUndoIncidence ); | ||
125 | else | ||
126 | delete mUndoIncidence; | ||
127 | } | ||
128 | mUndoIncidence = newUndo; | ||
129 | if ( mUndoIncidence ) { | ||
130 | mUndoIncidence->clearRelations(); | ||
131 | } | ||
132 | |||
133 | } | ||
134 | |||
116 | void Calendar::setDontDeleteIncidencesOnClose () | 135 | void Calendar::setDontDeleteIncidencesOnClose () |
117 | { | 136 | { |
118 | mDeleteIncidencesOnClose = false; | 137 | mDeleteIncidencesOnClose = false; |
119 | } | 138 | } |
120 | void Calendar::setDefaultCalendar( int d ) | 139 | void Calendar::setDefaultCalendar( int d ) |
121 | { | 140 | { |
122 | mDefaultCalendar = d; | 141 | mDefaultCalendar = d; |
123 | } | 142 | } |
124 | int Calendar::defaultCalendar() | 143 | int Calendar::defaultCalendar() |
125 | { | 144 | { |
126 | return mDefaultCalendar; | 145 | return mDefaultCalendar; |
127 | } | 146 | } |
128 | const QString &Calendar::getOwner() const | 147 | const QString &Calendar::getOwner() const |
129 | { | 148 | { |
130 | return mOwner; | 149 | return mOwner; |
131 | } | 150 | } |
132 | 151 | ||
133 | bool Calendar::undoDeleteIncidence() | 152 | bool Calendar::undoDeleteIncidence() |
134 | { | 153 | { |
135 | if (!mUndoIncidence) | 154 | if (!mUndoIncidence) |
136 | return false; | 155 | return false; |
137 | addIncidence(mUndoIncidence); | 156 | addIncidence(mUndoIncidence); |
138 | mUndoIncidence = 0; | 157 | mUndoIncidence = 0; |
139 | return true; | 158 | return true; |
140 | } | 159 | } |
141 | void Calendar::setOwner(const QString &os) | 160 | void Calendar::setOwner(const QString &os) |
142 | { | 161 | { |
143 | int i; | 162 | int i; |
144 | mOwner = os; | 163 | mOwner = os; |
145 | i = mOwner.find(','); | 164 | i = mOwner.find(','); |
146 | if (i != -1) | 165 | if (i != -1) |
147 | mOwner = mOwner.left(i); | 166 | mOwner = mOwner.left(i); |
148 | 167 | ||
149 | setModified( true ); | 168 | setModified( true ); |
150 | } | 169 | } |
151 | 170 | ||
152 | void Calendar::setTimeZone(const QString & tz) | 171 | void Calendar::setTimeZone(const QString & tz) |
153 | { | 172 | { |
154 | bool neg = FALSE; | 173 | bool neg = FALSE; |
155 | int hours, minutes; | 174 | int hours, minutes; |
156 | QString tmpStr(tz); | 175 | QString tmpStr(tz); |
157 | 176 | ||
158 | if (tmpStr.left(1) == "-") | 177 | if (tmpStr.left(1) == "-") |
159 | neg = TRUE; | 178 | neg = TRUE; |
160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 179 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
161 | tmpStr.remove(0, 1); | 180 | tmpStr.remove(0, 1); |
162 | hours = tmpStr.left(2).toInt(); | 181 | hours = tmpStr.left(2).toInt(); |
163 | if (tmpStr.length() > 2) | 182 | if (tmpStr.length() > 2) |
164 | minutes = tmpStr.right(2).toInt(); | 183 | minutes = tmpStr.right(2).toInt(); |
165 | else | 184 | else |
166 | minutes = 0; | 185 | minutes = 0; |
167 | mTimeZone = (60*hours+minutes); | 186 | mTimeZone = (60*hours+minutes); |
168 | if (neg) | 187 | if (neg) |
169 | mTimeZone = -mTimeZone; | 188 | mTimeZone = -mTimeZone; |
170 | mLocalTime = false; | 189 | mLocalTime = false; |
171 | 190 | ||
172 | setModified( true ); | 191 | setModified( true ); |
173 | } | 192 | } |
174 | 193 | ||
175 | QString Calendar::getTimeZoneStr() const | 194 | QString Calendar::getTimeZoneStr() const |
176 | { | 195 | { |
177 | if (mLocalTime) | 196 | if (mLocalTime) |
178 | return ""; | 197 | return ""; |
179 | QString tmpStr; | 198 | QString tmpStr; |
180 | int hours = abs(mTimeZone / 60); | 199 | int hours = abs(mTimeZone / 60); |
181 | int minutes = abs(mTimeZone % 60); | 200 | int minutes = abs(mTimeZone % 60); |
182 | bool neg = mTimeZone < 0; | 201 | bool neg = mTimeZone < 0; |
183 | 202 | ||
184 | tmpStr.sprintf("%c%.2d%.2d", | 203 | tmpStr.sprintf("%c%.2d%.2d", |
185 | (neg ? '-' : '+'), | 204 | (neg ? '-' : '+'), |
186 | hours, minutes); | 205 | hours, minutes); |
187 | return tmpStr; | 206 | return tmpStr; |
188 | } | 207 | } |
189 | 208 | ||
190 | void Calendar::setTimeZone(int tz) | 209 | void Calendar::setTimeZone(int tz) |
191 | { | 210 | { |
192 | mTimeZone = tz; | 211 | mTimeZone = tz; |
193 | mLocalTime = false; | 212 | mLocalTime = false; |
194 | 213 | ||
195 | setModified( true ); | 214 | setModified( true ); |
196 | } | 215 | } |
197 | 216 | ||
198 | int Calendar::getTimeZone() const | 217 | int Calendar::getTimeZone() const |
199 | { | 218 | { |
200 | return mTimeZone; | 219 | return mTimeZone; |
201 | } | 220 | } |
202 | 221 | ||
203 | void Calendar::setTimeZoneId(const QString &id) | 222 | void Calendar::setTimeZoneId(const QString &id) |
204 | { | 223 | { |
205 | mTimeZoneId = id; | 224 | mTimeZoneId = id; |
206 | mLocalTime = false; | 225 | mLocalTime = false; |
207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 226 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
208 | if ( mTimeZone > 1000) | 227 | if ( mTimeZone > 1000) |
209 | setLocalTime(); | 228 | setLocalTime(); |
210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 229 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
211 | setModified( true ); | 230 | setModified( true ); |
212 | } | 231 | } |
213 | 232 | ||
214 | QString Calendar::timeZoneId() const | 233 | QString Calendar::timeZoneId() const |
215 | { | 234 | { |
216 | return mTimeZoneId; | 235 | return mTimeZoneId; |
217 | } | 236 | } |
218 | 237 | ||
219 | void Calendar::setLocalTime() | 238 | void Calendar::setLocalTime() |
220 | { | 239 | { |
221 | //qDebug("Calendar::setLocalTime() "); | 240 | //qDebug("Calendar::setLocalTime() "); |
222 | mLocalTime = true; | 241 | mLocalTime = true; |
223 | mTimeZone = 0; | 242 | mTimeZone = 0; |
224 | mTimeZoneId = ""; | 243 | mTimeZoneId = ""; |
225 | 244 | ||
226 | setModified( true ); | 245 | setModified( true ); |
227 | } | 246 | } |
228 | 247 | ||
229 | bool Calendar::isLocalTime() const | 248 | bool Calendar::isLocalTime() const |
230 | { | 249 | { |
231 | return mLocalTime; | 250 | return mLocalTime; |
232 | } | 251 | } |
233 | 252 | ||
234 | const QString &Calendar::getEmail() | 253 | const QString &Calendar::getEmail() |
235 | { | 254 | { |
236 | return mOwnerEmail; | 255 | return mOwnerEmail; |
237 | } | 256 | } |
238 | 257 | ||
239 | void Calendar::setEmail(const QString &e) | 258 | void Calendar::setEmail(const QString &e) |
240 | { | 259 | { |
241 | mOwnerEmail = e; | 260 | mOwnerEmail = e; |
242 | 261 | ||
243 | setModified( true ); | 262 | setModified( true ); |
244 | } | 263 | } |
245 | 264 | ||
246 | void Calendar::setFilter(CalFilter *filter) | 265 | void Calendar::setFilter(CalFilter *filter) |
247 | { | 266 | { |
248 | mFilter = filter; | 267 | mFilter = filter; |
249 | } | 268 | } |
250 | 269 | ||
251 | CalFilter *Calendar::filter() | 270 | CalFilter *Calendar::filter() |
252 | { | 271 | { |
253 | return mFilter; | 272 | return mFilter; |
254 | } | 273 | } |
255 | 274 | ||
256 | QPtrList<Incidence> Calendar::incidences() | 275 | QPtrList<Incidence> Calendar::incidences() |
257 | { | 276 | { |
258 | QPtrList<Incidence> incidences; | 277 | QPtrList<Incidence> incidences; |
259 | 278 | ||
260 | Incidence *i; | 279 | Incidence *i; |
261 | 280 | ||
262 | QPtrList<Event> e = events(); | 281 | QPtrList<Event> e = events(); |
263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 282 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
264 | 283 | ||
265 | QPtrList<Todo> t = todos(); | 284 | QPtrList<Todo> t = todos(); |
266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 285 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
267 | 286 | ||
268 | QPtrList<Journal> j = journals(); | 287 | QPtrList<Journal> j = journals(); |
269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 288 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
270 | 289 | ||
271 | return incidences; | 290 | return incidences; |
272 | } | 291 | } |
273 | 292 | ||
274 | void Calendar::resetPilotStat(int id ) | 293 | void Calendar::resetPilotStat(int id ) |
275 | { | 294 | { |
276 | QPtrList<Incidence> incidences; | 295 | QPtrList<Incidence> incidences; |
277 | 296 | ||
278 | Incidence *i; | 297 | Incidence *i; |
279 | 298 | ||
280 | QPtrList<Event> e = rawEvents(); | 299 | QPtrList<Event> e = rawEvents(); |
281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 300 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
282 | 301 | ||
283 | QPtrList<Todo> t = rawTodos(); | 302 | QPtrList<Todo> t = rawTodos(); |
284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 303 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
285 | 304 | ||
286 | QPtrList<Journal> j = journals(); | 305 | QPtrList<Journal> j = journals(); |
287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 306 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
288 | } | 307 | } |
289 | void Calendar::resetTempSyncStat() | 308 | void Calendar::resetTempSyncStat() |
290 | { | 309 | { |
291 | QPtrList<Incidence> incidences; | 310 | QPtrList<Incidence> incidences; |
292 | 311 | ||
293 | Incidence *i; | 312 | Incidence *i; |
294 | 313 | ||
295 | QPtrList<Event> e = rawEvents(); | 314 | QPtrList<Event> e = rawEvents(); |
296 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 315 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
297 | 316 | ||
298 | QPtrList<Todo> t = rawTodos(); | 317 | QPtrList<Todo> t = rawTodos(); |
299 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 318 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
300 | 319 | ||
301 | QPtrList<Journal> j = journals(); | 320 | QPtrList<Journal> j = journals(); |
302 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 321 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
303 | } | 322 | } |
304 | QPtrList<Incidence> Calendar::rawIncidences() | 323 | QPtrList<Incidence> Calendar::rawIncidences() |
305 | { | 324 | { |
306 | QPtrList<Incidence> incidences; | 325 | QPtrList<Incidence> incidences; |
307 | 326 | ||
308 | Incidence *i; | 327 | Incidence *i; |
309 | 328 | ||
310 | QPtrList<Event> e = rawEvents(); | 329 | QPtrList<Event> e = rawEvents(); |
311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 330 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
312 | 331 | ||
313 | QPtrList<Todo> t = rawTodos(); | 332 | QPtrList<Todo> t = rawTodos(); |
314 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 333 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
315 | 334 | ||
316 | QPtrList<Journal> j = journals(); | 335 | QPtrList<Journal> j = journals(); |
317 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 336 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
318 | 337 | ||
319 | return incidences; | 338 | return incidences; |
320 | } | 339 | } |
321 | 340 | ||
322 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 341 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
323 | { | 342 | { |
324 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 343 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
325 | mFilter->apply(&el); | 344 | mFilter->apply(&el); |
326 | return el; | 345 | return el; |
327 | } | 346 | } |
328 | 347 | ||
329 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 348 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
330 | { | 349 | { |
331 | QPtrList<Event> el = rawEventsForDate(qdt); | 350 | QPtrList<Event> el = rawEventsForDate(qdt); |
332 | mFilter->apply(&el); | 351 | mFilter->apply(&el); |
333 | return el; | 352 | return el; |
334 | } | 353 | } |
335 | 354 | ||
336 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 355 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
337 | bool inclusive) | 356 | bool inclusive) |
338 | { | 357 | { |
339 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 358 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
340 | mFilter->apply(&el); | 359 | mFilter->apply(&el); |
341 | return el; | 360 | return el; |
342 | } | 361 | } |
343 | 362 | ||
344 | QPtrList<Event> Calendar::events() | 363 | QPtrList<Event> Calendar::events() |
345 | { | 364 | { |
346 | QPtrList<Event> el = rawEvents(); | 365 | QPtrList<Event> el = rawEvents(); |
347 | mFilter->apply(&el); | 366 | mFilter->apply(&el); |
348 | return el; | 367 | return el; |
349 | } | 368 | } |
350 | void Calendar::addIncidenceBranch(Incidence *i) | 369 | void Calendar::addIncidenceBranch(Incidence *i) |
351 | { | 370 | { |
352 | addIncidence( i ); | 371 | addIncidence( i ); |
353 | Incidence * inc; | 372 | Incidence * inc; |
354 | QPtrList<Incidence> Relations = i->relations(); | 373 | QPtrList<Incidence> Relations = i->relations(); |
355 | for (inc=Relations.first();inc;inc=Relations.next()) { | 374 | for (inc=Relations.first();inc;inc=Relations.next()) { |
356 | addIncidenceBranch( inc ); | 375 | addIncidenceBranch( inc ); |
357 | } | 376 | } |
358 | } | 377 | } |
359 | 378 | ||
360 | bool Calendar::addIncidence(Incidence *i) | 379 | bool Calendar::addIncidence(Incidence *i) |
361 | { | 380 | { |
362 | Incidence::AddVisitor<Calendar> v(this); | 381 | Incidence::AddVisitor<Calendar> v(this); |
363 | if ( i->calID() == 0 ) | 382 | if ( i->calID() == 0 ) |
364 | i->setCalID( mDefaultCalendar ); | 383 | i->setCalID( mDefaultCalendar ); |
365 | i->setCalEnabled( true ); | 384 | i->setCalEnabled( true ); |
366 | return i->accept(v); | 385 | return i->accept(v); |
367 | } | 386 | } |
368 | void Calendar::deleteIncidence(Incidence *in) | 387 | void Calendar::deleteIncidence(Incidence *in) |
369 | { | 388 | { |
370 | if ( in->typeID() == eventID ) | 389 | if ( in->typeID() == eventID ) |
371 | deleteEvent( (Event*) in ); | 390 | deleteEvent( (Event*) in ); |
372 | else if ( in->typeID() == todoID ) | 391 | else if ( in->typeID() == todoID ) |
373 | deleteTodo( (Todo*) in); | 392 | deleteTodo( (Todo*) in); |
374 | else if ( in->typeID() == journalID ) | 393 | else if ( in->typeID() == journalID ) |
375 | deleteJournal( (Journal*) in ); | 394 | deleteJournal( (Journal*) in ); |
376 | } | 395 | } |
377 | 396 | ||
378 | Incidence* Calendar::incidence( const QString& uid ) | 397 | Incidence* Calendar::incidence( const QString& uid ) |
379 | { | 398 | { |
380 | Incidence* i; | 399 | Incidence* i; |
381 | 400 | ||
382 | if( (i = todo( uid )) != 0 ) | 401 | if( (i = todo( uid )) != 0 ) |
383 | return i; | 402 | return i; |
384 | if( (i = event( uid )) != 0 ) | 403 | if( (i = event( uid )) != 0 ) |
385 | return i; | 404 | return i; |
386 | if( (i = journal( uid )) != 0 ) | 405 | if( (i = journal( uid )) != 0 ) |
387 | return i; | 406 | return i; |
388 | 407 | ||
389 | return 0; | 408 | return 0; |
390 | } | 409 | } |
391 | 410 | ||
392 | QPtrList<Todo> Calendar::todos() | 411 | QPtrList<Todo> Calendar::todos() |
393 | { | 412 | { |
394 | QPtrList<Todo> tl = rawTodos(); | 413 | QPtrList<Todo> tl = rawTodos(); |
395 | mFilter->apply( &tl ); | 414 | mFilter->apply( &tl ); |
396 | return tl; | 415 | return tl; |
397 | } | 416 | } |
398 | 417 | ||
399 | // When this is called, the todo have already been added to the calendar. | 418 | // When this is called, the todo have already been added to the calendar. |
400 | // This method is only about linking related todos | 419 | // This method is only about linking related todos |
401 | void Calendar::setupRelations( Incidence *incidence ) | 420 | void Calendar::setupRelations( Incidence *incidence ) |
402 | { | 421 | { |
403 | QString uid = incidence->uid(); | 422 | QString uid = incidence->uid(); |
404 | //qDebug("Calendar::setupRelations "); | 423 | //qDebug("Calendar::setupRelations "); |
405 | // First, go over the list of orphans and see if this is their parent | 424 | // First, go over the list of orphans and see if this is their parent |
406 | while( Incidence* i = mOrphans[ uid ] ) { | 425 | while( Incidence* i = mOrphans[ uid ] ) { |
407 | mOrphans.remove( uid ); | 426 | mOrphans.remove( uid ); |
408 | i->setRelatedTo( incidence ); | 427 | i->setRelatedTo( incidence ); |
409 | incidence->addRelation( i ); | 428 | incidence->addRelation( i ); |
410 | mOrphanUids.remove( i->uid() ); | 429 | mOrphanUids.remove( i->uid() ); |
411 | } | 430 | } |
412 | 431 | ||
413 | // Now see about this incidences parent | 432 | // Now see about this incidences parent |
414 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
415 | // This incidence has a uid it is related to, but is not registered to it yet | 434 | // This incidence has a uid it is related to, but is not registered to it yet |
416 | // Try to find it | 435 | // Try to find it |
417 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 436 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
418 | if( parent ) { | 437 | if( parent ) { |
419 | // Found it | 438 | // Found it |
420 | incidence->setRelatedTo( parent ); | 439 | incidence->setRelatedTo( parent ); |
421 | parent->addRelation( incidence ); | 440 | parent->addRelation( incidence ); |
422 | } else { | 441 | } else { |
423 | // Not found, put this in the mOrphans list | 442 | // Not found, put this in the mOrphans list |
424 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 443 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
425 | mOrphanUids.insert( incidence->uid(), incidence ); | 444 | mOrphanUids.insert( incidence->uid(), incidence ); |
426 | } | 445 | } |
427 | } | 446 | } |
428 | } | 447 | } |
429 | 448 | ||
430 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 449 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
431 | void Calendar::removeRelations( Incidence *incidence ) | 450 | void Calendar::removeRelations( Incidence *incidence ) |
432 | { | 451 | { |
433 | // qDebug("Calendar::removeRelations "); | 452 | // qDebug("Calendar::removeRelations "); |
434 | QString uid = incidence->uid(); | 453 | QString uid = incidence->uid(); |
435 | 454 | ||
436 | QPtrList<Incidence> relations = incidence->relations(); | 455 | QPtrList<Incidence> relations = incidence->relations(); |
437 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 456 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
438 | if( !mOrphanUids.find( i->uid() ) ) { | 457 | if( !mOrphanUids.find( i->uid() ) ) { |
439 | mOrphans.insert( uid, i ); | 458 | mOrphans.insert( uid, i ); |
440 | mOrphanUids.insert( i->uid(), i ); | 459 | mOrphanUids.insert( i->uid(), i ); |
441 | i->setRelatedTo( 0 ); | 460 | i->setRelatedTo( 0 ); |
442 | i->setRelatedToUid( uid ); | 461 | i->setRelatedToUid( uid ); |
443 | } | 462 | } |
444 | 463 | ||
445 | // If this incidence is related to something else, tell that about it | 464 | // If this incidence is related to something else, tell that about it |
446 | if( incidence->relatedTo() ) | 465 | if( incidence->relatedTo() ) |
447 | incidence->relatedTo()->removeRelation( incidence ); | 466 | incidence->relatedTo()->removeRelation( incidence ); |
448 | 467 | ||
449 | // Remove this one from the orphans list | 468 | // Remove this one from the orphans list |
450 | if( mOrphanUids.remove( uid ) ) | 469 | if( mOrphanUids.remove( uid ) ) { |
470 | QString r2uid = incidence->relatedToUid(); | ||
471 | QPtrList<Incidence> tempList; | ||
472 | while( Incidence* i = mOrphans[ r2uid ] ) { | ||
473 | mOrphans.remove( r2uid ); | ||
474 | if ( i != incidence ) tempList.append( i ); | ||
475 | } | ||
476 | Incidence* inc = tempList.first(); | ||
477 | while ( inc ) { | ||
478 | mOrphans.insert( r2uid, inc ); | ||
479 | inc = tempList.next(); | ||
480 | } | ||
481 | } | ||
482 | // LR: and another big bad bug found | ||
483 | #if 0 | ||
451 | // This incidence is located in the orphans list - it should be removed | 484 | // This incidence is located in the orphans list - it should be removed |
452 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 485 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
453 | // Removing wasn't that easy | 486 | // Removing wasn't that easy |
454 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 487 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
455 | if( it.current()->uid() == uid ) { | 488 | if( it.current()->uid() == uid ) { |
456 | mOrphans.remove( it.currentKey() ); | 489 | mOrphans.remove( it.currentKey() ); |
457 | break; | 490 | break; |
458 | } | 491 | } |
459 | } | 492 | } |
460 | } | 493 | } |
494 | #endif | ||
461 | } | 495 | } |
462 | 496 | ||
463 | void Calendar::registerObserver( Observer *observer ) | 497 | void Calendar::registerObserver( Observer *observer ) |
464 | { | 498 | { |
465 | mObserver = observer; | 499 | mObserver = observer; |
466 | mNewObserver = true; | 500 | mNewObserver = true; |
467 | } | 501 | } |
468 | 502 | ||
469 | void Calendar::setModified( bool modified ) | 503 | void Calendar::setModified( bool modified ) |
470 | { | 504 | { |
471 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 505 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
472 | if ( modified != mModified || mNewObserver ) { | 506 | if ( modified != mModified || mNewObserver ) { |
473 | mNewObserver = false; | 507 | mNewObserver = false; |
474 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 508 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
475 | mModified = modified; | 509 | mModified = modified; |
476 | } | 510 | } |
477 | } | 511 | } |
478 | 512 | ||
479 | void Calendar::setLoadedProductId( const QString &id ) | 513 | void Calendar::setLoadedProductId( const QString &id ) |
480 | { | 514 | { |
481 | mLoadedProductId = id; | 515 | mLoadedProductId = id; |
482 | } | 516 | } |
483 | 517 | ||
484 | QString Calendar::loadedProductId() | 518 | QString Calendar::loadedProductId() |
485 | { | 519 | { |
486 | return mLoadedProductId; | 520 | return mLoadedProductId; |
487 | } | 521 | } |
488 | 522 | ||
489 | //#include "calendar.moc" | 523 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 95477cd..3f6895d 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,379 +1,380 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | virtual void addCalendar( Calendar* ) = 0; | 77 | virtual void addCalendar( Calendar* ) = 0; |
78 | virtual bool addCalendarFile( QString name, int id ) = 0; | 78 | virtual bool addCalendarFile( QString name, int id ) = 0; |
79 | virtual bool mergeCalendarFile( QString name ) = 0; | 79 | virtual bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; | 80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; |
81 | virtual void setSyncEventsReadOnly() = 0; | 81 | virtual void setSyncEventsReadOnly() = 0; |
82 | virtual void stopAllTodos() = 0; | 82 | virtual void stopAllTodos() = 0; |
83 | virtual void clearUndo( Incidence * newUndo ); | ||
83 | 84 | ||
84 | /** | 85 | /** |
85 | Sync changes in memory to persistant storage. | 86 | Sync changes in memory to persistant storage. |
86 | */ | 87 | */ |
87 | virtual void save() = 0; | 88 | virtual void save() = 0; |
88 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 89 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
89 | virtual void removeSyncInfo( QString syncProfile) = 0; | 90 | virtual void removeSyncInfo( QString syncProfile) = 0; |
90 | virtual bool isSaving() { return false; } | 91 | virtual bool isSaving() { return false; } |
91 | 92 | ||
92 | /** | 93 | /** |
93 | Return the owner of the calendar's full name. | 94 | Return the owner of the calendar's full name. |
94 | */ | 95 | */ |
95 | const QString &getOwner() const; | 96 | const QString &getOwner() const; |
96 | /** | 97 | /** |
97 | Set the owner of the calendar. Should be owner's full name. | 98 | Set the owner of the calendar. Should be owner's full name. |
98 | */ | 99 | */ |
99 | void setOwner( const QString &os ); | 100 | void setOwner( const QString &os ); |
100 | /** | 101 | /** |
101 | Return the email address of the calendar owner. | 102 | Return the email address of the calendar owner. |
102 | */ | 103 | */ |
103 | const QString &getEmail(); | 104 | const QString &getEmail(); |
104 | /** | 105 | /** |
105 | Set the email address of the calendar owner. | 106 | Set the email address of the calendar owner. |
106 | */ | 107 | */ |
107 | void setEmail( const QString & ); | 108 | void setEmail( const QString & ); |
108 | 109 | ||
109 | /** | 110 | /** |
110 | Set time zone from a timezone string (e.g. -2:00) | 111 | Set time zone from a timezone string (e.g. -2:00) |
111 | */ | 112 | */ |
112 | void setTimeZone( const QString &tz ); | 113 | void setTimeZone( const QString &tz ); |
113 | /** | 114 | /** |
114 | Set time zone from a minutes value (e.g. -60) | 115 | Set time zone from a minutes value (e.g. -60) |
115 | */ | 116 | */ |
116 | void setTimeZone( int tz ); | 117 | void setTimeZone( int tz ); |
117 | /** | 118 | /** |
118 | Return time zone as offest in minutes. | 119 | Return time zone as offest in minutes. |
119 | */ | 120 | */ |
120 | int getTimeZone() const; | 121 | int getTimeZone() const; |
121 | /** | 122 | /** |
122 | Compute an ISO 8601 format string from the time zone. | 123 | Compute an ISO 8601 format string from the time zone. |
123 | */ | 124 | */ |
124 | QString getTimeZoneStr() const; | 125 | QString getTimeZoneStr() const; |
125 | /** | 126 | /** |
126 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 127 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
127 | values). | 128 | values). |
128 | */ | 129 | */ |
129 | void setTimeZoneId( const QString & ); | 130 | void setTimeZoneId( const QString & ); |
130 | /** | 131 | /** |
131 | Return time zone id. | 132 | Return time zone id. |
132 | */ | 133 | */ |
133 | QString timeZoneId() const; | 134 | QString timeZoneId() const; |
134 | /** | 135 | /** |
135 | Use local time, not UTC or a time zone. | 136 | Use local time, not UTC or a time zone. |
136 | */ | 137 | */ |
137 | void setLocalTime(); | 138 | void setLocalTime(); |
138 | /** | 139 | /** |
139 | Return whether local time is being used. | 140 | Return whether local time is being used. |
140 | */ | 141 | */ |
141 | bool isLocalTime() const; | 142 | bool isLocalTime() const; |
142 | 143 | ||
143 | /** | 144 | /** |
144 | Add an incidence to calendar. | 145 | Add an incidence to calendar. |
145 | 146 | ||
146 | @return true on success, false on error. | 147 | @return true on success, false on error. |
147 | */ | 148 | */ |
148 | virtual bool addIncidence( Incidence * ); | 149 | virtual bool addIncidence( Incidence * ); |
149 | 150 | ||
150 | // Adds an incidence and all relatedto incidences to the cal | 151 | // Adds an incidence and all relatedto incidences to the cal |
151 | void addIncidenceBranch( Incidence * ); | 152 | void addIncidenceBranch( Incidence * ); |
152 | /** | 153 | /** |
153 | Return filtered list of all incidences of this calendar. | 154 | Return filtered list of all incidences of this calendar. |
154 | */ | 155 | */ |
155 | virtual QPtrList<Incidence> incidences(); | 156 | virtual QPtrList<Incidence> incidences(); |
156 | 157 | ||
157 | /** | 158 | /** |
158 | Return unfiltered list of all incidences of this calendar. | 159 | Return unfiltered list of all incidences of this calendar. |
159 | */ | 160 | */ |
160 | virtual QPtrList<Incidence> rawIncidences(); | 161 | virtual QPtrList<Incidence> rawIncidences(); |
161 | 162 | ||
162 | /** | 163 | /** |
163 | Adds a Event to this calendar object. | 164 | Adds a Event to this calendar object. |
164 | @param anEvent a pointer to the event to add | 165 | @param anEvent a pointer to the event to add |
165 | 166 | ||
166 | @return true on success, false on error. | 167 | @return true on success, false on error. |
167 | */ | 168 | */ |
168 | virtual bool addEventNoDup( Event *event ) = 0; | 169 | virtual bool addEventNoDup( Event *event ) = 0; |
169 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 170 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
170 | virtual bool addEvent( Event *anEvent ) = 0; | 171 | virtual bool addEvent( Event *anEvent ) = 0; |
171 | /** | 172 | /** |
172 | Delete event from calendar. | 173 | Delete event from calendar. |
173 | */ | 174 | */ |
174 | virtual void deleteEvent( Event * ) = 0; | 175 | virtual void deleteEvent( Event * ) = 0; |
175 | /** | 176 | /** |
176 | Retrieves an event on the basis of the unique string ID. | 177 | Retrieves an event on the basis of the unique string ID. |
177 | */ | 178 | */ |
178 | virtual Event *event( const QString &UniqueStr ) = 0; | 179 | virtual Event *event( const QString &UniqueStr ) = 0; |
179 | virtual Event *event( QString, QString ) = 0; | 180 | virtual Event *event( QString, QString ) = 0; |
180 | /** | 181 | /** |
181 | Builds and then returns a list of all events that match for the | 182 | Builds and then returns a list of all events that match for the |
182 | date specified. useful for dayView, etc. etc. | 183 | date specified. useful for dayView, etc. etc. |
183 | The calendar filter is applied. | 184 | The calendar filter is applied. |
184 | */ | 185 | */ |
185 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 186 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
186 | /** | 187 | /** |
187 | Get events, which occur on the given date. | 188 | Get events, which occur on the given date. |
188 | The calendar filter is applied. | 189 | The calendar filter is applied. |
189 | */ | 190 | */ |
190 | QPtrList<Event> events( const QDateTime &qdt ); | 191 | QPtrList<Event> events( const QDateTime &qdt ); |
191 | /** | 192 | /** |
192 | Get events in a range of dates. If inclusive is set to true, only events | 193 | Get events in a range of dates. If inclusive is set to true, only events |
193 | are returned, which are completely included in the range. | 194 | are returned, which are completely included in the range. |
194 | The calendar filter is applied. | 195 | The calendar filter is applied. |
195 | */ | 196 | */ |
196 | QPtrList<Event> events( const QDate &start, const QDate &end, | 197 | QPtrList<Event> events( const QDate &start, const QDate &end, |
197 | bool inclusive = false); | 198 | bool inclusive = false); |
198 | /** | 199 | /** |
199 | Return filtered list of all events in calendar. | 200 | Return filtered list of all events in calendar. |
200 | */ | 201 | */ |
201 | virtual QPtrList<Event> events(); | 202 | virtual QPtrList<Event> events(); |
202 | /** | 203 | /** |
203 | Return unfiltered list of all events in calendar. | 204 | Return unfiltered list of all events in calendar. |
204 | */ | 205 | */ |
205 | virtual QPtrList<Event> rawEvents() = 0; | 206 | virtual QPtrList<Event> rawEvents() = 0; |
206 | 207 | ||
207 | /** | 208 | /** |
208 | Add a todo to the todolist. | 209 | Add a todo to the todolist. |
209 | 210 | ||
210 | @return true on success, false on error. | 211 | @return true on success, false on error. |
211 | */ | 212 | */ |
212 | virtual bool addTodo( Todo *todo ) = 0; | 213 | virtual bool addTodo( Todo *todo ) = 0; |
213 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 214 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
214 | /** | 215 | /** |
215 | Remove a todo from the todolist. | 216 | Remove a todo from the todolist. |
216 | */ | 217 | */ |
217 | virtual void deleteTodo( Todo * ) = 0; | 218 | virtual void deleteTodo( Todo * ) = 0; |
218 | virtual void deleteJournal( Journal * ) = 0; | 219 | virtual void deleteJournal( Journal * ) = 0; |
219 | /** | 220 | /** |
220 | Return filterd list of todos. | 221 | Return filterd list of todos. |
221 | */ | 222 | */ |
222 | virtual QPtrList<Todo> todos(); | 223 | virtual QPtrList<Todo> todos(); |
223 | /** | 224 | /** |
224 | Searches todolist for an event with this unique string identifier, | 225 | Searches todolist for an event with this unique string identifier, |
225 | returns a pointer or null. | 226 | returns a pointer or null. |
226 | */ | 227 | */ |
227 | virtual Todo *todo( const QString &uid ) = 0; | 228 | virtual Todo *todo( const QString &uid ) = 0; |
228 | virtual Todo *todo( QString, QString ) = 0; | 229 | virtual Todo *todo( QString, QString ) = 0; |
229 | /** | 230 | /** |
230 | Returns list of todos due on the specified date. | 231 | Returns list of todos due on the specified date. |
231 | */ | 232 | */ |
232 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 233 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
233 | /** | 234 | /** |
234 | Return unfiltered list of todos. | 235 | Return unfiltered list of todos. |
235 | */ | 236 | */ |
236 | virtual QPtrList<Todo> rawTodos() = 0; | 237 | virtual QPtrList<Todo> rawTodos() = 0; |
237 | 238 | ||
238 | /** | 239 | /** |
239 | Add a Journal entry to calendar. | 240 | Add a Journal entry to calendar. |
240 | 241 | ||
241 | @return true on success, false on error. | 242 | @return true on success, false on error. |
242 | */ | 243 | */ |
243 | virtual bool addJournal( Journal * ) = 0; | 244 | virtual bool addJournal( Journal * ) = 0; |
244 | /** | 245 | /** |
245 | Return Journal for given date. | 246 | Return Journal for given date. |
246 | */ | 247 | */ |
247 | virtual Journal *journal( const QDate & ) = 0; | 248 | virtual Journal *journal( const QDate & ) = 0; |
248 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; | 249 | virtual QPtrList<Journal> journals4Date( const QDate & ) = 0; |
249 | /** | 250 | /** |
250 | Return Journal with given UID. | 251 | Return Journal with given UID. |
251 | */ | 252 | */ |
252 | virtual Journal *journal( const QString &UID ) = 0; | 253 | virtual Journal *journal( const QString &UID ) = 0; |
253 | /** | 254 | /** |
254 | Return list of all Journal entries. | 255 | Return list of all Journal entries. |
255 | */ | 256 | */ |
256 | virtual QPtrList<Journal> journals() = 0; | 257 | virtual QPtrList<Journal> journals() = 0; |
257 | 258 | ||
258 | /** | 259 | /** |
259 | Searches all incidence types for an incidence with this unique | 260 | Searches all incidence types for an incidence with this unique |
260 | string identifier, returns a pointer or null. | 261 | string identifier, returns a pointer or null. |
261 | */ | 262 | */ |
262 | Incidence* incidence( const QString&UID ); | 263 | Incidence* incidence( const QString&UID ); |
263 | 264 | ||
264 | /** | 265 | /** |
265 | Setup relations for an incidence. | 266 | Setup relations for an incidence. |
266 | */ | 267 | */ |
267 | virtual void setupRelations( Incidence * ); | 268 | virtual void setupRelations( Incidence * ); |
268 | /** | 269 | /** |
269 | Remove all relations to an incidence | 270 | Remove all relations to an incidence |
270 | */ | 271 | */ |
271 | virtual void removeRelations( Incidence * ); | 272 | virtual void removeRelations( Incidence * ); |
272 | 273 | ||
273 | /** | 274 | /** |
274 | Set calendar filter, which filters events for the events() functions. | 275 | Set calendar filter, which filters events for the events() functions. |
275 | The Filter object is owned by the caller. | 276 | The Filter object is owned by the caller. |
276 | */ | 277 | */ |
277 | void setFilter( CalFilter * ); | 278 | void setFilter( CalFilter * ); |
278 | /** | 279 | /** |
279 | Return calendar filter. | 280 | Return calendar filter. |
280 | */ | 281 | */ |
281 | CalFilter *filter(); | 282 | CalFilter *filter(); |
282 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 283 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
283 | virtual QString nextSummary( ) const = 0; | 284 | virtual QString nextSummary( ) const = 0; |
284 | virtual void reInitAlarmSettings() = 0; | 285 | virtual void reInitAlarmSettings() = 0; |
285 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 286 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
286 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 287 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
287 | /** | 288 | /** |
288 | Return all alarms, which ocur in the given time interval. | 289 | Return all alarms, which ocur in the given time interval. |
289 | */ | 290 | */ |
290 | virtual Alarm::List alarms( const QDateTime &from, | 291 | virtual Alarm::List alarms( const QDateTime &from, |
291 | const QDateTime &to ) = 0; | 292 | const QDateTime &to ) = 0; |
292 | 293 | ||
293 | class Observer { | 294 | class Observer { |
294 | public: | 295 | public: |
295 | virtual void calendarModified( bool, Calendar * ) = 0; | 296 | virtual void calendarModified( bool, Calendar * ) = 0; |
296 | }; | 297 | }; |
297 | 298 | ||
298 | void registerObserver( Observer * ); | 299 | void registerObserver( Observer * ); |
299 | 300 | ||
300 | void setModified( bool ); | 301 | void setModified( bool ); |
301 | 302 | ||
302 | /** | 303 | /** |
303 | Set product id returned by loadedProductId(). This function is only | 304 | Set product id returned by loadedProductId(). This function is only |
304 | useful for the calendar loading code. | 305 | useful for the calendar loading code. |
305 | */ | 306 | */ |
306 | void setLoadedProductId( const QString & ); | 307 | void setLoadedProductId( const QString & ); |
307 | /** | 308 | /** |
308 | Return product id taken from file that has been loaded. Returns | 309 | Return product id taken from file that has been loaded. Returns |
309 | QString::null, if no calendar has been loaded. | 310 | QString::null, if no calendar has been loaded. |
310 | */ | 311 | */ |
311 | QString loadedProductId(); | 312 | QString loadedProductId(); |
312 | int defaultCalendar(); | 313 | int defaultCalendar(); |
313 | void setDontDeleteIncidencesOnClose (); | 314 | void setDontDeleteIncidencesOnClose (); |
314 | public slots: | 315 | public slots: |
315 | void setDefaultCalendar( int ); | 316 | void setDefaultCalendar( int ); |
316 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | 317 | virtual void setCalendarEnabled( int id, bool enable ) = 0; |
317 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | 318 | virtual void setAlarmEnabled( int id, bool enable ) = 0; |
318 | virtual void setReadOnly( int id, bool enable ) = 0; | 319 | virtual void setReadOnly( int id, bool enable ) = 0; |
319 | virtual void setDefaultCalendarEnabledOnly() = 0; | 320 | virtual void setDefaultCalendarEnabledOnly() = 0; |
320 | virtual void setCalendarRemove( int id ) = 0; | 321 | virtual void setCalendarRemove( int id ) = 0; |
321 | signals: | 322 | signals: |
322 | void calendarChanged(); | 323 | void calendarChanged(); |
323 | void calendarSaved(); | 324 | void calendarSaved(); |
324 | void calendarLoaded(); | 325 | void calendarLoaded(); |
325 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 326 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
326 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 327 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
327 | 328 | ||
328 | protected: | 329 | protected: |
329 | /** | 330 | /** |
330 | Get unfiltered events, which occur on the given date. | 331 | Get unfiltered events, which occur on the given date. |
331 | */ | 332 | */ |
332 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 333 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
333 | /** | 334 | /** |
334 | Get unfiltered events, which occur on the given date. | 335 | Get unfiltered events, which occur on the given date. |
335 | */ | 336 | */ |
336 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 337 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
337 | bool sorted = false ) = 0; | 338 | bool sorted = false ) = 0; |
338 | /** | 339 | /** |
339 | Get events in a range of dates. If inclusive is set to true, only events | 340 | Get events in a range of dates. If inclusive is set to true, only events |
340 | are returned, which are completely included in the range. | 341 | are returned, which are completely included in the range. |
341 | */ | 342 | */ |
342 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 343 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
343 | bool inclusive = false ) = 0; | 344 | bool inclusive = false ) = 0; |
344 | 345 | ||
345 | Incidence *mNextAlarmIncidence; | 346 | Incidence *mNextAlarmIncidence; |
346 | Incidence *mUndoIncidence; | 347 | Incidence *mUndoIncidence; |
347 | int mDefaultCalendar; | 348 | int mDefaultCalendar; |
348 | bool mDeleteIncidencesOnClose; | 349 | bool mDeleteIncidencesOnClose; |
349 | 350 | ||
350 | private: | 351 | private: |
351 | void init(); | 352 | void init(); |
352 | 353 | ||
353 | QString mOwner; // who the calendar belongs to | 354 | QString mOwner; // who the calendar belongs to |
354 | QString mOwnerEmail; // email address of the owner | 355 | QString mOwnerEmail; // email address of the owner |
355 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 356 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
356 | bool mLocalTime; // use local time, not UTC or a time zone | 357 | bool mLocalTime; // use local time, not UTC or a time zone |
357 | 358 | ||
358 | 359 | ||
359 | CalFilter *mFilter; | 360 | CalFilter *mFilter; |
360 | CalFilter *mDefaultFilter; | 361 | CalFilter *mDefaultFilter; |
361 | 362 | ||
362 | 363 | ||
363 | QString mTimeZoneId; | 364 | QString mTimeZoneId; |
364 | 365 | ||
365 | Observer *mObserver; | 366 | Observer *mObserver; |
366 | bool mNewObserver; | 367 | bool mNewObserver; |
367 | 368 | ||
368 | bool mModified; | 369 | bool mModified; |
369 | 370 | ||
370 | QString mLoadedProductId; | 371 | QString mLoadedProductId; |
371 | 372 | ||
372 | // This list is used to put together related todos | 373 | // This list is used to put together related todos |
373 | QDict<Incidence> mOrphans; | 374 | QDict<Incidence> mOrphans; |
374 | QDict<Incidence> mOrphanUids; | 375 | QDict<Incidence> mOrphanUids; |
375 | }; | 376 | }; |
376 | 377 | ||
377 | } | 378 | } |
378 | 379 | ||
379 | #endif | 380 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index e8c969f..1a1c6be 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,1036 +1,1020 @@ | |||
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) |
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::setSyncEventsReadOnly() | 176 | void CalendarLocal::setSyncEventsReadOnly() |
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->setReadOnly( true ); | 182 | ev->setReadOnly( true ); |
183 | ev = mEventList.next(); | 183 | ev = mEventList.next(); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | void CalendarLocal::addCalendar( Calendar* cal ) | 186 | void CalendarLocal::addCalendar( Calendar* cal ) |
187 | { | 187 | { |
188 | cal->setDontDeleteIncidencesOnClose(); | 188 | cal->setDontDeleteIncidencesOnClose(); |
189 | { | 189 | { |
190 | QPtrList<Event> EventList = cal->rawEvents(); | 190 | QPtrList<Event> EventList = cal->rawEvents(); |
191 | Event * ev = EventList.first(); | 191 | Event * ev = EventList.first(); |
192 | while ( ev ) { | 192 | while ( ev ) { |
193 | ev->unRegisterObserver( cal ); | 193 | ev->unRegisterObserver( cal ); |
194 | ev->registerObserver( this ); | 194 | ev->registerObserver( this ); |
195 | mEventList.append( ev ); | 195 | mEventList.append( ev ); |
196 | ev = EventList.next(); | 196 | ev = EventList.next(); |
197 | } | 197 | } |
198 | } | 198 | } |
199 | { | 199 | { |
200 | 200 | ||
201 | QPtrList<Todo> TodoList = cal->rawTodos(); | 201 | QPtrList<Todo> TodoList = cal->rawTodos(); |
202 | Todo * ev = TodoList.first(); | 202 | Todo * ev = TodoList.first(); |
203 | while ( ev ) { | 203 | while ( ev ) { |
204 | QString rel = ev->relatedToUid(); | 204 | QString rel = ev->relatedToUid(); |
205 | if ( !rel.isEmpty() ){ | 205 | if ( !rel.isEmpty() ){ |
206 | ev->setRelatedTo ( 0 ); | 206 | ev->setRelatedTo ( 0 ); |
207 | ev->setRelatedToUid( rel ); | 207 | ev->setRelatedToUid( rel ); |
208 | } | 208 | } |
209 | ev = TodoList.next(); | 209 | ev = TodoList.next(); |
210 | } | 210 | } |
211 | //TodoList = cal->rawTodos(); | 211 | //TodoList = cal->rawTodos(); |
212 | ev = TodoList.first(); | 212 | ev = TodoList.first(); |
213 | while ( ev ) { | 213 | while ( ev ) { |
214 | ev->unRegisterObserver( cal ); | 214 | ev->unRegisterObserver( cal ); |
215 | ev->registerObserver( this ); | 215 | ev->registerObserver( this ); |
216 | mTodoList.append( ev ); | 216 | mTodoList.append( ev ); |
217 | setupRelations( ev ); | 217 | setupRelations( ev ); |
218 | ev = TodoList.next(); | 218 | ev = TodoList.next(); |
219 | } | 219 | } |
220 | } | 220 | } |
221 | { | 221 | { |
222 | QPtrList<Journal> JournalList = cal->journals(); | 222 | QPtrList<Journal> JournalList = cal->journals(); |
223 | Journal * ev = JournalList.first(); | 223 | Journal * ev = JournalList.first(); |
224 | while ( ev ) { | 224 | while ( ev ) { |
225 | ev->unRegisterObserver( cal ); | 225 | ev->unRegisterObserver( cal ); |
226 | ev->registerObserver( this ); | 226 | ev->registerObserver( this ); |
227 | mJournalList.append( ev ); | 227 | mJournalList.append( ev ); |
228 | ev = JournalList.next(); | 228 | ev = JournalList.next(); |
229 | } | 229 | } |
230 | } | 230 | } |
231 | setModified( true ); | 231 | setModified( true ); |
232 | } | 232 | } |
233 | bool CalendarLocal::load( const QString &fileName ) | 233 | bool CalendarLocal::load( const QString &fileName ) |
234 | { | 234 | { |
235 | FileStorage storage( this, fileName ); | 235 | FileStorage storage( this, fileName ); |
236 | return storage.load(); | 236 | return storage.load(); |
237 | } | 237 | } |
238 | 238 | ||
239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
240 | { | 240 | { |
241 | FileStorage storage( this, fileName, format ); | 241 | FileStorage storage( this, fileName, format ); |
242 | return storage.save(); | 242 | return storage.save(); |
243 | } | 243 | } |
244 | 244 | ||
245 | void CalendarLocal::stopAllTodos() | 245 | void CalendarLocal::stopAllTodos() |
246 | { | 246 | { |
247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
248 | it->setRunning( false ); | 248 | it->setRunning( false ); |
249 | 249 | ||
250 | } | 250 | } |
251 | void CalendarLocal::close() | 251 | void CalendarLocal::close() |
252 | { | 252 | { |
253 | 253 | ||
254 | Todo * i; | 254 | Todo * i; |
255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
256 | 256 | ||
257 | mEventList.setAutoDelete( true ); | 257 | mEventList.setAutoDelete( true ); |
258 | mTodoList.setAutoDelete( true ); | 258 | mTodoList.setAutoDelete( true ); |
259 | mJournalList.setAutoDelete( true ); | 259 | mJournalList.setAutoDelete( true ); |
260 | 260 | ||
261 | mEventList.clear(); | 261 | mEventList.clear(); |
262 | mTodoList.clear(); | 262 | mTodoList.clear(); |
263 | mJournalList.clear(); | 263 | mJournalList.clear(); |
264 | 264 | ||
265 | mEventList.setAutoDelete( false ); | 265 | mEventList.setAutoDelete( false ); |
266 | mTodoList.setAutoDelete( false ); | 266 | mTodoList.setAutoDelete( false ); |
267 | mJournalList.setAutoDelete( false ); | 267 | mJournalList.setAutoDelete( false ); |
268 | 268 | ||
269 | setModified( false ); | 269 | setModified( false ); |
270 | } | 270 | } |
271 | void CalendarLocal::clearUndo() | 271 | |
272 | { | ||
273 | if ( mUndoIncidence ) { | ||
274 | if ( mUndoIncidence->typeID() == eventID ) | ||
275 | delete ((Event*) mUndoIncidence) ; | ||
276 | else if ( mUndoIncidence->typeID() == todoID ) | ||
277 | delete ( (Todo*) mUndoIncidence ); | ||
278 | else if ( mUndoIncidence->typeID() == journalID ) | ||
279 | delete ( (Journal*) mUndoIncidence ); | ||
280 | else | ||
281 | delete mUndoIncidence; | ||
282 | } | ||
283 | mUndoIncidence = 0; | ||
284 | } | ||
285 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
286 | { | 273 | { |
287 | QString cat; | 274 | QString cat; |
288 | bool isBirthday = true; | 275 | bool isBirthday = true; |
289 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
290 | isBirthday = false; | 277 | isBirthday = false; |
291 | cat = i18n( "Anniversary" ); | 278 | cat = i18n( "Anniversary" ); |
292 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 279 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
293 | isBirthday = true; | 280 | isBirthday = true; |
294 | cat = i18n( "Birthday" ); | 281 | cat = i18n( "Birthday" ); |
295 | } else { | 282 | } else { |
296 | qDebug("addAnniversaryNoDup called without fitting category! "); | 283 | qDebug("addAnniversaryNoDup called without fitting category! "); |
297 | return false; | 284 | return false; |
298 | } | 285 | } |
299 | Event * eve; | 286 | Event * eve; |
300 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 287 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
301 | if ( !(eve->categories().contains( cat ) )) | 288 | if ( !(eve->categories().contains( cat ) )) |
302 | continue; | 289 | continue; |
303 | // now we have an event with fitting category | 290 | // now we have an event with fitting category |
304 | if ( eve->dtStart().date() != event->dtStart().date() ) | 291 | if ( eve->dtStart().date() != event->dtStart().date() ) |
305 | continue; | 292 | continue; |
306 | // now we have an event with fitting category+date | 293 | // now we have an event with fitting category+date |
307 | if ( eve->summary() != event->summary() ) | 294 | if ( eve->summary() != event->summary() ) |
308 | continue; | 295 | continue; |
309 | // now we have an event with fitting category+date+summary | 296 | // now we have an event with fitting category+date+summary |
310 | return false; | 297 | return false; |
311 | } | 298 | } |
312 | return addEvent( event ); | 299 | return addEvent( event ); |
313 | 300 | ||
314 | } | 301 | } |
315 | bool CalendarLocal::addEventNoDup( Event *event ) | 302 | bool CalendarLocal::addEventNoDup( Event *event ) |
316 | { | 303 | { |
317 | Event * eve; | 304 | Event * eve; |
318 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 305 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
319 | if ( *eve == *event ) { | 306 | if ( *eve == *event ) { |
320 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 307 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
321 | return false; | 308 | return false; |
322 | } | 309 | } |
323 | } | 310 | } |
324 | return addEvent( event ); | 311 | return addEvent( event ); |
325 | } | 312 | } |
326 | 313 | ||
327 | bool CalendarLocal::addEvent( Event *event ) | 314 | bool CalendarLocal::addEvent( Event *event ) |
328 | { | 315 | { |
329 | insertEvent( event ); | 316 | insertEvent( event ); |
330 | 317 | ||
331 | event->registerObserver( this ); | 318 | event->registerObserver( this ); |
332 | 319 | ||
333 | setModified( true ); | 320 | setModified( true ); |
334 | if ( event->calID() == 0 ) | 321 | if ( event->calID() == 0 ) |
335 | event->setCalID( mDefaultCalendar ); | 322 | event->setCalID( mDefaultCalendar ); |
336 | event->setCalEnabled( true ); | 323 | event->setCalEnabled( true ); |
337 | 324 | ||
338 | return true; | 325 | return true; |
339 | } | 326 | } |
340 | 327 | ||
341 | void CalendarLocal::deleteEvent( Event *event ) | 328 | void CalendarLocal::deleteEvent( Event *event ) |
342 | { | 329 | { |
343 | clearUndo(); | 330 | clearUndo(event); |
344 | mUndoIncidence = event; | ||
345 | if ( mEventList.removeRef( event ) ) { | 331 | if ( mEventList.removeRef( event ) ) { |
346 | setModified( true ); | 332 | setModified( true ); |
347 | } | 333 | } |
348 | } | 334 | } |
349 | 335 | ||
350 | 336 | ||
351 | Event *CalendarLocal::event( const QString &uid ) | 337 | Event *CalendarLocal::event( const QString &uid ) |
352 | { | 338 | { |
353 | Event *event; | 339 | Event *event; |
354 | Event *retVal = 0; | 340 | Event *retVal = 0; |
355 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 341 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
356 | if ( event->calEnabled() && event->uid() == uid ) { | 342 | if ( event->calEnabled() && event->uid() == uid ) { |
357 | if ( retVal ) { | 343 | if ( retVal ) { |
358 | if ( retVal->calID() > event->calID() ) { | 344 | if ( retVal->calID() > event->calID() ) { |
359 | retVal = event; | 345 | retVal = event; |
360 | } | 346 | } |
361 | } else { | 347 | } else { |
362 | retVal = event; | 348 | retVal = event; |
363 | } | 349 | } |
364 | } | 350 | } |
365 | } | 351 | } |
366 | return retVal; | 352 | return retVal; |
367 | } | 353 | } |
368 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 354 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
369 | { | 355 | { |
370 | Todo * eve; | 356 | Todo * eve; |
371 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 357 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
372 | if ( *eve == *todo ) { | 358 | if ( *eve == *todo ) { |
373 | //qDebug("duplicate todo found! not inserted! "); | 359 | //qDebug("duplicate todo found! not inserted! "); |
374 | return false; | 360 | return false; |
375 | } | 361 | } |
376 | } | 362 | } |
377 | return addTodo( todo ); | 363 | return addTodo( todo ); |
378 | } | 364 | } |
379 | bool CalendarLocal::addTodo( Todo *todo ) | 365 | bool CalendarLocal::addTodo( Todo *todo ) |
380 | { | 366 | { |
381 | mTodoList.append( todo ); | 367 | mTodoList.append( todo ); |
382 | 368 | ||
383 | todo->registerObserver( this ); | 369 | todo->registerObserver( this ); |
384 | 370 | ||
385 | // Set up subtask relations | 371 | // Set up subtask relations |
386 | setupRelations( todo ); | 372 | setupRelations( todo ); |
387 | 373 | ||
388 | setModified( true ); | 374 | setModified( true ); |
389 | if ( todo->calID() == 0 ) | 375 | if ( todo->calID() == 0 ) |
390 | todo->setCalID( mDefaultCalendar ); | 376 | todo->setCalID( mDefaultCalendar ); |
391 | todo->setCalEnabled( true ); | 377 | todo->setCalEnabled( true ); |
392 | return true; | 378 | return true; |
393 | } | 379 | } |
394 | 380 | ||
395 | void CalendarLocal::deleteTodo( Todo *todo ) | 381 | void CalendarLocal::deleteTodo( Todo *todo ) |
396 | { | 382 | { |
397 | // Handle orphaned children | 383 | // Handle orphaned children |
398 | clearUndo(); | ||
399 | removeRelations( todo ); | 384 | removeRelations( todo ); |
400 | mUndoIncidence = todo; | 385 | clearUndo(todo); |
401 | 386 | ||
402 | if ( mTodoList.removeRef( todo ) ) { | 387 | if ( mTodoList.removeRef( todo ) ) { |
403 | setModified( true ); | 388 | setModified( true ); |
404 | } | 389 | } |
405 | } | 390 | } |
406 | 391 | ||
407 | QPtrList<Todo> CalendarLocal::rawTodos() | 392 | QPtrList<Todo> CalendarLocal::rawTodos() |
408 | { | 393 | { |
409 | QPtrList<Todo> el; | 394 | QPtrList<Todo> el; |
410 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 395 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
411 | if ( it->calEnabled() ) el.append( it ); | 396 | if ( it->calEnabled() ) el.append( it ); |
412 | return el; | 397 | return el; |
413 | } | 398 | } |
414 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 399 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
415 | { | 400 | { |
416 | Todo *todo; | 401 | Todo *todo; |
417 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 402 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
418 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 403 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
419 | } | 404 | } |
420 | 405 | ||
421 | return 0; | 406 | return 0; |
422 | } | 407 | } |
423 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 408 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
424 | { | 409 | { |
425 | QPtrList<Incidence> all = rawIncidences() ; | 410 | QPtrList<Incidence> all = rawIncidences() ; |
426 | Incidence *inc; | 411 | Incidence *inc; |
427 | for ( inc = all.first(); inc; inc = all.next() ) { | 412 | for ( inc = all.first(); inc; inc = all.next() ) { |
428 | inc->removeID( syncProfile ); | 413 | inc->removeID( syncProfile ); |
429 | } | 414 | } |
430 | if ( syncProfile.isEmpty() ) { | 415 | if ( syncProfile.isEmpty() ) { |
431 | QPtrList<Event> el; | 416 | QPtrList<Event> el; |
432 | Event *todo; | 417 | Event *todo; |
433 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 418 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
434 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 419 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
435 | el.append( todo ); | 420 | el.append( todo ); |
436 | } | 421 | } |
437 | for ( todo = el.first(); todo; todo = el.next() ) { | 422 | for ( todo = el.first(); todo; todo = el.next() ) { |
438 | deleteIncidence ( todo ); | 423 | deleteIncidence ( todo ); |
439 | } | 424 | } |
440 | } else { | 425 | } else { |
441 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 426 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
442 | if ( lse ) | 427 | if ( lse ) |
443 | deleteIncidence ( lse ); | 428 | deleteIncidence ( lse ); |
444 | } | 429 | } |
445 | } | 430 | } |
446 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 431 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
447 | { | 432 | { |
448 | QPtrList<Event> el; | 433 | QPtrList<Event> el; |
449 | Event *todo; | 434 | Event *todo; |
450 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 435 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
451 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 436 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
452 | if ( todo->summary().left(3) == "E: " ) | 437 | if ( todo->summary().left(3) == "E: " ) |
453 | el.append( todo ); | 438 | el.append( todo ); |
454 | } | 439 | } |
455 | 440 | ||
456 | return el; | 441 | return el; |
457 | 442 | ||
458 | } | 443 | } |
459 | Event *CalendarLocal::event( QString syncProf, QString id ) | 444 | Event *CalendarLocal::event( QString syncProf, QString id ) |
460 | { | 445 | { |
461 | Event *todo; | 446 | Event *todo; |
462 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 447 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
463 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; | 448 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
464 | } | 449 | } |
465 | 450 | ||
466 | return 0; | 451 | return 0; |
467 | } | 452 | } |
468 | Todo *CalendarLocal::todo( const QString &uid ) | 453 | Todo *CalendarLocal::todo( const QString &uid ) |
469 | { | 454 | { |
470 | Todo *todo;; | 455 | Todo *todo;; |
471 | Todo *retVal = 0; | 456 | Todo *retVal = 0; |
472 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 457 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
473 | if ( todo->calEnabled() && todo->uid() == uid ) { | 458 | if ( todo->calEnabled() && todo->uid() == uid ) { |
474 | if ( retVal ) { | 459 | if ( retVal ) { |
475 | if ( retVal->calID() > todo->calID() ) { | 460 | if ( retVal->calID() > todo->calID() ) { |
476 | retVal = todo; | 461 | retVal = todo; |
477 | } | 462 | } |
478 | } else { | 463 | } else { |
479 | retVal = todo; | 464 | retVal = todo; |
480 | } | 465 | } |
481 | } | 466 | } |
482 | } | 467 | } |
483 | return retVal; | 468 | return retVal; |
484 | } | 469 | } |
485 | QString CalendarLocal::nextSummary() const | 470 | QString CalendarLocal::nextSummary() const |
486 | { | 471 | { |
487 | return mNextSummary; | 472 | return mNextSummary; |
488 | } | 473 | } |
489 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 474 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
490 | { | 475 | { |
491 | return mNextAlarmEventDateTime; | 476 | return mNextAlarmEventDateTime; |
492 | } | 477 | } |
493 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 478 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
494 | { | 479 | { |
495 | //mNextAlarmIncidence | 480 | //mNextAlarmIncidence |
496 | //mNextAlarmDateTime | 481 | //mNextAlarmDateTime |
497 | //return mNextSummary; | 482 | //return mNextSummary; |
498 | //return mNextAlarmEventDateTime; | 483 | //return mNextAlarmEventDateTime; |
499 | bool newNextAlarm = false; | 484 | bool newNextAlarm = false; |
500 | bool computeNextAlarm = false; | 485 | bool computeNextAlarm = false; |
501 | bool ok; | 486 | bool ok; |
502 | int offset; | 487 | int offset; |
503 | QDateTime nextA; | 488 | QDateTime nextA; |
504 | // QString nextSum; | 489 | // QString nextSum; |
505 | //QDateTime nextEvent; | 490 | //QDateTime nextEvent; |
506 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 491 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
507 | computeNextAlarm = true; | 492 | computeNextAlarm = true; |
508 | } else { | 493 | } else { |
509 | if ( ! deleted ) { | 494 | if ( ! deleted ) { |
510 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 495 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
511 | if ( ok ) { | 496 | if ( ok ) { |
512 | if ( nextA < mNextAlarmDateTime ) { | 497 | if ( nextA < mNextAlarmDateTime ) { |
513 | deRegisterAlarm(); | 498 | deRegisterAlarm(); |
514 | mNextAlarmDateTime = nextA; | 499 | mNextAlarmDateTime = nextA; |
515 | mNextSummary = incidence->summary(); | 500 | mNextSummary = incidence->summary(); |
516 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 501 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
517 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 502 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
518 | newNextAlarm = true; | 503 | newNextAlarm = true; |
519 | mNextAlarmIncidence = incidence; | 504 | mNextAlarmIncidence = incidence; |
520 | } else { | 505 | } else { |
521 | if ( incidence == mNextAlarmIncidence ) { | 506 | if ( incidence == mNextAlarmIncidence ) { |
522 | computeNextAlarm = true; | 507 | computeNextAlarm = true; |
523 | } | 508 | } |
524 | } | 509 | } |
525 | } else { | 510 | } else { |
526 | if ( mNextAlarmIncidence == incidence ) { | 511 | if ( mNextAlarmIncidence == incidence ) { |
527 | computeNextAlarm = true; | 512 | computeNextAlarm = true; |
528 | } | 513 | } |
529 | } | 514 | } |
530 | } else { // deleted | 515 | } else { // deleted |
531 | if ( incidence == mNextAlarmIncidence ) { | 516 | if ( incidence == mNextAlarmIncidence ) { |
532 | computeNextAlarm = true; | 517 | computeNextAlarm = true; |
533 | } | 518 | } |
534 | } | 519 | } |
535 | } | 520 | } |
536 | if ( computeNextAlarm ) { | 521 | if ( computeNextAlarm ) { |
537 | deRegisterAlarm(); | 522 | deRegisterAlarm(); |
538 | nextA = nextAlarm( 1000 ); | 523 | nextA = nextAlarm( 1000 ); |
539 | if (! mNextAlarmIncidence ) { | 524 | if (! mNextAlarmIncidence ) { |
540 | return; | 525 | return; |
541 | } | 526 | } |
542 | newNextAlarm = true; | 527 | newNextAlarm = true; |
543 | } | 528 | } |
544 | if ( newNextAlarm ) | 529 | if ( newNextAlarm ) |
545 | registerAlarm(); | 530 | registerAlarm(); |
546 | } | 531 | } |
547 | QString CalendarLocal:: getAlarmNotification() | 532 | QString CalendarLocal:: getAlarmNotification() |
548 | { | 533 | { |
549 | QString ret; | 534 | QString ret; |
550 | // this should not happen | 535 | // this should not happen |
551 | if (! mNextAlarmIncidence ) | 536 | if (! mNextAlarmIncidence ) |
552 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 537 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
553 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 538 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
554 | if ( alarm->type() == Alarm::Procedure ) { | 539 | if ( alarm->type() == Alarm::Procedure ) { |
555 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 540 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
556 | } else { | 541 | } else { |
557 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 542 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
558 | } | 543 | } |
559 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 544 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
560 | if ( mNextSummary.length() > 25 ) | 545 | if ( mNextSummary.length() > 25 ) |
561 | ret += "\n" + mNextSummary.mid(25, 25 ); | 546 | ret += "\n" + mNextSummary.mid(25, 25 ); |
562 | ret+= "\n"+mNextAlarmEventDateTimeString; | 547 | ret+= "\n"+mNextAlarmEventDateTimeString; |
563 | return ret; | 548 | return ret; |
564 | } | 549 | } |
565 | void CalendarLocal::registerAlarm() | 550 | void CalendarLocal::registerAlarm() |
566 | { | 551 | { |
567 | mLastAlarmNotificationString = getAlarmNotification(); | 552 | mLastAlarmNotificationString = getAlarmNotification(); |
568 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 553 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
569 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 554 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
570 | // #ifndef DESKTOP_VERSION | 555 | // #ifndef DESKTOP_VERSION |
571 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 556 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
572 | // #endif | 557 | // #endif |
573 | } | 558 | } |
574 | void CalendarLocal::deRegisterAlarm() | 559 | void CalendarLocal::deRegisterAlarm() |
575 | { | 560 | { |
576 | if ( mLastAlarmNotificationString.isNull() ) | 561 | if ( mLastAlarmNotificationString.isNull() ) |
577 | return; | 562 | return; |
578 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 563 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
579 | 564 | ||
580 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 565 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
581 | mNextAlarmEventDateTime = QDateTime(); | 566 | mNextAlarmEventDateTime = QDateTime(); |
582 | // #ifndef DESKTOP_VERSION | 567 | // #ifndef DESKTOP_VERSION |
583 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 568 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
584 | // #endif | 569 | // #endif |
585 | } | 570 | } |
586 | 571 | ||
587 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 572 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
588 | { | 573 | { |
589 | QPtrList<Todo> todos; | 574 | QPtrList<Todo> todos; |
590 | 575 | ||
591 | Todo *todo; | 576 | Todo *todo; |
592 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 577 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
593 | if ( !todo->calEnabled() ) continue; | 578 | if ( !todo->calEnabled() ) continue; |
594 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 579 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
595 | todos.append( todo ); | 580 | todos.append( todo ); |
596 | } | 581 | } |
597 | } | 582 | } |
598 | 583 | ||
599 | filter()->apply( &todos ); | 584 | filter()->apply( &todos ); |
600 | return todos; | 585 | return todos; |
601 | } | 586 | } |
602 | void CalendarLocal::reInitAlarmSettings() | 587 | void CalendarLocal::reInitAlarmSettings() |
603 | { | 588 | { |
604 | if ( !mNextAlarmIncidence ) { | 589 | if ( !mNextAlarmIncidence ) { |
605 | nextAlarm( 1000 ); | 590 | nextAlarm( 1000 ); |
606 | } | 591 | } |
607 | deRegisterAlarm(); | 592 | deRegisterAlarm(); |
608 | mNextAlarmIncidence = 0; | 593 | mNextAlarmIncidence = 0; |
609 | checkAlarmForIncidence( 0, false ); | 594 | checkAlarmForIncidence( 0, false ); |
610 | 595 | ||
611 | } | 596 | } |
612 | 597 | ||
613 | 598 | ||
614 | 599 | ||
615 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 600 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
616 | { | 601 | { |
617 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 602 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
618 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 603 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
619 | QDateTime next; | 604 | QDateTime next; |
620 | Event *e; | 605 | Event *e; |
621 | bool ok; | 606 | bool ok; |
622 | bool found = false; | 607 | bool found = false; |
623 | int offset; | 608 | int offset; |
624 | mNextAlarmIncidence = 0; | 609 | mNextAlarmIncidence = 0; |
625 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 610 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
626 | if ( !e->calEnabled() ) continue; | 611 | if ( !e->calEnabled() ) continue; |
627 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 612 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
628 | if ( ok ) { | 613 | if ( ok ) { |
629 | if ( next < nextA ) { | 614 | if ( next < nextA ) { |
630 | nextA = next; | 615 | nextA = next; |
631 | found = true; | 616 | found = true; |
632 | mNextSummary = e->summary(); | 617 | mNextSummary = e->summary(); |
633 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 618 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
634 | mNextAlarmIncidence = (Incidence *) e; | 619 | mNextAlarmIncidence = (Incidence *) e; |
635 | } | 620 | } |
636 | } | 621 | } |
637 | } | 622 | } |
638 | Todo *t; | 623 | Todo *t; |
639 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 624 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
640 | if ( !t->calEnabled() ) continue; | 625 | if ( !t->calEnabled() ) continue; |
641 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 626 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
642 | if ( ok ) { | 627 | if ( ok ) { |
643 | if ( next < nextA ) { | 628 | if ( next < nextA ) { |
644 | nextA = next; | 629 | nextA = next; |
645 | found = true; | 630 | found = true; |
646 | mNextSummary = t->summary(); | 631 | mNextSummary = t->summary(); |
647 | mNextAlarmEventDateTime = next.addSecs(offset ); | 632 | mNextAlarmEventDateTime = next.addSecs(offset ); |
648 | mNextAlarmIncidence = (Incidence *) t; | 633 | mNextAlarmIncidence = (Incidence *) t; |
649 | } | 634 | } |
650 | } | 635 | } |
651 | } | 636 | } |
652 | if ( mNextAlarmIncidence ) { | 637 | if ( mNextAlarmIncidence ) { |
653 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 638 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
654 | mNextAlarmDateTime = nextA; | 639 | mNextAlarmDateTime = nextA; |
655 | } | 640 | } |
656 | return nextA; | 641 | return nextA; |
657 | } | 642 | } |
658 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 643 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
659 | { | 644 | { |
660 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 645 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
661 | } | 646 | } |
662 | 647 | ||
663 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 648 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
664 | { | 649 | { |
665 | 650 | ||
666 | Alarm::List alarms; | 651 | Alarm::List alarms; |
667 | 652 | ||
668 | Event *e; | 653 | Event *e; |
669 | 654 | ||
670 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 655 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
671 | if ( !e->calEnabled() ) continue; | 656 | if ( !e->calEnabled() ) continue; |
672 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 657 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
673 | else appendAlarms( alarms, e, from, to ); | 658 | else appendAlarms( alarms, e, from, to ); |
674 | } | 659 | } |
675 | 660 | ||
676 | Todo *t; | 661 | Todo *t; |
677 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 662 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
678 | if ( !t->calEnabled() ) continue; | 663 | if ( !t->calEnabled() ) continue; |
679 | appendAlarms( alarms, t, from, to ); | 664 | appendAlarms( alarms, t, from, to ); |
680 | } | 665 | } |
681 | 666 | ||
682 | return alarms; | 667 | return alarms; |
683 | } | 668 | } |
684 | 669 | ||
685 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 670 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
686 | const QDateTime &from, const QDateTime &to ) | 671 | const QDateTime &from, const QDateTime &to ) |
687 | { | 672 | { |
688 | QPtrList<Alarm> alarmList = incidence->alarms(); | 673 | QPtrList<Alarm> alarmList = incidence->alarms(); |
689 | Alarm *alarm; | 674 | Alarm *alarm; |
690 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 675 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
691 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 676 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
692 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 677 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
693 | if ( alarm->enabled() ) { | 678 | if ( alarm->enabled() ) { |
694 | if ( alarm->time() >= from && alarm->time() <= to ) { | 679 | if ( alarm->time() >= from && alarm->time() <= to ) { |
695 | alarms.append( alarm ); | 680 | alarms.append( alarm ); |
696 | } | 681 | } |
697 | } | 682 | } |
698 | } | 683 | } |
699 | } | 684 | } |
700 | 685 | ||
701 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 686 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
702 | Incidence *incidence, | 687 | Incidence *incidence, |
703 | const QDateTime &from, | 688 | const QDateTime &from, |
704 | const QDateTime &to ) | 689 | const QDateTime &to ) |
705 | { | 690 | { |
706 | 691 | ||
707 | QPtrList<Alarm> alarmList = incidence->alarms(); | 692 | QPtrList<Alarm> alarmList = incidence->alarms(); |
708 | Alarm *alarm; | 693 | Alarm *alarm; |
709 | QDateTime qdt; | 694 | QDateTime qdt; |
710 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 695 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
711 | if (incidence->recursOn(from.date())) { | 696 | if (incidence->recursOn(from.date())) { |
712 | qdt.setTime(alarm->time().time()); | 697 | qdt.setTime(alarm->time().time()); |
713 | qdt.setDate(from.date()); | 698 | qdt.setDate(from.date()); |
714 | } | 699 | } |
715 | else qdt = alarm->time(); | 700 | else qdt = alarm->time(); |
716 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 701 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
717 | if ( alarm->enabled() ) { | 702 | if ( alarm->enabled() ) { |
718 | if ( qdt >= from && qdt <= to ) { | 703 | if ( qdt >= from && qdt <= to ) { |
719 | alarms.append( alarm ); | 704 | alarms.append( alarm ); |
720 | } | 705 | } |
721 | } | 706 | } |
722 | } | 707 | } |
723 | } | 708 | } |
724 | 709 | ||
725 | 710 | ||
726 | /****************************** PROTECTED METHODS ****************************/ | 711 | /****************************** PROTECTED METHODS ****************************/ |
727 | 712 | ||
728 | // after changes are made to an event, this should be called. | 713 | // after changes are made to an event, this should be called. |
729 | void CalendarLocal::update( IncidenceBase *incidence ) | 714 | void CalendarLocal::update( IncidenceBase *incidence ) |
730 | { | 715 | { |
731 | incidence->setSyncStatus( Event::SYNCMOD ); | 716 | incidence->setSyncStatus( Event::SYNCMOD ); |
732 | incidence->setLastModified( QDateTime::currentDateTime() ); | 717 | incidence->setLastModified( QDateTime::currentDateTime() ); |
733 | // we should probably update the revision number here, | 718 | // we should probably update the revision number here, |
734 | // or internally in the Event itself when certain things change. | 719 | // or internally in the Event itself when certain things change. |
735 | // need to verify with ical documentation. | 720 | // need to verify with ical documentation. |
736 | 721 | ||
737 | setModified( true ); | 722 | setModified( true ); |
738 | } | 723 | } |
739 | 724 | ||
740 | void CalendarLocal::insertEvent( Event *event ) | 725 | void CalendarLocal::insertEvent( Event *event ) |
741 | { | 726 | { |
742 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 727 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
743 | } | 728 | } |
744 | 729 | ||
745 | 730 | ||
746 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 731 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
747 | { | 732 | { |
748 | QPtrList<Event> eventList; | 733 | QPtrList<Event> eventList; |
749 | 734 | ||
750 | Event *event; | 735 | Event *event; |
751 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 736 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
752 | if ( !event->calEnabled() ) continue; | 737 | if ( !event->calEnabled() ) continue; |
753 | if ( event->doesRecur() ) { | 738 | if ( event->doesRecur() ) { |
754 | if ( event->isMultiDay() ) { | 739 | if ( event->isMultiDay() ) { |
755 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 740 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
756 | int i; | 741 | int i; |
757 | for ( i = 0; i <= extraDays; i++ ) { | 742 | for ( i = 0; i <= extraDays; i++ ) { |
758 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 743 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
759 | eventList.append( event ); | 744 | eventList.append( event ); |
760 | break; | 745 | break; |
761 | } | 746 | } |
762 | } | 747 | } |
763 | } else { | 748 | } else { |
764 | if ( event->recursOn( qd ) ) | 749 | if ( event->recursOn( qd ) ) |
765 | eventList.append( event ); | 750 | eventList.append( event ); |
766 | } | 751 | } |
767 | } else { | 752 | } else { |
768 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 753 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
769 | eventList.append( event ); | 754 | eventList.append( event ); |
770 | } | 755 | } |
771 | } | 756 | } |
772 | } | 757 | } |
773 | 758 | ||
774 | if ( !sorted ) { | 759 | if ( !sorted ) { |
775 | return eventList; | 760 | return eventList; |
776 | } | 761 | } |
777 | 762 | ||
778 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 763 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
779 | // now, we have to sort it based on dtStart.time() | 764 | // now, we have to sort it based on dtStart.time() |
780 | QPtrList<Event> eventListSorted; | 765 | QPtrList<Event> eventListSorted; |
781 | Event *sortEvent; | 766 | Event *sortEvent; |
782 | for ( event = eventList.first(); event; event = eventList.next() ) { | 767 | for ( event = eventList.first(); event; event = eventList.next() ) { |
783 | sortEvent = eventListSorted.first(); | 768 | sortEvent = eventListSorted.first(); |
784 | int i = 0; | 769 | int i = 0; |
785 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 770 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
786 | { | 771 | { |
787 | i++; | 772 | i++; |
788 | sortEvent = eventListSorted.next(); | 773 | sortEvent = eventListSorted.next(); |
789 | } | 774 | } |
790 | eventListSorted.insert( i, event ); | 775 | eventListSorted.insert( i, event ); |
791 | } | 776 | } |
792 | return eventListSorted; | 777 | return eventListSorted; |
793 | } | 778 | } |
794 | 779 | ||
795 | 780 | ||
796 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 781 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
797 | bool inclusive ) | 782 | bool inclusive ) |
798 | { | 783 | { |
799 | Event *event = 0; | 784 | Event *event = 0; |
800 | 785 | ||
801 | QPtrList<Event> eventList; | 786 | QPtrList<Event> eventList; |
802 | 787 | ||
803 | // Get non-recurring events | 788 | // Get non-recurring events |
804 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 789 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
805 | if ( !event->calEnabled() ) continue; | 790 | if ( !event->calEnabled() ) continue; |
806 | if ( event->doesRecur() ) { | 791 | if ( event->doesRecur() ) { |
807 | QDate rStart = event->dtStart().date(); | 792 | QDate rStart = event->dtStart().date(); |
808 | bool found = false; | 793 | bool found = false; |
809 | if ( inclusive ) { | 794 | if ( inclusive ) { |
810 | if ( rStart >= start && rStart <= end ) { | 795 | if ( rStart >= start && rStart <= end ) { |
811 | // Start date of event is in range. Now check for end date. | 796 | // Start date of event is in range. Now check for end date. |
812 | // if duration is negative, event recurs forever, so do not include it. | 797 | // if duration is negative, event recurs forever, so do not include it. |
813 | if ( event->recurrence()->duration() == 0 ) { // End date set | 798 | if ( event->recurrence()->duration() == 0 ) { // End date set |
814 | QDate rEnd = event->recurrence()->endDate(); | 799 | QDate rEnd = event->recurrence()->endDate(); |
815 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 800 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
816 | found = true; | 801 | found = true; |
817 | } | 802 | } |
818 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 803 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
819 | // TODO: Calculate end date from duration. Should be done in Event | 804 | // TODO: Calculate end date from duration. Should be done in Event |
820 | // For now exclude all events with a duration. | 805 | // For now exclude all events with a duration. |
821 | } | 806 | } |
822 | } | 807 | } |
823 | } else { | 808 | } else { |
824 | bool founOne; | 809 | bool founOne; |
825 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 810 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
826 | if ( founOne ) { | 811 | if ( founOne ) { |
827 | if ( next <= end ) { | 812 | if ( next <= end ) { |
828 | found = true; | 813 | found = true; |
829 | } | 814 | } |
830 | } | 815 | } |
831 | 816 | ||
832 | /* | 817 | /* |
833 | // crap !!! | 818 | // crap !!! |
834 | if ( rStart <= end ) { // Start date not after range | 819 | if ( rStart <= end ) { // Start date not after range |
835 | if ( rStart >= start ) { // Start date within range | 820 | if ( rStart >= start ) { // Start date within range |
836 | found = true; | 821 | found = true; |
837 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 822 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
838 | found = true; | 823 | found = true; |
839 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 824 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
840 | QDate rEnd = event->recurrence()->endDate(); | 825 | QDate rEnd = event->recurrence()->endDate(); |
841 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 826 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
842 | found = true; | 827 | found = true; |
843 | } | 828 | } |
844 | } else { // Duration set | 829 | } else { // Duration set |
845 | // TODO: Calculate end date from duration. Should be done in Event | 830 | // TODO: Calculate end date from duration. Should be done in Event |
846 | // For now include all events with a duration. | 831 | // For now include all events with a duration. |
847 | found = true; | 832 | found = true; |
848 | } | 833 | } |
849 | } | 834 | } |
850 | */ | 835 | */ |
851 | 836 | ||
852 | } | 837 | } |
853 | 838 | ||
854 | if ( found ) eventList.append( event ); | 839 | if ( found ) eventList.append( event ); |
855 | } else { | 840 | } else { |
856 | QDate s = event->dtStart().date(); | 841 | QDate s = event->dtStart().date(); |
857 | QDate e = event->dtEnd().date(); | 842 | QDate e = event->dtEnd().date(); |
858 | 843 | ||
859 | if ( inclusive ) { | 844 | if ( inclusive ) { |
860 | if ( s >= start && e <= end ) { | 845 | if ( s >= start && e <= end ) { |
861 | eventList.append( event ); | 846 | eventList.append( event ); |
862 | } | 847 | } |
863 | } else { | 848 | } else { |
864 | if ( ( e >= start && s <= end ) ) { | 849 | if ( ( e >= start && s <= end ) ) { |
865 | eventList.append( event ); | 850 | eventList.append( event ); |
866 | } | 851 | } |
867 | } | 852 | } |
868 | } | 853 | } |
869 | } | 854 | } |
870 | 855 | ||
871 | return eventList; | 856 | return eventList; |
872 | } | 857 | } |
873 | 858 | ||
874 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 859 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
875 | { | 860 | { |
876 | return rawEventsForDate( qdt.date() ); | 861 | return rawEventsForDate( qdt.date() ); |
877 | } | 862 | } |
878 | 863 | ||
879 | QPtrList<Event> CalendarLocal::rawEvents() | 864 | QPtrList<Event> CalendarLocal::rawEvents() |
880 | { | 865 | { |
881 | QPtrList<Event> el; | 866 | QPtrList<Event> el; |
882 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 867 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
883 | if ( it->calEnabled() ) el.append( it ); | 868 | if ( it->calEnabled() ) el.append( it ); |
884 | return el; | 869 | return el; |
885 | } | 870 | } |
886 | 871 | ||
887 | bool CalendarLocal::addJournal(Journal *journal) | 872 | bool CalendarLocal::addJournal(Journal *journal) |
888 | { | 873 | { |
889 | mJournalList.append(journal); | 874 | mJournalList.append(journal); |
890 | 875 | ||
891 | journal->registerObserver( this ); | 876 | journal->registerObserver( this ); |
892 | 877 | ||
893 | setModified( true ); | 878 | setModified( true ); |
894 | if ( journal->calID() == 0 ) | 879 | if ( journal->calID() == 0 ) |
895 | journal->setCalID( mDefaultCalendar ); | 880 | journal->setCalID( mDefaultCalendar ); |
896 | journal->setCalEnabled( true ); | 881 | journal->setCalEnabled( true ); |
897 | return true; | 882 | return true; |
898 | } | 883 | } |
899 | 884 | ||
900 | void CalendarLocal::deleteJournal( Journal *journal ) | 885 | void CalendarLocal::deleteJournal( Journal *journal ) |
901 | { | 886 | { |
902 | clearUndo(); | 887 | clearUndo(journal); |
903 | mUndoIncidence = journal; | ||
904 | if ( mJournalList.removeRef(journal) ) { | 888 | if ( mJournalList.removeRef(journal) ) { |
905 | setModified( true ); | 889 | setModified( true ); |
906 | } | 890 | } |
907 | } | 891 | } |
908 | 892 | ||
909 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) | 893 | QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) |
910 | { | 894 | { |
911 | QPtrList<Journal> el; | 895 | QPtrList<Journal> el; |
912 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 896 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
913 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); | 897 | if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); |
914 | return el; | 898 | return el; |
915 | } | 899 | } |
916 | Journal *CalendarLocal::journal( const QDate &date ) | 900 | Journal *CalendarLocal::journal( const QDate &date ) |
917 | { | 901 | { |
918 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 902 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
919 | 903 | ||
920 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 904 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
921 | if ( it->calEnabled() && it->dtStart().date() == date ) | 905 | if ( it->calEnabled() && it->dtStart().date() == date ) |
922 | return it; | 906 | return it; |
923 | 907 | ||
924 | return 0; | 908 | return 0; |
925 | } | 909 | } |
926 | 910 | ||
927 | Journal *CalendarLocal::journal( const QString &uid ) | 911 | Journal *CalendarLocal::journal( const QString &uid ) |
928 | { | 912 | { |
929 | Journal * retVal = 0; | 913 | Journal * retVal = 0; |
930 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 914 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
931 | if ( it->calEnabled() && it->uid() == uid ) { | 915 | if ( it->calEnabled() && it->uid() == uid ) { |
932 | if ( retVal ) { | 916 | if ( retVal ) { |
933 | if ( retVal->calID() > it->calID() ) { | 917 | if ( retVal->calID() > it->calID() ) { |
934 | retVal = it; | 918 | retVal = it; |
935 | } | 919 | } |
936 | } else { | 920 | } else { |
937 | retVal = it; | 921 | retVal = it; |
938 | } | 922 | } |
939 | } | 923 | } |
940 | return retVal; | 924 | return retVal; |
941 | } | 925 | } |
942 | 926 | ||
943 | QPtrList<Journal> CalendarLocal::journals() | 927 | QPtrList<Journal> CalendarLocal::journals() |
944 | { | 928 | { |
945 | QPtrList<Journal> el; | 929 | QPtrList<Journal> el; |
946 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 930 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
947 | if ( it->calEnabled() ) el.append( it ); | 931 | if ( it->calEnabled() ) el.append( it ); |
948 | return el; | 932 | return el; |
949 | } | 933 | } |
950 | void CalendarLocal::setCalendarRemove( int id ) | 934 | void CalendarLocal::setCalendarRemove( int id ) |
951 | { | 935 | { |
952 | 936 | ||
953 | { | 937 | { |
954 | QPtrList<Event> EventList = mEventList; | 938 | QPtrList<Event> EventList = mEventList; |
955 | Event * ev = EventList.first(); | 939 | Event * ev = EventList.first(); |
956 | while ( ev ) { | 940 | while ( ev ) { |
957 | if ( ev->calID() == id ) | 941 | if ( ev->calID() == id ) |
958 | deleteEvent( ev ); | 942 | deleteEvent( ev ); |
959 | ev = EventList.next(); | 943 | ev = EventList.next(); |
960 | } | 944 | } |
961 | } | 945 | } |
962 | { | 946 | { |
963 | 947 | ||
964 | QPtrList<Todo> TodoList = mTodoList; | 948 | QPtrList<Todo> TodoList = mTodoList; |
965 | Todo * ev = TodoList.first(); | 949 | Todo * ev = TodoList.first(); |
966 | while ( ev ) { | 950 | while ( ev ) { |
967 | if ( ev->calID() == id ) | 951 | if ( ev->calID() == id ) |
968 | deleteTodo( ev ); | 952 | deleteTodo( ev ); |
969 | ev = TodoList.next(); | 953 | ev = TodoList.next(); |
970 | } | 954 | } |
971 | } | 955 | } |
972 | { | 956 | { |
973 | QPtrList<Journal> JournalList = mJournalList; | 957 | QPtrList<Journal> JournalList = mJournalList; |
974 | Journal * ev = JournalList.first(); | 958 | Journal * ev = JournalList.first(); |
975 | while ( ev ) { | 959 | while ( ev ) { |
976 | if ( ev->calID() == id ) | 960 | if ( ev->calID() == id ) |
977 | deleteJournal( ev ); | 961 | deleteJournal( ev ); |
978 | ev = JournalList.next(); | 962 | ev = JournalList.next(); |
979 | } | 963 | } |
980 | } | 964 | } |
981 | 965 | ||
982 | clearUndo(); | 966 | clearUndo(0); |
983 | 967 | ||
984 | } | 968 | } |
985 | 969 | ||
986 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | 970 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) |
987 | { | 971 | { |
988 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 972 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
989 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 973 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
990 | 974 | ||
991 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 975 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
992 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 976 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
993 | 977 | ||
994 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 978 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
995 | if ( it->calID() == id ) it->setCalEnabled( enable ); | 979 | if ( it->calID() == id ) it->setCalEnabled( enable ); |
996 | 980 | ||
997 | } | 981 | } |
998 | 982 | ||
999 | void CalendarLocal::setReadOnly( int id, bool enable ) | 983 | void CalendarLocal::setReadOnly( int id, bool enable ) |
1000 | { | 984 | { |
1001 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 985 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1002 | if ( it->calID() == id ) it->setReadOnly( enable ); | 986 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1003 | 987 | ||
1004 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 988 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1005 | if ( it->calID() == id ) it->setReadOnly( enable ); | 989 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1006 | 990 | ||
1007 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 991 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1008 | if ( it->calID() == id ) it->setReadOnly( enable ); | 992 | if ( it->calID() == id ) it->setReadOnly( enable ); |
1009 | 993 | ||
1010 | } | 994 | } |
1011 | 995 | ||
1012 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | 996 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) |
1013 | { | 997 | { |
1014 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 998 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1015 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 999 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1016 | 1000 | ||
1017 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1001 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1018 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1002 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1019 | 1003 | ||
1020 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1004 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1021 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | 1005 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); |
1022 | reInitAlarmSettings(); | 1006 | reInitAlarmSettings(); |
1023 | 1007 | ||
1024 | } | 1008 | } |
1025 | void CalendarLocal::setDefaultCalendarEnabledOnly() | 1009 | void CalendarLocal::setDefaultCalendarEnabledOnly() |
1026 | { | 1010 | { |
1027 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 1011 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
1028 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | 1012 | it->setCalEnabled( it->calID() == mDefaultCalendar ); |
1029 | 1013 | ||
1030 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | 1014 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) |
1031 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1015 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1032 | 1016 | ||
1033 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 1017 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
1034 | it->setCalEnabled( it->calID() == mDefaultCalendar); | 1018 | it->setCalEnabled( it->calID() == mDefaultCalendar); |
1035 | 1019 | ||
1036 | } | 1020 | } |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index ae7e30c..a7a85c8 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,231 +1,230 @@ | |||
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 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | void addCalendar( Calendar* ); | 46 | void addCalendar( Calendar* ); |
47 | bool addCalendarFile( QString name, int id ); | 47 | bool addCalendarFile( QString name, int id ); |
48 | bool mergeCalendarFile( QString name ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); |
51 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
52 | void stopAllTodos(); | 52 | void stopAllTodos(); |
53 | /** | 53 | /** |
54 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 54 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
55 | calendar. Any information already present is lost. | 55 | calendar. Any information already present is lost. |
56 | @return true, if successfull, false on error. | 56 | @return true, if successfull, false on error. |
57 | @param fileName the name of the calendar on disk. | 57 | @param fileName the name of the calendar on disk. |
58 | */ | 58 | */ |
59 | bool load( const QString &fileName ); | 59 | bool load( const QString &fileName ); |
60 | /** | 60 | /** |
61 | Writes out the calendar to disk in the specified \a format. | 61 | Writes out the calendar to disk in the specified \a format. |
62 | CalendarLocal takes ownership of the CalFormat object. | 62 | CalendarLocal takes ownership of the CalFormat object. |
63 | @return true, if successfull, false on error. | 63 | @return true, if successfull, false on error. |
64 | @param fileName the name of the file | 64 | @param fileName the name of the file |
65 | */ | 65 | */ |
66 | bool save( const QString &fileName, CalFormat *format = 0 ); | 66 | bool save( const QString &fileName, CalFormat *format = 0 ); |
67 | 67 | ||
68 | /** | 68 | /** |
69 | Clears out the current calendar, freeing all used memory etc. etc. | 69 | Clears out the current calendar, freeing all used memory etc. etc. |
70 | */ | 70 | */ |
71 | void close(); | 71 | void close(); |
72 | void clearUndo(); | ||
73 | 72 | ||
74 | void save() {} | 73 | void save() {} |
75 | 74 | ||
76 | /** | 75 | /** |
77 | Add Event to calendar. | 76 | Add Event to calendar. |
78 | */ | 77 | */ |
79 | void removeSyncInfo( QString syncProfile); | 78 | void removeSyncInfo( QString syncProfile); |
80 | bool addAnniversaryNoDup( Event *event ); | 79 | bool addAnniversaryNoDup( Event *event ); |
81 | bool addEventNoDup( Event *event ); | 80 | bool addEventNoDup( Event *event ); |
82 | bool addEvent( Event *event ); | 81 | bool addEvent( Event *event ); |
83 | /** | 82 | /** |
84 | Deletes an event from this calendar. | 83 | Deletes an event from this calendar. |
85 | */ | 84 | */ |
86 | void deleteEvent( Event *event ); | 85 | void deleteEvent( Event *event ); |
87 | 86 | ||
88 | /** | 87 | /** |
89 | Retrieves an event on the basis of the unique string ID. | 88 | Retrieves an event on the basis of the unique string ID. |
90 | */ | 89 | */ |
91 | Event *event( const QString &uid ); | 90 | Event *event( const QString &uid ); |
92 | /** | 91 | /** |
93 | Return unfiltered list of all events in calendar. | 92 | Return unfiltered list of all events in calendar. |
94 | */ | 93 | */ |
95 | QPtrList<Event> rawEvents(); | 94 | QPtrList<Event> rawEvents(); |
96 | QPtrList<Event> getExternLastSyncEvents(); | 95 | QPtrList<Event> getExternLastSyncEvents(); |
97 | /** | 96 | /** |
98 | Add a todo to the todolist. | 97 | Add a todo to the todolist. |
99 | */ | 98 | */ |
100 | bool addTodo( Todo *todo ); | 99 | bool addTodo( Todo *todo ); |
101 | bool addTodoNoDup( Todo *todo ); | 100 | bool addTodoNoDup( Todo *todo ); |
102 | /** | 101 | /** |
103 | Remove a todo from the todolist. | 102 | Remove a todo from the todolist. |
104 | */ | 103 | */ |
105 | void deleteTodo( Todo * ); | 104 | void deleteTodo( Todo * ); |
106 | /** | 105 | /** |
107 | Searches todolist for an event with this unique string identifier, | 106 | Searches todolist for an event with this unique string identifier, |
108 | returns a pointer or null. | 107 | returns a pointer or null. |
109 | */ | 108 | */ |
110 | Todo *todo( const QString &uid ); | 109 | Todo *todo( const QString &uid ); |
111 | /** | 110 | /** |
112 | Return list of all todos. | 111 | Return list of all todos. |
113 | */ | 112 | */ |
114 | QPtrList<Todo> rawTodos(); | 113 | QPtrList<Todo> rawTodos(); |
115 | /** | 114 | /** |
116 | Returns list of todos due on the specified date. | 115 | Returns list of todos due on the specified date. |
117 | */ | 116 | */ |
118 | QPtrList<Todo> todos( const QDate &date ); | 117 | QPtrList<Todo> todos( const QDate &date ); |
119 | /** | 118 | /** |
120 | Return list of all todos. | 119 | Return list of all todos. |
121 | 120 | ||
122 | Workaround because compiler does not recognize function of base class. | 121 | Workaround because compiler does not recognize function of base class. |
123 | */ | 122 | */ |
124 | QPtrList<Todo> todos() { return Calendar::todos(); } | 123 | QPtrList<Todo> todos() { return Calendar::todos(); } |
125 | 124 | ||
126 | /** | 125 | /** |
127 | Add a Journal entry to calendar. | 126 | Add a Journal entry to calendar. |
128 | */ | 127 | */ |
129 | bool addJournal( Journal * ); | 128 | bool addJournal( Journal * ); |
130 | /** | 129 | /** |
131 | Remove a Journal from the calendar. | 130 | Remove a Journal from the calendar. |
132 | */ | 131 | */ |
133 | void deleteJournal( Journal * ); | 132 | void deleteJournal( Journal * ); |
134 | /** | 133 | /** |
135 | Return Journal for given date. | 134 | Return Journal for given date. |
136 | */ | 135 | */ |
137 | Journal *journal( const QDate & ); | 136 | Journal *journal( const QDate & ); |
138 | QPtrList<Journal> journals4Date( const QDate & ); | 137 | QPtrList<Journal> journals4Date( const QDate & ); |
139 | /** | 138 | /** |
140 | Return Journal with given UID. | 139 | Return Journal with given UID. |
141 | */ | 140 | */ |
142 | Journal *journal( const QString &uid ); | 141 | Journal *journal( const QString &uid ); |
143 | /** | 142 | /** |
144 | Return list of all Journals stored in calendar. | 143 | Return list of all Journals stored in calendar. |
145 | */ | 144 | */ |
146 | QPtrList<Journal> journals(); | 145 | QPtrList<Journal> journals(); |
147 | 146 | ||
148 | /** | 147 | /** |
149 | Return all alarms, which ocur in the given time interval. | 148 | Return all alarms, which ocur in the given time interval. |
150 | */ | 149 | */ |
151 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 150 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
152 | 151 | ||
153 | /** | 152 | /** |
154 | Return all alarms, which ocur before given date. | 153 | Return all alarms, which ocur before given date. |
155 | */ | 154 | */ |
156 | Alarm::List alarmsTo( const QDateTime &to ); | 155 | Alarm::List alarmsTo( const QDateTime &to ); |
157 | 156 | ||
158 | QDateTime nextAlarm( int daysTo ) ; | 157 | QDateTime nextAlarm( int daysTo ) ; |
159 | QDateTime nextAlarmEventDateTime() const; | 158 | QDateTime nextAlarmEventDateTime() const; |
160 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 159 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
161 | void registerAlarm(); | 160 | void registerAlarm(); |
162 | void deRegisterAlarm(); | 161 | void deRegisterAlarm(); |
163 | QString getAlarmNotification(); | 162 | QString getAlarmNotification(); |
164 | QString nextSummary() const ; | 163 | QString nextSummary() const ; |
165 | /** | 164 | /** |
166 | This method should be called whenever a Event is modified directly | 165 | This method should be called whenever a Event is modified directly |
167 | via it's pointer. It makes sure that the calendar is internally | 166 | via it's pointer. It makes sure that the calendar is internally |
168 | consistent. | 167 | consistent. |
169 | */ | 168 | */ |
170 | void update( IncidenceBase *incidence ); | 169 | void update( IncidenceBase *incidence ); |
171 | 170 | ||
172 | /** | 171 | /** |
173 | Builds and then returns a list of all events that match for the | 172 | Builds and then returns a list of all events that match for the |
174 | date specified. useful for dayView, etc. etc. | 173 | date specified. useful for dayView, etc. etc. |
175 | */ | 174 | */ |
176 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 175 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
177 | /** | 176 | /** |
178 | Get unfiltered events for date \a qdt. | 177 | Get unfiltered events for date \a qdt. |
179 | */ | 178 | */ |
180 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 179 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
181 | /** | 180 | /** |
182 | Get unfiltered events in a range of dates. If inclusive is set to true, | 181 | Get unfiltered events in a range of dates. If inclusive is set to true, |
183 | only events are returned, which are completely included in the range. | 182 | only events are returned, which are completely included in the range. |
184 | */ | 183 | */ |
185 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 184 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
186 | bool inclusive = false ); | 185 | bool inclusive = false ); |
187 | Todo *todo( QString, QString ); | 186 | Todo *todo( QString, QString ); |
188 | Event *event( QString, QString ); | 187 | Event *event( QString, QString ); |
189 | 188 | ||
190 | public slots: | 189 | public slots: |
191 | void setCalendarEnabled( int id, bool enable ); | 190 | void setCalendarEnabled( int id, bool enable ); |
192 | void setAlarmEnabled( int id, bool enable ); | 191 | void setAlarmEnabled( int id, bool enable ); |
193 | void setReadOnly( int id, bool enable ); | 192 | void setReadOnly( int id, bool enable ); |
194 | void setDefaultCalendarEnabledOnly(); | 193 | void setDefaultCalendarEnabledOnly(); |
195 | void setCalendarRemove( int id ); | 194 | void setCalendarRemove( int id ); |
196 | 195 | ||
197 | protected: | 196 | protected: |
198 | 197 | ||
199 | // Event* mNextAlarmEvent; | 198 | // Event* mNextAlarmEvent; |
200 | QString mNextSummary; | 199 | QString mNextSummary; |
201 | QString mNextAlarmEventDateTimeString; | 200 | QString mNextAlarmEventDateTimeString; |
202 | QString mLastAlarmNotificationString; | 201 | QString mLastAlarmNotificationString; |
203 | QDateTime mNextAlarmEventDateTime; | 202 | QDateTime mNextAlarmEventDateTime; |
204 | QDateTime mNextAlarmDateTime; | 203 | QDateTime mNextAlarmDateTime; |
205 | void reInitAlarmSettings(); | 204 | void reInitAlarmSettings(); |
206 | 205 | ||
207 | /** Notification function of IncidenceBase::Observer. */ | 206 | /** Notification function of IncidenceBase::Observer. */ |
208 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 207 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
209 | 208 | ||
210 | /** inserts an event into its "proper place" in the calendar. */ | 209 | /** inserts an event into its "proper place" in the calendar. */ |
211 | void insertEvent( Event *event ); | 210 | void insertEvent( Event *event ); |
212 | 211 | ||
213 | /** Append alarms of incidence in interval to list of alarms. */ | 212 | /** Append alarms of incidence in interval to list of alarms. */ |
214 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 213 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
215 | const QDateTime &from, const QDateTime &to ); | 214 | const QDateTime &from, const QDateTime &to ); |
216 | 215 | ||
217 | /** Append alarms of recurring events in interval to list of alarms. */ | 216 | /** Append alarms of recurring events in interval to list of alarms. */ |
218 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 217 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
219 | const QDateTime &from, const QDateTime &to ); | 218 | const QDateTime &from, const QDateTime &to ); |
220 | 219 | ||
221 | private: | 220 | private: |
222 | void init(); | 221 | void init(); |
223 | 222 | ||
224 | QPtrList<Event> mEventList; | 223 | QPtrList<Event> mEventList; |
225 | QPtrList<Todo> mTodoList; | 224 | QPtrList<Todo> mTodoList; |
226 | QPtrList<Journal> mJournalList; | 225 | QPtrList<Journal> mJournalList; |
227 | }; | 226 | }; |
228 | 227 | ||
229 | } | 228 | } |
230 | 229 | ||
231 | #endif | 230 | #endif |
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 52d94fb..549014e 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -110,732 +110,736 @@ QString Incidence::durationText4Time( int offset ) | |||
110 | int hours = min /60; | 110 | int hours = min /60; |
111 | min = min % 60; | 111 | min = min % 60; |
112 | int days = hours /24; | 112 | int days = hours /24; |
113 | hours = hours % 24; | 113 | hours = hours % 24; |
114 | 114 | ||
115 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { | 115 | if ( doesFloat() || ( min == 0 && hours == 0 ) ) { |
116 | if ( days == 1 ) | 116 | if ( days == 1 ) |
117 | return "1" + i18n(" day"); | 117 | return "1" + i18n(" day"); |
118 | else | 118 | else |
119 | return QString::number( days )+ i18n(" days"); | 119 | return QString::number( days )+ i18n(" days"); |
120 | 120 | ||
121 | } | 121 | } |
122 | QString message = QString::number ( hours ) +":"; | 122 | QString message = QString::number ( hours ) +":"; |
123 | if ( min < 10 ) message += "0"; | 123 | if ( min < 10 ) message += "0"; |
124 | message += QString::number ( min ); | 124 | message += QString::number ( min ); |
125 | if ( days > 0 ) { | 125 | if ( days > 0 ) { |
126 | if ( days == 1 ) | 126 | if ( days == 1 ) |
127 | message = "1" + i18n(" day") + " "+message; | 127 | message = "1" + i18n(" day") + " "+message; |
128 | else | 128 | else |
129 | message = QString::number( days )+ i18n(" days") + " "+message; | 129 | message = QString::number( days )+ i18n(" days") + " "+message; |
130 | } | 130 | } |
131 | return message; | 131 | return message; |
132 | } | 132 | } |
133 | bool Incidence::isHoliday() const | 133 | bool Incidence::isHoliday() const |
134 | { | 134 | { |
135 | return mHoliday; | 135 | return mHoliday; |
136 | } | 136 | } |
137 | bool Incidence::isBirthday() const | 137 | bool Incidence::isBirthday() const |
138 | { | 138 | { |
139 | 139 | ||
140 | return mBirthday ; | 140 | return mBirthday ; |
141 | } | 141 | } |
142 | bool Incidence::isAnniversary() const | 142 | bool Incidence::isAnniversary() const |
143 | { | 143 | { |
144 | return mAnniversary ; | 144 | return mAnniversary ; |
145 | 145 | ||
146 | } | 146 | } |
147 | 147 | ||
148 | bool Incidence::hasRecurrenceID() const | 148 | bool Incidence::hasRecurrenceID() const |
149 | { | 149 | { |
150 | return mHasRecurrenceID; | 150 | return mHasRecurrenceID; |
151 | } | 151 | } |
152 | 152 | ||
153 | void Incidence::setHasRecurrenceID( bool b ) | 153 | void Incidence::setHasRecurrenceID( bool b ) |
154 | { | 154 | { |
155 | mHasRecurrenceID = b; | 155 | mHasRecurrenceID = b; |
156 | } | 156 | } |
157 | 157 | ||
158 | void Incidence::setRecurrenceID(QDateTime d) | 158 | void Incidence::setRecurrenceID(QDateTime d) |
159 | { | 159 | { |
160 | mRecurrenceID = d; | 160 | mRecurrenceID = d; |
161 | mHasRecurrenceID = true; | 161 | mHasRecurrenceID = true; |
162 | updated(); | 162 | updated(); |
163 | } | 163 | } |
164 | QDateTime Incidence::recurrenceID () const | 164 | QDateTime Incidence::recurrenceID () const |
165 | { | 165 | { |
166 | return mRecurrenceID; | 166 | return mRecurrenceID; |
167 | } | 167 | } |
168 | 168 | ||
169 | bool Incidence::cancelled() const | 169 | bool Incidence::cancelled() const |
170 | { | 170 | { |
171 | return mCancelled; | 171 | return mCancelled; |
172 | } | 172 | } |
173 | void Incidence::setCancelled( bool b ) | 173 | void Incidence::setCancelled( bool b ) |
174 | { | 174 | { |
175 | mCancelled = b; | 175 | mCancelled = b; |
176 | updated(); | 176 | updated(); |
177 | } | 177 | } |
178 | bool Incidence::hasStartDate() const | 178 | bool Incidence::hasStartDate() const |
179 | { | 179 | { |
180 | return mHasStartDate; | 180 | return mHasStartDate; |
181 | } | 181 | } |
182 | 182 | ||
183 | void Incidence::setHasStartDate(bool f) | 183 | void Incidence::setHasStartDate(bool f) |
184 | { | 184 | { |
185 | if (mReadOnly) return; | 185 | if (mReadOnly) return; |
186 | mHasStartDate = f; | 186 | mHasStartDate = f; |
187 | updated(); | 187 | updated(); |
188 | } | 188 | } |
189 | 189 | ||
190 | // A string comparison that considers that null and empty are the same | 190 | // A string comparison that considers that null and empty are the same |
191 | static bool stringCompare( const QString& s1, const QString& s2 ) | 191 | static bool stringCompare( const QString& s1, const QString& s2 ) |
192 | { | 192 | { |
193 | if ( s1.isEmpty() && s2.isEmpty() ) | 193 | if ( s1.isEmpty() && s2.isEmpty() ) |
194 | return true; | 194 | return true; |
195 | return s1 == s2; | 195 | return s1 == s2; |
196 | } | 196 | } |
197 | 197 | ||
198 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 198 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
199 | { | 199 | { |
200 | 200 | ||
201 | if( i1.alarms().count() != i2.alarms().count() ) { | 201 | if( i1.alarms().count() != i2.alarms().count() ) { |
202 | return false; // no need to check further | 202 | return false; // no need to check further |
203 | } | 203 | } |
204 | if ( i1.alarms().count() > 0 ) { | 204 | if ( i1.alarms().count() > 0 ) { |
205 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 205 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
206 | { | 206 | { |
207 | qDebug("alarm not equal "); | 207 | qDebug("alarm not equal "); |
208 | return false; | 208 | return false; |
209 | } | 209 | } |
210 | } | 210 | } |
211 | #if 0 | 211 | #if 0 |
212 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 212 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
213 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 213 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
214 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 214 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
215 | if( *a1.current() == *a2.current() ) { | 215 | if( *a1.current() == *a2.current() ) { |
216 | continue; | 216 | continue; |
217 | } | 217 | } |
218 | else { | 218 | else { |
219 | return false; | 219 | return false; |
220 | } | 220 | } |
221 | } | 221 | } |
222 | #endif | 222 | #endif |
223 | 223 | ||
224 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 224 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
225 | if ( i1.hasRecurrenceID() ) { | 225 | if ( i1.hasRecurrenceID() ) { |
226 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 226 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
227 | return false; | 227 | return false; |
228 | } | 228 | } |
229 | 229 | ||
230 | } else { | 230 | } else { |
231 | return false; | 231 | return false; |
232 | } | 232 | } |
233 | 233 | ||
234 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 234 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
235 | return false; | 235 | return false; |
236 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 236 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
237 | if ( i1.hasStartDate() ) { | 237 | if ( i1.hasStartDate() ) { |
238 | if ( i1.dtStart() != i2.dtStart() ) | 238 | if ( i1.dtStart() != i2.dtStart() ) |
239 | return false; | 239 | return false; |
240 | } | 240 | } |
241 | } else { | 241 | } else { |
242 | return false; | 242 | return false; |
243 | } | 243 | } |
244 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { | 244 | if ( i1.mRecurrence != 0 && i2.mRecurrence != 0 ) { |
245 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { | 245 | if (!( *i1.mRecurrence == *i2.mRecurrence) ) { |
246 | //qDebug("recurrence is NOT equal "); | 246 | //qDebug("recurrence is NOT equal "); |
247 | return false; | 247 | return false; |
248 | } | 248 | } |
249 | } else { | 249 | } else { |
250 | // one ( or both ) recurrence is 0 | 250 | // one ( or both ) recurrence is 0 |
251 | if ( i1.mRecurrence == 0 ) { | 251 | if ( i1.mRecurrence == 0 ) { |
252 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) | 252 | if ( i2.mRecurrence != 0 && i2.mRecurrence->doesRecur() != Recurrence::rNone ) |
253 | return false; | 253 | return false; |
254 | } else { | 254 | } else { |
255 | // i1.mRecurrence != 0 | 255 | // i1.mRecurrence != 0 |
256 | // i2.mRecurrence == 0 | 256 | // i2.mRecurrence == 0 |
257 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) | 257 | if ( i1.mRecurrence->doesRecur() != Recurrence::rNone ) |
258 | return false; | 258 | return false; |
259 | } | 259 | } |
260 | } | 260 | } |
261 | 261 | ||
262 | return | 262 | return |
263 | // i1.created() == i2.created() && | 263 | // i1.created() == i2.created() && |
264 | stringCompare( i1.description(), i2.description() ) && | 264 | stringCompare( i1.description(), i2.description() ) && |
265 | stringCompare( i1.summary(), i2.summary() ) && | 265 | stringCompare( i1.summary(), i2.summary() ) && |
266 | i1.categories() == i2.categories() && | 266 | i1.categories() == i2.categories() && |
267 | // no need to compare mRelatedTo | 267 | // no need to compare mRelatedTo |
268 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 268 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
269 | // i1.relations() == i2.relations() && | 269 | // i1.relations() == i2.relations() && |
270 | i1.exDates() == i2.exDates() && | 270 | i1.exDates() == i2.exDates() && |
271 | i1.attachments() == i2.attachments() && | 271 | i1.attachments() == i2.attachments() && |
272 | i1.resources() == i2.resources() && | 272 | i1.resources() == i2.resources() && |
273 | i1.secrecy() == i2.secrecy() && | 273 | i1.secrecy() == i2.secrecy() && |
274 | i1.priority() == i2.priority() && | 274 | i1.priority() == i2.priority() && |
275 | i1.cancelled() == i2.cancelled() && | 275 | i1.cancelled() == i2.cancelled() && |
276 | stringCompare( i1.location(), i2.location() ); | 276 | stringCompare( i1.location(), i2.location() ); |
277 | } | 277 | } |
278 | 278 | ||
279 | Incidence* Incidence::recreateCloneException( QDate d ) | 279 | Incidence* Incidence::recreateCloneException( QDate d ) |
280 | { | 280 | { |
281 | Incidence* newInc = clone(); | 281 | Incidence* newInc = clone(); |
282 | newInc->recreate(); | 282 | newInc->recreate(); |
283 | if ( doesRecur() ) { | 283 | if ( doesRecur() ) { |
284 | addExDate( d ); | 284 | addExDate( d ); |
285 | newInc->recurrence()->unsetRecurs(); | 285 | newInc->recurrence()->unsetRecurs(); |
286 | if ( typeID() == eventID ) { | 286 | if ( typeID() == eventID ) { |
287 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 287 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
288 | QTime tim = dtStart().time(); | 288 | QTime tim = dtStart().time(); |
289 | newInc->setDtStart( QDateTime(d, tim) ); | 289 | newInc->setDtStart( QDateTime(d, tim) ); |
290 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 290 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
291 | } else { | 291 | } else { |
292 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 292 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
293 | QTime tim = ((Todo*)this)->dtDue().time(); | 293 | QTime tim = ((Todo*)this)->dtDue().time(); |
294 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 294 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
295 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 295 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
296 | ((Todo*)this)->setRecurDates(); | 296 | ((Todo*)this)->setRecurDates(); |
297 | } | 297 | } |
298 | newInc->setExDates( DateList () ); | 298 | newInc->setExDates( DateList () ); |
299 | } | 299 | } |
300 | return newInc; | 300 | return newInc; |
301 | } | 301 | } |
302 | 302 | ||
303 | void Incidence::recreate() | 303 | void Incidence::recreate() |
304 | { | 304 | { |
305 | setCreated(QDateTime::currentDateTime()); | 305 | setCreated(QDateTime::currentDateTime()); |
306 | 306 | ||
307 | setUid(CalFormat::createUniqueId()); | 307 | setUid(CalFormat::createUniqueId()); |
308 | 308 | ||
309 | setRevision(0); | 309 | setRevision(0); |
310 | setIDStr( ":" ); | 310 | setIDStr( ":" ); |
311 | setLastModified(QDateTime::currentDateTime()); | 311 | setLastModified(QDateTime::currentDateTime()); |
312 | } | 312 | } |
313 | void Incidence::cloneRelations( Incidence * newInc ) | 313 | void Incidence::cloneRelations( Incidence * newInc ) |
314 | { | 314 | { |
315 | // newInc is already a clone of this incidence | 315 | // newInc is already a clone of this incidence |
316 | Incidence * inc; | 316 | Incidence * inc; |
317 | Incidence * cloneInc; | 317 | Incidence * cloneInc; |
318 | QPtrList<Incidence> Relations = relations(); | 318 | QPtrList<Incidence> Relations = relations(); |
319 | for (inc=Relations.first();inc;inc=Relations.next()) { | 319 | for (inc=Relations.first();inc;inc=Relations.next()) { |
320 | cloneInc = inc->clone(); | 320 | cloneInc = inc->clone(); |
321 | cloneInc->recreate(); | 321 | cloneInc->recreate(); |
322 | cloneInc->setRelatedTo( newInc ); | 322 | cloneInc->setRelatedTo( newInc ); |
323 | inc->cloneRelations( cloneInc ); | 323 | inc->cloneRelations( cloneInc ); |
324 | } | 324 | } |
325 | } | 325 | } |
326 | void Incidence::setReadOnly( bool readOnly ) | 326 | void Incidence::setReadOnly( bool readOnly ) |
327 | { | 327 | { |
328 | IncidenceBase::setReadOnly( readOnly ); | 328 | IncidenceBase::setReadOnly( readOnly ); |
329 | if ( mRecurrence ) | 329 | if ( mRecurrence ) |
330 | mRecurrence->setRecurReadOnly( readOnly); | 330 | mRecurrence->setRecurReadOnly( readOnly); |
331 | } | 331 | } |
332 | void Incidence::setLastModifiedSubInvalid() | 332 | void Incidence::setLastModifiedSubInvalid() |
333 | { | 333 | { |
334 | mLastModifiedSub = QDateTime(); | 334 | mLastModifiedSub = QDateTime(); |
335 | if ( mRelatedTo ) | 335 | if ( mRelatedTo ) |
336 | mRelatedTo->setLastModifiedSubInvalid(); | 336 | mRelatedTo->setLastModifiedSubInvalid(); |
337 | } | 337 | } |
338 | QDateTime Incidence::lastModifiedSub() | 338 | QDateTime Incidence::lastModifiedSub() |
339 | { | 339 | { |
340 | if ( !mRelations.count() ) | 340 | if ( !mRelations.count() ) |
341 | return lastModified(); | 341 | return lastModified(); |
342 | if ( mLastModifiedSub.isValid() ) | 342 | if ( mLastModifiedSub.isValid() ) |
343 | return mLastModifiedSub; | 343 | return mLastModifiedSub; |
344 | mLastModifiedSub = lastModified(); | 344 | mLastModifiedSub = lastModified(); |
345 | Incidence * inc; | 345 | Incidence * inc; |
346 | QPtrList<Incidence> Relations = relations(); | 346 | QPtrList<Incidence> Relations = relations(); |
347 | for (inc=Relations.first();inc;inc=Relations.next()) { | 347 | for (inc=Relations.first();inc;inc=Relations.next()) { |
348 | if ( inc->lastModifiedSub() > mLastModifiedSub ) | 348 | if ( inc->lastModifiedSub() > mLastModifiedSub ) |
349 | mLastModifiedSub = inc->lastModifiedSub(); | 349 | mLastModifiedSub = inc->lastModifiedSub(); |
350 | } | 350 | } |
351 | return mLastModifiedSub; | 351 | return mLastModifiedSub; |
352 | } | 352 | } |
353 | void Incidence::setCreated(QDateTime created) | 353 | void Incidence::setCreated(QDateTime created) |
354 | { | 354 | { |
355 | if (mReadOnly) return; | 355 | if (mReadOnly) return; |
356 | mCreated = getEvenTime(created); | 356 | mCreated = getEvenTime(created); |
357 | } | 357 | } |
358 | 358 | ||
359 | QDateTime Incidence::created() const | 359 | QDateTime Incidence::created() const |
360 | { | 360 | { |
361 | return mCreated; | 361 | return mCreated; |
362 | } | 362 | } |
363 | 363 | ||
364 | void Incidence::setRevision(int rev) | 364 | void Incidence::setRevision(int rev) |
365 | { | 365 | { |
366 | if (mReadOnly) return; | 366 | if (mReadOnly) return; |
367 | mRevision = rev; | 367 | mRevision = rev; |
368 | 368 | ||
369 | updated(); | 369 | updated(); |
370 | } | 370 | } |
371 | 371 | ||
372 | int Incidence::revision() const | 372 | int Incidence::revision() const |
373 | { | 373 | { |
374 | return mRevision; | 374 | return mRevision; |
375 | } | 375 | } |
376 | 376 | ||
377 | void Incidence::setDtStart(const QDateTime &dtStart) | 377 | void Incidence::setDtStart(const QDateTime &dtStart) |
378 | { | 378 | { |
379 | 379 | ||
380 | QDateTime dt = getEvenTime(dtStart); | 380 | QDateTime dt = getEvenTime(dtStart); |
381 | 381 | ||
382 | if ( mRecurrence ) | 382 | if ( mRecurrence ) |
383 | mRecurrence->setRecurStart( dt); | 383 | mRecurrence->setRecurStart( dt); |
384 | IncidenceBase::setDtStart( dt ); | 384 | IncidenceBase::setDtStart( dt ); |
385 | } | 385 | } |
386 | 386 | ||
387 | void Incidence::setDescription(const QString &description) | 387 | void Incidence::setDescription(const QString &description) |
388 | { | 388 | { |
389 | if (mReadOnly) return; | 389 | if (mReadOnly) return; |
390 | mDescription = description; | 390 | mDescription = description; |
391 | updated(); | 391 | updated(); |
392 | } | 392 | } |
393 | 393 | ||
394 | QString Incidence::description() const | 394 | QString Incidence::description() const |
395 | { | 395 | { |
396 | return mDescription; | 396 | return mDescription; |
397 | } | 397 | } |
398 | 398 | ||
399 | 399 | ||
400 | void Incidence::setSummary(const QString &summary) | 400 | void Incidence::setSummary(const QString &summary) |
401 | { | 401 | { |
402 | if (mReadOnly) return; | 402 | if (mReadOnly) return; |
403 | mSummary = summary; | 403 | mSummary = summary; |
404 | updated(); | 404 | updated(); |
405 | } | 405 | } |
406 | 406 | ||
407 | QString Incidence::summary() const | 407 | QString Incidence::summary() const |
408 | { | 408 | { |
409 | return mSummary; | 409 | return mSummary; |
410 | } | 410 | } |
411 | void Incidence::checkCategories() | 411 | void Incidence::checkCategories() |
412 | { | 412 | { |
413 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 413 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
414 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 414 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
415 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 415 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
416 | } | 416 | } |
417 | 417 | ||
418 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 418 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
419 | { | 419 | { |
420 | if (mReadOnly) return; | 420 | if (mReadOnly) return; |
421 | int i; | 421 | int i; |
422 | for( i = 0; i < categories.count(); ++i ) { | 422 | for( i = 0; i < categories.count(); ++i ) { |
423 | if ( !mCategories.contains (categories[i])) | 423 | if ( !mCategories.contains (categories[i])) |
424 | mCategories.append( categories[i] ); | 424 | mCategories.append( categories[i] ); |
425 | } | 425 | } |
426 | checkCategories(); | 426 | checkCategories(); |
427 | updated(); | 427 | updated(); |
428 | if ( addToRelations ) { | 428 | if ( addToRelations ) { |
429 | Incidence * inc; | 429 | Incidence * inc; |
430 | QPtrList<Incidence> Relations = relations(); | 430 | QPtrList<Incidence> Relations = relations(); |
431 | for (inc=Relations.first();inc;inc=Relations.next()) { | 431 | for (inc=Relations.first();inc;inc=Relations.next()) { |
432 | inc->addCategories( categories, true ); | 432 | inc->addCategories( categories, true ); |
433 | } | 433 | } |
434 | } | 434 | } |
435 | } | 435 | } |
436 | 436 | ||
437 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false | 437 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false |
438 | { | 438 | { |
439 | if (mReadOnly) return; | 439 | if (mReadOnly) return; |
440 | mCategories = categories; | 440 | mCategories = categories; |
441 | checkCategories(); | 441 | checkCategories(); |
442 | updated(); | 442 | updated(); |
443 | if ( setForRelations ) { | 443 | if ( setForRelations ) { |
444 | Incidence * inc; | 444 | Incidence * inc; |
445 | QPtrList<Incidence> Relations = relations(); | 445 | QPtrList<Incidence> Relations = relations(); |
446 | for (inc=Relations.first();inc;inc=Relations.next()) { | 446 | for (inc=Relations.first();inc;inc=Relations.next()) { |
447 | inc->setCategories( categories, true ); | 447 | inc->setCategories( categories, true ); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | } | 450 | } |
451 | 451 | ||
452 | // TODO: remove setCategories(QString) function | 452 | // TODO: remove setCategories(QString) function |
453 | void Incidence::setCategories(const QString &catStr) | 453 | void Incidence::setCategories(const QString &catStr) |
454 | { | 454 | { |
455 | if (mReadOnly) return; | 455 | if (mReadOnly) return; |
456 | mCategories.clear(); | 456 | mCategories.clear(); |
457 | 457 | ||
458 | if (catStr.isEmpty()) return; | 458 | if (catStr.isEmpty()) return; |
459 | 459 | ||
460 | mCategories = QStringList::split(",",catStr); | 460 | mCategories = QStringList::split(",",catStr); |
461 | 461 | ||
462 | QStringList::Iterator it; | 462 | QStringList::Iterator it; |
463 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 463 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
464 | *it = (*it).stripWhiteSpace(); | 464 | *it = (*it).stripWhiteSpace(); |
465 | } | 465 | } |
466 | checkCategories(); | 466 | checkCategories(); |
467 | updated(); | 467 | updated(); |
468 | } | 468 | } |
469 | // using this makes filtering 3 times faster | 469 | // using this makes filtering 3 times faster |
470 | QStringList* Incidence::categoriesP() | 470 | QStringList* Incidence::categoriesP() |
471 | { | 471 | { |
472 | return &mCategories; | 472 | return &mCategories; |
473 | } | 473 | } |
474 | 474 | ||
475 | QStringList Incidence::categories() const | 475 | QStringList Incidence::categories() const |
476 | { | 476 | { |
477 | return mCategories; | 477 | return mCategories; |
478 | } | 478 | } |
479 | 479 | ||
480 | QString Incidence::categoriesStr() | 480 | QString Incidence::categoriesStr() |
481 | { | 481 | { |
482 | return mCategories.join(","); | 482 | return mCategories.join(","); |
483 | } | 483 | } |
484 | QString Incidence::categoriesStrWithSpace() | 484 | QString Incidence::categoriesStrWithSpace() |
485 | { | 485 | { |
486 | return mCategories.join(", "); | 486 | return mCategories.join(", "); |
487 | } | 487 | } |
488 | 488 | ||
489 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 489 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
490 | { | 490 | { |
491 | if (mReadOnly) return; | 491 | if (mReadOnly) return; |
492 | mRelatedToUid = relatedToUid; | 492 | mRelatedToUid = relatedToUid; |
493 | } | 493 | } |
494 | 494 | void Incidence::clearRelations() | |
495 | { | ||
496 | mRelatedTo = 0; | ||
497 | mRelations.clear(); | ||
498 | } | ||
495 | QString Incidence::relatedToUid() const | 499 | QString Incidence::relatedToUid() const |
496 | { | 500 | { |
497 | return mRelatedToUid; | 501 | return mRelatedToUid; |
498 | } | 502 | } |
499 | 503 | ||
500 | void Incidence::setRelatedTo(Incidence *relatedTo) | 504 | void Incidence::setRelatedTo(Incidence *relatedTo) |
501 | { | 505 | { |
502 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 506 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
503 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 507 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
504 | if (mReadOnly || mRelatedTo == relatedTo) return; | 508 | if (mReadOnly || mRelatedTo == relatedTo) return; |
505 | if(mRelatedTo) { | 509 | if(mRelatedTo) { |
506 | // updated(); | 510 | // updated(); |
507 | mRelatedTo->removeRelation(this); | 511 | mRelatedTo->removeRelation(this); |
508 | } | 512 | } |
509 | mRelatedTo = relatedTo; | 513 | mRelatedTo = relatedTo; |
510 | if (mRelatedTo) { | 514 | if (mRelatedTo) { |
511 | mRelatedTo->addRelation(this); | 515 | mRelatedTo->addRelation(this); |
512 | mRelatedToUid = mRelatedTo->uid(); | 516 | mRelatedToUid = mRelatedTo->uid(); |
513 | } else { | 517 | } else { |
514 | mRelatedToUid = ""; | 518 | mRelatedToUid = ""; |
515 | } | 519 | } |
516 | } | 520 | } |
517 | 521 | ||
518 | Incidence *Incidence::relatedTo() const | 522 | Incidence *Incidence::relatedTo() const |
519 | { | 523 | { |
520 | return mRelatedTo; | 524 | return mRelatedTo; |
521 | } | 525 | } |
522 | 526 | ||
523 | QPtrList<Incidence> Incidence::relations() const | 527 | QPtrList<Incidence> Incidence::relations() const |
524 | { | 528 | { |
525 | return mRelations; | 529 | return mRelations; |
526 | } | 530 | } |
527 | 531 | ||
528 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) | 532 | void Incidence::addRelationsToList(QPtrList<Incidence> *rel) |
529 | { | 533 | { |
530 | Incidence* inc; | 534 | Incidence* inc; |
531 | QPtrList<Incidence> Relations = relations(); | 535 | QPtrList<Incidence> Relations = relations(); |
532 | for (inc=Relations.first();inc;inc=Relations.next()) { | 536 | for (inc=Relations.first();inc;inc=Relations.next()) { |
533 | inc->addRelationsToList( rel ); | 537 | inc->addRelationsToList( rel ); |
534 | } | 538 | } |
535 | if ( rel->findRef( this ) == -1 ) | 539 | if ( rel->findRef( this ) == -1 ) |
536 | rel->append( this ); | 540 | rel->append( this ); |
537 | } | 541 | } |
538 | 542 | ||
539 | void Incidence::addRelation(Incidence *event) | 543 | void Incidence::addRelation(Incidence *event) |
540 | { | 544 | { |
541 | setLastModifiedSubInvalid(); | 545 | setLastModifiedSubInvalid(); |
542 | if( mRelations.findRef( event ) == -1 ) { | 546 | if( mRelations.findRef( event ) == -1 ) { |
543 | mRelations.append(event); | 547 | mRelations.append(event); |
544 | //updated(); | 548 | //updated(); |
545 | } | 549 | } |
546 | } | 550 | } |
547 | 551 | ||
548 | void Incidence::removeRelation(Incidence *event) | 552 | void Incidence::removeRelation(Incidence *event) |
549 | { | 553 | { |
550 | setLastModifiedSubInvalid(); | 554 | setLastModifiedSubInvalid(); |
551 | mRelations.removeRef(event); | 555 | mRelations.removeRef(event); |
552 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 556 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
553 | } | 557 | } |
554 | 558 | ||
555 | bool Incidence::recursOn(const QDate &qd) const | 559 | bool Incidence::recursOn(const QDate &qd) const |
556 | { | 560 | { |
557 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; | 561 | if (mRecurrence && mRecurrence->recursOnPure(qd) && !isException(qd)) return true; |
558 | else return false; | 562 | else return false; |
559 | } | 563 | } |
560 | 564 | ||
561 | void Incidence::setExDates(const DateList &exDates) | 565 | void Incidence::setExDates(const DateList &exDates) |
562 | { | 566 | { |
563 | if (mReadOnly) return; | 567 | if (mReadOnly) return; |
564 | mExDates = exDates; | 568 | mExDates = exDates; |
565 | recurrence()->setRecurExDatesCount(mExDates.count()); | 569 | recurrence()->setRecurExDatesCount(mExDates.count()); |
566 | 570 | ||
567 | updated(); | 571 | updated(); |
568 | } | 572 | } |
569 | 573 | ||
570 | void Incidence::addExDate(const QDate &date) | 574 | void Incidence::addExDate(const QDate &date) |
571 | { | 575 | { |
572 | if (mReadOnly) return; | 576 | if (mReadOnly) return; |
573 | mExDates.append(date); | 577 | mExDates.append(date); |
574 | 578 | ||
575 | recurrence()->setRecurExDatesCount(mExDates.count()); | 579 | recurrence()->setRecurExDatesCount(mExDates.count()); |
576 | 580 | ||
577 | updated(); | 581 | updated(); |
578 | } | 582 | } |
579 | 583 | ||
580 | DateList Incidence::exDates() const | 584 | DateList Incidence::exDates() const |
581 | { | 585 | { |
582 | return mExDates; | 586 | return mExDates; |
583 | } | 587 | } |
584 | 588 | ||
585 | bool Incidence::isException(const QDate &date) const | 589 | bool Incidence::isException(const QDate &date) const |
586 | { | 590 | { |
587 | DateList::ConstIterator it; | 591 | DateList::ConstIterator it; |
588 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 592 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
589 | if ( (*it) == date ) { | 593 | if ( (*it) == date ) { |
590 | return true; | 594 | return true; |
591 | } | 595 | } |
592 | } | 596 | } |
593 | 597 | ||
594 | return false; | 598 | return false; |
595 | } | 599 | } |
596 | 600 | ||
597 | void Incidence::addAttachment(Attachment *attachment) | 601 | void Incidence::addAttachment(Attachment *attachment) |
598 | { | 602 | { |
599 | if (mReadOnly || !attachment) return; | 603 | if (mReadOnly || !attachment) return; |
600 | mAttachments.append(attachment); | 604 | mAttachments.append(attachment); |
601 | updated(); | 605 | updated(); |
602 | } | 606 | } |
603 | 607 | ||
604 | void Incidence::deleteAttachment(Attachment *attachment) | 608 | void Incidence::deleteAttachment(Attachment *attachment) |
605 | { | 609 | { |
606 | mAttachments.removeRef(attachment); | 610 | mAttachments.removeRef(attachment); |
607 | } | 611 | } |
608 | 612 | ||
609 | void Incidence::deleteAttachments(const QString& mime) | 613 | void Incidence::deleteAttachments(const QString& mime) |
610 | { | 614 | { |
611 | Attachment *at = mAttachments.first(); | 615 | Attachment *at = mAttachments.first(); |
612 | while (at) { | 616 | while (at) { |
613 | if (at->mimeType() == mime) | 617 | if (at->mimeType() == mime) |
614 | mAttachments.remove(); | 618 | mAttachments.remove(); |
615 | else | 619 | else |
616 | at = mAttachments.next(); | 620 | at = mAttachments.next(); |
617 | } | 621 | } |
618 | } | 622 | } |
619 | 623 | ||
620 | QPtrList<Attachment> Incidence::attachments() const | 624 | QPtrList<Attachment> Incidence::attachments() const |
621 | { | 625 | { |
622 | return mAttachments; | 626 | return mAttachments; |
623 | } | 627 | } |
624 | 628 | ||
625 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 629 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
626 | { | 630 | { |
627 | QPtrList<Attachment> attachments; | 631 | QPtrList<Attachment> attachments; |
628 | QPtrListIterator<Attachment> it( mAttachments ); | 632 | QPtrListIterator<Attachment> it( mAttachments ); |
629 | Attachment *at; | 633 | Attachment *at; |
630 | while ( (at = it.current()) ) { | 634 | while ( (at = it.current()) ) { |
631 | if (at->mimeType() == mime) | 635 | if (at->mimeType() == mime) |
632 | attachments.append(at); | 636 | attachments.append(at); |
633 | ++it; | 637 | ++it; |
634 | } | 638 | } |
635 | 639 | ||
636 | return attachments; | 640 | return attachments; |
637 | } | 641 | } |
638 | 642 | ||
639 | void Incidence::setResources(const QStringList &resources) | 643 | void Incidence::setResources(const QStringList &resources) |
640 | { | 644 | { |
641 | if (mReadOnly) return; | 645 | if (mReadOnly) return; |
642 | mResources = resources; | 646 | mResources = resources; |
643 | updated(); | 647 | updated(); |
644 | } | 648 | } |
645 | 649 | ||
646 | QStringList Incidence::resources() const | 650 | QStringList Incidence::resources() const |
647 | { | 651 | { |
648 | return mResources; | 652 | return mResources; |
649 | } | 653 | } |
650 | 654 | ||
651 | 655 | ||
652 | void Incidence::setPriority(int priority) | 656 | void Incidence::setPriority(int priority) |
653 | { | 657 | { |
654 | if (mReadOnly) return; | 658 | if (mReadOnly) return; |
655 | mPriority = priority; | 659 | mPriority = priority; |
656 | updated(); | 660 | updated(); |
657 | } | 661 | } |
658 | 662 | ||
659 | int Incidence::priority() const | 663 | int Incidence::priority() const |
660 | { | 664 | { |
661 | return mPriority; | 665 | return mPriority; |
662 | } | 666 | } |
663 | 667 | ||
664 | void Incidence::setSecrecy(int sec) | 668 | void Incidence::setSecrecy(int sec) |
665 | { | 669 | { |
666 | if (mReadOnly) return; | 670 | if (mReadOnly) return; |
667 | mSecrecy = sec; | 671 | mSecrecy = sec; |
668 | updated(); | 672 | updated(); |
669 | } | 673 | } |
670 | 674 | ||
671 | int Incidence::secrecy() const | 675 | int Incidence::secrecy() const |
672 | { | 676 | { |
673 | return mSecrecy; | 677 | return mSecrecy; |
674 | } | 678 | } |
675 | 679 | ||
676 | QString Incidence::secrecyStr() const | 680 | QString Incidence::secrecyStr() const |
677 | { | 681 | { |
678 | return secrecyName(mSecrecy); | 682 | return secrecyName(mSecrecy); |
679 | } | 683 | } |
680 | 684 | ||
681 | QString Incidence::secrecyName(int secrecy) | 685 | QString Incidence::secrecyName(int secrecy) |
682 | { | 686 | { |
683 | switch (secrecy) { | 687 | switch (secrecy) { |
684 | case SecrecyPublic: | 688 | case SecrecyPublic: |
685 | return i18n("Public"); | 689 | return i18n("Public"); |
686 | break; | 690 | break; |
687 | case SecrecyPrivate: | 691 | case SecrecyPrivate: |
688 | return i18n("Private"); | 692 | return i18n("Private"); |
689 | break; | 693 | break; |
690 | case SecrecyConfidential: | 694 | case SecrecyConfidential: |
691 | return i18n("Confidential"); | 695 | return i18n("Confidential"); |
692 | break; | 696 | break; |
693 | default: | 697 | default: |
694 | return i18n("Undefined"); | 698 | return i18n("Undefined"); |
695 | break; | 699 | break; |
696 | } | 700 | } |
697 | } | 701 | } |
698 | 702 | ||
699 | QStringList Incidence::secrecyList() | 703 | QStringList Incidence::secrecyList() |
700 | { | 704 | { |
701 | QStringList list; | 705 | QStringList list; |
702 | list << secrecyName(SecrecyPublic); | 706 | list << secrecyName(SecrecyPublic); |
703 | list << secrecyName(SecrecyPrivate); | 707 | list << secrecyName(SecrecyPrivate); |
704 | list << secrecyName(SecrecyConfidential); | 708 | list << secrecyName(SecrecyConfidential); |
705 | 709 | ||
706 | return list; | 710 | return list; |
707 | } | 711 | } |
708 | 712 | ||
709 | 713 | ||
710 | QPtrList<Alarm> Incidence::alarms() const | 714 | QPtrList<Alarm> Incidence::alarms() const |
711 | { | 715 | { |
712 | return mAlarms; | 716 | return mAlarms; |
713 | } | 717 | } |
714 | 718 | ||
715 | Alarm* Incidence::newAlarm() | 719 | Alarm* Incidence::newAlarm() |
716 | { | 720 | { |
717 | Alarm* alarm = new Alarm(this); | 721 | Alarm* alarm = new Alarm(this); |
718 | mAlarms.append(alarm); | 722 | mAlarms.append(alarm); |
719 | // updated(); | 723 | // updated(); |
720 | return alarm; | 724 | return alarm; |
721 | } | 725 | } |
722 | 726 | ||
723 | void Incidence::addAlarm(Alarm *alarm) | 727 | void Incidence::addAlarm(Alarm *alarm) |
724 | { | 728 | { |
725 | mAlarms.append(alarm); | 729 | mAlarms.append(alarm); |
726 | updated(); | 730 | updated(); |
727 | } | 731 | } |
728 | 732 | ||
729 | void Incidence::removeAlarm(Alarm *alarm) | 733 | void Incidence::removeAlarm(Alarm *alarm) |
730 | { | 734 | { |
731 | mAlarms.removeRef(alarm); | 735 | mAlarms.removeRef(alarm); |
732 | updated(); | 736 | updated(); |
733 | } | 737 | } |
734 | 738 | ||
735 | void Incidence::clearAlarms() | 739 | void Incidence::clearAlarms() |
736 | { | 740 | { |
737 | mAlarms.clear(); | 741 | mAlarms.clear(); |
738 | updated(); | 742 | updated(); |
739 | } | 743 | } |
740 | 744 | ||
741 | bool Incidence::isAlarmEnabled() const | 745 | bool Incidence::isAlarmEnabled() const |
742 | { | 746 | { |
743 | Alarm* alarm; | 747 | Alarm* alarm; |
744 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 748 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
745 | if (alarm->enabled()) | 749 | if (alarm->enabled()) |
746 | return true; | 750 | return true; |
747 | } | 751 | } |
748 | return false; | 752 | return false; |
749 | } | 753 | } |
750 | #include <stdlib.h> | 754 | #include <stdlib.h> |
751 | Recurrence *Incidence::recurrence() | 755 | Recurrence *Incidence::recurrence() |
752 | { | 756 | { |
753 | if ( ! mRecurrence ) { | 757 | if ( ! mRecurrence ) { |
754 | mRecurrence = new Recurrence(this); | 758 | mRecurrence = new Recurrence(this); |
755 | mRecurrence->setRecurStart( dtStart() ); | 759 | mRecurrence->setRecurStart( dtStart() ); |
756 | //qDebug("creating new recurence "); | 760 | //qDebug("creating new recurence "); |
757 | //abort(); | 761 | //abort(); |
758 | } | 762 | } |
759 | return mRecurrence; | 763 | return mRecurrence; |
760 | } | 764 | } |
761 | void Incidence::setRecurrence( Recurrence * r) | 765 | void Incidence::setRecurrence( Recurrence * r) |
762 | { | 766 | { |
763 | if ( mRecurrence ) | 767 | if ( mRecurrence ) |
764 | delete mRecurrence; | 768 | delete mRecurrence; |
765 | mRecurrence = r; | 769 | mRecurrence = r; |
766 | } | 770 | } |
767 | 771 | ||
768 | void Incidence::setLocation(const QString &location) | 772 | void Incidence::setLocation(const QString &location) |
769 | { | 773 | { |
770 | if (mReadOnly) return; | 774 | if (mReadOnly) return; |
771 | mLocation = location; | 775 | mLocation = location; |
772 | updated(); | 776 | updated(); |
773 | } | 777 | } |
774 | 778 | ||
775 | QString Incidence::location() const | 779 | QString Incidence::location() const |
776 | { | 780 | { |
777 | return mLocation; | 781 | return mLocation; |
778 | } | 782 | } |
779 | QString Incidence::recurrenceText() const | 783 | QString Incidence::recurrenceText() const |
780 | { | 784 | { |
781 | if ( mRecurrence ) return mRecurrence->recurrenceText(); | 785 | if ( mRecurrence ) return mRecurrence->recurrenceText(); |
782 | return i18n("No"); | 786 | return i18n("No"); |
783 | } | 787 | } |
784 | 788 | ||
785 | ushort Incidence::doesRecur() const | 789 | ushort Incidence::doesRecur() const |
786 | { | 790 | { |
787 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 791 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
788 | else return Recurrence::rNone; | 792 | else return Recurrence::rNone; |
789 | } | 793 | } |
790 | 794 | ||
791 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 795 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
792 | { | 796 | { |
793 | QDateTime incidenceStart = dt; | 797 | QDateTime incidenceStart = dt; |
794 | *ok = false; | 798 | *ok = false; |
795 | if ( doesRecur() ) { | 799 | if ( doesRecur() ) { |
796 | bool last; | 800 | bool last; |
797 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); | 801 | mRecurrence->getPreviousDateTime( incidenceStart , &last ); |
798 | int count = 0; | 802 | int count = 0; |
799 | if ( !last ) { | 803 | if ( !last ) { |
800 | while ( !last ) { | 804 | while ( !last ) { |
801 | ++count; | 805 | ++count; |
802 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); | 806 | incidenceStart = mRecurrence->getNextDateTime( incidenceStart, &last ); |
803 | if ( recursOn( incidenceStart.date() ) ) { | 807 | if ( recursOn( incidenceStart.date() ) ) { |
804 | last = true; // exit while llop | 808 | last = true; // exit while llop |
805 | } else { | 809 | } else { |
806 | if ( last ) { // no alarm on last recurrence | 810 | if ( last ) { // no alarm on last recurrence |
807 | return QDateTime (); | 811 | return QDateTime (); |
808 | } | 812 | } |
809 | int year = incidenceStart.date().year(); | 813 | int year = incidenceStart.date().year(); |
810 | // workaround for bug in recurrence | 814 | // workaround for bug in recurrence |
811 | if ( count == 100 || year < 1000 || year > 5000 ) { | 815 | if ( count == 100 || year < 1000 || year > 5000 ) { |
812 | return QDateTime (); | 816 | return QDateTime (); |
813 | } | 817 | } |
814 | incidenceStart = incidenceStart.addSecs( 1 ); | 818 | incidenceStart = incidenceStart.addSecs( 1 ); |
815 | } | 819 | } |
816 | } | 820 | } |
817 | } else { | 821 | } else { |
818 | return QDateTime (); | 822 | return QDateTime (); |
819 | } | 823 | } |
820 | } else { | 824 | } else { |
821 | if ( hasStartDate () ) { | 825 | if ( hasStartDate () ) { |
822 | incidenceStart = dtStart(); | 826 | incidenceStart = dtStart(); |
823 | } | 827 | } |
824 | if ( typeID() == todoID ) { | 828 | if ( typeID() == todoID ) { |
825 | if ( ((Todo*)this)->hasDueDate() ) | 829 | if ( ((Todo*)this)->hasDueDate() ) |
826 | incidenceStart = ((Todo*)this)->dtDue(); | 830 | incidenceStart = ((Todo*)this)->dtDue(); |
827 | } | 831 | } |
828 | } | 832 | } |
829 | if ( incidenceStart > dt ) | 833 | if ( incidenceStart > dt ) |
830 | *ok = true; | 834 | *ok = true; |
831 | return incidenceStart; | 835 | return incidenceStart; |
832 | } | 836 | } |
833 | QDateTime Incidence::dtStart() const | 837 | QDateTime Incidence::dtStart() const |
834 | { | 838 | { |
835 | if ( doesRecur() ) { | 839 | if ( doesRecur() ) { |
836 | if ( typeID() == todoID ) { | 840 | if ( typeID() == todoID ) { |
837 | ((Todo*)this)->checkSetCompletedFalse(); | 841 | ((Todo*)this)->checkSetCompletedFalse(); |
838 | } | 842 | } |
839 | } | 843 | } |
840 | return mDtStart; | 844 | return mDtStart; |
841 | } | 845 | } |
diff --git a/libkcal/incidence.h b/libkcal/incidence.h index 88df217..eef9e64 100644 --- a/libkcal/incidence.h +++ b/libkcal/incidence.h | |||
@@ -1,323 +1,324 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | #ifndef INCIDENCE_H | 20 | #ifndef INCIDENCE_H |
21 | #define INCIDENCE_H | 21 | #define INCIDENCE_H |
22 | // | 22 | // |
23 | // Incidence - base class of calendaring components | 23 | // Incidence - base class of calendaring components |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qstringlist.h> | 27 | #include <qstringlist.h> |
28 | #include <qvaluelist.h> | 28 | #include <qvaluelist.h> |
29 | 29 | ||
30 | #include "recurrence.h" | 30 | #include "recurrence.h" |
31 | #include "alarm.h" | 31 | #include "alarm.h" |
32 | #include "attachment.h" | 32 | #include "attachment.h" |
33 | #include "listbase.h" | 33 | #include "listbase.h" |
34 | #include "incidencebase.h" | 34 | #include "incidencebase.h" |
35 | 35 | ||
36 | namespace KCal { | 36 | namespace KCal { |
37 | 37 | ||
38 | class Event; | 38 | class Event; |
39 | class Todo; | 39 | class Todo; |
40 | class Journal; | 40 | class Journal; |
41 | 41 | ||
42 | /** | 42 | /** |
43 | This class provides the base class common to all calendar components. | 43 | This class provides the base class common to all calendar components. |
44 | */ | 44 | */ |
45 | class Incidence : public IncidenceBase | 45 | class Incidence : public IncidenceBase |
46 | { | 46 | { |
47 | public: | 47 | public: |
48 | /** | 48 | /** |
49 | This class provides the interface for a visitor of calendar components. It | 49 | This class provides the interface for a visitor of calendar components. It |
50 | serves as base class for concrete visitors, which implement certain actions on | 50 | serves as base class for concrete visitors, which implement certain actions on |
51 | calendar components. It allows to add functions, which operate on the concrete | 51 | calendar components. It allows to add functions, which operate on the concrete |
52 | types of calendar components, without changing the calendar component classes. | 52 | types of calendar components, without changing the calendar component classes. |
53 | */ | 53 | */ |
54 | class Visitor | 54 | class Visitor |
55 | { | 55 | { |
56 | public: | 56 | public: |
57 | /** Destruct Incidence::Visitor */ | 57 | /** Destruct Incidence::Visitor */ |
58 | virtual ~Visitor() {} | 58 | virtual ~Visitor() {} |
59 | 59 | ||
60 | /** | 60 | /** |
61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 61 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
62 | on an Event object. | 62 | on an Event object. |
63 | */ | 63 | */ |
64 | virtual bool visit(Event *) { return false; } | 64 | virtual bool visit(Event *) { return false; } |
65 | /** | 65 | /** |
66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 66 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
67 | on an Todo object. | 67 | on an Todo object. |
68 | */ | 68 | */ |
69 | virtual bool visit(Todo *) { return false; } | 69 | virtual bool visit(Todo *) { return false; } |
70 | /** | 70 | /** |
71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions | 71 | Reimplement this function in your concrete subclass of IncidenceVisitor to perform actions |
72 | on an Journal object. | 72 | on an Journal object. |
73 | */ | 73 | */ |
74 | virtual bool visit(Journal *) { return false; } | 74 | virtual bool visit(Journal *) { return false; } |
75 | 75 | ||
76 | protected: | 76 | protected: |
77 | /** Constructor is protected to prevent direct creation of visitor base class. */ | 77 | /** Constructor is protected to prevent direct creation of visitor base class. */ |
78 | Visitor() {} | 78 | Visitor() {} |
79 | }; | 79 | }; |
80 | 80 | ||
81 | /** | 81 | /** |
82 | This class implements a visitor for adding an Incidence to a resource | 82 | This class implements a visitor for adding an Incidence to a resource |
83 | supporting addEvent(), addTodo() and addJournal() calls. | 83 | supporting addEvent(), addTodo() and addJournal() calls. |
84 | */ | 84 | */ |
85 | template<class T> | 85 | template<class T> |
86 | class AddVisitor : public Visitor | 86 | class AddVisitor : public Visitor |
87 | { | 87 | { |
88 | public: | 88 | public: |
89 | AddVisitor( T *r ) : mResource( r ) {} | 89 | AddVisitor( T *r ) : mResource( r ) {} |
90 | bool visit( Event *e ) { return mResource->addEvent( e ); } | 90 | bool visit( Event *e ) { return mResource->addEvent( e ); } |
91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } | 91 | bool visit( Todo *t ) { return mResource->addTodo( t ); } |
92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } | 92 | bool visit( Journal *j ) { return mResource->addJournal( j ); } |
93 | 93 | ||
94 | private: | 94 | private: |
95 | T *mResource; | 95 | T *mResource; |
96 | }; | 96 | }; |
97 | 97 | ||
98 | /** enumeration for describing an event's secrecy. */ | 98 | /** enumeration for describing an event's secrecy. */ |
99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; | 99 | enum { SecrecyPublic = 0, SecrecyPrivate = 1, SecrecyConfidential = 2 }; |
100 | typedef ListBase<Incidence> List; | 100 | typedef ListBase<Incidence> List; |
101 | Incidence(); | 101 | Incidence(); |
102 | Incidence(const Incidence &); | 102 | Incidence(const Incidence &); |
103 | ~Incidence(); | 103 | ~Incidence(); |
104 | 104 | ||
105 | /** | 105 | /** |
106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to | 106 | Accept IncidenceVisitor. A class taking part in the visitor mechanism has to |
107 | provide this implementation: | 107 | provide this implementation: |
108 | <pre> | 108 | <pre> |
109 | bool accept(Visitor &v) { return v.visit(this); } | 109 | bool accept(Visitor &v) { return v.visit(this); } |
110 | </pre> | 110 | </pre> |
111 | */ | 111 | */ |
112 | virtual bool accept(Visitor &) { return false; } | 112 | virtual bool accept(Visitor &) { return false; } |
113 | 113 | ||
114 | virtual Incidence *clone() = 0; | 114 | virtual Incidence *clone() = 0; |
115 | virtual void cloneRelations( Incidence * ); | 115 | virtual void cloneRelations( Incidence * ); |
116 | void addRelationsToList(QPtrList<Incidence> *rel); | 116 | void addRelationsToList(QPtrList<Incidence> *rel); |
117 | void clearRelations(); | ||
117 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; | 118 | virtual QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const = 0; |
118 | void setReadOnly( bool ); | 119 | void setReadOnly( bool ); |
119 | 120 | ||
120 | /** | 121 | /** |
121 | Recreate event. The event is made a new unique event, but already stored | 122 | Recreate event. The event is made a new unique event, but already stored |
122 | event information is preserved. Sets uniquie id, creation date, last | 123 | event information is preserved. Sets uniquie id, creation date, last |
123 | modification date and revision number. | 124 | modification date and revision number. |
124 | */ | 125 | */ |
125 | void recreate(); | 126 | void recreate(); |
126 | Incidence* recreateCloneException(QDate); | 127 | Incidence* recreateCloneException(QDate); |
127 | 128 | ||
128 | /** set creation date */ | 129 | /** set creation date */ |
129 | void setCreated(QDateTime); | 130 | void setCreated(QDateTime); |
130 | /** return time and date of creation. */ | 131 | /** return time and date of creation. */ |
131 | QDateTime created() const; | 132 | QDateTime created() const; |
132 | 133 | ||
133 | /** set the number of revisions this event has seen */ | 134 | /** set the number of revisions this event has seen */ |
134 | void setRevision(int rev); | 135 | void setRevision(int rev); |
135 | /** return the number of revisions this event has seen */ | 136 | /** return the number of revisions this event has seen */ |
136 | int revision() const; | 137 | int revision() const; |
137 | 138 | ||
138 | /** Set starting date/time. */ | 139 | /** Set starting date/time. */ |
139 | virtual void setDtStart(const QDateTime &dtStart); | 140 | virtual void setDtStart(const QDateTime &dtStart); |
140 | /** Return the incidence's ending date/time as a QDateTime. */ | 141 | /** Return the incidence's ending date/time as a QDateTime. */ |
141 | virtual QDateTime dtEnd() const { return QDateTime(); } | 142 | virtual QDateTime dtEnd() const { return QDateTime(); } |
142 | 143 | ||
143 | /** sets the event's lengthy description. */ | 144 | /** sets the event's lengthy description. */ |
144 | void setDescription(const QString &description); | 145 | void setDescription(const QString &description); |
145 | /** returns a reference to the event's description. */ | 146 | /** returns a reference to the event's description. */ |
146 | QString description() const; | 147 | QString description() const; |
147 | 148 | ||
148 | /** sets the event's short summary. */ | 149 | /** sets the event's short summary. */ |
149 | void setSummary(const QString &summary); | 150 | void setSummary(const QString &summary); |
150 | /** returns a reference to the event's summary. */ | 151 | /** returns a reference to the event's summary. */ |
151 | QString summary() const; | 152 | QString summary() const; |
152 | 153 | ||
153 | /** set event's applicable categories */ | 154 | /** set event's applicable categories */ |
154 | void setCategories(const QStringList &categories, bool setForRelations = false); | 155 | void setCategories(const QStringList &categories, bool setForRelations = false); |
155 | void addCategories(const QStringList &categories, bool addToRelations = false); | 156 | void addCategories(const QStringList &categories, bool addToRelations = false); |
156 | /** set event's categories based on a comma delimited string */ | 157 | /** set event's categories based on a comma delimited string */ |
157 | void setCategories(const QString &catStr); | 158 | void setCategories(const QString &catStr); |
158 | /** return categories in a list */ | 159 | /** return categories in a list */ |
159 | QStringList categories() const; | 160 | QStringList categories() const; |
160 | QStringList* categoriesP(); | 161 | QStringList* categoriesP(); |
161 | /** return categories as a comma separated string */ | 162 | /** return categories as a comma separated string */ |
162 | QString categoriesStr(); | 163 | QString categoriesStr(); |
163 | QString categoriesStrWithSpace(); | 164 | QString categoriesStrWithSpace(); |
164 | 165 | ||
165 | /** point at some other event to which the event relates. This function should | 166 | /** point at some other event to which the event relates. This function should |
166 | * only be used when constructing a calendar before the related Event | 167 | * only be used when constructing a calendar before the related Event |
167 | * exists. */ | 168 | * exists. */ |
168 | void setRelatedToUid(const QString &); | 169 | void setRelatedToUid(const QString &); |
169 | /** what event does this one relate to? This function should | 170 | /** what event does this one relate to? This function should |
170 | * only be used when constructing a calendar before the related Event | 171 | * only be used when constructing a calendar before the related Event |
171 | * exists. */ | 172 | * exists. */ |
172 | QString relatedToUid() const; | 173 | QString relatedToUid() const; |
173 | /** point at some other event to which the event relates */ | 174 | /** point at some other event to which the event relates */ |
174 | void setRelatedTo(Incidence *relatedTo); | 175 | void setRelatedTo(Incidence *relatedTo); |
175 | /** what event does this one relate to? */ | 176 | /** what event does this one relate to? */ |
176 | Incidence *relatedTo() const; | 177 | Incidence *relatedTo() const; |
177 | /** All events that are related to this event */ | 178 | /** All events that are related to this event */ |
178 | QPtrList<Incidence> relations() const; | 179 | QPtrList<Incidence> relations() const; |
179 | /** Add an event which is related to this event */ | 180 | /** Add an event which is related to this event */ |
180 | void addRelation(Incidence *); | 181 | void addRelation(Incidence *); |
181 | /** Remove event that is related to this event */ | 182 | /** Remove event that is related to this event */ |
182 | void removeRelation(Incidence *); | 183 | void removeRelation(Incidence *); |
183 | 184 | ||
184 | /** returns the list of dates which are exceptions to the recurrence rule */ | 185 | /** returns the list of dates which are exceptions to the recurrence rule */ |
185 | DateList exDates() const; | 186 | DateList exDates() const; |
186 | /** sets the list of dates which are exceptions to the recurrence rule */ | 187 | /** sets the list of dates which are exceptions to the recurrence rule */ |
187 | void setExDates(const DateList &_exDates); | 188 | void setExDates(const DateList &_exDates); |
188 | void setExDates(const char *dates); | 189 | void setExDates(const char *dates); |
189 | /** Add a date to the list of exceptions of the recurrence rule. */ | 190 | /** Add a date to the list of exceptions of the recurrence rule. */ |
190 | void addExDate(const QDate &date); | 191 | void addExDate(const QDate &date); |
191 | 192 | ||
192 | /** returns true if there is an exception for this date in the recurrence | 193 | /** returns true if there is an exception for this date in the recurrence |
193 | rule set, or false otherwise. */ | 194 | rule set, or false otherwise. */ |
194 | bool isException(const QDate &qd) const; | 195 | bool isException(const QDate &qd) const; |
195 | 196 | ||
196 | /** add attachment to this event */ | 197 | /** add attachment to this event */ |
197 | void addAttachment(Attachment *attachment); | 198 | void addAttachment(Attachment *attachment); |
198 | /** remove and delete a specific attachment */ | 199 | /** remove and delete a specific attachment */ |
199 | void deleteAttachment(Attachment *attachment); | 200 | void deleteAttachment(Attachment *attachment); |
200 | /** remove and delete all attachments with this mime type */ | 201 | /** remove and delete all attachments with this mime type */ |
201 | void deleteAttachments(const QString& mime); | 202 | void deleteAttachments(const QString& mime); |
202 | /** return list of all associated attachments */ | 203 | /** return list of all associated attachments */ |
203 | QPtrList<Attachment> attachments() const; | 204 | QPtrList<Attachment> attachments() const; |
204 | /** find a list of attachments with this mime type */ | 205 | /** find a list of attachments with this mime type */ |
205 | QPtrList<Attachment> attachments(const QString& mime) const; | 206 | QPtrList<Attachment> attachments(const QString& mime) const; |
206 | 207 | ||
207 | /** sets the event's status the value specified. See the enumeration | 208 | /** sets the event's status the value specified. See the enumeration |
208 | * above for possible values. */ | 209 | * above for possible values. */ |
209 | void setSecrecy(int); | 210 | void setSecrecy(int); |
210 | /** return the event's secrecy. */ | 211 | /** return the event's secrecy. */ |
211 | int secrecy() const; | 212 | int secrecy() const; |
212 | /** return the event's secrecy in string format. */ | 213 | /** return the event's secrecy in string format. */ |
213 | QString secrecyStr() const; | 214 | QString secrecyStr() const; |
214 | /** return list of all availbale secrecy classes */ | 215 | /** return list of all availbale secrecy classes */ |
215 | static QStringList secrecyList(); | 216 | static QStringList secrecyList(); |
216 | /** return human-readable name of secrecy class */ | 217 | /** return human-readable name of secrecy class */ |
217 | static QString secrecyName(int); | 218 | static QString secrecyName(int); |
218 | 219 | ||
219 | /** returns TRUE if the date specified is one on which the event will | 220 | /** returns TRUE if the date specified is one on which the event will |
220 | * recur. */ | 221 | * recur. */ |
221 | bool recursOn(const QDate &qd) const; | 222 | bool recursOn(const QDate &qd) const; |
222 | 223 | ||
223 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): | 224 | // VEVENT and VTODO, but not VJOURNAL (move to EventBase class?): |
224 | 225 | ||
225 | /** set resources used, such as Office, Car, etc. */ | 226 | /** set resources used, such as Office, Car, etc. */ |
226 | void setResources(const QStringList &resources); | 227 | void setResources(const QStringList &resources); |
227 | /** return list of current resources */ | 228 | /** return list of current resources */ |
228 | QStringList resources() const; | 229 | QStringList resources() const; |
229 | 230 | ||
230 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ | 231 | /** set the event's priority, 0 is undefined, 1 highest (decreasing order) */ |
231 | void setPriority(int priority); | 232 | void setPriority(int priority); |
232 | /** get the event's priority */ | 233 | /** get the event's priority */ |
233 | int priority() const; | 234 | int priority() const; |
234 | 235 | ||
235 | /** All alarms that are associated with this incidence */ | 236 | /** All alarms that are associated with this incidence */ |
236 | QPtrList<Alarm> alarms() const; | 237 | QPtrList<Alarm> alarms() const; |
237 | /** Create a new alarm which is associated with this incidence */ | 238 | /** Create a new alarm which is associated with this incidence */ |
238 | Alarm* newAlarm(); | 239 | Alarm* newAlarm(); |
239 | /** Add an alarm which is associated with this incidence */ | 240 | /** Add an alarm which is associated with this incidence */ |
240 | void addAlarm(Alarm*); | 241 | void addAlarm(Alarm*); |
241 | /** Remove an alarm that is associated with this incidence */ | 242 | /** Remove an alarm that is associated with this incidence */ |
242 | void removeAlarm(Alarm*); | 243 | void removeAlarm(Alarm*); |
243 | /** Remove all alarms that are associated with this incidence */ | 244 | /** Remove all alarms that are associated with this incidence */ |
244 | void clearAlarms(); | 245 | void clearAlarms(); |
245 | /** return whether any alarm associated with this incidence is enabled */ | 246 | /** return whether any alarm associated with this incidence is enabled */ |
246 | bool isAlarmEnabled() const; | 247 | bool isAlarmEnabled() const; |
247 | 248 | ||
248 | /** | 249 | /** |
249 | Return the recurrence rule associated with this incidence. If there is | 250 | Return the recurrence rule associated with this incidence. If there is |
250 | none, returns an appropriate (non-0) object. | 251 | none, returns an appropriate (non-0) object. |
251 | */ | 252 | */ |
252 | Recurrence *recurrence(); | 253 | Recurrence *recurrence(); |
253 | void setRecurrence(Recurrence * r); | 254 | void setRecurrence(Recurrence * r); |
254 | /** | 255 | /** |
255 | Forward to Recurrence::doesRecur(). | 256 | Forward to Recurrence::doesRecur(). |
256 | */ | 257 | */ |
257 | ushort doesRecur() const; | 258 | ushort doesRecur() const; |
258 | 259 | ||
259 | /** set the event's/todo's location. Do _not_ use it with journal */ | 260 | /** set the event's/todo's location. Do _not_ use it with journal */ |
260 | void setLocation(const QString &location); | 261 | void setLocation(const QString &location); |
261 | /** return the event's/todo's location. Do _not_ use it with journal */ | 262 | /** return the event's/todo's location. Do _not_ use it with journal */ |
262 | QString location() const; | 263 | QString location() const; |
263 | /** returns TRUE or FALSE depending on whether the todo has a start date */ | 264 | /** returns TRUE or FALSE depending on whether the todo has a start date */ |
264 | bool hasStartDate() const; | 265 | bool hasStartDate() const; |
265 | /** sets the event's hasStartDate value. */ | 266 | /** sets the event's hasStartDate value. */ |
266 | void setHasStartDate(bool f); | 267 | void setHasStartDate(bool f); |
267 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; | 268 | QDateTime getNextOccurence( const QDateTime& dt, bool* yes ) const; |
268 | bool cancelled() const; | 269 | bool cancelled() const; |
269 | void setCancelled( bool b ); | 270 | void setCancelled( bool b ); |
270 | 271 | ||
271 | bool hasRecurrenceID() const; | 272 | bool hasRecurrenceID() const; |
272 | void setHasRecurrenceID( bool b ); | 273 | void setHasRecurrenceID( bool b ); |
273 | 274 | ||
274 | void setRecurrenceID(QDateTime); | 275 | void setRecurrenceID(QDateTime); |
275 | QDateTime recurrenceID () const; | 276 | QDateTime recurrenceID () const; |
276 | QDateTime dtStart() const; | 277 | QDateTime dtStart() const; |
277 | bool isHoliday() const; | 278 | bool isHoliday() const; |
278 | bool isBirthday() const; | 279 | bool isBirthday() const; |
279 | bool isAnniversary() const; | 280 | bool isAnniversary() const; |
280 | QDateTime lastModifiedSub(); | 281 | QDateTime lastModifiedSub(); |
281 | QString recurrenceText() const; | 282 | QString recurrenceText() const; |
282 | void setLastModifiedSubInvalid(); | 283 | void setLastModifiedSubInvalid(); |
283 | 284 | ||
284 | virtual QString durationText(); | 285 | virtual QString durationText(); |
285 | QString durationText4Time( int secs ); | 286 | QString durationText4Time( int secs ); |
286 | Recurrence *mRecurrence; | 287 | Recurrence *mRecurrence; |
287 | protected: | 288 | protected: |
288 | QPtrList<Alarm> mAlarms; | 289 | QPtrList<Alarm> mAlarms; |
289 | QPtrList<Incidence> mRelations; | 290 | QPtrList<Incidence> mRelations; |
290 | QDateTime mRecurrenceID; | 291 | QDateTime mRecurrenceID; |
291 | bool mHasRecurrenceID; | 292 | bool mHasRecurrenceID; |
292 | private: | 293 | private: |
293 | void checkCategories(); | 294 | void checkCategories(); |
294 | bool mHoliday, mBirthday, mAnniversary; | 295 | bool mHoliday, mBirthday, mAnniversary; |
295 | int mRevision; | 296 | int mRevision; |
296 | bool mCancelled; | 297 | bool mCancelled; |
297 | 298 | ||
298 | // base components of jounal, event and todo | 299 | // base components of jounal, event and todo |
299 | QDateTime mCreated; | 300 | QDateTime mCreated; |
300 | QDateTime mLastModifiedSub; | 301 | QDateTime mLastModifiedSub; |
301 | QString mDescription; | 302 | QString mDescription; |
302 | QString mSummary; | 303 | QString mSummary; |
303 | QStringList mCategories; | 304 | QStringList mCategories; |
304 | Incidence *mRelatedTo; | 305 | Incidence *mRelatedTo; |
305 | QString mRelatedToUid; | 306 | QString mRelatedToUid; |
306 | DateList mExDates; | 307 | DateList mExDates; |
307 | QPtrList<Attachment> mAttachments; | 308 | QPtrList<Attachment> mAttachments; |
308 | QStringList mResources; | 309 | QStringList mResources; |
309 | bool mHasStartDate; // if todo has associated start date | 310 | bool mHasStartDate; // if todo has associated start date |
310 | 311 | ||
311 | int mSecrecy; | 312 | int mSecrecy; |
312 | int mPriority; // 1 = highest, 2 = less, etc. | 313 | int mPriority; // 1 = highest, 2 = less, etc. |
313 | 314 | ||
314 | //QPtrList<Alarm> mAlarms; | 315 | //QPtrList<Alarm> mAlarms; |
315 | 316 | ||
316 | QString mLocation; | 317 | QString mLocation; |
317 | }; | 318 | }; |
318 | 319 | ||
319 | bool operator==( const Incidence&, const Incidence& ); | 320 | bool operator==( const Incidence&, const Incidence& ); |
320 | 321 | ||
321 | } | 322 | } |
322 | 323 | ||
323 | #endif | 324 | #endif |