summaryrefslogtreecommitdiffabout
path: root/libkcal
authorzautrix <zautrix>2004-08-10 19:41:31 (UTC)
committer zautrix <zautrix>2004-08-10 19:41:31 (UTC)
commit2f1b58e344b882578977dd3786f7a94495096d22 (patch) (side-by-side diff)
tree6658bef546b6feac1688aa465ca94344e15704d7 /libkcal
parent467e50111dfd6d66aca205501b6bf369b7f0a166 (diff)
downloadkdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.zip
kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.gz
kdepimpi-2f1b58e344b882578977dd3786f7a94495096d22.tar.bz2
More syncing stuff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendar.cpp15
-rw-r--r--libkcal/calendar.h1
-rw-r--r--libkcal/incidencebase.cpp3
-rw-r--r--libkcal/phoneformat.cpp227
-rw-r--r--libkcal/phoneformat.h4
-rw-r--r--libkcal/vcalformat.cpp7
-rw-r--r--libkcal/vcalformat.h4
7 files changed, 221 insertions, 40 deletions
diff --git a/libkcal/calendar.cpp b/libkcal/calendar.cpp
index 32aac7a..a3977d7 100644
--- a/libkcal/calendar.cpp
+++ b/libkcal/calendar.cpp
@@ -30,6 +30,7 @@
#include "calfilter.h"
#include "calendar.h"
+#include "syncdefines.h"
using namespace KCal;
@@ -247,7 +248,21 @@ QPtrList<Incidence> Calendar::incidences()
return incidences;
}
+void Calendar::resetTempSyncStat()
+{
+ QPtrList<Incidence> incidences;
+
+ Incidence *i;
+
+ QPtrList<Event> e = rawEvents();
+ for( i = e.first(); i; i = e.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ QPtrList<Todo> t = rawTodos();
+ for( i = t.first(); i; i = t.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+
+ QPtrList<Journal> j = journals();
+ for( i = j.first(); i; i = j.next() ) i->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+}
QPtrList<Incidence> Calendar::rawIncidences()
{
QPtrList<Incidence> incidences;
diff --git a/libkcal/calendar.h b/libkcal/calendar.h
index 4a3223c..06a911c 100644
--- a/libkcal/calendar.h
+++ b/libkcal/calendar.h
@@ -66,6 +66,7 @@ public:
Calendar(const QString &timeZoneId);
virtual ~Calendar();
void deleteIncidence(Incidence *in);
+ void resetTempSyncStat();
/**
Clears out the current calendar, freeing all used memory etc.
*/
diff --git a/libkcal/incidencebase.cpp b/libkcal/incidencebase.cpp
index 15c4fa8..64a343c 100644
--- a/libkcal/incidencebase.cpp
+++ b/libkcal/incidencebase.cpp
@@ -24,6 +24,7 @@
#include <kidmanager.h>
#include "calformat.h"
+#include "syncdefines.h"
#include "incidencebase.h"
@@ -40,7 +41,7 @@ IncidenceBase::IncidenceBase() :
mHasDuration = false;
mPilotId = 0;
mExternalId = ":";
- mTempSyncStat = 0;
+ mTempSyncStat = SYNC_TEMPSTATE_INITIAL;
mSyncStatus = 0;
mAttendees.setAutoDelete( true );
}
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index e6d4879..6bbc0a3 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -66,9 +66,9 @@ public:
todo->setTempSyncStat(SYNC_TEMPSTATE_NEW_EXTERNAL );
int priority;
switch (ToDo->Priority) {
- case GSM_Priority_Low : priority = 1; break;
+ case GSM_Priority_Low : priority = 5; break;
case GSM_Priority_Medium : priority = 3; break;
- case GSM_Priority_High : priority = 5; break;
+ case GSM_Priority_High : priority = 1; break;
default :priority = 3 ; break;
}
todo->setPriority( priority );
@@ -230,6 +230,7 @@ public:
event->setDtStart (fromGSM ( dtp ));
}
+ //Note->Entries[i].Date.Hour = 5;
break;
case CAL_END_DATETIME:
dtp = &Note->Entries[i].Date ;
@@ -770,13 +771,13 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
s.opened = false;
s.msg = NULL;
s.ConfigNum = 0;
- QLabel status ( i18n("Reading data. Opening device ..."), 0 );
+ QLabel status ( i18n("Opening device ..."), 0 );
int w = status.sizeHint().width()+20 ;
- if ( w < 200 ) w = 200;
+ if ( w < 200 ) w = 230;
int h = status.sizeHint().height()+20 ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
- status.setCaption(i18n("Reading Phone Data") );
+ status.setCaption(i18n("Reading phone...") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
@@ -835,7 +836,7 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
bool gshutdown = false;
PhoneParser handler( calendar, mProfileName );
int ccc = 0;
- QString message = i18n("Processing event # ");
+ QString message = i18n(" Reading event # ");
int procCount = 0;
qDebug("Debug: only 10 calender items are downloaded ");
while (!gshutdown && ccc++ < 10) {
@@ -846,20 +847,24 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
if (error == ERR_EMPTY) break;
start = false;
handler.readEvent( existingCal, &note );
+ qDebug("Org loc %d ",note.Location);
+ //note.Location = 0;
+ error=Phone->SetCalendar(&s,&note);
+ qDebug("new loc %d ",note.Location);
}
start = true;
GSM_ToDoEntry ToDo;
ccc = 0;
- message = i18n("Processing todo # ");
+ message = i18n(" Reading todo # ");
procCount = 0;
- while (!gshutdown) {
+ while (!gshutdown && ccc++ < 10) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
error = Phone->GetNextToDo(&s, &ToDo, start);
if (error == ERR_EMPTY) break;
start = false;
- qDebug("ReadTodo %d ", ++ccc);
+ qDebug("ReadTodo %d ", ccc);
handler.readTodo( existingCal, &ToDo, &s);
}
@@ -868,19 +873,42 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
return true;
}
-void PhoneFormat::event2GSM( Event* ev, GSM_CalendarEntry*Note )
+#include <qcstring.h>
+void PhoneFormat::event2GSM( Calendar *cal,Event* ev, GSM_CalendarEntry*Note )
{
- QString eText = vfconverter.eventToString( ev );
+ QString eText = vfconverter.eventToString( ev, cal );
int pos = 0;
GSM_ToDoEntry dummy;
- GSM_DecodeVCALENDAR_VTODO( (unsigned char*)eText.latin1(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert event");
+ QByteArray ba;
+ QDataStream s ( ba, IO_WriteOnly );
+ s << eText.utf8();
+ GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, Note , &dummy, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert event done");
+ Note->Location = 0;
+ QString loc = ev->getID(mProfileName);
+ if ( !loc.isEmpty() ){
+ Note->Location = loc.toInt();
+ }
+
}
-void PhoneFormat::todo2GSM( Todo* todo, GSM_ToDoEntry *gsmTodo )
+void PhoneFormat::todo2GSM( Calendar *cal, Todo* todo, GSM_ToDoEntry *gsmTodo )
{
- QString tText = vfconverter.todoToString( todo );
+ qDebug( "Convert todo1");
+ QString tText = vfconverter.todoToString( todo, cal );
int pos = 0;
GSM_CalendarEntry dummy;
- GSM_DecodeVCALENDAR_VTODO( (unsigned char*)tText.latin1(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
+ QByteArray ba;
+ QDataStream s ( ba, IO_WriteOnly );
+ s << tText.utf8();
+ GSM_DecodeVCALENDAR_VTODO( (unsigned char*) ba.data(), &pos, &dummy, gsmTodo, Nokia_VCalendar, Nokia_VToDo );
+ qDebug( "Convert todo done ");
+ gsmTodo->Location = 0;
+ QString loc = todo->getID(mProfileName);
+ if ( !loc.isEmpty() ){
+ gsmTodo->Location = loc.toInt();
+ }
+
}
void PhoneFormat::afterSave( Incidence* inc)
{
@@ -895,18 +923,19 @@ void PhoneFormat::afterSave( Incidence* inc)
}
bool PhoneFormat::save( Calendar *calendar)
{
+ return true;
GSM_StateMachine s;
qDebug(" save ");
s.opened = false;
s.msg = NULL;
s.ConfigNum = 0;
- QLabel status ( i18n("Writing data. Opening device ..."), 0 );
+ QLabel status ( i18n(" Opening device ..."), 0 );
int w = status.sizeHint().width()+20 ;
- if ( w < 200 ) w = 200;
+ if ( w < 200 ) w = 230;
int h = status.sizeHint().height()+20 ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
- status.setCaption(i18n("Writing Phone Data") );
+ status.setCaption(i18n("Writing to phone...") );
status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
status.show();
status.raise();
@@ -923,17 +952,23 @@ bool PhoneFormat::save( Calendar *calendar)
bool gshutdown = false;
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
- QString message = i18n("Processing event # ");
+ QString message = i18n(" Processing event # ");
int procCount = 0;
- while ( ev ) {
- //qDebug("i %d ", ++i);
+ bool planB = true;// false;
+ while ( ev && ! planB) {
if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { // event was changed during sync or is a new one
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- event2GSM( ev, &Note );
+ qDebug("event1 %d ", procCount);
+ event2GSM( calendar, ev, &Note );
if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
error = Phone->DeleteCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e delete planB %d ", error);
+ break;
+ }
}
else if ( ev->getID(mProfileName).isEmpty() ) { // add new
// we have to do this later after deleting
@@ -941,24 +976,38 @@ bool PhoneFormat::save( Calendar *calendar)
}
else { // change existing
error = Phone->SetCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e change planB %d ", error);
+ break;
+ }
+ qDebug("Change Calendar. Location %d status: %d",Note.Location, error );
}
}
ev = er.next();
}
ev = er.first();
// pending get empty slots
- while ( ev ) {
+ int loc = 0;
+ while ( ev && ! planB) {
if ( ev->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL && ev->tempSyncStat() != SYNC_TEMPSTATE_DELETE) {
+ qDebug("event2 %d ", procCount);
if ( ev->getID(mProfileName).isEmpty() ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
//int newID ;//= pending
//ev->setID(mProfileName, QString::number( newID ));
- event2GSM( ev, &Note );
- Note.Location = 0;
+ event2GSM( calendar, ev, &Note );
+ ++loc;
+ Note.Location = loc;
error = Phone->AddCalendar(&s, &Note);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug(" e add planB %d ", error);
+ break;
+ }
ev->setID( mProfileName, QString::number( Note.Location ) );
- qDebug("New Calendar. Location %d ",Note.Location );
+ qDebug("New Calendar. Location %d stat %d %d",Note.Location ,error, ERR_UNKNOWN);
afterSave( ev );
} else {
afterSave( ev ); // setting temp sync stat for changed items
@@ -966,25 +1015,92 @@ bool PhoneFormat::save( Calendar *calendar)
}
ev = er.next();
}
+
+
+ if ( planB ) {
+ qDebug("delete all calendar...");
+ status.setText ( i18n("Deleting all calendar..."));
+ qApp->processEvents();
+ error=Phone->DeleteAllCalendar(&s);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ message = i18n(" Deleting event # ");
+ procCount = 0;
+ while (1) {
+ status.setText ( message + QString::number ( ++procCount ) );
+ qApp->processEvents();
+ qDebug("deleting event ... %d", procCount);
+ error = Phone->GetNextCalendar(&s,&Note,true);
+ if (error != ERR_NONE) break;
+ error = Phone->DeleteCalendar(&s,&Note);
+ }
+ qDebug("deleting calendar ... finished");
+ } else {
+ status.setText ( i18n("All calendar deleted!"));
+ qDebug("all cal deleted");
+ }
+ bool planC = false;
+ ev = er.first();
+ procCount = 0;
+ message = i18n(" Writing event # ");
+ while ( ev && ! planC) {
+ status.setText ( message + QString::number ( ++procCount ) );
+ qApp->processEvents();
+ event2GSM( calendar, ev, &Note );
+ Note.Location = procCount;
+ error=Phone->AddCalendar(&s,&Note);
+ if (error != ERR_NONE ) {
+ // we have currently no planC :-(
+ // planC = true;
+ //qDebug("add planC %d ", error);
+ //break;
+ // we remove the ID such that this todo is not deleted after next sync
+ ev->removeID(mProfileName);
+ ev->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ qDebug("error :cal adding loc %d planB stat %d ", Note.Location ,error);
+ } else {
+ qDebug("cal adding loc %d planB stat %d ", Note.Location ,error);
+ ev->setID(mProfileName, QString::number( Note.Location ));
+ afterSave( ev );
+ }
+ ev = er.next();
+ }
+ if ( planC ) {
+ qDebug("writing cal went wrong...");
+
+ // we have currently no planC :-(
+ }
+ }
GSM_ToDoEntry ToDoEntry;
QPtrList<Todo> tl = calendar->rawTodos();
Todo* to = tl.first();
- message = i18n("Processing todo # ");
+ message = i18n(" Processing todo # ");
procCount = 0;
- while ( to ) {
+ planB = false;
+ while ( to && ! planB ) {
if ( to->tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) {
+ qDebug("todo3 %d ", procCount);
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- todo2GSM( to, &ToDoEntry );
+ qDebug("todo5 %d ", procCount);
+ todo2GSM( calendar, to, &ToDoEntry );
if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { // delete
error=Phone->DeleteToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("delete planB %d ", error);
+ }
}
- else if ( to->getID("Sharp_DTM").isEmpty() ) { // add new
+ else if ( to->getID(mProfileName).isEmpty() ) { // add new
;
}
else { // change existing
error=Phone->SetToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("set planB %d ", error);
+ }
+ qDebug("Old Todo. Location %d %d",ToDoEntry.Location , error );
}
}
to = tl.next();
@@ -992,25 +1108,70 @@ bool PhoneFormat::save( Calendar *calendar)
// pending get empty slots
to = tl.first();
- while ( to ) {
+ while ( to && ! planB ) {
+ 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();
//int newID ;//= pending
//to->setID(mProfileName, QString::number( newID ));
- todo2GSM( to, &ToDoEntry );
+ todo2GSM( calendar,to, &ToDoEntry );
ToDoEntry.Location = 0;
error=Phone->AddToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ planB = true;
+ qDebug("new planB %d ", error);
+ }
to->setID(mProfileName, QString::number( ToDoEntry.Location ));
afterSave( to );
- qDebug("New Todo. Location %d ",ToDoEntry.Location );
+ qDebug("New Todo. Location %d %d",ToDoEntry.Location, error );
} else {
afterSave( to );
}
}
to = tl.next();
}
+ if ( planB ) {
+ qDebug("delete all ...");
+ error=Phone->DeleteAllToDo(&s);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ while (1) {
+ qDebug("deleting todo ...");
+ error = Phone->GetNextToDo(&s,&ToDoEntry,true);
+ if (error != ERR_NONE) break;
+ error = Phone->DeleteToDo(&s,&ToDoEntry);
+ }
+ qDebug("deleting todo ... finished");
+ } else {
+ qDebug("all todo deleted");
+ }
+ bool planC = false;
+ to = tl.first();
+ while ( to && ! planC ) {
+ todo2GSM( calendar,to, &ToDoEntry );
+ ToDoEntry.Location = 0;
+ error=Phone->AddToDo(&s,&ToDoEntry);
+ if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
+ // we have currently no planC :-(
+ // planC = true;
+ //qDebug("add planC %d ", error);
+ //break;
+ // we remove the ID such that this todo is not deleted after next sync
+ to->removeID(mProfileName);
+ to->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
+ } else {
+ qDebug("adding %d planB %d ", ToDoEntry.Location ,error);
+ to->setID(mProfileName, QString::number( ToDoEntry.Location ));
+ afterSave( to );
+ }
+ to = tl.next();
+ }
+ if ( planC ) {
+ // we have currently no planC :-(
+ }
+ }
return true;
}
QString PhoneFormat::dtToGSM( const QDateTime& dti, bool useTZ )
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 33b2091..2c2e51c 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -52,8 +52,8 @@ class PhoneFormat : public QObject {
static ulong getCsumEvent( Event* ev );
private:
VCalFormat vfconverter;
- void event2GSM( Event* ev, GSM_CalendarEntry*Note );
- void todo2GSM( Todo* ev, GSM_ToDoEntry *ToDo );
+ void event2GSM( Calendar *, Event* ev, GSM_CalendarEntry*Note );
+ void todo2GSM( Calendar *, Todo* ev, GSM_ToDoEntry *ToDo );
int initDevice(GSM_StateMachine *s);
QString getEventString( Event* );
QString getTodoString( Todo* );
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 1167e58..076cd3f 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -45,6 +45,7 @@ using namespace KCal;
VCalFormat::VCalFormat()
{
+ mCalendar = 0;
}
VCalFormat::~VCalFormat()
@@ -165,18 +166,20 @@ bool VCalFormat::fromString( Calendar *calendar, const QString &text )
return true;
}
-QString VCalFormat::eventToString( Event * event)
+QString VCalFormat::eventToString( Event * event, Calendar *calendar)
{
if ( !event ) return QString::null;
+ mCalendar = calendar;
VObject *vevent = eventToVEvent( event );
char *buf = writeMemVObject( 0, 0, vevent );
QString result( buf );
cleanVObject( vevent );
return result;
}
-QString VCalFormat::todoToString( Todo * todo )
+QString VCalFormat::todoToString( Todo * todo, Calendar *calendar )
{
if ( !todo ) return QString::null;
+ mCalendar = calendar;
VObject *vevent = eventToVTodo( todo );
char *buf = writeMemVObject( 0, 0, vevent );
QString result( buf );
diff --git a/libkcal/vcalformat.h b/libkcal/vcalformat.h
index 8490125..7b9ca26 100644
--- a/libkcal/vcalformat.h
+++ b/libkcal/vcalformat.h
@@ -62,8 +62,8 @@ class VCalFormat : public CalFormat {
Return calendar information as string.
*/
QString toString( Calendar * );
- QString eventToString( Event * );
- QString todoToString( Todo * );
+ QString eventToString( Event *, Calendar *calendar );
+ QString todoToString( Todo * ,Calendar *calendar );
protected:
/** translates a VObject of the TODO type into a Event */