summaryrefslogtreecommitdiffabout
path: root/libkcal
Unidiff
Diffstat (limited to 'libkcal') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/icalformatimpl.cpp20
-rw-r--r--libkcal/recurrence.cpp17
-rw-r--r--libkcal/recurrence.h6
3 files changed, 30 insertions, 13 deletions
diff --git a/libkcal/icalformatimpl.cpp b/libkcal/icalformatimpl.cpp
index 32a1337..964ffe3 100644
--- a/libkcal/icalformatimpl.cpp
+++ b/libkcal/icalformatimpl.cpp
@@ -1011,937 +1011,941 @@ FreeBusy *ICalFormatImpl::readFreeBusy(icalcomponent *vfreebusy)
1011 break; 1011 break;
1012 1012
1013 default: 1013 default:
1014 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind 1014 kdDebug(5800) << "ICALFormat::readIncidence(): Unknown property: " << kind
1015 << endl; 1015 << endl;
1016 break; 1016 break;
1017 } 1017 }
1018 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY); 1018 p = icalcomponent_get_next_property(vfreebusy,ICAL_ANY_PROPERTY);
1019 } 1019 }
1020 1020
1021 return freebusy; 1021 return freebusy;
1022} 1022}
1023 1023
1024Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal) 1024Journal *ICalFormatImpl::readJournal(icalcomponent *vjournal)
1025{ 1025{
1026 Journal *journal = new Journal; 1026 Journal *journal = new Journal;
1027 1027
1028 readIncidence(vjournal,journal); 1028 readIncidence(vjournal,journal);
1029 1029
1030 return journal; 1030 return journal;
1031} 1031}
1032 1032
1033Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee) 1033Attendee *ICalFormatImpl::readAttendee(icalproperty *attendee)
1034{ 1034{
1035 icalparameter *p = 0; 1035 icalparameter *p = 0;
1036 1036
1037 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee)); 1037 QString email = QString::fromUtf8(icalproperty_get_attendee(attendee));
1038 1038
1039 QString name; 1039 QString name;
1040 QString uid = QString::null; 1040 QString uid = QString::null;
1041 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER); 1041 p = icalproperty_get_first_parameter(attendee,ICAL_CN_PARAMETER);
1042 if (p) { 1042 if (p) {
1043 name = QString::fromUtf8(icalparameter_get_cn(p)); 1043 name = QString::fromUtf8(icalparameter_get_cn(p));
1044 } else { 1044 } else {
1045 } 1045 }
1046 1046
1047 bool rsvp=false; 1047 bool rsvp=false;
1048 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER); 1048 p = icalproperty_get_first_parameter(attendee,ICAL_RSVP_PARAMETER);
1049 if (p) { 1049 if (p) {
1050 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p); 1050 icalparameter_rsvp rsvpParameter = icalparameter_get_rsvp(p);
1051 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true; 1051 if (rsvpParameter == ICAL_RSVP_TRUE) rsvp = true;
1052 } 1052 }
1053 1053
1054 Attendee::PartStat status = Attendee::NeedsAction; 1054 Attendee::PartStat status = Attendee::NeedsAction;
1055 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER); 1055 p = icalproperty_get_first_parameter(attendee,ICAL_PARTSTAT_PARAMETER);
1056 if (p) { 1056 if (p) {
1057 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p); 1057 icalparameter_partstat partStatParameter = icalparameter_get_partstat(p);
1058 switch(partStatParameter) { 1058 switch(partStatParameter) {
1059 default: 1059 default:
1060 case ICAL_PARTSTAT_NEEDSACTION: 1060 case ICAL_PARTSTAT_NEEDSACTION:
1061 status = Attendee::NeedsAction; 1061 status = Attendee::NeedsAction;
1062 break; 1062 break;
1063 case ICAL_PARTSTAT_ACCEPTED: 1063 case ICAL_PARTSTAT_ACCEPTED:
1064 status = Attendee::Accepted; 1064 status = Attendee::Accepted;
1065 break; 1065 break;
1066 case ICAL_PARTSTAT_DECLINED: 1066 case ICAL_PARTSTAT_DECLINED:
1067 status = Attendee::Declined; 1067 status = Attendee::Declined;
1068 break; 1068 break;
1069 case ICAL_PARTSTAT_TENTATIVE: 1069 case ICAL_PARTSTAT_TENTATIVE:
1070 status = Attendee::Tentative; 1070 status = Attendee::Tentative;
1071 break; 1071 break;
1072 case ICAL_PARTSTAT_DELEGATED: 1072 case ICAL_PARTSTAT_DELEGATED:
1073 status = Attendee::Delegated; 1073 status = Attendee::Delegated;
1074 break; 1074 break;
1075 case ICAL_PARTSTAT_COMPLETED: 1075 case ICAL_PARTSTAT_COMPLETED:
1076 status = Attendee::Completed; 1076 status = Attendee::Completed;
1077 break; 1077 break;
1078 case ICAL_PARTSTAT_INPROCESS: 1078 case ICAL_PARTSTAT_INPROCESS:
1079 status = Attendee::InProcess; 1079 status = Attendee::InProcess;
1080 break; 1080 break;
1081 } 1081 }
1082 } 1082 }
1083 1083
1084 Attendee::Role role = Attendee::ReqParticipant; 1084 Attendee::Role role = Attendee::ReqParticipant;
1085 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER); 1085 p = icalproperty_get_first_parameter(attendee,ICAL_ROLE_PARAMETER);
1086 if (p) { 1086 if (p) {
1087 icalparameter_role roleParameter = icalparameter_get_role(p); 1087 icalparameter_role roleParameter = icalparameter_get_role(p);
1088 switch(roleParameter) { 1088 switch(roleParameter) {
1089 case ICAL_ROLE_CHAIR: 1089 case ICAL_ROLE_CHAIR:
1090 role = Attendee::Chair; 1090 role = Attendee::Chair;
1091 break; 1091 break;
1092 default: 1092 default:
1093 case ICAL_ROLE_REQPARTICIPANT: 1093 case ICAL_ROLE_REQPARTICIPANT:
1094 role = Attendee::ReqParticipant; 1094 role = Attendee::ReqParticipant;
1095 break; 1095 break;
1096 case ICAL_ROLE_OPTPARTICIPANT: 1096 case ICAL_ROLE_OPTPARTICIPANT:
1097 role = Attendee::OptParticipant; 1097 role = Attendee::OptParticipant;
1098 break; 1098 break;
1099 case ICAL_ROLE_NONPARTICIPANT: 1099 case ICAL_ROLE_NONPARTICIPANT:
1100 role = Attendee::NonParticipant; 1100 role = Attendee::NonParticipant;
1101 break; 1101 break;
1102 } 1102 }
1103 } 1103 }
1104 1104
1105 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER); 1105 p = icalproperty_get_first_parameter(attendee,ICAL_X_PARAMETER);
1106 uid = icalparameter_get_xvalue(p); 1106 uid = icalparameter_get_xvalue(p);
1107 // This should be added, but there seems to be a libical bug here. 1107 // This should be added, but there seems to be a libical bug here.
1108 /*while (p) { 1108 /*while (p) {
1109 // if (icalparameter_get_xname(p) == "X-UID") { 1109 // if (icalparameter_get_xname(p) == "X-UID") {
1110 uid = icalparameter_get_xvalue(p); 1110 uid = icalparameter_get_xvalue(p);
1111 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER); 1111 p = icalproperty_get_next_parameter(attendee,ICAL_X_PARAMETER);
1112 } */ 1112 } */
1113 1113
1114 return new Attendee( name, email, rsvp, status, role, uid ); 1114 return new Attendee( name, email, rsvp, status, role, uid );
1115} 1115}
1116 1116
1117Attachment *ICalFormatImpl::readAttachment(icalproperty *attach) 1117Attachment *ICalFormatImpl::readAttachment(icalproperty *attach)
1118{ 1118{
1119 icalattach *a = icalproperty_get_attach(attach); 1119 icalattach *a = icalproperty_get_attach(attach);
1120 icalparameter_value v = ICAL_VALUE_NONE; 1120 icalparameter_value v = ICAL_VALUE_NONE;
1121 icalparameter_encoding e = ICAL_ENCODING_NONE; 1121 icalparameter_encoding e = ICAL_ENCODING_NONE;
1122 1122
1123 Attachment *attachment = 0; 1123 Attachment *attachment = 0;
1124 /* 1124 /*
1125 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER); 1125 icalparameter *vp = icalproperty_get_first_parameter(attach, ICAL_VALUE_PARAMETER);
1126 if (vp) 1126 if (vp)
1127 v = icalparameter_get_value(vp); 1127 v = icalparameter_get_value(vp);
1128 1128
1129 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER); 1129 icalparameter *ep = icalproperty_get_first_parameter(attach, ICAL_ENCODING_PARAMETER);
1130 if (ep) 1130 if (ep)
1131 e = icalparameter_get_encoding(ep); 1131 e = icalparameter_get_encoding(ep);
1132 */ 1132 */
1133 int isurl = icalattach_get_is_url (a); 1133 int isurl = icalattach_get_is_url (a);
1134 if (isurl == 0) 1134 if (isurl == 0)
1135 attachment = new Attachment((const char*)icalattach_get_data(a)); 1135 attachment = new Attachment((const char*)icalattach_get_data(a));
1136 else { 1136 else {
1137 attachment = new Attachment(QString(icalattach_get_url(a))); 1137 attachment = new Attachment(QString(icalattach_get_url(a)));
1138 } 1138 }
1139 1139
1140 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER); 1140 icalparameter *p = icalproperty_get_first_parameter(attach, ICAL_FMTTYPE_PARAMETER);
1141 if (p) 1141 if (p)
1142 attachment->setMimeType(QString(icalparameter_get_fmttype(p))); 1142 attachment->setMimeType(QString(icalparameter_get_fmttype(p)));
1143 1143
1144 return attachment; 1144 return attachment;
1145} 1145}
1146#include <qtextcodec.h> 1146#include <qtextcodec.h>
1147void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence) 1147void ICalFormatImpl::readIncidence(icalcomponent *parent,Incidence *incidence)
1148{ 1148{
1149 readIncidenceBase(parent,incidence); 1149 readIncidenceBase(parent,incidence);
1150 1150
1151 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY); 1151 icalproperty *p = icalcomponent_get_first_property(parent,ICAL_ANY_PROPERTY);
1152 bool readrec = false; 1152 bool readrec = false;
1153 const char *text; 1153 const char *text;
1154 int intvalue; 1154 int intvalue;
1155 icaltimetype icaltime; 1155 icaltimetype icaltime;
1156 icaldurationtype icalduration; 1156 icaldurationtype icalduration;
1157 struct icalrecurrencetype rectype; 1157 struct icalrecurrencetype rectype;
1158 QStringList categories; 1158 QStringList categories;
1159 1159
1160 while (p) { 1160 while (p) {
1161 icalproperty_kind kind = icalproperty_isa(p); 1161 icalproperty_kind kind = icalproperty_isa(p);
1162 switch (kind) { 1162 switch (kind) {
1163 1163
1164 case ICAL_CREATED_PROPERTY: 1164 case ICAL_CREATED_PROPERTY:
1165 icaltime = icalproperty_get_created(p); 1165 icaltime = icalproperty_get_created(p);
1166 incidence->setCreated(readICalDateTime(icaltime)); 1166 incidence->setCreated(readICalDateTime(icaltime));
1167 break; 1167 break;
1168 1168
1169 case ICAL_SEQUENCE_PROPERTY: // sequence 1169 case ICAL_SEQUENCE_PROPERTY: // sequence
1170 intvalue = icalproperty_get_sequence(p); 1170 intvalue = icalproperty_get_sequence(p);
1171 incidence->setRevision(intvalue); 1171 incidence->setRevision(intvalue);
1172 break; 1172 break;
1173 1173
1174 case ICAL_LASTMODIFIED_PROPERTY: // last modification date 1174 case ICAL_LASTMODIFIED_PROPERTY: // last modification date
1175 icaltime = icalproperty_get_lastmodified(p); 1175 icaltime = icalproperty_get_lastmodified(p);
1176 incidence->setLastModified(readICalDateTime(icaltime)); 1176 incidence->setLastModified(readICalDateTime(icaltime));
1177 break; 1177 break;
1178 1178
1179 case ICAL_DTSTART_PROPERTY: // start date and time 1179 case ICAL_DTSTART_PROPERTY: // start date and time
1180 icaltime = icalproperty_get_dtstart(p); 1180 icaltime = icalproperty_get_dtstart(p);
1181 if (icaltime.is_date) { 1181 if (icaltime.is_date) {
1182 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0))); 1182 incidence->setDtStart(QDateTime(readICalDate(icaltime),QTime(0,0,0)));
1183 incidence->setFloats(true); 1183 incidence->setFloats(true);
1184 } else { 1184 } else {
1185 incidence->setDtStart(readICalDateTime(icaltime)); 1185 incidence->setDtStart(readICalDateTime(icaltime));
1186 } 1186 }
1187 break; 1187 break;
1188 1188
1189 case ICAL_DURATION_PROPERTY: // start date and time 1189 case ICAL_DURATION_PROPERTY: // start date and time
1190 icalduration = icalproperty_get_duration(p); 1190 icalduration = icalproperty_get_duration(p);
1191 incidence->setDuration(readICalDuration(icalduration)); 1191 incidence->setDuration(readICalDuration(icalduration));
1192 break; 1192 break;
1193 1193
1194 case ICAL_DESCRIPTION_PROPERTY: // description 1194 case ICAL_DESCRIPTION_PROPERTY: // description
1195 text = icalproperty_get_description(p); 1195 text = icalproperty_get_description(p);
1196 incidence->setDescription(QString::fromUtf8(text)); 1196 incidence->setDescription(QString::fromUtf8(text));
1197 break; 1197 break;
1198 1198
1199 case ICAL_SUMMARY_PROPERTY: // summary 1199 case ICAL_SUMMARY_PROPERTY: // summary
1200 { 1200 {
1201 text = icalproperty_get_summary(p); 1201 text = icalproperty_get_summary(p);
1202 incidence->setSummary(QString::fromUtf8(text)); 1202 incidence->setSummary(QString::fromUtf8(text));
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
1756QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t) 1760QDateTime ICalFormatImpl::readICalDateTime(icaltimetype t)
1757{ 1761{
1758 QDateTime dt (QDate(t.year,t.month,t.day), 1762 QDateTime dt (QDate(t.year,t.month,t.day),
1759 QTime(t.hour,t.minute,t.second) ); 1763 QTime(t.hour,t.minute,t.second) );
1760 1764
1761 if (t.is_utc) { 1765 if (t.is_utc) {
1762 int offset = KGlobal::locale()->localTimeOffset( dt ); 1766 int offset = KGlobal::locale()->localTimeOffset( dt );
1763 dt = dt.addSecs ( offset*60); 1767 dt = dt.addSecs ( offset*60);
1764 } 1768 }
1765 1769
1766 return dt; 1770 return dt;
1767} 1771}
1768 1772
1769QDate ICalFormatImpl::readICalDate(icaltimetype t) 1773QDate ICalFormatImpl::readICalDate(icaltimetype t)
1770{ 1774{
1771 return QDate(t.year,t.month,t.day); 1775 return QDate(t.year,t.month,t.day);
1772} 1776}
1773 1777
1774icaldurationtype ICalFormatImpl::writeICalDuration(int seconds) 1778icaldurationtype ICalFormatImpl::writeICalDuration(int seconds)
1775{ 1779{
1776 icaldurationtype d; 1780 icaldurationtype d;
1777 1781
1778 d.weeks = seconds % gSecondsPerWeek; 1782 d.weeks = seconds % gSecondsPerWeek;
1779 seconds -= d.weeks * gSecondsPerWeek; 1783 seconds -= d.weeks * gSecondsPerWeek;
1780 d.days = seconds % gSecondsPerDay; 1784 d.days = seconds % gSecondsPerDay;
1781 seconds -= d.days * gSecondsPerDay; 1785 seconds -= d.days * gSecondsPerDay;
1782 d.hours = seconds % gSecondsPerHour; 1786 d.hours = seconds % gSecondsPerHour;
1783 seconds -= d.hours * gSecondsPerHour; 1787 seconds -= d.hours * gSecondsPerHour;
1784 d.minutes = seconds % gSecondsPerMinute; 1788 d.minutes = seconds % gSecondsPerMinute;
1785 seconds -= d.minutes * gSecondsPerMinute; 1789 seconds -= d.minutes * gSecondsPerMinute;
1786 d.seconds = seconds; 1790 d.seconds = seconds;
1787 d.is_neg = 0; 1791 d.is_neg = 0;
1788 1792
1789 return d; 1793 return d;
1790} 1794}
1791 1795
1792int ICalFormatImpl::readICalDuration(icaldurationtype d) 1796int ICalFormatImpl::readICalDuration(icaldurationtype d)
1793{ 1797{
1794 int result = 0; 1798 int result = 0;
1795 1799
1796 result += d.weeks * gSecondsPerWeek; 1800 result += d.weeks * gSecondsPerWeek;
1797 result += d.days * gSecondsPerDay; 1801 result += d.days * gSecondsPerDay;
1798 result += d.hours * gSecondsPerHour; 1802 result += d.hours * gSecondsPerHour;
1799 result += d.minutes * gSecondsPerMinute; 1803 result += d.minutes * gSecondsPerMinute;
1800 result += d.seconds; 1804 result += d.seconds;
1801 1805
1802 if (d.is_neg) result *= -1; 1806 if (d.is_neg) result *= -1;
1803 1807
1804 return result; 1808 return result;
1805} 1809}
1806 1810
1807icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal) 1811icalcomponent *ICalFormatImpl::createCalendarComponent(Calendar *cal)
1808{ 1812{
1809 icalcomponent *calendar; 1813 icalcomponent *calendar;
1810 1814
1811 // Root component 1815 // Root component
1812 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT); 1816 calendar = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
1813 1817
1814 icalproperty *p; 1818 icalproperty *p;
1815 1819
1816 // Product Identifier 1820 // Product Identifier
1817 p = icalproperty_new_prodid(CalFormat::productId().utf8()); 1821 p = icalproperty_new_prodid(CalFormat::productId().utf8());
1818 icalcomponent_add_property(calendar,p); 1822 icalcomponent_add_property(calendar,p);
1819 1823
1820 // TODO: Add time zone 1824 // TODO: Add time zone
1821 1825
1822 // iCalendar version (2.0) 1826 // iCalendar version (2.0)
1823 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION)); 1827 p = icalproperty_new_version(const_cast<char *>(_ICAL_VERSION));
1824 icalcomponent_add_property(calendar,p); 1828 icalcomponent_add_property(calendar,p);
1825 1829
1826 // Custom properties 1830 // Custom properties
1827 if( cal != 0 ) 1831 if( cal != 0 )
1828 writeCustomProperties(calendar, cal); 1832 writeCustomProperties(calendar, cal);
1829 1833
1830 return calendar; 1834 return calendar;
1831} 1835}
1832 1836
1833 1837
1834 1838
1835// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc. 1839// take a raw vcalendar (i.e. from a file on disk, clipboard, etc. etc.
1836// and break it down from its tree-like format into the dictionary format 1840// and break it down from its tree-like format into the dictionary format
1837// that is used internally in the ICalFormatImpl. 1841// that is used internally in the ICalFormatImpl.
1838bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar) 1842bool ICalFormatImpl::populate( Calendar *cal, icalcomponent *calendar)
1839{ 1843{
1840 // this function will populate the caldict dictionary and other event 1844 // this function will populate the caldict dictionary and other event
1841 // lists. It turns vevents into Events and then inserts them. 1845 // lists. It turns vevents into Events and then inserts them.
1842 1846
1843 if (!calendar) return false; 1847 if (!calendar) return false;
1844 1848
1845// TODO: check for METHOD 1849// TODO: check for METHOD
1846#if 0 1850#if 0
1847 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) { 1851 if ((curVO = isAPropertyOf(vcal, ICMethodProp)) != 0) {
1848 char *methodType = 0; 1852 char *methodType = 0;
1849 methodType = fakeCString(vObjectUStringZValue(curVO)); 1853 methodType = fakeCString(vObjectUStringZValue(curVO));
1850 if (mEnableDialogs) 1854 if (mEnableDialogs)
1851 KMessageBox::information(mTopWidget, 1855 KMessageBox::information(mTopWidget,
1852 i18n("This calendar is an iTIP transaction of type \"%1\".") 1856 i18n("This calendar is an iTIP transaction of type \"%1\".")
1853 .arg(methodType), 1857 .arg(methodType),
1854 i18n("%1: iTIP Transaction").arg(CalFormat::application())); 1858 i18n("%1: iTIP Transaction").arg(CalFormat::application()));
1855 delete methodType; 1859 delete methodType;
1856 } 1860 }
1857#endif 1861#endif
1858 1862
1859 icalproperty *p; 1863 icalproperty *p;
1860 1864
1861 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY); 1865 p = icalcomponent_get_first_property(calendar,ICAL_PRODID_PROPERTY);
1862 if (!p) { 1866 if (!p) {
1863// TODO: does no PRODID really matter? 1867// TODO: does no PRODID really matter?
1864// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1868// mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1865// return false; 1869// return false;
1866 mLoadedProductId = ""; 1870 mLoadedProductId = "";
1867 mCalendarVersion = 0; 1871 mCalendarVersion = 0;
1868 } else { 1872 } else {
1869 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p)); 1873 mLoadedProductId = QString::fromUtf8(icalproperty_get_prodid(p));
1870 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId); 1874 mCalendarVersion = CalFormat::calendarVersion(mLoadedProductId);
1871 1875
1872 delete mCompat; 1876 delete mCompat;
1873 mCompat = CompatFactory::createCompat( mLoadedProductId ); 1877 mCompat = CompatFactory::createCompat( mLoadedProductId );
1874 } 1878 }
1875 1879
1876// TODO: check for unknown PRODID 1880// TODO: check for unknown PRODID
1877#if 0 1881#if 0
1878 if (!mCalendarVersion 1882 if (!mCalendarVersion
1879 && CalFormat::productId() != mLoadedProductId) { 1883 && CalFormat::productId() != mLoadedProductId) {
1880 // warn the user that we might have trouble reading non-known calendar. 1884 // warn the user that we might have trouble reading non-known calendar.
1881 if (mEnableDialogs) 1885 if (mEnableDialogs)
1882 KMessageBox::information(mTopWidget, 1886 KMessageBox::information(mTopWidget,
1883 i18n("This vCalendar file was not created by KOrganizer " 1887 i18n("This vCalendar file was not created by KOrganizer "
1884 "or any other product we support. Loading anyway..."), 1888 "or any other product we support. Loading anyway..."),
1885 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application())); 1889 i18n("%1: Unknown vCalendar Vendor").arg(CalFormat::application()));
1886 } 1890 }
1887#endif 1891#endif
1888 1892
1889 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY); 1893 p = icalcomponent_get_first_property(calendar,ICAL_VERSION_PROPERTY);
1890 if (!p) { 1894 if (!p) {
1891 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1895 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1892 return false; 1896 return false;
1893 } else { 1897 } else {
1894 const char *version = icalproperty_get_version(p); 1898 const char *version = icalproperty_get_version(p);
1895 1899
1896 if (strcmp(version,"1.0") == 0) { 1900 if (strcmp(version,"1.0") == 0) {
1897 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1, 1901 mParent->setException(new ErrorFormat(ErrorFormat::CalVersion1,
1898 i18n("Expected iCalendar format"))); 1902 i18n("Expected iCalendar format")));
1899 return false; 1903 return false;
1900 } else if (strcmp(version,"2.0") != 0) { 1904 } else if (strcmp(version,"2.0") != 0) {
1901 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown)); 1905 mParent->setException(new ErrorFormat(ErrorFormat::CalVersionUnknown));
1902 return false; 1906 return false;
1903 } 1907 }
1904 } 1908 }
1905 1909
1906 1910
1907// TODO: check for calendar format version 1911// TODO: check for calendar format version
1908#if 0 1912#if 0
1909 // warn the user we might have trouble reading this unknown version. 1913 // warn the user we might have trouble reading this unknown version.
1910 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) { 1914 if ((curVO = isAPropertyOf(vcal, VCVersionProp)) != 0) {
1911 char *s = fakeCString(vObjectUStringZValue(curVO)); 1915 char *s = fakeCString(vObjectUStringZValue(curVO));
1912 if (strcmp(_VCAL_VERSION, s) != 0) 1916 if (strcmp(_VCAL_VERSION, s) != 0)
1913 if (mEnableDialogs) 1917 if (mEnableDialogs)
1914 KMessageBox::sorry(mTopWidget, 1918 KMessageBox::sorry(mTopWidget,
1915 i18n("This vCalendar file has version %1.\n" 1919 i18n("This vCalendar file has version %1.\n"
1916 "We only support %2.") 1920 "We only support %2.")
1917 .arg(s).arg(_VCAL_VERSION), 1921 .arg(s).arg(_VCAL_VERSION),
1918 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application())); 1922 i18n("%1: Unknown vCalendar Version").arg(CalFormat::application()));
1919 deleteStr(s); 1923 deleteStr(s);
1920 } 1924 }
1921#endif 1925#endif
1922 1926
1923 // custom properties 1927 // custom properties
1924 readCustomProperties(calendar, cal); 1928 readCustomProperties(calendar, cal);
1925 1929
1926// TODO: set time zone 1930// TODO: set time zone
1927#if 0 1931#if 0
1928 // set the time zone 1932 // set the time zone
1929 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) { 1933 if ((curVO = isAPropertyOf(vcal, VCTimeZoneProp)) != 0) {
1930 char *s = fakeCString(vObjectUStringZValue(curVO)); 1934 char *s = fakeCString(vObjectUStringZValue(curVO));
1931 cal->setTimeZone(s); 1935 cal->setTimeZone(s);
1932 deleteStr(s); 1936 deleteStr(s);
1933 } 1937 }
1934#endif 1938#endif
1935 1939
1936 // Store all events with a relatedTo property in a list for post-processing 1940 // Store all events with a relatedTo property in a list for post-processing
1937 mEventsRelate.clear(); 1941 mEventsRelate.clear();
1938 mTodosRelate.clear(); 1942 mTodosRelate.clear();
1939 // TODO: make sure that only actually added ecvens go to this lists. 1943 // TODO: make sure that only actually added ecvens go to this lists.
1940 1944
1941 icalcomponent *c; 1945 icalcomponent *c;
1942 1946
1943 // Iterate through all todos 1947 // Iterate through all todos
1944 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT); 1948 c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
1945 while (c) { 1949 while (c) {
1946// kdDebug(5800) << "----Todo found" << endl; 1950// kdDebug(5800) << "----Todo found" << endl;
1947 Todo *todo = readTodo(c); 1951 Todo *todo = readTodo(c);
diff --git a/libkcal/recurrence.cpp b/libkcal/recurrence.cpp
index 5fc5d1f..dd74e10 100644
--- a/libkcal/recurrence.cpp
+++ b/libkcal/recurrence.cpp
@@ -273,840 +273,853 @@ QDate Recurrence::endDate() const
273 case rDaily: 273 case rDaily:
274 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 274 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
275 275
276 case rWeekly: 276 case rWeekly:
277 count = weeklyCalc(END_DATE_AND_COUNT, end); 277 count = weeklyCalc(END_DATE_AND_COUNT, end);
278 break; 278 break;
279 case rMonthlyPos: 279 case rMonthlyPos:
280 case rMonthlyDay: 280 case rMonthlyDay:
281 count = monthlyCalc(END_DATE_AND_COUNT, end); 281 count = monthlyCalc(END_DATE_AND_COUNT, end);
282 break; 282 break;
283 case rYearlyMonth: 283 case rYearlyMonth:
284 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 284 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
285 break; 285 break;
286 case rYearlyDay: 286 case rYearlyDay:
287 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 287 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
288 break; 288 break;
289 case rYearlyPos: 289 case rYearlyPos:
290 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 290 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
291 break; 291 break;
292 default: 292 default:
293 // catch-all. Should never get here. 293 // catch-all. Should never get here.
294 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 294 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
295 break; 295 break;
296 } 296 }
297 } 297 }
298 if (!count) 298 if (!count)
299 return QDate(); // error - there is no recurrence 299 return QDate(); // error - there is no recurrence
300 return end; 300 return end;
301} 301}
302 302
303QDateTime Recurrence::endDateTime() const 303QDateTime Recurrence::endDateTime() const
304{ 304{
305 int count = 0; 305 int count = 0;
306 QDate end; 306 QDate end;
307 if (recurs != rNone) { 307 if (recurs != rNone) {
308 if (rDuration < 0) 308 if (rDuration < 0)
309 return QDateTime(); // infinite recurrence 309 return QDateTime(); // infinite recurrence
310 if (rDuration == 0) 310 if (rDuration == 0)
311 return rEndDateTime; 311 return rEndDateTime;
312 312
313 // The end date is determined by the recurrence count 313 // The end date is determined by the recurrence count
314 QDate dStart = mRecurStart.date(); 314 QDate dStart = mRecurStart.date();
315 switch (recurs) 315 switch (recurs)
316 { 316 {
317 case rMinutely: 317 case rMinutely:
318 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60); 318 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*60);
319 case rHourly: 319 case rHourly:
320 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600); 320 return mRecurStart.addSecs((rDuration-1+mRecurExDatesCount)*rFreq*3600);
321 case rDaily: 321 case rDaily:
322 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq); 322 return dStart.addDays((rDuration-1+mRecurExDatesCount)*rFreq);
323 323
324 case rWeekly: 324 case rWeekly:
325 count = weeklyCalc(END_DATE_AND_COUNT, end); 325 count = weeklyCalc(END_DATE_AND_COUNT, end);
326 break; 326 break;
327 case rMonthlyPos: 327 case rMonthlyPos:
328 case rMonthlyDay: 328 case rMonthlyDay:
329 count = monthlyCalc(END_DATE_AND_COUNT, end); 329 count = monthlyCalc(END_DATE_AND_COUNT, end);
330 break; 330 break;
331 case rYearlyMonth: 331 case rYearlyMonth:
332 count = yearlyMonthCalc(END_DATE_AND_COUNT, end); 332 count = yearlyMonthCalc(END_DATE_AND_COUNT, end);
333 break; 333 break;
334 case rYearlyDay: 334 case rYearlyDay:
335 count = yearlyDayCalc(END_DATE_AND_COUNT, end); 335 count = yearlyDayCalc(END_DATE_AND_COUNT, end);
336 break; 336 break;
337 case rYearlyPos: 337 case rYearlyPos:
338 count = yearlyPosCalc(END_DATE_AND_COUNT, end); 338 count = yearlyPosCalc(END_DATE_AND_COUNT, end);
339 break; 339 break;
340 default: 340 default:
341 // catch-all. Should never get here. 341 // catch-all. Should never get here.
342 kdDebug(5800) << "Control should never reach here in endDate()!" << endl; 342 kdDebug(5800) << "Control should never reach here in endDate()!" << endl;
343 break; 343 break;
344 } 344 }
345 } 345 }
346 if (!count) 346 if (!count)
347 return QDateTime(); // error - there is no recurrence 347 return QDateTime(); // error - there is no recurrence
348 return QDateTime(end, mRecurStart.time()); 348 return QDateTime(end, mRecurStart.time());
349} 349}
350 350
351int Recurrence::durationTo(const QDate &date) const 351int Recurrence::durationTo(const QDate &date) const
352{ 352{
353 QDate d = date; 353 QDate d = date;
354 return recurCalc(COUNT_TO_DATE, d); 354 return recurCalc(COUNT_TO_DATE, d);
355} 355}
356 356
357int Recurrence::durationTo(const QDateTime &datetime) const 357int Recurrence::durationTo(const QDateTime &datetime) const
358{ 358{
359 QDateTime dt = datetime; 359 QDateTime dt = datetime;
360 return recurCalc(COUNT_TO_DATE, dt); 360 return recurCalc(COUNT_TO_DATE, dt);
361} 361}
362 362
363void Recurrence::unsetRecurs() 363void Recurrence::unsetRecurs()
364{ 364{
365 if (mRecurReadOnly) return; 365 if (mRecurReadOnly) return;
366 recurs = rNone; 366 recurs = rNone;
367 rMonthPositions.clear(); 367 rMonthPositions.clear();
368 rMonthDays.clear(); 368 rMonthDays.clear();
369 rYearNums.clear(); 369 rYearNums.clear();
370} 370}
371 371
372void Recurrence::setRecurStart(const QDateTime &start) 372void Recurrence::setRecurStart(const QDateTime &start)
373{ 373{
374 mRecurStart = start; 374 mRecurStart = start;
375 mFloats = false; 375 mFloats = false;
376 switch (recurs) 376 switch (recurs)
377 { 377 {
378 case rMinutely: 378 case rMinutely:
379 case rHourly: 379 case rHourly:
380 break; 380 break;
381 case rDaily: 381 case rDaily:
382 case rWeekly: 382 case rWeekly:
383 case rMonthlyPos: 383 case rMonthlyPos:
384 case rMonthlyDay: 384 case rMonthlyDay:
385 case rYearlyMonth: 385 case rYearlyMonth:
386 case rYearlyDay: 386 case rYearlyDay:
387 case rYearlyPos: 387 case rYearlyPos:
388 default: 388 default:
389 rEndDateTime.setTime(start.time()); 389 rEndDateTime.setTime(start.time());
390 break; 390 break;
391 } 391 }
392} 392}
393 393
394void Recurrence::setRecurStart(const QDate &start) 394void Recurrence::setRecurStart(const QDate &start)
395{ 395{
396 mRecurStart.setDate(start); 396 mRecurStart.setDate(start);
397 mRecurStart.setTime(QTime(0,0,0)); 397 mRecurStart.setTime(QTime(0,0,0));
398 switch (recurs) 398 switch (recurs)
399 { 399 {
400 case rMinutely: 400 case rMinutely:
401 case rHourly: 401 case rHourly:
402 break; 402 break;
403 case rDaily: 403 case rDaily:
404 case rWeekly: 404 case rWeekly:
405 case rMonthlyPos: 405 case rMonthlyPos:
406 case rMonthlyDay: 406 case rMonthlyDay:
407 case rYearlyMonth: 407 case rYearlyMonth:
408 case rYearlyDay: 408 case rYearlyDay:
409 case rYearlyPos: 409 case rYearlyPos:
410 default: 410 default:
411 mFloats = true; 411 mFloats = true;
412 break; 412 break;
413 } 413 }
414} 414}
415 415
416void Recurrence::setFloats(bool f) 416void Recurrence::setFloats(bool f)
417{ 417{
418 switch (recurs) 418 switch (recurs)
419 { 419 {
420 case rDaily: 420 case rDaily:
421 case rWeekly: 421 case rWeekly:
422 case rMonthlyPos: 422 case rMonthlyPos:
423 case rMonthlyDay: 423 case rMonthlyDay:
424 case rYearlyMonth: 424 case rYearlyMonth:
425 case rYearlyDay: 425 case rYearlyDay:
426 case rYearlyPos: 426 case rYearlyPos:
427 break; 427 break;
428 case rMinutely: 428 case rMinutely:
429 case rHourly: 429 case rHourly:
430 default: 430 default:
431 return; // can't set sub-daily to floating 431 return; // can't set sub-daily to floating
432 } 432 }
433 mFloats = f; 433 mFloats = f;
434 if (f) { 434 if (f) {
435 mRecurStart.setTime(QTime(0,0,0)); 435 mRecurStart.setTime(QTime(0,0,0));
436 rEndDateTime.setTime(QTime(0,0,0)); 436 rEndDateTime.setTime(QTime(0,0,0));
437 } 437 }
438} 438}
439 439
440int Recurrence::frequency() const 440int Recurrence::frequency() const
441{ 441{
442 return rFreq; 442 return rFreq;
443} 443}
444 444
445int Recurrence::duration() const 445int Recurrence::duration() const
446{ 446{
447 return rDuration; 447 return rDuration;
448} 448}
449 449
450void Recurrence::setDuration(int _rDuration) 450void Recurrence::setDuration(int _rDuration)
451{ 451{
452 if (mRecurReadOnly) return; 452 if (mRecurReadOnly) return;
453 if (_rDuration > 0) { 453 if (_rDuration > 0) {
454 rDuration = _rDuration; 454 rDuration = _rDuration;
455 // Compatibility mode is only needed when reading the calendar in ICalFormatImpl, 455 // Compatibility mode is only needed when reading the calendar in ICalFormatImpl,
456 // so explicitly setting the duration means no backwards compatibility is needed. 456 // so explicitly setting the duration means no backwards compatibility is needed.
457 mCompatDuration = 0; 457 mCompatDuration = 0;
458 } 458 }
459} 459}
460 460
461QString Recurrence::endDateStr(bool shortfmt) const 461QString Recurrence::endDateStr(bool shortfmt) const
462{ 462{
463 return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt); 463 return KGlobal::locale()->formatDate(rEndDateTime.date(),shortfmt);
464} 464}
465 465
466const QBitArray &Recurrence::days() const 466const QBitArray &Recurrence::days() const
467{ 467{
468 return rDays; 468 return rDays;
469} 469}
470 470
471const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const 471const QPtrList<Recurrence::rMonthPos> &Recurrence::monthPositions() const
472{ 472{
473 return rMonthPositions; 473 return rMonthPositions;
474} 474}
475 475
476const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const 476const QPtrList<Recurrence::rMonthPos> &Recurrence::yearMonthPositions() const
477{ 477{
478 return rMonthPositions; 478 return rMonthPositions;
479} 479}
480 480
481const QPtrList<int> &Recurrence::monthDays() const 481const QPtrList<int> &Recurrence::monthDays() const
482{ 482{
483 return rMonthDays; 483 return rMonthDays;
484} 484}
485 485
486void Recurrence::setMinutely(int _rFreq, int _rDuration) 486void Recurrence::setMinutely(int _rFreq, int _rDuration)
487{ 487{
488 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 488 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
489 return; 489 return;
490 setDailySub(rMinutely, _rFreq, _rDuration); 490 setDailySub(rMinutely, _rFreq, _rDuration);
491} 491}
492 492
493void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime) 493void Recurrence::setMinutely(int _rFreq, const QDateTime &_rEndDateTime)
494{ 494{
495 if (mRecurReadOnly) return; 495 if (mRecurReadOnly) return;
496 rEndDateTime = _rEndDateTime; 496 rEndDateTime = _rEndDateTime;
497 setDailySub(rMinutely, _rFreq, 0); 497 setDailySub(rMinutely, _rFreq, 0);
498} 498}
499 499
500void Recurrence::setHourly(int _rFreq, int _rDuration) 500void Recurrence::setHourly(int _rFreq, int _rDuration)
501{ 501{
502 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 502 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
503 return; 503 return;
504 setDailySub(rHourly, _rFreq, _rDuration); 504 setDailySub(rHourly, _rFreq, _rDuration);
505} 505}
506 506
507void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime) 507void Recurrence::setHourly(int _rFreq, const QDateTime &_rEndDateTime)
508{ 508{
509 if (mRecurReadOnly) return; 509 if (mRecurReadOnly) return;
510 rEndDateTime = _rEndDateTime; 510 rEndDateTime = _rEndDateTime;
511 setDailySub(rHourly, _rFreq, 0); 511 setDailySub(rHourly, _rFreq, 0);
512} 512}
513 513
514void Recurrence::setDaily(int _rFreq, int _rDuration) 514void Recurrence::setDaily(int _rFreq, int _rDuration)
515{ 515{
516 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 516 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
517 return; 517 return;
518 setDailySub(rDaily, _rFreq, _rDuration); 518 setDailySub(rDaily, _rFreq, _rDuration);
519} 519}
520 520
521void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate) 521void Recurrence::setDaily(int _rFreq, const QDate &_rEndDate)
522{ 522{
523 if (mRecurReadOnly) return; 523 if (mRecurReadOnly) return;
524 rEndDateTime.setDate(_rEndDate); 524 rEndDateTime.setDate(_rEndDate);
525 rEndDateTime.setTime(mRecurStart.time()); 525 rEndDateTime.setTime(mRecurStart.time());
526 setDailySub(rDaily, _rFreq, 0); 526 setDailySub(rDaily, _rFreq, 0);
527} 527}
528 528
529void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, 529void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays,
530 int _rDuration, int _rWeekStart) 530 int _rDuration, int _rWeekStart)
531{ 531{
532 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 532 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
533 return; 533 return;
534 recurs = rWeekly; 534 recurs = rWeekly;
535 535
536 rFreq = _rFreq; 536 rFreq = _rFreq;
537 rDays = _rDays; 537 rDays = _rDays;
538 rWeekStart = _rWeekStart; 538 rWeekStart = _rWeekStart;
539 rDuration = _rDuration; 539 rDuration = _rDuration;
540 if (mCompatVersion < 310 && _rDuration > 0) { 540 if (mCompatVersion < 310 && _rDuration > 0) {
541 // Backwards compatibility for KDE < 3.1. 541 // Backwards compatibility for KDE < 3.1.
542 // rDuration was set to the number of time periods to recur, 542 // rDuration was set to the number of time periods to recur,
543 // with week start always on a Monday. 543 // with week start always on a Monday.
544 // Convert this to the number of occurrences. 544 // Convert this to the number of occurrences.
545 mCompatDuration = _rDuration; 545 mCompatDuration = _rDuration;
546 int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek()); 546 int weeks = ((mCompatDuration-1+mRecurExDatesCount)*7) + (7 - mRecurStart.date().dayOfWeek());
547 QDate end(mRecurStart.date().addDays(weeks * rFreq)); 547 QDate end(mRecurStart.date().addDays(weeks * rFreq));
548 rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly 548 rDuration = INT_MAX; // ensure that weeklyCalc() does its job correctly
549 rDuration = weeklyCalc(COUNT_TO_DATE, end); 549 rDuration = weeklyCalc(COUNT_TO_DATE, end);
550 } else { 550 } else {
551 mCompatDuration = 0; 551 mCompatDuration = 0;
552 } 552 }
553 rMonthPositions.clear(); 553 rMonthPositions.clear();
554 rMonthDays.clear(); 554 rMonthDays.clear();
555 if (mParent) mParent->updated(); 555 if (mParent) mParent->updated();
556} 556}
557 557
558void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays, 558void Recurrence::setWeekly(int _rFreq, const QBitArray &_rDays,
559 const QDate &_rEndDate, int _rWeekStart) 559 const QDate &_rEndDate, int _rWeekStart)
560{ 560{
561 if (mRecurReadOnly) return; 561 if (mRecurReadOnly) return;
562 recurs = rWeekly; 562 recurs = rWeekly;
563 563
564 rFreq = _rFreq; 564 rFreq = _rFreq;
565 rDays = _rDays; 565 rDays = _rDays;
566 rWeekStart = _rWeekStart; 566 rWeekStart = _rWeekStart;
567 rEndDateTime.setDate(_rEndDate); 567 rEndDateTime.setDate(_rEndDate);
568 rEndDateTime.setTime(mRecurStart.time()); 568 rEndDateTime.setTime(mRecurStart.time());
569 rDuration = 0; // set to 0 because there is an end date 569 rDuration = 0; // set to 0 because there is an end date
570 mCompatDuration = 0; 570 mCompatDuration = 0;
571 rMonthPositions.clear(); 571 rMonthPositions.clear();
572 rMonthDays.clear(); 572 rMonthDays.clear();
573 rYearNums.clear(); 573 rYearNums.clear();
574 if (mParent) mParent->updated(); 574 if (mParent) mParent->updated();
575} 575}
576 576
577void Recurrence::setMonthly(short type, int _rFreq, int _rDuration) 577void Recurrence::setMonthly(short type, int _rFreq, int _rDuration)
578{ 578{
579 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 579 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
580 return; 580 return;
581 recurs = type; 581 recurs = type;
582 582
583 rFreq = _rFreq; 583 rFreq = _rFreq;
584 rDuration = _rDuration; 584 rDuration = _rDuration;
585 if (mCompatVersion < 310) 585 if (mCompatVersion < 310)
586 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 586 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
587 rYearNums.clear(); 587 rYearNums.clear();
588 if (mParent) mParent->updated(); 588 if (mParent) mParent->updated();
589} 589}
590 590
591void Recurrence::setMonthly(short type, int _rFreq, 591void Recurrence::setMonthly(short type, int _rFreq,
592 const QDate &_rEndDate) 592 const QDate &_rEndDate)
593{ 593{
594 if (mRecurReadOnly) return; 594 if (mRecurReadOnly) return;
595 recurs = type; 595 recurs = type;
596 596
597 rFreq = _rFreq; 597 rFreq = _rFreq;
598 rEndDateTime.setDate(_rEndDate); 598 rEndDateTime.setDate(_rEndDate);
599 rEndDateTime.setTime(mRecurStart.time()); 599 rEndDateTime.setTime(mRecurStart.time());
600 rDuration = 0; // set to 0 because there is an end date 600 rDuration = 0; // set to 0 because there is an end date
601 mCompatDuration = 0; 601 mCompatDuration = 0;
602 rYearNums.clear(); 602 rYearNums.clear();
603 if (mParent) mParent->updated(); 603 if (mParent) mParent->updated();
604} 604}
605 605
606void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays) 606void Recurrence::addMonthlyPos(short _rPos, const QBitArray &_rDays)
607{ 607{
608 if (recurs == rMonthlyPos) 608 if (recurs == rMonthlyPos)
609 addMonthlyPos_(_rPos, _rDays); 609 addMonthlyPos_(_rPos, _rDays);
610} 610}
611 611
612void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays) 612void Recurrence::addMonthlyPos_(short _rPos, const QBitArray &_rDays)
613{ 613{
614 if (mRecurReadOnly 614 if (mRecurReadOnly
615 || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number 615 || _rPos == 0 || _rPos > 5 || _rPos < -5) // invalid week number
616 return; 616 return;
617 617
618 for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) { 618 for (rMonthPos* it = rMonthPositions.first(); it; it = rMonthPositions.next()) {
619 int itPos = it->negative ? -it->rPos : it->rPos; 619 int itPos = it->negative ? -it->rPos : it->rPos;
620 if (_rPos == itPos) { 620 if (_rPos == itPos) {
621 // This week is already in the list. 621 // This week is already in the list.
622 // Combine the specified days with those in the list. 622 // Combine the specified days with those in the list.
623 it->rDays |= _rDays; 623 it->rDays |= _rDays;
624 if (mParent) mParent->updated(); 624 if (mParent) mParent->updated();
625 return; 625 return;
626 } 626 }
627 } 627 }
628 // Add the new position to the list 628 // Add the new position to the list
629 rMonthPos *tmpPos = new rMonthPos; 629 rMonthPos *tmpPos = new rMonthPos;
630 if (_rPos > 0) { 630 if (_rPos > 0) {
631 tmpPos->rPos = _rPos; 631 tmpPos->rPos = _rPos;
632 tmpPos->negative = false; 632 tmpPos->negative = false;
633 } else { 633 } else {
634 tmpPos->rPos = -_rPos; // take abs() 634 tmpPos->rPos = -_rPos; // take abs()
635 tmpPos->negative = true; 635 tmpPos->negative = true;
636 } 636 }
637 tmpPos->rDays = _rDays; 637 tmpPos->rDays = _rDays;
638 tmpPos->rDays.detach(); 638 tmpPos->rDays.detach();
639 rMonthPositions.append(tmpPos); 639 rMonthPositions.append(tmpPos);
640 640
641 if (mCompatVersion < 310 && mCompatDuration > 0) { 641 if (mCompatVersion < 310 && mCompatDuration > 0) {
642 // Backwards compatibility for KDE < 3.1. 642 // Backwards compatibility for KDE < 3.1.
643 // rDuration was set to the number of time periods to recur. 643 // rDuration was set to the number of time periods to recur.
644 // Convert this to the number of occurrences. 644 // Convert this to the number of occurrences.
645 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 645 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
646 int month = mRecurStart.date().month() - 1 + monthsAhead; 646 int month = mRecurStart.date().month() - 1 + monthsAhead;
647 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 647 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
648 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 648 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
649 rDuration = recurCalc(COUNT_TO_DATE, end); 649 rDuration = recurCalc(COUNT_TO_DATE, end);
650 } 650 }
651 651
652 if (mParent) mParent->updated(); 652 if (mParent) mParent->updated();
653} 653}
654 654
655void Recurrence::addMonthlyDay(short _rDay) 655void Recurrence::addMonthlyDay(short _rDay)
656{ 656{
657 if (mRecurReadOnly || recurs != rMonthlyDay 657 if (mRecurReadOnly || (recurs != rMonthlyDay && recurs != rYearlyMonth)
658 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number 658 || _rDay == 0 || _rDay > 31 || _rDay < -31) // invalid day number
659 return; 659 return;
660 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) { 660 for (int* it = rMonthDays.first(); it; it = rMonthDays.next()) {
661 if (_rDay == *it) 661 if (_rDay == *it)
662 return; // this day is already in the list - avoid duplication 662 return; // this day is already in the list - avoid duplication
663 } 663 }
664 int *tmpDay = new int; 664 int *tmpDay = new int;
665 *tmpDay = _rDay; 665 *tmpDay = _rDay;
666 rMonthDays.append(tmpDay); 666 rMonthDays.append(tmpDay);
667 667
668 if (mCompatVersion < 310 && mCompatDuration > 0) { 668 if (mCompatVersion < 310 && mCompatDuration > 0) {
669 // Backwards compatibility for KDE < 3.1. 669 // Backwards compatibility for KDE < 3.1.
670 // rDuration was set to the number of time periods to recur. 670 // rDuration was set to the number of time periods to recur.
671 // Convert this to the number of occurrences. 671 // Convert this to the number of occurrences.
672 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq; 672 int monthsAhead = (mCompatDuration-1+mRecurExDatesCount) * rFreq;
673 int month = mRecurStart.date().month() - 1 + monthsAhead; 673 int month = mRecurStart.date().month() - 1 + monthsAhead;
674 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31); 674 QDate end(mRecurStart.date().year() + month/12, month%12 + 1, 31);
675 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 675 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
676 rDuration = recurCalc(COUNT_TO_DATE, end); 676 rDuration = recurCalc(COUNT_TO_DATE, end);
677 } 677 }
678 678
679 if (mParent) mParent->updated(); 679 if (mParent) mParent->updated();
680} 680}
681 681
682void Recurrence::setYearly(int type, int _rFreq, int _rDuration) 682void Recurrence::setYearly(int type, int _rFreq, int _rDuration)
683{ 683{
684 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 684 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
685 return; 685 return;
686 if (mCompatVersion < 310) 686 if (mCompatVersion < 310)
687 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 687 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
688 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration); 688 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, _rDuration);
689} 689}
690 690
691void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate) 691void Recurrence::setYearly(int type, int _rFreq, const QDate &_rEndDate)
692{ 692{
693 if (mRecurReadOnly) return; 693 if (mRecurReadOnly) return;
694 rEndDateTime.setDate(_rEndDate); 694 rEndDateTime.setDate(_rEndDate);
695 rEndDateTime.setTime(mRecurStart.time()); 695 rEndDateTime.setTime(mRecurStart.time());
696 mCompatDuration = 0; 696 mCompatDuration = 0;
697 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0); 697 setYearly_(type, mFeb29YearlyDefaultType, _rFreq, 0);
698} 698}
699 699
700void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration) 700void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, int _rDuration)
701{ 701{
702 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1) 702 if (mRecurReadOnly || _rDuration == 0 || _rDuration < -1)
703 return; 703 return;
704 if (mCompatVersion < 310) 704 if (mCompatVersion < 310)
705 mCompatDuration = (_rDuration > 0) ? _rDuration : 0; 705 mCompatDuration = (_rDuration > 0) ? _rDuration : 0;
706 setYearly_(rYearlyMonth, type, _rFreq, _rDuration); 706 setYearly_(rYearlyMonth, type, _rFreq, _rDuration);
707} 707}
708 708
709void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate) 709void Recurrence::setYearlyByDate(Feb29Type type, int _rFreq, const QDate &_rEndDate)
710{ 710{
711 if (mRecurReadOnly) return; 711 if (mRecurReadOnly) return;
712 rEndDateTime.setDate(_rEndDate); 712 rEndDateTime.setDate(_rEndDate);
713 rEndDateTime.setTime(mRecurStart.time()); 713 rEndDateTime.setTime(mRecurStart.time());
714 mCompatDuration = 0; 714 mCompatDuration = 0;
715 setYearly_(rYearlyMonth, type, _rFreq, 0); 715 setYearly_(rYearlyMonth, type, _rFreq, 0);
716} 716}
717 717
718void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays) 718void Recurrence::addYearlyMonthPos(short _rPos, const QBitArray &_rDays)
719{ 719{
720 if (recurs == rYearlyPos) 720 if (recurs == rYearlyPos)
721 addMonthlyPos_(_rPos, _rDays); 721 addMonthlyPos_(_rPos, _rDays);
722} 722}
723 723
724const QPtrList<int> &Recurrence::yearNums() const 724const QPtrList<int> &Recurrence::yearNums() const
725{ 725{
726 return rYearNums; 726 return rYearNums;
727} 727}
728 728void Recurrence::addYearlyMonth(short _rPos )
729{
730 if (mRecurReadOnly || recurs != rYearlyMonth) // invalid day/month number
731 return;
732 rMonthPos *tmpPos = new rMonthPos;
733 if ( _rPos > 0) {
734 tmpPos->rPos = _rPos;
735 tmpPos->negative = false;
736 } else {
737 tmpPos->rPos = -_rPos; // take abs()
738 tmpPos->negative = true;
739 }
740 rMonthPositions.append(tmpPos);
741}
729void Recurrence::addYearlyNum(short _rNum) 742void Recurrence::addYearlyNum(short _rNum)
730{ 743{
731 if (mRecurReadOnly 744 if (mRecurReadOnly
732 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos) 745 || (recurs != rYearlyMonth && recurs != rYearlyDay && recurs != rYearlyPos)
733 || _rNum <= 0) // invalid day/month number 746 || _rNum <= 0) // invalid day/month number
734 return; 747 return;
735 748
736 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) { 749 if (mCompatVersion < 310 && mCompatRecurs == rYearlyDay) {
737 // Backwards compatibility for KDE < 3.1. 750 // Backwards compatibility for KDE < 3.1.
738 // Dates were stored as day numbers, with a fiddle to take account of leap years. 751 // Dates were stored as day numbers, with a fiddle to take account of leap years.
739 // Convert the day number to a month. 752 // Convert the day number to a month.
740 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366)) 753 if (_rNum <= 0 || _rNum > 366 || (_rNum == 366 && mRecurStart.date().daysInYear() < 366))
741 return; // invalid day number 754 return; // invalid day number
742 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month(); 755 _rNum = QDate(mRecurStart.date().year(), 1, 1).addDays(_rNum - 1).month();
743 } else 756 } else
744 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12 757 if ((recurs == rYearlyMonth || recurs == rYearlyPos) && _rNum > 12
745 || recurs == rYearlyDay && _rNum > 366) 758 || recurs == rYearlyDay && _rNum > 366)
746 return; // invalid day number 759 return; // invalid day number
747 760
748 uint i = 0; 761 uint i = 0;
749 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) { 762 for (int* it = rYearNums.first(); it && _rNum >= *it; it = rYearNums.next()) {
750 if (_rNum == *it) 763 if (_rNum == *it)
751 return; // this day/month is already in the list - avoid duplication 764 return; // this day/month is already in the list - avoid duplication
752 ++i; 765 ++i;
753 } 766 }
754 767
755 int *tmpNum = new int; 768 int *tmpNum = new int;
756 *tmpNum = _rNum; 769 *tmpNum = _rNum;
757 rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position 770 rYearNums.insert(i, tmpNum); // insert the day/month in a sorted position
758 771
759 if (mCompatVersion < 310 && mCompatDuration > 0) { 772 if (mCompatVersion < 310 && mCompatDuration > 0) {
760 // Backwards compatibility for KDE < 3.1. 773 // Backwards compatibility for KDE < 3.1.
761 // rDuration was set to the number of time periods to recur. 774 // rDuration was set to the number of time periods to recur.
762 // Convert this to the number of occurrences. 775 // Convert this to the number of occurrences.
763 QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31); 776 QDate end(mRecurStart.date().year() + (mCompatDuration-1+mRecurExDatesCount)*rFreq, 12, 31);
764 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly 777 rDuration = INT_MAX; // ensure that recurCalc() does its job correctly
765 rDuration = recurCalc(COUNT_TO_DATE, end); 778 rDuration = recurCalc(COUNT_TO_DATE, end);
766 } 779 }
767 780
768 if (mParent) mParent->updated(); 781 if (mParent) mParent->updated();
769} 782}
770 783
771 784
772QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const 785QDateTime Recurrence::getNextDateTime(const QDateTime &preDateTime, bool *last) const
773{ 786{
774 if (last) 787 if (last)
775 *last = false; 788 *last = false;
776 int freq; 789 int freq;
777 switch (recurs) 790 switch (recurs)
778 { 791 {
779 case rMinutely: 792 case rMinutely:
780 freq = rFreq * 60; 793 freq = rFreq * 60;
781 break; 794 break;
782 case rHourly: 795 case rHourly:
783 freq = rFreq * 3600; 796 freq = rFreq * 3600;
784 break; 797 break;
785 case rDaily: 798 case rDaily:
786 case rWeekly: 799 case rWeekly:
787 case rMonthlyPos: 800 case rMonthlyPos:
788 case rMonthlyDay: 801 case rMonthlyDay:
789 case rYearlyMonth: 802 case rYearlyMonth:
790 case rYearlyDay: 803 case rYearlyDay:
791 case rYearlyPos: { 804 case rYearlyPos: {
792 QDate preDate = preDateTime.date(); 805 QDate preDate = preDateTime.date();
793 if (!mFloats && mRecurStart.time() > preDateTime.time()) 806 if (!mFloats && mRecurStart.time() > preDateTime.time())
794 preDate = preDate.addDays(-1); 807 preDate = preDate.addDays(-1);
795 return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time()); 808 return QDateTime(getNextDateNoTime(preDate, last), mRecurStart.time());
796 } 809 }
797 default: 810 default:
798 return QDateTime(); 811 return QDateTime();
799 } 812 }
800 813
801 // It's a sub-daily recurrence 814 // It's a sub-daily recurrence
802 if (preDateTime < mRecurStart) 815 if (preDateTime < mRecurStart)
803 return mRecurStart; 816 return mRecurStart;
804 int count = mRecurStart.secsTo(preDateTime) / freq + 2; 817 int count = mRecurStart.secsTo(preDateTime) / freq + 2;
805 if (rDuration > 0) { 818 if (rDuration > 0) {
806 if (count > rDuration) 819 if (count > rDuration)
807 return QDateTime(); 820 return QDateTime();
808 if (last && count == rDuration) 821 if (last && count == rDuration)
809 *last = true; 822 *last = true;
810 } 823 }
811 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); 824 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq);
812 if (rDuration == 0) { 825 if (rDuration == 0) {
813 if (endtime > rEndDateTime) 826 if (endtime > rEndDateTime)
814 return QDateTime(); 827 return QDateTime();
815 if (last && endtime == rEndDateTime) 828 if (last && endtime == rEndDateTime)
816 *last = true; 829 *last = true;
817 } 830 }
818 return endtime; 831 return endtime;
819} 832}
820 833
821QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const 834QDate Recurrence::getNextDate(const QDate &preDate, bool *last) const
822{ 835{
823 if (last) 836 if (last)
824 *last = false; 837 *last = false;
825 switch (recurs) 838 switch (recurs)
826 { 839 {
827 case rMinutely: 840 case rMinutely:
828 case rHourly: 841 case rHourly:
829 return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date(); 842 return getNextDateTime(QDateTime(preDate, QTime(23,59,59)), last).date();
830 case rDaily: 843 case rDaily:
831 case rWeekly: 844 case rWeekly:
832 case rMonthlyPos: 845 case rMonthlyPos:
833 case rMonthlyDay: 846 case rMonthlyDay:
834 case rYearlyMonth: 847 case rYearlyMonth:
835 case rYearlyDay: 848 case rYearlyDay:
836 case rYearlyPos: 849 case rYearlyPos:
837 return getNextDateNoTime(preDate, last); 850 return getNextDateNoTime(preDate, last);
838 default: 851 default:
839 return QDate(); 852 return QDate();
840 } 853 }
841} 854}
842 855
843 856
844QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const 857QDateTime Recurrence::getPreviousDateTime(const QDateTime &afterDateTime, bool *last) const
845{ 858{
846 if (last) 859 if (last)
847 *last = false; 860 *last = false;
848 int freq; 861 int freq;
849 switch (recurs) 862 switch (recurs)
850 { 863 {
851 case rMinutely: 864 case rMinutely:
852 freq = rFreq * 60; 865 freq = rFreq * 60;
853 break; 866 break;
854 case rHourly: 867 case rHourly:
855 freq = rFreq * 3600; 868 freq = rFreq * 3600;
856 break; 869 break;
857 case rDaily: 870 case rDaily:
858 case rWeekly: 871 case rWeekly:
859 case rMonthlyPos: 872 case rMonthlyPos:
860 case rMonthlyDay: 873 case rMonthlyDay:
861 case rYearlyMonth: 874 case rYearlyMonth:
862 case rYearlyDay: 875 case rYearlyDay:
863 case rYearlyPos: { 876 case rYearlyPos: {
864 QDate afterDate = afterDateTime.date(); 877 QDate afterDate = afterDateTime.date();
865 if (!mFloats && mRecurStart.time() < afterDateTime.time()) 878 if (!mFloats && mRecurStart.time() < afterDateTime.time())
866 afterDate = afterDate.addDays(1); 879 afterDate = afterDate.addDays(1);
867 return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time()); 880 return QDateTime(getPreviousDateNoTime(afterDate, last), mRecurStart.time());
868 } 881 }
869 default: 882 default:
870 return QDateTime(); 883 return QDateTime();
871 } 884 }
872 885
873 // It's a sub-daily recurrence 886 // It's a sub-daily recurrence
874 if (afterDateTime <= mRecurStart) 887 if (afterDateTime <= mRecurStart)
875 return QDateTime(); 888 return QDateTime();
876 int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1; 889 int count = (mRecurStart.secsTo(afterDateTime) - 1) / freq + 1;
877 if (rDuration > 0) { 890 if (rDuration > 0) {
878 if (count > rDuration) 891 if (count > rDuration)
879 count = rDuration; 892 count = rDuration;
880 if (last && count == rDuration) 893 if (last && count == rDuration)
881 *last = true; 894 *last = true;
882 } 895 }
883 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq); 896 QDateTime endtime = mRecurStart.addSecs((count - 1)*freq);
884 if (rDuration == 0) { 897 if (rDuration == 0) {
885 if (endtime > rEndDateTime) 898 if (endtime > rEndDateTime)
886 endtime = rEndDateTime; 899 endtime = rEndDateTime;
887 if (last && endtime == rEndDateTime) 900 if (last && endtime == rEndDateTime)
888 *last = true; 901 *last = true;
889 } 902 }
890 return endtime; 903 return endtime;
891} 904}
892 905
893QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const 906QDate Recurrence::getPreviousDate(const QDate &afterDate, bool *last) const
894{ 907{
895 if (last) 908 if (last)
896 *last = false; 909 *last = false;
897 switch (recurs) 910 switch (recurs)
898 { 911 {
899 case rMinutely: 912 case rMinutely:
900 case rHourly: 913 case rHourly:
901 return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date(); 914 return getPreviousDateTime(QDateTime(afterDate, QTime(0,0,0)), last).date();
902 case rDaily: 915 case rDaily:
903 case rWeekly: 916 case rWeekly:
904 case rMonthlyPos: 917 case rMonthlyPos:
905 case rMonthlyDay: 918 case rMonthlyDay:
906 case rYearlyMonth: 919 case rYearlyMonth:
907 case rYearlyDay: 920 case rYearlyDay:
908 case rYearlyPos: 921 case rYearlyPos:
909 return getPreviousDateNoTime(afterDate, last); 922 return getPreviousDateNoTime(afterDate, last);
910 default: 923 default:
911 return QDate(); 924 return QDate();
912 } 925 }
913} 926}
914 927
915 928
916/***************************** PROTECTED FUNCTIONS ***************************/ 929/***************************** PROTECTED FUNCTIONS ***************************/
917 930
918bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const 931bool Recurrence::recursSecondly(const QDate &qd, int secondFreq) const
919{ 932{
920 if ((qd >= mRecurStart.date()) && 933 if ((qd >= mRecurStart.date()) &&
921 ((rDuration > 0) && (qd <= endDate()) || 934 ((rDuration > 0) && (qd <= endDate()) ||
922 ((rDuration == 0) && (qd <= rEndDateTime.date())) || 935 ((rDuration == 0) && (qd <= rEndDateTime.date())) ||
923 (rDuration == -1))) { 936 (rDuration == -1))) {
924 // The date queried falls within the range of the event. 937 // The date queried falls within the range of the event.
925 if (secondFreq < 24*3600) 938 if (secondFreq < 24*3600)
926 return true; // the event recurs at least once each day 939 return true; // the event recurs at least once each day
927 int after = mRecurStart.secsTo(QDateTime(qd)); 940 int after = mRecurStart.secsTo(QDateTime(qd));
928 if (after / secondFreq != (after + 24*3600) / secondFreq) 941 if (after / secondFreq != (after + 24*3600) / secondFreq)
929 return true; 942 return true;
930 } 943 }
931 return false; 944 return false;
932} 945}
933 946
934bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const 947bool Recurrence::recursMinutelyAt(const QDateTime &dt, int minuteFreq) const
935{ 948{
936 if ((dt >= mRecurStart) && 949 if ((dt >= mRecurStart) &&
937 ((rDuration > 0) && (dt <= endDateTime()) || 950 ((rDuration > 0) && (dt <= endDateTime()) ||
938 ((rDuration == 0) && (dt <= rEndDateTime)) || 951 ((rDuration == 0) && (dt <= rEndDateTime)) ||
939 (rDuration == -1))) { 952 (rDuration == -1))) {
940 // The time queried falls within the range of the event. 953 // The time queried falls within the range of the event.
941 if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0) 954 if (((mRecurStart.secsTo(dt) / 60) % minuteFreq) == 0)
942 return true; 955 return true;
943 } 956 }
944 return false; 957 return false;
945} 958}
946 959
947bool Recurrence::recursDaily(const QDate &qd) const 960bool Recurrence::recursDaily(const QDate &qd) const
948{ 961{
949 QDate dStart = mRecurStart.date(); 962 QDate dStart = mRecurStart.date();
950 if ((dStart.daysTo(qd) % rFreq) == 0) { 963 if ((dStart.daysTo(qd) % rFreq) == 0) {
951 // The date is a day which recurs 964 // The date is a day which recurs
952 if (qd >= dStart 965 if (qd >= dStart
953 && ((rDuration > 0 && qd <= endDate()) || 966 && ((rDuration > 0 && qd <= endDate()) ||
954 (rDuration == 0 && qd <= rEndDateTime.date()) || 967 (rDuration == 0 && qd <= rEndDateTime.date()) ||
955 rDuration == -1)) { 968 rDuration == -1)) {
956 // The date queried falls within the range of the event. 969 // The date queried falls within the range of the event.
957 return true; 970 return true;
958 } 971 }
959 } 972 }
960 return false; 973 return false;
961} 974}
962 975
963bool Recurrence::recursWeekly(const QDate &qd) const 976bool Recurrence::recursWeekly(const QDate &qd) const
964{ 977{
965 QDate dStart = mRecurStart.date(); 978 QDate dStart = mRecurStart.date();
966 if ((dStart.daysTo(qd)/7) % rFreq == 0) { 979 if ((dStart.daysTo(qd)/7) % rFreq == 0) {
967 // The date is in a week which recurs 980 // The date is in a week which recurs
968 if (qd >= dStart 981 if (qd >= dStart
969 && ((rDuration > 0 && qd <= endDate()) || 982 && ((rDuration > 0 && qd <= endDate()) ||
970 (rDuration == 0 && qd <= rEndDateTime.date()) || 983 (rDuration == 0 && qd <= rEndDateTime.date()) ||
971 rDuration == -1)) { 984 rDuration == -1)) {
972 // The date queried falls within the range of the event. 985 // The date queried falls within the range of the event.
973 // check if the bits set match today. 986 // check if the bits set match today.
974 int i = qd.dayOfWeek()-1; 987 int i = qd.dayOfWeek()-1;
975 if (rDays.testBit((uint) i)) 988 if (rDays.testBit((uint) i))
976 return true; 989 return true;
977 } 990 }
978 } 991 }
979 return false; 992 return false;
980} 993}
981 994
982bool Recurrence::recursMonthly(const QDate &qd) const 995bool Recurrence::recursMonthly(const QDate &qd) const
983{ 996{
984 QDate dStart = mRecurStart.date(); 997 QDate dStart = mRecurStart.date();
985 int year = qd.year(); 998 int year = qd.year();
986 int month = qd.month(); 999 int month = qd.month();
987 int day = qd.day(); 1000 int day = qd.day();
988 // calculate how many months ahead this date is from the original 1001 // calculate how many months ahead this date is from the original
989 // event's date 1002 // event's date
990 int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month()); 1003 int monthsAhead = (year - dStart.year()) * 12 + (month - dStart.month());
991 if ((monthsAhead % rFreq) == 0) { 1004 if ((monthsAhead % rFreq) == 0) {
992 // The date is in a month which recurs 1005 // The date is in a month which recurs
993 if (qd >= dStart 1006 if (qd >= dStart
994 && ((rDuration > 0 && qd <= endDate()) || 1007 && ((rDuration > 0 && qd <= endDate()) ||
995 (rDuration == 0 && qd <= rEndDateTime.date()) || 1008 (rDuration == 0 && qd <= rEndDateTime.date()) ||
996 rDuration == -1)) { 1009 rDuration == -1)) {
997 // The date queried falls within the range of the event. 1010 // The date queried falls within the range of the event.
998 QValueList<int> days; 1011 QValueList<int> days;
999 int daysInMonth = qd.daysInMonth(); 1012 int daysInMonth = qd.daysInMonth();
1000 if (recurs == rMonthlyDay) 1013 if (recurs == rMonthlyDay)
1001 getMonthlyDayDays(days, daysInMonth); 1014 getMonthlyDayDays(days, daysInMonth);
1002 else if (recurs == rMonthlyPos) 1015 else if (recurs == rMonthlyPos)
1003 getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek()); 1016 getMonthlyPosDays(days, daysInMonth, QDate(year, month, 1).dayOfWeek());
1004 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { 1017 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) {
1005 if (*it == day) 1018 if (*it == day)
1006 return true; 1019 return true;
1007 } 1020 }
1008 // no dates matched 1021 // no dates matched
1009 } 1022 }
1010 } 1023 }
1011 return false; 1024 return false;
1012} 1025}
1013 1026
1014bool Recurrence::recursYearlyByMonth(const QDate &qd) const 1027bool Recurrence::recursYearlyByMonth(const QDate &qd) const
1015{ 1028{
1016 QDate dStart = mRecurStart.date(); 1029 QDate dStart = mRecurStart.date();
1017 int startDay = dStart.day(); 1030 int startDay = dStart.day();
1018 int qday = qd.day(); 1031 int qday = qd.day();
1019 int qmonth = qd.month(); 1032 int qmonth = qd.month();
1020 int qyear = qd.year(); 1033 int qyear = qd.year();
1021 bool match = (qday == startDay); 1034 bool match = (qday == startDay);
1022 if (!match && startDay == 29 && dStart.month() == 2) { 1035 if (!match && startDay == 29 && dStart.month() == 2) {
1023 // It's a recurrence on February 29th 1036 // It's a recurrence on February 29th
1024 switch (mFeb29YearlyType) { 1037 switch (mFeb29YearlyType) {
1025 case rFeb28: 1038 case rFeb28:
1026 if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear)) 1039 if (qday == 28 && qmonth == 2 && !QDate::leapYear(qyear))
1027 match = true; 1040 match = true;
1028 break; 1041 break;
1029 case rMar1: 1042 case rMar1:
1030 if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) { 1043 if (qday == 1 && qmonth == 3 && !QDate::leapYear(qyear)) {
1031 qmonth = 2; 1044 qmonth = 2;
1032 match = true; 1045 match = true;
1033 } 1046 }
1034 break; 1047 break;
1035 case rFeb29: 1048 case rFeb29:
1036 break; 1049 break;
1037 } 1050 }
1038 } 1051 }
1039 1052
1040 if (match) { 1053 if (match) {
1041 // The day of the month matches. Calculate how many years ahead 1054 // The day of the month matches. Calculate how many years ahead
1042 // this date is from the original event's date. 1055 // this date is from the original event's date.
1043 int yearsAhead = (qyear - dStart.year()); 1056 int yearsAhead = (qyear - dStart.year());
1044 if (yearsAhead % rFreq == 0) { 1057 if (yearsAhead % rFreq == 0) {
1045 // The date is in a year which recurs 1058 // The date is in a year which recurs
1046 if (qd >= dStart 1059 if (qd >= dStart
1047 && ((rDuration > 0 && qd <= endDate()) || 1060 && ((rDuration > 0 && qd <= endDate()) ||
1048 (rDuration == 0 && qd <= rEndDateTime.date()) || 1061 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1049 rDuration == -1)) { 1062 rDuration == -1)) {
1050 // The date queried falls within the range of the event. 1063 // The date queried falls within the range of the event.
1051 int i = qmonth; 1064 int i = qmonth;
1052 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1065 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1053 if (i == *qlin.current()) 1066 if (i == *qlin.current())
1054 return true; 1067 return true;
1055 } 1068 }
1056 } 1069 }
1057 } 1070 }
1058 } 1071 }
1059 return false; 1072 return false;
1060} 1073}
1061 1074
1062bool Recurrence::recursYearlyByPos(const QDate &qd) const 1075bool Recurrence::recursYearlyByPos(const QDate &qd) const
1063{ 1076{
1064 QDate dStart = mRecurStart.date(); 1077 QDate dStart = mRecurStart.date();
1065 int year = qd.year(); 1078 int year = qd.year();
1066 int month = qd.month(); 1079 int month = qd.month();
1067 int day = qd.day(); 1080 int day = qd.day();
1068 // calculate how many years ahead this date is from the original 1081 // calculate how many years ahead this date is from the original
1069 // event's date 1082 // event's date
1070 int yearsAhead = (year - dStart.year()); 1083 int yearsAhead = (year - dStart.year());
1071 if (yearsAhead % rFreq == 0) { 1084 if (yearsAhead % rFreq == 0) {
1072 // The date is in a year which recurs 1085 // The date is in a year which recurs
1073 if (qd >= dStart 1086 if (qd >= dStart
1074 && ((rDuration > 0 && qd <= endDate()) || 1087 && ((rDuration > 0 && qd <= endDate()) ||
1075 (rDuration == 0 && qd <= rEndDateTime.date()) || 1088 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1076 rDuration == -1)) { 1089 rDuration == -1)) {
1077 // The date queried falls within the range of the event. 1090 // The date queried falls within the range of the event.
1078 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1091 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1079 if (month == *qlin.current()) { 1092 if (month == *qlin.current()) {
1080 // The month recurs 1093 // The month recurs
1081 QValueList<int> days; 1094 QValueList<int> days;
1082 getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek()); 1095 getMonthlyPosDays(days, qd.daysInMonth(), QDate(year, month, 1).dayOfWeek());
1083 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) { 1096 for (QValueList<int>::Iterator it = days.begin(); it != days.end(); ++it) {
1084 if (*it == day) 1097 if (*it == day)
1085 return true; 1098 return true;
1086 } 1099 }
1087 } 1100 }
1088 } 1101 }
1089 } 1102 }
1090 } 1103 }
1091 return false; 1104 return false;
1092} 1105}
1093 1106
1094bool Recurrence::recursYearlyByDay(const QDate &qd) const 1107bool Recurrence::recursYearlyByDay(const QDate &qd) const
1095{ 1108{
1096 QDate dStart = mRecurStart.date(); 1109 QDate dStart = mRecurStart.date();
1097 // calculate how many years ahead this date is from the original 1110 // calculate how many years ahead this date is from the original
1098 // event's date 1111 // event's date
1099 int yearsAhead = (qd.year() - dStart.year()); 1112 int yearsAhead = (qd.year() - dStart.year());
1100 if (yearsAhead % rFreq == 0) { 1113 if (yearsAhead % rFreq == 0) {
1101 // The date is in a year which recurs 1114 // The date is in a year which recurs
1102 if (qd >= dStart 1115 if (qd >= dStart
1103 && ((rDuration > 0 && qd <= endDate()) || 1116 && ((rDuration > 0 && qd <= endDate()) ||
1104 (rDuration == 0 && qd <= rEndDateTime.date()) || 1117 (rDuration == 0 && qd <= rEndDateTime.date()) ||
1105 rDuration == -1)) { 1118 rDuration == -1)) {
1106 // The date queried falls within the range of the event. 1119 // The date queried falls within the range of the event.
1107 int i = qd.dayOfYear(); 1120 int i = qd.dayOfYear();
1108 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) { 1121 for (QPtrListIterator<int> qlin(rYearNums); qlin.current(); ++qlin) {
1109 if (i == *qlin.current()) 1122 if (i == *qlin.current())
1110 return true; 1123 return true;
1111 } 1124 }
1112 } 1125 }
diff --git a/libkcal/recurrence.h b/libkcal/recurrence.h
index a0f6d84..b13d14f 100644
--- a/libkcal/recurrence.h
+++ b/libkcal/recurrence.h
@@ -1,401 +1,401 @@
1/* 1/*
2 This file is part of libkcal. 2 This file is part of libkcal.
3 Copyright (c) 1998 Preston Brown 3 Copyright (c) 1998 Preston Brown
4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 4 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk> 5 Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
6 6
7 This library is free software; you can redistribute it and/or 7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public 8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22#ifndef KCAL_RECURRENCE_H 22#ifndef KCAL_RECURRENCE_H
23#define KCAL_RECURRENCE_H 23#define KCAL_RECURRENCE_H
24 24
25#include <qstring.h> 25#include <qstring.h>
26#include <qbitarray.h> 26#include <qbitarray.h>
27#include <qptrlist.h> 27#include <qptrlist.h>
28 28
29namespace KCal { 29namespace KCal {
30 30
31class Incidence; 31class Incidence;
32 32
33/** 33/**
34 This class represents a recurrence rule for a calendar incidence. 34 This class represents a recurrence rule for a calendar incidence.
35*/ 35*/
36class Recurrence 36class Recurrence
37{ 37{
38 public: 38 public:
39 /** enumeration for describing how an event recurs, if at all. */ 39 /** enumeration for describing how an event recurs, if at all. */
40 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003, 40 enum { rNone = 0, rMinutely = 0x001, rHourly = 0x0002, rDaily = 0x0003,
41 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006, 41 rWeekly = 0x0004, rMonthlyPos = 0x0005, rMonthlyDay = 0x0006,
42 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 }; 42 rYearlyMonth = 0x0007, rYearlyDay = 0x0008, rYearlyPos = 0x0009 };
43 43
44 /** Enumeration for specifying what date yearly recurrences of February 29th occur 44 /** Enumeration for specifying what date yearly recurrences of February 29th occur
45 * in non-leap years. */ 45 * in non-leap years. */
46 enum Feb29Type { 46 enum Feb29Type {
47 rMar1, // recur on March 1st (default) 47 rMar1, // recur on March 1st (default)
48 rFeb28, // recur on February 28th 48 rFeb28, // recur on February 28th
49 rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years 49 rFeb29 // only recur on February 29th, i.e. don't recur in non-leap years
50 }; 50 };
51 51
52 /** structure for Recurs rMonthlyPos */ 52 /** structure for Recurs rMonthlyPos */
53 struct rMonthPos { 53 struct rMonthPos {
54 QBitArray rDays; 54 QBitArray rDays;
55 short rPos; 55 short rPos;
56 bool negative; 56 bool negative;
57 }; 57 };
58 58
59 Recurrence(Incidence *parent, int compatVersion = 0); 59 Recurrence(Incidence *parent, int compatVersion = 0);
60 Recurrence(const Recurrence&, Incidence *parent); 60 Recurrence(const Recurrence&, Incidence *parent);
61 ~Recurrence(); 61 ~Recurrence();
62 62
63 bool operator==( const Recurrence& ) const; 63 bool operator==( const Recurrence& ) const;
64 bool operator!=( const Recurrence& r ) const { return !operator==(r); } 64 bool operator!=( const Recurrence& r ) const { return !operator==(r); }
65 65
66 Incidence *parent() { return mParent; } 66 Incidence *parent() { return mParent; }
67 67
68 /** Return the start of the recurrence */ 68 /** Return the start of the recurrence */
69 QDateTime recurStart() const { return mRecurStart; } 69 QDateTime recurStart() const { return mRecurStart; }
70 /** Returns the number of exception dates for the recurrence */ 70 /** Returns the number of exception dates for the recurrence */
71 int recurExDatesCount() const { return mRecurExDatesCount; } 71 int recurExDatesCount() const { return mRecurExDatesCount; }
72 /** Set start of recurrence, as a date and time. */ 72 /** Set start of recurrence, as a date and time. */
73 void setRecurStart(const QDateTime &start); 73 void setRecurStart(const QDateTime &start);
74 /** Set start of recurrence, as a date with no time. 74 /** Set start of recurrence, as a date with no time.
75 * Recurrence types which are sub-daily (e.g. rHourly) always have a time; 75 * Recurrence types which are sub-daily (e.g. rHourly) always have a time;
76 * the time is set to 00:00:00 in these cases. */ 76 * the time is set to 00:00:00 in these cases. */
77 void setRecurStart(const QDate &start); 77 void setRecurStart(const QDate &start);
78 /** Set whether the recurrence has no time, just a date. 78 /** Set whether the recurrence has no time, just a date.
79 * Recurrence types which are sub-daily (e.g. rHourly) always have a time 79 * Recurrence types which are sub-daily (e.g. rHourly) always have a time
80 * and cannot be set to float. 80 * and cannot be set to float.
81 * N.B. This property is derived by default from the parent incidence, 81 * N.B. This property is derived by default from the parent incidence,
82 * or according to whether a time is specified in setRecurStart(). */ 82 * or according to whether a time is specified in setRecurStart(). */
83 void setFloats(bool f); 83 void setFloats(bool f);
84 /** 84 /**
85 Returns whether the recurrence has no time, just a date. 85 Returns whether the recurrence has no time, just a date.
86 */ 86 */
87 bool doesFloat() const { 87 bool doesFloat() const {
88 return mFloats; 88 return mFloats;
89 } 89 }
90 90
91 /** Set if recurrence is read-only or can be changed. */ 91 /** Set if recurrence is read-only or can be changed. */
92 void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; } 92 void setRecurReadOnly(bool readOnly) { mRecurReadOnly = readOnly; }
93 bool recurReadOnly() const 93 bool recurReadOnly() const
94 { 94 {
95 return mRecurReadOnly; 95 return mRecurReadOnly;
96 } 96 }
97 97
98 98
99 /** Set number of exception dates. */ 99 /** Set number of exception dates. */
100 void setRecurExDatesCount(int count) { if (count >= 0) mRecurExDatesCount = count; } 100 void setRecurExDatesCount(int count) { if (count >= 0) mRecurExDatesCount = count; }
101 /** Set the calendar file version for backwards compatibility. 101 /** Set the calendar file version for backwards compatibility.
102 * @var version is the KOrganizer/libkcal version, e.g. 220 for KDE 2.2.0. 102 * @var version is the KOrganizer/libkcal version, e.g. 220 for KDE 2.2.0.
103 * Specify version = 0 to cancel compatibility mode. 103 * Specify version = 0 to cancel compatibility mode.
104 */ 104 */
105 void setCompatVersion(int version = 0); 105 void setCompatVersion(int version = 0);
106 106
107 /** Returns the event's recurrence status. See the enumeration at the top 107 /** Returns the event's recurrence status. See the enumeration at the top
108 * of this file for possible values. */ 108 * of this file for possible values. */
109 ushort doesRecur() const; 109 ushort doesRecur() const;
110 /** Returns true if the date specified is one on which the event will 110 /** Returns true if the date specified is one on which the event will
111 * recur. */ 111 * recur. */
112 bool recursOnPure(const QDate &qd) const; 112 bool recursOnPure(const QDate &qd) const;
113 /** Returns true if the date/time specified is one at which the event will 113 /** Returns true if the date/time specified is one at which the event will
114 * recur. Times are rounded down to the nearest minute to determine the result. */ 114 * recur. Times are rounded down to the nearest minute to determine the result. */
115 bool recursAtPure(const QDateTime &) const; 115 bool recursAtPure(const QDateTime &) const;
116 /** Turns off recurrence for the event. */ 116 /** Turns off recurrence for the event. */
117 void unsetRecurs(); 117 void unsetRecurs();
118 118
119 /** Returns the date of the next recurrence, after the specified date. 119 /** Returns the date of the next recurrence, after the specified date.
120 * @var preDate the date after which to find the recurrence. 120 * @var preDate the date after which to find the recurrence.
121 * @var last if non-null, *last is set to true if the next recurrence is the 121 * @var last if non-null, *last is set to true if the next recurrence is the
122 * last recurrence, else false. 122 * last recurrence, else false.
123 * Reply = date of next recurrence, or invalid date if none. 123 * Reply = date of next recurrence, or invalid date if none.
124 */ 124 */
125 QDate getNextDate(const QDate& preDate, bool* last = 0) const; 125 QDate getNextDate(const QDate& preDate, bool* last = 0) const;
126 /** Returns the date and time of the next recurrence, after the specified date/time. 126 /** Returns the date and time of the next recurrence, after the specified date/time.
127 * If the recurrence has no time, the next date after the specified date is returned. 127 * If the recurrence has no time, the next date after the specified date is returned.
128 * @var preDate the date/time after which to find the recurrence. 128 * @var preDate the date/time after which to find the recurrence.
129 * @var last if non-null, *last is set to true if the next recurrence is the 129 * @var last if non-null, *last is set to true if the next recurrence is the
130 * last recurrence, else false. 130 * last recurrence, else false.
131 * Reply = date/time of next recurrence, or invalid date if none. 131 * Reply = date/time of next recurrence, or invalid date if none.
132 */ 132 */
133 QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const; 133 QDateTime getNextDateTime(const QDateTime& preDateTime, bool* last = 0) const;
134 /** Returns the date of the last previous recurrence, before the specified date. 134 /** Returns the date of the last previous recurrence, before the specified date.
135 * @var afterDate the date before which to find the recurrence. 135 * @var afterDate the date before which to find the recurrence.
136 * @var last if non-null, *last is set to true if the previous recurrence is the 136 * @var last if non-null, *last is set to true if the previous recurrence is the
137 * last recurrence, else false. 137 * last recurrence, else false.
138 * Reply = date of previous recurrence, or invalid date if none. 138 * Reply = date of previous recurrence, or invalid date if none.
139 */ 139 */
140 QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const; 140 QDate getPreviousDate(const QDate& afterDate, bool* last = 0) const;
141 /** Returns the date and time of the last previous recurrence, before the specified date/time. 141 /** Returns the date and time of the last previous recurrence, before the specified date/time.
142 * If a time later than 00:00:00 is specified and the recurrence has no time, 00:00:00 on 142 * If a time later than 00:00:00 is specified and the recurrence has no time, 00:00:00 on
143 * the specified date is returned if that date recurs. 143 * the specified date is returned if that date recurs.
144 * @var afterDate the date/time before which to find the recurrence. 144 * @var afterDate the date/time before which to find the recurrence.
145 * @var last if non-null, *last is set to true if the previous recurrence is the 145 * @var last if non-null, *last is set to true if the previous recurrence is the
146 * last recurrence, else false. 146 * last recurrence, else false.
147 * Reply = date/time of previous recurrence, or invalid date if none. 147 * Reply = date/time of previous recurrence, or invalid date if none.
148 */ 148 */
149 QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const; 149 QDateTime getPreviousDateTime(const QDateTime& afterDateTime, bool* last = 0) const;
150 150
151 /** Returns frequency of recurrence, in terms of the recurrence time period type. */ 151 /** Returns frequency of recurrence, in terms of the recurrence time period type. */
152 int frequency() const; 152 int frequency() const;
153 /** Returns the total number of recurrences, including the initial occurrence. */ 153 /** Returns the total number of recurrences, including the initial occurrence. */
154 int duration() const; 154 int duration() const;
155 /** Sets the total number of times the event is to occur, including both the 155 /** Sets the total number of times the event is to occur, including both the
156 * first and last. */ 156 * first and last. */
157 void setDuration(int duration); 157 void setDuration(int duration);
158 /** Returns the number of recurrences up to and including the date specified. */ 158 /** Returns the number of recurrences up to and including the date specified. */
159 int durationTo(const QDate &) const; 159 int durationTo(const QDate &) const;
160 /** Returns the number of recurrences up to and including the date/time specified. */ 160 /** Returns the number of recurrences up to and including the date/time specified. */
161 int durationTo(const QDateTime &) const; 161 int durationTo(const QDateTime &) const;
162 162
163 /** Returns the date of the last recurrence. 163 /** Returns the date of the last recurrence.
164 * An invalid date is returned if the recurrence has no end. 164 * An invalid date is returned if the recurrence has no end.
165 * Note: for some recurrence types, endDate() can involve significant calculation. 165 * Note: for some recurrence types, endDate() can involve significant calculation.
166 */ 166 */
167 QDate endDate() const; 167 QDate endDate() const;
168 /** Returns the date and time of the last recurrence. 168 /** Returns the date and time of the last recurrence.
169 * An invalid date is returned if the recurrence has no end. 169 * An invalid date is returned if the recurrence has no end.
170 * Note: for some recurrence types, endDateTime() can involve significant calculation. 170 * Note: for some recurrence types, endDateTime() can involve significant calculation.
171 */ 171 */
172 QDateTime endDateTime() const; 172 QDateTime endDateTime() const;
173 /** Returns a string representing the recurrence end date in the format 173 /** Returns a string representing the recurrence end date in the format
174 according to the user's locale settings. */ 174 according to the user's locale settings. */
175 QString endDateStr(bool shortfmt=true) const; 175 QString endDateStr(bool shortfmt=true) const;
176 176
177 /** Sets an event to recur minutely. 177 /** Sets an event to recur minutely.
178 * @var _rFreq the frequency to recur, e.g. 2 is every other minute 178 * @var _rFreq the frequency to recur, e.g. 2 is every other minute
179 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 179 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
180 */ 180 */
181 void setMinutely(int _rFreq, int duration); 181 void setMinutely(int _rFreq, int duration);
182 /** Sets an event to recur minutely. 182 /** Sets an event to recur minutely.
183 * @var _rFreq the frequency to recur, e.g. 2 is every other minute 183 * @var _rFreq the frequency to recur, e.g. 2 is every other minute
184 * @var endDateTime the ending date/time after which to stop recurring 184 * @var endDateTime the ending date/time after which to stop recurring
185 */ 185 */
186 void setMinutely(int _rFreq, const QDateTime &endDateTime); 186 void setMinutely(int _rFreq, const QDateTime &endDateTime);
187 187
188 /** Sets an event to recur hourly. 188 /** Sets an event to recur hourly.
189 * @var _rFreq the frequency to recur, e.g. 2 is every other hour 189 * @var _rFreq the frequency to recur, e.g. 2 is every other hour
190 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 190 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
191 */ 191 */
192 void setHourly(int _rFreq, int duration); 192 void setHourly(int _rFreq, int duration);
193 /** Sets an event to recur hourly. 193 /** Sets an event to recur hourly.
194 * @var _rFreq the frequency to recur, e.g. 2 is every other hour 194 * @var _rFreq the frequency to recur, e.g. 2 is every other hour
195 * @var endDateTime the ending date/time after which to stop recurring 195 * @var endDateTime the ending date/time after which to stop recurring
196 */ 196 */
197 void setHourly(int _rFreq, const QDateTime &endDateTime); 197 void setHourly(int _rFreq, const QDateTime &endDateTime);
198 198
199 /** Sets an event to recur daily. 199 /** Sets an event to recur daily.
200 * @var _rFreq the frequency to recur, e.g. 2 is every other day 200 * @var _rFreq the frequency to recur, e.g. 2 is every other day
201 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 201 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
202 */ 202 */
203 void setDaily(int _rFreq, int duration); 203 void setDaily(int _rFreq, int duration);
204 /** Sets an event to recur daily. 204 /** Sets an event to recur daily.
205 * @var _rFreq the frequency to recur, e.g. 2 is every other day 205 * @var _rFreq the frequency to recur, e.g. 2 is every other day
206 * @var endDate the ending date after which to stop recurring 206 * @var endDate the ending date after which to stop recurring
207 */ 207 */
208 void setDaily(int _rFreq, const QDate &endDate); 208 void setDaily(int _rFreq, const QDate &endDate);
209 209
210 /** Sets an event to recur weekly. 210 /** Sets an event to recur weekly.
211 * @var _rFreq the frequency to recur, e.g. every other week etc. 211 * @var _rFreq the frequency to recur, e.g. every other week etc.
212 * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). 212 * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday).
213 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 213 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
214 * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). 214 * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday).
215 */ 215 */
216 void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1); 216 void setWeekly(int _rFreq, const QBitArray &_rDays, int duration, int weekStart = 1);
217 /** Sets an event to recur weekly. 217 /** Sets an event to recur weekly.
218 * @var _rFreq the frequency to recur, e.g. every other week etc. 218 * @var _rFreq the frequency to recur, e.g. every other week etc.
219 * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday). 219 * @var _rDays a 7 bit array indicating which days on which to recur (bit 0 = Monday).
220 * @var endDate the date on which to stop recurring. 220 * @var endDate the date on which to stop recurring.
221 * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday). 221 * @var weekStart the first day of the week (Monday=1 .. Sunday=7, default is Monday).
222 */ 222 */
223 void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1); 223 void setWeekly(int _rFreq, const QBitArray &_rDays, const QDate &endDate, int weekStart = 1);
224 /** Returns the first day of the week. Monday=1 .. Sunday=7. */ 224 /** Returns the first day of the week. Monday=1 .. Sunday=7. */
225 int weekStart() const { return rWeekStart; } 225 int weekStart() const { return rWeekStart; }
226 /** Returns week day mask (bit 0 = Monday). */ 226 /** Returns week day mask (bit 0 = Monday). */
227 const QBitArray &days() const; 227 const QBitArray &days() const;
228 228
229 /** Sets an event to recur monthly. 229 /** Sets an event to recur monthly.
230 * @var type rMonthlyPos or rMonthlyDay 230 * @var type rMonthlyPos or rMonthlyDay
231 * @var _rFreq the frequency to recur, e.g. 3 for every third month. 231 * @var _rFreq the frequency to recur, e.g. 3 for every third month.
232 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 232 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
233 */ 233 */
234 void setMonthly(short type, int _rFreq, int duration); 234 void setMonthly(short type, int _rFreq, int duration);
235 /** same as above, but with ending date not number of recurrences */ 235 /** same as above, but with ending date not number of recurrences */
236 void setMonthly(short type, int _rFreq, const QDate &endDate); 236 void setMonthly(short type, int _rFreq, const QDate &endDate);
237 /** Adds a position to the recursMonthlyPos recurrence rule, if it is 237 /** Adds a position to the recursMonthlyPos recurrence rule, if it is
238 * set. 238 * set.
239 * @var _rPos the position in the month for the recurrence, with valid 239 * @var _rPos the position in the month for the recurrence, with valid
240 * values being 1-5 (5 weeks max in a month). 240 * values being 1-5 (5 weeks max in a month).
241 * @var _rDays the days for the position to recur on (bit 0 = Monday). 241 * @var _rDays the days for the position to recur on (bit 0 = Monday).
242 * Example: _rPos = 2, and bits 0 and 2 are set in _rDays: 242 * Example: _rPos = 2, and bits 0 and 2 are set in _rDays:
243 * the rule is to repeat every 2nd Monday and Wednesday in the month. 243 * the rule is to repeat every 2nd Monday and Wednesday in the month.
244 */ 244 */
245 void addMonthlyPos(short _rPos, const QBitArray &_rDays); 245 void addMonthlyPos(short _rPos, const QBitArray &_rDays);
246 /** Adds a position the the recursMonthlyDay list. 246 /** Adds a position the the recursMonthlyDay list.
247 * @var _rDay the date in the month to recur. 247 * @var _rDay the date in the month to recur.
248 */ 248 */
249 void addMonthlyDay(short _rDay); 249 void addMonthlyDay(short _rDay);
250 /** Returns list of day positions in months. */ 250 /** Returns list of day positions in months. */
251 const QPtrList<rMonthPos> &monthPositions() const; 251 const QPtrList<rMonthPos> &monthPositions() const;
252 /** Returns list of day numbers of a month. */ 252 /** Returns list of day numbers of a month. */
253 const QPtrList<int> &monthDays() const; 253 const QPtrList<int> &monthDays() const;
254 254
255 /** Sets an event to recur yearly. 255 /** Sets an event to recur yearly.
256 * @var type rYearlyMonth, rYearlyPos or rYearlyDay 256 * @var type rYearlyMonth, rYearlyPos or rYearlyDay
257 * @var freq the frequency to recur, e.g. 3 for every third year. 257 * @var freq the frequency to recur, e.g. 3 for every third year.
258 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 258 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
259 */ 259 */
260 void setYearly(int type, int freq, int duration); 260 void setYearly(int type, int freq, int duration);
261 /** Sets an event to recur yearly ending at \a endDate. */ 261 /** Sets an event to recur yearly ending at \a endDate. */
262 void setYearly(int type, int freq, const QDate &endDate); 262 void setYearly(int type, int freq, const QDate &endDate);
263 /** Sets an event to recur yearly on specified dates. 263 /** Sets an event to recur yearly on specified dates.
264 * The dates must be specified by calling addYearlyNum(). 264 * The dates must be specified by calling addYearlyNum().
265 * @var type the way recurrences of February 29th are to be handled in non-leap years. 265 * @var type the way recurrences of February 29th are to be handled in non-leap years.
266 * @var freq the frequency to recur, e.g. 3 for every third year. 266 * @var freq the frequency to recur, e.g. 3 for every third year.
267 * @var duration the number of times the event is to occur, or -1 to recur indefinitely. 267 * @var duration the number of times the event is to occur, or -1 to recur indefinitely.
268 */ 268 */
269 void setYearlyByDate(Feb29Type type, int freq, int duration); 269 void setYearlyByDate(Feb29Type type, int freq, int duration);
270 /** Sets an event to recur yearly ending at \a endDate. */ 270 /** Sets an event to recur yearly ending at \a endDate. */
271 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate); 271 void setYearlyByDate(Feb29Type type, int freq, const QDate &endDate);
272 /** Adds position of day or month in year. 272 /** Adds position of day or month in year.
273 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called 273 * N.B. for recursYearlyPos, addYearlyMonthPos() must also be called
274 * to add positions within the month. */ 274 * to add positions within the month. */
275 void addYearlyNum(short _rNum); 275 void addYearlyNum(short _rNum);
276 /** Adds a position to the recursYearlyPos recurrence rule, if it is set. 276 /** Adds a position to the recursYearlyPos recurrence rule, if it is set.
277 * N.B. addYearlyNum() must also be called to add recurrence months. 277 * N.B. addYearlyNum() must also be called to add recurrence months.
278 * Parameters are the same as for addMonthlyPos(). 278 * Parameters are the same as for addMonthlyPos().
279 */ 279 */
280 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays); 280 void addYearlyMonthPos(short _rPos, const QBitArray &_rDays);
281 /** Returns positions of days or months in year. */ 281 /** Returns positions of days or months in year. */
282 const QPtrList<int> &yearNums() const; 282 const QPtrList<int> &yearNums() const;
283 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */ 283 /** Returns list of day positions in months, for a recursYearlyPos recurrence rule. */
284 const QPtrList<rMonthPos> &yearMonthPositions() const; 284 const QPtrList<rMonthPos> &yearMonthPositions() const;
285 /** Returns how yearly recurrences of February 29th are handled. */ 285 /** Returns how yearly recurrences of February 29th are handled. */
286 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; } 286 Feb29Type feb29YearlyType() const { return mFeb29YearlyType; }
287 /** Sets the default method for handling yearly recurrences of February 29th. */ 287 /** Sets the default method for handling yearly recurrences of February 29th. */
288 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; } 288 static void setFeb29YearlyTypeDefault(Feb29Type t) { mFeb29YearlyDefaultType = t; }
289 /** Returns the default method for handling yearly recurrences of February 29th. */ 289 /** Returns the default method for handling yearly recurrences of February 29th. */
290 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; } 290 static Feb29Type setFeb29YearlyTypeDefault() { return mFeb29YearlyDefaultType; }
291 291 void addYearlyMonth(short _rPos ); // added LR
292 /** 292 /**
293 Debug output. 293 Debug output.
294 */ 294 */
295 void dump() const; 295 void dump() const;
296 QString recurrenceText() const; 296 QString recurrenceText() const;
297 bool getYearlyMonthMonths(int day, QValueList<int>&,
298 QValueList<int> &leaplist) const;
297 299
298 protected: 300 protected:
299 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE }; 301 enum PeriodFunc { END_DATE_AND_COUNT, COUNT_TO_DATE, NEXT_AFTER_DATE };
300 struct MonthlyData; friend struct MonthlyData; 302 struct MonthlyData; friend struct MonthlyData;
301 struct YearlyMonthData; friend struct YearlyMonthData; 303 struct YearlyMonthData; friend struct YearlyMonthData;
302 struct YearlyPosData; friend struct YearlyPosData; 304 struct YearlyPosData; friend struct YearlyPosData;
303 struct YearlyDayData; friend struct YearlyDayData; 305 struct YearlyDayData; friend struct YearlyDayData;
304 306
305 bool recursSecondly(const QDate &, int secondFreq) const; 307 bool recursSecondly(const QDate &, int secondFreq) const;
306 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const; 308 bool recursMinutelyAt(const QDateTime &dt, int minuteFreq) const;
307 bool recursDaily(const QDate &) const; 309 bool recursDaily(const QDate &) const;
308 bool recursWeekly(const QDate &) const; 310 bool recursWeekly(const QDate &) const;
309 bool recursMonthly(const QDate &) const; 311 bool recursMonthly(const QDate &) const;
310 bool recursYearlyByMonth(const QDate &) const; 312 bool recursYearlyByMonth(const QDate &) const;
311 bool recursYearlyByPos(const QDate &) const; 313 bool recursYearlyByPos(const QDate &) const;
312 bool recursYearlyByDay(const QDate &) const; 314 bool recursYearlyByDay(const QDate &) const;
313 315
314 QDate getNextDateNoTime(const QDate& preDate, bool* last) const; 316 QDate getNextDateNoTime(const QDate& preDate, bool* last) const;
315 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const; 317 QDate getPreviousDateNoTime(const QDate& afterDate, bool* last) const;
316 318
317 void addMonthlyPos_(short _rPos, const QBitArray &_rDays); 319 void addMonthlyPos_(short _rPos, const QBitArray &_rDays);
318 void setDailySub(short type, int freq, int duration); 320 void setDailySub(short type, int freq, int duration);
319 void setYearly_(short type, Feb29Type, int freq, int duration); 321 void setYearly_(short type, Feb29Type, int freq, int duration);
320 int recurCalc(PeriodFunc, QDate &enddate) const; 322 int recurCalc(PeriodFunc, QDate &enddate) const;
321 int recurCalc(PeriodFunc, QDateTime &endtime) const; 323 int recurCalc(PeriodFunc, QDateTime &endtime) const;
322 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const; 324 int secondlyCalc(PeriodFunc, QDateTime& endtime, int freq) const;
323 int dailyCalc(PeriodFunc, QDate &enddate) const; 325 int dailyCalc(PeriodFunc, QDate &enddate) const;
324 int weeklyCalc(PeriodFunc, QDate &enddate) const; 326 int weeklyCalc(PeriodFunc, QDate &enddate) const;
325 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const; 327 int weeklyCalcEndDate(QDate& enddate, int daysPerWeek) const;
326 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const; 328 int weeklyCalcToDate(const QDate& enddate, int daysPerWeek) const;
327 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const; 329 int weeklyCalcNextAfter(QDate& enddate, int daysPerWeek) const;
328 int monthlyCalc(PeriodFunc, QDate &enddate) const; 330 int monthlyCalc(PeriodFunc, QDate &enddate) const;
329 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const; 331 int monthlyCalcEndDate(QDate& enddate, MonthlyData&) const;
330 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const; 332 int monthlyCalcToDate(const QDate& enddate, MonthlyData&) const;
331 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const; 333 int monthlyCalcNextAfter(QDate& enddate, MonthlyData&) const;
332 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const; 334 int yearlyMonthCalc(PeriodFunc, QDate &enddate) const;
333 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const; 335 int yearlyMonthCalcEndDate(QDate& enddate, YearlyMonthData&) const;
334 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const; 336 int yearlyMonthCalcToDate(const QDate& enddate, YearlyMonthData&) const;
335 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const; 337 int yearlyMonthCalcNextAfter(QDate& enddate, YearlyMonthData&) const;
336 int yearlyPosCalc(PeriodFunc, QDate &enddate) const; 338 int yearlyPosCalc(PeriodFunc, QDate &enddate) const;
337 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const; 339 int yearlyPosCalcEndDate(QDate& enddate, YearlyPosData&) const;
338 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const; 340 int yearlyPosCalcToDate(const QDate& enddate, YearlyPosData&) const;
339 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const; 341 int yearlyPosCalcNextAfter(QDate& enddate, YearlyPosData&) const;
340 int yearlyDayCalc(PeriodFunc, QDate &enddate) const; 342 int yearlyDayCalc(PeriodFunc, QDate &enddate) const;
341 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const; 343 int yearlyDayCalcEndDate(QDate& enddate, YearlyDayData&) const;
342 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const; 344 int yearlyDayCalcToDate(const QDate& enddate, YearlyDayData&) const;
343 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const; 345 int yearlyDayCalcNextAfter(QDate& enddate, YearlyDayData&) const;
344 346
345 int countMonthlyPosDays() const; 347 int countMonthlyPosDays() const;
346 void getMonthlyPosDays(QValueList<int>&, int daysInMonth, 348 void getMonthlyPosDays(QValueList<int>&, int daysInMonth,
347 int startDayOfWeek) const; 349 int startDayOfWeek) const;
348 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const; 350 bool getMonthlyDayDays(QValueList<int>&, int daysInMonth) const;
349 bool getYearlyMonthMonths(int day, QValueList<int>&,
350 QValueList<int> &leaplist) const;
351 351
352 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const; 352 int getFirstDayInWeek(int startDay, bool useWeekStart = true) const;
353 int getLastDayInWeek(int endDay, bool useWeekStart = true) const; 353 int getLastDayInWeek(int endDay, bool useWeekStart = true) const;
354 QDate getFirstDateInMonth(const QDate& earliestDate) const; 354 QDate getFirstDateInMonth(const QDate& earliestDate) const;
355 QDate getLastDateInMonth(const QDate& latestDate) const; 355 QDate getLastDateInMonth(const QDate& latestDate) const;
356 QDate getFirstDateInYear(const QDate& earliestDate) const; 356 QDate getFirstDateInYear(const QDate& earliestDate) const;
357 QDate getLastDateInYear(const QDate& latestDate) const; 357 QDate getLastDateInYear(const QDate& latestDate) const;
358 358
359 private: 359 private:
360 // Prohibit copying 360 // Prohibit copying
361 Recurrence(const Recurrence&); 361 Recurrence(const Recurrence&);
362 Recurrence &operator=(const Recurrence&); 362 Recurrence &operator=(const Recurrence&);
363 363
364 short recurs; // should be one of the enums. 364 short recurs; // should be one of the enums.
365 365
366 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7 366 int rWeekStart; // day which starts the week, Monday=1 .. Sunday=7
367 QBitArray rDays; // array of days during week it recurs 367 QBitArray rDays; // array of days during week it recurs
368 368
369 QPtrList<rMonthPos> rMonthPositions; // list of positions during a month 369 QPtrList<rMonthPos> rMonthPositions; // list of positions during a month
370 // on which an event recurs 370 // on which an event recurs
371 371
372 QPtrList<int> rMonthDays; // list of days during a month on 372 QPtrList<int> rMonthDays; // list of days during a month on
373 // which the event recurs 373 // which the event recurs
374 374
375 QPtrList<int> rYearNums; // either months/days to recur on for rYearly, 375 QPtrList<int> rYearNums; // either months/days to recur on for rYearly,
376 // sorted in numerical order 376 // sorted in numerical order
377 377
378 int rFreq; // frequency of period 378 int rFreq; // frequency of period
379 379
380 // one of the following must be specified 380 // one of the following must be specified
381 int rDuration; // num times to recur (inc. first occurrence), -1 = infinite 381 int rDuration; // num times to recur (inc. first occurrence), -1 = infinite
382 QDateTime rEndDateTime; // date/time at which to end recurrence 382 QDateTime rEndDateTime; // date/time at which to end recurrence
383 383
384 QDateTime mRecurStart; // date/time of first recurrence 384 QDateTime mRecurStart; // date/time of first recurrence
385 bool mFloats; // the recurrence has no time, just a date 385 bool mFloats; // the recurrence has no time, just a date
386 bool mRecurReadOnly; 386 bool mRecurReadOnly;
387 int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded 387 int mRecurExDatesCount; // number of recurrences (in addition to rDuration) which are excluded
388 Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th 388 Feb29Type mFeb29YearlyType; // how to handle yearly recurrences of February 29th
389 static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType 389 static Feb29Type mFeb29YearlyDefaultType; // default value for mFeb29YearlyType
390 390
391 // Backwards compatibility for KDE < 3.1. 391 // Backwards compatibility for KDE < 3.1.
392 int mCompatVersion; // calendar file version for backwards compatibility 392 int mCompatVersion; // calendar file version for backwards compatibility
393 short mCompatRecurs; // original 'recurs' in old calendar format, or rNone 393 short mCompatRecurs; // original 'recurs' in old calendar format, or rNone
394 int mCompatDuration; // original 'rDuration' in old calendar format, or 0 394 int mCompatDuration; // original 'rDuration' in old calendar format, or 0
395 395
396 Incidence *mParent; 396 Incidence *mParent;
397}; 397};
398 398
399} 399}
400 400
401#endif 401#endif