korganizer Library API Documentation

kdpevent.cpp

00001 // $Id: kdpevent.cpp,v 1.83 1999/07/10 17:23:21 cschumac Exp $ 00002 00003 #include <stdlib.h> 00004 #include <stdio.h> 00005 00006 #include <kapp.h> 00007 #include <klocale.h> 00008 #include <kconfig.h> 00009 00010 #include "kdpevent.h" 00011 #include "kdpevent.moc" 00012 00013 int KDPEvent::eventCount = 0; 00014 00015 bool KDPEvent::weekStartsMonday = FALSE; 00016 00017 KDPEvent::KDPEvent() 00018 : QObject() 00019 { 00020 KConfig *config; 00021 // initialize an event object 00022 00023 KDPEvent::eventCount++; 00024 id = KDPEvent::eventCount; 00025 00026 dateCreated = QDateTime::currentDateTime(); 00027 int hashTime = dateCreated.time().hour() + 00028 dateCreated.time().minute() + dateCreated.time().second() + 00029 dateCreated.time().msec(); 00030 vUID.sprintf("KOrganizer - %li.%d",random(),hashTime); 00031 00032 revisionNum = 0; 00033 relatedTo = 0; 00034 lastModified = QDateTime::currentDateTime(); 00035 00036 // KConfig now handles the cfg dir 00037 // QString cfgPath = KApplication::localconfigdir(); 00038 // cfgPath += "/korganizerrc"; 00039 00040 // config = new KConfig(cfgPath.data()); 00041 config = new KConfig("korganizerrc"); 00042 config->setGroup("Personal Settings"); 00043 organizer = config->readEntry("user_email"); 00044 if (organizer.isEmpty()) 00045 organizer = "x-none"; 00046 delete config; 00047 00048 description = ""; 00049 summary = ""; 00050 status = TENTATIVE; 00051 secrecy = PRIVATE; 00052 categories = 0; 00053 attachments = 0; 00054 resources = 0; 00055 00056 audioAlarmFile = ""; 00057 programAlarmFile = ""; 00058 mailAlarmAddress = ""; 00059 alarmText = ""; 00060 00061 floats = TRUE; // whether or not the event has a time attached. 00062 00063 alarmSnoozeTime = 5; 00064 alarmRepeatCount = 0; // alarm disabled 00065 00066 priority = 0; 00067 transparency = 0; 00068 00069 recurs = rNone; // by default, it's not a recurring event. 00070 // rDays.resize(7); // can't initialize in the header 00071 rMonthDays.setAutoDelete(TRUE); 00072 rMonthPositions.setAutoDelete(TRUE); 00073 rYearNums.setAutoDelete(TRUE); 00074 exDates.setAutoDelete(TRUE); 00075 categories.setAutoDelete(TRUE); 00076 attachments.setAutoDelete(TRUE); 00077 attendeeList.setAutoDelete(TRUE); 00078 resources.setAutoDelete(TRUE); 00079 00080 pilotId = 0; 00081 syncStatus = 1; 00082 00083 ro = FALSE; 00084 } 00085 00086 KDPEvent::~KDPEvent() 00087 { 00088 KDPEvent::eventCount--; 00089 } 00090 00091 inline void KDPEvent::setOrganizer(const char *o) 00092 { 00093 // we don't check for readonly here, because it is 00094 // possible that by setting the organizer we are changing 00095 // the event's readonly status... 00096 organizer = o; 00097 if (organizer.left(7).upper() == "MAILTO:") 00098 organizer = organizer.remove(0,7); 00099 emit eventUpdated(this); 00100 } 00101 00102 inline void KDPEvent::setOrganizer(const QString &o) 00103 { 00104 setOrganizer(o.data()); 00105 } 00106 00107 inline const QString &KDPEvent::getOrganizer() const 00108 { 00109 return organizer; 00110 } 00111 00112 inline void KDPEvent::addAttendee(Attendee *a) 00113 { 00114 if (ro) return; 00115 if (a->name.left(7).upper() == "MAILTO:") 00116 a->name = a->name.remove(0,7); 00117 00118 attendeeList.append(a); 00119 emit eventUpdated(this); 00120 } 00121 00122 inline void KDPEvent::removeAttendee(Attendee *a) 00123 { 00124 if (ro) return; 00125 attendeeList.removeRef(a); 00126 emit eventUpdated(this); 00127 } 00128 00129 inline void KDPEvent::removeAttendee(const char *n) 00130 { 00131 Attendee *a; 00132 00133 if (ro) return; 00134 for (a = attendeeList.first(); a; a = attendeeList.next()) 00135 if (a->getName() == n) { 00136 attendeeList.remove(); 00137 break; 00138 } 00139 } 00140 00141 inline void KDPEvent::clearAttendees() 00142 { 00143 if (ro) return; 00144 attendeeList.clear(); 00145 } 00146 00147 Attendee *KDPEvent::getAttendee(const char *n) const 00148 { 00149 QListIterator<Attendee> qli(attendeeList); 00150 00151 qli.toFirst(); 00152 while (qli) { 00153 if (qli.current()->getName() == n) 00154 return qli.current(); 00155 ++qli; 00156 } 00157 return 0L; 00158 } 00159 00160 inline void KDPEvent::setDtStart(const QDateTime &dtStart) 00161 { 00162 int diffsecs = KDPEvent::dtStart.secsTo(dtStart); 00163 00164 if (ro) return; 00165 if (alarmRepeatCount) 00166 alarmTime = alarmTime.addSecs(diffsecs); 00167 00168 KDPEvent::dtStart = dtStart; 00169 emit eventUpdated(this); 00170 } 00171 00172 inline void KDPEvent::setDtStart(const QString &dtStartStr) 00173 { 00174 QDateTime tmpDt(strToDateTime(dtStartStr)); 00175 int diffsecs = KDPEvent::dtStart.secsTo(tmpDt); 00176 00177 if (ro) return; 00178 if (alarmRepeatCount) 00179 alarmTime = alarmTime.addSecs(diffsecs); 00180 00181 KDPEvent::dtStart = tmpDt; 00182 emit eventUpdated(this); 00183 } 00184 00185 inline const QDateTime &KDPEvent::getDtStart() const 00186 { 00187 return dtStart; 00188 } 00189 00190 inline QString KDPEvent::getDtStartTimeStr() const 00191 { 00192 QString timeStr; 00193 00194 timeStr.sprintf("%02d:%02d",dtStart.time().hour(), 00195 dtStart.time().minute()); 00196 return timeStr; 00197 00198 } 00199 00200 inline QString KDPEvent::getDtStartDateStr() const 00201 { 00202 QString dateStr; 00203 00204 dateStr.sprintf("%.2d %3s %4d",dtStart.date().day(), 00205 (const char*)dtStart.date().monthName(dtStart.date().month()), 00206 dtStart.date().year()); 00207 return dateStr; 00208 } 00209 00210 inline void KDPEvent::setDtEnd(const QDateTime &dtEnd) 00211 { 00212 if (ro) return; 00213 KDPEvent::dtEnd = dtEnd; 00214 emit eventUpdated(this); 00215 } 00216 00217 inline void KDPEvent::setDtEnd(const QString &dtEndStr) 00218 { 00219 if (ro) return; 00220 KDPEvent::dtEnd = strToDateTime(dtEndStr); 00221 emit eventUpdated(this); 00222 } 00223 00224 inline const QDateTime &KDPEvent::getDtEnd() const 00225 { 00226 return dtEnd; 00227 } 00228 00229 inline QString KDPEvent::getDtEndTimeStr() const 00230 { 00231 QString timeStr; 00232 00233 timeStr.sprintf("%02d:%02d",dtEnd.time().hour(), 00234 dtEnd.time().minute()); 00235 return timeStr; 00236 00237 } 00238 00239 inline QString KDPEvent::getDtEndDateStr() const 00240 { 00241 QString dateStr; 00242 00243 dateStr.sprintf("%.2d %3s %4d",dtEnd.date().day(), 00244 (const char*)dtEnd.date().monthName(dtEnd.date().month()), 00245 dtEnd.date().year()); 00246 return dateStr; 00247 } 00248 00249 inline bool KDPEvent::doesFloat() const 00250 { 00251 return floats; 00252 } 00253 00254 inline void KDPEvent::setFloats(bool f) 00255 { 00256 if (ro) return; 00257 floats = f; 00258 emit eventUpdated(this); 00259 } 00260 00261 inline void KDPEvent::setDescription(const QString &description) 00262 { 00263 if (ro) return; 00264 KDPEvent::description = description; 00265 emit eventUpdated(this); 00266 } 00267 00268 inline void KDPEvent::setDescription(const char *description) 00269 { 00270 if (ro) return; 00271 KDPEvent::description = description; 00272 emit eventUpdated(this); 00273 } 00274 00275 inline const QString &KDPEvent::getDescription() const 00276 { 00277 return description; 00278 } 00279 00280 inline void KDPEvent::setSummary(const QString &summary) 00281 { 00282 if (ro) return; 00283 KDPEvent::summary = summary.data(); // so it gets detached 00284 emit eventUpdated(this); 00285 } 00286 00287 inline void KDPEvent::setSummary(const char *summary) 00288 { 00289 if (ro) return; 00290 KDPEvent::summary = summary; 00291 emit eventUpdated(this); 00292 } 00293 00294 inline const QString &KDPEvent::getSummary() const 00295 { 00296 return summary; 00297 } 00298 00299 void KDPEvent::setStatus(const QString &statStr) 00300 { 00301 if (ro) return; 00302 QString ss(statStr.upper()); 00303 00304 if (ss == "X-ACTION") 00305 status = NEEDS_ACTION; 00306 else if (ss == "NEEDS ACTION") 00307 status = NEEDS_ACTION; 00308 else if (ss == "ACCEPTED") 00309 status = ACCEPTED; 00310 else if (ss == "SENT") 00311 status = SENT; 00312 else if (ss == "TENTATIVE") 00313 status = TENTATIVE; 00314 else if (ss == "CONFIRMED") 00315 status = CONFIRMED; 00316 else if (ss == "DECLINED") 00317 status = DECLINED; 00318 else if (ss == "COMPLETED") 00319 status = COMPLETED; 00320 else if (ss == "DELEGATED") 00321 status = DELEGATED; 00322 else 00323 debug("error setting status, unknown status!"); 00324 00325 emit eventUpdated(this); 00326 } 00327 00328 inline void KDPEvent::setStatus(int status) 00329 { 00330 if (ro) return; 00331 KDPEvent::status = status; 00332 emit eventUpdated(this); 00333 } 00334 00335 inline int KDPEvent::getStatus() const 00336 { 00337 return status; 00338 } 00339 00340 QString KDPEvent::getStatusStr() const 00341 { 00342 switch(status) { 00343 case NEEDS_ACTION: 00344 return QString("NEEDS ACTION"); 00345 break; 00346 case ACCEPTED: 00347 return QString("ACCEPTED"); 00348 break; 00349 case SENT: 00350 return QString("SENT"); 00351 break; 00352 case TENTATIVE: 00353 return QString("TENTATIVE"); 00354 break; 00355 case CONFIRMED: 00356 return QString("CONFIRMED"); 00357 break; 00358 case DECLINED: 00359 return QString("DECLINED"); 00360 break; 00361 case COMPLETED: 00362 return QString("COMPLETED"); 00363 break; 00364 case DELEGATED: 00365 return QString("DELEGATED"); 00366 break; 00367 } 00368 return QString(""); 00369 } 00370 00371 void KDPEvent::setSecrecy(const QString &secStr) 00372 { 00373 if (ro) return; 00374 if (secStr == "PUBLIC") 00375 secrecy = PUBLIC; 00376 else if (secStr == "PRIVATE") 00377 secrecy = PRIVATE; 00378 else if (secStr == "CONFIDENTIAL") 00379 secrecy = CONFIDENTIAL; 00380 else 00381 debug("Unknown secrecy value specified!"); 00382 00383 emit eventUpdated(this); 00384 } 00385 00386 void KDPEvent::setSecrecy(const char *secStr) 00387 { 00388 if (ro) return; 00389 QString sec = secStr; 00390 setSecrecy(sec.toInt()); 00391 } 00392 00393 void KDPEvent::setSecrecy(int sec) 00394 { 00395 if (ro) return; 00396 secrecy = sec; 00397 emit eventUpdated(this); 00398 } 00399 00400 inline int KDPEvent::getSecrecy() const 00401 { 00402 return secrecy; 00403 } 00404 00405 QString KDPEvent::getSecrecyStr() const 00406 { 00407 switch (secrecy) { 00408 case PUBLIC: 00409 return QString("PUBLIC"); 00410 break; 00411 case PRIVATE: 00412 return QString("PRIVATE"); 00413 break; 00414 case CONFIDENTIAL: 00415 return QString("CONFIDENTIAL"); 00416 break; 00417 } 00418 // should never reach here... 00419 return QString(""); 00420 } 00421 00422 inline void KDPEvent::setCategories(const QStrList &categories) 00423 { 00424 if (ro) return; 00425 KDPEvent::categories = categories; 00426 emit eventUpdated(this); 00427 } 00428 00429 void KDPEvent::setCategories(const QString &catStr) 00430 { 00431 if (ro) return; 00432 QStrList tmpList; 00433 int index1 = 0; 00434 int index2 = 0; 00435 00436 while ((index2 = catStr.find(',', index1)) != -1) { 00437 tmpList.append(catStr.mid(index1, index2-index1).data()); 00438 index1 = index2 + 1; 00439 } 00440 // get last category 00441 tmpList.append(catStr.mid(index1, (catStr.length()-index1))); 00442 categories = tmpList; 00443 emit eventUpdated(this); 00444 } 00445 00446 inline const QStrList &KDPEvent::getCategories() const 00447 { 00448 return categories; 00449 } 00450 00451 QString KDPEvent::getCategoriesStr() 00452 { 00453 QString temp; 00454 QString cat; 00455 bool first = TRUE; 00456 for (cat = categories.first(); cat; cat = categories.next()) { 00457 if (!first) { 00458 temp += ","; 00459 } else { 00460 first = FALSE; 00461 } 00462 temp += cat; 00463 } 00464 return temp; 00465 } 00466 00467 inline void KDPEvent::setAttachments(const QStrList &attachments) 00468 { 00469 if (ro) return; 00470 KDPEvent::attachments = attachments; 00471 emit eventUpdated(this); 00472 } 00473 00474 inline const QStrList &KDPEvent::getAttachments() const 00475 { 00476 return attachments; 00477 } 00478 00479 inline void KDPEvent::setResources(const QStrList &resources) 00480 { 00481 if (ro) return; 00482 KDPEvent::resources = resources; 00483 emit eventUpdated(this); 00484 } 00485 00486 inline const QStrList &KDPEvent::getResources() const 00487 { 00488 return resources; 00489 } 00490 00491 inline void KDPEvent::setAudioAlarmFile(const QString &audioAlarmFile) 00492 { 00493 if (ro) return; 00494 KDPEvent::audioAlarmFile = audioAlarmFile; 00495 emit eventUpdated(this); 00496 } 00497 00498 inline void KDPEvent::setAudioAlarmFile(const char *audioAlarmFile) 00499 { 00500 if (ro) return; 00501 KDPEvent::audioAlarmFile = audioAlarmFile; 00502 emit eventUpdated(this); 00503 } 00504 00505 inline const QString &KDPEvent::getAudioAlarmFile() const 00506 { 00507 return audioAlarmFile; 00508 } 00509 00510 inline void KDPEvent::setProgramAlarmFile(const QString &programAlarmFile) 00511 { 00512 if (ro) return; 00513 KDPEvent::programAlarmFile = programAlarmFile; 00514 emit eventUpdated(this); 00515 } 00516 00517 inline void KDPEvent::setProgramAlarmFile(const char *programAlarmFile) 00518 { 00519 if (ro) return; 00520 KDPEvent::programAlarmFile = programAlarmFile; 00521 emit eventUpdated(this); 00522 } 00523 00524 inline const QString &KDPEvent::getProgramAlarmFile() const 00525 { 00526 return programAlarmFile; 00527 } 00528 00529 inline void KDPEvent::setMailAlarmAddress(const QString &mailAlarmAddress) 00530 { 00531 if (ro) return; 00532 KDPEvent::mailAlarmAddress = mailAlarmAddress; 00533 emit eventUpdated(this); 00534 } 00535 00536 inline void KDPEvent::setMailAlarmAddress(const char *mailAlarmAddress) 00537 { 00538 if (ro) return; 00539 KDPEvent::mailAlarmAddress = mailAlarmAddress; 00540 emit eventUpdated(this); 00541 } 00542 00543 inline const QString &KDPEvent::getMailAlarmAddress() const 00544 { 00545 return mailAlarmAddress; 00546 } 00547 00548 inline void KDPEvent::setAlarmText(const QString &alarmText) 00549 { 00550 if (ro) return; 00551 KDPEvent::alarmText = alarmText.data(); // so it gets detached 00552 emit eventUpdated(this); 00553 } 00554 00555 inline void KDPEvent::setAlarmText(const char *alarmText) 00556 { 00557 if (ro) return; 00558 KDPEvent::alarmText = alarmText; 00559 emit eventUpdated(this); 00560 } 00561 00562 inline const QString &KDPEvent::getAlarmText() const 00563 { 00564 return alarmText; 00565 } 00566 00567 inline void KDPEvent::setAlarmTime(const QDateTime &alarmTime) 00568 { 00569 if (ro) return; 00570 KDPEvent::alarmTime = alarmTime; 00571 emit eventUpdated(this); 00572 } 00573 00574 inline void KDPEvent::setAlarmTime(const QString &alarmTimeStr) 00575 { 00576 if (ro) return; 00577 KDPEvent::alarmTime = strToDateTime(alarmTimeStr); 00578 emit eventUpdated(this); 00579 } 00580 00581 inline const QDateTime &KDPEvent::getAlarmTime() const 00582 { 00583 return alarmTime; 00584 } 00585 00586 inline void KDPEvent::setAlarmSnoozeTime(int alarmSnoozeTime) 00587 { 00588 if (ro) return; 00589 KDPEvent::alarmSnoozeTime = alarmSnoozeTime; 00590 emit eventUpdated(this); 00591 } 00592 00593 inline int KDPEvent::getAlarmSnoozeTime() const 00594 { 00595 return alarmSnoozeTime; 00596 } 00597 00598 inline void KDPEvent::setAlarmRepeatCount(int alarmRepeatCount) 00599 { 00600 if (ro) return; 00601 KDPEvent::alarmRepeatCount = alarmRepeatCount; 00602 emit eventUpdated(this); 00603 } 00604 00605 inline int KDPEvent::getAlarmRepeatCount() const 00606 { 00607 return alarmRepeatCount; 00608 } 00609 00610 inline void KDPEvent::toggleAlarm() 00611 { 00612 if (ro) return; 00613 if (alarmRepeatCount) { 00614 alarmRepeatCount = 0; 00615 } else { 00616 alarmRepeatCount = 1; 00617 KConfig *config(kapp->getConfig()); 00618 config->setGroup("Time & Date"); 00619 QString alarmStr(config->readEntry("Default Alarm Time", "15")); 00620 int pos = alarmStr.find(' '); 00621 if (pos >= 0) 00622 alarmStr.truncate(pos); 00623 alarmTime = dtStart.addSecs(-60 * alarmStr.toUInt()); 00624 } 00625 emit eventUpdated(this); 00626 } 00627 00628 inline void KDPEvent::setPriority(int priority) 00629 { 00630 if (ro) return; 00631 KDPEvent::priority = priority; 00632 emit eventUpdated(this); 00633 } 00634 00635 inline int KDPEvent::getPriority() const 00636 { 00637 return priority; 00638 } 00639 00640 inline void KDPEvent::setTransparency(int transparency) 00641 { 00642 if (ro) return; 00643 KDPEvent::transparency = transparency; 00644 emit eventUpdated(this); 00645 } 00646 00647 inline int KDPEvent::getTransparency() const 00648 { 00649 return transparency; 00650 } 00651 00652 inline void KDPEvent::setRelatedTo(int relatedTo) 00653 { 00654 if (ro) return; 00655 KDPEvent::relatedTo = relatedTo; 00656 emit eventUpdated(this); 00657 } 00658 00659 inline int KDPEvent::getRelatedTo() const 00660 { 00661 return relatedTo; 00662 } 00663 00664 inline void KDPEvent::setEventId(int id) 00665 { 00666 KDPEvent::id = id; 00667 emit eventUpdated(this); 00668 } 00669 00670 inline int KDPEvent::getEventId() const 00671 { 00672 return id; 00673 } 00674 00675 inline void KDPEvent::setVUID(const char *vUID) 00676 { 00677 KDPEvent::vUID = vUID; 00678 emit eventUpdated(this); 00679 } 00680 00681 inline const QString &KDPEvent::getVUID() const 00682 { 00683 return vUID; 00684 } 00685 00686 inline void KDPEvent::setRevisionNum(int rev) 00687 { 00688 if (ro) return; 00689 revisionNum = rev; 00690 emit eventUpdated(this); 00691 } 00692 00693 inline int KDPEvent::getRevisionNum() const 00694 { 00695 return revisionNum; 00696 } 00697 00698 inline void KDPEvent::setLastModified(const QDateTime &lm) 00699 { 00700 // DON'T! emit eventUpdated because we call this from 00701 // CalObject::updateEvent(). 00702 lastModified = lm; 00703 } 00704 00705 inline const QDateTime &KDPEvent::getLastModified() const 00706 { 00707 return lastModified; 00708 } 00709 00710 inline ushort KDPEvent::doesRecur() const 00711 { 00712 return recurs; 00713 } 00714 00715 bool KDPEvent::recursOn(const QDate &qd) const 00716 { 00717 // first off, check to see if the flag is even set 00718 if (recurs == rNone) 00719 return FALSE; 00720 00721 // check if this date is on the exception list. 00722 if (recurs != rNone) { 00723 if (isException(qd)) 00724 return FALSE; 00725 } 00726 00727 // it recurs, let's check to see if this date is valid 00728 switch(recurs) { 00729 case rDaily: 00730 return recursDaily(qd); 00731 break; 00732 case rWeekly: 00733 return recursWeekly(qd); 00734 break; 00735 case rMonthlyPos: 00736 return recursMonthlyByPos(qd); 00737 break; 00738 case rMonthlyDay: 00739 return recursMonthlyByDay(qd); 00740 break; 00741 case rYearlyMonth: 00742 return recursYearlyByMonth(qd); 00743 break; 00744 case rYearlyDay: 00745 return recursYearlyByDay(qd); 00746 break; 00747 default: 00748 // catch-all. Should never get here. 00749 debug("Control should never reach here in recursOn()!"); 00750 return FALSE; 00751 break; 00752 } // case 00753 } 00754 00755 bool KDPEvent::recursDaily(const QDate &qd) const 00756 { 00757 QDate dStart = dtStart.date(); 00758 int i; 00759 00760 if ((qd >= dStart) && 00761 (((qd <= dStart.addDays((rDuration-1+exDates.count())*rFreq)) && (rDuration > 0)) || 00762 (rDuration == -1) || 00763 ((rDuration == 0) && (qd <= rEndDate)))) { 00764 i = dStart.daysTo(qd); 00765 // here's the real check... 00766 if ((i % rFreq) == 0) { 00767 return TRUE; 00768 } 00769 else // frequency didn't match 00770 return FALSE; 00771 } 00772 // the date queried fell outside the range of the event 00773 return FALSE; 00774 } 00775 00776 bool KDPEvent::recursWeekly(const QDate &qd) const 00777 { 00778 QDate dStart = dtStart.date(); 00779 int i; 00780 00781 00782 i = ((rDuration-1+exDates.count())*7) + (7 - dStart.dayOfWeek()); 00783 if ((qd >= dStart) && 00784 (((qd <= dStart.addDays(i*rFreq)) && (rDuration > 0)) || 00785 (rDuration == -1) || 00786 ((rDuration == 0) && (qd <= rEndDate)))) { 00787 // do frequency check. 00788 i = dStart.daysTo(qd)/7; 00789 if ((i % rFreq) == 0) { 00790 // check if the bits set match today. 00791 i = qd.dayOfWeek()-1; 00792 if (rDays.testBit((uint) i)) 00793 return TRUE; 00794 else 00795 return FALSE; 00796 } else // frequency didn't match 00797 return FALSE; 00798 } 00799 // the date queried fell outside the range of the event 00800 return FALSE; 00801 } 00802 00803 bool KDPEvent::recursMonthlyByDay(const QDate &qd) const 00804 { 00805 QDate dStart = dtStart.date(); 00806 int monthsAhead = 0; 00807 int i = 0; 00808 QListIterator<int> qlid(rMonthDays); 00809 // calculate how many months ahead this date is from the original 00810 // event's date 00811 00812 // calculate year's months first 00813 monthsAhead = (qd.year() - dStart.year()) * 12; 00814 00815 // calculate month offset within the year. 00816 i = qd.month() - dStart.month(); // may be positive or negative 00817 00818 monthsAhead += i; // add the month offset in 00819 00820 // check to see if the date is in the proper range 00821 if ((qd >= dStart) && 00822 (((monthsAhead <= (rDuration-1+(signed)exDates.count())*rFreq) && (rDuration > 0)) || 00823 (rDuration == -1) || 00824 ((rDuration == 0) && (qd <= rEndDate)))) { 00825 // do frequency check 00826 if ((monthsAhead % rFreq) == 0) { 00827 i = qd.day(); 00828 for (; qlid.current(); ++qlid) { 00829 if (*qlid.current() < 0) { 00830 if (i == (qd.daysInMonth()-*qlid.current()+1)) 00831 return TRUE; 00832 } else { 00833 if (i == *qlid.current()) 00834 return TRUE; 00835 } 00836 } // for loop 00837 // no dates matched, return false 00838 return FALSE; 00839 } else // frequency didn't match 00840 return FALSE; 00841 } 00842 // outsize proper date range 00843 return FALSE; 00844 } 00845 00846 bool KDPEvent::recursMonthlyByPos(const QDate &qd) const 00847 { 00848 QDate dStart = dtStart.date(); 00849 int monthsAhead = 0; 00850 int i = 0; 00851 QListIterator<rMonthPos> qlip(rMonthPositions); 00852 00853 // calculate how many months ahead this date is from the original 00854 // event's date 00855 00856 // calculate year's months first 00857 monthsAhead = (qd.year() - dStart.year()) * 12; 00858 00859 // calculate month offset within the year. 00860 i = qd.month() - dStart.month(); // may be positive or negative 00861 00862 monthsAhead += i; // add the month offset in 00863 00864 // check to see if the date is in the proper range 00865 if ((qd >= dStart) && 00866 (((monthsAhead <= (rDuration-1+(signed)exDates.count())*rFreq) && (rDuration > 0)) || 00867 (rDuration == -1) || 00868 ((rDuration == 0) && (qd <= rEndDate)))) { 00869 // do frequency check 00870 if ((monthsAhead % rFreq) == 0) { 00871 i = weekOfMonth(qd); 00872 // check to see if this day of the week isn't found in the first 00873 // week of the month. 00874 QDate first(qd.year(), qd.month(), 1); 00875 if (qd.dayOfWeek() < first.dayOfWeek()) 00876 --i; 00877 00878 // now loop through the list of modifiers, and check them 00879 // all against the day of the month 00880 for (; qlip.current(); ++qlip) { 00881 if (qlip.current()->negative) { 00882 i = 5 - i; // convert to negative offset format 00883 } 00884 // check position offset 00885 if (i == qlip.current()->rPos) { 00886 // check day(s) 00887 if (qlip.current()->rDays.testBit((uint) qd.dayOfWeek()-1)) 00888 return TRUE; 00889 } // if position test 00890 } // for loop 00891 // no dates matched as true, must be false. 00892 return FALSE; 00893 } else // frequency didn't match 00894 return FALSE; 00895 } 00896 // the date queried fell outside the range of the event 00897 return FALSE; 00898 } 00899 00900 bool KDPEvent::recursYearlyByMonth(const QDate &qd) const 00901 { 00902 QDate dStart = dtStart.date(); 00903 int yearsAhead = 0; 00904 int i = 0; 00905 QListIterator<int> qlin(rYearNums); 00906 00907 // calculate how many years ahead this date is from the original 00908 // event's date 00909 00910 yearsAhead = (qd.year() - dStart.year()); 00911 00912 // check to see if the date is in the proper range 00913 if ((qd >= dStart) && 00914 (((yearsAhead <= (rDuration-1+(signed)exDates.count())*rFreq) && (rDuration > 0)) || 00915 (rDuration == -1) || 00916 ((rDuration == 0) && (qd <= rEndDate)))) { 00917 // do frequency check 00918 if ((yearsAhead % rFreq) == 0) { 00919 i = qd.month(); 00920 for (; qlin.current(); ++qlin) { 00921 if (i == *qlin.current()) 00922 if (qd.day() == dStart.day()) 00923 return TRUE; 00924 } 00925 // no dates matched, return false 00926 return FALSE; 00927 } else 00928 // frequency didn't match 00929 return FALSE; 00930 } // outside proper date range 00931 return FALSE; 00932 } 00933 00934 bool KDPEvent::recursYearlyByDay(const QDate &qd) const 00935 { 00936 QDate dStart = dtStart.date(); 00937 int yearsAhead = 0; 00938 int i = 0; 00939 QListIterator<int> qlin(rYearNums); 00940 00941 // calculate how many years ahead this date is from the original 00942 // event's date 00943 00944 yearsAhead = (qd.year() - dStart.year()); 00945 00946 // check to see if date is in the proper range 00947 if ((qd >= dStart) && 00948 (((yearsAhead <= (rDuration-1+(signed)exDates.count())*rFreq) && (rDuration > 0)) || 00949 (rDuration == -1) || 00950 ((rDuration == 0) && (qd <= rEndDate)))) { 00951 // do frequency check 00952 if ((yearsAhead % rFreq) == 0) { 00953 i = qd.dayOfYear(); 00954 // correct for leapYears 00955 if (!QDate::leapYear(dStart.year()) && 00956 QDate::leapYear(qd.year()) && 00957 qd > QDate(qd.year(), 2, 28)) 00958 --i; 00959 if (QDate::leapYear(dStart.year()) && 00960 !QDate::leapYear(qd.year()) && 00961 qd > QDate(qd.year(), 2, 28)) 00962 ++i; 00963 00964 for (; qlin.current(); ++qlin) { 00965 if (i == *qlin.current()) 00966 return TRUE; 00967 } 00968 // no dates matched, return false 00969 return FALSE; 00970 } else 00971 // frequency didn't match 00972 return FALSE; 00973 } // outside allowable date range 00974 return FALSE; 00975 } 00976 00977 void KDPEvent::unsetRecurs() 00978 { 00979 if (ro) return; 00980 recurs = rNone; 00981 rMonthPositions.clear(); 00982 rMonthDays.clear(); 00983 rYearNums.clear(); 00984 } 00985 00986 void KDPEvent::setRecursDaily(int _rFreq, int _rDuration) 00987 { 00988 if (ro) return; 00989 recurs = rDaily; 00990 00991 rFreq = _rFreq; 00992 rDuration = _rDuration; 00993 rMonthPositions.clear(); 00994 rMonthDays.clear(); 00995 rYearNums.clear(); 00996 emit eventUpdated(this); 00997 } 00998 00999 void KDPEvent::setRecursDaily(int _rFreq, const QDate &_rEndDate) 01000 { 01001 if (ro) return; 01002 recurs = rDaily; 01003 01004 rFreq = _rFreq; 01005 rEndDate = _rEndDate; 01006 rDuration = 0; // set to 0 because there is an end date 01007 rMonthPositions.clear(); 01008 rMonthDays.clear(); 01009 rYearNums.clear(); 01010 emit eventUpdated(this); 01011 } 01012 01013 inline int KDPEvent::getRecursFrequency() const 01014 { 01015 return rFreq; 01016 } 01017 01018 inline int KDPEvent::getRecursDuration() const 01019 { 01020 return rDuration; 01021 } 01022 01023 inline const QDate &KDPEvent::getRecursEndDate() const 01024 { 01025 return rEndDate; 01026 } 01027 01028 inline QString KDPEvent::getRecursEndDateStr() const 01029 { 01030 QString dateStr; 01031 01032 dateStr.sprintf("%.2d %3s %4d",rEndDate.day(), 01033 (const char*)rEndDate.monthName(rEndDate.month()), 01034 rEndDate.year()); 01035 return dateStr; 01036 } 01037 01038 inline const QBitArray &KDPEvent::getRecursDays() const 01039 { 01040 return rDays; 01041 } 01042 01043 inline const QList<KDPEvent::rMonthPos> &KDPEvent::getRecursMonthPositions() const 01044 { 01045 return rMonthPositions; 01046 } 01047 01048 inline const QList<int> &KDPEvent::getRecursMonthDays() const 01049 { 01050 return rMonthDays; 01051 } 01052 01053 void KDPEvent::setRecursWeekly(int _rFreq, const QBitArray &_rDays, 01054 int _rDuration) 01055 { 01056 if (ro) return; 01057 recurs = rWeekly; 01058 01059 rFreq = _rFreq; 01060 rDays = _rDays; 01061 rDuration = _rDuration; 01062 rMonthPositions.clear(); 01063 rMonthDays.clear(); 01064 emit eventUpdated(this); 01065 } 01066 01067 void KDPEvent::setRecursWeekly(int _rFreq, const QBitArray &_rDays, 01068 const QDate &_rEndDate) 01069 { 01070 if (ro) return; 01071 recurs = rWeekly; 01072 01073 rFreq = _rFreq; 01074 rDays = _rDays; 01075 rEndDate = _rEndDate; 01076 rDuration = 0; // set to 0 because there is an end date 01077 rMonthPositions.clear(); 01078 rMonthDays.clear(); 01079 rYearNums.clear(); 01080 emit eventUpdated(this); 01081 } 01082 01083 void KDPEvent::setRecursMonthly(short type, int _rFreq, int _rDuration) 01084 { 01085 if (ro) return; 01086 recurs = type; 01087 01088 rFreq = _rFreq; 01089 rDuration = _rDuration; 01090 rYearNums.clear(); 01091 emit eventUpdated(this); 01092 } 01093 01094 void KDPEvent::setRecursMonthly(short type, int _rFreq, 01095 const QDate &_rEndDate) 01096 { 01097 if (ro) return; 01098 recurs = type; 01099 01100 rFreq = _rFreq; 01101 rEndDate = _rEndDate; 01102 rDuration = 0; // set to 0 because there is an end date 01103 rYearNums.clear(); 01104 emit eventUpdated(this); 01105 } 01106 01107 void KDPEvent::addRecursMonthlyPos(short _rPos, const QBitArray &_rDays) 01108 { 01109 if (ro) return; 01110 rMonthPos *tmpPos = new rMonthPos; 01111 tmpPos->negative = FALSE; 01112 if (_rPos < 0) { 01113 _rPos = 0 - _rPos; // take abs() 01114 tmpPos->negative = TRUE; 01115 } 01116 tmpPos->rPos = _rPos; 01117 tmpPos->rDays = _rDays; 01118 rMonthPositions.append(tmpPos); 01119 emit eventUpdated(this); 01120 } 01121 01122 void KDPEvent::addRecursMonthlyDay(short _rDay) 01123 { 01124 if (ro) return; 01125 int *tmpDay = new int; 01126 *tmpDay = _rDay; 01127 rMonthDays.append(tmpDay); 01128 emit eventUpdated(this); 01129 } 01130 01131 void KDPEvent::setRecursYearly(int type, int _rFreq, int _rDuration) 01132 { 01133 if (ro) return; 01134 recurs = type; 01135 01136 rFreq = _rFreq; 01137 rDuration = _rDuration; 01138 rMonthPositions.clear(); 01139 rMonthDays.clear(); 01140 emit eventUpdated(this); 01141 } 01142 01143 void KDPEvent::setRecursYearly(int type, int _rFreq, const QDate &_rEndDate) 01144 { 01145 if (ro) return; 01146 recurs = type; 01147 01148 rFreq = _rFreq; 01149 rEndDate = _rEndDate; 01150 rDuration = 0; 01151 rMonthPositions.clear(); 01152 rMonthDays.clear(); 01153 emit eventUpdated(this); 01154 } 01155 01156 inline const QList<int> &KDPEvent::getRecursYearNums() const 01157 { 01158 return rYearNums; 01159 } 01160 01161 void KDPEvent::addRecursYearlyNum(short _rNum) 01162 { 01163 01164 if (ro) return; 01165 int *tmpNum = new int; 01166 *tmpNum = _rNum; 01167 rYearNums.append(tmpNum); 01168 emit eventUpdated(this); 01169 } 01170 01171 void KDPEvent::setExDates(const QDateList &_exDates) 01172 { 01173 if (ro) return; 01174 exDates.clear(); 01175 exDates = _exDates; 01176 emit eventUpdated(this); 01177 } 01178 01179 void KDPEvent::setExDates(const char *dates) 01180 { 01181 if (ro) return; 01182 exDates.clear(); 01183 QString tmpStr = dates; 01184 int index = 0; 01185 int index2 = 0; 01186 01187 while ((index2 = tmpStr.find(',', index)) != -1) { 01188 QDate *tmpDate = new QDate; 01189 *tmpDate = strToDate(tmpStr.mid(index, (index2-index))); 01190 01191 exDates.append(tmpDate); 01192 index = index2 + 1; 01193 } 01194 QDate *tmpDate = new QDate; 01195 *tmpDate = strToDate(tmpStr.mid(index, (tmpStr.length()-index))); 01196 exDates.inSort(tmpDate); 01197 emit eventUpdated(this); 01198 } 01199 01200 void KDPEvent::addExDate(const QDate &date) 01201 { 01202 if (ro) return; 01203 QDate *addDate = new QDate(date); 01204 exDates.inSort(addDate); 01205 emit eventUpdated(this); 01206 } 01207 01208 inline const QDateList &KDPEvent::getExDates() const 01209 { 01210 return exDates; 01211 } 01212 01213 bool KDPEvent::isException(const QDate &qd) const 01214 { 01215 QDateList tmpList(FALSE); // we want a shallow copy 01216 01217 tmpList = exDates; 01218 01219 QDate *datePtr; 01220 for (datePtr = tmpList.first(); datePtr; 01221 datePtr = tmpList.next()) { 01222 if (qd == *datePtr) { 01223 return TRUE; 01224 } 01225 } 01226 return FALSE; 01227 } 01228 01229 inline void KDPEvent::setPilotId(int id) 01230 { 01231 if (ro) return; 01232 pilotId = id; 01233 //emit eventUpdated(this); 01234 } 01235 01236 inline int KDPEvent::getPilotId() const 01237 { 01238 return pilotId; 01239 } 01240 01241 inline void KDPEvent::setSyncStatus(int stat) 01242 { 01243 if (ro) return; 01244 syncStatus = stat; 01245 // emit eventUpdated(this); 01246 } 01247 01248 inline int KDPEvent::getSyncStatus() const 01249 { 01250 return syncStatus; 01251 } 01252 01253 void KDPEvent::print(int style) const 01254 { 01255 switch(style) { 01256 case ASCII: 01257 if (doesFloat()) 01258 debug("\t\t: %s", getSummary().data()); 01259 else 01260 debug("\t%02d:%02d-%02d:%02d: %s", 01261 dtStart.time().hour(), dtStart.time().minute(), 01262 dtEnd.time().hour(), dtEnd.time().minute(), 01263 summary.data()); 01264 break; 01265 case POSTSCRIPT: 01266 break; 01267 } 01268 } 01269 01270 /***************************** PROTECTED FUNCTIONS ***************************/ 01271 01272 QDateTime KDPEvent::strToDateTime(const QString &dateStr) 01273 { 01274 // string should be in the format yyyymmddThhmmss 01275 01276 int year, month, day, hour, minute, second; 01277 QDate tmpDate; 01278 QTime tmpTime; 01279 01280 year = dateStr.left(4).toInt(); 01281 month = dateStr.mid(4, 2).toInt(); 01282 day = dateStr.mid(6, 2).toInt(); 01283 01284 hour = dateStr.mid(9, 2).toInt(); 01285 minute = dateStr.mid(11, 2).toInt(); 01286 second = dateStr.right(2).toInt(); 01287 01288 tmpDate.setYMD(year, month, day); 01289 tmpTime.setHMS(hour, minute, second); 01290 01291 return QDateTime(tmpDate, tmpTime); 01292 } 01293 01294 QDate KDPEvent::strToDate(const QString &dateStr) 01295 { 01296 01297 int year, month, day; 01298 01299 year = dateStr.left(4).toInt(); 01300 month = dateStr.mid(4,2).toInt(); 01301 day = dateStr.mid(6,2).toInt(); 01302 return(QDate(year, month, day)); 01303 } 01304 01305 // this should return the week of the month for the date 01306 int KDPEvent::weekOfMonth(const QDate &qd) const 01307 { 01308 QDate firstDate(qd.year(), qd.month(), 1); 01309 // I don't really know what formulas I'm using here. :) 01310 int firstWeekNum(1 +(firstDate.dayOfYear() - firstDate.dayOfWeek() + 6)/7); 01311 int thisWeekNum(1 +(qd.dayOfYear() - qd.dayOfWeek() + 6)/7); 01312 return (thisWeekNum - firstWeekNum + 1); 01313 } 01314 01315 void KDPEvent::updateConfig() 01316 { 01317 KConfig *config(kapp->getConfig()); 01318 config->setGroup("Time & Date"); 01319 01320 weekStartsMonday = config->readBoolEntry("Week Starts Monday", FALSE); 01321 } 01322 01323 /******************************* ATTENDEE CLASS *****************************/ 01324 // most methods have been inlined, see kdpevent.h for more information. 01325 Attendee::Attendee(const char *n, const char *e, bool _rsvp, int s, int r) 01326 { 01327 flag = TRUE; 01328 rsvp = _rsvp; 01329 name = n; 01330 email = e; 01331 status = s; 01332 role = r; 01333 } 01334 01335 Attendee::Attendee(const Attendee &a) 01336 { 01337 flag = a.flag; 01338 rsvp = a.rsvp; 01339 name = a.name.copy(); 01340 email = a.email.copy(); 01341 status = a.status; 01342 role = a.role; 01343 } 01344 01345 Attendee::~Attendee() 01346 { 01347 } 01348 01349 void Attendee::setStatus(const char *s) 01350 { 01351 QString statStr = s; 01352 statStr = statStr.upper(); 01353 01354 if (statStr == "X-ACTION") 01355 status = NEEDS_ACTION; 01356 else if (statStr == "NEEDS ACTION") 01357 status = NEEDS_ACTION; 01358 else if (statStr== "ACCEPTED") 01359 status = ACCEPTED; 01360 else if (statStr== "SENT") 01361 status = SENT; 01362 else if (statStr== "TENTATIVE") 01363 01364 status = TENTATIVE; 01365 else if (statStr== "CONFIRMED") 01366 status = CONFIRMED; 01367 else if (statStr== "DECLINED") 01368 status = DECLINED; 01369 else if (statStr== "COMPLETED") 01370 status = COMPLETED; 01371 else if (statStr== "DELEGATED") 01372 status = DELEGATED; 01373 else { 01374 debug("error setting attendee status, unknown status!"); 01375 status = NEEDS_ACTION; 01376 } 01377 } 01378 01379 QString Attendee::getStatusStr() const 01380 { 01381 switch(status) { 01382 case NEEDS_ACTION: 01383 return QString("NEEDS ACTION"); 01384 break; 01385 case ACCEPTED: 01386 return QString("ACCEPTED"); 01387 break; 01388 case SENT: 01389 return QString("SENT"); 01390 break; 01391 case TENTATIVE: 01392 return QString("TENTATIVE"); 01393 break; 01394 case CONFIRMED: 01395 return QString("CONFIRMED"); 01396 break; 01397 case DECLINED: 01398 return QString("DECLINED"); 01399 break; 01400 case COMPLETED: 01401 return QString("COMPLETED"); 01402 break; 01403 case DELEGATED: 01404 return QString("DELEGATED"); 01405 break; 01406 } 01407 return QString(""); 01408 } 01409 01410 QString Attendee::getRoleStr() const 01411 { 01412 switch(role) { 01413 case 0: 01414 return QString("Attendee"); 01415 break; 01416 case 1: 01417 return QString("Organizer"); 01418 break; 01419 case 2: 01420 return QString("Owner"); 01421 break; 01422 case 3: 01423 return QString("Delegate"); 01424 break; 01425 default: 01426 return QString("Attendee"); 01427 break; 01428 } 01429 01430 } 01431 01432 void Attendee::setRSVP(const char *r) 01433 { 01434 QString s; 01435 s = r; 01436 s = s.upper(); 01437 if (s == "TRUE") 01438 rsvp = TRUE; 01439 else 01440 rsvp = FALSE; 01441 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003