summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/calendarlocal.cpp35
-rw-r--r--libkcal/calendarlocal.h2
-rw-r--r--libkcal/incidencebase.cpp8
-rw-r--r--libkcal/incidencebase.h1
5 files changed, 37 insertions, 10 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 14a1a45..95477cd 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -76,8 +76,9 @@ public:
virtual void close() = 0;
virtual void addCalendar( Calendar* ) = 0;
virtual bool addCalendarFile( QString name, int id ) = 0;
virtual bool mergeCalendarFile( QString name ) = 0;
+ virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
virtual void setSyncEventsReadOnly() = 0;
virtual void stopAllTodos() = 0;
/**
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3e42ec0..e37a7ad 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -78,14 +78,15 @@ bool CalendarLocal::mergeCalendarFile( QString name )
}
return false;
}
-Incidence* CalendarLocal::incidenceForUid( const QString& uid )
+Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
{
Todo *todo;;
Incidence *retVal = 0;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->uid() == uid ) {
+ if ( doNotCheckDuplicates ) return todo;
if ( retVal ) {
if ( retVal->calID() > todo->calID() ) {
retVal = todo;
}
@@ -97,8 +98,9 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid )
if ( retVal ) return retVal;
Event *event;
for ( event = mEventList.first(); event; event = mEventList.next() ) {
if ( event->uid() == uid ) {
+ if ( doNotCheckDuplicates ) return event;
if ( retVal ) {
if ( retVal->calID() > event->calID() ) {
retVal = event;
}
@@ -109,8 +111,9 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid )
}
if ( retVal ) return retVal;
for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
if ( it->uid() == uid ) {
+ if ( doNotCheckDuplicates ) return it;
if ( retVal ) {
if ( retVal->calID() > it->calID() ) {
retVal = it;
}
@@ -122,19 +125,33 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid )
}
bool CalendarLocal::mergeCalendar( Calendar* remote )
{
+ // 1 look for raw inc in local
+ // if inc not in remote, delete in local
+ // 2 look for raw inc in remote
+ // if inc in local, replace it
+ // if not in local, add it to default calendar
+ QPtrList<Incidence> localInc = rawIncidences();
+ Incidence* inL = localInc.first();
+ while ( inL ) {
+ if ( ! inL->isReadOnly () )
+ if ( !remote->incidenceForUid( inL->uid(), true ))
+ deleteIncidence( inL );
+ inL = localInc.next();
+ }
QPtrList<Incidence> er = remote->rawIncidences();
Incidence* inR = er.first();
- Incidence* inL;
while ( inR ) {
- inL = incidenceForUid( inR->uid() );
+ inL = incidenceForUid( inR->uid(),false );
if ( inL ) {
- int calID = inL->calID();
- deleteIncidence( inL );
- inL = inR->clone();
- inL->setCalID( calID );
- addIncidence( inL );
+ if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
+ int calID = inL->calID();
+ deleteIncidence( inL );
+ inL = inR->clone();
+ inL->setCalID( calID );
+ addIncidence( inL );
+ }
} else {
inL = inR->clone();
inL->setCalID( 0 );// add to default cal
addIncidence( inL );
@@ -142,8 +159,10 @@ bool CalendarLocal::mergeCalendar( Calendar* remote )
inR = er.next();
}
return true;
}
+
+
bool CalendarLocal::addCalendarFile( QString name, int id )
{
CalendarLocal calendar( timeZoneId() );
calendar.setDefaultCalendar( id );
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 23b0542..a7a85c8 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -46,9 +46,9 @@ class CalendarLocal : public Calendar
void addCalendar( Calendar* );
bool addCalendarFile( QString name, int id );
bool mergeCalendarFile( QString name );
bool mergeCalendar( Calendar* cal );
- Incidence* incidenceForUid( const QString& uid );
+ Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates );
void setSyncEventsReadOnly();
void stopAllTodos();
/**
Loads a calendar on disk in vCalendar or iCalendar format into the current
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index dcead02..1a19f3e 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -33,8 +33,9 @@ using namespace KCal;
IncidenceBase::IncidenceBase() :
mReadOnly(false), mFloats(true), mDuration(0), mHasDuration(false),
mPilotId(0), mSyncStatus(SYNCMOD)
{
+ blockLastModified = false;
setUid(CalFormat::createUniqueId());
mOrganizer = "";
mFloats = false;
mDuration = 0;
@@ -52,8 +53,9 @@ IncidenceBase::IncidenceBase() :
IncidenceBase::IncidenceBase(const IncidenceBase &i) :
CustomProperties( i )
{
+ blockLastModified = false;
mReadOnly = i.mReadOnly;
mDtStart = i.mDtStart;
mDuration = i.mDuration;
mHasDuration = i.mHasDuration;
@@ -148,10 +150,13 @@ void IncidenceBase::setTagged( bool b)
mIsTagged = b;
}
void IncidenceBase::setCalID( int id )
{
- if ( mCalID > 0 )
+ if ( mCalID > 0 ) {
+ blockLastModified = true;
updated();
+ blockLastModified = false;
+ }
mCalID = id;
}
int IncidenceBase::calID() const
{
@@ -188,8 +193,9 @@ QString IncidenceBase::uid() const
}
void IncidenceBase::setLastModified(const QDateTime &lm)
{
+ if ( blockLastModified ) return;
// DON'T! updated() because we call this from
// Calendar::updateEvent().
mLastModified = getEvenTime(lm);
//qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index bccf287..bed73db 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -149,8 +149,9 @@ class IncidenceBase : public CustomProperties
bool alarmEnabled() const;
bool isTagged() const;
void setTagged( bool );
protected:
+ bool blockLastModified;
bool mIsTagged;
QDateTime mDtStart;
bool mReadOnly;
QDateTime getEvenTime( QDateTime );