summaryrefslogtreecommitdiff
path: root/library/datebookdb.cpp
Side-by-side diff
Diffstat (limited to 'library/datebookdb.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/datebookdb.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/library/datebookdb.cpp b/library/datebookdb.cpp
index e4ec2bf..165a637 100644
--- a/library/datebookdb.cpp
+++ b/library/datebookdb.cpp
@@ -297,192 +297,195 @@ bool nextOccurance(const Event &e, const QDate &from, QDateTime &next)
/* else divides by 4 already, leave freq alone */
diff = 4;
}
a = from.year() - e.start().date().year();
if(a % freq) {
a = freq - (a % freq);
iyear = iyear + a;
}
/* under the assumption we won't hit one of the special not-leap years twice */
if(!QDate::isValid(iyear, imonth, iday)) {
/* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
iyear += freq;
}
if(QDate(iyear, imonth, iday) >= from) {
next = QDateTime(QDate(iyear, imonth, iday),
e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
}
/* iyear == from.year(), need to advance again */
iyear += freq;
/* under the assumption we won't hit one of the special not-leap years twice */
if(!QDate::isValid(iyear, imonth, iday)) {
/* must have been skipping by leap years and hit one that wasn't, (e.g. 2100) */
iyear += freq;
}
next = QDateTime(QDate(iyear, imonth, iday), e.start().time());
if ((next.date() > e.repeatPattern().endDate()) && e.repeatPattern().hasEndDate)
return FALSE;
return TRUE;
default:
return FALSE;
}
}
static bool nextAlarm( const Event &ev, QDateTime& when, int& warn)
{
QDateTime now = QDateTime::currentDateTime();
if ( ev.hasRepeat() ) {
QDateTime ralarm;
if (nextOccurance(ev, now.date(), ralarm)) {
ralarm = ralarm.addSecs(-ev.alarmTime()*60);
if ( ralarm > now ) {
when = ralarm;
warn = ev.alarmTime();
} else if ( nextOccurance(ev, now.date().addDays(1), ralarm) ) {
ralarm = ralarm.addSecs( -ev.alarmTime()*60 );
if ( ralarm > now ) {
when = ralarm;
warn = ev.alarmTime();
}
}
}
} else {
warn = ev.alarmTime();
when = ev.start().addSecs( -ev.alarmTime()*60 );
}
return when > now;
}
static void addEventAlarm( const Event &ev )
{
QDateTime when;
int warn;
if ( nextAlarm(ev,when,warn) )
AlarmServer::addAlarm( when,
"QPE/Application/datebook",
"alarm(QDateTime,int)", warn );
}
static void delEventAlarm( const Event &ev )
{
QDateTime when;
int warn;
if ( nextAlarm(ev,when,warn) )
AlarmServer::deleteAlarm( when,
"QPE/Application/datebook",
"alarm(QDateTime,int)", warn );
}
DateBookDB::DateBookDB()
{
init();
}
DateBookDB::~DateBookDB()
{
save();
eventList.clear();
repeatEvents.clear();
+
+ delete d;
+ d=0;
}
//#### Why is this code duplicated in getEffectiveEvents ?????
//#### Addendum. Don't use this function, lets faze it out if we can.
QValueList<Event> DateBookDB::getEvents( const QDate &from, const QDate &to )
{
QValueList<Event> tmpList;
tmpList = getNonRepeatingEvents( from, to );
// check for repeating events...
for (QValueList<Event>::ConstIterator it = repeatEvents.begin();
it != repeatEvents.end(); ++it) {
QDate itDate = from;
QDateTime due;
/* create a false end date, to short circuit on hard
MonthlyDay recurences */
Event dummy_event = *it;
Event::RepeatPattern r = dummy_event.repeatPattern();
if ( !r.hasEndDate || r.endDate() > to ) {
r.setEndDate( to );
r.hasEndDate = TRUE;
}
dummy_event.setRepeat(TRUE, r);
while (nextOccurance(dummy_event, itDate, due)) {
if (due.date() > to)
break;
Event newEvent = *it;
newEvent.setStart(due);
newEvent.setEnd(due.addSecs((*it).start().secsTo((*it).end())));
tmpList.append(newEvent);
itDate = due.date().addDays(1); /* the next event */
}
}
qHeapSort(tmpList);
return tmpList;
}
QValueList<Event> DateBookDB::getEvents( const QDateTime &start )
{
QValueList<Event> day = getEvents(start.date(),start.date());
QValueListConstIterator<Event> it;
QDateTime dtTmp;
QValueList<Event> tmpList;
for (it = day.begin(); it != day.end(); ++it ) {
dtTmp = (*it).start(TRUE);
if ( dtTmp == start )
tmpList.append( *it );
}
return tmpList;
}
//#### Why is this code duplicated in getEvents ?????
QValueList<EffectiveEvent> DateBookDB::getEffectiveEvents( const QDate &from,
const QDate &to )
{
QValueList<EffectiveEvent> tmpList;
QValueListIterator<Event> it;
EffectiveEvent effEv;
QDateTime dtTmp,
dtEnd;
for (it = eventList.begin(); it != eventList.end(); ++it ) {
if (!(*it).isValidUid())
(*it).assignUid(); // FIXME: Hack to restore cleared uids
dtTmp = (*it).start(TRUE);
dtEnd = (*it).end(TRUE);
if ( dtTmp.date() >= from && dtTmp.date() <= to ) {
Event tmpEv = *it;
effEv.setEvent(tmpEv);
effEv.setDate( dtTmp.date() );
effEv.setStart( dtTmp.time() );
if ( dtTmp.date() != dtEnd.date() )
effEv.setEnd( QTime(23, 59, 0) );
else
effEv.setEnd( dtEnd.time() );
tmpList.append( effEv );
}
// we must also check for end date information...
if ( dtEnd.date() != dtTmp.date() && dtEnd.date() >= from ) {
QDateTime dt = dtTmp.addDays( 1 );
dt.setTime( QTime(0, 0, 0) );
QDateTime dtStop;
if ( dtEnd > to ) {
dtStop = to;
} else
dtStop = dtEnd;
while ( dt <= dtStop ) {