-rw-r--r-- | libkcal/sharpformat.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index 24b8349..c2ee2c9 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp | |||
@@ -161,194 +161,197 @@ class SharpParser : public QObject | |||
161 | if ( hasEndDate ) | 161 | if ( hasEndDate ) |
162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); | 162 | r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); |
163 | else | 163 | else |
164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); | 164 | r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); |
165 | r->addYearlyNum( startDate.month() ); | 165 | r->addYearlyNum( startDate.month() ); |
166 | } | 166 | } |
167 | } else { | 167 | } else { |
168 | event->recurrence()->unsetRecurs(); | 168 | event->recurrence()->unsetRecurs(); |
169 | } | 169 | } |
170 | 170 | ||
171 | QString categoryList = attList[1] ; | 171 | QString categoryList = attList[1] ; |
172 | event->setCategories( categoryList ); | 172 | event->setCategories( categoryList ); |
173 | 173 | ||
174 | // strange 0 semms to mean: alarm enabled | 174 | // strange 0 semms to mean: alarm enabled |
175 | if ( attList[8] == "0" ) { | 175 | if ( attList[8] == "0" ) { |
176 | Alarm *alarm; | 176 | Alarm *alarm; |
177 | if ( event->alarms().count() > 0 ) | 177 | if ( event->alarms().count() > 0 ) |
178 | alarm = event->alarms().first(); | 178 | alarm = event->alarms().first(); |
179 | else { | 179 | else { |
180 | alarm = new Alarm( event ); | 180 | alarm = new Alarm( event ); |
181 | event->addAlarm( alarm ); | 181 | event->addAlarm( alarm ); |
182 | alarm->setType( Alarm::Audio ); | 182 | alarm->setType( Alarm::Audio ); |
183 | } | 183 | } |
184 | //alarm->setType( Alarm::Audio ); | 184 | //alarm->setType( Alarm::Audio ); |
185 | alarm->setEnabled( true ); | 185 | alarm->setEnabled( true ); |
186 | int alarmOffset = attList[9].toInt(); | 186 | int alarmOffset = attList[9].toInt(); |
187 | alarm->setStartOffset( alarmOffset * -60 ); | 187 | alarm->setStartOffset( alarmOffset * -60 ); |
188 | } else { | 188 | } else { |
189 | Alarm *alarm; | 189 | Alarm *alarm; |
190 | if ( event->alarms().count() > 0 ) { | 190 | if ( event->alarms().count() > 0 ) { |
191 | alarm = event->alarms().first(); | 191 | alarm = event->alarms().first(); |
192 | alarm->setType( Alarm::Audio ); | 192 | alarm->setType( Alarm::Audio ); |
193 | alarm->setStartOffset( -60*15 ); | 193 | alarm->setStartOffset( -60*15 ); |
194 | alarm->setEnabled( false ); | 194 | alarm->setEnabled( false ); |
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | mCalendar->addEvent( event); | 198 | mCalendar->addEvent( event); |
199 | } else if ( qName == "Todo" ) { | 199 | } else if ( qName == "Todo" ) { |
200 | Todo *todo; | 200 | Todo *todo; |
201 | 201 | ||
202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); | 202 | todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); |
203 | if (todo ) | 203 | if (todo ) |
204 | todo = (Todo*)todo->clone(); | 204 | todo = (Todo*)todo->clone(); |
205 | else | 205 | else |
206 | todo = new Todo; | 206 | todo = new Todo; |
207 | 207 | ||
208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 | 208 | //CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 |
209 | // 0 1 2 3 4 5 6 7 8 | 209 | // 0 1 2 3 4 5 6 7 8 |
210 | //1,,,,,1,4,Loch zumachen,"" | 210 | //1,,,,,1,4,Loch zumachen,"" |
211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " | 211 | //3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " |
212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes | 212 | //2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes |
213 | 213 | ||
214 | todo->setID( "Sharp_DTM", attList[0]); | 214 | todo->setID( "Sharp_DTM", attList[0]); |
215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); | 215 | todo->setCsum( "Sharp_DTM", QString::number( cSum )); |
216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 216 | todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
217 | 217 | ||
218 | todo->setSummary( attList[7] ); | 218 | todo->setSummary( attList[7] ); |
219 | todo->setDescription( attList[8]); | 219 | todo->setDescription( attList[8]); |
220 | 220 | ||
221 | int priority = attList[6].toInt(); | 221 | int priority = attList[6].toInt(); |
222 | if ( priority == 0 ) priority = 3; | 222 | if ( priority == 0 ) priority = 3; |
223 | todo->setPriority( priority ); | 223 | todo->setPriority( priority ); |
224 | 224 | ||
225 | QString categoryList = attList[1]; | 225 | QString categoryList = attList[1]; |
226 | todo->setCategories( categoryList ); | 226 | todo->setCategories( categoryList ); |
227 | 227 | ||
228 | 228 | ||
229 | 229 | ||
230 | QString hasDateStr = attList[3]; // due | 230 | QString hasDateStr = attList[3]; // due |
231 | if ( !hasDateStr.isEmpty() ) { | 231 | if ( !hasDateStr.isEmpty() ) { |
232 | if ( hasDateStr.right(6) == "000000" ) { | 232 | if ( hasDateStr.right(6) == "000000" ) { |
233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); | 233 | todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); |
234 | todo->setFloats( true ); | 234 | todo->setFloats( true ); |
235 | } | 235 | } |
236 | else { | 236 | else { |
237 | todo->setDtDue( fromString( hasDateStr ) ); | 237 | todo->setDtDue( fromString( hasDateStr ) ); |
238 | todo->setFloats( false ); | 238 | todo->setFloats( false ); |
239 | } | 239 | } |
240 | 240 | ||
241 | todo->setHasDueDate( true ); | 241 | todo->setHasDueDate( true ); |
242 | } | 242 | } |
243 | hasDateStr = attList[2];//start | 243 | hasDateStr = attList[2];//start |
244 | if ( !hasDateStr.isEmpty() ) { | 244 | if ( !hasDateStr.isEmpty() ) { |
245 | 245 | ||
246 | todo->setDtStart( fromString( hasDateStr ) ); | 246 | todo->setDtStart( fromString( hasDateStr ) ); |
247 | todo->setHasStartDate( true); | 247 | todo->setHasStartDate( true); |
248 | } else | 248 | } else |
249 | todo->setHasStartDate( false ); | 249 | todo->setHasStartDate( false ); |
250 | hasDateStr = attList[4];//completed | 250 | hasDateStr = attList[4];//completed |
251 | if ( !hasDateStr.isEmpty() ) { | 251 | if ( !hasDateStr.isEmpty() ) { |
252 | todo->setCompleted(fromString( hasDateStr ) ); | 252 | todo->setCompleted(fromString( hasDateStr ) ); |
253 | } | 253 | } |
254 | QString completedStr = attList[5]; | 254 | QString completedStr = attList[5]; |
255 | if ( completedStr == "0" ) | 255 | if ( completedStr == "0" ) |
256 | todo->setCompleted( true ); | 256 | todo->setCompleted( true ); |
257 | else | 257 | else { |
258 | todo->setCompleted( false ); | 258 | // do not change percent complete |
259 | if ( todo->isCompleted() ) | ||
260 | todo->setCompleted( false ); | ||
261 | } | ||
259 | mCalendar->addTodo( todo ); | 262 | mCalendar->addTodo( todo ); |
260 | 263 | ||
261 | } else if ( qName == "Category" ) { | 264 | } else if ( qName == "Category" ) { |
262 | /* | 265 | /* |
263 | QString id = attributes.value( "id" ); | 266 | QString id = attributes.value( "id" ); |
264 | QString name = attributes.value( "name" ); | 267 | QString name = attributes.value( "name" ); |
265 | setCategory( id, name ); | 268 | setCategory( id, name ); |
266 | */ | 269 | */ |
267 | } | 270 | } |
268 | //qDebug("end "); | 271 | //qDebug("end "); |
269 | return true; | 272 | return true; |
270 | } | 273 | } |
271 | 274 | ||
272 | 275 | ||
273 | QDateTime fromString ( QString s, bool useTz = true ) { | 276 | QDateTime fromString ( QString s, bool useTz = true ) { |
274 | QDateTime dt; | 277 | QDateTime dt; |
275 | int y,m,t,h,min,sec; | 278 | int y,m,t,h,min,sec; |
276 | y = s.mid(0,4).toInt(); | 279 | y = s.mid(0,4).toInt(); |
277 | m = s.mid(4,2).toInt(); | 280 | m = s.mid(4,2).toInt(); |
278 | t = s.mid(6,2).toInt(); | 281 | t = s.mid(6,2).toInt(); |
279 | h = s.mid(9,2).toInt(); | 282 | h = s.mid(9,2).toInt(); |
280 | min = s.mid(11,2).toInt(); | 283 | min = s.mid(11,2).toInt(); |
281 | sec = s.mid(13,2).toInt(); | 284 | sec = s.mid(13,2).toInt(); |
282 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); | 285 | dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); |
283 | int offset = KGlobal::locale()->localTimeOffset( dt ); | 286 | int offset = KGlobal::locale()->localTimeOffset( dt ); |
284 | if ( useTz ) | 287 | if ( useTz ) |
285 | dt = dt.addSecs ( offset*60); | 288 | dt = dt.addSecs ( offset*60); |
286 | return dt; | 289 | return dt; |
287 | 290 | ||
288 | } | 291 | } |
289 | protected: | 292 | protected: |
290 | QDateTime toDateTime( const QString &value ) | 293 | QDateTime toDateTime( const QString &value ) |
291 | { | 294 | { |
292 | QDateTime dt; | 295 | QDateTime dt; |
293 | dt.setTime_t( value.toUInt() ); | 296 | dt.setTime_t( value.toUInt() ); |
294 | 297 | ||
295 | return dt; | 298 | return dt; |
296 | } | 299 | } |
297 | 300 | ||
298 | private: | 301 | private: |
299 | Calendar *mCalendar; | 302 | Calendar *mCalendar; |
300 | }; | 303 | }; |
301 | 304 | ||
302 | 305 | ||
303 | SharpFormat::SharpFormat() | 306 | SharpFormat::SharpFormat() |
304 | { | 307 | { |
305 | 308 | ||
306 | } | 309 | } |
307 | 310 | ||
308 | SharpFormat::~SharpFormat() | 311 | SharpFormat::~SharpFormat() |
309 | { | 312 | { |
310 | } | 313 | } |
311 | ulong SharpFormat::getCsum( const QStringList & attList) | 314 | ulong SharpFormat::getCsum( const QStringList & attList) |
312 | { | 315 | { |
313 | int max = attList.count() -1; | 316 | int max = attList.count() -1; |
314 | ulong cSum = 0; | 317 | ulong cSum = 0; |
315 | int j,k,i; | 318 | int j,k,i; |
316 | int add; | 319 | int add; |
317 | for ( i = 1; i < max ; ++i ) { | 320 | for ( i = 1; i < max ; ++i ) { |
318 | QString s = attList[i]; | 321 | QString s = attList[i]; |
319 | if ( ! s.isEmpty() ){ | 322 | if ( ! s.isEmpty() ){ |
320 | j = s.length(); | 323 | j = s.length(); |
321 | for ( k = 0; k < j; ++k ) { | 324 | for ( k = 0; k < j; ++k ) { |
322 | int mul = k +1; | 325 | int mul = k +1; |
323 | add = s[k].unicode (); | 326 | add = s[k].unicode (); |
324 | if ( k < 16 ) | 327 | if ( k < 16 ) |
325 | mul = mul * mul; | 328 | mul = mul * mul; |
326 | add = add * mul *i*i*i; | 329 | add = add * mul *i*i*i; |
327 | cSum += add; | 330 | cSum += add; |
328 | } | 331 | } |
329 | } | 332 | } |
330 | } | 333 | } |
331 | return cSum; | 334 | return cSum; |
332 | 335 | ||
333 | } | 336 | } |
334 | #include <stdlib.h> | 337 | #include <stdlib.h> |
335 | #define DEBUGMODE false | 338 | #define DEBUGMODE false |
336 | //#define DEBUGMODE true | 339 | //#define DEBUGMODE true |
337 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) | 340 | bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) |
338 | { | 341 | { |
339 | 342 | ||
340 | 343 | ||
341 | bool debug = DEBUGMODE; | 344 | bool debug = DEBUGMODE; |
342 | QString text; | 345 | QString text; |
343 | QString codec = "utf8"; | 346 | QString codec = "utf8"; |
344 | QLabel status ( i18n("Reading events ..."), 0 ); | 347 | QLabel status ( i18n("Reading events ..."), 0 ); |
345 | 348 | ||
346 | int w = status.sizeHint().width()+20 ; | 349 | int w = status.sizeHint().width()+20 ; |
347 | if ( w < 200 ) w = 200; | 350 | if ( w < 200 ) w = 200; |
348 | int h = status.sizeHint().height()+20 ; | 351 | int h = status.sizeHint().height()+20 ; |
349 | int dw = QApplication::desktop()->width(); | 352 | int dw = QApplication::desktop()->width(); |
350 | int dh = QApplication::desktop()->height(); | 353 | int dh = QApplication::desktop()->height(); |
351 | status.setCaption(i18n("Reading DTM Data") ); | 354 | status.setCaption(i18n("Reading DTM Data") ); |
352 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 355 | status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
353 | status.show(); | 356 | status.show(); |
354 | status.raise(); | 357 | status.raise(); |