summaryrefslogtreecommitdiffabout
path: root/libkcal/calendarlocal.cpp
Unidiff
Diffstat (limited to 'libkcal/calendarlocal.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libkcal/calendarlocal.cpp66
1 files changed, 33 insertions, 33 deletions
diff --git a/libkcal/calendarlocal.cpp b/libkcal/calendarlocal.cpp
index ce3cd09..cb52b7c 100644
--- a/libkcal/calendarlocal.cpp
+++ b/libkcal/calendarlocal.cpp
@@ -9,33 +9,33 @@
9 License as published by the Free Software Foundation; either 9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version. 10 version 2 of the License, or (at your option) any later version.
11 11
12 This library is distributed in the hope that it will be useful, 12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details. 15 Library General Public License for more details.
16 16
17 You should have received a copy of the GNU Library General Public License 17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to 18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. 20 Boston, MA 02111-1307, USA.
21*/ 21*/
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qstring.h> 24#include <qstring.h>
25#include <qptrlist.h> 25#include <q3ptrlist.h>
26 26
27#include <kdebug.h> 27#include <kdebug.h>
28#include <kconfig.h> 28#include <kconfig.h>
29#include <kglobal.h> 29#include <kglobal.h>
30#include <klocale.h> 30#include <klocale.h>
31 31
32#include "vcaldrag.h" 32#include "vcaldrag.h"
33#include "vcalformat.h" 33#include "vcalformat.h"
34#include "icalformat.h" 34#include "icalformat.h"
35#include "exceptions.h" 35#include "exceptions.h"
36#include "incidence.h" 36#include "incidence.h"
37#include "journal.h" 37#include "journal.h"
38#include "filestorage.h" 38#include "filestorage.h"
39#include "calfilter.h" 39#include "calfilter.h"
40 40
41#include "calendarlocal.h" 41#include "calendarlocal.h"
@@ -179,41 +179,41 @@ Incidence* CalendarLocal::incidenceForUid( const QString& uid , bool doNotCheckD
179 retVal = it; 179 retVal = it;
180 } 180 }
181 } else { 181 } else {
182 retVal = it; 182 retVal = it;
183 } 183 }
184 } 184 }
185 return retVal; 185 return retVal;
186} 186}
187 187
188bool CalendarLocal::mergeCalendar( Calendar* remote ) 188bool CalendarLocal::mergeCalendar( Calendar* remote )
189{ 189{
190 // 1 look for raw inc in local 190 // 1 look for raw inc in local
191 // if inc not in remote, delete in local 191 // if inc not in remote, delete in local
192 // 2 look for raw inc in remote 192 // 2 look for raw inc in remote
193 // if inc in local, replace it 193 // if inc in local, replace it
194 // if not in local, add it to default calendar 194 // if not in local, add it to default calendar
195 QPtrList<Incidence> localInc = rawIncidences(); 195 Q3PtrList<Incidence> localInc = rawIncidences();
196 Incidence* inL = localInc.first(); 196 Incidence* inL = localInc.first();
197 while ( inL ) { 197 while ( inL ) {
198 if ( ! inL->isReadOnly () ) 198 if ( ! inL->isReadOnly () )
199 if ( !remote->incidenceForUid( inL->uid(), true )) 199 if ( !remote->incidenceForUid( inL->uid(), true ))
200 deleteIncidence( inL ); 200 deleteIncidence( inL );
201 inL = localInc.next(); 201 inL = localInc.next();
202 } 202 }
203 QPtrList<Incidence> er = remote->rawIncidences(); 203 Q3PtrList<Incidence> er = remote->rawIncidences();
204 Incidence* inR = er.first(); 204 Incidence* inR = er.first();
205 while ( inR ) { 205 while ( inR ) {
206 inL = incidenceForUid( inR->uid(),false ); 206 inL = incidenceForUid( inR->uid(),false );
207 if ( inL ) { 207 if ( inL ) {
208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) { 208 if ( ! inL->isReadOnly () || inL->uid().left(15) == QString("last-syncEvent-") ) {
209 int calID = inL->calID(); 209 int calID = inL->calID();
210 deleteIncidence( inL ); 210 deleteIncidence( inL );
211 inL = inR->clone(); 211 inL = inR->clone();
212 inL->setCalID_block( calID ); 212 inL->setCalID_block( calID );
213 addIncidence( inL ); 213 addIncidence( inL );
214 } 214 }
215 } else { 215 } else {
216 inL = inR->clone(); 216 inL = inR->clone();
217 inL->setCalID_block( 0 );// add to default cal 217 inL->setCalID_block( 0 );// add to default cal
218 addIncidence( inL ); 218 addIncidence( inL );
219 } 219 }
@@ -246,73 +246,73 @@ void CalendarLocal::setSyncEventsEnabled()
246void CalendarLocal::setSyncEventsReadOnly() 246void CalendarLocal::setSyncEventsReadOnly()
247{ 247{
248 Event * ev; 248 Event * ev;
249 ev = mEventList.first(); 249 ev = mEventList.first();
250 while ( ev ) { 250 while ( ev ) {
251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) { 251 if ( ev->uid().left(15) == QString("last-syncEvent-") ) {
252 ev->setReadOnly( true ); 252 ev->setReadOnly( true );
253 } 253 }
254 ev = mEventList.next(); 254 ev = mEventList.next();
255 } 255 }
256} 256}
257 257
258void CalendarLocal::addCalendar( Calendar* cal ) 258void CalendarLocal::addCalendar( Calendar* cal )
259{ 259{
260 cal->setDontDeleteIncidencesOnClose(); 260 cal->setDontDeleteIncidencesOnClose();
261 setSyncEventsEnabled(); 261 setSyncEventsEnabled();
262 QPtrList<Incidence> incList; 262 Q3PtrList<Incidence> incList;
263 { 263 {
264 QPtrList<Event> EventList = cal->rawEvents(); 264 Q3PtrList<Event> EventList = cal->rawEvents();
265 Event * ev = EventList.first(); 265 Event * ev = EventList.first();
266 while ( ev ) { 266 while ( ev ) {
267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) { 267 if ( ev->uid().left( 15 ) == QString("last-syncEvent-") ) {
268 ev->setCalID_block( 1 ); 268 ev->setCalID_block( 1 );
269 } 269 }
270 Event * se = event( ev->uid() ); 270 Event * se = event( ev->uid() );
271 if ( se ) 271 if ( se )
272 incList.append( se ); 272 incList.append( se );
273 ev->unRegisterObserver( cal ); 273 ev->unRegisterObserver( cal );
274 ev->registerObserver( this ); 274 ev->registerObserver( this );
275 mEventList.append( ev ); 275 mEventList.append( ev );
276 ev = EventList.next(); 276 ev = EventList.next();
277 } 277 }
278 278
279 } 279 }
280 { 280 {
281 281
282 QPtrList<Todo> TodoList = cal->rawTodos(); 282 Q3PtrList<Todo> TodoList = cal->rawTodos();
283 Todo * ev = TodoList.first(); 283 Todo * ev = TodoList.first();
284 while ( ev ) { 284 while ( ev ) {
285 ev->resetRelatedTo(); 285 ev->resetRelatedTo();
286 Todo * se = todo( ev->uid() ); 286 Todo * se = todo( ev->uid() );
287 if ( se ) 287 if ( se )
288 deleteTodo( se ); 288 deleteTodo( se );
289 ev = TodoList.next(); 289 ev = TodoList.next();
290 } 290 }
291 //TodoList = cal->rawTodos(); 291 //TodoList = cal->rawTodos();
292 ev = TodoList.first(); 292 ev = TodoList.first();
293 while ( ev ) { 293 while ( ev ) {
294 ev->unRegisterObserver( cal ); 294 ev->unRegisterObserver( cal );
295 ev->registerObserver( this ); 295 ev->registerObserver( this );
296 mTodoList.append( ev ); 296 mTodoList.append( ev );
297 setupRelations( ev ); 297 setupRelations( ev );
298 ev = TodoList.next(); 298 ev = TodoList.next();
299 } 299 }
300 } 300 }
301 { 301 {
302 QPtrList<Journal> JournalList = cal->journals(); 302 Q3PtrList<Journal> JournalList = cal->journals();
303 Journal * ev = JournalList.first(); 303 Journal * ev = JournalList.first();
304 while ( ev ) { 304 while ( ev ) {
305 Journal * se = journal( ev->uid() ); 305 Journal * se = journal( ev->uid() );
306 if ( se ) 306 if ( se )
307 incList.append( se ); 307 incList.append( se );
308 ev->unRegisterObserver( cal ); 308 ev->unRegisterObserver( cal );
309 ev->registerObserver( this ); 309 ev->registerObserver( this );
310 mJournalList.append( ev ); 310 mJournalList.append( ev );
311 ev = JournalList.next(); 311 ev = JournalList.next();
312 } 312 }
313 } 313 }
314 { 314 {
315 for (Incidence * inc = incList.first(); inc; inc = incList.next() ) { 315 for (Incidence * inc = incList.first(); inc; inc = incList.next() ) {
316 deleteIncidence ( inc ); 316 deleteIncidence ( inc );
317 } 317 }
318 } 318 }
@@ -468,74 +468,74 @@ bool CalendarLocal::addTodo( Todo *todo )
468 468
469void CalendarLocal::deleteTodo( Todo *todo ) 469void CalendarLocal::deleteTodo( Todo *todo )
470{ 470{
471 QString uid = todo->uid(); 471 QString uid = todo->uid();
472 // Handle orphaned children 472 // Handle orphaned children
473 removeRelations( todo ); 473 removeRelations( todo );
474 clearUndo(todo); 474 clearUndo(todo);
475 475
476 if ( mTodoList.removeRef( todo ) ) { 476 if ( mTodoList.removeRef( todo ) ) {
477 setModified( true ); 477 setModified( true );
478 } 478 }
479 Todo* dup = todoForUid( uid ); 479 Todo* dup = todoForUid( uid );
480 if ( dup ) 480 if ( dup )
481 setupRelations( dup ); 481 setupRelations( dup );
482} 482}
483 483
484QPtrList<Todo> CalendarLocal::rawTodos() 484Q3PtrList<Todo> CalendarLocal::rawTodos()
485{ 485{
486 QPtrList<Todo> el; 486 Q3PtrList<Todo> el;
487 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() ) 487 for ( Todo *it = mTodoList.first(); it; it = mTodoList.next() )
488 if ( it->calEnabled() ) el.append( it ); 488 if ( it->calEnabled() ) el.append( it );
489 return el; 489 return el;
490} 490}
491Todo *CalendarLocal::todo( QString syncProf, QString id ) 491Todo *CalendarLocal::todo( QString syncProf, QString id )
492{ 492{
493 Todo *todo; 493 Todo *todo;
494 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 494 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
495 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 495 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
496 } 496 }
497 497
498 return 0; 498 return 0;
499} 499}
500void CalendarLocal::removeSyncInfo( QString syncProfile) 500void CalendarLocal::removeSyncInfo( QString syncProfile)
501{ 501{
502 QPtrList<Incidence> all = rawIncidences() ; 502 Q3PtrList<Incidence> all = rawIncidences() ;
503 Incidence *inc; 503 Incidence *inc;
504 for ( inc = all.first(); inc; inc = all.next() ) { 504 for ( inc = all.first(); inc; inc = all.next() ) {
505 inc->removeID( syncProfile ); 505 inc->removeID( syncProfile );
506 } 506 }
507 if ( syncProfile.isEmpty() ) { 507 if ( syncProfile.isEmpty() ) {
508 QPtrList<Event> el; 508 Q3PtrList<Event> el;
509 Event *todo; 509 Event *todo;
510 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 510 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
511 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 511 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
512 el.append( todo ); 512 el.append( todo );
513 } 513 }
514 for ( todo = el.first(); todo; todo = el.next() ) { 514 for ( todo = el.first(); todo; todo = el.next() ) {
515 deleteIncidence ( todo ); 515 deleteIncidence ( todo );
516 } 516 }
517 } else { 517 } else {
518 Event *lse = event( "last-syncEvent-"+ syncProfile); 518 Event *lse = event( "last-syncEvent-"+ syncProfile);
519 if ( lse ) 519 if ( lse )
520 deleteIncidence ( lse ); 520 deleteIncidence ( lse );
521 } 521 }
522} 522}
523QPtrList<Event> CalendarLocal::getExternLastSyncEvents() 523Q3PtrList<Event> CalendarLocal::getExternLastSyncEvents()
524{ 524{
525 QPtrList<Event> el; 525 Q3PtrList<Event> el;
526 Event *todo; 526 Event *todo;
527 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 527 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
528 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") ) 528 if ( todo->uid().left( 15 ) == QString("last-syncEvent-") )
529 if ( todo->summary().left(3) == "E: " ) 529 if ( todo->summary().left(3) == "E: " )
530 el.append( todo ); 530 el.append( todo );
531 } 531 }
532 532
533 return el; 533 return el;
534 534
535} 535}
536Event *CalendarLocal::event( QString syncProf, QString id ) 536Event *CalendarLocal::event( QString syncProf, QString id )
537{ 537{
538 Event *todo; 538 Event *todo;
539 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) { 539 for ( todo = mEventList.first(); todo; todo = mEventList.next() ) {
540 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo; 540 if ( todo->calEnabled() && todo->getID( syncProf ) == id ) return todo;
541 } 541 }
@@ -672,35 +672,35 @@ void CalendarLocal::registerAlarm()
672// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() ); 672// AlarmServer::addAlarm ( mNextAlarmDateTime,"koalarm", mLastAlarmNotificationString.latin1() );
673// #endif 673// #endif
674} 674}
675void CalendarLocal::deRegisterAlarm() 675void CalendarLocal::deRegisterAlarm()
676{ 676{
677 if ( mLastAlarmNotificationString.isNull() ) 677 if ( mLastAlarmNotificationString.isNull() )
678 return; 678 return;
679 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() ); 679 //qDebug("-- deregister Alarm %s ", mLastAlarmNotificationString.latin1() );
680 680
681 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString ); 681 emit removeAlarm ( mNextAlarmDateTime, mLastAlarmNotificationString );
682 mNextAlarmEventDateTime = QDateTime(); 682 mNextAlarmEventDateTime = QDateTime();
683// #ifndef DESKTOP_VERSION 683// #ifndef DESKTOP_VERSION
684// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() ); 684// AlarmServer::deleteAlarm (mNextAlarmDateTime ,"koalarm" ,mLastAlarmNotificationString.latin1() );
685// #endif 685// #endif
686} 686}
687 687
688QPtrList<Todo> CalendarLocal::todos( const QDate &date ) 688Q3PtrList<Todo> CalendarLocal::todos( const QDate &date )
689{ 689{
690 QPtrList<Todo> todos; 690 Q3PtrList<Todo> todos;
691 691
692 Todo *todo; 692 Todo *todo;
693 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) { 693 for ( todo = mTodoList.first(); todo; todo = mTodoList.next() ) {
694 if ( !todo->calEnabled() ) continue; 694 if ( !todo->calEnabled() ) continue;
695 if ( todo->hasDueDate() && todo->dtDue().date() == date ) { 695 if ( todo->hasDueDate() && todo->dtDue().date() == date ) {
696 todos.append( todo ); 696 todos.append( todo );
697 } 697 }
698 } 698 }
699 699
700 filter()->apply( &todos ); 700 filter()->apply( &todos );
701 return todos; 701 return todos;
702} 702}
703void CalendarLocal::reInitAlarmSettings() 703void CalendarLocal::reInitAlarmSettings()
704{ 704{
705 if ( !mNextAlarmIncidence ) { 705 if ( !mNextAlarmIncidence ) {
706 nextAlarm( 1000 ); 706 nextAlarm( 1000 );
@@ -773,52 +773,52 @@ Alarm::List CalendarLocal::alarms( const QDateTime &from, const QDateTime &to )
773 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to ); 773 if ( e->doesRecur() ) appendRecurringAlarms( alarms, e, from, to );
774 else appendAlarms( alarms, e, from, to ); 774 else appendAlarms( alarms, e, from, to );
775 } 775 }
776 776
777 Todo *t; 777 Todo *t;
778 for( t = mTodoList.first(); t; t = mTodoList.next() ) { 778 for( t = mTodoList.first(); t; t = mTodoList.next() ) {
779 if ( !t->calEnabled() ) continue; 779 if ( !t->calEnabled() ) continue;
780 appendAlarms( alarms, t, from, to ); 780 appendAlarms( alarms, t, from, to );
781 } 781 }
782 782
783 return alarms; 783 return alarms;
784} 784}
785 785
786void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence, 786void CalendarLocal::appendAlarms( Alarm::List &alarms, Incidence *incidence,
787 const QDateTime &from, const QDateTime &to ) 787 const QDateTime &from, const QDateTime &to )
788{ 788{
789 QPtrList<Alarm> alarmList = incidence->alarms(); 789 Q3PtrList<Alarm> alarmList = incidence->alarms();
790 Alarm *alarm; 790 Alarm *alarm;
791 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 791 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
792// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text() 792// kdDebug(5800) << "CalendarLocal::appendAlarms() '" << alarm->text()
793// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl; 793// << "': " << alarm->time().toString() << " - " << alarm->enabled() << endl;
794 if ( alarm->enabled() ) { 794 if ( alarm->enabled() ) {
795 if ( alarm->time() >= from && alarm->time() <= to ) { 795 if ( alarm->time() >= from && alarm->time() <= to ) {
796 alarms.append( alarm ); 796 alarms.append( alarm );
797 } 797 }
798 } 798 }
799 } 799 }
800} 800}
801 801
802void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms, 802void CalendarLocal::appendRecurringAlarms( Alarm::List &alarms,
803 Incidence *incidence, 803 Incidence *incidence,
804 const QDateTime &from, 804 const QDateTime &from,
805 const QDateTime &to ) 805 const QDateTime &to )
806{ 806{
807 807
808 QPtrList<Alarm> alarmList = incidence->alarms(); 808 Q3PtrList<Alarm> alarmList = incidence->alarms();
809 Alarm *alarm; 809 Alarm *alarm;
810 QDateTime qdt; 810 QDateTime qdt;
811 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) { 811 for( alarm = alarmList.first(); alarm; alarm = alarmList.next() ) {
812 if (incidence->recursOn(from.date())) { 812 if (incidence->recursOn(from.date())) {
813 qdt.setTime(alarm->time().time()); 813 qdt.setTime(alarm->time().time());
814 qdt.setDate(from.date()); 814 qdt.setDate(from.date());
815 } 815 }
816 else qdt = alarm->time(); 816 else qdt = alarm->time();
817 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1()); 817 // qDebug("1 %s %s %s", qdt.toString().latin1(), from.toString().latin1(), to.toString().latin1());
818 if ( alarm->enabled() ) { 818 if ( alarm->enabled() ) {
819 if ( qdt >= from && qdt <= to ) { 819 if ( qdt >= from && qdt <= to ) {
820 alarms.append( alarm ); 820 alarms.append( alarm );
821 } 821 }
822 } 822 }
823 } 823 }
824} 824}
@@ -831,112 +831,112 @@ void CalendarLocal::update( IncidenceBase *incidence )
831{ 831{
832 incidence->setSyncStatus( Event::SYNCMOD ); 832 incidence->setSyncStatus( Event::SYNCMOD );
833 incidence->setLastModified( QDateTime::currentDateTime() ); 833 incidence->setLastModified( QDateTime::currentDateTime() );
834 // we should probably update the revision number here, 834 // we should probably update the revision number here,
835 // or internally in the Event itself when certain things change. 835 // or internally in the Event itself when certain things change.
836 // need to verify with ical documentation. 836 // need to verify with ical documentation.
837 837
838 setModified( true ); 838 setModified( true );
839} 839}
840 840
841void CalendarLocal::insertEvent( Event *event ) 841void CalendarLocal::insertEvent( Event *event )
842{ 842{
843 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event ); 843 if ( mEventList.findRef( event ) < 0 ) mEventList.append( event );
844} 844}
845 845
846 846
847QPtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted ) 847Q3PtrList<Event> CalendarLocal::rawEventsForDate( const QDate &qd, bool sorted )
848{ 848{
849 QPtrList<Event> eventList; 849 Q3PtrList<Event> eventList;
850 850
851 Event *event; 851 Event *event;
852 for( event = mEventList.first(); event; event = mEventList.next() ) { 852 for( event = mEventList.first(); event; event = mEventList.next() ) {
853 if ( !event->calEnabled() ) continue; 853 if ( !event->calEnabled() ) continue;
854 if ( event->doesRecur() ) { 854 if ( event->doesRecur() ) {
855 if ( event->isMultiDay() ) { 855 if ( event->isMultiDay() ) {
856 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() ); 856 int extraDays = event->dtStart().date().daysTo( event->dtEnd().date() );
857 int i; 857 int i;
858 for ( i = 0; i <= extraDays; i++ ) { 858 for ( i = 0; i <= extraDays; i++ ) {
859 if ( event->recursOn( qd.addDays( -i ) ) ) { 859 if ( event->recursOn( qd.addDays( -i ) ) ) {
860 eventList.append( event ); 860 eventList.append( event );
861 break; 861 break;
862 } 862 }
863 } 863 }
864 } else { 864 } else {
865 if ( event->recursOn( qd ) ) 865 if ( event->recursOn( qd ) )
866 eventList.append( event ); 866 eventList.append( event );
867 } 867 }
868 } else { 868 } else {
869 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) { 869 if ( event->dtStart().date() <= qd && event->dtEnd().date() >= qd ) {
870 eventList.append( event ); 870 eventList.append( event );
871 } 871 }
872 } 872 }
873 } 873 }
874 874
875 if ( !sorted ) { 875 if ( !sorted ) {
876 return eventList; 876 return eventList;
877 } 877 }
878 878
879 // kdDebug(5800) << "Sorting events for date\n" << endl; 879 // kdDebug(5800) << "Sorting events for date\n" << endl;
880 // now, we have to sort it based on dtStart.time() 880 // now, we have to sort it based on dtStart.time()
881 QPtrList<Event> eventListSorted; 881 Q3PtrList<Event> eventListSorted;
882 Event *sortEvent; 882 Event *sortEvent;
883 for ( event = eventList.first(); event; event = eventList.next() ) { 883 for ( event = eventList.first(); event; event = eventList.next() ) {
884 sortEvent = eventListSorted.first(); 884 sortEvent = eventListSorted.first();
885 int i = 0; 885 int i = 0;
886 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() ) 886 while ( sortEvent && event->dtStart().time()>=sortEvent->dtStart().time() )
887 { 887 {
888 i++; 888 i++;
889 sortEvent = eventListSorted.next(); 889 sortEvent = eventListSorted.next();
890 } 890 }
891 eventListSorted.insert( i, event ); 891 eventListSorted.insert( i, event );
892 } 892 }
893 return eventListSorted; 893 return eventListSorted;
894} 894}
895 895
896 896
897QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end, 897Q3PtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
898 bool inclusive ) 898 bool inclusive )
899{ 899{
900 Event *event = 0; 900 Event *event = 0;
901 901
902 QPtrList<Event> eventList; 902 Q3PtrList<Event> eventList;
903 903
904 // Get non-recurring events 904 // Get non-recurring events
905 for( event = mEventList.first(); event; event = mEventList.next() ) { 905 for( event = mEventList.first(); event; event = mEventList.next() ) {
906 if ( !event->calEnabled() ) continue; 906 if ( !event->calEnabled() ) continue;
907 if ( event->doesRecur() ) { 907 if ( event->doesRecur() ) {
908 QDate rStart = event->dtStart().date(); 908 QDate rStart = event->dtStart().date();
909 bool found = false; 909 bool found = false;
910 if ( inclusive ) { 910 if ( inclusive ) {
911 if ( rStart >= start && rStart <= end ) { 911 if ( rStart >= start && rStart <= end ) {
912 // Start date of event is in range. Now check for end date. 912 // Start date of event is in range. Now check for end date.
913 // if duration is negative, event recurs forever, so do not include it. 913 // if duration is negative, event recurs forever, so do not include it.
914 if ( event->recurrence()->duration() == 0 ) { // End date set 914 if ( event->recurrence()->duration() == 0 ) { // End date set
915 QDate rEnd = event->recurrence()->endDate(); 915 QDate rEnd = event->recurrence()->endDate();
916 if ( rEnd >= start && rEnd <= end ) { // End date within range 916 if ( rEnd >= start && rEnd <= end ) { // End date within range
917 found = true; 917 found = true;
918 } 918 }
919 } else if ( event->recurrence()->duration() > 0 ) { // Duration set 919 } else if ( event->recurrence()->duration() > 0 ) { // Duration set
920 // TODO: Calculate end date from duration. Should be done in Event 920 // TODO: Calculate end date from duration. Should be done in Event
921 // For now exclude all events with a duration. 921 // For now exclude all events with a duration.
922 } 922 }
923 } 923 }
924 } else { 924 } else {
925 bool founOne; 925 bool founOne;
926 QDate next = event->getNextOccurence( start, &founOne ).date(); 926 QDate next = event->getNextOccurence( (QDateTime)start, &founOne ).date();
927 if ( founOne ) { 927 if ( founOne ) {
928 if ( next <= end ) { 928 if ( next <= end ) {
929 found = true; 929 found = true;
930 } 930 }
931 } 931 }
932 932
933 /* 933 /*
934 // crap !!! 934 // crap !!!
935 if ( rStart <= end ) { // Start date not after range 935 if ( rStart <= end ) { // Start date not after range
936 if ( rStart >= start ) { // Start date within range 936 if ( rStart >= start ) { // Start date within range
937 found = true; 937 found = true;
938 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever 938 } else if ( event->recurrence()->duration() == -1 ) { // Recurs forever
939 found = true; 939 found = true;
940 } else if ( event->recurrence()->duration() == 0 ) { // End date set 940 } else if ( event->recurrence()->duration() == 0 ) { // End date set
941 QDate rEnd = event->recurrence()->endDate(); 941 QDate rEnd = event->recurrence()->endDate();
942 if ( rEnd >= start && rEnd <= end ) { // End date within range 942 if ( rEnd >= start && rEnd <= end ) { // End date within range
@@ -959,131 +959,131 @@ QPtrList<Event> CalendarLocal::rawEvents( const QDate &start, const QDate &end,
959 959
960 if ( inclusive ) { 960 if ( inclusive ) {
961 if ( s >= start && e <= end ) { 961 if ( s >= start && e <= end ) {
962 eventList.append( event ); 962 eventList.append( event );
963 } 963 }
964 } else { 964 } else {
965 if ( ( e >= start && s <= end ) ) { 965 if ( ( e >= start && s <= end ) ) {
966 eventList.append( event ); 966 eventList.append( event );
967 } 967 }
968 } 968 }
969 } 969 }
970 } 970 }
971 971
972 return eventList; 972 return eventList;
973} 973}
974 974
975QPtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt ) 975Q3PtrList<Event> CalendarLocal::rawEventsForDate( const QDateTime &qdt )
976{ 976{
977 return rawEventsForDate( qdt.date() ); 977 return rawEventsForDate( qdt.date() );
978} 978}
979 979
980QPtrList<Event> CalendarLocal::rawEvents() 980Q3PtrList<Event> CalendarLocal::rawEvents()
981{ 981{
982 QPtrList<Event> el; 982 Q3PtrList<Event> el;
983 for ( Event *it = mEventList.first(); it; it = mEventList.next() ) 983 for ( Event *it = mEventList.first(); it; it = mEventList.next() )
984 if ( it->calEnabled() ) el.append( it ); 984 if ( it->calEnabled() ) el.append( it );
985 return el; 985 return el;
986} 986}
987 987
988bool CalendarLocal::addJournal(Journal *journal) 988bool CalendarLocal::addJournal(Journal *journal)
989{ 989{
990 mJournalList.append(journal); 990 mJournalList.append(journal);
991 991
992 journal->registerObserver( this ); 992 journal->registerObserver( this );
993 993
994 setModified( true ); 994 setModified( true );
995 if ( journal->calID() == 0 ) 995 if ( journal->calID() == 0 )
996 journal->setCalID_block( mDefaultCalendar ); 996 journal->setCalID_block( mDefaultCalendar );
997 journal->setCalEnabled( true ); 997 journal->setCalEnabled( true );
998 return true; 998 return true;
999} 999}
1000 1000
1001void CalendarLocal::deleteJournal( Journal *journal ) 1001void CalendarLocal::deleteJournal( Journal *journal )
1002{ 1002{
1003 clearUndo(journal); 1003 clearUndo(journal);
1004 if ( mJournalList.removeRef(journal) ) { 1004 if ( mJournalList.removeRef(journal) ) {
1005 setModified( true ); 1005 setModified( true );
1006 } 1006 }
1007} 1007}
1008 1008
1009QPtrList<Journal> CalendarLocal::journals4Date( const QDate & date ) 1009Q3PtrList<Journal> CalendarLocal::journals4Date( const QDate & date )
1010{ 1010{
1011 QPtrList<Journal> el; 1011 Q3PtrList<Journal> el;
1012 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1012 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1013 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it ); 1013 if ( it->calEnabled() && it->dtStart().date() == date) el.append( it );
1014 return el; 1014 return el;
1015} 1015}
1016Journal *CalendarLocal::journal( const QDate &date ) 1016Journal *CalendarLocal::journal( const QDate &date )
1017{ 1017{
1018// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl; 1018// kdDebug(5800) << "CalendarLocal::journal() " << date.toString() << endl;
1019 1019
1020 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1020 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1021 if ( it->calEnabled() && it->dtStart().date() == date ) 1021 if ( it->calEnabled() && it->dtStart().date() == date )
1022 return it; 1022 return it;
1023 1023
1024 return 0; 1024 return 0;
1025} 1025}
1026 1026
1027Journal *CalendarLocal::journal( const QString &uid ) 1027Journal *CalendarLocal::journal( const QString &uid )
1028{ 1028{
1029 Journal * retVal = 0; 1029 Journal * retVal = 0;
1030 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1030 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1031 if ( it->calEnabled() && it->uid() == uid ) { 1031 if ( it->calEnabled() && it->uid() == uid ) {
1032 if ( retVal ) { 1032 if ( retVal ) {
1033 if ( retVal->calID() > it->calID() ) { 1033 if ( retVal->calID() > it->calID() ) {
1034 retVal = it; 1034 retVal = it;
1035 } 1035 }
1036 } else { 1036 } else {
1037 retVal = it; 1037 retVal = it;
1038 } 1038 }
1039 } 1039 }
1040 return retVal; 1040 return retVal;
1041} 1041}
1042 1042
1043QPtrList<Journal> CalendarLocal::journals() 1043Q3PtrList<Journal> CalendarLocal::journals()
1044{ 1044{
1045 QPtrList<Journal> el; 1045 Q3PtrList<Journal> el;
1046 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1046 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1047 if ( it->calEnabled() ) el.append( it ); 1047 if ( it->calEnabled() ) el.append( it );
1048 return el; 1048 return el;
1049} 1049}
1050void CalendarLocal::setCalendarRemove( int id ) 1050void CalendarLocal::setCalendarRemove( int id )
1051{ 1051{
1052 1052
1053 { 1053 {
1054 QPtrList<Event> EventList = mEventList; 1054 Q3PtrList<Event> EventList = mEventList;
1055 Event * ev = EventList.first(); 1055 Event * ev = EventList.first();
1056 while ( ev ) { 1056 while ( ev ) {
1057 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") ) 1057 if ( ev->calID() == id && ev->uid().left( 15 ) != QString("last-syncEvent-") )
1058 deleteEvent( ev ); 1058 deleteEvent( ev );
1059 ev = EventList.next(); 1059 ev = EventList.next();
1060 } 1060 }
1061 } 1061 }
1062 { 1062 {
1063 1063
1064 QPtrList<Todo> TodoList = mTodoList; 1064 Q3PtrList<Todo> TodoList = mTodoList;
1065 Todo * ev = TodoList.first(); 1065 Todo * ev = TodoList.first();
1066 while ( ev ) { 1066 while ( ev ) {
1067 if ( ev->calID() == id ) 1067 if ( ev->calID() == id )
1068 deleteTodo( ev ); 1068 deleteTodo( ev );
1069 ev = TodoList.next(); 1069 ev = TodoList.next();
1070 } 1070 }
1071 } 1071 }
1072 { 1072 {
1073 QPtrList<Journal> JournalList = mJournalList; 1073 Q3PtrList<Journal> JournalList = mJournalList;
1074 Journal * ev = JournalList.first(); 1074 Journal * ev = JournalList.first();
1075 while ( ev ) { 1075 while ( ev ) {
1076 if ( ev->calID() == id ) 1076 if ( ev->calID() == id )
1077 deleteJournal( ev ); 1077 deleteJournal( ev );
1078 ev = JournalList.next(); 1078 ev = JournalList.next();
1079 } 1079 }
1080 } 1080 }
1081 1081
1082 clearUndo(0); 1082 clearUndo(0);
1083 1083
1084} 1084}
1085 1085
1086void CalendarLocal::setAllCalendarEnabled( bool enable ) 1086void CalendarLocal::setAllCalendarEnabled( bool enable )
1087{ 1087{
1088 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() ) 1088 for ( Journal *it = mJournalList.first(); it; it = mJournalList.next() )
1089 it->setCalEnabled( enable ); 1089 it->setCalEnabled( enable );