-rw-r--r-- | libkcal/phoneformat.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp index 6276498..1769b37 100644 --- a/libkcal/phoneformat.cpp +++ b/libkcal/phoneformat.cpp @@ -353,279 +353,284 @@ public: startDate = datefromGSM ( &repeat_startdate ); event->setDtStart(QDateTime ( startDate, event->dtStart().time())); } 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 ; // 1 == monday, 7 == sunday QBitArray weekDays( 7 ); int i; int bb = 1; for( i = 1; i <= 7; ++i ) { weekDays.setBit( i - 1, ( bb & weekDaysNum )); bb = 2 << (i-1); //qDebug(" %d bit %d ",i-1,weekDays.at(i-1) ); } // qDebug("next "); int pos = 0; Recurrence *r = event->recurrence(); /* 0 daily; 1 weekly;x 2 monthpos;x 3 monthlyday; 4 rYearlyMont bool repeating = false; int repeat_dayofweek = -1; int repeat_day = -1; int repeat_weekofmonth = -1; int repeat_month = -1; int repeat_frequency = -1; */ int dayOfWeek = startDate.dayOfWeek(); if ( repeat_weekofmonth >= 0 ) { rtype = 2; // ************************ 2 MonthlyPos pos = repeat_weekofmonth; if ( repeat_dayofweek >= 0 ) dayOfWeek = repeat_dayofweek; if (repeat_month > 0) { if ( repeat_month != event->dtStart().date().month() ) { QDate date (event->dtStart().date().year(),repeat_month,event->dtStart().date().day() ); event->setDtStart(QDateTime ( date , event->dtStart().time()) ); } if ( freq == 1 ) freq = 12; } } else if ( repeat_dayofweek >= 0 ) { rtype = 1;// ************************ 1 Weekly } else if ( repeat_day >= 0 ) { if ( repeat_month > 0) { rtype = 4; } else { rtype = 3; } } else { rtype = 0 ; } if ( rtype == 0 ) { if ( hasEndDate ) r->setDaily( freq, endDate ); else r->setDaily( freq, -1 ); } else if ( rtype == 1 ) { if ( hasEndDate ) r->setWeekly( freq, weekDays, endDate ); else r->setWeekly( freq, weekDays, -1 ); } 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 ) { if ( hasEndDate ) r->setMonthly( Recurrence::rMonthlyPos, freq, endDate ); else r->setMonthly( Recurrence::rMonthlyPos, freq, -1 ); QBitArray days( 7 ); days.fill( false ); days.setBit( dayOfWeek - 1 ); r->addMonthlyPos( pos, days ); } 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(); } - QStringList categoryList; - categoryList << getCategory( Note ); - event->setCategories( categoryList ); - // strange 0 semms to mean: alarm enabled + QStringList cat = event->categories(); + QString nCat = getCategory( Note ); + + if ( !nCat.isEmpty() ) + if ( !cat.contains( nCat )) { + cat << nCat; + event->setCategories( cat ); + } + if ( alarm ) { Alarm *alarm; if ( event->alarms().count() > 0 ) alarm = event->alarms().first(); else { alarm = new Alarm( event ); event->addAlarm( alarm ); } alarm->setType( Alarm::Audio ); alarm->setEnabled( true ); int alarmOffset = alarmDt.secsTo( event->dtStart() ); alarm->setStartOffset( -alarmOffset ); } else { Alarm *alarm; if ( event->alarms().count() > 0 ) { alarm = event->alarms().first(); alarm->setType( Alarm::Audio ); alarm->setStartOffset( -60*15 ); alarm->setEnabled( false ); } } // csum ***************************************** uint cSum; cSum = PhoneFormat::getCsumEvent( event ); event->setCsum( mProfileName, QString::number( cSum )); event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); mCalendar->addEvent( event); return true; } QDateTime fromGSM ( GSM_DateTime* dtp, bool useTz = false ) { QDateTime dt; int y,m,t,h,min,sec; 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; } static QString dtToString( const QDateTime& dti, bool useTZ = false ) { QString datestr; QString timestr; int offset = KGlobal::locale()->localTimeOffset( dti ); QDateTime dt; if (useTZ) dt = dti.addSecs ( -(offset*60)); else dt = dti; if(dt.date().isValid()){ const QDate& date = dt.date(); datestr.sprintf("%04d%02d%02d", date.year(), date.month(), date.day()); } if(dt.time().isValid()){ const QTime& time = dt.time(); timestr.sprintf("T%02d%02d%02d", time.hour(), time.minute(), time.second()); } return datestr + timestr; } QDate datefromGSM ( GSM_DateTime* dtp ) { return QDate ( dtp->Year, dtp->Month, dtp->Day ); } QString getCategory( GSM_CalendarEntry* Note) { QString CATEGORY; switch (Note->Type) { case GSM_CAL_REMINDER : CATEGORY = QString("Reminder"); break; case GSM_CAL_CALL : CATEGORY = QString("Call"); break; - case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; + //case GSM_CAL_MEETING : CATEGORY = QString("Meeting"); break; case GSM_CAL_BIRTHDAY : CATEGORY = QString("Birthday"); break; case GSM_CAL_MEMO : CATEGORY = QString("Memo"); break; case GSM_CAL_TRAVEL : CATEGORY = QString("Travel"); break; case GSM_CAL_VACATION : CATEGORY = QString("Vacation"); break; case GSM_CAL_ALARM : CATEGORY = QString("Alarm"); break; case GSM_CAL_DAILY_ALARM : CATEGORY = QString("Daily alarm"); break; case GSM_CAL_T_ATHL : CATEGORY = QString("Training/Athletism"); break; case GSM_CAL_T_BALL : CATEGORY = QString("Training/Ball Games"); break; case GSM_CAL_T_CYCL : CATEGORY = QString("Training/Cycling"); break; case GSM_CAL_T_BUDO : CATEGORY = QString("Training/Budo"); break; case GSM_CAL_T_DANC : CATEGORY = QString("Training/Dance"); break; case GSM_CAL_T_EXTR : CATEGORY = QString("Training/Extreme Sports"); break; case GSM_CAL_T_FOOT : CATEGORY = QString("Training/Football"); break; case GSM_CAL_T_GOLF : CATEGORY = QString("Training/Golf"); break; case GSM_CAL_T_GYM : CATEGORY = QString("Training/Gym"); break; case GSM_CAL_T_HORS : CATEGORY = QString("Training/Horse Races"); break; case GSM_CAL_T_HOCK : CATEGORY = QString("Training/Hockey"); break; case GSM_CAL_T_RACE : CATEGORY = QString("Training/Races"); break; case GSM_CAL_T_RUGB : CATEGORY = QString("Training/Rugby"); break; case GSM_CAL_T_SAIL : CATEGORY = QString("Training/Sailing"); break; case GSM_CAL_T_STRE : CATEGORY = QString("Training/Street Games"); break; case GSM_CAL_T_SWIM : CATEGORY = QString("Training/Swimming"); break; case GSM_CAL_T_TENN : CATEGORY = QString("Training/Tennis"); break; case GSM_CAL_T_TRAV : CATEGORY = QString("Training/Travels"); break; case GSM_CAL_T_WINT : CATEGORY = QString("Training/Winter Games"); break; default : CATEGORY = QString(""); } return CATEGORY; } protected: private: Calendar *mCalendar; QString mProfileName ; }; PhoneFormat::PhoneFormat(QString profileName, QString device,QString connection, QString model ) { mProfileName = profileName; mDevice = device; mConnection = connection; mModel = model; } PhoneFormat::~PhoneFormat() { } int PhoneFormat::initDevice(GSM_StateMachine *s) { GSM_ReadConfig(NULL, &s->Config[0], 0); s->ConfigNum = 1; GSM_Config *cfg = &s->Config[0]; if ( ! mConnection.isEmpty() ) { cfg->Connection = strdup(mConnection.latin1()); cfg->DefaultConnection = false; qDebug("Connection set %s ", cfg->Connection ); } if ( ! mDevice.isEmpty() ) { cfg->Device = strdup(mDevice.latin1()); cfg->DefaultDevice = false; qDebug("Device set %s ", cfg->Device); } if ( ! mModel.isEmpty() ) { strcpy(cfg->Model,mModel.latin1() ); cfg->DefaultModel = false; qDebug("Model set %s ",cfg->Model ); } int error=GSM_InitConnection(s,3); return error; } ulong PhoneFormat::getCsumTodo( Todo* todo ) { QStringList attList; if ( todo->hasDueDate() ) attList << PhoneParser::dtToString ( todo->dtDue() ); attList << todo->summary(); QString completedString = "no"; if ( todo->isCompleted() ) completedString = "yes"; attList << completedString; attList << QString::number( todo->priority() ); QString alarmString = "na"; Alarm *alarm; if ( todo->alarms().count() > 0 ) { alarm = todo->alarms().first(); if ( alarm->enabled() ) { alarmString = QString::number(alarm->startOffset().asSeconds() ); } } attList << alarmString; attList << todo->categoriesStr(); attList << todo->secrecyStr(); @@ -977,199 +982,226 @@ bool PhoneFormat::save( Calendar *calendar) qApp->processEvents(); qDebug("todo5 %d ", procCount); // todo2GSM( calendar, to, &ToDoEntry ); QString loc = to->getID(mProfileName); if ( !loc.isEmpty() ){ ToDoEntry.Location = loc.toInt(); } else { qDebug("error2: loc is empty "); } if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete error=Phone->DeleteToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { qDebug("delete planB %d ", error); } } else if ( to->getID(mProfileName).isEmpty() ) { // add new ; } else { // change existing error=Phone->DeleteToDo(&s,&ToDoEntry); if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { qDebug("set planB %d ", error); } to->removeID( mProfileName ); } } to = tl.next(); } //algo 2 add event ev = er.first(); QString filec; message = i18n(" Preparing event # "); procCount = 0; while ( ev ) { if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { if ( ev->getID(mProfileName).isEmpty() ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); filec += vfconverter.eventToString( ev, calendar )+ "\n"; afterSave ( ev ); } } ev = er.next(); } //algo 2 add todo to = tl.first(); procCount = 0; message = i18n(" Preparing todo # "); while ( to ) { qDebug("todo2 %d ", procCount); if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) { qDebug("todo4 %d ", procCount); if ( to->getID(mProfileName).isEmpty() ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); filec += vfconverter.todoToString( to, calendar )+ "\n"; afterSave ( to ); } } to = tl.next(); } if ( filec.isEmpty() ) { qDebug("Nothing to write back.Finished. "); error=GSM_TerminateConnection(&s); return true; } //algo 3 saving file message = i18n(" Saving temp file ... "); status.setText ( message ); qApp->processEvents(); QFile file( fileName ); if (!file.open( IO_WriteOnly ) ) { qDebug("error open file "); error=GSM_TerminateConnection(&s); return false; } QTextStream ts( &file ); ts.setCodec( QTextCodec::codecForName("utf8") ); ts << filec ; file.close(); message = i18n(" Parsing temp file ... "); status.setText ( message ); qApp->processEvents(); GSM_Backup Backup; error=GSM_ReadBackupFile( (char*) fileName.latin1() ,&Backup); qDebug("Read file result %d ",error ); //algo 4 writing event int max, i; procCount = 0; message = i18n(" Writing event # "); if (Backup.Calendar[0] != NULL) { max = 0; while (Backup.Calendar[max]!=NULL) max++; + + GSM_DateTime* dtp; + for (i=0;i<max;i++) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); Note = *Backup.Calendar[i]; + +#if 0 + int j; + for (j=0;j<Note.EntriesNum;j++) { + //qDebug(" for ev"); + switch (Note.Entries[j].EntryType) { + case CAL_START_DATETIME: + //Note->Entries[i].Date.Hour = 5; + dtp = &Note.Entries[j].Date; + qDebug("start event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); + break; + case CAL_END_DATETIME: + dtp = &Note.Entries[j].Date; + qDebug("end event %d %d %d - %d %d %d", dtp->Year, dtp->Month, dtp->Day, dtp->Hour, dtp->Minute, dtp->Second ); + break; + } + } + int type = Note.Type; + qDebug(" event type %d - %d %d - %d %d %d",type, GSM_CAL_CALL , GSM_CAL_MEETING ,GSM_CAL_BIRTHDAY, GSM_CAL_MEMO ,GSM_CAL_ALARM ); +#endif + + Note.Type = GSM_CAL_MEETING; + // pending: fix in gammu GSM_ReadBackupFile the type settings + int loc = Note.Location; Note.Location = 0; error=Phone->AddCalendar(&s,&Note); - qDebug("add event %d %d", error, Note.Location ); + qDebug("add event %d %d %d", error, Note.Location, loc ); } } //algo 4 writing todo procCount = 0; message = i18n(" Writing todo # "); if (Backup.ToDo[0] != NULL) { max = 0; while (Backup.ToDo[max]!=NULL) max++; for (i=0;i<max;i++) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); ToDoEntry = *Backup.ToDo[i]; error = Phone->AddToDo(&s,&ToDoEntry); qDebug("add todo %d ", error); } } //algo 5 reread message = i18n(" Rereading all data ... "); status.setText ( message ); qApp->processEvents(); error=GSM_TerminateConnection(&s); CalendarLocal* calendarTemp = new CalendarLocal(); calendarTemp->setTimeZoneId( calendar->timeZoneId()); if ( ! load( calendarTemp,calendar) ){ qDebug("error reloading calendar "); delete calendarTemp; return false; } //algo 6 compare event ev = er.first(); message = i18n(" Comparing event # "); QPtrList<Event> er1 = calendarTemp->rawEvents(); Event* ev1; procCount = 0; while ( ev ) { if ( ev->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { qDebug("event new ID "); status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString cSum = ev->getCsum(mProfileName); ev1 = er1.first(); while ( ev1 ) { if ( ev1->getCsum( mProfileName ) == cSum ) { er1.remove( ev1 ); ev->setID(mProfileName, ev1->getID(mProfileName) ); break; } ev1 = er1.next(); } if ( ! ev1 ) { ev->removeID(mProfileName); qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); qDebug("Probably writing back of events not supported "); } } ev = er.next(); } //algo 6 compare todo to = tl.first(); procCount = 0; QPtrList<Todo> tl1 = calendarTemp->rawTodos(); Todo* to1 ; message = i18n(" Comparing todo # "); while ( to ) { qDebug("todo2 %d ", procCount); if ( to->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString cSum = to->getCsum(mProfileName); Todo* to1 = tl1.first(); while ( to1 ) { if ( to1->getCsum( mProfileName ) == cSum ) { tl1.remove( to1 ); to->setID(mProfileName, to1->getID(mProfileName) ); break; } to1 = tl1.next(); } if ( ! to1 ) { to->removeID(mProfileName); qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); qDebug("Probably writing back of todos not supported "); } } to = tl.next(); } delete calendarTemp; return true; // ******************************************************************* // ******************************************************************* // ******************************************************************* #if 0 while ( ev && ! planB) { |