summaryrefslogtreecommitdiffabout
path: root/libkcal/incidencebase.cpp
Unidiff
Diffstat (limited to 'libkcal/incidencebase.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/incidencebase.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 51f2e9d..1e99082 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -1,307 +1,314 @@
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} 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() ) {
110 if ( i1.hasDuration() ) {
111 if ( i1.duration() != i2.duration() )
112 return false;
113 }
114 } else {
115 return false;
116 }
117
109 return ( i1.organizer() == i2.organizer() && 118 return ( i1.organizer() == i2.organizer() &&
110 // i1.uid() == i2.uid() && 119 // i1.uid() == i2.uid() &&
111 // Don't compare lastModified, otherwise the operator is not 120 // Don't compare lastModified, otherwise the operator is not
112 // of much use. We are not comparing for identity, after all. 121 // of much use. We are not comparing for identity, after all.
113 i1.doesFloat() == i2.doesFloat() && 122 i1.doesFloat() == i2.doesFloat() &&
114 i1.duration() == i2.duration() &&
115 i1.hasDuration() == i2.hasDuration() &&
116 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() ); 123 i1.pilotId() == i2.pilotId() );// && i1.syncStatus() == i2.syncStatus() );
117 // no need to compare mObserver 124 // no need to compare mObserver
118} 125}
119 126
120 127
121QDateTime IncidenceBase::getEvenTime( QDateTime dt ) 128QDateTime IncidenceBase::getEvenTime( QDateTime dt )
122{ 129{
123 QTime t = dt.time(); 130 QTime t = dt.time();
124 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); 131 dt.setTime( QTime (t.hour (), t.minute (), t.second () ) );
125 return dt; 132 return dt;
126} 133}
127 134
128 135
129void IncidenceBase::setUid(const QString &uid) 136void IncidenceBase::setUid(const QString &uid)
130{ 137{
131 mUid = uid; 138 mUid = uid;
132 updated(); 139 updated();
133} 140}
134 141
135QString IncidenceBase::uid() const 142QString IncidenceBase::uid() const
136{ 143{
137 return mUid; 144 return mUid;
138} 145}
139 146
140void IncidenceBase::setLastModified(const QDateTime &lm) 147void IncidenceBase::setLastModified(const QDateTime &lm)
141{ 148{
142 // DON'T! updated() because we call this from 149 // DON'T! updated() because we call this from
143 // Calendar::updateEvent(). 150 // Calendar::updateEvent().
144 mLastModified = getEvenTime(lm); 151 mLastModified = getEvenTime(lm);
145 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 152 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
146} 153}
147 154
148QDateTime IncidenceBase::lastModified() const 155QDateTime IncidenceBase::lastModified() const
149{ 156{
150 return mLastModified; 157 return mLastModified;
151} 158}
152 159
153void IncidenceBase::setOrganizer(const QString &o) 160void IncidenceBase::setOrganizer(const QString &o)
154{ 161{
155 // we don't check for readonly here, because it is 162 // we don't check for readonly here, because it is
156 // possible that by setting the organizer we are changing 163 // possible that by setting the organizer we are changing
157 // the event's readonly status... 164 // the event's readonly status...
158 mOrganizer = o; 165 mOrganizer = o;
159 if (mOrganizer.left(7).upper() == "MAILTO:") 166 if (mOrganizer.left(7).upper() == "MAILTO:")
160 mOrganizer = mOrganizer.remove(0,7); 167 mOrganizer = mOrganizer.remove(0,7);
161 168
162 updated(); 169 updated();
163} 170}
164 171
165QString IncidenceBase::organizer() const 172QString IncidenceBase::organizer() const
166{ 173{
167 return mOrganizer; 174 return mOrganizer;
168} 175}
169 176
170void IncidenceBase::setReadOnly( bool readOnly ) 177void IncidenceBase::setReadOnly( bool readOnly )
171{ 178{
172 mReadOnly = readOnly; 179 mReadOnly = readOnly;
173} 180}
174 181
175void IncidenceBase::setDtStart(const QDateTime &dtStart) 182void IncidenceBase::setDtStart(const QDateTime &dtStart)
176{ 183{
177// if (mReadOnly) return; 184// if (mReadOnly) return;
178 mDtStart = getEvenTime(dtStart); 185 mDtStart = getEvenTime(dtStart);
179 updated(); 186 updated();
180} 187}
181 188
182 189
183QDateTime IncidenceBase::dtStart() const 190QDateTime IncidenceBase::dtStart() const
184{ 191{
185 return mDtStart; 192 return mDtStart;
186} 193}
187 194
188QString IncidenceBase::dtStartTimeStr() const 195QString IncidenceBase::dtStartTimeStr() const
189{ 196{
190 return KGlobal::locale()->formatTime(dtStart().time()); 197 return KGlobal::locale()->formatTime(dtStart().time());
191} 198}
192 199
193QString IncidenceBase::dtStartDateStr(bool shortfmt) const 200QString IncidenceBase::dtStartDateStr(bool shortfmt) const
194{ 201{
195 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt); 202 return KGlobal::locale()->formatDate(dtStart().date(),shortfmt);
196} 203}
197 204
198QString IncidenceBase::dtStartStr(bool shortfmt) const 205QString IncidenceBase::dtStartStr(bool shortfmt) const
199{ 206{
200 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt); 207 return KGlobal::locale()->formatDateTime(dtStart(), shortfmt);
201} 208}
202 209
203 210
204bool IncidenceBase::doesFloat() const 211bool IncidenceBase::doesFloat() const
205{ 212{
206 return mFloats; 213 return mFloats;
207} 214}
208 215
209void IncidenceBase::setFloats(bool f) 216void IncidenceBase::setFloats(bool f)
210{ 217{
211 if (mReadOnly) return; 218 if (mReadOnly) return;
212 mFloats = f; 219 mFloats = f;
213 updated(); 220 updated();
214} 221}
215 222
216 223
217bool IncidenceBase::addAttendee(Attendee *a, bool doupdate) 224bool IncidenceBase::addAttendee(Attendee *a, bool doupdate)
218{ 225{
219 if (mReadOnly) return false; 226 if (mReadOnly) return false;
220 if (a->name().left(7).upper() == "MAILTO:") 227 if (a->name().left(7).upper() == "MAILTO:")
221 a->setName(a->name().remove(0,7)); 228 a->setName(a->name().remove(0,7));
222 229
223 QPtrListIterator<Attendee> qli(mAttendees); 230 QPtrListIterator<Attendee> qli(mAttendees);
224 231
225 qli.toFirst(); 232 qli.toFirst();
226 while (qli) { 233 while (qli) {
227 if (*qli.current() == *a) 234 if (*qli.current() == *a)
228 return false; 235 return false;
229 ++qli; 236 ++qli;
230 } 237 }
231 mAttendees.append(a); 238 mAttendees.append(a);
232 if (doupdate) updated(); 239 if (doupdate) updated();
233 return true; 240 return true;
234} 241}
235 242
236#if 0 243#if 0
237void IncidenceBase::removeAttendee(Attendee *a) 244void IncidenceBase::removeAttendee(Attendee *a)
238{ 245{
239 if (mReadOnly) return; 246 if (mReadOnly) return;
240 mAttendees.removeRef(a); 247 mAttendees.removeRef(a);
241 updated(); 248 updated();
242} 249}
243 250
244void IncidenceBase::removeAttendee(const char *n) 251void IncidenceBase::removeAttendee(const char *n)
245{ 252{
246 Attendee *a; 253 Attendee *a;
247 254
248 if (mReadOnly) return; 255 if (mReadOnly) return;
249 for (a = mAttendees.first(); a; a = mAttendees.next()) 256 for (a = mAttendees.first(); a; a = mAttendees.next())
250 if (a->getName() == n) { 257 if (a->getName() == n) {
251 mAttendees.remove(); 258 mAttendees.remove();
252 break; 259 break;
253 } 260 }
254} 261}
255#endif 262#endif
256 263
257void IncidenceBase::clearAttendees() 264void IncidenceBase::clearAttendees()
258{ 265{
259 if (mReadOnly) return; 266 if (mReadOnly) return;
260 mAttendees.clear(); 267 mAttendees.clear();
261} 268}
262 269
263#if 0 270#if 0
264Attendee *IncidenceBase::getAttendee(const char *n) const 271Attendee *IncidenceBase::getAttendee(const char *n) const
265{ 272{
266 QPtrListIterator<Attendee> qli(mAttendees); 273 QPtrListIterator<Attendee> qli(mAttendees);
267 274
268 qli.toFirst(); 275 qli.toFirst();
269 while (qli) { 276 while (qli) {
270 if (qli.current()->getName() == n) 277 if (qli.current()->getName() == n)
271 return qli.current(); 278 return qli.current();
272 ++qli; 279 ++qli;
273 } 280 }
274 return 0L; 281 return 0L;
275} 282}
276#endif 283#endif
277 284
278Attendee *IncidenceBase::attendeeByMail(const QString &email) 285Attendee *IncidenceBase::attendeeByMail(const QString &email)
279{ 286{
280 QPtrListIterator<Attendee> qli(mAttendees); 287 QPtrListIterator<Attendee> qli(mAttendees);
281 288
282 qli.toFirst(); 289 qli.toFirst();
283 while (qli) { 290 while (qli) {
284 if (qli.current()->email().lower() == email.lower()) 291 if (qli.current()->email().lower() == email.lower())
285 return qli.current(); 292 return qli.current();
286 ++qli; 293 ++qli;
287 } 294 }
288 return 0L; 295 return 0L;
289} 296}
290 297
291Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email) 298Attendee *IncidenceBase::attendeeByMails(const QStringList &emails, const QString& email)
292{ 299{
293 QPtrListIterator<Attendee> qli(mAttendees); 300 QPtrListIterator<Attendee> qli(mAttendees);
294 301
295 QStringList mails = emails; 302 QStringList mails = emails;
296 if (!email.isEmpty()) { 303 if (!email.isEmpty()) {
297 mails.append(email); 304 mails.append(email);
298 } 305 }
299 qli.toFirst(); 306 qli.toFirst();
300 while (qli) { 307 while (qli) {
301 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) { 308 for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
302 if (qli.current()->email().lower() == (*it).lower()) 309 if (qli.current()->email().lower() == (*it).lower())
303 return qli.current(); 310 return qli.current();
304 } 311 }
305 312
306 ++qli; 313 ++qli;
307 } 314 }