From e954cc1e29b129982e4d07c4f490d7e881597374 Mon Sep 17 00:00:00 2001 From: zautrix Date: Sun, 01 Aug 2004 11:37:35 +0000 Subject: Made sync code more readable by using defines --- diff --git a/Makefile b/Makefile index 826e70e..19c57e5 100644 --- a/Makefile +++ b/Makefile @@ -26,19 +26,13 @@ SUBDIRS_MICROKDE = \ kaddressbook SUBDIRS_QTOPIA_PLUGIN = \ - kabc/converter/qtopia \ - kabc/plugins/qtopia \ - kaddressbook/xxport/qtopia + kabc/plugins/qtopia SUBDIRS_OPIE_PLUGIN = \ - kabc/converter/opie \ - kabc/plugins/opie \ - kaddressbook/xxport/opie + kabc/plugins/opie SUBDIRS_SHARP_PLUGIN = \ - kabc/converter/sharpdtm \ - kabc/plugins/sharpdtm \ - kaddressbook/xxport/sharpdtm + kabc/plugins/sharpdtm SUBDIRS_LDAP_PLUGIN = \ kabc/plugins/ldap @@ -148,10 +142,10 @@ variable_test: variable_info ifdef BUILD_NO_SHARP_PLUGIN @echo SHARP PLUGIN will not be build, because BUILD_NO_SHARP_PLUGIN is set to $(BUILD_NO_SHARP_PLUGIN) else - ifndef SHARPDTMSDK + ifndef SHARPDTMSDK @echo SHARP PLUGIN can not be build, because SHARPDTMSDK is set to $(SHARPDTMSDK) $(error SHARPDTMSDK is not defined) - endif + endif endif @echo -------------------------------------- @@ -196,9 +190,6 @@ tmake: objects \ libical/src/libical/Makefile$(PLATFORM) \ libical/src/libicalss/Makefile$(PLATFORM) \ kabc/Makefile$(PLATFORM) \ - kabc/converter/opie/Makefile$(PLATFORM) \ - kabc/converter/qtopia/Makefile$(PLATFORM) \ - kabc/converter/sharpdtm/Makefile$(PLATFORM) \ kabc/formats/binary/Makefile$(PLATFORM) \ kabc/plugins/file/Makefile$(PLATFORM) \ kabc/plugins/dir/Makefile$(PLATFORM) \ @@ -213,7 +204,6 @@ tmake: objects \ kmicromail/Makefile$(PLATFORM) \ kmicromail/libetpan/Makefile$(PLATFORM) \ kmicromail/libmailwrapper/Makefile$(PLATFORM) - @@ -245,16 +235,6 @@ libical/src/libicalss/Makefile$(PLATFORM): libical/src/libicalss/libicalssE.pro kabc/Makefile$(PLATFORM): kabc/kabcE.pro cd kabc; tmake "CONFIG+=$(RELEASE_DEBUG)" kabcE.pro -o Makefile$(PLATFORM) -kabc/converter/opie/Makefile$(PLATFORM): kabc/converter/opie/opieE.pro - cd kabc/converter/opie; tmake "CONFIG+=$(RELEASE_DEBUG)" opieE.pro -o Makefile$(PLATFORM) - -kabc/converter/qtopia/Makefile$(PLATFORM): kabc/converter/qtopia/qtopiaE.pro - cd kabc/converter/qtopia; tmake "CONFIG+=$(RELEASE_DEBUG)" qtopiaE.pro -o Makefile$(PLATFORM) - -kabc/converter/sharpdtm/Makefile$(PLATFORM): kabc/converter/sharpdtm/sharpdtmE.pro - cd kabc/converter/sharpdtm; tmake "CONFIG+=$(RELEASE_DEBUG)" sharpdtmE.pro -o Makefile$(PLATFORM) - - kabc/formats/binary/Makefile$(PLATFORM): kabc/formats/binary/kabcformat_binaryE.pro cd kabc/formats/binary; tmake "CONFIG+=$(RELEASE_DEBUG)" kabcformat_binaryE.pro -o Makefile$(PLATFORM) diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp index 58b3d70..fd68dc4 100644 --- a/korganizer/calendarview.cpp +++ b/korganizer/calendarview.cpp @@ -129,9 +129,7 @@ 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 { @@ -727,10 +725,10 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b // 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 "); @@ -750,8 +748,8 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b } } 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() ) @@ -774,10 +772,10 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b 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 @@ -785,31 +783,31 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b } 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; @@ -835,14 +833,15 @@ int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , b 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; @@ -996,13 +995,13 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int } } } 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 { @@ -1045,12 +1044,12 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int 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; @@ -1141,7 +1140,7 @@ bool CalendarView::syncCalendar(QString filename, int mode) void CalendarView::syncSharp() { #ifndef DESKTOP_VERSION - mGlobalSyncMode = SYNC_MODE_SHARP; + mGlobalSyncMode = SYNC_MODE_EXTERNAL; //mCurrentSyncDevice = "sharp-DTM"; if ( KOPrefs::instance()->mAskForPreferences ) edit_sync_options(); @@ -1160,17 +1159,19 @@ void CalendarView::syncSharp() { QPtrList 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() ); diff --git a/libkcal/sharpformat.cpp b/libkcal/sharpformat.cpp index f83f72e..973f19d 100644 --- a/libkcal/sharpformat.cpp +++ b/libkcal/sharpformat.cpp @@ -42,6 +42,7 @@ #include "calendarlocal.h" #include "sharpformat.h" +#include "syncdefines.h" using namespace KCal; @@ -91,7 +92,7 @@ class SharpParser : public QObject event = new Event; event->setZaurusId( attList[0].toInt() ); event->setZaurusUid( cSum ); - event->setZaurusStat( -2 ); + event->setZaurusStat(SYNC_TEMPSTATE_NEW_EXTERNAL ); event->setSummary( attList[2] ); event->setLocation( attList[3] ); @@ -202,7 +203,7 @@ class SharpParser : public QObject todo->setZaurusId( attList[0].toInt() ); todo->setZaurusUid( cSum ); - todo->setZaurusStat( -2 ); + todo->setZaurusStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); todo->setSummary( attList[7] ); todo->setDescription( attList[8]); @@ -467,7 +468,7 @@ int SharpFormat::getNumFromRecord( QString answer, Incidence* inc ) retval = newnum; inc->setZaurusId( newnum ); inc->setZaurusUid( getCsum( templist ) ); - inc->setZaurusStat( -4 ); + inc->setZaurusStat( SYNC_TEMPSTATE_NEW_ID ); } } } @@ -506,11 +507,11 @@ bool SharpFormat::save( Calendar *calendar) int procCount = 0; while ( ev ) { //qDebug("i %d ", ++i); - if ( ev->zaurusStat() != -2 ) { + if ( ev->zaurusStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString eString = getEventString( ev ); - if ( ev->zaurusStat() == -3 ) { // delete + if ( ev->zaurusStat() == SYNC_TEMPSTATE_DELETE ) { // delete // deleting empty strings does not work. // we write first and x and then delete the record with the x eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); @@ -592,11 +593,11 @@ bool SharpFormat::save( Calendar *calendar) message = i18n("Processing todo # "); procCount = 0; while ( to ) { - if ( to->zaurusStat() != -2 ) { + if ( to->zaurusStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { status.setText ( message + QString::number ( ++procCount ) ); qApp->processEvents(); QString eString = getTodoString( to ); - if ( to->zaurusStat() == -3 ) { // delete + if ( to->zaurusStat() == SYNC_TEMPSTATE_DELETE ) { // delete // deleting empty strings does not work. // we write first and x and then delete the record with the x eString = eString.replace( QRegExp(",\"\""),",\"x\"" ); diff --git a/libkcal/syncdefines.h b/libkcal/syncdefines.h new file mode 100644 index 0000000..57642ec --- a/dev/null +++ b/libkcal/syncdefines.h @@ -0,0 +1,22 @@ + +#ifndef _KSYNC_DEFINES_H_ +#define _KSYNC_DEFINES_H_ + +#define SYNC_PREF_LOCAL 0 +#define SYNC_PREF_REMOTE 1 +#define SYNC_PREF_NEWEST 2 +#define SYNC_PREF_ASK 3 +#define SYNC_PREF_FORCE_LOCAL 4 +#define SYNC_PREF_FORCE_REMOTE 5 +#define SYNC_PREF_TAKE_BOTH 6 + +#define SYNC_MODE_NORMAL 0 +#define SYNC_MODE_EXTERNAL 1 + +#define SYNC_TEMPSTATE_INITIAL 0 +#define SYNC_TEMPSTATE_NEW_EXTERNAL -2 +#define SYNC_TEMPSTATE_DELETE -3 +#define SYNC_TEMPSTATE_NEW_ID -4 + + +#endif diff --git a/libkdepim/ksyncprofile.h b/libkdepim/ksyncprofile.h index 238ffad..3f7f1ac 100644 --- a/libkdepim/ksyncprofile.h +++ b/libkdepim/ksyncprofile.h @@ -27,13 +27,9 @@ #include #include -#define SYNC_PREF_LOCAL 0 -#define SYNC_PREF_REMOTE 1 -#define SYNC_PREF_NEWEST 2 -#define SYNC_PREF_ASK 3 -#define SYNC_PREF_FORCE_LOCAL 4 -#define SYNC_PREF_FORCE_REMOTE 5 -#define SYNC_PREF_TAKE_BOTH 6 +#include + + class KConfig; -- cgit v0.9.0.2