-rw-r--r-- | kde2file/caldump/main.cpp | 55 |
1 files changed, 31 insertions, 24 deletions
diff --git a/kde2file/caldump/main.cpp b/kde2file/caldump/main.cpp index 03571b9..755e792 100644 --- a/kde2file/caldump/main.cpp +++ b/kde2file/caldump/main.cpp | |||
@@ -136,96 +136,103 @@ int main( int argc, char *argv[] ) | |||
136 | localCalendar->addJournal( (Journal *) cl ); | 136 | localCalendar->addJournal( (Journal *) cl ); |
137 | else if ( cl->type() == "Todo" ) | 137 | else if ( cl->type() == "Todo" ) |
138 | localCalendar->addTodo( (Todo *) cl ); | 138 | localCalendar->addTodo( (Todo *) cl ); |
139 | else if ( cl->type() == "Event" ) | 139 | else if ( cl->type() == "Event" ) |
140 | localCalendar->addEvent( (Event *) cl ); | 140 | localCalendar->addEvent( (Event *) cl ); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | FileStorage* storage = new FileStorage( calendarResource ); | 144 | FileStorage* storage = new FileStorage( calendarResource ); |
145 | storage->setFileName( fileName ); | 145 | storage->setFileName( fileName ); |
146 | storage->setSaveFormat( new ICalFormat() ); | 146 | storage->setSaveFormat( new ICalFormat() ); |
147 | storage->save(); | 147 | storage->save(); |
148 | delete storage; | 148 | delete storage; |
149 | qDebug("************************************* "); | 149 | qDebug("************************************* "); |
150 | qDebug("************kdecaldump*************** "); | 150 | qDebug("************kdecaldump*************** "); |
151 | qDebug("************************************* "); | 151 | qDebug("************************************* "); |
152 | qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); | 152 | qDebug("%d calendar entries dumped to file %s", num, fileName.latin1()); |
153 | 153 | ||
154 | } else { | 154 | } else { |
155 | qDebug("*************************load"); | 155 | qDebug("*************************load"); |
156 | localCalendar = new CalendarLocal(); | 156 | localCalendar = new CalendarLocal(); |
157 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); | 157 | localCalendar->setTimeZoneId( calendarResource->timeZoneId()); |
158 | FileStorage* storage = new FileStorage( localCalendar ); | 158 | FileStorage* storage = new FileStorage( localCalendar ); |
159 | storage->setFileName( fileName ); | 159 | storage->setFileName( fileName ); |
160 | int num = 0; | 160 | int num = 0; |
161 | int del = 0; | 161 | int del = 0; |
162 | int add = 0; | 162 | int add = 0; |
163 | if ( storage->load() ) { | 163 | if ( storage->load() ) { |
164 | qDebug("*************************loaded!"); | 164 | qDebug("*************************loaded!"); |
165 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); | 165 | KCal::Incidence::List newInc = localCalendar->rawIncidences(); |
166 | Incidence::List::ConstIterator it; | 166 | Incidence::List::ConstIterator it; |
167 | for( it = newInc.begin(); it != newInc.end(); ++it ) { | 167 | for( it = newInc.begin(); it != newInc.end(); ++it ) { |
168 | Incidence* cl = (*it)->clone(); | 168 | if ( (*it)->pilotId() > 0 ) { //changed |
169 | Incidence *incOld = calendarResource->incidence( cl->uid() ); | 169 | Incidence* cl = (*it)->clone(); |
170 | ResourceCalendar * res = 0; | 170 | Incidence *incOld = calendarResource->incidence( cl->uid() ); |
171 | if ( incOld ) | 171 | ResourceCalendar * res = 0; |
172 | res = calendarResource->resource( incOld ); | 172 | if ( incOld ) |
173 | if ( res ) { | 173 | res = calendarResource->resource( incOld ); |
174 | ++num; | 174 | if ( res ) { |
175 | if ( incOld->type() == "Journal" ) | 175 | cl->setPilotId( incOld->pilotId() ); |
176 | calendarResource->deleteJournal( (Journal *) incOld ); | 176 | ++num; |
177 | else if ( incOld->type() == "Todo" ) | ||
178 | calendarResource->deleteTodo( (Todo *) incOld ); | ||
179 | else if ( incOld->type() == "Event" ) | ||
180 | calendarResource->deleteEvent( (Event *) incOld ); | ||
181 | |||
182 | if ( cl->type() == "Journal" ) | ||
183 | calendarResource->addJournal( (Journal *) cl, res ); | ||
184 | else if ( cl->type() == "Todo" ) | ||
185 | calendarResource->addTodo( (Todo *) cl, res ); | ||
186 | else if ( cl->type() == "Event" ) | ||
187 | calendarResource->addEvent( (Event *) cl, res ); | ||
188 | |||
189 | } else { | ||
190 | if ( incOld ) { | ||
191 | qDebug("ERROR: no resource found for old incidence "); | ||
192 | if ( incOld->type() == "Journal" ) | 177 | if ( incOld->type() == "Journal" ) |
193 | calendarResource->deleteJournal( (Journal *) incOld ); | 178 | calendarResource->deleteJournal( (Journal *) incOld ); |
194 | else if ( incOld->type() == "Todo" ) | 179 | else if ( incOld->type() == "Todo" ) |
195 | calendarResource->deleteTodo( (Todo *) incOld ); | 180 | calendarResource->deleteTodo( (Todo *) incOld ); |
196 | else if ( incOld->type() == "Event" ) | 181 | else if ( incOld->type() == "Event" ) |
197 | calendarResource->deleteEvent( (Event *) incOld ); | 182 | calendarResource->deleteEvent( (Event *) incOld ); |
183 | |||
184 | if ( cl->type() == "Journal" ) | ||
185 | calendarResource->addJournal( (Journal *) cl, res ); | ||
186 | else if ( cl->type() == "Todo" ) | ||
187 | calendarResource->addTodo( (Todo *) cl, res ); | ||
188 | else if ( cl->type() == "Event" ) | ||
189 | calendarResource->addEvent( (Event *) cl, res ); | ||
190 | |||
191 | } else { | ||
192 | if ( incOld ) { | ||
193 | qDebug("ERROR: no resource found for old incidence "); | ||
194 | if ( incOld->type() == "Journal" ) | ||
195 | calendarResource->deleteJournal( (Journal *) incOld ); | ||
196 | else if ( incOld->type() == "Todo" ) | ||
197 | calendarResource->deleteTodo( (Todo *) incOld ); | ||
198 | else if ( incOld->type() == "Event" ) | ||
199 | calendarResource->deleteEvent( (Event *) incOld ); | ||
198 | 200 | ||
201 | } | ||
202 | calendarResource->addIncidence( cl ); | ||
203 | ++add; | ||
199 | } | 204 | } |
205 | } else { // added | ||
206 | Incidence* cl = (*it)->clone(); | ||
200 | calendarResource->addIncidence( cl ); | 207 | calendarResource->addIncidence( cl ); |
201 | ++add; | 208 | ++add; |
202 | } | 209 | } |
203 | } | 210 | } |
204 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); | 211 | KCal::Incidence::List allInc = calendarResource->rawIncidences(); |
205 | 212 | ||
206 | for( it = allInc.begin(); it != allInc.end(); ++it ) { | 213 | for( it = allInc.begin(); it != allInc.end(); ++it ) { |
207 | ResourceCalendar * re = calendarResource->resource( (*it) ); | 214 | ResourceCalendar * re = calendarResource->resource( (*it) ); |
208 | if ( re && !re->readOnly() ) { | 215 | if ( re && !re->readOnly() ) { |
209 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); | 216 | Incidence* cl = localCalendar->incidence( (*it)->uid() ); |
210 | if ( !cl ) { | 217 | if ( !cl ) { |
211 | ++del; | 218 | ++del; |
212 | cl = (*it); | 219 | cl = (*it); |
213 | if ( cl->type() == "Journal" ) | 220 | if ( cl->type() == "Journal" ) |
214 | calendarResource->deleteJournal( (Journal *) cl ); | 221 | calendarResource->deleteJournal( (Journal *) cl ); |
215 | else if ( cl->type() == "Todo" ) | 222 | else if ( cl->type() == "Todo" ) |
216 | calendarResource->deleteTodo( (Todo *) cl ); | 223 | calendarResource->deleteTodo( (Todo *) cl ); |
217 | else if ( cl->type() == "Event" ) | 224 | else if ( cl->type() == "Event" ) |
218 | calendarResource->deleteEvent( (Event *) cl ); | 225 | calendarResource->deleteEvent( (Event *) cl ); |
219 | //QDateTime lm = cl->lastModified(); | 226 | //QDateTime lm = cl->lastModified(); |
220 | //cl->setResources( (*it)->resources() ); | 227 | //cl->setResources( (*it)->resources() ); |
221 | //cl->setLastModified(lm); | 228 | //cl->setLastModified(lm); |
222 | } | 229 | } |
223 | } | 230 | } |
224 | } | 231 | } |
225 | 232 | ||
226 | calendarResource->save(); | 233 | calendarResource->save(); |
227 | qDebug("************************************* "); | 234 | qDebug("************************************* "); |
228 | qDebug("************kdecaldump*************** "); | 235 | qDebug("************kdecaldump*************** "); |
229 | qDebug("************************************* "); | 236 | qDebug("************************************* "); |
230 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); | 237 | qDebug("Calendar entries\nchanged %d\ndeleted %d\nadded %d\nfrom file %s", num,del, add, fileName.latin1()); |
231 | 238 | ||