summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-20 04:35:46 (UTC)
committer zautrix <zautrix>2004-08-20 04:35:46 (UTC)
commitb42c4af4200c67802ee0cc57e10e1464903736b7 (patch) (unidiff)
tree59f35319f3223892e2353bb8a2c72cb9e87ca0f9
parent93decd4185adc7197008e8397cf753a5ab674d99 (diff)
downloadkdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.zip
kdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.tar.gz
kdepimpi-b42c4af4200c67802ee0cc57e10e1464903736b7.tar.bz2
change reverted
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 820d068..defdb09 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -126,769 +126,769 @@ class SharpParser : public QObject
126 126
127 QBitArray weekDays( 7 ); 127 QBitArray weekDays( 7 );
128 int i; 128 int i;
129 int bb = 1; 129 int bb = 1;
130 for( i = 1; i <= 7; ++i ) { 130 for( i = 1; i <= 7; ++i ) {
131 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 131 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
132 bb = 2 << (i-1); 132 bb = 2 << (i-1);
133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 133 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
134 } 134 }
135 // qDebug("next "); 135 // qDebug("next ");
136 QString posStr = attList[13]; 136 QString posStr = attList[13];
137 int pos = posStr.toInt(); 137 int pos = posStr.toInt();
138 Recurrence *r = event->recurrence(); 138 Recurrence *r = event->recurrence();
139 139
140 if ( rtype == "0" ) { 140 if ( rtype == "0" ) {
141 if ( hasEndDate ) r->setDaily( freq, endDate ); 141 if ( hasEndDate ) r->setDaily( freq, endDate );
142 else r->setDaily( freq, -1 ); 142 else r->setDaily( freq, -1 );
143 } else if ( rtype == "1" ) { 143 } else if ( rtype == "1" ) {
144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 144 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
145 else r->setWeekly( freq, weekDays, -1 ); 145 else r->setWeekly( freq, weekDays, -1 );
146 } else if ( rtype == "3" ) { 146 } else if ( rtype == "3" ) {
147 if ( hasEndDate ) 147 if ( hasEndDate )
148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 148 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
149 else 149 else
150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 150 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
151 r->addMonthlyDay( startDate.day() ); 151 r->addMonthlyDay( startDate.day() );
152 } else if ( rtype == "2" ) { 152 } else if ( rtype == "2" ) {
153 if ( hasEndDate ) 153 if ( hasEndDate )
154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 154 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
155 else 155 else
156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 156 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
157 QBitArray days( 7 ); 157 QBitArray days( 7 );
158 days.fill( false ); 158 days.fill( false );
159 days.setBit( startDate.dayOfWeek() - 1 ); 159 days.setBit( startDate.dayOfWeek() - 1 );
160 r->addMonthlyPos( pos, days ); 160 r->addMonthlyPos( pos, days );
161 } else if ( rtype == "4" ) { 161 } else if ( rtype == "4" ) {
162 if ( hasEndDate ) 162 if ( hasEndDate )
163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 163 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
164 else 164 else
165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 165 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
166 r->addYearlyNum( startDate.month() ); 166 r->addYearlyNum( startDate.month() );
167 } 167 }
168 } else { 168 } else {
169 event->recurrence()->unsetRecurs(); 169 event->recurrence()->unsetRecurs();
170 } 170 }
171 171
172 QString categoryList = attList[1] ; 172 QString categoryList = attList[1] ;
173 event->setCategories( lookupCategories( categoryList ) ); 173 event->setCategories( lookupCategories( categoryList ) );
174 174
175 // strange 0 semms to mean: alarm enabled 175 // strange 0 semms to mean: alarm enabled
176 if ( attList[8] == "0" ) { 176 if ( attList[8] == "0" ) {
177 Alarm *alarm; 177 Alarm *alarm;
178 if ( event->alarms().count() > 0 ) 178 if ( event->alarms().count() > 0 )
179 alarm = event->alarms().first(); 179 alarm = event->alarms().first();
180 else { 180 else {
181 alarm = new Alarm( event ); 181 alarm = new Alarm( event );
182 event->addAlarm( alarm ); 182 event->addAlarm( alarm );
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( lookupCategories( categoryList ) ); 226 todo->setCategories( lookupCategories( 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 todo->setCompleted( false );
259 mCalendar->addTodo( todo ); 259 mCalendar->addTodo( todo );
260 260
261 } else if ( qName == "Category" ) { 261 } else if ( qName == "Category" ) {
262 /* 262 /*
263 QString id = attributes.value( "id" ); 263 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 264 QString name = attributes.value( "name" );
265 setCategory( id, name ); 265 setCategory( id, name );
266 */ 266 */
267 } 267 }
268 //qDebug("end "); 268 //qDebug("end ");
269 return true; 269 return true;
270 } 270 }
271 271
272 272
273 void setCategoriesList ( QStringList * c ) 273 void setCategoriesList ( QStringList * c )
274 { 274 {
275 oldCategories = c; 275 oldCategories = c;
276 } 276 }
277 277
278 QDateTime fromString ( QString s, bool useTz = true ) { 278 QDateTime fromString ( QString s, bool useTz = true ) {
279 QDateTime dt; 279 QDateTime dt;
280 int y,m,t,h,min,sec; 280 int y,m,t,h,min,sec;
281 y = s.mid(0,4).toInt(); 281 y = s.mid(0,4).toInt();
282 m = s.mid(4,2).toInt(); 282 m = s.mid(4,2).toInt();
283 t = s.mid(6,2).toInt(); 283 t = s.mid(6,2).toInt();
284 h = s.mid(9,2).toInt(); 284 h = s.mid(9,2).toInt();
285 min = s.mid(11,2).toInt(); 285 min = s.mid(11,2).toInt();
286 sec = s.mid(13,2).toInt(); 286 sec = s.mid(13,2).toInt();
287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 287 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
288 int offset = KGlobal::locale()->localTimeOffset( dt ); 288 int offset = KGlobal::locale()->localTimeOffset( dt );
289 if ( useTz ) 289 if ( useTz )
290 dt = dt.addSecs ( offset*60); 290 dt = dt.addSecs ( offset*60);
291 return dt; 291 return dt;
292 292
293 } 293 }
294 protected: 294 protected:
295 QDateTime toDateTime( const QString &value ) 295 QDateTime toDateTime( const QString &value )
296 { 296 {
297 QDateTime dt; 297 QDateTime dt;
298 dt.setTime_t( value.toUInt() ); 298 dt.setTime_t( value.toUInt() );
299 299
300 return dt; 300 return dt;
301 } 301 }
302 302
303 QStringList lookupCategories( const QString &categoryList ) 303 QStringList lookupCategories( const QString &categoryList )
304 { 304 {
305 QStringList categoryIds = QStringList::split( ";", categoryList ); 305 QStringList categoryIds = QStringList::split( ";", categoryList );
306 QStringList categories; 306 QStringList categories;
307 QStringList::ConstIterator it; 307 QStringList::ConstIterator it;
308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 308 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
309 QString cate = category( *it ); 309 QString cate = category( *it );
310 if ( oldCategories ) { 310 if ( oldCategories ) {
311 if ( ! oldCategories->contains( cate ) ) 311 if ( ! oldCategories->contains( cate ) )
312 oldCategories->append( cate ); 312 oldCategories->append( cate );
313 } 313 }
314 categories.append(cate ); 314 categories.append(cate );
315 } 315 }
316 return categories; 316 return categories;
317 } 317 }
318 318
319 private: 319 private:
320 Calendar *mCalendar; 320 Calendar *mCalendar;
321 QStringList * oldCategories; 321 QStringList * oldCategories;
322 static QString category( const QString &id ) 322 static QString category( const QString &id )
323 { 323 {
324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 324 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
325 if ( it == mCategoriesMap.end() ) return id; 325 if ( it == mCategoriesMap.end() ) return id;
326 else return *it; 326 else return *it;
327 } 327 }
328 328
329 static void setCategory( const QString &id, const QString &name ) 329 static void setCategory( const QString &id, const QString &name )
330 { 330 {
331 mCategoriesMap.insert( id, name ); 331 mCategoriesMap.insert( id, name );
332 } 332 }
333 333
334 static QMap<QString,QString> mCategoriesMap; 334 static QMap<QString,QString> mCategoriesMap;
335}; 335};
336 336
337QMap<QString,QString> SharpParser::mCategoriesMap; 337QMap<QString,QString> SharpParser::mCategoriesMap;
338 338
339SharpFormat::SharpFormat() 339SharpFormat::SharpFormat()
340{ 340{
341 mCategories = 0; 341 mCategories = 0;
342} 342}
343 343
344SharpFormat::~SharpFormat() 344SharpFormat::~SharpFormat()
345{ 345{
346} 346}
347ulong SharpFormat::getCsum( const QStringList & attList) 347ulong SharpFormat::getCsum( const QStringList & attList)
348{ 348{
349 int max = attList.count() -1; 349 int max = attList.count() -1;
350 ulong cSum = 0; 350 ulong cSum = 0;
351 int j,k,i; 351 int j,k,i;
352 int add; 352 int add;
353 for ( i = 1; i < max ; ++i ) { 353 for ( i = 1; i < max ; ++i ) {
354 QString s = attList[i]; 354 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
356 j = s.length(); 356 j = s.length();
357 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 358 int mul = k +1;
359 add = s[k].unicode (); 359 add = s[k].unicode ();
360 if ( k < 16 ) 360 if ( k < 16 )
361 mul = mul * mul; 361 mul = mul * mul;
362 add = add * mul *i*i*i; 362 add = add * mul *i*i*i;
363 cSum += add; 363 cSum += add;
364 } 364 }
365 } 365 }
366 } 366 }
367 return cSum; 367 return cSum;
368 368
369} 369}
370#include <stdlib.h> 370#include <stdlib.h>
371#define DEBUGMODE false 371#define DEBUGMODE false
372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 372bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
373{ 373{
374 374
375 375
376 bool debug = DEBUGMODE; 376 bool debug = DEBUGMODE;
377 //debug = true; 377 //debug = true;
378 QString text; 378 QString text;
379 QString codec = "utf8"; 379 QString codec = "utf8";
380 QLabel status ( i18n("Reading events ..."), 0 ); 380 QLabel status ( i18n("Reading events ..."), 0 );
381 381
382 int w = status.sizeHint().width()+20 ; 382 int w = status.sizeHint().width()+20 ;
383 if ( w < 200 ) w = 200; 383 if ( w < 200 ) w = 200;
384 int h = status.sizeHint().height()+20 ; 384 int h = status.sizeHint().height()+20 ;
385 int dw = QApplication::desktop()->width(); 385 int dw = QApplication::desktop()->width();
386 int dh = QApplication::desktop()->height(); 386 int dh = QApplication::desktop()->height();
387 status.setCaption(i18n("Reading DTM Data") ); 387 status.setCaption(i18n("Reading DTM Data") );
388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 388 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
389 status.show(); 389 status.show();
390 status.raise(); 390 status.raise();
391 qApp->processEvents(); 391 qApp->processEvents();
392 QString fileName; 392 QString fileName;
393 if ( ! debug ) { 393 if ( ! debug ) {
394 fileName = "/tmp/kopitempout"; 394 fileName = "/tmp/kopitempout";
395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 395 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
396 system ( command.latin1() ); 396 system ( command.latin1() );
397 } else { 397 } else {
398 fileName = "/tmp/events.txt"; 398 fileName = "/tmp/events.txt";
399 399
400 } 400 }
401 QFile file( fileName ); 401 QFile file( fileName );
402 if (!file.open( IO_ReadOnly ) ) { 402 if (!file.open( IO_ReadOnly ) ) {
403 return false; 403 return false;
404 404
405 } 405 }
406 QTextStream ts( &file ); 406 QTextStream ts( &file );
407 ts.setCodec( QTextCodec::codecForName("utf8") ); 407 ts.setCodec( QTextCodec::codecForName("utf8") );
408 text = ts.read(); 408 text = ts.read();
409 file.close(); 409 file.close();
410 status.setText( i18n("Processing events ...") ); 410 status.setText( i18n("Processing events ...") );
411 status.raise(); 411 status.raise();
412 qApp->processEvents(); 412 qApp->processEvents();
413 fromString2Cal( calendar, existngCal, text, "Event" ); 413 fromString2Cal( calendar, existngCal, text, "Event" );
414 status.setText( i18n("Reading todos ...") ); 414 status.setText( i18n("Reading todos ...") );
415 qApp->processEvents(); 415 qApp->processEvents();
416 if ( ! debug ) { 416 if ( ! debug ) {
417 fileName = "/tmp/kopitempout"; 417 fileName = "/tmp/kopitempout";
418 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 418 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
419 system ( command.latin1() ); 419 system ( command.latin1() );
420 } else { 420 } else {
421 fileName = "/tmp/todo.txt"; 421 fileName = "/tmp/todo.txt";
422 } 422 }
423 file.setName( fileName ); 423 file.setName( fileName );
424 if (!file.open( IO_ReadOnly ) ) { 424 if (!file.open( IO_ReadOnly ) ) {
425 return false; 425 return false;
426 426
427 } 427 }
428 ts.setDevice( &file ); 428 ts.setDevice( &file );
429 text = ts.read(); 429 text = ts.read();
430 file.close(); 430 file.close();
431 431
432 status.setText( i18n("Processing todos ...") ); 432 status.setText( i18n("Processing todos ...") );
433 status.raise(); 433 status.raise();
434 qApp->processEvents(); 434 qApp->processEvents();
435 fromString2Cal( calendar, existngCal, text, "Todo" ); 435 fromString2Cal( calendar, existngCal, text, "Todo" );
436 return true; 436 return true;
437} 437}
438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 438int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
439{ 439{
440 int retval = -1; 440 int retval = -1;
441 QStringList templist; 441 QStringList templist;
442 QString tempString; 442 QString tempString;
443 int start = 0; 443 int start = 0;
444 int len = answer.length(); 444 int len = answer.length();
445 int end = answer.find ("\n",start)+1; 445 int end = answer.find ("\n",start)+1;
446 bool ok = true; 446 bool ok = true;
447 start = end; 447 start = end;
448 int ccc = 0; 448 int ccc = 0;
449 while ( start > 0 ) { 449 while ( start > 0 ) {
450 templist.clear(); 450 templist.clear();
451 ok = true; 451 ok = true;
452 int loopCount = 0; 452 int loopCount = 0;
453 while ( ok ) { 453 while ( ok ) {
454 ++loopCount; 454 ++loopCount;
455 if ( loopCount > 25 ) { 455 if ( loopCount > 25 ) {
456 qDebug("KO: Error in while loop"); 456 qDebug("KO: Error in while loop");
457 ok = false; 457 ok = false;
458 start = 0; 458 start = 0;
459 break; 459 break;
460 } 460 }
461 if ( ok ) 461 if ( ok )
462 tempString = getPart( answer, ok, start ); 462 tempString = getPart( answer, ok, start );
463 if ( start >= len || start == 0 ) { 463 if ( start >= len || start == 0 ) {
464 start = 0; 464 start = 0;
465 ok = false; 465 ok = false;
466 } 466 }
467 if ( tempString.right(1) =="\n" ) 467 if ( tempString.right(1) =="\n" )
468 tempString = tempString.left( tempString.length()-1); 468 tempString = tempString.left( tempString.length()-1);
469 469
470 templist.append( tempString ); 470 templist.append( tempString );
471 } 471 }
472 ++ccc; 472 ++ccc;
473 if ( ccc == 2 && loopCount < 25 ) { 473 if ( ccc == 2 && loopCount < 25 ) {
474 start = 0; 474 start = 0;
475 bool ok; 475 bool ok;
476 int newnum = templist[0].toInt( &ok ); 476 int newnum = templist[0].toInt( &ok );
477 if ( ok && newnum > 0) { 477 if ( ok && newnum > 0) {
478 retval = newnum; 478 retval = newnum;
479 inc->setID( "Sharp_DTM",templist[0] ); 479 inc->setID( "Sharp_DTM",templist[0] );
480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 480 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 481 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
482 } 482 }
483 } 483 }
484 } 484 }
485 //qDebug("getNumFromRecord returning : %d ", retval); 485 //qDebug("getNumFromRecord returning : %d ", retval);
486 return retval; 486 return retval;
487} 487}
488bool SharpFormat::save( Calendar *calendar) 488bool SharpFormat::save( Calendar *calendar)
489{ 489{
490 490
491 QLabel status ( i18n("Processing/adding events ..."), 0 ); 491 QLabel status ( i18n("Processing/adding events ..."), 0 );
492 int w = status.sizeHint().width()+20 ; 492 int w = status.sizeHint().width()+20 ;
493 if ( w < 200 ) w = 200; 493 if ( w < 200 ) w = 200;
494 int h = status.sizeHint().height()+20 ; 494 int h = status.sizeHint().height()+20 ;
495 int dw = QApplication::desktop()->width(); 495 int dw = QApplication::desktop()->width();
496 int dh = QApplication::desktop()->height(); 496 int dh = QApplication::desktop()->height();
497 status.setCaption(i18n("Writing DTM Data") ); 497 status.setCaption(i18n("Writing DTM Data") );
498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 498 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
499 status.show(); 499 status.show();
500 status.raise(); 500 status.raise();
501 qApp->processEvents(); 501 qApp->processEvents();
502 bool debug = DEBUGMODE; 502 bool debug = DEBUGMODE;
503 QString codec = "utf8"; 503 QString codec = "utf8";
504 QString answer; 504 QString answer;
505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 505 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 506 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
507 QString command; 507 QString command;
508 QPtrList<Event> er = calendar->rawEvents(); 508 QPtrList<Event> er = calendar->rawEvents();
509 Event* ev = er.first(); 509 Event* ev = er.first();
510 QString fileName = "/tmp/kdepimtempfile"; 510 QString fileName = "/tmp/kopitempout";
511 int i = 0; 511 int i = 0;
512 QString changeString = ePrefix; 512 QString changeString = ePrefix;
513 QString deleteString = ePrefix; 513 QString deleteString = ePrefix;
514 bool deleteEnt = false; 514 bool deleteEnt = false;
515 bool changeEnt = false; 515 bool changeEnt = false;
516 QString message = i18n("Processing event # "); 516 QString message = i18n("Processing event # ");
517 int procCount = 0; 517 int procCount = 0;
518 while ( ev ) { 518 while ( ev ) {
519 //qDebug("i %d ", ++i); 519 //qDebug("i %d ", ++i);
520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 520 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
521 status.setText ( message + QString::number ( ++procCount ) ); 521 status.setText ( message + QString::number ( ++procCount ) );
522 qApp->processEvents(); 522 qApp->processEvents();
523 QString eString = getEventString( ev ); 523 QString eString = getEventString( ev );
524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 524 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
525 // deleting empty strings does not work. 525 // deleting empty strings does not work.
526 // we write first and x and then delete the record with the x 526 // we write first and x and then delete the record with the x
527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 527 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
528 changeString += eString + "\n"; 528 changeString += eString + "\n";
529 deleteString += eString + "\n"; 529 deleteString += eString + "\n";
530 deleteEnt = true; 530 deleteEnt = true;
531 changeEnt = true; 531 changeEnt = true;
532 } 532 }
533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 533 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 534 command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
535 system ( command.utf8() ); 535 system ( command.utf8() );
536 QFile file( fileName ); 536 QFile file( fileName );
537 if (!file.open( IO_ReadOnly ) ) { 537 if (!file.open( IO_ReadOnly ) ) {
538 return false; 538 return false;
539 539
540 } 540 }
541 QTextStream ts( &file ); 541 QTextStream ts( &file );
542 ts.setCodec( QTextCodec::codecForName("utf8") ); 542 ts.setCodec( QTextCodec::codecForName("utf8") );
543 answer = ts.read(); 543 answer = ts.read();
544 file.close(); 544 file.close();
545 //qDebug("answer \n%s ", answer.latin1()); 545 //qDebug("answer \n%s ", answer.latin1());
546 getNumFromRecord( answer, ev ) ; 546 getNumFromRecord( answer, ev ) ;
547 547
548 } 548 }
549 else { // change existing 549 else { // change existing
550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 550 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 551 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
552 changeString += eString + "\n"; 552 changeString += eString + "\n";
553 changeEnt = true; 553 changeEnt = true;
554 554
555 } 555 }
556 } 556 }
557 ev = er.next(); 557 ev = er.next();
558 } 558 }
559 status.setText ( i18n("Changing events ...") ); 559 status.setText ( i18n("Changing events ...") );
560 qApp->processEvents(); 560 qApp->processEvents();
561 //qDebug("changing... "); 561 //qDebug("changing... ");
562 if ( changeEnt ) { 562 if ( changeEnt ) {
563 QFile file( fileName ); 563 QFile file( fileName );
564 if (!file.open( IO_WriteOnly ) ) { 564 if (!file.open( IO_WriteOnly ) ) {
565 return false; 565 return false;
566 566
567 } 567 }
568 QTextStream ts( &file ); 568 QTextStream ts( &file );
569 ts.setCodec( QTextCodec::codecForName("utf8") ); 569 ts.setCodec( QTextCodec::codecForName("utf8") );
570 ts << changeString ; 570 ts << changeString ;
571 file.close(); 571 file.close();
572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 572 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
573 system ( command.latin1() ); 573 system ( command.latin1() );
574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 574 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
575 575
576 } 576 }
577 status.setText ( i18n("Deleting events ...") ); 577 status.setText ( i18n("Deleting events ...") );
578 qApp->processEvents(); 578 qApp->processEvents();
579 //qDebug("deleting... "); 579 //qDebug("deleting... ");
580 if ( deleteEnt ) { 580 if ( deleteEnt ) {
581 QFile file( fileName ); 581 QFile file( fileName );
582 if (!file.open( IO_WriteOnly ) ) { 582 if (!file.open( IO_WriteOnly ) ) {
583 return false; 583 return false;
584 584
585 } 585 }
586 QTextStream ts( &file ); 586 QTextStream ts( &file );
587 ts.setCodec( QTextCodec::codecForName("utf8") ); 587 ts.setCodec( QTextCodec::codecForName("utf8") );
588 ts << deleteString; 588 ts << deleteString;
589 file.close(); 589 file.close();
590 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 590 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
591 system ( command.latin1() ); 591 system ( command.latin1() );
592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 592 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
593 } 593 }
594 594
595 595
596 changeString = tPrefix; 596 changeString = tPrefix;
597 deleteString = tPrefix; 597 deleteString = tPrefix;
598 status.setText ( i18n("Processing todos ...") ); 598 status.setText ( i18n("Processing todos ...") );
599 qApp->processEvents(); 599 qApp->processEvents();
600 QPtrList<Todo> tl = calendar->rawTodos(); 600 QPtrList<Todo> tl = calendar->rawTodos();
601 Todo* to = tl.first(); 601 Todo* to = tl.first();
602 i = 0; 602 i = 0;
603 message = i18n("Processing todo # "); 603 message = i18n("Processing todo # ");
604 procCount = 0; 604 procCount = 0;
605 while ( to ) { 605 while ( to ) {
606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 606 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
607 status.setText ( message + QString::number ( ++procCount ) ); 607 status.setText ( message + QString::number ( ++procCount ) );
608 qApp->processEvents(); 608 qApp->processEvents();
609 QString eString = getTodoString( to ); 609 QString eString = getTodoString( to );
610 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 610 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
611 // deleting empty strings does not work. 611 // deleting empty strings does not work.
612 // we write first and x and then delete the record with the x 612 // we write first and x and then delete the record with the x
613 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 613 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
614 changeString += eString + "\n"; 614 changeString += eString + "\n";
615 deleteString += eString + "\n"; 615 deleteString += eString + "\n";
616 deleteEnt = true; 616 deleteEnt = true;
617 changeEnt = true; 617 changeEnt = true;
618 } 618 }
619 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 619 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
620 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 620 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName;
621 system ( command.utf8() ); 621 system ( command.utf8() );
622 QFile file( fileName ); 622 QFile file( fileName );
623 if (!file.open( IO_ReadOnly ) ) { 623 if (!file.open( IO_ReadOnly ) ) {
624 return false; 624 return false;
625 625
626 } 626 }
627 QTextStream ts( &file ); 627 QTextStream ts( &file );
628 ts.setCodec( QTextCodec::codecForName("utf8") ); 628 ts.setCodec( QTextCodec::codecForName("utf8") );
629 answer = ts.read(); 629 answer = ts.read();
630 file.close(); 630 file.close();
631 //qDebug("answer \n%s ", answer.latin1()); 631 //qDebug("answer \n%s ", answer.latin1());
632 getNumFromRecord( answer, to ) ; 632 getNumFromRecord( answer, to ) ;
633 633
634 } 634 }
635 else { // change existing 635 else { // change existing
636 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 636 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
637 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 637 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
638 changeString += eString + "\n"; 638 changeString += eString + "\n";
639 changeEnt = true; 639 changeEnt = true;
640 640
641 } 641 }
642 } 642 }
643 643
644 to = tl.next(); 644 to = tl.next();
645 } 645 }
646 status.setText ( i18n("Changing todos ...") ); 646 status.setText ( i18n("Changing todos ...") );
647 qApp->processEvents(); 647 qApp->processEvents();
648 //qDebug("changing... "); 648 //qDebug("changing... ");
649 if ( changeEnt ) { 649 if ( changeEnt ) {
650 QFile file( fileName ); 650 QFile file( fileName );
651 if (!file.open( IO_WriteOnly ) ) { 651 if (!file.open( IO_WriteOnly ) ) {
652 return false; 652 return false;
653 653
654 } 654 }
655 QTextStream ts( &file ); 655 QTextStream ts( &file );
656 ts.setCodec( QTextCodec::codecForName("utf8") ); 656 ts.setCodec( QTextCodec::codecForName("utf8") );
657 ts << changeString ; 657 ts << changeString ;
658 file.close(); 658 file.close();
659 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 659 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
660 system ( command.latin1() ); 660 system ( command.latin1() );
661 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 661 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
662 662
663 } 663 }
664 status.setText ( i18n("Deleting todos ...") ); 664 status.setText ( i18n("Deleting todos ...") );
665 qApp->processEvents(); 665 qApp->processEvents();
666 //qDebug("deleting... "); 666 //qDebug("deleting... ");
667 if ( deleteEnt ) { 667 if ( deleteEnt ) {
668 QFile file( fileName ); 668 QFile file( fileName );
669 if (!file.open( IO_WriteOnly ) ) { 669 if (!file.open( IO_WriteOnly ) ) {
670 return false; 670 return false;
671 671
672 } 672 }
673 QTextStream ts( &file ); 673 QTextStream ts( &file );
674 ts.setCodec( QTextCodec::codecForName("utf8") ); 674 ts.setCodec( QTextCodec::codecForName("utf8") );
675 ts << deleteString; 675 ts << deleteString;
676 file.close(); 676 file.close();
677 command = "db2file todo -d -c " + codec+ " < "+ fileName; 677 command = "db2file todo -d -c " + codec+ " < "+ fileName;
678 system ( command.latin1() ); 678 system ( command.latin1() );
679 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 679 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
680 } 680 }
681 681
682 return true; 682 return true;
683} 683}
684QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 684QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
685{ 685{
686 QString datestr; 686 QString datestr;
687 QString timestr; 687 QString timestr;
688 int offset = KGlobal::locale()->localTimeOffset( dti ); 688 int offset = KGlobal::locale()->localTimeOffset( dti );
689 QDateTime dt; 689 QDateTime dt;
690 if (useTZ) 690 if (useTZ)
691 dt = dti.addSecs ( -(offset*60)); 691 dt = dti.addSecs ( -(offset*60));
692 else 692 else
693 dt = dti; 693 dt = dti;
694 if(dt.date().isValid()){ 694 if(dt.date().isValid()){
695 const QDate& date = dt.date(); 695 const QDate& date = dt.date();
696 datestr.sprintf("%04d%02d%02d", 696 datestr.sprintf("%04d%02d%02d",
697 date.year(), date.month(), date.day()); 697 date.year(), date.month(), date.day());
698 } 698 }
699 if(dt.time().isValid()){ 699 if(dt.time().isValid()){
700 const QTime& time = dt.time(); 700 const QTime& time = dt.time();
701 timestr.sprintf("T%02d%02d%02d", 701 timestr.sprintf("T%02d%02d%02d",
702 time.hour(), time.minute(), time.second()); 702 time.hour(), time.minute(), time.second());
703 } 703 }
704 return datestr + timestr; 704 return datestr + timestr;
705} 705}
706QString SharpFormat::getEventString( Event* event ) 706QString SharpFormat::getEventString( Event* event )
707{ 707{
708 QStringList list; 708 QStringList list;
709 list.append( event->getID("Sharp_DTM") ); 709 list.append( event->getID("Sharp_DTM") );
710 list.append( event->categories().join(",") ); 710 list.append( event->categories().join(",") );
711 if ( !event->summary().isEmpty() ) 711 if ( !event->summary().isEmpty() )
712 list.append( event->summary() ); 712 list.append( event->summary() );
713 else 713 else
714 list.append("" ); 714 list.append("" );
715 if ( !event->location().isEmpty() ) 715 if ( !event->location().isEmpty() )
716 list.append( event->location() ); 716 list.append( event->location() );
717 else 717 else
718 list.append("" ); 718 list.append("" );
719 if ( !event->description().isEmpty() ) 719 if ( !event->description().isEmpty() )
720 list.append( event->description() ); 720 list.append( event->description() );
721 else 721 else
722 list.append( "" ); 722 list.append( "" );
723 if ( event->doesFloat () ) { 723 if ( event->doesFloat () ) {
724 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 724 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
725 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 725 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
726 list.append( "1" ); 726 list.append( "1" );
727 727
728 } 728 }
729 else { 729 else {
730 list.append( dtToString( event->dtStart()) ); 730 list.append( dtToString( event->dtStart()) );
731 list.append( dtToString( event->dtEnd()) ); //6 731 list.append( dtToString( event->dtEnd()) ); //6
732 list.append( "0" ); 732 list.append( "0" );
733 } 733 }
734 bool noAlarm = true; 734 bool noAlarm = true;
735 if ( event->alarms().count() > 0 ) { 735 if ( event->alarms().count() > 0 ) {
736 Alarm * al = event->alarms().first(); 736 Alarm * al = event->alarms().first();
737 if ( al->enabled() ) { 737 if ( al->enabled() ) {
738 noAlarm = false; 738 noAlarm = false;
739 list.append( "0" ); // yes, 0 == alarm 739 list.append( "0" ); // yes, 0 == alarm
740 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 740 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
741 if ( al->type() == Alarm::Audio ) 741 if ( al->type() == Alarm::Audio )
742 list.append( "1" ); // type audio 742 list.append( "1" ); // type audio
743 else 743 else
744 list.append( "0" ); // type silent 744 list.append( "0" ); // type silent
745 } 745 }
746 } 746 }
747 if ( noAlarm ) { 747 if ( noAlarm ) {
748 list.append( "1" ); // yes, 1 == no alarm 748 list.append( "1" ); // yes, 1 == no alarm
749 list.append( "0" ); // no alarm offset 749 list.append( "0" ); // no alarm offset
750 list.append( "1" ); // type 750 list.append( "1" ); // type
751 } 751 }
752 // next is: 11 752 // next is: 11
753 // next is: 11-16 are recurrence 753 // next is: 11-16 are recurrence
754 Recurrence* rec = event->recurrence(); 754 Recurrence* rec = event->recurrence();
755 755
756 bool writeEndDate = false; 756 bool writeEndDate = false;
757 switch ( rec->doesRecur() ) 757 switch ( rec->doesRecur() )
758 { 758 {
759 case Recurrence::rDaily: // 0 759 case Recurrence::rDaily: // 0
760 list.append( "0" ); 760 list.append( "0" );
761 list.append( QString::number( rec->frequency() ));//12 761 list.append( QString::number( rec->frequency() ));//12
762 list.append( "0" ); 762 list.append( "0" );
763 list.append( "0" ); 763 list.append( "0" );
764 writeEndDate = true; 764 writeEndDate = true;
765 break; 765 break;
766 case Recurrence::rWeekly:// 1 766 case Recurrence::rWeekly:// 1
767 list.append( "1" ); 767 list.append( "1" );
768 list.append( QString::number( rec->frequency()) );//12 768 list.append( QString::number( rec->frequency()) );//12
769 list.append( "0" ); 769 list.append( "0" );
770 { 770 {
771 int days = 0; 771 int days = 0;
772 QBitArray weekDays = rec->days(); 772 QBitArray weekDays = rec->days();
773 int i; 773 int i;
774 for( i = 1; i <= 7; ++i ) { 774 for( i = 1; i <= 7; ++i ) {
775 if ( weekDays[i-1] ) { 775 if ( weekDays[i-1] ) {
776 days += 1 << (i-1); 776 days += 1 << (i-1);
777 } 777 }
778 } 778 }
779 list.append( QString::number( days ) ); 779 list.append( QString::number( days ) );
780 } 780 }
781 //pending weekdays 781 //pending weekdays
782 writeEndDate = true; 782 writeEndDate = true;
783 783
784 break; 784 break;
785 case Recurrence::rMonthlyPos:// 2 785 case Recurrence::rMonthlyPos:// 2
786 list.append( "2" ); 786 list.append( "2" );
787 list.append( QString::number( rec->frequency()) );//12 787 list.append( QString::number( rec->frequency()) );//12
788 788
789 writeEndDate = true; 789 writeEndDate = true;
790 { 790 {
791 int count = 1; 791 int count = 1;
792 QPtrList<Recurrence::rMonthPos> rmp; 792 QPtrList<Recurrence::rMonthPos> rmp;
793 rmp = rec->monthPositions(); 793 rmp = rec->monthPositions();
794 if ( rmp.first()->negative ) 794 if ( rmp.first()->negative )
795 count = 5 - rmp.first()->rPos - 1; 795 count = 5 - rmp.first()->rPos - 1;
796 else 796 else
797 count = rmp.first()->rPos - 1; 797 count = rmp.first()->rPos - 1;
798 list.append( QString::number( count ) ); 798 list.append( QString::number( count ) );
799 799
800 } 800 }
801 801
802 list.append( "0" ); 802 list.append( "0" );
803 break; 803 break;
804 case Recurrence::rMonthlyDay:// 3 804 case Recurrence::rMonthlyDay:// 3
805 list.append( "3" ); 805 list.append( "3" );
806 list.append( QString::number( rec->frequency()) );//12 806 list.append( QString::number( rec->frequency()) );//12
807 list.append( "0" ); 807 list.append( "0" );
808 list.append( "0" ); 808 list.append( "0" );
809 writeEndDate = true; 809 writeEndDate = true;
810 break; 810 break;
811 case Recurrence::rYearlyMonth://4 811 case Recurrence::rYearlyMonth://4
812 list.append( "4" ); 812 list.append( "4" );
813 list.append( QString::number( rec->frequency()) );//12 813 list.append( QString::number( rec->frequency()) );//12
814 list.append( "0" ); 814 list.append( "0" );
815 list.append( "0" ); 815 list.append( "0" );
816 writeEndDate = true; 816 writeEndDate = true;
817 break; 817 break;
818 818
819 default: 819 default:
820 list.append( "255" ); 820 list.append( "255" );
821 list.append( QString() ); 821 list.append( QString() );
822 list.append( "0" ); 822 list.append( "0" );
823 list.append( QString() ); 823 list.append( QString() );
824 list.append( "0" ); 824 list.append( "0" );
825 list.append( "20991231T000000" ); 825 list.append( "20991231T000000" );
826 break; 826 break;
827 } 827 }
828 if ( writeEndDate ) { 828 if ( writeEndDate ) {
829 829
830 if ( rec->endDate().isValid() ) { // 15 + 16 830 if ( rec->endDate().isValid() ) { // 15 + 16
831 list.append( "1" ); 831 list.append( "1" );
832 list.append( dtToString( rec->endDate()) ); 832 list.append( dtToString( rec->endDate()) );
833 } else { 833 } else {
834 list.append( "0" ); 834 list.append( "0" );
835 list.append( "20991231T000000" ); 835 list.append( "20991231T000000" );
836 } 836 }
837 837
838 } 838 }
839 if ( event->doesFloat () ) { 839 if ( event->doesFloat () ) {
840 list.append( dtToString( event->dtStart(), false ).left( 8 )); 840 list.append( dtToString( event->dtStart(), false ).left( 8 ));
841 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 841 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
842 842
843 } 843 }
844 else { 844 else {
845 list.append( QString() ); 845 list.append( QString() );
846 list.append( QString() ); 846 list.append( QString() );
847 847
848 } 848 }
849 if (event->dtStart().date() == event->dtEnd().date() ) 849 if (event->dtStart().date() == event->dtEnd().date() )
850 list.append( "0" ); 850 list.append( "0" );
851 else 851 else
852 list.append( "1" ); 852 list.append( "1" );
853 853
854 854
855 for(QStringList::Iterator it=list.begin(); 855 for(QStringList::Iterator it=list.begin();
856 it!=list.end(); ++it){ 856 it!=list.end(); ++it){
857 QString& s = (*it); 857 QString& s = (*it);
858 s.replace(QRegExp("\""), "\"\""); 858 s.replace(QRegExp("\""), "\"\"");
859 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 859 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
860 s.prepend('\"'); 860 s.prepend('\"');
861 s.append('\"'); 861 s.append('\"');
862 } else if(s.isEmpty() && !s.isNull()){ 862 } else if(s.isEmpty() && !s.isNull()){
863 s = "\"\""; 863 s = "\"\"";
864 } 864 }
865 } 865 }
866 return list.join(","); 866 return list.join(",");
867 867
868 868
869} 869}
870QString SharpFormat::getTodoString( Todo* todo ) 870QString SharpFormat::getTodoString( Todo* todo )
871{ 871{
872 QStringList list; 872 QStringList list;
873 list.append( todo->getID("Sharp_DTM") ); 873 list.append( todo->getID("Sharp_DTM") );
874 list.append( todo->categories().join(",") ); 874 list.append( todo->categories().join(",") );
875 875
876 if ( todo->hasStartDate() ) { 876 if ( todo->hasStartDate() ) {
877 list.append( dtToString( todo->dtStart()) ); 877 list.append( dtToString( todo->dtStart()) );
878 } else 878 } else
879 list.append( QString() ); 879 list.append( QString() );
880 880
881 if ( todo->hasDueDate() ) { 881 if ( todo->hasDueDate() ) {
882 QTime tim; 882 QTime tim;
883 if ( todo->doesFloat()) { 883 if ( todo->doesFloat()) {
884 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 884 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
885 } else { 885 } else {
886 list.append( dtToString(todo->dtDue() ) ); 886 list.append( dtToString(todo->dtDue() ) );
887 } 887 }
888 } else 888 } else
889 list.append( QString() ); 889 list.append( QString() );
890 890
891 if ( todo->isCompleted() ) { 891 if ( todo->isCompleted() ) {
892 list.append( dtToString( todo->completed()) ); 892 list.append( dtToString( todo->completed()) );
893 list.append( "0" ); // yes 0 == completed 893 list.append( "0" ); // yes 0 == completed
894 } else { 894 } else {