author | zautrix <zautrix> | 2005-07-09 08:48:32 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-07-09 08:48:32 (UTC) |
commit | f731dd9fc5b3f14c44d4de26eb5370a79c63887c (patch) (unidiff) | |
tree | e3d7b3929cc8819a5451bd04c9698bc0767e49b1 /libkcal/calendarlocal.cpp | |
parent | e27ad31c6016152449bbdaf4f9f387fa61183c37 (diff) | |
download | kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.zip kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.gz kdepimpi-f731dd9fc5b3f14c44d4de26eb5370a79c63887c.tar.bz2 |
fixi
-rw-r--r-- | libkcal/calendarlocal.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp index cce798f..3e42ec0 100644 --- a/libkcal/calendarlocal.cpp +++ b/libkcal/calendarlocal.cpp | |||
@@ -1,166 +1,241 @@ | |||
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 | 22 | ||
23 | #include <qdatetime.h> | 23 | #include <qdatetime.h> |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | 26 | ||
27 | #include <kdebug.h> | 27 | #include <kdebug.h> |
28 | #include <kconfig.h> | 28 | #include <kconfig.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klocale.h> | 30 | #include <klocale.h> |
31 | 31 | ||
32 | #include "vcaldrag.h" | 32 | #include "vcaldrag.h" |
33 | #include "vcalformat.h" | 33 | #include "vcalformat.h" |
34 | #include "icalformat.h" | 34 | #include "icalformat.h" |
35 | #include "exceptions.h" | 35 | #include "exceptions.h" |
36 | #include "incidence.h" | 36 | #include "incidence.h" |
37 | #include "journal.h" | 37 | #include "journal.h" |
38 | #include "filestorage.h" | 38 | #include "filestorage.h" |
39 | #include "calfilter.h" | 39 | #include "calfilter.h" |
40 | 40 | ||
41 | #include "calendarlocal.h" | 41 | #include "calendarlocal.h" |
42 | 42 | ||
43 | // #ifndef DESKTOP_VERSION | 43 | // #ifndef DESKTOP_VERSION |
44 | // #include <qtopia/alarmserver.h> | 44 | // #include <qtopia/alarmserver.h> |
45 | // #endif | 45 | // #endif |
46 | using namespace KCal; | 46 | using namespace KCal; |
47 | 47 | ||
48 | CalendarLocal::CalendarLocal() | 48 | CalendarLocal::CalendarLocal() |
49 | : Calendar() | 49 | : Calendar() |
50 | { | 50 | { |
51 | init(); | 51 | init(); |
52 | } | 52 | } |
53 | 53 | ||
54 | CalendarLocal::CalendarLocal(const QString &timeZoneId) | 54 | 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-") ) |
87 | ev->setReadOnly( true ); | 162 | ev->setReadOnly( true ); |
88 | ev = mEventList.next(); | 163 | ev = mEventList.next(); |
89 | } | 164 | } |
90 | } | 165 | } |
91 | void CalendarLocal::addCalendar( Calendar* cal ) | 166 | void CalendarLocal::addCalendar( Calendar* cal ) |
92 | { | 167 | { |
93 | cal->setDontDeleteIncidencesOnClose(); | 168 | cal->setDontDeleteIncidencesOnClose(); |
94 | { | 169 | { |
95 | QPtrList<Event> EventList = cal->rawEvents(); | 170 | QPtrList<Event> EventList = cal->rawEvents(); |
96 | Event * ev = EventList.first(); | 171 | Event * ev = EventList.first(); |
97 | while ( ev ) { | 172 | while ( ev ) { |
98 | ev->unRegisterObserver( cal ); | 173 | ev->unRegisterObserver( cal ); |
99 | ev->registerObserver( this ); | 174 | ev->registerObserver( this ); |
100 | mEventList.append( ev ); | 175 | mEventList.append( ev ); |
101 | ev = EventList.next(); | 176 | ev = EventList.next(); |
102 | } | 177 | } |
103 | } | 178 | } |
104 | { | 179 | { |
105 | 180 | ||
106 | QPtrList<Todo> TodoList = cal->rawTodos(); | 181 | QPtrList<Todo> TodoList = cal->rawTodos(); |
107 | Todo * ev = TodoList.first(); | 182 | Todo * ev = TodoList.first(); |
108 | while ( ev ) { | 183 | while ( ev ) { |
109 | QString rel = ev->relatedToUid(); | 184 | QString rel = ev->relatedToUid(); |
110 | if ( !rel.isEmpty() ){ | 185 | if ( !rel.isEmpty() ){ |
111 | ev->setRelatedTo ( 0 ); | 186 | ev->setRelatedTo ( 0 ); |
112 | ev->setRelatedToUid( rel ); | 187 | ev->setRelatedToUid( rel ); |
113 | } | 188 | } |
114 | ev = TodoList.next(); | 189 | ev = TodoList.next(); |
115 | } | 190 | } |
116 | //TodoList = cal->rawTodos(); | 191 | //TodoList = cal->rawTodos(); |
117 | ev = TodoList.first(); | 192 | ev = TodoList.first(); |
118 | while ( ev ) { | 193 | while ( ev ) { |
119 | ev->unRegisterObserver( cal ); | 194 | ev->unRegisterObserver( cal ); |
120 | ev->registerObserver( this ); | 195 | ev->registerObserver( this ); |
121 | mTodoList.append( ev ); | 196 | mTodoList.append( ev ); |
122 | setupRelations( ev ); | 197 | setupRelations( ev ); |
123 | ev = TodoList.next(); | 198 | ev = TodoList.next(); |
124 | } | 199 | } |
125 | } | 200 | } |
126 | { | 201 | { |
127 | QPtrList<Journal> JournalList = cal->journals(); | 202 | QPtrList<Journal> JournalList = cal->journals(); |
128 | Journal * ev = JournalList.first(); | 203 | Journal * ev = JournalList.first(); |
129 | while ( ev ) { | 204 | while ( ev ) { |
130 | ev->unRegisterObserver( cal ); | 205 | ev->unRegisterObserver( cal ); |
131 | ev->registerObserver( this ); | 206 | ev->registerObserver( this ); |
132 | mJournalList.append( ev ); | 207 | mJournalList.append( ev ); |
133 | ev = JournalList.next(); | 208 | ev = JournalList.next(); |
134 | } | 209 | } |
135 | } | 210 | } |
136 | setModified( true ); | 211 | setModified( true ); |
137 | } | 212 | } |
138 | bool CalendarLocal::load( const QString &fileName ) | 213 | bool CalendarLocal::load( const QString &fileName ) |
139 | { | 214 | { |
140 | FileStorage storage( this, fileName ); | 215 | FileStorage storage( this, fileName ); |
141 | return storage.load(); | 216 | return storage.load(); |
142 | } | 217 | } |
143 | 218 | ||
144 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) | 219 | bool CalendarLocal::save( const QString &fileName, CalFormat *format ) |
145 | { | 220 | { |
146 | FileStorage storage( this, fileName, format ); | 221 | FileStorage storage( this, fileName, format ); |
147 | return storage.save(); | 222 | return storage.save(); |
148 | } | 223 | } |
149 | 224 | ||
150 | void CalendarLocal::stopAllTodos() | 225 | void CalendarLocal::stopAllTodos() |
151 | { | 226 | { |
152 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) | 227 | for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) |
153 | it->setRunning( false ); | 228 | it->setRunning( false ); |
154 | 229 | ||
155 | } | 230 | } |
156 | void CalendarLocal::close() | 231 | void CalendarLocal::close() |
157 | { | 232 | { |
158 | 233 | ||
159 | Todo * i; | 234 | Todo * i; |
160 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); | 235 | for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false); |
161 | 236 | ||
162 | mEventList.setAutoDelete( true ); | 237 | mEventList.setAutoDelete( true ); |
163 | mTodoList.setAutoDelete( true ); | 238 | mTodoList.setAutoDelete( true ); |
164 | mJournalList.setAutoDelete( false ); | 239 | mJournalList.setAutoDelete( false ); |
165 | 240 | ||
166 | mEventList.clear(); | 241 | mEventList.clear(); |