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

List:       kde-commits
Subject:    KDE/kdepimlibs/kcalutils
From:       Allen Winter <winter () kde ! org>
Date:       2010-10-03 22:37:37
Message-ID: 20101003223737.6B5EFAC88C () svn ! kde ! org
[Download RAW message or body]

SVN commit 1182237 by winterz:

add EXDATES support to recurrenceString().

MERGE: e35


 M  +103 -47   incidenceformatter.cpp  
 M  +11 -3     tests/testincidenceformatter.cpp  


--- trunk/KDE/kdepimlibs/kcalutils/incidenceformatter.cpp #1182236:1182237
@@ -3727,54 +3727,64 @@
   dayList.append( i18n( "29th" ) );
   dayList.append( i18n( "30th" ) );
   dayList.append( i18n( "31st" ) );
+
   int weekStart = KGlobal::locale()->weekStartDay();
   QString dayNames;
-  QString txt;
   const KCalendarSystem *calSys = KGlobal::locale()->calendar();
+
   Recurrence *recur = incidence->recurrence();
+
+  QString txt, recurStr;
   switch ( recur->recurrenceType() ) {
   case Recurrence::rNone:
     return i18n( "No recurrence" );
+
   case Recurrence::rMinutely:
     if ( recur->duration() != -1 ) {
-      txt = i18np( "Recurs every minute until %2",
+      recurStr = i18np( "Recurs every minute until %2",
                    "Recurs every %1 minutes until %2",
                    recur->frequency(), recurEnd( incidence ) );
       if ( recur->duration() >  0 ) {
-        txt += i18nc( "number of occurrences",
+        recurStr += i18nc( "number of occurrences",
                       " (<numid>%1</numid> occurrences)",
                       recur->duration() );
       }
-      return txt;
+    } else {
+      recurStr = i18np( "Recurs every minute",
+                        "Recurs every %1 minutes", recur->frequency() );
     }
-    return i18np( "Recurs every minute",
-                  "Recurs every %1 minutes", recur->frequency() );
+    break;
+
   case Recurrence::rHourly:
     if ( recur->duration() != -1 ) {
-      txt = i18np( "Recurs hourly until %2",
+      recurStr = i18np( "Recurs hourly until %2",
                    "Recurs every %1 hours until %2",
                    recur->frequency(), recurEnd( incidence ) );
       if ( recur->duration() >  0 ) {
-        txt += i18nc( "number of occurrences",
+        recurStr += i18nc( "number of occurrences",
                       " (<numid>%1</numid> occurrences)",
                       recur->duration() );
       }
-      return txt;
+    } else {
+      recurStr = i18np( "Recurs hourly", "Recurs every %1 hours", recur->frequency() );
     }
-    return i18np( "Recurs hourly", "Recurs every %1 hours", recur->frequency() );
+    break;
+
   case Recurrence::rDaily:
     if ( recur->duration() != -1 ) {
-      txt = i18np( "Recurs daily until %2",
+      recurStr = i18np( "Recurs daily until %2",
                    "Recurs every %1 days until %2",
                    recur->frequency(), recurEnd( incidence ) );
       if ( recur->duration() >  0 ) {
-        txt += i18nc( "number of occurrences",
+        recurStr += i18nc( "number of occurrences",
                       " (<numid>%1</numid> occurrences)",
                       recur->duration() );
       }
-      return txt;
+    } else {
+      recurStr = i18np( "Recurs daily", "Recurs every %1 days", recur->frequency() );
     }
-    return i18np( "Recurs daily", "Recurs every %1 days", recur->frequency() );
+    break;
+
   case Recurrence::rWeekly:
   {
     bool addSpace = false;
@@ -3792,28 +3802,29 @@
       dayNames = i18nc( "Recurs weekly on no days", "no days" );
     }
     if ( recur->duration() != -1 ) {
-      txt = i18ncp( "Recurs weekly on [list of days] until end-date",
+      recurStr = i18ncp( "Recurs weekly on [list of days] until end-date",
                     "Recurs weekly on %2 until %3",
                     "Recurs every <numid>%1</numid> weeks on %2 until %3",
                     recur->frequency(), dayNames, recurEnd( incidence ) );
       if ( recur->duration() >  0 ) {
-        txt += i18nc( "number of occurrences",
+        recurStr += i18nc( "number of occurrences",
                       " (<numid>%1</numid> occurrences)",
                       recur->duration() );
       }
-      return txt;
-    }
-    return i18ncp( "Recurs weekly on [list of days]",
+    } else {
+      recurStr = i18ncp( "Recurs weekly on [list of days]",
                    "Recurs weekly on %2",
                    "Recurs every <numid>%1</numid> weeks on %2",
                    recur->frequency(), dayNames );
   }
+    break;
+  }
   case Recurrence::rMonthlyPos:
   {
     if ( !recur->monthPositions().isEmpty() ) {
       RecurrenceRule::WDayPos rule = recur->monthPositions()[0];
       if ( recur->duration() != -1 ) {
-        txt = i18ncp( "Recurs every N months on the [2nd|3rd|...]"
+        recurStr = i18ncp( "Recurs every N months on the [2nd|3rd|...]"
                       " weekdayname until end-date",
                       "Recurs every month on the %2 %3 until %4",
                       "Recurs every <numid>%1</numid> months on the %2 %3 until %4",
@@ -3822,19 +3833,19 @@
                       calSys->weekDayName( rule.day(), KCalendarSystem::LongDayName ),
                       recurEnd( incidence ) );
         if ( recur->duration() >  0 ) {
-          txt += i18nc( "number of occurrences",
+          recurStr += i18nc( "number of occurrences",
                         " (<numid>%1</numid> occurrences)",
                         recur->duration() );
         }
-        return txt;
-      }
-      return i18ncp( "Recurs every N months on the [2nd|3rd|...] weekdayname",
+      } else {
+        recurStr = i18ncp( "Recurs every N months on the [2nd|3rd|...] weekdayname",
                      "Recurs every month on the %2 %3",
                      "Recurs every %1 months on the %2 %3",
                      recur->frequency(),
                      dayList[rule.pos() + 31],
                      calSys->weekDayName( rule.day(), KCalendarSystem::LongDayName ) );
     }
+    }
     break;
   }
   case Recurrence::rMonthlyDay:
@@ -3842,32 +3853,32 @@
     if ( !recur->monthDays().isEmpty() ) {
       int days = recur->monthDays()[0];
       if ( recur->duration() != -1 ) {
-        txt = i18ncp( "Recurs monthly on the [1st|2nd|...] day until end-date",
+        recurStr = i18ncp( "Recurs monthly on the [1st|2nd|...] day until end-date",
                       "Recurs monthly on the %2 day until %3",
                       "Recurs every %1 months on the %2 day until %3",
                       recur->frequency(),
                       dayList[days + 31],
                       recurEnd( incidence ) );
         if ( recur->duration() >  0 ) {
-          txt += i18nc( "number of occurrences",
+          recurStr += i18nc( "number of occurrences",
                         " (<numid>%1</numid> occurrences)",
                         recur->duration() );
         }
-        return txt;
-      }
-      return i18ncp( "Recurs monthly on the [1st|2nd|...] day",
+      } else {
+        recurStr = i18ncp( "Recurs monthly on the [1st|2nd|...] day",
                      "Recurs monthly on the %2 day",
                      "Recurs every <numid>%1</numid> month on the %2 day",
                      recur->frequency(),
                      dayList[days + 31] );
     }
+    }
     break;
   }
   case Recurrence::rYearlyMonth:
   {
     if ( recur->duration() != -1 ) {
       if ( !recur->yearDates().isEmpty() && !recur->yearMonths().isEmpty() ) {
-        txt = i18ncp( "Recurs Every N years on month-name [1st|2nd|...]"
+        recurStr = i18ncp( "Recurs Every N years on month-name [1st|2nd|...]"
                       " until end-date",
                       "Recurs yearly on %2 %3 until %4",
                       "Recurs every %1 years on %2 %3 until %4",
@@ -3876,15 +3887,14 @@
                       dayList[ recur->yearDates()[0] + 31 ],
                       recurEnd( incidence ) );
         if ( recur->duration() >  0 ) {
-          txt += i18nc( "number of occurrences",
+          recurStr += i18nc( "number of occurrences",
                         " (<numid>%1</numid> occurrences)",
                         recur->duration() );
         }
-        return txt;
       }
-    }
+    } else {
     if ( !recur->yearDates().isEmpty() && !recur->yearMonths().isEmpty() ) {
-      return i18ncp( "Recurs Every N years on month-name [1st|2nd|...]",
+        recurStr = i18ncp( "Recurs Every N years on month-name [1st|2nd|...]",
                      "Recurs yearly on %2 %3",
                      "Recurs every %1 years on %2 %3",
                      recur->frequency(),
@@ -3893,25 +3903,26 @@
                      dayList[ recur->yearDates()[0] + 31 ] );
     } else {
       if (!recur->yearMonths().isEmpty() ) {
-        return i18nc( "Recurs Every year on month-name [1st|2nd|...]",
+          recurStr = i18nc( "Recurs Every year on month-name [1st|2nd|...]",
                       "Recurs yearly on %1 %2",
                       calSys->monthName( recur->yearMonths()[0],
                                          recur->startDate().year() ),
                       dayList[ recur->startDate().day() + 31 ] );
       } else {
-        return i18nc( "Recurs Every year on month-name [1st|2nd|...]",
+          recurStr = i18nc( "Recurs Every year on month-name [1st|2nd|...]",
                       "Recurs yearly on %1 %2",
                       calSys->monthName( recur->startDate().month(),
                                          recur->startDate().year() ),
                       dayList[ recur->startDate().day() + 31 ] );
       }
     }
+    }
     break;
   }
   case Recurrence::rYearlyDay:
     if ( !recur->yearDays().isEmpty() ) {
       if ( recur->duration() != -1 ) {
-        txt = i18ncp( "Recurs every N years on day N until end-date",
+        recurStr = i18ncp( "Recurs every N years on day N until end-date",
                       "Recurs every year on day <numid>%2</numid> until %3",
                       "Recurs every <numid>%1</numid> years"
                       " on day <numid>%2</numid> until %3",
@@ -3919,25 +3930,25 @@
                       recur->yearDays()[0],
                       recurEnd( incidence ) );
         if ( recur->duration() >  0 ) {
-          txt += i18nc( "number of occurrences",
+          recurStr += i18nc( "number of occurrences",
                         " (<numid>%1</numid> occurrences)",
                         recur->duration() );
         }
-        return txt;
-      }
-      return i18ncp( "Recurs every N YEAR[S] on day N",
+      } else {
+        recurStr = i18ncp( "Recurs every N YEAR[S] on day N",
                      "Recurs every year on day <numid>%2</numid>",
                      "Recurs every <numid>%1</numid> years"
                      " on day <numid>%2</numid>",
                      recur->frequency(), recur->yearDays()[0] );
     }
+    }
     break;
   case Recurrence::rYearlyPos:
   {
     if ( !recur->yearMonths().isEmpty() && !recur->yearPositions().isEmpty() ) {
       RecurrenceRule::WDayPos rule = recur->yearPositions()[0];
       if ( recur->duration() != -1 ) {
-        txt = i18ncp( "Every N years on the [2nd|3rd|...] weekdayname "
+        recurStr = i18ncp( "Every N years on the [2nd|3rd|...] weekdayname "
                       "of monthname until end-date",
                       "Every year on the %2 %3 of %4 until %5",
                       "Every <numid>%1</numid> years on the %2 %3 of %4"
@@ -3948,13 +3959,12 @@
                       calSys->monthName( recur->yearMonths()[0], recur->startDate().year() ),
                       recurEnd( incidence ) );
         if ( recur->duration() >  0 ) {
-          txt += i18nc( "number of occurrences",
+          recurStr += i18nc( "number of occurrences",
                         " (<numid>%1</numid> occurrences)",
                         recur->duration() );
         }
-        return txt;
-      }
-      return i18ncp( "Every N years on the [2nd|3rd|...] weekdayname "
+      } else {
+        recurStr = i18ncp( "Every N years on the [2nd|3rd|...] weekdayname "
                      "of monthname",
                      "Every year on the %2 %3 of %4",
                      "Every <numid>%1</numid> years on the %2 %3 of %4",
@@ -3964,11 +3974,57 @@
                      calSys->monthName( recur->yearMonths()[0], recur->startDate().year() ) );
     }
   }
+  }
   break;
   }
-  return i18n( "Incidence recurs" );
+
+  if ( recurStr.isEmpty() ) {
+    recurStr = i18n( "Incidence recurs" );
 }
 
+  // Now, append the EXDATES
+  DateTimeList l = recur->exDateTimes();
+  DateTimeList::ConstIterator il;
+  QStringList exStr;
+  for ( il = l.constBegin(); il != l.constEnd(); ++il ) {
+    switch ( recur->recurrenceType() ) {
+    case Recurrence::rMinutely:
+      exStr << i18n( "minute %1", (*il).time().minute() );
+      break;
+    case Recurrence::rHourly:
+      exStr << KGlobal::locale()->formatTime( (*il).time() );
+      break;
+    case Recurrence::rDaily:
+      exStr << KGlobal::locale()->formatDate( (*il).date(), KLocale::ShortDate );
+      break;
+    case Recurrence::rWeekly:
+      exStr << calSys->weekDayName( (*il).date(), KCalendarSystem::ShortDayName );
+      break;
+    case Recurrence::rMonthlyPos:
+      exStr << KGlobal::locale()->formatDate( (*il).date(), KLocale::ShortDate );
+      break;
+    case Recurrence::rMonthlyDay:
+      exStr << KGlobal::locale()->formatDate( (*il).date(), KLocale::ShortDate );
+      break;
+    case Recurrence::rYearlyMonth:
+      exStr << calSys->monthName( (*il).date(), KCalendarSystem::LongName );
+      break;
+    case Recurrence::rYearlyDay:
+      exStr << KGlobal::locale()->formatDate( (*il).date(), KLocale::ShortDate );
+      break;
+    case Recurrence::rYearlyPos:
+      exStr << KGlobal::locale()->formatDate( (*il).date(), KLocale::ShortDate );
+      break;
+    }
+  }
+
+  if ( !exStr.isEmpty() ) {
+    recurStr = i18n( "%1 (excluding %2)", recurStr, exStr.join( "," ) );
+  }
+
+  return recurStr;
+}
+
 QString IncidenceFormatter::timeToString( const KDateTime &date,
                                           bool shortfmt,
                                           const KDateTime::Spec &spec )
--- trunk/KDE/kdepimlibs/kcalutils/tests/testincidenceformatter.cpp #1182236:1182237
@@ -26,6 +26,7 @@
 #include <kcalcore/event.h>
 
 #include <KDateTime>
+#include <KLocale>
 
 #include <QDebug>
 #include <qtest_kde.h>
@@ -42,14 +43,14 @@
   QTime tim( 12, 0, 0 );
   KDateTime kdt( day,  tim,  KDateTime::UTC );
   e->setDtStart( kdt );
-  e->setDtEnd( kdt.addSecs( 60 * 60 ) );
+  e->setDtEnd( kdt.addSecs( 60 * 60 ) );  // 1hr event
 
   QVERIFY( IncidenceFormatter::recurrenceString( e ) == i18n( "No recurrence" ) );
 
   Recurrence *r = e->recurrence();
 
   r->setDaily( 1 );
-  r->setEndDateTime( kdt.addSecs( 60 * 60 * 24 * 5 ) ); // ends 5 days from now
+  r->setEndDateTime( kdt.addDays( 5 ) ); // ends 5 days from now
   QVERIFY( IncidenceFormatter::recurrenceString( e ) ==
            i18n( "Recurs daily until 2010-10-08 12:00" ) );
 
@@ -58,6 +59,13 @@
   QVERIFY( IncidenceFormatter::recurrenceString( e ) ==
            i18n( "Recurs every 2 days until 2010-10-08 12:00" ) );
 
+  r->addExDateTime( kdt.addDays( 1 ) );
+  QVERIFY( IncidenceFormatter::recurrenceString( e ) ==
+           i18n( "Recurs every 2 days until 2010-10-08 12:00 (excluding 2010-10-04)" ) );
+
+  r->addExDateTime( kdt.addDays( 3 ) );
+  QVERIFY( IncidenceFormatter::recurrenceString( e ) ==
+           i18n( "Recurs every 2 days until 2010-10-08 12:00 (excluding 2010-10-04,2010-10-06)" ) );
+
 //  qDebug() << "recurrenceString=" << IncidenceFormatter::recurrenceString( e );
-
 }
[prev in list] [next in list] [prev in thread] [next in thread] 

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