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

List:       kde-pim
Subject:    Re: [Kde-pim] [patch] korganizer - printing calendar item recurrence
From:       "Ron Goodheart" <ron.goodheart () gmail ! com>
Date:       2008-08-31 15:00:15
Message-ID: 138cf8bd0808310800w1843ee4ev20aef33abe1360e0 () mail ! gmail ! com
[Download RAW message or body]

> Date: Thu, 21 Aug 2008 22:18:50 -0700
> From: "Ron Goodheart" <ron.goodheart@gmail.com>
> Subject: [Kde-pim] [patch] korganizer - printing calendar item
>        recurrence
> To: kde-pim <kde-pim@kde.org>
>
> HI all,
> Got the following on my printout when printing my scheduled event on korganizer.
>   "Repeat: TODO: Convert Repeat to String!"
>
> So created the attached patch to print the recurrence information.
>
> However, have only tested with 3.5 - could not get trunk to compile
> due to never finding "AkonadiConfig.cmake".
> The patch does support all of the recurrence available on the 3.5 GUI.
>
> Regards,
> Ron
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: calprintdefaultplugins.diff
> Type: text/x-patch
> Size: 6473 bytes
> Desc: not available
> Url : http://mail.kde.org/pipermail/kde-pim/attachments/20080821/7dc3a12c/attachment.diff
>
> ------------------------------
>
> Date: Fri, 22 Aug 2008 10:05:25 +0200 (CEST)
> From: "Thorsten Staerk" <Thorsten@Staerk.de>
> Subject: Re: [Kde-pim] [patch] korganizer - printing calendar item
>        recurrence
> To: "KDE PIM" <kde-pim@kde.org>
>
>> HI all,
>> Got the following on my printout when printing my scheduled event on
>> korganizer.
>>    "Repeat: TODO: Convert Repeat to String!"
>>
>> So created the attached patch to print the recurrence information.
>>
>> However, have only tested with 3.5 - could not get trunk to compile
>> due to never finding "AkonadiConfig.cmake".
>> The patch does support all of the recurrence available on the 3.5 GUI.
>>
>> Regards,
>> Ron
> good stuff! I can port it to KDE trunk, or you can do after you follow
> http://techbase.kde.org/Getting_Started/Build/KDE4 and get trunk
> compiling. To be short: In order to compile trunk, compile in this order:
> kdesupport
> KDE/kdelibs
> KDE/kdepimlibs
> KDE/kdebase
> KDE/kdepim
> Then the Akonadi problem should be solved.
>
> regards and go on like this
>
> Thorsten
>


Thanks for all the feedback! Another stab at recurrence printing code...

I've attached the modified diffs for korganizer printing 3.5 and trunk
with corrections and information for the translators.
I tried to make abundantly clear the usage of the parameters and moved
out singular/plural constructs into i18np() calls. I will be glad to
revise if I went overboard on this.

Additionally, I did have some difficulty with linking
libkorg_stdprinting.so due to including
"KOGlobals::self()->calendarSystem();" which was needed for some of
the date formatting. This was solved by changing the linking to STATIC
(diff attached) - perhaps there is a better way to do this?

attached are three diffs:
1) changes to 3.5 - recurrence print code
2) changes to trunk - recurrence print code
3) changes to trunk - static linking of libkorg_stdprinting

Regards,
Ron

["calprintdefaultplugins-3.5.diff" (text/x-patch)]

Index: 3.5/kdepim/korganizer/printing/calprintdefaultplugins.cpp
===================================================================
--- 3.5/kdepim/korganizer/printing/calprintdefaultplugins.cpp	(revision 850710)
+++ 3.5/kdepim/korganizer/printing/calprintdefaultplugins.cpp	(working copy)
@@ -37,6 +37,7 @@
 #include <kcalendarsystem.h>
 #include <knuminput.h>
 #include <kcombobox.h>
+#include <koglobals.h>
 
 #include "calprintdefaultplugins.h"
 
@@ -280,12 +281,152 @@
       h = QMAX( printCaptionAndText( p, textRect, stringVis.mEndCaption, \
stringVis.mEndString, captionFont, textFont ), h );  }
     
