summaryrefslogtreecommitdiffabout
path: root/libkcal
Side-by-side diff
Diffstat (limited to 'libkcal') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/event.cpp46
-rw-r--r--libkcal/event.h2
-rw-r--r--libkcal/phoneformat.cpp100
-rw-r--r--libkcal/phoneformat.h2
-rw-r--r--libkcal/todo.cpp58
-rw-r--r--libkcal/todo.h1
-rw-r--r--libkcal/vcalformat.cpp9
7 files changed, 159 insertions, 59 deletions
diff --git a/libkcal/event.cpp b/libkcal/event.cpp
index dfa265b..7256f05 100644
--- a/libkcal/event.cpp
+++ b/libkcal/event.cpp
@@ -47,24 +47,70 @@ Incidence *Event::clone()
return new Event(*this);
}
bool KCal::operator==( const Event& e1, const Event& e2 )
{
return operator==( (const Incidence&)e1, (const Incidence&)e2 ) &&
e1.dtEnd() == e2.dtEnd() &&
e1.hasEndDate() == e2.hasEndDate() &&
e1.transparency() == e2.transparency();
}
+bool Event::contains ( Event* from )
+{
+
+ if ( !from->summary().isEmpty() )
+ if ( !summary().startsWith( from->summary() ))
+ return false;
+ if ( from->dtStart().isValid() )
+ if (dtStart() != from->dtStart() )
+ return false;
+ if ( from->dtEnd().isValid() )
+ if ( dtEnd() != from->dtEnd() )
+ return false;
+ if ( !from->location().isEmpty() )
+ if ( !location().startsWith( from->location() ) )
+ return false;
+ if ( !from->description().isEmpty() )
+ if ( !description().startsWith( from->description() ))
+ return false;
+ if ( from->alarms().count() ) {
+ Alarm *a = from->alarms().first();
+ if ( a->enabled() ){
+ if ( !alarms().count() )
+ return false;
+ Alarm *b = alarms().first();
+ if( ! b->enabled() )
+ return false;
+ if ( ! (a->offset() == b->offset() ))
+ return false;
+ }
+ }
+ QStringList cat = categories();
+ QStringList catFrom = from->categories();
+ QString nCat;
+ int iii;
+ for ( iii = 0; iii < catFrom.count();++iii ) {
+ nCat = catFrom[iii];
+ if ( !nCat.isEmpty() )
+ if ( !cat.contains( nCat )) {
+ return false;
+ }
+ }
+ if ( from->doesRecur() )
+ if ( from->doesRecur() != doesRecur() && ! (from->doesRecur()== Recurrence::rYearlyMonth && doesRecur()== Recurrence::rYearlyDay) )
+ return false;
+ return true;
+}
void Event::setDtEnd(const QDateTime &dtEnd)
{
if (mReadOnly) return;
mDtEnd = getEvenTime( dtEnd );
setHasEndDate(true);
setHasDuration(false);
updated();
}
diff --git a/libkcal/event.h b/libkcal/event.h
index 2a8bd95..3bc8adc 100644
--- a/libkcal/event.h
+++ b/libkcal/event.h
@@ -62,24 +62,26 @@ class Event : public Incidence
bool hasEndDate() const;
/** Return true if the event spans multiple days, otherwise return false. */
bool isMultiDay() const;
/** set the event's time transparency level. */
void setTransparency(Transparency transparency);
/** get the event's time transparency level. */
Transparency transparency() const;
void setDuration(int seconds);
+ bool contains ( Event*);
+
private:
bool accept(Visitor &v) { return v.visit(this); }
QDateTime mDtEnd;
bool mHasEndDate;
Transparency mTransparency;
};
bool operator==( const Event&, const Event& );
}
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index 281434e..101db57 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -303,68 +303,75 @@ bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
vfload.setLocalTime ( true );
qDebug("loading file ...");
if ( ! vfload.load( calendar, fileName ) )
return false;
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
qDebug("reading events... ");
while ( ev ) {
QStringList cat = ev->categories();
if ( cat.contains( "MeetingDEF" )) {
ev->setCategories( QStringList() );
+ } else
+ if ( cat.contains( "Birthday" )) {
+ ev->setFloats( true );
+ QDate da = ev->dtStart().date();
+ ev->setDtStart( QDateTime( da) );
+ ev->setDtEnd( QDateTime( da.addDays(1)) );
+
}
+ uint cSum;
+ cSum = PhoneFormat::getCsumEvent( ev );
int id = ev->pilotId();
Event *event;
event = existingCal->event( mProfileName ,QString::number( id ) );
if ( event ) {
event = (Event*)event->clone();
copyEvent( event, ev );
calendar->deleteEvent( ev );
calendar->addEvent( event);
}
else
event = ev;
- uint cSum;
- cSum = PhoneFormat::getCsumEvent( event );
event->setCsum( mProfileName, QString::number( cSum ));
event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
event->setID( mProfileName,QString::number( id ) );
ev = er.next();
}
{
qDebug("reading todos... ");
QPtrList<Todo> tr = calendar->rawTodos();
Todo* ev = tr.first();
while ( ev ) {
QStringList cat = ev->categories();
if ( cat.contains( "MeetingDEF" )) {
ev->setCategories( QStringList() );
}
int id = ev->pilotId();
+ uint cSum;
+ cSum = PhoneFormat::getCsumTodo( ev );
Todo *event;
event = existingCal->todo( mProfileName ,QString::number( id ) );
if ( event ) {
//qDebug("copy todo %s ", event->summary().latin1());
event = (Todo*)event->clone();
copyTodo( event, ev );
calendar->deleteTodo( ev );
calendar->addTodo( event);
}
else
event = ev;
- uint cSum;
- cSum = PhoneFormat::getCsumTodo( event );
event->setCsum( mProfileName, QString::number( cSum ));
event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
event->setID( mProfileName,QString::number( id ) );
ev = tr.next();
}
}
return true;
}
void PhoneFormat::copyEvent( Event* to, Event* from )
{
if ( from->dtStart().isValid() )
to->setDtStart( from->dtStart() );
@@ -373,70 +380,69 @@ void PhoneFormat::copyEvent( Event* to, Event* from )
if ( !from->location().isEmpty() )
to->setLocation( from->location() );
if ( !from->description().isEmpty() )
to->setDescription( from->description() );
if ( !from->summary().isEmpty() )
to->setSummary( from->summary() );
if ( from->alarms().count() ) {
to->clearAlarms();
Alarm *a = from->alarms().first();
Alarm *b = to->newAlarm( );
b->setEnabled( a->enabled() );
- if ( a->hasStartOffset() ) {
- b->setStartOffset( a->startOffset() );
- }
- if ( a->hasTime() )
- b->setTime( a->time() );
+ b->setStartOffset(Duration( a->offset() ) );
}
QStringList cat = to->categories();
QStringList catFrom = from->categories();
QString nCat;
int iii;
for ( iii = 0; iii < catFrom.count();++iii ) {
nCat = catFrom[iii];
if ( !nCat.isEmpty() )
if ( !cat.contains( nCat )) {
cat << nCat;
}
}
to->setCategories( cat );
+ if ( from->doesRecur() ) {
Recurrence * r = new Recurrence( *from->recurrence(),to);
to->setRecurrence( r ) ;
+ }
}
void PhoneFormat::copyTodo( Todo* to, Todo* from )
{
- if ( from->dtStart().isValid() )
+ if ( from->hasStartDate() ) {
+ to->setHasStartDate( true );
to->setDtStart( from->dtStart() );
- if ( from->dtDue().isValid() )
+ }
+ if ( from->hasDueDate() ){
+ to->setHasDueDate( true );
to->setDtDue( from->dtDue() );
+ }
if ( !from->location().isEmpty() )
to->setLocation( from->location() );
if ( !from->description().isEmpty() )
to->setDescription( from->description() );
if ( !from->summary().isEmpty() )
to->setSummary( from->summary() );
if ( from->alarms().count() ) {
to->clearAlarms();
Alarm *a = from->alarms().first();
Alarm *b = to->newAlarm( );
b->setEnabled( a->enabled() );
- if ( a->hasStartOffset() )
- b->setStartOffset( a->startOffset() );
- if ( a->hasTime() )
- b->setTime( a->time() );
+ b->setStartOffset(Duration( a->offset() ) );
}
QStringList cat = to->categories();
QStringList catFrom = from->categories();
QString nCat;
int iii;
for ( iii = 0; iii < catFrom.count();++iii ) {
nCat = catFrom[iii];
if ( !nCat.isEmpty() )
if ( !cat.contains( nCat )) {
cat << nCat;
}
@@ -452,69 +458,52 @@ void PhoneFormat::copyTodo( Todo* to, Todo* from )
to->setPercentComplete(from->percentComplete());
}
if( to->priority() == 2 && from->priority() == 1 )
; //skip
else if (to->priority() == 4 && from->priority() == 5 )
;
else
to->setPriority(from->priority());
}
#include <qcstring.h>
-void PhoneFormat::afterSave( Incidence* inc)
+void PhoneFormat::afterSave( Incidence* inc,const QString& id ,const QString& csum)
{
- uint csum;
- inc->removeID( mProfileName );
- if ( inc->type() == "Event")
- csum = PhoneFormat::getCsumEvent( (Event*) inc );
- else
- csum = PhoneFormat::getCsumTodo( (Todo*) inc );
- inc->setCsum( mProfileName, QString::number( csum ));
-
+ inc->setID( mProfileName, id );
+ inc->setCsum( mProfileName, csum);
inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
}
bool PhoneFormat::writeToPhone( Calendar * calendar)
{
#ifdef _WIN32_
- QString fileName = locateLocal("tmp", "tempfile.vcs");
+ QString fileName = locateLocal("tmp", "phonefile.vcs");
#else
- QString fileName = "/tmp/kdepimtemp.vcs";
+ QString fileName = "/tmp/phonefile.vcs";
#endif
VCalFormat vfsave;
vfsave.setLocalTime ( true );
QString id = calendar->timeZoneId();
calendar->setLocalTime();
if ( ! vfsave.save( calendar, fileName ) )
return false;
calendar->setTimeZoneId( id );
return PhoneAccess::writeToPhone( fileName );
}
bool PhoneFormat::save( Calendar *calendar)
{
- QLabel status ( i18n(" Opening device ..."), 0 );
- int w = status.sizeHint().width()+20 ;
- 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 to phone...") );
- status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
- status.show();
- status.raise();
- qApp->processEvents();
- QString message;
+
// 1 remove events which should be deleted
QPtrList<Event> er = calendar->rawEvents();
Event* ev = er.first();
while ( ev ) {
if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
calendar->deleteEvent( ev );
} else {
}
ev = er.next();
}
@@ -525,95 +514,92 @@ bool PhoneFormat::save( Calendar *calendar)
if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
calendar->deleteTodo( to );
} else {
if ( to->isCompleted()) {
calendar->deleteTodo( to );
}
}
to = tl.next();
}
// 3 save file
if ( !writeToPhone( calendar ) )
return false;
-
+ QLabel status ( i18n(" Opening device ..."), 0 );
+ int w = status.sizeHint().width()+20 ;
+ 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 to phone...") );
+ status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
+ QString message;
+ status.show();
+ status.raise();
+ qApp->processEvents();
// 5 reread data
message = i18n(" Rereading all data ... ");
status.setText ( message );
qApp->processEvents();
CalendarLocal* calendarTemp = new CalendarLocal();
calendarTemp->setTimeZoneId( calendar->timeZoneId());
if ( ! load( calendarTemp,calendar) ){
qDebug("error reloading calendar ");
delete calendarTemp;
return false;
}
// 6 compare data
//algo 6 compare event
er = calendar->rawEvents();
ev = er.first();
message = i18n(" Comparing event # ");
QPtrList<Event> er1 = calendarTemp->rawEvents();
Event* ev1;
int procCount = 0;
while ( ev ) {
//qDebug("event new ID %s",ev->summary().latin1());
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- uint csum;
- csum = PhoneFormat::getCsumEvent( ev );
- QString cSum = QString::number( csum );
- //ev->setCsum( mProfileName, cSum );
- //qDebug("Event cSum %s ", cSum.latin1());
ev1 = er1.first();
while ( ev1 ) {
- if ( ev1->getCsum( mProfileName ) == cSum ) {
+ if ( ev->contains( ev1 ) ) {
+ afterSave( ev ,ev1->getID(mProfileName),ev1->getCsum(mProfileName));
er1.remove( ev1 );
- afterSave( ev );
- ev->setID(mProfileName, ev1->getID(mProfileName) );
- //qDebug("Event found on phone for %s ", ev->summary().latin1());
-
break;
}
ev1 = er1.next();
}
if ( ! ev1 ) {
// ev->removeID(mProfileName);
qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
}
ev = er.next();
}
//algo 6 compare todo
tl = calendar->rawTodos();
to = tl.first();
procCount = 0;
QPtrList<Todo> tl1 = calendarTemp->rawTodos();
Todo* to1 ;
message = i18n(" Comparing todo # ");
while ( to ) {
status.setText ( message + QString::number ( ++procCount ) );
qApp->processEvents();
- uint csum;
- csum = PhoneFormat::getCsumTodo( to );
- QString cSum = QString::number( csum );
- //to->setCsum( mProfileName, cSum );
- //qDebug("Todo cSum %s ", cSum.latin1());
Todo* to1 = tl1.first();
while ( to1 ) {
- if ( to1->getCsum( mProfileName ) == cSum ) {
+ if ( to->contains( to1 ) ) {
+ afterSave( to ,to1->getID(mProfileName),to1->getCsum(mProfileName));
tl1.remove( to1 );
- afterSave( to );
- 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());
}
to = tl.next();
}
delete calendarTemp;
diff --git a/libkcal/phoneformat.h b/libkcal/phoneformat.h
index 001fd81..d11f68b 100644
--- a/libkcal/phoneformat.h
+++ b/libkcal/phoneformat.h
@@ -45,18 +45,18 @@ class PhoneFormat : public QObject {
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 );
static bool writeToPhone( Calendar * );
private:
void copyEvent( Event* to, Event* from );
void copyTodo( Todo* to, Todo* from );
//int initDevice(GSM_StateMachine *s);
QString mProfileName;
- void afterSave( Incidence* );
+ void afterSave( Incidence* ,const QString&,const QString&);
};
}
#endif
diff --git a/libkcal/todo.cpp b/libkcal/todo.cpp
index 0c1e3e4..3d2de61 100644
--- a/libkcal/todo.cpp
+++ b/libkcal/todo.cpp
@@ -47,25 +47,83 @@ Todo::Todo(const Todo &t) : Incidence(t)
}
Todo::~Todo()
{
}
Incidence *Todo::clone()
{
return new Todo(*this);
}
+bool Todo::contains ( Todo* from )
+{
+ if ( !from->summary().isEmpty() )
+ if ( !summary().startsWith( from->summary() ))
+ return false;
+ if ( from->hasStartDate() ) {
+ if ( !hasStartDate() )
+ return false;
+ if ( from->dtStart() != dtStart())
+ return false;
+ }
+ if ( from->hasDueDate() ){
+ if ( !hasDueDate() )
+ return false;
+ if ( from->dtDue() != dtDue())
+ return false;
+ }
+ if ( !from->location().isEmpty() )
+ if ( !location().startsWith( from->location() ) )
+ return false;
+ if ( !from->description().isEmpty() )
+ if ( !description().startsWith( from->description() ))
+ return false;
+ if ( from->alarms().count() ) {
+ Alarm *a = from->alarms().first();
+ if ( a->enabled() ){
+ if ( !alarms().count() )
+ return false;
+ Alarm *b = alarms().first();
+ if( ! b->enabled() )
+ return false;
+ if ( ! (a->offset() == b->offset() ))
+ return false;
+ }
+ }
+
+ QStringList cat = categories();
+ QStringList catFrom = from->categories();
+ QString nCat;
+ int iii;
+ for ( iii = 0; iii < catFrom.count();++iii ) {
+ nCat = catFrom[iii];
+ if ( !nCat.isEmpty() )
+ if ( !cat.contains( nCat )) {
+ return false;
+ }
+ }
+ if ( from->isCompleted() ) {
+ if ( !isCompleted() )
+ return false;
+ }
+ if( priority() != from->priority() )
+ return false;
+
+
+ return true;
+
+}
bool KCal::operator==( const Todo& t1, const Todo& t2 )
{
bool ret = operator==( (const Incidence&)t1, (const Incidence&)t2 );
if ( ! ret )
return false;
if ( t1.hasDueDate() == t2.hasDueDate() ) {
if ( t1.hasDueDate() ) {
if ( t1.doesFloat() == t2.doesFloat() ) {
if ( t1.doesFloat() ) {
if ( t1.dtDue().date() != t2.dtDue().date() )
return false;
diff --git a/libkcal/todo.h b/libkcal/todo.h
index 9aa92f8..0f22c59 100644
--- a/libkcal/todo.h
+++ b/libkcal/todo.h
@@ -90,24 +90,25 @@ class Todo : public Incidence
range from 0 to 100.
*/
void setPercentComplete(int);
/** return date and time when todo was completed */
QDateTime completed() const;
QString completedStr() const;
/** set date and time of completion */
void setCompleted(const QDateTime &completed);
/** Return true, if todo has a date associated with completion */
bool hasCompletedDate() const;
+ bool contains ( Todo*);
private:
bool accept(Visitor &v) { return v.visit(this); }
QDateTime mDtDue; // due date of todo
bool mHasDueDate; // if todo has associated due date
// int mStatus; // confirmed/delegated/tentative/etc
QDateTime mCompleted;
bool mHasCompletedDate;
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index a6ae1bc..df93209 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -53,24 +53,25 @@ VCalFormat::VCalFormat()
VCalFormat::~VCalFormat()
{
}
void VCalFormat::setLocalTime ( bool b )
{
useLocalTime = b;
}
bool VCalFormat::load(Calendar *calendar, const QString &fileName)
{
mCalendar = calendar;
clearException();
+ if ( ! useLocalTime )
useLocalTime = mCalendar->isLocalTime();
VObject *vcal = 0;
// this is not necessarily only 1 vcal. Could be many vcals, or include
// a vcard...
vcal = Parse_MIME_FromFileName(const_cast<char *>(QFile::encodeName(fileName).data()));
if (!vcal) {
setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
return FALSE;
}
@@ -81,24 +82,25 @@ bool VCalFormat::load(Calendar *calendar, const QString &fileName)
// clean up from vcal API stuff
cleanVObjects(vcal);
cleanStrTbl();
return true;
}
bool VCalFormat::save(Calendar *calendar, const QString &fileName)
{
mCalendar = calendar;
+ if ( ! useLocalTime )
useLocalTime = mCalendar->isLocalTime();
QString tmpStr;
VObject *vcal, *vo;
vcal = newVObject(VCCalProp);
// addPropValue(vcal,VCLocationProp, "0.0");
addPropValue(vcal,VCProdIdProp, productId());
tmpStr = mCalendar->getTimeZoneStr();
//qDebug("mCalendar->getTimeZoneStr() %s",tmpStr.latin1() );
@@ -1163,24 +1165,26 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate);
} else {
int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
if (rDuration == 0)
anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1);
else
anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration);
}
}
/*********************** YEARLY-BY-MONTH *******************************/
else if (tmpStr.left(2) == "YM") {
+ // we have to set this such that recurrence accepts addYearlyNum(tmpDay);
+ anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, 1, -1);
int index = tmpStr.find(' ');
int last = tmpStr.findRev(' ') + 1;
int rFreq = tmpStr.mid(2, (index-1)).toInt();
index += 1;
short tmpMonth;
if( index == last ) {
// e.g. YM1 #0
tmpMonth = anEvent->dtStart().date().month();
anEvent->recurrence()->addYearlyNum(tmpMonth);
}
else {
// e.g. YM1 3 #0
@@ -1197,24 +1201,26 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate);
} else {
int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
if (rDuration == 0)
anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1);
else
anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration);
}
}
/*********************** YEARLY-BY-DAY *********************************/
else if (tmpStr.left(2) == "YD") {
+ // we have to set this such that recurrence accepts addYearlyNum(tmpDay);
+ anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, 1, -1);
int index = tmpStr.find(' ');
int last = tmpStr.findRev(' ') + 1;
int rFreq = tmpStr.mid(2, (index-1)).toInt();
index += 1;
short tmpDay;
if( index == last ) {
// e.g. YD1 #0
tmpDay = anEvent->dtStart().date().dayOfYear();
anEvent->recurrence()->addYearlyNum(tmpDay);
}
else {
// e.g. YD1 123 #0
@@ -1527,29 +1533,30 @@ void VCalFormat::populate(VObject *vcal)
// warn the user we might have trouble reading this unknown version.
if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
char *s = fakeCString(vObjectUStringZValue(curVO));
if (strcmp(_VCAL_VERSION, s) != 0)
kdDebug() << "This vCalendar file has version " << s
<< "We only support " << _VCAL_VERSION << endl;
deleteStr(s);
}
// set the time zone
if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
+ if ( vObjectUStringZValue(curVO) != 0 ) {
char *s = fakeCString(vObjectUStringZValue(curVO));
mCalendar->setTimeZone(s);
deleteStr(s);
}
-
+ }
// Store all events with a relatedTo property in a list for post-processing
mEventsRelate.clear();
mTodosRelate.clear();
initPropIterator(&i, vcal);
// go through all the vobjects in the vcal
while (moreIteration(&i)) {
curVO = nextVObject(&i);
/************************************************************************/