summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp44
-rw-r--r--libkcal/calendarlocal.cpp27
2 files changed, 41 insertions, 30 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 1800cf2..8385bcc 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1686,145 +1686,151 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
qDebug("KO: mLastCalendarSync %s .Full: %d",mLastCalendarSync.toString().latin1(), fullDateRange);
QPtrList<Incidence> er = remote->rawIncidences();
Incidence* inR = er.first();
Incidence* inL;
QProgressBar bar( er.count(),0 );
bar.setCaption (i18n("Syncing - close to abort!") );
// ************** setting up filter *************
CalFilter *filterIN = 0;
CalFilter *filterOUT = 0;
CalFilter *filter = mFilters.first();
while(filter) {
if ( filter->name() == mSyncManager->mFilterInCal )
filterIN = filter;
if ( filter->name() == mSyncManager->mFilterOutCal )
filterOUT = filter;
filter = mFilters.next();
}
int w = 300;
if ( QApplication::desktop()->width() < 320 )
w = 220;
int h = bar.sizeHint().height() ;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
bar.show();
int modulo = (er.count()/10)+1;
int incCounter = 0;
while ( inR ) {
if ( ! bar.isVisible() )
return false;
if ( incCounter % modulo == 0 )
bar.setProgress( incCounter );
++incCounter;
uid = inR->uid();
bool skipIncidence = false;
if ( uid.left(15) == QString("last-syncEvent-") )
skipIncidence = true;
QString idS;
qApp->processEvents();
if ( !skipIncidence ) {
int hasCalId = 0;
inL = local->incidenceForUid( uid , false , true, &hasCalId );
if ( hasCalId && !inL )
inL = local->incidenceForUid( uid , false , true, &hasCalId );
else
hasCalId = 0;
if ( inL ) { // maybe conflict - same uid in both calendars
- if ( hasCalId )
- qDebug("KO: Cal id %d conflict detected: %s ", hasCalId, inL->summary().latin1());
+
if ( (take = takeEvent( inL, inR, mode, fullDateRange )) > 0 ) {
//qDebug("take %d %s ", take, inL->summary().latin1());
if ( take == 3 )
return false;
if ( take == 1 ) {// take local **********************
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL )
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
else
idS = inR->IDStr();
int calID = inR->calID();
remote->deleteIncidence( inR );
- inR = inL->clone();
- inR->setCalID_block( calID );
- inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
- if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
- inR->setIDStr( idS );
- remote->addIncidence( inR );
- if ( mSyncManager->syncWithDesktop() )
- inR->setPilotId( 2 );
- ++changedRemote;
+ if ( !hasCalId ) {
+ inR = inL->clone();
+ inR->setCalID_block( calID );
+ inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
+ if ( mGlobalSyncMode != SYNC_MODE_EXTERNAL )
+ inR->setIDStr( idS );
+ remote->addIncidence( inR );
+ if ( mSyncManager->syncWithDesktop() )
+ inR->setPilotId( 2 );
+ ++changedRemote;
+ } else
+ ++deletedEventR;
} else {// take remote **********************
if ( !inL->isReadOnly() ) {
idS = inL->IDStr();
int pid = inL->pilotId();
int calID = inL->calID();
- if ( hasCalId )
- calID = hasCalId;
+ if ( hasCalId )
+ calID = 0;// add to default calendar
local->deleteIncidence( inL );
inL = inR->clone();
inL->setCalID_block( calID );
if ( mSyncManager->syncWithDesktop() )
inL->setPilotId( pid );
inL->setIDStr( idS );
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
}
local->addIncidence( inL );
++changedLocal;
}
}
} else {
// take == 0; events equal
- if ( hasCalId )
- qDebug("EV EQUALLLL **************************** ");
+ if ( hasCalId ) {
+ qDebug("KO: Changing Cal id %d to %d for : %s ", hasCalId, local->defaultCalendar(),inL->summary().latin1());
+ inL->setCalID( local->defaultCalendar() );
+ }
}
+
+
} else { // no conflict ********** add or delete remote
if ( !filterIN || filterIN->filterCalendarItem( inR ) ){
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
QString des = eventLSync->description();
QString pref = "e";
if ( inR->typeID() == todoID )
pref = "t";
if ( des.find(pref+ inR->getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it
inR->setTempSyncStat( SYNC_TEMPSTATE_DELETE );
//remote->deleteIncidence( inR );
++deletedEventR;
} else {
inR->setLastModified( modifiedCalendar );
inL = inR->clone();
inL->setIDStr( ":" );
inL->setCsum( mCurrentSyncDevice, inR->getCsum(mCurrentSyncDevice) );
inL->setID( mCurrentSyncDevice, inR->getID(mCurrentSyncDevice) );
inL->setCalID_block( 0 );// add to default cal
local->addIncidence( inL );
++addedEvent;
}
} else {
if ( inR->lastModified() > mLastCalendarSync || mode == 5 ) {
inR->setLastModified( modifiedCalendar );
inL = inR->clone();
inL->setIDStr( ":" );
inL->setCalID_block( 0 );// add to default cal
local->addIncidence( inL );
++addedEvent;
} else {
checkExternSyncEvent(eventRSyncSharp, inR);
remote->deleteIncidence( inR );
++deletedEventR;
}
}
} else {
++filteredIN;
}
}
}
inR = er.next();
}
QPtrList<Incidence> el = local->rawIncidences();
inL = el.first();
modulo = (el.count()/10)+1;
@@ -2437,106 +2443,102 @@ bool CalendarView::openCalendar(QString filename, bool merge)
return true;
} else {
// while failing to load, the calendar object could
// have become partially populated. Clear it out.
if ( !merge ) {
mCalendar->close();
mViewManager->setDocumentId( filename );
mDialogManager->setDocumentId( filename );
mTodoList->setDocumentId( filename );
}
//KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
globalFlagBlockAgenda = 2;
mCalendar->reInitAlarmSettings();
setSyncEventsReadOnly();
updateUnmanagedViews();
updateView();
}
return false;
}
void CalendarView::mergeFile( QString fn )
{
clearAllViews();
mCalendar->mergeCalendarFile( fn );
mCalendar->reInitAlarmSettings();
setSyncEventsReadOnly();
updateUnmanagedViews();
updateView();
}
void CalendarView::mergeFileResource( QString fn ,QString resource )
{
if ( resource == "ALL" ) {
mCalendar->setAllCalendarEnabled( true );
mergeFile( fn );
restoreCalendarSettings();
return;
}
int exclusiveResource = KOPrefs::instance()->getFuzzyCalendarID( resource );
if ( !exclusiveResource ) {
qDebug("KO: CalendarView::mergeFileResource: resource not found %s", resource.latin1() );
return;
}
clearAllViews();
mCalendar->setCalendarRemove( exclusiveResource );
- int def = mCalendar->defaultCalendar();
mCalendar->setDefaultCalendar(exclusiveResource);
+ mCalendar->setAllCalendarEnabled( true );
if ( !mCalendar->addCalendarFile( fn, exclusiveResource )) {
qDebug("KO: CalendarView::mergeFileResource: error adding file %s", fn.latin1() );
}
- mCalendar->setDefaultCalendar( def );
- mCalendar->reInitAlarmSettings();
- setSyncEventsReadOnly();
- updateUnmanagedViews();
- updateView();
+ restoreCalendarSettings();
}
void CalendarView::showOpenError()
{
KMessageBox::error(this,i18n("Couldn't load calendar\n."));
}
void CalendarView::setLoadedFileVersion(QDateTime dt)
{
loadedFileVersion = dt;
}
bool CalendarView::checkFileChanged(QString fn)
{
QFileInfo finf ( fn );
if ( !finf.exists() )
return true;
QDateTime dt = finf.lastModified ();
if ( dt <= loadedFileVersion )
return false;
return true;
}
void CalendarView::watchSavedFile()
{
QFileInfo finf ( MainWindow::defaultFileName());
if ( !finf.exists() )
return;
QDateTime dt = finf.lastModified ();
if ( dt < loadedFileVersion ) {
//qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
return;
}
loadedFileVersion = dt;
}
bool CalendarView::checkAllFileVersions()
{
QPtrList<KopiCalendarFile> calendars = KOPrefs::instance()->mCalendars;
KopiCalendarFile * cal = calendars.first();
mCalendar->setDefaultCalendar( 1 );
mCalendar->setDefaultCalendarEnabledOnly();
if ( !cal->isReadOnly && !cal->mErrorOnLoad ) {
if ( !checkFileVersion(MainWindow::defaultFileName())) {
restoreCalendarSettings();
return false;
}
}
cal = calendars.next();
QDateTime storeTemp = loadedFileVersion;
while ( cal ) {
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 980663f..8a5a76f 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -214,144 +214,153 @@ bool CalendarLocal::mergeCalendar( Calendar* remote )
}
} else {
inL = inR->clone();
inL->setCalID_block( 0 );// add to default cal
addIncidence( inL );
}
inR = er.next();
}
return true;
}
bool CalendarLocal::addCalendarFile( QString name, int id )
{
CalendarLocal calendar( timeZoneId() );
calendar.setDefaultCalendar( id );
if ( calendar.load( name ) ) {
addCalendar( &calendar );
return true;
}
return false;
}
void CalendarLocal::setSyncEventsEnabled()
{
Event * ev;
ev = mEventList.first();
while ( ev ) {
if ( ev->uid().left(15) == QString("last-syncEvent-") )
ev->setCalEnabled( true );
ev = mEventList.next();
}
}
void CalendarLocal::setSyncEventsReadOnly()
{
Event * ev;
ev = mEventList.first();
while ( ev ) {
if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
ev->setReadOnly( true );
}
ev = mEventList.next();
}
}
void CalendarLocal::addCalendar( Calendar* cal )
{
cal->setDontDeleteIncidencesOnClose();
setSyncEventsEnabled();
+ QPtrList<Incidence> incList;
{
QPtrList<Event> EventList = cal->rawEvents();
- QPtrList<Event> el;
Event * ev = EventList.first();
while ( ev ) {
- if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
- Event * se = event( ev->uid() );
- if ( se )
- el.append( se );
+ if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
ev->setCalID_block( 1 );
}
+ Event * se = event( ev->uid() );
+ if ( se )
+ incList.append( se );
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mEventList.append( ev );
ev = EventList.next();
}
- for ( ev = el.first(); ev; ev = el.next() ) {
- deleteIncidence ( ev );
- }
+
}
{
QPtrList<Todo> TodoList = cal->rawTodos();
Todo * ev = TodoList.first();
while ( ev ) {
ev->resetRelatedTo();
ev = TodoList.next();
}
//TodoList = cal->rawTodos();
ev = TodoList.first();
- while ( ev ) {
+ while ( ev ) {
+ Todo * se = todo( ev->uid() );
+ if ( se )
+ incList.append( se );
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mTodoList.append( ev );
setupRelations( ev );
ev = TodoList.next();
}
}
{
QPtrList<Journal> JournalList = cal->journals();
Journal * ev = JournalList.first();
while ( ev ) {
+ Journal * se = journal( ev->uid() );
+ if ( se )
+ incList.append( se );
ev->unRegisterObserver( cal );
ev->registerObserver( this );
mJournalList.append( ev );
ev = JournalList.next();
}
}
+ {
+ for (Incidence * ev = incList.first(); ev; ev = incList.next() ) {
+ deleteIncidence ( ev );
+ }
+ }
setModified( true );
}
bool CalendarLocal::load( const QString &fileName )
{
FileStorage storage( this, fileName );
return storage.load();
}
bool CalendarLocal::save( const QString &fileName, CalFormat *format )
{
FileStorage storage( this, fileName, format );
return storage.save();
}
void CalendarLocal::stopAllTodos()
{
for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
it->setRunning( false );
}
void CalendarLocal::close()
{
Todo * i;
for( i = mTodoList.first(); i; i = mTodoList.next() ) i->setRunning(false);
mEventList.setAutoDelete( true );
mTodoList.setAutoDelete( true );
mJournalList.setAutoDelete( true );
mEventList.clear();
mTodoList.clear();
mJournalList.clear();
mEventList.setAutoDelete( false );
mTodoList.setAutoDelete( false );
mJournalList.setAutoDelete( false );
setModified( false );
}
bool CalendarLocal::addAnniversaryNoDup( Event *event )
{
QString cat;
bool isBirthday = true;
if( event->categoriesStr() == i18n( "Anniversary" ) ) {
isBirthday = false;
cat = i18n( "Anniversary" );