summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-05 13:34:33 (UTC)
committer zautrix <zautrix>2004-10-05 13:34:33 (UTC)
commit191ced43b27c047b0a39f0acdc8ba1f8a58817df (patch) (unidiff)
treed164ae32c16259d9a8d5c9fdfa74f975d1f10075
parenta946c09db6f71f595d8bdcb6b34ba3160c5497dc (diff)
downloadkdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.zip
kdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.tar.gz
kdepimpi-191ced43b27c047b0a39f0acdc8ba1f8a58817df.tar.bz2
fix for filewatch and vcal timezone
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/calendarview.cpp3
-rw-r--r--libkcal/vcalformat.cpp2
2 files changed, 3 insertions, 2 deletions
diff --git a/korganizer/calendarview.cpp b/korganizer/calendarview.cpp
index 687943e..b1da144 100644
--- a/korganizer/calendarview.cpp
+++ b/korganizer/calendarview.cpp
@@ -1133,821 +1133,822 @@ bool CalendarView::synchronizeCalendar( Calendar* local, Calendar* remote, int
1133 } else { 1133 } else {
1134 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) { 1134 if ( inL->lastModified() < mLastCalendarSync && mode != 4 ) {
1135 checkExternSyncEvent(eventLSyncSharp, inL); 1135 checkExternSyncEvent(eventLSyncSharp, inL);
1136 local->deleteIncidence( inL ); 1136 local->deleteIncidence( inL );
1137 ++deletedEventL; 1137 ++deletedEventL;
1138 } else { 1138 } else {
1139 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) { 1139 if ( ! KOPrefs::instance()->mWriteBackExistingOnly ) {
1140 ++addedEventR; 1140 ++addedEventR;
1141 inL->setLastModified( modifiedCalendar ); 1141 inL->setLastModified( modifiedCalendar );
1142 remote->addIncidence( inL->clone() ); 1142 remote->addIncidence( inL->clone() );
1143 } 1143 }
1144 } 1144 }
1145 } 1145 }
1146 } 1146 }
1147 } 1147 }
1148 inL = el.next(); 1148 inL = el.next();
1149 } 1149 }
1150 int delFut = 0; 1150 int delFut = 0;
1151 if ( KOPrefs::instance()->mWriteBackInFuture ) { 1151 if ( KOPrefs::instance()->mWriteBackInFuture ) {
1152 er = remote->rawIncidences(); 1152 er = remote->rawIncidences();
1153 inR = er.first(); 1153 inR = er.first();
1154 QDateTime dt; 1154 QDateTime dt;
1155 QDateTime cur = QDateTime::currentDateTime().addDays( -7 ); 1155 QDateTime cur = QDateTime::currentDateTime().addDays( -7 );
1156 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 ); 1156 QDateTime end = cur.addDays( (KOPrefs::instance()->mWriteBackInFuture +1 ) *7 );
1157 while ( inR ) { 1157 while ( inR ) {
1158 if ( inR->type() == "Todo" ) { 1158 if ( inR->type() == "Todo" ) {
1159 Todo * t = (Todo*)inR; 1159 Todo * t = (Todo*)inR;
1160 if ( t->hasDueDate() ) 1160 if ( t->hasDueDate() )
1161 dt = t->dtDue(); 1161 dt = t->dtDue();
1162 else 1162 else
1163 dt = cur.addSecs( 62 ); 1163 dt = cur.addSecs( 62 );
1164 } 1164 }
1165 else if (inR->type() == "Event" ) { 1165 else if (inR->type() == "Event" ) {
1166 bool ok; 1166 bool ok;
1167 dt = inR->getNextOccurence( cur, &ok ); 1167 dt = inR->getNextOccurence( cur, &ok );
1168 if ( !ok ) 1168 if ( !ok )
1169 dt = cur.addSecs( -62 ); 1169 dt = cur.addSecs( -62 );
1170 } 1170 }
1171 else 1171 else
1172 dt = inR->dtStart(); 1172 dt = inR->dtStart();
1173 if ( dt < cur || dt > end ) { 1173 if ( dt < cur || dt > end ) {
1174 remote->deleteIncidence( inR ); 1174 remote->deleteIncidence( inR );
1175 ++delFut; 1175 ++delFut;
1176 } 1176 }
1177 inR = er.next(); 1177 inR = er.next();
1178 } 1178 }
1179 } 1179 }
1180 bar.hide(); 1180 bar.hide();
1181 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 ); 1181 mLastCalendarSync = QDateTime::currentDateTime().addSecs( 1 );
1182 eventLSync->setReadOnly( false ); 1182 eventLSync->setReadOnly( false );
1183 eventLSync->setDtStart( mLastCalendarSync ); 1183 eventLSync->setDtStart( mLastCalendarSync );
1184 eventRSync->setDtStart( mLastCalendarSync ); 1184 eventRSync->setDtStart( mLastCalendarSync );
1185 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1185 eventLSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1186 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) ); 1186 eventRSync->setDtEnd( mLastCalendarSync.addSecs( 3600 ) );
1187 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ; 1187 eventRSync->setLocation( i18n("Remote from: ")+mCurrentSyncName ) ;
1188 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName ); 1188 eventLSync->setLocation(i18n("Local from: ") + mCurrentSyncName );
1189 eventLSync->setReadOnly( true ); 1189 eventLSync->setReadOnly( true );
1190 if ( mGlobalSyncMode == SYNC_MODE_NORMAL) 1190 if ( mGlobalSyncMode == SYNC_MODE_NORMAL)
1191 remote->addEvent( eventRSync ); 1191 remote->addEvent( eventRSync );
1192 QString mes; 1192 QString mes;
1193 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 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 );
1194 QString delmess; 1194 QString delmess;
1195 if ( delFut ) { 1195 if ( delFut ) {
1196 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 ); 1196 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 );
1197 mes += delmess; 1197 mes += delmess;
1198 } 1198 }
1199 if ( KOPrefs::instance()->mShowSyncSummary ) { 1199 if ( KOPrefs::instance()->mShowSyncSummary ) {
1200 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") ); 1200 KMessageBox::information(this, mes, i18n("KO/Pi Synchronization") );
1201 } 1201 }
1202 qDebug( mes ); 1202 qDebug( mes );
1203 mCalendar->checkAlarmForIncidence( 0, true ); 1203 mCalendar->checkAlarmForIncidence( 0, true );
1204 return syncOK; 1204 return syncOK;
1205} 1205}
1206 1206
1207void CalendarView::setSyncDevice( QString s ) 1207void CalendarView::setSyncDevice( QString s )
1208{ 1208{
1209 mCurrentSyncDevice= s; 1209 mCurrentSyncDevice= s;
1210} 1210}
1211void CalendarView::setSyncName( QString s ) 1211void CalendarView::setSyncName( QString s )
1212{ 1212{
1213 mCurrentSyncName= s; 1213 mCurrentSyncName= s;
1214} 1214}
1215bool CalendarView::syncCalendar(QString filename, int mode) 1215bool CalendarView::syncCalendar(QString filename, int mode)
1216{ 1216{
1217 mGlobalSyncMode = SYNC_MODE_NORMAL; 1217 mGlobalSyncMode = SYNC_MODE_NORMAL;
1218 CalendarLocal* calendar = new CalendarLocal(); 1218 CalendarLocal* calendar = new CalendarLocal();
1219 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1219 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1220 FileStorage* storage = new FileStorage( calendar ); 1220 FileStorage* storage = new FileStorage( calendar );
1221 bool syncOK = false; 1221 bool syncOK = false;
1222 storage->setFileName( filename ); 1222 storage->setFileName( filename );
1223 // qDebug("loading ... "); 1223 // qDebug("loading ... ");
1224 if ( storage->load() ) { 1224 if ( storage->load() ) {
1225 getEventViewerDialog()->setSyncMode( true ); 1225 getEventViewerDialog()->setSyncMode( true );
1226 syncOK = synchronizeCalendar( mCalendar, calendar, mode ); 1226 syncOK = synchronizeCalendar( mCalendar, calendar, mode );
1227 getEventViewerDialog()->setSyncMode( false ); 1227 getEventViewerDialog()->setSyncMode( false );
1228 if ( syncOK ) { 1228 if ( syncOK ) {
1229 if ( KOPrefs::instance()->mWriteBackFile ) 1229 if ( KOPrefs::instance()->mWriteBackFile )
1230 { 1230 {
1231 storage->setSaveFormat( new ICalFormat() ); 1231 storage->setSaveFormat( new ICalFormat() );
1232 storage->save(); 1232 storage->save();
1233 } 1233 }
1234 } 1234 }
1235 setModified( true ); 1235 setModified( true );
1236 } 1236 }
1237 delete storage; 1237 delete storage;
1238 delete calendar; 1238 delete calendar;
1239 if ( syncOK ) 1239 if ( syncOK )
1240 updateView(); 1240 updateView();
1241 return syncOK; 1241 return syncOK;
1242} 1242}
1243void CalendarView::syncPhone() 1243void CalendarView::syncPhone()
1244{ 1244{
1245 syncExternal( 1 ); 1245 syncExternal( 1 );
1246} 1246}
1247void CalendarView::syncExternal( int mode ) 1247void CalendarView::syncExternal( int mode )
1248{ 1248{
1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL; 1249 mGlobalSyncMode = SYNC_MODE_EXTERNAL;
1250 //mCurrentSyncDevice = "sharp-DTM"; 1250 //mCurrentSyncDevice = "sharp-DTM";
1251 if ( KOPrefs::instance()->mAskForPreferences ) 1251 if ( KOPrefs::instance()->mAskForPreferences )
1252 edit_sync_options(); 1252 edit_sync_options();
1253 qApp->processEvents(); 1253 qApp->processEvents();
1254 CalendarLocal* calendar = new CalendarLocal(); 1254 CalendarLocal* calendar = new CalendarLocal();
1255 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1255 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1256 bool syncOK = false; 1256 bool syncOK = false;
1257 bool loadSuccess = false; 1257 bool loadSuccess = false;
1258 PhoneFormat* phoneFormat = 0; 1258 PhoneFormat* phoneFormat = 0;
1259#ifndef DESKTOP_VERSION 1259#ifndef DESKTOP_VERSION
1260 SharpFormat* sharpFormat = 0; 1260 SharpFormat* sharpFormat = 0;
1261 if ( mode == 0 ) { // sharp 1261 if ( mode == 0 ) { // sharp
1262 sharpFormat = new SharpFormat () ; 1262 sharpFormat = new SharpFormat () ;
1263 loadSuccess = sharpFormat->load( calendar, mCalendar ); 1263 loadSuccess = sharpFormat->load( calendar, mCalendar );
1264 1264
1265 } else 1265 } else
1266#endif 1266#endif
1267 if ( mode == 1 ) { // phone 1267 if ( mode == 1 ) { // phone
1268 phoneFormat = new PhoneFormat (mCurrentSyncDevice, 1268 phoneFormat = new PhoneFormat (mCurrentSyncDevice,
1269 KOPrefs::instance()->mPhoneDevice, 1269 KOPrefs::instance()->mPhoneDevice,
1270 KOPrefs::instance()->mPhoneConnection, 1270 KOPrefs::instance()->mPhoneConnection,
1271 KOPrefs::instance()->mPhoneModel); 1271 KOPrefs::instance()->mPhoneModel);
1272 loadSuccess = phoneFormat->load( calendar,mCalendar); 1272 loadSuccess = phoneFormat->load( calendar,mCalendar);
1273 1273
1274 } else 1274 } else
1275 return; 1275 return;
1276 if ( loadSuccess ) { 1276 if ( loadSuccess ) {
1277 getEventViewerDialog()->setSyncMode( true ); 1277 getEventViewerDialog()->setSyncMode( true );
1278 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1278 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1279 getEventViewerDialog()->setSyncMode( false ); 1279 getEventViewerDialog()->setSyncMode( false );
1280 qApp->processEvents(); 1280 qApp->processEvents();
1281 if ( syncOK ) { 1281 if ( syncOK ) {
1282 if ( KOPrefs::instance()->mWriteBackFile ) 1282 if ( KOPrefs::instance()->mWriteBackFile )
1283 { 1283 {
1284 QPtrList<Incidence> iL = mCalendar->rawIncidences(); 1284 QPtrList<Incidence> iL = mCalendar->rawIncidences();
1285 Incidence* inc = iL.first(); 1285 Incidence* inc = iL.first();
1286 if ( phoneFormat ) { 1286 if ( phoneFormat ) {
1287 while ( inc ) { 1287 while ( inc ) {
1288 inc->removeID(mCurrentSyncDevice); 1288 inc->removeID(mCurrentSyncDevice);
1289 inc = iL.next(); 1289 inc = iL.next();
1290 } 1290 }
1291 } 1291 }
1292#ifndef DESKTOP_VERSION 1292#ifndef DESKTOP_VERSION
1293 if ( sharpFormat ) 1293 if ( sharpFormat )
1294 sharpFormat->save(calendar); 1294 sharpFormat->save(calendar);
1295#endif 1295#endif
1296 if ( phoneFormat ) 1296 if ( phoneFormat )
1297 phoneFormat->save(calendar); 1297 phoneFormat->save(calendar);
1298 iL = calendar->rawIncidences(); 1298 iL = calendar->rawIncidences();
1299 inc = iL.first(); 1299 inc = iL.first();
1300 Incidence* loc; 1300 Incidence* loc;
1301 while ( inc ) { 1301 while ( inc ) {
1302 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) { 1302 if ( inc->tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) {
1303 loc = mCalendar->incidence(inc->uid() ); 1303 loc = mCalendar->incidence(inc->uid() );
1304 if ( loc ) { 1304 if ( loc ) {
1305 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) ); 1305 loc->setID(mCurrentSyncDevice, inc->getID(mCurrentSyncDevice) );
1306 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) ); 1306 loc->setCsum( mCurrentSyncDevice, inc->getCsum(mCurrentSyncDevice) );
1307 } 1307 }
1308 } 1308 }
1309 inc = iL.next(); 1309 inc = iL.next();
1310 } 1310 }
1311 Incidence* lse = getLastSyncEvent(); 1311 Incidence* lse = getLastSyncEvent();
1312 if ( lse ) { 1312 if ( lse ) {
1313 lse->setReadOnly( false ); 1313 lse->setReadOnly( false );
1314 lse->setDescription( "" ); 1314 lse->setDescription( "" );
1315 lse->setReadOnly( true ); 1315 lse->setReadOnly( true );
1316 } 1316 }
1317 } 1317 }
1318 } 1318 }
1319 setModified( true ); 1319 setModified( true );
1320 } else { 1320 } else {
1321 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ; 1321 QString question = i18n("Sorry, the database access\ncommand failed!\n\nNothing synced!\n") ;
1322 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"), 1322 QMessageBox::information( 0, i18n("KO/Pi Import - ERROR"),
1323 question, i18n("Ok")) ; 1323 question, i18n("Ok")) ;
1324 1324
1325 } 1325 }
1326 delete calendar; 1326 delete calendar;
1327 updateView(); 1327 updateView();
1328 return ;//syncOK; 1328 return ;//syncOK;
1329 1329
1330} 1330}
1331void CalendarView::syncSharp() 1331void CalendarView::syncSharp()
1332{ 1332{
1333 syncExternal( 0 ); 1333 syncExternal( 0 );
1334 1334
1335} 1335}
1336 1336
1337 1337
1338//#include <kabc/stdaddressbook.h> 1338//#include <kabc/stdaddressbook.h>
1339bool CalendarView::importBday() 1339bool CalendarView::importBday()
1340{ 1340{
1341#if 0 1341#if 0
1342 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true ); 1342 KABC::StdAddressBook* AddressBook = KABC::StdAddressBook::self( true );
1343 KABC::AddressBook::Iterator it; 1343 KABC::AddressBook::Iterator it;
1344 int count = 0; 1344 int count = 0;
1345 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1345 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1346 ++count; 1346 ++count;
1347 } 1347 }
1348 QProgressBar bar(count,0 ); 1348 QProgressBar bar(count,0 );
1349 int w = 300; 1349 int w = 300;
1350 if ( QApplication::desktop()->width() < 320 ) 1350 if ( QApplication::desktop()->width() < 320 )
1351 w = 220; 1351 w = 220;
1352 int h = bar.sizeHint().height() ; 1352 int h = bar.sizeHint().height() ;
1353 int dw = QApplication::desktop()->width(); 1353 int dw = QApplication::desktop()->width();
1354 int dh = QApplication::desktop()->height(); 1354 int dh = QApplication::desktop()->height();
1355 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 1355 bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
1356 bar.show(); 1356 bar.show();
1357 bar.setCaption (i18n("Reading addressbook - close to abort!") ); 1357 bar.setCaption (i18n("Reading addressbook - close to abort!") );
1358 qApp->processEvents(); 1358 qApp->processEvents();
1359 count = 0; 1359 count = 0;
1360 int addCount = 0; 1360 int addCount = 0;
1361 KCal::Attendee* a = 0; 1361 KCal::Attendee* a = 0;
1362 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) { 1362 for( it = AddressBook->begin(); it != AddressBook->end(); ++it ) {
1363 if ( ! bar.isVisible() ) 1363 if ( ! bar.isVisible() )
1364 return false; 1364 return false;
1365 bar.setProgress( count++ ); 1365 bar.setProgress( count++ );
1366 qApp->processEvents(); 1366 qApp->processEvents();
1367 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() ); 1367 //qDebug("add BDay %s %s", (*it).realName().latin1(),(*it).birthday().date().toString().latin1() );
1368 if ( (*it).birthday().date().isValid() ){ 1368 if ( (*it).birthday().date().isValid() ){
1369 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1369 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1370 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) ) 1370 if ( addAnniversary( (*it).birthday().date(), (*it).assembledName(), a, true ) )
1371 ++addCount; 1371 ++addCount;
1372 } 1372 }
1373 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); 1373 QDate anni = KGlobal::locale()->readDate( (*it).custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d");
1374 if ( anni.isValid() ){ 1374 if ( anni.isValid() ){
1375 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ; 1375 a = new KCal::Attendee( (*it).realName(), (*it).preferredEmail(),false,KCal::Attendee::NeedsAction,KCal::Attendee::ReqParticipant,(*it).uid()) ;
1376 if ( addAnniversary( anni, (*it).assembledName(), a, false ) ) 1376 if ( addAnniversary( anni, (*it).assembledName(), a, false ) )
1377 ++addCount; 1377 ++addCount;
1378 } 1378 }
1379 } 1379 }
1380 updateView(); 1380 updateView();
1381 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!")); 1381 topLevelWidget()->setCaption(QString::number( addCount )+ i18n(" birthdays/anniversaries added!"));
1382#endif 1382#endif
1383 return true; 1383 return true;
1384} 1384}
1385 1385
1386bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday) 1386bool CalendarView::addAnniversary( QDate date, QString name, KCal::Attendee* a, bool birthday)
1387{ 1387{
1388 //qDebug("addAnni "); 1388 //qDebug("addAnni ");
1389 Event * ev = new Event(); 1389 Event * ev = new Event();
1390 if ( a ) { 1390 if ( a ) {
1391 ev->addAttendee( a ); 1391 ev->addAttendee( a );
1392 } 1392 }
1393 QString kind; 1393 QString kind;
1394 if ( birthday ) 1394 if ( birthday )
1395 kind = i18n( "Birthday" ); 1395 kind = i18n( "Birthday" );
1396 else 1396 else
1397 kind = i18n( "Anniversary" ); 1397 kind = i18n( "Anniversary" );
1398 ev->setSummary( name + " - " + kind ); 1398 ev->setSummary( name + " - " + kind );
1399 ev->setOrganizer( "nobody@nowhere" ); 1399 ev->setOrganizer( "nobody@nowhere" );
1400 ev->setCategories( kind ); 1400 ev->setCategories( kind );
1401 ev->setDtStart( QDateTime(date) ); 1401 ev->setDtStart( QDateTime(date) );
1402 ev->setDtEnd( QDateTime(date) ); 1402 ev->setDtEnd( QDateTime(date) );
1403 ev->setFloats( true ); 1403 ev->setFloats( true );
1404 Recurrence * rec = ev->recurrence(); 1404 Recurrence * rec = ev->recurrence();
1405 rec->setYearly(Recurrence::rYearlyMonth,1,-1); 1405 rec->setYearly(Recurrence::rYearlyMonth,1,-1);
1406 rec->addYearlyNum( date.month() ); 1406 rec->addYearlyNum( date.month() );
1407 if ( !mCalendar->addAnniversaryNoDup( ev ) ) { 1407 if ( !mCalendar->addAnniversaryNoDup( ev ) ) {
1408 delete ev; 1408 delete ev;
1409 return false; 1409 return false;
1410 } 1410 }
1411 return true; 1411 return true;
1412 1412
1413} 1413}
1414bool CalendarView::importQtopia( const QString &categories, 1414bool CalendarView::importQtopia( const QString &categories,
1415 const QString &datebook, 1415 const QString &datebook,
1416 const QString &todolist ) 1416 const QString &todolist )
1417{ 1417{
1418 1418
1419 QtopiaFormat qtopiaFormat; 1419 QtopiaFormat qtopiaFormat;
1420 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1420 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1421 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories ); 1421 if ( !categories.isEmpty() ) qtopiaFormat.load( mCalendar, categories );
1422 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook ); 1422 if ( !datebook.isEmpty() ) qtopiaFormat.load( mCalendar, datebook );
1423 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist ); 1423 if ( !todolist.isEmpty() ) qtopiaFormat.load( mCalendar, todolist );
1424 1424
1425 updateView(); 1425 updateView();
1426 return true; 1426 return true;
1427 1427
1428#if 0 1428#if 0
1429 mGlobalSyncMode = SYNC_MODE_QTOPIA; 1429 mGlobalSyncMode = SYNC_MODE_QTOPIA;
1430 mCurrentSyncDevice = "qtopia-XML"; 1430 mCurrentSyncDevice = "qtopia-XML";
1431 if ( KOPrefs::instance()->mAskForPreferences ) 1431 if ( KOPrefs::instance()->mAskForPreferences )
1432 edit_sync_options(); 1432 edit_sync_options();
1433 qApp->processEvents(); 1433 qApp->processEvents();
1434 CalendarLocal* calendar = new CalendarLocal(); 1434 CalendarLocal* calendar = new CalendarLocal();
1435 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1435 calendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1436 bool syncOK = false; 1436 bool syncOK = false;
1437 QtopiaFormat qtopiaFormat; 1437 QtopiaFormat qtopiaFormat;
1438 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories)); 1438 qtopiaFormat.setCategoriesList ( &(KOPrefs::instance()->mCustomCategories));
1439 bool loadOk = true; 1439 bool loadOk = true;
1440 if ( !categories.isEmpty() ) 1440 if ( !categories.isEmpty() )
1441 loadOk = qtopiaFormat.load( calendar, categories ); 1441 loadOk = qtopiaFormat.load( calendar, categories );
1442 if ( loadOk && !datebook.isEmpty() ) 1442 if ( loadOk && !datebook.isEmpty() )
1443 loadOk = qtopiaFormat.load( calendar, datebook ); 1443 loadOk = qtopiaFormat.load( calendar, datebook );
1444 if ( loadOk && !todolist.isEmpty() ) 1444 if ( loadOk && !todolist.isEmpty() )
1445 loadOk = qtopiaFormat.load( calendar, todolist ); 1445 loadOk = qtopiaFormat.load( calendar, todolist );
1446 1446
1447 if ( loadOk ) { 1447 if ( loadOk ) {
1448 getEventViewerDialog()->setSyncMode( true ); 1448 getEventViewerDialog()->setSyncMode( true );
1449 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs ); 1449 syncOK = synchronizeCalendar( mCalendar, calendar, KOPrefs::instance()->mSyncAlgoPrefs );
1450 getEventViewerDialog()->setSyncMode( false ); 1450 getEventViewerDialog()->setSyncMode( false );
1451 qApp->processEvents(); 1451 qApp->processEvents();
1452 if ( syncOK ) { 1452 if ( syncOK ) {
1453 if ( KOPrefs::instance()->mWriteBackFile ) 1453 if ( KOPrefs::instance()->mWriteBackFile )
1454 { 1454 {
1455 // write back XML file 1455 // write back XML file
1456 1456
1457 } 1457 }
1458 setModified( true ); 1458 setModified( true );
1459 } 1459 }
1460 } else { 1460 } else {
1461 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ; 1461 QString question = i18n("Sorry, the file loading\ncommand failed!\n\nNothing synced!\n") ;
1462 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"), 1462 QMessageBox::information( 0, i18n("KO/Pi Sync - ERROR"),
1463 question, i18n("Ok")) ; 1463 question, i18n("Ok")) ;
1464 } 1464 }
1465 delete calendar; 1465 delete calendar;
1466 updateView(); 1466 updateView();
1467 return syncOK; 1467 return syncOK;
1468 1468
1469 1469
1470#endif 1470#endif
1471 1471
1472} 1472}
1473 1473
1474void CalendarView::setSyncEventsReadOnly() 1474void CalendarView::setSyncEventsReadOnly()
1475{ 1475{
1476 Event * ev; 1476 Event * ev;
1477 QPtrList<Event> eL = mCalendar->rawEvents(); 1477 QPtrList<Event> eL = mCalendar->rawEvents();
1478 ev = eL.first(); 1478 ev = eL.first();
1479 while ( ev ) { 1479 while ( ev ) {
1480 if ( ev->uid().left(15) == QString("last-syncEvent-") ) 1480 if ( ev->uid().left(15) == QString("last-syncEvent-") )
1481 ev->setReadOnly( true ); 1481 ev->setReadOnly( true );
1482 ev = eL.next(); 1482 ev = eL.next();
1483 } 1483 }
1484} 1484}
1485bool CalendarView::openCalendar(QString filename, bool merge) 1485bool CalendarView::openCalendar(QString filename, bool merge)
1486{ 1486{
1487 1487
1488 if (filename.isEmpty()) { 1488 if (filename.isEmpty()) {
1489 return false; 1489 return false;
1490 } 1490 }
1491 1491
1492 if (!QFile::exists(filename)) { 1492 if (!QFile::exists(filename)) {
1493 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename)); 1493 KMessageBox::error(this,i18n("File does not exist:\n '%1'.").arg(filename));
1494 return false; 1494 return false;
1495 } 1495 }
1496 1496
1497 globalFlagBlockAgenda = 1; 1497 globalFlagBlockAgenda = 1;
1498 if (!merge) mCalendar->close(); 1498 if (!merge) mCalendar->close();
1499 1499
1500 mStorage->setFileName( filename ); 1500 mStorage->setFileName( filename );
1501 1501
1502 if ( mStorage->load() ) { 1502 if ( mStorage->load() ) {
1503 if ( merge ) ;//setModified( true ); 1503 if ( merge ) ;//setModified( true );
1504 else { 1504 else {
1505 //setModified( true ); 1505 //setModified( true );
1506 mViewManager->setDocumentId( filename ); 1506 mViewManager->setDocumentId( filename );
1507 mDialogManager->setDocumentId( filename ); 1507 mDialogManager->setDocumentId( filename );
1508 mTodoList->setDocumentId( filename ); 1508 mTodoList->setDocumentId( filename );
1509 } 1509 }
1510 globalFlagBlockAgenda = 2; 1510 globalFlagBlockAgenda = 2;
1511 // if ( getLastSyncEvent() ) 1511 // if ( getLastSyncEvent() )
1512 // getLastSyncEvent()->setReadOnly( true ); 1512 // getLastSyncEvent()->setReadOnly( true );
1513 mCalendar->reInitAlarmSettings(); 1513 mCalendar->reInitAlarmSettings();
1514 setSyncEventsReadOnly(); 1514 setSyncEventsReadOnly();
1515 updateUnmanagedViews(); 1515 updateUnmanagedViews();
1516 updateView(); 1516 updateView();
1517 loadedFileVersion = QDateTime::currentDateTime(); 1517 setLoadedFileVersion( QDateTime::currentDateTime().addSecs( -1 ));
1518 if ( filename != MainWindow::defaultFileName() ) { 1518 if ( filename != MainWindow::defaultFileName() ) {
1519 saveCalendar( MainWindow::defaultFileName() ); 1519 saveCalendar( MainWindow::defaultFileName() );
1520 watchSavedFile(); 1520 watchSavedFile();
1521 } 1521 }
1522 return true; 1522 return true;
1523 } else { 1523 } else {
1524 // while failing to load, the calendar object could 1524 // while failing to load, the calendar object could
1525 // have become partially populated. Clear it out. 1525 // have become partially populated. Clear it out.
1526 if ( !merge ) { 1526 if ( !merge ) {
1527 mCalendar->close(); 1527 mCalendar->close();
1528 mViewManager->setDocumentId( filename ); 1528 mViewManager->setDocumentId( filename );
1529 mDialogManager->setDocumentId( filename ); 1529 mDialogManager->setDocumentId( filename );
1530 mTodoList->setDocumentId( filename ); 1530 mTodoList->setDocumentId( filename );
1531 } 1531 }
1532 1532
1533 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename)); 1533 //KMessageBox::error(this,i18n("Couldn't load calendar\n '%1'.").arg(filename));
1534 1534
1535 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) ); 1535 QTimer::singleShot ( 1, this, SLOT ( showOpenError() ) );
1536 globalFlagBlockAgenda = 2; 1536 globalFlagBlockAgenda = 2;
1537 mCalendar->reInitAlarmSettings(); 1537 mCalendar->reInitAlarmSettings();
1538 setSyncEventsReadOnly(); 1538 setSyncEventsReadOnly();
1539 updateUnmanagedViews(); 1539 updateUnmanagedViews();
1540 updateView(); 1540 updateView();
1541 } 1541 }
1542 return false; 1542 return false;
1543} 1543}
1544void CalendarView::showOpenError() 1544void CalendarView::showOpenError()
1545{ 1545{
1546 KMessageBox::error(this,i18n("Couldn't load calendar\n.")); 1546 KMessageBox::error(this,i18n("Couldn't load calendar\n."));
1547} 1547}
1548void CalendarView::setLoadedFileVersion(QDateTime dt) 1548void CalendarView::setLoadedFileVersion(QDateTime dt)
1549{ 1549{
1550 loadedFileVersion = dt; 1550 loadedFileVersion = dt;
1551} 1551}
1552bool CalendarView::checkFileChanged(QString fn) 1552bool CalendarView::checkFileChanged(QString fn)
1553{ 1553{
1554 QFileInfo finf ( fn ); 1554 QFileInfo finf ( fn );
1555 if ( !finf.exists() ) 1555 if ( !finf.exists() )
1556 return true; 1556 return true;
1557 QDateTime dt = finf.lastModified (); 1557 QDateTime dt = finf.lastModified ();
1558 if ( dt <= loadedFileVersion ) 1558 if ( dt <= loadedFileVersion )
1559 return false; 1559 return false;
1560 return true; 1560 return true;
1561 1561
1562} 1562}
1563void CalendarView::watchSavedFile() 1563void CalendarView::watchSavedFile()
1564{ 1564{
1565 QFileInfo finf ( MainWindow::defaultFileName()); 1565 QFileInfo finf ( MainWindow::defaultFileName());
1566 if ( !finf.exists() ) 1566 if ( !finf.exists() )
1567 return; 1567 return;
1568 QDateTime dt = finf.lastModified (); 1568 QDateTime dt = finf.lastModified ();
1569 if ( dt < loadedFileVersion ) { 1569 if ( dt < loadedFileVersion ) {
1570 //qDebug("watch %s %s ", dt.toString().latin1(), loadedFileVersion.toString().latin1());
1570 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) ); 1571 QTimer::singleShot( 1000 , this, SLOT ( watchSavedFile() ) );
1571 return; 1572 return;
1572 } 1573 }
1573 loadedFileVersion = dt; 1574 loadedFileVersion = dt;
1574} 1575}
1575 1576
1576bool CalendarView::checkFileVersion(QString fn) 1577bool CalendarView::checkFileVersion(QString fn)
1577{ 1578{
1578 QFileInfo finf ( fn ); 1579 QFileInfo finf ( fn );
1579 if ( !finf.exists() ) 1580 if ( !finf.exists() )
1580 return true; 1581 return true;
1581 QDateTime dt = finf.lastModified (); 1582 QDateTime dt = finf.lastModified ();
1582 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1()); 1583 //qDebug("loaded file version %s",loadedFileVersion.toString().latin1());
1583 //qDebug("file on disk version %s",dt.toString().latin1()); 1584 //qDebug("file on disk version %s",dt.toString().latin1());
1584 if ( dt <= loadedFileVersion ) 1585 if ( dt <= loadedFileVersion )
1585 return true; 1586 return true;
1586 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) , 1587 int km = KMessageBox::warningYesNoCancel(this, i18n("\nThe file on disk has changed!\nFile size: %1 bytes.\nLast modified: %2\nDo you want to:\n\n - Save and overwrite file?\n - Sync with file, then save?\n - Cancel without saving? \n").arg( QString::number( finf.size())).arg( KGlobal::locale()->formatDateTime(finf.lastModified (), true, true)) ,
1587 i18n("KO/Pi Warning"),i18n("Overwrite"), 1588 i18n("KO/Pi Warning"),i18n("Overwrite"),
1588 i18n("Sync+save")); 1589 i18n("Sync+save"));
1589 1590
1590 if ( km == KMessageBox::Cancel ) 1591 if ( km == KMessageBox::Cancel )
1591 return false; 1592 return false;
1592 if ( km == KMessageBox::Yes ) 1593 if ( km == KMessageBox::Yes )
1593 return true; 1594 return true;
1594 1595
1595 setSyncDevice("deleteaftersync" ); 1596 setSyncDevice("deleteaftersync" );
1596 KOPrefs::instance()->mAskForPreferences = true; 1597 KOPrefs::instance()->mAskForPreferences = true;
1597 KOPrefs::instance()->mSyncAlgoPrefs = 3; 1598 KOPrefs::instance()->mSyncAlgoPrefs = 3;
1598 KOPrefs::instance()->mWriteBackFile = false; 1599 KOPrefs::instance()->mWriteBackFile = false;
1599 KOPrefs::instance()->mWriteBackExistingOnly = false; 1600 KOPrefs::instance()->mWriteBackExistingOnly = false;
1600 KOPrefs::instance()->mShowSyncSummary = false; 1601 KOPrefs::instance()->mShowSyncSummary = false;
1601 syncCalendar( fn, 3 ); 1602 syncCalendar( fn, 3 );
1602 Event * e = getLastSyncEvent(); 1603 Event * e = getLastSyncEvent();
1603 mCalendar->deleteEvent ( e ); 1604 mCalendar->deleteEvent ( e );
1604 updateView(); 1605 updateView();
1605 return true; 1606 return true;
1606} 1607}
1607 1608
1608bool CalendarView::saveCalendar( QString filename ) 1609bool CalendarView::saveCalendar( QString filename )
1609{ 1610{
1610 1611
1611 // Store back all unsaved data into calendar object 1612 // Store back all unsaved data into calendar object
1612 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() ); 1613 // qDebug("file %s %d ", filename.latin1() , mViewManager->currentView() );
1613 if ( mViewManager->currentView() ) 1614 if ( mViewManager->currentView() )
1614 mViewManager->currentView()->flushView(); 1615 mViewManager->currentView()->flushView();
1615 1616
1616 //mStorage->setFileName( filename ); 1617 //mStorage->setFileName( filename );
1617 1618
1618 mStorage->setSaveFormat( new ICalFormat() ); 1619 mStorage->setSaveFormat( new ICalFormat() );
1619 mStorage->setFileName( filename ); 1620 mStorage->setFileName( filename );
1620 bool success; 1621 bool success;
1621 success = mStorage->save(); 1622 success = mStorage->save();
1622 if ( !success ) { 1623 if ( !success ) {
1623 return false; 1624 return false;
1624 } 1625 }
1625 1626
1626 return true; 1627 return true;
1627} 1628}
1628 1629
1629void CalendarView::closeCalendar() 1630void CalendarView::closeCalendar()
1630{ 1631{
1631 1632
1632 // child windows no longer valid 1633 // child windows no longer valid
1633 emit closingDown(); 1634 emit closingDown();
1634 1635
1635 mCalendar->close(); 1636 mCalendar->close();
1636 setModified(false); 1637 setModified(false);
1637 updateView(); 1638 updateView();
1638} 1639}
1639 1640
1640void CalendarView::archiveCalendar() 1641void CalendarView::archiveCalendar()
1641{ 1642{
1642 mDialogManager->showArchiveDialog(); 1643 mDialogManager->showArchiveDialog();
1643} 1644}
1644 1645
1645 1646
1646void CalendarView::readSettings() 1647void CalendarView::readSettings()
1647{ 1648{
1648 1649
1649 1650
1650 // mViewManager->showAgendaView(); 1651 // mViewManager->showAgendaView();
1651 QString str; 1652 QString str;
1652 //qDebug("CalendarView::readSettings() "); 1653 //qDebug("CalendarView::readSettings() ");
1653 // read settings from the KConfig, supplying reasonable 1654 // read settings from the KConfig, supplying reasonable
1654 // defaults where none are to be found 1655 // defaults where none are to be found
1655 KConfig *config = KOGlobals::config(); 1656 KConfig *config = KOGlobals::config();
1656#ifndef KORG_NOSPLITTER 1657#ifndef KORG_NOSPLITTER
1657 config->setGroup("KOrganizer Geometry"); 1658 config->setGroup("KOrganizer Geometry");
1658 1659
1659 QValueList<int> sizes = config->readIntListEntry("Separator1"); 1660 QValueList<int> sizes = config->readIntListEntry("Separator1");
1660 if (sizes.count() != 2) { 1661 if (sizes.count() != 2) {
1661 sizes << mDateNavigator->minimumSizeHint().width(); 1662 sizes << mDateNavigator->minimumSizeHint().width();
1662 sizes << 300; 1663 sizes << 300;
1663 } 1664 }
1664 mPanner->setSizes(sizes); 1665 mPanner->setSizes(sizes);
1665 1666
1666 sizes = config->readIntListEntry("Separator2"); 1667 sizes = config->readIntListEntry("Separator2");
1667 if ( ( mResourceView && sizes.count() == 4 ) || 1668 if ( ( mResourceView && sizes.count() == 4 ) ||
1668 ( !mResourceView && sizes.count() == 3 ) ) { 1669 ( !mResourceView && sizes.count() == 3 ) ) {
1669 mLeftSplitter->setSizes(sizes); 1670 mLeftSplitter->setSizes(sizes);
1670 } 1671 }
1671#endif 1672#endif
1672 globalFlagBlockAgenda = 1; 1673 globalFlagBlockAgenda = 1;
1673 mViewManager->showAgendaView(); 1674 mViewManager->showAgendaView();
1674 //mViewManager->readSettings( config ); 1675 //mViewManager->readSettings( config );
1675 mTodoList->restoreLayout(config,QString("Todo Layout")); 1676 mTodoList->restoreLayout(config,QString("Todo Layout"));
1676 readFilterSettings(config); 1677 readFilterSettings(config);
1677 config->setGroup( "Views" ); 1678 config->setGroup( "Views" );
1678 int dateCount = config->readNumEntry( "ShownDatesCount", 7 ); 1679 int dateCount = config->readNumEntry( "ShownDatesCount", 7 );
1679 if ( dateCount == 5 ) mNavigator->selectWorkWeek(); 1680 if ( dateCount == 5 ) mNavigator->selectWorkWeek();
1680 else if ( dateCount == 7 ) mNavigator->selectWeek(); 1681 else if ( dateCount == 7 ) mNavigator->selectWeek();
1681 else mNavigator->selectDates( dateCount ); 1682 else mNavigator->selectDates( dateCount );
1682 // mViewManager->readSettings( config ); 1683 // mViewManager->readSettings( config );
1683 updateConfig(); 1684 updateConfig();
1684 globalFlagBlockAgenda = 2; 1685 globalFlagBlockAgenda = 2;
1685 mViewManager->readSettings( config ); 1686 mViewManager->readSettings( config );
1686#ifdef DESKTOP_VERSION 1687#ifdef DESKTOP_VERSION
1687 config->setGroup("WidgetLayout"); 1688 config->setGroup("WidgetLayout");
1688 QStringList list; 1689 QStringList list;
1689 list = config->readListEntry("MainLayout"); 1690 list = config->readListEntry("MainLayout");
1690 int x,y,w,h; 1691 int x,y,w,h;
1691 if ( ! list.isEmpty() ) { 1692 if ( ! list.isEmpty() ) {
1692 x = list[0].toInt(); 1693 x = list[0].toInt();
1693 y = list[1].toInt(); 1694 y = list[1].toInt();
1694 w = list[2].toInt(); 1695 w = list[2].toInt();
1695 h = list[3].toInt(); 1696 h = list[3].toInt();
1696 topLevelWidget()->setGeometry(x,y,w,h); 1697 topLevelWidget()->setGeometry(x,y,w,h);
1697 1698
1698 } else { 1699 } else {
1699 topLevelWidget()->setGeometry( 40 ,40 , 640, 440); 1700 topLevelWidget()->setGeometry( 40 ,40 , 640, 440);
1700 } 1701 }
1701 list = config->readListEntry("EditEventLayout"); 1702 list = config->readListEntry("EditEventLayout");
1702 if ( ! list.isEmpty() ) { 1703 if ( ! list.isEmpty() ) {
1703 x = list[0].toInt(); 1704 x = list[0].toInt();
1704 y = list[1].toInt(); 1705 y = list[1].toInt();
1705 w = list[2].toInt(); 1706 w = list[2].toInt();
1706 h = list[3].toInt(); 1707 h = list[3].toInt();
1707 mEventEditor->setGeometry(x,y,w,h); 1708 mEventEditor->setGeometry(x,y,w,h);
1708 1709
1709 } 1710 }
1710 list = config->readListEntry("EditTodoLayout"); 1711 list = config->readListEntry("EditTodoLayout");
1711 if ( ! list.isEmpty() ) { 1712 if ( ! list.isEmpty() ) {
1712 x = list[0].toInt(); 1713 x = list[0].toInt();
1713 y = list[1].toInt(); 1714 y = list[1].toInt();
1714 w = list[2].toInt(); 1715 w = list[2].toInt();
1715 h = list[3].toInt(); 1716 h = list[3].toInt();
1716 mTodoEditor->setGeometry(x,y,w,h); 1717 mTodoEditor->setGeometry(x,y,w,h);
1717 1718
1718 } 1719 }
1719 list = config->readListEntry("ViewerLayout"); 1720 list = config->readListEntry("ViewerLayout");
1720 if ( ! list.isEmpty() ) { 1721 if ( ! list.isEmpty() ) {
1721 x = list[0].toInt(); 1722 x = list[0].toInt();
1722 y = list[1].toInt(); 1723 y = list[1].toInt();
1723 w = list[2].toInt(); 1724 w = list[2].toInt();
1724 h = list[3].toInt(); 1725 h = list[3].toInt();
1725 getEventViewerDialog()->setGeometry(x,y,w,h); 1726 getEventViewerDialog()->setGeometry(x,y,w,h);
1726 } 1727 }
1727#endif 1728#endif
1728 1729
1729} 1730}
1730 1731
1731 1732
1732void CalendarView::writeSettings() 1733void CalendarView::writeSettings()
1733{ 1734{
1734 // kdDebug() << "CalendarView::writeSettings" << endl; 1735 // kdDebug() << "CalendarView::writeSettings" << endl;
1735 1736
1736 KConfig *config = KOGlobals::config(); 1737 KConfig *config = KOGlobals::config();
1737 1738
1738#ifndef KORG_NOSPLITTER 1739#ifndef KORG_NOSPLITTER
1739 config->setGroup("KOrganizer Geometry"); 1740 config->setGroup("KOrganizer Geometry");
1740 1741
1741 QValueList<int> list = mPanner->sizes(); 1742 QValueList<int> list = mPanner->sizes();
1742 config->writeEntry("Separator1",list); 1743 config->writeEntry("Separator1",list);
1743 1744
1744 list = mLeftSplitter->sizes(); 1745 list = mLeftSplitter->sizes();
1745 config->writeEntry("Separator2",list); 1746 config->writeEntry("Separator2",list);
1746#endif 1747#endif
1747 1748
1748 mViewManager->writeSettings( config ); 1749 mViewManager->writeSettings( config );
1749 mTodoList->saveLayout(config,QString("Todo Layout")); 1750 mTodoList->saveLayout(config,QString("Todo Layout"));
1750 mDialogManager->writeSettings( config ); 1751 mDialogManager->writeSettings( config );
1751 //KOPrefs::instance()->usrWriteConfig(); 1752 //KOPrefs::instance()->usrWriteConfig();
1752 KOPrefs::instance()->writeConfig(); 1753 KOPrefs::instance()->writeConfig();
1753 1754
1754 writeFilterSettings(config); 1755 writeFilterSettings(config);
1755 1756
1756 config->setGroup( "Views" ); 1757 config->setGroup( "Views" );
1757 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() ); 1758 config->writeEntry( "ShownDatesCount", mNavigator->selectedDates().count() );
1758 1759
1759#ifdef DESKTOP_VERSION 1760#ifdef DESKTOP_VERSION
1760 config->setGroup("WidgetLayout"); 1761 config->setGroup("WidgetLayout");
1761 QStringList list ;//= config->readListEntry("MainLayout"); 1762 QStringList list ;//= config->readListEntry("MainLayout");
1762 int x,y,w,h; 1763 int x,y,w,h;
1763 QWidget* wid; 1764 QWidget* wid;
1764 wid = topLevelWidget(); 1765 wid = topLevelWidget();
1765 x = wid->geometry().x(); 1766 x = wid->geometry().x();
1766 y = wid->geometry().y(); 1767 y = wid->geometry().y();
1767 w = wid->width(); 1768 w = wid->width();
1768 h = wid->height(); 1769 h = wid->height();
1769 list.clear(); 1770 list.clear();
1770 list << QString::number( x ); 1771 list << QString::number( x );
1771 list << QString::number( y ); 1772 list << QString::number( y );
1772 list << QString::number( w ); 1773 list << QString::number( w );
1773 list << QString::number( h ); 1774 list << QString::number( h );
1774 config->writeEntry("MainLayout",list ); 1775 config->writeEntry("MainLayout",list );
1775 1776
1776 wid = mEventEditor; 1777 wid = mEventEditor;
1777 x = wid->geometry().x(); 1778 x = wid->geometry().x();
1778 y = wid->geometry().y(); 1779 y = wid->geometry().y();
1779 w = wid->width(); 1780 w = wid->width();
1780 h = wid->height(); 1781 h = wid->height();
1781 list.clear(); 1782 list.clear();
1782 list << QString::number( x ); 1783 list << QString::number( x );
1783 list << QString::number( y ); 1784 list << QString::number( y );
1784 list << QString::number( w ); 1785 list << QString::number( w );
1785 list << QString::number( h ); 1786 list << QString::number( h );
1786 config->writeEntry("EditEventLayout",list ); 1787 config->writeEntry("EditEventLayout",list );
1787 1788
1788 wid = mTodoEditor; 1789 wid = mTodoEditor;
1789 x = wid->geometry().x(); 1790 x = wid->geometry().x();
1790 y = wid->geometry().y(); 1791 y = wid->geometry().y();
1791 w = wid->width(); 1792 w = wid->width();
1792 h = wid->height(); 1793 h = wid->height();
1793 list.clear(); 1794 list.clear();
1794 list << QString::number( x ); 1795 list << QString::number( x );
1795 list << QString::number( y ); 1796 list << QString::number( y );
1796 list << QString::number( w ); 1797 list << QString::number( w );
1797 list << QString::number( h ); 1798 list << QString::number( h );
1798 config->writeEntry("EditTodoLayout",list ); 1799 config->writeEntry("EditTodoLayout",list );
1799 wid = getEventViewerDialog(); 1800 wid = getEventViewerDialog();
1800 x = wid->geometry().x(); 1801 x = wid->geometry().x();
1801 y = wid->geometry().y(); 1802 y = wid->geometry().y();
1802 w = wid->width(); 1803 w = wid->width();
1803 h = wid->height(); 1804 h = wid->height();
1804 list.clear(); 1805 list.clear();
1805 list << QString::number( x ); 1806 list << QString::number( x );
1806 list << QString::number( y ); 1807 list << QString::number( y );
1807 list << QString::number( w ); 1808 list << QString::number( w );
1808 list << QString::number( h ); 1809 list << QString::number( h );
1809 config->writeEntry("ViewerLayout",list ); 1810 config->writeEntry("ViewerLayout",list );
1810 wid = mDialogManager->getSearchDialog(); 1811 wid = mDialogManager->getSearchDialog();
1811 if ( wid ) { 1812 if ( wid ) {
1812 x = wid->geometry().x(); 1813 x = wid->geometry().x();
1813 y = wid->geometry().y(); 1814 y = wid->geometry().y();
1814 w = wid->width(); 1815 w = wid->width();
1815 h = wid->height(); 1816 h = wid->height();
1816 list.clear(); 1817 list.clear();
1817 list << QString::number( x ); 1818 list << QString::number( x );
1818 list << QString::number( y ); 1819 list << QString::number( y );
1819 list << QString::number( w ); 1820 list << QString::number( w );
1820 list << QString::number( h ); 1821 list << QString::number( h );
1821 config->writeEntry("SearchLayout",list ); 1822 config->writeEntry("SearchLayout",list );
1822 } 1823 }
1823#endif 1824#endif
1824 1825
1825 1826
1826 config->sync(); 1827 config->sync();
1827} 1828}
1828 1829
1829void CalendarView::readFilterSettings(KConfig *config) 1830void CalendarView::readFilterSettings(KConfig *config)
1830{ 1831{
1831 // kdDebug() << "CalendarView::readFilterSettings()" << endl; 1832 // kdDebug() << "CalendarView::readFilterSettings()" << endl;
1832 1833
1833 mFilters.clear(); 1834 mFilters.clear();
1834 1835
1835 config->setGroup("General"); 1836 config->setGroup("General");
1836 QStringList filterList = config->readListEntry("CalendarFilters"); 1837 QStringList filterList = config->readListEntry("CalendarFilters");
1837 1838
1838 QStringList::ConstIterator it = filterList.begin(); 1839 QStringList::ConstIterator it = filterList.begin();
1839 QStringList::ConstIterator end = filterList.end(); 1840 QStringList::ConstIterator end = filterList.end();
1840 while(it != end) { 1841 while(it != end) {
1841 // kdDebug() << " filter: " << (*it) << endl; 1842 // kdDebug() << " filter: " << (*it) << endl;
1842 1843
1843 CalFilter *filter; 1844 CalFilter *filter;
1844 filter = new CalFilter(*it); 1845 filter = new CalFilter(*it);
1845 config->setGroup("Filter_" + (*it)); 1846 config->setGroup("Filter_" + (*it));
1846 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) ); 1847 //qDebug("readFilterSettings %d ",config->readNumEntry("Criteria",0) );
1847 filter->setCriteria(config->readNumEntry("Criteria",0)); 1848 filter->setCriteria(config->readNumEntry("Criteria",0));
1848 filter->setCategoryList(config->readListEntry("CategoryList")); 1849 filter->setCategoryList(config->readListEntry("CategoryList"));
1849 mFilters.append(filter); 1850 mFilters.append(filter);
1850 1851
1851 ++it; 1852 ++it;
1852 } 1853 }
1853 1854
1854 if (mFilters.count() == 0) { 1855 if (mFilters.count() == 0) {
1855 CalFilter *filter = new CalFilter(i18n("Default")); 1856 CalFilter *filter = new CalFilter(i18n("Default"));
1856 mFilters.append(filter); 1857 mFilters.append(filter);
1857 } 1858 }
1858 mFilterView->updateFilters(); 1859 mFilterView->updateFilters();
1859 config->setGroup("FilterView"); 1860 config->setGroup("FilterView");
1860 1861
1861 mFilterView->blockSignals(true); 1862 mFilterView->blockSignals(true);
1862 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled")); 1863 mFilterView->setFiltersEnabled(config->readBoolEntry("FilterEnabled"));
1863 mFilterView->setSelectedFilter(config->readEntry("Current Filter")); 1864 mFilterView->setSelectedFilter(config->readEntry("Current Filter"));
1864 mFilterView->blockSignals(false); 1865 mFilterView->blockSignals(false);
1865 // We do it manually to avoid it being done twice by the above calls 1866 // We do it manually to avoid it being done twice by the above calls
1866 updateFilter(); 1867 updateFilter();
1867} 1868}
1868 1869
1869void CalendarView::writeFilterSettings(KConfig *config) 1870void CalendarView::writeFilterSettings(KConfig *config)
1870{ 1871{
1871 // kdDebug() << "CalendarView::writeFilterSettings()" << endl; 1872 // kdDebug() << "CalendarView::writeFilterSettings()" << endl;
1872 1873
1873 QStringList filterList; 1874 QStringList filterList;
1874 1875
1875 CalFilter *filter = mFilters.first(); 1876 CalFilter *filter = mFilters.first();
1876 while(filter) { 1877 while(filter) {
1877 // kdDebug() << " fn: " << filter->name() << endl; 1878 // kdDebug() << " fn: " << filter->name() << endl;
1878 filterList << filter->name(); 1879 filterList << filter->name();
1879 config->setGroup("Filter_" + filter->name()); 1880 config->setGroup("Filter_" + filter->name());
1880 config->writeEntry("Criteria",filter->criteria()); 1881 config->writeEntry("Criteria",filter->criteria());
1881 config->writeEntry("CategoryList",filter->categoryList()); 1882 config->writeEntry("CategoryList",filter->categoryList());
1882 filter = mFilters.next(); 1883 filter = mFilters.next();
1883 } 1884 }
1884 config->setGroup("General"); 1885 config->setGroup("General");
1885 config->writeEntry("CalendarFilters",filterList); 1886 config->writeEntry("CalendarFilters",filterList);
1886 1887
1887 config->setGroup("FilterView"); 1888 config->setGroup("FilterView");
1888 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled()); 1889 config->writeEntry("FilterEnabled",mFilterView->filtersEnabled());
1889 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name()); 1890 config->writeEntry("Current Filter",mFilterView->selectedFilter()->name());
1890} 1891}
1891 1892
1892 1893
1893void CalendarView::goToday() 1894void CalendarView::goToday()
1894{ 1895{
1895 mNavigator->selectToday(); 1896 mNavigator->selectToday();
1896} 1897}
1897 1898
1898void CalendarView::goNext() 1899void CalendarView::goNext()
1899{ 1900{
1900 mNavigator->selectNext(); 1901 mNavigator->selectNext();
1901} 1902}
1902 1903
1903void CalendarView::goPrevious() 1904void CalendarView::goPrevious()
1904{ 1905{
1905 mNavigator->selectPrevious(); 1906 mNavigator->selectPrevious();
1906} 1907}
1907void CalendarView::goNextMonth() 1908void CalendarView::goNextMonth()
1908{ 1909{
1909 mNavigator->selectNextMonth(); 1910 mNavigator->selectNextMonth();
1910} 1911}
1911 1912
1912void CalendarView::goPreviousMonth() 1913void CalendarView::goPreviousMonth()
1913{ 1914{
1914 mNavigator->selectPreviousMonth(); 1915 mNavigator->selectPreviousMonth();
1915} 1916}
1916void CalendarView::writeLocale() 1917void CalendarView::writeLocale()
1917{ 1918{
1918 //KPimGlobalPrefs::instance()->setGlobalConfig(); 1919 //KPimGlobalPrefs::instance()->setGlobalConfig();
1919#if 0 1920#if 0
1920 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime ); 1921 KGlobal::locale()->setHore24Format( !KOPrefs::instance()->mPreferredTime );
1921 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday ); 1922 KGlobal::locale()->setWeekStartMonday( !KOPrefs::instance()->mWeekStartsOnSunday );
1922 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate ); 1923 KGlobal::locale()->setIntDateFormat( (KLocale::IntDateFormat)KOPrefs::instance()->mPreferredDate );
1923 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage ); 1924 KGlobal::locale()->setLanguage( KOPrefs::instance()->mPreferredLanguage );
1924 QString dummy = KOPrefs::instance()->mUserDateFormatLong; 1925 QString dummy = KOPrefs::instance()->mUserDateFormatLong;
1925 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") )); 1926 KGlobal::locale()->setDateFormat(dummy.replace( QRegExp("K"), QString(",") ));
1926 dummy = KOPrefs::instance()->mUserDateFormatShort; 1927 dummy = KOPrefs::instance()->mUserDateFormatShort;
1927 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") )); 1928 KGlobal::locale()->setDateFormatShort(dummy.replace( QRegExp("K"), QString(",") ));
1928 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving, 1929 KGlobal::locale()->setDaylightSaving( KOPrefs::instance()->mUseDaylightsaving,
1929 KOPrefs::instance()->mDaylightsavingStart, 1930 KOPrefs::instance()->mDaylightsavingStart,
1930 KOPrefs::instance()->mDaylightsavingEnd ); 1931 KOPrefs::instance()->mDaylightsavingEnd );
1931 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId ); 1932 KGlobal::locale()->setTimezone( KOPrefs::instance()->mTimeZoneId );
1932#endif 1933#endif
1933} 1934}
1934void CalendarView::updateConfig() 1935void CalendarView::updateConfig()
1935{ 1936{
1936 writeLocale(); 1937 writeLocale();
1937 if ( KOPrefs::instance()->mUseAppColors ) 1938 if ( KOPrefs::instance()->mUseAppColors )
1938 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true ); 1939 QApplication::setPalette( QPalette (KOPrefs::instance()->mAppColor1, KOPrefs::instance()->mAppColor2), true );
1939 emit configChanged(); 1940 emit configChanged();
1940 mTodoList->updateConfig(); 1941 mTodoList->updateConfig();
1941 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont); 1942 // mDateNavigator->setFont ( KOPrefs::instance()->mDateNavigatorFont);
1942 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId); 1943 mCalendar->setTimeZoneId(KOPrefs::instance()->mTimeZoneId);
1943 // To make the "fill window" configurations work 1944 // To make the "fill window" configurations work
1944 //mViewManager->raiseCurrentView(); 1945 //mViewManager->raiseCurrentView();
1945} 1946}
1946 1947
1947 1948
1948void CalendarView::eventChanged(Event *event) 1949void CalendarView::eventChanged(Event *event)
1949{ 1950{
1950 changeEventDisplay(event,KOGlobals::EVENTEDITED); 1951 changeEventDisplay(event,KOGlobals::EVENTEDITED);
1951 //updateUnmanagedViews(); 1952 //updateUnmanagedViews();
1952} 1953}
1953 1954
diff --git a/libkcal/vcalformat.cpp b/libkcal/vcalformat.cpp
index 4727a7a..309c699 100644
--- a/libkcal/vcalformat.cpp
+++ b/libkcal/vcalformat.cpp
@@ -1103,615 +1103,615 @@ Event* VCalFormat::VEventToEvent(VObject *vevent)
1103 tmpPos = -1; 1103 tmpPos = -1;
1104 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1); 1104 qba.setBit(anEvent->dtStart().date().dayOfWeek() - 1);
1105 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1105 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1106 } 1106 }
1107 else { 1107 else {
1108 // e.g. MP1 1+ SU #0 1108 // e.g. MP1 1+ SU #0
1109 while (index < last) { 1109 while (index < last) {
1110 tmpPos = tmpStr.mid(index,1).toShort(); 1110 tmpPos = tmpStr.mid(index,1).toShort();
1111 index += 1; 1111 index += 1;
1112 if (tmpStr.mid(index,1) == "-") 1112 if (tmpStr.mid(index,1) == "-")
1113 // convert tmpPos to negative 1113 // convert tmpPos to negative
1114 tmpPos = 0 - tmpPos; 1114 tmpPos = 0 - tmpPos;
1115 index += 2; // advance to day(s) 1115 index += 2; // advance to day(s)
1116 while (numFromDay(tmpStr.mid(index,3)) >= 0) { 1116 while (numFromDay(tmpStr.mid(index,3)) >= 0) {
1117 int dayNum = numFromDay(tmpStr.mid(index,3)); 1117 int dayNum = numFromDay(tmpStr.mid(index,3));
1118 qba.setBit(dayNum); 1118 qba.setBit(dayNum);
1119 index += 3; // advance to next day, or possibly pos or "#" 1119 index += 3; // advance to next day, or possibly pos or "#"
1120 } 1120 }
1121 anEvent->recurrence()->addMonthlyPos(tmpPos, qba); 1121 anEvent->recurrence()->addMonthlyPos(tmpPos, qba);
1122 qba.detach(); 1122 qba.detach();
1123 qba.fill(FALSE); // clear out 1123 qba.fill(FALSE); // clear out
1124 } // while != "#" 1124 } // while != "#"
1125 } 1125 }
1126 index = last; if (tmpStr.mid(index,1) == "#") index++; 1126 index = last; if (tmpStr.mid(index,1) == "#") index++;
1127 if (tmpStr.find('T', index) != -1) { 1127 if (tmpStr.find('T', index) != -1) {
1128 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() - 1128 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length() -
1129 index))).date(); 1129 index))).date();
1130 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate); 1130 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rEndDate);
1131 } else { 1131 } else {
1132 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1132 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1133 if (rDuration == 0) 1133 if (rDuration == 0)
1134 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1); 1134 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, -1);
1135 else 1135 else
1136 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration); 1136 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyPos, rFreq, rDuration);
1137 } 1137 }
1138 } 1138 }
1139 1139
1140 /**************************** MONTHLY-BY-DAY ***************************/ 1140 /**************************** MONTHLY-BY-DAY ***************************/
1141 else if (tmpStr.left(2) == "MD") { 1141 else if (tmpStr.left(2) == "MD") {
1142 int index = tmpStr.find(' '); 1142 int index = tmpStr.find(' ');
1143 int last = tmpStr.findRev(' ') + 1; 1143 int last = tmpStr.findRev(' ') + 1;
1144 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1144 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1145 index += 1; 1145 index += 1;
1146 short tmpDay; 1146 short tmpDay;
1147 if( index == last ) { 1147 if( index == last ) {
1148 // e.g. MD1 #0 1148 // e.g. MD1 #0
1149 tmpDay = anEvent->dtStart().date().day(); 1149 tmpDay = anEvent->dtStart().date().day();
1150 anEvent->recurrence()->addMonthlyDay(tmpDay); 1150 anEvent->recurrence()->addMonthlyDay(tmpDay);
1151 } 1151 }
1152 else { 1152 else {
1153 // e.g. MD1 3 #0 1153 // e.g. MD1 3 #0
1154 while (index < last) { 1154 while (index < last) {
1155 int index2 = tmpStr.find(' ', index); 1155 int index2 = tmpStr.find(' ', index);
1156 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1156 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1157 index = index2-1; 1157 index = index2-1;
1158 if (tmpStr.mid(index, 1) == "-") 1158 if (tmpStr.mid(index, 1) == "-")
1159 tmpDay = 0 - tmpDay; 1159 tmpDay = 0 - tmpDay;
1160 index += 2; // advance the index; 1160 index += 2; // advance the index;
1161 anEvent->recurrence()->addMonthlyDay(tmpDay); 1161 anEvent->recurrence()->addMonthlyDay(tmpDay);
1162 } // while != # 1162 } // while != #
1163 } 1163 }
1164 index = last; if (tmpStr.mid(index,1) == "#") index++; 1164 index = last; if (tmpStr.mid(index,1) == "#") index++;
1165 if (tmpStr.find('T', index) != -1) { 1165 if (tmpStr.find('T', index) != -1) {
1166 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1166 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1167 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate); 1167 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rEndDate);
1168 } else { 1168 } else {
1169 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1169 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1170 if (rDuration == 0) 1170 if (rDuration == 0)
1171 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1); 1171 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, -1);
1172 else 1172 else
1173 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration); 1173 anEvent->recurrence()->setMonthly(Recurrence::rMonthlyDay, rFreq, rDuration);
1174 } 1174 }
1175 } 1175 }
1176 1176
1177 /*********************** YEARLY-BY-MONTH *******************************/ 1177 /*********************** YEARLY-BY-MONTH *******************************/
1178 else if (tmpStr.left(2) == "YM") { 1178 else if (tmpStr.left(2) == "YM") {
1179 int index = tmpStr.find(' '); 1179 int index = tmpStr.find(' ');
1180 int last = tmpStr.findRev(' ') + 1; 1180 int last = tmpStr.findRev(' ') + 1;
1181 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1181 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1182 index += 1; 1182 index += 1;
1183 short tmpMonth; 1183 short tmpMonth;
1184 if( index == last ) { 1184 if( index == last ) {
1185 // e.g. YM1 #0 1185 // e.g. YM1 #0
1186 tmpMonth = anEvent->dtStart().date().month(); 1186 tmpMonth = anEvent->dtStart().date().month();
1187 anEvent->recurrence()->addYearlyNum(tmpMonth); 1187 anEvent->recurrence()->addYearlyNum(tmpMonth);
1188 } 1188 }
1189 else { 1189 else {
1190 // e.g. YM1 3 #0 1190 // e.g. YM1 3 #0
1191 while (index < last) { 1191 while (index < last) {
1192 int index2 = tmpStr.find(' ', index); 1192 int index2 = tmpStr.find(' ', index);
1193 tmpMonth = tmpStr.mid(index, (index2-index)).toShort(); 1193 tmpMonth = tmpStr.mid(index, (index2-index)).toShort();
1194 index = index2+1; 1194 index = index2+1;
1195 anEvent->recurrence()->addYearlyNum(tmpMonth); 1195 anEvent->recurrence()->addYearlyNum(tmpMonth);
1196 } // while != # 1196 } // while != #
1197 } 1197 }
1198 index = last; if (tmpStr.mid(index,1) == "#") index++; 1198 index = last; if (tmpStr.mid(index,1) == "#") index++;
1199 if (tmpStr.find('T', index) != -1) { 1199 if (tmpStr.find('T', index) != -1) {
1200 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1200 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1201 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate); 1201 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rEndDate);
1202 } else { 1202 } else {
1203 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1203 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1204 if (rDuration == 0) 1204 if (rDuration == 0)
1205 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1); 1205 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, -1);
1206 else 1206 else
1207 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration); 1207 anEvent->recurrence()->setYearly(Recurrence::rYearlyMonth, rFreq, rDuration);
1208 } 1208 }
1209 } 1209 }
1210 1210
1211 /*********************** YEARLY-BY-DAY *********************************/ 1211 /*********************** YEARLY-BY-DAY *********************************/
1212 else if (tmpStr.left(2) == "YD") { 1212 else if (tmpStr.left(2) == "YD") {
1213 int index = tmpStr.find(' '); 1213 int index = tmpStr.find(' ');
1214 int last = tmpStr.findRev(' ') + 1; 1214 int last = tmpStr.findRev(' ') + 1;
1215 int rFreq = tmpStr.mid(2, (index-1)).toInt(); 1215 int rFreq = tmpStr.mid(2, (index-1)).toInt();
1216 index += 1; 1216 index += 1;
1217 short tmpDay; 1217 short tmpDay;
1218 if( index == last ) { 1218 if( index == last ) {
1219 // e.g. YD1 #0 1219 // e.g. YD1 #0
1220 tmpDay = anEvent->dtStart().date().dayOfYear(); 1220 tmpDay = anEvent->dtStart().date().dayOfYear();
1221 anEvent->recurrence()->addYearlyNum(tmpDay); 1221 anEvent->recurrence()->addYearlyNum(tmpDay);
1222 } 1222 }
1223 else { 1223 else {
1224 // e.g. YD1 123 #0 1224 // e.g. YD1 123 #0
1225 while (index < last) { 1225 while (index < last) {
1226 int index2 = tmpStr.find(' ', index); 1226 int index2 = tmpStr.find(' ', index);
1227 tmpDay = tmpStr.mid(index, (index2-index)).toShort(); 1227 tmpDay = tmpStr.mid(index, (index2-index)).toShort();
1228 index = index2+1; 1228 index = index2+1;
1229 anEvent->recurrence()->addYearlyNum(tmpDay); 1229 anEvent->recurrence()->addYearlyNum(tmpDay);
1230 } // while != # 1230 } // while != #
1231 } 1231 }
1232 index = last; if (tmpStr.mid(index,1) == "#") index++; 1232 index = last; if (tmpStr.mid(index,1) == "#") index++;
1233 if (tmpStr.find('T', index) != -1) { 1233 if (tmpStr.find('T', index) != -1) {
1234 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date(); 1234 QDate rEndDate = (ISOToQDateTime(tmpStr.mid(index, tmpStr.length()-index))).date();
1235 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate); 1235 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rEndDate);
1236 } else { 1236 } else {
1237 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt(); 1237 int rDuration = tmpStr.mid(index, tmpStr.length()-index).toInt();
1238 if (rDuration == 0) 1238 if (rDuration == 0)
1239 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1); 1239 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, -1);
1240 else 1240 else
1241 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration); 1241 anEvent->recurrence()->setYearly(Recurrence::rYearlyDay, rFreq, rDuration);
1242 } 1242 }
1243 } else { 1243 } else {
1244 kdDebug(5800) << "we don't understand this type of recurrence!" << endl; 1244 kdDebug(5800) << "we don't understand this type of recurrence!" << endl;
1245 } // if 1245 } // if
1246 } // repeats 1246 } // repeats
1247 1247
1248 1248
1249 // recurrence exceptions 1249 // recurrence exceptions
1250 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) { 1250 if ((vo = isAPropertyOf(vevent, VCExpDateProp)) != 0) {
1251 s = fakeCString(vObjectUStringZValue(vo)); 1251 s = fakeCString(vObjectUStringZValue(vo));
1252 QStringList exDates = QStringList::split(",",s); 1252 QStringList exDates = QStringList::split(",",s);
1253 QStringList::ConstIterator it; 1253 QStringList::ConstIterator it;
1254 for(it = exDates.begin(); it != exDates.end(); ++it ) { 1254 for(it = exDates.begin(); it != exDates.end(); ++it ) {
1255 anEvent->addExDate(ISOToQDate(*it)); 1255 anEvent->addExDate(ISOToQDate(*it));
1256 } 1256 }
1257 deleteStr(s); 1257 deleteStr(s);
1258 } 1258 }
1259 1259
1260 // summary 1260 // summary
1261 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) { 1261 if ((vo = isAPropertyOf(vevent, VCSummaryProp))) {
1262 s = fakeCString(vObjectUStringZValue(vo)); 1262 s = fakeCString(vObjectUStringZValue(vo));
1263 anEvent->setSummary(QString::fromLocal8Bit(s)); 1263 anEvent->setSummary(QString::fromLocal8Bit(s));
1264 deleteStr(s); 1264 deleteStr(s);
1265 } 1265 }
1266 if ((vo = isAPropertyOf(vevent, VCLocationProp))) { 1266 if ((vo = isAPropertyOf(vevent, VCLocationProp))) {
1267 s = fakeCString(vObjectUStringZValue(vo)); 1267 s = fakeCString(vObjectUStringZValue(vo));
1268 anEvent->setLocation(QString::fromLocal8Bit(s)); 1268 anEvent->setLocation(QString::fromLocal8Bit(s));
1269 deleteStr(s); 1269 deleteStr(s);
1270 } 1270 }
1271 1271
1272 // description 1272 // description
1273 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) { 1273 if ((vo = isAPropertyOf(vevent, VCDescriptionProp)) != 0) {
1274 s = fakeCString(vObjectUStringZValue(vo)); 1274 s = fakeCString(vObjectUStringZValue(vo));
1275 if (!anEvent->description().isEmpty()) { 1275 if (!anEvent->description().isEmpty()) {
1276 anEvent->setDescription(anEvent->description() + "\n" + 1276 anEvent->setDescription(anEvent->description() + "\n" +
1277 QString::fromLocal8Bit(s)); 1277 QString::fromLocal8Bit(s));
1278 } else { 1278 } else {
1279 anEvent->setDescription(QString::fromLocal8Bit(s)); 1279 anEvent->setDescription(QString::fromLocal8Bit(s));
1280 } 1280 }
1281 deleteStr(s); 1281 deleteStr(s);
1282 } 1282 }
1283 1283
1284 // some stupid vCal exporters ignore the standard and use Description 1284 // some stupid vCal exporters ignore the standard and use Description
1285 // instead of Summary for the default field. Correct for this. 1285 // instead of Summary for the default field. Correct for this.
1286 if (anEvent->summary().isEmpty() && 1286 if (anEvent->summary().isEmpty() &&
1287 !(anEvent->description().isEmpty())) { 1287 !(anEvent->description().isEmpty())) {
1288 QString tmpStr = anEvent->description().simplifyWhiteSpace(); 1288 QString tmpStr = anEvent->description().simplifyWhiteSpace();
1289 anEvent->setDescription(""); 1289 anEvent->setDescription("");
1290 anEvent->setSummary(tmpStr); 1290 anEvent->setSummary(tmpStr);
1291 } 1291 }
1292 1292
1293#if 0 1293#if 0
1294 // status 1294 // status
1295 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) { 1295 if ((vo = isAPropertyOf(vevent, VCStatusProp)) != 0) {
1296 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo))); 1296 QString tmpStr(s = fakeCString(vObjectUStringZValue(vo)));
1297 deleteStr(s); 1297 deleteStr(s);
1298// TODO: Define Event status 1298// TODO: Define Event status
1299// anEvent->setStatus(tmpStr); 1299// anEvent->setStatus(tmpStr);
1300 } 1300 }
1301 else 1301 else
1302// anEvent->setStatus("NEEDS ACTION"); 1302// anEvent->setStatus("NEEDS ACTION");
1303#endif 1303#endif
1304 1304
1305 // secrecy 1305 // secrecy
1306 int secrecy = Incidence::SecrecyPublic; 1306 int secrecy = Incidence::SecrecyPublic;
1307 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) { 1307 if ((vo = isAPropertyOf(vevent, VCClassProp)) != 0) {
1308 s = fakeCString(vObjectUStringZValue(vo)); 1308 s = fakeCString(vObjectUStringZValue(vo));
1309 if (strcmp(s,"PRIVATE") == 0) { 1309 if (strcmp(s,"PRIVATE") == 0) {
1310 secrecy = Incidence::SecrecyPrivate; 1310 secrecy = Incidence::SecrecyPrivate;
1311 } else if (strcmp(s,"CONFIDENTIAL") == 0) { 1311 } else if (strcmp(s,"CONFIDENTIAL") == 0) {
1312 secrecy = Incidence::SecrecyConfidential; 1312 secrecy = Incidence::SecrecyConfidential;
1313 } 1313 }
1314 deleteStr(s); 1314 deleteStr(s);
1315 } 1315 }
1316 anEvent->setSecrecy(secrecy); 1316 anEvent->setSecrecy(secrecy);
1317 1317
1318 // categories 1318 // categories
1319 QStringList tmpStrList; 1319 QStringList tmpStrList;
1320 int index1 = 0; 1320 int index1 = 0;
1321 int index2 = 0; 1321 int index2 = 0;
1322 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) { 1322 if ((vo = isAPropertyOf(vevent, VCCategoriesProp)) != 0) {
1323 s = fakeCString(vObjectUStringZValue(vo)); 1323 s = fakeCString(vObjectUStringZValue(vo));
1324 QString categories = QString::fromLocal8Bit(s); 1324 QString categories = QString::fromLocal8Bit(s);
1325 deleteStr(s); 1325 deleteStr(s);
1326 //const char* category; 1326 //const char* category;
1327 QString category; 1327 QString category;
1328 while ((index2 = categories.find(',', index1)) != -1) { 1328 while ((index2 = categories.find(',', index1)) != -1) {
1329 //category = (const char *) categories.mid(index1, (index2 - index1)); 1329 //category = (const char *) categories.mid(index1, (index2 - index1));
1330 category = categories.mid(index1, (index2 - index1)); 1330 category = categories.mid(index1, (index2 - index1));
1331 tmpStrList.append(category); 1331 tmpStrList.append(category);
1332 index1 = index2+1; 1332 index1 = index2+1;
1333 } 1333 }
1334 // get last category 1334 // get last category
1335 category = categories.mid(index1, (categories.length()-index1)); 1335 category = categories.mid(index1, (categories.length()-index1));
1336 tmpStrList.append(category); 1336 tmpStrList.append(category);
1337 anEvent->setCategories(tmpStrList); 1337 anEvent->setCategories(tmpStrList);
1338 } 1338 }
1339 1339
1340 // attachments 1340 // attachments
1341 tmpStrList.clear(); 1341 tmpStrList.clear();
1342 initPropIterator(&voi, vevent); 1342 initPropIterator(&voi, vevent);
1343 while (moreIteration(&voi)) { 1343 while (moreIteration(&voi)) {
1344 vo = nextVObject(&voi); 1344 vo = nextVObject(&voi);
1345 if (strcmp(vObjectName(vo), VCAttachProp) == 0) { 1345 if (strcmp(vObjectName(vo), VCAttachProp) == 0) {
1346 s = fakeCString(vObjectUStringZValue(vo)); 1346 s = fakeCString(vObjectUStringZValue(vo));
1347 anEvent->addAttachment(new Attachment(QString(s))); 1347 anEvent->addAttachment(new Attachment(QString(s)));
1348 deleteStr(s); 1348 deleteStr(s);
1349 } 1349 }
1350 } 1350 }
1351 1351
1352 // resources 1352 // resources
1353 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) { 1353 if ((vo = isAPropertyOf(vevent, VCResourcesProp)) != 0) {
1354 QString resources = (s = fakeCString(vObjectUStringZValue(vo))); 1354 QString resources = (s = fakeCString(vObjectUStringZValue(vo)));
1355 deleteStr(s); 1355 deleteStr(s);
1356 tmpStrList.clear(); 1356 tmpStrList.clear();
1357 index1 = 0; 1357 index1 = 0;
1358 index2 = 0; 1358 index2 = 0;
1359 QString resource; 1359 QString resource;
1360 while ((index2 = resources.find(';', index1)) != -1) { 1360 while ((index2 = resources.find(';', index1)) != -1) {
1361 resource = resources.mid(index1, (index2 - index1)); 1361 resource = resources.mid(index1, (index2 - index1));
1362 tmpStrList.append(resource); 1362 tmpStrList.append(resource);
1363 index1 = index2; 1363 index1 = index2;
1364 } 1364 }
1365 anEvent->setResources(tmpStrList); 1365 anEvent->setResources(tmpStrList);
1366 } 1366 }
1367 1367
1368 /* alarm stuff */ 1368 /* alarm stuff */
1369 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) { 1369 if ((vo = isAPropertyOf(vevent, VCDAlarmProp))) {
1370 Alarm* alarm = anEvent->newAlarm(); 1370 Alarm* alarm = anEvent->newAlarm();
1371 VObject *a; 1371 VObject *a;
1372 if ((a = isAPropertyOf(vo, VCRunTimeProp))) { 1372 if ((a = isAPropertyOf(vo, VCRunTimeProp))) {
1373 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a)))); 1373 alarm->setTime(ISOToQDateTime(s = fakeCString(vObjectUStringZValue(a))));
1374 deleteStr(s); 1374 deleteStr(s);
1375 } 1375 }
1376 alarm->setEnabled(true); 1376 alarm->setEnabled(true);
1377 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) { 1377 if ((vo = isAPropertyOf(vevent, VCPAlarmProp))) {
1378 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) { 1378 if ((a = isAPropertyOf(vo, VCProcedureNameProp))) {
1379 s = fakeCString(vObjectUStringZValue(a)); 1379 s = fakeCString(vObjectUStringZValue(a));
1380 alarm->setProcedureAlarm(QFile::decodeName(s)); 1380 alarm->setProcedureAlarm(QFile::decodeName(s));
1381 deleteStr(s); 1381 deleteStr(s);
1382 } 1382 }
1383 } 1383 }
1384 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) { 1384 if ((vo = isAPropertyOf(vevent, VCAAlarmProp))) {
1385 if ((a = isAPropertyOf(vo, VCAudioContentProp))) { 1385 if ((a = isAPropertyOf(vo, VCAudioContentProp))) {
1386 s = fakeCString(vObjectUStringZValue(a)); 1386 s = fakeCString(vObjectUStringZValue(a));
1387 alarm->setAudioAlarm(QFile::decodeName(s)); 1387 alarm->setAudioAlarm(QFile::decodeName(s));
1388 deleteStr(s); 1388 deleteStr(s);
1389 } 1389 }
1390 } 1390 }
1391 } 1391 }
1392 1392
1393 // priority 1393 // priority
1394 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) { 1394 if ((vo = isAPropertyOf(vevent, VCPriorityProp))) {
1395 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1395 anEvent->setPriority(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1396 deleteStr(s); 1396 deleteStr(s);
1397 } 1397 }
1398 1398
1399 // transparency 1399 // transparency
1400 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) { 1400 if ((vo = isAPropertyOf(vevent, VCTranspProp)) != 0) {
1401 int i = atoi(s = fakeCString(vObjectUStringZValue(vo))); 1401 int i = atoi(s = fakeCString(vObjectUStringZValue(vo)));
1402 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque ); 1402 anEvent->setTransparency( i == 1 ? Event::Transparent : Event::Opaque );
1403 deleteStr(s); 1403 deleteStr(s);
1404 } 1404 }
1405 1405
1406 // related event 1406 // related event
1407 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) { 1407 if ((vo = isAPropertyOf(vevent, VCRelatedToProp)) != 0) {
1408 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo))); 1408 anEvent->setRelatedToUid(s = fakeCString(vObjectUStringZValue(vo)));
1409 deleteStr(s); 1409 deleteStr(s);
1410 mEventsRelate.append(anEvent); 1410 mEventsRelate.append(anEvent);
1411 } 1411 }
1412 1412
1413 /* PILOT SYNC STUFF */ 1413 /* PILOT SYNC STUFF */
1414 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) { 1414 if ((vo = isAPropertyOf(vevent, XPilotIdProp))) {
1415 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1415 anEvent->setPilotId(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1416 deleteStr(s); 1416 deleteStr(s);
1417 } 1417 }
1418 else 1418 else
1419 anEvent->setPilotId(0); 1419 anEvent->setPilotId(0);
1420 1420
1421 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) { 1421 if ((vo = isAPropertyOf(vevent, XPilotStatusProp))) {
1422 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo)))); 1422 anEvent->setSyncStatus(atoi(s = fakeCString(vObjectUStringZValue(vo))));
1423 deleteStr(s); 1423 deleteStr(s);
1424 } 1424 }
1425 else 1425 else
1426 anEvent->setSyncStatus(Event::SYNCMOD); 1426 anEvent->setSyncStatus(Event::SYNCMOD);
1427 1427
1428 return anEvent; 1428 return anEvent;
1429} 1429}
1430 1430
1431 1431
1432QString VCalFormat::qDateToISO(const QDate &qd) 1432QString VCalFormat::qDateToISO(const QDate &qd)
1433{ 1433{
1434 QString tmpStr; 1434 QString tmpStr;
1435 1435
1436 ASSERT(qd.isValid()); 1436 ASSERT(qd.isValid());
1437 1437
1438 tmpStr.sprintf("%.2d%.2d%.2d", 1438 tmpStr.sprintf("%.2d%.2d%.2d",
1439 qd.year(), qd.month(), qd.day()); 1439 qd.year(), qd.month(), qd.day());
1440 return tmpStr; 1440 return tmpStr;
1441 1441
1442} 1442}
1443 1443
1444QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu) 1444QString VCalFormat::qDateTimeToISO(const QDateTime &qdt, bool zulu)
1445{ 1445{
1446 QString tmpStr; 1446 QString tmpStr;
1447 1447
1448 ASSERT(qdt.date().isValid()); 1448 ASSERT(qdt.date().isValid());
1449 ASSERT(qdt.time().isValid()); 1449 ASSERT(qdt.time().isValid());
1450 if (zulu && !useLocalTime ) { 1450 if (zulu && !useLocalTime ) {
1451 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60); 1451 QDateTime tmpDT = qdt.addSecs ( -KGlobal::locale()->localTimeOffset( qdt )*60);
1452 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ", 1452 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2dZ",
1453 tmpDT.date().year(), tmpDT.date().month(), 1453 tmpDT.date().year(), tmpDT.date().month(),
1454 tmpDT.date().day(), tmpDT.time().hour(), 1454 tmpDT.date().day(), tmpDT.time().hour(),
1455 tmpDT.time().minute(), tmpDT.time().second()); 1455 tmpDT.time().minute(), tmpDT.time().second());
1456 } else { 1456 } else {
1457 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d", 1457 tmpStr.sprintf("%.2d%.2d%.2dT%.2d%.2d%.2d",
1458 qdt.date().year(), qdt.date().month(), 1458 qdt.date().year(), qdt.date().month(),
1459 qdt.date().day(), qdt.time().hour(), 1459 qdt.date().day(), qdt.time().hour(),
1460 qdt.time().minute(), qdt.time().second()); 1460 qdt.time().minute(), qdt.time().second());
1461 } 1461 }
1462 return tmpStr; 1462 return tmpStr;
1463} 1463}
1464 1464
1465QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr) 1465QDateTime VCalFormat::ISOToQDateTime(const QString & dtStr)
1466{ 1466{
1467 QDate tmpDate; 1467 QDate tmpDate;
1468 QTime tmpTime; 1468 QTime tmpTime;
1469 QString tmpStr; 1469 QString tmpStr;
1470 int year, month, day, hour, minute, second; 1470 int year, month, day, hour, minute, second;
1471 1471
1472 tmpStr = dtStr; 1472 tmpStr = dtStr;
1473 year = tmpStr.left(4).toInt(); 1473 year = tmpStr.left(4).toInt();
1474 month = tmpStr.mid(4,2).toInt(); 1474 month = tmpStr.mid(4,2).toInt();
1475 day = tmpStr.mid(6,2).toInt(); 1475 day = tmpStr.mid(6,2).toInt();
1476 hour = tmpStr.mid(9,2).toInt(); 1476 hour = tmpStr.mid(9,2).toInt();
1477 minute = tmpStr.mid(11,2).toInt(); 1477 minute = tmpStr.mid(11,2).toInt();
1478 second = tmpStr.mid(13,2).toInt(); 1478 second = tmpStr.mid(13,2).toInt();
1479 tmpDate.setYMD(year, month, day); 1479 tmpDate.setYMD(year, month, day);
1480 tmpTime.setHMS(hour, minute, second); 1480 tmpTime.setHMS(hour, minute, second);
1481 1481
1482 ASSERT(tmpDate.isValid()); 1482 ASSERT(tmpDate.isValid());
1483 ASSERT(tmpTime.isValid()); 1483 ASSERT(tmpTime.isValid());
1484 QDateTime tmpDT(tmpDate, tmpTime); 1484 QDateTime tmpDT(tmpDate, tmpTime);
1485 // correct for GMT if string is in Zulu format 1485 // correct for GMT if string is in Zulu format
1486 if (dtStr.at(dtStr.length()-1) == 'Z') 1486 if (dtStr.at(dtStr.length()-1) == 'Z')
1487 tmpDT = tmpDT.addSecs(60*mCalendar->getTimeZone()); 1487 tmpDT = tmpDT.addSecs (KGlobal::locale()->localTimeOffset( tmpDT )*60);
1488 return tmpDT; 1488 return tmpDT;
1489} 1489}
1490 1490
1491QDate VCalFormat::ISOToQDate(const QString &dateStr) 1491QDate VCalFormat::ISOToQDate(const QString &dateStr)
1492{ 1492{
1493 int year, month, day; 1493 int year, month, day;
1494 1494
1495 year = dateStr.left(4).toInt(); 1495 year = dateStr.left(4).toInt();
1496 month = dateStr.mid(4,2).toInt(); 1496 month = dateStr.mid(4,2).toInt();
1497 day = dateStr.mid(6,2).toInt(); 1497 day = dateStr.mid(6,2).toInt();
1498 1498
1499 return(QDate(year, month, day)); 1499 return(QDate(year, month, day));
1500} 1500}
1501 1501
1502// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1502// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1503// and break it down from it's tree-like format into the dictionary format 1503// and break it down from it's tree-like format into the dictionary format
1504// that is used internally in the VCalFormat. 1504// that is used internally in the VCalFormat.
1505void VCalFormat::populate(VObject *vcal) 1505void VCalFormat::populate(VObject *vcal)
1506{ 1506{
1507 // this function will populate the caldict dictionary and other event 1507 // this function will populate the caldict dictionary and other event
1508 // lists. It turns vevents into Events and then inserts them. 1508 // lists. It turns vevents into Events and then inserts them.
1509 1509
1510 VObjectIterator i; 1510 VObjectIterator i;
1511 VObject *curVO, *curVOProp; 1511 VObject *curVO, *curVOProp;
1512 Event *anEvent; 1512 Event *anEvent;
1513 1513
1514 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1514 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1515 char *methodType = 0; 1515 char *methodType = 0;
1516 methodType = fakeCString(vObjectUStringZValue(curVO)); 1516 methodType = fakeCString(vObjectUStringZValue(curVO));
1517 kdDebug() << "This calendar is an iTIP transaction of type '" 1517 kdDebug() << "This calendar is an iTIP transaction of type '"
1518 << methodType << "'" << endl; 1518 << methodType << "'" << endl;
1519 delete methodType; 1519 delete methodType;
1520 } 1520 }
1521 1521
1522 // warn the user that we might have trouble reading non-known calendar. 1522 // warn the user that we might have trouble reading non-known calendar.
1523 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) { 1523 if ((curVO = isAPropertyOf(vcal, VCProdIdProp)) != 0) {
1524 char *s = fakeCString(vObjectUStringZValue(curVO)); 1524 char *s = fakeCString(vObjectUStringZValue(curVO));
1525 if (strcmp(productId().local8Bit(), s) != 0) 1525 if (strcmp(productId().local8Bit(), s) != 0)
1526 kdDebug() << "This vCalendar file was not created by KOrganizer " 1526 kdDebug() << "This vCalendar file was not created by KOrganizer "
1527 "or any other product we support. Loading anyway..." << endl; 1527 "or any other product we support. Loading anyway..." << endl;
1528 mLoadedProductId = s; 1528 mLoadedProductId = s;
1529 deleteStr(s); 1529 deleteStr(s);
1530 } 1530 }
1531 1531
1532 // warn the user we might have trouble reading this unknown version. 1532 // warn the user we might have trouble reading this unknown version.
1533 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1533 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1534 char *s = fakeCString(vObjectUStringZValue(curVO)); 1534 char *s = fakeCString(vObjectUStringZValue(curVO));
1535 if (strcmp(_VCAL_VERSION, s) != 0) 1535 if (strcmp(_VCAL_VERSION, s) != 0)
1536 kdDebug() << "This vCalendar file has version " << s 1536 kdDebug() << "This vCalendar file has version " << s
1537 << "We only support " << _VCAL_VERSION << endl; 1537 << "We only support " << _VCAL_VERSION << endl;
1538 deleteStr(s); 1538 deleteStr(s);
1539 } 1539 }
1540 1540
1541 // set the time zone 1541 // set the time zone
1542 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1542 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1543 char *s = fakeCString(vObjectUStringZValue(curVO)); 1543 char *s = fakeCString(vObjectUStringZValue(curVO));
1544 mCalendar->setTimeZone(s); 1544 mCalendar->setTimeZone(s);
1545 deleteStr(s); 1545 deleteStr(s);
1546 } 1546 }
1547 1547
1548 1548
1549 // Store all events with a relatedTo property in a list for post-processing 1549 // Store all events with a relatedTo property in a list for post-processing
1550 mEventsRelate.clear(); 1550 mEventsRelate.clear();
1551 mTodosRelate.clear(); 1551 mTodosRelate.clear();
1552 1552
1553 initPropIterator(&i, vcal); 1553 initPropIterator(&i, vcal);
1554 1554
1555 // go through all the vobjects in the vcal 1555 // go through all the vobjects in the vcal
1556 while (moreIteration(&i)) { 1556 while (moreIteration(&i)) {
1557 curVO = nextVObject(&i); 1557 curVO = nextVObject(&i);
1558 1558
1559 /************************************************************************/ 1559 /************************************************************************/
1560 1560
1561 // now, check to see that the object is an event or todo. 1561 // now, check to see that the object is an event or todo.
1562 if (strcmp(vObjectName(curVO), VCEventProp) == 0) { 1562 if (strcmp(vObjectName(curVO), VCEventProp) == 0) {
1563 1563
1564 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) { 1564 if ((curVOProp = isAPropertyOf(curVO, XPilotStatusProp)) != 0) {
1565 char *s; 1565 char *s;
1566 s = fakeCString(vObjectUStringZValue(curVOProp)); 1566 s = fakeCString(vObjectUStringZValue(curVOProp));
1567 // check to see if event was deleted by the kpilot conduit 1567 // check to see if event was deleted by the kpilot conduit
1568 if (atoi(s) == Event::SYNCDEL) { 1568 if (atoi(s) == Event::SYNCDEL) {
1569 deleteStr(s); 1569 deleteStr(s);
1570 kdDebug(5800) << "skipping pilot-deleted event" << endl; 1570 kdDebug(5800) << "skipping pilot-deleted event" << endl;
1571 goto SKIP; 1571 goto SKIP;
1572 } 1572 }
1573 deleteStr(s); 1573 deleteStr(s);
1574 } 1574 }
1575 1575
1576 // this code checks to see if we are trying to read in an event 1576 // this code checks to see if we are trying to read in an event
1577 // that we already find to be in the calendar. If we find this 1577 // that we already find to be in the calendar. If we find this
1578 // to be the case, we skip the event. 1578 // to be the case, we skip the event.
1579 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) { 1579 if ((curVOProp = isAPropertyOf(curVO, VCUniqueStringProp)) != 0) {
1580 char *s = fakeCString(vObjectUStringZValue(curVOProp)); 1580 char *s = fakeCString(vObjectUStringZValue(curVOProp));
1581 QString tmpStr(s); 1581 QString tmpStr(s);
1582 deleteStr(s); 1582 deleteStr(s);
1583 1583
1584 if (mCalendar->event(tmpStr)) { 1584 if (mCalendar->event(tmpStr)) {
1585 goto SKIP; 1585 goto SKIP;
1586 } 1586 }
1587 if (mCalendar->todo(tmpStr)) { 1587 if (mCalendar->todo(tmpStr)) {
1588 goto SKIP; 1588 goto SKIP;
1589 } 1589 }
1590 } 1590 }
1591 1591
1592 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) && 1592 if ((!(curVOProp = isAPropertyOf(curVO, VCDTstartProp))) &&
1593 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) { 1593 (!(curVOProp = isAPropertyOf(curVO, VCDTendProp)))) {
1594 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl; 1594 kdDebug(5800) << "found a VEvent with no DTSTART and no DTEND! Skipping..." << endl;
1595 goto SKIP; 1595 goto SKIP;
1596 } 1596 }
1597 1597
1598 anEvent = VEventToEvent(curVO); 1598 anEvent = VEventToEvent(curVO);
1599 // we now use addEvent instead of insertEvent so that the 1599 // we now use addEvent instead of insertEvent so that the
1600 // signal/slot get connected. 1600 // signal/slot get connected.
1601 if (anEvent) { 1601 if (anEvent) {
1602 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) { 1602 if ( !anEvent->dtStart().isValid() || !anEvent->dtEnd().isValid() ) {
1603 kdDebug() << "VCalFormat::populate(): Event has invalid dates." 1603 kdDebug() << "VCalFormat::populate(): Event has invalid dates."
1604 << endl; 1604 << endl;
1605 } else { 1605 } else {
1606 mCalendar->addEvent(anEvent); 1606 mCalendar->addEvent(anEvent);
1607 } 1607 }
1608 } else { 1608 } else {
1609 // some sort of error must have occurred while in translation. 1609 // some sort of error must have occurred while in translation.
1610 goto SKIP; 1610 goto SKIP;
1611 } 1611 }
1612 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) { 1612 } else if (strcmp(vObjectName(curVO), VCTodoProp) == 0) {
1613 Todo *aTodo = VTodoToEvent(curVO); 1613 Todo *aTodo = VTodoToEvent(curVO);
1614 mCalendar->addTodo(aTodo); 1614 mCalendar->addTodo(aTodo);
1615 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) || 1615 } else if ((strcmp(vObjectName(curVO), VCVersionProp) == 0) ||
1616 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) || 1616 (strcmp(vObjectName(curVO), VCProdIdProp) == 0) ||
1617 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) { 1617 (strcmp(vObjectName(curVO), VCTimeZoneProp) == 0)) {
1618 // do nothing, we know these properties and we want to skip them. 1618 // do nothing, we know these properties and we want to skip them.
1619 // we have either already processed them or are ignoring them. 1619 // we have either already processed them or are ignoring them.
1620 ; 1620 ;
1621 } else { 1621 } else {
1622 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl; 1622 kdDebug(5800) << "Ignoring unknown vObject \"" << vObjectName(curVO) << "\"" << endl;
1623 } 1623 }
1624 SKIP: 1624 SKIP:
1625 ; 1625 ;
1626 } // while 1626 } // while
1627 1627
1628 // Post-Process list of events with relations, put Event objects in relation 1628 // Post-Process list of events with relations, put Event objects in relation
1629 Event *ev; 1629 Event *ev;
1630 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) { 1630 for ( ev=mEventsRelate.first(); ev != 0; ev=mEventsRelate.next() ) {
1631 ev->setRelatedTo(mCalendar->event(ev->relatedToUid())); 1631 ev->setRelatedTo(mCalendar->event(ev->relatedToUid()));
1632 } 1632 }
1633 Todo *todo; 1633 Todo *todo;
1634 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) { 1634 for ( todo=mTodosRelate.first(); todo != 0; todo=mTodosRelate.next() ) {
1635 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid())); 1635 todo->setRelatedTo(mCalendar->todo(todo->relatedToUid()));
1636 } 1636 }
1637} 1637}
1638 1638
1639const char *VCalFormat::dayFromNum(int day) 1639const char *VCalFormat::dayFromNum(int day)
1640{ 1640{
1641 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " }; 1641 const char *days[7] = { "MO ", "TU ", "WE ", "TH ", "FR ", "SA ", "SU " };
1642 1642
1643 return days[day]; 1643 return days[day];
1644} 1644}
1645 1645
1646int VCalFormat::numFromDay(const QString &day) 1646int VCalFormat::numFromDay(const QString &day)
1647{ 1647{
1648 if (day == "MO ") return 0; 1648 if (day == "MO ") return 0;
1649 if (day == "TU ") return 1; 1649 if (day == "TU ") return 1;
1650 if (day == "WE ") return 2; 1650 if (day == "WE ") return 2;
1651 if (day == "TH ") return 3; 1651 if (day == "TH ") return 3;
1652 if (day == "FR ") return 4; 1652 if (day == "FR ") return 4;
1653 if (day == "SA ") return 5; 1653 if (day == "SA ") return 5;
1654 if (day == "SU ") return 6; 1654 if (day == "SU ") return 6;
1655 1655
1656 return -1; // something bad happened. :) 1656 return -1; // something bad happened. :)
1657} 1657}
1658 1658
1659Attendee::PartStat VCalFormat::readStatus(const char *s) const 1659Attendee::PartStat VCalFormat::readStatus(const char *s) const
1660{ 1660{
1661 QString statStr = s; 1661 QString statStr = s;
1662 statStr = statStr.upper(); 1662 statStr = statStr.upper();
1663 Attendee::PartStat status; 1663 Attendee::PartStat status;
1664 1664
1665 if (statStr == "X-ACTION") 1665 if (statStr == "X-ACTION")
1666 status = Attendee::NeedsAction; 1666 status = Attendee::NeedsAction;
1667 else if (statStr == "NEEDS ACTION") 1667 else if (statStr == "NEEDS ACTION")
1668 status = Attendee::NeedsAction; 1668 status = Attendee::NeedsAction;
1669 else if (statStr== "ACCEPTED") 1669 else if (statStr== "ACCEPTED")
1670 status = Attendee::Accepted; 1670 status = Attendee::Accepted;
1671 else if (statStr== "SENT") 1671 else if (statStr== "SENT")
1672 status = Attendee::NeedsAction; 1672 status = Attendee::NeedsAction;
1673 else if (statStr== "TENTATIVE") 1673 else if (statStr== "TENTATIVE")
1674 status = Attendee::Tentative; 1674 status = Attendee::Tentative;
1675 else if (statStr== "CONFIRMED") 1675 else if (statStr== "CONFIRMED")
1676 status = Attendee::Accepted; 1676 status = Attendee::Accepted;
1677 else if (statStr== "DECLINED") 1677 else if (statStr== "DECLINED")
1678 status = Attendee::Declined; 1678 status = Attendee::Declined;
1679 else if (statStr== "COMPLETED") 1679 else if (statStr== "COMPLETED")
1680 status = Attendee::Completed; 1680 status = Attendee::Completed;
1681 else if (statStr== "DELEGATED") 1681 else if (statStr== "DELEGATED")
1682 status = Attendee::Delegated; 1682 status = Attendee::Delegated;
1683 else { 1683 else {
1684 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl; 1684 kdDebug(5800) << "error setting attendee mStatus, unknown mStatus!" << endl;
1685 status = Attendee::NeedsAction; 1685 status = Attendee::NeedsAction;
1686 } 1686 }
1687 1687
1688 return status; 1688 return status;
1689} 1689}
1690 1690
1691QCString VCalFormat::writeStatus(Attendee::PartStat status) const 1691QCString VCalFormat::writeStatus(Attendee::PartStat status) const
1692{ 1692{
1693 switch(status) { 1693 switch(status) {
1694 default: 1694 default:
1695 case Attendee::NeedsAction: 1695 case Attendee::NeedsAction:
1696 return "NEEDS ACTION"; 1696 return "NEEDS ACTION";
1697 break; 1697 break;
1698 case Attendee::Accepted: 1698 case Attendee::Accepted:
1699 return "ACCEPTED"; 1699 return "ACCEPTED";
1700 break; 1700 break;
1701 case Attendee::Declined: 1701 case Attendee::Declined:
1702 return "DECLINED"; 1702 return "DECLINED";
1703 break; 1703 break;
1704 case Attendee::Tentative: 1704 case Attendee::Tentative:
1705 return "TENTATIVE"; 1705 return "TENTATIVE";
1706 break; 1706 break;
1707 case Attendee::Delegated: 1707 case Attendee::Delegated:
1708 return "DELEGATED"; 1708 return "DELEGATED";
1709 break; 1709 break;
1710 case Attendee::Completed: 1710 case Attendee::Completed:
1711 return "COMPLETED"; 1711 return "COMPLETED";
1712 break; 1712 break;
1713 case Attendee::InProcess: 1713 case Attendee::InProcess:
1714 return "NEEDS ACTION"; 1714 return "NEEDS ACTION";
1715 break; 1715 break;
1716 } 1716 }
1717} 1717}