summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Side-by-side diff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (show whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp26
1 files changed, 25 insertions, 1 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index 1a1c6be..0ddfeca 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -359,207 +359,231 @@ bool CalendarLocal::addTodoNoDup( Todo *todo )
//qDebug("duplicate todo found! not inserted! ");
return false;
}
}
return addTodo( todo );
}
bool CalendarLocal::addTodo( Todo *todo )
{
mTodoList.append( todo );
todo->registerObserver( this );
// Set up subtask relations
setupRelations( todo );
setModified( true );
if ( todo->calID() == 0 )
todo->setCalID( mDefaultCalendar );
todo->setCalEnabled( true );
return true;
}
void CalendarLocal::deleteTodo( Todo *todo )
{
// Handle orphaned children
removeRelations( todo );
clearUndo(todo);
if ( mTodoList.removeRef( todo ) ) {
setModified( true );
}
}
QPtrList<Todo> CalendarLocal::rawTodos()
{
QPtrList<Todo> el;
for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
if ( it->calEnabled() ) el.append( it );
return el;
}
Todo *CalendarLocal::todo( QString syncProf, QString id )
{
Todo *todo;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
}
return 0;
}
void CalendarLocal::removeSyncInfo( QString syncProfile)
{
QPtrList<Incidence> all = rawIncidences() ;
Incidence *inc;
for ( inc = all.first(); inc; inc = all.next() ) {
inc->removeID( syncProfile );
}
if ( syncProfile.isEmpty() ) {
QPtrList<Event> el;
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
el.append( todo );
}
for ( todo = el.first(); todo; todo = el.next() ) {
deleteIncidence ( todo );
}
} else {
Event *lse = event( "last-syncEvent-"+ syncProfile);
if ( lse )
deleteIncidence ( lse );
}
}
QPtrList<Event> CalendarLocal::getExternLastSyncEvents()
{
QPtrList<Event> el;
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
if ( todo->summary().left(3) == "E: " )
el.append( todo );
}
return el;
}
Event *CalendarLocal::event( QString syncProf, QString id )
{
Event *todo;
for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
}
return 0;
}
Todo *CalendarLocal::todo( const QString &uid )
{
- Todo *todo;;
+ Todo *todo;
Todo *retVal = 0;
for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
if ( todo->calEnabled() && todo->uid() == uid ) {
if ( retVal ) {
if ( retVal->calID() > todo->calID() ) {
retVal = todo;
}
} else {
retVal = todo;
}
}
}
return retVal;
}
+void CalendarLocal::getIncidenceCount( int calId, int& events, int & todos, int & journals)
+{
+ events = 0;
+ todos = 0;
+ journals = 0;
+ {
+ Todo *todo;
+ for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
+ if ( todo->calID() == calId )
+ ++todos;
+ }
+ }
+ {
+ Event *todo;
+ for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
+ if ( todo->calID() == calId )
+ ++events;
+
+ }
+ }
+ for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
+ if ( it->calID() == calId ) ++journals;
+
+}
QString CalendarLocal::nextSummary() const
{
return mNextSummary;
}
QDateTime CalendarLocal::nextAlarmEventDateTime() const
{
return mNextAlarmEventDateTime;
}
void CalendarLocal::checkAlarmForIncidence( Incidence * incidence, bool deleted)
{
//mNextAlarmIncidence
//mNextAlarmDateTime
//return mNextSummary;
//return mNextAlarmEventDateTime;
bool newNextAlarm = false;
bool computeNextAlarm = false;
bool ok;
int offset;
QDateTime nextA;
// QString nextSum;
//QDateTime nextEvent;
if ( mNextAlarmIncidence == 0 || incidence == 0 ) {
computeNextAlarm = true;
} else {
if ( ! deleted ) {
nextA = incidence->getNextAlarmDateTime(& ok, &offset, QDateTime::currentDateTime() ) ;
if ( ok ) {
if ( nextA < mNextAlarmDateTime ) {
deRegisterAlarm();
mNextAlarmDateTime = nextA;
mNextSummary = incidence->summary();
mNextAlarmEventDateTime = nextA.addSecs(offset ) ;
mNextAlarmEventDateTimeString = KGlobal::locale()->formatDateTime(mNextAlarmEventDateTime);
newNextAlarm = true;
mNextAlarmIncidence = incidence;
} else {
if ( incidence == mNextAlarmIncidence ) {
computeNextAlarm = true;
}
}
} else {
if ( mNextAlarmIncidence == incidence ) {
computeNextAlarm = true;
}
}
} else { // deleted
if ( incidence == mNextAlarmIncidence ) {
computeNextAlarm = true;
}
}
}
if ( computeNextAlarm ) {
deRegisterAlarm();
nextA = nextAlarm( 1000 );
if (! mNextAlarmIncidence ) {
return;
}
newNextAlarm = true;
}
if ( newNextAlarm )
registerAlarm();
}
QString CalendarLocal:: getAlarmNotification()
{
QString ret;
// this should not happen
if (! mNextAlarmIncidence )
return "cal_alarm"+ mNextSummary.left( 25 )+"\n"+mNextAlarmEventDateTimeString;
Alarm* alarm = mNextAlarmIncidence->alarms().first();
if ( alarm->type() == Alarm::Procedure ) {
ret = "proc_alarm" + alarm->programFile()+"+++";
} else {
ret = "audio_alarm" +alarm->audioFile() +"+++";
}
ret += "cal_alarm"+ mNextSummary.left( 25 );
if ( mNextSummary.length() > 25 )
ret += "\n" + mNextSummary.mid(25, 25 );
ret+= "\n"+mNextAlarmEventDateTimeString;
return ret;
}
void CalendarLocal::registerAlarm()
{
mLastAlarmNotificationString = getAlarmNotification();
// qDebug("++ register Alarm %s %s",mNextAlarmDateTime.toString().latin1(), mLastAlarmNotificationString.latin1() );
emit addAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
// #ifndef DESKTOP_VERSION
// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
// #endif
}
void CalendarLocal::deRegisterAlarm()
{
if ( mLastAlarmNotificationString.isNull() )
return;
//qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );