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

📄 event.cpp

📁 Trolltech公司发布的图形界面操作系统。可在qt-embedded-2.3.10平台上编译为嵌入式图形界面操作系统。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/************************************************************************ Copyright (C) 2000-2005 Trolltech AS.  All rights reserved.**** This file is part of the Qtopia Environment.** ** This program is free software; you can redistribute it and/or modify it** under the terms of the GNU General Public License as published by the** Free Software Foundation; either version 2 of the License, or (at your** option) any later version.** ** A copy of the GNU GPL license version 2 is included in this package as ** LICENSE.GPL.**** This program is distributed in the hope that it will be useful, but** WITHOUT ANY WARRANTY; without even the implied warranty of** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ** See the GNU General Public License for more details.**** In addition, as a special exception Trolltech gives permission to link** the code of this program with Qtopia applications copyrighted, developed** and distributed by Trolltech under the terms of the Qtopia Personal Use** License Agreement. You must comply with the GNU General Public License** in all respects for all of the code used other than the applications** licensed under the Qtopia Personal Use License Agreement. If you modify** this file, you may extend this exception to your version of the file,** but you are not obligated to do so. If you do not wish to do so, delete** this exception statement from your version.** ** See http://www.trolltech.com/gpl/ for GPL licensing information.**** Contact info@trolltech.com if any conditions of this licensing are** not clear to you.************************************************************************/#include "event.h"#include <qtopia/calendar.h>#include <qtopia/qpeapplication.h>#include <qtopia/private/qfiledirect_p.h>#include <qtopia/timeconversion.h>#include <qtopia/stringutil.h>#include <qtopia/private/recordfields.h>#include <qtopia/private/vobject_p.h>#include <qtopia/pim/private/xmlio_p.h>#include <qtopia/pim/private/eventio_p.h>#include <qbuffer.h>#include <qtextcodec.h>#include <time.h>#include <stdio.h>/*!  \class PimEvent  \module qpepim  \ingroup qpepim  \brief The PimEvent class holds the data of a calendar event.  This data includes descriptive data of the event and schedualing information.*//*!  \enum PimEvent::RepeatType  This enum type defines how an event repeats.  <ul>  <li>\c NoRepeat - Event occurs only once.  <li>\c Daily - Event occurs every N days.  <li>\c Weekly - Event occurs every N weeks.  <li>\c MonthlyDate - Event occurs on the Xth day of the month every N months.  <li>\c MonthlyDay - Event occurs on the Xth week of the month every N months.  <li>\c MonthlyEndDay - Event occurs on the Xth last week of the month every N months.  <li>\c Yearly - Event occurs every N years.  </ul>  \sa frequency(), weekOffset() showOnNearest() repeatOnWeekDay()*//*!  \enum PimEvent::SoundTypeChoice  This enum type defines what kind of sound is made when an alarm occurs  for an event.  The currently defined types are:  <ul>  <li>\c Silent - No sound is produced.  <li>\c Loud - A loud sound is produced.  </ul>  \sa setAlarm(), alarmSound()*//*!  \fn void PimEvent::description() const  Returns the description of the event.  \sa setDescription()*//*!  \fn void PimEvent::location() const  Returns the location of the event.  \sa setLocation()*//*!  \fn void PimEvent::notes() const  Returns the notes of the event.  \sa setNotes()*//*!  \fn bool PimEvent::hasAlarm() const  Returns TRUE if there is an alarm set for the event.  Otherwise returns FALSE. \sa setAlarm()*//*!  \fn int PimEvent::alarmDelay() const  Returns the number of minutes before the event to activate the alarm  for the event. \sa setAlarm()*//*!  \fn PimEvent::SoundTypeChoice PimEvent::alarmSound() const  Returns the type of alarm to sound.  \sa setAlarm(), SoundTypeChoice*//*!  \fn RepeatType PimEvent::repeatType() const  Returns the RepeatType of the event.  \sa setRepeatType(), RepeatType*//*!  \fn bool PimEvent::hasRepeat() const  Returns FALSE if the event has repeat type NoRepeat.  Otherwise returns TRUE.  \sa setRepeatType(), RepeatType*//*!  \fn int PimEvent::frequency() const  Returns how often the event repeats.  \sa setFrequency()*//*!  \fn bool PimEvent::showOnNearest() const  Returns if the event should be shown on the nearest match of an occurrence  if the exact date the event would occur is not a valid date.  \sa setShowOnNearest()*//*!  \fn bool PimEvent::isAllDay() const  Returns TRUE if the event is an all day event.  Otherwise returns FALSE.  \sa setAllDay()*//*!  \fn bool PimEvent::isTravel() const  \internal*//*!  \fn QDateTime PimEvent::start() const  Returns when the first occurrence of the event starts.  \sa startInCurrentTZ() setStart()*//*!  \fn QDateTime PimEvent::end() const  Returns when the first occurrence of the event starts.  \sa endInCurrentTZ() setEnd()*//*!  \enum PimEvent::EventFields  \internal*//*!  \fn QMap<int,QString> PimEvent::fields() const  \internal*//*!  Constructs a new PimEvent.*/PimEvent::PimEvent() : PimRecord(){    QDateTime start = QDateTime::currentDateTime();    QDateTime end = start.addSecs(5 * 60);    init(start, end);}/*!  Constructs a new PimEvent starting at \a start and running till \a end.*/PimEvent::PimEvent(const QDateTime &start, const QDateTime &end){    // smallest event 5 minutes    if (end < start.addSecs(5 * 60))	init(start, start.addSecs(5 * 60));    else 	init(start, end);}/*!  \internal*/void PimEvent::fromMap( const QMap<int,QString> &m ){    QDateTime start = QDateTime::currentDateTime();    QDateTime end = start.addSecs(5 * 60);    init(start, end);    setFields( m );}void PimEvent::init(const QDateTime &s, const QDateTime &e){    mStart = s;    mEnd = e;    weekMask = 0;    mHasAlarm = FALSE;    mAlarmDelay = 0;    mAlarmSound = Silent;    mRepeatTill = mStart.date();    mHasEndDate = FALSE;    mType = NoRepeat;    mFrequency = 1;    mShowOnNearest = FALSE;    mAllDay = FALSE;}/*!  Destroys a PimEvent.*/PimEvent::~PimEvent(){}/*!  Sets the description of the event to \a text.  \sa description()*/void PimEvent::setDescription( const QString &text ){    mDescription = text;}/*!  Set the location of the event to \a text.  \sa location()*/void PimEvent::setLocation( const QString &text ){    mLocation = text;}/*!  Sets the start time of the event to \a time.  This will change the end time fo the event to maintain the same duration.  \sa start(), startInCurrentTZ()*/void PimEvent::setStart( const QDateTime &time ){    // get existing, dependent state.    int duration = mStart.secsTo(mEnd);    // move the start, (end moves with it)    mStart = time;    mEnd = mStart.addSecs(duration);    if (mRepeatTill < mEnd.date())	mRepeatTill = mEnd.date();}/*!  Sets the end time of the event to \a time.  This will also change the duration of the event. \a time must be at least  5 minutes after the start time of the event.  \sa end(), endInCurrentTZ()*/void PimEvent::setEnd( const QDateTime &time ){    if (time < mStart.addSecs(60 * 5))	return; // can't set end before start.    mEnd = time;    // make sure repeatForever and repeatTill are still valid.    if (mRepeatTill < mEnd.date())	mRepeatTill = mEnd.date();}/*!  Sets the notes of the event to \a text.  \sa notes()*/void PimEvent::setNotes( const QString &text ){    mNotes = text;}/*!  Sets the time zone of the event to \a zone.  This will affect when the event occurs in UTC.  All day events cannot have  a time zone set.  Setting the time zone to an invalid TimeZone will cause the event to  have no associated time zone.  \sa timeZone(), isAllDay()*/void PimEvent::setTimeZone( const TimeZone &zone ){    mTimeZone = zone;}/*!  \internal for the moment. finish documenting when adding travel events.  Sets the end TimeZone of the event.*/void PimEvent::setEndTimeZone( const TimeZone &zone ){    mEndTimeZone = zone;}/*!  Sets an alarm for the event, \a minutes before the start of the event, with  an alarm type of \a s.  \sa clearAlarm(), hasAlarm(), alarmSound(), alarmDelay()*/void PimEvent::setAlarm( int minutes, SoundTypeChoice s ){    mHasAlarm = TRUE;    mAlarmDelay = minutes;    mAlarmSound = s;}/*!  Clears any alarms set for the event.  \sa setAlarm()*/void PimEvent::clearAlarm(){    mHasAlarm = FALSE;}/*!  Sets the repeat type of the event to \a t.  \sa repeatType(), hasRepeat(), RepeatType*/void PimEvent::setRepeatType( RepeatType t ){    mType = t;}/*!  Sets the frequency of the event to \a freq.  If \a freq is less than 1  will set the frequency of the event to 1.  \sa frequency()*/void PimEvent::setFrequency( int freq ){    mFrequency = freq > 0 ? freq : 1;}/*!  Sets the date the event will repeat until to \a date.  If date is before  the end of the first event will set the event to occur once.  \sa repeatTill(), repeatForever()*/void PimEvent::setRepeatTill( const QDate &date ){    mRepeatTill = date > mEnd.date() ? date : mEnd.date();    mHasEndDate = TRUE;}/*!  Sets whether the event is an an all day event to \a enable.  All day events have a no set time-zone (empty string).  \sa isAllDay(), setTimeZone()*/void PimEvent::setAllDay( bool enable ){    mAllDay = enable;}/*!  Returns the time zone of the event or an invalid TimeZone if the event has  no time zone.  All day events allways have no time zone.  \sa setTimeZone(), isAllDay()*/TimeZone PimEvent::timeZone() const{    return mAllDay ? TimeZone() : mTimeZone;}/*!  \internal*/TimeZone PimEvent::endTimeZone() const{    return mAllDay ? TimeZone() : mEndTimeZone;}/*!  Returns the date the event will repeat until  \sa repeatForever(), setRepeatTill()*/QDate PimEvent::repeatTill() const{    if (!hasRepeat())	return mEnd.date();    return mRepeatTill;}/*!  Returns TRUE if the event will repeat forever.  Otherwise returns FALSE.  \sa repeatTill(), setRepeatForever()*/bool PimEvent::repeatForever( ) const{    if (!hasRepeat())	return FALSE;    return !mHasEndDate;}/*!  Returns the instance of the week the event will occur for the repeat types  MonthlyDay and MonthlyEndDay.  The week offset is determined by the starting  date of the event.  if (weekOffset() == 1) event occurs in first week of the month.  if (weekOffset() == 3) event occurs in third week of the month.  if (weekOffset() == -1) event occurs in last week of the month.  Returns 0 if there is no week offset for the event.*/int PimEvent::weekOffset( ) const{    if (mType == MonthlyDay) {	if (mStart.date().day() == 1)	    return 1;	return (mStart.date().day() - 1) / 7 + 1;    } else if (mType == MonthlyEndDay) {	if (mStart.date().day() == mStart.date().daysInMonth())	    return -1;	return -((mStart.date().daysInMonth() - mStart.date().day()) / 7 + 1);    }    return 0;}/*!  If \a b is TRUE then sets the event to repeat forever.  Otherwise event  will repeat until repeatUntil()  \sa repeatForever()*/void PimEvent::setRepeatForever( bool b ){    //if (b == repeatForever())	//return;    mHasEndDate = !b;}/*!  Sets whether to show a repeating event on the nearest previous date if the

⌨️ 快捷键说明

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