summaryrefslogtreecommitdiffabout
path: root/libkcal/sharpformat.cpp
Unidiff
Diffstat (limited to 'libkcal/sharpformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp48
1 files changed, 24 insertions, 24 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 9b757f7..b8c2aa7 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,126 +1,126 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 3
4 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2003 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#include <qdatetime.h> 22#include <qdatetime.h>
23#include <qstring.h> 23#include <qstring.h>
24#include <qapplication.h> 24#include <qapplication.h>
25#include <qptrlist.h> 25#include <q3ptrlist.h>
26#include <qregexp.h> 26#include <qregexp.h>
27#include <qmessagebox.h> 27#include <qmessagebox.h>
28#include <qclipboard.h> 28#include <qclipboard.h>
29#include <qfile.h> 29#include <qfile.h>
30#include <qtextstream.h> 30#include <q3textstream.h>
31#include <qtextcodec.h> 31#include <qtextcodec.h>
32#include <qxml.h> 32#include <qxml.h>
33#include <qlabel.h> 33#include <qlabel.h>
34 34
35#include <kdebug.h> 35#include <kdebug.h>
36#include <klocale.h> 36#include <klocale.h>
37#include <kglobal.h> 37#include <kglobal.h>
38 38
39#include "calendar.h" 39#include "calendar.h"
40#include "alarm.h" 40#include "alarm.h"
41#include "recurrence.h" 41#include "recurrence.h"
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "sharpformat.h" 44#include "sharpformat.h"
45#include "syncdefines.h" 45#include "syncdefines.h"
46 46
47using namespace KCal; 47using namespace KCal;
48 48
49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY 49//CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY
50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 50// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
51 51
52//ARSD silentalarm = 0 52//ARSD silentalarm = 0
53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly 53// 11 RTYP 225 no /0 dialy/ 1 weekly/ 3 month by date/ 2 month by day(pos)/ yearly
54// 12 RFRQ 54// 12 RFRQ
55// 13 RPOS pos = 4. monday in month 55// 13 RPOS pos = 4. monday in month
56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun 56// 14 RDYS days: 1 mon/ 2 tue .. 64 sun
57// 15 REND 0 = no end/ 1 = end 57// 15 REND 0 = no end/ 1 = end
58// 16 REDT rec end dt 58// 16 REDT rec end dt
59//ALSD 59//ALSD
60//ALED 60//ALED
61//MDAY 61//MDAY
62 62
63class SharpParser : public QObject 63class SharpParser : public QObject
64{ 64{
65 public: 65 public:
66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) { 66 SharpParser( Calendar *calendar ) : mCalendar( calendar ) {
67 } 67 }
68 68
69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
70 { 70 {
71 int i = 1; 71 int i = 1;
72 bool skip = true; 72 bool skip = true;
73 int max = attList.count() -2; 73 int max = attList.count() -2;
74 while ( i < max ) { 74 while ( i < max ) {
75 if ( !attList[i].isEmpty() ) { 75 if ( !attList[i].isEmpty() ) {
76 skip = false; 76 skip = false;
77 break; 77 break;
78 } 78 }
79 ++i ; 79 ++i ;
80 } 80 }
81 if ( skip ) 81 if ( skip )
82 return false; 82 return false;
83 ulong cSum = SharpFormat::getCsum(attList ); 83 ulong cSum = SharpFormat::getCsum(attList );
84 84
85 if ( qName == "Event" ) { 85 if ( qName == "Event" ) {
86 Event *event; 86 Event *event;
87 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 87 event = existingCalendar->event( "Sharp_DTM",attList[0] );
88 if ( event ) 88 if ( event )
89 event = (Event*)event->clone(); 89 event = (Event*)event->clone();
90 else 90 else
91 event = new Event; 91 event = new Event;
92 event->setID("Sharp_DTM", attList[0] ); 92 event->setID("Sharp_DTM", attList[0] );
93 event->setCsum( "Sharp_DTM", QString::number( cSum )); 93 event->setCsum( "Sharp_DTM", QString::number( cSum ));
94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
95 95
96 event->setSummary( attList[2] ); 96 event->setSummary( attList[2] );
97 event->setLocation( attList[3] ); 97 event->setLocation( attList[3] );
98 event->setDescription( attList[4] ); 98 event->setDescription( attList[4] );
99 if ( attList[7] == "1" ) { 99 if ( attList[7] == "1" ) {
100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
102 event->setFloats( true ); 102 event->setFloats( true );
103 } else { 103 } else {
104 event->setFloats( false ); 104 event->setFloats( false );
105 event->setDtStart( fromString( attList[5] ) ); 105 event->setDtStart( fromString( attList[5] ) );
106 event->setDtEnd( fromString( attList[6] )); 106 event->setDtEnd( fromString( attList[6] ));
107 } 107 }
108 108
109 QString rtype = attList[11]; 109 QString rtype = attList[11];
110 if ( rtype != "255" ) { 110 if ( rtype != "255" ) {
111 // qDebug("recurs "); 111 // qDebug("recurs ");
112 QDate startDate = event->dtStart().date(); 112 QDate startDate = event->dtStart().date();
113 113
114 QString freqStr = attList[12]; 114 QString freqStr = attList[12];
115 int freq = freqStr.toInt(); 115 int freq = freqStr.toInt();
116 116
117 QString hasEndDateStr = attList[15] ; 117 QString hasEndDateStr = attList[15] ;
118 bool hasEndDate = hasEndDateStr == "1"; 118 bool hasEndDate = hasEndDateStr == "1";
119 119
120 QString endDateStr = attList[16]; 120 QString endDateStr = attList[16];
121 QDate endDate = fromString( endDateStr ).date(); 121 QDate endDate = fromString( endDateStr ).date();
122 122
123 QString weekDaysStr = attList[14]; 123 QString weekDaysStr = attList[14];
124 uint weekDaysNum = weekDaysStr.toInt(); 124 uint weekDaysNum = weekDaysStr.toInt();
125 125
126 QBitArray weekDays( 7 ); 126 QBitArray weekDays( 7 );
@@ -273,610 +273,610 @@ class SharpParser : public QObject
273 } 273 }
274 274
275 275
276 QDateTime fromString ( QString s, bool useTz = true ) { 276 QDateTime fromString ( QString s, bool useTz = true ) {
277 QDateTime dt; 277 QDateTime dt;
278 int y,m,t,h,min,sec; 278 int y,m,t,h,min,sec;
279 y = s.mid(0,4).toInt(); 279 y = s.mid(0,4).toInt();
280 m = s.mid(4,2).toInt(); 280 m = s.mid(4,2).toInt();
281 t = s.mid(6,2).toInt(); 281 t = s.mid(6,2).toInt();
282 h = s.mid(9,2).toInt(); 282 h = s.mid(9,2).toInt();
283 min = s.mid(11,2).toInt(); 283 min = s.mid(11,2).toInt();
284 sec = s.mid(13,2).toInt(); 284 sec = s.mid(13,2).toInt();
285 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 285 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
286 int offset = KGlobal::locale()->localTimeOffset( dt ); 286 int offset = KGlobal::locale()->localTimeOffset( dt );
287 if ( useTz ) 287 if ( useTz )
288 dt = dt.addSecs ( offset*60); 288 dt = dt.addSecs ( offset*60);
289 return dt; 289 return dt;
290 290
291 } 291 }
292 protected: 292 protected:
293 QDateTime toDateTime( const QString &value ) 293 QDateTime toDateTime( const QString &value )
294 { 294 {
295 QDateTime dt; 295 QDateTime dt;
296 dt.setTime_t( value.toUInt() ); 296 dt.setTime_t( value.toUInt() );
297 297
298 return dt; 298 return dt;
299 } 299 }
300 300
301 private: 301 private:
302 Calendar *mCalendar; 302 Calendar *mCalendar;
303}; 303};
304 304
305 305
306SharpFormat::SharpFormat() 306SharpFormat::SharpFormat()
307{ 307{
308 308
309} 309}
310 310
311SharpFormat::~SharpFormat() 311SharpFormat::~SharpFormat()
312{ 312{
313} 313}
314ulong SharpFormat::getCsum( const QStringList & attList) 314ulong SharpFormat::getCsum( const QStringList & attList)
315{ 315{
316 int max = attList.count() -1; 316 int max = attList.count() -1;
317 ulong cSum = 0; 317 ulong cSum = 0;
318 int j,k,i; 318 int j,k,i;
319 int add; 319 int add;
320 for ( i = 1; i < max ; ++i ) { 320 for ( i = 1; i < max ; ++i ) {
321 QString s = attList[i]; 321 QString s = attList[i];
322 if ( ! s.isEmpty() ){ 322 if ( ! s.isEmpty() ){
323 j = s.length(); 323 j = s.length();
324 for ( k = 0; k < j; ++k ) { 324 for ( k = 0; k < j; ++k ) {
325 int mul = k +1; 325 int mul = k +1;
326 add = s[k].unicode (); 326 add = s[k].unicode ();
327 if ( k < 16 ) 327 if ( k < 16 )
328 mul = mul * mul; 328 mul = mul * mul;
329 add = add * mul *i*i*i; 329 add = add * mul *i*i*i;
330 cSum += add; 330 cSum += add;
331 } 331 }
332 } 332 }
333 } 333 }
334 return cSum; 334 return cSum;
335 335
336} 336}
337#include <stdlib.h> 337#include <stdlib.h>
338#define DEBUGMODE false 338#define DEBUGMODE false
339//#define DEBUGMODE true 339//#define DEBUGMODE true
340bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 340bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
341{ 341{
342 342
343 343
344 bool debug = DEBUGMODE; 344 bool debug = DEBUGMODE;
345 QString text; 345 QString text;
346 QString codec = "utf8"; 346 QString codec = "utf8";
347 QLabel status ( i18n("Reading events ..."), 0 ); 347 QLabel status ( i18n("Reading events ..."), 0 );
348 348
349 int w = status.sizeHint().width()+20 ; 349 int w = status.sizeHint().width()+20 ;
350 if ( w < 200 ) w = 200; 350 if ( w < 200 ) w = 200;
351 int h = status.sizeHint().height()+20 ; 351 int h = status.sizeHint().height()+20 ;
352 int dw = QApplication::desktop()->width(); 352 int dw = QApplication::desktop()->width();
353 int dh = QApplication::desktop()->height(); 353 int dh = QApplication::desktop()->height();
354 status.setCaption(i18n("Reading DTM Data") ); 354 status.setCaption(i18n("Reading DTM Data") );
355 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 355 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
356 status.show(); 356 status.show();
357 status.raise(); 357 status.raise();
358 qApp->processEvents(); 358 qApp->processEvents();
359 QString fileName; 359 QString fileName;
360 if ( ! debug ) { 360 if ( ! debug ) {
361 fileName = "/tmp/kopitempout"; 361 fileName = "/tmp/kopitempout";
362 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 362 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
363 system ( command.latin1() ); 363 system ( command.latin1() );
364 } else { 364 } else {
365 fileName = "/tmp/events.txt"; 365 fileName = "/tmp/events.txt";
366 366
367 } 367 }
368 QFile file( fileName ); 368 QFile file( fileName );
369 if (!file.open( IO_ReadOnly ) ) { 369 if (!file.open( QIODevice::ReadOnly ) ) {
370 return false; 370 return false;
371 371
372 } 372 }
373 QTextStream ts( &file ); 373 Q3TextStream ts( &file );
374 ts.setCodec( QTextCodec::codecForName("utf8") ); 374 ts.setCodec( QTextCodec::codecForName("utf8") );
375 text = ts.read(); 375 text = ts.read();
376 file.close(); 376 file.close();
377 status.setText( i18n("Processing events ...") ); 377 status.setText( i18n("Processing events ...") );
378 status.raise(); 378 status.raise();
379 qApp->processEvents(); 379 qApp->processEvents();
380 fromString2Cal( calendar, existngCal, text, "Event" ); 380 fromString2Cal( calendar, existngCal, text, "Event" );
381 status.setText( i18n("Reading todos ...") ); 381 status.setText( i18n("Reading todos ...") );
382 qApp->processEvents(); 382 qApp->processEvents();
383 if ( ! debug ) { 383 if ( ! debug ) {
384 fileName = "/tmp/kopitempout"; 384 fileName = "/tmp/kopitempout";
385 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 385 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
386 system ( command.latin1() ); 386 system ( command.latin1() );
387 } else { 387 } else {
388 fileName = "/tmp/todo.txt"; 388 fileName = "/tmp/todo.txt";
389 } 389 }
390 file.setName( fileName ); 390 file.setName( fileName );
391 if (!file.open( IO_ReadOnly ) ) { 391 if (!file.open( QIODevice::ReadOnly ) ) {
392 return false; 392 return false;
393 393
394 } 394 }
395 ts.setDevice( &file ); 395 ts.setDevice( &file );
396 text = ts.read(); 396 text = ts.read();
397 file.close(); 397 file.close();
398 398
399 status.setText( i18n("Processing todos ...") ); 399 status.setText( i18n("Processing todos ...") );
400 status.raise(); 400 status.raise();
401 qApp->processEvents(); 401 qApp->processEvents();
402 fromString2Cal( calendar, existngCal, text, "Todo" ); 402 fromString2Cal( calendar, existngCal, text, "Todo" );
403 return true; 403 return true;
404} 404}
405int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 405int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
406{ 406{
407 int retval = -1; 407 int retval = -1;
408 QStringList templist; 408 QStringList templist;
409 QString tempString; 409 QString tempString;
410 int start = 0; 410 int start = 0;
411 int len = answer.length(); 411 int len = answer.length();
412 int end = answer.find ("\n",start)+1; 412 int end = answer.find ("\n",start)+1;
413 bool ok = true; 413 bool ok = true;
414 start = end; 414 start = end;
415 int ccc = 0; 415 int ccc = 0;
416 while ( start > 0 ) { 416 while ( start > 0 ) {
417 templist.clear(); 417 templist.clear();
418 ok = true; 418 ok = true;
419 int loopCount = 0; 419 int loopCount = 0;
420 while ( ok ) { 420 while ( ok ) {
421 ++loopCount; 421 ++loopCount;
422 if ( loopCount > 25 ) { 422 if ( loopCount > 25 ) {
423 qDebug("KO: Error in while loop"); 423 qDebug("KO: Error in while loop");
424 ok = false; 424 ok = false;
425 start = 0; 425 start = 0;
426 break; 426 break;
427 } 427 }
428 if ( ok ) 428 if ( ok )
429 tempString = getPart( answer, ok, start ); 429 tempString = getPart( answer, ok, start );
430 if ( start >= len || start == 0 ) { 430 if ( start >= len || start == 0 ) {
431 start = 0; 431 start = 0;
432 ok = false; 432 ok = false;
433 } 433 }
434 if ( tempString.right(1) =="\n" ) 434 if ( tempString.right(1) =="\n" )
435 tempString = tempString.left( tempString.length()-1); 435 tempString = tempString.left( tempString.length()-1);
436 436
437 templist.append( tempString ); 437 templist.append( tempString );
438 } 438 }
439 ++ccc; 439 ++ccc;
440 if ( ccc == 2 && loopCount < 25 ) { 440 if ( ccc == 2 && loopCount < 25 ) {
441 start = 0; 441 start = 0;
442 bool ok; 442 bool ok;
443 int newnum = templist[0].toInt( &ok ); 443 int newnum = templist[0].toInt( &ok );
444 if ( ok && newnum > 0) { 444 if ( ok && newnum > 0) {
445 retval = newnum; 445 retval = newnum;
446 inc->setID( "Sharp_DTM",templist[0] ); 446 inc->setID( "Sharp_DTM",templist[0] );
447 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 447 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
448 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 448 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
449 } 449 }
450 if ( ok && newnum == -1 ) { 450 if ( ok && newnum == -1 ) {
451 qDebug("Error writing back %s ", inc->summary().latin1()); 451 qDebug("Error writing back %s ", inc->summary().latin1());
452 } 452 }
453 } 453 }
454 } 454 }
455 //qDebug("getNumFromRecord returning : %d ", retval); 455 //qDebug("getNumFromRecord returning : %d ", retval);
456 return retval; 456 return retval;
457} 457}
458bool SharpFormat::save( Calendar *calendar) 458bool SharpFormat::save( Calendar *calendar)
459{ 459{
460 460
461 QLabel status ( i18n("Processing/adding events ..."), 0 ); 461 QLabel status ( i18n("Processing/adding events ..."), 0 );
462 int w = status.sizeHint().width()+20 ; 462 int w = status.sizeHint().width()+20 ;
463 if ( w < 200 ) w = 200; 463 if ( w < 200 ) w = 200;
464 int h = status.sizeHint().height()+20 ; 464 int h = status.sizeHint().height()+20 ;
465 int dw = QApplication::desktop()->width(); 465 int dw = QApplication::desktop()->width();
466 int dh = QApplication::desktop()->height(); 466 int dh = QApplication::desktop()->height();
467 status.setCaption(i18n("Writing DTM Data") ); 467 status.setCaption(i18n("Writing DTM Data") );
468 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 468 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
469 status.show(); 469 status.show();
470 status.raise(); 470 status.raise();
471 qApp->processEvents(); 471 qApp->processEvents();
472 bool debug = DEBUGMODE; 472 bool debug = DEBUGMODE;
473 QString codec = "utf8"; 473 QString codec = "utf8";
474 QString answer; 474 QString answer;
475 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 475 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
476 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 476 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
477 QString command; 477 QString command;
478 QPtrList<Event> er = calendar->rawEvents(); 478 Q3PtrList<Event> er = calendar->rawEvents();
479 Event* ev = er.first(); 479 Event* ev = er.first();
480 QString fileName = "/tmp/kopitempout"; 480 QString fileName = "/tmp/kopitempout";
481 int i = 0; 481 int i = 0;
482 QString changeString = ePrefix; 482 QString changeString = ePrefix;
483 QString deleteString = ePrefix; 483 QString deleteString = ePrefix;
484 bool deleteEnt = false; 484 bool deleteEnt = false;
485 bool changeEnt = false; 485 bool changeEnt = false;
486 QString message = i18n("Processing event # "); 486 QString message = i18n("Processing event # ");
487 int procCount = 0; 487 int procCount = 0;
488 while ( ev ) { 488 while ( ev ) {
489 //qDebug("i %d ", ++i); 489 //qDebug("i %d ", ++i);
490 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 490 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
491 status.setText ( message + QString::number ( ++procCount ) ); 491 status.setText ( message + QString::number ( ++procCount ) );
492 qApp->processEvents(); 492 qApp->processEvents();
493 QString eString = getEventString( ev ); 493 QString eString = getEventString( ev );
494 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 494 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
495 // deleting empty strings does not work. 495 // deleting empty strings does not work.
496 // we write first and x and then delete the record with the x 496 // we write first and x and then delete the record with the x
497 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 497 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
498 changeString += eString + "\n"; 498 changeString += eString + "\n";
499 deleteString += eString + "\n"; 499 deleteString += eString + "\n";
500 deleteEnt = true; 500 deleteEnt = true;
501 changeEnt = true; 501 changeEnt = true;
502 } 502 }
503 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 503 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
504 QString fileNameIn = "/tmp/kopitempin"; 504 QString fileNameIn = "/tmp/kopitempin";
505 QFile fileIn( fileNameIn ); 505 QFile fileIn( fileNameIn );
506 if (!fileIn.open( IO_WriteOnly ) ) { 506 if (!fileIn.open( QIODevice::WriteOnly ) ) {
507 return false; 507 return false;
508 } 508 }
509 QTextStream tsIn( &fileIn ); 509 Q3TextStream tsIn( &fileIn );
510 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 510 tsIn.setCodec( QTextCodec::codecForName("utf8") );
511 tsIn << ePrefix << eString ; 511 tsIn << ePrefix << eString ;
512 fileIn.close(); 512 fileIn.close();
513 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 513 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
514 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; 514 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
515 //qDebug("command ++++++++ "); 515 //qDebug("command ++++++++ ");
516 //qDebug("%s ",command.latin1()); 516 //qDebug("%s ",command.latin1());
517 //qDebug("command -------- "); 517 //qDebug("command -------- ");
518 system ( command.utf8() ); 518 system ( command.utf8() );
519 QFile file( fileName ); 519 QFile file( fileName );
520 if (!file.open( IO_ReadOnly ) ) { 520 if (!file.open( QIODevice::ReadOnly ) ) {
521 return false; 521 return false;
522 522
523 } 523 }
524 QTextStream ts( &file ); 524 Q3TextStream ts( &file );
525 ts.setCodec( QTextCodec::codecForName("utf8") ); 525 ts.setCodec( QTextCodec::codecForName("utf8") );
526 answer = ts.read(); 526 answer = ts.read();
527 file.close(); 527 file.close();
528 //qDebug("answer \n%s ", answer.latin1()); 528 //qDebug("answer \n%s ", answer.latin1());
529 getNumFromRecord( answer, ev ) ; 529 getNumFromRecord( answer, ev ) ;
530 530
531 } 531 }
532 else { // change existing 532 else { // change existing
533 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 533 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
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 changeString += eString + "\n"; 535 changeString += eString + "\n";
536 changeEnt = true; 536 changeEnt = true;
537 537
538 } 538 }
539 } 539 }
540 ev = er.next(); 540 ev = er.next();
541 } 541 }
542 status.setText ( i18n("Changing events ...") ); 542 status.setText ( i18n("Changing events ...") );
543 qApp->processEvents(); 543 qApp->processEvents();
544 //qDebug("changing... "); 544 //qDebug("changing... ");
545 if ( changeEnt ) { 545 if ( changeEnt ) {
546 QFile file( fileName ); 546 QFile file( fileName );
547 if (!file.open( IO_WriteOnly ) ) { 547 if (!file.open( QIODevice::WriteOnly ) ) {
548 return false; 548 return false;
549 549
550 } 550 }
551 QTextStream ts( &file ); 551 Q3TextStream ts( &file );
552 ts.setCodec( QTextCodec::codecForName("utf8") ); 552 ts.setCodec( QTextCodec::codecForName("utf8") );
553 ts << changeString ; 553 ts << changeString ;
554 file.close(); 554 file.close();
555 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 555 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
556 system ( command.latin1() ); 556 system ( command.latin1() );
557 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 557 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
558 558
559 } 559 }
560 status.setText ( i18n("Deleting events ...") ); 560 status.setText ( i18n("Deleting events ...") );
561 qApp->processEvents(); 561 qApp->processEvents();
562 //qDebug("deleting... "); 562 //qDebug("deleting... ");
563 if ( deleteEnt ) { 563 if ( deleteEnt ) {
564 QFile file( fileName ); 564 QFile file( fileName );
565 if (!file.open( IO_WriteOnly ) ) { 565 if (!file.open( QIODevice::WriteOnly ) ) {
566 return false; 566 return false;
567 567
568 } 568 }
569 QTextStream ts( &file ); 569 Q3TextStream ts( &file );
570 ts.setCodec( QTextCodec::codecForName("utf8") ); 570 ts.setCodec( QTextCodec::codecForName("utf8") );
571 ts << deleteString; 571 ts << deleteString;
572 file.close(); 572 file.close();
573 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 573 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
574 system ( command.latin1() ); 574 system ( command.latin1() );
575 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 575 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
576 } 576 }
577 577
578 578
579 changeString = tPrefix; 579 changeString = tPrefix;
580 deleteString = tPrefix; 580 deleteString = tPrefix;
581 status.setText ( i18n("Processing todos ...") ); 581 status.setText ( i18n("Processing todos ...") );
582 qApp->processEvents(); 582 qApp->processEvents();
583 QPtrList<Todo> tl = calendar->rawTodos(); 583 Q3PtrList<Todo> tl = calendar->rawTodos();
584 Todo* to = tl.first(); 584 Todo* to = tl.first();
585 i = 0; 585 i = 0;
586 message = i18n("Processing todo # "); 586 message = i18n("Processing todo # ");
587 procCount = 0; 587 procCount = 0;
588 while ( to ) { 588 while ( to ) {
589 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 589 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
590 status.setText ( message + QString::number ( ++procCount ) ); 590 status.setText ( message + QString::number ( ++procCount ) );
591 qApp->processEvents(); 591 qApp->processEvents();
592 QString eString = getTodoString( to ); 592 QString eString = getTodoString( to );
593 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 593 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
594 // deleting empty strings does not work. 594 // deleting empty strings does not work.
595 // we write first and x and then delete the record with the x 595 // we write first and x and then delete the record with the x
596 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 596 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
597 changeString += eString + "\n"; 597 changeString += eString + "\n";
598 deleteString += eString + "\n"; 598 deleteString += eString + "\n";
599 deleteEnt = true; 599 deleteEnt = true;
600 changeEnt = true; 600 changeEnt = true;
601 } 601 }
602 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 602 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
603 603
604 604
605 605
606 QString fileNameIn = "/tmp/kopitempin"; 606 QString fileNameIn = "/tmp/kopitempin";
607 QFile fileIn( fileNameIn ); 607 QFile fileIn( fileNameIn );
608 if (!fileIn.open( IO_WriteOnly ) ) { 608 if (!fileIn.open( QIODevice::WriteOnly ) ) {
609 return false; 609 return false;
610 } 610 }
611 QTextStream tsIn( &fileIn ); 611 Q3TextStream tsIn( &fileIn );
612 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 612 tsIn.setCodec( QTextCodec::codecForName("utf8") );
613 tsIn << tPrefix << eString ; 613 tsIn << tPrefix << eString ;
614 fileIn.close(); 614 fileIn.close();
615 command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName; 615 command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName;
616 system ( command.utf8() ); 616 system ( command.utf8() );
617 QFile file( fileName ); 617 QFile file( fileName );
618 if (!file.open( IO_ReadOnly ) ) { 618 if (!file.open( QIODevice::ReadOnly ) ) {
619 return false; 619 return false;
620 } 620 }
621 QTextStream ts( &file ); 621 Q3TextStream ts( &file );
622 ts.setCodec( QTextCodec::codecForName("utf8") ); 622 ts.setCodec( QTextCodec::codecForName("utf8") );
623 answer = ts.read(); 623 answer = ts.read();
624 file.close(); 624 file.close();
625 //qDebug("answer \n%s ", answer.latin1()); 625 //qDebug("answer \n%s ", answer.latin1());
626 getNumFromRecord( answer, to ) ; 626 getNumFromRecord( answer, to ) ;
627 627
628 } 628 }
629 else { // change existing 629 else { // change existing
630 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 630 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
631 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 631 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
632 changeString += eString + "\n"; 632 changeString += eString + "\n";
633 changeEnt = true; 633 changeEnt = true;
634 634
635 } 635 }
636 } 636 }
637 637
638 to = tl.next(); 638 to = tl.next();
639 } 639 }
640 status.setText ( i18n("Changing todos ...") ); 640 status.setText ( i18n("Changing todos ...") );
641 qApp->processEvents(); 641 qApp->processEvents();
642 //qDebug("changing... "); 642 //qDebug("changing... ");
643 if ( changeEnt ) { 643 if ( changeEnt ) {
644 QFile file( fileName ); 644 QFile file( fileName );
645 if (!file.open( IO_WriteOnly ) ) { 645 if (!file.open( QIODevice::WriteOnly ) ) {
646 return false; 646 return false;
647 647
648 } 648 }
649 QTextStream ts( &file ); 649 Q3TextStream ts( &file );
650 ts.setCodec( QTextCodec::codecForName("utf8") ); 650 ts.setCodec( QTextCodec::codecForName("utf8") );
651 ts << changeString ; 651 ts << changeString ;
652 file.close(); 652 file.close();
653 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 653 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
654 system ( command.latin1() ); 654 system ( command.latin1() );
655 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 655 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
656 656
657 } 657 }
658 status.setText ( i18n("Deleting todos ...") ); 658 status.setText ( i18n("Deleting todos ...") );
659 qApp->processEvents(); 659 qApp->processEvents();
660 //qDebug("deleting... "); 660 //qDebug("deleting... ");
661 if ( deleteEnt ) { 661 if ( deleteEnt ) {
662 QFile file( fileName ); 662 QFile file( fileName );
663 if (!file.open( IO_WriteOnly ) ) { 663 if (!file.open( QIODevice::WriteOnly ) ) {
664 return false; 664 return false;
665 665
666 } 666 }
667 QTextStream ts( &file ); 667 Q3TextStream ts( &file );
668 ts.setCodec( QTextCodec::codecForName("utf8") ); 668 ts.setCodec( QTextCodec::codecForName("utf8") );
669 ts << deleteString; 669 ts << deleteString;
670 file.close(); 670 file.close();
671 command = "db2file todo -d -c " + codec+ " < "+ fileName; 671 command = "db2file todo -d -c " + codec+ " < "+ fileName;
672 system ( command.latin1() ); 672 system ( command.latin1() );
673 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 673 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
674 } 674 }
675 675
676 return true; 676 return true;
677} 677}
678QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 678QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
679{ 679{
680 QString datestr; 680 QString datestr;
681 QString timestr; 681 QString timestr;
682 int offset = KGlobal::locale()->localTimeOffset( dti ); 682 int offset = KGlobal::locale()->localTimeOffset( dti );
683 QDateTime dt; 683 QDateTime dt;
684 if (useTZ) 684 if (useTZ)
685 dt = dti.addSecs ( -(offset*60)); 685 dt = dti.addSecs ( -(offset*60));
686 else 686 else
687 dt = dti; 687 dt = dti;
688 if(dt.date().isValid()){ 688 if(dt.date().isValid()){
689 const QDate& date = dt.date(); 689 const QDate& date = dt.date();
690 datestr.sprintf("%04d%02d%02d", 690 datestr.sprintf("%04d%02d%02d",
691 date.year(), date.month(), date.day()); 691 date.year(), date.month(), date.day());
692 } 692 }
693 if(dt.time().isValid()){ 693 if(dt.time().isValid()){
694 const QTime& time = dt.time(); 694 const QTime& time = dt.time();
695 timestr.sprintf("T%02d%02d%02d", 695 timestr.sprintf("T%02d%02d%02d",
696 time.hour(), time.minute(), time.second()); 696 time.hour(), time.minute(), time.second());
697 } 697 }
698 return datestr + timestr; 698 return datestr + timestr;
699} 699}
700QString SharpFormat::getEventString( Event* event ) 700QString SharpFormat::getEventString( Event* event )
701{ 701{
702 QStringList list; 702 QStringList list;
703 list.append( event->getID("Sharp_DTM") ); 703 list.append( event->getID("Sharp_DTM") );
704 list.append( event->categories().join(",") ); 704 list.append( event->categories().join(",") );
705 if ( !event->summary().isEmpty() ) 705 if ( !event->summary().isEmpty() )
706 list.append( event->summary() ); 706 list.append( event->summary() );
707 else 707 else
708 list.append("" ); 708 list.append("" );
709 if ( !event->location().isEmpty() ) 709 if ( !event->location().isEmpty() )
710 list.append( event->location() ); 710 list.append( event->location() );
711 else 711 else
712 list.append("" ); 712 list.append("" );
713 if ( !event->description().isEmpty() ) 713 if ( !event->description().isEmpty() )
714 list.append( event->description() ); 714 list.append( event->description() );
715 else 715 else
716 list.append( "" ); 716 list.append( "" );
717 if ( event->doesFloat () ) { 717 if ( event->doesFloat () ) {
718 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 718 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
719 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 719 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
720 list.append( "1" ); 720 list.append( "1" );
721 721
722 } 722 }
723 else { 723 else {
724 list.append( dtToString( event->dtStart()) ); 724 list.append( dtToString( event->dtStart()) );
725 list.append( dtToString( event->dtEnd()) ); //6 725 list.append( dtToString( event->dtEnd()) ); //6
726 list.append( "0" ); 726 list.append( "0" );
727 } 727 }
728 bool noAlarm = true; 728 bool noAlarm = true;
729 if ( event->alarms().count() > 0 ) { 729 if ( event->alarms().count() > 0 ) {
730 Alarm * al = event->alarms().first(); 730 Alarm * al = event->alarms().first();
731 if ( al->enabled() ) { 731 if ( al->enabled() ) {
732 noAlarm = false; 732 noAlarm = false;
733 list.append( "0" ); // yes, 0 == alarm 733 list.append( "0" ); // yes, 0 == alarm
734 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 734 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
735 if ( al->type() == Alarm::Audio ) 735 if ( al->type() == Alarm::Audio )
736 list.append( "1" ); // type audio 736 list.append( "1" ); // type audio
737 else 737 else
738 list.append( "0" ); // type silent 738 list.append( "0" ); // type silent
739 } 739 }
740 } 740 }
741 if ( noAlarm ) { 741 if ( noAlarm ) {
742 list.append( "1" ); // yes, 1 == no alarm 742 list.append( "1" ); // yes, 1 == no alarm
743 list.append( "0" ); // no alarm offset 743 list.append( "0" ); // no alarm offset
744 list.append( "1" ); // type 744 list.append( "1" ); // type
745 } 745 }
746 // next is: 11 746 // next is: 11
747 // next is: 11-16 are recurrence 747 // next is: 11-16 are recurrence
748 Recurrence* rec = event->recurrence(); 748 Recurrence* rec = event->recurrence();
749 749
750 bool writeEndDate = false; 750 bool writeEndDate = false;
751 switch ( rec->doesRecur() ) 751 switch ( rec->doesRecur() )
752 { 752 {
753 case Recurrence::rDaily: // 0 753 case Recurrence::rDaily: // 0
754 list.append( "0" ); 754 list.append( "0" );
755 list.append( QString::number( rec->frequency() ));//12 755 list.append( QString::number( rec->frequency() ));//12
756 list.append( "0" ); 756 list.append( "0" );
757 list.append( "0" ); 757 list.append( "0" );
758 writeEndDate = true; 758 writeEndDate = true;
759 break; 759 break;
760 case Recurrence::rWeekly:// 1 760 case Recurrence::rWeekly:// 1
761 list.append( "1" ); 761 list.append( "1" );
762 list.append( QString::number( rec->frequency()) );//12 762 list.append( QString::number( rec->frequency()) );//12
763 list.append( "0" ); 763 list.append( "0" );
764 { 764 {
765 int days = 0; 765 int days = 0;
766 QBitArray weekDays = rec->days(); 766 QBitArray weekDays = rec->days();
767 int i; 767 int i;
768 for( i = 1; i <= 7; ++i ) { 768 for( i = 1; i <= 7; ++i ) {
769 if ( weekDays[i-1] ) { 769 if ( weekDays[i-1] ) {
770 days += 1 << (i-1); 770 days += 1 << (i-1);
771 } 771 }
772 } 772 }
773 list.append( QString::number( days ) ); 773 list.append( QString::number( days ) );
774 } 774 }
775 //pending weekdays 775 //pending weekdays
776 writeEndDate = true; 776 writeEndDate = true;
777 777
778 break; 778 break;
779 case Recurrence::rMonthlyPos:// 2 779 case Recurrence::rMonthlyPos:// 2
780 list.append( "2" ); 780 list.append( "2" );
781 list.append( QString::number( rec->frequency()) );//12 781 list.append( QString::number( rec->frequency()) );//12
782 782
783 writeEndDate = true; 783 writeEndDate = true;
784 { 784 {
785 int count = 1; 785 int count = 1;
786 QPtrList<Recurrence::rMonthPos> rmp; 786 Q3PtrList<Recurrence::rMonthPos> rmp;
787 rmp = rec->monthPositions(); 787 rmp = rec->monthPositions();
788 if ( rmp.first()->negative ) 788 if ( rmp.first()->negative )
789 count = 5 - rmp.first()->rPos - 1; 789 count = 5 - rmp.first()->rPos - 1;
790 else 790 else
791 count = rmp.first()->rPos - 1; 791 count = rmp.first()->rPos - 1;
792 list.append( QString::number( count ) ); 792 list.append( QString::number( count ) );
793 793
794 } 794 }
795 795
796 list.append( "0" ); 796 list.append( "0" );
797 break; 797 break;
798 case Recurrence::rMonthlyDay:// 3 798 case Recurrence::rMonthlyDay:// 3
799 list.append( "3" ); 799 list.append( "3" );
800 list.append( QString::number( rec->frequency()) );//12 800 list.append( QString::number( rec->frequency()) );//12
801 list.append( "0" ); 801 list.append( "0" );
802 list.append( "0" ); 802 list.append( "0" );
803 writeEndDate = true; 803 writeEndDate = true;
804 break; 804 break;
805 case Recurrence::rYearlyMonth://4 805 case Recurrence::rYearlyMonth://4
806 list.append( "4" ); 806 list.append( "4" );
807 list.append( QString::number( rec->frequency()) );//12 807 list.append( QString::number( rec->frequency()) );//12
808 list.append( "0" ); 808 list.append( "0" );
809 list.append( "0" ); 809 list.append( "0" );
810 writeEndDate = true; 810 writeEndDate = true;
811 break; 811 break;
812 812
813 default: 813 default:
814 list.append( "255" ); 814 list.append( "255" );
815 list.append( QString() ); 815 list.append( QString() );
816 list.append( "0" ); 816 list.append( "0" );
817 list.append( QString() ); 817 list.append( QString() );
818 list.append( "0" ); 818 list.append( "0" );
819 list.append( "20991231T000000" ); 819 list.append( "20991231T000000" );
820 break; 820 break;
821 } 821 }
822 if ( writeEndDate ) { 822 if ( writeEndDate ) {
823 823
824 if ( rec->endDate().isValid() ) { // 15 + 16 824 if ( rec->endDate().isValid() ) { // 15 + 16
825 list.append( "1" ); 825 list.append( "1" );
826 list.append( dtToString( rec->endDate(), false ) ); 826 list.append( dtToString( rec->endDate(), false ) );
827 } else { 827 } else {
828 list.append( "0" ); 828 list.append( "0" );
829 list.append( "20991231T000000" ); 829 list.append( "20991231T000000" );
830 } 830 }
831 831
832 } 832 }
833 if ( event->doesFloat () ) { 833 if ( event->doesFloat () ) {
834 list.append( dtToString( event->dtStart(), false ).left( 8 )); 834 list.append( dtToString( event->dtStart(), false ).left( 8 ));
835 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 835 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
836 836
837 } 837 }
838 else { 838 else {
839 list.append( QString() ); 839 list.append( QString() );
840 list.append( QString() ); 840 list.append( QString() );
841 841
842 } 842 }
843 if (event->dtStart().date() == event->dtEnd().date() ) 843 if (event->dtStart().date() == event->dtEnd().date() )
844 list.append( "0" ); 844 list.append( "0" );
845 else 845 else
846 list.append( "1" ); 846 list.append( "1" );
847 847
848 848
849 for(QStringList::Iterator it=list.begin(); 849 for(QStringList::Iterator it=list.begin();
850 it!=list.end(); ++it){ 850 it!=list.end(); ++it){
851 QString& s = (*it); 851 QString& s = (*it);
852 s.replace(QRegExp("\""), "\"\""); 852 s.replace(QRegExp("\""), "\"\"");
853 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 853 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
854 s.prepend('\"'); 854 s.prepend('\"');
855 s.append('\"'); 855 s.append('\"');
856 } else if(s.isEmpty() && !s.isNull()){ 856 } else if(s.isEmpty() && !s.isNull()){
857 s = "\"\""; 857 s = "\"\"";
858 } 858 }
859 } 859 }
860 return list.join(","); 860 return list.join(",");
861 861
862 862
863} 863}
864QString SharpFormat::getTodoString( Todo* todo ) 864QString SharpFormat::getTodoString( Todo* todo )
865{ 865{
866 QStringList list; 866 QStringList list;
867 list.append( todo->getID("Sharp_DTM") ); 867 list.append( todo->getID("Sharp_DTM") );
868 list.append( todo->categories().join(",") ); 868 list.append( todo->categories().join(",") );
869 869
870 if ( todo->hasStartDate() ) { 870 if ( todo->hasStartDate() ) {
871 list.append( dtToString( todo->dtStart()) ); 871 list.append( dtToString( todo->dtStart()) );
872 } else 872 } else
873 list.append( QString() ); 873 list.append( QString() );
874 874
875 if ( todo->hasDueDate() ) { 875 if ( todo->hasDueDate() ) {
876 QTime tim; 876 QTime tim;
877 if ( todo->doesFloat()) { 877 if ( todo->doesFloat()) {
878 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 878 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
879 } else { 879 } else {
880 list.append( dtToString(todo->dtDue() ) ); 880 list.append( dtToString(todo->dtDue() ) );
881 } 881 }
882 } else 882 } else