summaryrefslogtreecommitdiffabout
path: root/libkcal/incidencebase.cpp
Unidiff
Diffstat (limited to 'libkcal/incidencebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidencebase.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index b5fe2e6..2ddbb01 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,390 +1,423 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
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 <kglobal.h> 21#include <kglobal.h>
22#include <klocale.h> 22#include <klocale.h>
23#include <kdebug.h> 23#include <kdebug.h>
24#include <kidmanager.h> 24#include <kidmanager.h>
25 25
26#include "calformat.h" 26#include "calformat.h"
27#include "syncdefines.h" 27#include "syncdefines.h"
28 28
29#include "incidencebase.h" 29#include "incidencebase.h"
30 30
31using namespace KCal; 31using namespace KCal;
32 32
33IncidenceBase::IncidenceBase() : 33IncidenceBase::IncidenceBase() :
34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false), 34 mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
35 mPilotId(0), mSyncStatus(SYNCMOD) 35 mPilotId(0), mSyncStatus(SYNCMOD)
36{ 36{
37 setUid(CalFormat::createUniqueId()); 37 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 38 mOrganizer = "";
39 mFloats = false; 39 mFloats = false;
40 mDuration = 0; 40 mDuration = 0;
41 mHasDuration = false; 41 mHasDuration = false;
42 mPilotId = 0; 42 mPilotId = 0;
43 mExternalId = ":"; 43 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 45 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 46 mAttendees.setAutoDelete( true );
47 mCalEnabled = true;
48 mAlarmEnabled = true;
49 mCalID = 0;
47} 50}
48 51
49IncidenceBase::IncidenceBase(const IncidenceBase &i) : 52IncidenceBase::IncidenceBase(const IncidenceBase &i) :
50 CustomProperties( i ) 53 CustomProperties( i )
51{ 54{
55
52 mReadOnly = i.mReadOnly; 56 mReadOnly = i.mReadOnly;
53 mDtStart = i.mDtStart; 57 mDtStart = i.mDtStart;
54 mDuration = i.mDuration; 58 mDuration = i.mDuration;
55 mHasDuration = i.mHasDuration; 59 mHasDuration = i.mHasDuration;
56 mOrganizer = i.mOrganizer; 60 mOrganizer = i.mOrganizer;
57 mUid = i.mUid; 61 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID;
58 QPtrList<Attendee> attendees = i.attendees(); 65 QPtrList<Attendee> attendees = i.attendees();
59 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
60 mAttendees.append( new Attendee( *a ) ); 67 mAttendees.append( new Attendee( *a ) );
61 } 68 }
62 mFloats = i.mFloats; 69 mFloats = i.mFloats;
63 mLastModified = i.mLastModified; 70 mLastModified = i.mLastModified;
64 mPilotId = i.mPilotId; 71 mPilotId = i.mPilotId;
65 mTempSyncStat = i.mTempSyncStat; 72 mTempSyncStat = i.mTempSyncStat;
66 mSyncStatus = i.mSyncStatus; 73 mSyncStatus = i.mSyncStatus;
67 mExternalId = i.mExternalId; 74 mExternalId = i.mExternalId;
68 // The copied object is a new one, so it isn't observed by the observer 75 // The copied object is a new one, so it isn't observed by the observer
69 // of the original object. 76 // of the original object.
70 mObservers.clear(); 77 mObservers.clear();
71 78
72 mAttendees.setAutoDelete( true ); 79 mAttendees.setAutoDelete( true );
73} 80}
74 81
75IncidenceBase::~IncidenceBase() 82IncidenceBase::~IncidenceBase()
76{ 83{
77} 84}
78 85
79 86
80bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 ) 87bool KCal::operator==( const IncidenceBase& i1, const IncidenceBase& i2 )
81{ 88{
82 // do not compare mSyncStatus and mExternalId 89 // do not compare mSyncStatus and mExternalId
83 if( i1.attendees().count() != i2.attendees().count() ) { 90 if( i1.attendees().count() != i2.attendees().count() ) {
84 return false; // no need to check further 91 return false; // no need to check further
85 } 92 }
86 if ( i1.attendees().count() > 0 ) { 93 if ( i1.attendees().count() > 0 ) {
87 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ; 94 Attendee * a1 = i1.attendees().first(), *a2 =i2.attendees().first() ;
88 while ( a1 ) { 95 while ( a1 ) {
89 if ( !( (*a1) == (*a2)) ) 96 if ( !( (*a1) == (*a2)) )
90 { 97 {
91 //qDebug("Attendee not equal "); 98 //qDebug("Attendee not equal ");
92 return false; 99 return false;
93 } 100 }
94 a1 = i1.attendees().next(); 101 a1 = i1.attendees().next();
95 a2 = i2.attendees().next(); 102 a2 = i2.attendees().next();
96 } 103 }
97 } 104 }
98 //if ( i1.dtStart() != i2.dtStart() ) 105 //if ( i1.dtStart() != i2.dtStart() )
99 // return false; 106 // return false;
100#if 0 107#if 0
101 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() ); 108 qDebug("1 %d ",i1.doesFloat() == i2.doesFloat() );
102 qDebug("1 %d ",i1.duration() == i2.duration() ); 109 qDebug("1 %d ",i1.duration() == i2.duration() );
103 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() ); 110 qDebug("3 %d ",i1.hasDuration() == i2.hasDuration() );
104 qDebug("1 %d ",i1.pilotId() == i2.pilotId() ); 111 qDebug("1 %d ",i1.pilotId() == i2.pilotId() );
105 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() ); 112 qDebug("1 %d %d %d",i1.syncStatus() == i2.syncStatus() , i1.syncStatus(),i2.syncStatus() );
106 qDebug("6 %d ",i1.organizer() == i2.organizer() ); 113 qDebug("6 %d ",i1.organizer() == i2.organizer() );
107 114
108#endif 115#endif
109 if ( i1.hasDuration() == i2.hasDuration() ) { 116 if ( i1.hasDuration() == i2.hasDuration() ) {
110 if ( i1.hasDuration() ) { 117 if ( i1.hasDuration() ) {
111 if ( i1.duration() != i2.duration() ) 118 if ( i1.duration() != i2.duration() )
112 return false; 119 return false;
113 } 120 }
114 } else { 121 } else {
115 return false; 122 return false;
116 } 123 }
117 124
118 return ( i1.organizer() == i2.organizer() && 125 return ( i1.organizer() == i2.organizer() &&
119 // i1.uid() == i2.uid() && 126 // i1.uid() == i2.uid() &&
120 // Don't compare lastModified, otherwise the operator is not 127 // Don't compare lastModified, otherwise the operator is not
121 // of much use. We are not comparing for identity, after all. 128 // of much use. We are not comparing for identity, after all.
122 i1.doesFloat() == i2.doesFloat() && 129 i1.doesFloat() == i2.doesFloat() &&
123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 130 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
124 // no need to compare mObserver 131 // no need to compare mObserver
125} 132}
126 133
127 134
128QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 135QDateTime IncidenceBase::getEvenTime( QDateTime dt )
129{ 136{
130 QTime t = dt.time(); 137 QTime t = dt.time();
131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 138 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
132 return dt; 139 return dt;
133} 140}
134 141
142void IncidenceBase::setCalID( int id )
143{
144 mCalID = id;
145}
146int IncidenceBase::calID() const
147{
148 return mCalID;
149}
150void IncidenceBase::setCalEnabled( bool b )
151{
152 mCalEnabled = b;
153}
154bool IncidenceBase::calEnabled() const
155{
156 return mCalEnabled;
157}
158
159void IncidenceBase::setAlarmEnabled( bool b )
160{
161 mAlarmEnabled = b;
162}
163bool IncidenceBase::alarmEnabled() const
164{
165 return mAlarmEnabled;
166}
167
135 168
136void IncidenceBase::setUid(const QString &uid) 169void IncidenceBase::setUid(const QString &uid)
137{ 170{
138 mUid = uid; 171 mUid = uid;
139 updated(); 172 updated();
140} 173}
141 174
142QString IncidenceBase::uid() const 175QString IncidenceBase::uid() const
143{ 176{
144 return mUid; 177 return mUid;
145} 178}
146 179
147void IncidenceBase::setLastModified(const QDateTime &lm) 180void IncidenceBase::setLastModified(const QDateTime &lm)
148{ 181{
149 // DON'T! updated() because we call this from 182 // DON'T! updated() because we call this from
150 // Calendar::updateEvent(). 183 // Calendar::updateEvent().
151 mLastModified = getEvenTime(lm); 184 mLastModified = getEvenTime(lm);
152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 185 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
153} 186}
154 187
155QDateTime IncidenceBase::lastModified() const 188QDateTime IncidenceBase::lastModified() const
156{ 189{
157 return mLastModified; 190 return mLastModified;
158} 191}
159 192
160void IncidenceBase::setOrganizer(const QString &o) 193void IncidenceBase::setOrganizer(const QString &o)
161{ 194{
162 // we don't check for readonly here, because it is 195 // we don't check for readonly here, because it is
163 // possible that by setting the organizer we are changing 196 // possible that by setting the organizer we are changing
164 // the event's readonly status... 197 // the event's readonly status...
165 mOrganizer = o; 198 mOrganizer = o;
166 if (mOrganizer.left(7).upper() == "MAILTO:") 199 if (mOrganizer.left(7).upper() == "MAILTO:")
167 mOrganizer = mOrganizer.remove(0,7); 200 mOrganizer = mOrganizer.remove(0,7);
168 201
169 updated(); 202 updated();
170} 203}
171 204
172QString IncidenceBase::organizer() const 205QString IncidenceBase::organizer() const
173{ 206{
174 return mOrganizer; 207 return mOrganizer;
175} 208}
176 209
177void IncidenceBase::setReadOnly( bool readOnly ) 210void IncidenceBase::setReadOnly( bool readOnly )
178{ 211{
179 mReadOnly = readOnly; 212 mReadOnly = readOnly;
180} 213}
181 214
182void IncidenceBase::setDtStart(const QDateTime &dtStart) 215void IncidenceBase::setDtStart(const QDateTime &dtStart)
183{ 216{
184// if (mReadOnly) return; 217// if (mReadOnly) return;
185 mDtStart = getEvenTime(dtStart); 218 mDtStart = getEvenTime(dtStart);
186 updated(); 219 updated();
187} 220}
188 221
189 222
190QDateTime IncidenceBase::dtStart() const 223QDateTime IncidenceBase::dtStart() const
191{ 224{
192 return mDtStart; 225 return mDtStart;
193} 226}
194 227
195QString IncidenceBase::dtStartTimeStr() const 228QString IncidenceBase::dtStartTimeStr() const
196{ 229{
197 return KGlobal::locale()->formatTime(dtStart().time()); 230 return KGlobal::locale()->formatTime(dtStart().time());
198} 231}
199 232
200QString IncidenceBase::dtStartDateStr(bool shortfmt) const 233QString IncidenceBase::dtStartDateStr(bool shortfmt) const
201{ 234{
202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 235 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
203} 236}
204 237
205QString IncidenceBase::dtStartStr(bool shortfmt) const 238QString IncidenceBase::dtStartStr(bool shortfmt) const
206{ 239{
207 if ( doesFloat() ) 240 if ( doesFloat() )
208 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 241 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
209 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 242 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
210} 243}
211 244
212 245
213bool IncidenceBase::doesFloat() const 246bool IncidenceBase::doesFloat() const
214{ 247{
215 return mFloats; 248 return mFloats;
216} 249}
217 250
218void IncidenceBase::setFloats(bool f) 251void IncidenceBase::setFloats(bool f)
219{ 252{
220 if (mReadOnly) return; 253 if (mReadOnly) return;
221 mFloats = f; 254 mFloats = f;
222 updated(); 255 updated();
223} 256}
224 257
225 258
226bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 259bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
227{ 260{
228 if (mReadOnly) return false; 261 if (mReadOnly) return false;
229 if (a->name().left(7).upper() == "MAILTO:") 262 if (a->name().left(7).upper() == "MAILTO:")
230 a->setName(a->name().remove(0,7)); 263 a->setName(a->name().remove(0,7));
231 264
232 QPtrListIterator<Attendee> qli(mAttendees); 265 QPtrListIterator<Attendee> qli(mAttendees);
233 266
234 qli.toFirst(); 267 qli.toFirst();
235 while (qli) { 268 while (qli) {
236 if (*qli.current() == *a) 269 if (*qli.current() == *a)
237 return false; 270 return false;
238 ++qli; 271 ++qli;
239 } 272 }
240 mAttendees.append(a); 273 mAttendees.append(a);
241 if (doupdate) updated(); 274 if (doupdate) updated();
242 return true; 275 return true;
243} 276}
244 277
245#if 0 278#if 0
246void IncidenceBase::removeAttendee(Attendee *a) 279void IncidenceBase::removeAttendee(Attendee *a)
247{ 280{
248 if (mReadOnly) return; 281 if (mReadOnly) return;
249 mAttendees.removeRef(a); 282 mAttendees.removeRef(a);
250 updated(); 283 updated();
251} 284}
252 285
253void IncidenceBase::removeAttendee(const char *n) 286void IncidenceBase::removeAttendee(const char *n)
254{ 287{
255 Attendee *a; 288 Attendee *a;
256 289
257 if (mReadOnly) return; 290 if (mReadOnly) return;
258 for (a = mAttendees.first(); a; a = mAttendees.next()) 291 for (a = mAttendees.first(); a; a = mAttendees.next())
259 if (a->getName() == n) { 292 if (a->getName() == n) {
260 mAttendees.remove(); 293 mAttendees.remove();
261 break; 294 break;
262 } 295 }
263} 296}
264#endif 297#endif
265 298
266void IncidenceBase::clearAttendees() 299void IncidenceBase::clearAttendees()
267{ 300{
268 if (mReadOnly) return; 301 if (mReadOnly) return;
269 mAttendees.clear(); 302 mAttendees.clear();
270} 303}
271 304
272#if 0 305#if 0
273Attendee *IncidenceBase::getAttendee(const char *n) const 306Attendee *IncidenceBase::getAttendee(const char *n) const
274{ 307{
275 QPtrListIterator<Attendee> qli(mAttendees); 308 QPtrListIterator<Attendee> qli(mAttendees);
276 309
277 qli.toFirst(); 310 qli.toFirst();
278 while (qli) { 311 while (qli) {
279 if (qli.current()->getName() == n) 312 if (qli.current()->getName() == n)
280 return qli.current(); 313 return qli.current();
281 ++qli; 314 ++qli;
282 } 315 }
283 return 0L; 316 return 0L;
284} 317}
285#endif 318#endif
286 319
287Attendee *IncidenceBase::attendeeByMail(const QString &email) 320Attendee *IncidenceBase::attendeeByMail(const QString &email)
288{ 321{
289 QPtrListIterator<Attendee> qli(mAttendees); 322 QPtrListIterator<Attendee> qli(mAttendees);
290 323
291 qli.toFirst(); 324 qli.toFirst();
292 while (qli) { 325 while (qli) {
293 if (qli.current()->email().lower() == email.lower()) 326 if (qli.current()->email().lower() == email.lower())
294 return qli.current(); 327 return qli.current();
295 ++qli; 328 ++qli;
296 } 329 }
297 return 0L; 330 return 0L;
298} 331}
299 332
300Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 333Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
301{ 334{
302 QPtrListIterator<Attendee> qli(mAttendees); 335 QPtrListIterator<Attendee> qli(mAttendees);
303 336
304 QStringList mails = emails; 337 QStringList mails = emails;
305 if (!email.isEmpty()) { 338 if (!email.isEmpty()) {
306 mails.append(email); 339 mails.append(email);
307 } 340 }
308 qli.toFirst(); 341 qli.toFirst();
309 while (qli) { 342 while (qli) {
310 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 343 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
311 if (qli.current()->email().lower() == (*it).lower()) 344 if (qli.current()->email().lower() == (*it).lower())
312 return qli.current(); 345 return qli.current();
313 } 346 }
314 347
315 ++qli; 348 ++qli;
316 } 349 }
317 return 0L; 350 return 0L;
318} 351}
319 352
320void IncidenceBase::setDuration(int seconds) 353void IncidenceBase::setDuration(int seconds)
321{ 354{
322 mDuration = seconds; 355 mDuration = seconds;
323 setHasDuration(true); 356 setHasDuration(true);
324} 357}
325 358
326int IncidenceBase::duration() const 359int IncidenceBase::duration() const
327{ 360{
328 return mDuration; 361 return mDuration;
329} 362}
330 363
331void IncidenceBase::setHasDuration(bool b) 364void IncidenceBase::setHasDuration(bool b)
332{ 365{
333 mHasDuration = b; 366 mHasDuration = b;
334} 367}
335 368
336bool IncidenceBase::hasDuration() const 369bool IncidenceBase::hasDuration() const
337{ 370{
338 return mHasDuration; 371 return mHasDuration;
339} 372}
340 373
341void IncidenceBase::setSyncStatus(int stat) 374void IncidenceBase::setSyncStatus(int stat)
342{ 375{
343 if (mReadOnly) return; 376 if (mReadOnly) return;
344 mSyncStatus = stat; 377 mSyncStatus = stat;
345} 378}
346 379
347int IncidenceBase::syncStatus() const 380int IncidenceBase::syncStatus() const
348{ 381{
349 return mSyncStatus; 382 return mSyncStatus;
350} 383}
351 384
352void IncidenceBase::setPilotId( int id ) 385void IncidenceBase::setPilotId( int id )
353{ 386{
354 if (mReadOnly) return; 387 if (mReadOnly) return;
355 mPilotId = id; 388 mPilotId = id;
356} 389}
357 390
358int IncidenceBase::pilotId() const 391int IncidenceBase::pilotId() const
359{ 392{
360 return mPilotId; 393 return mPilotId;
361} 394}
362 395
363int IncidenceBase::tempSyncStat() const 396int IncidenceBase::tempSyncStat() const
364{ 397{
365 return mTempSyncStat; 398 return mTempSyncStat;
366} 399}
367void IncidenceBase::setTempSyncStat( int id ) 400void IncidenceBase::setTempSyncStat( int id )
368{ 401{
369 if (mReadOnly) return; 402 if (mReadOnly) return;
370 mTempSyncStat = id; 403 mTempSyncStat = id;
371} 404}
372 405
373void IncidenceBase::removeID(const QString &prof) 406void IncidenceBase::removeID(const QString &prof)
374{ 407{
375 if ( prof.isEmpty() ) 408 if ( prof.isEmpty() )
376 mExternalId = ":"; 409 mExternalId = ":";
377 else 410 else
378 mExternalId = KIdManager::removeId ( mExternalId, prof); 411 mExternalId = KIdManager::removeId ( mExternalId, prof);
379 412
380} 413}
381void IncidenceBase::setID( const QString & prof , const QString & id ) 414void IncidenceBase::setID( const QString & prof , const QString & id )
382{ 415{
383 mExternalId = KIdManager::setId ( mExternalId, prof, id ); 416 mExternalId = KIdManager::setId ( mExternalId, prof, id );
384} 417}
385QString IncidenceBase::getID( const QString & prof) 418QString IncidenceBase::getID( const QString & prof)
386{ 419{
387 return KIdManager::getId ( mExternalId, prof ); 420 return KIdManager::getId ( mExternalId, prof );
388} 421}
389 422
390// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: 423// example :Sharp_DTM;22;23566:TP;-1;8654:TPP;18;0: