author | zautrix <zautrix> | 2004-08-07 21:04:24 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-08-07 21:04:24 (UTC) |
commit | a9c3191a42084b6631dededef1709fa67eb2c048 (patch) (side-by-side diff) | |
tree | 9950e3c8fc54c2994a4a50417008921bfdc58889 /libkcal | |
parent | 809e502f4b6e84524c10fa963e2d17564e6b1af9 (diff) | |
download | kdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.zip kdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.tar.gz kdepimpi-a9c3191a42084b6631dededef1709fa67eb2c048.tar.bz2 |
more phone sync
-rw-r--r-- | libkcal/phoneformat.cpp | 273 | ||||
-rw-r--r-- | libkcal/phoneformat.h | 3 |
2 files changed, 215 insertions, 61 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 @@ #include "calendarlocal.h" #include "phoneformat.h" +#include "syncdefines.h" using namespace KCal; @@ -62,12 +63,15 @@ using namespace KCal; class PhoneParser : public QObject { public: - PhoneParser( Calendar *calendar ) : mCalendar( calendar ) { + PhoneParser( Calendar *calendar, QString profileName ) : mCalendar( calendar ), mProfileName ( profileName ) { oldCategories = 0; } - bool startElement( Calendar *existingCalendar, const QStringList & attList, QString qName ) + bool startElement( Calendar *existingCalendar, GSM_CalendarEntry* Note, QString qName ) { + QStringList attList; + /* +// pending csum int i = 1; bool skip = true; int max = attList.count() -2; @@ -81,47 +85,159 @@ class PhoneParser : public QObject if ( skip ) return false; ulong cSum = PhoneFormat::getCsum(attList ); - + */ if ( qName == "Event" ) { + int id = Note->Location; Event *event; - event = existingCalendar->event( attList[0] ); + event = existingCalendar->event( mProfileName ,QString::number( id ) ); if ( event ) event = (Event*)event->clone(); else event = new Event; - // event->setZaurusId( attList[0].toInt() ); - //event->setZaurusUid( cSum ); - //event->setZaurusStat( -2 ); + event->setID( mProfileName, attList[0] ); + // pending event->setCsum( "Sharp_DTM", QString::number( cSum )); + event->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); + + + int i = 0; + bool repeating = false; + int repeat_dayofweek = -1; + int repeat_day = -1; + int repeat_weekofmonth = -1; + int repeat_month = -1; + int repeat_frequency = -1; + GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; + GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; + GSM_DateTime* dtp; + bool alarm = false; + QDateTime alarmDt; + repeat_startdate.Day = 0; + repeat_stopdate.Day = 0; + for (i=0;i<Note->EntriesNum;i++) { + + qDebug(" for "); + switch (Note->Entries[i].EntryType) { + case CAL_START_DATETIME: + dtp = &Note->Entries[i].Date ; + if ( dtp->Hour > 24 ) { + event->setFloats( true ); + event->setDtStart( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); + } else { + event->setDtStart (fromGSM ( dtp )); - event->setSummary( attList[2] ); - event->setLocation( attList[3] ); - event->setDescription( attList[4] ); - if ( attList[7] == "1" ) { - event->setDtStart( QDateTime(fromString( attList[17]+"T000000", false ).date(),QTime(0,0,0 ) )); - event->setDtEnd( QDateTime(fromString( attList[18]+"T000000", false ).date(),QTime(0,0,0 ))); - event->setFloats( true ); - } else { - event->setFloats( false ); - event->setDtStart( fromString( attList[5] ) ); - event->setDtEnd( fromString( attList[6] )); + } + break; + case CAL_END_DATETIME: + dtp = &Note->Entries[i].Date ; + if ( dtp->Hour > 24 ) { + event->setFloats( true ); + event->setDtEnd( QDateTime (datefromGSM ( dtp ), QTime(0,0,0 ))); + } else { + event->setDtEnd (fromGSM ( dtp )); + } + break; + case CAL_ALARM_DATETIME: + dtp = &Note->Entries[i].Date ; + alarm = true; + alarmDt = fromGSM ( dtp ); + break; + case CAL_SILENT_ALARM_DATETIME: + dtp = &Note->Entries[i].Date ; + alarm = true; + alarmDt = fromGSM ( dtp ); + break; + case CAL_RECURRANCE: + //printmsg("Repeat : %d day%s\n",Note->Entries[i].Number/24,((Note->Entries[i].Number/24)>1) ? "s":"" ); + break; + case CAL_TEXT: + event->setSummary( QString ( (const char*) Note->Entries[i].Text )); + break; + case CAL_LOCATION: + event->setLocation(QString ((const char*) Note->Entries[i].Text )); + break; + case CAL_PHONE: + //printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(Note->Entries[i].Text)); + break; + case CAL_PRIVATE: + //printmsg("Private : %s\n",Note->Entries[i].Number == 1 ? "Yes" : "No"); + break; + case CAL_CONTACTID: +#if 0 + entry.Location = Note->Entries[i].Number; + entry.MemoryType = MEM_ME; + error=Phone->GetMemory(&s, &entry); + if (error == ERR_NONE) { + name = GSM_PhonebookGetEntryName(&entry); + if (name != NULL) { + //printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); + } else { + //printmsg("Contact ID : %d\n",Note->Entries[i].Number); + } + } else { + //printmsg("Contact ID : %d\n",Note->Entries[i].Number); + } +#endif + break; + case CAL_REPEAT_DAYOFWEEK: + repeat_dayofweek = Note->Entries[i].Number; + repeating = true; + break; + case CAL_REPEAT_DAY: + repeat_day = Note->Entries[i].Number; + repeating = true; + break; + case CAL_REPEAT_WEEKOFMONTH: + repeat_weekofmonth = Note->Entries[i].Number; + repeating = true; + break; + case CAL_REPEAT_MONTH: + repeat_month = Note->Entries[i].Number; + repeating = true; + break; + case CAL_REPEAT_FREQUENCY: + repeat_frequency = Note->Entries[i].Number; + repeating = true; + break; + case CAL_REPEAT_STARTDATE: + repeat_startdate = Note->Entries[i].Date; + repeating = true; + break; + case CAL_REPEAT_STOPDATE: + repeat_stopdate = Note->Entries[i].Date; + repeating = true; + break; + } } +#if 0 + event->setDescription( attList[4] ); + bool repeating = false; + int repeat_dayofweek = -1; + int repeat_day = -1; + int repeat_weekofmonth = -1; + int repeat_month = -1; + int repeat_frequency = -1; + GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; + GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; + +#endif QString rtype = attList[11]; - if ( rtype != "255" ) { + if ( repeating ) { + int rtype = 0; // qDebug("recurs "); - QDate startDate = event->dtStart().date(); - - QString freqStr = attList[12]; - int freq = freqStr.toInt(); - - QString hasEndDateStr = attList[15] ; - bool hasEndDate = hasEndDateStr == "1"; - - QString endDateStr = attList[16]; - QDate endDate = fromString( endDateStr ).date(); - - QString weekDaysStr = attList[14]; - uint weekDaysNum = weekDaysStr.toInt(); + QDate startDate, endDate; + if ( repeat_startdate.Day > 0 ) + startDate = datefromGSM ( &repeat_startdate ); + else + startDate = event->dtStart().date(); + int freq = repeat_frequency; + bool hasEndDate = false; + if ( repeat_stopdate.Day > 0 ) { + endDate = datefromGSM ( &repeat_stopdate ); + hasEndDate = true; + } + + uint weekDaysNum = repeat_dayofweek ; QBitArray weekDays( 7 ); int i; @@ -132,45 +248,64 @@ class PhoneParser : public QObject //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); } // qDebug("next "); - QString posStr = attList[13]; - int pos = posStr.toInt(); + int pos = 0; Recurrence *r = event->recurrence(); + /* + 0 daily; + 1 weekly;x + 2 monthpos;x + 3 monthlyday; + 4 rYearlyMont + */ + int dayOfWeek = startDate.dayOfWeek(); + if ( repeat_weekofmonth >= 0 ) { + rtype = 2; + pos = repeat_weekofmonth; + if ( repeat_dayofweek >= 0 ) + dayOfWeek = repeat_dayofweek; + } else if ( repeat_dayofweek >= 0 ) { + rtype = 1; + } if ( repeat_dayofweek >= 0 ) { + rtype = 1; + } - if ( rtype == "0" ) { + if ( rtype == 0 ) { if ( hasEndDate ) r->setDaily( freq, endDate ); else r->setDaily( freq, -1 ); - } else if ( rtype == "1" ) { + } else if ( rtype == 1 ) { if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); else r->setWeekly( freq, weekDays, -1 ); - } else if ( rtype == "3" ) { + } else if ( rtype == 3 ) { if ( hasEndDate ) r->setMonthly( Recurrence::rMonthlyDay, freq, endDate ); else r->setMonthly( Recurrence::rMonthlyDay, freq, -1 ); r->addMonthlyDay( startDate.day() ); - } else if ( rtype == "2" ) { + } else if ( rtype == 2 ) { if ( hasEndDate ) r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); else r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); QBitArray days( 7 ); days.fill( false ); - days.setBit( startDate.dayOfWeek() - 1 ); + days.setBit( dayOfWeek - 1 ); r->addMonthlyPos( pos, days ); - } else if ( rtype == "4" ) { + } else if ( rtype == 4 ) { if ( hasEndDate ) r->setYearly( Recurrence::rYearlyMonth, freq, endDate ); else r->setYearly( Recurrence::rYearlyMonth, freq, -1 ); r->addYearlyNum( startDate.month() ); } + } else { + event->recurrence()->unsetRecurs(); } QString categoryList = attList[1] ; event->setCategories( lookupCategories( categoryList ) ); // strange 0 semms to mean: alarm enabled - if ( attList[8] == "0" ) { + if ( alarm ) { Alarm *alarm; if ( event->alarms().count() > 0 ) alarm = event->alarms().first(); @@ -180,12 +315,12 @@ class PhoneParser : public QObject } alarm->setType( Alarm::Audio ); alarm->setEnabled( true ); - int alarmOffset = attList[9].toInt(); - alarm->setStartOffset( alarmOffset * -60 ); + int alarmOffset = alarmDt.secsTo( event->dtStart() ); + alarm->setStartOffset( alarmOffset ); } - mCalendar->addEvent( event); } else if ( qName == "Todo" ) { +#if 0 Todo *todo; todo = existingCalendar->todo( attList[0] ); @@ -246,6 +381,7 @@ class PhoneParser : public QObject else todo->setCompleted( false ); mCalendar->addTodo( todo ); +#endif } else if ( qName == "Category" ) { /* @@ -264,22 +400,26 @@ class PhoneParser : public QObject oldCategories = c; } - QDateTime fromString ( QString s, bool useTz = true ) { + QDateTime fromGSM ( GSM_DateTime* dtp, bool useTz = true ) { QDateTime dt; int y,m,t,h,min,sec; - y = s.mid(0,4).toInt(); - m = s.mid(4,2).toInt(); - t = s.mid(6,2).toInt(); - h = s.mid(9,2).toInt(); - min = s.mid(11,2).toInt(); - sec = s.mid(13,2).toInt(); + y = dtp->Year; + m = dtp->Month; + t = dtp->Day; + h = dtp->Hour; + min = dtp->Minute; + sec = dtp->Second; dt = QDateTime(QDate(y,m,t), QTime(h,min,sec)); + // dtp->Timezone: offset in hours int offset = KGlobal::locale()->localTimeOffset( dt ); if ( useTz ) dt = dt.addSecs ( offset*60); return dt; } + QDate datefromGSM ( GSM_DateTime* dtp ) { + return QDate ( dtp->Year, dtp->Month, dtp->Day ); + } protected: QDateTime toDateTime( const QString &value ) { @@ -305,7 +445,8 @@ class PhoneParser : public QObject return categories; } - private: + private: + QString mProfileName ; Calendar *mCalendar; QStringList * oldCategories; static QString category( const QString &id ) @@ -359,9 +500,9 @@ ulong PhoneFormat::getCsum( const QStringList & attList) //extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); #include <stdlib.h> #define DEBUGMODE false -bool PhoneFormat::load( Calendar *calendar, Calendar *existngCal ) +bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal ,QString profileName, QString device,QString connection, QString model ) { - + mProfileName = profileName; GSM_StateMachine s; qDebug(" load "); s.opened = false; @@ -417,12 +558,23 @@ static char *cp; qDebug(" init %d %d", error, ERR_NONE); if ( error != ERR_NONE ) return false; - fromString2Cal( calendar, existngCal, &s, "Event" ); - - + // fromString2Cal( calendar, existngCal, &s, "Event" ); + GSM_Phone_Functions *Phone; + GSM_CalendarEntry note; + bool refresh = true; + Phone=s.Phone.Functions; + bool gshutdown = false; + PhoneParser handler( calendar, profileName ); + //handler.setCategoriesList( mCategories ); + int ccc = 0; + while (!gshutdown && ccc++ < 10 ) { + + qDebug("count %d ", ccc); + error=Phone->GetNextCalendar(&s,¬e,refresh); + if (error == ERR_EMPTY) break; + handler.startElement( existingCal, ¬e, "Event" ); + } error=GSM_TerminateConnection(&s); - - #if 0 bool debug = DEBUGMODE; @@ -1039,6 +1191,7 @@ bool PhoneFormat::fromString( Calendar *calendar, const QString & text) } bool PhoneFormat::fromString2Cal( Calendar *calendar,Calendar *existingCalendar, GSM_StateMachine* s, const QString & type) { +#if 0 GSM_Phone_Functions *Phone; GSM_CalendarEntry note; @@ -1325,7 +1478,7 @@ typedef struct { } - +#endif #if 0 // qDebug("test %s ", text.latin1()); QStringList templist; diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h index 4ddf6f0..4da38c8 100644 --- a/libkcal/phoneformat.h +++ b/libkcal/phoneformat.h @@ -42,7 +42,7 @@ class PhoneFormat : public QObject { PhoneFormat(); virtual ~PhoneFormat(); - bool load( Calendar * ,Calendar *); + bool load( Calendar * ,Calendar *, QString profileName, QString device,QString connection, QString model ); bool save( Calendar * ); void setCategoriesList ( QStringList * cat ){ mCategories = cat; } bool fromString2Cal( Calendar *, Calendar *, GSM_StateMachine* s , const QString & ); @@ -58,6 +58,7 @@ class PhoneFormat : public QObject { QStringList *mCategories; int getNumFromRecord( QString answer,Incidence* inc ) ; QString getPart( const QString & text, bool &ok, int &start ); + QString mProfileName; }; } |