-    
+    // Convert recurrence to a string
     if ( (*it)->doesRecur() ) {
       QRect recurBox( timesBox.left()+padding(), h+padding(), \
                timesBox.right()-padding(), lineHeight );
-      // TODO: Convert the recurrence to a string and print it out!
-      QString recurString( "TODO: Convert Repeat to String!" );
-      h = QMAX( printCaptionAndText( p, recurBox, i18n("Repeats: "), recurString, \
captionFont, textFont ), h ); +      KCal::Recurrence *recurs = (*it)->recurrence();
+      // recurrence
+      QStringList dayList;
+      dayList.push_back( i18n("5th Last") );
+      dayList.push_back( i18n("4th Last") );
+      dayList.push_back( i18n("3rd Last") );
+      dayList.push_back( i18n("2nd Last") );
+      dayList.push_back( i18n("Last") ); 
+      dayList.push_back( i18n("unknown") ); // zero, should not be referenced
+      dayList.push_back( i18n("1st") );
+      dayList.push_back( i18n("2nd") );
+      dayList.push_back( i18n("3rd") );
+      dayList.push_back( i18n("4th") );
+      dayList.push_back( i18n("5th") );      
+      QString recurString;
+      const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
+      switch(recurs->recurrenceType()) {
+        case Recurrence::rNone:
+          recurString = i18n("None");
+          break;
+        case Recurrence::rDaily:
+          recurString = i18n("Every %n day",
+                             "Every %n days",
+                             recurs->frequency());
+          break;
+        case Recurrence::rWeekly: 
+        {
+          QString dayNames;
+          // Respect start of week setting
+          int weekStart = KGlobal::locale()->weekStartDay();
+          bool addSpace = false;
+          for ( int i = 0; i < 7; ++i ) { 
+            if ( recurs->days().testBit( (i+weekStart+6)%7 )) {
+              if (addSpace) dayNames.append(" ");  
+              dayNames.append( calSys->weekDayName( ((i+weekStart+6)%7)+1, true ) );
+              addSpace=true;
+            }
+          }
+          recurString = i18n("Every NUMBER WEEK[S] on WEEKDAYNAMELIST"
+                             " (Every 4 weeks on Tues Wed Thu)",
+                             "Every %1 %2 on %3")
+                            .arg(recurs->frequency())
+                            .arg(i18n("week","weeks",recurs->frequency()))
+              							.arg(dayNames);
+          break;
+        }
+        case Recurrence::rMonthlyPos:
+        {
+          KCal::RecurrenceRule::WDayPos rule = recurs->monthPositions()[0];
+          recurString = i18n("Every NUMBER MONTH[S] on the [2nd|3rd|...] \
WEEKDAYNAME" +                             " (Every 2 months on the 3rd Wednesday)",
+                             "Every %1 %2 on the %3 %4")
+              							.arg(recurs->frequency())
+                            .arg(i18n("month","months",recurs->frequency()))
+                            .arg(dayList[rule.pos() + 5])
+                            .arg(calSys->weekDayName(rule.day()));
+          break;
+        }
+        case Recurrence::rMonthlyDay:
+        {     
+          int days = recurs->monthDays()[0];
+          if (days < 0) {
+            recurString = i18n("Every NUMBER MONTH[S] on the [2nd|3rd|...] day"
+                               " (Every 5 months on the 3rd day)",
+                               "Every %1 %2 on the %3 day")
+              							  .arg(recurs->frequency())
+                              .arg(i18n("month","months",recurs->frequency()))
+                              .arg( dayList[days + 5] );
+          } else {
+            recurString = i18n("Every NUMBER MONTH[S} on day NUMBER"
+                               " (Every 4 months on day 5)",
+              							   "Every %1 %2 on day %3")
+               							  .arg(recurs->frequency())
+                              .arg(i18n("month","months",recurs->frequency()))
+                              .arg(recurs->monthDays()[0]);
+          }
+          break;
+        }                              
+
+        case Recurrence::rYearlyMonth:
+          recurString = i18n("Every NUMBER YEAR[S] on day NUMBER of MONTHNAME"
+                             " (Every 2 years on day 12 of March)",
+              							 "Every %1 %2 on day %3 of %4")
+              							.arg(recurs->frequency())
+                            .arg(i18n("year","years",recurs->frequency()))
+                            .arg(recurs->yearDates()[0])
+                            .arg(calSys->monthName(recurs->yearMonths()[0],1960));
+          break;
+        case Recurrence::rYearlyPos:
+        {
+          KCal::RecurrenceRule::WDayPos rule = recurs->yearPositions()[0];
+          recurString = i18n("Every NUMBER YEAR[S] on the [2nd|3rd|...] WEEKDAYNAME \
of MONTHNAME" +                             " (Every 2 years on the 2nd Tuesday of \
March)", +              							 "Every %1 %2 on the %3 %4 of %5")
+              							.arg(recurs->frequency())
+                            .arg(i18n("year","years",recurs->frequency()))
+                            .arg( dayList[rule.pos() + 5] )
+                            .arg( calSys->weekDayName(rule.day()) )
+                            .arg( calSys->monthName(recurs->yearMonths()[0],1960) );
+          break;
+        }
+        case Recurrence::rYearlyDay:
+          recurString = i18n("Every NUMBER YEAR[S] on day NUMBER"
+                             " (Every 2 years on day 122)",
+              							 "Every %1 %2 on day %3")
+              							.arg(recurs->frequency())
+                            .arg(i18n("year","years",recurs->frequency()))
+                            .arg( recurs->yearDays()[0] );
+          break;
+      }      
+      // occurrences
+      QString occurString;
+      switch (recurs->duration()) {
+        case 0: // end date set
+          occurString = i18n("until DATE", "until %1")
+							.arg(KGlobal::locale()->formatDate(recurs->endDate(),true));
+          break;
+        case -1: // infinite
+          break;
+        default: // number of occurrences
+          occurString = i18n("for %n occurence", 
+                  					 "for %n occurences",
+              							 recurs->duration());
+          break;
+      }
+      // exception dates
+      QString exceptString;
+      if ( !recurs->exDates().isEmpty() ) {
+        exceptString = i18n("excluding DATE DATE...", "except");
+        for ( unsigned i = 0; i < recurs->exDates().size(); i++ ) {
+          exceptString.append(" ");
+          exceptString.append( KGlobal::locale()->formatDate( \
recurs->exDates()[i],true) ); +        }
+      }      
+      QString displayString;
+      displayString.append(recurString);
+      if (!displayString.endsWith(" "))
+        displayString.append(" ");
+      displayString.append(occurString);
+      if (!displayString.endsWith(" "))
+        displayString.append(" ");
+      displayString.append(exceptString);
+      h = QMAX( printCaptionAndText( p, recurBox, i18n("Repeats: "), displayString, \
captionFont, textFont ), h );  }
     
     QRect alarmBox( timesBox.left()+padding(), h+padding(), \
timesBox.right()-padding(), lineHeight );


