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

List:       kde-commits
Subject:    KDE/kdepim/mobile/calendar
From:       Bertjan Broeksema <broeksema () kde ! org>
Date:       2010-10-07 10:08:15
Message-ID: 20101007100815.821DFAC892 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1183390 by bbroeksema:

Fix duration formatting in the listview of the calendar app. Take in account
that an Incidence can be a todo as well. (No support for the other incidence
types yet, though).

BUG: 251316


 M  +1 -1      EventListView.qml  
 M  +28 -7     eventlistproxy.cpp  


--- trunk/KDE/kdepim/mobile/calendar/EventListView.qml #1183389:1183390
@@ -40,7 +40,7 @@
           anchors.topMargin : 1
           anchors.left : parent.left
           anchors.leftMargin : 10
-          text : KDE.i18n( "%1 (duration %2)", model.begin, model.duration );
+          text : KDE.i18n( "%1 (%2)", model.begin, model.duration );
           color : "#0C55BB"
           font.pixelSize: 16
           elide: "ElideRight"
--- trunk/KDE/kdepim/mobile/calendar/eventlistproxy.cpp #1183389:1183390
@@ -20,8 +20,10 @@
 #include "eventlistproxy.h"
 
 #include <akonadi/item.h>
-#include <kcalcore/event.h>
 
+#include <KCalCore/Event>
+#include <KCalCore/Todo>
+
 #include <KLocale>
 #include <KGlobal>
 
@@ -31,21 +33,40 @@
   sort( 0, Qt::DescendingOrder );
 }
 
+QString durationString( const KCalCore::Incidence::Ptr &incidence )
+{
+  if ( KCalCore::Event::Ptr event = incidence.dynamicCast<KCalCore::Event>() ) {
+    if ( event->allDay() )
+      return i18n( "Whole day" );
+
+    if ( event->duration() )
+      return KGlobal::locale()->formatDuration( event->duration().asSeconds() * 1000 \
); +    else
+      return KGlobal::locale()->formatDuration( event->dtStart().secsTo( \
event->dtEnd() ) * 1000 ); +
+  } else if ( KCalCore::Todo::Ptr todo = incidence.dynamicCast<KCalCore::Todo>() ) {
+    if ( todo->hasDueDate() )
+      return i18n( "Due at %1", KGlobal::locale()->formatDateTime( todo->dtDue(), \
KLocale::FancyShortDate ) ); +    else
+      return i18n( "No due date" );
+  } else {
+    kDebug() << "Invalid incindce type" << incidence->typeStr();
+    return QString();
+  }
+}
+
 QVariant EventListProxy::data(const QModelIndex& index, int role) const
 {
   const Akonadi::Item item = QSortFilterProxyModel::data( index, \
                Akonadi::EntityTreeModel::ItemRole ).value<Akonadi::Item>();
-  if ( item.isValid() && item.hasPayload<KCalCore::Event::Ptr>() ) {
-    const KCalCore::Event::Ptr event = item.payload<KCalCore::Event::Ptr>();
+  if ( item.isValid() && item.hasPayload<KCalCore::Incidence::Ptr>() ) {
+    const KCalCore::Incidence::Ptr event = item.payload<KCalCore::Incidence::Ptr>();
     switch ( role ) {
       case SummaryRole:
         return event->summary();
       case BeginRole:
         return KGlobal::locale()->formatDateTime( event->dtStart(), \
KLocale::FancyShortDate );  case DurationRole:
-        if ( event->duration() )
-          return KGlobal::locale()->formatDuration( event->duration().asSeconds() * \
                1000 );
-        else
-          return KGlobal::locale()->formatDuration( event->dtStart().secsTo( \
event->dtEnd() ) * 1000 ); +        return durationString( event );
     }
   }
   return QSortFilterProxyModel::data(index, role);


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

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