summaryrefslogtreecommitdiffabout
path: root/korganizer/calendarview.cpp
Unidiff
Diffstat (limited to 'korganizer/calendarview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/calendarview.cpp136
1 files changed, 48 insertions, 88 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index ea9607d..b56f1f9 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -697,25 +697,13 @@ void CalendarView::createPrinter()
697 } 697 }
698#endif 698#endif
699} 699}
700 700
701void CalendarView::confSync() 701void CalendarView::confSync()
702{ 702{
703 static KSyncPrefsDialog* sp = 0; 703 //DELETE
704 if ( ! sp ) {
705 sp = new KSyncPrefsDialog( this, "syncprefs", true );
706 }
707 sp->usrReadConfig();
708#ifndef DESKTOP_VERSION
709 sp->showMaximized();
710#else
711 sp->show();
712#endif
713 sp->exec();
714 KOPrefs::instance()->mSyncProfileNames = sp->getSyncProfileNames();
715 KOPrefs::instance()->mLocalMachineName = sp->getLocalMachineName ();
716} 704}
717 705
718 706
719//KOPrefs::instance()->mWriteBackFile 707//KOPrefs::instance()->mWriteBackFile
720//KOPrefs::instance()->mWriteBackExistingOnly 708//KOPrefs::instance()->mWriteBackExistingOnly
721 709
@@ -874,13 +862,13 @@ Event* CalendarView::getLastSyncEvent()
874 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); 862 //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() );
875 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice ); 863 lse = mCalendar->event( "last-syncEvent-"+mCurrentSyncDevice );
876 if (!lse) { 864 if (!lse) {
877 lse = new Event(); 865 lse = new Event();
878 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice ); 866 lse->setUid( "last-syncEvent-"+mCurrentSyncDevice );
879 QString sum = ""; 867 QString sum = "";
880 if ( KOPrefs::instance()->mExternSyncProfiles.contains( mCurrentSyncDevice ) ) 868 if ( mSyncManager->mExternSyncProfiles.contains( mCurrentSyncDevice ) )
881 sum = "E: "; 869 sum = "E: ";
882 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event")); 870 lse->setSummary(sum+mCurrentSyncDevice + i18n(" - sync event"));
883 lse->setDtStart( mLastCalendarSync ); 871 lse->setDtStart( mLastCalendarSync );
884 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) ); 872 lse->setDtEnd( mLastCalendarSync.addSecs( 7200 ) );
885 lse->setCategories( i18n("SyncEvent") ); 873 lse->setCategories( i18n("SyncEvent") );
886 lse->setReadOnly( true ); 874 lse->setReadOnly( true );
@@ -1116,13 +1104,13 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1116 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { 1104 if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) {
1117 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { 1105 if ( !inL->getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) {
1118 checkExternSyncEvent(eventLSyncSharp, inL); 1106 checkExternSyncEvent(eventLSyncSharp, inL);
1119 local->deleteIncidence( inL ); 1107 local->deleteIncidence( inL );
1120 ++deletedEventL; 1108 ++deletedEventL;
1121 } else { 1109 } else {
1122 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1110 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1123 inL->removeID(mCurrentSyncDevice ); 1111 inL->removeID(mCurrentSyncDevice );
1124 ++addedEventR; 1112 ++addedEventR;
1125 //qDebug("remote added Incidence %s ", inL->summary().latin1()); 1113 //qDebug("remote added Incidence %s ", inL->summary().latin1());
1126 inL->setLastModified( modifiedCalendar ); 1114 inL->setLastModified( modifiedCalendar );
1127 inR = inL->clone(); 1115 inR = inL->clone();
1128 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); 1116 inR->setTempSyncStat( SYNC_TEMPSTATE_INITIAL );
@@ -1132,30 +1120,30 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1132 } else { 1120 } else {
1133 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1121 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1134 checkExternSyncEvent(eventLSyncSharp, inL); 1122 checkExternSyncEvent(eventLSyncSharp, inL);
1135 local->deleteIncidence( inL ); 1123 local->deleteIncidence( inL );
1136 ++deletedEventL; 1124 ++deletedEventL;
1137 } else { 1125 } else {
1138 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1126 if ( ! mSyncManager->mWriteBackExistingOnly ) {
1139 ++addedEventR; 1127 ++addedEventR;
1140 inL->setLastModified( modifiedCalendar ); 1128 inL->setLastModified( modifiedCalendar );
1141 remote->addIncidence( inL->clone() ); 1129 remote->addIncidence( inL->clone() );
1142 } 1130 }
1143 } 1131 }
1144 } 1132 }
1145 } 1133 }
1146 } 1134 }
1147 inL = el.next(); 1135 inL = el.next();
1148 } 1136 }
1149 int delFut = 0; 1137 int delFut = 0;
1150 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1138 if ( mSyncManager->mWriteBackInFuture ) {
1151 er = remote->rawIncidences(); 1139 er = remote->rawIncidences();
1152 inR = er.first(); 1140 inR = er.first();
1153 QDateTime dt; 1141 QDateTime dt;
1154 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1142 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1155 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); 1143 QDateTime end = cur.addDays( (mSyncManager->mWriteBackInFuture +1 ) *7 );
1156 while ( inR ) { 1144 while ( inR ) {
1157 if ( inR->type() == "Todo" ) { 1145 if ( inR->type() == "Todo" ) {
1158 Todo * t = (Todo*)inR; 1146 Todo * t = (Todo*)inR;
1159 if ( t->hasDueDate() ) 1147 if ( t->hasDueDate() )
1160 dt = t->dtDue(); 1148 dt = t->dtDue();
1161 else 1149 else
@@ -1189,16 +1177,16 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1189 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1177 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1190 remote->addEvent( eventRSync ); 1178 remote->addEvent( eventRSync );
1191 QString mes; 1179 QString mes;
1192 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR ); 1180 mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedEvent, addedEventR, changedLocal, changedRemote, deletedEventL, deletedEventR );
1193 QString delmess; 1181 QString delmess;
1194 if ( delFut ) { 1182 if ( delFut ) {
1195 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, KOPrefs::instance()->mWriteBackInFuture ); 1183 delmess.sprintf( i18n("%d items skipped on remote,\nbecause they are in the past or\nmore than %d weeks in the future.\n"),delFut, mSyncManager->mWriteBackInFuture );
1196 mes += delmess; 1184 mes += delmess;
1197 } 1185 }
1198 if ( KOPrefs::instance()->mShowSyncSummary ) { 1186 if ( mSyncManager->mShowSyncSummary ) {
1199 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1187 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1200 } 1188 }
1201 qDebug( mes ); 1189 qDebug( mes );
1202 mCalendar->checkAlarmForIncidence( 0, true ); 1190 mCalendar->checkAlarmForIncidence( 0, true );
1203 return syncOK; 1191 return syncOK;
1204} 1192}
@@ -1222,13 +1210,13 @@ bool CalendarView::syncCalendar(QString filename, int mode)
1222 // qDebug("loading ... "); 1210 // qDebug("loading ... ");
1223 if ( storage->load() ) { 1211 if ( storage->load() ) {
1224 getEventViewerDialog()->setSyncMode( true ); 1212 getEventViewerDialog()->setSyncMode( true );
1225 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1213 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1226 getEventViewerDialog()->setSyncMode( false ); 1214 getEventViewerDialog()->setSyncMode( false );
1227 if ( syncOK ) { 1215 if ( syncOK ) {
1228 if ( KOPrefs::instance()->mWriteBackFile ) 1216 if ( mSyncManager->mWriteBackFile )
1229 { 1217 {
1230 storage->setSaveFormat( new ICalFormat() ); 1218 storage->setSaveFormat( new ICalFormat() );
1231 storage->save(); 1219 storage->save();
1232 } 1220 }
1233 } 1221 }
1234 setModified( true ); 1222 setModified( true );
@@ -1238,20 +1226,18 @@ bool CalendarView::syncCalendar(QString filename, int mode)
1238 if ( syncOK ) 1226 if ( syncOK )
1239 updateView(); 1227 updateView();
1240 return syncOK; 1228 return syncOK;
1241} 1229}
1242void CalendarView::syncPhone() 1230void CalendarView::syncPhone()
1243{ 1231{
1244 syncExternal( 1 ); 1232 //DELETE
1245} 1233}
1246void CalendarView::syncExternal( int mode ) 1234void CalendarView::syncExternal( int mode )
1247{ 1235{
1248 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1236 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1249 //mCurrentSyncDevice = "sharp-DTM"; 1237
1250 if ( KOPrefs::instance()->mAskForPreferences )
1251 edit_sync_options();
1252 qApp->processEvents(); 1238 qApp->processEvents();
1253 CalendarLocal* calendar = new CalendarLocal(); 1239 CalendarLocal* calendar = new CalendarLocal();
1254 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1240 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1255 bool syncOK = false; 1241 bool syncOK = false;
1256 bool loadSuccess = false; 1242 bool loadSuccess = false;
1257 PhoneFormat* phoneFormat = 0; 1243 PhoneFormat* phoneFormat = 0;
@@ -1262,26 +1248,26 @@ void CalendarView::syncExternal( int mode )
1262 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1248 loadSuccess = sharpFormat->load( calendar, mCalendar );
1263 1249
1264 } else 1250 } else
1265#endif 1251#endif
1266 if ( mode == 1 ) { // phone 1252 if ( mode == 1 ) { // phone
1267 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1253 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1268 KOPrefs::instance()->mPhoneDevice, 1254 mSyncManager->mPhoneDevice,
1269 KOPrefs::instance()->mPhoneConnection, 1255 mSyncManager->mPhoneConnection,
1270 KOPrefs::instance()->mPhoneModel); 1256 mSyncManager->mPhoneModel);
1271 loadSuccess = phoneFormat->load( calendar,mCalendar); 1257 loadSuccess = phoneFormat->load( calendar,mCalendar);
1272 1258
1273 } else 1259 } else
1274 return; 1260 return;
1275 if ( loadSuccess ) { 1261 if ( loadSuccess ) {
1276 getEventViewerDialog()->setSyncMode( true ); 1262 getEventViewerDialog()->setSyncMode( true );
1277 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1263 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1278 getEventViewerDialog()->setSyncMode( false ); 1264 getEventViewerDialog()->setSyncMode( false );
1279 qApp->processEvents(); 1265 qApp->processEvents();
1280 if ( syncOK ) { 1266 if ( syncOK ) {
1281 if ( KOPrefs::instance()->mWriteBackFile ) 1267 if ( mSyncManager->mWriteBackFile )
1282 { 1268 {
1283 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1269 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1284 Incidence* inc = iL.first(); 1270 Incidence* inc = iL.first();
1285 if ( phoneFormat ) { 1271 if ( phoneFormat ) {
1286 while ( inc ) { 1272 while ( inc ) {
1287 inc->removeID(mCurrentSyncDevice); 1273 inc->removeID(mCurrentSyncDevice);
@@ -1326,13 +1312,13 @@ void CalendarView::syncExternal( int mode )
1326 updateView(); 1312 updateView();
1327 return ;//syncOK; 1313 return ;//syncOK;
1328 1314
1329} 1315}
1330void CalendarView::syncSharp() 1316void CalendarView::syncSharp()
1331{ 1317{
1332 syncExternal( 0 ); 1318 //DELETE
1333 1319
1334} 1320}
1335 1321
1336 1322
1337bool CalendarView::importBday() 1323bool CalendarView::importBday()
1338{ 1324{
@@ -1514,13 +1500,13 @@ bool CalendarView::importQtopia( const QString &categories,
1514 updateView(); 1500 updateView();
1515 return true; 1501 return true;
1516 1502
1517#if 0 1503#if 0
1518 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1504 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1519 mCurrentSyncDevice = "qtopia-XML"; 1505 mCurrentSyncDevice = "qtopia-XML";
1520 if ( KOPrefs::instance()->mAskForPreferences ) 1506 if ( mSyncManager->mAskForPreferences )
1521 edit_sync_options(); 1507 edit_sync_options();
1522 qApp->processEvents(); 1508 qApp->processEvents();
1523 CalendarLocal* calendar = new CalendarLocal(); 1509 CalendarLocal* calendar = new CalendarLocal();
1524 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1510 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1525 bool syncOK = false; 1511 bool syncOK = false;
1526 QtopiaFormat qtopiaFormat; 1512 QtopiaFormat qtopiaFormat;
@@ -1532,17 +1518,17 @@ bool CalendarView::importQtopia( const QString &categories,
1532 loadOk = qtopiaFormat.load( calendar, datebook ); 1518 loadOk = qtopiaFormat.load( calendar, datebook );
1533 if ( loadOk && !todolist.isEmpty() ) 1519 if ( loadOk && !todolist.isEmpty() )
1534 loadOk = qtopiaFormat.load( calendar, todolist ); 1520 loadOk = qtopiaFormat.load( calendar, todolist );
1535 1521
1536 if ( loadOk ) { 1522 if ( loadOk ) {
1537 getEventViewerDialog()->setSyncMode( true ); 1523 getEventViewerDialog()->setSyncMode( true );
1538 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1524 syncOK = synchronizeCalendar( mCalendar, calendar, mSyncManager->mSyncAlgoPrefs );
1539 getEventViewerDialog()->setSyncMode( false ); 1525 getEventViewerDialog()->setSyncMode( false );
1540 qApp->processEvents(); 1526 qApp->processEvents();
1541 if ( syncOK ) { 1527 if ( syncOK ) {
1542 if ( KOPrefs::instance()->mWriteBackFile ) 1528 if ( mSyncManager->mWriteBackFile )
1543 { 1529 {
1544 // write back XML file 1530 // write back XML file
1545 1531
1546 } 1532 }
1547 setModified( true ); 1533 setModified( true );
1548 } 1534 }
@@ -1680,17 +1666,17 @@ bool CalendarView::checkFileVersion(QString fn)
1680 if ( km == KMessageBox::Cancel ) 1666 if ( km == KMessageBox::Cancel )
1681 return false; 1667 return false;
1682 if ( km == KMessageBox::Yes ) 1668 if ( km == KMessageBox::Yes )
1683 return true; 1669 return true;
1684 1670
1685 setSyncDevice("deleteaftersync" ); 1671 setSyncDevice("deleteaftersync" );
1686 KOPrefs::instance()->mAskForPreferences = true; 1672 mSyncManager->mAskForPreferences = true;
1687 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1673 mSyncManager->mSyncAlgoPrefs = 3;
1688 KOPrefs::instance()->mWriteBackFile = false; 1674 mSyncManager->mWriteBackFile = false;
1689 KOPrefs::instance()->mWriteBackExistingOnly = false; 1675 mSyncManager->mWriteBackExistingOnly = false;
1690 KOPrefs::instance()->mShowSyncSummary = false; 1676 mSyncManager->mShowSyncSummary = false;
1691 syncCalendar( fn, 3 ); 1677 syncCalendar( fn, 3 );
1692 Event * e = getLastSyncEvent(); 1678 Event * e = getLastSyncEvent();
1693 mCalendar->deleteEvent ( e ); 1679 mCalendar->deleteEvent ( e );
1694 updateView(); 1680 updateView();
1695 return true; 1681 return true;
1696} 1682}
@@ -2195,59 +2181,13 @@ void CalendarView::edit_options()
2195{ 2181{
2196 mDialogManager->showOptionsDialog(); 2182 mDialogManager->showOptionsDialog();
2197 //writeSettings(); 2183 //writeSettings();
2198} 2184}
2199void CalendarView::edit_sync_options() 2185void CalendarView::edit_sync_options()
2200{ 2186{
2201 //mDialogManager->showSyncOptions(); 2187 // DELETE
2202 //KOPrefs::instance()->mSyncAlgoPrefs
2203 QDialog dia( this, "dia", true );
2204 dia.setCaption( i18n("Device: " ) +mCurrentSyncDevice );
2205 QButtonGroup gr ( 1, Qt::Horizontal, i18n("Sync preferences"), &dia);
2206 QVBoxLayout lay ( &dia );
2207 lay.setSpacing( 2 );
2208 lay.setMargin( 3 );
2209 lay.addWidget(&gr);
2210 QRadioButton loc ( i18n("Take local entry on conflict"), &gr );
2211 QRadioButton rem ( i18n("Take remote entry on conflict"), &gr );
2212 QRadioButton newest( i18n("Take newest entry on conflict"), &gr );
2213 QRadioButton ask( i18n("Ask for every entry on conflict"), &gr );
2214 QRadioButton f_loc( i18n("Force: Take local entry always"), &gr );
2215 QRadioButton f_rem( i18n("Force: Take remote entry always"), &gr );
2216 //QRadioButton both( i18n("Take both on conflict"), &gr );
2217 QPushButton pb ( "OK", &dia);
2218 lay.addWidget( &pb );
2219 connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) );
2220 switch ( KOPrefs::instance()->mSyncAlgoPrefs ) {
2221 case 0:
2222 loc.setChecked( true);
2223 break;
2224 case 1:
2225 rem.setChecked( true );
2226 break;
2227 case 2:
2228 newest.setChecked( true);
2229 break;
2230 case 3:
2231 ask.setChecked( true);
2232 break;
2233 case 4:
2234 f_loc.setChecked( true);
2235 break;
2236 case 5:
2237 f_rem.setChecked( true);
2238 break;
2239 case 6:
2240 // both.setChecked( true);
2241 break;
2242 default:
2243 break;
2244 }
2245 if ( dia.exec() ) {
2246 KOPrefs::instance()->mSyncAlgoPrefs = rem.isChecked()*1+newest.isChecked()*2+ ask.isChecked()*3+ f_loc.isChecked()*4+ f_rem.isChecked()*5;//+ both.isChecked()*6 ;
2247 }
2248 2188
2249} 2189}
2250 2190
2251void CalendarView::slotSelectPickerDate( QDate d) 2191void CalendarView::slotSelectPickerDate( QDate d)
2252{ 2192{
2253 mDateFrame->hide(); 2193 mDateFrame->hide();
@@ -3765,9 +3705,29 @@ NavigatorBar *CalendarView::navigatorBar()
3765void CalendarView::keyPressEvent ( QKeyEvent *e) 3705void CalendarView::keyPressEvent ( QKeyEvent *e)
3766{ 3706{
3767 //qDebug(" alendarView::keyPressEvent "); 3707 //qDebug(" alendarView::keyPressEvent ");
3768 e->ignore(); 3708 e->ignore();
3769} 3709}
3770 3710
3771//#include "calendarview.moc"
3772 3711
3773//#include "calendarviewbase.moc" 3712bool CalendarView::sync(KSyncManager* manager, QString filename, int mode)
3713{
3714 // mSyncManager = manager;
3715 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3716 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3717 return syncCalendar( filename, mode );
3718}
3719bool CalendarView::syncExternal(KSyncManager* manager, QString resource)
3720{
3721 //mSyncManager = manager;
3722 mCurrentSyncDevice = mSyncManager->getCurrentSyncDevice();
3723 mCurrentSyncName = mSyncManager->getCurrentSyncName();
3724 if ( resource == "sharp" )
3725 syncExternal( 0 );
3726 if ( resource == "phone" )
3727 syncExternal( 1 );
3728 // pending setmodified
3729}
3730void CalendarView::setSyncManager(KSyncManager* manager)
3731{
3732 mSyncManager = manager;
3733}