summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
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
@@ -68,24 +68,25 @@ public:
68 Incidence * undoIncidence() { return mUndoIncidence; }; 68 Incidence * undoIncidence() { return mUndoIncidence; };
69 bool undoDeleteIncidence(); 69 bool undoDeleteIncidence();
70 void deleteIncidence(Incidence *in); 70 void deleteIncidence(Incidence *in);
71 void resetTempSyncStat(); 71 void resetTempSyncStat();
72 void resetPilotStat(int id); 72 void resetPilotStat(int id);
73 /** 73 /**
74 Clears out the current calendar, freeing all used memory etc. 74 Clears out the current calendar, freeing all used memory etc.
75 */ 75 */
76 virtual void close() = 0; 76 virtual void close() = 0;
77 virtual void addCalendar( Calendar* ) = 0; 77 virtual void addCalendar( Calendar* ) = 0;
78 virtual bool addCalendarFile( QString name, int id ) = 0; 78 virtual bool addCalendarFile( QString name, int id ) = 0;
79 virtual bool mergeCalendarFile( QString name ) = 0; 79 virtual bool mergeCalendarFile( QString name ) = 0;
80 virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0;
80 virtual void setSyncEventsReadOnly() = 0; 81 virtual void setSyncEventsReadOnly() = 0;
81 virtual void stopAllTodos() = 0; 82 virtual void stopAllTodos() = 0;
82 83
83 /** 84 /**
84 Sync changes in memory to persistant storage. 85 Sync changes in memory to persistant storage.
85 */ 86 */
86 virtual void save() = 0; 87 virtual void save() = 0;
87 virtual QPtrList<Event> getExternLastSyncEvents() = 0; 88 virtual QPtrList<Event> getExternLastSyncEvents() = 0;
88 virtual void removeSyncInfo( QString syncProfile) = 0; 89 virtual void removeSyncInfo( QString syncProfile) = 0;
89 virtual bool isSaving() { return false; } 90 virtual bool isSaving() { return false; }
90 91
91 /** 92 /**
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 3e42ec0..e37a7ad 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -70,88 +70,107 @@ CalendarLocal::~CalendarLocal()
70} 70}
71bool CalendarLocal::mergeCalendarFile( QString name ) 71bool CalendarLocal::mergeCalendarFile( QString name )
72{ 72{
73 CalendarLocal calendar( timeZoneId() ); 73 CalendarLocal calendar( timeZoneId() );
74 calendar.setDefaultCalendar( 1 ); 74 calendar.setDefaultCalendar( 1 );
75 if ( calendar.load( name ) ) { 75 if ( calendar.load( name ) ) {
76 mergeCalendar( &calendar ); 76 mergeCalendar( &calendar );
77 return true; 77 return true;
78 } 78 }
79 return false; 79 return false;
80} 80}
81 81
82Incidence* CalendarLocal::incidenceForUid( const QString& uid ) 82Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates)
83{ 83{
84 Todo *todo;; 84 Todo *todo;;
85 Incidence *retVal = 0; 85 Incidence *retVal = 0;
86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 86 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
87 if ( todo->uid() == uid ) { 87 if ( todo->uid() == uid ) {
88 if ( doNotCheckDuplicates ) return todo;
88 if ( retVal ) { 89 if ( retVal ) {
89 if ( retVal->calID() > todo->calID() ) { 90 if ( retVal->calID() > todo->calID() ) {
90 retVal = todo; 91 retVal = todo;
91 } 92 }
92 } else { 93 } else {
93 retVal = todo; 94 retVal = todo;
94 } 95 }
95 } 96 }
96 } 97 }
97 if ( retVal ) return retVal; 98 if ( retVal ) return retVal;
98 Event *event; 99 Event *event;
99 for ( event = mEventList.first(); event; event = mEventList.next() ) { 100 for ( event = mEventList.first(); event; event = mEventList.next() ) {
100 if ( event->uid() == uid ) { 101 if ( event->uid() == uid ) {
102 if ( doNotCheckDuplicates ) return event;
101 if ( retVal ) { 103 if ( retVal ) {
102 if ( retVal->calID() > event->calID() ) { 104 if ( retVal->calID() > event->calID() ) {
103 retVal = event; 105 retVal = event;
104 } 106 }
105 } else { 107 } else {
106 retVal = event; 108 retVal = event;
107 } 109 }
108 } 110 }
109 } 111 }
110 if ( retVal ) return retVal; 112 if ( retVal ) return retVal;
111 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 113 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
112 if ( it->uid() == uid ) { 114 if ( it->uid() == uid ) {
115 if ( doNotCheckDuplicates ) return it;
113 if ( retVal ) { 116 if ( retVal ) {
114 if ( retVal->calID() > it->calID() ) { 117 if ( retVal->calID() > it->calID() ) {
115 retVal = it; 118 retVal = it;
116 } 119 }
117 } else { 120 } else {
118 retVal = it; 121 retVal = it;
119 } 122 }
120 } 123 }
121 return retVal; 124 return retVal;
122} 125}
123 126
124bool CalendarLocal::mergeCalendar( Calendar* remote ) 127bool CalendarLocal::mergeCalendar( Calendar* remote )
125{ 128{
129 // 1 look for raw inc in local
130 // if inc not in remote, delete in local
131 // 2 look for raw inc in remote
132 // if inc in local, replace it
133 // if not in local, add it to default calendar
134 QPtrList<Incidence> localInc = rawIncidences();
135 Incidence* inL = localInc.first();
136 while ( inL ) {
137 if ( ! inL->isReadOnly () )
138 if ( !remote->incidenceForUid( inL->uid(), true ))
139 deleteIncidence( inL );
140 inL = localInc.next();
141 }
126 QPtrList<Incidence> er = remote->rawIncidences(); 142 QPtrList<Incidence> er = remote->rawIncidences();
127 Incidence* inR = er.first(); 143 Incidence* inR = er.first();
128 Incidence* inL;
129 while ( inR ) { 144 while ( inR ) {
130 inL = incidenceForUid( inR->uid() ); 145 inL = incidenceForUid( inR->uid(),false );
131 if ( inL ) { 146 if ( inL ) {
132 int calID = inL->calID(); 147 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
133 deleteIncidence( inL ); 148 int calID = inL->calID();
134 inL = inR->clone(); 149 deleteIncidence( inL );
135 inL->setCalID( calID ); 150 inL = inR->clone();
136 addIncidence( inL ); 151 inL->setCalID( calID );
152 addIncidence( inL );
153 }
137 } else { 154 } else {
138 inL = inR->clone(); 155 inL = inR->clone();
139 inL->setCalID( 0 );// add to default cal 156 inL->setCalID( 0 );// add to default cal
140 addIncidence( inL ); 157 addIncidence( inL );
141 } 158 }
142 inR = er.next(); 159 inR = er.next();
143 } 160 }
144 return true; 161 return true;
145} 162}
163
164
146bool CalendarLocal::addCalendarFile( QString name, int id ) 165bool CalendarLocal::addCalendarFile( QString name, int id )
147{ 166{
148 CalendarLocal calendar( timeZoneId() ); 167 CalendarLocal calendar( timeZoneId() );
149 calendar.setDefaultCalendar( id ); 168 calendar.setDefaultCalendar( id );
150 if ( calendar.load( name ) ) { 169 if ( calendar.load( name ) ) {
151 addCalendar( &calendar ); 170 addCalendar( &calendar );
152 return true; 171 return true;
153 } 172 }
154 return false; 173 return false;
155} 174}
156void CalendarLocal::setSyncEventsReadOnly() 175void CalendarLocal::setSyncEventsReadOnly()
157{ 176{
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h
index 23b0542..a7a85c8 100644
--- a/libkcal/calendarlocal.h
+++ b/libkcal/calendarlocal.h
@@ -38,25 +38,25 @@ class CalendarLocal : public Calendar
38 Constructs a new calendar, with variables initialized to sane values. 38 Constructs a new calendar, with variables initialized to sane values.
39 */ 39 */
40 CalendarLocal(); 40 CalendarLocal();
41 /** 41 /**
42 Constructs a new calendar, with variables initialized to sane values. 42 Constructs a new calendar, with variables initialized to sane values.
43 */ 43 */
44 CalendarLocal( const QString &timeZoneId ); 44 CalendarLocal( const QString &timeZoneId );
45 ~CalendarLocal(); 45 ~CalendarLocal();
46 void addCalendar( Calendar* ); 46 void addCalendar( Calendar* );
47 bool addCalendarFile( QString name, int id ); 47 bool addCalendarFile( QString name, int id );
48 bool mergeCalendarFile( QString name ); 48 bool mergeCalendarFile( QString name );
49 bool mergeCalendar( Calendar* cal ); 49 bool mergeCalendar( Calendar* cal );
50 Incidence* incidenceForUid( const QString& uid ); 50 Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates );
51 void setSyncEventsReadOnly(); 51 void setSyncEventsReadOnly();
52 void stopAllTodos(); 52 void stopAllTodos();
53 /** 53 /**
54 Loads a calendar on disk in vCalendar or iCalendar format into the current 54 Loads a calendar on disk in vCalendar or iCalendar format into the current
55 calendar. Any information already present is lost. 55 calendar. Any information already present is lost.
56 @return true, if successfull, false on error. 56 @return true, if successfull, false on error.
57 @param fileName the name of the calendar on disk. 57 @param fileName the name of the calendar on disk.
58 */ 58 */
59 bool load( const QString &fileName ); 59 bool load( const QString &fileName );
60 /** 60 /**
61 Writes out the calendar to disk in the specified \a format. 61 Writes out the calendar to disk in the specified \a format.
62 CalendarLocal takes ownership of the CalFormat object. 62 CalendarLocal takes ownership of the CalFormat object.
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index dcead02..1a19f3e 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -25,43 +25,45 @@
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 blockLastModified = false;
37 setUid(CalFormat::createUniqueId()); 38 setUid(CalFormat::createUniqueId());
38 mOrganizer = ""; 39 mOrganizer = "";
39 mFloats = false; 40 mFloats = false;
40 mDuration = 0; 41 mDuration = 0;
41 mHasDuration = false; 42 mHasDuration = false;
42 mPilotId = 0; 43 mPilotId = 0;
43 mExternalId = ":"; 44 mExternalId = ":";
44 mTempSyncStat = SYNC_TEMPSTATE_INITIAL; 45 mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
45 mSyncStatus = 0; 46 mSyncStatus = 0;
46 mAttendees.setAutoDelete( true ); 47 mAttendees.setAutoDelete( true );
47 mCalEnabled = true; 48 mCalEnabled = true;
48 mAlarmEnabled = true; 49 mAlarmEnabled = true;
49 mCalID = 0; 50 mCalID = 0;
50} 51}
51 52
52IncidenceBase::IncidenceBase(const IncidenceBase &i) : 53IncidenceBase::IncidenceBase(const IncidenceBase &i) :
53 CustomProperties( i ) 54 CustomProperties( i )
54{ 55{
55 56
57 blockLastModified = false;
56 mReadOnly = i.mReadOnly; 58 mReadOnly = i.mReadOnly;
57 mDtStart = i.mDtStart; 59 mDtStart = i.mDtStart;
58 mDuration = i.mDuration; 60 mDuration = i.mDuration;
59 mHasDuration = i.mHasDuration; 61 mHasDuration = i.mHasDuration;
60 mOrganizer = i.mOrganizer; 62 mOrganizer = i.mOrganizer;
61 mUid = i.mUid; 63 mUid = i.mUid;
62 mCalEnabled = i.mCalEnabled; 64 mCalEnabled = i.mCalEnabled;
63 mAlarmEnabled = i.mAlarmEnabled; 65 mAlarmEnabled = i.mAlarmEnabled;
64 mCalID = i.mCalID; 66 mCalID = i.mCalID;
65 QPtrList<Attendee> attendees = i.attendees(); 67 QPtrList<Attendee> attendees = i.attendees();
66 for( Attendee *a = attendees.first(); a; a = attendees.next() ) { 68 for( Attendee *a = attendees.first(); a; a = attendees.next() ) {
67 mAttendees.append( new Attendee( *a ) ); 69 mAttendees.append( new Attendee( *a ) );
@@ -140,26 +142,29 @@ QDateTime IncidenceBase::getEvenTime( QDateTime dt )
140} 142}
141 143
142bool IncidenceBase::isTagged() const 144bool IncidenceBase::isTagged() const
143{ 145{
144 return mIsTagged; 146 return mIsTagged;
145} 147}
146void IncidenceBase::setTagged( bool b) 148void IncidenceBase::setTagged( bool b)
147{ 149{
148 mIsTagged = b; 150 mIsTagged = b;
149} 151}
150void IncidenceBase::setCalID( int id ) 152void IncidenceBase::setCalID( int id )
151{ 153{
152 if ( mCalID > 0 ) 154 if ( mCalID > 0 ) {
155 blockLastModified = true;
153 updated(); 156 updated();
157 blockLastModified = false;
158 }
154 mCalID = id; 159 mCalID = id;
155} 160}
156int IncidenceBase::calID() const 161int IncidenceBase::calID() const
157{ 162{
158 return mCalID; 163 return mCalID;
159} 164}
160void IncidenceBase::setCalEnabled( bool b ) 165void IncidenceBase::setCalEnabled( bool b )
161{ 166{
162 mCalEnabled = b; 167 mCalEnabled = b;
163} 168}
164bool IncidenceBase::calEnabled() const 169bool IncidenceBase::calEnabled() const
165{ 170{
@@ -180,24 +185,25 @@ void IncidenceBase::setUid(const QString &uid)
180{ 185{
181 mUid = uid; 186 mUid = uid;
182 updated(); 187 updated();
183} 188}
184 189
185QString IncidenceBase::uid() const 190QString IncidenceBase::uid() const
186{ 191{
187 return mUid; 192 return mUid;
188} 193}
189 194
190void IncidenceBase::setLastModified(const QDateTime &lm) 195void IncidenceBase::setLastModified(const QDateTime &lm)
191{ 196{
197 if ( blockLastModified ) return;
192 // DON'T! updated() because we call this from 198 // DON'T! updated() because we call this from
193 // Calendar::updateEvent(). 199 // Calendar::updateEvent().
194 mLastModified = getEvenTime(lm); 200 mLastModified = getEvenTime(lm);
195 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1()); 201 //qDebug("IncidenceBase::setLastModified %s ",lm.toString().latin1());
196} 202}
197 203
198QDateTime IncidenceBase::lastModified() const 204QDateTime IncidenceBase::lastModified() const
199{ 205{
200 return mLastModified; 206 return mLastModified;
201} 207}
202 208
203void IncidenceBase::setOrganizer(const QString &o) 209void IncidenceBase::setOrganizer(const QString &o)
diff --git a/libkcal/incidencebase.h b/libkcal/incidencebase.h
index bccf287..bed73db 100644
--- a/libkcal/incidencebase.h
+++ b/libkcal/incidencebase.h
@@ -141,24 +141,25 @@ class IncidenceBase : public CustomProperties
141 void registerObserver( Observer * ); 141 void registerObserver( Observer * );
142 void unRegisterObserver( Observer * ); 142 void unRegisterObserver( Observer * );
143 void updated(); 143 void updated();
144 void setCalID( int id ); 144 void setCalID( int id );
145 int calID() const; 145 int calID() const;
146 void setCalEnabled( bool ); 146 void setCalEnabled( bool );
147 bool calEnabled() const; 147 bool calEnabled() const;
148 void setAlarmEnabled( bool ); 148 void setAlarmEnabled( bool );
149 bool alarmEnabled() const; 149 bool alarmEnabled() const;
150 bool isTagged() const; 150 bool isTagged() const;
151 void setTagged( bool ); 151 void setTagged( bool );
152 protected: 152 protected:
153 bool blockLastModified;
153 bool mIsTagged; 154 bool mIsTagged;
154 QDateTime mDtStart; 155 QDateTime mDtStart;
155 bool mReadOnly; 156 bool mReadOnly;
156 QDateTime getEvenTime( QDateTime ); 157 QDateTime getEvenTime( QDateTime );
157 158
158 private: 159 private:
159 // base components 160 // base components
160 QString mOrganizer; 161 QString mOrganizer;
161 QString mUid; 162 QString mUid;
162 int mCalID; 163 int mCalID;
163 bool mCalEnabled; 164 bool mCalEnabled;
164 bool mAlarmEnabled; 165 bool mAlarmEnabled;