author | zautrix <zautrix> | 2005-06-13 10:51:47 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-06-13 10:51:47 (UTC) |
commit | 4f3ff02932b39bf16b9692c3cb69c101a28b4616 (patch) (unidiff) | |
tree | bae36a7e654c788a0994bb353f3997b495e2459c /libkcal/calendar.cpp | |
parent | 2be8214908c52298ba79c8058d340edca5a8b417 (diff) | |
download | kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.zip kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.gz kdepimpi-4f3ff02932b39bf16b9692c3cb69c101a28b4616.tar.bz2 |
fixx
-rw-r--r-- | libkcal/calendar.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index f4350d9..5092d1a 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -1,306 +1,311 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #include <stdlib.h> | 22 | #include <stdlib.h> |
23 | #include <time.h> | 23 | #include <time.h> |
24 | 24 | ||
25 | #include <kdebug.h> | 25 | #include <kdebug.h> |
26 | #include <kglobal.h> | 26 | #include <kglobal.h> |
27 | #include <klocale.h> | 27 | #include <klocale.h> |
28 | 28 | ||
29 | #include "exceptions.h" | 29 | #include "exceptions.h" |
30 | #include "calfilter.h" | 30 | #include "calfilter.h" |
31 | 31 | ||
32 | #include "calendar.h" | 32 | #include "calendar.h" |
33 | #include "syncdefines.h" | 33 | #include "syncdefines.h" |
34 | 34 | ||
35 | using namespace KCal; | 35 | using namespace KCal; |
36 | 36 | ||
37 | Calendar::Calendar() | 37 | Calendar::Calendar() |
38 | { | 38 | { |
39 | 39 | ||
40 | init(); | 40 | init(); |
41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); | 41 | setTimeZoneId( " 00:00 Europe/London(UTC)" ); |
42 | } | 42 | } |
43 | 43 | ||
44 | Calendar::Calendar( const QString &timeZoneId ) | 44 | Calendar::Calendar( const QString &timeZoneId ) |
45 | { | 45 | { |
46 | 46 | ||
47 | init(); | 47 | init(); |
48 | setTimeZoneId(timeZoneId); | 48 | setTimeZoneId(timeZoneId); |
49 | } | 49 | } |
50 | 50 | ||
51 | void Calendar::init() | 51 | void Calendar::init() |
52 | { | 52 | { |
53 | mObserver = 0; | 53 | mObserver = 0; |
54 | mNewObserver = false; | 54 | mNewObserver = false; |
55 | mUndoIncidence = 0; | 55 | mUndoIncidence = 0; |
56 | mDeleteIncidencesOnClose = true; | ||
56 | mModified = false; | 57 | mModified = false; |
57 | mDefaultCalendar = 1; | 58 | mDefaultCalendar = 1; |
58 | // Setup default filter, which does nothing | 59 | // Setup default filter, which does nothing |
59 | mDefaultFilter = new CalFilter; | 60 | mDefaultFilter = new CalFilter; |
60 | mFilter = mDefaultFilter; | 61 | mFilter = mDefaultFilter; |
61 | mFilter->setEnabled(false); | 62 | mFilter->setEnabled(false); |
62 | 63 | ||
63 | // initialize random numbers. This is a hack, and not | 64 | // initialize random numbers. This is a hack, and not |
64 | // even that good of one at that. | 65 | // even that good of one at that. |
65 | // srandom(time(0)); | 66 | // srandom(time(0)); |
66 | 67 | ||
67 | // user information... | 68 | // user information... |
68 | setOwner(i18n("Unknown Name")); | 69 | setOwner(i18n("Unknown Name")); |
69 | setEmail(i18n("unknown@nowhere")); | 70 | setEmail(i18n("unknown@nowhere")); |
70 | 71 | ||
71 | #if 0 | 72 | #if 0 |
72 | tmpStr = KOPrefs::instance()->mTimeZone; | 73 | tmpStr = KOPrefs::instance()->mTimeZone; |
73 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; | 74 | // kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; |
74 | int dstSetting = KOPrefs::instance()->mDaylightSavings; | 75 | int dstSetting = KOPrefs::instance()->mDaylightSavings; |
75 | extern long int timezone; | 76 | extern long int timezone; |
76 | struct tm *now; | 77 | struct tm *now; |
77 | time_t curtime; | 78 | time_t curtime; |
78 | curtime = time(0); | 79 | curtime = time(0); |
79 | now = localtime(&curtime); | 80 | now = localtime(&curtime); |
80 | int hourOff = - ((timezone / 60) / 60); | 81 | int hourOff = - ((timezone / 60) / 60); |
81 | if (now->tm_isdst) | 82 | if (now->tm_isdst) |
82 | hourOff += 1; | 83 | hourOff += 1; |
83 | QString tzStr; | 84 | QString tzStr; |
84 | tzStr.sprintf("%.2d%.2d", | 85 | tzStr.sprintf("%.2d%.2d", |
85 | hourOff, | 86 | hourOff, |
86 | abs((timezone / 60) % 60)); | 87 | abs((timezone / 60) % 60)); |
87 | 88 | ||
88 | // if no time zone was in the config file, write what we just discovered. | 89 | // if no time zone was in the config file, write what we just discovered. |
89 | if (tmpStr.isEmpty()) { | 90 | if (tmpStr.isEmpty()) { |
90 | // KOPrefs::instance()->mTimeZone = tzStr; | 91 | // KOPrefs::instance()->mTimeZone = tzStr; |
91 | } else { | 92 | } else { |
92 | tzStr = tmpStr; | 93 | tzStr = tmpStr; |
93 | } | 94 | } |
94 | 95 | ||
95 | // if daylight savings has changed since last load time, we need | 96 | // if daylight savings has changed since last load time, we need |
96 | // to rewrite these settings to the config file. | 97 | // to rewrite these settings to the config file. |
97 | if ((now->tm_isdst && !dstSetting) || | 98 | if ((now->tm_isdst && !dstSetting) || |
98 | (!now->tm_isdst && dstSetting)) { | 99 | (!now->tm_isdst && dstSetting)) { |
99 | KOPrefs::instance()->mTimeZone = tzStr; | 100 | KOPrefs::instance()->mTimeZone = tzStr; |
100 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; | 101 | KOPrefs::instance()->mDaylightSavings = now->tm_isdst; |
101 | } | 102 | } |
102 | 103 | ||
103 | setTimeZone(tzStr); | 104 | setTimeZone(tzStr); |
104 | #endif | 105 | #endif |
105 | 106 | ||
106 | // KOPrefs::instance()->writeConfig(); | 107 | // KOPrefs::instance()->writeConfig(); |
107 | } | 108 | } |
108 | 109 | ||
109 | Calendar::~Calendar() | 110 | Calendar::~Calendar() |
110 | { | 111 | { |
111 | delete mDefaultFilter; | 112 | delete mDefaultFilter; |
112 | if ( mUndoIncidence ) | 113 | if ( mUndoIncidence ) |
113 | delete mUndoIncidence; | 114 | delete mUndoIncidence; |
114 | } | 115 | } |
116 | void Calendar::setDontDeleteIncidencesOnClose () | ||
117 | { | ||
118 | mDeleteIncidencesOnClose = false; | ||
119 | } | ||
115 | void Calendar::setDefaultCalendar( int d ) | 120 | void Calendar::setDefaultCalendar( int d ) |
116 | { | 121 | { |
117 | mDefaultCalendar = d; | 122 | mDefaultCalendar = d; |
118 | } | 123 | } |
119 | int Calendar::defaultCalendar() | 124 | int Calendar::defaultCalendar() |
120 | { | 125 | { |
121 | return mDefaultCalendar; | 126 | return mDefaultCalendar; |
122 | } | 127 | } |
123 | const QString &Calendar::getOwner() const | 128 | const QString &Calendar::getOwner() const |
124 | { | 129 | { |
125 | return mOwner; | 130 | return mOwner; |
126 | } | 131 | } |
127 | 132 | ||
128 | bool Calendar::undoDeleteIncidence() | 133 | bool Calendar::undoDeleteIncidence() |
129 | { | 134 | { |
130 | if (!mUndoIncidence) | 135 | if (!mUndoIncidence) |
131 | return false; | 136 | return false; |
132 | addIncidence(mUndoIncidence); | 137 | addIncidence(mUndoIncidence); |
133 | mUndoIncidence = 0; | 138 | mUndoIncidence = 0; |
134 | return true; | 139 | return true; |
135 | } | 140 | } |
136 | void Calendar::setOwner(const QString &os) | 141 | void Calendar::setOwner(const QString &os) |
137 | { | 142 | { |
138 | int i; | 143 | int i; |
139 | mOwner = os; | 144 | mOwner = os; |
140 | i = mOwner.find(','); | 145 | i = mOwner.find(','); |
141 | if (i != -1) | 146 | if (i != -1) |
142 | mOwner = mOwner.left(i); | 147 | mOwner = mOwner.left(i); |
143 | 148 | ||
144 | setModified( true ); | 149 | setModified( true ); |
145 | } | 150 | } |
146 | 151 | ||
147 | void Calendar::setTimeZone(const QString & tz) | 152 | void Calendar::setTimeZone(const QString & tz) |
148 | { | 153 | { |
149 | bool neg = FALSE; | 154 | bool neg = FALSE; |
150 | int hours, minutes; | 155 | int hours, minutes; |
151 | QString tmpStr(tz); | 156 | QString tmpStr(tz); |
152 | 157 | ||
153 | if (tmpStr.left(1) == "-") | 158 | if (tmpStr.left(1) == "-") |
154 | neg = TRUE; | 159 | neg = TRUE; |
155 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") | 160 | if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") |
156 | tmpStr.remove(0, 1); | 161 | tmpStr.remove(0, 1); |
157 | hours = tmpStr.left(2).toInt(); | 162 | hours = tmpStr.left(2).toInt(); |
158 | if (tmpStr.length() > 2) | 163 | if (tmpStr.length() > 2) |
159 | minutes = tmpStr.right(2).toInt(); | 164 | minutes = tmpStr.right(2).toInt(); |
160 | else | 165 | else |
161 | minutes = 0; | 166 | minutes = 0; |
162 | mTimeZone = (60*hours+minutes); | 167 | mTimeZone = (60*hours+minutes); |
163 | if (neg) | 168 | if (neg) |
164 | mTimeZone = -mTimeZone; | 169 | mTimeZone = -mTimeZone; |
165 | mLocalTime = false; | 170 | mLocalTime = false; |
166 | 171 | ||
167 | setModified( true ); | 172 | setModified( true ); |
168 | } | 173 | } |
169 | 174 | ||
170 | QString Calendar::getTimeZoneStr() const | 175 | QString Calendar::getTimeZoneStr() const |
171 | { | 176 | { |
172 | if (mLocalTime) | 177 | if (mLocalTime) |
173 | return ""; | 178 | return ""; |
174 | QString tmpStr; | 179 | QString tmpStr; |
175 | int hours = abs(mTimeZone / 60); | 180 | int hours = abs(mTimeZone / 60); |
176 | int minutes = abs(mTimeZone % 60); | 181 | int minutes = abs(mTimeZone % 60); |
177 | bool neg = mTimeZone < 0; | 182 | bool neg = mTimeZone < 0; |
178 | 183 | ||
179 | tmpStr.sprintf("%c%.2d%.2d", | 184 | tmpStr.sprintf("%c%.2d%.2d", |
180 | (neg ? '-' : '+'), | 185 | (neg ? '-' : '+'), |
181 | hours, minutes); | 186 | hours, minutes); |
182 | return tmpStr; | 187 | return tmpStr; |
183 | } | 188 | } |
184 | 189 | ||
185 | void Calendar::setTimeZone(int tz) | 190 | void Calendar::setTimeZone(int tz) |
186 | { | 191 | { |
187 | mTimeZone = tz; | 192 | mTimeZone = tz; |
188 | mLocalTime = false; | 193 | mLocalTime = false; |
189 | 194 | ||
190 | setModified( true ); | 195 | setModified( true ); |
191 | } | 196 | } |
192 | 197 | ||
193 | int Calendar::getTimeZone() const | 198 | int Calendar::getTimeZone() const |
194 | { | 199 | { |
195 | return mTimeZone; | 200 | return mTimeZone; |
196 | } | 201 | } |
197 | 202 | ||
198 | void Calendar::setTimeZoneId(const QString &id) | 203 | void Calendar::setTimeZoneId(const QString &id) |
199 | { | 204 | { |
200 | mTimeZoneId = id; | 205 | mTimeZoneId = id; |
201 | mLocalTime = false; | 206 | mLocalTime = false; |
202 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); | 207 | mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); |
203 | if ( mTimeZone > 1000) | 208 | if ( mTimeZone > 1000) |
204 | setLocalTime(); | 209 | setLocalTime(); |
205 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); | 210 | //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); |
206 | setModified( true ); | 211 | setModified( true ); |
207 | } | 212 | } |
208 | 213 | ||
209 | QString Calendar::timeZoneId() const | 214 | QString Calendar::timeZoneId() const |
210 | { | 215 | { |
211 | return mTimeZoneId; | 216 | return mTimeZoneId; |
212 | } | 217 | } |
213 | 218 | ||
214 | void Calendar::setLocalTime() | 219 | void Calendar::setLocalTime() |
215 | { | 220 | { |
216 | //qDebug("Calendar::setLocalTime() "); | 221 | //qDebug("Calendar::setLocalTime() "); |
217 | mLocalTime = true; | 222 | mLocalTime = true; |
218 | mTimeZone = 0; | 223 | mTimeZone = 0; |
219 | mTimeZoneId = ""; | 224 | mTimeZoneId = ""; |
220 | 225 | ||
221 | setModified( true ); | 226 | setModified( true ); |
222 | } | 227 | } |
223 | 228 | ||
224 | bool Calendar::isLocalTime() const | 229 | bool Calendar::isLocalTime() const |
225 | { | 230 | { |
226 | return mLocalTime; | 231 | return mLocalTime; |
227 | } | 232 | } |
228 | 233 | ||
229 | const QString &Calendar::getEmail() | 234 | const QString &Calendar::getEmail() |
230 | { | 235 | { |
231 | return mOwnerEmail; | 236 | return mOwnerEmail; |
232 | } | 237 | } |
233 | 238 | ||
234 | void Calendar::setEmail(const QString &e) | 239 | void Calendar::setEmail(const QString &e) |
235 | { | 240 | { |
236 | mOwnerEmail = e; | 241 | mOwnerEmail = e; |
237 | 242 | ||
238 | setModified( true ); | 243 | setModified( true ); |
239 | } | 244 | } |
240 | 245 | ||
241 | void Calendar::setFilter(CalFilter *filter) | 246 | void Calendar::setFilter(CalFilter *filter) |
242 | { | 247 | { |
243 | mFilter = filter; | 248 | mFilter = filter; |
244 | } | 249 | } |
245 | 250 | ||
246 | CalFilter *Calendar::filter() | 251 | CalFilter *Calendar::filter() |
247 | { | 252 | { |
248 | return mFilter; | 253 | return mFilter; |
249 | } | 254 | } |
250 | 255 | ||
251 | QPtrList<Incidence> Calendar::incidences() | 256 | QPtrList<Incidence> Calendar::incidences() |
252 | { | 257 | { |
253 | QPtrList<Incidence> incidences; | 258 | QPtrList<Incidence> incidences; |
254 | 259 | ||
255 | Incidence *i; | 260 | Incidence *i; |
256 | 261 | ||
257 | QPtrList<Event> e = events(); | 262 | QPtrList<Event> e = events(); |
258 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 263 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |
259 | 264 | ||
260 | QPtrList<Todo> t = todos(); | 265 | QPtrList<Todo> t = todos(); |
261 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); | 266 | for( i = t.first(); i; i = t.next() ) incidences.append( i ); |
262 | 267 | ||
263 | QPtrList<Journal> j = journals(); | 268 | QPtrList<Journal> j = journals(); |
264 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); | 269 | for( i = j.first(); i; i = j.next() ) incidences.append( i ); |
265 | 270 | ||
266 | return incidences; | 271 | return incidences; |
267 | } | 272 | } |
268 | 273 | ||
269 | void Calendar::resetPilotStat(int id ) | 274 | void Calendar::resetPilotStat(int id ) |
270 | { | 275 | { |
271 | QPtrList<Incidence> incidences; | 276 | QPtrList<Incidence> incidences; |
272 | 277 | ||
273 | Incidence *i; | 278 | Incidence *i; |
274 | 279 | ||
275 | QPtrList<Event> e = rawEvents(); | 280 | QPtrList<Event> e = rawEvents(); |
276 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); | 281 | for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); |
277 | 282 | ||
278 | QPtrList<Todo> t = rawTodos(); | 283 | QPtrList<Todo> t = rawTodos(); |
279 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); | 284 | for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); |
280 | 285 | ||
281 | QPtrList<Journal> j = journals(); | 286 | QPtrList<Journal> j = journals(); |
282 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); | 287 | for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); |
283 | } | 288 | } |
284 | void Calendar::resetTempSyncStat() | 289 | void Calendar::resetTempSyncStat() |
285 | { | 290 | { |
286 | QPtrList<Incidence> incidences; | 291 | QPtrList<Incidence> incidences; |
287 | 292 | ||
288 | Incidence *i; | 293 | Incidence *i; |
289 | 294 | ||
290 | QPtrList<Event> e = rawEvents(); | 295 | QPtrList<Event> e = rawEvents(); |
291 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 296 | for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
292 | 297 | ||
293 | QPtrList<Todo> t = rawTodos(); | 298 | QPtrList<Todo> t = rawTodos(); |
294 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 299 | for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
295 | 300 | ||
296 | QPtrList<Journal> j = journals(); | 301 | QPtrList<Journal> j = journals(); |
297 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 302 | for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
298 | } | 303 | } |
299 | QPtrList<Incidence> Calendar::rawIncidences() | 304 | QPtrList<Incidence> Calendar::rawIncidences() |
300 | { | 305 | { |
301 | QPtrList<Incidence> incidences; | 306 | QPtrList<Incidence> incidences; |
302 | 307 | ||
303 | Incidence *i; | 308 | Incidence *i; |
304 | 309 | ||
305 | QPtrList<Event> e = rawEvents(); | 310 | QPtrList<Event> e = rawEvents(); |
306 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); | 311 | for( i = e.first(); i; i = e.next() ) incidences.append( i ); |