summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-28 13:13:08 (UTC)
committer zautrix <zautrix>2004-10-28 13:13:08 (UTC)
commit12068392f1d131c3f599b8854fe131dd9291a5ea (patch) (unidiff)
treebd49e43036eefde4aa2bdaa9b167b6b8d0e216b0
parent849ad402a00e2fe7bfd37c4c452b205767dab3d2 (diff)
downloadkdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.zip
kdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.tar.gz
kdepimpi-12068392f1d131c3f599b8854fe131dd9291a5ea.tar.bz2
fixed todo DTM sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index d56eab6..b88e729 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,1035 +1,1046 @@
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 <qptrlist.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 <qtextstream.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 oldCategories = 0; 67 oldCategories = 0;
68 } 68 }
69 69
70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
71 { 71 {
72 int i = 1; 72 int i = 1;
73 bool skip = true; 73 bool skip = true;
74 int max = attList.count() -2; 74 int max = attList.count() -2;
75 while ( i < max ) { 75 while ( i < max ) {
76 if ( !attList[i].isEmpty() ) { 76 if ( !attList[i].isEmpty() ) {
77 skip = false; 77 skip = false;
78 break; 78 break;
79 } 79 }
80 ++i ; 80 ++i ;
81 } 81 }
82 if ( skip ) 82 if ( skip )
83 return false; 83 return false;
84 ulong cSum = SharpFormat::getCsum(attList ); 84 ulong cSum = SharpFormat::getCsum(attList );
85 85
86 if ( qName == "Event" ) { 86 if ( qName == "Event" ) {
87 Event *event; 87 Event *event;
88 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 88 event = existingCalendar->event( "Sharp_DTM",attList[0] );
89 if ( event ) 89 if ( event )
90 event = (Event*)event->clone(); 90 event = (Event*)event->clone();
91 else 91 else
92 event = new Event; 92 event = new Event;
93 event->setID("Sharp_DTM", attList[0] ); 93 event->setID("Sharp_DTM", attList[0] );
94 event->setCsum( "Sharp_DTM", QString::number( cSum )); 94 event->setCsum( "Sharp_DTM", QString::number( cSum ));
95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 95 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
96 96
97 event->setSummary( attList[2] ); 97 event->setSummary( attList[2] );
98 event->setLocation( attList[3] ); 98 event->setLocation( attList[3] );
99 event->setDescription( attList[4] ); 99 event->setDescription( attList[4] );
100 if ( attList[7] == "1" ) { 100 if ( attList[7] == "1" ) {
101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 101 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 102 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
103 event->setFloats( true ); 103 event->setFloats( true );
104 } else { 104 } else {
105 event->setFloats( false ); 105 event->setFloats( false );
106 event->setDtStart( fromString( attList[5] ) ); 106 event->setDtStart( fromString( attList[5] ) );
107 event->setDtEnd( fromString( attList[6] )); 107 event->setDtEnd( fromString( attList[6] ));
108 } 108 }
109 109
110 QString rtype = attList[11]; 110 QString rtype = attList[11];
111 if ( rtype != "255" ) { 111 if ( rtype != "255" ) {
112 // qDebug("recurs "); 112 // qDebug("recurs ");
113 QDate startDate = event->dtStart().date(); 113 QDate startDate = event->dtStart().date();
114 114
115 QString freqStr = attList[12]; 115 QString freqStr = attList[12];
116 int freq = freqStr.toInt(); 116 int freq = freqStr.toInt();
117 117
118 QString hasEndDateStr = attList[15] ; 118 QString hasEndDateStr = attList[15] ;
119 bool hasEndDate = hasEndDateStr == "1"; 119 bool hasEndDate = hasEndDateStr == "1";
120 120
121 QString endDateStr = attList[16]; 121 QString endDateStr = attList[16];
122 QDate endDate = fromString( endDateStr ).date(); 122 QDate endDate = fromString( endDateStr ).date();
123 123
124 QString weekDaysStr = attList[14]; 124 QString weekDaysStr = attList[14];
125 uint weekDaysNum = weekDaysStr.toInt(); 125 uint weekDaysNum = weekDaysStr.toInt();
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 alarm->setType( Alarm::Audio ); 183 alarm->setType( Alarm::Audio );
184 } 184 }
185 //alarm->setType( Alarm::Audio ); 185 //alarm->setType( Alarm::Audio );
186 alarm->setEnabled( true ); 186 alarm->setEnabled( true );
187 int alarmOffset = attList[9].toInt(); 187 int alarmOffset = attList[9].toInt();
188 alarm->setStartOffset( alarmOffset * -60 ); 188 alarm->setStartOffset( alarmOffset * -60 );
189 } else { 189 } else {
190 Alarm *alarm; 190 Alarm *alarm;
191 if ( event->alarms().count() > 0 ) { 191 if ( event->alarms().count() > 0 ) {
192 alarm = event->alarms().first(); 192 alarm = event->alarms().first();
193 alarm->setType( Alarm::Audio ); 193 alarm->setType( Alarm::Audio );
194 alarm->setStartOffset( -60*15 ); 194 alarm->setStartOffset( -60*15 );
195 alarm->setEnabled( false ); 195 alarm->setEnabled( false );
196 } 196 }
197 } 197 }
198 198
199 mCalendar->addEvent( event); 199 mCalendar->addEvent( event);
200 } else if ( qName == "Todo" ) { 200 } else if ( qName == "Todo" ) {
201 Todo *todo; 201 Todo *todo;
202 202
203 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 203 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
204 if (todo ) 204 if (todo )
205 todo = (Todo*)todo->clone(); 205 todo = (Todo*)todo->clone();
206 else 206 else
207 todo = new Todo; 207 todo = new Todo;
208 208
209//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 209//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
210// 0 1 2 3 4 5 6 7 8 210// 0 1 2 3 4 5 6 7 8
211//1,,,,,1,4,Loch zumachen,"" 211//1,,,,,1,4,Loch zumachen,""
212//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 212//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
213//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 213//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
214 214
215 todo->setID( "Sharp_DTM", attList[0]); 215 todo->setID( "Sharp_DTM", attList[0]);
216 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 216 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
217 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 217 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
218 218
219 todo->setSummary( attList[7] ); 219 todo->setSummary( attList[7] );
220 todo->setDescription( attList[8]); 220 todo->setDescription( attList[8]);
221 221
222 int priority = attList[6].toInt(); 222 int priority = attList[6].toInt();
223 if ( priority == 0 ) priority = 3; 223 if ( priority == 0 ) priority = 3;
224 todo->setPriority( priority ); 224 todo->setPriority( priority );
225 225
226 QString categoryList = attList[1]; 226 QString categoryList = attList[1];
227 todo->setCategories( lookupCategories( categoryList ) ); 227 todo->setCategories( lookupCategories( categoryList ) );
228 228
229 229
230 230
231 QString hasDateStr = attList[3]; // due 231 QString hasDateStr = attList[3]; // due
232 if ( !hasDateStr.isEmpty() ) { 232 if ( !hasDateStr.isEmpty() ) {
233 if ( hasDateStr.right(6) == "000000" ) { 233 if ( hasDateStr.right(6) == "000000" ) {
234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 234 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
235 todo->setFloats( true ); 235 todo->setFloats( true );
236 } 236 }
237 else { 237 else {
238 todo->setDtDue( fromString( hasDateStr ) ); 238 todo->setDtDue( fromString( hasDateStr ) );
239 todo->setFloats( false ); 239 todo->setFloats( false );
240 } 240 }
241 241
242 todo->setHasDueDate( true ); 242 todo->setHasDueDate( true );
243 } 243 }
244 hasDateStr = attList[2];//start 244 hasDateStr = attList[2];//start
245 if ( !hasDateStr.isEmpty() ) { 245 if ( !hasDateStr.isEmpty() ) {
246 246
247 todo->setDtStart( fromString( hasDateStr ) ); 247 todo->setDtStart( fromString( hasDateStr ) );
248 todo->setHasStartDate( true); 248 todo->setHasStartDate( true);
249 } else 249 } else
250 todo->setHasStartDate( false ); 250 todo->setHasStartDate( false );
251 hasDateStr = attList[4];//completed 251 hasDateStr = attList[4];//completed
252 if ( !hasDateStr.isEmpty() ) { 252 if ( !hasDateStr.isEmpty() ) {
253 todo->setCompleted(fromString( hasDateStr ) ); 253 todo->setCompleted(fromString( hasDateStr ) );
254 } 254 }
255 QString completedStr = attList[5]; 255 QString completedStr = attList[5];
256 if ( completedStr == "0" ) 256 if ( completedStr == "0" )
257 todo->setCompleted( true ); 257 todo->setCompleted( true );
258 else 258 else
259 todo->setCompleted( false ); 259 todo->setCompleted( false );
260 mCalendar->addTodo( todo ); 260 mCalendar->addTodo( todo );
261 261
262 } else if ( qName == "Category" ) { 262 } else if ( qName == "Category" ) {
263 /* 263 /*
264 QString id = attributes.value( "id" ); 264 QString id = attributes.value( "id" );
265 QString name = attributes.value( "name" ); 265 QString name = attributes.value( "name" );
266 setCategory( id, name ); 266 setCategory( id, name );
267 */ 267 */
268 } 268 }
269 //qDebug("end "); 269 //qDebug("end ");
270 return true; 270 return true;
271 } 271 }
272 272
273 273
274 void setCategoriesList ( QStringList * c ) 274 void setCategoriesList ( QStringList * c )
275 { 275 {
276 oldCategories = c; 276 oldCategories = c;
277 } 277 }
278 278
279 QDateTime fromString ( QString s, bool useTz = true ) { 279 QDateTime fromString ( QString s, bool useTz = true ) {
280 QDateTime dt; 280 QDateTime dt;
281 int y,m,t,h,min,sec; 281 int y,m,t,h,min,sec;
282 y = s.mid(0,4).toInt(); 282 y = s.mid(0,4).toInt();
283 m = s.mid(4,2).toInt(); 283 m = s.mid(4,2).toInt();
284 t = s.mid(6,2).toInt(); 284 t = s.mid(6,2).toInt();
285 h = s.mid(9,2).toInt(); 285 h = s.mid(9,2).toInt();
286 min = s.mid(11,2).toInt(); 286 min = s.mid(11,2).toInt();
287 sec = s.mid(13,2).toInt(); 287 sec = s.mid(13,2).toInt();
288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 288 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
289 int offset = KGlobal::locale()->localTimeOffset( dt ); 289 int offset = KGlobal::locale()->localTimeOffset( dt );
290 if ( useTz ) 290 if ( useTz )
291 dt = dt.addSecs ( offset*60); 291 dt = dt.addSecs ( offset*60);
292 return dt; 292 return dt;
293 293
294 } 294 }
295 protected: 295 protected:
296 QDateTime toDateTime( const QString &value ) 296 QDateTime toDateTime( const QString &value )
297 { 297 {
298 QDateTime dt; 298 QDateTime dt;
299 dt.setTime_t( value.toUInt() ); 299 dt.setTime_t( value.toUInt() );
300 300
301 return dt; 301 return dt;
302 } 302 }
303 303
304 QStringList lookupCategories( const QString &categoryList ) 304 QStringList lookupCategories( const QString &categoryList )
305 { 305 {
306 QStringList categoryIds = QStringList::split( ";", categoryList ); 306 QStringList categoryIds = QStringList::split( ";", categoryList );
307 QStringList categories; 307 QStringList categories;
308 QStringList::ConstIterator it; 308 QStringList::ConstIterator it;
309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) { 309 for( it = categoryIds.begin(); it != categoryIds.end(); ++it ) {
310 QString cate = category( *it ); 310 QString cate = category( *it );
311 if ( oldCategories ) { 311 if ( oldCategories ) {
312 if ( ! oldCategories->contains( cate ) ) 312 if ( ! oldCategories->contains( cate ) )
313 oldCategories->append( cate ); 313 oldCategories->append( cate );
314 } 314 }
315 categories.append(cate ); 315 categories.append(cate );
316 } 316 }
317 return categories; 317 return categories;
318 } 318 }
319 319
320 private: 320 private:
321 Calendar *mCalendar; 321 Calendar *mCalendar;
322 QStringList * oldCategories; 322 QStringList * oldCategories;
323 static QString category( const QString &id ) 323 static QString category( const QString &id )
324 { 324 {
325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id ); 325 QMap<QString,QString>::ConstIterator it = mCategoriesMap.find( id );
326 if ( it == mCategoriesMap.end() ) return id; 326 if ( it == mCategoriesMap.end() ) return id;
327 else return *it; 327 else return *it;
328 } 328 }
329 329
330 static void setCategory( const QString &id, const QString &name ) 330 static void setCategory( const QString &id, const QString &name )
331 { 331 {
332 mCategoriesMap.insert( id, name ); 332 mCategoriesMap.insert( id, name );
333 } 333 }
334 334
335 static QMap<QString,QString> mCategoriesMap; 335 static QMap<QString,QString> mCategoriesMap;
336}; 336};
337 337
338QMap<QString,QString> SharpParser::mCategoriesMap; 338QMap<QString,QString> SharpParser::mCategoriesMap;
339 339
340SharpFormat::SharpFormat() 340SharpFormat::SharpFormat()
341{ 341{
342 mCategories = 0; 342 mCategories = 0;
343} 343}
344 344
345SharpFormat::~SharpFormat() 345SharpFormat::~SharpFormat()
346{ 346{
347} 347}
348ulong SharpFormat::getCsum( const QStringList & attList) 348ulong SharpFormat::getCsum( const QStringList & attList)
349{ 349{
350 int max = attList.count() -1; 350 int max = attList.count() -1;
351 ulong cSum = 0; 351 ulong cSum = 0;
352 int j,k,i; 352 int j,k,i;
353 int add; 353 int add;
354 for ( i = 1; i < max ; ++i ) { 354 for ( i = 1; i < max ; ++i ) {
355 QString s = attList[i]; 355 QString s = attList[i];
356 if ( ! s.isEmpty() ){ 356 if ( ! s.isEmpty() ){
357 j = s.length(); 357 j = s.length();
358 for ( k = 0; k < j; ++k ) { 358 for ( k = 0; k < j; ++k ) {
359 int mul = k +1; 359 int mul = k +1;
360 add = s[k].unicode (); 360 add = s[k].unicode ();
361 if ( k < 16 ) 361 if ( k < 16 )
362 mul = mul * mul; 362 mul = mul * mul;
363 add = add * mul *i*i*i; 363 add = add * mul *i*i*i;
364 cSum += add; 364 cSum += add;
365 } 365 }
366 } 366 }
367 } 367 }
368 return cSum; 368 return cSum;
369 369
370} 370}
371#include <stdlib.h> 371#include <stdlib.h>
372#define DEBUGMODE false 372#define DEBUGMODE false
373//#define DEBUGMODE true 373//#define DEBUGMODE true
374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 374bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
375{ 375{
376 376
377 377
378 bool debug = DEBUGMODE; 378 bool debug = DEBUGMODE;
379 QString text; 379 QString text;
380 QString codec = "utf8"; 380 QString codec = "utf8";
381 QLabel status ( i18n("Reading events ..."), 0 ); 381 QLabel status ( i18n("Reading events ..."), 0 );
382 382
383 int w = status.sizeHint().width()+20 ; 383 int w = status.sizeHint().width()+20 ;
384 if ( w < 200 ) w = 200; 384 if ( w < 200 ) w = 200;
385 int h = status.sizeHint().height()+20 ; 385 int h = status.sizeHint().height()+20 ;
386 int dw = QApplication::desktop()->width(); 386 int dw = QApplication::desktop()->width();
387 int dh = QApplication::desktop()->height(); 387 int dh = QApplication::desktop()->height();
388 status.setCaption(i18n("Reading DTM Data") ); 388 status.setCaption(i18n("Reading DTM Data") );
389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 389 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
390 status.show(); 390 status.show();
391 status.raise(); 391 status.raise();
392 qApp->processEvents(); 392 qApp->processEvents();
393 QString fileName; 393 QString fileName;
394 if ( ! debug ) { 394 if ( ! debug ) {
395 fileName = "/tmp/kopitempout"; 395 fileName = "/tmp/kopitempout";
396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 396 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
397 system ( command.latin1() ); 397 system ( command.latin1() );
398 } else { 398 } else {
399 fileName = "/tmp/events.txt"; 399 fileName = "/tmp/events.txt";
400 400
401 } 401 }
402 QFile file( fileName ); 402 QFile file( fileName );
403 if (!file.open( IO_ReadOnly ) ) { 403 if (!file.open( IO_ReadOnly ) ) {
404 return false; 404 return false;
405 405
406 } 406 }
407 QTextStream ts( &file ); 407 QTextStream ts( &file );
408 ts.setCodec( QTextCodec::codecForName("utf8") ); 408 ts.setCodec( QTextCodec::codecForName("utf8") );
409 text = ts.read(); 409 text = ts.read();
410 file.close(); 410 file.close();
411 status.setText( i18n("Processing events ...") ); 411 status.setText( i18n("Processing events ...") );
412 status.raise(); 412 status.raise();
413 qApp->processEvents(); 413 qApp->processEvents();
414 fromString2Cal( calendar, existngCal, text, "Event" ); 414 fromString2Cal( calendar, existngCal, text, "Event" );
415 status.setText( i18n("Reading todos ...") ); 415 status.setText( i18n("Reading todos ...") );
416 qApp->processEvents(); 416 qApp->processEvents();
417 if ( ! debug ) { 417 if ( ! debug ) {
418 fileName = "/tmp/kopitempout"; 418 fileName = "/tmp/kopitempout";
419 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 419 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
420 system ( command.latin1() ); 420 system ( command.latin1() );
421 } else { 421 } else {
422 fileName = "/tmp/todo.txt"; 422 fileName = "/tmp/todo.txt";
423 } 423 }
424 file.setName( fileName ); 424 file.setName( fileName );
425 if (!file.open( IO_ReadOnly ) ) { 425 if (!file.open( IO_ReadOnly ) ) {
426 return false; 426 return false;
427 427
428 } 428 }
429 ts.setDevice( &file ); 429 ts.setDevice( &file );
430 text = ts.read(); 430 text = ts.read();
431 file.close(); 431 file.close();
432 432
433 status.setText( i18n("Processing todos ...") ); 433 status.setText( i18n("Processing todos ...") );
434 status.raise(); 434 status.raise();
435 qApp->processEvents(); 435 qApp->processEvents();
436 fromString2Cal( calendar, existngCal, text, "Todo" ); 436 fromString2Cal( calendar, existngCal, text, "Todo" );
437 return true; 437 return true;
438} 438}
439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 439int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
440{ 440{
441 int retval = -1; 441 int retval = -1;
442 QStringList templist; 442 QStringList templist;
443 QString tempString; 443 QString tempString;
444 int start = 0; 444 int start = 0;
445 int len = answer.length(); 445 int len = answer.length();
446 int end = answer.find ("\n",start)+1; 446 int end = answer.find ("\n",start)+1;
447 bool ok = true; 447 bool ok = true;
448 start = end; 448 start = end;
449 int ccc = 0; 449 int ccc = 0;
450 while ( start > 0 ) { 450 while ( start > 0 ) {
451 templist.clear(); 451 templist.clear();
452 ok = true; 452 ok = true;
453 int loopCount = 0; 453 int loopCount = 0;
454 while ( ok ) { 454 while ( ok ) {
455 ++loopCount; 455 ++loopCount;
456 if ( loopCount > 25 ) { 456 if ( loopCount > 25 ) {
457 qDebug("KO: Error in while loop"); 457 qDebug("KO: Error in while loop");
458 ok = false; 458 ok = false;
459 start = 0; 459 start = 0;
460 break; 460 break;
461 } 461 }
462 if ( ok ) 462 if ( ok )
463 tempString = getPart( answer, ok, start ); 463 tempString = getPart( answer, ok, start );
464 if ( start >= len || start == 0 ) { 464 if ( start >= len || start == 0 ) {
465 start = 0; 465 start = 0;
466 ok = false; 466 ok = false;
467 } 467 }
468 if ( tempString.right(1) =="\n" ) 468 if ( tempString.right(1) =="\n" )
469 tempString = tempString.left( tempString.length()-1); 469 tempString = tempString.left( tempString.length()-1);
470 470
471 templist.append( tempString ); 471 templist.append( tempString );
472 } 472 }
473 ++ccc; 473 ++ccc;
474 if ( ccc == 2 && loopCount < 25 ) { 474 if ( ccc == 2 && loopCount < 25 ) {
475 start = 0; 475 start = 0;
476 bool ok; 476 bool ok;
477 int newnum = templist[0].toInt( &ok ); 477 int newnum = templist[0].toInt( &ok );
478 if ( ok && newnum > 0) { 478 if ( ok && newnum > 0) {
479 retval = newnum; 479 retval = newnum;
480 inc->setID( "Sharp_DTM",templist[0] ); 480 inc->setID( "Sharp_DTM",templist[0] );
481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 481 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 482 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
483 } 483 }
484 if ( ok && newnum == -1 ) { 484 if ( ok && newnum == -1 ) {
485 qDebug("Error writing back %s ", inc->summary().latin1()); 485 qDebug("Error writing back %s ", inc->summary().latin1());
486 } 486 }
487 } 487 }
488 } 488 }
489 //qDebug("getNumFromRecord returning : %d ", retval); 489 //qDebug("getNumFromRecord returning : %d ", retval);
490 return retval; 490 return retval;
491} 491}
492bool SharpFormat::save( Calendar *calendar) 492bool SharpFormat::save( Calendar *calendar)
493{ 493{
494 494
495 QLabel status ( i18n("Processing/adding events ..."), 0 ); 495 QLabel status ( i18n("Processing/adding events ..."), 0 );
496 int w = status.sizeHint().width()+20 ; 496 int w = status.sizeHint().width()+20 ;
497 if ( w < 200 ) w = 200; 497 if ( w < 200 ) w = 200;
498 int h = status.sizeHint().height()+20 ; 498 int h = status.sizeHint().height()+20 ;
499 int dw = QApplication::desktop()->width(); 499 int dw = QApplication::desktop()->width();
500 int dh = QApplication::desktop()->height(); 500 int dh = QApplication::desktop()->height();
501 status.setCaption(i18n("Writing DTM Data") ); 501 status.setCaption(i18n("Writing DTM Data") );
502 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 502 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
503 status.show(); 503 status.show();
504 status.raise(); 504 status.raise();
505 qApp->processEvents(); 505 qApp->processEvents();
506 bool debug = DEBUGMODE; 506 bool debug = DEBUGMODE;
507 QString codec = "utf8"; 507 QString codec = "utf8";
508 QString answer; 508 QString answer;
509 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 509 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
510 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 510 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
511 QString command; 511 QString command;
512 QPtrList<Event> er = calendar->rawEvents(); 512 QPtrList<Event> er = calendar->rawEvents();
513 Event* ev = er.first(); 513 Event* ev = er.first();
514 QString fileName = "/tmp/kopitempout"; 514 QString fileName = "/tmp/kopitempout";
515 int i = 0; 515 int i = 0;
516 QString changeString = ePrefix; 516 QString changeString = ePrefix;
517 QString deleteString = ePrefix; 517 QString deleteString = ePrefix;
518 bool deleteEnt = false; 518 bool deleteEnt = false;
519 bool changeEnt = false; 519 bool changeEnt = false;
520 QString message = i18n("Processing event # "); 520 QString message = i18n("Processing event # ");
521 int procCount = 0; 521 int procCount = 0;
522 while ( ev ) { 522 while ( ev ) {
523 //qDebug("i %d ", ++i); 523 //qDebug("i %d ", ++i);
524 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 524 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
525 status.setText ( message + QString::number ( ++procCount ) ); 525 status.setText ( message + QString::number ( ++procCount ) );
526 qApp->processEvents(); 526 qApp->processEvents();
527 QString eString = getEventString( ev ); 527 QString eString = getEventString( ev );
528 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 528 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
529 // deleting empty strings does not work. 529 // deleting empty strings does not work.
530 // we write first and x and then delete the record with the x 530 // we write first and x and then delete the record with the x
531 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 531 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
532 changeString += eString + "\n"; 532 changeString += eString + "\n";
533 deleteString += eString + "\n"; 533 deleteString += eString + "\n";
534 deleteEnt = true; 534 deleteEnt = true;
535 changeEnt = true; 535 changeEnt = true;
536 } 536 }
537 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 537 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
538 QString fileNameIn = "/tmp/kopitempin"; 538 QString fileNameIn = "/tmp/kopitempin";
539 QFile fileIn( fileNameIn ); 539 QFile fileIn( fileNameIn );
540 if (!fileIn.open( IO_WriteOnly ) ) { 540 if (!fileIn.open( IO_WriteOnly ) ) {
541 return false; 541 return false;
542 } 542 }
543 QTextStream tsIn( &fileIn ); 543 QTextStream tsIn( &fileIn );
544 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 544 tsIn.setCodec( QTextCodec::codecForName("utf8") );
545 tsIn << ePrefix << eString ; 545 tsIn << ePrefix << eString ;
546 fileIn.close(); 546 fileIn.close();
547 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 547 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
548 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; 548 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
549 //qDebug("command ++++++++ "); 549 //qDebug("command ++++++++ ");
550 //qDebug("%s ",command.latin1()); 550 //qDebug("%s ",command.latin1());
551 //qDebug("command -------- "); 551 //qDebug("command -------- ");
552 system ( command.utf8() ); 552 system ( command.utf8() );
553 QFile file( fileName ); 553 QFile file( fileName );
554 if (!file.open( IO_ReadOnly ) ) { 554 if (!file.open( IO_ReadOnly ) ) {
555 return false; 555 return false;
556 556
557 } 557 }
558 QTextStream ts( &file ); 558 QTextStream ts( &file );
559 ts.setCodec( QTextCodec::codecForName("utf8") ); 559 ts.setCodec( QTextCodec::codecForName("utf8") );
560 answer = ts.read(); 560 answer = ts.read();
561 file.close(); 561 file.close();
562 //qDebug("answer \n%s ", answer.latin1()); 562 //qDebug("answer \n%s ", answer.latin1());
563 getNumFromRecord( answer, ev ) ; 563 getNumFromRecord( answer, ev ) ;
564 564
565 } 565 }
566 else { // change existing 566 else { // change existing
567 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() ); 567 //qDebug("canging %d %d",ev->zaurusStat() ,ev->zaurusId() );
568 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 568 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
569 changeString += eString + "\n"; 569 changeString += eString + "\n";
570 changeEnt = true; 570 changeEnt = true;
571 571
572 } 572 }
573 } 573 }
574 ev = er.next(); 574 ev = er.next();
575 } 575 }
576 status.setText ( i18n("Changing events ...") ); 576 status.setText ( i18n("Changing events ...") );
577 qApp->processEvents(); 577 qApp->processEvents();
578 //qDebug("changing... "); 578 //qDebug("changing... ");
579 if ( changeEnt ) { 579 if ( changeEnt ) {
580 QFile file( fileName ); 580 QFile file( fileName );
581 if (!file.open( IO_WriteOnly ) ) { 581 if (!file.open( IO_WriteOnly ) ) {
582 return false; 582 return false;
583 583
584 } 584 }
585 QTextStream ts( &file ); 585 QTextStream ts( &file );
586 ts.setCodec( QTextCodec::codecForName("utf8") ); 586 ts.setCodec( QTextCodec::codecForName("utf8") );
587 ts << changeString ; 587 ts << changeString ;
588 file.close(); 588 file.close();
589 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName; 589 command = "db2file datebook -w -g -c " + codec+ " < "+ fileName;
590 system ( command.latin1() ); 590 system ( command.latin1() );
591 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 591 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
592 592
593 } 593 }
594 status.setText ( i18n("Deleting events ...") ); 594 status.setText ( i18n("Deleting events ...") );
595 qApp->processEvents(); 595 qApp->processEvents();
596 //qDebug("deleting... "); 596 //qDebug("deleting... ");
597 if ( deleteEnt ) { 597 if ( deleteEnt ) {
598 QFile file( fileName ); 598 QFile file( fileName );
599 if (!file.open( IO_WriteOnly ) ) { 599 if (!file.open( IO_WriteOnly ) ) {
600 return false; 600 return false;
601 601
602 } 602 }
603 QTextStream ts( &file ); 603 QTextStream ts( &file );
604 ts.setCodec( QTextCodec::codecForName("utf8") ); 604 ts.setCodec( QTextCodec::codecForName("utf8") );
605 ts << deleteString; 605 ts << deleteString;
606 file.close(); 606 file.close();
607 command = "db2file datebook -d -c " + codec+ " < "+ fileName; 607 command = "db2file datebook -d -c " + codec+ " < "+ fileName;
608 system ( command.latin1() ); 608 system ( command.latin1() );
609 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 609 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
610 } 610 }
611 611
612 612
613 changeString = tPrefix; 613 changeString = tPrefix;
614 deleteString = tPrefix; 614 deleteString = tPrefix;
615 status.setText ( i18n("Processing todos ...") ); 615 status.setText ( i18n("Processing todos ...") );
616 qApp->processEvents(); 616 qApp->processEvents();
617 QPtrList<Todo> tl = calendar->rawTodos(); 617 QPtrList<Todo> tl = calendar->rawTodos();
618 Todo* to = tl.first(); 618 Todo* to = tl.first();
619 i = 0; 619 i = 0;
620 message = i18n("Processing todo # "); 620 message = i18n("Processing todo # ");
621 procCount = 0; 621 procCount = 0;
622 while ( to ) { 622 while ( to ) {
623 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 623 if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
624 status.setText ( message + QString::number ( ++procCount ) ); 624 status.setText ( message + QString::number ( ++procCount ) );
625 qApp->processEvents(); 625 qApp->processEvents();
626 QString eString = getTodoString( to ); 626 QString eString = getTodoString( to );
627 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 627 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
628 // deleting empty strings does not work. 628 // deleting empty strings does not work.
629 // we write first and x and then delete the record with the x 629 // we write first and x and then delete the record with the x
630 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 630 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
631 changeString += eString + "\n"; 631 changeString += eString + "\n";
632 deleteString += eString + "\n"; 632 deleteString += eString + "\n";
633 deleteEnt = true; 633 deleteEnt = true;
634 changeEnt = true; 634 changeEnt = true;
635 } 635 }
636 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new 636 else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
637 command = "(echo \"" + tPrefix + eString + "\" ) | db2file todo -w -g -c " + codec+ " > "+ fileName; 637
638
639
640 QString fileNameIn = "/tmp/kopitempin";
641 QFile fileIn( fileNameIn );
642 if (!fileIn.open( IO_WriteOnly ) ) {
643 return false;
644 }
645 QTextStream tsIn( &fileIn );
646 tsIn.setCodec( QTextCodec::codecForName("utf8") );
647 tsIn << tPrefix << eString ;
648 fileIn.close();
649 command = "(cat /tmp/kopitempin | db2file todo -w -g -c " + codec+ ") > "+ fileName;
638 system ( command.utf8() ); 650 system ( command.utf8() );
639 QFile file( fileName ); 651 QFile file( fileName );
640 if (!file.open( IO_ReadOnly ) ) { 652 if (!file.open( IO_ReadOnly ) ) {
641 return false; 653 return false;
642
643 } 654 }
644 QTextStream ts( &file ); 655 QTextStream ts( &file );
645 ts.setCodec( QTextCodec::codecForName("utf8") ); 656 ts.setCodec( QTextCodec::codecForName("utf8") );
646 answer = ts.read(); 657 answer = ts.read();
647 file.close(); 658 file.close();
648 //qDebug("answer \n%s ", answer.latin1()); 659 //qDebug("answer \n%s ", answer.latin1());
649 getNumFromRecord( answer, to ) ; 660 getNumFromRecord( answer, to ) ;
650 661
651 } 662 }
652 else { // change existing 663 else { // change existing
653 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() ); 664 //qDebug("canging %d %d",to->zaurusStat() ,to->zaurusId() );
654 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 665 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
655 changeString += eString + "\n"; 666 changeString += eString + "\n";
656 changeEnt = true; 667 changeEnt = true;
657 668
658 } 669 }
659 } 670 }
660 671
661 to = tl.next(); 672 to = tl.next();
662 } 673 }
663 status.setText ( i18n("Changing todos ...") ); 674 status.setText ( i18n("Changing todos ...") );
664 qApp->processEvents(); 675 qApp->processEvents();
665 //qDebug("changing... "); 676 //qDebug("changing... ");
666 if ( changeEnt ) { 677 if ( changeEnt ) {
667 QFile file( fileName ); 678 QFile file( fileName );
668 if (!file.open( IO_WriteOnly ) ) { 679 if (!file.open( IO_WriteOnly ) ) {
669 return false; 680 return false;
670 681
671 } 682 }
672 QTextStream ts( &file ); 683 QTextStream ts( &file );
673 ts.setCodec( QTextCodec::codecForName("utf8") ); 684 ts.setCodec( QTextCodec::codecForName("utf8") );
674 ts << changeString ; 685 ts << changeString ;
675 file.close(); 686 file.close();
676 command = "db2file todo -w -g -c " + codec+ " < "+ fileName; 687 command = "db2file todo -w -g -c " + codec+ " < "+ fileName;
677 system ( command.latin1() ); 688 system ( command.latin1() );
678 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1()); 689 //qDebug("command %s file :\n%s ", command.latin1(), changeString.latin1());
679 690
680 } 691 }
681 status.setText ( i18n("Deleting todos ...") ); 692 status.setText ( i18n("Deleting todos ...") );
682 qApp->processEvents(); 693 qApp->processEvents();
683 //qDebug("deleting... "); 694 //qDebug("deleting... ");
684 if ( deleteEnt ) { 695 if ( deleteEnt ) {
685 QFile file( fileName ); 696 QFile file( fileName );
686 if (!file.open( IO_WriteOnly ) ) { 697 if (!file.open( IO_WriteOnly ) ) {
687 return false; 698 return false;
688 699
689 } 700 }
690 QTextStream ts( &file ); 701 QTextStream ts( &file );
691 ts.setCodec( QTextCodec::codecForName("utf8") ); 702 ts.setCodec( QTextCodec::codecForName("utf8") );
692 ts << deleteString; 703 ts << deleteString;
693 file.close(); 704 file.close();
694 command = "db2file todo -d -c " + codec+ " < "+ fileName; 705 command = "db2file todo -d -c " + codec+ " < "+ fileName;
695 system ( command.latin1() ); 706 system ( command.latin1() );
696 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1()); 707 // qDebug("command %s file :\n%s ", command.latin1(), deleteString.latin1());
697 } 708 }
698 709
699 return true; 710 return true;
700} 711}
701QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ ) 712QString SharpFormat::dtToString( const QDateTime& dti, bool useTZ )
702{ 713{
703 QString datestr; 714 QString datestr;
704 QString timestr; 715 QString timestr;
705 int offset = KGlobal::locale()->localTimeOffset( dti ); 716 int offset = KGlobal::locale()->localTimeOffset( dti );
706 QDateTime dt; 717 QDateTime dt;
707 if (useTZ) 718 if (useTZ)
708 dt = dti.addSecs ( -(offset*60)); 719 dt = dti.addSecs ( -(offset*60));
709 else 720 else
710 dt = dti; 721 dt = dti;
711 if(dt.date().isValid()){ 722 if(dt.date().isValid()){
712 const QDate& date = dt.date(); 723 const QDate& date = dt.date();
713 datestr.sprintf("%04d%02d%02d", 724 datestr.sprintf("%04d%02d%02d",
714 date.year(), date.month(), date.day()); 725 date.year(), date.month(), date.day());
715 } 726 }
716 if(dt.time().isValid()){ 727 if(dt.time().isValid()){
717 const QTime& time = dt.time(); 728 const QTime& time = dt.time();
718 timestr.sprintf("T%02d%02d%02d", 729 timestr.sprintf("T%02d%02d%02d",
719 time.hour(), time.minute(), time.second()); 730 time.hour(), time.minute(), time.second());
720 } 731 }
721 return datestr + timestr; 732 return datestr + timestr;
722} 733}
723QString SharpFormat::getEventString( Event* event ) 734QString SharpFormat::getEventString( Event* event )
724{ 735{
725 QStringList list; 736 QStringList list;
726 list.append( event->getID("Sharp_DTM") ); 737 list.append( event->getID("Sharp_DTM") );
727 list.append( event->categories().join(",") ); 738 list.append( event->categories().join(",") );
728 if ( !event->summary().isEmpty() ) 739 if ( !event->summary().isEmpty() )
729 list.append( event->summary() ); 740 list.append( event->summary() );
730 else 741 else
731 list.append("" ); 742 list.append("" );
732 if ( !event->location().isEmpty() ) 743 if ( !event->location().isEmpty() )
733 list.append( event->location() ); 744 list.append( event->location() );
734 else 745 else
735 list.append("" ); 746 list.append("" );
736 if ( !event->description().isEmpty() ) 747 if ( !event->description().isEmpty() )
737 list.append( event->description() ); 748 list.append( event->description() );
738 else 749 else
739 list.append( "" ); 750 list.append( "" );
740 if ( event->doesFloat () ) { 751 if ( event->doesFloat () ) {
741 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false )); 752 list.append( dtToString( QDateTime(event->dtStart().date(), QTime(0,0,0)), false ));
742 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6 753 list.append( dtToString( QDateTime(event->dtEnd().date(),QTime(23,59,59)), false )); //6
743 list.append( "1" ); 754 list.append( "1" );
744 755
745 } 756 }
746 else { 757 else {
747 list.append( dtToString( event->dtStart()) ); 758 list.append( dtToString( event->dtStart()) );
748 list.append( dtToString( event->dtEnd()) ); //6 759 list.append( dtToString( event->dtEnd()) ); //6
749 list.append( "0" ); 760 list.append( "0" );
750 } 761 }
751 bool noAlarm = true; 762 bool noAlarm = true;
752 if ( event->alarms().count() > 0 ) { 763 if ( event->alarms().count() > 0 ) {
753 Alarm * al = event->alarms().first(); 764 Alarm * al = event->alarms().first();
754 if ( al->enabled() ) { 765 if ( al->enabled() ) {
755 noAlarm = false; 766 noAlarm = false;
756 list.append( "0" ); // yes, 0 == alarm 767 list.append( "0" ); // yes, 0 == alarm
757 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) ); 768 list.append( QString::number( al->startOffset().asSeconds()/(-60) ) );
758 if ( al->type() == Alarm::Audio ) 769 if ( al->type() == Alarm::Audio )
759 list.append( "1" ); // type audio 770 list.append( "1" ); // type audio
760 else 771 else
761 list.append( "0" ); // type silent 772 list.append( "0" ); // type silent
762 } 773 }
763 } 774 }
764 if ( noAlarm ) { 775 if ( noAlarm ) {
765 list.append( "1" ); // yes, 1 == no alarm 776 list.append( "1" ); // yes, 1 == no alarm
766 list.append( "0" ); // no alarm offset 777 list.append( "0" ); // no alarm offset
767 list.append( "1" ); // type 778 list.append( "1" ); // type
768 } 779 }
769 // next is: 11 780 // next is: 11
770 // next is: 11-16 are recurrence 781 // next is: 11-16 are recurrence
771 Recurrence* rec = event->recurrence(); 782 Recurrence* rec = event->recurrence();
772 783
773 bool writeEndDate = false; 784 bool writeEndDate = false;
774 switch ( rec->doesRecur() ) 785 switch ( rec->doesRecur() )
775 { 786 {
776 case Recurrence::rDaily: // 0 787 case Recurrence::rDaily: // 0
777 list.append( "0" ); 788 list.append( "0" );
778 list.append( QString::number( rec->frequency() ));//12 789 list.append( QString::number( rec->frequency() ));//12
779 list.append( "0" ); 790 list.append( "0" );
780 list.append( "0" ); 791 list.append( "0" );
781 writeEndDate = true; 792 writeEndDate = true;
782 break; 793 break;
783 case Recurrence::rWeekly:// 1 794 case Recurrence::rWeekly:// 1
784 list.append( "1" ); 795 list.append( "1" );
785 list.append( QString::number( rec->frequency()) );//12 796 list.append( QString::number( rec->frequency()) );//12
786 list.append( "0" ); 797 list.append( "0" );
787 { 798 {
788 int days = 0; 799 int days = 0;
789 QBitArray weekDays = rec->days(); 800 QBitArray weekDays = rec->days();
790 int i; 801 int i;
791 for( i = 1; i <= 7; ++i ) { 802 for( i = 1; i <= 7; ++i ) {
792 if ( weekDays[i-1] ) { 803 if ( weekDays[i-1] ) {
793 days += 1 << (i-1); 804 days += 1 << (i-1);
794 } 805 }
795 } 806 }
796 list.append( QString::number( days ) ); 807 list.append( QString::number( days ) );
797 } 808 }
798 //pending weekdays 809 //pending weekdays
799 writeEndDate = true; 810 writeEndDate = true;
800 811
801 break; 812 break;
802 case Recurrence::rMonthlyPos:// 2 813 case Recurrence::rMonthlyPos:// 2
803 list.append( "2" ); 814 list.append( "2" );
804 list.append( QString::number( rec->frequency()) );//12 815 list.append( QString::number( rec->frequency()) );//12
805 816
806 writeEndDate = true; 817 writeEndDate = true;
807 { 818 {
808 int count = 1; 819 int count = 1;
809 QPtrList<Recurrence::rMonthPos> rmp; 820 QPtrList<Recurrence::rMonthPos> rmp;
810 rmp = rec->monthPositions(); 821 rmp = rec->monthPositions();
811 if ( rmp.first()->negative ) 822 if ( rmp.first()->negative )
812 count = 5 - rmp.first()->rPos - 1; 823 count = 5 - rmp.first()->rPos - 1;
813 else 824 else
814 count = rmp.first()->rPos - 1; 825 count = rmp.first()->rPos - 1;
815 list.append( QString::number( count ) ); 826 list.append( QString::number( count ) );
816 827
817 } 828 }
818 829
819 list.append( "0" ); 830 list.append( "0" );
820 break; 831 break;
821 case Recurrence::rMonthlyDay:// 3 832 case Recurrence::rMonthlyDay:// 3
822 list.append( "3" ); 833 list.append( "3" );
823 list.append( QString::number( rec->frequency()) );//12 834 list.append( QString::number( rec->frequency()) );//12
824 list.append( "0" ); 835 list.append( "0" );
825 list.append( "0" ); 836 list.append( "0" );
826 writeEndDate = true; 837 writeEndDate = true;
827 break; 838 break;
828 case Recurrence::rYearlyMonth://4 839 case Recurrence::rYearlyMonth://4
829 list.append( "4" ); 840 list.append( "4" );
830 list.append( QString::number( rec->frequency()) );//12 841 list.append( QString::number( rec->frequency()) );//12
831 list.append( "0" ); 842 list.append( "0" );
832 list.append( "0" ); 843 list.append( "0" );
833 writeEndDate = true; 844 writeEndDate = true;
834 break; 845 break;
835 846
836 default: 847 default:
837 list.append( "255" ); 848 list.append( "255" );
838 list.append( QString() ); 849 list.append( QString() );
839 list.append( "0" ); 850 list.append( "0" );
840 list.append( QString() ); 851 list.append( QString() );
841 list.append( "0" ); 852 list.append( "0" );
842 list.append( "20991231T000000" ); 853 list.append( "20991231T000000" );
843 break; 854 break;
844 } 855 }
845 if ( writeEndDate ) { 856 if ( writeEndDate ) {
846 857
847 if ( rec->endDate().isValid() ) { // 15 + 16 858 if ( rec->endDate().isValid() ) { // 15 + 16
848 list.append( "1" ); 859 list.append( "1" );
849 list.append( dtToString( rec->endDate()) ); 860 list.append( dtToString( rec->endDate()) );
850 } else { 861 } else {
851 list.append( "0" ); 862 list.append( "0" );
852 list.append( "20991231T000000" ); 863 list.append( "20991231T000000" );
853 } 864 }
854 865
855 } 866 }
856 if ( event->doesFloat () ) { 867 if ( event->doesFloat () ) {
857 list.append( dtToString( event->dtStart(), false ).left( 8 )); 868 list.append( dtToString( event->dtStart(), false ).left( 8 ));
858 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6 869 list.append( dtToString( event->dtEnd(), false ).left( 8 )); //6
859 870
860 } 871 }
861 else { 872 else {
862 list.append( QString() ); 873 list.append( QString() );
863 list.append( QString() ); 874 list.append( QString() );
864 875
865 } 876 }
866 if (event->dtStart().date() == event->dtEnd().date() ) 877 if (event->dtStart().date() == event->dtEnd().date() )
867 list.append( "0" ); 878 list.append( "0" );
868 else 879 else
869 list.append( "1" ); 880 list.append( "1" );
870 881
871 882
872 for(QStringList::Iterator it=list.begin(); 883 for(QStringList::Iterator it=list.begin();
873 it!=list.end(); ++it){ 884 it!=list.end(); ++it){
874 QString& s = (*it); 885 QString& s = (*it);
875 s.replace(QRegExp("\""), "\"\""); 886 s.replace(QRegExp("\""), "\"\"");
876 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 887 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
877 s.prepend('\"'); 888 s.prepend('\"');
878 s.append('\"'); 889 s.append('\"');
879 } else if(s.isEmpty() && !s.isNull()){ 890 } else if(s.isEmpty() && !s.isNull()){
880 s = "\"\""; 891 s = "\"\"";
881 } 892 }
882 } 893 }
883 return list.join(","); 894 return list.join(",");
884 895
885 896
886} 897}
887QString SharpFormat::getTodoString( Todo* todo ) 898QString SharpFormat::getTodoString( Todo* todo )
888{ 899{
889 QStringList list; 900 QStringList list;
890 list.append( todo->getID("Sharp_DTM") ); 901 list.append( todo->getID("Sharp_DTM") );
891 list.append( todo->categories().join(",") ); 902 list.append( todo->categories().join(",") );
892 903
893 if ( todo->hasStartDate() ) { 904 if ( todo->hasStartDate() ) {
894 list.append( dtToString( todo->dtStart()) ); 905 list.append( dtToString( todo->dtStart()) );
895 } else 906 } else
896 list.append( QString() ); 907 list.append( QString() );
897 908
898 if ( todo->hasDueDate() ) { 909 if ( todo->hasDueDate() ) {
899 QTime tim; 910 QTime tim;
900 if ( todo->doesFloat()) { 911 if ( todo->doesFloat()) {
901 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ; 912 list.append( dtToString( QDateTime(todo->dtDue().date(),QTime( 0,0,0 )), false)) ;
902 } else { 913 } else {
903 list.append( dtToString(todo->dtDue() ) ); 914 list.append( dtToString(todo->dtDue() ) );
904 } 915 }
905 } else 916 } else
906 list.append( QString() ); 917 list.append( QString() );
907 918
908 if ( todo->isCompleted() ) { 919 if ( todo->isCompleted() ) {
909 list.append( dtToString( todo->completed()) ); 920 list.append( dtToString( todo->completed()) );
910 list.append( "0" ); // yes 0 == completed 921 list.append( "0" ); // yes 0 == completed
911 } else { 922 } else {
912 list.append( dtToString( todo->completed()) ); 923 list.append( dtToString( todo->completed()) );
913 list.append( "1" ); 924 list.append( "1" );
914 } 925 }
915 list.append( QString::number( todo->priority() )); 926 list.append( QString::number( todo->priority() ));
916 if( ! todo->summary().isEmpty() ) 927 if( ! todo->summary().isEmpty() )
917 list.append( todo->summary() ); 928 list.append( todo->summary() );
918 else 929 else
919 list.append( "" ); 930 list.append( "" );
920 if (! todo->description().isEmpty() ) 931 if (! todo->description().isEmpty() )
921 list.append( todo->description() ); 932 list.append( todo->description() );
922 else 933 else
923 list.append( "" ); 934 list.append( "" );
924 for(QStringList::Iterator it=list.begin(); 935 for(QStringList::Iterator it=list.begin();
925 it!=list.end(); ++it){ 936 it!=list.end(); ++it){
926 QString& s = (*it); 937 QString& s = (*it);
927 s.replace(QRegExp("\""), "\"\""); 938 s.replace(QRegExp("\""), "\"\"");
928 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){ 939 if(s.contains(QRegExp("[,\"\r\n]")) || s.stripWhiteSpace() != s){
929 s.prepend('\"'); 940 s.prepend('\"');
930 s.append('\"'); 941 s.append('\"');
931 } else if(s.isEmpty() && !s.isNull()){ 942 } else if(s.isEmpty() && !s.isNull()){
932 s = "\"\""; 943 s = "\"\"";
933 } 944 }
934 } 945 }
935 return list.join(","); 946 return list.join(",");
936} 947}
937QString SharpFormat::getPart( const QString & text, bool &ok, int &start ) 948QString SharpFormat::getPart( const QString & text, bool &ok, int &start )
938{ 949{
939 //qDebug("start %d ", start); 950 //qDebug("start %d ", start);
940 951
941 QString retval =""; 952 QString retval ="";
942 if ( text.at(start) == '"' ) { 953 if ( text.at(start) == '"' ) {
943 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) { 954 if ( text.mid( start,2) == "\"\"" && !( text.mid( start+2,1) == "\"")) {
944 start = start +2; 955 start = start +2;
945 if ( text.mid( start,1) == "," ) { 956 if ( text.mid( start,1) == "," ) {
946 start += 1; 957 start += 1;
947 } 958 }
948 retval = ""; 959 retval = "";
949 if ( text.mid( start,1) == "\n" ) { 960 if ( text.mid( start,1) == "\n" ) {
950 start += 1; 961 start += 1;
951 ok = false; 962 ok = false;
952 } 963 }
953 return retval; 964 return retval;
954 } 965 }
955 int hk = start+1; 966 int hk = start+1;
956 hk = text.find ('"',hk); 967 hk = text.find ('"',hk);
957 while ( text.at(hk+1) == '"' ) 968 while ( text.at(hk+1) == '"' )
958 hk = text.find ('"',hk+2); 969 hk = text.find ('"',hk+2);
959 retval = text.mid( start+1, hk-start-1); 970 retval = text.mid( start+1, hk-start-1);
960 start = hk+1; 971 start = hk+1;
961 retval.replace( QRegExp("\"\""), "\""); 972 retval.replace( QRegExp("\"\""), "\"");
962 if ( text.mid( start,1) == "," ) { 973 if ( text.mid( start,1) == "," ) {
963 start += 1; 974 start += 1;
964 } 975 }
965 if ( text.mid( start,1) == "\n" ) { 976 if ( text.mid( start,1) == "\n" ) {
966 start += 1; 977 start += 1;
967 ok = false; 978 ok = false;
968 } 979 }
969 //qDebug("retval***%s*** ",retval.latin1() ); 980 //qDebug("retval***%s*** ",retval.latin1() );
970 return retval; 981 return retval;
971 982
972 } else { 983 } else {
973 int nl = text.find ("\n",start); 984 int nl = text.find ("\n",start);
974 int kom = text.find (',',start); 985 int kom = text.find (',',start);
975 if ( kom < nl ) { 986 if ( kom < nl ) {
976 // qDebug("kom < nl %d ", kom); 987 // qDebug("kom < nl %d ", kom);
977 retval = text.mid(start, kom-start); 988 retval = text.mid(start, kom-start);
978 start = kom+1; 989 start = kom+1;
979 return retval; 990 return retval;
980 } else { 991 } else {
981 if ( nl == kom ) { 992 if ( nl == kom ) {
982 // qDebug(" nl == kom "); 993 // qDebug(" nl == kom ");
983 start = 0; 994 start = 0;
984 ok = false; 995 ok = false;
985 return "0"; 996 return "0";
986 } 997 }
987 // qDebug(" nl < kom ", nl); 998 // qDebug(" nl < kom ", nl);
988 retval = text.mid( start, nl-start); 999 retval = text.mid( start, nl-start);
989 ok = false; 1000 ok = false;
990 start = nl+1; 1001 start = nl+1;
991 return retval; 1002 return retval;
992 } 1003 }
993 } 1004 }
994} 1005}
995bool SharpFormat::fromString( Calendar *calendar, const QString & text) 1006bool SharpFormat::fromString( Calendar *calendar, const QString & text)
996{ 1007{
997 return false; 1008 return false;
998} 1009}
999bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type) 1010bool SharpFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, const QString & text, const QString & type)
1000{ 1011{
1001 // qDebug("test %s ", text.latin1()); 1012 // qDebug("test %s ", text.latin1());
1002 QStringList templist; 1013 QStringList templist;
1003 QString tempString; 1014 QString tempString;
1004 int start = 0; 1015 int start = 0;
1005 int len = text.length(); 1016 int len = text.length();
1006 int end = text.find ("\n",start)+1; 1017 int end = text.find ("\n",start)+1;
1007 bool ok = true; 1018 bool ok = true;
1008 start = end; 1019 start = end;
1009 SharpParser handler( calendar ); 1020 SharpParser handler( calendar );
1010 handler.setCategoriesList( mCategories ); 1021 handler.setCategoriesList( mCategories );
1011 while ( start > 0 ) { 1022 while ( start > 0 ) {
1012 templist.clear(); 1023 templist.clear();
1013 ok = true; 1024 ok = true;
1014 while ( ok ) { 1025 while ( ok ) {
1015 tempString = getPart( text, ok, start ); 1026 tempString = getPart( text, ok, start );
1016 if ( start >= len || start == 0 ) { 1027 if ( start >= len || start == 0 ) {
1017 start = 0; 1028 start = 0;
1018 ok = false; 1029 ok = false;
1019 } 1030 }
1020 if ( tempString.right(1) =="\n" ) 1031 if ( tempString.right(1) =="\n" )
1021 tempString = tempString.left( tempString.length()-1); 1032 tempString = tempString.left( tempString.length()-1);
1022 //if ( ok ) 1033 //if ( ok )
1023 templist.append( tempString ); 1034 templist.append( tempString );
1024 //qDebug("%d ---%s---", templist.count(),tempString.latin1() ); 1035 //qDebug("%d ---%s---", templist.count(),tempString.latin1() );
1025 } 1036 }
1026 handler.startElement( existingCalendar, templist, type ); 1037 handler.startElement( existingCalendar, templist, type );
1027 } 1038 }
1028 1039
1029 return false; 1040 return false;
1030} 1041}
1031 1042
1032QString SharpFormat::toString( Calendar * ) 1043QString SharpFormat::toString( Calendar * )
1033{ 1044{
1034 return QString::null; 1045 return QString::null;
1035} 1046}