-rw-r--r-- | libkcal/calendar.cpp | 6 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 6 | ||||
-rw-r--r-- | libkcal/calfilter.cpp | 6 | ||||
-rw-r--r-- | libkcal/event.h | 1 | ||||
-rw-r--r-- | libkcal/freebusy.h | 1 | ||||
-rw-r--r-- | libkcal/icalformat.cpp | 4 | ||||
-rw-r--r-- | libkcal/icalformatimpl.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidence.cpp | 6 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 2 | ||||
-rw-r--r-- | libkcal/journal.h | 1 | ||||
-rw-r--r-- | libkcal/kincidenceformatter.cpp | 4 | ||||
-rw-r--r-- | libkcal/todo.cpp | 5 | ||||
-rw-r--r-- | libkcal/todo.h | 1 |
13 files changed, 26 insertions, 23 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index ed39ddb..7e8e2c5 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,475 +1,475 @@ | |||
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 | mModified = false; | 56 | mModified = false; |
57 | 57 | ||
58 | // Setup default filter, which does nothing | 58 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 59 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 60 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 61 | mFilter->setEnabled(false); |
62 | 62 | ||
63 | // initialize random numbers. This is a hack, and not | 63 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 64 | // even that good of one at that. |
65 | // srandom(time(0)); | 65 | // srandom(time(0)); |
66 | 66 | ||
67 | // user information... | 67 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 68 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 69 | setEmail(i18n("unknown@nowhere")); |
70 | 70 | ||
71 | #if 0 | 71 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 72 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 75 | extern long int timezone; |
76 | struct tm *now; | 76 | struct tm *now; |
77 | time_t curtime; | 77 | time_t curtime; |
78 | curtime = time(0); | 78 | curtime = time(0); |
79 | now = localtime(&curtime); | 79 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 80 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 81 | if (now->tm_isdst) |
82 | hourOff += 1; | 82 | hourOff += 1; |
83 | QString tzStr; | 83 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 84 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 85 | hourOff, |
86 | abs((timezone / 60) % 60)); | 86 | abs((timezone / 60) % 60)); |
87 | 87 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 88 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 89 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 90 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 91 | } else { |
92 | tzStr = tmpStr; | 92 | tzStr = tmpStr; |
93 | } | 93 | } |
94 | 94 | ||
95 | // if daylight savings has changed since last load time, we need | 95 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 96 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 97 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 98 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 99 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 101 | } |
102 | 102 | ||
103 | setTimeZone(tzStr); | 103 | setTimeZone(tzStr); |
104 | #endif | 104 | #endif |
105 | 105 | ||
106 | // KOPrefs::instance()->writeConfig(); | 106 | // KOPrefs::instance()->writeConfig(); |
107 | } | 107 | } |
108 | 108 | ||
109 | Calendar::~Calendar() | 109 | Calendar::~Calendar() |
110 | { | 110 | { |
111 | delete mDefaultFilter; | 111 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | 112 | if ( mUndoIncidence ) |
113 | delete mUndoIncidence; | 113 | delete mUndoIncidence; |
114 | } | 114 | } |
115 | 115 | ||
116 | const QString &Calendar::getOwner() const | 116 | const QString &Calendar::getOwner() const |
117 | { | 117 | { |
118 | return mOwner; | 118 | return mOwner; |
119 | } | 119 | } |
120 | 120 | ||
121 | bool Calendar::undoDeleteIncidence() | 121 | bool Calendar::undoDeleteIncidence() |
122 | { | 122 | { |
123 | if (!mUndoIncidence) | 123 | if (!mUndoIncidence) |
124 | return false; | 124 | return false; |
125 | addIncidence(mUndoIncidence); | 125 | addIncidence(mUndoIncidence); |
126 | mUndoIncidence = 0; | 126 | mUndoIncidence = 0; |
127 | return true; | 127 | return true; |
128 | } | 128 | } |
129 | void Calendar::setOwner(const QString &os) | 129 | void Calendar::setOwner(const QString &os) |
130 | { | 130 | { |
131 | int i; | 131 | int i; |
132 | mOwner = os; | 132 | mOwner = os; |
133 | i = mOwner.find(','); | 133 | i = mOwner.find(','); |
134 | if (i != -1) | 134 | if (i != -1) |
135 | mOwner = mOwner.left(i); | 135 | mOwner = mOwner.left(i); |
136 | 136 | ||
137 | setModified( true ); | 137 | setModified( true ); |
138 | } | 138 | } |
139 | 139 | ||
140 | void Calendar::setTimeZone(const QString & tz) | 140 | void Calendar::setTimeZone(const QString & tz) |
141 | { | 141 | { |
142 | bool neg = FALSE; | 142 | bool neg = FALSE; |
143 | int hours, minutes; | 143 | int hours, minutes; |
144 | QString tmpStr(tz); | 144 | QString tmpStr(tz); |
145 | 145 | ||
146 | if (tmpStr.left(1) == "-") | 146 | if (tmpStr.left(1) == "-") |
147 | neg = TRUE; | 147 | neg = TRUE; |
148 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 148 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
149 | tmpStr.remove(0, 1); | 149 | tmpStr.remove(0, 1); |
150 | hours = tmpStr.left(2).toInt(); | 150 | hours = tmpStr.left(2).toInt(); |
151 | if (tmpStr.length() > 2) | 151 | if (tmpStr.length() > 2) |
152 | minutes = tmpStr.right(2).toInt(); | 152 | minutes = tmpStr.right(2).toInt(); |
153 | else | 153 | else |
154 | minutes = 0; | 154 | minutes = 0; |
155 | mTimeZone = (60*hours+minutes); | 155 | mTimeZone = (60*hours+minutes); |
156 | if (neg) | 156 | if (neg) |
157 | mTimeZone = -mTimeZone; | 157 | mTimeZone = -mTimeZone; |
158 | mLocalTime = false; | 158 | mLocalTime = false; |
159 | 159 | ||
160 | setModified( true ); | 160 | setModified( true ); |
161 | } | 161 | } |
162 | 162 | ||
163 | QString Calendar::getTimeZoneStr() const | 163 | QString Calendar::getTimeZoneStr() const |
164 | { | 164 | { |
165 | if (mLocalTime) | 165 | if (mLocalTime) |
166 | return ""; | 166 | return ""; |
167 | QString tmpStr; | 167 | QString tmpStr; |
168 | int hours = abs(mTimeZone / 60); | 168 | int hours = abs(mTimeZone / 60); |
169 | int minutes = abs(mTimeZone % 60); | 169 | int minutes = abs(mTimeZone % 60); |
170 | bool neg = mTimeZone < 0; | 170 | bool neg = mTimeZone < 0; |
171 | 171 | ||
172 | tmpStr.sprintf("%c%.2d%.2d", | 172 | tmpStr.sprintf("%c%.2d%.2d", |
173 | (neg ? '-' : '+'), | 173 | (neg ? '-' : '+'), |
174 | hours, minutes); | 174 | hours, minutes); |
175 | return tmpStr; | 175 | return tmpStr; |
176 | } | 176 | } |
177 | 177 | ||
178 | void Calendar::setTimeZone(int tz) | 178 | void Calendar::setTimeZone(int tz) |
179 | { | 179 | { |
180 | mTimeZone = tz; | 180 | mTimeZone = tz; |
181 | mLocalTime = false; | 181 | mLocalTime = false; |
182 | 182 | ||
183 | setModified( true ); | 183 | setModified( true ); |
184 | } | 184 | } |
185 | 185 | ||
186 | int Calendar::getTimeZone() const | 186 | int Calendar::getTimeZone() const |
187 | { | 187 | { |
188 | return mTimeZone; | 188 | return mTimeZone; |
189 | } | 189 | } |
190 | 190 | ||
191 | void Calendar::setTimeZoneId(const QString &id) | 191 | void Calendar::setTimeZoneId(const QString &id) |
192 | { | 192 | { |
193 | mTimeZoneId = id; | 193 | mTimeZoneId = id; |
194 | mLocalTime = false; | 194 | mLocalTime = false; |
195 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 195 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
196 | if ( mTimeZone > 1000) | 196 | if ( mTimeZone > 1000) |
197 | setLocalTime(); | 197 | setLocalTime(); |
198 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 198 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
199 | setModified( true ); | 199 | setModified( true ); |
200 | } | 200 | } |
201 | 201 | ||
202 | QString Calendar::timeZoneId() const | 202 | QString Calendar::timeZoneId() const |
203 | { | 203 | { |
204 | return mTimeZoneId; | 204 | return mTimeZoneId; |
205 | } | 205 | } |
206 | 206 | ||
207 | void Calendar::setLocalTime() | 207 | void Calendar::setLocalTime() |
208 | { | 208 | { |
209 | //qDebug("Calendar::setLocalTime() "); | 209 | //qDebug("Calendar::setLocalTime() "); |
210 | mLocalTime = true; | 210 | mLocalTime = true; |
211 | mTimeZone = 0; | 211 | mTimeZone = 0; |
212 | mTimeZoneId = ""; | 212 | mTimeZoneId = ""; |
213 | 213 | ||
214 | setModified( true ); | 214 | setModified( true ); |
215 | } | 215 | } |
216 | 216 | ||
217 | bool Calendar::isLocalTime() const | 217 | bool Calendar::isLocalTime() const |
218 | { | 218 | { |
219 | return mLocalTime; | 219 | return mLocalTime; |
220 | } | 220 | } |
221 | 221 | ||
222 | const QString &Calendar::getEmail() | 222 | const QString &Calendar::getEmail() |
223 | { | 223 | { |
224 | return mOwnerEmail; | 224 | return mOwnerEmail; |
225 | } | 225 | } |
226 | 226 | ||
227 | void Calendar::setEmail(const QString &e) | 227 | void Calendar::setEmail(const QString &e) |
228 | { | 228 | { |
229 | mOwnerEmail = e; | 229 | mOwnerEmail = e; |
230 | 230 | ||
231 | setModified( true ); | 231 | setModified( true ); |
232 | } | 232 | } |
233 | 233 | ||
234 | void Calendar::setFilter(CalFilter *filter) | 234 | void Calendar::setFilter(CalFilter *filter) |
235 | { | 235 | { |
236 | mFilter = filter; | 236 | mFilter = filter; |
237 | } | 237 | } |
238 | 238 | ||
239 | CalFilter *Calendar::filter() | 239 | CalFilter *Calendar::filter() |
240 | { | 240 | { |
241 | return mFilter; | 241 | return mFilter; |
242 | } | 242 | } |
243 | 243 | ||
244 | QPtrList<Incidence> Calendar::incidences() | 244 | QPtrList<Incidence> Calendar::incidences() |
245 | { | 245 | { |
246 | QPtrList<Incidence> incidences; | 246 | QPtrList<Incidence> incidences; |
247 | 247 | ||
248 | Incidence *i; | 248 | Incidence *i; |
249 | 249 | ||
250 | QPtrList<Event> e = events(); | 250 | QPtrList<Event> e = events(); |
251 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 251 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
252 | 252 | ||
253 | QPtrList<Todo> t = todos(); | 253 | QPtrList<Todo> t = todos(); |
254 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 254 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
255 | 255 | ||
256 | QPtrList<Journal> j = journals(); | 256 | QPtrList<Journal> j = journals(); |
257 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 257 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
258 | 258 | ||
259 | return incidences; | 259 | return incidences; |
260 | } | 260 | } |
261 | 261 | ||
262 | void Calendar::resetPilotStat(int id ) | 262 | void Calendar::resetPilotStat(int id ) |
263 | { | 263 | { |
264 | QPtrList<Incidence> incidences; | 264 | QPtrList<Incidence> incidences; |
265 | 265 | ||
266 | Incidence *i; | 266 | Incidence *i; |
267 | 267 | ||
268 | QPtrList<Event> e = rawEvents(); | 268 | QPtrList<Event> e = rawEvents(); |
269 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 269 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
270 | 270 | ||
271 | QPtrList<Todo> t = rawTodos(); | 271 | QPtrList<Todo> t = rawTodos(); |
272 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 272 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
273 | 273 | ||
274 | QPtrList<Journal> j = journals(); | 274 | QPtrList<Journal> j = journals(); |
275 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 275 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
276 | } | 276 | } |
277 | void Calendar::resetTempSyncStat() | 277 | void Calendar::resetTempSyncStat() |
278 | { | 278 | { |
279 | QPtrList<Incidence> incidences; | 279 | QPtrList<Incidence> incidences; |
280 | 280 | ||
281 | Incidence *i; | 281 | Incidence *i; |
282 | 282 | ||
283 | QPtrList<Event> e = rawEvents(); | 283 | QPtrList<Event> e = rawEvents(); |
284 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 284 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
285 | 285 | ||
286 | QPtrList<Todo> t = rawTodos(); | 286 | QPtrList<Todo> t = rawTodos(); |
287 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 287 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
288 | 288 | ||
289 | QPtrList<Journal> j = journals(); | 289 | QPtrList<Journal> j = journals(); |
290 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 290 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
291 | } | 291 | } |
292 | QPtrList<Incidence> Calendar::rawIncidences() | 292 | QPtrList<Incidence> Calendar::rawIncidences() |
293 | { | 293 | { |
294 | QPtrList<Incidence> incidences; | 294 | QPtrList<Incidence> incidences; |
295 | 295 | ||
296 | Incidence *i; | 296 | Incidence *i; |
297 | 297 | ||
298 | QPtrList<Event> e = rawEvents(); | 298 | QPtrList<Event> e = rawEvents(); |
299 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 299 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
300 | 300 | ||
301 | QPtrList<Todo> t = rawTodos(); | 301 | QPtrList<Todo> t = rawTodos(); |
302 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 302 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
303 | 303 | ||
304 | QPtrList<Journal> j = journals(); | 304 | QPtrList<Journal> j = journals(); |
305 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 305 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
306 | 306 | ||
307 | return incidences; | 307 | return incidences; |
308 | } | 308 | } |
309 | 309 | ||
310 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 310 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
311 | { | 311 | { |
312 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 312 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
313 | mFilter->apply(&el); | 313 | mFilter->apply(&el); |
314 | return el; | 314 | return el; |
315 | } | 315 | } |
316 | 316 | ||
317 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 317 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
318 | { | 318 | { |
319 | QPtrList<Event> el = rawEventsForDate(qdt); | 319 | QPtrList<Event> el = rawEventsForDate(qdt); |
320 | mFilter->apply(&el); | 320 | mFilter->apply(&el); |
321 | return el; | 321 | return el; |
322 | } | 322 | } |
323 | 323 | ||
324 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 324 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
325 | bool inclusive) | 325 | bool inclusive) |
326 | { | 326 | { |
327 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 327 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
328 | mFilter->apply(&el); | 328 | mFilter->apply(&el); |
329 | return el; | 329 | return el; |
330 | } | 330 | } |
331 | 331 | ||
332 | QPtrList<Event> Calendar::events() | 332 | QPtrList<Event> Calendar::events() |
333 | { | 333 | { |
334 | QPtrList<Event> el = rawEvents(); | 334 | QPtrList<Event> el = rawEvents(); |
335 | mFilter->apply(&el); | 335 | mFilter->apply(&el); |
336 | return el; | 336 | return el; |
337 | } | 337 | } |
338 | void Calendar::addIncidenceBranch(Incidence *i) | 338 | void Calendar::addIncidenceBranch(Incidence *i) |
339 | { | 339 | { |
340 | addIncidence( i ); | 340 | addIncidence( i ); |
341 | Incidence * inc; | 341 | Incidence * inc; |
342 | QPtrList<Incidence> Relations = i->relations(); | 342 | QPtrList<Incidence> Relations = i->relations(); |
343 | for (inc=Relations.first();inc;inc=Relations.next()) { | 343 | for (inc=Relations.first();inc;inc=Relations.next()) { |
344 | addIncidenceBranch( inc ); | 344 | addIncidenceBranch( inc ); |
345 | } | 345 | } |
346 | } | 346 | } |
347 | 347 | ||
348 | bool Calendar::addIncidence(Incidence *i) | 348 | bool Calendar::addIncidence(Incidence *i) |
349 | { | 349 | { |
350 | Incidence::AddVisitor<Calendar> v(this); | 350 | Incidence::AddVisitor<Calendar> v(this); |
351 | 351 | ||
352 | return i->accept(v); | 352 | return i->accept(v); |
353 | } | 353 | } |
354 | void Calendar::deleteIncidence(Incidence *in) | 354 | void Calendar::deleteIncidence(Incidence *in) |
355 | { | 355 | { |
356 | if ( in->type() == "Event" ) | 356 | if ( in->typeID() == eventID ) |
357 | deleteEvent( (Event*) in ); | 357 | deleteEvent( (Event*) in ); |
358 | else if ( in->type() =="Todo" ) | 358 | else if ( in->typeID() == todoID ) |
359 | deleteTodo( (Todo*) in); | 359 | deleteTodo( (Todo*) in); |
360 | else if ( in->type() =="Journal" ) | 360 | else if ( in->typeID() == journalID ) |
361 | deleteJournal( (Journal*) in ); | 361 | deleteJournal( (Journal*) in ); |
362 | } | 362 | } |
363 | 363 | ||
364 | Incidence* Calendar::incidence( const QString& uid ) | 364 | Incidence* Calendar::incidence( const QString& uid ) |
365 | { | 365 | { |
366 | Incidence* i; | 366 | Incidence* i; |
367 | 367 | ||
368 | if( (i = todo( uid )) != 0 ) | 368 | if( (i = todo( uid )) != 0 ) |
369 | return i; | 369 | return i; |
370 | if( (i = event( uid )) != 0 ) | 370 | if( (i = event( uid )) != 0 ) |
371 | return i; | 371 | return i; |
372 | if( (i = journal( uid )) != 0 ) | 372 | if( (i = journal( uid )) != 0 ) |
373 | return i; | 373 | return i; |
374 | 374 | ||
375 | return 0; | 375 | return 0; |
376 | } | 376 | } |
377 | 377 | ||
378 | QPtrList<Todo> Calendar::todos() | 378 | QPtrList<Todo> Calendar::todos() |
379 | { | 379 | { |
380 | QPtrList<Todo> tl = rawTodos(); | 380 | QPtrList<Todo> tl = rawTodos(); |
381 | mFilter->apply( &tl ); | 381 | mFilter->apply( &tl ); |
382 | return tl; | 382 | return tl; |
383 | } | 383 | } |
384 | 384 | ||
385 | // When this is called, the todo have already been added to the calendar. | 385 | // When this is called, the todo have already been added to the calendar. |
386 | // This method is only about linking related todos | 386 | // This method is only about linking related todos |
387 | void Calendar::setupRelations( Incidence *incidence ) | 387 | void Calendar::setupRelations( Incidence *incidence ) |
388 | { | 388 | { |
389 | QString uid = incidence->uid(); | 389 | QString uid = incidence->uid(); |
390 | //qDebug("Calendar::setupRelations "); | 390 | //qDebug("Calendar::setupRelations "); |
391 | // First, go over the list of orphans and see if this is their parent | 391 | // First, go over the list of orphans and see if this is their parent |
392 | while( Incidence* i = mOrphans[ uid ] ) { | 392 | while( Incidence* i = mOrphans[ uid ] ) { |
393 | mOrphans.remove( uid ); | 393 | mOrphans.remove( uid ); |
394 | i->setRelatedTo( incidence ); | 394 | i->setRelatedTo( incidence ); |
395 | incidence->addRelation( i ); | 395 | incidence->addRelation( i ); |
396 | mOrphanUids.remove( i->uid() ); | 396 | mOrphanUids.remove( i->uid() ); |
397 | } | 397 | } |
398 | 398 | ||
399 | // Now see about this incidences parent | 399 | // Now see about this incidences parent |
400 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 400 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
401 | // This incidence has a uid it is related to, but is not registered to it yet | 401 | // This incidence has a uid it is related to, but is not registered to it yet |
402 | // Try to find it | 402 | // Try to find it |
403 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 403 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
404 | if( parent ) { | 404 | if( parent ) { |
405 | // Found it | 405 | // Found it |
406 | incidence->setRelatedTo( parent ); | 406 | incidence->setRelatedTo( parent ); |
407 | parent->addRelation( incidence ); | 407 | parent->addRelation( incidence ); |
408 | } else { | 408 | } else { |
409 | // Not found, put this in the mOrphans list | 409 | // Not found, put this in the mOrphans list |
410 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 410 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
411 | mOrphanUids.insert( incidence->uid(), incidence ); | 411 | mOrphanUids.insert( incidence->uid(), incidence ); |
412 | } | 412 | } |
413 | } | 413 | } |
414 | } | 414 | } |
415 | 415 | ||
416 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 416 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
417 | void Calendar::removeRelations( Incidence *incidence ) | 417 | void Calendar::removeRelations( Incidence *incidence ) |
418 | { | 418 | { |
419 | // qDebug("Calendar::removeRelations "); | 419 | // qDebug("Calendar::removeRelations "); |
420 | QString uid = incidence->uid(); | 420 | QString uid = incidence->uid(); |
421 | 421 | ||
422 | QPtrList<Incidence> relations = incidence->relations(); | 422 | QPtrList<Incidence> relations = incidence->relations(); |
423 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 423 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
424 | if( !mOrphanUids.find( i->uid() ) ) { | 424 | if( !mOrphanUids.find( i->uid() ) ) { |
425 | mOrphans.insert( uid, i ); | 425 | mOrphans.insert( uid, i ); |
426 | mOrphanUids.insert( i->uid(), i ); | 426 | mOrphanUids.insert( i->uid(), i ); |
427 | i->setRelatedTo( 0 ); | 427 | i->setRelatedTo( 0 ); |
428 | i->setRelatedToUid( uid ); | 428 | i->setRelatedToUid( uid ); |
429 | } | 429 | } |
430 | 430 | ||
431 | // If this incidence is related to something else, tell that about it | 431 | // If this incidence is related to something else, tell that about it |
432 | if( incidence->relatedTo() ) | 432 | if( incidence->relatedTo() ) |
433 | incidence->relatedTo()->removeRelation( incidence ); | 433 | incidence->relatedTo()->removeRelation( incidence ); |
434 | 434 | ||
435 | // Remove this one from the orphans list | 435 | // Remove this one from the orphans list |
436 | if( mOrphanUids.remove( uid ) ) | 436 | if( mOrphanUids.remove( uid ) ) |
437 | // This incidence is located in the orphans list - it should be removed | 437 | // This incidence is located in the orphans list - it should be removed |
438 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 438 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
439 | // Removing wasn't that easy | 439 | // Removing wasn't that easy |
440 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 440 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
441 | if( it.current()->uid() == uid ) { | 441 | if( it.current()->uid() == uid ) { |
442 | mOrphans.remove( it.currentKey() ); | 442 | mOrphans.remove( it.currentKey() ); |
443 | break; | 443 | break; |
444 | } | 444 | } |
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | 448 | ||
449 | void Calendar::registerObserver( Observer *observer ) | 449 | void Calendar::registerObserver( Observer *observer ) |
450 | { | 450 | { |
451 | mObserver = observer; | 451 | mObserver = observer; |
452 | mNewObserver = true; | 452 | mNewObserver = true; |
453 | } | 453 | } |
454 | 454 | ||
455 | void Calendar::setModified( bool modified ) | 455 | void Calendar::setModified( bool modified ) |
456 | { | 456 | { |
457 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 457 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
458 | if ( modified != mModified || mNewObserver ) { | 458 | if ( modified != mModified || mNewObserver ) { |
459 | mNewObserver = false; | 459 | mNewObserver = false; |
460 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 460 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
461 | mModified = modified; | 461 | mModified = modified; |
462 | } | 462 | } |
463 | } | 463 | } |
464 | 464 | ||
465 | void Calendar::setLoadedProductId( const QString &id ) | 465 | void Calendar::setLoadedProductId( const QString &id ) |
466 | { | 466 | { |
467 | mLoadedProductId = id; | 467 | mLoadedProductId = id; |
468 | } | 468 | } |
469 | 469 | ||
470 | QString Calendar::loadedProductId() | 470 | QString Calendar::loadedProductId() |
471 | { | 471 | { |
472 | return mLoadedProductId; | 472 | return mLoadedProductId; |
473 | } | 473 | } |
474 | 474 | ||
475 | //#include "calendar.moc" | 475 | //#include "calendar.moc" |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index bc76c0b..fe74052 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -77,654 +77,650 @@ bool CalendarLocal::load( const QString &fileName ) | |||
77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 77 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
78 | { | 78 | { |
79 | FileStorage storage( this, fileName, format ); | 79 | FileStorage storage( this, fileName, format ); |
80 | return storage.save(); | 80 | return storage.save(); |
81 | } | 81 | } |
82 | 82 | ||
83 | void CalendarLocal::close() | 83 | void CalendarLocal::close() |
84 | { | 84 | { |
85 | 85 | ||
86 | Todo * i; | 86 | Todo * i; |
87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 87 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
88 | 88 | ||
89 | mEventList.setAutoDelete( true ); | 89 | mEventList.setAutoDelete( true ); |
90 | mTodoList.setAutoDelete( true ); | 90 | mTodoList.setAutoDelete( true ); |
91 | mJournalList.setAutoDelete( false ); | 91 | mJournalList.setAutoDelete( false ); |
92 | 92 | ||
93 | mEventList.clear(); | 93 | mEventList.clear(); |
94 | mTodoList.clear(); | 94 | mTodoList.clear(); |
95 | mJournalList.clear(); | 95 | mJournalList.clear(); |
96 | 96 | ||
97 | mEventList.setAutoDelete( false ); | 97 | mEventList.setAutoDelete( false ); |
98 | mTodoList.setAutoDelete( false ); | 98 | mTodoList.setAutoDelete( false ); |
99 | mJournalList.setAutoDelete( false ); | 99 | mJournalList.setAutoDelete( false ); |
100 | 100 | ||
101 | setModified( false ); | 101 | setModified( false ); |
102 | } | 102 | } |
103 | 103 | ||
104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 104 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
105 | { | 105 | { |
106 | QString cat; | 106 | QString cat; |
107 | bool isBirthday = true; | 107 | bool isBirthday = true; |
108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 108 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
109 | isBirthday = false; | 109 | isBirthday = false; |
110 | cat = i18n( "Anniversary" ); | 110 | cat = i18n( "Anniversary" ); |
111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { | 111 | } else if( event->categoriesStr() == i18n( "Birthday" ) ) { |
112 | isBirthday = true; | 112 | isBirthday = true; |
113 | cat = i18n( "Birthday" ); | 113 | cat = i18n( "Birthday" ); |
114 | } else { | 114 | } else { |
115 | qDebug("addAnniversaryNoDup called without fitting category! "); | 115 | qDebug("addAnniversaryNoDup called without fitting category! "); |
116 | return false; | 116 | return false; |
117 | } | 117 | } |
118 | Event * eve; | 118 | Event * eve; |
119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 119 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
120 | if ( !(eve->categories().contains( cat ) )) | 120 | if ( !(eve->categories().contains( cat ) )) |
121 | continue; | 121 | continue; |
122 | // now we have an event with fitting category | 122 | // now we have an event with fitting category |
123 | if ( eve->dtStart().date() != event->dtStart().date() ) | 123 | if ( eve->dtStart().date() != event->dtStart().date() ) |
124 | continue; | 124 | continue; |
125 | // now we have an event with fitting category+date | 125 | // now we have an event with fitting category+date |
126 | if ( eve->summary() != event->summary() ) | 126 | if ( eve->summary() != event->summary() ) |
127 | continue; | 127 | continue; |
128 | // now we have an event with fitting category+date+summary | 128 | // now we have an event with fitting category+date+summary |
129 | return false; | 129 | return false; |
130 | } | 130 | } |
131 | return addEvent( event ); | 131 | return addEvent( event ); |
132 | 132 | ||
133 | } | 133 | } |
134 | bool CalendarLocal::addEventNoDup( Event *event ) | 134 | bool CalendarLocal::addEventNoDup( Event *event ) |
135 | { | 135 | { |
136 | Event * eve; | 136 | Event * eve; |
137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { | 137 | for ( eve = mEventList.first(); eve ; eve = mEventList.next() ) { |
138 | if ( *eve == *event ) { | 138 | if ( *eve == *event ) { |
139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); | 139 | //qDebug("CalendarLocal::Duplicate event found! Not inserted! "); |
140 | return false; | 140 | return false; |
141 | } | 141 | } |
142 | } | 142 | } |
143 | return addEvent( event ); | 143 | return addEvent( event ); |
144 | } | 144 | } |
145 | 145 | ||
146 | bool CalendarLocal::addEvent( Event *event ) | 146 | bool CalendarLocal::addEvent( Event *event ) |
147 | { | 147 | { |
148 | insertEvent( event ); | 148 | insertEvent( event ); |
149 | 149 | ||
150 | event->registerObserver( this ); | 150 | event->registerObserver( this ); |
151 | 151 | ||
152 | setModified( true ); | 152 | setModified( true ); |
153 | 153 | ||
154 | return true; | 154 | return true; |
155 | } | 155 | } |
156 | 156 | ||
157 | void CalendarLocal::deleteEvent( Event *event ) | 157 | void CalendarLocal::deleteEvent( Event *event ) |
158 | { | 158 | { |
159 | if ( mUndoIncidence ) delete mUndoIncidence; | 159 | if ( mUndoIncidence ) delete mUndoIncidence; |
160 | mUndoIncidence = event->clone(); | 160 | mUndoIncidence = event->clone(); |
161 | if ( mEventList.removeRef( event ) ) { | 161 | if ( mEventList.removeRef( event ) ) { |
162 | setModified( true ); | 162 | setModified( true ); |
163 | } | 163 | } |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | Event *CalendarLocal::event( const QString &uid ) | 167 | Event *CalendarLocal::event( const QString &uid ) |
168 | { | 168 | { |
169 | 169 | ||
170 | Event *event; | 170 | Event *event; |
171 | 171 | ||
172 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 172 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
173 | if ( event->uid() == uid ) { | 173 | if ( event->uid() == uid ) { |
174 | return event; | 174 | return event; |
175 | } | 175 | } |
176 | } | 176 | } |
177 | 177 | ||
178 | return 0; | 178 | return 0; |
179 | } | 179 | } |
180 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 180 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
181 | { | 181 | { |
182 | Todo * eve; | 182 | Todo * eve; |
183 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 183 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
184 | if ( *eve == *todo ) { | 184 | if ( *eve == *todo ) { |
185 | //qDebug("duplicate todo found! not inserted! "); | 185 | //qDebug("duplicate todo found! not inserted! "); |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | return addTodo( todo ); | 189 | return addTodo( todo ); |
190 | } | 190 | } |
191 | bool CalendarLocal::addTodo( Todo *todo ) | 191 | bool CalendarLocal::addTodo( Todo *todo ) |
192 | { | 192 | { |
193 | mTodoList.append( todo ); | 193 | mTodoList.append( todo ); |
194 | 194 | ||
195 | todo->registerObserver( this ); | 195 | todo->registerObserver( this ); |
196 | 196 | ||
197 | // Set up subtask relations | 197 | // Set up subtask relations |
198 | setupRelations( todo ); | 198 | setupRelations( todo ); |
199 | 199 | ||
200 | setModified( true ); | 200 | setModified( true ); |
201 | 201 | ||
202 | return true; | 202 | return true; |
203 | } | 203 | } |
204 | 204 | ||
205 | void CalendarLocal::deleteTodo( Todo *todo ) | 205 | void CalendarLocal::deleteTodo( Todo *todo ) |
206 | { | 206 | { |
207 | // Handle orphaned children | 207 | // Handle orphaned children |
208 | if ( mUndoIncidence ) delete mUndoIncidence; | 208 | if ( mUndoIncidence ) delete mUndoIncidence; |
209 | removeRelations( todo ); | 209 | removeRelations( todo ); |
210 | mUndoIncidence = todo->clone(); | 210 | mUndoIncidence = todo->clone(); |
211 | 211 | ||
212 | if ( mTodoList.removeRef( todo ) ) { | 212 | if ( mTodoList.removeRef( todo ) ) { |
213 | setModified( true ); | 213 | setModified( true ); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | QPtrList<Todo> CalendarLocal::rawTodos() | 217 | QPtrList<Todo> CalendarLocal::rawTodos() |
218 | { | 218 | { |
219 | return mTodoList; | 219 | return mTodoList; |
220 | } | 220 | } |
221 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 221 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
222 | { | 222 | { |
223 | Todo *todo; | 223 | Todo *todo; |
224 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 224 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
225 | if ( todo->getID( syncProf ) == id ) return todo; | 225 | if ( todo->getID( syncProf ) == id ) return todo; |
226 | } | 226 | } |
227 | 227 | ||
228 | return 0; | 228 | return 0; |
229 | } | 229 | } |
230 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 230 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
231 | { | 231 | { |
232 | QPtrList<Incidence> all = rawIncidences() ; | 232 | QPtrList<Incidence> all = rawIncidences() ; |
233 | Incidence *inc; | 233 | Incidence *inc; |
234 | for ( inc = all.first(); inc; inc = all.next() ) { | 234 | for ( inc = all.first(); inc; inc = all.next() ) { |
235 | inc->removeID( syncProfile ); | 235 | inc->removeID( syncProfile ); |
236 | } | 236 | } |
237 | if ( syncProfile.isEmpty() ) { | 237 | if ( syncProfile.isEmpty() ) { |
238 | QPtrList<Event> el; | 238 | QPtrList<Event> el; |
239 | Event *todo; | 239 | Event *todo; |
240 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 240 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
241 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 241 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
242 | el.append( todo ); | 242 | el.append( todo ); |
243 | } | 243 | } |
244 | for ( todo = el.first(); todo; todo = el.next() ) { | 244 | for ( todo = el.first(); todo; todo = el.next() ) { |
245 | deleteIncidence ( todo ); | 245 | deleteIncidence ( todo ); |
246 | } | 246 | } |
247 | } else { | 247 | } else { |
248 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 248 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
249 | if ( lse ) | 249 | if ( lse ) |
250 | deleteIncidence ( lse ); | 250 | deleteIncidence ( lse ); |
251 | } | 251 | } |
252 | } | 252 | } |
253 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 253 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
254 | { | 254 | { |
255 | QPtrList<Event> el; | 255 | QPtrList<Event> el; |
256 | Event *todo; | 256 | Event *todo; |
257 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 257 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
258 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 258 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
259 | if ( todo->summary().left(3) == "E: " ) | 259 | if ( todo->summary().left(3) == "E: " ) |
260 | el.append( todo ); | 260 | el.append( todo ); |
261 | } | 261 | } |
262 | 262 | ||
263 | return el; | 263 | return el; |
264 | 264 | ||
265 | } | 265 | } |
266 | Event *CalendarLocal::event( QString syncProf, QString id ) | 266 | Event *CalendarLocal::event( QString syncProf, QString id ) |
267 | { | 267 | { |
268 | Event *todo; | 268 | Event *todo; |
269 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 269 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
270 | if ( todo->getID( syncProf ) == id ) return todo; | 270 | if ( todo->getID( syncProf ) == id ) return todo; |
271 | } | 271 | } |
272 | 272 | ||
273 | return 0; | 273 | return 0; |
274 | } | 274 | } |
275 | Todo *CalendarLocal::todo( const QString &uid ) | 275 | Todo *CalendarLocal::todo( const QString &uid ) |
276 | { | 276 | { |
277 | Todo *todo; | 277 | Todo *todo; |
278 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 278 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
279 | if ( todo->uid() == uid ) return todo; | 279 | if ( todo->uid() == uid ) return todo; |
280 | } | 280 | } |
281 | 281 | ||
282 | return 0; | 282 | return 0; |
283 | } | 283 | } |
284 | QString CalendarLocal::nextSummary() const | 284 | QString CalendarLocal::nextSummary() const |
285 | { | 285 | { |
286 | return mNextSummary; | 286 | return mNextSummary; |
287 | } | 287 | } |
288 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 288 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
289 | { | 289 | { |
290 | return mNextAlarmEventDateTime; | 290 | return mNextAlarmEventDateTime; |
291 | } | 291 | } |
292 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 292 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
293 | { | 293 | { |
294 | //mNextAlarmIncidence | 294 | //mNextAlarmIncidence |
295 | //mNextAlarmDateTime | 295 | //mNextAlarmDateTime |
296 | //return mNextSummary; | 296 | //return mNextSummary; |
297 | //return mNextAlarmEventDateTime; | 297 | //return mNextAlarmEventDateTime; |
298 | bool newNextAlarm = false; | 298 | bool newNextAlarm = false; |
299 | bool computeNextAlarm = false; | 299 | bool computeNextAlarm = false; |
300 | bool ok; | 300 | bool ok; |
301 | int offset; | 301 | int offset; |
302 | QDateTime nextA; | 302 | QDateTime nextA; |
303 | // QString nextSum; | 303 | // QString nextSum; |
304 | //QDateTime nextEvent; | 304 | //QDateTime nextEvent; |
305 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 305 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
306 | computeNextAlarm = true; | 306 | computeNextAlarm = true; |
307 | } else { | 307 | } else { |
308 | if ( ! deleted ) { | 308 | if ( ! deleted ) { |
309 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 309 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
310 | if ( ok ) { | 310 | if ( ok ) { |
311 | if ( nextA < mNextAlarmDateTime ) { | 311 | if ( nextA < mNextAlarmDateTime ) { |
312 | deRegisterAlarm(); | 312 | deRegisterAlarm(); |
313 | mNextAlarmDateTime = nextA; | 313 | mNextAlarmDateTime = nextA; |
314 | mNextSummary = incidence->summary(); | 314 | mNextSummary = incidence->summary(); |
315 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 315 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
316 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 316 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
317 | newNextAlarm = true; | 317 | newNextAlarm = true; |
318 | mNextAlarmIncidence = incidence; | 318 | mNextAlarmIncidence = incidence; |
319 | } else { | 319 | } else { |
320 | if ( incidence == mNextAlarmIncidence ) { | 320 | if ( incidence == mNextAlarmIncidence ) { |
321 | computeNextAlarm = true; | 321 | computeNextAlarm = true; |
322 | } | 322 | } |
323 | } | 323 | } |
324 | } else { | 324 | } else { |
325 | if ( mNextAlarmIncidence == incidence ) { | 325 | if ( mNextAlarmIncidence == incidence ) { |
326 | computeNextAlarm = true; | 326 | computeNextAlarm = true; |
327 | } | 327 | } |
328 | } | 328 | } |
329 | } else { // deleted | 329 | } else { // deleted |
330 | if ( incidence == mNextAlarmIncidence ) { | 330 | if ( incidence == mNextAlarmIncidence ) { |
331 | computeNextAlarm = true; | 331 | computeNextAlarm = true; |
332 | } | 332 | } |
333 | } | 333 | } |
334 | } | 334 | } |
335 | if ( computeNextAlarm ) { | 335 | if ( computeNextAlarm ) { |
336 | deRegisterAlarm(); | 336 | deRegisterAlarm(); |
337 | nextA = nextAlarm( 1000 ); | 337 | nextA = nextAlarm( 1000 ); |
338 | if (! mNextAlarmIncidence ) { | 338 | if (! mNextAlarmIncidence ) { |
339 | return; | 339 | return; |
340 | } | 340 | } |
341 | newNextAlarm = true; | 341 | newNextAlarm = true; |
342 | } | 342 | } |
343 | if ( newNextAlarm ) | 343 | if ( newNextAlarm ) |
344 | registerAlarm(); | 344 | registerAlarm(); |
345 | } | 345 | } |
346 | QString CalendarLocal:: getAlarmNotification() | 346 | QString CalendarLocal:: getAlarmNotification() |
347 | { | 347 | { |
348 | QString ret; | 348 | QString ret; |
349 | // this should not happen | 349 | // this should not happen |
350 | if (! mNextAlarmIncidence ) | 350 | if (! mNextAlarmIncidence ) |
351 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 351 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
352 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 352 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
353 | if ( alarm->type() == Alarm::Procedure ) { | 353 | if ( alarm->type() == Alarm::Procedure ) { |
354 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 354 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
355 | } else { | 355 | } else { |
356 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 356 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
357 | } | 357 | } |
358 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 358 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
359 | if ( mNextSummary.length() > 25 ) | 359 | if ( mNextSummary.length() > 25 ) |
360 | ret += "\n" + mNextSummary.mid(25, 25 ); | 360 | ret += "\n" + mNextSummary.mid(25, 25 ); |
361 | ret+= "\n"+mNextAlarmEventDateTimeString; | 361 | ret+= "\n"+mNextAlarmEventDateTimeString; |
362 | return ret; | 362 | return ret; |
363 | } | 363 | } |
364 | void CalendarLocal::registerAlarm() | 364 | void CalendarLocal::registerAlarm() |
365 | { | 365 | { |
366 | mLastAlarmNotificationString = getAlarmNotification(); | 366 | mLastAlarmNotificationString = getAlarmNotification(); |
367 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 367 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
368 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 368 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
369 | // #ifndef DESKTOP_VERSION | 369 | // #ifndef DESKTOP_VERSION |
370 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 370 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
371 | // #endif | 371 | // #endif |
372 | } | 372 | } |
373 | void CalendarLocal::deRegisterAlarm() | 373 | void CalendarLocal::deRegisterAlarm() |
374 | { | 374 | { |
375 | if ( mLastAlarmNotificationString.isNull() ) | 375 | if ( mLastAlarmNotificationString.isNull() ) |
376 | return; | 376 | return; |
377 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 377 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
378 | 378 | ||
379 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 379 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
380 | mNextAlarmEventDateTime = QDateTime(); | 380 | mNextAlarmEventDateTime = QDateTime(); |
381 | // #ifndef DESKTOP_VERSION | 381 | // #ifndef DESKTOP_VERSION |
382 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 382 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
383 | // #endif | 383 | // #endif |
384 | } | 384 | } |
385 | 385 | ||
386 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 386 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
387 | { | 387 | { |
388 | QPtrList<Todo> todos; | 388 | QPtrList<Todo> todos; |
389 | 389 | ||
390 | Todo *todo; | 390 | Todo *todo; |
391 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 391 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
392 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 392 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
393 | todos.append( todo ); | 393 | todos.append( todo ); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | 396 | ||
397 | filter()->apply( &todos ); | 397 | filter()->apply( &todos ); |
398 | return todos; | 398 | return todos; |
399 | } | 399 | } |
400 | void CalendarLocal::reInitAlarmSettings() | 400 | void CalendarLocal::reInitAlarmSettings() |
401 | { | 401 | { |
402 | if ( !mNextAlarmIncidence ) { | 402 | if ( !mNextAlarmIncidence ) { |
403 | nextAlarm( 1000 ); | 403 | nextAlarm( 1000 ); |
404 | } | 404 | } |
405 | deRegisterAlarm(); | 405 | deRegisterAlarm(); |
406 | mNextAlarmIncidence = 0; | 406 | mNextAlarmIncidence = 0; |
407 | checkAlarmForIncidence( 0, false ); | 407 | checkAlarmForIncidence( 0, false ); |
408 | 408 | ||
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | 412 | ||
413 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 413 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
414 | { | 414 | { |
415 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 415 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
416 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 416 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
417 | QDateTime next; | 417 | QDateTime next; |
418 | Event *e; | 418 | Event *e; |
419 | bool ok; | 419 | bool ok; |
420 | bool found = false; | 420 | bool found = false; |
421 | int offset; | 421 | int offset; |
422 | mNextAlarmIncidence = 0; | 422 | mNextAlarmIncidence = 0; |
423 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 423 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
424 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 424 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
425 | if ( ok ) { | 425 | if ( ok ) { |
426 | if ( next < nextA ) { | 426 | if ( next < nextA ) { |
427 | nextA = next; | 427 | nextA = next; |
428 | found = true; | 428 | found = true; |
429 | mNextSummary = e->summary(); | 429 | mNextSummary = e->summary(); |
430 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 430 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
431 | mNextAlarmIncidence = (Incidence *) e; | 431 | mNextAlarmIncidence = (Incidence *) e; |
432 | } | 432 | } |
433 | } | 433 | } |
434 | } | 434 | } |
435 | Todo *t; | 435 | Todo *t; |
436 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 436 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
437 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 437 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
438 | if ( ok ) { | 438 | if ( ok ) { |
439 | if ( next < nextA ) { | 439 | if ( next < nextA ) { |
440 | nextA = next; | 440 | nextA = next; |
441 | found = true; | 441 | found = true; |
442 | mNextSummary = t->summary(); | 442 | mNextSummary = t->summary(); |
443 | mNextAlarmEventDateTime = next.addSecs(offset ); | 443 | mNextAlarmEventDateTime = next.addSecs(offset ); |
444 | mNextAlarmIncidence = (Incidence *) t; | 444 | mNextAlarmIncidence = (Incidence *) t; |
445 | } | 445 | } |
446 | } | 446 | } |
447 | } | 447 | } |
448 | if ( mNextAlarmIncidence ) { | 448 | if ( mNextAlarmIncidence ) { |
449 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 449 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
450 | mNextAlarmDateTime = nextA; | 450 | mNextAlarmDateTime = nextA; |
451 | } | 451 | } |
452 | return nextA; | 452 | return nextA; |
453 | } | 453 | } |
454 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 454 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
455 | { | 455 | { |
456 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 456 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
457 | } | 457 | } |
458 | 458 | ||
459 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 459 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
460 | { | 460 | { |
461 | kdDebug(5800) << "CalendarLocal::alarms(" << from.toString() << " - " | 461 | |
462 | << to.toString() << ")\n"; | ||
463 | |||
464 | Alarm::List alarms; | 462 | Alarm::List alarms; |
465 | 463 | ||
466 | Event *e; | 464 | Event *e; |
467 | 465 | ||
468 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 466 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
469 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 467 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
470 | else appendAlarms( alarms, e, from, to ); | 468 | else appendAlarms( alarms, e, from, to ); |
471 | } | 469 | } |
472 | 470 | ||
473 | Todo *t; | 471 | Todo *t; |
474 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 472 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
475 | appendAlarms( alarms, t, from, to ); | 473 | appendAlarms( alarms, t, from, to ); |
476 | } | 474 | } |
477 | 475 | ||
478 | return alarms; | 476 | return alarms; |
479 | } | 477 | } |
480 | 478 | ||
481 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 479 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
482 | const QDateTime &from, const QDateTime &to ) | 480 | const QDateTime &from, const QDateTime &to ) |
483 | { | 481 | { |
484 | QPtrList<Alarm> alarmList = incidence->alarms(); | 482 | QPtrList<Alarm> alarmList = incidence->alarms(); |
485 | Alarm *alarm; | 483 | Alarm *alarm; |
486 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 484 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
487 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 485 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
488 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 486 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
489 | if ( alarm->enabled() ) { | 487 | if ( alarm->enabled() ) { |
490 | if ( alarm->time() >= from && alarm->time() <= to ) { | 488 | if ( alarm->time() >= from && alarm->time() <= to ) { |
491 | kdDebug(5800) << "CalendarLocal::appendAlarms() '" << incidence->summary() | ||
492 | << "': " << alarm->time().toString() << endl; | ||
493 | alarms.append( alarm ); | 489 | alarms.append( alarm ); |
494 | } | 490 | } |
495 | } | 491 | } |
496 | } | 492 | } |
497 | } | 493 | } |
498 | 494 | ||
499 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 495 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
500 | Incidence *incidence, | 496 | Incidence *incidence, |
501 | const QDateTime &from, | 497 | const QDateTime &from, |
502 | const QDateTime &to ) | 498 | const QDateTime &to ) |
503 | { | 499 | { |
504 | 500 | ||
505 | QPtrList<Alarm> alarmList = incidence->alarms(); | 501 | QPtrList<Alarm> alarmList = incidence->alarms(); |
506 | Alarm *alarm; | 502 | Alarm *alarm; |
507 | QDateTime qdt; | 503 | QDateTime qdt; |
508 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 504 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
509 | if (incidence->recursOn(from.date())) { | 505 | if (incidence->recursOn(from.date())) { |
510 | qdt.setTime(alarm->time().time()); | 506 | qdt.setTime(alarm->time().time()); |
511 | qdt.setDate(from.date()); | 507 | qdt.setDate(from.date()); |
512 | } | 508 | } |
513 | else qdt = alarm->time(); | 509 | else qdt = alarm->time(); |
514 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 510 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
515 | if ( alarm->enabled() ) { | 511 | if ( alarm->enabled() ) { |
516 | if ( qdt >= from && qdt <= to ) { | 512 | if ( qdt >= from && qdt <= to ) { |
517 | alarms.append( alarm ); | 513 | alarms.append( alarm ); |
518 | } | 514 | } |
519 | } | 515 | } |
520 | } | 516 | } |
521 | } | 517 | } |
522 | 518 | ||
523 | 519 | ||
524 | /****************************** PROTECTED METHODS ****************************/ | 520 | /****************************** PROTECTED METHODS ****************************/ |
525 | 521 | ||
526 | // after changes are made to an event, this should be called. | 522 | // after changes are made to an event, this should be called. |
527 | void CalendarLocal::update( IncidenceBase *incidence ) | 523 | void CalendarLocal::update( IncidenceBase *incidence ) |
528 | { | 524 | { |
529 | incidence->setSyncStatus( Event::SYNCMOD ); | 525 | incidence->setSyncStatus( Event::SYNCMOD ); |
530 | incidence->setLastModified( QDateTime::currentDateTime() ); | 526 | incidence->setLastModified( QDateTime::currentDateTime() ); |
531 | // we should probably update the revision number here, | 527 | // we should probably update the revision number here, |
532 | // or internally in the Event itself when certain things change. | 528 | // or internally in the Event itself when certain things change. |
533 | // need to verify with ical documentation. | 529 | // need to verify with ical documentation. |
534 | 530 | ||
535 | setModified( true ); | 531 | setModified( true ); |
536 | } | 532 | } |
537 | 533 | ||
538 | void CalendarLocal::insertEvent( Event *event ) | 534 | void CalendarLocal::insertEvent( Event *event ) |
539 | { | 535 | { |
540 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 536 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
541 | } | 537 | } |
542 | 538 | ||
543 | 539 | ||
544 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 540 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
545 | { | 541 | { |
546 | QPtrList<Event> eventList; | 542 | QPtrList<Event> eventList; |
547 | 543 | ||
548 | Event *event; | 544 | Event *event; |
549 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 545 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
550 | if ( event->doesRecur() ) { | 546 | if ( event->doesRecur() ) { |
551 | if ( event->isMultiDay() ) { | 547 | if ( event->isMultiDay() ) { |
552 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 548 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
553 | int i; | 549 | int i; |
554 | for ( i = 0; i <= extraDays; i++ ) { | 550 | for ( i = 0; i <= extraDays; i++ ) { |
555 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 551 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
556 | eventList.append( event ); | 552 | eventList.append( event ); |
557 | break; | 553 | break; |
558 | } | 554 | } |
559 | } | 555 | } |
560 | } else { | 556 | } else { |
561 | if ( event->recursOn( qd ) ) | 557 | if ( event->recursOn( qd ) ) |
562 | eventList.append( event ); | 558 | eventList.append( event ); |
563 | } | 559 | } |
564 | } else { | 560 | } else { |
565 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 561 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
566 | eventList.append( event ); | 562 | eventList.append( event ); |
567 | } | 563 | } |
568 | } | 564 | } |
569 | } | 565 | } |
570 | 566 | ||
571 | if ( !sorted ) { | 567 | if ( !sorted ) { |
572 | return eventList; | 568 | return eventList; |
573 | } | 569 | } |
574 | 570 | ||
575 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 571 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
576 | // now, we have to sort it based on dtStart.time() | 572 | // now, we have to sort it based on dtStart.time() |
577 | QPtrList<Event> eventListSorted; | 573 | QPtrList<Event> eventListSorted; |
578 | Event *sortEvent; | 574 | Event *sortEvent; |
579 | for ( event = eventList.first(); event; event = eventList.next() ) { | 575 | for ( event = eventList.first(); event; event = eventList.next() ) { |
580 | sortEvent = eventListSorted.first(); | 576 | sortEvent = eventListSorted.first(); |
581 | int i = 0; | 577 | int i = 0; |
582 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 578 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
583 | { | 579 | { |
584 | i++; | 580 | i++; |
585 | sortEvent = eventListSorted.next(); | 581 | sortEvent = eventListSorted.next(); |
586 | } | 582 | } |
587 | eventListSorted.insert( i, event ); | 583 | eventListSorted.insert( i, event ); |
588 | } | 584 | } |
589 | return eventListSorted; | 585 | return eventListSorted; |
590 | } | 586 | } |
591 | 587 | ||
592 | 588 | ||
593 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 589 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
594 | bool inclusive ) | 590 | bool inclusive ) |
595 | { | 591 | { |
596 | Event *event = 0; | 592 | Event *event = 0; |
597 | 593 | ||
598 | QPtrList<Event> eventList; | 594 | QPtrList<Event> eventList; |
599 | 595 | ||
600 | // Get non-recurring events | 596 | // Get non-recurring events |
601 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 597 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
602 | if ( event->doesRecur() ) { | 598 | if ( event->doesRecur() ) { |
603 | QDate rStart = event->dtStart().date(); | 599 | QDate rStart = event->dtStart().date(); |
604 | bool found = false; | 600 | bool found = false; |
605 | if ( inclusive ) { | 601 | if ( inclusive ) { |
606 | if ( rStart >= start && rStart <= end ) { | 602 | if ( rStart >= start && rStart <= end ) { |
607 | // Start date of event is in range. Now check for end date. | 603 | // Start date of event is in range. Now check for end date. |
608 | // if duration is negative, event recurs forever, so do not include it. | 604 | // if duration is negative, event recurs forever, so do not include it. |
609 | if ( event->recurrence()->duration() == 0 ) { // End date set | 605 | if ( event->recurrence()->duration() == 0 ) { // End date set |
610 | QDate rEnd = event->recurrence()->endDate(); | 606 | QDate rEnd = event->recurrence()->endDate(); |
611 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 607 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
612 | found = true; | 608 | found = true; |
613 | } | 609 | } |
614 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 610 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
615 | // TODO: Calculate end date from duration. Should be done in Event | 611 | // TODO: Calculate end date from duration. Should be done in Event |
616 | // For now exclude all events with a duration. | 612 | // For now exclude all events with a duration. |
617 | } | 613 | } |
618 | } | 614 | } |
619 | } else { | 615 | } else { |
620 | bool founOne; | 616 | bool founOne; |
621 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 617 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
622 | if ( founOne ) { | 618 | if ( founOne ) { |
623 | if ( next <= end ) { | 619 | if ( next <= end ) { |
624 | found = true; | 620 | found = true; |
625 | } | 621 | } |
626 | } | 622 | } |
627 | 623 | ||
628 | /* | 624 | /* |
629 | // crap !!! | 625 | // crap !!! |
630 | if ( rStart <= end ) { // Start date not after range | 626 | if ( rStart <= end ) { // Start date not after range |
631 | if ( rStart >= start ) { // Start date within range | 627 | if ( rStart >= start ) { // Start date within range |
632 | found = true; | 628 | found = true; |
633 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 629 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
634 | found = true; | 630 | found = true; |
635 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 631 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
636 | QDate rEnd = event->recurrence()->endDate(); | 632 | QDate rEnd = event->recurrence()->endDate(); |
637 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 633 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
638 | found = true; | 634 | found = true; |
639 | } | 635 | } |
640 | } else { // Duration set | 636 | } else { // Duration set |
641 | // TODO: Calculate end date from duration. Should be done in Event | 637 | // TODO: Calculate end date from duration. Should be done in Event |
642 | // For now include all events with a duration. | 638 | // For now include all events with a duration. |
643 | found = true; | 639 | found = true; |
644 | } | 640 | } |
645 | } | 641 | } |
646 | */ | 642 | */ |
647 | 643 | ||
648 | } | 644 | } |
649 | 645 | ||
650 | if ( found ) eventList.append( event ); | 646 | if ( found ) eventList.append( event ); |
651 | } else { | 647 | } else { |
652 | QDate s = event->dtStart().date(); | 648 | QDate s = event->dtStart().date(); |
653 | QDate e = event->dtEnd().date(); | 649 | QDate e = event->dtEnd().date(); |
654 | 650 | ||
655 | if ( inclusive ) { | 651 | if ( inclusive ) { |
656 | if ( s >= start && e <= end ) { | 652 | if ( s >= start && e <= end ) { |
657 | eventList.append( event ); | 653 | eventList.append( event ); |
658 | } | 654 | } |
659 | } else { | 655 | } else { |
660 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 656 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
661 | eventList.append( event ); | 657 | eventList.append( event ); |
662 | } | 658 | } |
663 | } | 659 | } |
664 | } | 660 | } |
665 | } | 661 | } |
666 | 662 | ||
667 | return eventList; | 663 | return eventList; |
668 | } | 664 | } |
669 | 665 | ||
670 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 666 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
671 | { | 667 | { |
672 | return rawEventsForDate( qdt.date() ); | 668 | return rawEventsForDate( qdt.date() ); |
673 | } | 669 | } |
674 | 670 | ||
675 | QPtrList<Event> CalendarLocal::rawEvents() | 671 | QPtrList<Event> CalendarLocal::rawEvents() |
676 | { | 672 | { |
677 | return mEventList; | 673 | return mEventList; |
678 | } | 674 | } |
679 | 675 | ||
680 | bool CalendarLocal::addJournal(Journal *journal) | 676 | bool CalendarLocal::addJournal(Journal *journal) |
681 | { | 677 | { |
682 | if ( journal->dtStart().isValid()) | 678 | if ( journal->dtStart().isValid()) |
683 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 679 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
684 | else | 680 | else |
685 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 681 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
686 | 682 | ||
687 | mJournalList.append(journal); | 683 | mJournalList.append(journal); |
688 | 684 | ||
689 | journal->registerObserver( this ); | 685 | journal->registerObserver( this ); |
690 | 686 | ||
691 | setModified( true ); | 687 | setModified( true ); |
692 | 688 | ||
693 | return true; | 689 | return true; |
694 | } | 690 | } |
695 | 691 | ||
696 | void CalendarLocal::deleteJournal( Journal *journal ) | 692 | void CalendarLocal::deleteJournal( Journal *journal ) |
697 | { | 693 | { |
698 | if ( mUndoIncidence ) delete mUndoIncidence; | 694 | if ( mUndoIncidence ) delete mUndoIncidence; |
699 | mUndoIncidence = journal->clone(); | 695 | mUndoIncidence = journal->clone(); |
700 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 696 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
701 | if ( mJournalList.removeRef(journal) ) { | 697 | if ( mJournalList.removeRef(journal) ) { |
702 | setModified( true ); | 698 | setModified( true ); |
703 | } | 699 | } |
704 | } | 700 | } |
705 | 701 | ||
706 | Journal *CalendarLocal::journal( const QDate &date ) | 702 | Journal *CalendarLocal::journal( const QDate &date ) |
707 | { | 703 | { |
708 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 704 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
709 | 705 | ||
710 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 706 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
711 | if ( it->dtStart().date() == date ) | 707 | if ( it->dtStart().date() == date ) |
712 | return it; | 708 | return it; |
713 | 709 | ||
714 | return 0; | 710 | return 0; |
715 | } | 711 | } |
716 | 712 | ||
717 | Journal *CalendarLocal::journal( const QString &uid ) | 713 | Journal *CalendarLocal::journal( const QString &uid ) |
718 | { | 714 | { |
719 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 715 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
720 | if ( it->uid() == uid ) | 716 | if ( it->uid() == uid ) |
721 | return it; | 717 | return it; |
722 | 718 | ||
723 | return 0; | 719 | return 0; |
724 | } | 720 | } |
725 | 721 | ||
726 | QPtrList<Journal> CalendarLocal::journals() | 722 | QPtrList<Journal> CalendarLocal::journals() |
727 | { | 723 | { |
728 | return mJournalList; | 724 | return mJournalList; |
729 | } | 725 | } |
730 | 726 | ||
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index c425dfc..20078a7 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp | |||
@@ -1,212 +1,212 @@ | |||
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 | 20 | ||
21 | #include <kdebug.h> | 21 | #include <kdebug.h> |
22 | 22 | ||
23 | #include "calfilter.h" | 23 | #include "calfilter.h" |
24 | 24 | ||
25 | using namespace KCal; | 25 | using namespace KCal; |
26 | 26 | ||
27 | CalFilter::CalFilter() | 27 | CalFilter::CalFilter() |
28 | { | 28 | { |
29 | mEnabled = true; | 29 | mEnabled = true; |
30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 30 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
31 | } | 31 | } |
32 | 32 | ||
33 | CalFilter::CalFilter(const QString &name) | 33 | CalFilter::CalFilter(const QString &name) |
34 | { | 34 | { |
35 | mName = name; | 35 | mName = name; |
36 | mEnabled = true; | 36 | mEnabled = true; |
37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; | 37 | mCriteria = ShowPublic | ShowPrivate| ShowConfidential ; |
38 | } | 38 | } |
39 | 39 | ||
40 | CalFilter::~CalFilter() | 40 | CalFilter::~CalFilter() |
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | void CalFilter::apply(QPtrList<Event> *eventlist) | 44 | void CalFilter::apply(QPtrList<Event> *eventlist) |
45 | { | 45 | { |
46 | if (!mEnabled) return; | 46 | if (!mEnabled) return; |
47 | 47 | ||
48 | // kdDebug(5800) << "CalFilter::apply()" << endl; | 48 | // kdDebug(5800) << "CalFilter::apply()" << endl; |
49 | 49 | ||
50 | Event *event = eventlist->first(); | 50 | Event *event = eventlist->first(); |
51 | while(event) { | 51 | while(event) { |
52 | if (!filterEvent(event)) { | 52 | if (!filterEvent(event)) { |
53 | eventlist->remove(); | 53 | eventlist->remove(); |
54 | event = eventlist->current(); | 54 | event = eventlist->current(); |
55 | } else { | 55 | } else { |
56 | event = eventlist->next(); | 56 | event = eventlist->next(); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | 59 | ||
60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 60 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
61 | } | 61 | } |
62 | 62 | ||
63 | // TODO: avoid duplicating apply() code | 63 | // TODO: avoid duplicating apply() code |
64 | void CalFilter::apply(QPtrList<Todo> *eventlist) | 64 | void CalFilter::apply(QPtrList<Todo> *eventlist) |
65 | { | 65 | { |
66 | if (!mEnabled) return; | 66 | if (!mEnabled) return; |
67 | Todo *event = eventlist->first(); | 67 | Todo *event = eventlist->first(); |
68 | while(event) { | 68 | while(event) { |
69 | if (!filterTodo(event)) { | 69 | if (!filterTodo(event)) { |
70 | eventlist->remove(); | 70 | eventlist->remove(); |
71 | event = eventlist->current(); | 71 | event = eventlist->current(); |
72 | } else { | 72 | } else { |
73 | event = eventlist->next(); | 73 | event = eventlist->next(); |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; | 77 | // kdDebug(5800) << "CalFilter::apply() done" << endl; |
78 | } | 78 | } |
79 | bool CalFilter::filterCalendarItem(Incidence *in) | 79 | bool CalFilter::filterCalendarItem(Incidence *in) |
80 | { | 80 | { |
81 | if ( in->type() == "Event" ) | 81 | if ( in->typeID() == eventID ) |
82 | return filterEvent( (Event*) in ); | 82 | return filterEvent( (Event*) in ); |
83 | else if ( in->type() =="Todo" ) | 83 | else if ( in->typeID() == todoID ) |
84 | return filterTodo( (Todo*) in); | 84 | return filterTodo( (Todo*) in); |
85 | else if ( in->type() =="Journal" ) | 85 | else if ( in->typeID () == journalID ) |
86 | return filterJournal( (Journal*) in ); | 86 | return filterJournal( (Journal*) in ); |
87 | return false; | 87 | return false; |
88 | } | 88 | } |
89 | bool CalFilter::filterEvent(Event *event) | 89 | bool CalFilter::filterEvent(Event *event) |
90 | { | 90 | { |
91 | if (mCriteria & HideEvents) | 91 | if (mCriteria & HideEvents) |
92 | return false; | 92 | return false; |
93 | if (mCriteria & HideRecurring) { | 93 | if (mCriteria & HideRecurring) { |
94 | if (event->recurrence()->doesRecur()) return false; | 94 | if (event->recurrence()->doesRecur()) return false; |
95 | } | 95 | } |
96 | 96 | ||
97 | return filterIncidence(event); | 97 | return filterIncidence(event); |
98 | } | 98 | } |
99 | bool CalFilter::filterJournal(Journal *j) | 99 | bool CalFilter::filterJournal(Journal *j) |
100 | { | 100 | { |
101 | if (mCriteria & HideJournals) | 101 | if (mCriteria & HideJournals) |
102 | return false; | 102 | return false; |
103 | return true; | 103 | return true; |
104 | } | 104 | } |
105 | bool CalFilter::filterTodo(Todo *todo) | 105 | bool CalFilter::filterTodo(Todo *todo) |
106 | { | 106 | { |
107 | if (mCriteria & HideTodos) | 107 | if (mCriteria & HideTodos) |
108 | return false; | 108 | return false; |
109 | if (mCriteria & HideCompleted) { | 109 | if (mCriteria & HideCompleted) { |
110 | if (todo->isCompleted()) return false; | 110 | if (todo->isCompleted()) return false; |
111 | } | 111 | } |
112 | 112 | ||
113 | return filterIncidence(todo); | 113 | return filterIncidence(todo); |
114 | } | 114 | } |
115 | bool CalFilter::showCategories() | 115 | bool CalFilter::showCategories() |
116 | { | 116 | { |
117 | return mCriteria & ShowCategories; | 117 | return mCriteria & ShowCategories; |
118 | } | 118 | } |
119 | int CalFilter::getSecrecy() | 119 | int CalFilter::getSecrecy() |
120 | { | 120 | { |
121 | if ( (mCriteria & ShowPublic )) | 121 | if ( (mCriteria & ShowPublic )) |
122 | return Incidence::SecrecyPublic; | 122 | return Incidence::SecrecyPublic; |
123 | if ( (mCriteria & ShowPrivate )) | 123 | if ( (mCriteria & ShowPrivate )) |
124 | return Incidence::SecrecyPrivate; | 124 | return Incidence::SecrecyPrivate; |
125 | if ( (mCriteria & ShowConfidential )) | 125 | if ( (mCriteria & ShowConfidential )) |
126 | return Incidence::SecrecyConfidential; | 126 | return Incidence::SecrecyConfidential; |
127 | return Incidence::SecrecyPublic; | 127 | return Incidence::SecrecyPublic; |
128 | } | 128 | } |
129 | bool CalFilter::filterIncidence(Incidence *incidence) | 129 | bool CalFilter::filterIncidence(Incidence *incidence) |
130 | { | 130 | { |
131 | if ( mCriteria > 7 ) { | 131 | if ( mCriteria > 7 ) { |
132 | switch (incidence->secrecy()) { | 132 | switch (incidence->secrecy()) { |
133 | case Incidence::SecrecyPublic: | 133 | case Incidence::SecrecyPublic: |
134 | if (! (mCriteria & ShowPublic )) | 134 | if (! (mCriteria & ShowPublic )) |
135 | return false; | 135 | return false; |
136 | break; | 136 | break; |
137 | case Incidence::SecrecyPrivate: | 137 | case Incidence::SecrecyPrivate: |
138 | if (! (mCriteria & ShowPrivate )) | 138 | if (! (mCriteria & ShowPrivate )) |
139 | return false; | 139 | return false; |
140 | break; | 140 | break; |
141 | case Incidence::SecrecyConfidential: | 141 | case Incidence::SecrecyConfidential: |
142 | if (! (mCriteria & ShowConfidential )) | 142 | if (! (mCriteria & ShowConfidential )) |
143 | return false; | 143 | return false; |
144 | break; | 144 | break; |
145 | default: | 145 | default: |
146 | return false; | 146 | return false; |
147 | break; | 147 | break; |
148 | } | 148 | } |
149 | } | 149 | } |
150 | 150 | ||
151 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 151 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; |
152 | 152 | ||
153 | if (mCriteria & ShowCategories) { | 153 | if (mCriteria & ShowCategories) { |
154 | for (QStringList::Iterator it = mCategoryList.begin(); | 154 | for (QStringList::Iterator it = mCategoryList.begin(); |
155 | it != mCategoryList.end(); ++it ) { | 155 | it != mCategoryList.end(); ++it ) { |
156 | QStringList incidenceCategories = incidence->categories(); | 156 | QStringList incidenceCategories = incidence->categories(); |
157 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 157 | for (QStringList::Iterator it2 = incidenceCategories.begin(); |
158 | it2 != incidenceCategories.end(); ++it2 ) { | 158 | it2 != incidenceCategories.end(); ++it2 ) { |
159 | if ((*it) == (*it2)) { | 159 | if ((*it) == (*it2)) { |
160 | return true; | 160 | return true; |
161 | } | 161 | } |
162 | } | 162 | } |
163 | } | 163 | } |
164 | return false; | 164 | return false; |
165 | } else { | 165 | } else { |
166 | for (QStringList::Iterator it = mCategoryList.begin(); | 166 | for (QStringList::Iterator it = mCategoryList.begin(); |
167 | it != mCategoryList.end(); ++it ) { | 167 | it != mCategoryList.end(); ++it ) { |
168 | QStringList incidenceCategories = incidence->categories(); | 168 | QStringList incidenceCategories = incidence->categories(); |
169 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 169 | for (QStringList::Iterator it2 = incidenceCategories.begin(); |
170 | it2 != incidenceCategories.end(); ++it2 ) { | 170 | it2 != incidenceCategories.end(); ++it2 ) { |
171 | if ((*it) == (*it2)) { | 171 | if ((*it) == (*it2)) { |
172 | return false; | 172 | return false; |
173 | } | 173 | } |
174 | } | 174 | } |
175 | } | 175 | } |
176 | return true; | 176 | return true; |
177 | } | 177 | } |
178 | 178 | ||
179 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; | 179 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; |
180 | 180 | ||
181 | return true; | 181 | return true; |
182 | } | 182 | } |
183 | 183 | ||
184 | void CalFilter::setEnabled(bool enabled) | 184 | void CalFilter::setEnabled(bool enabled) |
185 | { | 185 | { |
186 | mEnabled = enabled; | 186 | mEnabled = enabled; |
187 | } | 187 | } |
188 | 188 | ||
189 | bool CalFilter::isEnabled() | 189 | bool CalFilter::isEnabled() |
190 | { | 190 | { |
191 | return mEnabled; | 191 | return mEnabled; |
192 | } | 192 | } |
193 | 193 | ||
194 | void CalFilter::setCriteria(int criteria) | 194 | void CalFilter::setCriteria(int criteria) |
195 | { | 195 | { |
196 | mCriteria = criteria; | 196 | mCriteria = criteria; |
197 | } | 197 | } |
198 | 198 | ||
199 | int CalFilter::criteria() | 199 | int CalFilter::criteria() |
200 | { | 200 | { |
201 | return mCriteria; | 201 | return mCriteria; |
202 | } | 202 | } |
203 | 203 | ||
204 | void CalFilter::setCategoryList(const QStringList &categoryList) | 204 | void CalFilter::setCategoryList(const QStringList &categoryList) |
205 | { | 205 | { |
206 | mCategoryList = categoryList; | 206 | mCategoryList = categoryList; |
207 | } | 207 | } |
208 | 208 | ||
209 | QStringList CalFilter::categoryList() | 209 | QStringList CalFilter::categoryList() |
210 | { | 210 | { |
211 | return mCategoryList; | 211 | return mCategoryList; |
212 | } | 212 | } |
diff --git a/libkcal/event.h b/libkcal/event.h index 8729956..287d403 100644 --- a/libkcal/event.h +++ b/libkcal/event.h | |||
@@ -1,90 +1,91 @@ | |||
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 | 20 | ||
21 | #ifndef EVENT_H | 21 | #ifndef EVENT_H |
22 | #define EVENT_H | 22 | #define EVENT_H |
23 | // | 23 | // |
24 | // Event component, representing a VEVENT object | 24 | // Event component, representing a VEVENT object |
25 | // | 25 | // |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | namespace KCal { | 28 | namespace KCal { |
29 | 29 | ||
30 | /** | 30 | /** |
31 | This class provides an Event in the sense of RFC2445. | 31 | This class provides an Event in the sense of RFC2445. |
32 | */ | 32 | */ |
33 | class Event : public Incidence | 33 | class Event : public Incidence |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | enum Transparency { Opaque, Transparent }; | 36 | enum Transparency { Opaque, Transparent }; |
37 | typedef ListBase<Event> List; | 37 | typedef ListBase<Event> List; |
38 | Event(); | 38 | Event(); |
39 | Event(const Event &); | 39 | Event(const Event &); |
40 | ~Event(); | 40 | ~Event(); |
41 | 41 | ||
42 | QCString type() const { return "Event"; } | 42 | QCString type() const { return "Event"; } |
43 | IncTypeID typeID() const { return eventID; } | ||
43 | 44 | ||
44 | Incidence *clone(); | 45 | Incidence *clone(); |
45 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; | 46 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; |
46 | 47 | ||
47 | /** for setting an event's ending date/time with a QDateTime. */ | 48 | /** for setting an event's ending date/time with a QDateTime. */ |
48 | void setDtEnd(const QDateTime &dtEnd); | 49 | void setDtEnd(const QDateTime &dtEnd); |
49 | /** Return the event's ending date/time as a QDateTime. */ | 50 | /** Return the event's ending date/time as a QDateTime. */ |
50 | virtual QDateTime dtEnd() const; | 51 | virtual QDateTime dtEnd() const; |
51 | /** returns an event's end time as a string formatted according to the | 52 | /** returns an event's end time as a string formatted according to the |
52 | users locale settings */ | 53 | users locale settings */ |
53 | QString dtEndTimeStr() const; | 54 | QString dtEndTimeStr() const; |
54 | /** returns an event's end date as a string formatted according to the | 55 | /** returns an event's end date as a string formatted according to the |
55 | users locale settings */ | 56 | users locale settings */ |
56 | QString dtEndDateStr(bool shortfmt=true) const; | 57 | QString dtEndDateStr(bool shortfmt=true) const; |
57 | /** returns an event's end date and time as a string formatted according | 58 | /** returns an event's end date and time as a string formatted according |
58 | to the users locale settings */ | 59 | to the users locale settings */ |
59 | QString dtEndStr(bool shortfmt=true) const; | 60 | QString dtEndStr(bool shortfmt=true) const; |
60 | void setHasEndDate(bool); | 61 | void setHasEndDate(bool); |
61 | /** Return whether the event has an end date/time. */ | 62 | /** Return whether the event has an end date/time. */ |
62 | bool hasEndDate() const; | 63 | bool hasEndDate() const; |
63 | 64 | ||
64 | /** Return true if the event spans multiple days, otherwise return false. */ | 65 | /** Return true if the event spans multiple days, otherwise return false. */ |
65 | bool isMultiDay() const; | 66 | bool isMultiDay() const; |
66 | 67 | ||
67 | /** set the event's time transparency level. */ | 68 | /** set the event's time transparency level. */ |
68 | void setTransparency(Transparency transparency); | 69 | void setTransparency(Transparency transparency); |
69 | /** get the event's time transparency level. */ | 70 | /** get the event's time transparency level. */ |
70 | Transparency transparency() const; | 71 | Transparency transparency() const; |
71 | 72 | ||
72 | void setDuration(int seconds); | 73 | void setDuration(int seconds); |
73 | 74 | ||
74 | bool contains ( Event*); | 75 | bool contains ( Event*); |
75 | 76 | ||
76 | private: | 77 | private: |
77 | bool accept(Visitor &v) { return v.visit(this); } | 78 | bool accept(Visitor &v) { return v.visit(this); } |
78 | 79 | ||
79 | QDateTime mDtEnd; | 80 | QDateTime mDtEnd; |
80 | bool mHasEndDate; | 81 | bool mHasEndDate; |
81 | Transparency mTransparency; | 82 | Transparency mTransparency; |
82 | }; | 83 | }; |
83 | 84 | ||
84 | bool operator==( const Event&, const Event& ); | 85 | bool operator==( const Event&, const Event& ); |
85 | 86 | ||
86 | 87 | ||
87 | } | 88 | } |
88 | 89 | ||
89 | 90 | ||
90 | #endif | 91 | #endif |
diff --git a/libkcal/freebusy.h b/libkcal/freebusy.h index 054feda..d741c72 100644 --- a/libkcal/freebusy.h +++ b/libkcal/freebusy.h | |||
@@ -1,72 +1,73 @@ | |||
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 KCAL_FREEBUSY_H | 20 | #ifndef KCAL_FREEBUSY_H |
21 | #define KCAL_FREEBUSY_H | 21 | #define KCAL_FREEBUSY_H |
22 | // | 22 | // |
23 | // FreeBusy - information about free/busy times | 23 | // FreeBusy - information about free/busy times |
24 | // | 24 | // |
25 | 25 | ||
26 | #include <qdatetime.h> | 26 | #include <qdatetime.h> |
27 | #include <qvaluelist.h> | 27 | #include <qvaluelist.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | 29 | ||
30 | #include "period.h" | 30 | #include "period.h" |
31 | #include "calendar.h" | 31 | #include "calendar.h" |
32 | 32 | ||
33 | #include "incidencebase.h" | 33 | #include "incidencebase.h" |
34 | 34 | ||
35 | namespace KCal { | 35 | namespace KCal { |
36 | 36 | ||
37 | /** | 37 | /** |
38 | This class provides information about free/busy time of a calendar user. | 38 | This class provides information about free/busy time of a calendar user. |
39 | */ | 39 | */ |
40 | class FreeBusy : public IncidenceBase | 40 | class FreeBusy : public IncidenceBase |
41 | { | 41 | { |
42 | public: | 42 | public: |
43 | FreeBusy(); | 43 | FreeBusy(); |
44 | FreeBusy(const QDateTime &start, const QDateTime &end); | 44 | FreeBusy(const QDateTime &start, const QDateTime &end); |
45 | FreeBusy(Calendar *calendar, const QDateTime &start, const QDateTime &end); | 45 | FreeBusy(Calendar *calendar, const QDateTime &start, const QDateTime &end); |
46 | FreeBusy(QValueList<Period> busyPeriods); | 46 | FreeBusy(QValueList<Period> busyPeriods); |
47 | 47 | ||
48 | ~FreeBusy(); | 48 | ~FreeBusy(); |
49 | 49 | ||
50 | QCString type() const { return "FreeBusy"; } | 50 | QCString type() const { return "FreeBusy"; } |
51 | IncTypeID typeID() const { return freebusyID; } | ||
51 | 52 | ||
52 | virtual QDateTime dtEnd() const; | 53 | virtual QDateTime dtEnd() const; |
53 | bool setDtEnd( const QDateTime &end ); | 54 | bool setDtEnd( const QDateTime &end ); |
54 | 55 | ||
55 | QValueList<Period> busyPeriods() const; | 56 | QValueList<Period> busyPeriods() const; |
56 | 57 | ||
57 | void addPeriod(const QDateTime &start, const QDateTime &end); | 58 | void addPeriod(const QDateTime &start, const QDateTime &end); |
58 | void sortList(); | 59 | void sortList(); |
59 | 60 | ||
60 | private: | 61 | private: |
61 | 62 | ||
62 | //This is used for creating a freebusy object for the current user | 63 | //This is used for creating a freebusy object for the current user |
63 | bool addLocalPeriod(const QDateTime &start, const QDateTime &end); | 64 | bool addLocalPeriod(const QDateTime &start, const QDateTime &end); |
64 | 65 | ||
65 | QDateTime mDtEnd; | 66 | QDateTime mDtEnd; |
66 | QValueList<Period> mBusyPeriods; | 67 | QValueList<Period> mBusyPeriods; |
67 | Calendar *mCalendar; | 68 | Calendar *mCalendar; |
68 | }; | 69 | }; |
69 | 70 | ||
70 | } | 71 | } |
71 | 72 | ||
72 | #endif | 73 | #endif |
diff --git a/libkcal/icalformat.cpp b/libkcal/icalformat.cpp index 3a2aac6..d9fe40b 100644 --- a/libkcal/icalformat.cpp +++ b/libkcal/icalformat.cpp | |||
@@ -3,458 +3,458 @@ | |||
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 | 20 | ||
21 | #include <qdatetime.h> | 21 | #include <qdatetime.h> |
22 | #include <qstring.h> | 22 | #include <qstring.h> |
23 | #include <qptrlist.h> | 23 | #include <qptrlist.h> |
24 | #include <qregexp.h> | 24 | #include <qregexp.h> |
25 | #include <qclipboard.h> | 25 | #include <qclipboard.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qtextstream.h> | 27 | #include <qtextstream.h> |
28 | #include <qtextcodec.h> | 28 | #include <qtextcodec.h> |
29 | #include <stdlib.h> | 29 | #include <stdlib.h> |
30 | 30 | ||
31 | #include <kdebug.h> | 31 | #include <kdebug.h> |
32 | #include <kglobal.h> | 32 | #include <kglobal.h> |
33 | #include <klocale.h> | 33 | #include <klocale.h> |
34 | 34 | ||
35 | extern "C" { | 35 | extern "C" { |
36 | #include <ical.h> | 36 | #include <ical.h> |
37 | #include <icalss.h> | 37 | #include <icalss.h> |
38 | #include <icalparser.h> | 38 | #include <icalparser.h> |
39 | #include <icalrestriction.h> | 39 | #include <icalrestriction.h> |
40 | } | 40 | } |
41 | 41 | ||
42 | #include "calendar.h" | 42 | #include "calendar.h" |
43 | #include "calendarlocal.h" | 43 | #include "calendarlocal.h" |
44 | #include "journal.h" | 44 | #include "journal.h" |
45 | 45 | ||
46 | #include "icalformat.h" | 46 | #include "icalformat.h" |
47 | #include "icalformatimpl.h" | 47 | #include "icalformatimpl.h" |
48 | 48 | ||
49 | #define _ICAL_VERSION "2.0" | 49 | #define _ICAL_VERSION "2.0" |
50 | 50 | ||
51 | using namespace KCal; | 51 | using namespace KCal; |
52 | 52 | ||
53 | ICalFormat::ICalFormat( ) | 53 | ICalFormat::ICalFormat( ) |
54 | { | 54 | { |
55 | mImpl = new ICalFormatImpl( this ); | 55 | mImpl = new ICalFormatImpl( this ); |
56 | tzOffsetMin = 0; | 56 | tzOffsetMin = 0; |
57 | //qDebug("new ICalFormat() "); | 57 | //qDebug("new ICalFormat() "); |
58 | } | 58 | } |
59 | 59 | ||
60 | ICalFormat::~ICalFormat() | 60 | ICalFormat::~ICalFormat() |
61 | { | 61 | { |
62 | delete mImpl; | 62 | delete mImpl; |
63 | //qDebug("delete ICalFormat "); | 63 | //qDebug("delete ICalFormat "); |
64 | } | 64 | } |
65 | 65 | ||
66 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) | 66 | bool ICalFormat::load( Calendar *calendar, const QString &fileName) |
67 | { | 67 | { |
68 | 68 | ||
69 | clearException(); | 69 | clearException(); |
70 | 70 | ||
71 | QFile file( fileName ); | 71 | QFile file( fileName ); |
72 | if (!file.open( IO_ReadOnly ) ) { | 72 | if (!file.open( IO_ReadOnly ) ) { |
73 | setException(new ErrorFormat(ErrorFormat::LoadError)); | 73 | setException(new ErrorFormat(ErrorFormat::LoadError)); |
74 | return false; | 74 | return false; |
75 | } | 75 | } |
76 | QTextStream ts( &file ); | 76 | QTextStream ts( &file ); |
77 | QString text; | 77 | QString text; |
78 | 78 | ||
79 | ts.setEncoding( QTextStream::Latin1 ); | 79 | ts.setEncoding( QTextStream::Latin1 ); |
80 | text = ts.read(); | 80 | text = ts.read(); |
81 | file.close(); | 81 | file.close(); |
82 | 82 | ||
83 | return fromString( calendar, text ); | 83 | return fromString( calendar, text ); |
84 | } | 84 | } |
85 | 85 | ||
86 | //#include <qdatetime.h> | 86 | //#include <qdatetime.h> |
87 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) | 87 | bool ICalFormat::save( Calendar *calendar, const QString &fileName ) |
88 | { | 88 | { |
89 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; | 89 | //kdDebug(5800) << "ICalFormat::save(): " << fileName << endl; |
90 | //qDebug("ICalFormat::save "); | 90 | //qDebug("ICalFormat::save "); |
91 | clearException(); | 91 | clearException(); |
92 | QString text = toString( calendar ); | 92 | QString text = toString( calendar ); |
93 | //return false; | 93 | //return false; |
94 | // qDebug("to string takes ms: %d ",is.elapsed() ); | 94 | // qDebug("to string takes ms: %d ",is.elapsed() ); |
95 | if ( text.isNull() ) return false; | 95 | if ( text.isNull() ) return false; |
96 | 96 | ||
97 | // TODO: write backup file | 97 | // TODO: write backup file |
98 | //is.restart(); | 98 | //is.restart(); |
99 | QFile file( fileName ); | 99 | QFile file( fileName ); |
100 | if (!file.open( IO_WriteOnly ) ) { | 100 | if (!file.open( IO_WriteOnly ) ) { |
101 | setException(new ErrorFormat(ErrorFormat::SaveError, | 101 | setException(new ErrorFormat(ErrorFormat::SaveError, |
102 | i18n("Could not open file '%1'").arg(fileName))); | 102 | i18n("Could not open file '%1'").arg(fileName))); |
103 | return false; | 103 | return false; |
104 | } | 104 | } |
105 | QTextStream ts( &file ); | 105 | QTextStream ts( &file ); |
106 | 106 | ||
107 | ts.setEncoding( QTextStream::Latin1 ); | 107 | ts.setEncoding( QTextStream::Latin1 ); |
108 | ts << text; | 108 | ts << text; |
109 | file.close(); | 109 | file.close(); |
110 | //qDebug("saving file takes ms: %d ", is.elapsed() ); | 110 | //qDebug("saving file takes ms: %d ", is.elapsed() ); |
111 | return true; | 111 | return true; |
112 | } | 112 | } |
113 | 113 | ||
114 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) | 114 | bool ICalFormat::fromString( Calendar *cal, const QString &text ) |
115 | { | 115 | { |
116 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 116 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
117 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); | 117 | // qDebug("ICalFormat::fromString tz: %s ", cal->timeZoneId().latin1()); |
118 | // Get first VCALENDAR component. | 118 | // Get first VCALENDAR component. |
119 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components | 119 | // TODO: Handle more than one VCALENDAR or non-VCALENDAR top components |
120 | icalcomponent *calendar; | 120 | icalcomponent *calendar; |
121 | 121 | ||
122 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); | 122 | //calendar = icalcomponent_new_from_string( text.local8Bit().data()); |
123 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); | 123 | // good calendar = icalcomponent_new_from_string( text.utf8().data()); |
124 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); | 124 | calendar = icalcomponent_new_from_string( (char*)text.latin1()); |
125 | if (!calendar) { | 125 | if (!calendar) { |
126 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); | 126 | setException(new ErrorFormat(ErrorFormat::ParseErrorIcal)); |
127 | return false; | 127 | return false; |
128 | } | 128 | } |
129 | 129 | ||
130 | bool success = true; | 130 | bool success = true; |
131 | 131 | ||
132 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { | 132 | if (icalcomponent_isa(calendar) != ICAL_VCALENDAR_COMPONENT) { |
133 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); | 133 | setException(new ErrorFormat(ErrorFormat::NoCalendar)); |
134 | success = false; | 134 | success = false; |
135 | } else { | 135 | } else { |
136 | // put all objects into their proper places | 136 | // put all objects into their proper places |
137 | if ( !mImpl->populate( cal, calendar ) ) { | 137 | if ( !mImpl->populate( cal, calendar ) ) { |
138 | if ( !exception() ) { | 138 | if ( !exception() ) { |
139 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); | 139 | setException(new ErrorFormat(ErrorFormat::ParseErrorKcal)); |
140 | } | 140 | } |
141 | success = false; | 141 | success = false; |
142 | } else | 142 | } else |
143 | mLoadedProductId = mImpl->loadedProductId(); | 143 | mLoadedProductId = mImpl->loadedProductId(); |
144 | } | 144 | } |
145 | 145 | ||
146 | icalcomponent_free( calendar ); | 146 | icalcomponent_free( calendar ); |
147 | 147 | ||
148 | return success; | 148 | return success; |
149 | } | 149 | } |
150 | 150 | ||
151 | Incidence *ICalFormat::fromString( const QString &text ) | 151 | Incidence *ICalFormat::fromString( const QString &text ) |
152 | { | 152 | { |
153 | CalendarLocal cal( mTimeZoneId ); | 153 | CalendarLocal cal( mTimeZoneId ); |
154 | fromString(&cal, text); | 154 | fromString(&cal, text); |
155 | 155 | ||
156 | Incidence *ical = 0; | 156 | Incidence *ical = 0; |
157 | QPtrList<Event> elist = cal.events(); | 157 | QPtrList<Event> elist = cal.events(); |
158 | if ( elist.count() > 0 ) { | 158 | if ( elist.count() > 0 ) { |
159 | ical = elist.first(); | 159 | ical = elist.first(); |
160 | } else { | 160 | } else { |
161 | QPtrList<Todo> tlist = cal.todos(); | 161 | QPtrList<Todo> tlist = cal.todos(); |
162 | if ( tlist.count() > 0 ) { | 162 | if ( tlist.count() > 0 ) { |
163 | ical = tlist.first(); | 163 | ical = tlist.first(); |
164 | } else { | 164 | } else { |
165 | QPtrList<Journal> jlist = cal.journals(); | 165 | QPtrList<Journal> jlist = cal.journals(); |
166 | if ( jlist.count() > 0 ) { | 166 | if ( jlist.count() > 0 ) { |
167 | ical = jlist.first(); | 167 | ical = jlist.first(); |
168 | } | 168 | } |
169 | } | 169 | } |
170 | } | 170 | } |
171 | return ical; | 171 | return ical; |
172 | } | 172 | } |
173 | #include <qapp.h> | 173 | #include <qapp.h> |
174 | 174 | ||
175 | QString ICalFormat::toString( Calendar *cal ) | 175 | QString ICalFormat::toString( Calendar *cal ) |
176 | { | 176 | { |
177 | 177 | ||
178 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 178 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
179 | 179 | ||
180 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); | 180 | icalcomponent *calendar = mImpl->createCalendarComponent(cal); |
181 | 181 | ||
182 | icalcomponent *component; | 182 | icalcomponent *component; |
183 | 183 | ||
184 | // todos | 184 | // todos |
185 | QPtrList<Todo> todoList = cal->rawTodos(); | 185 | QPtrList<Todo> todoList = cal->rawTodos(); |
186 | QPtrListIterator<Todo> qlt(todoList); | 186 | QPtrListIterator<Todo> qlt(todoList); |
187 | for (; qlt.current(); ++qlt) { | 187 | for (; qlt.current(); ++qlt) { |
188 | component = mImpl->writeTodo(qlt.current()); | 188 | component = mImpl->writeTodo(qlt.current()); |
189 | icalcomponent_add_component(calendar,component); | 189 | icalcomponent_add_component(calendar,component); |
190 | //qDebug(" todos "); | 190 | //qDebug(" todos "); |
191 | qApp->processEvents(); | 191 | qApp->processEvents(); |
192 | } | 192 | } |
193 | // events | 193 | // events |
194 | QPtrList<Event> events = cal->rawEvents(); | 194 | QPtrList<Event> events = cal->rawEvents(); |
195 | Event *ev; | 195 | Event *ev; |
196 | for(ev=events.first();ev;ev=events.next()) { | 196 | for(ev=events.first();ev;ev=events.next()) { |
197 | component = mImpl->writeEvent(ev); | 197 | component = mImpl->writeEvent(ev); |
198 | icalcomponent_add_component(calendar,component); | 198 | icalcomponent_add_component(calendar,component); |
199 | //qDebug("events "); | 199 | //qDebug("events "); |
200 | qApp->processEvents(); | 200 | qApp->processEvents(); |
201 | } | 201 | } |
202 | 202 | ||
203 | // journals | 203 | // journals |
204 | QPtrList<Journal> journals = cal->journals(); | 204 | QPtrList<Journal> journals = cal->journals(); |
205 | Journal *j; | 205 | Journal *j; |
206 | for(j=journals.first();j;j=journals.next()) { | 206 | for(j=journals.first();j;j=journals.next()) { |
207 | component = mImpl->writeJournal(j); | 207 | component = mImpl->writeJournal(j); |
208 | icalcomponent_add_component(calendar,component); | 208 | icalcomponent_add_component(calendar,component); |
209 | //qDebug("journals "); | 209 | //qDebug("journals "); |
210 | qApp->processEvents(); | 210 | qApp->processEvents(); |
211 | } | 211 | } |
212 | const char *text; | 212 | const char *text; |
213 | QString ret =""; | 213 | QString ret =""; |
214 | text = icalcomponent_as_ical_string( calendar ); | 214 | text = icalcomponent_as_ical_string( calendar ); |
215 | qApp->processEvents(); | 215 | qApp->processEvents(); |
216 | 216 | ||
217 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; | 217 | // text = "BEGIN:VCALENDAR\nPRODID\n :-//K Desktop Environment//NONSGML libkcal 3.1//EN\nVERSION\n :2.0\nBEGIN:VEVENT\nDTSTAMP\n :20031231T213514Z\nORGANIZER\n :MAILTO:lutz@putz.de\nCREATED\n :20031231T213513Z\nUID\n :libkcal-1295166342.120\nSEQUENCE\n :0\nLAST-MODIFIED\n :20031231T213513Z\nSUMMARY\n :test1\nCLASS\n :PUBLIC\nPRIORITY\n :3\nDTSTART\n :20040101T090000Z\nDTEND\n :20040101T110000Z\nTRANSP\n :OPAQUE\nEND:VEVENT\nEND:VCALENDAR\n"; |
218 | 218 | ||
219 | 219 | ||
220 | if ( text ) { | 220 | if ( text ) { |
221 | ret = QString ( text ); | 221 | ret = QString ( text ); |
222 | } | 222 | } |
223 | icalcomponent_free( calendar ); | 223 | icalcomponent_free( calendar ); |
224 | 224 | ||
225 | if (!text) { | 225 | if (!text) { |
226 | setException(new ErrorFormat(ErrorFormat::SaveError, | 226 | setException(new ErrorFormat(ErrorFormat::SaveError, |
227 | i18n("libical error"))); | 227 | i18n("libical error"))); |
228 | return QString::null; | 228 | return QString::null; |
229 | } | 229 | } |
230 | 230 | ||
231 | return ret; | 231 | return ret; |
232 | } | 232 | } |
233 | 233 | ||
234 | QString ICalFormat::toICalString( Incidence *incidence ) | 234 | QString ICalFormat::toICalString( Incidence *incidence ) |
235 | { | 235 | { |
236 | CalendarLocal cal( mTimeZoneId ); | 236 | CalendarLocal cal( mTimeZoneId ); |
237 | cal.addIncidence( incidence->clone() ); | 237 | cal.addIncidence( incidence->clone() ); |
238 | return toString( &cal ); | 238 | return toString( &cal ); |
239 | } | 239 | } |
240 | 240 | ||
241 | QString ICalFormat::toString( Incidence *incidence ) | 241 | QString ICalFormat::toString( Incidence *incidence ) |
242 | { | 242 | { |
243 | icalcomponent *component; | 243 | icalcomponent *component; |
244 | 244 | ||
245 | component = mImpl->writeIncidence( incidence ); | 245 | component = mImpl->writeIncidence( incidence ); |
246 | 246 | ||
247 | const char *text = icalcomponent_as_ical_string( component ); | 247 | const char *text = icalcomponent_as_ical_string( component ); |
248 | 248 | ||
249 | icalcomponent_free( component ); | 249 | icalcomponent_free( component ); |
250 | 250 | ||
251 | return QString::fromLocal8Bit( text ); | 251 | return QString::fromLocal8Bit( text ); |
252 | } | 252 | } |
253 | 253 | ||
254 | QString ICalFormat::toString( Recurrence *recurrence ) | 254 | QString ICalFormat::toString( Recurrence *recurrence ) |
255 | { | 255 | { |
256 | icalproperty *property; | 256 | icalproperty *property; |
257 | property = mImpl->writeRecurrenceRule( recurrence ); | 257 | property = mImpl->writeRecurrenceRule( recurrence ); |
258 | const char *text = icalproperty_as_ical_string( property ); | 258 | const char *text = icalproperty_as_ical_string( property ); |
259 | icalproperty_free( property ); | 259 | icalproperty_free( property ); |
260 | return QString::fromLocal8Bit( text ); | 260 | return QString::fromLocal8Bit( text ); |
261 | } | 261 | } |
262 | /* | 262 | /* |
263 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) | 263 | bool ICalFormat::fromString( Recurrence * recurrence, const QString& rrule ) |
264 | { | 264 | { |
265 | bool success = true; | 265 | bool success = true; |
266 | icalerror_clear_errno(); | 266 | icalerror_clear_errno(); |
267 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); | 267 | struct icalrecurrencetype recur = icalrecurrencetype_from_string( rrule ); |
268 | if ( icalerrno != ICAL_NO_ERROR ) { | 268 | if ( icalerrno != ICAL_NO_ERROR ) { |
269 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; | 269 | kdDebug() << "Recurrence parsing error: " << icalerror_strerror( icalerrno ) << endl; |
270 | success = false; | 270 | success = false; |
271 | } | 271 | } |
272 | 272 | ||
273 | if ( success ) { | 273 | if ( success ) { |
274 | mImpl->readRecurrence( recur, recurrence ); | 274 | mImpl->readRecurrence( recur, recurrence ); |
275 | } | 275 | } |
276 | 276 | ||
277 | return success; | 277 | return success; |
278 | } | 278 | } |
279 | */ | 279 | */ |
280 | 280 | ||
281 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, | 281 | QString ICalFormat::createScheduleMessage(IncidenceBase *incidence, |
282 | Scheduler::Method method) | 282 | Scheduler::Method method) |
283 | { | 283 | { |
284 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); | 284 | icalcomponent *message = mImpl->createScheduleComponent(incidence,method); |
285 | 285 | ||
286 | QString messageText = icalcomponent_as_ical_string(message); | 286 | QString messageText = icalcomponent_as_ical_string(message); |
287 | 287 | ||
288 | 288 | ||
289 | 289 | ||
290 | return messageText; | 290 | return messageText; |
291 | } | 291 | } |
292 | 292 | ||
293 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, | 293 | ScheduleMessage *ICalFormat::parseScheduleMessage( Calendar *cal, |
294 | const QString &messageText ) | 294 | const QString &messageText ) |
295 | { | 295 | { |
296 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); | 296 | setTimeZone( cal->timeZoneId(), !cal->isLocalTime() ); |
297 | clearException(); | 297 | clearException(); |
298 | 298 | ||
299 | if (messageText.isEmpty()) return 0; | 299 | if (messageText.isEmpty()) return 0; |
300 | 300 | ||
301 | icalcomponent *message; | 301 | icalcomponent *message; |
302 | message = icalparser_parse_string(messageText.local8Bit()); | 302 | message = icalparser_parse_string(messageText.local8Bit()); |
303 | 303 | ||
304 | if (!message) return 0; | 304 | if (!message) return 0; |
305 | 305 | ||
306 | icalproperty *m = icalcomponent_get_first_property(message, | 306 | icalproperty *m = icalcomponent_get_first_property(message, |
307 | ICAL_METHOD_PROPERTY); | 307 | ICAL_METHOD_PROPERTY); |
308 | 308 | ||
309 | if (!m) return 0; | 309 | if (!m) return 0; |
310 | 310 | ||
311 | icalcomponent *c; | 311 | icalcomponent *c; |
312 | 312 | ||
313 | IncidenceBase *incidence = 0; | 313 | IncidenceBase *incidence = 0; |
314 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); | 314 | c = icalcomponent_get_first_component(message,ICAL_VEVENT_COMPONENT); |
315 | if (c) { | 315 | if (c) { |
316 | incidence = mImpl->readEvent(c); | 316 | incidence = mImpl->readEvent(c); |
317 | } | 317 | } |
318 | 318 | ||
319 | if (!incidence) { | 319 | if (!incidence) { |
320 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); | 320 | c = icalcomponent_get_first_component(message,ICAL_VTODO_COMPONENT); |
321 | if (c) { | 321 | if (c) { |
322 | incidence = mImpl->readTodo(c); | 322 | incidence = mImpl->readTodo(c); |
323 | } | 323 | } |
324 | } | 324 | } |
325 | 325 | ||
326 | if (!incidence) { | 326 | if (!incidence) { |
327 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); | 327 | c = icalcomponent_get_first_component(message,ICAL_VFREEBUSY_COMPONENT); |
328 | if (c) { | 328 | if (c) { |
329 | incidence = mImpl->readFreeBusy(c); | 329 | incidence = mImpl->readFreeBusy(c); |
330 | } | 330 | } |
331 | } | 331 | } |
332 | 332 | ||
333 | if (!incidence) { | 333 | if (!incidence) { |
334 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; | 334 | kdDebug() << "ICalFormat:parseScheduleMessage: object is not a freebusy, event or todo" << endl; |
335 | return 0; | 335 | return 0; |
336 | } | 336 | } |
337 | 337 | ||
338 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; | 338 | kdDebug(5800) << "ICalFormat::parseScheduleMessage() getting method..." << endl; |
339 | 339 | ||
340 | icalproperty_method icalmethod = icalproperty_get_method(m); | 340 | icalproperty_method icalmethod = icalproperty_get_method(m); |
341 | Scheduler::Method method; | 341 | Scheduler::Method method; |
342 | 342 | ||
343 | switch (icalmethod) { | 343 | switch (icalmethod) { |
344 | case ICAL_METHOD_PUBLISH: | 344 | case ICAL_METHOD_PUBLISH: |
345 | method = Scheduler::Publish; | 345 | method = Scheduler::Publish; |
346 | break; | 346 | break; |
347 | case ICAL_METHOD_REQUEST: | 347 | case ICAL_METHOD_REQUEST: |
348 | method = Scheduler::Request; | 348 | method = Scheduler::Request; |
349 | break; | 349 | break; |
350 | case ICAL_METHOD_REFRESH: | 350 | case ICAL_METHOD_REFRESH: |
351 | method = Scheduler::Refresh; | 351 | method = Scheduler::Refresh; |
352 | break; | 352 | break; |
353 | case ICAL_METHOD_CANCEL: | 353 | case ICAL_METHOD_CANCEL: |
354 | method = Scheduler::Cancel; | 354 | method = Scheduler::Cancel; |
355 | break; | 355 | break; |
356 | case ICAL_METHOD_ADD: | 356 | case ICAL_METHOD_ADD: |
357 | method = Scheduler::Add; | 357 | method = Scheduler::Add; |
358 | break; | 358 | break; |
359 | case ICAL_METHOD_REPLY: | 359 | case ICAL_METHOD_REPLY: |
360 | method = Scheduler::Reply; | 360 | method = Scheduler::Reply; |
361 | break; | 361 | break; |
362 | case ICAL_METHOD_COUNTER: | 362 | case ICAL_METHOD_COUNTER: |
363 | method = Scheduler::Counter; | 363 | method = Scheduler::Counter; |
364 | break; | 364 | break; |
365 | case ICAL_METHOD_DECLINECOUNTER: | 365 | case ICAL_METHOD_DECLINECOUNTER: |
366 | method = Scheduler::Declinecounter; | 366 | method = Scheduler::Declinecounter; |
367 | break; | 367 | break; |
368 | default: | 368 | default: |
369 | method = Scheduler::NoMethod; | 369 | method = Scheduler::NoMethod; |
370 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; | 370 | kdDebug(5800) << "ICalFormat::parseScheduleMessage(): Unknow method" << endl; |
371 | break; | 371 | break; |
372 | } | 372 | } |
373 | 373 | ||
374 | 374 | ||
375 | if (!icalrestriction_check(message)) { | 375 | if (!icalrestriction_check(message)) { |
376 | setException(new ErrorFormat(ErrorFormat::Restriction, | 376 | setException(new ErrorFormat(ErrorFormat::Restriction, |
377 | Scheduler::translatedMethodName(method) + ": " + | 377 | Scheduler::translatedMethodName(method) + ": " + |
378 | mImpl->extractErrorProperty(c))); | 378 | mImpl->extractErrorProperty(c))); |
379 | return 0; | 379 | return 0; |
380 | } | 380 | } |
381 | 381 | ||
382 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); | 382 | icalcomponent *calendarComponent = mImpl->createCalendarComponent(cal); |
383 | 383 | ||
384 | Incidence *existingIncidence = cal->event(incidence->uid()); | 384 | Incidence *existingIncidence = cal->event(incidence->uid()); |
385 | if (existingIncidence) { | 385 | if (existingIncidence) { |
386 | // TODO: check, if cast is required, or if it can be done by virtual funcs. | 386 | // TODO: check, if cast is required, or if it can be done by virtual funcs. |
387 | if (existingIncidence->type() == "Todo") { | 387 | if (existingIncidence->typeID() == todoID ) { |
388 | Todo *todo = static_cast<Todo *>(existingIncidence); | 388 | Todo *todo = static_cast<Todo *>(existingIncidence); |
389 | icalcomponent_add_component(calendarComponent, | 389 | icalcomponent_add_component(calendarComponent, |
390 | mImpl->writeTodo(todo)); | 390 | mImpl->writeTodo(todo)); |
391 | } | 391 | } |
392 | if (existingIncidence->type() == "Event") { | 392 | if (existingIncidence->typeID() == eventID ) { |
393 | Event *event = static_cast<Event *>(existingIncidence); | 393 | Event *event = static_cast<Event *>(existingIncidence); |
394 | icalcomponent_add_component(calendarComponent, | 394 | icalcomponent_add_component(calendarComponent, |
395 | mImpl->writeEvent(event)); | 395 | mImpl->writeEvent(event)); |
396 | } | 396 | } |
397 | } else { | 397 | } else { |
398 | calendarComponent = 0; | 398 | calendarComponent = 0; |
399 | } | 399 | } |
400 | qDebug("icalclassify commented out "); | 400 | qDebug("icalclassify commented out "); |
401 | ScheduleMessage::Status status; | 401 | ScheduleMessage::Status status; |
402 | #if 0 | 402 | #if 0 |
403 | 403 | ||
404 | icalclass result = icalclassify(message,calendarComponent,(char *)""); | 404 | icalclass result = icalclassify(message,calendarComponent,(char *)""); |
405 | 405 | ||
406 | 406 | ||
407 | 407 | ||
408 | switch (result) { | 408 | switch (result) { |
409 | case ICAL_PUBLISH_NEW_CLASS: | 409 | case ICAL_PUBLISH_NEW_CLASS: |
410 | status = ScheduleMessage::PublishNew; | 410 | status = ScheduleMessage::PublishNew; |
411 | break; | 411 | break; |
412 | case ICAL_OBSOLETE_CLASS: | 412 | case ICAL_OBSOLETE_CLASS: |
413 | status = ScheduleMessage::Obsolete; | 413 | status = ScheduleMessage::Obsolete; |
414 | break; | 414 | break; |
415 | case ICAL_REQUEST_NEW_CLASS: | 415 | case ICAL_REQUEST_NEW_CLASS: |
416 | status = ScheduleMessage::RequestNew; | 416 | status = ScheduleMessage::RequestNew; |
417 | break; | 417 | break; |
418 | case ICAL_REQUEST_UPDATE_CLASS: | 418 | case ICAL_REQUEST_UPDATE_CLASS: |
419 | status = ScheduleMessage::RequestUpdate; | 419 | status = ScheduleMessage::RequestUpdate; |
420 | break; | 420 | break; |
421 | case ICAL_UNKNOWN_CLASS: | 421 | case ICAL_UNKNOWN_CLASS: |
422 | default: | 422 | default: |
423 | status = ScheduleMessage::Unknown; | 423 | status = ScheduleMessage::Unknown; |
424 | break; | 424 | break; |
425 | } | 425 | } |
426 | #endif | 426 | #endif |
427 | status = ScheduleMessage::RequestUpdate; | 427 | status = ScheduleMessage::RequestUpdate; |
428 | return new ScheduleMessage(incidence,method,status); | 428 | return new ScheduleMessage(incidence,method,status); |
429 | } | 429 | } |
430 | 430 | ||
431 | void ICalFormat::setTimeZone( const QString &id, bool utc ) | 431 | void ICalFormat::setTimeZone( const QString &id, bool utc ) |
432 | { | 432 | { |
433 | 433 | ||
434 | 434 | ||
435 | mTimeZoneId = id; | 435 | mTimeZoneId = id; |
436 | mUtc = utc; | 436 | mUtc = utc; |
437 | 437 | ||
438 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 438 | tzOffsetMin = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
439 | 439 | ||
440 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); | 440 | //qDebug("ICalFormat::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), tzOffsetMin); |
441 | } | 441 | } |
442 | 442 | ||
443 | QString ICalFormat::timeZoneId() const | 443 | QString ICalFormat::timeZoneId() const |
444 | { | 444 | { |
445 | return mTimeZoneId; | 445 | return mTimeZoneId; |
446 | } | 446 | } |
447 | 447 | ||
448 | bool ICalFormat::utc() const | 448 | bool ICalFormat::utc() const |
449 | { | 449 | { |
450 | return mUtc; | 450 | return mUtc; |
451 | } | 451 | } |
452 | int ICalFormat::timeOffset() | 452 | int ICalFormat::timeOffset() |
453 | { | 453 | { |
454 | return tzOffsetMin; | 454 | return tzOffsetMin; |
455 | } | 455 | } |
456 | const char *ICalFormat::tzString() | 456 | const char *ICalFormat::tzString() |
457 | { | 457 | { |
458 | const char* ret = (const char* ) mTzString; | 458 | const char* ret = (const char* ) mTzString; |
459 | return ret; | 459 | return ret; |
460 | } | 460 | } |
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp index 2405682..3e28714 100644 --- a/libkcal/icalformatimpl.cpp +++ b/libkcal/icalformatimpl.cpp | |||
@@ -1774,399 +1774,399 @@ icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) | |||
1774 | 1774 | ||
1775 | d.is_neg = (seconds<0)?1:0; | 1775 | d.is_neg = (seconds<0)?1:0; |
1776 | if (seconds<0) seconds = -seconds; | 1776 | if (seconds<0) seconds = -seconds; |
1777 | 1777 | ||
1778 | d.weeks = seconds / gSecondsPerWeek; | 1778 | d.weeks = seconds / gSecondsPerWeek; |
1779 | seconds %= gSecondsPerWeek; | 1779 | seconds %= gSecondsPerWeek; |
1780 | d.days = seconds / gSecondsPerDay; | 1780 | d.days = seconds / gSecondsPerDay; |
1781 | seconds %= gSecondsPerDay; | 1781 | seconds %= gSecondsPerDay; |
1782 | d.hours = seconds / gSecondsPerHour; | 1782 | d.hours = seconds / gSecondsPerHour; |
1783 | seconds %= gSecondsPerHour; | 1783 | seconds %= gSecondsPerHour; |
1784 | d.minutes = seconds / gSecondsPerMinute; | 1784 | d.minutes = seconds / gSecondsPerMinute; |
1785 | seconds %= gSecondsPerMinute; | 1785 | seconds %= gSecondsPerMinute; |
1786 | d.seconds = seconds; | 1786 | d.seconds = seconds; |
1787 | return d; | 1787 | return d; |
1788 | } | 1788 | } |
1789 | 1789 | ||
1790 | int ICalFormatImpl::readICalDuration(icaldurationtype d) | 1790 | int ICalFormatImpl::readICalDuration(icaldurationtype d) |
1791 | { | 1791 | { |
1792 | int result = 0; | 1792 | int result = 0; |
1793 | 1793 | ||
1794 | result += d.weeks * gSecondsPerWeek; | 1794 | result += d.weeks * gSecondsPerWeek; |
1795 | result += d.days * gSecondsPerDay; | 1795 | result += d.days * gSecondsPerDay; |
1796 | result += d.hours * gSecondsPerHour; | 1796 | result += d.hours * gSecondsPerHour; |
1797 | result += d.minutes * gSecondsPerMinute; | 1797 | result += d.minutes * gSecondsPerMinute; |
1798 | result += d.seconds; | 1798 | result += d.seconds; |
1799 | 1799 | ||
1800 | if (d.is_neg) result *= -1; | 1800 | if (d.is_neg) result *= -1; |
1801 | 1801 | ||
1802 | return result; | 1802 | return result; |
1803 | } | 1803 | } |
1804 | 1804 | ||
1805 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) | 1805 | icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) |
1806 | { | 1806 | { |
1807 | icalcomponent *calendar; | 1807 | icalcomponent *calendar; |
1808 | 1808 | ||
1809 | // Root component | 1809 | // Root component |
1810 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); | 1810 | calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); |
1811 | 1811 | ||
1812 | icalproperty *p; | 1812 | icalproperty *p; |
1813 | 1813 | ||
1814 | // Product Identifier | 1814 | // Product Identifier |
1815 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); | 1815 | p = icalproperty_new_prodid(CalFormat::productId().utf8()); |
1816 | icalcomponent_add_property(calendar,p); | 1816 | icalcomponent_add_property(calendar,p); |
1817 | 1817 | ||
1818 | // TODO: Add time zone | 1818 | // TODO: Add time zone |
1819 | 1819 | ||
1820 | // iCalendar version (2.0) | 1820 | // iCalendar version (2.0) |
1821 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); | 1821 | p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); |
1822 | icalcomponent_add_property(calendar,p); | 1822 | icalcomponent_add_property(calendar,p); |
1823 | 1823 | ||
1824 | // Custom properties | 1824 | // Custom properties |
1825 | if( cal != 0 ) | 1825 | if( cal != 0 ) |
1826 | writeCustomProperties(calendar, cal); | 1826 | writeCustomProperties(calendar, cal); |
1827 | 1827 | ||
1828 | return calendar; | 1828 | return calendar; |
1829 | } | 1829 | } |
1830 | 1830 | ||
1831 | 1831 | ||
1832 | 1832 | ||
1833 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. | 1833 | // take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. |
1834 | // and break it down from its tree-like format into the dictionary format | 1834 | // and break it down from its tree-like format into the dictionary format |
1835 | // that is used internally in the ICalFormatImpl. | 1835 | // that is used internally in the ICalFormatImpl. |
1836 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) | 1836 | bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) |
1837 | { | 1837 | { |
1838 | // this function will populate the caldict dictionary and other event | 1838 | // this function will populate the caldict dictionary and other event |
1839 | // lists. It turns vevents into Events and then inserts them. | 1839 | // lists. It turns vevents into Events and then inserts them. |
1840 | 1840 | ||
1841 | if (!calendar) return false; | 1841 | if (!calendar) return false; |
1842 | 1842 | ||
1843 | // TODO: check for METHOD | 1843 | // TODO: check for METHOD |
1844 | #if 0 | 1844 | #if 0 |
1845 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { | 1845 | if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { |
1846 | char *methodType = 0; | 1846 | char *methodType = 0; |
1847 | methodType = fakeCString(vObjectUStringZValue(curVO)); | 1847 | methodType = fakeCString(vObjectUStringZValue(curVO)); |
1848 | if (mEnableDialogs) | 1848 | if (mEnableDialogs) |
1849 | KMessageBox::information(mTopWidget, | 1849 | KMessageBox::information(mTopWidget, |
1850 | i18n("This calendar is an iTIP transaction of type \"%1\".") | 1850 | i18n("This calendar is an iTIP transaction of type \"%1\".") |
1851 | .arg(methodType), | 1851 | .arg(methodType), |
1852 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); | 1852 | i18n("%1: iTIP Transaction").arg(CalFormat::application())); |
1853 | delete methodType; | 1853 | delete methodType; |
1854 | } | 1854 | } |
1855 | #endif | 1855 | #endif |
1856 | 1856 | ||
1857 | icalproperty *p; | 1857 | icalproperty *p; |
1858 | 1858 | ||
1859 | p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); | 1859 | p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); |
1860 | if (!p) { | 1860 | if (!p) { |
1861 | // TODO: does no PRODID really matter? | 1861 | // TODO: does no PRODID really matter? |
1862 | // mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1862 | // mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1863 | // return false; | 1863 | // return false; |
1864 | mLoadedProductId = ""; | 1864 | mLoadedProductId = ""; |
1865 | mCalendarVersion = 0; | 1865 | mCalendarVersion = 0; |
1866 | } else { | 1866 | } else { |
1867 | mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); | 1867 | mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); |
1868 | mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); | 1868 | mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); |
1869 | 1869 | ||
1870 | delete mCompat; | 1870 | delete mCompat; |
1871 | mCompat = CompatFactory::createCompat( mLoadedProductId ); | 1871 | mCompat = CompatFactory::createCompat( mLoadedProductId ); |
1872 | } | 1872 | } |
1873 | 1873 | ||
1874 | // TODO: check for unknown PRODID | 1874 | // TODO: check for unknown PRODID |
1875 | #if 0 | 1875 | #if 0 |
1876 | if (!mCalendarVersion | 1876 | if (!mCalendarVersion |
1877 | && CalFormat::productId() != mLoadedProductId) { | 1877 | && CalFormat::productId() != mLoadedProductId) { |
1878 | // warn the user that we might have trouble reading non-known calendar. | 1878 | // warn the user that we might have trouble reading non-known calendar. |
1879 | if (mEnableDialogs) | 1879 | if (mEnableDialogs) |
1880 | KMessageBox::information(mTopWidget, | 1880 | KMessageBox::information(mTopWidget, |
1881 | i18n("This vCalendar file was not created by KOrganizer " | 1881 | i18n("This vCalendar file was not created by KOrganizer " |
1882 | "or any other product we support. Loading anyway..."), | 1882 | "or any other product we support. Loading anyway..."), |
1883 | i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); | 1883 | i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); |
1884 | } | 1884 | } |
1885 | #endif | 1885 | #endif |
1886 | 1886 | ||
1887 | p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); | 1887 | p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); |
1888 | if (!p) { | 1888 | if (!p) { |
1889 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1889 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1890 | return false; | 1890 | return false; |
1891 | } else { | 1891 | } else { |
1892 | const char *version = icalproperty_get_version(p); | 1892 | const char *version = icalproperty_get_version(p); |
1893 | 1893 | ||
1894 | if (strcmp(version,"1.0") == 0) { | 1894 | if (strcmp(version,"1.0") == 0) { |
1895 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, | 1895 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, |
1896 | i18n("Expected iCalendar format"))); | 1896 | i18n("Expected iCalendar format"))); |
1897 | return false; | 1897 | return false; |
1898 | } else if (strcmp(version,"2.0") != 0) { | 1898 | } else if (strcmp(version,"2.0") != 0) { |
1899 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); | 1899 | mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); |
1900 | return false; | 1900 | return false; |
1901 | } | 1901 | } |
1902 | } | 1902 | } |
1903 | 1903 | ||
1904 | 1904 | ||
1905 | // TODO: check for calendar format version | 1905 | // TODO: check for calendar format version |
1906 | #if 0 | 1906 | #if 0 |
1907 | // warn the user we might have trouble reading this unknown version. | 1907 | // warn the user we might have trouble reading this unknown version. |
1908 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { | 1908 | if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { |
1909 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1909 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1910 | if (strcmp(_VCAL_VERSION, s) != 0) | 1910 | if (strcmp(_VCAL_VERSION, s) != 0) |
1911 | if (mEnableDialogs) | 1911 | if (mEnableDialogs) |
1912 | KMessageBox::sorry(mTopWidget, | 1912 | KMessageBox::sorry(mTopWidget, |
1913 | i18n("This vCalendar file has version %1.\n" | 1913 | i18n("This vCalendar file has version %1.\n" |
1914 | "We only support %2.") | 1914 | "We only support %2.") |
1915 | .arg(s).arg(_VCAL_VERSION), | 1915 | .arg(s).arg(_VCAL_VERSION), |
1916 | i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); | 1916 | i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); |
1917 | deleteStr(s); | 1917 | deleteStr(s); |
1918 | } | 1918 | } |
1919 | #endif | 1919 | #endif |
1920 | 1920 | ||
1921 | // custom properties | 1921 | // custom properties |
1922 | readCustomProperties(calendar, cal); | 1922 | readCustomProperties(calendar, cal); |
1923 | 1923 | ||
1924 | // TODO: set time zone | 1924 | // TODO: set time zone |
1925 | #if 0 | 1925 | #if 0 |
1926 | // set the time zone | 1926 | // set the time zone |
1927 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { | 1927 | if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { |
1928 | char *s = fakeCString(vObjectUStringZValue(curVO)); | 1928 | char *s = fakeCString(vObjectUStringZValue(curVO)); |
1929 | cal->setTimeZone(s); | 1929 | cal->setTimeZone(s); |
1930 | deleteStr(s); | 1930 | deleteStr(s); |
1931 | } | 1931 | } |
1932 | #endif | 1932 | #endif |
1933 | 1933 | ||
1934 | // Store all events with a relatedTo property in a list for post-processing | 1934 | // Store all events with a relatedTo property in a list for post-processing |
1935 | mEventsRelate.clear(); | 1935 | mEventsRelate.clear(); |
1936 | mTodosRelate.clear(); | 1936 | mTodosRelate.clear(); |
1937 | // TODO: make sure that only actually added ecvens go to this lists. | 1937 | // TODO: make sure that only actually added ecvens go to this lists. |
1938 | 1938 | ||
1939 | icalcomponent *c; | 1939 | icalcomponent *c; |
1940 | 1940 | ||
1941 | // Iterate through all todos | 1941 | // Iterate through all todos |
1942 | c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); | 1942 | c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); |
1943 | while (c) { | 1943 | while (c) { |
1944 | // kdDebug(5800) << "----Todo found" << endl; | 1944 | // kdDebug(5800) << "----Todo found" << endl; |
1945 | Todo *todo = readTodo(c); | 1945 | Todo *todo = readTodo(c); |
1946 | if (!cal->todo(todo->uid())) cal->addTodo(todo); | 1946 | if (!cal->todo(todo->uid())) cal->addTodo(todo); |
1947 | c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); | 1947 | c = icalcomponent_get_next_component(calendar,ICAL_VTODO_COMPONENT); |
1948 | } | 1948 | } |
1949 | 1949 | ||
1950 | // Iterate through all events | 1950 | // Iterate through all events |
1951 | c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); | 1951 | c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT); |
1952 | while (c) { | 1952 | while (c) { |
1953 | // kdDebug(5800) << "----Event found" << endl; | 1953 | // kdDebug(5800) << "----Event found" << endl; |
1954 | Event *event = readEvent(c); | 1954 | Event *event = readEvent(c); |
1955 | if (!cal->event(event->uid())) cal->addEvent(event); | 1955 | if (!cal->event(event->uid())) cal->addEvent(event); |
1956 | c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); | 1956 | c = icalcomponent_get_next_component(calendar,ICAL_VEVENT_COMPONENT); |
1957 | } | 1957 | } |
1958 | 1958 | ||
1959 | // Iterate through all journals | 1959 | // Iterate through all journals |
1960 | c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); | 1960 | c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT); |
1961 | while (c) { | 1961 | while (c) { |
1962 | // kdDebug(5800) << "----Journal found" << endl; | 1962 | // kdDebug(5800) << "----Journal found" << endl; |
1963 | Journal *journal = readJournal(c); | 1963 | Journal *journal = readJournal(c); |
1964 | if (!cal->journal(journal->uid())) cal->addJournal(journal); | 1964 | if (!cal->journal(journal->uid())) cal->addJournal(journal); |
1965 | c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); | 1965 | c = icalcomponent_get_next_component(calendar,ICAL_VJOURNAL_COMPONENT); |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | #if 0 | 1968 | #if 0 |
1969 | initPropIterator(&i, vcal); | 1969 | initPropIterator(&i, vcal); |
1970 | 1970 | ||
1971 | // go through all the vobjects in the vcal | 1971 | // go through all the vobjects in the vcal |
1972 | while (moreIteration(&i)) { | 1972 | while (moreIteration(&i)) { |
1973 | curVO = nextVObject(&i); | 1973 | curVO = nextVObject(&i); |
1974 | 1974 | ||
1975 | /************************************************************************/ | 1975 | /************************************************************************/ |
1976 | 1976 | ||
1977 | // now, check to see that the object is an event or todo. | 1977 | // now, check to see that the object is an event or todo. |
1978 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { | 1978 | if (strcmp(vObjectName(curVO), VCEventProp) == 0) { |
1979 | 1979 | ||
1980 | if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { | 1980 | if ((curVOProp = isAPropertyOf(curVO, KPilotStatusProp)) != 0) { |
1981 | char *s; | 1981 | char *s; |
1982 | s = fakeCString(vObjectUStringZValue(curVOProp)); | 1982 | s = fakeCString(vObjectUStringZValue(curVOProp)); |
1983 | // check to see if event was deleted by the kpilot conduit | 1983 | // check to see if event was deleted by the kpilot conduit |
1984 | if (atoi(s) == Event::SYNCDEL) { | 1984 | if (atoi(s) == Event::SYNCDEL) { |
1985 | deleteStr(s); | 1985 | deleteStr(s); |
1986 | goto SKIP; | 1986 | goto SKIP; |
1987 | } | 1987 | } |
1988 | deleteStr(s); | 1988 | deleteStr(s); |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | // this code checks to see if we are trying to read in an event | 1991 | // this code checks to see if we are trying to read in an event |
1992 | // that we already find to be in the calendar. If we find this | 1992 | // that we already find to be in the calendar. If we find this |
1993 | // to be the case, we skip the event. | 1993 | // to be the case, we skip the event. |
1994 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { | 1994 | if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { |
1995 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); | 1995 | char *s = fakeCString(vObjectUStringZValue(curVOProp)); |
1996 | QString tmpStr(s); | 1996 | QString tmpStr(s); |
1997 | deleteStr(s); | 1997 | deleteStr(s); |
1998 | 1998 | ||
1999 | if (cal->event(tmpStr)) { | 1999 | if (cal->event(tmpStr)) { |
2000 | goto SKIP; | 2000 | goto SKIP; |
2001 | } | 2001 | } |
2002 | if (cal->todo(tmpStr)) { | 2002 | if (cal->todo(tmpStr)) { |
2003 | goto SKIP; | 2003 | goto SKIP; |
2004 | } | 2004 | } |
2005 | } | 2005 | } |
2006 | 2006 | ||
2007 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && | 2007 | if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && |
2008 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { | 2008 | (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { |
2009 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; | 2009 | kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; |
2010 | goto SKIP; | 2010 | goto SKIP; |
2011 | } | 2011 | } |
2012 | 2012 | ||
2013 | anEvent = VEventToEvent(curVO); | 2013 | anEvent = VEventToEvent(curVO); |
2014 | // we now use addEvent instead of insertEvent so that the | 2014 | // we now use addEvent instead of insertEvent so that the |
2015 | // signal/slot get connected. | 2015 | // signal/slot get connected. |
2016 | if (anEvent) | 2016 | if (anEvent) |
2017 | cal->addEvent(anEvent); | 2017 | cal->addEvent(anEvent); |
2018 | else { | 2018 | else { |
2019 | // some sort of error must have occurred while in translation. | 2019 | // some sort of error must have occurred while in translation. |
2020 | goto SKIP; | 2020 | goto SKIP; |
2021 | } | 2021 | } |
2022 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { | 2022 | } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { |
2023 | anEvent = VTodoToEvent(curVO); | 2023 | anEvent = VTodoToEvent(curVO); |
2024 | cal->addTodo(anEvent); | 2024 | cal->addTodo(anEvent); |
2025 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || | 2025 | } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || |
2026 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || | 2026 | (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || |
2027 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { | 2027 | (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { |
2028 | // do nothing, we know these properties and we want to skip them. | 2028 | // do nothing, we know these properties and we want to skip them. |
2029 | // we have either already processed them or are ignoring them. | 2029 | // we have either already processed them or are ignoring them. |
2030 | ; | 2030 | ; |
2031 | } else { | 2031 | } else { |
2032 | ; | 2032 | ; |
2033 | } | 2033 | } |
2034 | SKIP: | 2034 | SKIP: |
2035 | ; | 2035 | ; |
2036 | } // while | 2036 | } // while |
2037 | #endif | 2037 | #endif |
2038 | 2038 | ||
2039 | // Post-Process list of events with relations, put Event objects in relation | 2039 | // Post-Process list of events with relations, put Event objects in relation |
2040 | Event *ev; | 2040 | Event *ev; |
2041 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { | 2041 | for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { |
2042 | Incidence * inc = cal->event(ev->relatedToUid()); | 2042 | Incidence * inc = cal->event(ev->relatedToUid()); |
2043 | if ( inc ) | 2043 | if ( inc ) |
2044 | ev->setRelatedTo( inc ); | 2044 | ev->setRelatedTo( inc ); |
2045 | } | 2045 | } |
2046 | Todo *todo; | 2046 | Todo *todo; |
2047 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { | 2047 | for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { |
2048 | Incidence * inc = cal->todo(todo->relatedToUid()); | 2048 | Incidence * inc = cal->todo(todo->relatedToUid()); |
2049 | if ( inc ) | 2049 | if ( inc ) |
2050 | todo->setRelatedTo( inc ); | 2050 | todo->setRelatedTo( inc ); |
2051 | } | 2051 | } |
2052 | 2052 | ||
2053 | return true; | 2053 | return true; |
2054 | } | 2054 | } |
2055 | 2055 | ||
2056 | QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) | 2056 | QString ICalFormatImpl::extractErrorProperty(icalcomponent *c) |
2057 | { | 2057 | { |
2058 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " | 2058 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " |
2059 | // << icalcomponent_as_ical_string(c) << endl; | 2059 | // << icalcomponent_as_ical_string(c) << endl; |
2060 | 2060 | ||
2061 | QString errorMessage; | 2061 | QString errorMessage; |
2062 | 2062 | ||
2063 | icalproperty *error; | 2063 | icalproperty *error; |
2064 | error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); | 2064 | error = icalcomponent_get_first_property(c,ICAL_XLICERROR_PROPERTY); |
2065 | while(error) { | 2065 | while(error) { |
2066 | errorMessage += icalproperty_get_xlicerror(error); | 2066 | errorMessage += icalproperty_get_xlicerror(error); |
2067 | errorMessage += "\n"; | 2067 | errorMessage += "\n"; |
2068 | error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); | 2068 | error = icalcomponent_get_next_property(c,ICAL_XLICERROR_PROPERTY); |
2069 | } | 2069 | } |
2070 | 2070 | ||
2071 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; | 2071 | // kdDebug(5800) << "ICalFormatImpl:extractErrorProperty: " << errorMessage << endl; |
2072 | 2072 | ||
2073 | return errorMessage; | 2073 | return errorMessage; |
2074 | } | 2074 | } |
2075 | 2075 | ||
2076 | void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) | 2076 | void ICalFormatImpl::dumpIcalRecurrence(icalrecurrencetype r) |
2077 | { | 2077 | { |
2078 | int i; | 2078 | int i; |
2079 | 2079 | ||
2080 | 2080 | ||
2081 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2081 | if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2082 | int index = 0; | 2082 | int index = 0; |
2083 | QString out = " By Day: "; | 2083 | QString out = " By Day: "; |
2084 | while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2084 | while((i = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2085 | out.append(QString::number(i) + " "); | 2085 | out.append(QString::number(i) + " "); |
2086 | } | 2086 | } |
2087 | } | 2087 | } |
2088 | if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2088 | if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2089 | int index = 0; | 2089 | int index = 0; |
2090 | QString out = " By Month Day: "; | 2090 | QString out = " By Month Day: "; |
2091 | while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2091 | while((i = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2092 | out.append(QString::number(i) + " "); | 2092 | out.append(QString::number(i) + " "); |
2093 | } | 2093 | } |
2094 | } | 2094 | } |
2095 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2095 | if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2096 | int index = 0; | 2096 | int index = 0; |
2097 | QString out = " By Year Day: "; | 2097 | QString out = " By Year Day: "; |
2098 | while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2098 | while((i = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2099 | out.append(QString::number(i) + " "); | 2099 | out.append(QString::number(i) + " "); |
2100 | } | 2100 | } |
2101 | } | 2101 | } |
2102 | if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2102 | if (r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2103 | int index = 0; | 2103 | int index = 0; |
2104 | QString out = " By Month: "; | 2104 | QString out = " By Month: "; |
2105 | while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2105 | while((i = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2106 | out.append(QString::number(i) + " "); | 2106 | out.append(QString::number(i) + " "); |
2107 | } | 2107 | } |
2108 | } | 2108 | } |
2109 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { | 2109 | if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { |
2110 | int index = 0; | 2110 | int index = 0; |
2111 | QString out = " By Set Pos: "; | 2111 | QString out = " By Set Pos: "; |
2112 | while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { | 2112 | while((i = r.by_set_pos[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { |
2113 | out.append(QString::number(i) + " "); | 2113 | out.append(QString::number(i) + " "); |
2114 | } | 2114 | } |
2115 | } | 2115 | } |
2116 | } | 2116 | } |
2117 | 2117 | ||
2118 | icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, | 2118 | icalcomponent *ICalFormatImpl::createScheduleComponent(IncidenceBase *incidence, |
2119 | Scheduler::Method method) | 2119 | Scheduler::Method method) |
2120 | { | 2120 | { |
2121 | icalcomponent *message = createCalendarComponent(); | 2121 | icalcomponent *message = createCalendarComponent(); |
2122 | 2122 | ||
2123 | icalproperty_method icalmethod = ICAL_METHOD_NONE; | 2123 | icalproperty_method icalmethod = ICAL_METHOD_NONE; |
2124 | 2124 | ||
2125 | switch (method) { | 2125 | switch (method) { |
2126 | case Scheduler::Publish: | 2126 | case Scheduler::Publish: |
2127 | icalmethod = ICAL_METHOD_PUBLISH; | 2127 | icalmethod = ICAL_METHOD_PUBLISH; |
2128 | break; | 2128 | break; |
2129 | case Scheduler::Request: | 2129 | case Scheduler::Request: |
2130 | icalmethod = ICAL_METHOD_REQUEST; | 2130 | icalmethod = ICAL_METHOD_REQUEST; |
2131 | break; | 2131 | break; |
2132 | case Scheduler::Refresh: | 2132 | case Scheduler::Refresh: |
2133 | icalmethod = ICAL_METHOD_REFRESH; | 2133 | icalmethod = ICAL_METHOD_REFRESH; |
2134 | break; | 2134 | break; |
2135 | case Scheduler::Cancel: | 2135 | case Scheduler::Cancel: |
2136 | icalmethod = ICAL_METHOD_CANCEL; | 2136 | icalmethod = ICAL_METHOD_CANCEL; |
2137 | break; | 2137 | break; |
2138 | case Scheduler::Add: | 2138 | case Scheduler::Add: |
2139 | icalmethod = ICAL_METHOD_ADD; | 2139 | icalmethod = ICAL_METHOD_ADD; |
2140 | break; | 2140 | break; |
2141 | case Scheduler::Reply: | 2141 | case Scheduler::Reply: |
2142 | icalmethod = ICAL_METHOD_REPLY; | 2142 | icalmethod = ICAL_METHOD_REPLY; |
2143 | break; | 2143 | break; |
2144 | case Scheduler::Counter: | 2144 | case Scheduler::Counter: |
2145 | icalmethod = ICAL_METHOD_COUNTER; | 2145 | icalmethod = ICAL_METHOD_COUNTER; |
2146 | break; | 2146 | break; |
2147 | case Scheduler::Declinecounter: | 2147 | case Scheduler::Declinecounter: |
2148 | icalmethod = ICAL_METHOD_DECLINECOUNTER; | 2148 | icalmethod = ICAL_METHOD_DECLINECOUNTER; |
2149 | break; | 2149 | break; |
2150 | default: | 2150 | default: |
2151 | 2151 | ||
2152 | return message; | 2152 | return message; |
2153 | } | 2153 | } |
2154 | 2154 | ||
2155 | icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); | 2155 | icalcomponent_add_property(message,icalproperty_new_method(icalmethod)); |
2156 | 2156 | ||
2157 | // TODO: check, if dynamic cast is required | 2157 | // TODO: check, if dynamic cast is required |
2158 | if(incidence->type() == "Todo") { | 2158 | if(incidence->typeID() == todoID ) { |
2159 | Todo *todo = static_cast<Todo *>(incidence); | 2159 | Todo *todo = static_cast<Todo *>(incidence); |
2160 | icalcomponent_add_component(message,writeTodo(todo)); | 2160 | icalcomponent_add_component(message,writeTodo(todo)); |
2161 | } | 2161 | } |
2162 | if(incidence->type() == "Event") { | 2162 | if(incidence->typeID() == eventID ) { |
2163 | Event *event = static_cast<Event *>(incidence); | 2163 | Event *event = static_cast<Event *>(incidence); |
2164 | icalcomponent_add_component(message,writeEvent(event)); | 2164 | icalcomponent_add_component(message,writeEvent(event)); |
2165 | } | 2165 | } |
2166 | if(incidence->type() == "FreeBusy") { | 2166 | if(incidence->typeID() == freebusyID) { |
2167 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); | 2167 | FreeBusy *freebusy = static_cast<FreeBusy *>(incidence); |
2168 | icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); | 2168 | icalcomponent_add_component(message,writeFreeBusy(freebusy, method)); |
2169 | } | 2169 | } |
2170 | 2170 | ||
2171 | return message; | 2171 | return message; |
2172 | } | 2172 | } |
diff --git a/libkcal/incidence.cpp b/libkcal/incidence.cpp index 762103f..f446197 100644 --- a/libkcal/incidence.cpp +++ b/libkcal/incidence.cpp | |||
@@ -1,744 +1,744 @@ | |||
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 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <klocale.h> | 22 | #include <klocale.h> |
23 | #include <kdebug.h> | 23 | #include <kdebug.h> |
24 | 24 | ||
25 | #include "calformat.h" | 25 | #include "calformat.h" |
26 | 26 | ||
27 | #include "incidence.h" | 27 | #include "incidence.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | 29 | ||
30 | using namespace KCal; | 30 | using namespace KCal; |
31 | 31 | ||
32 | Incidence::Incidence() : | 32 | Incidence::Incidence() : |
33 | IncidenceBase(), | 33 | IncidenceBase(), |
34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) | 34 | mRelatedTo(0), mSecrecy(SecrecyPublic), mPriority(3) |
35 | { | 35 | { |
36 | mRecurrence = new Recurrence(this); | 36 | mRecurrence = new Recurrence(this); |
37 | mCancelled = false; | 37 | mCancelled = false; |
38 | recreate(); | 38 | recreate(); |
39 | mHasStartDate = true; | 39 | mHasStartDate = true; |
40 | mAlarms.setAutoDelete(true); | 40 | mAlarms.setAutoDelete(true); |
41 | mAttachments.setAutoDelete(true); | 41 | mAttachments.setAutoDelete(true); |
42 | mHasRecurrenceID = false; | 42 | mHasRecurrenceID = false; |
43 | mHoliday = false; | 43 | mHoliday = false; |
44 | mBirthday = false; | 44 | mBirthday = false; |
45 | mAnniversary = false; | 45 | mAnniversary = false; |
46 | 46 | ||
47 | } | 47 | } |
48 | 48 | ||
49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) | 49 | Incidence::Incidence( const Incidence &i ) : IncidenceBase( i ) |
50 | { | 50 | { |
51 | // TODO: reenable attributes currently commented out. | 51 | // TODO: reenable attributes currently commented out. |
52 | mRevision = i.mRevision; | 52 | mRevision = i.mRevision; |
53 | mCreated = i.mCreated; | 53 | mCreated = i.mCreated; |
54 | mDescription = i.mDescription; | 54 | mDescription = i.mDescription; |
55 | mSummary = i.mSummary; | 55 | mSummary = i.mSummary; |
56 | mCategories = i.mCategories; | 56 | mCategories = i.mCategories; |
57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; | 57 | // Incidence *mRelatedTo; Incidence *mRelatedTo; |
58 | mRelatedTo = 0; | 58 | mRelatedTo = 0; |
59 | mRelatedToUid = i.mRelatedToUid; | 59 | mRelatedToUid = i.mRelatedToUid; |
60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; | 60 | // QPtrList<Incidence> mRelations; QPtrList<Incidence> mRelations; |
61 | mExDates = i.mExDates; | 61 | mExDates = i.mExDates; |
62 | mAttachments = i.mAttachments; | 62 | mAttachments = i.mAttachments; |
63 | mResources = i.mResources; | 63 | mResources = i.mResources; |
64 | mSecrecy = i.mSecrecy; | 64 | mSecrecy = i.mSecrecy; |
65 | mPriority = i.mPriority; | 65 | mPriority = i.mPriority; |
66 | mLocation = i.mLocation; | 66 | mLocation = i.mLocation; |
67 | mCancelled = i.mCancelled; | 67 | mCancelled = i.mCancelled; |
68 | mHasStartDate = i.mHasStartDate; | 68 | mHasStartDate = i.mHasStartDate; |
69 | QPtrListIterator<Alarm> it( i.mAlarms ); | 69 | QPtrListIterator<Alarm> it( i.mAlarms ); |
70 | const Alarm *a; | 70 | const Alarm *a; |
71 | while( (a = it.current()) ) { | 71 | while( (a = it.current()) ) { |
72 | Alarm *b = new Alarm( *a ); | 72 | Alarm *b = new Alarm( *a ); |
73 | b->setParent( this ); | 73 | b->setParent( this ); |
74 | mAlarms.append( b ); | 74 | mAlarms.append( b ); |
75 | 75 | ||
76 | ++it; | 76 | ++it; |
77 | } | 77 | } |
78 | mAlarms.setAutoDelete(true); | 78 | mAlarms.setAutoDelete(true); |
79 | mHasRecurrenceID = i.mHasRecurrenceID; | 79 | mHasRecurrenceID = i.mHasRecurrenceID; |
80 | mRecurrenceID = i.mRecurrenceID; | 80 | mRecurrenceID = i.mRecurrenceID; |
81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); | 81 | mRecurrence = new Recurrence( *(i.mRecurrence), this ); |
82 | mHoliday = i.mHoliday ; | 82 | mHoliday = i.mHoliday ; |
83 | mBirthday = i.mBirthday; | 83 | mBirthday = i.mBirthday; |
84 | mAnniversary = i.mAnniversary; | 84 | mAnniversary = i.mAnniversary; |
85 | } | 85 | } |
86 | 86 | ||
87 | Incidence::~Incidence() | 87 | Incidence::~Incidence() |
88 | { | 88 | { |
89 | 89 | ||
90 | Incidence *ev; | 90 | Incidence *ev; |
91 | QPtrList<Incidence> Relations = relations(); | 91 | QPtrList<Incidence> Relations = relations(); |
92 | for (ev=Relations.first();ev;ev=Relations.next()) { | 92 | for (ev=Relations.first();ev;ev=Relations.next()) { |
93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); | 93 | if (ev->relatedTo() == this) ev->setRelatedTo(0); |
94 | } | 94 | } |
95 | if (relatedTo()) relatedTo()->removeRelation(this); | 95 | if (relatedTo()) relatedTo()->removeRelation(this); |
96 | delete mRecurrence; | 96 | delete mRecurrence; |
97 | 97 | ||
98 | } | 98 | } |
99 | 99 | ||
100 | bool Incidence::isHoliday() const | 100 | bool Incidence::isHoliday() const |
101 | { | 101 | { |
102 | return mHoliday; | 102 | return mHoliday; |
103 | } | 103 | } |
104 | bool Incidence::isBirthday() const | 104 | bool Incidence::isBirthday() const |
105 | { | 105 | { |
106 | 106 | ||
107 | return mBirthday ; | 107 | return mBirthday ; |
108 | } | 108 | } |
109 | bool Incidence::isAnniversary() const | 109 | bool Incidence::isAnniversary() const |
110 | { | 110 | { |
111 | return mAnniversary ; | 111 | return mAnniversary ; |
112 | 112 | ||
113 | } | 113 | } |
114 | 114 | ||
115 | bool Incidence::hasRecurrenceID() const | 115 | bool Incidence::hasRecurrenceID() const |
116 | { | 116 | { |
117 | return mHasRecurrenceID; | 117 | return mHasRecurrenceID; |
118 | } | 118 | } |
119 | 119 | ||
120 | void Incidence::setHasRecurrenceID( bool b ) | 120 | void Incidence::setHasRecurrenceID( bool b ) |
121 | { | 121 | { |
122 | mHasRecurrenceID = b; | 122 | mHasRecurrenceID = b; |
123 | } | 123 | } |
124 | 124 | ||
125 | void Incidence::setRecurrenceID(QDateTime d) | 125 | void Incidence::setRecurrenceID(QDateTime d) |
126 | { | 126 | { |
127 | mRecurrenceID = d; | 127 | mRecurrenceID = d; |
128 | mHasRecurrenceID = true; | 128 | mHasRecurrenceID = true; |
129 | updated(); | 129 | updated(); |
130 | } | 130 | } |
131 | QDateTime Incidence::recurrenceID () const | 131 | QDateTime Incidence::recurrenceID () const |
132 | { | 132 | { |
133 | return mRecurrenceID; | 133 | return mRecurrenceID; |
134 | } | 134 | } |
135 | 135 | ||
136 | bool Incidence::cancelled() const | 136 | bool Incidence::cancelled() const |
137 | { | 137 | { |
138 | return mCancelled; | 138 | return mCancelled; |
139 | } | 139 | } |
140 | void Incidence::setCancelled( bool b ) | 140 | void Incidence::setCancelled( bool b ) |
141 | { | 141 | { |
142 | mCancelled = b; | 142 | mCancelled = b; |
143 | updated(); | 143 | updated(); |
144 | } | 144 | } |
145 | bool Incidence::hasStartDate() const | 145 | bool Incidence::hasStartDate() const |
146 | { | 146 | { |
147 | return mHasStartDate; | 147 | return mHasStartDate; |
148 | } | 148 | } |
149 | 149 | ||
150 | void Incidence::setHasStartDate(bool f) | 150 | void Incidence::setHasStartDate(bool f) |
151 | { | 151 | { |
152 | if (mReadOnly) return; | 152 | if (mReadOnly) return; |
153 | mHasStartDate = f; | 153 | mHasStartDate = f; |
154 | updated(); | 154 | updated(); |
155 | } | 155 | } |
156 | 156 | ||
157 | // A string comparison that considers that null and empty are the same | 157 | // A string comparison that considers that null and empty are the same |
158 | static bool stringCompare( const QString& s1, const QString& s2 ) | 158 | static bool stringCompare( const QString& s1, const QString& s2 ) |
159 | { | 159 | { |
160 | if ( s1.isEmpty() && s2.isEmpty() ) | 160 | if ( s1.isEmpty() && s2.isEmpty() ) |
161 | return true; | 161 | return true; |
162 | return s1 == s2; | 162 | return s1 == s2; |
163 | } | 163 | } |
164 | 164 | ||
165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) | 165 | bool KCal::operator==( const Incidence& i1, const Incidence& i2 ) |
166 | { | 166 | { |
167 | 167 | ||
168 | if( i1.alarms().count() != i2.alarms().count() ) { | 168 | if( i1.alarms().count() != i2.alarms().count() ) { |
169 | return false; // no need to check further | 169 | return false; // no need to check further |
170 | } | 170 | } |
171 | if ( i1.alarms().count() > 0 ) { | 171 | if ( i1.alarms().count() > 0 ) { |
172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) | 172 | if ( !( *(i1.alarms().first()) == *(i2.alarms().first())) ) |
173 | { | 173 | { |
174 | qDebug("alarm not equal "); | 174 | qDebug("alarm not equal "); |
175 | return false; | 175 | return false; |
176 | } | 176 | } |
177 | } | 177 | } |
178 | #if 0 | 178 | #if 0 |
179 | QPtrListIterator<Alarm> a1( i1.alarms() ); | 179 | QPtrListIterator<Alarm> a1( i1.alarms() ); |
180 | QPtrListIterator<Alarm> a2( i2.alarms() ); | 180 | QPtrListIterator<Alarm> a2( i2.alarms() ); |
181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { | 181 | for( ; a1.current() && a2.current(); ++a1, ++a2 ) { |
182 | if( *a1.current() == *a2.current() ) { | 182 | if( *a1.current() == *a2.current() ) { |
183 | continue; | 183 | continue; |
184 | } | 184 | } |
185 | else { | 185 | else { |
186 | return false; | 186 | return false; |
187 | } | 187 | } |
188 | } | 188 | } |
189 | #endif | 189 | #endif |
190 | 190 | ||
191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { | 191 | if ( i1.hasRecurrenceID() == i2.hasRecurrenceID() ) { |
192 | if ( i1.hasRecurrenceID() ) { | 192 | if ( i1.hasRecurrenceID() ) { |
193 | if ( i1.recurrenceID() != i2.recurrenceID() ) | 193 | if ( i1.recurrenceID() != i2.recurrenceID() ) |
194 | return false; | 194 | return false; |
195 | } | 195 | } |
196 | 196 | ||
197 | } else { | 197 | } else { |
198 | return false; | 198 | return false; |
199 | } | 199 | } |
200 | 200 | ||
201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) | 201 | if ( ! operator==( (const IncidenceBase&)i1, (const IncidenceBase&)i2 ) ) |
202 | return false; | 202 | return false; |
203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { | 203 | if ( i1.hasStartDate() == i2.hasStartDate() ) { |
204 | if ( i1.hasStartDate() ) { | 204 | if ( i1.hasStartDate() ) { |
205 | if ( i1.dtStart() != i2.dtStart() ) | 205 | if ( i1.dtStart() != i2.dtStart() ) |
206 | return false; | 206 | return false; |
207 | } | 207 | } |
208 | } else { | 208 | } else { |
209 | return false; | 209 | return false; |
210 | } | 210 | } |
211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { | 211 | if (!( *i1.recurrence() == *i2.recurrence()) ) { |
212 | qDebug("recurrence is NOT equal "); | 212 | qDebug("recurrence is NOT equal "); |
213 | return false; | 213 | return false; |
214 | } | 214 | } |
215 | return | 215 | return |
216 | // i1.created() == i2.created() && | 216 | // i1.created() == i2.created() && |
217 | stringCompare( i1.description(), i2.description() ) && | 217 | stringCompare( i1.description(), i2.description() ) && |
218 | stringCompare( i1.summary(), i2.summary() ) && | 218 | stringCompare( i1.summary(), i2.summary() ) && |
219 | i1.categories() == i2.categories() && | 219 | i1.categories() == i2.categories() && |
220 | // no need to compare mRelatedTo | 220 | // no need to compare mRelatedTo |
221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && | 221 | stringCompare( i1.relatedToUid(), i2.relatedToUid() ) && |
222 | // i1.relations() == i2.relations() && | 222 | // i1.relations() == i2.relations() && |
223 | i1.exDates() == i2.exDates() && | 223 | i1.exDates() == i2.exDates() && |
224 | i1.attachments() == i2.attachments() && | 224 | i1.attachments() == i2.attachments() && |
225 | i1.resources() == i2.resources() && | 225 | i1.resources() == i2.resources() && |
226 | i1.secrecy() == i2.secrecy() && | 226 | i1.secrecy() == i2.secrecy() && |
227 | i1.priority() == i2.priority() && | 227 | i1.priority() == i2.priority() && |
228 | i1.cancelled() == i2.cancelled() && | 228 | i1.cancelled() == i2.cancelled() && |
229 | stringCompare( i1.location(), i2.location() ); | 229 | stringCompare( i1.location(), i2.location() ); |
230 | } | 230 | } |
231 | 231 | ||
232 | Incidence* Incidence::recreateCloneException( QDate d ) | 232 | Incidence* Incidence::recreateCloneException( QDate d ) |
233 | { | 233 | { |
234 | Incidence* newInc = clone(); | 234 | Incidence* newInc = clone(); |
235 | newInc->recreate(); | 235 | newInc->recreate(); |
236 | if ( doesRecur() ) { | 236 | if ( doesRecur() ) { |
237 | addExDate( d ); | 237 | addExDate( d ); |
238 | newInc->recurrence()->unsetRecurs(); | 238 | newInc->recurrence()->unsetRecurs(); |
239 | if ( type() == "Event") { | 239 | if ( typeID() == eventID ) { |
240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); | 240 | int len = dtStart().secsTo( ((Event*)this)->dtEnd()); |
241 | QTime tim = dtStart().time(); | 241 | QTime tim = dtStart().time(); |
242 | newInc->setDtStart( QDateTime(d, tim) ); | 242 | newInc->setDtStart( QDateTime(d, tim) ); |
243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); | 243 | ((Event*)newInc)->setDtEnd( newInc->dtStart().addSecs( len ) ); |
244 | } else { | 244 | } else { |
245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); | 245 | int len = dtStart().secsTo( ((Todo*)this)->dtDue()); |
246 | QTime tim = ((Todo*)this)->dtDue().time(); | 246 | QTime tim = ((Todo*)this)->dtDue().time(); |
247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); | 247 | ((Todo*)newInc)->setDtDue( QDateTime(d, tim) ); |
248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); | 248 | ((Todo*)newInc)->setDtStart( ((Todo*)newInc)->dtDue().addSecs( -len ) ); |
249 | ((Todo*)this)->setRecurDates(); | 249 | ((Todo*)this)->setRecurDates(); |
250 | } | 250 | } |
251 | newInc->setExDates( DateList () ); | 251 | newInc->setExDates( DateList () ); |
252 | } | 252 | } |
253 | return newInc; | 253 | return newInc; |
254 | } | 254 | } |
255 | 255 | ||
256 | void Incidence::recreate() | 256 | void Incidence::recreate() |
257 | { | 257 | { |
258 | setCreated(QDateTime::currentDateTime()); | 258 | setCreated(QDateTime::currentDateTime()); |
259 | 259 | ||
260 | setUid(CalFormat::createUniqueId()); | 260 | setUid(CalFormat::createUniqueId()); |
261 | 261 | ||
262 | setRevision(0); | 262 | setRevision(0); |
263 | setIDStr( ":" ); | 263 | setIDStr( ":" ); |
264 | setLastModified(QDateTime::currentDateTime()); | 264 | setLastModified(QDateTime::currentDateTime()); |
265 | } | 265 | } |
266 | void Incidence::cloneRelations( Incidence * newInc ) | 266 | void Incidence::cloneRelations( Incidence * newInc ) |
267 | { | 267 | { |
268 | // newInc is already a clone of this incidence | 268 | // newInc is already a clone of this incidence |
269 | Incidence * inc; | 269 | Incidence * inc; |
270 | Incidence * cloneInc; | 270 | Incidence * cloneInc; |
271 | QPtrList<Incidence> Relations = relations(); | 271 | QPtrList<Incidence> Relations = relations(); |
272 | for (inc=Relations.first();inc;inc=Relations.next()) { | 272 | for (inc=Relations.first();inc;inc=Relations.next()) { |
273 | cloneInc = inc->clone(); | 273 | cloneInc = inc->clone(); |
274 | cloneInc->recreate(); | 274 | cloneInc->recreate(); |
275 | cloneInc->setRelatedTo( newInc ); | 275 | cloneInc->setRelatedTo( newInc ); |
276 | inc->cloneRelations( cloneInc ); | 276 | inc->cloneRelations( cloneInc ); |
277 | } | 277 | } |
278 | } | 278 | } |
279 | void Incidence::setReadOnly( bool readOnly ) | 279 | void Incidence::setReadOnly( bool readOnly ) |
280 | { | 280 | { |
281 | IncidenceBase::setReadOnly( readOnly ); | 281 | IncidenceBase::setReadOnly( readOnly ); |
282 | recurrence()->setRecurReadOnly( readOnly); | 282 | recurrence()->setRecurReadOnly( readOnly); |
283 | } | 283 | } |
284 | 284 | ||
285 | void Incidence::setCreated(QDateTime created) | 285 | void Incidence::setCreated(QDateTime created) |
286 | { | 286 | { |
287 | if (mReadOnly) return; | 287 | if (mReadOnly) return; |
288 | mCreated = getEvenTime(created); | 288 | mCreated = getEvenTime(created); |
289 | } | 289 | } |
290 | 290 | ||
291 | QDateTime Incidence::created() const | 291 | QDateTime Incidence::created() const |
292 | { | 292 | { |
293 | return mCreated; | 293 | return mCreated; |
294 | } | 294 | } |
295 | 295 | ||
296 | void Incidence::setRevision(int rev) | 296 | void Incidence::setRevision(int rev) |
297 | { | 297 | { |
298 | if (mReadOnly) return; | 298 | if (mReadOnly) return; |
299 | mRevision = rev; | 299 | mRevision = rev; |
300 | 300 | ||
301 | updated(); | 301 | updated(); |
302 | } | 302 | } |
303 | 303 | ||
304 | int Incidence::revision() const | 304 | int Incidence::revision() const |
305 | { | 305 | { |
306 | return mRevision; | 306 | return mRevision; |
307 | } | 307 | } |
308 | 308 | ||
309 | void Incidence::setDtStart(const QDateTime &dtStart) | 309 | void Incidence::setDtStart(const QDateTime &dtStart) |
310 | { | 310 | { |
311 | 311 | ||
312 | QDateTime dt = getEvenTime(dtStart); | 312 | QDateTime dt = getEvenTime(dtStart); |
313 | recurrence()->setRecurStart( dt); | 313 | recurrence()->setRecurStart( dt); |
314 | IncidenceBase::setDtStart( dt ); | 314 | IncidenceBase::setDtStart( dt ); |
315 | } | 315 | } |
316 | 316 | ||
317 | void Incidence::setDescription(const QString &description) | 317 | void Incidence::setDescription(const QString &description) |
318 | { | 318 | { |
319 | if (mReadOnly) return; | 319 | if (mReadOnly) return; |
320 | mDescription = description; | 320 | mDescription = description; |
321 | updated(); | 321 | updated(); |
322 | } | 322 | } |
323 | 323 | ||
324 | QString Incidence::description() const | 324 | QString Incidence::description() const |
325 | { | 325 | { |
326 | return mDescription; | 326 | return mDescription; |
327 | } | 327 | } |
328 | 328 | ||
329 | 329 | ||
330 | void Incidence::setSummary(const QString &summary) | 330 | void Incidence::setSummary(const QString &summary) |
331 | { | 331 | { |
332 | if (mReadOnly) return; | 332 | if (mReadOnly) return; |
333 | mSummary = summary; | 333 | mSummary = summary; |
334 | updated(); | 334 | updated(); |
335 | } | 335 | } |
336 | 336 | ||
337 | QString Incidence::summary() const | 337 | QString Incidence::summary() const |
338 | { | 338 | { |
339 | return mSummary; | 339 | return mSummary; |
340 | } | 340 | } |
341 | void Incidence::checkCategories() | 341 | void Incidence::checkCategories() |
342 | { | 342 | { |
343 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); | 343 | mHoliday = mCategories.contains("Holiday") || mCategories.contains(i18n("Holiday")); |
344 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); | 344 | mBirthday = mCategories.contains("Birthday") || mCategories.contains(i18n("Birthday")); |
345 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); | 345 | mAnniversary = mCategories.contains("Anniversary") || mCategories.contains(i18n("Anniversary")); |
346 | } | 346 | } |
347 | 347 | ||
348 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false | 348 | void Incidence::addCategories(const QStringList &categories, bool addToRelations ) //addToRelations = false |
349 | { | 349 | { |
350 | if (mReadOnly) return; | 350 | if (mReadOnly) return; |
351 | int i; | 351 | int i; |
352 | for( i = 0; i < categories.count(); ++i ) { | 352 | for( i = 0; i < categories.count(); ++i ) { |
353 | if ( !mCategories.contains (categories[i])) | 353 | if ( !mCategories.contains (categories[i])) |
354 | mCategories.append( categories[i] ); | 354 | mCategories.append( categories[i] ); |
355 | } | 355 | } |
356 | checkCategories(); | 356 | checkCategories(); |
357 | updated(); | 357 | updated(); |
358 | if ( addToRelations ) { | 358 | if ( addToRelations ) { |
359 | Incidence * inc; | 359 | Incidence * inc; |
360 | QPtrList<Incidence> Relations = relations(); | 360 | QPtrList<Incidence> Relations = relations(); |
361 | for (inc=Relations.first();inc;inc=Relations.next()) { | 361 | for (inc=Relations.first();inc;inc=Relations.next()) { |
362 | inc->addCategories( categories, true ); | 362 | inc->addCategories( categories, true ); |
363 | } | 363 | } |
364 | } | 364 | } |
365 | } | 365 | } |
366 | 366 | ||
367 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false | 367 | void Incidence::setCategories(const QStringList &categories, bool setForRelations ) //setForRelations = false |
368 | { | 368 | { |
369 | if (mReadOnly) return; | 369 | if (mReadOnly) return; |
370 | mCategories = categories; | 370 | mCategories = categories; |
371 | checkCategories(); | 371 | checkCategories(); |
372 | updated(); | 372 | updated(); |
373 | if ( setForRelations ) { | 373 | if ( setForRelations ) { |
374 | Incidence * inc; | 374 | Incidence * inc; |
375 | QPtrList<Incidence> Relations = relations(); | 375 | QPtrList<Incidence> Relations = relations(); |
376 | for (inc=Relations.first();inc;inc=Relations.next()) { | 376 | for (inc=Relations.first();inc;inc=Relations.next()) { |
377 | inc->setCategories( categories, true ); | 377 | inc->setCategories( categories, true ); |
378 | } | 378 | } |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | // TODO: remove setCategories(QString) function | 382 | // TODO: remove setCategories(QString) function |
383 | void Incidence::setCategories(const QString &catStr) | 383 | void Incidence::setCategories(const QString &catStr) |
384 | { | 384 | { |
385 | if (mReadOnly) return; | 385 | if (mReadOnly) return; |
386 | mCategories.clear(); | 386 | mCategories.clear(); |
387 | 387 | ||
388 | if (catStr.isEmpty()) return; | 388 | if (catStr.isEmpty()) return; |
389 | 389 | ||
390 | mCategories = QStringList::split(",",catStr); | 390 | mCategories = QStringList::split(",",catStr); |
391 | 391 | ||
392 | QStringList::Iterator it; | 392 | QStringList::Iterator it; |
393 | for(it = mCategories.begin();it != mCategories.end(); ++it) { | 393 | for(it = mCategories.begin();it != mCategories.end(); ++it) { |
394 | *it = (*it).stripWhiteSpace(); | 394 | *it = (*it).stripWhiteSpace(); |
395 | } | 395 | } |
396 | checkCategories(); | 396 | checkCategories(); |
397 | updated(); | 397 | updated(); |
398 | } | 398 | } |
399 | 399 | ||
400 | QStringList Incidence::categories() const | 400 | QStringList Incidence::categories() const |
401 | { | 401 | { |
402 | return mCategories; | 402 | return mCategories; |
403 | } | 403 | } |
404 | 404 | ||
405 | QString Incidence::categoriesStr() | 405 | QString Incidence::categoriesStr() |
406 | { | 406 | { |
407 | return mCategories.join(","); | 407 | return mCategories.join(","); |
408 | } | 408 | } |
409 | QString Incidence::categoriesStrWithSpace() | 409 | QString Incidence::categoriesStrWithSpace() |
410 | { | 410 | { |
411 | return mCategories.join(", "); | 411 | return mCategories.join(", "); |
412 | } | 412 | } |
413 | 413 | ||
414 | void Incidence::setRelatedToUid(const QString &relatedToUid) | 414 | void Incidence::setRelatedToUid(const QString &relatedToUid) |
415 | { | 415 | { |
416 | if (mReadOnly) return; | 416 | if (mReadOnly) return; |
417 | mRelatedToUid = relatedToUid; | 417 | mRelatedToUid = relatedToUid; |
418 | } | 418 | } |
419 | 419 | ||
420 | QString Incidence::relatedToUid() const | 420 | QString Incidence::relatedToUid() const |
421 | { | 421 | { |
422 | return mRelatedToUid; | 422 | return mRelatedToUid; |
423 | } | 423 | } |
424 | 424 | ||
425 | void Incidence::setRelatedTo(Incidence *relatedTo) | 425 | void Incidence::setRelatedTo(Incidence *relatedTo) |
426 | { | 426 | { |
427 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); | 427 | //qDebug("Incidence::setRelatedTo %d ", relatedTo); |
428 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); | 428 | //qDebug("setRelatedTo(Incidence *relatedTo) %s %s", summary().latin1(), relatedTo->summary().latin1() ); |
429 | if (mReadOnly || mRelatedTo == relatedTo) return; | 429 | if (mReadOnly || mRelatedTo == relatedTo) return; |
430 | if(mRelatedTo) { | 430 | if(mRelatedTo) { |
431 | // updated(); | 431 | // updated(); |
432 | mRelatedTo->removeRelation(this); | 432 | mRelatedTo->removeRelation(this); |
433 | } | 433 | } |
434 | mRelatedTo = relatedTo; | 434 | mRelatedTo = relatedTo; |
435 | if (mRelatedTo) { | 435 | if (mRelatedTo) { |
436 | mRelatedTo->addRelation(this); | 436 | mRelatedTo->addRelation(this); |
437 | mRelatedToUid = mRelatedTo->uid(); | 437 | mRelatedToUid = mRelatedTo->uid(); |
438 | } else { | 438 | } else { |
439 | mRelatedToUid = ""; | 439 | mRelatedToUid = ""; |
440 | } | 440 | } |
441 | } | 441 | } |
442 | 442 | ||
443 | Incidence *Incidence::relatedTo() const | 443 | Incidence *Incidence::relatedTo() const |
444 | { | 444 | { |
445 | return mRelatedTo; | 445 | return mRelatedTo; |
446 | } | 446 | } |
447 | 447 | ||
448 | QPtrList<Incidence> Incidence::relations() const | 448 | QPtrList<Incidence> Incidence::relations() const |
449 | { | 449 | { |
450 | return mRelations; | 450 | return mRelations; |
451 | } | 451 | } |
452 | 452 | ||
453 | void Incidence::addRelation(Incidence *event) | 453 | void Incidence::addRelation(Incidence *event) |
454 | { | 454 | { |
455 | if( mRelations.findRef( event ) == -1 ) { | 455 | if( mRelations.findRef( event ) == -1 ) { |
456 | mRelations.append(event); | 456 | mRelations.append(event); |
457 | //updated(); | 457 | //updated(); |
458 | } | 458 | } |
459 | } | 459 | } |
460 | 460 | ||
461 | void Incidence::removeRelation(Incidence *event) | 461 | void Incidence::removeRelation(Incidence *event) |
462 | { | 462 | { |
463 | 463 | ||
464 | mRelations.removeRef(event); | 464 | mRelations.removeRef(event); |
465 | 465 | ||
466 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); | 466 | // if (event->getRelatedTo() == this) event->setRelatedTo(0); |
467 | } | 467 | } |
468 | 468 | ||
469 | bool Incidence::recursOn(const QDate &qd) const | 469 | bool Incidence::recursOn(const QDate &qd) const |
470 | { | 470 | { |
471 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; | 471 | if (recurrence()->recursOnPure(qd) && !isException(qd)) return true; |
472 | else return false; | 472 | else return false; |
473 | } | 473 | } |
474 | 474 | ||
475 | void Incidence::setExDates(const DateList &exDates) | 475 | void Incidence::setExDates(const DateList &exDates) |
476 | { | 476 | { |
477 | if (mReadOnly) return; | 477 | if (mReadOnly) return; |
478 | mExDates = exDates; | 478 | mExDates = exDates; |
479 | 479 | ||
480 | recurrence()->setRecurExDatesCount(mExDates.count()); | 480 | recurrence()->setRecurExDatesCount(mExDates.count()); |
481 | 481 | ||
482 | updated(); | 482 | updated(); |
483 | } | 483 | } |
484 | 484 | ||
485 | void Incidence::addExDate(const QDate &date) | 485 | void Incidence::addExDate(const QDate &date) |
486 | { | 486 | { |
487 | if (mReadOnly) return; | 487 | if (mReadOnly) return; |
488 | mExDates.append(date); | 488 | mExDates.append(date); |
489 | 489 | ||
490 | recurrence()->setRecurExDatesCount(mExDates.count()); | 490 | recurrence()->setRecurExDatesCount(mExDates.count()); |
491 | 491 | ||
492 | updated(); | 492 | updated(); |
493 | } | 493 | } |
494 | 494 | ||
495 | DateList Incidence::exDates() const | 495 | DateList Incidence::exDates() const |
496 | { | 496 | { |
497 | return mExDates; | 497 | return mExDates; |
498 | } | 498 | } |
499 | 499 | ||
500 | bool Incidence::isException(const QDate &date) const | 500 | bool Incidence::isException(const QDate &date) const |
501 | { | 501 | { |
502 | DateList::ConstIterator it; | 502 | DateList::ConstIterator it; |
503 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { | 503 | for( it = mExDates.begin(); it != mExDates.end(); ++it ) { |
504 | if ( (*it) == date ) { | 504 | if ( (*it) == date ) { |
505 | return true; | 505 | return true; |
506 | } | 506 | } |
507 | } | 507 | } |
508 | 508 | ||
509 | return false; | 509 | return false; |
510 | } | 510 | } |
511 | 511 | ||
512 | void Incidence::addAttachment(Attachment *attachment) | 512 | void Incidence::addAttachment(Attachment *attachment) |
513 | { | 513 | { |
514 | if (mReadOnly || !attachment) return; | 514 | if (mReadOnly || !attachment) return; |
515 | mAttachments.append(attachment); | 515 | mAttachments.append(attachment); |
516 | updated(); | 516 | updated(); |
517 | } | 517 | } |
518 | 518 | ||
519 | void Incidence::deleteAttachment(Attachment *attachment) | 519 | void Incidence::deleteAttachment(Attachment *attachment) |
520 | { | 520 | { |
521 | mAttachments.removeRef(attachment); | 521 | mAttachments.removeRef(attachment); |
522 | } | 522 | } |
523 | 523 | ||
524 | void Incidence::deleteAttachments(const QString& mime) | 524 | void Incidence::deleteAttachments(const QString& mime) |
525 | { | 525 | { |
526 | Attachment *at = mAttachments.first(); | 526 | Attachment *at = mAttachments.first(); |
527 | while (at) { | 527 | while (at) { |
528 | if (at->mimeType() == mime) | 528 | if (at->mimeType() == mime) |
529 | mAttachments.remove(); | 529 | mAttachments.remove(); |
530 | else | 530 | else |
531 | at = mAttachments.next(); | 531 | at = mAttachments.next(); |
532 | } | 532 | } |
533 | } | 533 | } |
534 | 534 | ||
535 | QPtrList<Attachment> Incidence::attachments() const | 535 | QPtrList<Attachment> Incidence::attachments() const |
536 | { | 536 | { |
537 | return mAttachments; | 537 | return mAttachments; |
538 | } | 538 | } |
539 | 539 | ||
540 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const | 540 | QPtrList<Attachment> Incidence::attachments(const QString& mime) const |
541 | { | 541 | { |
542 | QPtrList<Attachment> attachments; | 542 | QPtrList<Attachment> attachments; |
543 | QPtrListIterator<Attachment> it( mAttachments ); | 543 | QPtrListIterator<Attachment> it( mAttachments ); |
544 | Attachment *at; | 544 | Attachment *at; |
545 | while ( (at = it.current()) ) { | 545 | while ( (at = it.current()) ) { |
546 | if (at->mimeType() == mime) | 546 | if (at->mimeType() == mime) |
547 | attachments.append(at); | 547 | attachments.append(at); |
548 | ++it; | 548 | ++it; |
549 | } | 549 | } |
550 | 550 | ||
551 | return attachments; | 551 | return attachments; |
552 | } | 552 | } |
553 | 553 | ||
554 | void Incidence::setResources(const QStringList &resources) | 554 | void Incidence::setResources(const QStringList &resources) |
555 | { | 555 | { |
556 | if (mReadOnly) return; | 556 | if (mReadOnly) return; |
557 | mResources = resources; | 557 | mResources = resources; |
558 | updated(); | 558 | updated(); |
559 | } | 559 | } |
560 | 560 | ||
561 | QStringList Incidence::resources() const | 561 | QStringList Incidence::resources() const |
562 | { | 562 | { |
563 | return mResources; | 563 | return mResources; |
564 | } | 564 | } |
565 | 565 | ||
566 | 566 | ||
567 | void Incidence::setPriority(int priority) | 567 | void Incidence::setPriority(int priority) |
568 | { | 568 | { |
569 | if (mReadOnly) return; | 569 | if (mReadOnly) return; |
570 | mPriority = priority; | 570 | mPriority = priority; |
571 | updated(); | 571 | updated(); |
572 | } | 572 | } |
573 | 573 | ||
574 | int Incidence::priority() const | 574 | int Incidence::priority() const |
575 | { | 575 | { |
576 | return mPriority; | 576 | return mPriority; |
577 | } | 577 | } |
578 | 578 | ||
579 | void Incidence::setSecrecy(int sec) | 579 | void Incidence::setSecrecy(int sec) |
580 | { | 580 | { |
581 | if (mReadOnly) return; | 581 | if (mReadOnly) return; |
582 | mSecrecy = sec; | 582 | mSecrecy = sec; |
583 | updated(); | 583 | updated(); |
584 | } | 584 | } |
585 | 585 | ||
586 | int Incidence::secrecy() const | 586 | int Incidence::secrecy() const |
587 | { | 587 | { |
588 | return mSecrecy; | 588 | return mSecrecy; |
589 | } | 589 | } |
590 | 590 | ||
591 | QString Incidence::secrecyStr() const | 591 | QString Incidence::secrecyStr() const |
592 | { | 592 | { |
593 | return secrecyName(mSecrecy); | 593 | return secrecyName(mSecrecy); |
594 | } | 594 | } |
595 | 595 | ||
596 | QString Incidence::secrecyName(int secrecy) | 596 | QString Incidence::secrecyName(int secrecy) |
597 | { | 597 | { |
598 | switch (secrecy) { | 598 | switch (secrecy) { |
599 | case SecrecyPublic: | 599 | case SecrecyPublic: |
600 | return i18n("Public"); | 600 | return i18n("Public"); |
601 | break; | 601 | break; |
602 | case SecrecyPrivate: | 602 | case SecrecyPrivate: |
603 | return i18n("Private"); | 603 | return i18n("Private"); |
604 | break; | 604 | break; |
605 | case SecrecyConfidential: | 605 | case SecrecyConfidential: |
606 | return i18n("Confidential"); | 606 | return i18n("Confidential"); |
607 | break; | 607 | break; |
608 | default: | 608 | default: |
609 | return i18n("Undefined"); | 609 | return i18n("Undefined"); |
610 | break; | 610 | break; |
611 | } | 611 | } |
612 | } | 612 | } |
613 | 613 | ||
614 | QStringList Incidence::secrecyList() | 614 | QStringList Incidence::secrecyList() |
615 | { | 615 | { |
616 | QStringList list; | 616 | QStringList list; |
617 | list << secrecyName(SecrecyPublic); | 617 | list << secrecyName(SecrecyPublic); |
618 | list << secrecyName(SecrecyPrivate); | 618 | list << secrecyName(SecrecyPrivate); |
619 | list << secrecyName(SecrecyConfidential); | 619 | list << secrecyName(SecrecyConfidential); |
620 | 620 | ||
621 | return list; | 621 | return list; |
622 | } | 622 | } |
623 | 623 | ||
624 | 624 | ||
625 | QPtrList<Alarm> Incidence::alarms() const | 625 | QPtrList<Alarm> Incidence::alarms() const |
626 | { | 626 | { |
627 | return mAlarms; | 627 | return mAlarms; |
628 | } | 628 | } |
629 | 629 | ||
630 | Alarm* Incidence::newAlarm() | 630 | Alarm* Incidence::newAlarm() |
631 | { | 631 | { |
632 | Alarm* alarm = new Alarm(this); | 632 | Alarm* alarm = new Alarm(this); |
633 | mAlarms.append(alarm); | 633 | mAlarms.append(alarm); |
634 | // updated(); | 634 | // updated(); |
635 | return alarm; | 635 | return alarm; |
636 | } | 636 | } |
637 | 637 | ||
638 | void Incidence::addAlarm(Alarm *alarm) | 638 | void Incidence::addAlarm(Alarm *alarm) |
639 | { | 639 | { |
640 | mAlarms.append(alarm); | 640 | mAlarms.append(alarm); |
641 | updated(); | 641 | updated(); |
642 | } | 642 | } |
643 | 643 | ||
644 | void Incidence::removeAlarm(Alarm *alarm) | 644 | void Incidence::removeAlarm(Alarm *alarm) |
645 | { | 645 | { |
646 | mAlarms.removeRef(alarm); | 646 | mAlarms.removeRef(alarm); |
647 | updated(); | 647 | updated(); |
648 | } | 648 | } |
649 | 649 | ||
650 | void Incidence::clearAlarms() | 650 | void Incidence::clearAlarms() |
651 | { | 651 | { |
652 | mAlarms.clear(); | 652 | mAlarms.clear(); |
653 | updated(); | 653 | updated(); |
654 | } | 654 | } |
655 | 655 | ||
656 | bool Incidence::isAlarmEnabled() const | 656 | bool Incidence::isAlarmEnabled() const |
657 | { | 657 | { |
658 | Alarm* alarm; | 658 | Alarm* alarm; |
659 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 659 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
660 | if (alarm->enabled()) | 660 | if (alarm->enabled()) |
661 | return true; | 661 | return true; |
662 | } | 662 | } |
663 | return false; | 663 | return false; |
664 | } | 664 | } |
665 | 665 | ||
666 | Recurrence *Incidence::recurrence() const | 666 | Recurrence *Incidence::recurrence() const |
667 | { | 667 | { |
668 | return mRecurrence; | 668 | return mRecurrence; |
669 | } | 669 | } |
670 | void Incidence::setRecurrence( Recurrence * r) | 670 | void Incidence::setRecurrence( Recurrence * r) |
671 | { | 671 | { |
672 | delete mRecurrence; | 672 | delete mRecurrence; |
673 | mRecurrence = r; | 673 | mRecurrence = r; |
674 | } | 674 | } |
675 | 675 | ||
676 | void Incidence::setLocation(const QString &location) | 676 | void Incidence::setLocation(const QString &location) |
677 | { | 677 | { |
678 | if (mReadOnly) return; | 678 | if (mReadOnly) return; |
679 | mLocation = location; | 679 | mLocation = location; |
680 | updated(); | 680 | updated(); |
681 | } | 681 | } |
682 | 682 | ||
683 | QString Incidence::location() const | 683 | QString Incidence::location() const |
684 | { | 684 | { |
685 | return mLocation; | 685 | return mLocation; |
686 | } | 686 | } |
687 | 687 | ||
688 | ushort Incidence::doesRecur() const | 688 | ushort Incidence::doesRecur() const |
689 | { | 689 | { |
690 | if ( mRecurrence ) return mRecurrence->doesRecur(); | 690 | if ( mRecurrence ) return mRecurrence->doesRecur(); |
691 | else return Recurrence::rNone; | 691 | else return Recurrence::rNone; |
692 | } | 692 | } |
693 | 693 | ||
694 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const | 694 | QDateTime Incidence::getNextOccurence( const QDateTime& dt, bool* ok ) const |
695 | { | 695 | { |
696 | QDateTime incidenceStart = dt; | 696 | QDateTime incidenceStart = dt; |
697 | *ok = false; | 697 | *ok = false; |
698 | if ( doesRecur() ) { | 698 | if ( doesRecur() ) { |
699 | bool last; | 699 | bool last; |
700 | recurrence()->getPreviousDateTime( incidenceStart , &last ); | 700 | recurrence()->getPreviousDateTime( incidenceStart , &last ); |
701 | int count = 0; | 701 | int count = 0; |
702 | if ( !last ) { | 702 | if ( !last ) { |
703 | while ( !last ) { | 703 | while ( !last ) { |
704 | ++count; | 704 | ++count; |
705 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); | 705 | incidenceStart = recurrence()->getNextDateTime( incidenceStart, &last ); |
706 | if ( recursOn( incidenceStart.date() ) ) { | 706 | if ( recursOn( incidenceStart.date() ) ) { |
707 | last = true; // exit while llop | 707 | last = true; // exit while llop |
708 | } else { | 708 | } else { |
709 | if ( last ) { // no alarm on last recurrence | 709 | if ( last ) { // no alarm on last recurrence |
710 | return QDateTime (); | 710 | return QDateTime (); |
711 | } | 711 | } |
712 | int year = incidenceStart.date().year(); | 712 | int year = incidenceStart.date().year(); |
713 | // workaround for bug in recurrence | 713 | // workaround for bug in recurrence |
714 | if ( count == 100 || year < 1000 || year > 5000 ) { | 714 | if ( count == 100 || year < 1000 || year > 5000 ) { |
715 | return QDateTime (); | 715 | return QDateTime (); |
716 | } | 716 | } |
717 | incidenceStart = incidenceStart.addSecs( 1 ); | 717 | incidenceStart = incidenceStart.addSecs( 1 ); |
718 | } | 718 | } |
719 | } | 719 | } |
720 | } else { | 720 | } else { |
721 | return QDateTime (); | 721 | return QDateTime (); |
722 | } | 722 | } |
723 | } else { | 723 | } else { |
724 | if ( hasStartDate () ) { | 724 | if ( hasStartDate () ) { |
725 | incidenceStart = dtStart(); | 725 | incidenceStart = dtStart(); |
726 | } | 726 | } |
727 | if ( type() =="Todo" ) { | 727 | if ( typeID() == todoID ) { |
728 | if ( ((Todo*)this)->hasDueDate() ) | 728 | if ( ((Todo*)this)->hasDueDate() ) |
729 | incidenceStart = ((Todo*)this)->dtDue(); | 729 | incidenceStart = ((Todo*)this)->dtDue(); |
730 | } | 730 | } |
731 | } | 731 | } |
732 | if ( incidenceStart > dt ) | 732 | if ( incidenceStart > dt ) |
733 | *ok = true; | 733 | *ok = true; |
734 | return incidenceStart; | 734 | return incidenceStart; |
735 | } | 735 | } |
736 | QDateTime Incidence::dtStart() const | 736 | QDateTime Incidence::dtStart() const |
737 | { | 737 | { |
738 | if ( doesRecur() ) { | 738 | if ( doesRecur() ) { |
739 | if ( type() == "Todo" ) { | 739 | if ( typeID() == todoID ) { |
740 | ((Todo*)this)->checkSetCompletedFalse(); | 740 | ((Todo*)this)->checkSetCompletedFalse(); |
741 | } | 741 | } |
742 | } | 742 | } |
743 | return mDtStart; | 743 | return mDtStart; |
744 | } | 744 | } |
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index 8624786..05209e0 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h | |||
@@ -1,172 +1,174 @@ | |||
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 KCAL_INCIDENCEBASE_H | 20 | #ifndef KCAL_INCIDENCEBASE_H |
21 | #define KCAL_INCIDENCEBASE_H | 21 | #define KCAL_INCIDENCEBASE_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 | #include <qptrlist.h> | 29 | #include <qptrlist.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "attendee.h" | 32 | #include "attendee.h" |
33 | 33 | ||
34 | namespace KCal { | 34 | namespace KCal { |
35 | 35 | ||
36 | typedef QValueList<QDate> DateList; | 36 | typedef QValueList<QDate> DateList; |
37 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; | ||
37 | 38 | ||
38 | /** | 39 | /** |
39 | This class provides the base class common to all calendar components. | 40 | This class provides the base class common to all calendar components. |
40 | */ | 41 | */ |
41 | class IncidenceBase : public CustomProperties | 42 | class IncidenceBase : public CustomProperties |
42 | { | 43 | { |
43 | public: | 44 | public: |
44 | class Observer { | 45 | class Observer { |
45 | public: | 46 | public: |
46 | virtual void incidenceUpdated( IncidenceBase * ) = 0; | 47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; |
47 | }; | 48 | }; |
48 | 49 | ||
49 | IncidenceBase(); | 50 | IncidenceBase(); |
50 | IncidenceBase(const IncidenceBase &); | 51 | IncidenceBase(const IncidenceBase &); |
51 | virtual ~IncidenceBase(); | 52 | virtual ~IncidenceBase(); |
52 | 53 | ||
53 | virtual QCString type() const = 0; | 54 | virtual QCString type() const = 0; |
55 | virtual IncTypeID typeID() const = 0; | ||
54 | 56 | ||
55 | /** Set the unique id for the event */ | 57 | /** Set the unique id for the event */ |
56 | void setUid(const QString &); | 58 | void setUid(const QString &); |
57 | /** Return the unique id for the event */ | 59 | /** Return the unique id for the event */ |
58 | QString uid() const; | 60 | QString uid() const; |
59 | 61 | ||
60 | /** Sets the time the incidence was last modified. */ | 62 | /** Sets the time the incidence was last modified. */ |
61 | void setLastModified(const QDateTime &lm); | 63 | void setLastModified(const QDateTime &lm); |
62 | /** Return the time the incidence was last modified. */ | 64 | /** Return the time the incidence was last modified. */ |
63 | QDateTime lastModified() const; | 65 | QDateTime lastModified() const; |
64 | 66 | ||
65 | /** sets the organizer for the event */ | 67 | /** sets the organizer for the event */ |
66 | void setOrganizer(const QString &o); | 68 | void setOrganizer(const QString &o); |
67 | QString organizer() const; | 69 | QString organizer() const; |
68 | 70 | ||
69 | /** Set readonly status. */ | 71 | /** Set readonly status. */ |
70 | virtual void setReadOnly( bool ); | 72 | virtual void setReadOnly( bool ); |
71 | /** Return if the object is read-only. */ | 73 | /** Return if the object is read-only. */ |
72 | bool isReadOnly() const { return mReadOnly; } | 74 | bool isReadOnly() const { return mReadOnly; } |
73 | 75 | ||
74 | /** for setting the event's starting date/time with a QDateTime. */ | 76 | /** for setting the event's starting date/time with a QDateTime. */ |
75 | virtual void setDtStart(const QDateTime &dtStart); | 77 | virtual void setDtStart(const QDateTime &dtStart); |
76 | /** returns an event's starting date/time as a QDateTime. */ | 78 | /** returns an event's starting date/time as a QDateTime. */ |
77 | virtual QDateTime dtStart() const; | 79 | virtual QDateTime dtStart() const; |
78 | /** returns an event's starting time as a string formatted according to the | 80 | /** returns an event's starting time as a string formatted according to the |
79 | users locale settings */ | 81 | users locale settings */ |
80 | QString dtStartTimeStr() const; | 82 | QString dtStartTimeStr() const; |
81 | /** returns an event's starting date as a string formatted according to the | 83 | /** returns an event's starting date as a string formatted according to the |
82 | users locale settings */ | 84 | users locale settings */ |
83 | QString dtStartDateStr(bool shortfmt=true) const; | 85 | QString dtStartDateStr(bool shortfmt=true) const; |
84 | /** returns an event's starting date and time as a string formatted according | 86 | /** returns an event's starting date and time as a string formatted according |
85 | to the users locale settings */ | 87 | to the users locale settings */ |
86 | QString dtStartStr(bool shortfmt=true) const; | 88 | QString dtStartStr(bool shortfmt=true) const; |
87 | 89 | ||
88 | virtual void setDuration(int seconds); | 90 | virtual void setDuration(int seconds); |
89 | int duration() const; | 91 | int duration() const; |
90 | void setHasDuration(bool); | 92 | void setHasDuration(bool); |
91 | bool hasDuration() const; | 93 | bool hasDuration() const; |
92 | 94 | ||
93 | /** Return true or false depending on whether the incidence "floats," | 95 | /** Return true or false depending on whether the incidence "floats," |
94 | * i.e. has a date but no time attached to it. */ | 96 | * i.e. has a date but no time attached to it. */ |
95 | bool doesFloat() const; | 97 | bool doesFloat() const; |
96 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ | 98 | /** Set whether the incidence floats, i.e. has a date but no time attached to it. */ |
97 | void setFloats(bool f); | 99 | void setFloats(bool f); |
98 | 100 | ||
99 | /** | 101 | /** |
100 | Add Attendee to this incidence. IncidenceBase takes ownership of the | 102 | Add Attendee to this incidence. IncidenceBase takes ownership of the |
101 | Attendee object. | 103 | Attendee object. |
102 | */ | 104 | */ |
103 | bool addAttendee(Attendee *a, bool doupdate=true ); | 105 | bool addAttendee(Attendee *a, bool doupdate=true ); |
104 | // void removeAttendee(Attendee *a); | 106 | // void removeAttendee(Attendee *a); |
105 | // void removeAttendee(const char *n); | 107 | // void removeAttendee(const char *n); |
106 | /** Remove all Attendees. */ | 108 | /** Remove all Attendees. */ |
107 | void clearAttendees(); | 109 | void clearAttendees(); |
108 | /** Return list of attendees. */ | 110 | /** Return list of attendees. */ |
109 | QPtrList<Attendee> attendees() const { return mAttendees; }; | 111 | QPtrList<Attendee> attendees() const { return mAttendees; }; |
110 | /** Return number of attendees. */ | 112 | /** Return number of attendees. */ |
111 | int attendeeCount() const { return mAttendees.count(); }; | 113 | int attendeeCount() const { return mAttendees.count(); }; |
112 | /** Return the Attendee with this email */ | 114 | /** Return the Attendee with this email */ |
113 | Attendee* attendeeByMail(const QString &); | 115 | Attendee* attendeeByMail(const QString &); |
114 | /** Return first Attendee with one of this emails */ | 116 | /** Return first Attendee with one of this emails */ |
115 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); | 117 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); |
116 | 118 | ||
117 | /** pilot syncronization states */ | 119 | /** pilot syncronization states */ |
118 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; | 120 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; |
119 | /** Set synchronisation satus. */ | 121 | /** Set synchronisation satus. */ |
120 | void setSyncStatus(int stat); | 122 | void setSyncStatus(int stat); |
121 | /** Return synchronisation status. */ | 123 | /** Return synchronisation status. */ |
122 | int syncStatus() const; | 124 | int syncStatus() const; |
123 | 125 | ||
124 | /** Set Pilot Id. */ | 126 | /** Set Pilot Id. */ |
125 | void setPilotId(int id); | 127 | void setPilotId(int id); |
126 | /** Return Pilot Id. */ | 128 | /** Return Pilot Id. */ |
127 | int pilotId() const; | 129 | int pilotId() const; |
128 | 130 | ||
129 | void setTempSyncStat(int id); | 131 | void setTempSyncStat(int id); |
130 | int tempSyncStat() const; | 132 | int tempSyncStat() const; |
131 | void setIDStr( const QString & ); | 133 | void setIDStr( const QString & ); |
132 | QString IDStr() const; | 134 | QString IDStr() const; |
133 | void setID( const QString &, const QString & ); | 135 | void setID( const QString &, const QString & ); |
134 | QString getID( const QString & ); | 136 | QString getID( const QString & ); |
135 | void setCsum( const QString &, const QString & ); | 137 | void setCsum( const QString &, const QString & ); |
136 | QString getCsum( const QString & ); | 138 | QString getCsum( const QString & ); |
137 | void removeID(const QString &); | 139 | void removeID(const QString &); |
138 | 140 | ||
139 | void registerObserver( Observer * ); | 141 | void registerObserver( Observer * ); |
140 | void unRegisterObserver( Observer * ); | 142 | void unRegisterObserver( Observer * ); |
141 | void updated(); | 143 | void updated(); |
142 | 144 | ||
143 | protected: | 145 | protected: |
144 | QDateTime mDtStart; | 146 | QDateTime mDtStart; |
145 | bool mReadOnly; | 147 | bool mReadOnly; |
146 | QDateTime getEvenTime( QDateTime ); | 148 | QDateTime getEvenTime( QDateTime ); |
147 | 149 | ||
148 | private: | 150 | private: |
149 | // base components | 151 | // base components |
150 | QString mOrganizer; | 152 | QString mOrganizer; |
151 | QString mUid; | 153 | QString mUid; |
152 | QDateTime mLastModified; | 154 | QDateTime mLastModified; |
153 | QPtrList<Attendee> mAttendees; | 155 | QPtrList<Attendee> mAttendees; |
154 | 156 | ||
155 | bool mFloats; | 157 | bool mFloats; |
156 | 158 | ||
157 | int mDuration; | 159 | int mDuration; |
158 | bool mHasDuration; | 160 | bool mHasDuration; |
159 | QString mExternalId; | 161 | QString mExternalId; |
160 | int mTempSyncStat; | 162 | int mTempSyncStat; |
161 | 163 | ||
162 | // PILOT SYNCHRONIZATION STUFF | 164 | // PILOT SYNCHRONIZATION STUFF |
163 | int mPilotId; // unique id for pilot sync | 165 | int mPilotId; // unique id for pilot sync |
164 | int mSyncStatus; // status (for sync) | 166 | int mSyncStatus; // status (for sync) |
165 | 167 | ||
166 | QPtrList<Observer> mObservers; | 168 | QPtrList<Observer> mObservers; |
167 | }; | 169 | }; |
168 | 170 | ||
169 | bool operator==( const IncidenceBase&, const IncidenceBase& ); | 171 | bool operator==( const IncidenceBase&, const IncidenceBase& ); |
170 | } | 172 | } |
171 | 173 | ||
172 | #endif | 174 | #endif |
diff --git a/libkcal/journal.h b/libkcal/journal.h index 2c1d7ea..1cd0a22 100644 --- a/libkcal/journal.h +++ b/libkcal/journal.h | |||
@@ -1,50 +1,51 @@ | |||
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 JOURNAL_H | 20 | #ifndef JOURNAL_H |
21 | #define JOURNAL_H | 21 | #define JOURNAL_H |
22 | // | 22 | // |
23 | // Journal component, representing a VJOURNAL object | 23 | // Journal component, representing a VJOURNAL object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | 27 | ||
28 | namespace KCal { | 28 | namespace KCal { |
29 | 29 | ||
30 | /** | 30 | /** |
31 | This class provides a Journal in the sense of RFC2445. | 31 | This class provides a Journal in the sense of RFC2445. |
32 | */ | 32 | */ |
33 | class Journal : public Incidence | 33 | class Journal : public Incidence |
34 | { | 34 | { |
35 | public: | 35 | public: |
36 | Journal(); | 36 | Journal(); |
37 | ~Journal(); | 37 | ~Journal(); |
38 | 38 | ||
39 | QCString type() const { return "Journal"; } | 39 | QCString type() const { return "Journal"; } |
40 | IncTypeID typeID() const { return journalID; } | ||
40 | 41 | ||
41 | Incidence *clone(); | 42 | Incidence *clone(); |
42 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; | 43 | QDateTime getNextAlarmDateTime( bool * ok, int * offset ,QDateTime start_dt ) const; |
43 | private: | 44 | private: |
44 | bool accept(Visitor &v) { return v.visit(this); } | 45 | bool accept(Visitor &v) { return v.visit(this); } |
45 | }; | 46 | }; |
46 | 47 | ||
47 | bool operator==( const Journal&, const Journal& ); | 48 | bool operator==( const Journal&, const Journal& ); |
48 | } | 49 | } |
49 | 50 | ||
50 | #endif | 51 | #endif |
diff --git a/libkcal/kincidenceformatter.cpp b/libkcal/kincidenceformatter.cpp index 7d61b7f..d1ace4f 100644 --- a/libkcal/kincidenceformatter.cpp +++ b/libkcal/kincidenceformatter.cpp | |||
@@ -1,410 +1,410 @@ | |||
1 | #include "kincidenceformatter.h" | 1 | #include "kincidenceformatter.h" |
2 | #include <kstaticdeleter.h> | 2 | #include <kstaticdeleter.h> |
3 | #include <kglobal.h> | 3 | #include <kglobal.h> |
4 | #include <klocale.h> | 4 | #include <klocale.h> |
5 | #ifdef DEKTOP_VERSION | 5 | #ifdef DEKTOP_VERSION |
6 | #include <kabc/stdaddressbook.h> | 6 | #include <kabc/stdaddressbook.h> |
7 | #define size count | 7 | #define size count |
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; | 10 | KIncidenceFormatter* KIncidenceFormatter::mInstance = 0; |
11 | static KStaticDeleter<KIncidenceFormatter> insd; | 11 | static KStaticDeleter<KIncidenceFormatter> insd; |
12 | 12 | ||
13 | QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) | 13 | QString KIncidenceFormatter::getFormattedText( Incidence * inc, bool details, bool created , bool modified ) |
14 | { | 14 | { |
15 | // #ifndef QT_NO_INPUTDIALOG | 15 | // #ifndef QT_NO_INPUTDIALOG |
16 | // return QInputDialog::getItem( caption, label, items, current, editable ); | 16 | // return QInputDialog::getItem( caption, label, items, current, editable ); |
17 | // #else | 17 | // #else |
18 | // return QString::null; | 18 | // return QString::null; |
19 | // #endif | 19 | // #endif |
20 | mDetails = details; | 20 | mDetails = details; |
21 | mCreated = created ; | 21 | mCreated = created ; |
22 | mModified = modified; | 22 | mModified = modified; |
23 | mText = ""; | 23 | mText = ""; |
24 | if ( inc->type() == "Event" ) | 24 | if ( inc->typeID() == eventID ) |
25 | setEvent((Event *) inc ); | 25 | setEvent((Event *) inc ); |
26 | else if ( inc->type() == "Todo" ) | 26 | else if ( inc->typeID() == todoID ) |
27 | setTodo((Todo *) inc ); | 27 | setTodo((Todo *) inc ); |
28 | return mText; | 28 | return mText; |
29 | } | 29 | } |
30 | 30 | ||
31 | KIncidenceFormatter* KIncidenceFormatter::instance() | 31 | KIncidenceFormatter* KIncidenceFormatter::instance() |
32 | { | 32 | { |
33 | if (!mInstance) { | 33 | if (!mInstance) { |
34 | mInstance = insd.setObject(new KIncidenceFormatter()); | 34 | mInstance = insd.setObject(new KIncidenceFormatter()); |
35 | } | 35 | } |
36 | return mInstance; | 36 | return mInstance; |
37 | } | 37 | } |
38 | KIncidenceFormatter::~KIncidenceFormatter() | 38 | KIncidenceFormatter::~KIncidenceFormatter() |
39 | { | 39 | { |
40 | if (mInstance == this) | 40 | if (mInstance == this) |
41 | mInstance = insd.setObject(0); | 41 | mInstance = insd.setObject(0); |
42 | //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); | 42 | //qDebug("KIncidenceFormatter::~KIncidenceFormatter "); |
43 | } | 43 | } |
44 | KIncidenceFormatter::KIncidenceFormatter() | 44 | KIncidenceFormatter::KIncidenceFormatter() |
45 | { | 45 | { |
46 | mColorMode = 0; | 46 | mColorMode = 0; |
47 | } | 47 | } |
48 | void KIncidenceFormatter::setEvent(Event *event) | 48 | void KIncidenceFormatter::setEvent(Event *event) |
49 | { | 49 | { |
50 | int mode = 0; | 50 | int mode = 0; |
51 | mCurrentIncidence = event; | 51 | mCurrentIncidence = event; |
52 | bool shortDate = true; | 52 | bool shortDate = true; |
53 | if ( mode == 0 ) { | 53 | if ( mode == 0 ) { |
54 | addTag("h3",deTag(event->summary())); | 54 | addTag("h3",deTag(event->summary())); |
55 | } | 55 | } |
56 | else { | 56 | else { |
57 | if ( mColorMode == 1 ) { | 57 | if ( mColorMode == 1 ) { |
58 | mText +="<font color=\"#00A000\">"; | 58 | mText +="<font color=\"#00A000\">"; |
59 | } | 59 | } |
60 | if ( mColorMode == 2 ) { | 60 | if ( mColorMode == 2 ) { |
61 | mText +="<font color=\"#C00000\">"; | 61 | mText +="<font color=\"#C00000\">"; |
62 | } | 62 | } |
63 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; | 63 | // mText +="<font color=\"#F00000\">" + i18n("O-due!") + "</font>"; |
64 | if ( mode == 1 ) { | 64 | if ( mode == 1 ) { |
65 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); | 65 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); |
66 | } else { | 66 | } else { |
67 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); | 67 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); |
68 | } | 68 | } |
69 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | 69 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); |
70 | if ( mColorMode ) | 70 | if ( mColorMode ) |
71 | mText += "</font>"; | 71 | mText += "</font>"; |
72 | } | 72 | } |
73 | if (event->cancelled ()) { | 73 | if (event->cancelled ()) { |
74 | mText +="<font color=\"#B00000\">"; | 74 | mText +="<font color=\"#B00000\">"; |
75 | addTag("i",i18n("This event has been cancelled!")); | 75 | addTag("i",i18n("This event has been cancelled!")); |
76 | mText.append("<br>"); | 76 | mText.append("<br>"); |
77 | mText += "</font>"; | 77 | mText += "</font>"; |
78 | } | 78 | } |
79 | if (event->doesFloat()) { | 79 | if (event->doesFloat()) { |
80 | if (event->isMultiDay()) { | 80 | if (event->isMultiDay()) { |
81 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") | 81 | mText.append(i18n("<p><b>From:</b> %1 </p><p><b>To:</b> %2</p>") |
82 | .arg(event->dtStartDateStr(shortDate)) | 82 | .arg(event->dtStartDateStr(shortDate)) |
83 | .arg(event->dtEndDateStr(shortDate))); | 83 | .arg(event->dtEndDateStr(shortDate))); |
84 | } else { | 84 | } else { |
85 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); | 85 | mText.append(i18n("<p><b>On:</b> %1</p>").arg(event->dtStartDateStr( shortDate ))); |
86 | } | 86 | } |
87 | } else { | 87 | } else { |
88 | if (event->isMultiDay()) { | 88 | if (event->isMultiDay()) { |
89 | mText.append(i18n("<p><b>From:</b> %1</p> ") | 89 | mText.append(i18n("<p><b>From:</b> %1</p> ") |
90 | .arg(event->dtStartStr( shortDate))); | 90 | .arg(event->dtStartStr( shortDate))); |
91 | mText.append(i18n("<p><b>To:</b> %1</p>") | 91 | mText.append(i18n("<p><b>To:</b> %1</p>") |
92 | .arg(event->dtEndStr(shortDate))); | 92 | .arg(event->dtEndStr(shortDate))); |
93 | } else { | 93 | } else { |
94 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") | 94 | mText.append(i18n("<p><b>From:</b> %1 <b>To:</b> %2</p>") |
95 | .arg(event->dtStartTimeStr()) | 95 | .arg(event->dtStartTimeStr()) |
96 | .arg(event->dtEndTimeStr())); | 96 | .arg(event->dtEndTimeStr())); |
97 | mText.append(i18n("<p><b>On:</b> %1</p> ") | 97 | mText.append(i18n("<p><b>On:</b> %1</p> ") |
98 | .arg(event->dtStartDateStr( shortDate ))); | 98 | .arg(event->dtStartDateStr( shortDate ))); |
99 | } | 99 | } |
100 | } | 100 | } |
101 | if (!event->location().isEmpty()) { | 101 | if (!event->location().isEmpty()) { |
102 | addTag("b",i18n("Location: ")); | 102 | addTag("b",i18n("Location: ")); |
103 | mText.append(deTag(event->location())+"<br>"); | 103 | mText.append(deTag(event->location())+"<br>"); |
104 | } | 104 | } |
105 | 105 | ||
106 | if (event->recurrence()->doesRecur()) { | 106 | if (event->recurrence()->doesRecur()) { |
107 | 107 | ||
108 | QString recurText = event->recurrence()->recurrenceText(); | 108 | QString recurText = event->recurrence()->recurrenceText(); |
109 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); | 109 | addTag("p","<em>" + i18n("This is a %1 recurring event.").arg(recurText ) + "</em>"); |
110 | 110 | ||
111 | bool ok; | 111 | bool ok; |
112 | QDate start = QDate::currentDate(); | 112 | QDate start = QDate::currentDate(); |
113 | QDateTime next; | 113 | QDateTime next; |
114 | next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); | 114 | next = event->getNextOccurence( QDateTime::currentDateTime() , &ok ); |
115 | if ( ok ) { | 115 | if ( ok ) { |
116 | addTag("p",i18n("<b>Next recurrence is on:</b>") ); | 116 | addTag("p",i18n("<b>Next recurrence is on:</b>") ); |
117 | addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); | 117 | addTag("p", KGlobal::locale()->formatDate( next.date(), shortDate )); |
118 | 118 | ||
119 | } else { | 119 | } else { |
120 | bool last; | 120 | bool last; |
121 | QDate nextd; | 121 | QDate nextd; |
122 | nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); | 122 | nextd = event->recurrence()->getPreviousDate( QDate::currentDate() , &last ); |
123 | if ( last ) { | 123 | if ( last ) { |
124 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); | 124 | addTag("p",i18n("<b>Last recurrence was on:</b>") ); |
125 | addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); | 125 | addTag("p", KGlobal::locale()->formatDate( nextd, shortDate )); |
126 | } | 126 | } |
127 | } | 127 | } |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | if (event->isAlarmEnabled()) { | 131 | if (event->isAlarmEnabled()) { |
132 | Alarm *alarm =event->alarms().first() ; | 132 | Alarm *alarm =event->alarms().first() ; |
133 | QDateTime t = alarm->time(); | 133 | QDateTime t = alarm->time(); |
134 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); | 134 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); |
135 | addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); | 135 | addTag("p",i18n("<b>Alarm on: </b>") + s + ": "+KGlobal::locale()->formatDateTime( t, shortDate )); |
136 | //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | 136 | //addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); |
137 | //addTag("p",s); | 137 | //addTag("p",s); |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | 141 | ||
142 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | 142 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); |
143 | // mText.append(event->secrecyStr()+"<br>"); | 143 | // mText.append(event->secrecyStr()+"<br>"); |
144 | formatCategories(event); | 144 | formatCategories(event); |
145 | 145 | ||
146 | formatReadOnly(event); | 146 | formatReadOnly(event); |
147 | formatAttendees(event); | 147 | formatAttendees(event); |
148 | 148 | ||
149 | if ( mCreated ) { | 149 | if ( mCreated ) { |
150 | #ifdef DESKTOP_VERSION | 150 | #ifdef DESKTOP_VERSION |
151 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 151 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
152 | #else | 152 | #else |
153 | addTag("p",i18n("<b>Created: ") +" </b>"); | 153 | addTag("p",i18n("<b>Created: ") +" </b>"); |
154 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 154 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
155 | #endif | 155 | #endif |
156 | 156 | ||
157 | } | 157 | } |
158 | if ( mModified ) { | 158 | if ( mModified ) { |
159 | #ifdef DESKTOP_VERSION | 159 | #ifdef DESKTOP_VERSION |
160 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 160 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
161 | #else | 161 | #else |
162 | addTag("p",i18n("<b>Last modified: ") +" </b>"); | 162 | addTag("p",i18n("<b>Last modified: ") +" </b>"); |
163 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 163 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
164 | #endif | 164 | #endif |
165 | 165 | ||
166 | } | 166 | } |
167 | if ( mDetails ) { | 167 | if ( mDetails ) { |
168 | if (!event->description().isEmpty()) { | 168 | if (!event->description().isEmpty()) { |
169 | addTag("p",i18n("<b>Details: </b>")); | 169 | addTag("p",i18n("<b>Details: </b>")); |
170 | addTag("p",deTag(event->description())); | 170 | addTag("p",deTag(event->description())); |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | } | 174 | } |
175 | 175 | ||
176 | void KIncidenceFormatter::setTodo(Todo *event ) | 176 | void KIncidenceFormatter::setTodo(Todo *event ) |
177 | { | 177 | { |
178 | int mode = 0; | 178 | int mode = 0; |
179 | mCurrentIncidence = event; | 179 | mCurrentIncidence = event; |
180 | bool shortDate = true; | 180 | bool shortDate = true; |
181 | if (mode == 0 ) | 181 | if (mode == 0 ) |
182 | addTag("h3",deTag(event->summary())); | 182 | addTag("h3",deTag(event->summary())); |
183 | else { | 183 | else { |
184 | if ( mColorMode == 1 ) { | 184 | if ( mColorMode == 1 ) { |
185 | mText +="<font color=\"#00A000\">"; | 185 | mText +="<font color=\"#00A000\">"; |
186 | } | 186 | } |
187 | if ( mColorMode == 2 ) { | 187 | if ( mColorMode == 2 ) { |
188 | mText +="<font color=\"#B00000\">"; | 188 | mText +="<font color=\"#B00000\">"; |
189 | } | 189 | } |
190 | if ( mode == 1 ) { | 190 | if ( mode == 1 ) { |
191 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); | 191 | addTag("h2",i18n( "Local: " ) +deTag(event->summary())); |
192 | } else { | 192 | } else { |
193 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); | 193 | addTag("h2",i18n( "Remote: " ) +deTag(event->summary())); |
194 | } | 194 | } |
195 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); | 195 | addTag("h3",i18n( "Last modified: " ) + KGlobal::locale()->formatDateTime(event->lastModified(),shortDate, true ) ); |
196 | if ( mColorMode ) | 196 | if ( mColorMode ) |
197 | mText += "</font>"; | 197 | mText += "</font>"; |
198 | } | 198 | } |
199 | if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { | 199 | if ( event->percentComplete() == 100 && event->hasCompletedDate() ) { |
200 | mText +="<font color=\"#B00000\">"; | 200 | mText +="<font color=\"#B00000\">"; |
201 | addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); | 201 | addTag("i", i18n("<p><i>Completed on %1</i></p>").arg( event->completedStr(shortDate) ) ); |
202 | mText += "</font>"; | 202 | mText += "</font>"; |
203 | } else { | 203 | } else { |
204 | mText.append(i18n("<p><i>%1 % completed</i></p>") | 204 | mText.append(i18n("<p><i>%1 % completed</i></p>") |
205 | .arg(event->percentComplete())); | 205 | .arg(event->percentComplete())); |
206 | } | 206 | } |
207 | if (event->cancelled ()) { | 207 | if (event->cancelled ()) { |
208 | mText +="<font color=\"#B00000\">"; | 208 | mText +="<font color=\"#B00000\">"; |
209 | addTag("i",i18n("This todo has been cancelled!")); | 209 | addTag("i",i18n("This todo has been cancelled!")); |
210 | mText.append("<br>"); | 210 | mText.append("<br>"); |
211 | mText += "</font>"; | 211 | mText += "</font>"; |
212 | } | 212 | } |
213 | 213 | ||
214 | 214 | ||
215 | if (event->recurrence()->doesRecur()) { | 215 | if (event->recurrence()->doesRecur()) { |
216 | 216 | ||
217 | QString recurText = event->recurrence()->recurrenceText(); | 217 | QString recurText = event->recurrence()->recurrenceText(); |
218 | addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); | 218 | addTag("p","<em>" + i18n("This is a %1 recurring todo.").arg(recurText ) + "</em>"); |
219 | } | 219 | } |
220 | 220 | ||
221 | if (event->hasStartDate()) { | 221 | if (event->hasStartDate()) { |
222 | mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); | 222 | mText.append(i18n("<p><b>Start on:</b> %1</p>").arg(event->dtStartStr(shortDate))); |
223 | } | 223 | } |
224 | 224 | ||
225 | 225 | ||
226 | if (event->hasDueDate()) { | 226 | if (event->hasDueDate()) { |
227 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); | 227 | mText.append(i18n("<p><b>Due on:</b> %1</p>").arg(event->dtDueStr(shortDate))); |
228 | } | 228 | } |
229 | 229 | ||
230 | if (!event->location().isEmpty()) { | 230 | if (!event->location().isEmpty()) { |
231 | addTag("b",i18n("Location: ")); | 231 | addTag("b",i18n("Location: ")); |
232 | mText.append(deTag(event->location())+"<br>"); | 232 | mText.append(deTag(event->location())+"<br>"); |
233 | } | 233 | } |
234 | 234 | ||
235 | mText.append(i18n("<p><b>Priority:</b> %2</p>") | 235 | mText.append(i18n("<p><b>Priority:</b> %2</p>") |
236 | .arg(QString::number(event->priority()))); | 236 | .arg(QString::number(event->priority()))); |
237 | 237 | ||
238 | if (event->isAlarmEnabled()) { | 238 | if (event->isAlarmEnabled()) { |
239 | Alarm *alarm =event->alarms().first() ; | 239 | Alarm *alarm =event->alarms().first() ; |
240 | QDateTime t = alarm->time(); | 240 | QDateTime t = alarm->time(); |
241 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); | 241 | QString s =i18n("( %1 before )").arg( alarm->offsetText() ); |
242 | addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); | 242 | addTag("p",i18n("<b>Alarm on: ") + s +" </b>"); |
243 | addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); | 243 | addTag("p", KGlobal::locale()->formatDateTime( t, shortDate )); |
244 | //addTag("p",s); | 244 | //addTag("p",s); |
245 | } | 245 | } |
246 | 246 | ||
247 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); | 247 | addTag("p",i18n("<b>Access: </b>") +event->secrecyStr() ); |
248 | formatCategories(event); | 248 | formatCategories(event); |
249 | 249 | ||
250 | formatReadOnly(event); | 250 | formatReadOnly(event); |
251 | formatAttendees(event); | 251 | formatAttendees(event); |
252 | if ( mCreated ) { | 252 | if ( mCreated ) { |
253 | #ifdef DESKTOP_VERSION | 253 | #ifdef DESKTOP_VERSION |
254 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 254 | addTag("p",i18n("<b>Created: ") +" </b>"+KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
255 | #else | 255 | #else |
256 | addTag("p",i18n("<b>Created: ") +" </b>"); | 256 | addTag("p",i18n("<b>Created: ") +" </b>"); |
257 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); | 257 | addTag("p", KGlobal::locale()->formatDateTime( event->created(), shortDate )); |
258 | #endif | 258 | #endif |
259 | 259 | ||
260 | } | 260 | } |
261 | if ( mModified ) { | 261 | if ( mModified ) { |
262 | #ifdef DESKTOP_VERSION | 262 | #ifdef DESKTOP_VERSION |
263 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 263 | addTag("p",i18n("<b>Last modified: ") +" </b>"+KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
264 | #else | 264 | #else |
265 | addTag("p",i18n("<b>Last modified: ") +" </b>"); | 265 | addTag("p",i18n("<b>Last modified: ") +" </b>"); |
266 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); | 266 | addTag("p", KGlobal::locale()->formatDateTime( event->lastModified(), shortDate )); |
267 | #endif | 267 | #endif |
268 | 268 | ||
269 | } | 269 | } |
270 | if ( mDetails ) { | 270 | if ( mDetails ) { |
271 | if (!event->description().isEmpty()) { | 271 | if (!event->description().isEmpty()) { |
272 | addTag("p",i18n("<b>Details: </b>")); | 272 | addTag("p",i18n("<b>Details: </b>")); |
273 | addTag("p",deTag(event->description())); | 273 | addTag("p",deTag(event->description())); |
274 | } | 274 | } |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | void KIncidenceFormatter::setJournal(Journal* ) | 278 | void KIncidenceFormatter::setJournal(Journal* ) |
279 | { | 279 | { |
280 | 280 | ||
281 | } | 281 | } |
282 | 282 | ||
283 | void KIncidenceFormatter::formatCategories(Incidence *event) | 283 | void KIncidenceFormatter::formatCategories(Incidence *event) |
284 | { | 284 | { |
285 | if (!event->categoriesStr().isEmpty()) { | 285 | if (!event->categoriesStr().isEmpty()) { |
286 | addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() ); | 286 | addTag("p",i18n("<b>Categories: </b>")+event->categoriesStrWithSpace() ); |
287 | //mText.append(event->categoriesStr()); | 287 | //mText.append(event->categoriesStr()); |
288 | } | 288 | } |
289 | } | 289 | } |
290 | void KIncidenceFormatter::addTag(const QString & tag,const QString & text) | 290 | void KIncidenceFormatter::addTag(const QString & tag,const QString & text) |
291 | { | 291 | { |
292 | int number=text.contains("\n"); | 292 | int number=text.contains("\n"); |
293 | QString str = "<" + tag + ">"; | 293 | QString str = "<" + tag + ">"; |
294 | QString tmpText=text; | 294 | QString tmpText=text; |
295 | QString tmpStr=str; | 295 | QString tmpStr=str; |
296 | if(number !=-1) | 296 | if(number !=-1) |
297 | { | 297 | { |
298 | if (number > 0) { | 298 | if (number > 0) { |
299 | int pos=0; | 299 | int pos=0; |
300 | QString tmp; | 300 | QString tmp; |
301 | for(int i=0;i<=number;i++) { | 301 | for(int i=0;i<=number;i++) { |
302 | pos=tmpText.find("\n"); | 302 | pos=tmpText.find("\n"); |
303 | tmp=tmpText.left(pos); | 303 | tmp=tmpText.left(pos); |
304 | tmpText=tmpText.right(tmpText.length()-pos-1); | 304 | tmpText=tmpText.right(tmpText.length()-pos-1); |
305 | tmpStr+=tmp+"<br>"; | 305 | tmpStr+=tmp+"<br>"; |
306 | } | 306 | } |
307 | } | 307 | } |
308 | else tmpStr += tmpText; | 308 | else tmpStr += tmpText; |
309 | tmpStr+="</" + tag + ">"; | 309 | tmpStr+="</" + tag + ">"; |
310 | mText.append(tmpStr); | 310 | mText.append(tmpStr); |
311 | } | 311 | } |
312 | else | 312 | else |
313 | { | 313 | { |
314 | str += text + "</" + tag + ">"; | 314 | str += text + "</" + tag + ">"; |
315 | mText.append(str); | 315 | mText.append(str); |
316 | } | 316 | } |
317 | } | 317 | } |
318 | 318 | ||
319 | void KIncidenceFormatter::formatAttendees(Incidence *event) | 319 | void KIncidenceFormatter::formatAttendees(Incidence *event) |
320 | { | 320 | { |
321 | QPtrList<Attendee> attendees = event->attendees(); | 321 | QPtrList<Attendee> attendees = event->attendees(); |
322 | if (attendees.count()) { | 322 | if (attendees.count()) { |
323 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); | 323 | QString iconPath = KGlobal::iconLoader()->iconPath("mailappt",KIcon::Small); |
324 | QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); | 324 | QString NOiconPath = KGlobal::iconLoader()->iconPath("nomailappt",KIcon::Small); |
325 | addTag("h3",i18n("Organizer")); | 325 | addTag("h3",i18n("Organizer")); |
326 | mText.append("<ul><li>"); | 326 | mText.append("<ul><li>"); |
327 | #if 0 | 327 | #if 0 |
328 | //ndef KORG_NOKABC | 328 | //ndef KORG_NOKABC |
329 | 329 | ||
330 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); | 330 | KABC::AddressBook *add_book = KABC::StdAddressBook::self(); |
331 | KABC::Addressee::List addressList; | 331 | KABC::Addressee::List addressList; |
332 | addressList = add_book->findByEmail(event->organizer()); | 332 | addressList = add_book->findByEmail(event->organizer()); |
333 | KABC::Addressee o = addressList.first(); | 333 | KABC::Addressee o = addressList.first(); |
334 | if (!o.isEmpty() && addressList.size()<2) { | 334 | if (!o.isEmpty() && addressList.size()<2) { |
335 | mText += "<a href=\"uid:" + o.uid() + "\">"; | 335 | mText += "<a href=\"uid:" + o.uid() + "\">"; |
336 | mText += o.formattedName(); | 336 | mText += o.formattedName(); |
337 | mText += "</a>\n"; | 337 | mText += "</a>\n"; |
338 | } else { | 338 | } else { |
339 | mText.append(event->organizer()); | 339 | mText.append(event->organizer()); |
340 | } | 340 | } |
341 | #else | 341 | #else |
342 | mText.append(event->organizer()); | 342 | mText.append(event->organizer()); |
343 | #endif | 343 | #endif |
344 | if (iconPath) { | 344 | if (iconPath) { |
345 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; | 345 | mText += " <a href=\"mailto:" + event->organizer() + "\">"; |
346 | mText += "<IMG src=\"" + iconPath + "\">"; | 346 | mText += "<IMG src=\"" + iconPath + "\">"; |
347 | mText += "</a>\n"; | 347 | mText += "</a>\n"; |
348 | } | 348 | } |
349 | mText.append("</li></ul>"); | 349 | mText.append("</li></ul>"); |
350 | 350 | ||
351 | addTag("h3",i18n("Attendees")); | 351 | addTag("h3",i18n("Attendees")); |
352 | Attendee *a; | 352 | Attendee *a; |
353 | mText.append("<ul>"); | 353 | mText.append("<ul>"); |
354 | for(a=attendees.first();a;a=attendees.next()) { | 354 | for(a=attendees.first();a;a=attendees.next()) { |
355 | #if 0 | 355 | #if 0 |
356 | //ndef KORG_NOKABC | 356 | //ndef KORG_NOKABC |
357 | if (a->name().isEmpty()) { | 357 | if (a->name().isEmpty()) { |
358 | addressList = add_book->findByEmail(a->email()); | 358 | addressList = add_book->findByEmail(a->email()); |
359 | KABC::Addressee o = addressList.first(); | 359 | KABC::Addressee o = addressList.first(); |
360 | if (!o.isEmpty() && addressList.size()<2) { | 360 | if (!o.isEmpty() && addressList.size()<2) { |
361 | mText += "<a href=\"uid:" + o.uid() + "\">"; | 361 | mText += "<a href=\"uid:" + o.uid() + "\">"; |
362 | mText += o.formattedName(); | 362 | mText += o.formattedName(); |
363 | mText += "</a>\n"; | 363 | mText += "</a>\n"; |
364 | } else { | 364 | } else { |
365 | mText += "<li>"; | 365 | mText += "<li>"; |
366 | mText.append(a->email()); | 366 | mText.append(a->email()); |
367 | mText += "\n"; | 367 | mText += "\n"; |
368 | } | 368 | } |
369 | } else { | 369 | } else { |
370 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | 370 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; |
371 | if (!a->name().isEmpty()) mText += a->name(); | 371 | if (!a->name().isEmpty()) mText += a->name(); |
372 | else mText += a->email(); | 372 | else mText += a->email(); |
373 | mText += "</a>\n"; | 373 | mText += "</a>\n"; |
374 | } | 374 | } |
375 | #else | 375 | #else |
376 | //qDebug("nokabc "); | 376 | //qDebug("nokabc "); |
377 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; | 377 | mText += "<li><a href=\"uid:" + a->uid() + "\">"; |
378 | if (!a->name().isEmpty()) mText += a->name(); | 378 | if (!a->name().isEmpty()) mText += a->name(); |
379 | else mText += a->email(); | 379 | else mText += a->email(); |
380 | mText += "</a>\n"; | 380 | mText += "</a>\n"; |
381 | #endif | 381 | #endif |
382 | 382 | ||
383 | if (!a->email().isEmpty()) { | 383 | if (!a->email().isEmpty()) { |
384 | if (iconPath) { | 384 | if (iconPath) { |
385 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; | 385 | mText += "<a href=\"mailto:" + a->name() +" "+ "<" + a->email() + ">" + "\">"; |
386 | if ( a->RSVP() ) | 386 | if ( a->RSVP() ) |
387 | mText += "<IMG src=\"" + iconPath + "\">"; | 387 | mText += "<IMG src=\"" + iconPath + "\">"; |
388 | else | 388 | else |
389 | mText += "<IMG src=\"" + NOiconPath + "\">"; | 389 | mText += "<IMG src=\"" + NOiconPath + "\">"; |
390 | mText += "</a>\n"; | 390 | mText += "</a>\n"; |
391 | } | 391 | } |
392 | } | 392 | } |
393 | if (a->status() != Attendee::NeedsAction ) | 393 | if (a->status() != Attendee::NeedsAction ) |
394 | mText +="[" + a->statusStr() + "] "; | 394 | mText +="[" + a->statusStr() + "] "; |
395 | if (a->role() == Attendee::Chair ) | 395 | if (a->role() == Attendee::Chair ) |
396 | mText +="(" + a->roleStr().left(1) + ".)"; | 396 | mText +="(" + a->roleStr().left(1) + ".)"; |
397 | } | 397 | } |
398 | mText.append("</li></ul>"); | 398 | mText.append("</li></ul>"); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | void KIncidenceFormatter::formatReadOnly(Incidence *event) | 402 | void KIncidenceFormatter::formatReadOnly(Incidence *event) |
403 | { | 403 | { |
404 | if (event->isReadOnly()) { | 404 | if (event->isReadOnly()) { |
405 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); | 405 | addTag("p","<em>(" + i18n("read-only") + ")</em>"); |
406 | } | 406 | } |
407 | } | 407 | } |
408 | QString KIncidenceFormatter::deTag(QString text) | 408 | QString KIncidenceFormatter::deTag(QString text) |
409 | { | 409 | { |
410 | #if QT_VERSION >= 0x030000 | 410 | #if QT_VERSION >= 0x030000 |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index 38ba2c7..c97a61e 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -1,580 +1,581 @@ | |||
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 | 20 | ||
21 | #include <kglobal.h> | 21 | #include <kglobal.h> |
22 | #include <kglobalsettings.h> | 22 | #include <kglobalsettings.h> |
23 | #include <klocale.h> | 23 | #include <klocale.h> |
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <qregexp.h> | 25 | #include <qregexp.h> |
26 | #include <qfileinfo.h> | 26 | #include <qfileinfo.h> |
27 | 27 | ||
28 | #include "calendarlocal.h" | 28 | #include "calendarlocal.h" |
29 | #include "icalformat.h" | 29 | #include "icalformat.h" |
30 | #include "todo.h" | 30 | #include "todo.h" |
31 | 31 | ||
32 | using namespace KCal; | 32 | using namespace KCal; |
33 | 33 | ||
34 | Todo::Todo(): QObject(), Incidence() | 34 | Todo::Todo(): QObject(), Incidence() |
35 | { | 35 | { |
36 | // mStatus = TENTATIVE; | 36 | // mStatus = TENTATIVE; |
37 | 37 | ||
38 | mHasDueDate = false; | 38 | mHasDueDate = false; |
39 | setHasStartDate( false ); | 39 | setHasStartDate( false ); |
40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); | 40 | mCompleted = getEvenTime(QDateTime::currentDateTime()); |
41 | mHasCompletedDate = false; | 41 | mHasCompletedDate = false; |
42 | mPercentComplete = 0; | 42 | mPercentComplete = 0; |
43 | mRunning = false; | 43 | mRunning = false; |
44 | mRunSaveTimer = 0; | 44 | mRunSaveTimer = 0; |
45 | } | 45 | } |
46 | 46 | ||
47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) | 47 | Todo::Todo(const Todo &t) : QObject(),Incidence(t) |
48 | { | 48 | { |
49 | mDtDue = t.mDtDue; | 49 | mDtDue = t.mDtDue; |
50 | mHasDueDate = t.mHasDueDate; | 50 | mHasDueDate = t.mHasDueDate; |
51 | mCompleted = t.mCompleted; | 51 | mCompleted = t.mCompleted; |
52 | mHasCompletedDate = t.mHasCompletedDate; | 52 | mHasCompletedDate = t.mHasCompletedDate; |
53 | mPercentComplete = t.mPercentComplete; | 53 | mPercentComplete = t.mPercentComplete; |
54 | mRunning = false; | 54 | mRunning = false; |
55 | mRunSaveTimer = 0; | 55 | mRunSaveTimer = 0; |
56 | } | 56 | } |
57 | 57 | ||
58 | Todo::~Todo() | 58 | Todo::~Todo() |
59 | { | 59 | { |
60 | setRunning( false ); | 60 | setRunning( false ); |
61 | //qDebug("Todo::~Todo() "); | 61 | //qDebug("Todo::~Todo() "); |
62 | } | 62 | } |
63 | 63 | ||
64 | void Todo::setRunningFalse( QString s ) | 64 | void Todo::setRunningFalse( QString s ) |
65 | { | 65 | { |
66 | if ( ! mRunning ) | 66 | if ( ! mRunning ) |
67 | return; | 67 | return; |
68 | mRunning = false; | 68 | mRunning = false; |
69 | mRunSaveTimer->stop(); | 69 | mRunSaveTimer->stop(); |
70 | saveRunningInfoToFile( s ); | 70 | saveRunningInfoToFile( s ); |
71 | } | 71 | } |
72 | void Todo::setRunning( bool run ) | 72 | void Todo::setRunning( bool run ) |
73 | { | 73 | { |
74 | if ( run == mRunning ) | 74 | if ( run == mRunning ) |
75 | return; | 75 | return; |
76 | //qDebug("Todo::setRunning %d ", run); | 76 | //qDebug("Todo::setRunning %d ", run); |
77 | if ( !mRunSaveTimer ) { | 77 | if ( !mRunSaveTimer ) { |
78 | mRunSaveTimer = new QTimer ( this ); | 78 | mRunSaveTimer = new QTimer ( this ); |
79 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); | 79 | connect ( mRunSaveTimer, SIGNAL( timeout() ), this , SLOT ( saveRunningInfoToFile() ) ); |
80 | } | 80 | } |
81 | mRunning = run; | 81 | mRunning = run; |
82 | if ( mRunning ) { | 82 | if ( mRunning ) { |
83 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min | 83 | mRunSaveTimer->start( 1000 * 60 * 5 ); // 5 min |
84 | mRunStart = QDateTime::currentDateTime(); | 84 | mRunStart = QDateTime::currentDateTime(); |
85 | } else { | 85 | } else { |
86 | mRunSaveTimer->stop(); | 86 | mRunSaveTimer->stop(); |
87 | saveRunningInfoToFile(); | 87 | saveRunningInfoToFile(); |
88 | } | 88 | } |
89 | } | 89 | } |
90 | 90 | ||
91 | void Todo::saveRunningInfoToFile( QString comment ) | 91 | void Todo::saveRunningInfoToFile( QString comment ) |
92 | { | 92 | { |
93 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); | 93 | //qDebug("Todo::saveRunningInfoToFile() %s", summary().latin1()); |
94 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { | 94 | if ( mRunStart.secsTo ( QDateTime::currentDateTime() ) < 30 ) { |
95 | qDebug("Running time < 30 seconds. Skipped. "); | 95 | qDebug("Running time < 30 seconds. Skipped. "); |
96 | return; | 96 | return; |
97 | } | 97 | } |
98 | QString dir = KGlobalSettings::timeTrackerDir(); | 98 | QString dir = KGlobalSettings::timeTrackerDir(); |
99 | //qDebug("%s ", dir.latin1()); | 99 | //qDebug("%s ", dir.latin1()); |
100 | QString file = "%1%2%3-%4%5%6-"; | 100 | QString file = "%1%2%3-%4%5%6-"; |
101 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); | 101 | file = file.arg( mRunStart.date().year(), 4).arg( mRunStart.date().month(),2 ).arg( mRunStart.date().day(), 2 ).arg( mRunStart.time().hour(),2 ).arg( mRunStart.time().minute(),2 ).arg( mRunStart.time().second(),2 ); |
102 | file.replace ( QRegExp (" "), "0" ); | 102 | file.replace ( QRegExp (" "), "0" ); |
103 | file += uid(); | 103 | file += uid(); |
104 | //qDebug("File %s ",file.latin1() ); | 104 | //qDebug("File %s ",file.latin1() ); |
105 | CalendarLocal cal; | 105 | CalendarLocal cal; |
106 | cal.setLocalTime(); | 106 | cal.setLocalTime(); |
107 | Todo * to = (Todo*) clone(); | 107 | Todo * to = (Todo*) clone(); |
108 | to->setFloats( false ); | 108 | to->setFloats( false ); |
109 | to->setDtStart( mRunStart ); | 109 | to->setDtStart( mRunStart ); |
110 | to->setHasStartDate( true ); | 110 | to->setHasStartDate( true ); |
111 | to->setDtDue( QDateTime::currentDateTime() ); | 111 | to->setDtDue( QDateTime::currentDateTime() ); |
112 | to->setHasDueDate( true ); | 112 | to->setHasDueDate( true ); |
113 | to->setUid( file ); | 113 | to->setUid( file ); |
114 | if ( !comment.isEmpty() ) { | 114 | if ( !comment.isEmpty() ) { |
115 | QString des = to->description(); | 115 | QString des = to->description(); |
116 | if ( des.isEmpty () ) | 116 | if ( des.isEmpty () ) |
117 | to->setDescription( "TT-Note: " + comment ); | 117 | to->setDescription( "TT-Note: " + comment ); |
118 | else | 118 | else |
119 | to->setDescription( "TT-Note: " + comment +"\n" + des ); | 119 | to->setDescription( "TT-Note: " + comment +"\n" + des ); |
120 | } | 120 | } |
121 | cal.addIncidence( to ); | 121 | cal.addIncidence( to ); |
122 | ICalFormat format; | 122 | ICalFormat format; |
123 | file = dir +"/" +file +".ics"; | 123 | file = dir +"/" +file +".ics"; |
124 | format.save( &cal, file ); | 124 | format.save( &cal, file ); |
125 | saveParents(); | 125 | saveParents(); |
126 | 126 | ||
127 | } | 127 | } |
128 | void Todo::saveParents() | 128 | void Todo::saveParents() |
129 | { | 129 | { |
130 | if (!relatedTo() ) | 130 | if (!relatedTo() ) |
131 | return; | 131 | return; |
132 | Incidence * inc = relatedTo(); | 132 | Incidence * inc = relatedTo(); |
133 | if ( inc->type() != "Todo" ) | 133 | if ( inc->typeID() != todoID ) |
134 | return; | 134 | return; |
135 | Todo* to = (Todo*)inc; | 135 | Todo* to = (Todo*)inc; |
136 | bool saveTodo = false; | 136 | bool saveTodo = false; |
137 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; | 137 | QString file = KGlobalSettings::timeTrackerDir() + "/"+ to->uid() + ".ics"; |
138 | QFileInfo fi ( file ); | 138 | QFileInfo fi ( file ); |
139 | if ( fi.exists() ) { | 139 | if ( fi.exists() ) { |
140 | if ( fi.lastModified () < to->lastModified ()) | 140 | if ( fi.lastModified () < to->lastModified ()) |
141 | saveTodo = true; | 141 | saveTodo = true; |
142 | } else { | 142 | } else { |
143 | saveTodo = true; | 143 | saveTodo = true; |
144 | } | 144 | } |
145 | if ( saveTodo ) { | 145 | if ( saveTodo ) { |
146 | CalendarLocal cal; | 146 | CalendarLocal cal; |
147 | cal.setLocalTime(); | 147 | cal.setLocalTime(); |
148 | Todo * par = (Todo *) to->clone(); | 148 | Todo * par = (Todo *) to->clone(); |
149 | cal.addIncidence( par ); | 149 | cal.addIncidence( par ); |
150 | ICalFormat format; | 150 | ICalFormat format; |
151 | format.save( &cal, file ); | 151 | format.save( &cal, file ); |
152 | } | 152 | } |
153 | to->saveParents(); | 153 | to->saveParents(); |
154 | } | 154 | } |
155 | 155 | ||
156 | int Todo::runTime() | 156 | int Todo::runTime() |
157 | { | 157 | { |
158 | if ( !mRunning ) | 158 | if ( !mRunning ) |
159 | return 0; | 159 | return 0; |
160 | return mRunStart.secsTo( QDateTime::currentDateTime() ); | 160 | return mRunStart.secsTo( QDateTime::currentDateTime() ); |
161 | } | 161 | } |
162 | bool Todo::hasRunningSub() | 162 | bool Todo::hasRunningSub() |
163 | { | 163 | { |
164 | if ( mRunning ) | 164 | if ( mRunning ) |
165 | return true; | 165 | return true; |
166 | Incidence *aTodo; | 166 | Incidence *aTodo; |
167 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 167 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
168 | if ( ((Todo*)aTodo)->hasRunningSub() ) | 168 | if ( ((Todo*)aTodo)->hasRunningSub() ) |
169 | return true; | 169 | return true; |
170 | } | 170 | } |
171 | return false; | 171 | return false; |
172 | } | 172 | } |
173 | Incidence *Todo::clone() | 173 | Incidence *Todo::clone() |
174 | { | 174 | { |
175 | return new Todo(*this); | 175 | return new Todo(*this); |
176 | } | 176 | } |
177 | 177 | ||
178 | bool Todo::contains ( Todo* from ) | 178 | bool Todo::contains ( Todo* from ) |
179 | { | 179 | { |
180 | 180 | ||
181 | if ( !from->summary().isEmpty() ) | 181 | if ( !from->summary().isEmpty() ) |
182 | if ( !summary().startsWith( from->summary() )) | 182 | if ( !summary().startsWith( from->summary() )) |
183 | return false; | 183 | return false; |
184 | if ( from->hasStartDate() ) { | 184 | if ( from->hasStartDate() ) { |
185 | if ( !hasStartDate() ) | 185 | if ( !hasStartDate() ) |
186 | return false; | 186 | return false; |
187 | if ( from->dtStart() != dtStart()) | 187 | if ( from->dtStart() != dtStart()) |
188 | return false; | 188 | return false; |
189 | } | 189 | } |
190 | if ( from->hasDueDate() ){ | 190 | if ( from->hasDueDate() ){ |
191 | if ( !hasDueDate() ) | 191 | if ( !hasDueDate() ) |
192 | return false; | 192 | return false; |
193 | if ( from->dtDue() != dtDue()) | 193 | if ( from->dtDue() != dtDue()) |
194 | return false; | 194 | return false; |
195 | } | 195 | } |
196 | if ( !from->location().isEmpty() ) | 196 | if ( !from->location().isEmpty() ) |
197 | if ( !location().startsWith( from->location() ) ) | 197 | if ( !location().startsWith( from->location() ) ) |
198 | return false; | 198 | return false; |
199 | if ( !from->description().isEmpty() ) | 199 | if ( !from->description().isEmpty() ) |
200 | if ( !description().startsWith( from->description() )) | 200 | if ( !description().startsWith( from->description() )) |
201 | return false; | 201 | return false; |
202 | if ( from->alarms().count() ) { | 202 | if ( from->alarms().count() ) { |
203 | Alarm *a = from->alarms().first(); | 203 | Alarm *a = from->alarms().first(); |
204 | if ( a->enabled() ){ | 204 | if ( a->enabled() ){ |
205 | if ( !alarms().count() ) | 205 | if ( !alarms().count() ) |
206 | return false; | 206 | return false; |
207 | Alarm *b = alarms().first(); | 207 | Alarm *b = alarms().first(); |
208 | if( ! b->enabled() ) | 208 | if( ! b->enabled() ) |
209 | return false; | 209 | return false; |
210 | if ( ! (a->offset() == b->offset() )) | 210 | if ( ! (a->offset() == b->offset() )) |
211 | return false; | 211 | return false; |
212 | } | 212 | } |
213 | } | 213 | } |
214 | 214 | ||
215 | QStringList cat = categories(); | 215 | QStringList cat = categories(); |
216 | QStringList catFrom = from->categories(); | 216 | QStringList catFrom = from->categories(); |
217 | QString nCat; | 217 | QString nCat; |
218 | unsigned int iii; | 218 | unsigned int iii; |
219 | for ( iii = 0; iii < catFrom.count();++iii ) { | 219 | for ( iii = 0; iii < catFrom.count();++iii ) { |
220 | nCat = catFrom[iii]; | 220 | nCat = catFrom[iii]; |
221 | if ( !nCat.isEmpty() ) | 221 | if ( !nCat.isEmpty() ) |
222 | if ( !cat.contains( nCat )) { | 222 | if ( !cat.contains( nCat )) { |
223 | return false; | 223 | return false; |
224 | } | 224 | } |
225 | } | 225 | } |
226 | if ( from->isCompleted() ) { | 226 | if ( from->isCompleted() ) { |
227 | if ( !isCompleted() ) | 227 | if ( !isCompleted() ) |
228 | return false; | 228 | return false; |
229 | } | 229 | } |
230 | if( priority() != from->priority() ) | 230 | if( priority() != from->priority() ) |
231 | return false; | 231 | return false; |
232 | 232 | ||
233 | 233 | ||
234 | return true; | 234 | return true; |
235 | 235 | ||
236 | } | 236 | } |
237 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) | 237 | bool KCal::operator==( const Todo& t1, const Todo& t2 ) |
238 | { | 238 | { |
239 | 239 | ||
240 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); | 240 | bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 ); |
241 | if ( ! ret ) | 241 | if ( ! ret ) |
242 | return false; | 242 | return false; |
243 | if ( t1.hasDueDate() == t2.hasDueDate() ) { | 243 | if ( t1.hasDueDate() == t2.hasDueDate() ) { |
244 | if ( t1.hasDueDate() ) { | 244 | if ( t1.hasDueDate() ) { |
245 | if ( t1.doesFloat() == t2.doesFloat() ) { | 245 | if ( t1.doesFloat() == t2.doesFloat() ) { |
246 | if ( t1.doesFloat() ) { | 246 | if ( t1.doesFloat() ) { |
247 | if ( t1.dtDue().date() != t2.dtDue().date() ) | 247 | if ( t1.dtDue().date() != t2.dtDue().date() ) |
248 | return false; | 248 | return false; |
249 | } else | 249 | } else |
250 | if ( t1.dtDue() != t2.dtDue() ) | 250 | if ( t1.dtDue() != t2.dtDue() ) |
251 | return false; | 251 | return false; |
252 | } else | 252 | } else |
253 | return false;// float != | 253 | return false;// float != |
254 | } | 254 | } |
255 | 255 | ||
256 | } else | 256 | } else |
257 | return false; | 257 | return false; |
258 | if ( t1.percentComplete() != t2.percentComplete() ) | 258 | if ( t1.percentComplete() != t2.percentComplete() ) |
259 | return false; | 259 | return false; |
260 | if ( t1.isCompleted() ) { | 260 | if ( t1.isCompleted() ) { |
261 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { | 261 | if ( t1.hasCompletedDate() == t2.hasCompletedDate() ) { |
262 | if ( t1.hasCompletedDate() ) { | 262 | if ( t1.hasCompletedDate() ) { |
263 | if ( t1.completed() != t2.completed() ) | 263 | if ( t1.completed() != t2.completed() ) |
264 | return false; | 264 | return false; |
265 | } | 265 | } |
266 | 266 | ||
267 | } else | 267 | } else |
268 | return false; | 268 | return false; |
269 | } | 269 | } |
270 | return true; | 270 | return true; |
271 | 271 | ||
272 | } | 272 | } |
273 | 273 | ||
274 | void Todo::setDtDue(const QDateTime &dtDue) | 274 | void Todo::setDtDue(const QDateTime &dtDue) |
275 | { | 275 | { |
276 | //int diffsecs = mDtDue.secsTo(dtDue); | 276 | //int diffsecs = mDtDue.secsTo(dtDue); |
277 | 277 | ||
278 | /*if (mReadOnly) return; | 278 | /*if (mReadOnly) return; |
279 | const QPtrList<Alarm>& alarms = alarms(); | 279 | const QPtrList<Alarm>& alarms = alarms(); |
280 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { | 280 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) { |
281 | if (alarm->enabled()) { | 281 | if (alarm->enabled()) { |
282 | alarm->setTime(alarm->time().addSecs(diffsecs)); | 282 | alarm->setTime(alarm->time().addSecs(diffsecs)); |
283 | } | 283 | } |
284 | }*/ | 284 | }*/ |
285 | mDtDue = getEvenTime(dtDue); | 285 | mDtDue = getEvenTime(dtDue); |
286 | 286 | ||
287 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; | 287 | //kdDebug(5800) << "setDtDue says date is " << mDtDue.toString() << endl; |
288 | 288 | ||
289 | /*const QPtrList<Alarm>& alarms = alarms(); | 289 | /*const QPtrList<Alarm>& alarms = alarms(); |
290 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) | 290 | for (Alarm* alarm = alarms.first(); alarm; alarm = alarms.next()) |
291 | alarm->setAlarmStart(mDtDue);*/ | 291 | alarm->setAlarmStart(mDtDue);*/ |
292 | updated(); | 292 | updated(); |
293 | } | 293 | } |
294 | 294 | ||
295 | QDateTime Todo::dtDue() const | 295 | QDateTime Todo::dtDue() const |
296 | { | 296 | { |
297 | return mDtDue; | 297 | return mDtDue; |
298 | } | 298 | } |
299 | 299 | ||
300 | QString Todo::dtDueTimeStr() const | 300 | QString Todo::dtDueTimeStr() const |
301 | { | 301 | { |
302 | return KGlobal::locale()->formatTime(mDtDue.time()); | 302 | return KGlobal::locale()->formatTime(mDtDue.time()); |
303 | } | 303 | } |
304 | 304 | ||
305 | QString Todo::dtDueDateStr(bool shortfmt) const | 305 | QString Todo::dtDueDateStr(bool shortfmt) const |
306 | { | 306 | { |
307 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 307 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
308 | } | 308 | } |
309 | 309 | ||
310 | QString Todo::dtDueStr(bool shortfmt) const | 310 | QString Todo::dtDueStr(bool shortfmt) const |
311 | { | 311 | { |
312 | if ( doesFloat() ) | 312 | if ( doesFloat() ) |
313 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); | 313 | return KGlobal::locale()->formatDate(mDtDue.date(),shortfmt); |
314 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); | 314 | return KGlobal::locale()->formatDateTime(mDtDue, shortfmt); |
315 | } | 315 | } |
316 | // retval 0 : no found | 316 | // retval 0 : no found |
317 | // 1 : due for date found | 317 | // 1 : due for date found |
318 | // 2 : overdue for date found | 318 | // 2 : overdue for date found |
319 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) | 319 | int Todo::hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ) |
320 | { | 320 | { |
321 | int retval = 0; | 321 | int retval = 0; |
322 | if ( isCompleted() ) | 322 | if ( isCompleted() ) |
323 | return 0; | 323 | return 0; |
324 | if ( hasDueDate() ) { | 324 | if ( hasDueDate() ) { |
325 | if ( dtDue().date() < date ) | 325 | if ( dtDue().date() < date ) |
326 | return 2; | 326 | return 2; |
327 | // we do not return, because we may find an overdue sub todo | 327 | // we do not return, because we may find an overdue sub todo |
328 | if ( dtDue().date() == date ) | 328 | if ( dtDue().date() == date ) |
329 | retval = 1; | 329 | retval = 1; |
330 | } | 330 | } |
331 | if ( checkSubtodos ) { | 331 | if ( checkSubtodos ) { |
332 | Incidence *aTodo; | 332 | Incidence *aTodo; |
333 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { | 333 | for (aTodo = mRelations.first(); aTodo; aTodo = mRelations.next()) { |
334 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); | 334 | int ret = ((Todo*)aTodo)->hasDueSubTodoForDate( date ,checkSubtodos ); |
335 | if ( ret == 2 ) | 335 | if ( ret == 2 ) |
336 | return 2; | 336 | return 2; |
337 | if ( ret == 1) | 337 | if ( ret == 1) |
338 | retval = 1; | 338 | retval = 1; |
339 | } | 339 | } |
340 | } | 340 | } |
341 | return retval; | 341 | return retval; |
342 | } | 342 | } |
343 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true | 343 | int Todo::hasDueSubTodo( bool checkSubtodos ) //= true |
344 | { | 344 | { |
345 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); | 345 | return hasDueSubTodoForDate(QDate::currentDate(), checkSubtodos ); |
346 | } | 346 | } |
347 | bool Todo::hasDueDate() const | 347 | bool Todo::hasDueDate() const |
348 | { | 348 | { |
349 | return mHasDueDate; | 349 | return mHasDueDate; |
350 | } | 350 | } |
351 | 351 | ||
352 | void Todo::setHasDueDate(bool f) | 352 | void Todo::setHasDueDate(bool f) |
353 | { | 353 | { |
354 | if (mReadOnly) return; | 354 | if (mReadOnly) return; |
355 | mHasDueDate = f; | 355 | mHasDueDate = f; |
356 | updated(); | 356 | updated(); |
357 | } | 357 | } |
358 | 358 | ||
359 | 359 | ||
360 | #if 0 | 360 | #if 0 |
361 | void Todo::setStatus(const QString &statStr) | 361 | void Todo::setStatus(const QString &statStr) |
362 | { | 362 | { |
363 | if (mReadOnly) return; | 363 | if (mReadOnly) return; |
364 | QString ss(statStr.upper()); | 364 | QString ss(statStr.upper()); |
365 | 365 | ||
366 | if (ss == "X-ACTION") | 366 | if (ss == "X-ACTION") |
367 | mStatus = NEEDS_ACTION; | 367 | mStatus = NEEDS_ACTION; |
368 | else if (ss == "NEEDS ACTION") | 368 | else if (ss == "NEEDS ACTION") |
369 | mStatus = NEEDS_ACTION; | 369 | mStatus = NEEDS_ACTION; |
370 | else if (ss == "ACCEPTED") | 370 | else if (ss == "ACCEPTED") |
371 | mStatus = ACCEPTED; | 371 | mStatus = ACCEPTED; |
372 | else if (ss == "SENT") | 372 | else if (ss == "SENT") |
373 | mStatus = SENT; | 373 | mStatus = SENT; |
374 | else if (ss == "TENTATIVE") | 374 | else if (ss == "TENTATIVE") |
375 | mStatus = TENTATIVE; | 375 | mStatus = TENTATIVE; |
376 | else if (ss == "CONFIRMED") | 376 | else if (ss == "CONFIRMED") |
377 | mStatus = CONFIRMED; | 377 | mStatus = CONFIRMED; |
378 | else if (ss == "DECLINED") | 378 | else if (ss == "DECLINED") |
379 | mStatus = DECLINED; | 379 | mStatus = DECLINED; |
380 | else if (ss == "COMPLETED") | 380 | else if (ss == "COMPLETED") |
381 | mStatus = COMPLETED; | 381 | mStatus = COMPLETED; |
382 | else if (ss == "DELEGATED") | 382 | else if (ss == "DELEGATED") |
383 | mStatus = DELEGATED; | 383 | mStatus = DELEGATED; |
384 | 384 | ||
385 | updated(); | 385 | updated(); |
386 | } | 386 | } |
387 | 387 | ||
388 | void Todo::setStatus(int status) | 388 | void Todo::setStatus(int status) |
389 | { | 389 | { |
390 | if (mReadOnly) return; | 390 | if (mReadOnly) return; |
391 | mStatus = status; | 391 | mStatus = status; |
392 | updated(); | 392 | updated(); |
393 | } | 393 | } |
394 | 394 | ||
395 | int Todo::status() const | 395 | int Todo::status() const |
396 | { | 396 | { |
397 | return mStatus; | 397 | return mStatus; |
398 | } | 398 | } |
399 | 399 | ||
400 | QString Todo::statusStr() const | 400 | QString Todo::statusStr() const |
401 | { | 401 | { |
402 | switch(mStatus) { | 402 | switch(mStatus) { |
403 | case NEEDS_ACTION: | 403 | case NEEDS_ACTION: |
404 | return QString("NEEDS ACTION"); | 404 | return QString("NEEDS ACTION"); |
405 | break; | 405 | break; |
406 | case ACCEPTED: | 406 | case ACCEPTED: |
407 | return QString("ACCEPTED"); | 407 | return QString("ACCEPTED"); |
408 | break; | 408 | break; |
409 | case SENT: | 409 | case SENT: |
410 | return QString("SENT"); | 410 | return QString("SENT"); |
411 | break; | 411 | break; |
412 | case TENTATIVE: | 412 | case TENTATIVE: |
413 | return QString("TENTATIVE"); | 413 | return QString("TENTATIVE"); |
414 | break; | 414 | break; |
415 | case CONFIRMED: | 415 | case CONFIRMED: |
416 | return QString("CONFIRMED"); | 416 | return QString("CONFIRMED"); |
417 | break; | 417 | break; |
418 | case DECLINED: | 418 | case DECLINED: |
419 | return QString("DECLINED"); | 419 | return QString("DECLINED"); |
420 | break; | 420 | break; |
421 | case COMPLETED: | 421 | case COMPLETED: |
422 | return QString("COMPLETED"); | 422 | return QString("COMPLETED"); |
423 | break; | 423 | break; |
424 | case DELEGATED: | 424 | case DELEGATED: |
425 | return QString("DELEGATED"); | 425 | return QString("DELEGATED"); |
426 | break; | 426 | break; |
427 | } | 427 | } |
428 | return QString(""); | 428 | return QString(""); |
429 | } | 429 | } |
430 | #endif | 430 | #endif |
431 | 431 | ||
432 | bool Todo::isCompleted() const | 432 | bool Todo::isCompleted() const |
433 | { | 433 | { |
434 | if (mPercentComplete == 100) { | 434 | if (mPercentComplete == 100) { |
435 | return true; | 435 | return true; |
436 | } | 436 | } |
437 | else return false; | 437 | else return false; |
438 | } | 438 | } |
439 | 439 | ||
440 | void Todo::setCompleted(bool completed) | 440 | void Todo::setCompleted(bool completed) |
441 | { | 441 | { |
442 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { | 442 | if ( mHasRecurrenceID && completed && mPercentComplete != 100 ) { |
443 | if ( !setRecurDates() ) | 443 | if ( !setRecurDates() ) |
444 | completed = false; | 444 | completed = false; |
445 | } | 445 | } |
446 | if (completed) mPercentComplete = 100; | 446 | if (completed) mPercentComplete = 100; |
447 | else { | 447 | else { |
448 | mPercentComplete = 0; | 448 | mPercentComplete = 0; |
449 | mHasCompletedDate = false; | 449 | mHasCompletedDate = false; |
450 | } | 450 | } |
451 | updated(); | 451 | updated(); |
452 | } | 452 | } |
453 | 453 | ||
454 | QDateTime Todo::completed() const | 454 | QDateTime Todo::completed() const |
455 | { | 455 | { |
456 | return mCompleted; | 456 | return mCompleted; |
457 | } | 457 | } |
458 | 458 | ||
459 | QString Todo::completedStr( bool shortF ) const | 459 | QString Todo::completedStr( bool shortF ) const |
460 | { | 460 | { |
461 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); | 461 | return KGlobal::locale()->formatDateTime(mCompleted, shortF); |
462 | } | 462 | } |
463 | 463 | ||
464 | void Todo::setCompleted(const QDateTime &completed) | 464 | void Todo::setCompleted(const QDateTime &completed) |
465 | { | 465 | { |
466 | //qDebug("Todo::setCompleted "); | 466 | //qDebug("Todo::setCompleted "); |
467 | if ( mHasCompletedDate ) { | 467 | if ( mHasCompletedDate ) { |
468 | // qDebug("has completed data - return "); | 468 | // qDebug("has completed data - return "); |
469 | return; | 469 | return; |
470 | } | 470 | } |
471 | mHasCompletedDate = true; | 471 | mHasCompletedDate = true; |
472 | mPercentComplete = 100; | 472 | mPercentComplete = 100; |
473 | mCompleted = getEvenTime(completed); | 473 | mCompleted = getEvenTime(completed); |
474 | updated(); | 474 | updated(); |
475 | } | 475 | } |
476 | 476 | ||
477 | bool Todo::hasCompletedDate() const | 477 | bool Todo::hasCompletedDate() const |
478 | { | 478 | { |
479 | return mHasCompletedDate; | 479 | return mHasCompletedDate; |
480 | } | 480 | } |
481 | 481 | ||
482 | int Todo::percentComplete() const | 482 | int Todo::percentComplete() const |
483 | { | 483 | { |
484 | return mPercentComplete; | 484 | return mPercentComplete; |
485 | } | 485 | } |
486 | bool Todo::setRecurDates() | 486 | bool Todo::setRecurDates() |
487 | { | 487 | { |
488 | if ( !mHasRecurrenceID ) | 488 | if ( !mHasRecurrenceID ) |
489 | return true; | 489 | return true; |
490 | int secs = mDtStart.secsTo( dtDue() ); | 490 | int secs = mDtStart.secsTo( dtDue() ); |
491 | bool ok; | 491 | bool ok; |
492 | qDebug("T:setRecurDates() "); | 492 | qDebug("T:setRecurDates() "); |
493 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 493 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
494 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); | 494 | QDateTime next = getNextOccurence( mRecurrenceID, &ok ); |
495 | if ( ok ) { | 495 | if ( ok ) { |
496 | mRecurrenceID = next; | 496 | mRecurrenceID = next; |
497 | mDtStart = next; | 497 | mDtStart = next; |
498 | setDtDue( next.addSecs( secs ) ); | 498 | setDtDue( next.addSecs( secs ) ); |
499 | if ( QDateTime::currentDateTime() > next) | 499 | if ( QDateTime::currentDateTime() > next) |
500 | return false; | 500 | return false; |
501 | } else { | 501 | } else { |
502 | setHasRecurrenceID( false ); | 502 | setHasRecurrenceID( false ); |
503 | recurrence()->unsetRecurs(); | 503 | recurrence()->unsetRecurs(); |
504 | } | 504 | } |
505 | return true; | 505 | return true; |
506 | } | 506 | } |
507 | void Todo::setPercentComplete(int v) | 507 | void Todo::setPercentComplete(int v) |
508 | { | 508 | { |
509 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { | 509 | if ( mHasRecurrenceID && v == 100 && mPercentComplete != 100 ) { |
510 | if ( !setRecurDates() ) | 510 | if ( !setRecurDates() ) |
511 | v = 0; | 511 | v = 0; |
512 | } | 512 | } |
513 | mPercentComplete = v; | 513 | mPercentComplete = v; |
514 | if ( v != 100 ) | 514 | if ( v != 100 ) |
515 | mHasCompletedDate = false; | 515 | mHasCompletedDate = false; |
516 | updated(); | 516 | updated(); |
517 | } | 517 | } |
518 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 518 | QDateTime Todo::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
519 | { | 519 | { |
520 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { | 520 | if ( isCompleted() || ! hasDueDate() || cancelled() ) { |
521 | *ok = false; | 521 | *ok = false; |
522 | return QDateTime (); | 522 | return QDateTime (); |
523 | } | 523 | } |
524 | QDateTime incidenceStart; | 524 | QDateTime incidenceStart; |
525 | incidenceStart = dtDue(); | 525 | incidenceStart = dtDue(); |
526 | bool enabled = false; | 526 | bool enabled = false; |
527 | Alarm* alarm; | 527 | Alarm* alarm; |
528 | int off = 0; | 528 | int off = 0; |
529 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 529 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
530 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 530 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
531 | // *ok = false; | 531 | // *ok = false; |
532 | // return incidenceStart; | 532 | // return incidenceStart; |
533 | // } | 533 | // } |
534 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 534 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
535 | if (alarm->enabled()) { | 535 | if (alarm->enabled()) { |
536 | if ( alarm->hasTime () ) { | 536 | if ( alarm->hasTime () ) { |
537 | if ( alarm->time() < alarmStart ) { | 537 | if ( alarm->time() < alarmStart ) { |
538 | alarmStart = alarm->time(); | 538 | alarmStart = alarm->time(); |
539 | enabled = true; | 539 | enabled = true; |
540 | off = alarmStart.secsTo( incidenceStart ); | 540 | off = alarmStart.secsTo( incidenceStart ); |
541 | } | 541 | } |
542 | 542 | ||
543 | } else { | 543 | } else { |
544 | int secs = alarm->startOffset().asSeconds(); | 544 | int secs = alarm->startOffset().asSeconds(); |
545 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 545 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
546 | alarmStart = incidenceStart.addSecs( secs ); | 546 | alarmStart = incidenceStart.addSecs( secs ); |
547 | enabled = true; | 547 | enabled = true; |
548 | off = -secs; | 548 | off = -secs; |
549 | } | 549 | } |
550 | } | 550 | } |
551 | } | 551 | } |
552 | } | 552 | } |
553 | if ( enabled ) { | 553 | if ( enabled ) { |
554 | if ( alarmStart > start_dt ) { | 554 | if ( alarmStart > start_dt ) { |
555 | *ok = true; | 555 | *ok = true; |
556 | * offset = off; | 556 | * offset = off; |
557 | return alarmStart; | 557 | return alarmStart; |
558 | } | 558 | } |
559 | } | 559 | } |
560 | *ok = false; | 560 | *ok = false; |
561 | return QDateTime (); | 561 | return QDateTime (); |
562 | 562 | ||
563 | } | 563 | } |
564 | 564 | ||
565 | void Todo::checkSetCompletedFalse() | 565 | void Todo::checkSetCompletedFalse() |
566 | { | 566 | { |
567 | if ( !hasRecurrenceID() ) { | 567 | if ( !mHasRecurrenceID ) { |
568 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 568 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
569 | return; | ||
569 | } | 570 | } |
570 | // qDebug("Todo::checkSetCompletedFalse()"); | 571 | // qDebug("Todo::checkSetCompletedFalse()"); |
571 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 572 | //qDebug("%s %s %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
572 | if ( mPercentComplete == 100 ) { | 573 | if ( mPercentComplete == 100 ) { |
573 | QDateTime dt = QDateTime::currentDateTime(); | 574 | QDateTime dt = QDateTime::currentDateTime(); |
574 | if ( dt > mDtStart && dt > mRecurrenceID ) { | 575 | if ( dt > mDtStart && dt > mRecurrenceID ) { |
575 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); | 576 | qDebug("start: %s --due: %s --recID: %s ",mDtStart.toString().latin1(), dtDue().toString().latin1(),mRecurrenceID.toString().latin1() ); |
576 | setCompleted( false ); | 577 | setCompleted( false ); |
577 | qDebug("Todo::checkSetCompletedFalse "); | 578 | qDebug("Todo::checkSetCompletedFalse "); |
578 | } | 579 | } |
579 | } | 580 | } |
580 | } | 581 | } |
diff --git a/libkcal/todo.h b/libkcal/todo.h index ab8fdf1..501c2ba 100644 --- a/libkcal/todo.h +++ b/libkcal/todo.h | |||
@@ -1,150 +1,151 @@ | |||
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 TODO_H | 20 | #ifndef TODO_H |
21 | #define TODO_H | 21 | #define TODO_H |
22 | // | 22 | // |
23 | // Todo component, representing a VTODO object | 23 | // Todo component, representing a VTODO object |
24 | // | 24 | // |
25 | 25 | ||
26 | #include "incidence.h" | 26 | #include "incidence.h" |
27 | 27 | ||
28 | #include <qtimer.h> | 28 | #include <qtimer.h> |
29 | 29 | ||
30 | namespace KCal { | 30 | namespace KCal { |
31 | 31 | ||
32 | /** | 32 | /** |
33 | This class provides a Todo in the sense of RFC2445. | 33 | This class provides a Todo in the sense of RFC2445. |
34 | */ | 34 | */ |
35 | class Todo : public QObject,public Incidence | 35 | class Todo : public QObject,public Incidence |
36 | { | 36 | { |
37 | Q_OBJECT | 37 | Q_OBJECT |
38 | public: | 38 | public: |
39 | Todo(); | 39 | Todo(); |
40 | Todo(const Todo &); | 40 | Todo(const Todo &); |
41 | ~Todo(); | 41 | ~Todo(); |
42 | typedef ListBase<Todo> List; | 42 | typedef ListBase<Todo> List; |
43 | QCString type() const { return "Todo"; } | 43 | QCString type() const { return "Todo"; } |
44 | IncTypeID typeID() const { return todoID; } | ||
44 | 45 | ||
45 | /** Return an exact copy of this todo. */ | 46 | /** Return an exact copy of this todo. */ |
46 | Incidence *clone(); | 47 | Incidence *clone(); |
47 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; | 48 | QDateTime getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const; |
48 | 49 | ||
49 | /** for setting the todo's due date/time with a QDateTime. */ | 50 | /** for setting the todo's due date/time with a QDateTime. */ |
50 | void setDtDue(const QDateTime &dtDue); | 51 | void setDtDue(const QDateTime &dtDue); |
51 | /** returns an event's Due date/time as a QDateTime. */ | 52 | /** returns an event's Due date/time as a QDateTime. */ |
52 | QDateTime dtDue() const; | 53 | QDateTime dtDue() const; |
53 | /** returns an event's due time as a string formatted according to the | 54 | /** returns an event's due time as a string formatted according to the |
54 | users locale settings */ | 55 | users locale settings */ |
55 | QString dtDueTimeStr() const; | 56 | QString dtDueTimeStr() const; |
56 | /** returns an event's due date as a string formatted according to the | 57 | /** returns an event's due date as a string formatted according to the |
57 | users locale settings */ | 58 | users locale settings */ |
58 | QString dtDueDateStr(bool shortfmt=true) const; | 59 | QString dtDueDateStr(bool shortfmt=true) const; |
59 | /** returns an event's due date and time as a string formatted according | 60 | /** returns an event's due date and time as a string formatted according |
60 | to the users locale settings */ | 61 | to the users locale settings */ |
61 | QString dtDueStr(bool shortfmt=true) const; | 62 | QString dtDueStr(bool shortfmt=true) const; |
62 | 63 | ||
63 | /** returns TRUE or FALSE depending on whether the todo has a due date */ | 64 | /** returns TRUE or FALSE depending on whether the todo has a due date */ |
64 | bool hasDueDate() const; | 65 | bool hasDueDate() const; |
65 | /** sets the event's hasDueDate value. */ | 66 | /** sets the event's hasDueDate value. */ |
66 | void setHasDueDate(bool f); | 67 | void setHasDueDate(bool f); |
67 | 68 | ||
68 | /* | 69 | /* |
69 | Looks for a subtodo (including itself ) which is not complete and is | 70 | Looks for a subtodo (including itself ) which is not complete and is |
70 | - overdue, or | 71 | - overdue, or |
71 | - due today. | 72 | - due today. |
72 | It returns 0 for nothing found, | 73 | It returns 0 for nothing found, |
73 | 1 for found a todo which is due today and no overdue found | 74 | 1 for found a todo which is due today and no overdue found |
74 | 2 for found a overdue todo | 75 | 2 for found a overdue todo |
75 | */ | 76 | */ |
76 | int hasDueSubTodo( bool checkSubtodos = true ); | 77 | int hasDueSubTodo( bool checkSubtodos = true ); |
77 | /* same as above, but a specific date can be specified*/ | 78 | /* same as above, but a specific date can be specified*/ |
78 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); | 79 | int hasDueSubTodoForDate( const QDate & date, bool checkSubtodos ); |
79 | 80 | ||
80 | 81 | ||
81 | /** sets the event's status to the string specified. The string | 82 | /** sets the event's status to the string specified. The string |
82 | * must be a recognized value for the status field, i.e. a string | 83 | * must be a recognized value for the status field, i.e. a string |
83 | * equivalent of the possible status enumerations previously described. */ | 84 | * equivalent of the possible status enumerations previously described. */ |
84 | // void setStatus(const QString &statStr); | 85 | // void setStatus(const QString &statStr); |
85 | /** sets the event's status to the value specified. See the enumeration | 86 | /** sets the event's status to the value specified. See the enumeration |
86 | * above for possible values. */ | 87 | * above for possible values. */ |
87 | // void setStatus(int); | 88 | // void setStatus(int); |
88 | /** return the event's status. */ | 89 | /** return the event's status. */ |
89 | // int status() const; | 90 | // int status() const; |
90 | /** return the event's status in string format. */ | 91 | /** return the event's status in string format. */ |
91 | // QString statusStr() const; | 92 | // QString statusStr() const; |
92 | 93 | ||
93 | /** return, if this todo is completed */ | 94 | /** return, if this todo is completed */ |
94 | bool isCompleted() const; | 95 | bool isCompleted() const; |
95 | /** set completed state of this todo */ | 96 | /** set completed state of this todo */ |
96 | void setCompleted(bool); | 97 | void setCompleted(bool); |
97 | 98 | ||
98 | /** | 99 | /** |
99 | Return how many percent of the task are completed. Returns a value | 100 | Return how many percent of the task are completed. Returns a value |
100 | between 0 and 100. | 101 | between 0 and 100. |
101 | */ | 102 | */ |
102 | int percentComplete() const; | 103 | int percentComplete() const; |
103 | /** | 104 | /** |
104 | Set how many percent of the task are completed. Valid values are in the | 105 | Set how many percent of the task are completed. Valid values are in the |
105 | range from 0 to 100. | 106 | range from 0 to 100. |
106 | */ | 107 | */ |
107 | void setPercentComplete(int); | 108 | void setPercentComplete(int); |
108 | 109 | ||
109 | /** return date and time when todo was completed */ | 110 | /** return date and time when todo was completed */ |
110 | QDateTime completed() const; | 111 | QDateTime completed() const; |
111 | QString completedStr(bool shortF = true) const; | 112 | QString completedStr(bool shortF = true) const; |
112 | /** set date and time of completion */ | 113 | /** set date and time of completion */ |
113 | void setCompleted(const QDateTime &completed); | 114 | void setCompleted(const QDateTime &completed); |
114 | 115 | ||
115 | /** Return true, if todo has a date associated with completion */ | 116 | /** Return true, if todo has a date associated with completion */ |
116 | bool hasCompletedDate() const; | 117 | bool hasCompletedDate() const; |
117 | bool contains ( Todo*); | 118 | bool contains ( Todo*); |
118 | void checkSetCompletedFalse(); | 119 | void checkSetCompletedFalse(); |
119 | bool setRecurDates(); | 120 | bool setRecurDates(); |
120 | bool isRunning() {return mRunning;} | 121 | bool isRunning() {return mRunning;} |
121 | bool hasRunningSub(); | 122 | bool hasRunningSub(); |
122 | void setRunning( bool ); | 123 | void setRunning( bool ); |
123 | void setRunningFalse( QString ); | 124 | void setRunningFalse( QString ); |
124 | int runTime(); | 125 | int runTime(); |
125 | QDateTime runStart () const { return mRunStart;} | 126 | QDateTime runStart () const { return mRunStart;} |
126 | public slots: | 127 | public slots: |
127 | void saveRunningInfoToFile( QString st = QString::null ); | 128 | void saveRunningInfoToFile( QString st = QString::null ); |
128 | void saveParents(); | 129 | void saveParents(); |
129 | private: | 130 | private: |
130 | bool mRunning; | 131 | bool mRunning; |
131 | QTimer * mRunSaveTimer; | 132 | QTimer * mRunSaveTimer; |
132 | QDateTime mRunStart; | 133 | QDateTime mRunStart; |
133 | bool accept(Visitor &v) { return v.visit(this); } | 134 | bool accept(Visitor &v) { return v.visit(this); } |
134 | 135 | ||
135 | QDateTime mDtDue; // due date of todo | 136 | QDateTime mDtDue; // due date of todo |
136 | 137 | ||
137 | bool mHasDueDate; // if todo has associated due date | 138 | bool mHasDueDate; // if todo has associated due date |
138 | 139 | ||
139 | // int mStatus; // confirmed/delegated/tentative/etc | 140 | // int mStatus; // confirmed/delegated/tentative/etc |
140 | 141 | ||
141 | QDateTime mCompleted; | 142 | QDateTime mCompleted; |
142 | bool mHasCompletedDate; | 143 | bool mHasCompletedDate; |
143 | 144 | ||
144 | int mPercentComplete; | 145 | int mPercentComplete; |
145 | }; | 146 | }; |
146 | 147 | ||
147 | bool operator==( const Todo&, const Todo& ); | 148 | bool operator==( const Todo&, const Todo& ); |
148 | } | 149 | } |
149 | 150 | ||
150 | #endif | 151 | #endif |