summaryrefslogtreecommitdiffabout
path: root/libkcal/calendar.cpp
authorzautrix <zautrix>2005-06-10 20:13:31 (UTC)
committer zautrix <zautrix>2005-06-10 20:13:31 (UTC)
commitcdc55afb3d2c3ebd970843b7dce02acb1e6a189b (patch) (unidiff)
tree45f3bfa69a72de4e8b53bbcb2414478ec65cd183 /libkcal/calendar.cpp
parent31fed261955dcb25d06052a8154ac4cc630b0f7d (diff)
downloadkdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.zip
kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.gz
kdepimpi-cdc55afb3d2c3ebd970843b7dce02acb1e6a189b.tar.bz2
many preparations for multiple calendars
Diffstat (limited to 'libkcal/calendar.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp14
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
@@ -9,155 +9,162 @@
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( " 00:00 Europe/London(UTC)" ); 41 setTimeZoneId( " 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 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
109Calendar::~Calendar() 109Calendar::~Calendar()
110{ 110{
111 delete mDefaultFilter; 111 delete mDefaultFilter;
112 if ( mUndoIncidence ) 112 if ( mUndoIncidence )
113 delete mUndoIncidence; 113 delete mUndoIncidence;
114} 114}
115 115void Calendar::setDefaultCalendar( int d )
116{
117 mDefaultCalendar = d;
118}
119int Calendar::defaultCalendar()
120{
121 return mDefaultCalendar;
122}
116const QString &Calendar::getOwner() const 123const QString &Calendar::getOwner() const
117{ 124{
118 return mOwner; 125 return mOwner;
119} 126}
120 127
121bool Calendar::undoDeleteIncidence() 128bool 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}
129void Calendar::setOwner(const QString &os) 136void 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
140void Calendar::setTimeZone(const QString & tz) 147void 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
163QString Calendar::getTimeZoneStr() const 170QString Calendar::getTimeZoneStr() const
@@ -303,97 +310,98 @@ QPtrList<Incidence> Calendar::rawIncidences()
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
310QPtrList<Event> Calendar::events( const QDate &date, bool sorted ) 317QPtrList<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
317QPtrList<Event> Calendar::events( const QDateTime &qdt ) 324QPtrList<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
324QPtrList<Event> Calendar::events( const QDate &start, const QDate &end, 331QPtrList<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
332QPtrList<Event> Calendar::events() 339QPtrList<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}
338void Calendar::addIncidenceBranch(Incidence *i) 345void 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
348bool Calendar::addIncidence(Incidence *i) 355bool 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}
354void Calendar::deleteIncidence(Incidence *in) 362void 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
364Incidence* Calendar::incidence( const QString& uid ) 372Incidence* 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
378QPtrList<Todo> Calendar::todos() 386QPtrList<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
387void Calendar::setupRelations( Incidence *incidence ) 395void 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