author | zautrix <zautrix> | 2005-06-10 20:13:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-10 20:13:31 (UTC) |
commit | cdc55afb3d2c3ebd970843b7dce02acb1e6a189b (patch) (unidiff) | |
tree | 45f3bfa69a72de4e8b53bbcb2414478ec65cd183 | |
parent | 31fed261955dcb25d06052a8154ac4cc630b0f7d (diff) | |
download | kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.zip kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.gz kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.bz2 |
many preparations for multiple calendars
-rw-r--r-- | libkcal/calendar.cpp | 14 | ||||
-rw-r--r-- | libkcal/calendar.h | 9 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 80 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 3 | ||||
-rw-r--r-- | libkcal/calfilter.cpp | 9 | ||||
-rw-r--r-- | libkcal/calfilter.h | 1 | ||||
-rw-r--r-- | libkcal/event.cpp | 4 | ||||
-rw-r--r-- | libkcal/incidencebase.cpp | 33 | ||||
-rw-r--r-- | libkcal/incidencebase.h | 9 | ||||
-rw-r--r-- | libkcal/todo.cpp | 2 |
10 files changed, 146 insertions, 18 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 7e8e2c5..f4350d9 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,475 +1,483 @@ | |||
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 | mDefaultCalendar = 1; | |
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 | void Calendar::setDefaultCalendar( int d ) | |
116 | { | ||
117 | mDefaultCalendar = d; | ||
118 | } | ||
119 | int Calendar::defaultCalendar() | ||
120 | { | ||
121 | return mDefaultCalendar; | ||
122 | } | ||
116 | const QString &Calendar::getOwner() const | 123 | const QString &Calendar::getOwner() const |
117 | { | 124 | { |
118 | return mOwner; | 125 | return mOwner; |
119 | } | 126 | } |
120 | 127 | ||
121 | bool Calendar::undoDeleteIncidence() | 128 | bool Calendar::undoDeleteIncidence() |
122 | { | 129 | { |
123 | if (!mUndoIncidence) | 130 | if (!mUndoIncidence) |
124 | return false; | 131 | return false; |
125 | addIncidence(mUndoIncidence); | 132 | addIncidence(mUndoIncidence); |
126 | mUndoIncidence = 0; | 133 | mUndoIncidence = 0; |
127 | return true; | 134 | return true; |
128 | } | 135 | } |
129 | void Calendar::setOwner(const QString &os) | 136 | void Calendar::setOwner(const QString &os) |
130 | { | 137 | { |
131 | int i; | 138 | int i; |
132 | mOwner = os; | 139 | mOwner = os; |
133 | i = mOwner.find(','); | 140 | i = mOwner.find(','); |
134 | if (i != -1) | 141 | if (i != -1) |
135 | mOwner = mOwner.left(i); | 142 | mOwner = mOwner.left(i); |
136 | 143 | ||
137 | setModified( true ); | 144 | setModified( true ); |
138 | } | 145 | } |
139 | 146 | ||
140 | void Calendar::setTimeZone(const QString & tz) | 147 | void Calendar::setTimeZone(const QString & tz) |
141 | { | 148 | { |
142 | bool neg = FALSE; | 149 | bool neg = FALSE; |
143 | int hours, minutes; | 150 | int hours, minutes; |
144 | QString tmpStr(tz); | 151 | QString tmpStr(tz); |
145 | 152 | ||
146 | if (tmpStr.left(1) == "-") | 153 | if (tmpStr.left(1) == "-") |
147 | neg = TRUE; | 154 | neg = TRUE; |
148 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 155 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
149 | tmpStr.remove(0, 1); | 156 | tmpStr.remove(0, 1); |
150 | hours = tmpStr.left(2).toInt(); | 157 | hours = tmpStr.left(2).toInt(); |
151 | if (tmpStr.length() > 2) | 158 | if (tmpStr.length() > 2) |
152 | minutes = tmpStr.right(2).toInt(); | 159 | minutes = tmpStr.right(2).toInt(); |
153 | else | 160 | else |
154 | minutes = 0; | 161 | minutes = 0; |
155 | mTimeZone = (60*hours+minutes); | 162 | mTimeZone = (60*hours+minutes); |
156 | if (neg) | 163 | if (neg) |
157 | mTimeZone = -mTimeZone; | 164 | mTimeZone = -mTimeZone; |
158 | mLocalTime = false; | 165 | mLocalTime = false; |
159 | 166 | ||
160 | setModified( true ); | 167 | setModified( true ); |
161 | } | 168 | } |
162 | 169 | ||
163 | QString Calendar::getTimeZoneStr() const | 170 | QString Calendar::getTimeZoneStr() const |
164 | { | 171 | { |
165 | if (mLocalTime) | 172 | if (mLocalTime) |
166 | return ""; | 173 | return ""; |
167 | QString tmpStr; | 174 | QString tmpStr; |
168 | int hours = abs(mTimeZone / 60); | 175 | int hours = abs(mTimeZone / 60); |
169 | int minutes = abs(mTimeZone % 60); | 176 | int minutes = abs(mTimeZone % 60); |
170 | bool neg = mTimeZone < 0; | 177 | bool neg = mTimeZone < 0; |
171 | 178 | ||
172 | tmpStr.sprintf("%c%.2d%.2d", | 179 | tmpStr.sprintf("%c%.2d%.2d", |
173 | (neg ? '-' : '+'), | 180 | (neg ? '-' : '+'), |
174 | hours, minutes); | 181 | hours, minutes); |
175 | return tmpStr; | 182 | return tmpStr; |
176 | } | 183 | } |
177 | 184 | ||
178 | void Calendar::setTimeZone(int tz) | 185 | void Calendar::setTimeZone(int tz) |
179 | { | 186 | { |
180 | mTimeZone = tz; | 187 | mTimeZone = tz; |
181 | mLocalTime = false; | 188 | mLocalTime = false; |
182 | 189 | ||
183 | setModified( true ); | 190 | setModified( true ); |
184 | } | 191 | } |
185 | 192 | ||
186 | int Calendar::getTimeZone() const | 193 | int Calendar::getTimeZone() const |
187 | { | 194 | { |
188 | return mTimeZone; | 195 | return mTimeZone; |
189 | } | 196 | } |
190 | 197 | ||
191 | void Calendar::setTimeZoneId(const QString &id) | 198 | void Calendar::setTimeZoneId(const QString &id) |
192 | { | 199 | { |
193 | mTimeZoneId = id; | 200 | mTimeZoneId = id; |
194 | mLocalTime = false; | 201 | mLocalTime = false; |
195 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 202 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
196 | if ( mTimeZone > 1000) | 203 | if ( mTimeZone > 1000) |
197 | setLocalTime(); | 204 | setLocalTime(); |
198 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 205 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
199 | setModified( true ); | 206 | setModified( true ); |
200 | } | 207 | } |
201 | 208 | ||
202 | QString Calendar::timeZoneId() const | 209 | QString Calendar::timeZoneId() const |
203 | { | 210 | { |
204 | return mTimeZoneId; | 211 | return mTimeZoneId; |
205 | } | 212 | } |
206 | 213 | ||
207 | void Calendar::setLocalTime() | 214 | void Calendar::setLocalTime() |
208 | { | 215 | { |
209 | //qDebug("Calendar::setLocalTime() "); | 216 | //qDebug("Calendar::setLocalTime() "); |
210 | mLocalTime = true; | 217 | mLocalTime = true; |
211 | mTimeZone = 0; | 218 | mTimeZone = 0; |
212 | mTimeZoneId = ""; | 219 | mTimeZoneId = ""; |
213 | 220 | ||
214 | setModified( true ); | 221 | setModified( true ); |
215 | } | 222 | } |
216 | 223 | ||
217 | bool Calendar::isLocalTime() const | 224 | bool Calendar::isLocalTime() const |
218 | { | 225 | { |
219 | return mLocalTime; | 226 | return mLocalTime; |
220 | } | 227 | } |
221 | 228 | ||
222 | const QString &Calendar::getEmail() | 229 | const QString &Calendar::getEmail() |
223 | { | 230 | { |
224 | return mOwnerEmail; | 231 | return mOwnerEmail; |
225 | } | 232 | } |
226 | 233 | ||
227 | void Calendar::setEmail(const QString &e) | 234 | void Calendar::setEmail(const QString &e) |
228 | { | 235 | { |
229 | mOwnerEmail = e; | 236 | mOwnerEmail = e; |
230 | 237 | ||
231 | setModified( true ); | 238 | setModified( true ); |
232 | } | 239 | } |
233 | 240 | ||
234 | void Calendar::setFilter(CalFilter *filter) | 241 | void Calendar::setFilter(CalFilter *filter) |
235 | { | 242 | { |
236 | mFilter = filter; | 243 | mFilter = filter; |
237 | } | 244 | } |
238 | 245 | ||
239 | CalFilter *Calendar::filter() | 246 | CalFilter *Calendar::filter() |
240 | { | 247 | { |
241 | return mFilter; | 248 | return mFilter; |
242 | } | 249 | } |
243 | 250 | ||
244 | QPtrList<Incidence> Calendar::incidences() | 251 | QPtrList<Incidence> Calendar::incidences() |
245 | { | 252 | { |
246 | QPtrList<Incidence> incidences; | 253 | QPtrList<Incidence> incidences; |
247 | 254 | ||
248 | Incidence *i; | 255 | Incidence *i; |
249 | 256 | ||
250 | QPtrList<Event> e = events(); | 257 | QPtrList<Event> e = events(); |
251 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 258 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
252 | 259 | ||
253 | QPtrList<Todo> t = todos(); | 260 | QPtrList<Todo> t = todos(); |
254 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 261 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
255 | 262 | ||
256 | QPtrList<Journal> j = journals(); | 263 | QPtrList<Journal> j = journals(); |
257 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 264 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
258 | 265 | ||
259 | return incidences; | 266 | return incidences; |
260 | } | 267 | } |
261 | 268 | ||
262 | void Calendar::resetPilotStat(int id ) | 269 | void Calendar::resetPilotStat(int id ) |
263 | { | 270 | { |
264 | QPtrList<Incidence> incidences; | 271 | QPtrList<Incidence> incidences; |
265 | 272 | ||
266 | Incidence *i; | 273 | Incidence *i; |
267 | 274 | ||
268 | QPtrList<Event> e = rawEvents(); | 275 | QPtrList<Event> e = rawEvents(); |
269 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 276 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
270 | 277 | ||
271 | QPtrList<Todo> t = rawTodos(); | 278 | QPtrList<Todo> t = rawTodos(); |
272 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 279 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
273 | 280 | ||
274 | QPtrList<Journal> j = journals(); | 281 | QPtrList<Journal> j = journals(); |
275 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 282 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
276 | } | 283 | } |
277 | void Calendar::resetTempSyncStat() | 284 | void Calendar::resetTempSyncStat() |
278 | { | 285 | { |
279 | QPtrList<Incidence> incidences; | 286 | QPtrList<Incidence> incidences; |
280 | 287 | ||
281 | Incidence *i; | 288 | Incidence *i; |
282 | 289 | ||
283 | QPtrList<Event> e = rawEvents(); | 290 | QPtrList<Event> e = rawEvents(); |
284 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 291 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
285 | 292 | ||
286 | QPtrList<Todo> t = rawTodos(); | 293 | QPtrList<Todo> t = rawTodos(); |
287 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 294 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
288 | 295 | ||
289 | QPtrList<Journal> j = journals(); | 296 | QPtrList<Journal> j = journals(); |
290 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 297 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
291 | } | 298 | } |
292 | QPtrList<Incidence> Calendar::rawIncidences() | 299 | QPtrList<Incidence> Calendar::rawIncidences() |
293 | { | 300 | { |
294 | QPtrList<Incidence> incidences; | 301 | QPtrList<Incidence> incidences; |
295 | 302 | ||
296 | Incidence *i; | 303 | Incidence *i; |
297 | 304 | ||
298 | QPtrList<Event> e = rawEvents(); | 305 | QPtrList<Event> e = rawEvents(); |
299 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 306 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
300 | 307 | ||
301 | QPtrList<Todo> t = rawTodos(); | 308 | QPtrList<Todo> t = rawTodos(); |
302 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 309 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
303 | 310 | ||
304 | QPtrList<Journal> j = journals(); | 311 | QPtrList<Journal> j = journals(); |
305 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 312 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
306 | 313 | ||
307 | return incidences; | 314 | return incidences; |
308 | } | 315 | } |
309 | 316 | ||
310 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 317 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
311 | { | 318 | { |
312 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 319 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
313 | mFilter->apply(&el); | 320 | mFilter->apply(&el); |
314 | return el; | 321 | return el; |
315 | } | 322 | } |
316 | 323 | ||
317 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 324 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
318 | { | 325 | { |
319 | QPtrList<Event> el = rawEventsForDate(qdt); | 326 | QPtrList<Event> el = rawEventsForDate(qdt); |
320 | mFilter->apply(&el); | 327 | mFilter->apply(&el); |
321 | return el; | 328 | return el; |
322 | } | 329 | } |
323 | 330 | ||
324 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 331 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
325 | bool inclusive) | 332 | bool inclusive) |
326 | { | 333 | { |
327 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 334 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
328 | mFilter->apply(&el); | 335 | mFilter->apply(&el); |
329 | return el; | 336 | return el; |
330 | } | 337 | } |
331 | 338 | ||
332 | QPtrList<Event> Calendar::events() | 339 | QPtrList<Event> Calendar::events() |
333 | { | 340 | { |
334 | QPtrList<Event> el = rawEvents(); | 341 | QPtrList<Event> el = rawEvents(); |
335 | mFilter->apply(&el); | 342 | mFilter->apply(&el); |
336 | return el; | 343 | return el; |
337 | } | 344 | } |
338 | void Calendar::addIncidenceBranch(Incidence *i) | 345 | void Calendar::addIncidenceBranch(Incidence *i) |
339 | { | 346 | { |
340 | addIncidence( i ); | 347 | addIncidence( i ); |
341 | Incidence * inc; | 348 | Incidence * inc; |
342 | QPtrList<Incidence> Relations = i->relations(); | 349 | QPtrList<Incidence> Relations = i->relations(); |
343 | for (inc=Relations.first();inc;inc=Relations.next()) { | 350 | for (inc=Relations.first();inc;inc=Relations.next()) { |
344 | addIncidenceBranch( inc ); | 351 | addIncidenceBranch( inc ); |
345 | } | 352 | } |
346 | } | 353 | } |
347 | 354 | ||
348 | bool Calendar::addIncidence(Incidence *i) | 355 | bool Calendar::addIncidence(Incidence *i) |
349 | { | 356 | { |
350 | Incidence::AddVisitor<Calendar> v(this); | 357 | Incidence::AddVisitor<Calendar> v(this); |
351 | 358 | i->setCalID( mDefaultCalendar ); | |
359 | i->setCalEnabled( true ); | ||
352 | return i->accept(v); | 360 | return i->accept(v); |
353 | } | 361 | } |
354 | void Calendar::deleteIncidence(Incidence *in) | 362 | void Calendar::deleteIncidence(Incidence *in) |
355 | { | 363 | { |
356 | if ( in->typeID() == eventID ) | 364 | if ( in->typeID() == eventID ) |
357 | deleteEvent( (Event*) in ); | 365 | deleteEvent( (Event*) in ); |
358 | else if ( in->typeID() == todoID ) | 366 | else if ( in->typeID() == todoID ) |
359 | deleteTodo( (Todo*) in); | 367 | deleteTodo( (Todo*) in); |
360 | else if ( in->typeID() == journalID ) | 368 | else if ( in->typeID() == journalID ) |
361 | deleteJournal( (Journal*) in ); | 369 | deleteJournal( (Journal*) in ); |
362 | } | 370 | } |
363 | 371 | ||
364 | Incidence* Calendar::incidence( const QString& uid ) | 372 | Incidence* Calendar::incidence( const QString& uid ) |
365 | { | 373 | { |
366 | Incidence* i; | 374 | Incidence* i; |
367 | 375 | ||
368 | if( (i = todo( uid )) != 0 ) | 376 | if( (i = todo( uid )) != 0 ) |
369 | return i; | 377 | return i; |
370 | if( (i = event( uid )) != 0 ) | 378 | if( (i = event( uid )) != 0 ) |
371 | return i; | 379 | return i; |
372 | if( (i = journal( uid )) != 0 ) | 380 | if( (i = journal( uid )) != 0 ) |
373 | return i; | 381 | return i; |
374 | 382 | ||
375 | return 0; | 383 | return 0; |
376 | } | 384 | } |
377 | 385 | ||
378 | QPtrList<Todo> Calendar::todos() | 386 | QPtrList<Todo> Calendar::todos() |
379 | { | 387 | { |
380 | QPtrList<Todo> tl = rawTodos(); | 388 | QPtrList<Todo> tl = rawTodos(); |
381 | mFilter->apply( &tl ); | 389 | mFilter->apply( &tl ); |
382 | return tl; | 390 | return tl; |
383 | } | 391 | } |
384 | 392 | ||
385 | // When this is called, the todo have already been added to the calendar. | 393 | // When this is called, the todo have already been added to the calendar. |
386 | // This method is only about linking related todos | 394 | // This method is only about linking related todos |
387 | void Calendar::setupRelations( Incidence *incidence ) | 395 | void Calendar::setupRelations( Incidence *incidence ) |
388 | { | 396 | { |
389 | QString uid = incidence->uid(); | 397 | QString uid = incidence->uid(); |
390 | //qDebug("Calendar::setupRelations "); | 398 | //qDebug("Calendar::setupRelations "); |
391 | // First, go over the list of orphans and see if this is their parent | 399 | // First, go over the list of orphans and see if this is their parent |
392 | while( Incidence* i = mOrphans[ uid ] ) { | 400 | while( Incidence* i = mOrphans[ uid ] ) { |
393 | mOrphans.remove( uid ); | 401 | mOrphans.remove( uid ); |
394 | i->setRelatedTo( incidence ); | 402 | i->setRelatedTo( incidence ); |
395 | incidence->addRelation( i ); | 403 | incidence->addRelation( i ); |
396 | mOrphanUids.remove( i->uid() ); | 404 | mOrphanUids.remove( i->uid() ); |
397 | } | 405 | } |
398 | 406 | ||
399 | // Now see about this incidences parent | 407 | // Now see about this incidences parent |
400 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 408 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
401 | // This incidence has a uid it is related to, but is not registered to it yet | 409 | // This incidence has a uid it is related to, but is not registered to it yet |
402 | // Try to find it | 410 | // Try to find it |
403 | Incidence* parent = this->incidence( incidence->relatedToUid() ); | 411 | Incidence* parent = this->incidence( incidence->relatedToUid() ); |
404 | if( parent ) { | 412 | if( parent ) { |
405 | // Found it | 413 | // Found it |
406 | incidence->setRelatedTo( parent ); | 414 | incidence->setRelatedTo( parent ); |
407 | parent->addRelation( incidence ); | 415 | parent->addRelation( incidence ); |
408 | } else { | 416 | } else { |
409 | // Not found, put this in the mOrphans list | 417 | // Not found, put this in the mOrphans list |
410 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 418 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
411 | mOrphanUids.insert( incidence->uid(), incidence ); | 419 | mOrphanUids.insert( incidence->uid(), incidence ); |
412 | } | 420 | } |
413 | } | 421 | } |
414 | } | 422 | } |
415 | 423 | ||
416 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 424 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
417 | void Calendar::removeRelations( Incidence *incidence ) | 425 | void Calendar::removeRelations( Incidence *incidence ) |
418 | { | 426 | { |
419 | // qDebug("Calendar::removeRelations "); | 427 | // qDebug("Calendar::removeRelations "); |
420 | QString uid = incidence->uid(); | 428 | QString uid = incidence->uid(); |
421 | 429 | ||
422 | QPtrList<Incidence> relations = incidence->relations(); | 430 | QPtrList<Incidence> relations = incidence->relations(); |
423 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 431 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
424 | if( !mOrphanUids.find( i->uid() ) ) { | 432 | if( !mOrphanUids.find( i->uid() ) ) { |
425 | mOrphans.insert( uid, i ); | 433 | mOrphans.insert( uid, i ); |
426 | mOrphanUids.insert( i->uid(), i ); | 434 | mOrphanUids.insert( i->uid(), i ); |
427 | i->setRelatedTo( 0 ); | 435 | i->setRelatedTo( 0 ); |
428 | i->setRelatedToUid( uid ); | 436 | i->setRelatedToUid( uid ); |
429 | } | 437 | } |
430 | 438 | ||
431 | // If this incidence is related to something else, tell that about it | 439 | // If this incidence is related to something else, tell that about it |
432 | if( incidence->relatedTo() ) | 440 | if( incidence->relatedTo() ) |
433 | incidence->relatedTo()->removeRelation( incidence ); | 441 | incidence->relatedTo()->removeRelation( incidence ); |
434 | 442 | ||
435 | // Remove this one from the orphans list | 443 | // Remove this one from the orphans list |
436 | if( mOrphanUids.remove( uid ) ) | 444 | if( mOrphanUids.remove( uid ) ) |
437 | // This incidence is located in the orphans list - it should be removed | 445 | // This incidence is located in the orphans list - it should be removed |
438 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 446 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
439 | // Removing wasn't that easy | 447 | // Removing wasn't that easy |
440 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 448 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
441 | if( it.current()->uid() == uid ) { | 449 | if( it.current()->uid() == uid ) { |
442 | mOrphans.remove( it.currentKey() ); | 450 | mOrphans.remove( it.currentKey() ); |
443 | break; | 451 | break; |
444 | } | 452 | } |
445 | } | 453 | } |
446 | } | 454 | } |
447 | } | 455 | } |
448 | 456 | ||
449 | void Calendar::registerObserver( Observer *observer ) | 457 | void Calendar::registerObserver( Observer *observer ) |
450 | { | 458 | { |
451 | mObserver = observer; | 459 | mObserver = observer; |
452 | mNewObserver = true; | 460 | mNewObserver = true; |
453 | } | 461 | } |
454 | 462 | ||
455 | void Calendar::setModified( bool modified ) | 463 | void Calendar::setModified( bool modified ) |
456 | { | 464 | { |
457 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 465 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
458 | if ( modified != mModified || mNewObserver ) { | 466 | if ( modified != mModified || mNewObserver ) { |
459 | mNewObserver = false; | 467 | mNewObserver = false; |
460 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 468 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
461 | mModified = modified; | 469 | mModified = modified; |
462 | } | 470 | } |
463 | } | 471 | } |
464 | 472 | ||
465 | void Calendar::setLoadedProductId( const QString &id ) | 473 | void Calendar::setLoadedProductId( const QString &id ) |
466 | { | 474 | { |
467 | mLoadedProductId = id; | 475 | mLoadedProductId = id; |
468 | } | 476 | } |
469 | 477 | ||
470 | QString Calendar::loadedProductId() | 478 | QString Calendar::loadedProductId() |
471 | { | 479 | { |
472 | return mLoadedProductId; | 480 | return mLoadedProductId; |
473 | } | 481 | } |
474 | 482 | ||
475 | //#include "calendar.moc" | 483 | //#include "calendar.moc" |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index ab40970..4c6760f 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -49,311 +49,318 @@ namespace KCal { | |||
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
68 | Incidence * undoIncidence() { return mUndoIncidence; }; | 68 | Incidence * undoIncidence() { return mUndoIncidence; }; |
69 | bool undoDeleteIncidence(); | 69 | bool undoDeleteIncidence(); |
70 | void deleteIncidence(Incidence *in); | 70 | void deleteIncidence(Incidence *in); |
71 | void resetTempSyncStat(); | 71 | void resetTempSyncStat(); |
72 | void resetPilotStat(int id); | 72 | void resetPilotStat(int id); |
73 | /** | 73 | /** |
74 | Clears out the current calendar, freeing all used memory etc. | 74 | Clears out the current calendar, freeing all used memory etc. |
75 | */ | 75 | */ |
76 | virtual void close() = 0; | 76 | virtual void close() = 0; |
77 | 77 | ||
78 | /** | 78 | /** |
79 | Sync changes in memory to persistant storage. | 79 | Sync changes in memory to persistant storage. |
80 | */ | 80 | */ |
81 | virtual void save() = 0; | 81 | virtual void save() = 0; |
82 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 82 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
83 | virtual void removeSyncInfo( QString syncProfile) = 0; | 83 | virtual void removeSyncInfo( QString syncProfile) = 0; |
84 | virtual bool isSaving() { return false; } | 84 | virtual bool isSaving() { return false; } |
85 | 85 | ||
86 | /** | 86 | /** |
87 | Return the owner of the calendar's full name. | 87 | Return the owner of the calendar's full name. |
88 | */ | 88 | */ |
89 | const QString &getOwner() const; | 89 | const QString &getOwner() const; |
90 | /** | 90 | /** |
91 | Set the owner of the calendar. Should be owner's full name. | 91 | Set the owner of the calendar. Should be owner's full name. |
92 | */ | 92 | */ |
93 | void setOwner( const QString &os ); | 93 | void setOwner( const QString &os ); |
94 | /** | 94 | /** |
95 | Return the email address of the calendar owner. | 95 | Return the email address of the calendar owner. |
96 | */ | 96 | */ |
97 | const QString &getEmail(); | 97 | const QString &getEmail(); |
98 | /** | 98 | /** |
99 | Set the email address of the calendar owner. | 99 | Set the email address of the calendar owner. |
100 | */ | 100 | */ |
101 | void setEmail( const QString & ); | 101 | void setEmail( const QString & ); |
102 | 102 | ||
103 | /** | 103 | /** |
104 | Set time zone from a timezone string (e.g. -2:00) | 104 | Set time zone from a timezone string (e.g. -2:00) |
105 | */ | 105 | */ |
106 | void setTimeZone( const QString &tz ); | 106 | void setTimeZone( const QString &tz ); |
107 | /** | 107 | /** |
108 | Set time zone from a minutes value (e.g. -60) | 108 | Set time zone from a minutes value (e.g. -60) |
109 | */ | 109 | */ |
110 | void setTimeZone( int tz ); | 110 | void setTimeZone( int tz ); |
111 | /** | 111 | /** |
112 | Return time zone as offest in minutes. | 112 | Return time zone as offest in minutes. |
113 | */ | 113 | */ |
114 | int getTimeZone() const; | 114 | int getTimeZone() const; |
115 | /** | 115 | /** |
116 | Compute an ISO 8601 format string from the time zone. | 116 | Compute an ISO 8601 format string from the time zone. |
117 | */ | 117 | */ |
118 | QString getTimeZoneStr() const; | 118 | QString getTimeZoneStr() const; |
119 | /** | 119 | /** |
120 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 120 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
121 | values). | 121 | values). |
122 | */ | 122 | */ |
123 | void setTimeZoneId( const QString & ); | 123 | void setTimeZoneId( const QString & ); |
124 | /** | 124 | /** |
125 | Return time zone id. | 125 | Return time zone id. |
126 | */ | 126 | */ |
127 | QString timeZoneId() const; | 127 | QString timeZoneId() const; |
128 | /** | 128 | /** |
129 | Use local time, not UTC or a time zone. | 129 | Use local time, not UTC or a time zone. |
130 | */ | 130 | */ |
131 | void setLocalTime(); | 131 | void setLocalTime(); |
132 | /** | 132 | /** |
133 | Return whether local time is being used. | 133 | Return whether local time is being used. |
134 | */ | 134 | */ |
135 | bool isLocalTime() const; | 135 | bool isLocalTime() const; |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Add an incidence to calendar. | 138 | Add an incidence to calendar. |
139 | 139 | ||
140 | @return true on success, false on error. | 140 | @return true on success, false on error. |
141 | */ | 141 | */ |
142 | virtual bool addIncidence( Incidence * ); | 142 | virtual bool addIncidence( Incidence * ); |
143 | 143 | ||
144 | // Adds an incidence and all relatedto incidences to the cal | 144 | // Adds an incidence and all relatedto incidences to the cal |
145 | void addIncidenceBranch( Incidence * ); | 145 | void addIncidenceBranch( Incidence * ); |
146 | /** | 146 | /** |
147 | Return filtered list of all incidences of this calendar. | 147 | Return filtered list of all incidences of this calendar. |
148 | */ | 148 | */ |
149 | virtual QPtrList<Incidence> incidences(); | 149 | virtual QPtrList<Incidence> incidences(); |
150 | 150 | ||
151 | /** | 151 | /** |
152 | Return unfiltered list of all incidences of this calendar. | 152 | Return unfiltered list of all incidences of this calendar. |
153 | */ | 153 | */ |
154 | virtual QPtrList<Incidence> rawIncidences(); | 154 | virtual QPtrList<Incidence> rawIncidences(); |
155 | 155 | ||
156 | /** | 156 | /** |
157 | Adds a Event to this calendar object. | 157 | Adds a Event to this calendar object. |
158 | @param anEvent a pointer to the event to add | 158 | @param anEvent a pointer to the event to add |
159 | 159 | ||
160 | @return true on success, false on error. | 160 | @return true on success, false on error. |
161 | */ | 161 | */ |
162 | virtual bool addEventNoDup( Event *event ) = 0; | 162 | virtual bool addEventNoDup( Event *event ) = 0; |
163 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 163 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
164 | virtual bool addEvent( Event *anEvent ) = 0; | 164 | virtual bool addEvent( Event *anEvent ) = 0; |
165 | /** | 165 | /** |
166 | Delete event from calendar. | 166 | Delete event from calendar. |
167 | */ | 167 | */ |
168 | virtual void deleteEvent( Event * ) = 0; | 168 | virtual void deleteEvent( Event * ) = 0; |
169 | /** | 169 | /** |
170 | Retrieves an event on the basis of the unique string ID. | 170 | Retrieves an event on the basis of the unique string ID. |
171 | */ | 171 | */ |
172 | virtual Event *event( const QString &UniqueStr ) = 0; | 172 | virtual Event *event( const QString &UniqueStr ) = 0; |
173 | virtual Event *event( QString, QString ) = 0; | 173 | virtual Event *event( QString, QString ) = 0; |
174 | /** | 174 | /** |
175 | Builds and then returns a list of all events that match for the | 175 | Builds and then returns a list of all events that match for the |
176 | date specified. useful for dayView, etc. etc. | 176 | date specified. useful for dayView, etc. etc. |
177 | The calendar filter is applied. | 177 | The calendar filter is applied. |
178 | */ | 178 | */ |
179 | QPtrList<Event> events( const QDate &date, bool sorted = false); | 179 | QPtrList<Event> events( const QDate &date, bool sorted = false); |
180 | /** | 180 | /** |
181 | Get events, which occur on the given date. | 181 | Get events, which occur on the given date. |
182 | The calendar filter is applied. | 182 | The calendar filter is applied. |
183 | */ | 183 | */ |
184 | QPtrList<Event> events( const QDateTime &qdt ); | 184 | QPtrList<Event> events( const QDateTime &qdt ); |
185 | /** | 185 | /** |
186 | Get events in a range of dates. If inclusive is set to true, only events | 186 | Get events in a range of dates. If inclusive is set to true, only events |
187 | are returned, which are completely included in the range. | 187 | are returned, which are completely included in the range. |
188 | The calendar filter is applied. | 188 | The calendar filter is applied. |
189 | */ | 189 | */ |
190 | QPtrList<Event> events( const QDate &start, const QDate &end, | 190 | QPtrList<Event> events( const QDate &start, const QDate &end, |
191 | bool inclusive = false); | 191 | bool inclusive = false); |
192 | /** | 192 | /** |
193 | Return filtered list of all events in calendar. | 193 | Return filtered list of all events in calendar. |
194 | */ | 194 | */ |
195 | virtual QPtrList<Event> events(); | 195 | virtual QPtrList<Event> events(); |
196 | /** | 196 | /** |
197 | Return unfiltered list of all events in calendar. | 197 | Return unfiltered list of all events in calendar. |
198 | */ | 198 | */ |
199 | virtual QPtrList<Event> rawEvents() = 0; | 199 | virtual QPtrList<Event> rawEvents() = 0; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | Add a todo to the todolist. | 202 | Add a todo to the todolist. |
203 | 203 | ||
204 | @return true on success, false on error. | 204 | @return true on success, false on error. |
205 | */ | 205 | */ |
206 | virtual bool addTodo( Todo *todo ) = 0; | 206 | virtual bool addTodo( Todo *todo ) = 0; |
207 | virtual bool addTodoNoDup( Todo *todo ) = 0; | 207 | virtual bool addTodoNoDup( Todo *todo ) = 0; |
208 | /** | 208 | /** |
209 | Remove a todo from the todolist. | 209 | Remove a todo from the todolist. |
210 | */ | 210 | */ |
211 | virtual void deleteTodo( Todo * ) = 0; | 211 | virtual void deleteTodo( Todo * ) = 0; |
212 | virtual void deleteJournal( Journal * ) = 0; | 212 | virtual void deleteJournal( Journal * ) = 0; |
213 | /** | 213 | /** |
214 | Return filterd list of todos. | 214 | Return filterd list of todos. |
215 | */ | 215 | */ |
216 | virtual QPtrList<Todo> todos(); | 216 | virtual QPtrList<Todo> todos(); |
217 | /** | 217 | /** |
218 | Searches todolist for an event with this unique string identifier, | 218 | Searches todolist for an event with this unique string identifier, |
219 | returns a pointer or null. | 219 | returns a pointer or null. |
220 | */ | 220 | */ |
221 | virtual Todo *todo( const QString &uid ) = 0; | 221 | virtual Todo *todo( const QString &uid ) = 0; |
222 | virtual Todo *todo( QString, QString ) = 0; | 222 | virtual Todo *todo( QString, QString ) = 0; |
223 | /** | 223 | /** |
224 | Returns list of todos due on the specified date. | 224 | Returns list of todos due on the specified date. |
225 | */ | 225 | */ |
226 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; | 226 | virtual QPtrList<Todo> todos( const QDate &date ) = 0; |
227 | /** | 227 | /** |
228 | Return unfiltered list of todos. | 228 | Return unfiltered list of todos. |
229 | */ | 229 | */ |
230 | virtual QPtrList<Todo> rawTodos() = 0; | 230 | virtual QPtrList<Todo> rawTodos() = 0; |
231 | 231 | ||
232 | /** | 232 | /** |
233 | Add a Journal entry to calendar. | 233 | Add a Journal entry to calendar. |
234 | 234 | ||
235 | @return true on success, false on error. | 235 | @return true on success, false on error. |
236 | */ | 236 | */ |
237 | virtual bool addJournal( Journal * ) = 0; | 237 | virtual bool addJournal( Journal * ) = 0; |
238 | /** | 238 | /** |
239 | Return Journal for given date. | 239 | Return Journal for given date. |
240 | */ | 240 | */ |
241 | virtual Journal *journal( const QDate & ) = 0; | 241 | virtual Journal *journal( const QDate & ) = 0; |
242 | /** | 242 | /** |
243 | Return Journal with given UID. | 243 | Return Journal with given UID. |
244 | */ | 244 | */ |
245 | virtual Journal *journal( const QString &UID ) = 0; | 245 | virtual Journal *journal( const QString &UID ) = 0; |
246 | /** | 246 | /** |
247 | Return list of all Journal entries. | 247 | Return list of all Journal entries. |
248 | */ | 248 | */ |
249 | virtual QPtrList<Journal> journals() = 0; | 249 | virtual QPtrList<Journal> journals() = 0; |
250 | 250 | ||
251 | /** | 251 | /** |
252 | Searches all incidence types for an incidence with this unique | 252 | Searches all incidence types for an incidence with this unique |
253 | string identifier, returns a pointer or null. | 253 | string identifier, returns a pointer or null. |
254 | */ | 254 | */ |
255 | Incidence* incidence( const QString&UID ); | 255 | Incidence* incidence( const QString&UID ); |
256 | 256 | ||
257 | /** | 257 | /** |
258 | Setup relations for an incidence. | 258 | Setup relations for an incidence. |
259 | */ | 259 | */ |
260 | virtual void setupRelations( Incidence * ); | 260 | virtual void setupRelations( Incidence * ); |
261 | /** | 261 | /** |
262 | Remove all relations to an incidence | 262 | Remove all relations to an incidence |
263 | */ | 263 | */ |
264 | virtual void removeRelations( Incidence * ); | 264 | virtual void removeRelations( Incidence * ); |
265 | 265 | ||
266 | /** | 266 | /** |
267 | Set calendar filter, which filters events for the events() functions. | 267 | Set calendar filter, which filters events for the events() functions. |
268 | The Filter object is owned by the caller. | 268 | The Filter object is owned by the caller. |
269 | */ | 269 | */ |
270 | void setFilter( CalFilter * ); | 270 | void setFilter( CalFilter * ); |
271 | /** | 271 | /** |
272 | Return calendar filter. | 272 | Return calendar filter. |
273 | */ | 273 | */ |
274 | CalFilter *filter(); | 274 | CalFilter *filter(); |
275 | virtual QDateTime nextAlarm( int daysTo ) = 0; | 275 | virtual QDateTime nextAlarm( int daysTo ) = 0; |
276 | virtual QString nextSummary( ) const = 0; | 276 | virtual QString nextSummary( ) const = 0; |
277 | virtual void reInitAlarmSettings() = 0; | 277 | virtual void reInitAlarmSettings() = 0; |
278 | virtual QDateTime nextAlarmEventDateTime() const = 0; | 278 | virtual QDateTime nextAlarmEventDateTime() const = 0; |
279 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; | 279 | virtual void checkAlarmForIncidence( Incidence *, bool ) = 0; |
280 | /** | 280 | /** |
281 | Return all alarms, which ocur in the given time interval. | 281 | Return all alarms, which ocur in the given time interval. |
282 | */ | 282 | */ |
283 | virtual Alarm::List alarms( const QDateTime &from, | 283 | virtual Alarm::List alarms( const QDateTime &from, |
284 | const QDateTime &to ) = 0; | 284 | const QDateTime &to ) = 0; |
285 | 285 | ||
286 | class Observer { | 286 | class Observer { |
287 | public: | 287 | public: |
288 | virtual void calendarModified( bool, Calendar * ) = 0; | 288 | virtual void calendarModified( bool, Calendar * ) = 0; |
289 | }; | 289 | }; |
290 | 290 | ||
291 | void registerObserver( Observer * ); | 291 | void registerObserver( Observer * ); |
292 | 292 | ||
293 | void setModified( bool ); | 293 | void setModified( bool ); |
294 | 294 | ||
295 | /** | 295 | /** |
296 | Set product id returned by loadedProductId(). This function is only | 296 | Set product id returned by loadedProductId(). This function is only |
297 | useful for the calendar loading code. | 297 | useful for the calendar loading code. |
298 | */ | 298 | */ |
299 | void setLoadedProductId( const QString & ); | 299 | void setLoadedProductId( const QString & ); |
300 | /** | 300 | /** |
301 | Return product id taken from file that has been loaded. Returns | 301 | Return product id taken from file that has been loaded. Returns |
302 | QString::null, if no calendar has been loaded. | 302 | QString::null, if no calendar has been loaded. |
303 | */ | 303 | */ |
304 | QString loadedProductId(); | 304 | QString loadedProductId(); |
305 | 305 | void setDefaultCalendar( int ); | |
306 | int defaultCalendar(); | ||
307 | virtual void setCalendarEnabled( int id, bool enable ) = 0; | ||
308 | virtual void setAlarmEnabled( int id, bool enable ) = 0; | ||
309 | virtual void setDefaultCalendarEnabledOnly() = 0; | ||
306 | signals: | 310 | signals: |
307 | void calendarChanged(); | 311 | void calendarChanged(); |
308 | void calendarSaved(); | 312 | void calendarSaved(); |
309 | void calendarLoaded(); | 313 | void calendarLoaded(); |
310 | void addAlarm(const QDateTime &qdt, const QString ¬i ); | 314 | void addAlarm(const QDateTime &qdt, const QString ¬i ); |
311 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); | 315 | void removeAlarm(const QDateTime &qdt, const QString ¬i ); |
312 | 316 | ||
313 | protected: | 317 | protected: |
314 | /** | 318 | /** |
315 | Get unfiltered events, which occur on the given date. | 319 | Get unfiltered events, which occur on the given date. |
316 | */ | 320 | */ |
317 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; | 321 | virtual QPtrList<Event> rawEventsForDate( const QDateTime &qdt ) = 0; |
318 | /** | 322 | /** |
319 | Get unfiltered events, which occur on the given date. | 323 | Get unfiltered events, which occur on the given date. |
320 | */ | 324 | */ |
321 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, | 325 | virtual QPtrList<Event> rawEventsForDate( const QDate &date, |
322 | bool sorted = false ) = 0; | 326 | bool sorted = false ) = 0; |
323 | /** | 327 | /** |
324 | Get events in a range of dates. If inclusive is set to true, only events | 328 | Get events in a range of dates. If inclusive is set to true, only events |
325 | are returned, which are completely included in the range. | 329 | are returned, which are completely included in the range. |
326 | */ | 330 | */ |
327 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 331 | virtual QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
328 | bool inclusive = false ) = 0; | 332 | bool inclusive = false ) = 0; |
333 | |||
329 | Incidence *mNextAlarmIncidence; | 334 | Incidence *mNextAlarmIncidence; |
330 | Incidence *mUndoIncidence; | 335 | Incidence *mUndoIncidence; |
336 | int mDefaultCalendar; | ||
331 | 337 | ||
332 | private: | 338 | private: |
333 | void init(); | 339 | void init(); |
334 | 340 | ||
335 | QString mOwner; // who the calendar belongs to | 341 | QString mOwner; // who the calendar belongs to |
336 | QString mOwnerEmail; // email address of the owner | 342 | QString mOwnerEmail; // email address of the owner |
337 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) | 343 | int mTimeZone; // timezone OFFSET from GMT (MINUTES) |
338 | bool mLocalTime; // use local time, not UTC or a time zone | 344 | bool mLocalTime; // use local time, not UTC or a time zone |
339 | 345 | ||
340 | CalFilter *mFilter; | 346 | CalFilter *mFilter; |
341 | CalFilter *mDefaultFilter; | 347 | CalFilter *mDefaultFilter; |
348 | |||
342 | 349 | ||
343 | QString mTimeZoneId; | 350 | QString mTimeZoneId; |
344 | 351 | ||
345 | Observer *mObserver; | 352 | Observer *mObserver; |
346 | bool mNewObserver; | 353 | bool mNewObserver; |
347 | 354 | ||
348 | bool mModified; | 355 | bool mModified; |
349 | 356 | ||
350 | QString mLoadedProductId; | 357 | QString mLoadedProductId; |
351 | 358 | ||
352 | // This list is used to put together related todos | 359 | // This list is used to put together related todos |
353 | QDict<Incidence> mOrphans; | 360 | QDict<Incidence> mOrphans; |
354 | QDict<Incidence> mOrphanUids; | 361 | QDict<Incidence> mOrphanUids; |
355 | }; | 362 | }; |
356 | 363 | ||
357 | } | 364 | } |
358 | 365 | ||
359 | #endif | 366 | #endif |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index fe74052..c5500bf 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,726 +1,782 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) |
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | close(); | 68 | close(); |
69 | } | 69 | } |
70 | 70 | ||
71 | bool CalendarLocal::load( const QString &fileName ) | 71 | bool CalendarLocal::load( const QString &fileName ) |
72 | { | 72 | { |
73 | FileStorage storage( this, fileName ); | 73 | FileStorage storage( this, fileName ); |
74 | return storage.load(); | 74 | return storage.load(); |
75 | } | 75 | } |
76 | 76 | ||
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 | event->setCalID( mDefaultCalendar ); | ||
154 | event->setCalEnabled( true ); | ||
153 | 155 | ||
154 | return true; | 156 | return true; |
155 | } | 157 | } |
156 | 158 | ||
157 | void CalendarLocal::deleteEvent( Event *event ) | 159 | void CalendarLocal::deleteEvent( Event *event ) |
158 | { | 160 | { |
159 | if ( mUndoIncidence ) delete mUndoIncidence; | 161 | if ( mUndoIncidence ) delete mUndoIncidence; |
160 | mUndoIncidence = event->clone(); | 162 | mUndoIncidence = event->clone(); |
161 | if ( mEventList.removeRef( event ) ) { | 163 | if ( mEventList.removeRef( event ) ) { |
162 | setModified( true ); | 164 | setModified( true ); |
163 | } | 165 | } |
164 | } | 166 | } |
165 | 167 | ||
166 | 168 | ||
167 | Event *CalendarLocal::event( const QString &uid ) | 169 | Event *CalendarLocal::event( const QString &uid ) |
168 | { | 170 | { |
169 | 171 | ||
170 | Event *event; | 172 | Event *event; |
171 | 173 | ||
172 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 174 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
173 | if ( event->uid() == uid ) { | 175 | if ( event->uid() == uid && event->calEnabled() ) { |
174 | return event; | 176 | return event; |
175 | } | 177 | } |
176 | } | 178 | } |
177 | 179 | ||
178 | return 0; | 180 | return 0; |
179 | } | 181 | } |
180 | bool CalendarLocal::addTodoNoDup( Todo *todo ) | 182 | bool CalendarLocal::addTodoNoDup( Todo *todo ) |
181 | { | 183 | { |
182 | Todo * eve; | 184 | Todo * eve; |
183 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { | 185 | for ( eve = mTodoList.first(); eve ; eve = mTodoList.next() ) { |
184 | if ( *eve == *todo ) { | 186 | if ( *eve == *todo ) { |
185 | //qDebug("duplicate todo found! not inserted! "); | 187 | //qDebug("duplicate todo found! not inserted! "); |
186 | return false; | 188 | return false; |
187 | } | 189 | } |
188 | } | 190 | } |
189 | return addTodo( todo ); | 191 | return addTodo( todo ); |
190 | } | 192 | } |
191 | bool CalendarLocal::addTodo( Todo *todo ) | 193 | bool CalendarLocal::addTodo( Todo *todo ) |
192 | { | 194 | { |
193 | mTodoList.append( todo ); | 195 | mTodoList.append( todo ); |
194 | 196 | ||
195 | todo->registerObserver( this ); | 197 | todo->registerObserver( this ); |
196 | 198 | ||
197 | // Set up subtask relations | 199 | // Set up subtask relations |
198 | setupRelations( todo ); | 200 | setupRelations( todo ); |
199 | 201 | ||
200 | setModified( true ); | 202 | setModified( true ); |
201 | 203 | todo->setCalID( mDefaultCalendar ); | |
204 | todo->setCalEnabled( true ); | ||
202 | return true; | 205 | return true; |
203 | } | 206 | } |
204 | 207 | ||
205 | void CalendarLocal::deleteTodo( Todo *todo ) | 208 | void CalendarLocal::deleteTodo( Todo *todo ) |
206 | { | 209 | { |
207 | // Handle orphaned children | 210 | // Handle orphaned children |
208 | if ( mUndoIncidence ) delete mUndoIncidence; | 211 | if ( mUndoIncidence ) delete mUndoIncidence; |
209 | removeRelations( todo ); | 212 | removeRelations( todo ); |
210 | mUndoIncidence = todo->clone(); | 213 | mUndoIncidence = todo->clone(); |
211 | 214 | ||
212 | if ( mTodoList.removeRef( todo ) ) { | 215 | if ( mTodoList.removeRef( todo ) ) { |
213 | setModified( true ); | 216 | setModified( true ); |
214 | } | 217 | } |
215 | } | 218 | } |
216 | 219 | ||
217 | QPtrList<Todo> CalendarLocal::rawTodos() | 220 | QPtrList<Todo> CalendarLocal::rawTodos() |
218 | { | 221 | { |
219 | return mTodoList; | 222 | QPtrList<Todo> el; |
223 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
224 | if ( it->calEnabled() ) el.append( it ); | ||
225 | return el; | ||
220 | } | 226 | } |
221 | Todo *CalendarLocal::todo( QString syncProf, QString id ) | 227 | Todo *CalendarLocal::todo( QString syncProf, QString id ) |
222 | { | 228 | { |
223 | Todo *todo; | 229 | Todo *todo; |
224 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 230 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
225 | if ( todo->getID( syncProf ) == id ) return todo; | 231 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
226 | } | 232 | } |
227 | 233 | ||
228 | return 0; | 234 | return 0; |
229 | } | 235 | } |
230 | void CalendarLocal::removeSyncInfo( QString syncProfile) | 236 | void CalendarLocal::removeSyncInfo( QString syncProfile) |
231 | { | 237 | { |
232 | QPtrList<Incidence> all = rawIncidences() ; | 238 | QPtrList<Incidence> all = rawIncidences() ; |
233 | Incidence *inc; | 239 | Incidence *inc; |
234 | for ( inc = all.first(); inc; inc = all.next() ) { | 240 | for ( inc = all.first(); inc; inc = all.next() ) { |
235 | inc->removeID( syncProfile ); | 241 | inc->removeID( syncProfile ); |
236 | } | 242 | } |
237 | if ( syncProfile.isEmpty() ) { | 243 | if ( syncProfile.isEmpty() ) { |
238 | QPtrList<Event> el; | 244 | QPtrList<Event> el; |
239 | Event *todo; | 245 | Event *todo; |
240 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 246 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
241 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 247 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
242 | el.append( todo ); | 248 | el.append( todo ); |
243 | } | 249 | } |
244 | for ( todo = el.first(); todo; todo = el.next() ) { | 250 | for ( todo = el.first(); todo; todo = el.next() ) { |
245 | deleteIncidence ( todo ); | 251 | deleteIncidence ( todo ); |
246 | } | 252 | } |
247 | } else { | 253 | } else { |
248 | Event *lse = event( "last-syncEvent-"+ syncProfile); | 254 | Event *lse = event( "last-syncEvent-"+ syncProfile); |
249 | if ( lse ) | 255 | if ( lse ) |
250 | deleteIncidence ( lse ); | 256 | deleteIncidence ( lse ); |
251 | } | 257 | } |
252 | } | 258 | } |
253 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() | 259 | QPtrList<Event> CalendarLocal::getExternLastSyncEvents() |
254 | { | 260 | { |
255 | QPtrList<Event> el; | 261 | QPtrList<Event> el; |
256 | Event *todo; | 262 | Event *todo; |
257 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 263 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
258 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) | 264 | if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) |
259 | if ( todo->summary().left(3) == "E: " ) | 265 | if ( todo->summary().left(3) == "E: " ) |
260 | el.append( todo ); | 266 | el.append( todo ); |
261 | } | 267 | } |
262 | 268 | ||
263 | return el; | 269 | return el; |
264 | 270 | ||
265 | } | 271 | } |
266 | Event *CalendarLocal::event( QString syncProf, QString id ) | 272 | Event *CalendarLocal::event( QString syncProf, QString id ) |
267 | { | 273 | { |
268 | Event *todo; | 274 | Event *todo; |
269 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { | 275 | for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { |
270 | if ( todo->getID( syncProf ) == id ) return todo; | 276 | if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; |
271 | } | 277 | } |
272 | 278 | ||
273 | return 0; | 279 | return 0; |
274 | } | 280 | } |
275 | Todo *CalendarLocal::todo( const QString &uid ) | 281 | Todo *CalendarLocal::todo( const QString &uid ) |
276 | { | 282 | { |
277 | Todo *todo; | 283 | Todo *todo; |
278 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 284 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
279 | if ( todo->uid() == uid ) return todo; | 285 | if ( todo->calEnabled() && todo->uid() == uid ) return todo; |
280 | } | 286 | } |
281 | 287 | ||
282 | return 0; | 288 | return 0; |
283 | } | 289 | } |
284 | QString CalendarLocal::nextSummary() const | 290 | QString CalendarLocal::nextSummary() const |
285 | { | 291 | { |
286 | return mNextSummary; | 292 | return mNextSummary; |
287 | } | 293 | } |
288 | QDateTime CalendarLocal::nextAlarmEventDateTime() const | 294 | QDateTime CalendarLocal::nextAlarmEventDateTime() const |
289 | { | 295 | { |
290 | return mNextAlarmEventDateTime; | 296 | return mNextAlarmEventDateTime; |
291 | } | 297 | } |
292 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) | 298 | void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted) |
293 | { | 299 | { |
294 | //mNextAlarmIncidence | 300 | //mNextAlarmIncidence |
295 | //mNextAlarmDateTime | 301 | //mNextAlarmDateTime |
296 | //return mNextSummary; | 302 | //return mNextSummary; |
297 | //return mNextAlarmEventDateTime; | 303 | //return mNextAlarmEventDateTime; |
298 | bool newNextAlarm = false; | 304 | bool newNextAlarm = false; |
299 | bool computeNextAlarm = false; | 305 | bool computeNextAlarm = false; |
300 | bool ok; | 306 | bool ok; |
301 | int offset; | 307 | int offset; |
302 | QDateTime nextA; | 308 | QDateTime nextA; |
303 | // QString nextSum; | 309 | // QString nextSum; |
304 | //QDateTime nextEvent; | 310 | //QDateTime nextEvent; |
305 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { | 311 | if ( mNextAlarmIncidence == 0 || incidence == 0 ) { |
306 | computeNextAlarm = true; | 312 | computeNextAlarm = true; |
307 | } else { | 313 | } else { |
308 | if ( ! deleted ) { | 314 | if ( ! deleted ) { |
309 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 315 | nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
310 | if ( ok ) { | 316 | if ( ok ) { |
311 | if ( nextA < mNextAlarmDateTime ) { | 317 | if ( nextA < mNextAlarmDateTime ) { |
312 | deRegisterAlarm(); | 318 | deRegisterAlarm(); |
313 | mNextAlarmDateTime = nextA; | 319 | mNextAlarmDateTime = nextA; |
314 | mNextSummary = incidence->summary(); | 320 | mNextSummary = incidence->summary(); |
315 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; | 321 | mNextAlarmEventDateTime = nextA.addSecs(offset ) ; |
316 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 322 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
317 | newNextAlarm = true; | 323 | newNextAlarm = true; |
318 | mNextAlarmIncidence = incidence; | 324 | mNextAlarmIncidence = incidence; |
319 | } else { | 325 | } else { |
320 | if ( incidence == mNextAlarmIncidence ) { | 326 | if ( incidence == mNextAlarmIncidence ) { |
321 | computeNextAlarm = true; | 327 | computeNextAlarm = true; |
322 | } | 328 | } |
323 | } | 329 | } |
324 | } else { | 330 | } else { |
325 | if ( mNextAlarmIncidence == incidence ) { | 331 | if ( mNextAlarmIncidence == incidence ) { |
326 | computeNextAlarm = true; | 332 | computeNextAlarm = true; |
327 | } | 333 | } |
328 | } | 334 | } |
329 | } else { // deleted | 335 | } else { // deleted |
330 | if ( incidence == mNextAlarmIncidence ) { | 336 | if ( incidence == mNextAlarmIncidence ) { |
331 | computeNextAlarm = true; | 337 | computeNextAlarm = true; |
332 | } | 338 | } |
333 | } | 339 | } |
334 | } | 340 | } |
335 | if ( computeNextAlarm ) { | 341 | if ( computeNextAlarm ) { |
336 | deRegisterAlarm(); | 342 | deRegisterAlarm(); |
337 | nextA = nextAlarm( 1000 ); | 343 | nextA = nextAlarm( 1000 ); |
338 | if (! mNextAlarmIncidence ) { | 344 | if (! mNextAlarmIncidence ) { |
339 | return; | 345 | return; |
340 | } | 346 | } |
341 | newNextAlarm = true; | 347 | newNextAlarm = true; |
342 | } | 348 | } |
343 | if ( newNextAlarm ) | 349 | if ( newNextAlarm ) |
344 | registerAlarm(); | 350 | registerAlarm(); |
345 | } | 351 | } |
346 | QString CalendarLocal:: getAlarmNotification() | 352 | QString CalendarLocal:: getAlarmNotification() |
347 | { | 353 | { |
348 | QString ret; | 354 | QString ret; |
349 | // this should not happen | 355 | // this should not happen |
350 | if (! mNextAlarmIncidence ) | 356 | if (! mNextAlarmIncidence ) |
351 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; | 357 | return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString; |
352 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); | 358 | Alarm* alarm = mNextAlarmIncidence->alarms().first(); |
353 | if ( alarm->type() == Alarm::Procedure ) { | 359 | if ( alarm->type() == Alarm::Procedure ) { |
354 | ret = "proc_alarm" + alarm->programFile()+"+++"; | 360 | ret = "proc_alarm" + alarm->programFile()+"+++"; |
355 | } else { | 361 | } else { |
356 | ret = "audio_alarm" +alarm->audioFile() +"+++"; | 362 | ret = "audio_alarm" +alarm->audioFile() +"+++"; |
357 | } | 363 | } |
358 | ret += "cal_alarm"+ mNextSummary.left( 25 ); | 364 | ret += "cal_alarm"+ mNextSummary.left( 25 ); |
359 | if ( mNextSummary.length() > 25 ) | 365 | if ( mNextSummary.length() > 25 ) |
360 | ret += "\n" + mNextSummary.mid(25, 25 ); | 366 | ret += "\n" + mNextSummary.mid(25, 25 ); |
361 | ret+= "\n"+mNextAlarmEventDateTimeString; | 367 | ret+= "\n"+mNextAlarmEventDateTimeString; |
362 | return ret; | 368 | return ret; |
363 | } | 369 | } |
364 | void CalendarLocal::registerAlarm() | 370 | void CalendarLocal::registerAlarm() |
365 | { | 371 | { |
366 | mLastAlarmNotificationString = getAlarmNotification(); | 372 | mLastAlarmNotificationString = getAlarmNotification(); |
367 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); | 373 | // qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() ); |
368 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 374 | emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
369 | // #ifndef DESKTOP_VERSION | 375 | // #ifndef DESKTOP_VERSION |
370 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); | 376 | // AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); |
371 | // #endif | 377 | // #endif |
372 | } | 378 | } |
373 | void CalendarLocal::deRegisterAlarm() | 379 | void CalendarLocal::deRegisterAlarm() |
374 | { | 380 | { |
375 | if ( mLastAlarmNotificationString.isNull() ) | 381 | if ( mLastAlarmNotificationString.isNull() ) |
376 | return; | 382 | return; |
377 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); | 383 | //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); |
378 | 384 | ||
379 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); | 385 | emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); |
380 | mNextAlarmEventDateTime = QDateTime(); | 386 | mNextAlarmEventDateTime = QDateTime(); |
381 | // #ifndef DESKTOP_VERSION | 387 | // #ifndef DESKTOP_VERSION |
382 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); | 388 | // AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); |
383 | // #endif | 389 | // #endif |
384 | } | 390 | } |
385 | 391 | ||
386 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) | 392 | QPtrList<Todo> CalendarLocal::todos( const QDate &date ) |
387 | { | 393 | { |
388 | QPtrList<Todo> todos; | 394 | QPtrList<Todo> todos; |
389 | 395 | ||
390 | Todo *todo; | 396 | Todo *todo; |
391 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 397 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
398 | if ( !todo->calEnabled() ) continue; | ||
392 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { | 399 | if ( todo->hasDueDate() && todo->dtDue().date() == date ) { |
393 | todos.append( todo ); | 400 | todos.append( todo ); |
394 | } | 401 | } |
395 | } | 402 | } |
396 | 403 | ||
397 | filter()->apply( &todos ); | 404 | filter()->apply( &todos ); |
398 | return todos; | 405 | return todos; |
399 | } | 406 | } |
400 | void CalendarLocal::reInitAlarmSettings() | 407 | void CalendarLocal::reInitAlarmSettings() |
401 | { | 408 | { |
402 | if ( !mNextAlarmIncidence ) { | 409 | if ( !mNextAlarmIncidence ) { |
403 | nextAlarm( 1000 ); | 410 | nextAlarm( 1000 ); |
404 | } | 411 | } |
405 | deRegisterAlarm(); | 412 | deRegisterAlarm(); |
406 | mNextAlarmIncidence = 0; | 413 | mNextAlarmIncidence = 0; |
407 | checkAlarmForIncidence( 0, false ); | 414 | checkAlarmForIncidence( 0, false ); |
408 | 415 | ||
409 | } | 416 | } |
410 | 417 | ||
411 | 418 | ||
412 | 419 | ||
413 | QDateTime CalendarLocal::nextAlarm( int daysTo ) | 420 | QDateTime CalendarLocal::nextAlarm( int daysTo ) |
414 | { | 421 | { |
415 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); | 422 | QDateTime nextA = QDateTime::currentDateTime().addDays( daysTo ); |
416 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); | 423 | QDateTime start = QDateTime::currentDateTime().addSecs( 30 ); |
417 | QDateTime next; | 424 | QDateTime next; |
418 | Event *e; | 425 | Event *e; |
419 | bool ok; | 426 | bool ok; |
420 | bool found = false; | 427 | bool found = false; |
421 | int offset; | 428 | int offset; |
422 | mNextAlarmIncidence = 0; | 429 | mNextAlarmIncidence = 0; |
423 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 430 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
431 | if ( !e->calEnabled() ) continue; | ||
424 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 432 | next = e->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
425 | if ( ok ) { | 433 | if ( ok ) { |
426 | if ( next < nextA ) { | 434 | if ( next < nextA ) { |
427 | nextA = next; | 435 | nextA = next; |
428 | found = true; | 436 | found = true; |
429 | mNextSummary = e->summary(); | 437 | mNextSummary = e->summary(); |
430 | mNextAlarmEventDateTime = next.addSecs(offset ) ; | 438 | mNextAlarmEventDateTime = next.addSecs(offset ) ; |
431 | mNextAlarmIncidence = (Incidence *) e; | 439 | mNextAlarmIncidence = (Incidence *) e; |
432 | } | 440 | } |
433 | } | 441 | } |
434 | } | 442 | } |
435 | Todo *t; | 443 | Todo *t; |
436 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 444 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
445 | if ( !t->calEnabled() ) continue; | ||
437 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; | 446 | next = t->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ; |
438 | if ( ok ) { | 447 | if ( ok ) { |
439 | if ( next < nextA ) { | 448 | if ( next < nextA ) { |
440 | nextA = next; | 449 | nextA = next; |
441 | found = true; | 450 | found = true; |
442 | mNextSummary = t->summary(); | 451 | mNextSummary = t->summary(); |
443 | mNextAlarmEventDateTime = next.addSecs(offset ); | 452 | mNextAlarmEventDateTime = next.addSecs(offset ); |
444 | mNextAlarmIncidence = (Incidence *) t; | 453 | mNextAlarmIncidence = (Incidence *) t; |
445 | } | 454 | } |
446 | } | 455 | } |
447 | } | 456 | } |
448 | if ( mNextAlarmIncidence ) { | 457 | if ( mNextAlarmIncidence ) { |
449 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); | 458 | mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime); |
450 | mNextAlarmDateTime = nextA; | 459 | mNextAlarmDateTime = nextA; |
451 | } | 460 | } |
452 | return nextA; | 461 | return nextA; |
453 | } | 462 | } |
454 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) | 463 | Alarm::List CalendarLocal::alarmsTo( const QDateTime &to ) |
455 | { | 464 | { |
456 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); | 465 | return alarms( QDateTime( QDate( 1900, 1, 1 ) ), to ); |
457 | } | 466 | } |
458 | 467 | ||
459 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) | 468 | Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to ) |
460 | { | 469 | { |
461 | 470 | ||
462 | Alarm::List alarms; | 471 | Alarm::List alarms; |
463 | 472 | ||
464 | Event *e; | 473 | Event *e; |
465 | 474 | ||
466 | for( e = mEventList.first(); e; e = mEventList.next() ) { | 475 | for( e = mEventList.first(); e; e = mEventList.next() ) { |
476 | if ( !e->calEnabled() ) continue; | ||
467 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); | 477 | if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); |
468 | else appendAlarms( alarms, e, from, to ); | 478 | else appendAlarms( alarms, e, from, to ); |
469 | } | 479 | } |
470 | 480 | ||
471 | Todo *t; | 481 | Todo *t; |
472 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { | 482 | for( t = mTodoList.first(); t; t = mTodoList.next() ) { |
473 | appendAlarms( alarms, t, from, to ); | 483 | if ( !t->calEnabled() ) continue; |
484 | appendAlarms( alarms, t, from, to ); | ||
474 | } | 485 | } |
475 | 486 | ||
476 | return alarms; | 487 | return alarms; |
477 | } | 488 | } |
478 | 489 | ||
479 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, | 490 | void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, |
480 | const QDateTime &from, const QDateTime &to ) | 491 | const QDateTime &from, const QDateTime &to ) |
481 | { | 492 | { |
482 | QPtrList<Alarm> alarmList = incidence->alarms(); | 493 | QPtrList<Alarm> alarmList = incidence->alarms(); |
483 | Alarm *alarm; | 494 | Alarm *alarm; |
484 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 495 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
485 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() | 496 | // kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() |
486 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; | 497 | // << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; |
487 | if ( alarm->enabled() ) { | 498 | if ( alarm->enabled() ) { |
488 | if ( alarm->time() >= from && alarm->time() <= to ) { | 499 | if ( alarm->time() >= from && alarm->time() <= to ) { |
489 | alarms.append( alarm ); | 500 | alarms.append( alarm ); |
490 | } | 501 | } |
491 | } | 502 | } |
492 | } | 503 | } |
493 | } | 504 | } |
494 | 505 | ||
495 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, | 506 | void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, |
496 | Incidence *incidence, | 507 | Incidence *incidence, |
497 | const QDateTime &from, | 508 | const QDateTime &from, |
498 | const QDateTime &to ) | 509 | const QDateTime &to ) |
499 | { | 510 | { |
500 | 511 | ||
501 | QPtrList<Alarm> alarmList = incidence->alarms(); | 512 | QPtrList<Alarm> alarmList = incidence->alarms(); |
502 | Alarm *alarm; | 513 | Alarm *alarm; |
503 | QDateTime qdt; | 514 | QDateTime qdt; |
504 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { | 515 | for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { |
505 | if (incidence->recursOn(from.date())) { | 516 | if (incidence->recursOn(from.date())) { |
506 | qdt.setTime(alarm->time().time()); | 517 | qdt.setTime(alarm->time().time()); |
507 | qdt.setDate(from.date()); | 518 | qdt.setDate(from.date()); |
508 | } | 519 | } |
509 | else qdt = alarm->time(); | 520 | else qdt = alarm->time(); |
510 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); | 521 | // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); |
511 | if ( alarm->enabled() ) { | 522 | if ( alarm->enabled() ) { |
512 | if ( qdt >= from && qdt <= to ) { | 523 | if ( qdt >= from && qdt <= to ) { |
513 | alarms.append( alarm ); | 524 | alarms.append( alarm ); |
514 | } | 525 | } |
515 | } | 526 | } |
516 | } | 527 | } |
517 | } | 528 | } |
518 | 529 | ||
519 | 530 | ||
520 | /****************************** PROTECTED METHODS ****************************/ | 531 | /****************************** PROTECTED METHODS ****************************/ |
521 | 532 | ||
522 | // after changes are made to an event, this should be called. | 533 | // after changes are made to an event, this should be called. |
523 | void CalendarLocal::update( IncidenceBase *incidence ) | 534 | void CalendarLocal::update( IncidenceBase *incidence ) |
524 | { | 535 | { |
525 | incidence->setSyncStatus( Event::SYNCMOD ); | 536 | incidence->setSyncStatus( Event::SYNCMOD ); |
526 | incidence->setLastModified( QDateTime::currentDateTime() ); | 537 | incidence->setLastModified( QDateTime::currentDateTime() ); |
527 | // we should probably update the revision number here, | 538 | // we should probably update the revision number here, |
528 | // or internally in the Event itself when certain things change. | 539 | // or internally in the Event itself when certain things change. |
529 | // need to verify with ical documentation. | 540 | // need to verify with ical documentation. |
530 | 541 | ||
531 | setModified( true ); | 542 | setModified( true ); |
532 | } | 543 | } |
533 | 544 | ||
534 | void CalendarLocal::insertEvent( Event *event ) | 545 | void CalendarLocal::insertEvent( Event *event ) |
535 | { | 546 | { |
536 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); | 547 | if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); |
537 | } | 548 | } |
538 | 549 | ||
539 | 550 | ||
540 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) | 551 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) |
541 | { | 552 | { |
542 | QPtrList<Event> eventList; | 553 | QPtrList<Event> eventList; |
543 | 554 | ||
544 | Event *event; | 555 | Event *event; |
545 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 556 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
557 | if ( !event->calEnabled() ) continue; | ||
546 | if ( event->doesRecur() ) { | 558 | if ( event->doesRecur() ) { |
547 | if ( event->isMultiDay() ) { | 559 | if ( event->isMultiDay() ) { |
548 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); | 560 | int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); |
549 | int i; | 561 | int i; |
550 | for ( i = 0; i <= extraDays; i++ ) { | 562 | for ( i = 0; i <= extraDays; i++ ) { |
551 | if ( event->recursOn( qd.addDays( -i ) ) ) { | 563 | if ( event->recursOn( qd.addDays( -i ) ) ) { |
552 | eventList.append( event ); | 564 | eventList.append( event ); |
553 | break; | 565 | break; |
554 | } | 566 | } |
555 | } | 567 | } |
556 | } else { | 568 | } else { |
557 | if ( event->recursOn( qd ) ) | 569 | if ( event->recursOn( qd ) ) |
558 | eventList.append( event ); | 570 | eventList.append( event ); |
559 | } | 571 | } |
560 | } else { | 572 | } else { |
561 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { | 573 | if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { |
562 | eventList.append( event ); | 574 | eventList.append( event ); |
563 | } | 575 | } |
564 | } | 576 | } |
565 | } | 577 | } |
566 | 578 | ||
567 | if ( !sorted ) { | 579 | if ( !sorted ) { |
568 | return eventList; | 580 | return eventList; |
569 | } | 581 | } |
570 | 582 | ||
571 | // kdDebug(5800) << "Sorting events for date\n" << endl; | 583 | // kdDebug(5800) << "Sorting events for date\n" << endl; |
572 | // now, we have to sort it based on dtStart.time() | 584 | // now, we have to sort it based on dtStart.time() |
573 | QPtrList<Event> eventListSorted; | 585 | QPtrList<Event> eventListSorted; |
574 | Event *sortEvent; | 586 | Event *sortEvent; |
575 | for ( event = eventList.first(); event; event = eventList.next() ) { | 587 | for ( event = eventList.first(); event; event = eventList.next() ) { |
576 | sortEvent = eventListSorted.first(); | 588 | sortEvent = eventListSorted.first(); |
577 | int i = 0; | 589 | int i = 0; |
578 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) | 590 | while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) |
579 | { | 591 | { |
580 | i++; | 592 | i++; |
581 | sortEvent = eventListSorted.next(); | 593 | sortEvent = eventListSorted.next(); |
582 | } | 594 | } |
583 | eventListSorted.insert( i, event ); | 595 | eventListSorted.insert( i, event ); |
584 | } | 596 | } |
585 | return eventListSorted; | 597 | return eventListSorted; |
586 | } | 598 | } |
587 | 599 | ||
588 | 600 | ||
589 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, | 601 | QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, |
590 | bool inclusive ) | 602 | bool inclusive ) |
591 | { | 603 | { |
592 | Event *event = 0; | 604 | Event *event = 0; |
593 | 605 | ||
594 | QPtrList<Event> eventList; | 606 | QPtrList<Event> eventList; |
595 | 607 | ||
596 | // Get non-recurring events | 608 | // Get non-recurring events |
597 | for( event = mEventList.first(); event; event = mEventList.next() ) { | 609 | for( event = mEventList.first(); event; event = mEventList.next() ) { |
610 | if ( !event->calEnabled() ) continue; | ||
598 | if ( event->doesRecur() ) { | 611 | if ( event->doesRecur() ) { |
599 | QDate rStart = event->dtStart().date(); | 612 | QDate rStart = event->dtStart().date(); |
600 | bool found = false; | 613 | bool found = false; |
601 | if ( inclusive ) { | 614 | if ( inclusive ) { |
602 | if ( rStart >= start && rStart <= end ) { | 615 | if ( rStart >= start && rStart <= end ) { |
603 | // Start date of event is in range. Now check for end date. | 616 | // Start date of event is in range. Now check for end date. |
604 | // if duration is negative, event recurs forever, so do not include it. | 617 | // if duration is negative, event recurs forever, so do not include it. |
605 | if ( event->recurrence()->duration() == 0 ) { // End date set | 618 | if ( event->recurrence()->duration() == 0 ) { // End date set |
606 | QDate rEnd = event->recurrence()->endDate(); | 619 | QDate rEnd = event->recurrence()->endDate(); |
607 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 620 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
608 | found = true; | 621 | found = true; |
609 | } | 622 | } |
610 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set | 623 | } else if ( event->recurrence()->duration() > 0 ) { // Duration set |
611 | // TODO: Calculate end date from duration. Should be done in Event | 624 | // TODO: Calculate end date from duration. Should be done in Event |
612 | // For now exclude all events with a duration. | 625 | // For now exclude all events with a duration. |
613 | } | 626 | } |
614 | } | 627 | } |
615 | } else { | 628 | } else { |
616 | bool founOne; | 629 | bool founOne; |
617 | QDate next = event->getNextOccurence( start, &founOne ).date(); | 630 | QDate next = event->getNextOccurence( start, &founOne ).date(); |
618 | if ( founOne ) { | 631 | if ( founOne ) { |
619 | if ( next <= end ) { | 632 | if ( next <= end ) { |
620 | found = true; | 633 | found = true; |
621 | } | 634 | } |
622 | } | 635 | } |
623 | 636 | ||
624 | /* | 637 | /* |
625 | // crap !!! | 638 | // crap !!! |
626 | if ( rStart <= end ) { // Start date not after range | 639 | if ( rStart <= end ) { // Start date not after range |
627 | if ( rStart >= start ) { // Start date within range | 640 | if ( rStart >= start ) { // Start date within range |
628 | found = true; | 641 | found = true; |
629 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever | 642 | } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever |
630 | found = true; | 643 | found = true; |
631 | } else if ( event->recurrence()->duration() == 0 ) { // End date set | 644 | } else if ( event->recurrence()->duration() == 0 ) { // End date set |
632 | QDate rEnd = event->recurrence()->endDate(); | 645 | QDate rEnd = event->recurrence()->endDate(); |
633 | if ( rEnd >= start && rEnd <= end ) { // End date within range | 646 | if ( rEnd >= start && rEnd <= end ) { // End date within range |
634 | found = true; | 647 | found = true; |
635 | } | 648 | } |
636 | } else { // Duration set | 649 | } else { // Duration set |
637 | // TODO: Calculate end date from duration. Should be done in Event | 650 | // TODO: Calculate end date from duration. Should be done in Event |
638 | // For now include all events with a duration. | 651 | // For now include all events with a duration. |
639 | found = true; | 652 | found = true; |
640 | } | 653 | } |
641 | } | 654 | } |
642 | */ | 655 | */ |
643 | 656 | ||
644 | } | 657 | } |
645 | 658 | ||
646 | if ( found ) eventList.append( event ); | 659 | if ( found ) eventList.append( event ); |
647 | } else { | 660 | } else { |
648 | QDate s = event->dtStart().date(); | 661 | QDate s = event->dtStart().date(); |
649 | QDate e = event->dtEnd().date(); | 662 | QDate e = event->dtEnd().date(); |
650 | 663 | ||
651 | if ( inclusive ) { | 664 | if ( inclusive ) { |
652 | if ( s >= start && e <= end ) { | 665 | if ( s >= start && e <= end ) { |
653 | eventList.append( event ); | 666 | eventList.append( event ); |
654 | } | 667 | } |
655 | } else { | 668 | } else { |
656 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { | 669 | if ( ( s >= start && s <= end ) || ( e >= start && e <= end ) ) { |
657 | eventList.append( event ); | 670 | eventList.append( event ); |
658 | } | 671 | } |
659 | } | 672 | } |
660 | } | 673 | } |
661 | } | 674 | } |
662 | 675 | ||
663 | return eventList; | 676 | return eventList; |
664 | } | 677 | } |
665 | 678 | ||
666 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) | 679 | QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) |
667 | { | 680 | { |
668 | return rawEventsForDate( qdt.date() ); | 681 | return rawEventsForDate( qdt.date() ); |
669 | } | 682 | } |
670 | 683 | ||
671 | QPtrList<Event> CalendarLocal::rawEvents() | 684 | QPtrList<Event> CalendarLocal::rawEvents() |
672 | { | 685 | { |
673 | return mEventList; | 686 | QPtrList<Event> el; |
687 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
688 | if ( it->calEnabled() ) el.append( it ); | ||
689 | return el; | ||
674 | } | 690 | } |
675 | 691 | ||
676 | bool CalendarLocal::addJournal(Journal *journal) | 692 | bool CalendarLocal::addJournal(Journal *journal) |
677 | { | 693 | { |
678 | if ( journal->dtStart().isValid()) | 694 | if ( journal->dtStart().isValid()) |
679 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; | 695 | kdDebug(5800) << "Adding Journal on " << journal->dtStart().toString() << endl; |
680 | else | 696 | else |
681 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; | 697 | kdDebug(5800) << "Adding Journal without a DTSTART" << endl; |
682 | 698 | ||
683 | mJournalList.append(journal); | 699 | mJournalList.append(journal); |
684 | 700 | ||
685 | journal->registerObserver( this ); | 701 | journal->registerObserver( this ); |
686 | 702 | ||
687 | setModified( true ); | 703 | setModified( true ); |
688 | 704 | journal->setCalID( mDefaultCalendar ); | |
705 | journal->setCalEnabled( true ); | ||
689 | return true; | 706 | return true; |
690 | } | 707 | } |
691 | 708 | ||
692 | void CalendarLocal::deleteJournal( Journal *journal ) | 709 | void CalendarLocal::deleteJournal( Journal *journal ) |
693 | { | 710 | { |
694 | if ( mUndoIncidence ) delete mUndoIncidence; | 711 | if ( mUndoIncidence ) delete mUndoIncidence; |
695 | mUndoIncidence = journal->clone(); | 712 | mUndoIncidence = journal->clone(); |
696 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); | 713 | mUndoIncidence->setSummary( mUndoIncidence->description().left(25)); |
697 | if ( mJournalList.removeRef(journal) ) { | 714 | if ( mJournalList.removeRef(journal) ) { |
698 | setModified( true ); | 715 | setModified( true ); |
699 | } | 716 | } |
700 | } | 717 | } |
701 | 718 | ||
702 | Journal *CalendarLocal::journal( const QDate &date ) | 719 | Journal *CalendarLocal::journal( const QDate &date ) |
703 | { | 720 | { |
704 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; | 721 | // kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; |
705 | 722 | ||
706 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 723 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
707 | if ( it->dtStart().date() == date ) | 724 | if ( it->calEnabled() && it->dtStart().date() == date ) |
708 | return it; | 725 | return it; |
709 | 726 | ||
710 | return 0; | 727 | return 0; |
711 | } | 728 | } |
712 | 729 | ||
713 | Journal *CalendarLocal::journal( const QString &uid ) | 730 | Journal *CalendarLocal::journal( const QString &uid ) |
714 | { | 731 | { |
715 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 732 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
716 | if ( it->uid() == uid ) | 733 | if ( it->calEnabled() && it->uid() == uid ) |
717 | return it; | 734 | return it; |
718 | 735 | ||
719 | return 0; | 736 | return 0; |
720 | } | 737 | } |
721 | 738 | ||
722 | QPtrList<Journal> CalendarLocal::journals() | 739 | QPtrList<Journal> CalendarLocal::journals() |
723 | { | 740 | { |
724 | return mJournalList; | 741 | QPtrList<Journal> el; |
742 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
743 | if ( it->calEnabled() ) el.append( it ); | ||
744 | return el; | ||
725 | } | 745 | } |
726 | 746 | ||
747 | void CalendarLocal::setCalendarEnabled( int id, bool enable ) | ||
748 | { | ||
749 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
750 | if ( it->calID() == id ) it->setCalEnabled( enable ); | ||
751 | |||
752 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
753 | if ( it->calID() == id ) it->setCalEnabled( enable ); | ||
754 | |||
755 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
756 | if ( it->calID() == id ) it->setCalEnabled( enable ); | ||
757 | |||
758 | } | ||
759 | void CalendarLocal::setAlarmEnabled( int id, bool enable ) | ||
760 | { | ||
761 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
762 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | ||
763 | |||
764 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
765 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | ||
766 | |||
767 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
768 | if ( it->calID() == id ) it->setAlarmEnabled( enable ); | ||
769 | |||
770 | } | ||
771 | void CalendarLocal::setDefaultCalendarEnabledOnly() | ||
772 | { | ||
773 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
774 | it->setCalEnabled( it->calID() == mDefaultCalendar ); | ||
775 | |||
776 | for ( Event *it = mEventList.first(); it; it = mEventList.next() ) | ||
777 | it->setCalEnabled( it->calID() == mDefaultCalendar); | ||
778 | |||
779 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | ||
780 | it->setCalEnabled( it->calID() == mDefaultCalendar); | ||
781 | |||
782 | } | ||
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 98ec710..b25fcbe 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,218 +1,221 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
38 | Constructs a new calendar, with variables initialized to sane values. | 38 | Constructs a new calendar, with variables initialized to sane values. |
39 | */ | 39 | */ |
40 | CalendarLocal(); | 40 | CalendarLocal(); |
41 | /** | 41 | /** |
42 | Constructs a new calendar, with variables initialized to sane values. | 42 | Constructs a new calendar, with variables initialized to sane values. |
43 | */ | 43 | */ |
44 | CalendarLocal( const QString &timeZoneId ); | 44 | CalendarLocal( const QString &timeZoneId ); |
45 | ~CalendarLocal(); | 45 | ~CalendarLocal(); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 48 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
49 | calendar. Any information already present is lost. | 49 | calendar. Any information already present is lost. |
50 | @return true, if successfull, false on error. | 50 | @return true, if successfull, false on error. |
51 | @param fileName the name of the calendar on disk. | 51 | @param fileName the name of the calendar on disk. |
52 | */ | 52 | */ |
53 | bool load( const QString &fileName ); | 53 | bool load( const QString &fileName ); |
54 | /** | 54 | /** |
55 | Writes out the calendar to disk in the specified \a format. | 55 | Writes out the calendar to disk in the specified \a format. |
56 | CalendarLocal takes ownership of the CalFormat object. | 56 | CalendarLocal takes ownership of the CalFormat object. |
57 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
58 | @param fileName the name of the file | 58 | @param fileName the name of the file |
59 | */ | 59 | */ |
60 | bool save( const QString &fileName, CalFormat *format = 0 ); | 60 | bool save( const QString &fileName, CalFormat *format = 0 ); |
61 | 61 | ||
62 | /** | 62 | /** |
63 | Clears out the current calendar, freeing all used memory etc. etc. | 63 | Clears out the current calendar, freeing all used memory etc. etc. |
64 | */ | 64 | */ |
65 | void close(); | 65 | void close(); |
66 | 66 | ||
67 | void save() {} | 67 | void save() {} |
68 | 68 | ||
69 | /** | 69 | /** |
70 | Add Event to calendar. | 70 | Add Event to calendar. |
71 | */ | 71 | */ |
72 | void removeSyncInfo( QString syncProfile); | 72 | void removeSyncInfo( QString syncProfile); |
73 | bool addAnniversaryNoDup( Event *event ); | 73 | bool addAnniversaryNoDup( Event *event ); |
74 | bool addEventNoDup( Event *event ); | 74 | bool addEventNoDup( Event *event ); |
75 | bool addEvent( Event *event ); | 75 | bool addEvent( Event *event ); |
76 | /** | 76 | /** |
77 | Deletes an event from this calendar. | 77 | Deletes an event from this calendar. |
78 | */ | 78 | */ |
79 | void deleteEvent( Event *event ); | 79 | void deleteEvent( Event *event ); |
80 | 80 | ||
81 | /** | 81 | /** |
82 | Retrieves an event on the basis of the unique string ID. | 82 | Retrieves an event on the basis of the unique string ID. |
83 | */ | 83 | */ |
84 | Event *event( const QString &uid ); | 84 | Event *event( const QString &uid ); |
85 | /** | 85 | /** |
86 | Return unfiltered list of all events in calendar. | 86 | Return unfiltered list of all events in calendar. |
87 | */ | 87 | */ |
88 | QPtrList<Event> rawEvents(); | 88 | QPtrList<Event> rawEvents(); |
89 | QPtrList<Event> getExternLastSyncEvents(); | 89 | QPtrList<Event> getExternLastSyncEvents(); |
90 | /** | 90 | /** |
91 | Add a todo to the todolist. | 91 | Add a todo to the todolist. |
92 | */ | 92 | */ |
93 | bool addTodo( Todo *todo ); | 93 | bool addTodo( Todo *todo ); |
94 | bool addTodoNoDup( Todo *todo ); | 94 | bool addTodoNoDup( Todo *todo ); |
95 | /** | 95 | /** |
96 | Remove a todo from the todolist. | 96 | Remove a todo from the todolist. |
97 | */ | 97 | */ |
98 | void deleteTodo( Todo * ); | 98 | void deleteTodo( Todo * ); |
99 | /** | 99 | /** |
100 | Searches todolist for an event with this unique string identifier, | 100 | Searches todolist for an event with this unique string identifier, |
101 | returns a pointer or null. | 101 | returns a pointer or null. |
102 | */ | 102 | */ |
103 | Todo *todo( const QString &uid ); | 103 | Todo *todo( const QString &uid ); |
104 | /** | 104 | /** |
105 | Return list of all todos. | 105 | Return list of all todos. |
106 | */ | 106 | */ |
107 | QPtrList<Todo> rawTodos(); | 107 | QPtrList<Todo> rawTodos(); |
108 | /** | 108 | /** |
109 | Returns list of todos due on the specified date. | 109 | Returns list of todos due on the specified date. |
110 | */ | 110 | */ |
111 | QPtrList<Todo> todos( const QDate &date ); | 111 | QPtrList<Todo> todos( const QDate &date ); |
112 | /** | 112 | /** |
113 | Return list of all todos. | 113 | Return list of all todos. |
114 | 114 | ||
115 | Workaround because compiler does not recognize function of base class. | 115 | Workaround because compiler does not recognize function of base class. |
116 | */ | 116 | */ |
117 | QPtrList<Todo> todos() { return Calendar::todos(); } | 117 | QPtrList<Todo> todos() { return Calendar::todos(); } |
118 | 118 | ||
119 | /** | 119 | /** |
120 | Add a Journal entry to calendar. | 120 | Add a Journal entry to calendar. |
121 | */ | 121 | */ |
122 | bool addJournal( Journal * ); | 122 | bool addJournal( Journal * ); |
123 | /** | 123 | /** |
124 | Remove a Journal from the calendar. | 124 | Remove a Journal from the calendar. |
125 | */ | 125 | */ |
126 | void deleteJournal( Journal * ); | 126 | void deleteJournal( Journal * ); |
127 | /** | 127 | /** |
128 | Return Journal for given date. | 128 | Return Journal for given date. |
129 | */ | 129 | */ |
130 | Journal *journal( const QDate & ); | 130 | Journal *journal( const QDate & ); |
131 | /** | 131 | /** |
132 | Return Journal with given UID. | 132 | Return Journal with given UID. |
133 | */ | 133 | */ |
134 | Journal *journal( const QString &uid ); | 134 | Journal *journal( const QString &uid ); |
135 | /** | 135 | /** |
136 | Return list of all Journals stored in calendar. | 136 | Return list of all Journals stored in calendar. |
137 | */ | 137 | */ |
138 | QPtrList<Journal> journals(); | 138 | QPtrList<Journal> journals(); |
139 | 139 | ||
140 | /** | 140 | /** |
141 | Return all alarms, which ocur in the given time interval. | 141 | Return all alarms, which ocur in the given time interval. |
142 | */ | 142 | */ |
143 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); | 143 | Alarm::List alarms( const QDateTime &from, const QDateTime &to ); |
144 | 144 | ||
145 | /** | 145 | /** |
146 | Return all alarms, which ocur before given date. | 146 | Return all alarms, which ocur before given date. |
147 | */ | 147 | */ |
148 | Alarm::List alarmsTo( const QDateTime &to ); | 148 | Alarm::List alarmsTo( const QDateTime &to ); |
149 | 149 | ||
150 | QDateTime nextAlarm( int daysTo ) ; | 150 | QDateTime nextAlarm( int daysTo ) ; |
151 | QDateTime nextAlarmEventDateTime() const; | 151 | QDateTime nextAlarmEventDateTime() const; |
152 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; | 152 | void checkAlarmForIncidence( Incidence *, bool deleted ) ; |
153 | void registerAlarm(); | 153 | void registerAlarm(); |
154 | void deRegisterAlarm(); | 154 | void deRegisterAlarm(); |
155 | QString getAlarmNotification(); | 155 | QString getAlarmNotification(); |
156 | QString nextSummary() const ; | 156 | QString nextSummary() const ; |
157 | /** | 157 | /** |
158 | This method should be called whenever a Event is modified directly | 158 | This method should be called whenever a Event is modified directly |
159 | via it's pointer. It makes sure that the calendar is internally | 159 | via it's pointer. It makes sure that the calendar is internally |
160 | consistent. | 160 | consistent. |
161 | */ | 161 | */ |
162 | void update( IncidenceBase *incidence ); | 162 | void update( IncidenceBase *incidence ); |
163 | 163 | ||
164 | /** | 164 | /** |
165 | Builds and then returns a list of all events that match for the | 165 | Builds and then returns a list of all events that match for the |
166 | date specified. useful for dayView, etc. etc. | 166 | date specified. useful for dayView, etc. etc. |
167 | */ | 167 | */ |
168 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); | 168 | QPtrList<Event> rawEventsForDate( const QDate &date, bool sorted = false ); |
169 | /** | 169 | /** |
170 | Get unfiltered events for date \a qdt. | 170 | Get unfiltered events for date \a qdt. |
171 | */ | 171 | */ |
172 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); | 172 | QPtrList<Event> rawEventsForDate( const QDateTime &qdt ); |
173 | /** | 173 | /** |
174 | Get unfiltered events in a range of dates. If inclusive is set to true, | 174 | Get unfiltered events in a range of dates. If inclusive is set to true, |
175 | only events are returned, which are completely included in the range. | 175 | only events are returned, which are completely included in the range. |
176 | */ | 176 | */ |
177 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, | 177 | QPtrList<Event> rawEvents( const QDate &start, const QDate &end, |
178 | bool inclusive = false ); | 178 | bool inclusive = false ); |
179 | Todo *todo( QString, QString ); | 179 | Todo *todo( QString, QString ); |
180 | Event *event( QString, QString ); | 180 | Event *event( QString, QString ); |
181 | 181 | ||
182 | 182 | ||
183 | void setCalendarEnabled( int id, bool enable ); | ||
184 | void setAlarmEnabled( int id, bool enable ); | ||
185 | void setDefaultCalendarEnabledOnly(); | ||
183 | 186 | ||
184 | protected: | 187 | protected: |
185 | 188 | ||
186 | // Event* mNextAlarmEvent; | 189 | // Event* mNextAlarmEvent; |
187 | QString mNextSummary; | 190 | QString mNextSummary; |
188 | QString mNextAlarmEventDateTimeString; | 191 | QString mNextAlarmEventDateTimeString; |
189 | QString mLastAlarmNotificationString; | 192 | QString mLastAlarmNotificationString; |
190 | QDateTime mNextAlarmEventDateTime; | 193 | QDateTime mNextAlarmEventDateTime; |
191 | QDateTime mNextAlarmDateTime; | 194 | QDateTime mNextAlarmDateTime; |
192 | void reInitAlarmSettings(); | 195 | void reInitAlarmSettings(); |
193 | 196 | ||
194 | /** Notification function of IncidenceBase::Observer. */ | 197 | /** Notification function of IncidenceBase::Observer. */ |
195 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } | 198 | void incidenceUpdated( IncidenceBase *i ) { update( i ); } |
196 | 199 | ||
197 | /** inserts an event into its "proper place" in the calendar. */ | 200 | /** inserts an event into its "proper place" in the calendar. */ |
198 | void insertEvent( Event *event ); | 201 | void insertEvent( Event *event ); |
199 | 202 | ||
200 | /** Append alarms of incidence in interval to list of alarms. */ | 203 | /** Append alarms of incidence in interval to list of alarms. */ |
201 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, | 204 | void appendAlarms( Alarm::List &alarms, Incidence *incidence, |
202 | const QDateTime &from, const QDateTime &to ); | 205 | const QDateTime &from, const QDateTime &to ); |
203 | 206 | ||
204 | /** Append alarms of recurring events in interval to list of alarms. */ | 207 | /** Append alarms of recurring events in interval to list of alarms. */ |
205 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, | 208 | void appendRecurringAlarms( Alarm::List &alarms, Incidence *incidence, |
206 | const QDateTime &from, const QDateTime &to ); | 209 | const QDateTime &from, const QDateTime &to ); |
207 | 210 | ||
208 | private: | 211 | private: |
209 | void init(); | 212 | void init(); |
210 | 213 | ||
211 | QPtrList<Event> mEventList; | 214 | QPtrList<Event> mEventList; |
212 | QPtrList<Todo> mTodoList; | 215 | QPtrList<Todo> mTodoList; |
213 | QPtrList<Journal> mJournalList; | 216 | QPtrList<Journal> mJournalList; |
214 | }; | 217 | }; |
215 | 218 | ||
216 | } | 219 | } |
217 | 220 | ||
218 | #endif | 221 | #endif |
diff --git a/libkcal/calfilter.cpp b/libkcal/calfilter.cpp index 20078a7..3510c7d 100644 --- a/libkcal/calfilter.cpp +++ b/libkcal/calfilter.cpp | |||
@@ -1,212 +1,221 @@ | |||
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->calEnabled() ) | ||
82 | return false; | ||
81 | if ( in->typeID() == eventID ) | 83 | if ( in->typeID() == eventID ) |
82 | return filterEvent( (Event*) in ); | 84 | return filterEvent( (Event*) in ); |
83 | else if ( in->typeID() == todoID ) | 85 | else if ( in->typeID() == todoID ) |
84 | return filterTodo( (Todo*) in); | 86 | return filterTodo( (Todo*) in); |
85 | else if ( in->typeID () == journalID ) | 87 | else if ( in->typeID () == journalID ) |
86 | return filterJournal( (Journal*) in ); | 88 | return filterJournal( (Journal*) in ); |
87 | return false; | 89 | return false; |
88 | } | 90 | } |
89 | bool CalFilter::filterEvent(Event *event) | 91 | bool CalFilter::filterEvent(Event *event) |
90 | { | 92 | { |
93 | |||
94 | if ( !event->calEnabled() ) | ||
95 | return false; | ||
91 | if (mCriteria & HideEvents) | 96 | if (mCriteria & HideEvents) |
92 | return false; | 97 | return false; |
93 | if (mCriteria & HideRecurring) { | 98 | if (mCriteria & HideRecurring) { |
94 | if (event->recurrence()->doesRecur()) return false; | 99 | if (event->recurrence()->doesRecur()) return false; |
95 | } | 100 | } |
96 | 101 | ||
97 | return filterIncidence(event); | 102 | return filterIncidence(event); |
98 | } | 103 | } |
99 | bool CalFilter::filterJournal(Journal *j) | 104 | bool CalFilter::filterJournal(Journal *j) |
100 | { | 105 | { |
106 | if ( !j->calEnabled() ) | ||
107 | return false; | ||
101 | if (mCriteria & HideJournals) | 108 | if (mCriteria & HideJournals) |
102 | return false; | 109 | return false; |
103 | return true; | 110 | return true; |
104 | } | 111 | } |
105 | bool CalFilter::filterTodo(Todo *todo) | 112 | bool CalFilter::filterTodo(Todo *todo) |
106 | { | 113 | { |
114 | if ( !todo->calEnabled() ) | ||
115 | return false; | ||
107 | if (mCriteria & HideTodos) | 116 | if (mCriteria & HideTodos) |
108 | return false; | 117 | return false; |
109 | if (mCriteria & HideCompleted) { | 118 | if (mCriteria & HideCompleted) { |
110 | if (todo->isCompleted()) return false; | 119 | if (todo->isCompleted()) return false; |
111 | } | 120 | } |
112 | 121 | ||
113 | return filterIncidence(todo); | 122 | return filterIncidence(todo); |
114 | } | 123 | } |
115 | bool CalFilter::showCategories() | 124 | bool CalFilter::showCategories() |
116 | { | 125 | { |
117 | return mCriteria & ShowCategories; | 126 | return mCriteria & ShowCategories; |
118 | } | 127 | } |
119 | int CalFilter::getSecrecy() | 128 | int CalFilter::getSecrecy() |
120 | { | 129 | { |
121 | if ( (mCriteria & ShowPublic )) | 130 | if ( (mCriteria & ShowPublic )) |
122 | return Incidence::SecrecyPublic; | 131 | return Incidence::SecrecyPublic; |
123 | if ( (mCriteria & ShowPrivate )) | 132 | if ( (mCriteria & ShowPrivate )) |
124 | return Incidence::SecrecyPrivate; | 133 | return Incidence::SecrecyPrivate; |
125 | if ( (mCriteria & ShowConfidential )) | 134 | if ( (mCriteria & ShowConfidential )) |
126 | return Incidence::SecrecyConfidential; | 135 | return Incidence::SecrecyConfidential; |
127 | return Incidence::SecrecyPublic; | 136 | return Incidence::SecrecyPublic; |
128 | } | 137 | } |
129 | bool CalFilter::filterIncidence(Incidence *incidence) | 138 | bool CalFilter::filterIncidence(Incidence *incidence) |
130 | { | 139 | { |
131 | if ( mCriteria > 7 ) { | 140 | if ( mCriteria > 7 ) { |
132 | switch (incidence->secrecy()) { | 141 | switch (incidence->secrecy()) { |
133 | case Incidence::SecrecyPublic: | 142 | case Incidence::SecrecyPublic: |
134 | if (! (mCriteria & ShowPublic )) | 143 | if (! (mCriteria & ShowPublic )) |
135 | return false; | 144 | return false; |
136 | break; | 145 | break; |
137 | case Incidence::SecrecyPrivate: | 146 | case Incidence::SecrecyPrivate: |
138 | if (! (mCriteria & ShowPrivate )) | 147 | if (! (mCriteria & ShowPrivate )) |
139 | return false; | 148 | return false; |
140 | break; | 149 | break; |
141 | case Incidence::SecrecyConfidential: | 150 | case Incidence::SecrecyConfidential: |
142 | if (! (mCriteria & ShowConfidential )) | 151 | if (! (mCriteria & ShowConfidential )) |
143 | return false; | 152 | return false; |
144 | break; | 153 | break; |
145 | default: | 154 | default: |
146 | return false; | 155 | return false; |
147 | break; | 156 | break; |
148 | } | 157 | } |
149 | } | 158 | } |
150 | 159 | ||
151 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; | 160 | // kdDebug(5800) << "CalFilter::filterEvent(): " << event->getSummary() << endl; |
152 | 161 | ||
153 | if (mCriteria & ShowCategories) { | 162 | if (mCriteria & ShowCategories) { |
154 | for (QStringList::Iterator it = mCategoryList.begin(); | 163 | for (QStringList::Iterator it = mCategoryList.begin(); |
155 | it != mCategoryList.end(); ++it ) { | 164 | it != mCategoryList.end(); ++it ) { |
156 | QStringList incidenceCategories = incidence->categories(); | 165 | QStringList incidenceCategories = incidence->categories(); |
157 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 166 | for (QStringList::Iterator it2 = incidenceCategories.begin(); |
158 | it2 != incidenceCategories.end(); ++it2 ) { | 167 | it2 != incidenceCategories.end(); ++it2 ) { |
159 | if ((*it) == (*it2)) { | 168 | if ((*it) == (*it2)) { |
160 | return true; | 169 | return true; |
161 | } | 170 | } |
162 | } | 171 | } |
163 | } | 172 | } |
164 | return false; | 173 | return false; |
165 | } else { | 174 | } else { |
166 | for (QStringList::Iterator it = mCategoryList.begin(); | 175 | for (QStringList::Iterator it = mCategoryList.begin(); |
167 | it != mCategoryList.end(); ++it ) { | 176 | it != mCategoryList.end(); ++it ) { |
168 | QStringList incidenceCategories = incidence->categories(); | 177 | QStringList incidenceCategories = incidence->categories(); |
169 | for (QStringList::Iterator it2 = incidenceCategories.begin(); | 178 | for (QStringList::Iterator it2 = incidenceCategories.begin(); |
170 | it2 != incidenceCategories.end(); ++it2 ) { | 179 | it2 != incidenceCategories.end(); ++it2 ) { |
171 | if ((*it) == (*it2)) { | 180 | if ((*it) == (*it2)) { |
172 | return false; | 181 | return false; |
173 | } | 182 | } |
174 | } | 183 | } |
175 | } | 184 | } |
176 | return true; | 185 | return true; |
177 | } | 186 | } |
178 | 187 | ||
179 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; | 188 | // kdDebug(5800) << "CalFilter::filterEvent(): passed" << endl; |
180 | 189 | ||
181 | return true; | 190 | return true; |
182 | } | 191 | } |
183 | 192 | ||
184 | void CalFilter::setEnabled(bool enabled) | 193 | void CalFilter::setEnabled(bool enabled) |
185 | { | 194 | { |
186 | mEnabled = enabled; | 195 | mEnabled = enabled; |
187 | } | 196 | } |
188 | 197 | ||
189 | bool CalFilter::isEnabled() | 198 | bool CalFilter::isEnabled() |
190 | { | 199 | { |
191 | return mEnabled; | 200 | return mEnabled; |
192 | } | 201 | } |
193 | 202 | ||
194 | void CalFilter::setCriteria(int criteria) | 203 | void CalFilter::setCriteria(int criteria) |
195 | { | 204 | { |
196 | mCriteria = criteria; | 205 | mCriteria = criteria; |
197 | } | 206 | } |
198 | 207 | ||
199 | int CalFilter::criteria() | 208 | int CalFilter::criteria() |
200 | { | 209 | { |
201 | return mCriteria; | 210 | return mCriteria; |
202 | } | 211 | } |
203 | 212 | ||
204 | void CalFilter::setCategoryList(const QStringList &categoryList) | 213 | void CalFilter::setCategoryList(const QStringList &categoryList) |
205 | { | 214 | { |
206 | mCategoryList = categoryList; | 215 | mCategoryList = categoryList; |
207 | } | 216 | } |
208 | 217 | ||
209 | QStringList CalFilter::categoryList() | 218 | QStringList CalFilter::categoryList() |
210 | { | 219 | { |
211 | return mCategoryList; | 220 | return mCategoryList; |
212 | } | 221 | } |
diff --git a/libkcal/calfilter.h b/libkcal/calfilter.h index 29db441..e349770 100644 --- a/libkcal/calfilter.h +++ b/libkcal/calfilter.h | |||
@@ -1,129 +1,130 @@ | |||
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 _CALFILTER_H | 21 | #ifndef _CALFILTER_H |
22 | #define _CALFILTER_H | 22 | #define _CALFILTER_H |
23 | 23 | ||
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include "event.h" | 27 | #include "event.h" |
28 | #include "todo.h" | 28 | #include "todo.h" |
29 | #include "journal.h" | ||
29 | 30 | ||
30 | namespace KCal { | 31 | namespace KCal { |
31 | 32 | ||
32 | /** | 33 | /** |
33 | Filter for calendar objects. | 34 | Filter for calendar objects. |
34 | */ | 35 | */ |
35 | class CalFilter { | 36 | class CalFilter { |
36 | public: | 37 | public: |
37 | /** Construct filter. */ | 38 | /** Construct filter. */ |
38 | CalFilter(); | 39 | CalFilter(); |
39 | /** Construct filter with name */ | 40 | /** Construct filter with name */ |
40 | CalFilter(const QString &name); | 41 | CalFilter(const QString &name); |
41 | /** Destruct filter. */ | 42 | /** Destruct filter. */ |
42 | ~CalFilter(); | 43 | ~CalFilter(); |
43 | 44 | ||
44 | /** | 45 | /** |
45 | Set name of filter. | 46 | Set name of filter. |
46 | */ | 47 | */ |
47 | void setName(const QString &name) { mName = name; } | 48 | void setName(const QString &name) { mName = name; } |
48 | /** | 49 | /** |
49 | Return name of filter. | 50 | Return name of filter. |
50 | */ | 51 | */ |
51 | QString name() const { return mName; } | 52 | QString name() const { return mName; } |
52 | 53 | ||
53 | /** | 54 | /** |
54 | Apply filter to eventlist, all events not matching filter criterias are | 55 | Apply filter to eventlist, all events not matching filter criterias are |
55 | removed from the list. | 56 | removed from the list. |
56 | */ | 57 | */ |
57 | void apply(QPtrList<Event> *eventlist); | 58 | void apply(QPtrList<Event> *eventlist); |
58 | 59 | ||
59 | /** | 60 | /** |
60 | Apply filter to todolist, all todos not matching filter criterias are | 61 | Apply filter to todolist, all todos not matching filter criterias are |
61 | removed from the list. | 62 | removed from the list. |
62 | */ | 63 | */ |
63 | void apply(QPtrList<Todo> *todolist); | 64 | void apply(QPtrList<Todo> *todolist); |
64 | bool CalFilter::filterCalendarItem(Incidence *in); | 65 | bool CalFilter::filterCalendarItem(Incidence *in); |
65 | bool CalFilter::filterJournal(Journal *in); | 66 | bool CalFilter::filterJournal(Journal *in); |
66 | /** | 67 | /** |
67 | Apply filter criteria on the specified event. Return true, if event passes | 68 | Apply filter criteria on the specified event. Return true, if event passes |
68 | criteria, otherwise return false. | 69 | criteria, otherwise return false. |
69 | */ | 70 | */ |
70 | bool filterEvent(Event *); | 71 | bool filterEvent(Event *); |
71 | 72 | ||
72 | /** | 73 | /** |
73 | Apply filter criteria on the specified todo. Return true, if event passes | 74 | Apply filter criteria on the specified todo. Return true, if event passes |
74 | criteria, otherwise return false. | 75 | criteria, otherwise return false. |
75 | */ | 76 | */ |
76 | bool filterTodo(Todo *); | 77 | bool filterTodo(Todo *); |
77 | 78 | ||
78 | /** | 79 | /** |
79 | Apply filter criteria on the specified incidence. Return true, if event passes | 80 | Apply filter criteria on the specified incidence. Return true, if event passes |
80 | criteria, otherwise return false. | 81 | criteria, otherwise return false. |
81 | */ | 82 | */ |
82 | bool filterIncidence(Incidence *); | 83 | bool filterIncidence(Incidence *); |
83 | 84 | ||
84 | /** | 85 | /** |
85 | Enable or disable filter. | 86 | Enable or disable filter. |
86 | */ | 87 | */ |
87 | void setEnabled(bool); | 88 | void setEnabled(bool); |
88 | /** | 89 | /** |
89 | Return wheter the filter is enabled or not. | 90 | Return wheter the filter is enabled or not. |
90 | */ | 91 | */ |
91 | bool isEnabled(); | 92 | bool isEnabled(); |
92 | bool showCategories(); | 93 | bool showCategories(); |
93 | int getSecrecy(); | 94 | int getSecrecy(); |
94 | /** | 95 | /** |
95 | Set list of categories, which is used for showing/hiding categories of | 96 | Set list of categories, which is used for showing/hiding categories of |
96 | events. | 97 | events. |
97 | See related functions. | 98 | See related functions. |
98 | */ | 99 | */ |
99 | void setCategoryList(const QStringList &); | 100 | void setCategoryList(const QStringList &); |
100 | /** | 101 | /** |
101 | Return category list, used for showing/hiding categories of events. | 102 | Return category list, used for showing/hiding categories of events. |
102 | See related functions. | 103 | See related functions. |
103 | */ | 104 | */ |
104 | QStringList categoryList(); | 105 | QStringList categoryList(); |
105 | 106 | ||
106 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; | 107 | enum { HideRecurring = 1, HideCompleted = 2, ShowCategories = 4 ,ShowPublic = 8, ShowPrivate = 16, ShowConfidential = 32, HideEvents = 64, HideTodos = 128, HideJournals = 256 }; |
107 | 108 | ||
108 | /** | 109 | /** |
109 | Set criteria, which have to be fulfilled by events passing the filter. | 110 | Set criteria, which have to be fulfilled by events passing the filter. |
110 | */ | 111 | */ |
111 | void setCriteria(int); | 112 | void setCriteria(int); |
112 | /** | 113 | /** |
113 | Get inclusive filter criteria. | 114 | Get inclusive filter criteria. |
114 | */ | 115 | */ |
115 | int criteria(); | 116 | int criteria(); |
116 | 117 | ||
117 | private: | 118 | private: |
118 | QString mName; | 119 | QString mName; |
119 | 120 | ||
120 | int mCriteria; | 121 | int mCriteria; |
121 | 122 | ||
122 | bool mEnabled; | 123 | bool mEnabled; |
123 | 124 | ||
124 | QStringList mCategoryList; | 125 | QStringList mCategoryList; |
125 | }; | 126 | }; |
126 | 127 | ||
127 | } | 128 | } |
128 | 129 | ||
129 | #endif /* _CALFILTER_H */ | 130 | #endif /* _CALFILTER_H */ |
diff --git a/libkcal/event.cpp b/libkcal/event.cpp index 9b99855..7cd81fa 100644 --- a/libkcal/event.cpp +++ b/libkcal/event.cpp | |||
@@ -1,221 +1,223 @@ | |||
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 "event.h" | 25 | #include "event.h" |
26 | 26 | ||
27 | using namespace KCal; | 27 | using namespace KCal; |
28 | 28 | ||
29 | Event::Event() : | 29 | Event::Event() : |
30 | mHasEndDate( false ), mTransparency( Opaque ) | 30 | mHasEndDate( false ), mTransparency( Opaque ) |
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | Event::Event(const Event &e) : Incidence(e) | 34 | Event::Event(const Event &e) : Incidence(e) |
35 | { | 35 | { |
36 | mDtEnd = e.mDtEnd; | 36 | mDtEnd = e.mDtEnd; |
37 | mHasEndDate = e.mHasEndDate; | 37 | mHasEndDate = e.mHasEndDate; |
38 | mTransparency = e.mTransparency; | 38 | mTransparency = e.mTransparency; |
39 | } | 39 | } |
40 | 40 | ||
41 | Event::~Event() | 41 | Event::~Event() |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | Incidence *Event::clone() | 45 | Incidence *Event::clone() |
46 | { | 46 | { |
47 | return new Event(*this); | 47 | return new Event(*this); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool KCal::operator==( const Event& e1, const Event& e2 ) | 50 | bool KCal::operator==( const Event& e1, const Event& e2 ) |
51 | { | 51 | { |
52 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && | 52 | return operator==( (const Incidence&)e1, (const Incidence&)e2 ) && |
53 | e1.dtEnd() == e2.dtEnd() && | 53 | e1.dtEnd() == e2.dtEnd() && |
54 | e1.hasEndDate() == e2.hasEndDate() && | 54 | e1.hasEndDate() == e2.hasEndDate() && |
55 | e1.transparency() == e2.transparency(); | 55 | e1.transparency() == e2.transparency(); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | ||
59 | bool Event::contains ( Event* from ) | 59 | bool Event::contains ( Event* from ) |
60 | { | 60 | { |
61 | 61 | ||
62 | if ( !from->summary().isEmpty() ) | 62 | if ( !from->summary().isEmpty() ) |
63 | if ( !summary().startsWith( from->summary() )) | 63 | if ( !summary().startsWith( from->summary() )) |
64 | return false; | 64 | return false; |
65 | if ( from->dtStart().isValid() ) | 65 | if ( from->dtStart().isValid() ) |
66 | if (dtStart() != from->dtStart() ) | 66 | if (dtStart() != from->dtStart() ) |
67 | return false; | 67 | return false; |
68 | if ( from->dtEnd().isValid() ) | 68 | if ( from->dtEnd().isValid() ) |
69 | if ( dtEnd() != from->dtEnd() ) | 69 | if ( dtEnd() != from->dtEnd() ) |
70 | return false; | 70 | return false; |
71 | if ( !from->location().isEmpty() ) | 71 | if ( !from->location().isEmpty() ) |
72 | if ( !location().startsWith( from->location() ) ) | 72 | if ( !location().startsWith( from->location() ) ) |
73 | return false; | 73 | return false; |
74 | if ( !from->description().isEmpty() ) | 74 | if ( !from->description().isEmpty() ) |
75 | if ( !description().startsWith( from->description() )) | 75 | if ( !description().startsWith( from->description() )) |
76 | return false; | 76 | return false; |
77 | if ( from->alarms().count() ) { | 77 | if ( from->alarms().count() ) { |
78 | Alarm *a = from->alarms().first(); | 78 | Alarm *a = from->alarms().first(); |
79 | if ( a->enabled() ){ | 79 | if ( a->enabled() ){ |
80 | if ( !alarms().count() ) | 80 | if ( !alarms().count() ) |
81 | return false; | 81 | return false; |
82 | Alarm *b = alarms().first(); | 82 | Alarm *b = alarms().first(); |
83 | if( ! b->enabled() ) | 83 | if( ! b->enabled() ) |
84 | return false; | 84 | return false; |
85 | if ( ! (a->offset() == b->offset() )) | 85 | if ( ! (a->offset() == b->offset() )) |
86 | return false; | 86 | return false; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | QStringList cat = categories(); | 89 | QStringList cat = categories(); |
90 | QStringList catFrom = from->categories(); | 90 | QStringList catFrom = from->categories(); |
91 | QString nCat; | 91 | QString nCat; |
92 | unsigned int iii; | 92 | unsigned int iii; |
93 | for ( iii = 0; iii < catFrom.count();++iii ) { | 93 | for ( iii = 0; iii < catFrom.count();++iii ) { |
94 | nCat = catFrom[iii]; | 94 | nCat = catFrom[iii]; |
95 | if ( !nCat.isEmpty() ) | 95 | if ( !nCat.isEmpty() ) |
96 | if ( !cat.contains( nCat )) { | 96 | if ( !cat.contains( nCat )) { |
97 | return false; | 97 | return false; |
98 | } | 98 | } |
99 | } | 99 | } |
100 | if ( from->doesRecur() ) | 100 | if ( from->doesRecur() ) |
101 | if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) | 101 | if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) ) |
102 | return false; | 102 | return false; |
103 | return true; | 103 | return true; |
104 | } | 104 | } |
105 | 105 | ||
106 | void Event::setDtEnd(const QDateTime &dtEnd) | 106 | void Event::setDtEnd(const QDateTime &dtEnd) |
107 | { | 107 | { |
108 | if (mReadOnly) return; | 108 | if (mReadOnly) return; |
109 | 109 | ||
110 | mDtEnd = getEvenTime( dtEnd ); | 110 | mDtEnd = getEvenTime( dtEnd ); |
111 | 111 | ||
112 | setHasEndDate(true); | 112 | setHasEndDate(true); |
113 | setHasDuration(false); | 113 | setHasDuration(false); |
114 | 114 | ||
115 | updated(); | 115 | updated(); |
116 | } | 116 | } |
117 | 117 | ||
118 | QDateTime Event::dtEnd() const | 118 | QDateTime Event::dtEnd() const |
119 | { | 119 | { |
120 | if (hasEndDate()) return mDtEnd; | 120 | if (hasEndDate()) return mDtEnd; |
121 | if (hasDuration()) return dtStart().addSecs(duration()); | 121 | if (hasDuration()) return dtStart().addSecs(duration()); |
122 | 122 | ||
123 | return dtStart(); | 123 | return dtStart(); |
124 | } | 124 | } |
125 | 125 | ||
126 | QString Event::dtEndTimeStr() const | 126 | QString Event::dtEndTimeStr() const |
127 | { | 127 | { |
128 | return KGlobal::locale()->formatTime(mDtEnd.time()); | 128 | return KGlobal::locale()->formatTime(mDtEnd.time()); |
129 | } | 129 | } |
130 | 130 | ||
131 | QString Event::dtEndDateStr(bool shortfmt) const | 131 | QString Event::dtEndDateStr(bool shortfmt) const |
132 | { | 132 | { |
133 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); | 133 | return KGlobal::locale()->formatDate(mDtEnd.date(),shortfmt); |
134 | } | 134 | } |
135 | 135 | ||
136 | QString Event::dtEndStr(bool shortfmt) const | 136 | QString Event::dtEndStr(bool shortfmt) const |
137 | { | 137 | { |
138 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); | 138 | return KGlobal::locale()->formatDateTime(mDtEnd, shortfmt); |
139 | } | 139 | } |
140 | 140 | ||
141 | void Event::setHasEndDate(bool b) | 141 | void Event::setHasEndDate(bool b) |
142 | { | 142 | { |
143 | mHasEndDate = b; | 143 | mHasEndDate = b; |
144 | } | 144 | } |
145 | 145 | ||
146 | bool Event::hasEndDate() const | 146 | bool Event::hasEndDate() const |
147 | { | 147 | { |
148 | return mHasEndDate; | 148 | return mHasEndDate; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool Event::isMultiDay() const | 151 | bool Event::isMultiDay() const |
152 | { | 152 | { |
153 | bool multi = !(dtStart().date() == dtEnd().date()); | 153 | bool multi = !(dtStart().date() == dtEnd().date()); |
154 | return multi; | 154 | return multi; |
155 | } | 155 | } |
156 | 156 | ||
157 | void Event::setTransparency(Event::Transparency transparency) | 157 | void Event::setTransparency(Event::Transparency transparency) |
158 | { | 158 | { |
159 | if (mReadOnly) return; | 159 | if (mReadOnly) return; |
160 | mTransparency = transparency; | 160 | mTransparency = transparency; |
161 | updated(); | 161 | updated(); |
162 | } | 162 | } |
163 | 163 | ||
164 | Event::Transparency Event::transparency() const | 164 | Event::Transparency Event::transparency() const |
165 | { | 165 | { |
166 | return mTransparency; | 166 | return mTransparency; |
167 | } | 167 | } |
168 | 168 | ||
169 | void Event::setDuration(int seconds) | 169 | void Event::setDuration(int seconds) |
170 | { | 170 | { |
171 | setHasEndDate(false); | 171 | setHasEndDate(false); |
172 | Incidence::setDuration(seconds); | 172 | Incidence::setDuration(seconds); |
173 | } | 173 | } |
174 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const | 174 | QDateTime Event::getNextAlarmDateTime( bool * ok, int * offset, QDateTime start_dt ) const |
175 | { | 175 | { |
176 | 176 | *ok = false; | |
177 | if ( !alarmEnabled() ) | ||
178 | return QDateTime (); | ||
177 | bool yes; | 179 | bool yes; |
178 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); | 180 | QDateTime incidenceStart = getNextOccurence( start_dt, &yes ); |
179 | if ( ! yes || cancelled() ) { | 181 | if ( ! yes || cancelled() ) { |
180 | *ok = false; | 182 | *ok = false; |
181 | return QDateTime (); | 183 | return QDateTime (); |
182 | } | 184 | } |
183 | 185 | ||
184 | bool enabled = false; | 186 | bool enabled = false; |
185 | Alarm* alarm; | 187 | Alarm* alarm; |
186 | int off = 0; | 188 | int off = 0; |
187 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; | 189 | QDateTime alarmStart = QDateTime::currentDateTime().addDays( 3650 );; |
188 | // if ( QDateTime::currentDateTime() > incidenceStart ){ | 190 | // if ( QDateTime::currentDateTime() > incidenceStart ){ |
189 | // *ok = false; | 191 | // *ok = false; |
190 | // return incidenceStart; | 192 | // return incidenceStart; |
191 | // } | 193 | // } |
192 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { | 194 | for (QPtrListIterator<Alarm> it(mAlarms); (alarm = it.current()) != 0; ++it) { |
193 | if (alarm->enabled()) { | 195 | if (alarm->enabled()) { |
194 | if ( alarm->hasTime () ) { | 196 | if ( alarm->hasTime () ) { |
195 | if ( alarm->time() < alarmStart ) { | 197 | if ( alarm->time() < alarmStart ) { |
196 | alarmStart = alarm->time(); | 198 | alarmStart = alarm->time(); |
197 | enabled = true; | 199 | enabled = true; |
198 | off = alarmStart.secsTo( incidenceStart ); | 200 | off = alarmStart.secsTo( incidenceStart ); |
199 | } | 201 | } |
200 | 202 | ||
201 | } else { | 203 | } else { |
202 | int secs = alarm->startOffset().asSeconds(); | 204 | int secs = alarm->startOffset().asSeconds(); |
203 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { | 205 | if ( incidenceStart.addSecs( secs ) < alarmStart ) { |
204 | alarmStart = incidenceStart.addSecs( secs ); | 206 | alarmStart = incidenceStart.addSecs( secs ); |
205 | enabled = true; | 207 | enabled = true; |
206 | off = -secs; | 208 | off = -secs; |
207 | } | 209 | } |
208 | } | 210 | } |
209 | } | 211 | } |
210 | } | 212 | } |
211 | if ( enabled ) { | 213 | if ( enabled ) { |
212 | if ( alarmStart > start_dt ) { | 214 | if ( alarmStart > start_dt ) { |
213 | *ok = true; | 215 | *ok = true; |
214 | * offset = off; | 216 | * offset = off; |
215 | return alarmStart; | 217 | return alarmStart; |
216 | } | 218 | } |
217 | } | 219 | } |
218 | *ok = false; | 220 | *ok = false; |
219 | return QDateTime (); | 221 | return QDateTime (); |
220 | 222 | ||
221 | } | 223 | } |
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp index b5fe2e6..2ddbb01 100644 --- a/libkcal/incidencebase.cpp +++ b/libkcal/incidencebase.cpp | |||
@@ -1,390 +1,423 @@ | |||
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 | #include <kidmanager.h> | 24 | #include <kidmanager.h> |
25 | 25 | ||
26 | #include "calformat.h" | 26 | #include "calformat.h" |
27 | #include "syncdefines.h" | 27 | #include "syncdefines.h" |
28 | 28 | ||
29 | #include "incidencebase.h" | 29 | #include "incidencebase.h" |
30 | 30 | ||
31 | using namespace KCal; | 31 | using namespace KCal; |
32 | 32 | ||
33 | IncidenceBase::IncidenceBase() : | 33 | IncidenceBase::IncidenceBase() : |
34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), | 34 | mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), |
35 | mPilotId(0), mSyncStatus(SYNCMOD) | 35 | mPilotId(0), mSyncStatus(SYNCMOD) |
36 | { | 36 | { |
37 | setUid(CalFormat::createUniqueId()); | 37 | setUid(CalFormat::createUniqueId()); |
38 | mOrganizer = ""; | 38 | mOrganizer = ""; |
39 | mFloats = false; | 39 | mFloats = false; |
40 | mDuration = 0; | 40 | mDuration = 0; |
41 | mHasDuration = false; | 41 | mHasDuration = false; |
42 | mPilotId = 0; | 42 | mPilotId = 0; |
43 | mExternalId = ":"; | 43 | mExternalId = ":"; |
44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 44 | mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
45 | mSyncStatus = 0; | 45 | mSyncStatus = 0; |
46 | mAttendees.setAutoDelete( true ); | 46 | mAttendees.setAutoDelete( true ); |
47 | mCalEnabled = true; | ||
48 | mAlarmEnabled = true; | ||
49 | mCalID = 0; | ||
47 | } | 50 | } |
48 | 51 | ||
49 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : | 52 | IncidenceBase::IncidenceBase(const IncidenceBase &i) : |
50 | CustomProperties( i ) | 53 | CustomProperties( i ) |
51 | { | 54 | { |
55 | |||
52 | mReadOnly = i.mReadOnly; | 56 | mReadOnly = i.mReadOnly; |
53 | mDtStart = i.mDtStart; | 57 | mDtStart = i.mDtStart; |
54 | mDuration = i.mDuration; | 58 | mDuration = i.mDuration; |
55 | mHasDuration = i.mHasDuration; | 59 | mHasDuration = i.mHasDuration; |
56 | mOrganizer = i.mOrganizer; | 60 | mOrganizer = i.mOrganizer; |
57 | mUid = i.mUid; | 61 | mUid = i.mUid; |
62 | mCalEnabled = i.mCalEnabled; | ||
63 | mAlarmEnabled = i.mAlarmEnabled; | ||
64 | mCalID = i.mCalID; | ||
58 | QPtrList<Attendee> attendees = i.attendees(); | 65 | QPtrList<Attendee> attendees = i.attendees(); |
59 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { | 66 | for( Attendee *a = attendees.first(); a; a = attendees.next() ) { |
60 | mAttendees.append( new Attendee( *a ) ); | 67 | mAttendees.append( new Attendee( *a ) ); |
61 | } | 68 | } |
62 | mFloats = i.mFloats; | 69 | mFloats = i.mFloats; |
63 | mLastModified = i.mLastModified; | 70 | mLastModified = i.mLastModified; |
64 | mPilotId = i.mPilotId; | 71 | mPilotId = i.mPilotId; |
65 | mTempSyncStat = i.mTempSyncStat; | 72 | mTempSyncStat = i.mTempSyncStat; |
66 | mSyncStatus = i.mSyncStatus; | 73 | mSyncStatus = i.mSyncStatus; |
67 | mExternalId = i.mExternalId; | 74 | mExternalId = i.mExternalId; |
68 | // The copied object is a new one, so it isn't observed by the observer | 75 | // The copied object is a new one, so it isn't observed by the observer |
69 | // of the original object. | 76 | // of the original object. |
70 | mObservers.clear(); | 77 | mObservers.clear(); |
71 | 78 | ||
72 | mAttendees.setAutoDelete( true ); | 79 | mAttendees.setAutoDelete( true ); |
73 | } | 80 | } |
74 | 81 | ||
75 | IncidenceBase::~IncidenceBase() | 82 | IncidenceBase::~IncidenceBase() |
76 | { | 83 | { |
77 | } | 84 | } |
78 | 85 | ||
79 | 86 | ||
80 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) | 87 | bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) |
81 | { | 88 | { |
82 | // do not compare mSyncStatus and mExternalId | 89 | // do not compare mSyncStatus and mExternalId |
83 | if( i1.attendees().count() != i2.attendees().count() ) { | 90 | if( i1.attendees().count() != i2.attendees().count() ) { |
84 | return false; // no need to check further | 91 | return false; // no need to check further |
85 | } | 92 | } |
86 | if ( i1.attendees().count() > 0 ) { | 93 | if ( i1.attendees().count() > 0 ) { |
87 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; | 94 | Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; |
88 | while ( a1 ) { | 95 | while ( a1 ) { |
89 | if ( !( (*a1) == (*a2)) ) | 96 | if ( !( (*a1) == (*a2)) ) |
90 | { | 97 | { |
91 | //qDebug("Attendee not equal "); | 98 | //qDebug("Attendee not equal "); |
92 | return false; | 99 | return false; |
93 | } | 100 | } |
94 | a1 = i1.attendees().next(); | 101 | a1 = i1.attendees().next(); |
95 | a2 = i2.attendees().next(); | 102 | a2 = i2.attendees().next(); |
96 | } | 103 | } |
97 | } | 104 | } |
98 | //if ( i1.dtStart() != i2.dtStart() ) | 105 | //if ( i1.dtStart() != i2.dtStart() ) |
99 | // return false; | 106 | // return false; |
100 | #if 0 | 107 | #if 0 |
101 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); | 108 | qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); |
102 | qDebug("1 %d ",i1.duration() == i2.duration() ); | 109 | qDebug("1 %d ",i1.duration() == i2.duration() ); |
103 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); | 110 | qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); |
104 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); | 111 | qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); |
105 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); | 112 | qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); |
106 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); | 113 | qDebug("6 %d ",i1.organizer() == i2.organizer() ); |
107 | 114 | ||
108 | #endif | 115 | #endif |
109 | if ( i1.hasDuration() == i2.hasDuration() ) { | 116 | if ( i1.hasDuration() == i2.hasDuration() ) { |
110 | if ( i1.hasDuration() ) { | 117 | if ( i1.hasDuration() ) { |
111 | if ( i1.duration() != i2.duration() ) | 118 | if ( i1.duration() != i2.duration() ) |
112 | return false; | 119 | return false; |
113 | } | 120 | } |
114 | } else { | 121 | } else { |
115 | return false; | 122 | return false; |
116 | } | 123 | } |
117 | 124 | ||
118 | return ( i1.organizer() == i2.organizer() && | 125 | return ( i1.organizer() == i2.organizer() && |
119 | // i1.uid() == i2.uid() && | 126 | // i1.uid() == i2.uid() && |
120 | // Don't compare lastModified, otherwise the operator is not | 127 | // Don't compare lastModified, otherwise the operator is not |
121 | // of much use. We are not comparing for identity, after all. | 128 | // of much use. We are not comparing for identity, after all. |
122 | i1.doesFloat() == i2.doesFloat() && | 129 | i1.doesFloat() == i2.doesFloat() && |
123 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); | 130 | i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); |
124 | // no need to compare mObserver | 131 | // no need to compare mObserver |
125 | } | 132 | } |
126 | 133 | ||
127 | 134 | ||
128 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) | 135 | QDateTime IncidenceBase::getEvenTime( QDateTime dt ) |
129 | { | 136 | { |
130 | QTime t = dt.time(); | 137 | QTime t = dt.time(); |
131 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 138 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
132 | return dt; | 139 | return dt; |
133 | } | 140 | } |
134 | 141 | ||
142 | void IncidenceBase::setCalID( int id ) | ||
143 | { | ||
144 | mCalID = id; | ||
145 | } | ||
146 | int IncidenceBase::calID() const | ||
147 | { | ||
148 | return mCalID; | ||
149 | } | ||
150 | void IncidenceBase::setCalEnabled( bool b ) | ||
151 | { | ||
152 | mCalEnabled = b; | ||
153 | } | ||
154 | bool IncidenceBase::calEnabled() const | ||
155 | { | ||
156 | return mCalEnabled; | ||
157 | } | ||
158 | |||
159 | void IncidenceBase::setAlarmEnabled( bool b ) | ||
160 | { | ||
161 | mAlarmEnabled = b; | ||
162 | } | ||
163 | bool IncidenceBase::alarmEnabled() const | ||
164 | { | ||
165 | return mAlarmEnabled; | ||
166 | } | ||
167 | |||
135 | 168 | ||
136 | void IncidenceBase::setUid(const QString &uid) | 169 | void IncidenceBase::setUid(const QString &uid) |
137 | { | 170 | { |
138 | mUid = uid; | 171 | mUid = uid; |
139 | updated(); | 172 | updated(); |
140 | } | 173 | } |
141 | 174 | ||
142 | QString IncidenceBase::uid() const | 175 | QString IncidenceBase::uid() const |
143 | { | 176 | { |
144 | return mUid; | 177 | return mUid; |
145 | } | 178 | } |
146 | 179 | ||
147 | void IncidenceBase::setLastModified(const QDateTime &lm) | 180 | void IncidenceBase::setLastModified(const QDateTime &lm) |
148 | { | 181 | { |
149 | // DON'T! updated() because we call this from | 182 | // DON'T! updated() because we call this from |
150 | // Calendar::updateEvent(). | 183 | // Calendar::updateEvent(). |
151 | mLastModified = getEvenTime(lm); | 184 | mLastModified = getEvenTime(lm); |
152 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); | 185 | //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); |
153 | } | 186 | } |
154 | 187 | ||
155 | QDateTime IncidenceBase::lastModified() const | 188 | QDateTime IncidenceBase::lastModified() const |
156 | { | 189 | { |
157 | return mLastModified; | 190 | return mLastModified; |
158 | } | 191 | } |
159 | 192 | ||
160 | void IncidenceBase::setOrganizer(const QString &o) | 193 | void IncidenceBase::setOrganizer(const QString &o) |
161 | { | 194 | { |
162 | // we don't check for readonly here, because it is | 195 | // we don't check for readonly here, because it is |
163 | // possible that by setting the organizer we are changing | 196 | // possible that by setting the organizer we are changing |
164 | // the event's readonly status... | 197 | // the event's readonly status... |
165 | mOrganizer = o; | 198 | mOrganizer = o; |
166 | if (mOrganizer.left(7).upper() == "MAILTO:") | 199 | if (mOrganizer.left(7).upper() == "MAILTO:") |
167 | mOrganizer = mOrganizer.remove(0,7); | 200 | mOrganizer = mOrganizer.remove(0,7); |
168 | 201 | ||
169 | updated(); | 202 | updated(); |
170 | } | 203 | } |
171 | 204 | ||
172 | QString IncidenceBase::organizer() const | 205 | QString IncidenceBase::organizer() const |
173 | { | 206 | { |
174 | return mOrganizer; | 207 | return mOrganizer; |
175 | } | 208 | } |
176 | 209 | ||
177 | void IncidenceBase::setReadOnly( bool readOnly ) | 210 | void IncidenceBase::setReadOnly( bool readOnly ) |
178 | { | 211 | { |
179 | mReadOnly = readOnly; | 212 | mReadOnly = readOnly; |
180 | } | 213 | } |
181 | 214 | ||
182 | void IncidenceBase::setDtStart(const QDateTime &dtStart) | 215 | void IncidenceBase::setDtStart(const QDateTime &dtStart) |
183 | { | 216 | { |
184 | // if (mReadOnly) return; | 217 | // if (mReadOnly) return; |
185 | mDtStart = getEvenTime(dtStart); | 218 | mDtStart = getEvenTime(dtStart); |
186 | updated(); | 219 | updated(); |
187 | } | 220 | } |
188 | 221 | ||
189 | 222 | ||
190 | QDateTime IncidenceBase::dtStart() const | 223 | QDateTime IncidenceBase::dtStart() const |
191 | { | 224 | { |
192 | return mDtStart; | 225 | return mDtStart; |
193 | } | 226 | } |
194 | 227 | ||
195 | QString IncidenceBase::dtStartTimeStr() const | 228 | QString IncidenceBase::dtStartTimeStr() const |
196 | { | 229 | { |
197 | return KGlobal::locale()->formatTime(dtStart().time()); | 230 | return KGlobal::locale()->formatTime(dtStart().time()); |
198 | } | 231 | } |
199 | 232 | ||
200 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const | 233 | QString IncidenceBase::dtStartDateStr(bool shortfmt) const |
201 | { | 234 | { |
202 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 235 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
203 | } | 236 | } |
204 | 237 | ||
205 | QString IncidenceBase::dtStartStr(bool shortfmt) const | 238 | QString IncidenceBase::dtStartStr(bool shortfmt) const |
206 | { | 239 | { |
207 | if ( doesFloat() ) | 240 | if ( doesFloat() ) |
208 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); | 241 | return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); |
209 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); | 242 | return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); |
210 | } | 243 | } |
211 | 244 | ||
212 | 245 | ||
213 | bool IncidenceBase::doesFloat() const | 246 | bool IncidenceBase::doesFloat() const |
214 | { | 247 | { |
215 | return mFloats; | 248 | return mFloats; |
216 | } | 249 | } |
217 | 250 | ||
218 | void IncidenceBase::setFloats(bool f) | 251 | void IncidenceBase::setFloats(bool f) |
219 | { | 252 | { |
220 | if (mReadOnly) return; | 253 | if (mReadOnly) return; |
221 | mFloats = f; | 254 | mFloats = f; |
222 | updated(); | 255 | updated(); |
223 | } | 256 | } |
224 | 257 | ||
225 | 258 | ||
226 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) | 259 | bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) |
227 | { | 260 | { |
228 | if (mReadOnly) return false; | 261 | if (mReadOnly) return false; |
229 | if (a->name().left(7).upper() == "MAILTO:") | 262 | if (a->name().left(7).upper() == "MAILTO:") |
230 | a->setName(a->name().remove(0,7)); | 263 | a->setName(a->name().remove(0,7)); |
231 | 264 | ||
232 | QPtrListIterator<Attendee> qli(mAttendees); | 265 | QPtrListIterator<Attendee> qli(mAttendees); |
233 | 266 | ||
234 | qli.toFirst(); | 267 | qli.toFirst(); |
235 | while (qli) { | 268 | while (qli) { |
236 | if (*qli.current() == *a) | 269 | if (*qli.current() == *a) |
237 | return false; | 270 | return false; |
238 | ++qli; | 271 | ++qli; |
239 | } | 272 | } |
240 | mAttendees.append(a); | 273 | mAttendees.append(a); |
241 | if (doupdate) updated(); | 274 | if (doupdate) updated(); |
242 | return true; | 275 | return true; |
243 | } | 276 | } |
244 | 277 | ||
245 | #if 0 | 278 | #if 0 |
246 | void IncidenceBase::removeAttendee(Attendee *a) | 279 | void IncidenceBase::removeAttendee(Attendee *a) |
247 | { | 280 | { |
248 | if (mReadOnly) return; | 281 | if (mReadOnly) return; |
249 | mAttendees.removeRef(a); | 282 | mAttendees.removeRef(a); |
250 | updated(); | 283 | updated(); |
251 | } | 284 | } |
252 | 285 | ||
253 | void IncidenceBase::removeAttendee(const char *n) | 286 | void IncidenceBase::removeAttendee(const char *n) |
254 | { | 287 | { |
255 | Attendee *a; | 288 | Attendee *a; |
256 | 289 | ||
257 | if (mReadOnly) return; | 290 | if (mReadOnly) return; |
258 | for (a = mAttendees.first(); a; a = mAttendees.next()) | 291 | for (a = mAttendees.first(); a; a = mAttendees.next()) |
259 | if (a->getName() == n) { | 292 | if (a->getName() == n) { |
260 | mAttendees.remove(); | 293 | mAttendees.remove(); |
261 | break; | 294 | break; |
262 | } | 295 | } |
263 | } | 296 | } |
264 | #endif | 297 | #endif |
265 | 298 | ||
266 | void IncidenceBase::clearAttendees() | 299 | void IncidenceBase::clearAttendees() |
267 | { | 300 | { |
268 | if (mReadOnly) return; | 301 | if (mReadOnly) return; |
269 | mAttendees.clear(); | 302 | mAttendees.clear(); |
270 | } | 303 | } |
271 | 304 | ||
272 | #if 0 | 305 | #if 0 |
273 | Attendee *IncidenceBase::getAttendee(const char *n) const | 306 | Attendee *IncidenceBase::getAttendee(const char *n) const |
274 | { | 307 | { |
275 | QPtrListIterator<Attendee> qli(mAttendees); | 308 | QPtrListIterator<Attendee> qli(mAttendees); |
276 | 309 | ||
277 | qli.toFirst(); | 310 | qli.toFirst(); |
278 | while (qli) { | 311 | while (qli) { |
279 | if (qli.current()->getName() == n) | 312 | if (qli.current()->getName() == n) |
280 | return qli.current(); | 313 | return qli.current(); |
281 | ++qli; | 314 | ++qli; |
282 | } | 315 | } |
283 | return 0L; | 316 | return 0L; |
284 | } | 317 | } |
285 | #endif | 318 | #endif |
286 | 319 | ||
287 | Attendee *IncidenceBase::attendeeByMail(const QString &email) | 320 | Attendee *IncidenceBase::attendeeByMail(const QString &email) |
288 | { | 321 | { |
289 | QPtrListIterator<Attendee> qli(mAttendees); | 322 | QPtrListIterator<Attendee> qli(mAttendees); |
290 | 323 | ||
291 | qli.toFirst(); | 324 | qli.toFirst(); |
292 | while (qli) { | 325 | while (qli) { |
293 | if (qli.current()->email().lower() == email.lower()) | 326 | if (qli.current()->email().lower() == email.lower()) |
294 | return qli.current(); | 327 | return qli.current(); |
295 | ++qli; | 328 | ++qli; |
296 | } | 329 | } |
297 | return 0L; | 330 | return 0L; |
298 | } | 331 | } |
299 | 332 | ||
300 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) | 333 | Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) |
301 | { | 334 | { |
302 | QPtrListIterator<Attendee> qli(mAttendees); | 335 | QPtrListIterator<Attendee> qli(mAttendees); |
303 | 336 | ||
304 | QStringList mails = emails; | 337 | QStringList mails = emails; |
305 | if (!email.isEmpty()) { | 338 | if (!email.isEmpty()) { |
306 | mails.append(email); | 339 | mails.append(email); |
307 | } | 340 | } |
308 | qli.toFirst(); | 341 | qli.toFirst(); |
309 | while (qli) { | 342 | while (qli) { |
310 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { | 343 | for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { |
311 | if (qli.current()->email().lower() == (*it).lower()) | 344 | if (qli.current()->email().lower() == (*it).lower()) |
312 | return qli.current(); | 345 | return qli.current(); |
313 | } | 346 | } |
314 | 347 | ||
315 | ++qli; | 348 | ++qli; |
316 | } | 349 | } |
317 | return 0L; | 350 | return 0L; |
318 | } | 351 | } |
319 | 352 | ||
320 | void IncidenceBase::setDuration(int seconds) | 353 | void IncidenceBase::setDuration(int seconds) |
321 | { | 354 | { |
322 | mDuration = seconds; | 355 | mDuration = seconds; |
323 | setHasDuration(true); | 356 | setHasDuration(true); |
324 | } | 357 | } |
325 | 358 | ||
326 | int IncidenceBase::duration() const | 359 | int IncidenceBase::duration() const |
327 | { | 360 | { |
328 | return mDuration; | 361 | return mDuration; |
329 | } | 362 | } |
330 | 363 | ||
331 | void IncidenceBase::setHasDuration(bool b) | 364 | void IncidenceBase::setHasDuration(bool b) |
332 | { | 365 | { |
333 | mHasDuration = b; | 366 | mHasDuration = b; |
334 | } | 367 | } |
335 | 368 | ||
336 | bool IncidenceBase::hasDuration() const | 369 | bool IncidenceBase::hasDuration() const |
337 | { | 370 | { |
338 | return mHasDuration; | 371 | return mHasDuration; |
339 | } | 372 | } |
340 | 373 | ||
341 | void IncidenceBase::setSyncStatus(int stat) | 374 | void IncidenceBase::setSyncStatus(int stat) |
342 | { | 375 | { |
343 | if (mReadOnly) return; | 376 | if (mReadOnly) return; |
344 | mSyncStatus = stat; | 377 | mSyncStatus = stat; |
345 | } | 378 | } |
346 | 379 | ||
347 | int IncidenceBase::syncStatus() const | 380 | int IncidenceBase::syncStatus() const |
348 | { | 381 | { |
349 | return mSyncStatus; | 382 | return mSyncStatus; |
350 | } | 383 | } |
351 | 384 | ||
352 | void IncidenceBase::setPilotId( int id ) | 385 | void IncidenceBase::setPilotId( int id ) |
353 | { | 386 | { |
354 | if (mReadOnly) return; | 387 | if (mReadOnly) return; |
355 | mPilotId = id; | 388 | mPilotId = id; |
356 | } | 389 | } |
357 | 390 | ||
358 | int IncidenceBase::pilotId() const | 391 | int IncidenceBase::pilotId() const |
359 | { | 392 | { |
360 | return mPilotId; | 393 | return mPilotId; |
361 | } | 394 | } |
362 | 395 | ||
363 | int IncidenceBase::tempSyncStat() const | 396 | int IncidenceBase::tempSyncStat() const |
364 | { | 397 | { |
365 | return mTempSyncStat; | 398 | return mTempSyncStat; |
366 | } | 399 | } |
367 | void IncidenceBase::setTempSyncStat( int id ) | 400 | void IncidenceBase::setTempSyncStat( int id ) |
368 | { | 401 | { |
369 | if (mReadOnly) return; | 402 | if (mReadOnly) return; |
370 | mTempSyncStat = id; | 403 | mTempSyncStat = id; |
371 | } | 404 | } |
372 | 405 | ||
373 | void IncidenceBase::removeID(const QString &prof) | 406 | void IncidenceBase::removeID(const QString &prof) |
374 | { | 407 | { |
375 | if ( prof.isEmpty() ) | 408 | if ( prof.isEmpty() ) |
376 | mExternalId = ":"; | 409 | mExternalId = ":"; |
377 | else | 410 | else |
378 | mExternalId = KIdManager::removeId ( mExternalId, prof); | 411 | mExternalId = KIdManager::removeId ( mExternalId, prof); |
379 | 412 | ||
380 | } | 413 | } |
381 | void IncidenceBase::setID( const QString & prof , const QString & id ) | 414 | void IncidenceBase::setID( const QString & prof , const QString & id ) |
382 | { | 415 | { |
383 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); | 416 | mExternalId = KIdManager::setId ( mExternalId, prof, id ); |
384 | } | 417 | } |
385 | QString IncidenceBase::getID( const QString & prof) | 418 | QString IncidenceBase::getID( const QString & prof) |
386 | { | 419 | { |
387 | return KIdManager::getId ( mExternalId, prof ); | 420 | return KIdManager::getId ( mExternalId, prof ); |
388 | } | 421 | } |
389 | 422 | ||
390 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: | 423 | // example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: |
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h index 05209e0..dc6024a 100644 --- a/libkcal/incidencebase.h +++ b/libkcal/incidencebase.h | |||
@@ -1,174 +1,183 @@ | |||
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 | enum IncTypeID { eventID,todoID,journalID,freebusyID }; |
38 | 38 | ||
39 | /** | 39 | /** |
40 | This class provides the base class common to all calendar components. | 40 | This class provides the base class common to all calendar components. |
41 | */ | 41 | */ |
42 | class IncidenceBase : public CustomProperties | 42 | class IncidenceBase : public CustomProperties |
43 | { | 43 | { |
44 | public: | 44 | public: |
45 | class Observer { | 45 | class Observer { |
46 | public: | 46 | public: |
47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; | 47 | virtual void incidenceUpdated( IncidenceBase * ) = 0; |
48 | }; | 48 | }; |
49 | 49 | ||
50 | IncidenceBase(); | 50 | IncidenceBase(); |
51 | IncidenceBase(const IncidenceBase &); | 51 | IncidenceBase(const IncidenceBase &); |
52 | virtual ~IncidenceBase(); | 52 | virtual ~IncidenceBase(); |
53 | 53 | ||
54 | virtual QCString type() const = 0; | 54 | virtual QCString type() const = 0; |
55 | virtual IncTypeID typeID() const = 0; | 55 | virtual IncTypeID typeID() const = 0; |
56 | 56 | ||
57 | /** Set the unique id for the event */ | 57 | /** Set the unique id for the event */ |
58 | void setUid(const QString &); | 58 | void setUid(const QString &); |
59 | /** Return the unique id for the event */ | 59 | /** Return the unique id for the event */ |
60 | QString uid() const; | 60 | QString uid() const; |
61 | 61 | ||
62 | /** Sets the time the incidence was last modified. */ | 62 | /** Sets the time the incidence was last modified. */ |
63 | void setLastModified(const QDateTime &lm); | 63 | void setLastModified(const QDateTime &lm); |
64 | /** Return the time the incidence was last modified. */ | 64 | /** Return the time the incidence was last modified. */ |
65 | QDateTime lastModified() const; | 65 | QDateTime lastModified() const; |
66 | 66 | ||
67 | /** sets the organizer for the event */ | 67 | /** sets the organizer for the event */ |
68 | void setOrganizer(const QString &o); | 68 | void setOrganizer(const QString &o); |
69 | QString organizer() const; | 69 | QString organizer() const; |
70 | 70 | ||
71 | /** Set readonly status. */ | 71 | /** Set readonly status. */ |
72 | virtual void setReadOnly( bool ); | 72 | virtual void setReadOnly( bool ); |
73 | /** Return if the object is read-only. */ | 73 | /** Return if the object is read-only. */ |
74 | bool isReadOnly() const { return mReadOnly; } | 74 | bool isReadOnly() const { return mReadOnly; } |
75 | 75 | ||
76 | /** for setting the event's starting date/time with a QDateTime. */ | 76 | /** for setting the event's starting date/time with a QDateTime. */ |
77 | virtual void setDtStart(const QDateTime &dtStart); | 77 | virtual void setDtStart(const QDateTime &dtStart); |
78 | /** returns an event's starting date/time as a QDateTime. */ | 78 | /** returns an event's starting date/time as a QDateTime. */ |
79 | virtual QDateTime dtStart() const; | 79 | virtual QDateTime dtStart() const; |
80 | /** 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 |
81 | users locale settings */ | 81 | users locale settings */ |
82 | QString dtStartTimeStr() const; | 82 | QString dtStartTimeStr() const; |
83 | /** 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 |
84 | users locale settings */ | 84 | users locale settings */ |
85 | QString dtStartDateStr(bool shortfmt=true) const; | 85 | QString dtStartDateStr(bool shortfmt=true) const; |
86 | /** 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 |
87 | to the users locale settings */ | 87 | to the users locale settings */ |
88 | QString dtStartStr(bool shortfmt=true) const; | 88 | QString dtStartStr(bool shortfmt=true) const; |
89 | 89 | ||
90 | virtual void setDuration(int seconds); | 90 | virtual void setDuration(int seconds); |
91 | int duration() const; | 91 | int duration() const; |
92 | void setHasDuration(bool); | 92 | void setHasDuration(bool); |
93 | bool hasDuration() const; | 93 | bool hasDuration() const; |
94 | 94 | ||
95 | /** Return true or false depending on whether the incidence "floats," | 95 | /** Return true or false depending on whether the incidence "floats," |
96 | * i.e. has a date but no time attached to it. */ | 96 | * i.e. has a date but no time attached to it. */ |
97 | bool doesFloat() const; | 97 | bool doesFloat() const; |
98 | /** 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. */ |
99 | void setFloats(bool f); | 99 | void setFloats(bool f); |
100 | 100 | ||
101 | /** | 101 | /** |
102 | Add Attendee to this incidence. IncidenceBase takes ownership of the | 102 | Add Attendee to this incidence. IncidenceBase takes ownership of the |
103 | Attendee object. | 103 | Attendee object. |
104 | */ | 104 | */ |
105 | bool addAttendee(Attendee *a, bool doupdate=true ); | 105 | bool addAttendee(Attendee *a, bool doupdate=true ); |
106 | // void removeAttendee(Attendee *a); | 106 | // void removeAttendee(Attendee *a); |
107 | // void removeAttendee(const char *n); | 107 | // void removeAttendee(const char *n); |
108 | /** Remove all Attendees. */ | 108 | /** Remove all Attendees. */ |
109 | void clearAttendees(); | 109 | void clearAttendees(); |
110 | /** Return list of attendees. */ | 110 | /** Return list of attendees. */ |
111 | QPtrList<Attendee> attendees() const { return mAttendees; }; | 111 | QPtrList<Attendee> attendees() const { return mAttendees; }; |
112 | /** Return number of attendees. */ | 112 | /** Return number of attendees. */ |
113 | int attendeeCount() const { return mAttendees.count(); }; | 113 | int attendeeCount() const { return mAttendees.count(); }; |
114 | /** Return the Attendee with this email */ | 114 | /** Return the Attendee with this email */ |
115 | Attendee* attendeeByMail(const QString &); | 115 | Attendee* attendeeByMail(const QString &); |
116 | /** Return first Attendee with one of this emails */ | 116 | /** Return first Attendee with one of this emails */ |
117 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); | 117 | Attendee* attendeeByMails(const QStringList &, const QString& email = QString::null); |
118 | 118 | ||
119 | /** pilot syncronization states */ | 119 | /** pilot syncronization states */ |
120 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; | 120 | enum { SYNCNONE = 0, SYNCMOD = 1, SYNCDEL = 3 }; |
121 | /** Set synchronisation satus. */ | 121 | /** Set synchronisation satus. */ |
122 | void setSyncStatus(int stat); | 122 | void setSyncStatus(int stat); |
123 | /** Return synchronisation status. */ | 123 | /** Return synchronisation status. */ |
124 | int syncStatus() const; | 124 | int syncStatus() const; |
125 | 125 | ||
126 | /** Set Pilot Id. */ | 126 | /** Set Pilot Id. */ |
127 | void setPilotId(int id); | 127 | void setPilotId(int id); |
128 | /** Return Pilot Id. */ | 128 | /** Return Pilot Id. */ |
129 | int pilotId() const; | 129 | int pilotId() const; |
130 | 130 | ||
131 | void setTempSyncStat(int id); | 131 | void setTempSyncStat(int id); |
132 | int tempSyncStat() const; | 132 | int tempSyncStat() const; |
133 | void setIDStr( const QString & ); | 133 | void setIDStr( const QString & ); |
134 | QString IDStr() const; | 134 | QString IDStr() const; |
135 | void setID( const QString &, const QString & ); | 135 | void setID( const QString &, const QString & ); |
136 | QString getID( const QString & ); | 136 | QString getID( const QString & ); |
137 | void setCsum( const QString &, const QString & ); | 137 | void setCsum( const QString &, const QString & ); |
138 | QString getCsum( const QString & ); | 138 | QString getCsum( const QString & ); |
139 | void removeID(const QString &); | 139 | void removeID(const QString &); |
140 | 140 | ||
141 | void registerObserver( Observer * ); | 141 | void registerObserver( Observer * ); |
142 | void unRegisterObserver( Observer * ); | 142 | void unRegisterObserver( Observer * ); |
143 | void updated(); | 143 | void updated(); |
144 | void setCalID( int id ); | ||
145 | int calID() const; | ||
146 | void setCalEnabled( bool ); | ||
147 | bool calEnabled() const; | ||
148 | void setAlarmEnabled( bool ); | ||
149 | bool alarmEnabled() const; | ||
144 | 150 | ||
145 | protected: | 151 | protected: |
146 | QDateTime mDtStart; | 152 | QDateTime mDtStart; |
147 | bool mReadOnly; | 153 | bool mReadOnly; |
148 | QDateTime getEvenTime( QDateTime ); | 154 | QDateTime getEvenTime( QDateTime ); |
149 | 155 | ||
150 | private: | 156 | private: |
151 | // base components | 157 | // base components |
152 | QString mOrganizer; | 158 | QString mOrganizer; |
153 | QString mUid; | 159 | QString mUid; |
160 | int mCalID; | ||
161 | bool mCalEnabled; | ||
162 | bool mAlarmEnabled; | ||
154 | QDateTime mLastModified; | 163 | QDateTime mLastModified; |
155 | QPtrList<Attendee> mAttendees; | 164 | QPtrList<Attendee> mAttendees; |
156 | 165 | ||
157 | bool mFloats; | 166 | bool mFloats; |
158 | 167 | ||
159 | int mDuration; | 168 | int mDuration; |
160 | bool mHasDuration; | 169 | bool mHasDuration; |
161 | QString mExternalId; | 170 | QString mExternalId; |
162 | int mTempSyncStat; | 171 | int mTempSyncStat; |
163 | 172 | ||
164 | // PILOT SYNCHRONIZATION STUFF | 173 | // PILOT SYNCHRONIZATION STUFF |
165 | int mPilotId; // unique id for pilot sync | 174 | int mPilotId; // unique id for pilot sync |
166 | int mSyncStatus; // status (for sync) | 175 | int mSyncStatus; // status (for sync) |
167 | 176 | ||
168 | QPtrList<Observer> mObservers; | 177 | QPtrList<Observer> mObservers; |
169 | }; | 178 | }; |
170 | 179 | ||
171 | bool operator==( const IncidenceBase&, const IncidenceBase& ); | 180 | bool operator==( const IncidenceBase&, const IncidenceBase& ); |
172 | } | 181 | } |
173 | 182 | ||
174 | #endif | 183 | #endif |
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp index c97a61e..42274ff 100644 --- a/libkcal/todo.cpp +++ b/libkcal/todo.cpp | |||
@@ -264,318 +264,318 @@ bool KCal::operator==( const Todo& t1, const Todo& t2 ) | |||
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() || !alarmEnabled() ) { |
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 ( !mHasRecurrenceID ) { | 567 | if ( !mHasRecurrenceID ) { |
568 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); | 568 | qDebug("ERROR 1 in Todo::checkSetCompletedFalse"); |
569 | return; | 569 | return; |
570 | } | 570 | } |
571 | // qDebug("Todo::checkSetCompletedFalse()"); | 571 | // qDebug("Todo::checkSetCompletedFalse()"); |
572 | //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() ); |
573 | if ( mPercentComplete == 100 ) { | 573 | if ( mPercentComplete == 100 ) { |
574 | QDateTime dt = QDateTime::currentDateTime(); | 574 | QDateTime dt = QDateTime::currentDateTime(); |
575 | if ( dt > mDtStart && dt > mRecurrenceID ) { | 575 | if ( dt > mDtStart && dt > mRecurrenceID ) { |
576 | 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() ); |
577 | setCompleted( false ); | 577 | setCompleted( false ); |
578 | qDebug("Todo::checkSetCompletedFalse "); | 578 | qDebug("Todo::checkSetCompletedFalse "); |
579 | } | 579 | } |
580 | } | 580 | } |
581 | } | 581 | } |