[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/KDE/3.5/kdepim/kontact/plugins/korganizer
From:       Allen Winter <winter () kde ! org>
Date:       2006-09-22 16:51:04
Message-ID: 1158943864.796906.20880.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 587417 by winterz:

Fix the bug where recurring events can be out of chronological order.

This is because Calendar::sortEvents() method only looks at the dtStartDate()
when sorting and does not concern itself with recurrence info.  In order
to fix this, we must muck the the QDate part of the start datetime
of recurring events.

And, while I'm at it, compute the current date once rather then
multiple (expensive) times.



 M  +23 -10    summarywidget.cpp  


--- branches/KDE/3.5/kdepim/kontact/plugins/korganizer/summarywidget.cpp #587416:587417
@@ -93,11 +93,26 @@
   QPixmap pm = loader.loadIcon( "appointment", KIcon::Small );
 
   QDate dt;
-  for ( dt=QDate::currentDate();
-        dt<=QDate::currentDate().addDays( days - 1 );
+  QDate currentDate = QDate::currentDate();
+  for ( dt=currentDate;
+        dt<=currentDate.addDays( days - 1 );
         dt=dt.addDays(1) ) {
     KCal::Event::List events = mCalendar->events( dt );
 
+    KCal::Event *ev;
+    KCal::Event::List::ConstIterator it;
+    QDateTime qdt;
+
+    // Find recurring events, replacing the QDate with the currentDate
+    for ( it=events.begin(); it!=events.end(); ++it ) {
+      ev = *it;
+      if ( ev->recursOn( dt ) ) {
+        qdt = ev->dtStart();
+        qdt.setDate( dt );
+        ev->setDtStart( qdt );
+      }
+    }
+
     // sort the events for this date by summary
     events = KCal::Calendar::sortEvents( &events,
                                          KCal::EventSortSummary,
@@ -107,8 +122,6 @@
                                          KCal::EventSortStartDate,
                                          KCal::SortDirectionAscending );
 
-    KCal::Event *ev;
-    KCal::Event::List::ConstIterator it;
     for ( it=events.begin(); it!=events.end(); ++it ) {
       ev = *it;
 
@@ -116,8 +129,8 @@
       int span=1; int dayof=1;
       if ( ev->isMultiDay() ) {
         QDate d = ev->dtStart().date();
-        if ( d < QDate::currentDate() ) {
-          d = QDate::currentDate();
+        if ( d < currentDate ) {
+          d = currentDate;
         }
         while ( d < ev->dtEnd().date() ) {
           if ( d < dt ) {
@@ -146,12 +159,12 @@
 
       // Modify event date for printing
       QDate sD = QDate::QDate( dt.year(), dt.month(), dt.day() );
-      if ( ( sD.month() == QDate::currentDate().month() ) &&
-           ( sD.day()   == QDate::currentDate().day() ) ) {
+      if ( ( sD.month() == currentDate.month() ) &&
+           ( sD.day()   == currentDate.day() ) ) {
         datestr = i18n( "Today" );
         makeBold = true;
-      } else if ( ( sD.month() == QDate::currentDate().addDays( 1 ).month() ) &&
-                  ( sD.day()   == QDate::currentDate().addDays( 1 ).day() ) ) {
+      } else if ( ( sD.month() == currentDate.addDays( 1 ).month() ) &&
+                  ( sD.day()   == currentDate.addDays( 1 ).day() ) ) {
         datestr = i18n( "Tomorrow" );
       } else {
         datestr = KGlobal::locale()->formatDate( sD );
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic