-rw-r--r-- | libkcal/calendar.cpp | 3 | ||||
-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 75 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 3 |
4 files changed, 81 insertions, 1 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp index a662eeb..b7990d4 100644 --- a/libkcal/calendar.cpp +++ b/libkcal/calendar.cpp | |||
@@ -347,33 +347,34 @@ QPtrList<Event> Calendar::events() | |||
347 | mFilter->apply(&el); | 347 | mFilter->apply(&el); |
348 | return el; | 348 | return el; |
349 | } | 349 | } |
350 | void Calendar::addIncidenceBranch(Incidence *i) | 350 | void Calendar::addIncidenceBranch(Incidence *i) |
351 | { | 351 | { |
352 | addIncidence( i ); | 352 | addIncidence( i ); |
353 | Incidence * inc; | 353 | Incidence * inc; |
354 | QPtrList<Incidence> Relations = i->relations(); | 354 | QPtrList<Incidence> Relations = i->relations(); |
355 | for (inc=Relations.first();inc;inc=Relations.next()) { | 355 | for (inc=Relations.first();inc;inc=Relations.next()) { |
356 | addIncidenceBranch( inc ); | 356 | addIncidenceBranch( inc ); |
357 | } | 357 | } |
358 | } | 358 | } |
359 | 359 | ||
360 | bool Calendar::addIncidence(Incidence *i) | 360 | bool Calendar::addIncidence(Incidence *i) |
361 | { | 361 | { |
362 | Incidence::AddVisitor<Calendar> v(this); | 362 | Incidence::AddVisitor<Calendar> v(this); |
363 | i->setCalID( mDefaultCalendar ); | 363 | if ( i->calID() == 0 ) |
364 | i->setCalID( mDefaultCalendar ); | ||
364 | i->setCalEnabled( true ); | 365 | i->setCalEnabled( true ); |
365 | return i->accept(v); | 366 | return i->accept(v); |
366 | } | 367 | } |
367 | void Calendar::deleteIncidence(Incidence *in) | 368 | void Calendar::deleteIncidence(Incidence *in) |
368 | { | 369 | { |
369 | if ( in->typeID() == eventID ) | 370 | if ( in->typeID() == eventID ) |
370 | deleteEvent( (Event*) in ); | 371 | deleteEvent( (Event*) in ); |
371 | else if ( in->typeID() == todoID ) | 372 | else if ( in->typeID() == todoID ) |
372 | deleteTodo( (Todo*) in); | 373 | deleteTodo( (Todo*) in); |
373 | else if ( in->typeID() == journalID ) | 374 | else if ( in->typeID() == journalID ) |
374 | deleteJournal( (Journal*) in ); | 375 | deleteJournal( (Journal*) in ); |
375 | } | 376 | } |
376 | 377 | ||
377 | Incidence* Calendar::incidence( const QString& uid ) | 378 | Incidence* Calendar::incidence( const QString& uid ) |
378 | { | 379 | { |
379 | Incidence* i; | 380 | Incidence* i; |
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4652fe5..14a1a45 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -63,32 +63,33 @@ class Calendar : public QObject, public CustomProperties, | |||
63 | Q_OBJECT | 63 | Q_OBJECT |
64 | public: | 64 | public: |
65 | Calendar(); | 65 | Calendar(); |
66 | Calendar(const QString &timeZoneId); | 66 | Calendar(const QString &timeZoneId); |
67 | virtual ~Calendar(); | 67 | virtual ~Calendar(); |
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 void setSyncEventsReadOnly() = 0; | 80 | virtual void setSyncEventsReadOnly() = 0; |
80 | virtual void stopAllTodos() = 0; | 81 | virtual void stopAllTodos() = 0; |
81 | 82 | ||
82 | /** | 83 | /** |
83 | Sync changes in memory to persistant storage. | 84 | Sync changes in memory to persistant storage. |
84 | */ | 85 | */ |
85 | virtual void save() = 0; | 86 | virtual void save() = 0; |
86 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 87 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
87 | virtual void removeSyncInfo( QString syncProfile) = 0; | 88 | virtual void removeSyncInfo( QString syncProfile) = 0; |
88 | virtual bool isSaving() { return false; } | 89 | virtual bool isSaving() { return false; } |
89 | 90 | ||
90 | /** | 91 | /** |
91 | Return the owner of the calendar's full name. | 92 | Return the owner of the calendar's full name. |
92 | */ | 93 | */ |
93 | const QString &getOwner() const; | 94 | const QString &getOwner() const; |
94 | /** | 95 | /** |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index cce798f..3e42ec0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -55,32 +55,107 @@ CalendarLocal::CalendarLocal(const QString &timeZoneId) | |||
55 | : Calendar(timeZoneId) | 55 | : Calendar(timeZoneId) |
56 | { | 56 | { |
57 | init(); | 57 | init(); |
58 | } | 58 | } |
59 | 59 | ||
60 | void CalendarLocal::init() | 60 | void CalendarLocal::init() |
61 | { | 61 | { |
62 | mNextAlarmIncidence = 0; | 62 | mNextAlarmIncidence = 0; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | CalendarLocal::~CalendarLocal() | 66 | CalendarLocal::~CalendarLocal() |
67 | { | 67 | { |
68 | if ( mDeleteIncidencesOnClose ) | 68 | if ( mDeleteIncidencesOnClose ) |
69 | close(); | 69 | close(); |
70 | } | 70 | } |
71 | bool CalendarLocal::mergeCalendarFile( QString name ) | ||
72 | { | ||
73 | CalendarLocal calendar( timeZoneId() ); | ||
74 | calendar.setDefaultCalendar( 1 ); | ||
75 | if ( calendar.load( name ) ) { | ||
76 | mergeCalendar( &calendar ); | ||
77 | return true; | ||
78 | } | ||
79 | return false; | ||
80 | } | ||
81 | |||
82 | Incidence* CalendarLocal::incidenceForUid( const QString& uid ) | ||
83 | { | ||
84 | Todo *todo;; | ||
85 | Incidence *retVal = 0; | ||
86 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | ||
87 | if ( todo->uid() == uid ) { | ||
88 | if ( retVal ) { | ||
89 | if ( retVal->calID() > todo->calID() ) { | ||
90 | retVal = todo; | ||
91 | } | ||
92 | } else { | ||
93 | retVal = todo; | ||
94 | } | ||
95 | } | ||
96 | } | ||
97 | if ( retVal ) return retVal; | ||
98 | Event *event; | ||
99 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | ||
100 | if ( event->uid() == uid ) { | ||
101 | if ( retVal ) { | ||
102 | if ( retVal->calID() > event->calID() ) { | ||
103 | retVal = event; | ||
104 | } | ||
105 | } else { | ||
106 | retVal = event; | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | if ( retVal ) return retVal; | ||
111 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | ||
112 | if ( it->uid() == uid ) { | ||
113 | if ( retVal ) { | ||
114 | if ( retVal->calID() > it->calID() ) { | ||
115 | retVal = it; | ||
116 | } | ||
117 | } else { | ||
118 | retVal = it; | ||
119 | } | ||
120 | } | ||
121 | return retVal; | ||
122 | } | ||
123 | |||
124 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | ||
125 | { | ||
126 | QPtrList<Incidence> er = remote->rawIncidences(); | ||
127 | Incidence* inR = er.first(); | ||
128 | Incidence* inL; | ||
129 | while ( inR ) { | ||
130 | inL = incidenceForUid( inR->uid() ); | ||
131 | if ( inL ) { | ||
132 | int calID = inL->calID(); | ||
133 | deleteIncidence( inL ); | ||
134 | inL = inR->clone(); | ||
135 | inL->setCalID( calID ); | ||
136 | addIncidence( inL ); | ||
137 | } else { | ||
138 | inL = inR->clone(); | ||
139 | inL->setCalID( 0 );// add to default cal | ||
140 | addIncidence( inL ); | ||
141 | } | ||
142 | inR = er.next(); | ||
143 | } | ||
144 | return true; | ||
145 | } | ||
71 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 146 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
72 | { | 147 | { |
73 | CalendarLocal calendar( timeZoneId() ); | 148 | CalendarLocal calendar( timeZoneId() ); |
74 | calendar.setDefaultCalendar( id ); | 149 | calendar.setDefaultCalendar( id ); |
75 | if ( calendar.load( name ) ) { | 150 | if ( calendar.load( name ) ) { |
76 | addCalendar( &calendar ); | 151 | addCalendar( &calendar ); |
77 | return true; | 152 | return true; |
78 | } | 153 | } |
79 | return false; | 154 | return false; |
80 | } | 155 | } |
81 | void CalendarLocal::setSyncEventsReadOnly() | 156 | void CalendarLocal::setSyncEventsReadOnly() |
82 | { | 157 | { |
83 | Event * ev; | 158 | Event * ev; |
84 | ev = mEventList.first(); | 159 | ev = mEventList.first(); |
85 | while ( ev ) { | 160 | while ( ev ) { |
86 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 161 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index 98d16a3..23b0542 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -32,32 +32,35 @@ class CalFormat; | |||
32 | This class provides a calendar stored as a local file. | 32 | This class provides a calendar stored as a local file. |
33 | */ | 33 | */ |
34 | class CalendarLocal : public Calendar | 34 | class CalendarLocal : public Calendar |
35 | { | 35 | { |
36 | public: | 36 | public: |
37 | /** | 37 | /** |
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 ); | ||
49 | bool mergeCalendar( Calendar* cal ); | ||
50 | Incidence* incidenceForUid( const QString& uid ); | ||
48 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
49 | void stopAllTodos(); | 52 | void stopAllTodos(); |
50 | /** | 53 | /** |
51 | 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 |
52 | calendar. Any information already present is lost. | 55 | calendar. Any information already present is lost. |
53 | @return true, if successfull, false on error. | 56 | @return true, if successfull, false on error. |
54 | @param fileName the name of the calendar on disk. | 57 | @param fileName the name of the calendar on disk. |
55 | */ | 58 | */ |
56 | bool load( const QString &fileName ); | 59 | bool load( const QString &fileName ); |
57 | /** | 60 | /** |
58 | Writes out the calendar to disk in the specified \a format. | 61 | Writes out the calendar to disk in the specified \a format. |
59 | CalendarLocal takes ownership of the CalFormat object. | 62 | CalendarLocal takes ownership of the CalFormat object. |
60 | @return true, if successfull, false on error. | 63 | @return true, if successfull, false on error. |
61 | @param fileName the name of the file | 64 | @param fileName the name of the file |
62 | */ | 65 | */ |
63 | bool save( const QString &fileName, CalFormat *format = 0 ); | 66 | bool save( const QString &fileName, CalFormat *format = 0 ); |