summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Side-by-side diff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp32
1 files changed, 31 insertions, 1 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index d51187a..316826a 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -870,795 +870,825 @@ void CalendarView::checkAlarms()
if ( ok ) {
//qDebug("OK %s",next.toString().latin1());
if ( next < cur ) {
al.append( inL );
//qDebug("found missed alarm: %s ", inL->summary().latin1() );
}
}
inL = el.next();
}
if ( al.count() ) {
QDialog* dia = new QDialog( this, "huhu", false, WDestructiveClose | WStyle_StaysOnTop );
dia->setCaption( i18n("KO/Pi: Missing alarms!") );
QVBoxLayout* lay = new QVBoxLayout( dia );
lay->setSpacing( 0 );
lay->setMargin( 0 );
MissedAlarmTextBrowser* matb = new MissedAlarmTextBrowser ( dia, al, latest );
connect( matb, SIGNAL( showIncidence( QString ) ),SLOT( showIncidence( QString ) ));
lay->addWidget( matb );
if ( QApplication::desktop()->width() == 480 || QApplication::desktop()->width() == 640 ) {
int wid = 210;
int x = QApplication::desktop()->width() - wid - 7;
int y = QApplication::desktop()->height() - wid - 70;
dia->setGeometry ( x,y,wid,wid);
} else {
int si = 220;
if ( QApplication::desktop()->width() > 470 )
si = 400;
dia->resize(si,si/2);
}
dia->setBackgroundColor( QColor( 255, 255, 255 ) );
dia->show();
}
#if 0
// for creating timetracker test data
qDebug("CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCc ");
Todo * nt;
mCalendar->close();
{
Todo * root1 = new Todo;
mCalendar->addTodo( root1 );
root1->setSummary( "Project1");
root1->setPriority( 1 );
root1->setCategories( QString( "Cat_Pro1") );
root1->setDescription( "This is a test description of a root Project" );
root1->setPercentComplete( 20 );
updateView();
QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project1");
nt->setPriority( 1 );
nt->setDescription( "This is a test description of Planning Project1" );
nt->setPercentComplete( 20 );
nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1") );
Todo * sub1 = nt;
sub1->setRelatedTo( root1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project1: Lutz");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setPercentComplete( 20 );
nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Lutz") );
Todo * workLutz11 = nt;
workLutz11->setRelatedTo( sub1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project1: Norbert");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setPercentComplete( 20 );
nt->setCategories( QString( "Cat_Pro1,Cat_Plan_Pro1,Cat_Work_Norbert") );
Todo * workNorbert11 = nt;
workNorbert11->setRelatedTo( sub1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 1");
nt->setPriority( 1 );
nt->setDescription( "This is a test description of Work Project_1" );
nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1") );
nt->setPercentComplete( 20 );
Todo * sub2 = nt;
sub2->setRelatedTo( root1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 1: Lutz");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Lutz") );
nt->setPercentComplete( 20 );
Todo * workLutz12 = nt;
workLutz12->setRelatedTo( sub2 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 1: Norbert");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro1,Cat_Work_Pro1,Cat_Work_Norbert") );
nt->setPercentComplete( 20 );
Todo * workNorbert12 = nt;
workNorbert12->setRelatedTo( sub2 );
int secLenRunning = 7200;
int secLenPausing = 3600 * 3;
int dayInterval = 1;
//createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, dayInterval );
createRunningDate4Todo( root1, start, end, secLenRunning*24, secLenPausing, 14 );
createRunningDate4Todo( sub1, start.addSecs( secLenRunning ), start.addDays( 10 ), secLenRunning*4, secLenPausing, 1);
createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*4, secLenPausing, 3);
createRunningDate4Todo( workLutz11, start, start.addDays( 8 ), secLenRunning, secLenPausing, 0);
createRunningDate4Todo( workNorbert11, start, start.addDays( 8 ), secLenRunning*2, secLenPausing, 1);
createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning*5, secLenPausing, 3);
createRunningDate4Todo( workNorbert12, start.addDays( 8 ), end, secLenRunning, secLenPausing*3, 0);
}
{
Todo * root1 = new Todo;
mCalendar->addTodo( root1 );
root1->setSummary( "Project2");
root1->setPriority( 1 );
root1->setDescription( "This is a test description of a root Project 2" );
root1->setPercentComplete( 20 );
root1->setCategories( QString( "Cat_Pro2") );
updateView();
QDateTime start = QDateTime ( QDate( 2004,11,1), QTime ( 7,30,0) );
QDateTime end = QDateTime ( QDate( 2005,8,5), QTime ( 0,0,0) );
int secLenRunning = 7200;
int secLenPausing = 3600 * 3;
int dayInterval = 1;
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project2");
nt->setPriority( 1 );
nt->setDescription( "This is a test description of Planning_Project_2" );
nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2") );
nt->setPercentComplete( 20 );
Todo * sub1 = nt;
sub1->setRelatedTo( root1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project2: Lutz");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Lutz") );
nt->setPercentComplete( 20 );
Todo * workLutz11 = nt;
workLutz11->setRelatedTo( sub1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Planning Project2: Norbert");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro2,Cat_Plan_Pro2,Cat_Work_Norbert") );
nt->setPercentComplete( 20 );
Todo * workNorbert11 = nt;
workNorbert11->setRelatedTo( sub1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 2");
nt->setPriority( 1 );
nt->setDescription( "This is a test description of Work Project_2" );
nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2") );
nt->setPercentComplete( 20 );
Todo * sub2 = nt;
sub2->setRelatedTo( root1 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 2: Lutz");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Lutz") );
nt->setPercentComplete( 20 );
Todo * workLutz12 = nt;
workLutz12->setRelatedTo( sub2 );
nt = new Todo;
mCalendar->addTodo( nt );
nt->setSummary( "Work on 2: Norbert");
nt->setPriority( 1 );
nt->setDescription( "This todo counts the actual work of a person on a project" );
nt->setCategories( QString( "Cat_Pro2,Cat_Work_Pro2,Cat_Work_Norbert") );
nt->setPercentComplete( 20 );
Todo * workNorbert12 = nt;
workNorbert12->setRelatedTo( sub2 );
createRunningDate4Todo( root1, start, end, secLenRunning, secLenPausing, 10 );
createRunningDate4Todo( sub1, start.addSecs( secLenRunning*3 ), start.addDays( 20 ), secLenRunning*2, secLenPausing, 2);
createRunningDate4Todo( sub2, start.addDays( 8 ), end, secLenRunning*3, secLenPausing, 7);
createRunningDate4Todo( workLutz11, start, start.addDays( 18 ), secLenRunning/2, secLenPausing*5, 0);
createRunningDate4Todo( workNorbert11, start.addDays( 8 ), start.addDays( 18 ), secLenRunning*5, secLenPausing*5, 1);
createRunningDate4Todo( workLutz12, start.addDays( 8 ),end, secLenRunning, secLenPausing*8, 0);
createRunningDate4Todo( workNorbert12, start.addDays( 28 ), end, secLenRunning/8, secLenPausing*6, 0);
}
updateView();
#endif
}
void CalendarView::createRunningDate4Todo( Todo * runT, QDateTime start , QDateTime end, int secLenRunning, int secLenPausing,int dayInterval )
{
static int ccc = 0;
++ccc;
QDateTime t_start = start;
runT->setPriority( 5 );
runT->setPercentComplete( 0 );
int count = 0;
int prio = 5;
int complete = 0;
while ( t_start < end ) {
++count;
if ( count > ccc ) {
count = 0;
--prio;
if ( prio == 0 ) prio = 5;
complete += 20;
if ( complete > 100 ) complete = 0;
runT->setPriority( prio );
runT->setPercentComplete( complete );
}
runT->setRunning( true );
runT->saveRunningInfo( "Additional tt comment: running on "+ t_start.toString(), t_start, t_start.addSecs( secLenRunning ) );
if ( dayInterval )
t_start = t_start.addDays( dayInterval );
else {
t_start = t_start.addSecs( secLenRunning + secLenPausing );
}
}
}
void CalendarView::showDay( QDate d )
{
dateNavigator()->blockSignals( true );
dateNavigator()->selectDate( d );
dateNavigator()->blockSignals( false );
mViewManager->showDayView();
//dateNavigator()->selectDate( d );
}
void CalendarView::timerAlarm()
{
//qDebug("CalendarView::timerAlarm() ");
computeAlarm(mAlarmNotification );
}
void CalendarView::suspendAlarm()
{
//qDebug(" CalendarView::suspendAlarm() ");
computeAlarm(mSuspendAlarmNotification );
}
void CalendarView::startAlarm( QString mess , QString filename)
{
topLevelWidget()->showNormal();
topLevelWidget()->setActiveWindow();
topLevelWidget()->raise();
mAlarmDialog->eventNotification( mess, KOPrefs::instance()->mAlarmPlayBeeps, filename, true,KOPrefs::instance()->mAlarmBeepInterval ,KOPrefs::instance()->mAlarmSuspendCount );
QTimer::singleShot( 2000, this, SLOT( checkNextTimerAlarm() ) );
}
void CalendarView::checkNextTimerAlarm()
{
mCalendar->checkAlarmForIncidence( 0, true );
}
void CalendarView::computeAlarm( QString msg )
{
QString mess = msg;
QString mAlarmMessage = mess.mid( 9 );
QString filename = MainWindow::resourcePath();
filename += "koalarm.wav";
QString tempfilename;
if ( mess.left( 13 ) == "suspend_alarm") {
bool error = false;
int len = mess.mid( 13 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 13, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( ! error ) {
filename = tempfilename;
}
mAlarmMessage = mess.mid( 13+len+3 );
//qDebug("suspend file %s ",tempfilename.latin1() );
startAlarm( mAlarmMessage, filename);
return;
}
if ( mess.left( 11 ) == "timer_alarm") {
//mTimerTime = 0;
startAlarm( mess.mid( 11 ), filename );
return;
}
if ( mess.left( 10 ) == "proc_alarm") {
bool error = false;
int len = mess.mid( 10 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 10, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( error ) {
mAlarmMessage = "Procedure Alarm\nError - File not found\n";
mAlarmMessage += mess.mid( 10+len+3+9 );
} else {
//QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent");
//qDebug("-----system command %s ",tempfilename.latin1() );
#ifndef _WIN32_
if ( vfork () == 0 ) {
execl ( tempfilename.latin1(), 0 );
return;
}
#else
QProcess* p = new QProcess();
p->addArgument( tempfilename.latin1() );
p->start();
return;
#endif
return;
}
//qDebug("+++++++system command %s ",tempfilename.latin1() );
}
if ( mess.left( 11 ) == "audio_alarm") {
bool error = false;
int len = mess.mid( 11 ).find("+++");
if ( len < 2 )
error = true;
else {
tempfilename = mess.mid( 11, len );
if ( !QFile::exists( tempfilename ) )
error = true;
}
if ( ! error ) {
filename = tempfilename;
}
mAlarmMessage = mess.mid( 11+len+3+9 );
//qDebug("audio file command %s ",tempfilename.latin1() );
}
if ( mess.left( 9 ) == "cal_alarm") {
mAlarmMessage = mess.mid( 9 ) ;
}
startAlarm( mAlarmMessage, filename );
}
void CalendarView::addSuspendAlarm(const QDateTime &qdt, const QString &noti )
{
//qDebug("+++++addSUSPENDAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
mSuspendAlarmNotification = noti;
int ms = QDateTime::currentDateTime().secsTo( qdt )*1000;
//qDebug("Suspend Alarm timer started with secs: %d ", ms/1000);
mSuspendTimer->start( ms , true );
+#ifdef DESKTOP_VERSION
+ if ( QApplication::desktop()->width() < 1024 ) {
+ QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
+ //qDebug("nextsuspendalarm = \n%s ",mess.latin1() );
+ QString fn = QDir::homeDirPath() + "/.kopi_suspend_alarm";
+ QFile file( fn );
+ if (!file.open( IO_WriteOnly ) ) {
+ qDebug("KO: Error writing next suspend alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
+ } else {
+ QTextStream ts( &file );
+ ts << mess;
+ file.close();
+ }
+ }
+#endif
}
void CalendarView::addAlarm(const QDateTime &qdt, const QString &noti )
{
mNextAlarmDateTime = qdt;
//qDebug("+++++addAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
#ifndef DESKTOP_VERSION
AlarmServer::addAlarm ( qdt,"koalarm", noti.utf8() );
#endif
return;
}
+#ifdef DESKTOP_VERSION
+ if ( QApplication::desktop()->width() < 1024 ) {
+ QString mess = qdt.toString( "yyyy-MM-dd hh:mm:ss" ) + "\n" + noti;
+ //qDebug("nextalarm = \n%s ",mess.latin1() );
+ QString fn = QDir::homeDirPath() + "/.kopi_next_alarm";
+ QFile file( fn );
+ if (!file.open( IO_WriteOnly ) ) {
+ qDebug("KO: Error writing next alarm file %s\nContent: \n%s ", fn.latin1(), mess.latin1());
+ } else {
+ QTextStream ts( &file );
+ ts << mess;
+ file.close();
+ }
+ }
+#endif
int maxSec;
//maxSec = 5; //testing only
maxSec = 86400+3600; // one day+1hour
mAlarmNotification = noti;
int sec = QDateTime::currentDateTime().secsTo( qdt );
if ( sec > maxSec ) {
mRecheckAlarmTimer->start( maxSec * 1000 );
// qDebug("recheck Alarm timer started with secs: %d next alarm in sec:%d", maxSec,sec );
return;
} else {
mRecheckAlarmTimer->stop();
}
//qDebug("Alarm timer started with secs: %d ", sec);
- mAlarmTimer->start( sec *1000 , true );
+ mAlarmTimer->start( sec * 1000 , true );
}
// called by mRecheckAlarmTimer to get next alarm
// we need this, because a QTimer has only a max range of 25 days
void CalendarView::recheckTimerAlarm()
{
mAlarmTimer->stop();
mRecheckAlarmTimer->stop();
mCalendar->checkAlarmForIncidence( 0, true );
}
#ifndef DESKTOP_VERSION
void CalendarView::removeAlarm(const QDateTime &qdt, const QString &noti )
#else
void CalendarView::removeAlarm(const QDateTime &, const QString & )
#endif
{
//qDebug("-----removeAlarm %s %s ", qdt.toString().latin1() , noti.latin1() );
if ( ! KOPrefs::instance()->mUseInternalAlarmNotification ) {
#ifndef DESKTOP_VERSION
AlarmServer::deleteAlarm (qdt ,"koalarm" ,noti.utf8() );
#endif
return;
}
mAlarmTimer->stop();
}
void CalendarView::selectWeekNum ( int num )
{
dateNavigator()->blockSignals( true );
dateNavigator()->selectWeek( num );
dateNavigator()->blockSignals( false );
mViewManager->showWeekView();
}
KOViewManager *CalendarView::viewManager()
{
return mViewManager;
}
KODialogManager *CalendarView::dialogManager()
{
return mDialogManager;
}
QDate CalendarView::startDate()
{
DateList dates = mNavigator->selectedDates();
return dates.first();
}
QDate CalendarView::endDate()
{
DateList dates = mNavigator->selectedDates();
return dates.last();
}
void CalendarView::createPrinter()
{
#ifndef KORG_NOPRINTER
if (!mCalPrinter) {
mCalPrinter = new CalPrinter(this, mCalendar);
connect(this, SIGNAL(configChanged()), mCalPrinter, SLOT(updateConfig()));
}
#endif
}
//KOPrefs::instance()->mWriteBackFile
//KOPrefs::instance()->mWriteBackExistingOnly
// 0 syncPrefsGroup->addRadio(i18n("Take local entry on conflict"));
// 1 syncPrefsGroup->addRadio(i18n("Take remote entry on conflict"));
// 2 syncPrefsGroup->addRadio(i18n("Take newest entry on conflict"));
// 3 syncPrefsGroup->addRadio(i18n("Ask for every entry on conflict"));
// 4 syncPrefsGroup->addRadio(i18n("Force take local entry always"));
// 5 syncPrefsGroup->addRadio(i18n("Force take remote entry always"));
int CalendarView::takeEvent( Incidence* local, Incidence* remote, int mode , bool full )
{
// 0 equal
// 1 take local
// 2 take remote
// 3 cancel
QDateTime lastSync = mLastCalendarSync;
QDateTime localMod = local->lastModified();
QDateTime remoteMod = remote->lastModified();
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
bool remCh, locCh;
remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) );
//if ( remCh )
//qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() );
locCh = ( localMod > mLastCalendarSync );
if ( !remCh && ! locCh ) {
//qDebug("both not changed ");
lastSync = localMod.addDays(1);
if ( mode <= SYNC_PREF_ASK )
return 0;
} else {
if ( locCh ) {
//qDebug("loc changed %d %s %s", local->revision() , localMod.toString().latin1(), mLastCalendarSync.toString().latin1());
lastSync = localMod.addDays( -1 );
if ( !remCh )
remoteMod = ( lastSync.addDays( -1 ) );
} else {
//qDebug(" not loc changed ");
lastSync = localMod.addDays( 1 );
if ( remCh )
remoteMod =( lastSync.addDays( 1 ) );
}
}
full = true;
if ( mode < SYNC_PREF_ASK )
mode = SYNC_PREF_ASK;
} else {
if ( localMod == remoteMod )
// 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", localMod.toString().latin1() , local->revision(), remoteMod.toString().latin1(), remote->revision());
//qDebug("%d %d %d %d ", localMod.time().second(), localMod.time().msec(), remoteMod.time().second(), remoteMod.time().msec() );
//full = true; //debug only
if ( full ) {
bool equ = false;
if ( local->typeID() == eventID ) {
equ = (*((Event*) local) == *((Event*) remote));
}
else if ( local->typeID() == todoID )
equ = (*((Todo*) local) == (*(Todo*) remote));
else if ( local->typeID() == journalID )
equ = (*((Journal*) local) == *((Journal*) remote));
if ( equ ) {
//qDebug("equal ");
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) );
}
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;
//qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , localMod.toString().latin1() , remoteMod.toString().latin1() );
// ************************************************
// ************************************************
// ************************************************
// We may have that lastSync > remoteMod AND lastSync > localMod
// BUT remoteMod != localMod
if ( full && mode < SYNC_PREF_NEWEST )
mode = SYNC_PREF_ASK;
switch( mode ) {
case SYNC_PREF_LOCAL:
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
return 1;
break;
case SYNC_PREF_REMOTE:
if ( lastSync > localMod )
return 2;
if ( lastSync > remoteMod )
return 1;
return 2;
break;
case SYNC_PREF_NEWEST:
if ( localMod >= remoteMod )
return 1;
else
return 2;
break;
case SYNC_PREF_ASK:
qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
if ( lastSync > remoteMod && lastSync > localMod)
return 0;
if ( lastSync > remoteMod )
return 1;
if ( lastSync > localMod )
return 2;
qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() );
localIsNew = localMod >= remoteMod;
if ( localIsNew )
getEventViewerDialog()->setColorMode( 1 );
else
getEventViewerDialog()->setColorMode( 2 );
getEventViewerDialog()->setIncidence(local);
if ( localIsNew )
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 SYNC_PREF_FORCE_LOCAL:
return 1;
break;
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-"+mCurrentSyncDevice );
if (!lse) {
lse = new Event();
lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
QString sum = "";
if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
sum = "E: ";
lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
lse->setDtStart( mLastCalendarSync );
lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
lse->setCategories( i18n("SyncEvent") );
lse->setReadOnly( true );
mCalendar->addEvent( lse );
}
return lse;
}
// we check, if the to delete event has a id for a profile
// if yes, we set this id in the profile to delete
void CalendarView::checkExternSyncEvent( QPtrList<Event> lastSync , Incidence* toDelete )
{
if ( lastSync.count() == 0 ) {
//qDebug(" lastSync.count() == 0");
return;
}
if ( toDelete->typeID() == journalID )
return;
Event* eve = lastSync.first();
while ( eve ) {
QString id = toDelete->getID( eve->uid().mid( 15 ) ); // this is the sync profile name
if ( !id.isEmpty() ) {
QString des = eve->description();
QString pref = "e";
if ( toDelete->typeID() == todoID )
pref = "t";
des += pref+ id + ",";
eve->setReadOnly( false );
eve->setDescription( des );
//qDebug("setdes %s ", des.latin1());
eve->setReadOnly( true );
}
eve = lastSync.next();
}
}
void CalendarView::checkExternalId( Incidence * inc )
{
QPtrList<Event> lastSync = mCalendar->getExternLastSyncEvents() ;
checkExternSyncEvent( lastSync, inc );
}
bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int mode )
{
bool syncOK = true;
int addedEvent = 0;
int addedEventR = 0;
int deletedEventR = 0;
int deletedEventL = 0;
int changedLocal = 0;
int changedRemote = 0;
int filteredIN = 0;
int filteredOUT = 0;
//QPtrList<Event> el = local->rawEvents();
Event* eventR;
QString uid;
int take;
Event* eventRSync;
Event* eventLSync;
clearAllViews();
QPtrList<Event> eventRSyncSharp = remote->getExternLastSyncEvents();
QPtrList<Event> eventLSyncSharp = local->getExternLastSyncEvents();
bool fullDateRange = false;
local->resetTempSyncStat();
mLastCalendarSync = QDateTime::currentDateTime();
if ( mSyncManager->syncWithDesktop() ) {
remote->resetPilotStat(1);
if ( KSyncManager::mRequestedSyncEvent.isValid() ) {
mLastCalendarSync = KSyncManager::mRequestedSyncEvent;
qDebug("KO: using extern time for calendar sync: %s ", mLastCalendarSync.toString().latin1() );
} else {
qDebug("KSyncManager::mRequestedSyncEvent has invalid datatime ");
}
}
QDateTime modifiedCalendar = mLastCalendarSync;
eventLSync = getLastSyncEvent();
eventR = remote->event("last-syncEvent-"+mCurrentSyncName );
if ( eventR ) {
qDebug("last-syncEvent on remote found ");
eventRSync = (Event*) eventR->clone();
remote->deleteEvent(eventR );
} else {
if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL || mSyncManager->syncWithDesktop()) {
eventRSync = (Event*)eventLSync->clone();
} else {
fullDateRange = true;
eventRSync = new Event();
eventRSync->setSummary(mCurrentSyncName + i18n(" - sync event"));
eventRSync->setUid("last-syncEvent-"+mCurrentSyncName );
eventRSync->setDtStart( mLastCalendarSync );
eventRSync->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
eventRSync->setCategories( i18n("SyncEvent") );
}
}
if ( eventLSync->dtStart() == mLastCalendarSync )
fullDateRange = true;
if ( ! fullDateRange ) {
if ( eventLSync->dtStart() != eventRSync->dtStart() ) {
qDebug("set fulldate to true %s %s" ,eventLSync->dtStart().toString().latin1(), eventRSync->dtStart().toString().latin1() );
//qDebug("%d %d %d %d ", eventLSync->dtStart().time().second(), eventLSync->dtStart().time().msec() , eventRSync->dtStart().time().second(), eventRSync->dtStart().time().msec());
fullDateRange = true;
}
}
if ( mSyncManager->syncWithDesktop() ) {
fullDateRange = ( eventLSync->dtStart() <= mLastCalendarSync && eventLSync->dtStart().addSecs(1) >= mLastCalendarSync );
}
if ( fullDateRange )
mLastCalendarSync = QDateTime::currentDateTime().addDays( -100*365);
else
mLastCalendarSync = eventLSync->dtStart();
// for resyncing if own file has changed
if ( mCurrentSyncDevice == "deleteaftersync" ) {
mLastCalendarSync = loadedFileVersion;
//qDebug("setting mLastCalendarSync ");
}
//qDebug("*************************** ");
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();