author | zautrix <zautrix> | 2005-11-28 01:23:07 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-11-28 01:23:07 (UTC) |
commit | 084180efc1bccba341bf3f2f718fd10cdfdaf18e (patch) (unidiff) | |
tree | d464e19dd4b3e72bf553b7d083fb493e9e8405e6 | |
parent | e08811c2246f63b2b63f9db6b65701344460f3d7 (diff) | |
download | kdepimpi-084180efc1bccba341bf3f2f718fd10cdfdaf18e.zip kdepimpi-084180efc1bccba341bf3f2f718fd10cdfdaf18e.tar.gz kdepimpi-084180efc1bccba341bf3f2f718fd10cdfdaf18e.tar.bz2 |
ync
-rw-r--r-- | libkcal/calendar.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 1350f6d..9b38d3f 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,526 +1,526 @@ | |||
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 | 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 <stdlib.h> | 21 | #include <stdlib.h> |
22 | #include <time.h> | 22 | #include <time.h> |
23 | 23 | ||
24 | #include <kdebug.h> | 24 | #include <kdebug.h> |
25 | #include <kglobal.h> | 25 | #include <kglobal.h> |
26 | #include <klocale.h> | 26 | #include <klocale.h> |
27 | 27 | ||
28 | #include "exceptions.h" | 28 | #include "exceptions.h" |
29 | #include "calfilter.h" | 29 | #include "calfilter.h" |
30 | 30 | ||
31 | #include "calendar.h" | 31 | #include "calendar.h" |
32 | #include "syncdefines.h" | 32 | #include "syncdefines.h" |
33 | 33 | ||
34 | using namespace KCal; | 34 | using namespace KCal; |
35 | 35 | ||
36 | Calendar::Calendar() | 36 | Calendar::Calendar() |
37 | { | 37 | { |
38 | 38 | ||
39 | init(); | 39 | init(); |
40 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 40 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
41 | } | 41 | } |
42 | 42 | ||
43 | Calendar::Calendar( const QString &timeZoneId ) | 43 | Calendar::Calendar( const QString &timeZoneId ) |
44 | { | 44 | { |
45 | 45 | ||
46 | init(); | 46 | init(); |
47 | setTimeZoneId(timeZoneId); | 47 | setTimeZoneId(timeZoneId); |
48 | } | 48 | } |
49 | 49 | ||
50 | void Calendar::init() | 50 | void Calendar::init() |
51 | { | 51 | { |
52 | mObserver = 0; | 52 | mObserver = 0; |
53 | mNewObserver = false; | 53 | mNewObserver = false; |
54 | mUndoIncidence = 0; | 54 | mUndoIncidence = 0; |
55 | mDeleteIncidencesOnClose = true; | 55 | mDeleteIncidencesOnClose = true; |
56 | mModified = false; | 56 | mModified = false; |
57 | mDefaultCalendar = 1; | 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 | clearUndo( 0 ); | 112 | clearUndo( 0 ); |
113 | } | 113 | } |
114 | void Calendar::clearUndo( Incidence * newUndo ) | 114 | void Calendar::clearUndo( Incidence * newUndo ) |
115 | { | 115 | { |
116 | 116 | ||
117 | if ( mUndoIncidence ) { | 117 | if ( mUndoIncidence ) { |
118 | if ( mUndoIncidence->typeID() == eventID ) | 118 | if ( mUndoIncidence->typeID() == eventID ) |
119 | delete ((Event*) mUndoIncidence) ; | 119 | delete ((Event*) mUndoIncidence) ; |
120 | else if ( mUndoIncidence->typeID() == todoID ) | 120 | else if ( mUndoIncidence->typeID() == todoID ) |
121 | delete ( (Todo*) mUndoIncidence ); | 121 | delete ( (Todo*) mUndoIncidence ); |
122 | else if ( mUndoIncidence->typeID() == journalID ) | 122 | else if ( mUndoIncidence->typeID() == journalID ) |
123 | delete ( (Journal*) mUndoIncidence ); | 123 | delete ( (Journal*) mUndoIncidence ); |
124 | else | 124 | else |
125 | delete mUndoIncidence; | 125 | delete mUndoIncidence; |
126 | } | 126 | } |
127 | mUndoIncidence = newUndo; | 127 | mUndoIncidence = newUndo; |
128 | if ( mUndoIncidence ) { | 128 | if ( mUndoIncidence ) { |
129 | mUndoIncidence->clearRelations(); | 129 | mUndoIncidence->clearRelations(); |
130 | } | 130 | } |
131 | 131 | ||
132 | } | 132 | } |
133 | 133 | ||
134 | void Calendar::setDontDeleteIncidencesOnClose () | 134 | void Calendar::setDontDeleteIncidencesOnClose () |
135 | { | 135 | { |
136 | mDeleteIncidencesOnClose = false; | 136 | mDeleteIncidencesOnClose = false; |
137 | } | 137 | } |
138 | void Calendar::setDefaultCalendar( int d ) | 138 | void Calendar::setDefaultCalendar( int d ) |
139 | { | 139 | { |
140 | mDefaultCalendar = d; | 140 | mDefaultCalendar = d; |
141 | } | 141 | } |
142 | int Calendar::defaultCalendar() | 142 | int Calendar::defaultCalendar() |
143 | { | 143 | { |
144 | return mDefaultCalendar; | 144 | return mDefaultCalendar; |
145 | } | 145 | } |
146 | const QString &Calendar::getOwner() const | 146 | const QString &Calendar::getOwner() const |
147 | { | 147 | { |
148 | return mOwner; | 148 | return mOwner; |
149 | } | 149 | } |
150 | 150 | ||
151 | bool Calendar::undoDeleteIncidence() | 151 | bool Calendar::undoDeleteIncidence() |
152 | { | 152 | { |
153 | if (!mUndoIncidence) | 153 | if (!mUndoIncidence) |
154 | return false; | 154 | return false; |
155 | addIncidence(mUndoIncidence); | 155 | addIncidence(mUndoIncidence); |
156 | mUndoIncidence = 0; | 156 | mUndoIncidence = 0; |
157 | return true; | 157 | return true; |
158 | } | 158 | } |
159 | void Calendar::setOwner(const QString &os) | 159 | void Calendar::setOwner(const QString &os) |
160 | { | 160 | { |
161 | int i; | 161 | int i; |
162 | mOwner = os; | 162 | mOwner = os; |
163 | i = mOwner.find(','); | 163 | i = mOwner.find(','); |
164 | if (i != -1) | 164 | if (i != -1) |
165 | mOwner = mOwner.left(i); | 165 | mOwner = mOwner.left(i); |
166 | 166 | ||
167 | setModified( true ); | 167 | setModified( true ); |
168 | } | 168 | } |
169 | 169 | ||
170 | void Calendar::setTimeZone(const QString & tz) | 170 | void Calendar::setTimeZone(const QString & tz) |
171 | { | 171 | { |
172 | bool neg = FALSE; | 172 | bool neg = FALSE; |
173 | int hours, minutes; | 173 | int hours, minutes; |
174 | QString tmpStr(tz); | 174 | QString tmpStr(tz); |
175 | 175 | ||
176 | if (tmpStr.left(1) == "-") | 176 | if (tmpStr.left(1) == "-") |
177 | neg = TRUE; | 177 | neg = TRUE; |
178 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 178 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
179 | tmpStr.remove(0, 1); | 179 | tmpStr.remove(0, 1); |
180 | hours = tmpStr.left(2).toInt(); | 180 | hours = tmpStr.left(2).toInt(); |
181 | if (tmpStr.length() > 2) | 181 | if (tmpStr.length() > 2) |
182 | minutes = tmpStr.right(2).toInt(); | 182 | minutes = tmpStr.right(2).toInt(); |
183 | else | 183 | else |
184 | minutes = 0; | 184 | minutes = 0; |
185 | mTimeZone = (60*hours+minutes); | 185 | mTimeZone = (60*hours+minutes); |
186 | if (neg) | 186 | if (neg) |
187 | mTimeZone = -mTimeZone; | 187 | mTimeZone = -mTimeZone; |
188 | mLocalTime = false; | 188 | mLocalTime = false; |
189 | 189 | ||
190 | setModified( true ); | 190 | setModified( true ); |
191 | } | 191 | } |
192 | 192 | ||
193 | QString Calendar::getTimeZoneStr() const | 193 | QString Calendar::getTimeZoneStr() const |
194 | { | 194 | { |
195 | if (mLocalTime) | 195 | if (mLocalTime) |
196 | return ""; | 196 | return ""; |
197 | QString tmpStr; | 197 | QString tmpStr; |
198 | int hours = abs(mTimeZone / 60); | 198 | int hours = abs(mTimeZone / 60); |
199 | int minutes = abs(mTimeZone % 60); | 199 | int minutes = abs(mTimeZone % 60); |
200 | bool neg = mTimeZone < 0; | 200 | bool neg = mTimeZone < 0; |
201 | 201 | ||
202 | tmpStr.sprintf("%c%.2d%.2d", | 202 | tmpStr.sprintf("%c%.2d%.2d", |
203 | (neg ? '-' : '+'), | 203 | (neg ? '-' : '+'), |
204 | hours, minutes); | 204 | hours, minutes); |
205 | return tmpStr; | 205 | return tmpStr; |
206 | } | 206 | } |
207 | 207 | ||
208 | void Calendar::setTimeZone(int tz) | 208 | void Calendar::setTimeZone(int tz) |
209 | { | 209 | { |
210 | mTimeZone = tz; | 210 | mTimeZone = tz; |
211 | mLocalTime = false; | 211 | mLocalTime = false; |
212 | 212 | ||
213 | setModified( true ); | 213 | setModified( true ); |
214 | } | 214 | } |
215 | 215 | ||
216 | int Calendar::getTimeZone() const | 216 | int Calendar::getTimeZone() const |
217 | { | 217 | { |
218 | return mTimeZone; | 218 | return mTimeZone; |
219 | } | 219 | } |
220 | 220 | ||
221 | void Calendar::setTimeZoneId(const QString &id) | 221 | void Calendar::setTimeZoneId(const QString &id) |
222 | { | 222 | { |
223 | mTimeZoneId = id; | 223 | mTimeZoneId = id; |
224 | mLocalTime = false; | 224 | mLocalTime = false; |
225 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 225 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
226 | if ( mTimeZone > 1000) | 226 | if ( mTimeZone > 1000) |
227 | setLocalTime(); | 227 | setLocalTime(); |
228 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 228 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
229 | setModified( true ); | 229 | setModified( true ); |
230 | } | 230 | } |
231 | 231 | ||
232 | QString Calendar::timeZoneId() const | 232 | QString Calendar::timeZoneId() const |
233 | { | 233 | { |
234 | return mTimeZoneId; | 234 | return mTimeZoneId; |
235 | } | 235 | } |
236 | 236 | ||
237 | void Calendar::setLocalTime() | 237 | void Calendar::setLocalTime() |
238 | { | 238 | { |
239 | //qDebug("Calendar::setLocalTime() "); | 239 | //qDebug("Calendar::setLocalTime() "); |
240 | mLocalTime = true; | 240 | mLocalTime = true; |
241 | mTimeZone = 0; | 241 | mTimeZone = 0; |
242 | mTimeZoneId = ""; | 242 | mTimeZoneId = ""; |
243 | 243 | ||
244 | setModified( true ); | 244 | setModified( true ); |
245 | } | 245 | } |
246 | 246 | ||
247 | bool Calendar::isLocalTime() const | 247 | bool Calendar::isLocalTime() const |
248 | { | 248 | { |
249 | return mLocalTime; | 249 | return mLocalTime; |
250 | } | 250 | } |
251 | 251 | ||
252 | const QString &Calendar::getEmail() | 252 | const QString &Calendar::getEmail() |
253 | { | 253 | { |
254 | return mOwnerEmail; | 254 | return mOwnerEmail; |
255 | } | 255 | } |
256 | 256 | ||
257 | void Calendar::setEmail(const QString &e) | 257 | void Calendar::setEmail(const QString &e) |
258 | { | 258 | { |
259 | mOwnerEmail = e; | 259 | mOwnerEmail = e; |
260 | 260 | ||
261 | setModified( true ); | 261 | setModified( true ); |
262 | } | 262 | } |
263 | 263 | ||
264 | void Calendar::setFilter(CalFilter *filter) | 264 | void Calendar::setFilter(CalFilter *filter) |
265 | { | 265 | { |
266 | mFilter = filter; | 266 | mFilter = filter; |
267 | } | 267 | } |
268 | 268 | ||
269 | CalFilter *Calendar::filter() | 269 | CalFilter *Calendar::filter() |
270 | { | 270 | { |
271 | return mFilter; | 271 | return mFilter; |
272 | } | 272 | } |
273 | 273 | ||
274 | QPtrList<Incidence> Calendar::incidences() | 274 | QPtrList<Incidence> Calendar::incidences() |
275 | { | 275 | { |
276 | QPtrList<Incidence> incidences; | 276 | QPtrList<Incidence> incidences; |
277 | 277 | ||
278 | Incidence *i; | 278 | Incidence *i; |
279 | 279 | ||
280 | QPtrList<Event> e = events(); | 280 | QPtrList<Event> e = events(); |
281 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 281 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
282 | 282 | ||
283 | QPtrList<Todo> t = todos(); | 283 | QPtrList<Todo> t = todos(); |
284 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 284 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
285 | 285 | ||
286 | QPtrList<Journal> j = journals(); | 286 | QPtrList<Journal> j = journals(); |
287 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 287 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
288 | 288 | ||
289 | return incidences; | 289 | return incidences; |
290 | } | 290 | } |
291 | 291 | ||
292 | void Calendar::resetPilotStat(int id ) | 292 | void Calendar::resetPilotStat(int id ) |
293 | { | 293 | { |
294 | QPtrList<Incidence> incidences; | 294 | QPtrList<Incidence> incidences; |
295 | 295 | ||
296 | Incidence *i; | 296 | Incidence *i; |
297 | 297 | ||
298 | QPtrList<Event> e = rawEvents(); | 298 | QPtrList<Event> e = rawEvents(); |
299 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 299 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
300 | 300 | ||
301 | QPtrList<Todo> t = rawTodos(); | 301 | QPtrList<Todo> t = rawTodos(); |
302 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 302 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
303 | 303 | ||
304 | QPtrList<Journal> j = journals(); | 304 | QPtrList<Journal> j = journals(); |
305 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 305 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
306 | } | 306 | } |
307 | void Calendar::resetTempSyncStat() | 307 | void Calendar::resetTempSyncStat() |
308 | { | 308 | { |
309 | QPtrList<Incidence> incidences; | 309 | QPtrList<Incidence> incidences; |
310 | 310 | ||
311 | Incidence *i; | 311 | Incidence *i; |
312 | 312 | ||
313 | QPtrList<Event> e = rawEvents(); | 313 | QPtrList<Event> e = rawEvents(); |
314 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 314 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
315 | 315 | ||
316 | QPtrList<Todo> t = rawTodos(); | 316 | QPtrList<Todo> t = rawTodos(); |
317 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 317 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
318 | 318 | ||
319 | QPtrList<Journal> j = journals(); | 319 | QPtrList<Journal> j = journals(); |
320 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 320 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
321 | } | 321 | } |
322 | QPtrList<Incidence> Calendar::rawIncidences() | 322 | QPtrList<Incidence> Calendar::rawIncidences() |
323 | { | 323 | { |
324 | QPtrList<Incidence> incidences; | 324 | QPtrList<Incidence> incidences; |
325 | 325 | ||
326 | Incidence *i; | 326 | Incidence *i; |
327 | 327 | ||
328 | QPtrList<Event> e = rawEvents(); | 328 | QPtrList<Event> e = rawEvents(); |
329 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 329 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
330 | 330 | ||
331 | QPtrList<Todo> t = rawTodos(); | 331 | QPtrList<Todo> t = rawTodos(); |
332 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 332 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
333 | 333 | ||
334 | QPtrList<Journal> j = journals(); | 334 | QPtrList<Journal> j = journals(); |
335 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 335 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
336 | 336 | ||
337 | return incidences; | 337 | return incidences; |
338 | } | 338 | } |
339 | 339 | ||
340 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) | 340 | QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) |
341 | { | 341 | { |
342 | QPtrList<Event> el = rawEventsForDate(date,sorted); | 342 | QPtrList<Event> el = rawEventsForDate(date,sorted); |
343 | mFilter->apply(&el); | 343 | mFilter->apply(&el); |
344 | return el; | 344 | return el; |
345 | } | 345 | } |
346 | 346 | ||
347 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) | 347 | QPtrList<Event> Calendar::events( const QDateTime &qdt ) |
348 | { | 348 | { |
349 | QPtrList<Event> el = rawEventsForDate(qdt); | 349 | QPtrList<Event> el = rawEventsForDate(qdt); |
350 | mFilter->apply(&el); | 350 | mFilter->apply(&el); |
351 | return el; | 351 | return el; |
352 | } | 352 | } |
353 | 353 | ||
354 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | 354 | QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, |
355 | bool inclusive) | 355 | bool inclusive) |
356 | { | 356 | { |
357 | QPtrList<Event> el = rawEvents(start,end,inclusive); | 357 | QPtrList<Event> el = rawEvents(start,end,inclusive); |
358 | mFilter->apply(&el); | 358 | mFilter->apply(&el); |
359 | return el; | 359 | return el; |
360 | } | 360 | } |
361 | 361 | ||
362 | QPtrList<Event> Calendar::events() | 362 | QPtrList<Event> Calendar::events() |
363 | { | 363 | { |
364 | QPtrList<Event> el = rawEvents(); | 364 | QPtrList<Event> el = rawEvents(); |
365 | mFilter->apply(&el); | 365 | mFilter->apply(&el); |
366 | return el; | 366 | return el; |
367 | } | 367 | } |
368 | void Calendar::addIncidenceBranch(Incidence *i) | 368 | void Calendar::addIncidenceBranch(Incidence *i) |
369 | { | 369 | { |
370 | addIncidence( i ); | 370 | addIncidence( i ); |
371 | Incidence * inc; | 371 | Incidence * inc; |
372 | QPtrList<Incidence> Relations = i->relations(); | 372 | QPtrList<Incidence> Relations = i->relations(); |
373 | for (inc=Relations.first();inc;inc=Relations.next()) { | 373 | for (inc=Relations.first();inc;inc=Relations.next()) { |
374 | addIncidenceBranch( inc ); | 374 | addIncidenceBranch( inc ); |
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | bool Calendar::addIncidence(Incidence *i) | 378 | bool Calendar::addIncidence(Incidence *i) |
379 | { | 379 | { |
380 | Incidence::AddVisitor<Calendar> v(this); | 380 | Incidence::AddVisitor<Calendar> v(this); |
381 | if ( i->calID() == 0 ) | 381 | if ( i->calID() == 0 ) |
382 | i->setCalID_block( mDefaultCalendar ); | 382 | i->setCalID_block( mDefaultCalendar ); |
383 | i->setCalEnabled( true ); | 383 | i->setCalEnabled( true ); |
384 | return i->accept(v); | 384 | return i->accept(v); |
385 | } | 385 | } |
386 | void Calendar::deleteIncidence(Incidence *in) | 386 | void Calendar::deleteIncidence(Incidence *in) |
387 | { | 387 | { |
388 | if ( in->typeID() == eventID ) | 388 | if ( in->typeID() == eventID ) |
389 | deleteEvent( (Event*) in ); | 389 | deleteEvent( (Event*) in ); |
390 | else if ( in->typeID() == todoID ) | 390 | else if ( in->typeID() == todoID ) |
391 | deleteTodo( (Todo*) in); | 391 | deleteTodo( (Todo*) in); |
392 | else if ( in->typeID() == journalID ) | 392 | else if ( in->typeID() == journalID ) |
393 | deleteJournal( (Journal*) in ); | 393 | deleteJournal( (Journal*) in ); |
394 | } | 394 | } |
395 | 395 | ||
396 | Incidence* Calendar::incidence( const QString& uid ) | 396 | Incidence* Calendar::incidence( const QString& uid ) |
397 | { | 397 | { |
398 | Incidence* i; | 398 | Incidence* i; |
399 | 399 | ||
400 | if( (i = todo( uid )) != 0 ) | 400 | if( (i = todo( uid )) != 0 ) |
401 | return i; | 401 | return i; |
402 | if( (i = event( uid )) != 0 ) | 402 | if( (i = event( uid )) != 0 ) |
403 | return i; | 403 | return i; |
404 | if( (i = journal( uid )) != 0 ) | 404 | if( (i = journal( uid )) != 0 ) |
405 | return i; | 405 | return i; |
406 | 406 | ||
407 | return 0; | 407 | return 0; |
408 | } | 408 | } |
409 | 409 | ||
410 | QPtrList<Todo> Calendar::todos() | 410 | QPtrList<Todo> Calendar::todos() |
411 | { | 411 | { |
412 | QPtrList<Todo> tl = rawTodos(); | 412 | QPtrList<Todo> tl = rawTodos(); |
413 | mFilter->apply( &tl ); | 413 | mFilter->apply( &tl ); |
414 | return tl; | 414 | return tl; |
415 | } | 415 | } |
416 | 416 | ||
417 | // When this is called, the todo have already been added to the calendar. | 417 | // When this is called, the todo have already been added to the calendar. |
418 | // This method is only about linking related todos | 418 | // This method is only about linking related todos |
419 | void Calendar::setupRelations( Incidence *incidence ) | 419 | void Calendar::setupRelations( Incidence *incidence ) |
420 | { | 420 | { |
421 | QString uid = incidence->uid(); | 421 | QString uid = incidence->uid(); |
422 | //qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); | 422 | qDebug("Calendar::setupRelations %s", incidence->summary().latin1()); |
423 | // First, go over the list of orphans and see if this is their parent | 423 | // First, go over the list of orphans and see if this is their parent |
424 | while( Incidence* i = mOrphans[ uid ] ) { | 424 | while( Incidence* i = mOrphans[ uid ] ) { |
425 | mOrphans.remove( uid ); | 425 | mOrphans.remove( uid ); |
426 | i->setRelatedTo( incidence ); | 426 | i->setRelatedTo( incidence ); |
427 | //qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); | 427 | qDebug("Add child %s ti inc %s", i->summary().latin1(),incidence->summary().latin1()); |
428 | incidence->addRelation( i ); | 428 | incidence->addRelation( i ); |
429 | mOrphanUids.remove( i->uid() ); | 429 | mOrphanUids.remove( i->uid() ); |
430 | } | 430 | } |
431 | 431 | ||
432 | // Now see about this incidences parent | 432 | // Now see about this incidences parent |
433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { | 433 | if( !incidence->relatedTo() && !incidence->relatedToUid().isEmpty() ) { |
434 | // This incidence has a uid it is related to, but is not registered to it yet | 434 | // This incidence has a uid it is related to, but is not registered to it yet |
435 | // Try to find it | 435 | // Try to find it |
436 | //qDebug("Test parent for %s", incidence->summary().latin1()); | 436 | qDebug("Test parent for %s", incidence->summary().latin1()); |
437 | Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); | 437 | Incidence* parent = this->incidenceForUid( incidence->relatedToUid(), true ); |
438 | if( parent ) { | 438 | if( parent ) { |
439 | // Found it | 439 | // Found it |
440 | // qDebug("parent found for for %s", incidence->summary().latin1()); | 440 | qDebug("parent found for for %s", incidence->summary().latin1()); |
441 | incidence->setRelatedTo( parent ); | 441 | incidence->setRelatedTo( parent ); |
442 | parent->addRelation( incidence ); | 442 | parent->addRelation( incidence ); |
443 | } else { | 443 | } else { |
444 | // qDebug("NO parent found for for %s", incidence->summary().latin1()); | 444 | qDebug("NO parent found for for %s", incidence->summary().latin1()); |
445 | // Not found, put this in the mOrphans list | 445 | // Not found, put this in the mOrphans list |
446 | mOrphans.insert( incidence->relatedToUid(), incidence ); | 446 | mOrphans.insert( incidence->relatedToUid(), incidence ); |
447 | mOrphanUids.insert( incidence->uid(), incidence ); | 447 | mOrphanUids.insert( incidence->uid(), incidence ); |
448 | } | 448 | } |
449 | } | 449 | } |
450 | } | 450 | } |
451 | 451 | ||
452 | // If a task with subtasks is deleted, move it's subtasks to the orphans list | 452 | // If a task with subtasks is deleted, move it's subtasks to the orphans list |
453 | void Calendar::removeRelations( Incidence *incidence ) | 453 | void Calendar::removeRelations( Incidence *incidence ) |
454 | { | 454 | { |
455 | // qDebug("Calendar::removeRelations "); | 455 | // qDebug("Calendar::removeRelations "); |
456 | QString uid = incidence->uid(); | 456 | QString uid = incidence->uid(); |
457 | 457 | ||
458 | QPtrList<Incidence> relations = incidence->relations(); | 458 | QPtrList<Incidence> relations = incidence->relations(); |
459 | for( Incidence* i = relations.first(); i; i = relations.next() ) | 459 | for( Incidence* i = relations.first(); i; i = relations.next() ) |
460 | if( !mOrphanUids.find( i->uid() ) ) { | 460 | if( !mOrphanUids.find( i->uid() ) ) { |
461 | mOrphans.insert( uid, i ); | 461 | mOrphans.insert( uid, i ); |
462 | mOrphanUids.insert( i->uid(), i ); | 462 | mOrphanUids.insert( i->uid(), i ); |
463 | i->setRelatedTo( 0 ); | 463 | i->setRelatedTo( 0 ); |
464 | i->setRelatedToUid( uid ); | 464 | i->setRelatedToUid( uid ); |
465 | } | 465 | } |
466 | 466 | ||
467 | // If this incidence is related to something else, tell that about it | 467 | // If this incidence is related to something else, tell that about it |
468 | if( incidence->relatedTo() ) | 468 | if( incidence->relatedTo() ) |
469 | incidence->relatedTo()->removeRelation( incidence ); | 469 | incidence->relatedTo()->removeRelation( incidence ); |
470 | 470 | ||
471 | // Remove this one from the orphans list | 471 | // Remove this one from the orphans list |
472 | if( mOrphanUids.remove( uid ) ) { | 472 | if( mOrphanUids.remove( uid ) ) { |
473 | QString r2uid = incidence->relatedToUid(); | 473 | QString r2uid = incidence->relatedToUid(); |
474 | QPtrList<Incidence> tempList; | 474 | QPtrList<Incidence> tempList; |
475 | while( Incidence* i = mOrphans[ r2uid ] ) { | 475 | while( Incidence* i = mOrphans[ r2uid ] ) { |
476 | mOrphans.remove( r2uid ); | 476 | mOrphans.remove( r2uid ); |
477 | if ( i != incidence ) tempList.append( i ); | 477 | if ( i != incidence ) tempList.append( i ); |
478 | } | 478 | } |
479 | Incidence* inc = tempList.first(); | 479 | Incidence* inc = tempList.first(); |
480 | while ( inc ) { | 480 | while ( inc ) { |
481 | mOrphans.insert( r2uid, inc ); | 481 | mOrphans.insert( r2uid, inc ); |
482 | inc = tempList.next(); | 482 | inc = tempList.next(); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | // LR: and another big bad bug found | 485 | // LR: and another big bad bug found |
486 | #if 0 | 486 | #if 0 |
487 | // This incidence is located in the orphans list - it should be removed | 487 | // This incidence is located in the orphans list - it should be removed |
488 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { | 488 | if( !( incidence->relatedTo() != 0 && mOrphans.remove( incidence->relatedTo()->uid() ) ) ) { |
489 | // Removing wasn't that easy | 489 | // Removing wasn't that easy |
490 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { | 490 | for( QDictIterator<Incidence> it( mOrphans ); it.current(); ++it ) { |
491 | if( it.current()->uid() == uid ) { | 491 | if( it.current()->uid() == uid ) { |
492 | mOrphans.remove( it.currentKey() ); | 492 | mOrphans.remove( it.currentKey() ); |
493 | break; | 493 | break; |
494 | } | 494 | } |
495 | } | 495 | } |
496 | } | 496 | } |
497 | #endif | 497 | #endif |
498 | } | 498 | } |
499 | 499 | ||
500 | void Calendar::registerObserver( Observer *observer ) | 500 | void Calendar::registerObserver( Observer *observer ) |
501 | { | 501 | { |
502 | mObserver = observer; | 502 | mObserver = observer; |
503 | mNewObserver = true; | 503 | mNewObserver = true; |
504 | } | 504 | } |
505 | 505 | ||
506 | void Calendar::setModified( bool modified ) | 506 | void Calendar::setModified( bool modified ) |
507 | { | 507 | { |
508 | if ( mObserver ) mObserver->calendarModified( modified, this ); | 508 | if ( mObserver ) mObserver->calendarModified( modified, this ); |
509 | if ( modified != mModified || mNewObserver ) { | 509 | if ( modified != mModified || mNewObserver ) { |
510 | mNewObserver = false; | 510 | mNewObserver = false; |
511 | // if ( mObserver ) mObserver->calendarModified( modified, this ); | 511 | // if ( mObserver ) mObserver->calendarModified( modified, this ); |
512 | mModified = modified; | 512 | mModified = modified; |
513 | } | 513 | } |
514 | } | 514 | } |
515 | 515 | ||
516 | void Calendar::setLoadedProductId( const QString &id ) | 516 | void Calendar::setLoadedProductId( const QString &id ) |
517 | { | 517 | { |
518 | mLoadedProductId = id; | 518 | mLoadedProductId = id; |
519 | } | 519 | } |
520 | 520 | ||
521 | QString Calendar::loadedProductId() | 521 | QString Calendar::loadedProductId() |
522 | { | 522 | { |
523 | return mLoadedProductId; | 523 | return mLoadedProductId; |
524 | } | 524 | } |
525 | 525 | ||
526 | //#include "calendar.moc" | 526 | //#include "calendar.moc" |