summaryrefslogtreecommitdiffabout
path: root/libkcal/icalformatimpl.cpp
Unidiff
Diffstat (limited to 'libkcal/icalformatimpl.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 32a1337..964ffe3 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1203,553 +1203,557 @@ void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1203 } 1203 }
1204 break; 1204 break;
1205 case ICAL_STATUS_PROPERTY: // summary 1205 case ICAL_STATUS_PROPERTY: // summary
1206 { 1206 {
1207 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) ) 1207 if ( ICAL_STATUS_CANCELLED == icalproperty_get_status(p) )
1208 incidence->setCancelled( true ); 1208 incidence->setCancelled( true );
1209 } 1209 }
1210 break; 1210 break;
1211 1211
1212 case ICAL_LOCATION_PROPERTY: // location 1212 case ICAL_LOCATION_PROPERTY: // location
1213 text = icalproperty_get_location(p); 1213 text = icalproperty_get_location(p);
1214 incidence->setLocation(QString::fromUtf8(text)); 1214 incidence->setLocation(QString::fromUtf8(text));
1215 break; 1215 break;
1216 1216
1217#if 0 1217#if 0
1218 // status 1218 // status
1219 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) { 1219 if ((vo = isAPropertyOf(vincidence, VCStatusProp)) != 0) {
1220 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo))); 1220 incidence->setStatus(s = fakeCString(vObjectUStringZValue(vo)));
1221 deleteStr(s); 1221 deleteStr(s);
1222 } 1222 }
1223 else 1223 else
1224 incidence->setStatus("NEEDS ACTION"); 1224 incidence->setStatus("NEEDS ACTION");
1225#endif 1225#endif
1226 1226
1227 case ICAL_PRIORITY_PROPERTY: // priority 1227 case ICAL_PRIORITY_PROPERTY: // priority
1228 intvalue = icalproperty_get_priority(p); 1228 intvalue = icalproperty_get_priority(p);
1229 incidence->setPriority(intvalue); 1229 incidence->setPriority(intvalue);
1230 break; 1230 break;
1231 1231
1232 case ICAL_CATEGORIES_PROPERTY: // categories 1232 case ICAL_CATEGORIES_PROPERTY: // categories
1233 text = icalproperty_get_categories(p); 1233 text = icalproperty_get_categories(p);
1234 categories.append(QString::fromUtf8(text)); 1234 categories.append(QString::fromUtf8(text));
1235 break; 1235 break;
1236 //******************************************* 1236 //*******************************************
1237 case ICAL_RRULE_PROPERTY: 1237 case ICAL_RRULE_PROPERTY:
1238 // we do need (maybe )start datetime of incidence for recurrence 1238 // we do need (maybe )start datetime of incidence for recurrence
1239 // such that we can read recurrence only after we read incidence completely 1239 // such that we can read recurrence only after we read incidence completely
1240 readrec = true; 1240 readrec = true;
1241 rectype = icalproperty_get_rrule(p); 1241 rectype = icalproperty_get_rrule(p);
1242 break; 1242 break;
1243 1243
1244 case ICAL_EXDATE_PROPERTY: 1244 case ICAL_EXDATE_PROPERTY:
1245 icaltime = icalproperty_get_exdate(p); 1245 icaltime = icalproperty_get_exdate(p);
1246 incidence->addExDate(readICalDate(icaltime)); 1246 incidence->addExDate(readICalDate(icaltime));
1247 break; 1247 break;
1248 1248
1249 case ICAL_CLASS_PROPERTY: { 1249 case ICAL_CLASS_PROPERTY: {
1250 int inttext = icalproperty_get_class(p); 1250 int inttext = icalproperty_get_class(p);
1251 if (inttext == ICAL_CLASS_PUBLIC ) { 1251 if (inttext == ICAL_CLASS_PUBLIC ) {
1252 incidence->setSecrecy(Incidence::SecrecyPublic); 1252 incidence->setSecrecy(Incidence::SecrecyPublic);
1253 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) { 1253 } else if (inttext == ICAL_CLASS_CONFIDENTIAL ) {
1254 incidence->setSecrecy(Incidence::SecrecyConfidential); 1254 incidence->setSecrecy(Incidence::SecrecyConfidential);
1255 } else { 1255 } else {
1256 incidence->setSecrecy(Incidence::SecrecyPrivate); 1256 incidence->setSecrecy(Incidence::SecrecyPrivate);
1257 } 1257 }
1258 } 1258 }
1259 break; 1259 break;
1260 1260
1261 case ICAL_ATTACH_PROPERTY: // attachments 1261 case ICAL_ATTACH_PROPERTY: // attachments
1262 incidence->addAttachment(readAttachment(p)); 1262 incidence->addAttachment(readAttachment(p));
1263 break; 1263 break;
1264 1264
1265 default: 1265 default:
1266// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1266// kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1267// << endl; 1267// << endl;
1268 break; 1268 break;
1269 } 1269 }
1270 1270
1271 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1271 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1272 } 1272 }
1273 if ( readrec ) { 1273 if ( readrec ) {
1274 readRecurrenceRule(rectype,incidence); 1274 readRecurrenceRule(rectype,incidence);
1275 } 1275 }
1276 // kpilot stuff 1276 // kpilot stuff
1277// TODO: move this application-specific code to kpilot 1277// TODO: move this application-specific code to kpilot
1278 QString kp = incidence->nonKDECustomProperty("X-PILOTID"); 1278 QString kp = incidence->nonKDECustomProperty("X-PILOTID");
1279 if (!kp.isNull()) { 1279 if (!kp.isNull()) {
1280 incidence->setPilotId(kp.toInt()); 1280 incidence->setPilotId(kp.toInt());
1281 } 1281 }
1282 kp = incidence->nonKDECustomProperty("X-PILOTSTAT"); 1282 kp = incidence->nonKDECustomProperty("X-PILOTSTAT");
1283 if (!kp.isNull()) { 1283 if (!kp.isNull()) {
1284 incidence->setSyncStatus(kp.toInt()); 1284 incidence->setSyncStatus(kp.toInt());
1285 } 1285 }
1286 kp = incidence->nonKDECustomProperty("X-ZAURUSID"); 1286 kp = incidence->nonKDECustomProperty("X-ZAURUSID");
1287 if (!kp.isNull()) { 1287 if (!kp.isNull()) {
1288 incidence->setZaurusId(kp.toInt()); 1288 incidence->setZaurusId(kp.toInt());
1289 } 1289 }
1290 1290
1291 kp = incidence->nonKDECustomProperty("X-ZAURUSUID"); 1291 kp = incidence->nonKDECustomProperty("X-ZAURUSUID");
1292 if (!kp.isNull()) { 1292 if (!kp.isNull()) {
1293 incidence->setZaurusUid(kp.toInt()); 1293 incidence->setZaurusUid(kp.toInt());
1294 } 1294 }
1295 1295
1296 kp = incidence->nonKDECustomProperty("X-ZAURUSSTAT"); 1296 kp = incidence->nonKDECustomProperty("X-ZAURUSSTAT");
1297 if (!kp.isNull()) { 1297 if (!kp.isNull()) {
1298 incidence->setZaurusStat(kp.toInt()); 1298 incidence->setZaurusStat(kp.toInt());
1299 } 1299 }
1300 1300
1301 // Cancel backwards compatibility mode for subsequent changes by the application 1301 // Cancel backwards compatibility mode for subsequent changes by the application
1302 incidence->recurrence()->setCompatVersion(); 1302 incidence->recurrence()->setCompatVersion();
1303 1303
1304 // add categories 1304 // add categories
1305 incidence->setCategories(categories); 1305 incidence->setCategories(categories);
1306 1306
1307 // iterate through all alarms 1307 // iterate through all alarms
1308 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT); 1308 for (icalcomponent *alarm = icalcomponent_get_first_component(parent,ICAL_VALARM_COMPONENT);
1309 alarm; 1309 alarm;
1310 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) { 1310 alarm = icalcomponent_get_next_component(parent,ICAL_VALARM_COMPONENT)) {
1311 readAlarm(alarm,incidence); 1311 readAlarm(alarm,incidence);
1312 } 1312 }
1313} 1313}
1314 1314
1315void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase) 1315void ICalFormatImpl::readIncidenceBase(icalcomponent *parent,IncidenceBase *incidenceBase)
1316{ 1316{
1317 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1317 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1318 1318
1319 while (p) { 1319 while (p) {
1320 icalproperty_kind kind = icalproperty_isa(p); 1320 icalproperty_kind kind = icalproperty_isa(p);
1321 switch (kind) { 1321 switch (kind) {
1322 1322
1323 case ICAL_UID_PROPERTY: // unique id 1323 case ICAL_UID_PROPERTY: // unique id
1324 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p))); 1324 incidenceBase->setUid(QString::fromUtf8(icalproperty_get_uid(p)));
1325 break; 1325 break;
1326 1326
1327 case ICAL_ORGANIZER_PROPERTY: // organizer 1327 case ICAL_ORGANIZER_PROPERTY: // organizer
1328 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p))); 1328 incidenceBase->setOrganizer(QString::fromUtf8(icalproperty_get_organizer(p)));
1329 break; 1329 break;
1330 1330
1331 case ICAL_ATTENDEE_PROPERTY: // attendee 1331 case ICAL_ATTENDEE_PROPERTY: // attendee
1332 incidenceBase->addAttendee(readAttendee(p)); 1332 incidenceBase->addAttendee(readAttendee(p));
1333 break; 1333 break;
1334 1334
1335 default: 1335 default:
1336 break; 1336 break;
1337 } 1337 }
1338 1338
1339 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY); 1339 p = icalcomponent_get_next_property(parent,ICAL_ANY_PROPERTY);
1340 } 1340 }
1341 1341
1342 // custom properties 1342 // custom properties
1343 readCustomProperties(parent, incidenceBase); 1343 readCustomProperties(parent, incidenceBase);
1344} 1344}
1345 1345
1346void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties) 1346void ICalFormatImpl::readCustomProperties(icalcomponent *parent,CustomProperties *properties)
1347{ 1347{
1348 QMap<QCString, QString> customProperties; 1348 QMap<QCString, QString> customProperties;
1349 1349
1350 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY); 1350 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_X_PROPERTY);
1351 1351
1352 while (p) { 1352 while (p) {
1353 QString value = QString::fromUtf8(icalproperty_get_x(p)); 1353 QString value = QString::fromUtf8(icalproperty_get_x(p));
1354 customProperties[icalproperty_get_x_name(p)] = value; 1354 customProperties[icalproperty_get_x_name(p)] = value;
1355 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) ); 1355 //qDebug("ICalFormatImpl::readCustomProperties %s %s",value.latin1(), icalproperty_get_x_name(p) );
1356 1356
1357 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY); 1357 p = icalcomponent_get_next_property(parent,ICAL_X_PROPERTY);
1358 } 1358 }
1359 1359
1360 properties->setCustomProperties(customProperties); 1360 properties->setCustomProperties(customProperties);
1361} 1361}
1362 1362
1363void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence) 1363void ICalFormatImpl::readRecurrenceRule(struct icalrecurrencetype rrule,Incidence *incidence)
1364{ 1364{
1365// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl; 1365// kdDebug(5800) << "Read recurrence for " << incidence->summary() << endl;
1366 1366
1367 Recurrence *recur = incidence->recurrence(); 1367 Recurrence *recur = incidence->recurrence();
1368 recur->setCompatVersion(mCalendarVersion); 1368 recur->setCompatVersion(mCalendarVersion);
1369 recur->unsetRecurs(); 1369 recur->unsetRecurs();
1370 1370
1371 struct icalrecurrencetype r = rrule; 1371 struct icalrecurrencetype r = rrule;
1372 1372
1373 dumpIcalRecurrence(r); 1373 dumpIcalRecurrence(r);
1374 readRecurrence( r, recur, incidence); 1374 readRecurrence( r, recur, incidence);
1375} 1375}
1376 1376
1377void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence) 1377void ICalFormatImpl::readRecurrence( const struct icalrecurrencetype &r, Recurrence* recur, Incidence *incidence)
1378{ 1378{
1379 int wkst; 1379 int wkst;
1380 int index = 0; 1380 int index = 0;
1381 short day = 0; 1381 short day = 0;
1382 QBitArray qba(7); 1382 QBitArray qba(7);
1383 int frequ = r.freq; 1383 int frequ = r.freq;
1384 int interv = r.interval; 1384 int interv = r.interval;
1385 // preprocessing for odd recurrence definitions 1385 // preprocessing for odd recurrence definitions
1386 1386
1387 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) { 1387 if ( r.freq == ICAL_MONTHLY_RECURRENCE ) {
1388 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1388 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1389 interv = 12; 1389 interv = 12;
1390 } 1390 }
1391 } 1391 }
1392 if ( r.freq == ICAL_YEARLY_RECURRENCE ) { 1392 if ( r.freq == ICAL_YEARLY_RECURRENCE ) {
1393 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1393 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX && r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1394 frequ = ICAL_MONTHLY_RECURRENCE; 1394 frequ = ICAL_MONTHLY_RECURRENCE;
1395 interv = 12; 1395 interv = 12* r.interval;
1396 } 1396 }
1397 } 1397 }
1398 1398
1399 switch (frequ) { 1399 switch (frequ) {
1400 case ICAL_MINUTELY_RECURRENCE: 1400 case ICAL_MINUTELY_RECURRENCE:
1401 if (!icaltime_is_null_time(r.until)) { 1401 if (!icaltime_is_null_time(r.until)) {
1402 recur->setMinutely(interv,readICalDateTime(r.until)); 1402 recur->setMinutely(interv,readICalDateTime(r.until));
1403 } else { 1403 } else {
1404 if (r.count == 0) 1404 if (r.count == 0)
1405 recur->setMinutely(interv,-1); 1405 recur->setMinutely(interv,-1);
1406 else 1406 else
1407 recur->setMinutely(interv,r.count); 1407 recur->setMinutely(interv,r.count);
1408 } 1408 }
1409 break; 1409 break;
1410 case ICAL_HOURLY_RECURRENCE: 1410 case ICAL_HOURLY_RECURRENCE:
1411 if (!icaltime_is_null_time(r.until)) { 1411 if (!icaltime_is_null_time(r.until)) {
1412 recur->setHourly(interv,readICalDateTime(r.until)); 1412 recur->setHourly(interv,readICalDateTime(r.until));
1413 } else { 1413 } else {
1414 if (r.count == 0) 1414 if (r.count == 0)
1415 recur->setHourly(interv,-1); 1415 recur->setHourly(interv,-1);
1416 else 1416 else
1417 recur->setHourly(interv,r.count); 1417 recur->setHourly(interv,r.count);
1418 } 1418 }
1419 break; 1419 break;
1420 case ICAL_DAILY_RECURRENCE: 1420 case ICAL_DAILY_RECURRENCE:
1421 if (!icaltime_is_null_time(r.until)) { 1421 if (!icaltime_is_null_time(r.until)) {
1422 recur->setDaily(interv,readICalDate(r.until)); 1422 recur->setDaily(interv,readICalDate(r.until));
1423 } else { 1423 } else {
1424 if (r.count == 0) 1424 if (r.count == 0)
1425 recur->setDaily(interv,-1); 1425 recur->setDaily(interv,-1);
1426 else 1426 else
1427 recur->setDaily(interv,r.count); 1427 recur->setDaily(interv,r.count);
1428 } 1428 }
1429 break; 1429 break;
1430 case ICAL_WEEKLY_RECURRENCE: 1430 case ICAL_WEEKLY_RECURRENCE:
1431 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl; 1431 // kdDebug(5800) << "WEEKLY_RECURRENCE" << endl;
1432 wkst = (r.week_start + 5)%7 + 1; 1432 wkst = (r.week_start + 5)%7 + 1;
1433 if (!icaltime_is_null_time(r.until)) { 1433 if (!icaltime_is_null_time(r.until)) {
1434 recur->setWeekly(interv,qba,readICalDate(r.until),wkst); 1434 recur->setWeekly(interv,qba,readICalDate(r.until),wkst);
1435 } else { 1435 } else {
1436 if (r.count == 0) 1436 if (r.count == 0)
1437 recur->setWeekly(interv,qba,-1,wkst); 1437 recur->setWeekly(interv,qba,-1,wkst);
1438 else 1438 else
1439 recur->setWeekly(interv,qba,r.count,wkst); 1439 recur->setWeekly(interv,qba,r.count,wkst);
1440 } 1440 }
1441 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) { 1441 if ( r.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX) {
1442 int wday = incidence->dtStart().date().dayOfWeek ()-1; 1442 int wday = incidence->dtStart().date().dayOfWeek ()-1;
1443 //qDebug("weekly error found "); 1443 //qDebug("weekly error found ");
1444 qba.setBit(wday); 1444 qba.setBit(wday);
1445 } else { 1445 } else {
1446 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1446 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1447 // kdDebug(5800) << " " << day << endl; 1447 // kdDebug(5800) << " " << day << endl;
1448 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1448 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1449 } 1449 }
1450 } 1450 }
1451 break; 1451 break;
1452 case ICAL_MONTHLY_RECURRENCE: 1452 case ICAL_MONTHLY_RECURRENCE:
1453 1453
1454 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1454 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1455 if (!icaltime_is_null_time(r.until)) { 1455 if (!icaltime_is_null_time(r.until)) {
1456 recur->setMonthly(Recurrence::rMonthlyPos,interv, 1456 recur->setMonthly(Recurrence::rMonthlyPos,interv,
1457 readICalDate(r.until)); 1457 readICalDate(r.until));
1458 } else { 1458 } else {
1459 if (r.count == 0) 1459 if (r.count == 0)
1460 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1); 1460 recur->setMonthly(Recurrence::rMonthlyPos,interv,-1);
1461 else 1461 else
1462 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count); 1462 recur->setMonthly(Recurrence::rMonthlyPos,interv,r.count);
1463 } 1463 }
1464 bool useSetPos = false; 1464 bool useSetPos = false;
1465 short pos = 0; 1465 short pos = 0;
1466 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1466 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1467 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1467 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1468 pos = icalrecurrencetype_day_position(day); 1468 pos = icalrecurrencetype_day_position(day);
1469 if (pos) { 1469 if (pos) {
1470 day = icalrecurrencetype_day_day_of_week(day); 1470 day = icalrecurrencetype_day_day_of_week(day);
1471 QBitArray ba(7); // don't wipe qba 1471 QBitArray ba(7); // don't wipe qba
1472 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1472 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1473 recur->addMonthlyPos(pos,ba); 1473 recur->addMonthlyPos(pos,ba);
1474 } else { 1474 } else {
1475 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1475 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1476 useSetPos = true; 1476 useSetPos = true;
1477 } 1477 }
1478 } 1478 }
1479 if (useSetPos) { 1479 if (useSetPos) {
1480 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1480 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1481 recur->addMonthlyPos(r.by_set_pos[0],qba); 1481 recur->addMonthlyPos(r.by_set_pos[0],qba);
1482 } 1482 }
1483 } 1483 }
1484 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1484 } else if (r.by_month_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1485 if (!icaltime_is_null_time(r.until)) { 1485 if (!icaltime_is_null_time(r.until)) {
1486 recur->setMonthly(Recurrence::rMonthlyDay,interv, 1486 recur->setMonthly(Recurrence::rMonthlyDay,interv,
1487 readICalDate(r.until)); 1487 readICalDate(r.until));
1488 } else { 1488 } else {
1489 if (r.count == 0) 1489 if (r.count == 0)
1490 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1); 1490 recur->setMonthly(Recurrence::rMonthlyDay,interv,-1);
1491 else 1491 else
1492 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count); 1492 recur->setMonthly(Recurrence::rMonthlyDay,interv,r.count);
1493 } 1493 }
1494 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1494 while((day = r.by_month_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1495 // kdDebug(5800) << "----b " << day << endl; 1495 // kdDebug(5800) << "----b " << day << endl;
1496 recur->addMonthlyDay(day); 1496 recur->addMonthlyDay(day);
1497 } 1497 }
1498 } 1498 }
1499 break; 1499 break;
1500 case ICAL_YEARLY_RECURRENCE: 1500 case ICAL_YEARLY_RECURRENCE:
1501 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1501 if (r.by_year_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1502 qDebug(" YEARLY DAY OF YEAR");
1502 if (!icaltime_is_null_time(r.until)) { 1503 if (!icaltime_is_null_time(r.until)) {
1503 recur->setYearly(Recurrence::rYearlyDay,interv, 1504 recur->setYearly(Recurrence::rYearlyDay,interv,
1504 readICalDate(r.until)); 1505 readICalDate(r.until));
1505 } else { 1506 } else {
1506 if (r.count == 0) 1507 if (r.count == 0)
1507 recur->setYearly(Recurrence::rYearlyDay,interv,-1); 1508 recur->setYearly(Recurrence::rYearlyDay,interv,-1);
1508 else 1509 else
1509 recur->setYearly(Recurrence::rYearlyDay,interv,r.count); 1510 recur->setYearly(Recurrence::rYearlyDay,interv,r.count);
1510 } 1511 }
1511 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1512 while((day = r.by_year_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1512 recur->addYearlyNum(day); 1513 recur->addYearlyNum(day);
1513 } 1514 }
1514 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) { 1515 } else if ( true /*r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX*/) {
1515 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1516 if (r.by_day[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1517 qDebug("YEARLY POS NOT SUPPORTED BY GUI");
1516 if (!icaltime_is_null_time(r.until)) { 1518 if (!icaltime_is_null_time(r.until)) {
1517 recur->setYearly(Recurrence::rYearlyPos,interv, 1519 recur->setYearly(Recurrence::rYearlyPos,interv,
1518 readICalDate(r.until)); 1520 readICalDate(r.until));
1519 } else { 1521 } else {
1520 if (r.count == 0) 1522 if (r.count == 0)
1521 recur->setYearly(Recurrence::rYearlyPos,interv,-1); 1523 recur->setYearly(Recurrence::rYearlyPos,interv,-1);
1522 else 1524 else
1523 recur->setYearly(Recurrence::rYearlyPos,interv,r.count); 1525 recur->setYearly(Recurrence::rYearlyPos,interv,r.count);
1524 } 1526 }
1525 bool useSetPos = false; 1527 bool useSetPos = false;
1526 short pos = 0; 1528 short pos = 0;
1527 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1529 while((day = r.by_day[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1528 // kdDebug(5800) << "----a " << index << ": " << day << endl; 1530 // kdDebug(5800) << "----a " << index << ": " << day << endl;
1529 pos = icalrecurrencetype_day_position(day); 1531 pos = icalrecurrencetype_day_position(day);
1530 if (pos) { 1532 if (pos) {
1531 day = icalrecurrencetype_day_day_of_week(day); 1533 day = icalrecurrencetype_day_day_of_week(day);
1532 QBitArray ba(7); // don't wipe qba 1534 QBitArray ba(7); // don't wipe qba
1533 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1535 ba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1534 recur->addYearlyMonthPos(pos,ba); 1536 recur->addYearlyMonthPos(pos,ba);
1535 } else { 1537 } else {
1536 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0 1538 qba.setBit((day+5)%7); // convert from Sunday=1 to Monday=0
1537 useSetPos = true; 1539 useSetPos = true;
1538 } 1540 }
1539 } 1541 }
1540 if (useSetPos) { 1542 if (useSetPos) {
1541 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) { 1543 if (r.by_set_pos[0] != ICAL_RECURRENCE_ARRAY_MAX) {
1542 recur->addYearlyMonthPos(r.by_set_pos[0],qba); 1544 recur->addYearlyMonthPos(r.by_set_pos[0],qba);
1543 } 1545 }
1544 } 1546 }
1545 } else { 1547 } else {
1548 qDebug("YEARLY MONTH ");
1546 if (!icaltime_is_null_time(r.until)) { 1549 if (!icaltime_is_null_time(r.until)) {
1547 recur->setYearly(Recurrence::rYearlyMonth,interv, 1550 recur->setYearly(Recurrence::rYearlyMonth,interv,
1548 readICalDate(r.until)); 1551 readICalDate(r.until));
1549 } else { 1552 } else {
1550 if (r.count == 0) 1553 if (r.count == 0)
1551 recur->setYearly(Recurrence::rYearlyMonth,interv,-1); 1554 recur->setYearly(Recurrence::rYearlyMonth,interv,-1);
1552 else 1555 else
1553 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count); 1556 recur->setYearly(Recurrence::rYearlyMonth,interv,r.count);
1554 } 1557 }
1555 } 1558 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) {
1556 if ( r.by_month[0] != ICAL_RECURRENCE_ARRAY_MAX ) { 1559 index = 0;
1557 index = 0; 1560 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) {
1558 while((day = r.by_month[index++]) != ICAL_RECURRENCE_ARRAY_MAX) { 1561 recur->addYearlyNum(day);
1559 recur->addYearlyNum(day); 1562 }
1563 } else {
1564 recur->addYearlyNum(incidence->dtStart().date().month());
1560 } 1565 }
1561 } else {
1562 recur->addYearlyNum(incidence->dtStart().date().month());
1563 } 1566 }
1567
1564 } 1568 }
1565 break; 1569 break;
1566 default: 1570 default:
1567 ; 1571 ;
1568 break; 1572 break;
1569 } 1573 }
1570} 1574}
1571 1575
1572void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence) 1576void ICalFormatImpl::readAlarm(icalcomponent *alarm,Incidence *incidence)
1573{ 1577{
1574 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl; 1578 //kdDebug(5800) << "Read alarm for " << incidence->summary() << endl;
1575 1579
1576 Alarm* ialarm = incidence->newAlarm(); 1580 Alarm* ialarm = incidence->newAlarm();
1577 ialarm->setRepeatCount(0); 1581 ialarm->setRepeatCount(0);
1578 ialarm->setEnabled(true); 1582 ialarm->setEnabled(true);
1579 1583
1580 // Determine the alarm's action type 1584 // Determine the alarm's action type
1581 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY); 1585 icalproperty *p = icalcomponent_get_first_property(alarm,ICAL_ACTION_PROPERTY);
1582 if ( !p ) { 1586 if ( !p ) {
1583 return; 1587 return;
1584 } 1588 }
1585 1589
1586 icalproperty_action action = icalproperty_get_action(p); 1590 icalproperty_action action = icalproperty_get_action(p);
1587 Alarm::Type type = Alarm::Display; 1591 Alarm::Type type = Alarm::Display;
1588 switch ( action ) { 1592 switch ( action ) {
1589 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break; 1593 case ICAL_ACTION_DISPLAY: type = Alarm::Display; break;
1590 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break; 1594 case ICAL_ACTION_AUDIO: type = Alarm::Audio; break;
1591 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break; 1595 case ICAL_ACTION_PROCEDURE: type = Alarm::Procedure; break;
1592 case ICAL_ACTION_EMAIL: type = Alarm::Email; break; 1596 case ICAL_ACTION_EMAIL: type = Alarm::Email; break;
1593 default: 1597 default:
1594 ; 1598 ;
1595 return; 1599 return;
1596 } 1600 }
1597 ialarm->setType(type); 1601 ialarm->setType(type);
1598 1602
1599 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY); 1603 p = icalcomponent_get_first_property(alarm,ICAL_ANY_PROPERTY);
1600 while (p) { 1604 while (p) {
1601 icalproperty_kind kind = icalproperty_isa(p); 1605 icalproperty_kind kind = icalproperty_isa(p);
1602 1606
1603 switch (kind) { 1607 switch (kind) {
1604 case ICAL_TRIGGER_PROPERTY: { 1608 case ICAL_TRIGGER_PROPERTY: {
1605 icaltriggertype trigger = icalproperty_get_trigger(p); 1609 icaltriggertype trigger = icalproperty_get_trigger(p);
1606 if (icaltime_is_null_time(trigger.time)) { 1610 if (icaltime_is_null_time(trigger.time)) {
1607 if (icaldurationtype_is_null_duration(trigger.duration)) { 1611 if (icaldurationtype_is_null_duration(trigger.duration)) {
1608 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl; 1612 kdDebug(5800) << "ICalFormatImpl::readAlarm(): Trigger has no time and no duration." << endl;
1609 } else { 1613 } else {
1610 Duration duration = icaldurationtype_as_int( trigger.duration ); 1614 Duration duration = icaldurationtype_as_int( trigger.duration );
1611 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER); 1615 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_RELATED_PARAMETER);
1612 if (param && icalparameter_get_related(param) == ICAL_RELATED_END) 1616 if (param && icalparameter_get_related(param) == ICAL_RELATED_END)
1613 ialarm->setEndOffset(duration); 1617 ialarm->setEndOffset(duration);
1614 else 1618 else
1615 ialarm->setStartOffset(duration); 1619 ialarm->setStartOffset(duration);
1616 } 1620 }
1617 } else { 1621 } else {
1618 ialarm->setTime(readICalDateTime(trigger.time)); 1622 ialarm->setTime(readICalDateTime(trigger.time));
1619 } 1623 }
1620 break; 1624 break;
1621 } 1625 }
1622 case ICAL_DURATION_PROPERTY: { 1626 case ICAL_DURATION_PROPERTY: {
1623 icaldurationtype duration = icalproperty_get_duration(p); 1627 icaldurationtype duration = icalproperty_get_duration(p);
1624 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60); 1628 ialarm->setSnoozeTime(icaldurationtype_as_int(duration)/60);
1625 break; 1629 break;
1626 } 1630 }
1627 case ICAL_REPEAT_PROPERTY: 1631 case ICAL_REPEAT_PROPERTY:
1628 ialarm->setRepeatCount(icalproperty_get_repeat(p)); 1632 ialarm->setRepeatCount(icalproperty_get_repeat(p));
1629 break; 1633 break;
1630 1634
1631 // Only in DISPLAY and EMAIL and PROCEDURE alarms 1635 // Only in DISPLAY and EMAIL and PROCEDURE alarms
1632 case ICAL_DESCRIPTION_PROPERTY: { 1636 case ICAL_DESCRIPTION_PROPERTY: {
1633 QString description = QString::fromUtf8(icalproperty_get_description(p)); 1637 QString description = QString::fromUtf8(icalproperty_get_description(p));
1634 switch ( action ) { 1638 switch ( action ) {
1635 case ICAL_ACTION_DISPLAY: 1639 case ICAL_ACTION_DISPLAY:
1636 ialarm->setText( description ); 1640 ialarm->setText( description );
1637 break; 1641 break;
1638 case ICAL_ACTION_PROCEDURE: 1642 case ICAL_ACTION_PROCEDURE:
1639 ialarm->setProgramArguments( description ); 1643 ialarm->setProgramArguments( description );
1640 break; 1644 break;
1641 case ICAL_ACTION_EMAIL: 1645 case ICAL_ACTION_EMAIL:
1642 ialarm->setMailText( description ); 1646 ialarm->setMailText( description );
1643 break; 1647 break;
1644 default: 1648 default:
1645 break; 1649 break;
1646 } 1650 }
1647 break; 1651 break;
1648 } 1652 }
1649 // Only in EMAIL alarm 1653 // Only in EMAIL alarm
1650 case ICAL_SUMMARY_PROPERTY: 1654 case ICAL_SUMMARY_PROPERTY:
1651 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p))); 1655 ialarm->setMailSubject(QString::fromUtf8(icalproperty_get_summary(p)));
1652 break; 1656 break;
1653 1657
1654 // Only in EMAIL alarm 1658 // Only in EMAIL alarm
1655 case ICAL_ATTENDEE_PROPERTY: { 1659 case ICAL_ATTENDEE_PROPERTY: {
1656 QString email = QString::fromUtf8(icalproperty_get_attendee(p)); 1660 QString email = QString::fromUtf8(icalproperty_get_attendee(p));
1657 QString name; 1661 QString name;
1658 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER); 1662 icalparameter *param = icalproperty_get_first_parameter(p,ICAL_CN_PARAMETER);
1659 if (param) { 1663 if (param) {
1660 name = QString::fromUtf8(icalparameter_get_cn(param)); 1664 name = QString::fromUtf8(icalparameter_get_cn(param));
1661 } 1665 }
1662 ialarm->addMailAddress(Person(name, email)); 1666 ialarm->addMailAddress(Person(name, email));
1663 break; 1667 break;
1664 } 1668 }
1665 // Only in AUDIO and EMAIL and PROCEDURE alarms 1669 // Only in AUDIO and EMAIL and PROCEDURE alarms
1666 case ICAL_ATTACH_PROPERTY: { 1670 case ICAL_ATTACH_PROPERTY: {
1667 icalattach *attach = icalproperty_get_attach(p); 1671 icalattach *attach = icalproperty_get_attach(p);
1668 QString url = QFile::decodeName(icalattach_get_url(attach)); 1672 QString url = QFile::decodeName(icalattach_get_url(attach));
1669 switch ( action ) { 1673 switch ( action ) {
1670 case ICAL_ACTION_AUDIO: 1674 case ICAL_ACTION_AUDIO:
1671 ialarm->setAudioFile( url ); 1675 ialarm->setAudioFile( url );
1672 break; 1676 break;
1673 case ICAL_ACTION_PROCEDURE: 1677 case ICAL_ACTION_PROCEDURE:
1674 ialarm->setProgramFile( url ); 1678 ialarm->setProgramFile( url );
1675 break; 1679 break;
1676 case ICAL_ACTION_EMAIL: 1680 case ICAL_ACTION_EMAIL:
1677 ialarm->addMailAttachment( url ); 1681 ialarm->addMailAttachment( url );
1678 break; 1682 break;
1679 default: 1683 default:
1680 break; 1684 break;
1681 } 1685 }
1682 break; 1686 break;
1683 } 1687 }
1684 default: 1688 default:
1685 break; 1689 break;
1686 } 1690 }
1687 1691
1688 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY); 1692 p = icalcomponent_get_next_property(alarm,ICAL_ANY_PROPERTY);
1689 } 1693 }
1690 1694
1691 // custom properties 1695 // custom properties
1692 readCustomProperties(alarm, ialarm); 1696 readCustomProperties(alarm, ialarm);
1693 1697
1694 // TODO: check for consistency of alarm properties 1698 // TODO: check for consistency of alarm properties
1695} 1699}
1696 1700
1697icaltimetype ICalFormatImpl::writeICalDate(const QDate &date) 1701icaltimetype ICalFormatImpl::writeICalDate(const QDate &date)
1698{ 1702{
1699 icaltimetype t; 1703 icaltimetype t;
1700 1704
1701 t.year = date.year(); 1705 t.year = date.year();
1702 t.month = date.month(); 1706 t.month = date.month();
1703 t.day = date.day(); 1707 t.day = date.day();
1704 1708
1705 t.hour = 0; 1709 t.hour = 0;
1706 t.minute = 0; 1710 t.minute = 0;
1707 t.second = 0; 1711 t.second = 0;
1708 1712
1709 t.is_date = 1; 1713 t.is_date = 1;
1710 1714
1711 t.is_utc = 0; 1715 t.is_utc = 0;
1712 1716
1713 t.zone = 0; 1717 t.zone = 0;
1714 1718
1715 return t; 1719 return t;
1716} 1720}
1717 1721
1718icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt ) 1722icaltimetype ICalFormatImpl::writeICalDateTime(const QDateTime &dt )
1719{ 1723{
1720 icaltimetype t; 1724 icaltimetype t;
1721 t.is_date = 0; 1725 t.is_date = 0;
1722 t.zone = 0; 1726 t.zone = 0;
1723 QDateTime datetime; 1727 QDateTime datetime;
1724 if ( mParent->utc() ) { 1728 if ( mParent->utc() ) {
1725 int offset = KGlobal::locale()->localTimeOffset( dt ); 1729 int offset = KGlobal::locale()->localTimeOffset( dt );
1726 datetime = dt.addSecs ( -offset*60); 1730 datetime = dt.addSecs ( -offset*60);
1727 t.is_utc = 1; 1731 t.is_utc = 1;
1728 } 1732 }
1729 else { 1733 else {
1730 datetime = dt; 1734 datetime = dt;
1731 t.is_utc = 0; 1735 t.is_utc = 0;
1732 1736
1733 } 1737 }
1734 t.year = datetime.date().year(); 1738 t.year = datetime.date().year();
1735 t.month = datetime.date().month(); 1739 t.month = datetime.date().month();
1736 t.day = datetime.date().day(); 1740 t.day = datetime.date().day();
1737 1741
1738 t.hour = datetime.time().hour(); 1742 t.hour = datetime.time().hour();
1739 t.minute = datetime.time().minute(); 1743 t.minute = datetime.time().minute();
1740 t.second = datetime.time().second(); 1744 t.second = datetime.time().second();
1741 1745
1742 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1746 //qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1743 1747
1744// if ( mParent->utc() ) { 1748// if ( mParent->utc() ) {
1745// datetime = KGlobal::locale()->localTime( dt ); 1749// datetime = KGlobal::locale()->localTime( dt );
1746// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() ); 1750// qDebug("*** time %s localtime %s ",dt .toString().latin1() ,datetime .toString().latin1() );
1747// if (mParent->timeZoneId().isEmpty()) 1751// if (mParent->timeZoneId().isEmpty())
1748// t = icaltime_as_utc(t, 0); 1752// t = icaltime_as_utc(t, 0);
1749// else 1753// else
1750// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit()); 1754// t = icaltime_as_utc(t,mParent->timeZoneId().local8Bit());
1751// } 1755// }
1752 1756
1753 return t; 1757 return t;
1754} 1758}
1755 1759