📄 event.cpp
字号:
*/time_t PimEvent::endAsUTC() const{ return asUTC(end(), timeZone());}/*! \internal*/time_t PimEvent::repeatTillAsUTC() const{ return asUTC(repeatTill(), timeZone());}/*! \internal*/void PimEvent::setStartAsUTC(time_t time){ setStart(asDateTime(time, timeZone()));}/*! \internal*/void PimEvent::setEndAsUTC(time_t time){ setEnd(asDateTime(time, timeZone()));}/*! \internal*/void PimEvent::setRepeatTillAsUTC(time_t time){ setRepeatTill(asDateTime(time, timeZone()).date());}Occurrence::Occurrence(const QDate &start, const PimEvent &ca ) : eventCache(ca), mStart(start){}PimEvent Occurrence::event() const{ return eventCache;}QDate Occurrence::endDate() const{ return date().addDays(eventCache.start().date().daysTo(eventCache.end().date()));}QDateTime Occurrence::start() const{ return QDateTime(date(), eventCache.start().time());}QDateTime Occurrence::end() const{ return QDateTime(endDate(), eventCache.end().time());}// Timezone dependent functions...QDateTime Occurrence::startInCurrentTZ() const{ if (!eventCache.timeZone().isValid()) return start(); return eventCache.timeZone().toCurrent(start());}QDateTime Occurrence::endInCurrentTZ() const{ if (!eventCache.timeZone().isValid()) return end(); QDateTime nStart = eventCache.timeZone().toCurrent(start()); return end().addSecs(start().secsTo(nStart));}// used when loading to finalize records.static time_t startUtc = 0;static time_t endUtc = 0;static time_t endDateUtc = 0;static bool hasTimeZone = FALSE;/*! \internal*/void PimEvent::setFields(const QMap<int,QString> &m){ // Reimplemenmted to handle post processing of reading an event startUtc = 0; endUtc = 0; endDateUtc = 0; hasTimeZone = FALSE; PimRecord::setFields( m ); finalizeRecord();}// post Processing.void PimEvent::finalizeRecord(){ if (!hasTimeZone) { // make one up. Can't be "None" because in old datebook all // events were in UTC. So make it the current locale. setTimeZone( TimeZone::current() ); } // if there was a timezone, it would be set by now. setStartAsUTC( startUtc ); setEndAsUTC( endUtc ); if (hasRepeat() && endDateUtc != 0 && !repeatForever()) setRepeatTillAsUTC( endDateUtc ); // 0' out elements although this will be done in assignField anyway startUtc = 0; endUtc = 0; endDateUtc = 0; hasTimeZone = FALSE;}/*! \internal Don't do flow-on values here.. gets are direct from data bypassing relavent checks, puts will be the same.*/void PimEvent::setField(int key,const QString &value){ switch( key ) { case Description: setDescription( value ); break; case Location: setLocation( value ); break; case StartTimeZone: if (value != "None") // No tr setTimeZone( TimeZone(value) ); // hasTimeZone in that one is set, even if it is none. hasTimeZone = TRUE; break; case Notes: setNotes( value ); break; case StartDateTime: startUtc = (time_t) value.toLong(); break; case EndDateTime: endUtc = (time_t) value.toLong(); break; case DatebookType: setAllDay( value == "AllDay" ); break; case HasAlarm: if ( value.contains("true", FALSE)) { // No tr mHasAlarm = TRUE; } else { mHasAlarm = FALSE; } break; case AlarmDelay: mAlarmDelay = value.toInt(); break; case SoundType: mAlarmSound = value == "loud" ? Loud : Silent; // No tr break; case RepeatPattern: if ( value == "Daily" ) // No tr setRepeatType(Daily); else if ( value == "Weekly" ) // No tr setRepeatType(Weekly); else if ( value == "MonthlyDay" ) setRepeatType(MonthlyDay); else if ( value == "MonthlyDate" ) setRepeatType(MonthlyDate); else if ( value == "MonthlyEndDay" ) setRepeatType(MonthlyEndDay); else if ( value == "Yearly" ) // No tr setRepeatType(Yearly); else setRepeatType(NoRepeat); break; case RepeatFrequency: if (value.toInt() != 0) { setFrequency( value.toInt() ); } break; case RepeatHasEndDate: if ( value.toInt() != 0 ) { setRepeatForever( FALSE ); } else { setRepeatForever( TRUE ); } break; case RepeatWeekdays: weekMask = value.toInt(); break; case RepeatEndDate: endDateUtc = (time_t) value.toLong(); break; case RecordParent: mParent = PimXmlIO::uuidFromInt(value.toInt()); break; case RecordChildren: { QStringList list = QStringList::split(' ', value); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { mChildren.append( PimXmlIO::uuidFromInt((*it).toInt()) ); } } break; case Exceptions: { QStringList list = QStringList::split(' ', value); for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) { int tday = 1, tmonth = 1, tyear = 2000; switch( (*it).length() ) { case 8: tday = (*it).right( 2 ).toInt(); case 6: tmonth = (*it).mid( 4, 2 ).toInt(); case 4: tyear = (*it).left( 4 ).toInt(); break; default: break; } //QDate date = TimeConversion::fromISO8601( QCString(*it) ).date(); QDate date(tyear, tmonth, tday); mExceptions.append( date ); } } break; default: PimRecord::setField(key, value); }}/*! \internal*/QString PimEvent::field(int key) const{ switch( key ) { case Description: return mDescription; case Location: return mLocation; case StartTimeZone: { if (timeZone().isValid()) return timeZone().id(); else return "None"; // No tr } case Notes: return mNotes; case StartDateTime: return QString::number( startAsUTC() ); case EndDateTime: return QString::number( endAsUTC() ); case DatebookType: { if ( isAllDay() ) return "AllDay"; else return "Timed"; // No tr } case HasAlarm: return hasAlarm() ? "true" : "false"; // No tr case AlarmDelay: return QString::number( alarmDelay() ); case SoundType: { if ( alarmSound() == Loud ) return "loud"; // No tr else return "silent"; // No tr } case RepeatPattern: { switch ( repeatType() ) { case Daily: return "Daily"; // No tr case Weekly: return "Weekly"; // No tr case MonthlyDay: return "MonthlyDay"; case MonthlyEndDay: return "MonthlyEndDay"; case MonthlyDate: return "MonthlyDate"; case Yearly: return "Yearly"; // No tr default: return "NoRepeat"; } } case RepeatFrequency: return QString::number( frequency() ); case RepeatHasEndDate: return QString::number( !repeatForever() ); case RepeatEndDate: return QString::number( repeatTillAsUTC() ); case RepeatWeekdays: return QString::number( weekMask ); case RecordParent: return QString::number( PimXmlIO::uuidToInt( mParent ) ); case RecordChildren: { const QValueList<QUuid> &vlc = mChildren; QValueList<QUuid>::ConstIterator cit; QString out; for( cit = vlc.begin(); cit != vlc.end(); ++cit ) { if (cit != vlc.begin()) out += " "; out += QString::number( PimXmlIO::uuidToInt(*cit) ); } return out; } case Exceptions: { const QValueList<QDate> &vle = mExceptions; QValueList<QDate>::ConstIterator eit; QString out; for( eit = vle.begin(); eit != vle.end(); ++eit ) { QDate date = *eit; if (eit != vle.begin()) out += " "; QCString str; str.sprintf("%04d%02d%02d", date.year(), date.month(), date.day()); out += str; } return out; } default: return PimRecord::field(key); }}static QMap<int, int> *uniquenessMapPtr = 0;static QMap<QCString, int> *identifierToKeyMapPtr = 0;static QMap<int, QCString> *keyToIdentifierMapPtr = 0;static QMap<int, QString> * trFieldsMapPtr = 0;QMap<int, QString> PimEvent::fields() const{ QMap<int, QString> m = PimRecord::fields(); if (!keyToIdentifierMapPtr) initMaps(); QMap<int, QCString>::Iterator it; for (it = keyToIdentifierMapPtr->begin(); it != keyToIdentifierMapPtr->end(); ++it) { int i = it.key(); QString str = field(i); if (!str.isEmpty()) m.insert(i, str); } return m;}static const QtopiaPimMapEntry datebookentries[] = { { "description", // No tr QT_TRANSLATE_NOOP("PimEvent", "Description"), PimEvent::Description, 40}, { "location", QT_TRANSLATE_NOOP("PimEvent", "Location"), PimEvent::Location, 0 }, { "timezone", QT_TRANSLATE_NOOP("PimEvent", "Time zone"), PimEvent::StartTimeZone, 0 }, { "note", QT_TRANSLATE_NOOP("PimEvent", "Notes"), PimEvent::Notes, 0 }, { "start", QT_TRANSLATE_NOOP("PimEvent", "Start Date"), PimEvent::StartDateTime, 25 }, { "end", QT_TRANSLATE_NOOP("PimEvent", "End Date"), PimEvent::EndDateTime, 25 }, { "type", NULL, PimEvent::DatebookType, 0 }, { "alarm", NULL, PimEvent::AlarmDelay, 0 }, { "balarm", NULL, PimEvent::HasAlarm, 0 }, { "sound", NULL, PimEvent::SoundType, 0 }, { "rtype", NULL, PimEvent::RepeatPattern, 10 }, { "rfreq", NULL, PimEvent::RepeatFrequency, 0 }, { "rweekdays", NULL, PimEvent::RepeatWeekdays, 0 }, { "rhasenddate", NULL, PimEvent::RepeatHasEndDate, 0 }, { "enddt", NULL, PimEvent::RepeatEndDate, 0 }, { "recparent", NULL, PimEvent::RecordParent, 0 }, { "recchildren", NULL, PimEvent::RecordChildren, 0 }, { "exceptions", NULL, PimEvent::Exceptions, 0 }, { 0, 0, 0, 0 }};void PimEvent::initMaps(){ delete keyToIdentifierMapPtr; keyToIdentifierMapPtr = new QMap<int, QCString>; delete identifierToKeyMapPtr; identifierToKeyMapPtr = new QMap<QCString, int>; delete trFieldsMapPtr; trFieldsMapPtr = new QMap<int,QString>; delete uniquenessMapPtr; uniquenessMapPtr = new QMap<int, int>; PimRecord::initMaps("PimEvent", datebookentries, *uniquenessMapPtr, *identifierToKeyMapPtr, *keyToIdentifierMapPtr, *trFieldsMapPtr ); // Datebook xml file used lowercase letters for Categories and Uid (*keyToIdentifierMapPtr)[UID_ID] = "uid"; identifierToKeyMapPtr->remove("Uid"); (*identifierToKeyMapPtr)["uid"] = UID_ID; (*keyToIdentifierMapPtr)[Categories] = "categories"; // No tr identifierToKeyMapPtr->remove("Categories"); // No tr (*identifierToKeyMapPtr)["categories"] = Categories; // No tr}/*! \internal*/const QMap<int, QCString> &PimEvent::keyToIdentifierMap(){ if ( !keyToIdentifierMapPtr ) initMaps(); return *keyToIdentifierMapPtr;}/*! \internal*/const QMap<QCString,int> &PimEvent::identifierToKeyMap(){ if ( !identifierToKeyMapPtr ) initMaps(); return *identifierToKeyMapPtr;}/*! \internal*/const QMap<int, QString> & PimEvent::trFieldsMap(){ if ( !trFieldsMapPtr ) initMaps(); return *trFieldsMapPtr;}/*! \internal*/const QMap<int,int> & PimEvent::uniquenessMap(){ if ( !uniquenessMapPtr ) initMaps(); return *uniquenessMapPtr;}#ifndef QT_NO_DATASTREAMQDataStream &operator>>( QDataStream &s, PimEvent &c ){ s >> (PimRecord&)c; s >> c.mDescription; s >> c.mLocation; s >> c.mStart; s >> c.mEnd; s >> c.mNotes; s >> c.mTimeZone; s >> c.mEndTimeZone; uchar val; s >> val; c.mHasAlarm = val == 0 ? FALSE : TRUE; s >> c.mAlarmDelay; s >> val; c.mAlarmSound = (PimEvent::SoundTypeChoice)val; s >> val; c.mType = (PimEvent::RepeatType)val; s >> c.mFrequency; s >> val; c.mHasEndDate = val == 0 ? FALSE : TRUE; s >> c.mRepeatTill; s >> val; c.mShowOnNearest = val == 0 ? FALSE : TRUE; s >> c.weekMask; s >> val; c.mAllDay = val == 0 ? FALSE : TRUE; // exceptions. s >> c.mExceptions; s >> c.mParent; s >> c.mChildren; return s;}QDataStream &operator<<( QDataStream &s, const PimEvent &c ){ s << (const PimRecord&)c; s << c.mDescription; s << c.mLocation; s << c.mStart; s << c.mEnd; s << c.mNotes; s << c.mTimeZone; s << c.mEndTimeZone; s << (c.mHasAlarm ? (uchar)1 : (uchar)0); s << c.mAlarmDelay; s << (uchar)c.mAlarmSound; s << (uchar)c.mType; s << c.mFrequency; s << (c.mHasEndDate ? (uchar)1 : (uchar)0); s << c.mRepeatTill; s << (c.mShowOnNearest ? (uchar)1 : (uchar)0); s << c.weekMask; s << (c.mAllDay ? (uchar)1 : (uchar)0); // exceptions. s << c.mExceptions; s << c.mParent; s << c.mChildren; return s;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -