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