["calprintdefaultplugins-trunk.diff" (text/x-patch)]

Index: trunk/KDE/kdepim/korganizer/printing/calprintdefaultplugins.cpp
===================================================================
--- trunk/KDE/kdepim/korganizer/printing/calprintdefaultplugins.cpp	(revision 854669)
+++ trunk/KDE/kdepim/korganizer/printing/calprintdefaultplugins.cpp	(working copy)
@@ -34,7 +34,7 @@
 #include <kcal/todo.h>
 #include <kcal/calendar.h>
 
-#include <kglobal.h>
+#include <koglobals.h>
 #include <klocale.h>
 #include <kdebug.h>
 #include <kconfig.h>
@@ -50,6 +50,7 @@
 #include <QPrinter>
 #include <QWidget>
 
+
 /**************************************************************
  *           Print Incidence
  **************************************************************/
@@ -296,13 +297,181 @@
                                      stringVis.mEndString, captionFont, textFont ), \
h );  }
 
+    // Convert recurrence to a string
     if ( (*it)->recurs() ) {
-      QRect recurBox( timesBox.left() + padding(), h + padding(),
-                      timesBox.right() - padding(), lineHeight );
-      // TODO: Convert the recurrence to a string and print it out!
-      QString recurString( "TODO: Convert Repeat to String!" );
-      h = qMax( printCaptionAndText( p, recurBox, i18n( "Repeats: " ),
-                                     recurString, captionFont, textFont ), h );
+      QRect recurBox( timesBox.left()+padding(), h+padding(), \
timesBox.right()-padding(), lineHeight ); +      KCal::Recurrence *recurs = \
(*it)->recurrence(); +      // recurrence
+      QStringList dayList;
+      dayList.push_back( i18n("31st Last") );
+      dayList.push_back( i18n("30th Last") );
+      dayList.push_back( i18n("29th Last") );
+      dayList.push_back( i18n("28th Last") );
+      dayList.push_back( i18n("27th Last") );
+      dayList.push_back( i18n("26th Last") );
+      dayList.push_back( i18n("25th Last") );
+      dayList.push_back( i18n("24th Last") );
+      dayList.push_back( i18n("23rd Last") );
+      dayList.push_back( i18n("22nd Last") );
+      dayList.push_back( i18n("21st Last") );
+      dayList.push_back( i18n("20th Last") );
+      dayList.push_back( i18n("19th Last") );
+      dayList.push_back( i18n("18th Last") );
+      dayList.push_back( i18n("17th Last") );
+      dayList.push_back( i18n("16th Last") );
+      dayList.push_back( i18n("15th Last") );
+      dayList.push_back( i18n("14th Last") );
+      dayList.push_back( i18n("13th Last") );
+      dayList.push_back( i18n("12th Last") );
+      dayList.push_back( i18n("11th Last") );
+      dayList.push_back( i18n("10th Last") );
+      dayList.push_back( i18n("9th Last") );
+      dayList.push_back( i18n("8th Last") );
+      dayList.push_back( i18n("7th Last") );
+      dayList.push_back( i18n("6th Last") );
+      dayList.push_back( i18n("5th Last") );
+      dayList.push_back( i18n("4th Last") );
+      dayList.push_back( i18n("3rd Last") );
+      dayList.push_back( i18n("2nd Last") );
+      dayList.push_back( i18n("Last") ); 
+      dayList.push_back( i18n("unknown") ); //#31 - zero offset from UI, should not \
be referenced +      dayList.push_back( i18n("1st") );
+      dayList.push_back( i18n("2nd") );
+      dayList.push_back( i18n("3rd") );
+      dayList.push_back( i18n("4th") );
+      dayList.push_back( i18n("5th") );      
+      QString recurString;
+      const KCalendarSystem *calSys = KOGlobals::self()->calendarSystem();
+      switch(recurs->recurrenceType()) {
+        case Recurrence::rNone:
+          recurString = i18n("None");
+          break;
+        case Recurrence::rDaily:
+          recurString = i18np("Every %1 day",
+                              "Every %1 days",
+                              recurs->frequency());
+          break;
+        case Recurrence::rWeekly: 
+        {
+          QString dayNames;
+          // Respect start of week setting
+          int weekStart = KGlobal::locale()->weekStartDay();
+          bool addSpace = false;
+          for ( int i = 0; i < 7; ++i ) { 
+            if ( recurs->days().testBit( (i+weekStart+6)%7 )) {
+              if (addSpace) dayNames.append(" ");  
+              dayNames.append( calSys->weekDayName( ((i+weekStart+6)%7)+1, \
KCalendarSystem::ShortDayName ) ); +              addSpace=true;
+            }
+          } 
+          recurString = i18nc("Every N WEEK[S] on WEEKDAYNAMELIST"
+                              " (Every 4 weeks on Tues Wed Thu)",
+                              "Every <numid>%1</numid> %2 on %3",
+                              recurs->frequency(),
+                              i18np("week","weeks",recurs->frequency()),
+							                dayNames );
+          break;
+        }
+        case Recurrence::rMonthlyPos:
+        {
+          KCal::RecurrenceRule::WDayPos rule = recurs->monthPositions()[0];
+          recurString = i18nc("Every N MONTH[S] on the [2nd|3rd|...] WEEKDAYNAME"
+                              " (Every 2 months on the 3rd Wednesday)",
+                              "Every <numid>%1</numid> %2 on the %3 %4",
+  					            		  recurs->frequency(),
+                              i18np("month","months",recurs->frequency()),
+                              dayList[rule.pos() + 31],
+                              \
calSys->weekDayName(rule.day(),KCalendarSystem::LongDayName) ); +          break;
+        }
+        case Recurrence::rMonthlyDay:
+        {     
+          int days = recurs->monthDays()[0];
+          if (days < 0) {
+            recurString = i18nc("Every N MONTH[S] on the [2nd|3rd|...] day"
+                                " (Every 5 months on the 3rd day)",
+                                "Every <numid>%1<niumid> %2 on the %3 day",
+  					            		    recurs->frequency(),
+                                i18np("month","months",recurs->frequency()),
+                                dayList[days + 31] );
+          } else {
+            recurString = i18nc("Every N MONTH[S} on day N"
+                                " (Every 4 months on day 5)",
+		              					    "Every <numid>%1</numid> %2 on day <numid>%3</numid>",
+   	            						    recurs->frequency(),
+                                i18np("month","months",recurs->frequency()),
+                                recurs->monthDays()[0] );
+          }
+          break;
+        }                              
+
+        case Recurrence::rYearlyMonth:
+          recurString = i18nc("Every N YEAR[S] on day N of MONTHNAME"
+                              " (Every 2 years on day 12 of March)",
+						              	  "Every <numid>%1</numid> %2 on day <numid>%3</numid> of %4",
+  				            			  recurs->frequency(),
+                              i18np("year","years",recurs->frequency()),
+                              recurs->yearDates()[0],
+                              calSys->monthName(recurs->yearMonths()[0],1960) );
+          break;
+        case Recurrence::rYearlyPos:
+        {
+          KCal::RecurrenceRule::WDayPos rule = recurs->yearPositions()[0];
+          recurString = i18nc("Every N YEAR[S] on the [2nd|3rd|...] WEEKDAYNAME of \
MONTHNAME" +                              " (Every 2 years on the 2nd Tuesday of \
March)", +						              	  "Every <numid>%1</numid> %2 on the %3 %4 of %5",
+  						            	  recurs->frequency(),
+                              i18np("year","years",recurs->frequency()),
+                              dayList[rule.pos() + 31],
+                              calSys->weekDayName(rule.day(), \
KCalendarSystem::LongDayName), +                              \
calSys->monthName(recurs->yearMonths()[0],1960) ); +          break;
+        }
+        case Recurrence::rYearlyDay:
+          recurString = i18nc("Every N YEAR[S] on day N"
+                              " (Every 2 years on day 122)",
+							                "Every <numid>%1</numid> %2 on day <numid>%3</numid>",
+  				            			  recurs->frequency(),
+                              i18np("year","years",recurs->frequency()),
+                              recurs->yearDays()[0] );
+          break;
+      }      
+      // occurrences
+      QString occurString;
+      switch (recurs->duration()) {
+        case 0: // end date set
+          occurString = i18nc("until DATE", "until %1",
+							                KGlobal::locale()->formatDate(recurs->endDate(), 
+							                KLocale::ShortDate) );
+          break;
+        case -1: // infinite
+          break;
+        default: // number of occurrences
+          occurString = i18nc("for N %OCCURENCE[S]", 
+          					          "for <numid>%1</numid> %2",
+						              	  recurs->duration(),
+						              	  i18np("occurence", "occurences", recurs->duration()) );
+          break;
+      }
+      // exception dates
+      QString exceptString;
+      if ( !recurs->exDates().isEmpty() ) {
+        exceptString = i18nc("except for listed dates", "except");
+        for ( int i = 0; i < recurs->exDates().size(); i++ ) {
+          exceptString.append(" ");
+          exceptString.append( KGlobal::locale()->formatDate(recurs->exDates()[i], 
+                               KLocale::ShortDate) );
+        }
+      }      
+      QString displayString;
+      displayString.append(recurString);
+      if (!displayString.endsWith(" "))
+        displayString.append(" ");
+      displayString.append(occurString);
+      if (!displayString.endsWith(" "))
+        displayString.append(" ");
+      displayString.append(exceptString);
+      h = QMAX( printCaptionAndText( p, recurBox, i18n("Repeats: "), displayString, \
captionFont, textFont ), h );  }
 
     QRect alarmBox( timesBox.left() + padding(), h + padding(),


["printing-CMakeLists-trunk.diff" (text/x-patch)]

Index: trunk/KDE/kdepim/korganizer/printing/CMakeLists.txt
===================================================================
--- trunk/KDE/kdepim/korganizer/printing/CMakeLists.txt	(revision 854669)
+++ trunk/KDE/kdepim/korganizer/printing/CMakeLists.txt	(working copy)
@@ -31,7 +31,7 @@
    calprinttodoconfig_base.ui 
    calprintweekconfig_base.ui )
 
-kde4_add_library(korg_stdprinting SHARED ${korg_stdprinting_LIB_SRCS})
+kde4_add_library(korg_stdprinting STATIC ${korg_stdprinting_LIB_SRCS})
 
 target_link_libraries(korg_stdprinting ${KDE4_KUTILS_LIBS} kocorehelper kdepim \
${KDE4_KCAL_LIBS} ${QT_QT3SUPPORT_LIBRARY})  



_______________________________________________
KDE PIM mailing list kde-pim@kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/

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

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