summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-12-04 04:53:22 (UTC)
committer zautrix <zautrix>2004-12-04 04:53:22 (UTC)
commit7828f46413766ee5db72dc9bd457eac0868f0646 (patch) (unidiff)
treed3da09120bdef2b498f836c5b1b97a5b2aa2da99 /libkcal
parent967f7c879d06961dd7a25d019380c521f7a84792 (diff)
downloadkdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.zip
kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.gz
kdepimpi-7828f46413766ee5db72dc9bd457eac0868f0646.tar.bz2
fixed some bugs
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/sharpformat.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp
index 24b8349..c2ee2c9 100644
--- a/libkcal/sharpformat.cpp
+++ b/libkcal/sharpformat.cpp
@@ -1,514 +1,517 @@
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 } 67 }
68 68
69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName )
70 { 70 {
71 int i = 1; 71 int i = 1;
72 bool skip = true; 72 bool skip = true;
73 int max = attList.count() -2; 73 int max = attList.count() -2;
74 while ( i < max ) { 74 while ( i < max ) {
75 if ( !attList[i].isEmpty() ) { 75 if ( !attList[i].isEmpty() ) {
76 skip = false; 76 skip = false;
77 break; 77 break;
78 } 78 }
79 ++i ; 79 ++i ;
80 } 80 }
81 if ( skip ) 81 if ( skip )
82 return false; 82 return false;
83 ulong cSum = SharpFormat::getCsum(attList ); 83 ulong cSum = SharpFormat::getCsum(attList );
84 84
85 if ( qName == "Event" ) { 85 if ( qName == "Event" ) {
86 Event *event; 86 Event *event;
87 event = existingCalendar->event( "Sharp_DTM",attList[0] ); 87 event = existingCalendar->event( "Sharp_DTM",attList[0] );
88 if ( event ) 88 if ( event )
89 event = (Event*)event->clone(); 89 event = (Event*)event->clone();
90 else 90 else
91 event = new Event; 91 event = new Event;
92 event->setID("Sharp_DTM", attList[0] ); 92 event->setID("Sharp_DTM", attList[0] );
93 event->setCsum( "Sharp_DTM", QString::number( cSum )); 93 event->setCsum( "Sharp_DTM", QString::number( cSum ));
94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); 94 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
95 95
96 event->setSummary( attList[2] ); 96 event->setSummary( attList[2] );
97 event->setLocation( attList[3] ); 97 event->setLocation( attList[3] );
98 event->setDescription( attList[4] ); 98 event->setDescription( attList[4] );
99 if ( attList[7] == "1" ) { 99 if ( attList[7] == "1" ) {
100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) ));
101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 )));
102 event->setFloats( true ); 102 event->setFloats( true );
103 } else { 103 } else {
104 event->setFloats( false ); 104 event->setFloats( false );
105 event->setDtStart( fromString( attList[5] ) ); 105 event->setDtStart( fromString( attList[5] ) );
106 event->setDtEnd( fromString( attList[6] )); 106 event->setDtEnd( fromString( attList[6] ));
107 } 107 }
108 108
109 QString rtype = attList[11]; 109 QString rtype = attList[11];
110 if ( rtype != "255" ) { 110 if ( rtype != "255" ) {
111 // qDebug("recurs "); 111 // qDebug("recurs ");
112 QDate startDate = event->dtStart().date(); 112 QDate startDate = event->dtStart().date();
113 113
114 QString freqStr = attList[12]; 114 QString freqStr = attList[12];
115 int freq = freqStr.toInt(); 115 int freq = freqStr.toInt();
116 116
117 QString hasEndDateStr = attList[15] ; 117 QString hasEndDateStr = attList[15] ;
118 bool hasEndDate = hasEndDateStr == "1"; 118 bool hasEndDate = hasEndDateStr == "1";
119 119
120 QString endDateStr = attList[16]; 120 QString endDateStr = attList[16];
121 QDate endDate = fromString( endDateStr ).date(); 121 QDate endDate = fromString( endDateStr ).date();
122 122
123 QString weekDaysStr = attList[14]; 123 QString weekDaysStr = attList[14];
124 uint weekDaysNum = weekDaysStr.toInt(); 124 uint weekDaysNum = weekDaysStr.toInt();
125 125
126 QBitArray weekDays( 7 ); 126 QBitArray weekDays( 7 );
127 int i; 127 int i;
128 int bb = 1; 128 int bb = 1;
129 for( i = 1; i <= 7; ++i ) { 129 for( i = 1; i <= 7; ++i ) {
130 weekDays.setBit( i - 1, ( bb & weekDaysNum )); 130 weekDays.setBit( i - 1, ( bb & weekDaysNum ));
131 bb = 2 << (i-1); 131 bb = 2 << (i-1);
132 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 132 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
133 } 133 }
134 // qDebug("next "); 134 // qDebug("next ");
135 QString posStr = attList[13]; 135 QString posStr = attList[13];
136 int pos = posStr.toInt(); 136 int pos = posStr.toInt();
137 Recurrence *r = event->recurrence(); 137 Recurrence *r = event->recurrence();
138 138
139 if ( rtype == "0" ) { 139 if ( rtype == "0" ) {
140 if ( hasEndDate ) r->setDaily( freq, endDate ); 140 if ( hasEndDate ) r->setDaily( freq, endDate );
141 else r->setDaily( freq, -1 ); 141 else r->setDaily( freq, -1 );
142 } else if ( rtype == "1" ) { 142 } else if ( rtype == "1" ) {
143 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 143 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
144 else r->setWeekly( freq, weekDays, -1 ); 144 else r->setWeekly( freq, weekDays, -1 );
145 } else if ( rtype == "3" ) { 145 } else if ( rtype == "3" ) {
146 if ( hasEndDate ) 146 if ( hasEndDate )
147 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 147 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
148 else 148 else
149 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 149 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
150 r->addMonthlyDay( startDate.day() ); 150 r->addMonthlyDay( startDate.day() );
151 } else if ( rtype == "2" ) { 151 } else if ( rtype == "2" ) {
152 if ( hasEndDate ) 152 if ( hasEndDate )
153 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 153 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
154 else 154 else
155 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 155 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
156 QBitArray days( 7 ); 156 QBitArray days( 7 );
157 days.fill( false ); 157 days.fill( false );
158 days.setBit( startDate.dayOfWeek() - 1 ); 158 days.setBit( startDate.dayOfWeek() - 1 );
159 r->addMonthlyPos( pos, days ); 159 r->addMonthlyPos( pos, days );
160 } else if ( rtype == "4" ) { 160 } else if ( rtype == "4" ) {
161 if ( hasEndDate ) 161 if ( hasEndDate )
162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
163 else 163 else
164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
165 r->addYearlyNum( startDate.month() ); 165 r->addYearlyNum( startDate.month() );
166 } 166 }
167 } else { 167 } else {
168 event->recurrence()->unsetRecurs(); 168 event->recurrence()->unsetRecurs();
169 } 169 }
170 170
171 QString categoryList = attList[1] ; 171 QString categoryList = attList[1] ;
172 event->setCategories( categoryList ); 172 event->setCategories( categoryList );
173 173
174 // strange 0 semms to mean: alarm enabled 174 // strange 0 semms to mean: alarm enabled
175 if ( attList[8] == "0" ) { 175 if ( attList[8] == "0" ) {
176 Alarm *alarm; 176 Alarm *alarm;
177 if ( event->alarms().count() > 0 ) 177 if ( event->alarms().count() > 0 )
178 alarm = event->alarms().first(); 178 alarm = event->alarms().first();
179 else { 179 else {
180 alarm = new Alarm( event ); 180 alarm = new Alarm( event );
181 event->addAlarm( alarm ); 181 event->addAlarm( alarm );
182 alarm->setType( Alarm::Audio ); 182 alarm->setType( Alarm::Audio );
183 } 183 }
184 //alarm->setType( Alarm::Audio ); 184 //alarm->setType( Alarm::Audio );
185 alarm->setEnabled( true ); 185 alarm->setEnabled( true );
186 int alarmOffset = attList[9].toInt(); 186 int alarmOffset = attList[9].toInt();
187 alarm->setStartOffset( alarmOffset * -60 ); 187 alarm->setStartOffset( alarmOffset * -60 );
188 } else { 188 } else {
189 Alarm *alarm; 189 Alarm *alarm;
190 if ( event->alarms().count() > 0 ) { 190 if ( event->alarms().count() > 0 ) {
191 alarm = event->alarms().first(); 191 alarm = event->alarms().first();
192 alarm->setType( Alarm::Audio ); 192 alarm->setType( Alarm::Audio );
193 alarm->setStartOffset( -60*15 ); 193 alarm->setStartOffset( -60*15 );
194 alarm->setEnabled( false ); 194 alarm->setEnabled( false );
195 } 195 }
196 } 196 }
197 197
198 mCalendar->addEvent( event); 198 mCalendar->addEvent( event);
199 } else if ( qName == "Todo" ) { 199 } else if ( qName == "Todo" ) {
200 Todo *todo; 200 Todo *todo;
201 201
202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] ); 202 todo = existingCalendar->todo( "Sharp_DTM", attList[0] );
203 if (todo ) 203 if (todo )
204 todo = (Todo*)todo->clone(); 204 todo = (Todo*)todo->clone();
205 else 205 else
206 todo = new Todo; 206 todo = new Todo;
207 207
208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1 208//CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1
209// 0 1 2 3 4 5 6 7 8 209// 0 1 2 3 4 5 6 7 8
210//1,,,,,1,4,Loch zumachen,"" 210//1,,,,,1,4,Loch zumachen,""
211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" " 211//3,Privat,20040317T000000,20040318T000000,20040319T000000,0,5,Call bbb,"notes123 bbb gggg ""bb "" "
212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes 212//2,"Familie,Freunde,Holiday",20040318T000000,20040324T000000,20040317T000000,1,2,tod2,notes
213 213
214 todo->setID( "Sharp_DTM", attList[0]); 214 todo->setID( "Sharp_DTM", attList[0]);
215 todo->setCsum( "Sharp_DTM", QString::number( cSum )); 215 todo->setCsum( "Sharp_DTM", QString::number( cSum ));
216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 216 todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
217 217
218 todo->setSummary( attList[7] ); 218 todo->setSummary( attList[7] );
219 todo->setDescription( attList[8]); 219 todo->setDescription( attList[8]);
220 220
221 int priority = attList[6].toInt(); 221 int priority = attList[6].toInt();
222 if ( priority == 0 ) priority = 3; 222 if ( priority == 0 ) priority = 3;
223 todo->setPriority( priority ); 223 todo->setPriority( priority );
224 224
225 QString categoryList = attList[1]; 225 QString categoryList = attList[1];
226 todo->setCategories( categoryList ); 226 todo->setCategories( categoryList );
227 227
228 228
229 229
230 QString hasDateStr = attList[3]; // due 230 QString hasDateStr = attList[3]; // due
231 if ( !hasDateStr.isEmpty() ) { 231 if ( !hasDateStr.isEmpty() ) {
232 if ( hasDateStr.right(6) == "000000" ) { 232 if ( hasDateStr.right(6) == "000000" ) {
233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) ); 233 todo->setDtDue( QDateTime(fromString( hasDateStr, false ).date(), QTime(0,0,0 )) );
234 todo->setFloats( true ); 234 todo->setFloats( true );
235 } 235 }
236 else { 236 else {
237 todo->setDtDue( fromString( hasDateStr ) ); 237 todo->setDtDue( fromString( hasDateStr ) );
238 todo->setFloats( false ); 238 todo->setFloats( false );
239 } 239 }
240 240
241 todo->setHasDueDate( true ); 241 todo->setHasDueDate( true );
242 } 242 }
243 hasDateStr = attList[2];//start 243 hasDateStr = attList[2];//start
244 if ( !hasDateStr.isEmpty() ) { 244 if ( !hasDateStr.isEmpty() ) {
245 245
246 todo->setDtStart( fromString( hasDateStr ) ); 246 todo->setDtStart( fromString( hasDateStr ) );
247 todo->setHasStartDate( true); 247 todo->setHasStartDate( true);
248 } else 248 } else
249 todo->setHasStartDate( false ); 249 todo->setHasStartDate( false );
250 hasDateStr = attList[4];//completed 250 hasDateStr = attList[4];//completed
251 if ( !hasDateStr.isEmpty() ) { 251 if ( !hasDateStr.isEmpty() ) {
252 todo->setCompleted(fromString( hasDateStr ) ); 252 todo->setCompleted(fromString( hasDateStr ) );
253 } 253 }
254 QString completedStr = attList[5]; 254 QString completedStr = attList[5];
255 if ( completedStr == "0" ) 255 if ( completedStr == "0" )
256 todo->setCompleted( true ); 256 todo->setCompleted( true );
257 else 257 else {
258 todo->setCompleted( false ); 258 // do not change percent complete
259 if ( todo->isCompleted() )
260 todo->setCompleted( false );
261 }
259 mCalendar->addTodo( todo ); 262 mCalendar->addTodo( todo );
260 263
261 } else if ( qName == "Category" ) { 264 } else if ( qName == "Category" ) {
262 /* 265 /*
263 QString id = attributes.value( "id" ); 266 QString id = attributes.value( "id" );
264 QString name = attributes.value( "name" ); 267 QString name = attributes.value( "name" );
265 setCategory( id, name ); 268 setCategory( id, name );
266 */ 269 */
267 } 270 }
268 //qDebug("end "); 271 //qDebug("end ");
269 return true; 272 return true;
270 } 273 }
271 274
272 275
273 QDateTime fromString ( QString s, bool useTz = true ) { 276 QDateTime fromString ( QString s, bool useTz = true ) {
274 QDateTime dt; 277 QDateTime dt;
275 int y,m,t,h,min,sec; 278 int y,m,t,h,min,sec;
276 y = s.mid(0,4).toInt(); 279 y = s.mid(0,4).toInt();
277 m = s.mid(4,2).toInt(); 280 m = s.mid(4,2).toInt();
278 t = s.mid(6,2).toInt(); 281 t = s.mid(6,2).toInt();
279 h = s.mid(9,2).toInt(); 282 h = s.mid(9,2).toInt();
280 min = s.mid(11,2).toInt(); 283 min = s.mid(11,2).toInt();
281 sec = s.mid(13,2).toInt(); 284 sec = s.mid(13,2).toInt();
282 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 285 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
283 int offset = KGlobal::locale()->localTimeOffset( dt ); 286 int offset = KGlobal::locale()->localTimeOffset( dt );
284 if ( useTz ) 287 if ( useTz )
285 dt = dt.addSecs ( offset*60); 288 dt = dt.addSecs ( offset*60);
286 return dt; 289 return dt;
287 290
288 } 291 }
289 protected: 292 protected:
290 QDateTime toDateTime( const QString &value ) 293 QDateTime toDateTime( const QString &value )
291 { 294 {
292 QDateTime dt; 295 QDateTime dt;
293 dt.setTime_t( value.toUInt() ); 296 dt.setTime_t( value.toUInt() );
294 297
295 return dt; 298 return dt;
296 } 299 }
297 300
298 private: 301 private:
299 Calendar *mCalendar; 302 Calendar *mCalendar;
300}; 303};
301 304
302 305
303SharpFormat::SharpFormat() 306SharpFormat::SharpFormat()
304{ 307{
305 308
306} 309}
307 310
308SharpFormat::~SharpFormat() 311SharpFormat::~SharpFormat()
309{ 312{
310} 313}
311ulong SharpFormat::getCsum( const QStringList & attList) 314ulong SharpFormat::getCsum( const QStringList & attList)
312{ 315{
313 int max = attList.count() -1; 316 int max = attList.count() -1;
314 ulong cSum = 0; 317 ulong cSum = 0;
315 int j,k,i; 318 int j,k,i;
316 int add; 319 int add;
317 for ( i = 1; i < max ; ++i ) { 320 for ( i = 1; i < max ; ++i ) {
318 QString s = attList[i]; 321 QString s = attList[i];
319 if ( ! s.isEmpty() ){ 322 if ( ! s.isEmpty() ){
320 j = s.length(); 323 j = s.length();
321 for ( k = 0; k < j; ++k ) { 324 for ( k = 0; k < j; ++k ) {
322 int mul = k +1; 325 int mul = k +1;
323 add = s[k].unicode (); 326 add = s[k].unicode ();
324 if ( k < 16 ) 327 if ( k < 16 )
325 mul = mul * mul; 328 mul = mul * mul;
326 add = add * mul *i*i*i; 329 add = add * mul *i*i*i;
327 cSum += add; 330 cSum += add;
328 } 331 }
329 } 332 }
330 } 333 }
331 return cSum; 334 return cSum;
332 335
333} 336}
334#include <stdlib.h> 337#include <stdlib.h>
335#define DEBUGMODE false 338#define DEBUGMODE false
336//#define DEBUGMODE true 339//#define DEBUGMODE true
337bool SharpFormat::load( Calendar *calendar, Calendar *existngCal ) 340bool SharpFormat::load( Calendar *calendar, Calendar *existngCal )
338{ 341{
339 342
340 343
341 bool debug = DEBUGMODE; 344 bool debug = DEBUGMODE;
342 QString text; 345 QString text;
343 QString codec = "utf8"; 346 QString codec = "utf8";
344 QLabel status ( i18n("Reading events ..."), 0 ); 347 QLabel status ( i18n("Reading events ..."), 0 );
345 348
346 int w = status.sizeHint().width()+20 ; 349 int w = status.sizeHint().width()+20 ;
347 if ( w < 200 ) w = 200; 350 if ( w < 200 ) w = 200;
348 int h = status.sizeHint().height()+20 ; 351 int h = status.sizeHint().height()+20 ;
349 int dw = QApplication::desktop()->width(); 352 int dw = QApplication::desktop()->width();
350 int dh = QApplication::desktop()->height(); 353 int dh = QApplication::desktop()->height();
351 status.setCaption(i18n("Reading DTM Data") ); 354 status.setCaption(i18n("Reading DTM Data") );
352 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 355 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
353 status.show(); 356 status.show();
354 status.raise(); 357 status.raise();
355 qApp->processEvents(); 358 qApp->processEvents();
356 QString fileName; 359 QString fileName;
357 if ( ! debug ) { 360 if ( ! debug ) {
358 fileName = "/tmp/kopitempout"; 361 fileName = "/tmp/kopitempout";
359 QString command ="db2file datebook -r -c "+ codec + " > " + fileName; 362 QString command ="db2file datebook -r -c "+ codec + " > " + fileName;
360 system ( command.latin1() ); 363 system ( command.latin1() );
361 } else { 364 } else {
362 fileName = "/tmp/events.txt"; 365 fileName = "/tmp/events.txt";
363 366
364 } 367 }
365 QFile file( fileName ); 368 QFile file( fileName );
366 if (!file.open( IO_ReadOnly ) ) { 369 if (!file.open( IO_ReadOnly ) ) {
367 return false; 370 return false;
368 371
369 } 372 }
370 QTextStream ts( &file ); 373 QTextStream ts( &file );
371 ts.setCodec( QTextCodec::codecForName("utf8") ); 374 ts.setCodec( QTextCodec::codecForName("utf8") );
372 text = ts.read(); 375 text = ts.read();
373 file.close(); 376 file.close();
374 status.setText( i18n("Processing events ...") ); 377 status.setText( i18n("Processing events ...") );
375 status.raise(); 378 status.raise();
376 qApp->processEvents(); 379 qApp->processEvents();
377 fromString2Cal( calendar, existngCal, text, "Event" ); 380 fromString2Cal( calendar, existngCal, text, "Event" );
378 status.setText( i18n("Reading todos ...") ); 381 status.setText( i18n("Reading todos ...") );
379 qApp->processEvents(); 382 qApp->processEvents();
380 if ( ! debug ) { 383 if ( ! debug ) {
381 fileName = "/tmp/kopitempout"; 384 fileName = "/tmp/kopitempout";
382 QString command = "db2file todo -r -c " + codec+ " > " + fileName; 385 QString command = "db2file todo -r -c " + codec+ " > " + fileName;
383 system ( command.latin1() ); 386 system ( command.latin1() );
384 } else { 387 } else {
385 fileName = "/tmp/todo.txt"; 388 fileName = "/tmp/todo.txt";
386 } 389 }
387 file.setName( fileName ); 390 file.setName( fileName );
388 if (!file.open( IO_ReadOnly ) ) { 391 if (!file.open( IO_ReadOnly ) ) {
389 return false; 392 return false;
390 393
391 } 394 }
392 ts.setDevice( &file ); 395 ts.setDevice( &file );
393 text = ts.read(); 396 text = ts.read();
394 file.close(); 397 file.close();
395 398
396 status.setText( i18n("Processing todos ...") ); 399 status.setText( i18n("Processing todos ...") );
397 status.raise(); 400 status.raise();
398 qApp->processEvents(); 401 qApp->processEvents();
399 fromString2Cal( calendar, existngCal, text, "Todo" ); 402 fromString2Cal( calendar, existngCal, text, "Todo" );
400 return true; 403 return true;
401} 404}
402int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) 405int SharpFormat::getNumFromRecord( QString answer, Incidence* inc )
403{ 406{
404 int retval = -1; 407 int retval = -1;
405 QStringList templist; 408 QStringList templist;
406 QString tempString; 409 QString tempString;
407 int start = 0; 410 int start = 0;
408 int len = answer.length(); 411 int len = answer.length();
409 int end = answer.find ("\n",start)+1; 412 int end = answer.find ("\n",start)+1;
410 bool ok = true; 413 bool ok = true;
411 start = end; 414 start = end;
412 int ccc = 0; 415 int ccc = 0;
413 while ( start > 0 ) { 416 while ( start > 0 ) {
414 templist.clear(); 417 templist.clear();
415 ok = true; 418 ok = true;
416 int loopCount = 0; 419 int loopCount = 0;
417 while ( ok ) { 420 while ( ok ) {
418 ++loopCount; 421 ++loopCount;
419 if ( loopCount > 25 ) { 422 if ( loopCount > 25 ) {
420 qDebug("KO: Error in while loop"); 423 qDebug("KO: Error in while loop");
421 ok = false; 424 ok = false;
422 start = 0; 425 start = 0;
423 break; 426 break;
424 } 427 }
425 if ( ok ) 428 if ( ok )
426 tempString = getPart( answer, ok, start ); 429 tempString = getPart( answer, ok, start );
427 if ( start >= len || start == 0 ) { 430 if ( start >= len || start == 0 ) {
428 start = 0; 431 start = 0;
429 ok = false; 432 ok = false;
430 } 433 }
431 if ( tempString.right(1) =="\n" ) 434 if ( tempString.right(1) =="\n" )
432 tempString = tempString.left( tempString.length()-1); 435 tempString = tempString.left( tempString.length()-1);
433 436
434 templist.append( tempString ); 437 templist.append( tempString );
435 } 438 }
436 ++ccc; 439 ++ccc;
437 if ( ccc == 2 && loopCount < 25 ) { 440 if ( ccc == 2 && loopCount < 25 ) {
438 start = 0; 441 start = 0;
439 bool ok; 442 bool ok;
440 int newnum = templist[0].toInt( &ok ); 443 int newnum = templist[0].toInt( &ok );
441 if ( ok && newnum > 0) { 444 if ( ok && newnum > 0) {
442 retval = newnum; 445 retval = newnum;
443 inc->setID( "Sharp_DTM",templist[0] ); 446 inc->setID( "Sharp_DTM",templist[0] );
444 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) )); 447 inc->setCsum( "Sharp_DTM", QString::number( getCsum( templist ) ));
445 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 448 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
446 } 449 }
447 if ( ok && newnum == -1 ) { 450 if ( ok && newnum == -1 ) {
448 qDebug("Error writing back %s ", inc->summary().latin1()); 451 qDebug("Error writing back %s ", inc->summary().latin1());
449 } 452 }
450 } 453 }
451 } 454 }
452 //qDebug("getNumFromRecord returning : %d ", retval); 455 //qDebug("getNumFromRecord returning : %d ", retval);
453 return retval; 456 return retval;
454} 457}
455bool SharpFormat::save( Calendar *calendar) 458bool SharpFormat::save( Calendar *calendar)
456{ 459{
457 460
458 QLabel status ( i18n("Processing/adding events ..."), 0 ); 461 QLabel status ( i18n("Processing/adding events ..."), 0 );
459 int w = status.sizeHint().width()+20 ; 462 int w = status.sizeHint().width()+20 ;
460 if ( w < 200 ) w = 200; 463 if ( w < 200 ) w = 200;
461 int h = status.sizeHint().height()+20 ; 464 int h = status.sizeHint().height()+20 ;
462 int dw = QApplication::desktop()->width(); 465 int dw = QApplication::desktop()->width();
463 int dh = QApplication::desktop()->height(); 466 int dh = QApplication::desktop()->height();
464 status.setCaption(i18n("Writing DTM Data") ); 467 status.setCaption(i18n("Writing DTM Data") );
465 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 468 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
466 status.show(); 469 status.show();
467 status.raise(); 470 status.raise();
468 qApp->processEvents(); 471 qApp->processEvents();
469 bool debug = DEBUGMODE; 472 bool debug = DEBUGMODE;
470 QString codec = "utf8"; 473 QString codec = "utf8";
471 QString answer; 474 QString answer;
472 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n"; 475 QString ePrefix = "CARDID,CATEGORY,DSRP,PLCE,MEM1,TIM1,TIM2,ADAY,ARON,ARMN,ARSD,RTYP,RFRQ,RPOS,RDYS,REND,REDT,ALSD,ALED,MDAY\n";
473 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n"; 476 QString tPrefix = "CARDID,CATEGORY,ETDY,LTDY,FNDY,MARK,PRTY,TITL,MEM1\n";
474 QString command; 477 QString command;
475 QPtrList<Event> er = calendar->rawEvents(); 478 QPtrList<Event> er = calendar->rawEvents();
476 Event* ev = er.first(); 479 Event* ev = er.first();
477 QString fileName = "/tmp/kopitempout"; 480 QString fileName = "/tmp/kopitempout";
478 int i = 0; 481 int i = 0;
479 QString changeString = ePrefix; 482 QString changeString = ePrefix;
480 QString deleteString = ePrefix; 483 QString deleteString = ePrefix;
481 bool deleteEnt = false; 484 bool deleteEnt = false;
482 bool changeEnt = false; 485 bool changeEnt = false;
483 QString message = i18n("Processing event # "); 486 QString message = i18n("Processing event # ");
484 int procCount = 0; 487 int procCount = 0;
485 while ( ev ) { 488 while ( ev ) {
486 //qDebug("i %d ", ++i); 489 //qDebug("i %d ", ++i);
487 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { 490 if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
488 status.setText ( message + QString::number ( ++procCount ) ); 491 status.setText ( message + QString::number ( ++procCount ) );
489 qApp->processEvents(); 492 qApp->processEvents();
490 QString eString = getEventString( ev ); 493 QString eString = getEventString( ev );
491 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete 494 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
492 // deleting empty strings does not work. 495 // deleting empty strings does not work.
493 // we write first and x and then delete the record with the x 496 // we write first and x and then delete the record with the x
494 eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); 497 eString = eString.replace( QRegExp(",\"\""),",\"x\"" );
495 changeString += eString + "\n"; 498 changeString += eString + "\n";
496 deleteString += eString + "\n"; 499 deleteString += eString + "\n";
497 deleteEnt = true; 500 deleteEnt = true;
498 changeEnt = true; 501 changeEnt = true;
499 } 502 }
500 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new 503 else if ( ev->getID("Sharp_DTM").isEmpty() ) { // add new
501 QString fileNameIn = "/tmp/kopitempin"; 504 QString fileNameIn = "/tmp/kopitempin";
502 QFile fileIn( fileNameIn ); 505 QFile fileIn( fileNameIn );
503 if (!fileIn.open( IO_WriteOnly ) ) { 506 if (!fileIn.open( IO_WriteOnly ) ) {
504 return false; 507 return false;
505 } 508 }
506 QTextStream tsIn( &fileIn ); 509 QTextStream tsIn( &fileIn );
507 tsIn.setCodec( QTextCodec::codecForName("utf8") ); 510 tsIn.setCodec( QTextCodec::codecForName("utf8") );
508 tsIn << ePrefix << eString ; 511 tsIn << ePrefix << eString ;
509 fileIn.close(); 512 fileIn.close();
510 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName; 513 //command = "(echo \"" + ePrefix + eString + "\" ) | db2file datebook -w -g -c " + codec+ " > "+ fileName;
511 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName; 514 command = "(cat /tmp/kopitempin | db2file datebook -w -g -c " + codec+ ") > "+ fileName;
512 //qDebug("command ++++++++ "); 515 //qDebug("command ++++++++ ");
513 //qDebug("%s ",command.latin1()); 516 //qDebug("%s ",command.latin1());
514 //qDebug("command -------- "); 517 //qDebug("command -------- ");