-rw-r--r-- | libkcal/calendar.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index 7e8e2c5..f4350d9 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -33,49 +33,49 @@ | |||
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) |
@@ -91,49 +91,56 @@ void Calendar::init() | |||
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 | ||
@@ -327,49 +334,50 @@ QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, | |||
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; |