summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2004-12-07 09:55:57 (UTC)
committer zautrix <zautrix>2004-12-07 09:55:57 (UTC)
commit17b25691f0332e648dd1d800e89ccf4e1da8955d (patch) (unidiff)
treeb7bc28e6c57c043fc49328a7ebd86e1b5cd0f17a /libkcal/calendar.cpp
parentdcd2bbbc8d3064b35f268a831c567feaafea5fd8 (diff)
downloadkdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.zip
kdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.tar.gz
kdepimpi-17b25691f0332e648dd1d800e89ccf4e1da8955d.tar.bz2
some kopi usebility fixes
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 52daaaa..88351eb 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -1,374 +1,383 @@
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
35using namespace KCal; 35using namespace KCal;
36 36
37Calendar::Calendar() 37Calendar::Calendar()
38{ 38{
39 39
40 init(); 40 init();
41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") ); 41 setTimeZoneId( i18n (" 00:00 Europe/London(UTC)") );
42} 42}
43 43
44Calendar::Calendar( const QString &timeZoneId ) 44Calendar::Calendar( const QString &timeZoneId )
45{ 45{
46 46
47 init(); 47 init();
48 setTimeZoneId(timeZoneId); 48 setTimeZoneId(timeZoneId);
49} 49}
50 50
51void Calendar::init() 51void Calendar::init()
52{ 52{
53 mObserver = 0; 53 mObserver = 0;
54 mNewObserver = false; 54 mNewObserver = false;
55 55 mUndoIncidence = 0;
56 mModified = false; 56 mModified = false;
57 57
58 // Setup default filter, which does nothing 58 // Setup default filter, which does nothing
59 mDefaultFilter = new CalFilter; 59 mDefaultFilter = new CalFilter;
60 mFilter = mDefaultFilter; 60 mFilter = mDefaultFilter;
61 mFilter->setEnabled(false); 61 mFilter->setEnabled(false);
62 62
63 // initialize random numbers. This is a hack, and not 63 // initialize random numbers. This is a hack, and not
64 // even that good of one at that. 64 // even that good of one at that.
65// srandom(time(0)); 65// srandom(time(0));
66 66
67 // user information... 67 // user information...
68 setOwner(i18n("Unknown Name")); 68 setOwner(i18n("Unknown Name"));
69 setEmail(i18n("unknown@nowhere")); 69 setEmail(i18n("unknown@nowhere"));
70 70
71#if 0 71#if 0
72 tmpStr = KOPrefs::instance()->mTimeZone; 72 tmpStr = KOPrefs::instance()->mTimeZone;
73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl; 73// kdDebug(5800) << "Calendar::Calendar(): TimeZone: " << tmpStr << endl;
74 int dstSetting = KOPrefs::instance()->mDaylightSavings; 74 int dstSetting = KOPrefs::instance()->mDaylightSavings;
75 extern long int timezone; 75 extern long int timezone;
76 struct tm *now; 76 struct tm *now;
77 time_t curtime; 77 time_t curtime;
78 curtime = time(0); 78 curtime = time(0);
79 now = localtime(&curtime); 79 now = localtime(&curtime);
80 int hourOff = - ((timezone / 60) / 60); 80 int hourOff = - ((timezone / 60) / 60);
81 if (now->tm_isdst) 81 if (now->tm_isdst)
82 hourOff += 1; 82 hourOff += 1;
83 QString tzStr; 83 QString tzStr;
84 tzStr.sprintf("%.2d%.2d", 84 tzStr.sprintf("%.2d%.2d",
85 hourOff, 85 hourOff,
86 abs((timezone / 60) % 60)); 86 abs((timezone / 60) % 60));
87 87
88 // if no time zone was in the config file, write what we just discovered. 88 // if no time zone was in the config file, write what we just discovered.
89 if (tmpStr.isEmpty()) { 89 if (tmpStr.isEmpty()) {
90// KOPrefs::instance()->mTimeZone = tzStr; 90// KOPrefs::instance()->mTimeZone = tzStr;
91 } else { 91 } else {
92 tzStr = tmpStr; 92 tzStr = tmpStr;
93 } 93 }
94 94
95 // if daylight savings has changed since last load time, we need 95 // if daylight savings has changed since last load time, we need
96 // to rewrite these settings to the config file. 96 // to rewrite these settings to the config file.
97 if ((now->tm_isdst && !dstSetting) || 97 if ((now->tm_isdst && !dstSetting) ||
98 (!now->tm_isdst && dstSetting)) { 98 (!now->tm_isdst && dstSetting)) {
99 KOPrefs::instance()->mTimeZone = tzStr; 99 KOPrefs::instance()->mTimeZone = tzStr;
100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst; 100 KOPrefs::instance()->mDaylightSavings = now->tm_isdst;
101 } 101 }
102 102
103 setTimeZone(tzStr); 103 setTimeZone(tzStr);
104#endif 104#endif
105 105
106// KOPrefs::instance()->writeConfig(); 106// KOPrefs::instance()->writeConfig();
107} 107}
108 108
109Calendar::~Calendar() 109Calendar::~Calendar()
110{ 110{
111 delete mDefaultFilter; 111 delete mDefaultFilter;
112 if ( mUndoIncidence )
113 delete mUndoIncidence;
112} 114}
113 115
114const QString &Calendar::getOwner() const 116const QString &Calendar::getOwner() const
115{ 117{
116 return mOwner; 118 return mOwner;
117} 119}
118 120
121bool Calendar::undoDeleteIncidence()
122{
123 if (!mUndoIncidence)
124 return false;
125 addIncidence(mUndoIncidence);
126 mUndoIncidence = 0;
127}
119void Calendar::setOwner(const QString &os) 128void Calendar::setOwner(const QString &os)
120{ 129{
121 int i; 130 int i;
122 mOwner = os; 131 mOwner = os;
123 i = mOwner.find(','); 132 i = mOwner.find(',');
124 if (i != -1) 133 if (i != -1)
125 mOwner = mOwner.left(i); 134 mOwner = mOwner.left(i);
126 135
127 setModified( true ); 136 setModified( true );
128} 137}
129 138
130void Calendar::setTimeZone(const QString & tz) 139void Calendar::setTimeZone(const QString & tz)
131{ 140{
132 bool neg = FALSE; 141 bool neg = FALSE;
133 int hours, minutes; 142 int hours, minutes;
134 QString tmpStr(tz); 143 QString tmpStr(tz);
135 144
136 if (tmpStr.left(1) == "-") 145 if (tmpStr.left(1) == "-")
137 neg = TRUE; 146 neg = TRUE;
138 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+") 147 if (tmpStr.left(1) == "-" || tmpStr.left(1) == "+")
139 tmpStr.remove(0, 1); 148 tmpStr.remove(0, 1);
140 hours = tmpStr.left(2).toInt(); 149 hours = tmpStr.left(2).toInt();
141 if (tmpStr.length() > 2) 150 if (tmpStr.length() > 2)
142 minutes = tmpStr.right(2).toInt(); 151 minutes = tmpStr.right(2).toInt();
143 else 152 else
144 minutes = 0; 153 minutes = 0;
145 mTimeZone = (60*hours+minutes); 154 mTimeZone = (60*hours+minutes);
146 if (neg) 155 if (neg)
147 mTimeZone = -mTimeZone; 156 mTimeZone = -mTimeZone;
148 mLocalTime = false; 157 mLocalTime = false;
149 158
150 setModified( true ); 159 setModified( true );
151} 160}
152 161
153QString Calendar::getTimeZoneStr() const 162QString Calendar::getTimeZoneStr() const
154{ 163{
155 if (mLocalTime) 164 if (mLocalTime)
156 return ""; 165 return "";
157 QString tmpStr; 166 QString tmpStr;
158 int hours = abs(mTimeZone / 60); 167 int hours = abs(mTimeZone / 60);
159 int minutes = abs(mTimeZone % 60); 168 int minutes = abs(mTimeZone % 60);
160 bool neg = mTimeZone < 0; 169 bool neg = mTimeZone < 0;
161 170
162 tmpStr.sprintf("%c%.2d%.2d", 171 tmpStr.sprintf("%c%.2d%.2d",
163 (neg ? '-' : '+'), 172 (neg ? '-' : '+'),
164 hours, minutes); 173 hours, minutes);
165 return tmpStr; 174 return tmpStr;
166} 175}
167 176
168void Calendar::setTimeZone(int tz) 177void Calendar::setTimeZone(int tz)
169{ 178{
170 mTimeZone = tz; 179 mTimeZone = tz;
171 mLocalTime = false; 180 mLocalTime = false;
172 181
173 setModified( true ); 182 setModified( true );
174} 183}
175 184
176int Calendar::getTimeZone() const 185int Calendar::getTimeZone() const
177{ 186{
178 return mTimeZone; 187 return mTimeZone;
179} 188}
180 189
181void Calendar::setTimeZoneId(const QString &id) 190void Calendar::setTimeZoneId(const QString &id)
182{ 191{
183 mTimeZoneId = id; 192 mTimeZoneId = id;
184 mLocalTime = false; 193 mLocalTime = false;
185 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId); 194 mTimeZone = KGlobal::locale()->timezoneOffset(mTimeZoneId);
186 if ( mTimeZone > 1000) 195 if ( mTimeZone > 1000)
187 setLocalTime(); 196 setLocalTime();
188 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone); 197 //qDebug("Calendar::setTimeZoneOffset %s %d ",mTimeZoneId.latin1(), mTimeZone);
189 setModified( true ); 198 setModified( true );
190} 199}
191 200
192QString Calendar::timeZoneId() const 201QString Calendar::timeZoneId() const
193{ 202{
194 return mTimeZoneId; 203 return mTimeZoneId;
195} 204}
196 205
197void Calendar::setLocalTime() 206void Calendar::setLocalTime()
198{ 207{
199 //qDebug("Calendar::setLocalTime() "); 208 //qDebug("Calendar::setLocalTime() ");
200 mLocalTime = true; 209 mLocalTime = true;
201 mTimeZone = 0; 210 mTimeZone = 0;
202 mTimeZoneId = ""; 211 mTimeZoneId = "";
203 212
204 setModified( true ); 213 setModified( true );
205} 214}
206 215
207bool Calendar::isLocalTime() const 216bool Calendar::isLocalTime() const
208{ 217{
209 return mLocalTime; 218 return mLocalTime;
210} 219}
211 220
212const QString &Calendar::getEmail() 221const QString &Calendar::getEmail()
213{ 222{
214 return mOwnerEmail; 223 return mOwnerEmail;
215} 224}
216 225
217void Calendar::setEmail(const QString &e) 226void Calendar::setEmail(const QString &e)
218{ 227{
219 mOwnerEmail = e; 228 mOwnerEmail = e;
220 229
221 setModified( true ); 230 setModified( true );
222} 231}
223 232
224void Calendar::setFilter(CalFilter *filter) 233void Calendar::setFilter(CalFilter *filter)
225{ 234{
226 mFilter = filter; 235 mFilter = filter;
227} 236}
228 237
229CalFilter *Calendar::filter() 238CalFilter *Calendar::filter()
230{ 239{
231 return mFilter; 240 return mFilter;
232} 241}
233 242
234QPtrList<Incidence> Calendar::incidences() 243QPtrList<Incidence> Calendar::incidences()
235{ 244{
236 QPtrList<Incidence> incidences; 245 QPtrList<Incidence> incidences;
237 246
238 Incidence *i; 247 Incidence *i;
239 248
240 QPtrList<Event> e = events(); 249 QPtrList<Event> e = events();
241 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 250 for( i = e.first(); i; i = e.next() ) incidences.append( i );
242 251
243 QPtrList<Todo> t = todos(); 252 QPtrList<Todo> t = todos();
244 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 253 for( i = t.first(); i; i = t.next() ) incidences.append( i );
245 254
246 QPtrList<Journal> j = journals(); 255 QPtrList<Journal> j = journals();
247 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 256 for( i = j.first(); i; i = j.next() ) incidences.append( i );
248 257
249 return incidences; 258 return incidences;
250} 259}
251 260
252void Calendar::resetPilotStat(int id ) 261void Calendar::resetPilotStat(int id )
253{ 262{
254 QPtrList<Incidence> incidences; 263 QPtrList<Incidence> incidences;
255 264
256 Incidence *i; 265 Incidence *i;
257 266
258 QPtrList<Event> e = rawEvents(); 267 QPtrList<Event> e = rawEvents();
259 for( i = e.first(); i; i = e.next() ) i->setPilotId( id ); 268 for( i = e.first(); i; i = e.next() ) i->setPilotId( id );
260 269
261 QPtrList<Todo> t = rawTodos(); 270 QPtrList<Todo> t = rawTodos();
262 for( i = t.first(); i; i = t.next() ) i->setPilotId( id ); 271 for( i = t.first(); i; i = t.next() ) i->setPilotId( id );
263 272
264 QPtrList<Journal> j = journals(); 273 QPtrList<Journal> j = journals();
265 for( i = j.first(); i; i = j.next() ) i->setPilotId( id ); 274 for( i = j.first(); i; i = j.next() ) i->setPilotId( id );
266} 275}
267void Calendar::resetTempSyncStat() 276void Calendar::resetTempSyncStat()
268{ 277{
269 QPtrList<Incidence> incidences; 278 QPtrList<Incidence> incidences;
270 279
271 Incidence *i; 280 Incidence *i;
272 281
273 QPtrList<Event> e = rawEvents(); 282 QPtrList<Event> e = rawEvents();
274 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 283 for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
275 284
276 QPtrList<Todo> t = rawTodos(); 285 QPtrList<Todo> t = rawTodos();
277 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 286 for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
278 287
279 QPtrList<Journal> j = journals(); 288 QPtrList<Journal> j = journals();
280 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 289 for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
281} 290}
282QPtrList<Incidence> Calendar::rawIncidences() 291QPtrList<Incidence> Calendar::rawIncidences()
283{ 292{
284 QPtrList<Incidence> incidences; 293 QPtrList<Incidence> incidences;
285 294
286 Incidence *i; 295 Incidence *i;
287 296
288 QPtrList<Event> e = rawEvents(); 297 QPtrList<Event> e = rawEvents();
289 for( i = e.first(); i; i = e.next() ) incidences.append( i ); 298 for( i = e.first(); i; i = e.next() ) incidences.append( i );
290 299
291 QPtrList<Todo> t = rawTodos(); 300 QPtrList<Todo> t = rawTodos();
292 for( i = t.first(); i; i = t.next() ) incidences.append( i ); 301 for( i = t.first(); i; i = t.next() ) incidences.append( i );
293 302
294 QPtrList<Journal> j = journals(); 303 QPtrList<Journal> j = journals();
295 for( i = j.first(); i; i = j.next() ) incidences.append( i ); 304 for( i = j.first(); i; i = j.next() ) incidences.append( i );
296 305
297 return incidences; 306 return incidences;
298} 307}
299 308
300QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 309QPtrList<Event> Calendar::events( const QDate &date, bool sorted )
301{ 310{
302 QPtrList<Event> el = rawEventsForDate(date,sorted); 311 QPtrList<Event> el = rawEventsForDate(date,sorted);
303 mFilter->apply(&el); 312 mFilter->apply(&el);
304 return el; 313 return el;
305} 314}
306 315
307QPtrList<Event> Calendar::events( const QDateTime &qdt ) 316QPtrList<Event> Calendar::events( const QDateTime &qdt )
308{ 317{
309 QPtrList<Event> el = rawEventsForDate(qdt); 318 QPtrList<Event> el = rawEventsForDate(qdt);
310 mFilter->apply(&el); 319 mFilter->apply(&el);
311 return el; 320 return el;
312} 321}
313 322
314QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 323QPtrList<Event> Calendar::events( const QDate &start, const QDate &end,
315 bool inclusive) 324 bool inclusive)
316{ 325{
317 QPtrList<Event> el = rawEvents(start,end,inclusive); 326 QPtrList<Event> el = rawEvents(start,end,inclusive);
318 mFilter->apply(&el); 327 mFilter->apply(&el);
319 return el; 328 return el;
320} 329}
321 330
322QPtrList<Event> Calendar::events() 331QPtrList<Event> Calendar::events()
323{ 332{
324 QPtrList<Event> el = rawEvents(); 333 QPtrList<Event> el = rawEvents();
325 mFilter->apply(&el); 334 mFilter->apply(&el);
326 return el; 335 return el;
327} 336}
328 337
329 338
330bool Calendar::addIncidence(Incidence *i) 339bool Calendar::addIncidence(Incidence *i)
331{ 340{
332 Incidence::AddVisitor<Calendar> v(this); 341 Incidence::AddVisitor<Calendar> v(this);
333 342
334 return i->accept(v); 343 return i->accept(v);
335} 344}
336void Calendar::deleteIncidence(Incidence *in) 345void Calendar::deleteIncidence(Incidence *in)
337{ 346{
338 if ( in->type() == "Event" ) 347 if ( in->type() == "Event" )
339 deleteEvent( (Event*) in ); 348 deleteEvent( (Event*) in );
340 else if ( in->type() =="Todo" ) 349 else if ( in->type() =="Todo" )
341 deleteTodo( (Todo*) in); 350 deleteTodo( (Todo*) in);
342 else if ( in->type() =="Journal" ) 351 else if ( in->type() =="Journal" )
343 deleteJournal( (Journal*) in ); 352 deleteJournal( (Journal*) in );
344} 353}
345 354
346Incidence* Calendar::incidence( const QString& uid ) 355Incidence* Calendar::incidence( const QString& uid )
347{ 356{
348 Incidence* i; 357 Incidence* i;
349 358
350 if( (i = todo( uid )) != 0 ) 359 if( (i = todo( uid )) != 0 )
351 return i; 360 return i;
352 if( (i = event( uid )) != 0 ) 361 if( (i = event( uid )) != 0 )
353 return i; 362 return i;
354 if( (i = journal( uid )) != 0 ) 363 if( (i = journal( uid )) != 0 )
355 return i; 364 return i;
356 365
357 return 0; 366 return 0;
358} 367}
359 368
360QPtrList<Todo> Calendar::todos() 369QPtrList<Todo> Calendar::todos()
361{ 370{
362 QPtrList<Todo> tl = rawTodos(); 371 QPtrList<Todo> tl = rawTodos();
363 mFilter->apply( &tl ); 372 mFilter->apply( &tl );
364 return tl; 373 return tl;
365} 374}
366 375
367// When this is called, the todo have already been added to the calendar. 376// When this is called, the todo have already been added to the calendar.
368// This method is only about linking related todos 377// This method is only about linking related todos
369void Calendar::setupRelations( Incidence *incidence ) 378void Calendar::setupRelations( Incidence *incidence )
370{ 379{
371 QString uid = incidence->uid(); 380 QString uid = incidence->uid();
372 //qDebug("Calendar::setupRelations "); 381 //qDebug("Calendar::setupRelations ");
373 // First, go over the list of orphans and see if this is their parent 382 // First, go over the list of orphans and see if this is their parent
374 while( Incidence* i = mOrphans[ uid ] ) { 383 while( Incidence* i = mOrphans[ uid ] ) {