summaryrefslogtreecommitdiffabout
path: root/libkcal/phoneformat.cpp
authorzautrix <zautrix>2004-08-07 21:04:24 (UTC)
committer zautrix <zautrix>2004-08-07 21:04:24 (UTC)
commita9c3191a42084b6631dededef1709fa67eb2c048 (patch) (unidiff)
tree9950e3c8fc54c2994a4a50417008921bfdc58889 /libkcal/phoneformat.cpp
parent809e502f4b6e84524c10fa963e2d17564e6b1af9 (diff)
downloadkdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.zip
kdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.tar.gz
kdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.tar.bz2
more phone sync
Diffstat (limited to 'libkcal/phoneformat.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp273
1 files changed, 213 insertions, 60 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index fa18683..fd6b6af 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -42,6 +42,7 @@
42#include "calendarlocal.h" 42#include "calendarlocal.h"
43 43
44#include "phoneformat.h" 44#include "phoneformat.h"
45#include "syncdefines.h"
45 46
46using namespace KCal; 47using namespace KCal;
47 48
@@ -62,12 +63,15 @@ using namespace KCal;
62class PhoneParser : public QObject 63class PhoneParser : public QObject
63{ 64{
64 public: 65 public:
65 PhoneParser( Calendar *calendar ) : mCalendar( calendar ) { 66 PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) {
66 oldCategories = 0; 67 oldCategories = 0;
67 } 68 }
68 69
69 bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) 70 bool startElement( Calendar *existingCalendar, GSM_CalendarEntry*Note, QString qName )
70 { 71 {
72 QStringList attList;
73 /*
74// pending csum
71 int i = 1; 75 int i = 1;
72 bool skip = true; 76 bool skip = true;
73 int max = attList.count() -2; 77 int max = attList.count() -2;
@@ -81,47 +85,159 @@ class PhoneParser : public QObject
81 if ( skip ) 85 if ( skip )
82 return false; 86 return false;
83 ulong cSum = PhoneFormat::getCsum(attList ); 87 ulong cSum = PhoneFormat::getCsum(attList );
84 88 */
85 if ( qName == "Event" ) { 89 if ( qName == "Event" ) {
90 int id = Note->Location;
86 Event *event; 91 Event *event;
87 event = existingCalendar->event( attList[0] ); 92 event = existingCalendar->event( mProfileName ,QString::number( id ) );
88 if ( event ) 93 if ( event )
89 event = (Event*)event->clone(); 94 event = (Event*)event->clone();
90 else 95 else
91 event = new Event; 96 event = new Event;
92 // event->setZaurusId( attList[0].toInt() ); 97 event->setID( mProfileName, attList[0] );
93 //event->setZaurusUid( cSum ); 98 // pending event->setCsum( "Sharp_DTM", QString::number( cSum ));
94 //event->setZaurusStat( -2 ); 99 event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
100
101
102 int i = 0;
103 bool repeating = false;
104 int repeat_dayofweek = -1;
105 int repeat_day = -1;
106 int repeat_weekofmonth = -1;
107 int repeat_month = -1;
108 int repeat_frequency = -1;
109 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
110 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
111 GSM_DateTime* dtp;
112 bool alarm = false;
113 QDateTime alarmDt;
114 repeat_startdate.Day= 0;
115 repeat_stopdate.Day = 0;
116 for (i=0;i<Note->EntriesNum;i++) {
117
118 qDebug(" for ");
119 switch (Note->Entries[i].EntryType) {
120 case CAL_START_DATETIME:
121 dtp = &Note->Entries[i].Date ;
122 if ( dtp->Hour > 24 ) {
123 event->setFloats( true );
124 event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
125 } else {
126 event->setDtStart (fromGSM ( dtp ));
95 127
96 event->setSummary( attList[2] ); 128 }
97 event->setLocation( attList[3] ); 129 break;
98 event->setDescription( attList[4] ); 130 case CAL_END_DATETIME:
99 if ( attList[7] == "1" ) { 131 dtp = &Note->Entries[i].Date ;
100 event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); 132 if ( dtp->Hour > 24 ) {
101 event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); 133 event->setFloats( true );
102 event->setFloats( true ); 134 event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 )));
103 } else { 135 } else {
104 event->setFloats( false ); 136 event->setDtEnd (fromGSM ( dtp ));
105 event->setDtStart( fromString( attList[5] ) ); 137 }
106 event->setDtEnd( fromString( attList[6] )); 138 break;
139 case CAL_ALARM_DATETIME:
140 dtp = &Note->Entries[i].Date ;
141 alarm = true;
142 alarmDt = fromGSM ( dtp );
143 break;
144 case CAL_SILENT_ALARM_DATETIME:
145 dtp = &Note->Entries[i].Date ;
146 alarm = true;
147 alarmDt = fromGSM ( dtp );
148 break;
149 case CAL_RECURRANCE:
150 //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" );
151 break;
152 case CAL_TEXT:
153 event->setSummary( QString ( (const char*) Note->Entries[i].Text ));
154 break;
155 case CAL_LOCATION:
156 event->setLocation(QString ((const char*) Note->Entries[i].Text ));
157 break;
158 case CAL_PHONE:
159 //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text));
160 break;
161 case CAL_PRIVATE:
162 //printmsg("Private : %s\n",Note->Entries[i].Number == 1 ? "Yes" : "No");
163 break;
164 case CAL_CONTACTID:
165#if 0
166 entry.Location = Note->Entries[i].Number;
167 entry.MemoryType = MEM_ME;
168 error=Phone->GetMemory(&s, &entry);
169 if (error == ERR_NONE) {
170 name = GSM_PhonebookGetEntryName(&entry);
171 if (name != NULL) {
172 //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
173 } else {
174 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
175 }
176 } else {
177 //printmsg("Contact ID : %d\n",Note->Entries[i].Number);
178 }
179#endif
180 break;
181 case CAL_REPEAT_DAYOFWEEK:
182 repeat_dayofweek = Note->Entries[i].Number;
183 repeating = true;
184 break;
185 case CAL_REPEAT_DAY:
186 repeat_day = Note->Entries[i].Number;
187 repeating = true;
188 break;
189 case CAL_REPEAT_WEEKOFMONTH:
190 repeat_weekofmonth = Note->Entries[i].Number;
191 repeating = true;
192 break;
193 case CAL_REPEAT_MONTH:
194 repeat_month = Note->Entries[i].Number;
195 repeating = true;
196 break;
197 case CAL_REPEAT_FREQUENCY:
198 repeat_frequency = Note->Entries[i].Number;
199 repeating = true;
200 break;
201 case CAL_REPEAT_STARTDATE:
202 repeat_startdate = Note->Entries[i].Date;
203 repeating = true;
204 break;
205 case CAL_REPEAT_STOPDATE:
206 repeat_stopdate = Note->Entries[i].Date;
207 repeating = true;
208 break;
209 }
107 } 210 }
211#if 0
212 event->setDescription( attList[4] );
213 bool repeating = false;
214 int repeat_dayofweek = -1;
215 int repeat_day = -1;
216 int repeat_weekofmonth = -1;
217 int repeat_month = -1;
218 int repeat_frequency = -1;
219 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
220 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
221
222#endif
108 223
109 QString rtype = attList[11]; 224 QString rtype = attList[11];
110 if ( rtype != "255" ) { 225 if ( repeating ) {
226 int rtype = 0;
111 // qDebug("recurs "); 227 // qDebug("recurs ");
112 QDate startDate = event->dtStart().date(); 228 QDate startDate, endDate;
113 229 if ( repeat_startdate.Day > 0 )
114 QString freqStr = attList[12]; 230 startDate = datefromGSM ( &repeat_startdate );
115 int freq = freqStr.toInt(); 231 else
116 232 startDate = event->dtStart().date();
117 QString hasEndDateStr = attList[15] ; 233 int freq = repeat_frequency;
118 bool hasEndDate = hasEndDateStr == "1"; 234 bool hasEndDate = false;
119 235 if ( repeat_stopdate.Day > 0 ) {
120 QString endDateStr = attList[16]; 236 endDate = datefromGSM ( &repeat_stopdate );
121 QDate endDate = fromString( endDateStr ).date(); 237 hasEndDate = true;
122 238 }
123 QString weekDaysStr = attList[14]; 239
124 uint weekDaysNum = weekDaysStr.toInt(); 240 uint weekDaysNum = repeat_dayofweek ;
125 241
126 QBitArray weekDays( 7 ); 242 QBitArray weekDays( 7 );
127 int i; 243 int i;
@@ -132,45 +248,64 @@ class PhoneParser : public QObject
132 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); 248 //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) );
133 } 249 }
134 // qDebug("next "); 250 // qDebug("next ");
135 QString posStr = attList[13]; 251 int pos = 0;
136 int pos = posStr.toInt();
137 Recurrence *r = event->recurrence(); 252 Recurrence *r = event->recurrence();
253 /*
254 0 daily;
255 1 weekly;x
256 2 monthpos;x
257 3 monthlyday;
258 4 rYearlyMont
259 */
260 int dayOfWeek = startDate.dayOfWeek();
261 if ( repeat_weekofmonth >= 0 ) {
262 rtype = 2;
263 pos = repeat_weekofmonth;
264 if ( repeat_dayofweek >= 0 )
265 dayOfWeek = repeat_dayofweek;
266 } else if ( repeat_dayofweek >= 0 ) {
267 rtype = 1;
268 } if ( repeat_dayofweek >= 0 ) {
269 rtype = 1;
270 }
138 271
139 if ( rtype == "0" ) { 272 if ( rtype == 0 ) {
140 if ( hasEndDate ) r->setDaily( freq, endDate ); 273 if ( hasEndDate ) r->setDaily( freq, endDate );
141 else r->setDaily( freq, -1 ); 274 else r->setDaily( freq, -1 );
142 } else if ( rtype == "1" ) { 275 } else if ( rtype == 1 ) {
143 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); 276 if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate );
144 else r->setWeekly( freq, weekDays, -1 ); 277 else r->setWeekly( freq, weekDays, -1 );
145 } else if ( rtype == "3" ) { 278 } else if ( rtype == 3 ) {
146 if ( hasEndDate ) 279 if ( hasEndDate )
147 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); 280 r->setMonthly( Recurrence::rMonthlyDay, freq, endDate );
148 else 281 else
149 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); 282 r->setMonthly( Recurrence::rMonthlyDay, freq, -1 );
150 r->addMonthlyDay( startDate.day() ); 283 r->addMonthlyDay( startDate.day() );
151 } else if ( rtype == "2" ) { 284 } else if ( rtype == 2 ) {
152 if ( hasEndDate ) 285 if ( hasEndDate )
153 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); 286 r->setMonthly( Recurrence::rMonthlyPos, freq, endDate );
154 else 287 else
155 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); 288 r->setMonthly( Recurrence::rMonthlyPos, freq, -1 );
156 QBitArray days( 7 ); 289 QBitArray days( 7 );
157 days.fill( false ); 290 days.fill( false );
158 days.setBit( startDate.dayOfWeek() - 1 ); 291 days.setBit( dayOfWeek - 1 );
159 r->addMonthlyPos( pos, days ); 292 r->addMonthlyPos( pos, days );
160 } else if ( rtype == "4" ) { 293 } else if ( rtype == 4 ) {
161 if ( hasEndDate ) 294 if ( hasEndDate )
162 r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); 295 r->setYearly( Recurrence::rYearlyMonth, freq, endDate );
163 else 296 else
164 r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); 297 r->setYearly( Recurrence::rYearlyMonth, freq, -1 );
165 r->addYearlyNum( startDate.month() ); 298 r->addYearlyNum( startDate.month() );
166 } 299 }
300 } else {
301 event->recurrence()->unsetRecurs();
167 } 302 }
168 303
169 QString categoryList = attList[1] ; 304 QString categoryList = attList[1] ;
170 event->setCategories( lookupCategories( categoryList ) ); 305 event->setCategories( lookupCategories( categoryList ) );
171 306
172 // strange 0 semms to mean: alarm enabled 307 // strange 0 semms to mean: alarm enabled
173 if ( attList[8] == "0" ) { 308 if ( alarm ) {
174 Alarm *alarm; 309 Alarm *alarm;
175 if ( event->alarms().count() > 0 ) 310 if ( event->alarms().count() > 0 )
176 alarm = event->alarms().first(); 311 alarm = event->alarms().first();
@@ -180,12 +315,12 @@ class PhoneParser : public QObject
180 } 315 }
181 alarm->setType( Alarm::Audio ); 316 alarm->setType( Alarm::Audio );
182 alarm->setEnabled( true ); 317 alarm->setEnabled( true );
183 int alarmOffset = attList[9].toInt(); 318 int alarmOffset = alarmDt.secsTo( event->dtStart() );
184 alarm->setStartOffset( alarmOffset * -60 ); 319 alarm->setStartOffset( alarmOffset );
185 } 320 }
186
187 mCalendar->addEvent( event); 321 mCalendar->addEvent( event);
188 } else if ( qName == "Todo" ) { 322 } else if ( qName == "Todo" ) {
323#if 0
189 Todo *todo; 324 Todo *todo;
190 325
191 todo = existingCalendar->todo( attList[0] ); 326 todo = existingCalendar->todo( attList[0] );
@@ -246,6 +381,7 @@ class PhoneParser : public QObject
246 else 381 else
247 todo->setCompleted( false ); 382 todo->setCompleted( false );
248 mCalendar->addTodo( todo ); 383 mCalendar->addTodo( todo );
384#endif
249 385
250 } else if ( qName == "Category" ) { 386 } else if ( qName == "Category" ) {
251 /* 387 /*
@@ -264,22 +400,26 @@ class PhoneParser : public QObject
264 oldCategories = c; 400 oldCategories = c;
265 } 401 }
266 402
267 QDateTime fromString ( QString s, bool useTz = true ) { 403 QDateTime fromGSM ( GSM_DateTime*dtp, bool useTz = true ) {
268 QDateTime dt; 404 QDateTime dt;
269 int y,m,t,h,min,sec; 405 int y,m,t,h,min,sec;
270 y = s.mid(0,4).toInt(); 406 y = dtp->Year;
271 m = s.mid(4,2).toInt(); 407 m = dtp->Month;
272 t = s.mid(6,2).toInt(); 408 t = dtp->Day;
273 h = s.mid(9,2).toInt(); 409 h = dtp->Hour;
274 min = s.mid(11,2).toInt(); 410 min = dtp->Minute;
275 sec = s.mid(13,2).toInt(); 411 sec = dtp->Second;
276 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); 412 dt = QDateTime(QDate(y,m,t), QTime(h,min,sec));
413 // dtp->Timezone: offset in hours
277 int offset = KGlobal::locale()->localTimeOffset( dt ); 414 int offset = KGlobal::locale()->localTimeOffset( dt );
278 if ( useTz ) 415 if ( useTz )
279 dt = dt.addSecs ( offset*60); 416 dt = dt.addSecs ( offset*60);
280 return dt; 417 return dt;
281 418
282 } 419 }
420 QDate datefromGSM ( GSM_DateTime*dtp ) {
421 return QDate ( dtp->Year, dtp->Month, dtp->Day );
422 }
283 protected: 423 protected:
284 QDateTime toDateTime( const QString &value ) 424 QDateTime toDateTime( const QString &value )
285 { 425 {
@@ -305,7 +445,8 @@ class PhoneParser : public QObject
305 return categories; 445 return categories;
306 } 446 }
307 447
308 private: 448 private:
449 QString mProfileName ;
309 Calendar *mCalendar; 450 Calendar *mCalendar;
310 QStringList * oldCategories; 451 QStringList * oldCategories;
311 static QString category( const QString &id ) 452 static QString category( const QString &id )
@@ -359,9 +500,9 @@ ulong PhoneFormat::getCsum( const QStringList & attList)
359//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 500//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
360#include <stdlib.h> 501#include <stdlib.h>
361#define DEBUGMODE false 502#define DEBUGMODE false
362bool PhoneFormat::load( Calendar *calendar, Calendar *existngCal ) 503bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model )
363{ 504{
364 505 mProfileName = profileName;
365 GSM_StateMachines; 506 GSM_StateMachines;
366 qDebug(" load "); 507 qDebug(" load ");
367 s.opened = false; 508 s.opened = false;
@@ -417,12 +558,23 @@ static char *cp;
417 qDebug(" init %d %d", error, ERR_NONE); 558 qDebug(" init %d %d", error, ERR_NONE);
418 if ( error != ERR_NONE ) 559 if ( error != ERR_NONE )
419 return false; 560 return false;
420 fromString2Cal( calendar, existngCal, &s, "Event" ); 561 // fromString2Cal( calendar, existngCal, &s, "Event" );
421 562 GSM_Phone_Functions*Phone;
422 563 GSM_CalendarEntrynote;
564 bool refresh= true;
565 Phone=s.Phone.Functions;
566 bool gshutdown = false;
567 PhoneParser handler( calendar, profileName );
568 //handler.setCategoriesList( mCategories );
569 int ccc = 0;
570 while (!gshutdown && ccc++ < 10 ) {
571
572 qDebug("count %d ", ccc);
573 error=Phone->GetNextCalendar(&s,&note,refresh);
574 if (error == ERR_EMPTY) break;
575 handler.startElement( existingCal, &note, "Event" );
576 }
423 error=GSM_TerminateConnection(&s); 577 error=GSM_TerminateConnection(&s);
424
425
426#if 0 578#if 0
427 579
428 bool debug = DEBUGMODE; 580 bool debug = DEBUGMODE;
@@ -1039,6 +1191,7 @@ bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
1039} 1191}
1040 bool PhoneFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, GSM_StateMachine*s, const QString & type) 1192 bool PhoneFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, GSM_StateMachine*s, const QString & type)
1041{ 1193{
1194#if 0
1042 GSM_Phone_Functions*Phone; 1195 GSM_Phone_Functions*Phone;
1043 1196
1044 GSM_CalendarEntrynote; 1197 GSM_CalendarEntrynote;
@@ -1325,7 +1478,7 @@ typedef struct {
1325 } 1478 }
1326 1479
1327 1480
1328 1481#endif
1329#if 0 1482#if 0
1330 // qDebug("test %s ", text.latin1()); 1483 // qDebug("test %s ", text.latin1());
1331 QStringList templist; 1484 QStringList templist;