summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-09 16:25:52 (UTC)
committer zautrix <zautrix>2004-08-09 16:25:52 (UTC)
commitecdcad49975976ff877ff506fae3b14934c01898 (patch) (side-by-side diff)
tree55d79a2b7d90c4c7ce097063449946f2b2504d6a
parentad99dd380750834b3ccc4dd6fdcdd446ca5ba7ee (diff)
downloadkdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.zip
kdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.tar.gz
kdepimpi-ecdcad49975976ff877ff506fae3b14934c01898.tar.bz2
more phone sync
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/phoneformat.cpp194
-rw-r--r--libkcal/phoneformat.h4
2 files changed, 165 insertions, 33 deletions
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index b8fed47..e43a507 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -77,25 +77,23 @@ public:
int j;
GSM_DateTime* dtp;
bool alarm = false;
QDateTime alarmDt;
GSM_Category Category;
int error;
- QString completedString = "no";
for (j=0;j<ToDo->EntriesNum;j++) {
//qDebug(" for todo %d",ToDo->Location );
switch (ToDo->Entries[j].EntryType) {
case TODO_END_DATETIME:
dtp = &ToDo->Entries[j].Date ;
todo->setDtDue (fromGSM ( dtp ));
break;
case TODO_COMPLETED:
if ( ToDo->Entries[j].Number == 1 ) {
todo->setCompleted( true );
- completedString = "yes";
}
else {
todo->setCompleted( false );
}
break;
case TODO_ALARM_DATETIME:
@@ -179,24 +177,14 @@ public:
alarm->setType( Alarm::Audio );
alarm->setStartOffset( -60*15 );
alarm->setEnabled( false );
}
}
// csum *****************************************
- QStringList attList;
uint cSum;
- if ( todo->hasDueDate() )
- attList << dtToString ( todo->dtDue() );
- attList << QString::number( id );
- attList << todo->summary();
- attList << completedString;
- attList << QString::number( todo->priority() );
- attList << alarmString;
- attList << todo->categoriesStr();
- attList << todo->secrecyStr();
- cSum = PhoneFormat::getCsum(attList );
+ cSum = PhoneFormat::getCsumTodo( todo );
todo->setCsum( mProfileName, QString::number( cSum ));
todo->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
mCalendar->addTodo( todo);
return true;
}
@@ -457,13 +445,12 @@ public:
event->recurrence()->unsetRecurs();
}
QStringList categoryList;
categoryList << getCategory( Note );
event->setCategories( categoryList );
- QString alarmString = "na";
// strange 0 semms to mean: alarm enabled
if ( alarm ) {
Alarm *alarm;
if ( event->alarms().count() > 0 )
alarm = event->alarms().first();
else {
@@ -471,35 +458,25 @@ public:
event->addAlarm( alarm );
}
alarm->setType( Alarm::Audio );
alarm->setEnabled( true );
int alarmOffset = alarmDt.secsTo( event->dtStart() );
alarm->setStartOffset( -alarmOffset );
- alarmString = QString::number( 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 *****************************************
- QStringList attList;
+
uint cSum;
- attList << dtToString ( event->dtStart() );
- attList << dtToString ( event->dtEnd() );
- attList << QString::number( id );
- attList << event->summary();
- attList << event->location();
- attList << alarmString;
- attList << recurString;
- attList << event->categoriesStr();
- attList << event->secrecyStr();
- cSum = PhoneFormat::getCsum(attList );
+ cSum = PhoneFormat::getCsumEvent( event );
event->setCsum( mProfileName, QString::number( cSum ));
event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
mCalendar->addEvent( event);
return true;
}
@@ -520,13 +497,13 @@ public:
if ( useTz )
dt = dt.addSecs ( offset*60);
return dt;
}
- QString dtToString( const QDateTime& dti, bool useTZ = false )
+ static QString dtToString( const QDateTime& dti, bool useTZ = false )
{
QString datestr;
QString timestr;
int offset = KGlobal::locale()->localTimeOffset( dti );
QDateTime dt;
if (useTZ)
@@ -626,12 +603,143 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
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();
+ return PhoneFormat::getCsum(attList );
+
+}
+ulong PhoneFormat::getCsumEvent( Event* event )
+{
+ QStringList attList;
+ attList << PhoneParser::dtToString ( event->dtStart() );
+ attList << PhoneParser::dtToString ( event->dtEnd() );
+ attList << event->summary();
+ attList << event->location();
+ QString alarmString = "na";
+ Alarm *alarm;
+ if ( event->alarms().count() > 0 ) {
+ alarm = event->alarms().first();
+ if ( alarm->enabled() ) {
+ alarmString = QString::number( alarm->startOffset().asSeconds() );
+ }
+ }
+ attList << alarmString;
+ Recurrence* rec = event->recurrence();
+ QStringList list;
+ bool writeEndDate = false;
+ switch ( rec->doesRecur() )
+ {
+ case Recurrence::rDaily: // 0
+ list.append( "0" );
+ list.append( QString::number( rec->frequency() ));//12
+ list.append( "0" );
+ list.append( "0" );
+ writeEndDate = true;
+ break;
+ case Recurrence::rWeekly:// 1
+ list.append( "1" );
+ list.append( QString::number( rec->frequency()) );//12
+ list.append( "0" );
+ {
+ int days = 0;
+ QBitArray weekDays = rec->days();
+ int i;
+ for( i = 1; i <= 7; ++i ) {
+ if ( weekDays[i-1] ) {
+ days += 1 << (i-1);
+ }
+ }
+ list.append( QString::number( days ) );
+ }
+ //pending weekdays
+ writeEndDate = true;
+
+ break;
+ case Recurrence::rMonthlyPos:// 2
+ list.append( "2" );
+ list.append( QString::number( rec->frequency()) );//12
+
+ writeEndDate = true;
+ {
+ int count = 1;
+ QPtrList<Recurrence::rMonthPos> rmp;
+ rmp = rec->monthPositions();
+ if ( rmp.first()->negative )
+ count = 5 - rmp.first()->rPos - 1;
+ else
+ count = rmp.first()->rPos - 1;
+ list.append( QString::number( count ) );
+
+ }
+
+ list.append( "0" );
+ break;
+ case Recurrence::rMonthlyDay:// 3
+ list.append( "3" );
+ list.append( QString::number( rec->frequency()) );//12
+ list.append( "0" );
+ list.append( "0" );
+ writeEndDate = true;
+ break;
+ case Recurrence::rYearlyMonth://4
+ list.append( "4" );
+ list.append( QString::number( rec->frequency()) );//12
+ list.append( "0" );
+ list.append( "0" );
+ writeEndDate = true;
+ break;
+
+ default:
+ list.append( "255" );
+ list.append( QString() );
+ list.append( "0" );
+ list.append( QString() );
+ list.append( "0" );
+ list.append( "20991231T000000" );
+ break;
+ }
+ if ( writeEndDate ) {
+
+ if ( rec->endDate().isValid() ) { // 15 + 16
+ list.append( "1" );
+ list.append( PhoneParser::dtToString( rec->endDate()) );
+ } else {
+ list.append( "0" );
+ list.append( "20991231T000000" );
+ }
+
+ }
+ attList << list.join("");
+ attList << event->categoriesStr();
+ attList << event->secrecyStr();
+ return PhoneFormat::getCsum(attList );
+}
ulong PhoneFormat::getCsum( const QStringList & attList)
{
int max = attList.count() -1;
ulong cSum = 0;
int j,k,i;
int add;
@@ -795,12 +903,23 @@ void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsm )
s = "\"\"";
}
}
return list.join(",");
#endif
}
+void PhoneFormat::afterSave( Incidence* inc)
+{
+ uint csum;
+ if ( inc->type() == "Event")
+ csum = PhoneFormat::getCsumEvent( (Event*) inc );
+ else
+ csum = PhoneFormat::getCsumTodo( (Todo*) inc );
+ inc->setCsum( mProfileName, QString::number( csum ));
+ inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+
+}
bool PhoneFormat::save( Calendar *calendar)
{
GSM_StateMachine s;
qDebug(" save ");
s.opened = false;
s.msg = NULL;
@@ -842,28 +961,33 @@ bool PhoneFormat::save( Calendar *calendar)
}
else if ( ev->getID(mProfileName).isEmpty() ) { // add new
// we have to do this later after deleting
}
else { // change existing
- error = Phone->AddCalendar(&s, &Note);
+ error = Phone->SetCalendar(&s, &Note);
}
}
ev = er.next();
}
ev = er.first();
// pending get empty slots
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();
- int newID ;//= pending
- ev->setID(mProfileName, QString::number( newID ));
+ //int newID ;//= pending
+ //ev->setID(mProfileName, QString::number( newID ));
event2GSM( ev, &Note );
+ Note.Location = 0;
error = Phone->AddCalendar(&s, &Note);
+ ev->setID( mProfileName, QString::number( Note.Location ) );
+ afterSave( ev );
+ } else {
+ afterSave( ev ); // setting temp sync stat for changed items
}
}
ev = er.next();
}
GSM_ToDoEntry ToDoEntry;
QPtrList<Todo> tl = calendar->rawTodos();
@@ -893,16 +1017,22 @@ bool PhoneFormat::save( Calendar *calendar)
to = tl.first();
while ( to ) {
if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && to->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
if ( to->getID(mProfileName).isEmpty() ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- int newID ;//= pending
- to->setID(mProfileName, QString::number( newID ));
+ //int newID ;//= pending
+ //to->setID(mProfileName, QString::number( newID ));
todo2GSM( to, &ToDoEntry );
+ ToDoEntry.Location = 0;
error=Phone->AddToDo(&s,&ToDoEntry);
+ to->setID(mProfileName, QString::number( ToDoEntry.Location ));
+ afterSave( to );
+ qDebug("New Todo. Location %d ",ToDoEntry.Location );
+ } else {
+ afterSave( to );
}
}
to = tl.next();
}
return true;
}
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 1472880..7b7dd04 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -44,20 +44,22 @@ class PhoneFormat : public QObject {
bool load( Calendar * ,Calendar * );
bool save( Calendar * );
bool fromString( Calendar *, const QString & );
QString toString( Calendar * );
static ulong getCsum( const QStringList & );
-
+ static ulong getCsumTodo( Todo* to );
+ static ulong getCsumEvent( Event* ev );
private:
void event2GSM( Event* ev, GSM_CalendarEntry*Note );
void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
int initDevice(GSM_StateMachine *s);
QString getEventString( Event* );
QString getTodoString( Todo* );
QString dtToGSM( const QDateTime& dt, bool useTZ = true );
QString mProfileName, mDevice, mConnection, mModel;
+ void afterSave( Incidence* );
};
}
#endif