⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 event.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
  day it would repeat on does not exist to \a b.  An example would be a repeating event that occures on the 31st of each month.  Setting showOnNearest to TRUE will have the event show up on the 30th on  months that do not have 31 days, (or 28/29 in the case of Febuary).  \sa showOnNearest()*/void PimEvent::setShowOnNearest( bool b){    mShowOnNearest = b;}/*!  If the repeat type of the event is Weekly and the event is set to repeat on  \a day of the week, then returns TRUE.  Otherwise returns FALSE.  \sa setRepeatOnWeekDay()*/bool PimEvent::repeatOnWeekDay(int day) const{    if (repeatType() != Weekly)	return FALSE;    if (day == mStart.date().dayOfWeek())	return TRUE; // always repeat on the start day of week.    return ((1 << (day - 1) & weekMask) != 0);}/*!  Sets the event to repeat on the \a day of the wekif \a enable is TRUE.  Otherwise sets the event not to repeat on the \a day of the week.  Event will always repeat on the day of the week that it started on.  \sa repeatOnWeekDay()*/void PimEvent::setRepeatOnWeekDay(int day, bool enable){    if (repeatOnWeekDay(day) != enable)	weekMask ^= 1 << (day - 1);}// helper functionsint monthsTo(const QDate &from, const QDate &to){    int result = 12 * (to.year() - from.year());    result += (to.month() - from.month());    return result;}// weeks is the number of times this dayOfWeek of the// week appears in the month for this date.int weeksForDayInMonth(int dayOfWeek, const QDate &date){    QDate result;    result.setYMD(date.year(), date.month(), 1);    int dayOfMonth = result.dayOfWeek();    int fromStart = dayOfWeek - dayOfMonth;    if (fromStart < 0)	fromStart += 7;    return (result.daysInMonth() - fromStart - 1) / 7 + 1;}/*! \fn PimEvent::seriesUid() const  If the event is an exception to a recuring event  returns the UID for the event this event is an exception to.  Otherwise returns the UID of this event.  \sa hasExceptions(), isException()*//*!  Returns TRUE if this event represents an exception to the repeat  pattern of another event.  Otherwise returns FALSE.    For example if a daily event at 10am  starts on 11am one day, the 11am would be represent an exception  to the 10am repeating event.  \sa hasExceptions(), seriesUid()*/bool PimEvent::isException() const{    return !mParent.isNull();}/*!  Returns TRUE if the event is a repeating event   that has exceptions to the repeat pattern for that event.  Otherwise returns FALSE.  \sa isException(), seriesUid()*/bool PimEvent::hasExceptions() const{    return !mExceptions.isEmpty();}/*! \internal */void PimEvent::setSeriesUid( const QUuid &u ){    mParent = u;}/*! \internal */void PimEvent::addException( const QDate &d, const QUuid &u ){    mExceptions.append(d);    mChildren.append(u);}/*!  Returns TRUE if the event can occur.  Otherwise returns FALSE.*/bool PimEvent::isValid() const{    bool ok;    nextOccurrence(start().date(), &ok);    if ( !ok && mChildren.isEmpty() )  {	// no longer exist!	return FALSE;    }    return TRUE;}/*! \internal */void PimEvent::clearExceptions(){    mExceptions.clear();    mChildren.clear();}/*! \internal */void PimEvent::removeException( const QDate &d ){    QValueList<QDate>::Iterator eit = mExceptions.begin();    QValueList<QUuid>::Iterator cit = mChildren.begin();    for(; eit != mExceptions.end() && cit != mChildren.end(); ++eit, ++cit) {	if (*eit == d) {	    mExceptions.remove(eit);	    mChildren.remove(cit);	    break;	}    }}/*! \internal */void PimEvent::removeException( const QUuid &u ){    QValueList<QDate>::Iterator eit = mExceptions.begin();    QValueList<QUuid>::Iterator cit = mChildren.begin();    for(; eit != mExceptions.end() && cit != mChildren.end(); ++eit, ++cit) {	if (*cit == u) {	    mExceptions.remove(eit);	    mChildren.remove(cit);	    break;	}    }}/*!  Returns the first date on or after \a from that the event will next occur.  If the event only occurs once (no repeat) will return the date of the  start of the event if the start of the event is on or after \a from.  If \a ok is non-NULL, *ok is set to TRUE if the event occurs on or  after \a from and FALSE if the event does not occur on or after  \a from.*/QDate PimEvent::nextOccurrence( const QDate &from, bool *ok) const{    bool stillLooking;    QDate looking = p_nextOccurrence(from, &stillLooking);    while (stillLooking && mExceptions.contains(looking)) {	looking = p_nextOccurrence(looking.addDays(p_duration()), &stillLooking);    }    if (ok)	*ok = stillLooking;    return looking;}int PimEvent::p_duration() const{    return mStart.daysTo(mEnd) + 1;}/*!  \internal  Does the work of nextOccurence, apart from the exception check*/QDate PimEvent::p_nextOccurrence( const QDate &from, bool *ok) const{    QDate result = mStart.date();    // from should be for the start of the possible event.    QDate after = from.addDays(mEnd.daysTo(mStart));    if (result >= after) {	if (ok)	    *ok = TRUE;	return result;    }    if (!repeatForever() && repeatTill() < after) {	if (ok)	    *ok = FALSE;	return result;    }    switch(mType) {	default:	    if (ok)		*ok = FALSE;	    return result;	case NoRepeat:	    if (ok)		*ok = FALSE;	    return result;	case Daily:	    {		int daysBetween = mStart.daysTo(after);		int outBy = daysBetween % mFrequency;		if (outBy) {		    // this is in the wrong direction;		    outBy = mFrequency - outBy;		}		result = after.addDays(outBy);	    }	    break;	case Weekly:	    {		// first do a quick check to see if it i possble that there		// is an overlap.		int diff = result.daysTo(after);		int mod = diff % (mFrequency * 7);		// if diff is < 7, it may be not the day of week of the start		// day.  Check.  Don't look more than 6 days after the start		// day.		if (mod < 7) {		    // go after % to 6.  if day of week match, to a normal but		    // start with that day.		    for (int i = mod; i < 7; i++) {			if (repeatOnWeekDay(result.addDays(i).dayOfWeek())) {			    // move result forward to that week day			    result = result.addDays(i);			    break;			}		    }		}		// Now treat as a regular, daily, Freq*7 event.		// Remember, new result may now be after after.  Check		int daysBetween = result.daysTo(after);		if (daysBetween > 0) {		    int outBy = daysBetween % (mFrequency * 7);		    if (outBy) {			outBy = (mFrequency * 7) - outBy;		    }		    result = after.addDays(outBy);		}	    }	    break;	case MonthlyDate:	    {		int monthsBetween = monthsTo(mStart.date(), after);		// check to see if will be in after month.		if (mStart.date().day() < after.day()) {		    // wont be in after month, move to the next month.		    monthsBetween++;		    after = Calendar::addMonths(1, after);		}		int outBy = monthsBetween % mFrequency;		if (outBy) {		    outBy = mFrequency - outBy;		}		result = Calendar::addMonths(outBy, after);		if (mShowOnNearest) {		    if (mStart.date().day() < result.daysInMonth())			result.setYMD(result.year(), result.month(), mStart.date().day());		    else			result.setYMD(result.year(), result.month(), result.daysInMonth());		} else {		    // can't show on nearest, when is the next valid date.		    while (!QDate::isValid(				result.year(), result.month(), mStart.date().day())			    ) {			result = Calendar::addMonths(mFrequency, result);		    }		    result.setYMD(result.year(), result.month(), mStart.date().day());		}	    }	    break;	case MonthlyDay:	case MonthlyEndDay:	    {		// + for MonthlyDay, - for MonthlyEndDay.		// otherwise these are basically the same.		int mWeekOffset = weekOffset();		int monthsBetween = monthsTo(mStart.date(), after);		int outBy = monthsBetween % mFrequency;		if (outBy) {		    outBy = mFrequency - outBy;		}		result = Calendar::addMonths(outBy, after);		// this is tricky.  Need to move by mFreq months till we		// get a good one.		bool foundDate = FALSE;		while(!foundDate) {		    int day;		    int weeks = weeksForDayInMonth(mStart.date().dayOfWeek(), result);		    // get to first day for that day of week.		    int weekShift = mStart.date().dayOfWeek()			- QDate(result.year(), result.month(), 1).dayOfWeek();		    if (weekShift < 0)			weekShift += 7;		    if (mWeekOffset > 0) {			day = (mWeekOffset - 1) * 7 + 1 + weekShift;		    } else {			day = (weeks + mWeekOffset) * 7 + 1 + weekShift;		    }		    if (mShowOnNearest) {			if (day > result.daysInMonth())			    day -= 7;			if (day < 1)			    day += 7;		    } else {			if (day > result.daysInMonth() || day < 1) {			    result = Calendar::addMonths(mFrequency, result);			    continue;			}		    }		    result.setYMD(result.year(), result.month(), day);		    if (result < after)			result = Calendar::addMonths(mFrequency, result);		    else			foundDate = TRUE; // success.		}	    }	    break;	case Yearly:	    {		int yearsBetween = after.year() - mStart.date().year();		int outBy = yearsBetween % mFrequency;		if (outBy) {		    outBy = mFrequency - outBy;		}		result = Calendar::addYears(yearsBetween + outBy, mStart.date());		if (result < after)		    result = Calendar::addYears(mFrequency, result);		// at least after, may not be valid though.		if (!mShowOnNearest) {		    while (!QDate::isValid(result.year(), result.month(), mStart.date().day()))			result = Calendar::addYears(mFrequency, result);		    result.setYMD(result.year(), result.month(), mStart.date().day());		}	    }	    break;    }    if (ok)	*ok = (result <= repeatTill() || repeatForever());    return result;}// In pimrecord.cppvoid qpe_startVObjectInput();bool qpe_vobjectCompatibility(const char* misfeature);void qpe_endVObjectInput();void qpe_startVObjectOutput();void qpe_setVObjectProperty(const QString&, const QString&, const char* type, PimRecord*);void qpe_endVObjectOutput(VObject *,const char* type,const PimRecord*);VObject *qpe_safeAddPropValue( VObject *o, const char *prop, const QString &value );static inline VObject *safeAddPropValue( VObject *o, const char *prop, const QString &value ){ return qpe_safeAddPropValue(o,prop,value); }VObject *qpe_safeAddProp( VObject *o, const char *prop);static inline VObject *safeAddProp( VObject *o, const char *prop){ return qpe_safeAddProp(o,prop); }const char *dayToString(int d){    switch (d) {	case 1:	    return "MO ";	case 2:	    return "TU ";	case 3:	    return "WE ";	case 4:	    return "TH ";	case 5:	    return "FR ";	case 6:	    return "SA ";	case 7:	default:	    return "SU ";    }}static VObject *createVObject( const PimEvent &e ){    qpe_startVObjectOutput();    VObject *vcal = newVObject( VCCalProp );    safeAddPropValue( vcal, VCVersionProp, "1.0" );    VObject *event = safeAddProp( vcal, VCEventProp );    bool timeAsUTC = FALSE;    QString start, end;    if ( !e.isAllDay() ) {	// don't give UTC times if we don't have a timezone	timeAsUTC = e.timeZone().isValid();	start = TimeConversion::toISO8601( e.start(), timeAsUTC );	end = TimeConversion::toISO8601( e.end(), timeAsUTC );    } else {	start = TimeConversion::toISO8601( e.start().date(), FALSE );	end = TimeConversion::toISO8601( e.end().date(), FALSE );    }    safeAddPropValue( event, VCDTstartProp, start );    safeAddPropValue( event, VCDTendProp, end );    // vCal spec: VCSummaryProp is required    // Palm m100:     Yes (but accepts VCDescriptionProp VCAttachProp)    // SL5500:        No    // Ericsson T39m: Yes    if ( qpe_vobjectCompatibility("Palm-Event-DN") ) {	safeAddPropValue( event, VCDescriptionProp, e.description() );	safeAddPropValue( event, VCAttachProp, e.notes() );    } else {	safeAddPropValue( event, VCSummaryProp, e.description() );	safeAddPropValue( event, VCDescriptionProp, e.notes() );    }    safeAddPropValue( event, VCLocationProp, e.location() );    if ( e.hasAlarm() ) {	QDateTime dt = e.start();	dt = dt.addSecs( -e.alarmDelay()*60 );	VObject *alarm = safeAddProp( event, VCDAlarmProp );	safeAddPropValue( alarm, VCRunTimeProp, 		TimeConversion::toISO8601( dt, timeAsUTC ) );	if (e.alarmSound() != PimEvent::Silent)  {	    VObject *aalarm = safeAddProp( event, VCAAlarmProp );	    safeAddPropValue( aalarm, VCRunTimeProp, 		    TimeConversion::toISO8601( dt , timeAsUTC ) );	}    }    if (timeAsUTC)	safeAddPropValue( event, "X-Qtopia-TIMEZONE", e.timeZone().id() );    if (e.hasRepeat()) {	// minimal data.  if its optional and we want the default, stay quiet.	QString repeat_format;	switch (e.repeatType())	{	    default:	    case PimEvent::NoRepeat:		break;	    case PimEvent::Daily:		repeat_format = "D%1 %2";		break;	    case PimEvent::Weekly:		repeat_format = "W%1 ";		{		    for (int i = 1; i < 8; i++) {			if (e.repeatOnWeekDay(i)) {			    repeat_format += dayToString(i);			}		    }		}		repeat_format += "%2";		break;	    case PimEvent::MonthlyDate:		repeat_format = "MD%1 %2";		break;	    case PimEvent::MonthlyDay:		repeat_format = "MP%3 %1 %2%4";		repeat_format = repeat_format.arg(e.weekOffset());		repeat_format = repeat_format.arg(dayToString(e.start().date().dayOfWeek()));		// other stuff is default.		break;	    case PimEvent::MonthlyEndDay:		repeat_format = "MP%3 %1- %2%4";		repeat_format = repeat_format.arg(-e.weekOffset());		repeat_format = repeat_format.arg(dayToString(e.start().date().dayOfWeek()));		break;	    case PimEvent::Yearly:		repeat_format = "YM%1 %2";		break;	}	repeat_format = repeat_format.arg(e.frequency())	    .arg(		    e.repeatForever() ? "#0" : (const char *)TimeConversion::toISO8601(e.repeatTill(), FALSE));	safeAddPropValue( event, VCRRuleProp, repeat_format );	// Palm enters exceptions, but not their parents/not-parents.	// We will to because the uid's are meaningless outside of the little world of one	// device and one Qtopia Desktop.	if (e.hasExceptions()) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -