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