odatebookaccessbackend.cpp
Go to the documentation of this file.00001 #include <qtl.h>
00002
00003 #include "orecur.h"
00004
00005 #include "odatebookaccessbackend.h"
00006
00007 namespace {
00008
00009 void events( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& events,
00010 const QDate& from, const QDate& to ) {
00011 QDateTime dtStart, dtEnd;
00012
00013 for ( OEvent::ValueList::ConstIterator it = events.begin(); it != events.end(); ++it ) {
00014 dtStart = (*it).startDateTime();
00015 dtEnd = (*it).endDateTime();
00016
00017
00018
00019
00020 if (dtStart.date() >= from && dtEnd.date() <= to ) {
00021 OEffectiveEvent eff;
00022 eff.setEvent( (*it) );
00023 eff.setDate( dtStart.date() );
00024 eff.setStartTime( dtStart.time() );
00025
00026
00027 if ( dtStart.date() != dtEnd.date() )
00028 eff.setEndTime( QTime(23, 59, 0 ) );
00029 else
00030 eff.setEndTime( dtEnd.time() );
00031
00032 tmpList.append( eff );
00033 }
00034
00035
00036 if ( dtEnd.date() != dtStart.date() && dtEnd.date() >= from ) {
00037 QDateTime dt = dtStart.addDays( 1 );
00038 dt.setTime( QTime(0, 0, 0 ) );
00039 QDateTime dtStop;
00040 if ( dtEnd > to )
00041 dtStop = to;
00042 else
00043 dtStop = dtEnd;
00044
00045 while ( dt <= dtStop ) {
00046 OEffectiveEvent eff;
00047 eff.setEvent( (*it) );
00048 eff.setDate( dt.date() );
00049
00050 if ( dt >= from ) {
00051 eff.setStartTime( QTime(0, 0, 0 ) );
00052 if ( dt.date() == dtEnd.date() )
00053 eff.setEndTime( dtEnd.time() );
00054 else
00055 eff.setEndTime( QTime(23, 59, 0 ) );
00056 tmpList.append( eff );
00057 }
00058 dt = dt.addDays( 1 );
00059 }
00060 }
00061 }
00062 }
00063
00064 void repeat( OEffectiveEvent::ValueList& tmpList, const OEvent::ValueList& list,
00065 const QDate& from, const QDate& to ) {
00066 QDate repeat;
00067 for ( OEvent::ValueList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
00068 int dur = (*it).startDateTime().date().daysTo( (*it).endDateTime().date() );
00069 QDate itDate = from.addDays(-dur );
00070 ORecur rec = (*it).recurrence();
00071 if ( !rec.hasEndDate() || rec.endDate() > to ) {
00072 rec.setEndDate( to );
00073 rec.setHasEndDate( true );
00074 }
00075 while (rec.nextOcurrence(itDate, repeat ) ) {
00076 if (repeat > to ) break;
00077 OEffectiveEvent eff;
00078 eff.setDate( repeat );
00079 if ( (*it).isAllDay() ) {
00080 eff.setStartTime( QTime(0, 0, 0 ) );
00081 eff.setEndTime( QTime(23, 59, 59 ) );
00082 }else {
00083
00084
00085
00086
00087
00088 eff.setStartTime( (*it).startDateTime().time() );
00089 eff.setEndTime( (*it).endDateTime().time() );
00090 }
00091 if ( dur != 0 ) {
00092
00093 QDate sub_it = QMAX( repeat, from );
00094 QDate startDate = repeat;
00095 QDate endDate = startDate.addDays( dur );
00096
00097 while ( sub_it <= endDate && sub_it <= to ) {
00098 OEffectiveEvent tmpEff = eff;
00099 tmpEff.setEvent( (*it) );
00100 if ( sub_it != startDate )
00101 tmpEff.setStartTime( QTime(0, 0, 0 ) );
00102 if ( sub_it != endDate )
00103 tmpEff.setEndTime( QTime( 23, 59, 59 ) );
00104
00105 tmpEff.setDate( sub_it );
00106 tmpEff.setEffectiveDates( startDate, endDate );
00107 tmpList.append( tmpEff );
00108
00109 sub_it = sub_it.addDays( 1 );
00110 }
00111 itDate = endDate;
00112 }else {
00113 eff.setEvent( (*it) );
00114 tmpList.append( eff );
00115 itDate = repeat.addDays( 1 );
00116 }
00117 }
00118 }
00119 }
00120 }
00121
00122 ODateBookAccessBackend::ODateBookAccessBackend()
00123 : OPimAccessBackend<OEvent>()
00124 {
00125
00126 }
00127 ODateBookAccessBackend::~ODateBookAccessBackend() {
00128
00129 }
00130 OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDate& from,
00131 const QDate& to ) {
00132 OEffectiveEvent::ValueList tmpList;
00133 OEvent::ValueList list = directNonRepeats();
00134
00135 events( tmpList, list, from, to );
00136 repeat( tmpList, directRawRepeats(),from,to );
00137
00138 list = directRawRepeats();
00139
00140 qHeapSort( tmpList );
00141 return tmpList;
00142 }
00143 OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveEvents( const QDateTime& dt ) {
00144 OEffectiveEvent::ValueList day = effectiveEvents( dt.date(), dt.date() );
00145 OEffectiveEvent::ValueList::Iterator it;
00146
00147 OEffectiveEvent::ValueList tmpList;
00148 QDateTime dtTmp;
00149 for ( it = day.begin(); it != day.end(); ++it ) {
00150 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
00151 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
00152 tmpList.append( (*it) );
00153 }
00154
00155 return tmpList;
00156 }
00157
00158 OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDate& from,
00159 const QDate& to ) {
00160 OEffectiveEvent::ValueList tmpList;
00161 OEvent::ValueList list = directNonRepeats();
00162
00163 events( tmpList, list, from, to );
00164
00165 qHeapSort( tmpList );
00166 return tmpList;
00167 }
00168
00169 OEffectiveEvent::ValueList ODateBookAccessBackend::effectiveNonRepeatingEvents( const QDateTime& dt ) {
00170 OEffectiveEvent::ValueList day = effectiveNonRepeatingEvents( dt.date(), dt.date() );
00171 OEffectiveEvent::ValueList::Iterator it;
00172
00173 OEffectiveEvent::ValueList tmpList;
00174 QDateTime dtTmp;
00175 for ( it = day.begin(); it != day.end(); ++it ) {
00176 dtTmp = QDateTime( (*it).date(), (*it).startTime() );
00177 if ( QABS(dt.secsTo(dtTmp) ) < 60 )
00178 tmpList.append( (*it) );
00179 }
00180
00181 return tmpList;
00182 }
This file is part of the documentation for OPIE Version 1.1.