-rw-r--r-- | libkcal/calendar.h | 1 | ||||
-rw-r--r-- | libkcal/calendarlocal.cpp | 16 | ||||
-rw-r--r-- | libkcal/calendarlocal.h | 1 |
3 files changed, 16 insertions, 2 deletions
diff --git a/libkcal/calendar.h b/libkcal/calendar.h index 4b8b3ff..0a94914 100644 --- a/libkcal/calendar.h +++ b/libkcal/calendar.h | |||
@@ -1,177 +1,178 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | Copyright (c) 1998 Preston Brown | 3 | Copyright (c) 1998 Preston Brown |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | #ifndef CALENDAR_H | 22 | #ifndef CALENDAR_H |
23 | #define CALENDAR_H | 23 | #define CALENDAR_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qdatetime.h> | 27 | #include <qdatetime.h> |
28 | #include <qptrlist.h> | 28 | #include <qptrlist.h> |
29 | #include <qdict.h> | 29 | #include <qdict.h> |
30 | 30 | ||
31 | #include "customproperties.h" | 31 | #include "customproperties.h" |
32 | #include "event.h" | 32 | #include "event.h" |
33 | #include "todo.h" | 33 | #include "todo.h" |
34 | #include "journal.h" | 34 | #include "journal.h" |
35 | #include "calfilter.h" | 35 | #include "calfilter.h" |
36 | 36 | ||
37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ | 37 | //#define _TIME_ZONE "-0500" /* hardcoded, overridden in config file. */ |
38 | 38 | ||
39 | class KConfig; | 39 | class KConfig; |
40 | 40 | ||
41 | namespace KCal { | 41 | namespace KCal { |
42 | 42 | ||
43 | 43 | ||
44 | /** | 44 | /** |
45 | This is the main "calendar" object class for KOrganizer. It holds | 45 | This is the main "calendar" object class for KOrganizer. It holds |
46 | information like all appointments/events, user information, etc. etc. | 46 | information like all appointments/events, user information, etc. etc. |
47 | one calendar is associated with each CalendarView (@see calendarview.h). | 47 | one calendar is associated with each CalendarView (@see calendarview.h). |
48 | This is an abstract base class defining the interface to a calendar. It is | 48 | This is an abstract base class defining the interface to a calendar. It is |
49 | implemented by subclasses like @see CalendarLocal, which use different | 49 | implemented by subclasses like @see CalendarLocal, which use different |
50 | methods to store and access the data. | 50 | methods to store and access the data. |
51 | 51 | ||
52 | Ownership of events etc. is handled by the following policy: As soon as an | 52 | Ownership of events etc. is handled by the following policy: As soon as an |
53 | event (or any other subclass of IncidenceBase) object is added to the | 53 | event (or any other subclass of IncidenceBase) object is added to the |
54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes | 54 | Calendar by addEvent() it is owned by the Calendar object. The Calendar takes |
55 | care of deleting it. All Events returned by the query functions are returned | 55 | care of deleting it. All Events returned by the query functions are returned |
56 | as pointers, that means all changes to the returned events are immediately | 56 | as pointers, that means all changes to the returned events are immediately |
57 | visible in the Calendar. You shouldn't delete any Event object you get from | 57 | visible in the Calendar. You shouldn't delete any Event object you get from |
58 | Calendar. | 58 | Calendar. |
59 | */ | 59 | */ |
60 | class Calendar : public QObject, public CustomProperties, | 60 | class Calendar : public QObject, public CustomProperties, |
61 | public IncidenceBase::Observer | 61 | public IncidenceBase::Observer |
62 | { | 62 | { |
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 bool mergeCalendarFile( QString name ) = 0; |
80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; | 80 | virtual Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ) = 0; |
81 | virtual void setSyncEventsReadOnly() = 0; | 81 | virtual void setSyncEventsReadOnly() = 0; |
82 | virtual void setSyncEventsEnabled() = 0; | ||
82 | virtual void stopAllTodos() = 0; | 83 | virtual void stopAllTodos() = 0; |
83 | virtual void clearUndo( Incidence * newUndo ); | 84 | virtual void clearUndo( Incidence * newUndo ); |
84 | 85 | ||
85 | /** | 86 | /** |
86 | Sync changes in memory to persistant storage. | 87 | Sync changes in memory to persistant storage. |
87 | */ | 88 | */ |
88 | virtual void save() = 0; | 89 | virtual void save() = 0; |
89 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; | 90 | virtual QPtrList<Event> getExternLastSyncEvents() = 0; |
90 | virtual void removeSyncInfo( QString syncProfile) = 0; | 91 | virtual void removeSyncInfo( QString syncProfile) = 0; |
91 | virtual bool isSaving() { return false; } | 92 | virtual bool isSaving() { return false; } |
92 | 93 | ||
93 | /** | 94 | /** |
94 | Return the owner of the calendar's full name. | 95 | Return the owner of the calendar's full name. |
95 | */ | 96 | */ |
96 | const QString &getOwner() const; | 97 | const QString &getOwner() const; |
97 | /** | 98 | /** |
98 | Set the owner of the calendar. Should be owner's full name. | 99 | Set the owner of the calendar. Should be owner's full name. |
99 | */ | 100 | */ |
100 | void setOwner( const QString &os ); | 101 | void setOwner( const QString &os ); |
101 | /** | 102 | /** |
102 | Return the email address of the calendar owner. | 103 | Return the email address of the calendar owner. |
103 | */ | 104 | */ |
104 | const QString &getEmail(); | 105 | const QString &getEmail(); |
105 | /** | 106 | /** |
106 | Set the email address of the calendar owner. | 107 | Set the email address of the calendar owner. |
107 | */ | 108 | */ |
108 | void setEmail( const QString & ); | 109 | void setEmail( const QString & ); |
109 | 110 | ||
110 | /** | 111 | /** |
111 | Set time zone from a timezone string (e.g. -2:00) | 112 | Set time zone from a timezone string (e.g. -2:00) |
112 | */ | 113 | */ |
113 | void setTimeZone( const QString &tz ); | 114 | void setTimeZone( const QString &tz ); |
114 | /** | 115 | /** |
115 | Set time zone from a minutes value (e.g. -60) | 116 | Set time zone from a minutes value (e.g. -60) |
116 | */ | 117 | */ |
117 | void setTimeZone( int tz ); | 118 | void setTimeZone( int tz ); |
118 | /** | 119 | /** |
119 | Return time zone as offest in minutes. | 120 | Return time zone as offest in minutes. |
120 | */ | 121 | */ |
121 | int getTimeZone() const; | 122 | int getTimeZone() const; |
122 | /** | 123 | /** |
123 | Compute an ISO 8601 format string from the time zone. | 124 | Compute an ISO 8601 format string from the time zone. |
124 | */ | 125 | */ |
125 | QString getTimeZoneStr() const; | 126 | QString getTimeZoneStr() const; |
126 | /** | 127 | /** |
127 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal | 128 | Set time zone id (see /usr/share/zoneinfo/zone.tab for list of legal |
128 | values). | 129 | values). |
129 | */ | 130 | */ |
130 | void setTimeZoneId( const QString & ); | 131 | void setTimeZoneId( const QString & ); |
131 | /** | 132 | /** |
132 | Return time zone id. | 133 | Return time zone id. |
133 | */ | 134 | */ |
134 | QString timeZoneId() const; | 135 | QString timeZoneId() const; |
135 | /** | 136 | /** |
136 | Use local time, not UTC or a time zone. | 137 | Use local time, not UTC or a time zone. |
137 | */ | 138 | */ |
138 | void setLocalTime(); | 139 | void setLocalTime(); |
139 | /** | 140 | /** |
140 | Return whether local time is being used. | 141 | Return whether local time is being used. |
141 | */ | 142 | */ |
142 | bool isLocalTime() const; | 143 | bool isLocalTime() const; |
143 | 144 | ||
144 | /** | 145 | /** |
145 | Add an incidence to calendar. | 146 | Add an incidence to calendar. |
146 | 147 | ||
147 | @return true on success, false on error. | 148 | @return true on success, false on error. |
148 | */ | 149 | */ |
149 | virtual bool addIncidence( Incidence * ); | 150 | virtual bool addIncidence( Incidence * ); |
150 | 151 | ||
151 | // Adds an incidence and all relatedto incidences to the cal | 152 | // Adds an incidence and all relatedto incidences to the cal |
152 | void addIncidenceBranch( Incidence * ); | 153 | void addIncidenceBranch( Incidence * ); |
153 | /** | 154 | /** |
154 | Return filtered list of all incidences of this calendar. | 155 | Return filtered list of all incidences of this calendar. |
155 | */ | 156 | */ |
156 | virtual QPtrList<Incidence> incidences(); | 157 | virtual QPtrList<Incidence> incidences(); |
157 | 158 | ||
158 | /** | 159 | /** |
159 | Return unfiltered list of all incidences of this calendar. | 160 | Return unfiltered list of all incidences of this calendar. |
160 | */ | 161 | */ |
161 | virtual QPtrList<Incidence> rawIncidences(); | 162 | virtual QPtrList<Incidence> rawIncidences(); |
162 | 163 | ||
163 | /** | 164 | /** |
164 | Adds a Event to this calendar object. | 165 | Adds a Event to this calendar object. |
165 | @param anEvent a pointer to the event to add | 166 | @param anEvent a pointer to the event to add |
166 | 167 | ||
167 | @return true on success, false on error. | 168 | @return true on success, false on error. |
168 | */ | 169 | */ |
169 | virtual bool addEventNoDup( Event *event ) = 0; | 170 | virtual bool addEventNoDup( Event *event ) = 0; |
170 | virtual bool addAnniversaryNoDup( Event *event ) = 0; | 171 | virtual bool addAnniversaryNoDup( Event *event ) = 0; |
171 | virtual bool addEvent( Event *anEvent ) = 0; | 172 | virtual bool addEvent( Event *anEvent ) = 0; |
172 | /** | 173 | /** |
173 | Delete event from calendar. | 174 | Delete event from calendar. |
174 | */ | 175 | */ |
175 | virtual void deleteEvent( Event * ) = 0; | 176 | virtual void deleteEvent( Event * ) = 0; |
176 | /** | 177 | /** |
177 | Retrieves an event on the basis of the unique string ID. | 178 | Retrieves an event on the basis of the unique string ID. |
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index 0ddfeca..45e3128 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -80,199 +80,211 @@ bool CalendarLocal::mergeCalendarFile( QString name ) | |||
80 | return false; | 80 | return false; |
81 | } | 81 | } |
82 | 82 | ||
83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) | 83 | Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckDuplicates) |
84 | { | 84 | { |
85 | Todo *todo;; | 85 | Todo *todo;; |
86 | Incidence *retVal = 0; | 86 | Incidence *retVal = 0; |
87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { | 87 | for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { |
88 | if ( todo->uid() == uid ) { | 88 | if ( todo->uid() == uid ) { |
89 | if ( doNotCheckDuplicates ) return todo; | 89 | if ( doNotCheckDuplicates ) return todo; |
90 | if ( retVal ) { | 90 | if ( retVal ) { |
91 | if ( retVal->calID() > todo->calID() ) { | 91 | if ( retVal->calID() > todo->calID() ) { |
92 | retVal = todo; | 92 | retVal = todo; |
93 | } | 93 | } |
94 | } else { | 94 | } else { |
95 | retVal = todo; | 95 | retVal = todo; |
96 | } | 96 | } |
97 | } | 97 | } |
98 | } | 98 | } |
99 | if ( retVal ) return retVal; | 99 | if ( retVal ) return retVal; |
100 | Event *event; | 100 | Event *event; |
101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { | 101 | for ( event = mEventList.first(); event; event = mEventList.next() ) { |
102 | if ( event->uid() == uid ) { | 102 | if ( event->uid() == uid ) { |
103 | if ( doNotCheckDuplicates ) return event; | 103 | if ( doNotCheckDuplicates ) return event; |
104 | if ( retVal ) { | 104 | if ( retVal ) { |
105 | if ( retVal->calID() > event->calID() ) { | 105 | if ( retVal->calID() > event->calID() ) { |
106 | retVal = event; | 106 | retVal = event; |
107 | } | 107 | } |
108 | } else { | 108 | } else { |
109 | retVal = event; | 109 | retVal = event; |
110 | } | 110 | } |
111 | } | 111 | } |
112 | } | 112 | } |
113 | if ( retVal ) return retVal; | 113 | if ( retVal ) return retVal; |
114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) | 114 | for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) |
115 | if ( it->uid() == uid ) { | 115 | if ( it->uid() == uid ) { |
116 | if ( doNotCheckDuplicates ) return it; | 116 | if ( doNotCheckDuplicates ) return it; |
117 | if ( retVal ) { | 117 | if ( retVal ) { |
118 | if ( retVal->calID() > it->calID() ) { | 118 | if ( retVal->calID() > it->calID() ) { |
119 | retVal = it; | 119 | retVal = it; |
120 | } | 120 | } |
121 | } else { | 121 | } else { |
122 | retVal = it; | 122 | retVal = it; |
123 | } | 123 | } |
124 | } | 124 | } |
125 | return retVal; | 125 | return retVal; |
126 | } | 126 | } |
127 | 127 | ||
128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) | 128 | bool CalendarLocal::mergeCalendar( Calendar* remote ) |
129 | { | 129 | { |
130 | // 1 look for raw inc in local | 130 | // 1 look for raw inc in local |
131 | // if inc not in remote, delete in local | 131 | // if inc not in remote, delete in local |
132 | // 2 look for raw inc in remote | 132 | // 2 look for raw inc in remote |
133 | // if inc in local, replace it | 133 | // if inc in local, replace it |
134 | // if not in local, add it to default calendar | 134 | // if not in local, add it to default calendar |
135 | QPtrList<Incidence> localInc = rawIncidences(); | 135 | QPtrList<Incidence> localInc = rawIncidences(); |
136 | Incidence* inL = localInc.first(); | 136 | Incidence* inL = localInc.first(); |
137 | while ( inL ) { | 137 | while ( inL ) { |
138 | if ( ! inL->isReadOnly () ) | 138 | if ( ! inL->isReadOnly () ) |
139 | if ( !remote->incidenceForUid( inL->uid(), true )) | 139 | if ( !remote->incidenceForUid( inL->uid(), true )) |
140 | deleteIncidence( inL ); | 140 | deleteIncidence( inL ); |
141 | inL = localInc.next(); | 141 | inL = localInc.next(); |
142 | } | 142 | } |
143 | QPtrList<Incidence> er = remote->rawIncidences(); | 143 | QPtrList<Incidence> er = remote->rawIncidences(); |
144 | Incidence* inR = er.first(); | 144 | Incidence* inR = er.first(); |
145 | while ( inR ) { | 145 | while ( inR ) { |
146 | inL = incidenceForUid( inR->uid(),false ); | 146 | inL = incidenceForUid( inR->uid(),false ); |
147 | if ( inL ) { | 147 | if ( inL ) { |
148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { | 148 | if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { |
149 | int calID = inL->calID(); | 149 | int calID = inL->calID(); |
150 | deleteIncidence( inL ); | 150 | deleteIncidence( inL ); |
151 | inL = inR->clone(); | 151 | inL = inR->clone(); |
152 | inL->setCalID( calID ); | 152 | inL->setCalID( calID ); |
153 | addIncidence( inL ); | 153 | addIncidence( inL ); |
154 | } | 154 | } |
155 | } else { | 155 | } else { |
156 | inL = inR->clone(); | 156 | inL = inR->clone(); |
157 | inL->setCalID( 0 );// add to default cal | 157 | inL->setCalID( 0 );// add to default cal |
158 | addIncidence( inL ); | 158 | addIncidence( inL ); |
159 | } | 159 | } |
160 | inR = er.next(); | 160 | inR = er.next(); |
161 | } | 161 | } |
162 | return true; | 162 | return true; |
163 | } | 163 | } |
164 | 164 | ||
165 | 165 | ||
166 | bool CalendarLocal::addCalendarFile( QString name, int id ) | 166 | bool CalendarLocal::addCalendarFile( QString name, int id ) |
167 | { | 167 | { |
168 | CalendarLocal calendar( timeZoneId() ); | 168 | CalendarLocal calendar( timeZoneId() ); |
169 | calendar.setDefaultCalendar( id ); | 169 | calendar.setDefaultCalendar( id ); |
170 | if ( calendar.load( name ) ) { | 170 | if ( calendar.load( name ) ) { |
171 | addCalendar( &calendar ); | 171 | addCalendar( &calendar ); |
172 | return true; | 172 | return true; |
173 | } | 173 | } |
174 | return false; | 174 | return false; |
175 | } | 175 | } |
176 | void CalendarLocal::setSyncEventsReadOnly() | 176 | void CalendarLocal::setSyncEventsEnabled() |
177 | { | 177 | { |
178 | Event * ev; | 178 | Event * ev; |
179 | ev = mEventList.first(); | 179 | ev = mEventList.first(); |
180 | while ( ev ) { | 180 | while ( ev ) { |
181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) | 181 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) |
182 | ev->setReadOnly( true ); | 182 | ev->setCalEnabled( true ); |
183 | ev = mEventList.next(); | ||
184 | } | ||
185 | } | ||
186 | void CalendarLocal::setSyncEventsReadOnly() | ||
187 | { | ||
188 | Event * ev; | ||
189 | ev = mEventList.first(); | ||
190 | while ( ev ) { | ||
191 | if ( ev->uid().left(15) == QString("last-syncEvent-") ) { | ||
192 | ev->setReadOnly( true ); | ||
193 | ev->setCalID( 1 ); | ||
194 | } | ||
183 | ev = mEventList.next(); | 195 | ev = mEventList.next(); |
184 | } | 196 | } |
185 | } | 197 | } |
186 | void CalendarLocal::addCalendar( Calendar* cal ) | 198 | void CalendarLocal::addCalendar( Calendar* cal ) |
187 | { | 199 | { |
188 | cal->setDontDeleteIncidencesOnClose(); | 200 | cal->setDontDeleteIncidencesOnClose(); |
189 | { | 201 | { |
190 | QPtrList<Event> EventList = cal->rawEvents(); | 202 | QPtrList<Event> EventList = cal->rawEvents(); |
191 | Event * ev = EventList.first(); | 203 | Event * ev = EventList.first(); |
192 | while ( ev ) { | 204 | while ( ev ) { |
193 | ev->unRegisterObserver( cal ); | 205 | ev->unRegisterObserver( cal ); |
194 | ev->registerObserver( this ); | 206 | ev->registerObserver( this ); |
195 | mEventList.append( ev ); | 207 | mEventList.append( ev ); |
196 | ev = EventList.next(); | 208 | ev = EventList.next(); |
197 | } | 209 | } |
198 | } | 210 | } |
199 | { | 211 | { |
200 | 212 | ||
201 | QPtrList<Todo> TodoList = cal->rawTodos(); | 213 | QPtrList<Todo> TodoList = cal->rawTodos(); |
202 | Todo * ev = TodoList.first(); | 214 | Todo * ev = TodoList.first(); |
203 | while ( ev ) { | 215 | while ( ev ) { |
204 | QString rel = ev->relatedToUid(); | 216 | QString rel = ev->relatedToUid(); |
205 | if ( !rel.isEmpty() ){ | 217 | if ( !rel.isEmpty() ){ |
206 | ev->setRelatedTo ( 0 ); | 218 | ev->setRelatedTo ( 0 ); |
207 | ev->setRelatedToUid( rel ); | 219 | ev->setRelatedToUid( rel ); |
208 | } | 220 | } |
209 | ev = TodoList.next(); | 221 | ev = TodoList.next(); |
210 | } | 222 | } |
211 | //TodoList = cal->rawTodos(); | 223 | //TodoList = cal->rawTodos(); |
212 | ev = TodoList.first(); | 224 | ev = TodoList.first(); |
213 | while ( ev ) { | 225 | while ( ev ) { |
214 | ev->unRegisterObserver( cal ); | 226 | ev->unRegisterObserver( cal ); |
215 | ev->registerObserver( this ); | 227 | ev->registerObserver( this ); |
216 | mTodoList.append( ev ); | 228 | mTodoList.append( ev ); |
217 | setupRelations( ev ); | 229 | setupRelations( ev ); |
218 | ev = TodoList.next(); | 230 | ev = TodoList.next(); |
219 | } | 231 | } |
220 | } | 232 | } |
221 | { | 233 | { |
222 | QPtrList<Journal> JournalList = cal->journals(); | 234 | QPtrList<Journal> JournalList = cal->journals(); |
223 | Journal * ev = JournalList.first(); | 235 | Journal * ev = JournalList.first(); |
224 | while ( ev ) { | 236 | while ( ev ) { |
225 | ev->unRegisterObserver( cal ); | 237 | ev->unRegisterObserver( cal ); |
226 | ev->registerObserver( this ); | 238 | ev->registerObserver( this ); |
227 | mJournalList.append( ev ); | 239 | mJournalList.append( ev ); |
228 | ev = JournalList.next(); | 240 | ev = JournalList.next(); |
229 | } | 241 | } |
230 | } | 242 | } |
231 | setModified( true ); | 243 | setModified( true ); |
232 | } | 244 | } |
233 | bool CalendarLocal::load( const QString &fileName ) | 245 | bool CalendarLocal::load( const QString &fileName ) |
234 | { | 246 | { |
235 | FileStorage storage( this, fileName ); | 247 | FileStorage storage( this, fileName ); |
236 | return storage.load(); | 248 | return storage.load(); |
237 | } | 249 | } |
238 | 250 | ||
239 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 251 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
240 | { | 252 | { |
241 | FileStorage storage( this, fileName, format ); | 253 | FileStorage storage( this, fileName, format ); |
242 | return storage.save(); | 254 | return storage.save(); |
243 | } | 255 | } |
244 | 256 | ||
245 | void CalendarLocal::stopAllTodos() | 257 | void CalendarLocal::stopAllTodos() |
246 | { | 258 | { |
247 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 259 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
248 | it->setRunning( false ); | 260 | it->setRunning( false ); |
249 | 261 | ||
250 | } | 262 | } |
251 | void CalendarLocal::close() | 263 | void CalendarLocal::close() |
252 | { | 264 | { |
253 | 265 | ||
254 | Todo * i; | 266 | Todo * i; |
255 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 267 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
256 | 268 | ||
257 | mEventList.setAutoDelete( true ); | 269 | mEventList.setAutoDelete( true ); |
258 | mTodoList.setAutoDelete( true ); | 270 | mTodoList.setAutoDelete( true ); |
259 | mJournalList.setAutoDelete( true ); | 271 | mJournalList.setAutoDelete( true ); |
260 | 272 | ||
261 | mEventList.clear(); | 273 | mEventList.clear(); |
262 | mTodoList.clear(); | 274 | mTodoList.clear(); |
263 | mJournalList.clear(); | 275 | mJournalList.clear(); |
264 | 276 | ||
265 | mEventList.setAutoDelete( false ); | 277 | mEventList.setAutoDelete( false ); |
266 | mTodoList.setAutoDelete( false ); | 278 | mTodoList.setAutoDelete( false ); |
267 | mJournalList.setAutoDelete( false ); | 279 | mJournalList.setAutoDelete( false ); |
268 | 280 | ||
269 | setModified( false ); | 281 | setModified( false ); |
270 | } | 282 | } |
271 | 283 | ||
272 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) | 284 | bool CalendarLocal::addAnniversaryNoDup( Event *event ) |
273 | { | 285 | { |
274 | QString cat; | 286 | QString cat; |
275 | bool isBirthday = true; | 287 | bool isBirthday = true; |
276 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { | 288 | if( event->categoriesStr() == i18n( "Anniversary" ) ) { |
277 | isBirthday = false; | 289 | isBirthday = false; |
278 | cat = i18n( "Anniversary" ); | 290 | cat = i18n( "Anniversary" ); |
diff --git a/libkcal/calendarlocal.h b/libkcal/calendarlocal.h index ca0bd98..eb7bf34 100644 --- a/libkcal/calendarlocal.h +++ b/libkcal/calendarlocal.h | |||
@@ -1,147 +1,148 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkcal. | 2 | This file is part of libkcal. |
3 | 3 | ||
4 | Copyright (c) 1998 Preston Brown | 4 | Copyright (c) 1998 Preston Brown |
5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> | 5 | Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org> |
6 | 6 | ||
7 | This library is free software; you can redistribute it and/or | 7 | This library is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU Library General Public | 8 | modify it under the terms of the GNU Library General Public |
9 | License as published by the Free Software Foundation; either | 9 | License as published by the Free Software Foundation; either |
10 | version 2 of the License, or (at your option) any later version. | 10 | version 2 of the License, or (at your option) any later version. |
11 | 11 | ||
12 | This library is distributed in the hope that it will be useful, | 12 | This library is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | Library General Public License for more details. | 15 | Library General Public License for more details. |
16 | 16 | ||
17 | You should have received a copy of the GNU Library General Public License | 17 | You should have received a copy of the GNU Library General Public License |
18 | along with this library; see the file COPYING.LIB. If not, write to | 18 | along with this library; see the file COPYING.LIB. If not, write to |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. | 20 | Boston, MA 02111-1307, USA. |
21 | */ | 21 | */ |
22 | #ifndef KCAL_CALENDARLOCAL_H | 22 | #ifndef KCAL_CALENDARLOCAL_H |
23 | #define KCAL_CALENDARLOCAL_H | 23 | #define KCAL_CALENDARLOCAL_H |
24 | 24 | ||
25 | #include "calendar.h" | 25 | #include "calendar.h" |
26 | 26 | ||
27 | namespace KCal { | 27 | namespace KCal { |
28 | 28 | ||
29 | class CalFormat; | 29 | class CalFormat; |
30 | 30 | ||
31 | /** | 31 | /** |
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 ); | 48 | bool mergeCalendarFile( QString name ); |
49 | bool mergeCalendar( Calendar* cal ); | 49 | bool mergeCalendar( Calendar* cal ); |
50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); | 50 | Incidence* incidenceForUid( const QString& uid, bool doNotCheckDuplicates ); |
51 | void setSyncEventsReadOnly(); | 51 | void setSyncEventsReadOnly(); |
52 | void setSyncEventsEnabled(); | ||
52 | void stopAllTodos(); | 53 | void stopAllTodos(); |
53 | /** | 54 | /** |
54 | Loads a calendar on disk in vCalendar or iCalendar format into the current | 55 | Loads a calendar on disk in vCalendar or iCalendar format into the current |
55 | calendar. Any information already present is lost. | 56 | calendar. Any information already present is lost. |
56 | @return true, if successfull, false on error. | 57 | @return true, if successfull, false on error. |
57 | @param fileName the name of the calendar on disk. | 58 | @param fileName the name of the calendar on disk. |
58 | */ | 59 | */ |
59 | bool load( const QString &fileName ); | 60 | bool load( const QString &fileName ); |
60 | /** | 61 | /** |
61 | Writes out the calendar to disk in the specified \a format. | 62 | Writes out the calendar to disk in the specified \a format. |
62 | CalendarLocal takes ownership of the CalFormat object. | 63 | CalendarLocal takes ownership of the CalFormat object. |
63 | @return true, if successfull, false on error. | 64 | @return true, if successfull, false on error. |
64 | @param fileName the name of the file | 65 | @param fileName the name of the file |
65 | */ | 66 | */ |
66 | bool save( const QString &fileName, CalFormat *format = 0 ); | 67 | bool save( const QString &fileName, CalFormat *format = 0 ); |
67 | 68 | ||
68 | /** | 69 | /** |
69 | Clears out the current calendar, freeing all used memory etc. etc. | 70 | Clears out the current calendar, freeing all used memory etc. etc. |
70 | */ | 71 | */ |
71 | void close(); | 72 | void close(); |
72 | 73 | ||
73 | void save() {} | 74 | void save() {} |
74 | 75 | ||
75 | /** | 76 | /** |
76 | Add Event to calendar. | 77 | Add Event to calendar. |
77 | */ | 78 | */ |
78 | void removeSyncInfo( QString syncProfile); | 79 | void removeSyncInfo( QString syncProfile); |
79 | bool addAnniversaryNoDup( Event *event ); | 80 | bool addAnniversaryNoDup( Event *event ); |
80 | bool addEventNoDup( Event *event ); | 81 | bool addEventNoDup( Event *event ); |
81 | bool addEvent( Event *event ); | 82 | bool addEvent( Event *event ); |
82 | /** | 83 | /** |
83 | Deletes an event from this calendar. | 84 | Deletes an event from this calendar. |
84 | */ | 85 | */ |
85 | void deleteEvent( Event *event ); | 86 | void deleteEvent( Event *event ); |
86 | 87 | ||
87 | /** | 88 | /** |
88 | Retrieves an event on the basis of the unique string ID. | 89 | Retrieves an event on the basis of the unique string ID. |
89 | */ | 90 | */ |
90 | Event *event( const QString &uid ); | 91 | Event *event( const QString &uid ); |
91 | /** | 92 | /** |
92 | Return unfiltered list of all events in calendar. | 93 | Return unfiltered list of all events in calendar. |
93 | */ | 94 | */ |
94 | QPtrList<Event> rawEvents(); | 95 | QPtrList<Event> rawEvents(); |
95 | QPtrList<Event> getExternLastSyncEvents(); | 96 | QPtrList<Event> getExternLastSyncEvents(); |
96 | /** | 97 | /** |
97 | Add a todo to the todolist. | 98 | Add a todo to the todolist. |
98 | */ | 99 | */ |
99 | bool addTodo( Todo *todo ); | 100 | bool addTodo( Todo *todo ); |
100 | bool addTodoNoDup( Todo *todo ); | 101 | bool addTodoNoDup( Todo *todo ); |
101 | /** | 102 | /** |
102 | Remove a todo from the todolist. | 103 | Remove a todo from the todolist. |
103 | */ | 104 | */ |
104 | void deleteTodo( Todo * ); | 105 | void deleteTodo( Todo * ); |
105 | /** | 106 | /** |
106 | Searches todolist for an event with this unique string identifier, | 107 | Searches todolist for an event with this unique string identifier, |
107 | returns a pointer or null. | 108 | returns a pointer or null. |
108 | */ | 109 | */ |
109 | Todo *todo( const QString &uid ); | 110 | Todo *todo( const QString &uid ); |
110 | /** | 111 | /** |
111 | Return list of all todos. | 112 | Return list of all todos. |
112 | */ | 113 | */ |
113 | QPtrList<Todo> rawTodos(); | 114 | QPtrList<Todo> rawTodos(); |
114 | /** | 115 | /** |
115 | Returns list of todos due on the specified date. | 116 | Returns list of todos due on the specified date. |
116 | */ | 117 | */ |
117 | QPtrList<Todo> todos( const QDate &date ); | 118 | QPtrList<Todo> todos( const QDate &date ); |
118 | /** | 119 | /** |
119 | Return list of all todos. | 120 | Return list of all todos. |
120 | 121 | ||
121 | Workaround because compiler does not recognize function of base class. | 122 | Workaround because compiler does not recognize function of base class. |
122 | */ | 123 | */ |
123 | QPtrList<Todo> todos() { return Calendar::todos(); } | 124 | QPtrList<Todo> todos() { return Calendar::todos(); } |
124 | 125 | ||
125 | /** | 126 | /** |
126 | Add a Journal entry to calendar. | 127 | Add a Journal entry to calendar. |
127 | */ | 128 | */ |
128 | bool addJournal( Journal * ); | 129 | bool addJournal( Journal * ); |
129 | /** | 130 | /** |
130 | Remove a Journal from the calendar. | 131 | Remove a Journal from the calendar. |
131 | */ | 132 | */ |
132 | void deleteJournal( Journal * ); | 133 | void deleteJournal( Journal * ); |
133 | /** | 134 | /** |
134 | Return Journal for given date. | 135 | Return Journal for given date. |
135 | */ | 136 | */ |
136 | Journal *journal( const QDate & ); | 137 | Journal *journal( const QDate & ); |
137 | QPtrList<Journal> journals4Date( const QDate & ); | 138 | QPtrList<Journal> journals4Date( const QDate & ); |
138 | /** | 139 | /** |
139 | Return Journal with given UID. | 140 | Return Journal with given UID. |
140 | */ | 141 | */ |
141 | Journal *journal( const QString &uid ); | 142 | Journal *journal( const QString &uid ); |
142 | /** | 143 | /** |
143 | Return list of all Journals stored in calendar. | 144 | Return list of all Journals stored in calendar. |
144 | */ | 145 | */ |
145 | QPtrList<Journal> journals(); | 146 | QPtrList<Journal> journals(); |
146 | 147 | ||
147 | /** | 148 | /** |