summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp47
1 files changed, 24 insertions, 23 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 58b3d70..fd68dc4 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -120,27 +120,25 @@
#ifndef _WIN32_
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#else
#include <qprocess.h>
#endif
using namespace KOrg;
using namespace KCal;
extern int globalFlagBlockAgenda;
extern int globalFlagBlockStartup;
-#define SYNC_MODE_NORMAL 0
-#define SYNC_MODE_SHARP 1
-#define SYNC_MODE_QTOPIA 2
+
class KOBeamPrefs : public QDialog
{
public:
KOBeamPrefs( QWidget *parent=0, const char *name=0 ) :
QDialog( parent, name, true )
{
setCaption( i18n("Beam Options") );
QVBoxLayout* lay = new QVBoxLayout( this );
lay->setSpacing( 3 );
lay->setMargin( 3 );
QButtonGroup* format = new QButtonGroup( 1, Horizontal, i18n("File format"), this );
@@ -718,107 +716,107 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
//void setZaurusId(int id);
// int zaurusId() const;
// void setZaurusUid(int id);
// int zaurusUid() const;
// void setZaurusStat(int id);
// int zaurusStat() const;
// 0 equal
// 1 take local
// 2 take remote
// 3 cancel
QDateTime lastSync = mLastCalendarSync;
- if ( mGlobalSyncMode == SYNC_MODE_SHARP ) {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
bool remCh, locCh;
remCh = ( remote->zaurusUid() != local->zaurusUid() );
- locCh = ( local->zaurusStat() != local->revision() );
+ locCh = ( local->lastModified() > mLastCalendarSync );
//qDebug("locCh %d remCh %d locuid %d remuid %d", locCh, remCh,local->zaurusUid(), remote->zaurusUid() );
if ( !remCh && ! locCh ) {
//qDebug("both not changed ");
lastSync = local->lastModified().addDays(1);
} else {
if ( locCh ) {
//qDebug("loc changed %d %d", local->zaurusStat(), local->revision() );
lastSync = local->lastModified().addDays( -1 );
if ( !remCh )
remote->setLastModified( lastSync.addDays( -1 ) );
} else {
//qDebug(" not loc changed ");
lastSync = local->lastModified().addDays( 1 );
if ( remCh )
remote->setLastModified( lastSync.addDays( 1 ) );
}
}
full = true;
- if ( mode < 3 )
- mode = 3;
+ if ( mode < SYNC_PREF_ASK )
+ mode = SYNC_PREF_ASK;
} else {
if ( local->lastModified() == remote->lastModified() )
if ( local->revision() == remote->revision() )
return 0;
}
// qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() );
//qDebug("%s %d %s %d", local->lastModified().toString().latin1() , local->revision(), remote->lastModified().toString().latin1(), remote->revision());
//qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() );
//full = true; //debug only
if ( full ) {
bool equ = false;
if ( local->type() == "Event" ) {
equ = (*((Event*) local) == *((Event*) remote));
}
else if ( local->type() =="Todo" )
equ = (*((Todo*) local) == (*(Todo*) remote));
else if ( local->type() =="Journal" )
equ = (*((Journal*) local) == *((Journal*) remote));
if ( equ ) {
//qDebug("equal ");
- if ( mGlobalSyncMode == SYNC_MODE_SHARP ) {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
local->setZaurusUid( remote->zaurusUid() );
}
- if ( mode < 4 )
+ if ( mode < SYNC_PREF_FORCE_LOCAL )
return 0;
}//else //debug only
//qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1());
}
int result;
bool localIsNew;
- if ( full && mode < 2 )
- mode = 3;
+ if ( full && mode < SYNC_PREF_NEWEST )
+ mode = SYNC_PREF_ASK;
switch( mode ) {
- case 0:
+ case SYNC_PREF_LOCAL:
if ( lastSync > remote->lastModified() )
return 1;
if ( lastSync > local->lastModified() )
return 2;
return 1;
break;
- case 1:
+ case SYNC_PREF_REMOTE:
if ( lastSync > remote->lastModified() )
return 1;
if ( lastSync > local->lastModified() )
return 2;
return 2;
break;
- case 2:
+ case SYNC_PREF_NEWEST:
if ( local->lastModified() > remote->lastModified() )
return 1;
else
return 2;
break;
- case 3:
+ case SYNC_PREF_ASK:
//qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
if ( lastSync > remote->lastModified() )
return 1;
if ( lastSync > local->lastModified() )
return 2;
//qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), local->lastModified().toString().latin1(), remote->lastModified().toString().latin1() );
localIsNew = local->lastModified() > remote->lastModified();
if ( localIsNew )
getEventViewerDialog()->setColorMode( 1 );
else
getEventViewerDialog()->setColorMode( 2 );
getEventViewerDialog()->setIncidence(local);
@@ -826,32 +824,33 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b
getEventViewerDialog()->setColorMode( 2 );
else
getEventViewerDialog()->setColorMode( 1 );
getEventViewerDialog()->addIncidence(remote);
getEventViewerDialog()->setColorMode( 0 );
//qDebug("local %d remote %d ",local->relatedTo(),remote->relatedTo() );
getEventViewerDialog()->setCaption( mCurrentSyncDevice +i18n(" : Conflict! Please choose entry!"));
getEventViewerDialog()->showMe();
result = getEventViewerDialog()->executeS( localIsNew );
return result;
break;
- case 4:
+ case SYNC_PREF_FORCE_LOCAL:
return 1;
break;
- case 5:
+ case SYNC_PREF_FORCE_REMOTE:
return 2;
break;
default:
+ // SYNC_PREF_TAKE_BOTH not implemented
break;
}
return 0;
}
Event* CalendarView::getLastSyncEvent()
{
Event* lse;
//qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
lse = mCalendar->event( "last-syncEvent-device-"+mCurrentSyncDevice );
if (!lse) {
lse = new Event();
lse->setUid( "last-syncEvent-device-"+mCurrentSyncDevice );
@@ -987,31 +986,31 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
inL->setRevision( maxrev );
remote->addIncidence( inL->clone() );
++changedRemote;
} else {
if ( inR->revision() < maxrev )
inR->setRevision( maxrev );
local->deleteIncidence( inL );
local->addIncidence( inR->clone() );
++changedLocal;
}
}
} else { // no conflict
- if ( mGlobalSyncMode == SYNC_MODE_SHARP ) {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
QString des = eventLSync->description();
QString pref = "e";
if ( inR->type() == "Todo" )
pref = "t";
if ( des.find(pref+QString::number( inR->zaurusId() ) +"," ) >= 0 && mode != 5) { // delete it
- inR->setZaurusStat( -3 );
+ inR->setZaurusStat( SYNC_TEMPSTATE_DELETE );
//remote->deleteIncidence( inR );
++deletedEventR;
} else {
inR->setLastModified( modifiedCalendar );
local->addIncidence( inR->clone() );
++addedEvent;
}
} else {
if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
inR->setLastModified( modifiedCalendar );
local->addIncidence( inR->clone() );
++addedEvent;
@@ -1036,30 +1035,30 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
while ( inL ) {
qApp->processEvents();
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
++incCounter;
uid = inL->uid();
bool skipIncidence = false;
if ( uid.left(21) == QString("last-syncEvent-device") )
skipIncidence = true;
- if ( mGlobalSyncMode == SYNC_MODE_SHARP && inL->type() == "Journal" )
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL && inL->type() == "Journal" )
skipIncidence = true;
if ( !skipIncidence ) {
inR = remote->incidence( uid );
if ( ! inR ) {
- if ( mGlobalSyncMode == SYNC_MODE_SHARP ) {
+ if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
if ( inL->zaurusId() >= 0 && mode != 4 ) {
local->deleteIncidence( inL );
++deletedEventL;
} else {
if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
inL->setZaurusId( -1 );
++addedEventR;
inL->setLastModified( modifiedCalendar );
remote->addIncidence( inL->clone() );
}
}
} else {
@@ -1132,54 +1131,56 @@ bool CalendarView::syncCalendar(QString filename, int mode)
}
setModified( true );
}
delete storage;
delete calendar;
if ( syncOK )
updateView();
return syncOK;
}
void CalendarView::syncSharp()
{
#ifndef DESKTOP_VERSION
- mGlobalSyncMode = SYNC_MODE_SHARP;
+ mGlobalSyncMode = SYNC_MODE_EXTERNAL;
//mCurrentSyncDevice = "sharp-DTM";
if ( KOPrefs::instance()->mAskForPreferences )
edit_sync_options();
qApp->processEvents();
CalendarLocal* calendar = new CalendarLocal();
calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
bool syncOK = false;
SharpFormat sharpFormat;
if ( sharpFormat.load( calendar, mCalendar ) ) {
getEventViewerDialog()->setSyncMode( true );
syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
getEventViewerDialog()->setSyncMode( false );
qApp->processEvents();
if ( syncOK ) {
if ( KOPrefs::instance()->mWriteBackFile )
{
QPtrList<Incidence> iL = mCalendar->rawIncidences();
Incidence* inc = iL.first();
+ /* obsolete
while ( inc ) {
inc->setZaurusStat( inc->revision () );
inc = iL.next();
}
+ */
// pending: clean last sync event description
sharpFormat.save(calendar);
iL = calendar->rawIncidences();
inc = iL.first();
Incidence* loc;
while ( inc ) {
- if ( inc->zaurusStat() == -4 ) {
+ if ( inc->zaurusStat() == SYNC_TEMPSTATE_NEW_ID ) {
loc = mCalendar->incidence(inc->uid() );
if ( loc ) {
loc->setZaurusId( inc->zaurusId() );
loc->setZaurusUid( inc->zaurusUid() );
}
}
inc = iL.next();
}
Incidence* lse = getLastSyncEvent();
if ( lse ) {
lse->setReadOnly( false );
lse->setDescription( "" );