00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include <kglobal.h>
00023
#include <klocale.h>
00024
#include <kdebug.h>
00025
00026
#include "calformat.h"
00027
00028
#include "incidencebase.h"
00029
00030
using namespace KCal;
00031
00032 IncidenceBase::IncidenceBase()
00033 : mReadOnly( false ), mFloats( true ), mDuration( 0 ), mHasDuration( false ),
00034 mPilotId( 0 ), mSyncStatus( SYNCMOD )
00035 {
00036
setUid( CalFormat::createUniqueId() );
00037
00038 mAttendees.setAutoDelete(
true );
00039 }
00040
00041 IncidenceBase::IncidenceBase(
const IncidenceBase &i) :
00042
CustomProperties( i )
00043 {
00044 mReadOnly = i.
mReadOnly;
00045 mDtStart = i.
mDtStart;
00046 mDuration = i.
mDuration;
00047 mHasDuration = i.
mHasDuration;
00048 mOrganizer = i.
mOrganizer;
00049 mUid = i.
mUid;
00050
Attendee::List attendees = i.
attendees();
00051 Attendee::List::ConstIterator it;
00052
for( it = attendees.begin(); it != attendees.end(); ++it ) {
00053 mAttendees.append(
new Attendee( *(*it) ) );
00054 }
00055 mFloats = i.
mFloats;
00056 mLastModified = i.
mLastModified;
00057 mPilotId = i.
mPilotId;
00058 mSyncStatus = i.
mSyncStatus;
00059
00060
00061
00062 mObservers.clear();
00063
00064 mAttendees.setAutoDelete(
true );
00065 }
00066
00067 IncidenceBase::~IncidenceBase()
00068 {
00069 }
00070
00071
00072
bool IncidenceBase::operator==(
const IncidenceBase& i2 )
const
00073
{
00074
if(
attendees().count() != i2.
attendees().count() ) {
00075
return false;
00076 }
00077
00078
Attendee::List al1 =
attendees();
00079
Attendee::List al2 = i2.
attendees();
00080 Attendee::List::ConstIterator a1 = al1.begin();
00081 Attendee::List::ConstIterator a2 = al2.begin();
00082
for( ; a1 != al1.end() && a2 != al2.end(); ++a1, ++a2 ) {
00083
if( **a1 == **a2 )
00084
continue;
00085
else {
00086
return false;
00087 }
00088 }
00089
00090
return (
dtStart() == i2.
dtStart() &&
00091 organizer() == i2.
organizer() &&
00092
uid() == i2.
uid() &&
00093
00094
00095
doesFloat() == i2.
doesFloat() &&
00096 duration() == i2.
duration() &&
00097 hasDuration() == i2.
hasDuration() &&
00098
pilotId() == i2.
pilotId() &&
00099
syncStatus() == i2.
syncStatus() );
00100
00101 }
00102
00103
00104
00105
00106 void IncidenceBase::setUid(
const QString &uid)
00107 {
00108 mUid = uid;
00109
updated();
00110 }
00111
00112 QString IncidenceBase::uid()
const
00113
{
00114
return mUid;
00115 }
00116
00117 void IncidenceBase::setLastModified(
const QDateTime &lm)
00118 {
00119
00120
00121
00122
00123
QDateTime current = lm;
00124
QTime t = current.time();
00125 t.setHMS( t.hour(), t.minute(), t.second(), 0 );
00126 current.setTime( t );
00127
00128 mLastModified = current;
00129 }
00130
00131 QDateTime IncidenceBase::lastModified()
const
00132
{
00133
return mLastModified;
00134 }
00135
00136 void IncidenceBase::setOrganizer(
const QString &o)
00137 {
00138
00139
00140
00141 mOrganizer = o;
00142
if (mOrganizer.left(7).upper() ==
"MAILTO:")
00143 mOrganizer = mOrganizer.remove(0,7);
00144
00145
updated();
00146 }
00147
00148
QString IncidenceBase::organizer()
const
00149
{
00150
return mOrganizer;
00151 }
00152
00153 void IncidenceBase::setReadOnly(
bool readOnly )
00154 {
00155 mReadOnly = readOnly;
00156 }
00157
00158 void IncidenceBase::setDtStart(
const QDateTime &dtStart)
00159 {
00160
00161 mDtStart = dtStart;
00162
updated();
00163 }
00164
00165 QDateTime IncidenceBase::dtStart()
const
00166
{
00167
return mDtStart;
00168 }
00169
00170 QString IncidenceBase::dtStartTimeStr()
const
00171
{
00172
return KGlobal::locale()->formatTime(
dtStart().time());
00173 }
00174
00175 QString IncidenceBase::dtStartDateStr(
bool shortfmt)
const
00176
{
00177
return KGlobal::locale()->formatDate(
dtStart().date(),shortfmt);
00178 }
00179
00180 QString IncidenceBase::dtStartStr()
const
00181
{
00182
return KGlobal::locale()->formatDateTime(
dtStart());
00183 }
00184
00185
00186 bool IncidenceBase::doesFloat()
const
00187
{
00188
return mFloats;
00189 }
00190
00191 void IncidenceBase::setFloats(
bool f)
00192 {
00193
if (mReadOnly)
return;
00194 mFloats = f;
00195
updated();
00196 }
00197
00198
00199 void IncidenceBase::addComment(
const QString& comment)
00200 {
00201 mComments += comment;
00202 }
00203
00204 bool IncidenceBase::removeComment(
QString& comment)
00205 {
00206
bool found =
false;
00207 QStringList::Iterator i;
00208
00209
for ( i = mComments.begin(); !found && i != mComments.end(); ++i ) {
00210
if ( (*i) == comment) {
00211 found =
true;
00212 mComments.remove(i);
00213 }
00214 }
00215
00216
return found;
00217 }
00218
00219 void IncidenceBase::clearComments()
00220 {
00221 mComments.clear();
00222 }
00223
00224 QStringList IncidenceBase::comments()
const
00225
{
00226
return mComments;
00227 }
00228
00229
00230 void IncidenceBase::addAttendee(
Attendee *a,
bool doupdate)
00231 {
00232
00233
if (mReadOnly)
return;
00234
00235
if (a->
name().left(7).upper() ==
"MAILTO:")
00236 a->
setName(a->
name().remove(0,7));
00237
00238 mAttendees.append(a);
00239
if (doupdate)
updated();
00240 }
00241
00242
#if 0
00243
void IncidenceBase::removeAttendee(
Attendee *a)
00244 {
00245
if (mReadOnly)
return;
00246 mAttendees.
removeRef(a);
00247
updated();
00248 }
00249
00250
void IncidenceBase::removeAttendee(
const char *n)
00251 {
00252
Attendee *a;
00253
00254
if (mReadOnly)
return;
00255
for (a = mAttendees.first(); a; a = mAttendees.next())
00256
if (a->getName() == n) {
00257 mAttendees.remove();
00258
break;
00259 }
00260 }
00261
#endif
00262
00263 void IncidenceBase::clearAttendees()
00264 {
00265
if (mReadOnly)
return;
00266 mAttendees.clear();
00267 }
00268
00269 Attendee *
IncidenceBase::attendeeByMail(
const QString &email )
const
00270
{
00271 Attendee::List::ConstIterator it;
00272
for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00273
if ( (*it)->email() == email )
return *it;
00274 }
00275
00276
return 0;
00277 }
00278
00279 Attendee *
IncidenceBase::attendeeByMails(
const QStringList &emails,
00280
const QString &email)
const
00281
{
00282
QStringList mails = emails;
00283
if ( !email.isEmpty() ) mails.append( email );
00284
00285 Attendee::List::ConstIterator itA;
00286
for( itA = mAttendees.begin(); itA != mAttendees.end(); ++itA ) {
00287
for ( QStringList::Iterator it = mails.begin(); it != mails.end(); ++it ) {
00288
if ( (*itA)->email() == email )
return *itA;
00289 }
00290 }
00291
00292
return 0;
00293 }
00294
00295 Attendee *
IncidenceBase::attendeeByUid(
const QString &uid )
const
00296
{
00297 Attendee::List::ConstIterator it;
00298
for( it = mAttendees.begin(); it != mAttendees.end(); ++it ) {
00299
if ( (*it)->uid() == uid )
return *it;
00300 }
00301
00302
return 0;
00303 }
00304
00305
00306
void IncidenceBase::setDuration(
int seconds)
00307 {
00308 mDuration = seconds;
00309 setHasDuration(
true);
00310 }
00311
00312
int IncidenceBase::duration()
const
00313
{
00314
return mDuration;
00315 }
00316
00317
void IncidenceBase::setHasDuration(
bool hasDuration)
00318 {
00319 mHasDuration = hasDuration;
00320 }
00321
00322
bool IncidenceBase::hasDuration()
const
00323
{
00324
return mHasDuration;
00325 }
00326
00327 void IncidenceBase::setSyncStatus(
int stat)
00328 {
00329
if (mReadOnly)
return;
00330 mSyncStatus = stat;
00331 }
00332
00333 int IncidenceBase::syncStatus()
const
00334
{
00335
return mSyncStatus;
00336 }
00337
00338 void IncidenceBase::setPilotId(
unsigned long id )
00339 {
00340
if (mReadOnly)
return;
00341
00342 mPilotId =
id;
00343 }
00344
00345 unsigned long IncidenceBase::pilotId()
const
00346
{
00347
return mPilotId;
00348 }
00349
00350 void IncidenceBase::registerObserver( IncidenceBase::Observer *observer )
00351 {
00352
if( !mObservers.contains( observer ) ) mObservers.append( observer );
00353 }
00354
00355 void IncidenceBase::unRegisterObserver( IncidenceBase::Observer *observer )
00356 {
00357 mObservers.remove( observer );
00358 }
00359
00360 void IncidenceBase::updated()
00361 {
00362
QPtrListIterator<Observer> it(mObservers);
00363
while( it.current() ) {
00364 Observer *o = it.current();
00365 ++it;
00366 o->incidenceUpdated(
this );
00367 }
00368 }