Commit 43192715 authored by Volker Krause's avatar Volker Krause

Port event list view from KDateTime to QDateTime

While at it, also fix display of recurring events, in particular those
in different time zones.
parent f6b56972
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "listview.h" #include "listview.h"
#include "helper.h" #include "helper.h"
#include <CalendarSupport/KCalPrefs>
#include <CalendarSupport/Utils> #include <CalendarSupport/Utils>
#include <Akonadi/Calendar/ETMCalendar> #include <Akonadi/Calendar/ETMCalendar>
...@@ -38,6 +37,8 @@ ...@@ -38,6 +37,8 @@
#include <KCalUtils/IncidenceFormatter> #include <KCalUtils/IncidenceFormatter>
#include <KCalCore/Visitor> #include <KCalCore/Visitor>
#include <KConfig>
#include <KConfigGroup>
#include <KIconLoader> #include <KIconLoader>
#include "calendarview_debug.h" #include "calendarview_debug.h"
...@@ -58,16 +59,13 @@ enum { ...@@ -58,16 +59,13 @@ enum {
Dummy_EOF_Column // Dummy enum value for iteration purposes only. Always keep at the end. Dummy_EOF_Column // Dummy enum value for iteration purposes only. Always keep at the end.
}; };
static QString cleanSummary(const QString &summary, const KDateTime &next) static QString cleanSummary(const QString &summary, const QDateTime &next)
{ {
QString retStr = summary; QString retStr = summary;
retStr.replace(QLatin1Char('\n'), QLatin1Char(' ')); retStr.replace(QLatin1Char('\n'), QLatin1Char(' '));
if (next.isValid()) { if (next.isValid()) {
const QString dateStr = const QString dateStr = QLocale().toString(next.date(), QLocale::ShortFormat);
QLocale::system().toString(
next.toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).date(),
QLocale::ShortFormat);
retStr = i18nc("%1 is an item summary. %2 is the date when this item reoccurs", retStr = i18nc("%1 is an item summary. %2 is the date when this item reoccurs",
"%1 (next: %2)", retStr, dateStr); "%1 (next: %2)", retStr, dateStr);
} }
...@@ -86,8 +84,8 @@ public: ...@@ -86,8 +84,8 @@ public:
const QTreeWidget *mTreeWidget; const QTreeWidget *mTreeWidget;
const Akonadi::Item mIncidence; const Akonadi::Item mIncidence;
KDateTime start; QDateTime start;
KDateTime end; QDateTime end;
}; };
bool ListViewItem::operator<(const QTreeWidgetItem &other) const bool ListViewItem::operator<(const QTreeWidgetItem &other) const
...@@ -100,13 +98,11 @@ bool ListViewItem::operator<(const QTreeWidgetItem &other) const ...@@ -100,13 +98,11 @@ bool ListViewItem::operator<(const QTreeWidgetItem &other) const
return otheritem->start < start; return otheritem->start < start;
} }
case EndDateTime_Column: { case EndDateTime_Column: {
KDateTime thisEnd;
Incidence::Ptr thisInc = CalendarSupport::incidence(mIncidence); Incidence::Ptr thisInc = CalendarSupport::incidence(mIncidence);
thisEnd = thisInc->dateTime(Incidence::RoleEnd); const auto thisEnd = thisInc->dateTime(Incidence::RoleEnd).toLocalZone().dateTime();
KDateTime otherEnd;
Incidence::Ptr otherInc = CalendarSupport::incidence(otheritem->mIncidence); Incidence::Ptr otherInc = CalendarSupport::incidence(otheritem->mIncidence);
otherEnd = otherInc->dateTime(Incidence::RoleEnd); const auto otherEnd = otherInc->dateTime(Incidence::RoleEnd).toLocalZone().dateTime();
return otherEnd < thisEnd; return otherEnd < thisEnd;
} }
...@@ -186,28 +182,27 @@ bool ListView::Private::ListItemVisitor::visit(const Event::Ptr &e) ...@@ -186,28 +182,27 @@ bool ListView::Private::ListItemVisitor::visit(const Event::Ptr &e)
} }
mItem->setIcon(Summary_Column, eventPxmp); mItem->setIcon(Summary_Column, eventPxmp);
KDateTime next; QDateTime next;
mItem->start = e->dtStart(); mItem->start = e->dtStart().toLocalZone().dateTime();
mItem->end = e->dtEnd(); mItem->end = e->dtEnd().toLocalZone().dateTime();
if (e->recurs()) { if (e->recurs()) {
const int duration = e->dtStart().secsTo(e->dtEnd()); const int duration = e->dtStart().secsTo(e->dtEnd());
KDateTime kdt = KDateTime::currentDateTime( KDateTime kdt(mStartDate, QTime(0,0,0));
CalendarSupport::KCalPrefs::instance()->timeSpec());
kdt = kdt.addSecs(-1); kdt = kdt.addSecs(-1);
mItem->start.setDate(e->recurrence()->getNextDateTime(kdt).date()); mItem->start = e->recurrence()->getNextDateTime(kdt).toLocalZone().dateTime();
mItem->end = mItem->start.addSecs(duration); mItem->end = mItem->start.addSecs(duration);
next = e->recurrence()->getNextDateTime(mItem->start); next = e->recurrence()->getNextDateTime(KDateTime(mItem->start)).toLocalZone().dateTime();
} }
mItem->setText(Summary_Column, cleanSummary(e->summary(), next)); mItem->setText(Summary_Column, cleanSummary(e->summary(), next));
mItem->setText(StartDateTime_Column, IncidenceFormatter::dateTimeToString( if (e->allDay()) {
mItem->start, e->allDay(), true, mItem->setText(StartDateTime_Column, QLocale().toString(mItem->start.date(), QLocale::ShortFormat));
CalendarSupport::KCalPrefs::instance()->timeSpec())); mItem->setText(EndDateTime_Column, QLocale().toString(mItem->end.date(), QLocale::ShortFormat));
} else {
mItem->setText(EndDateTime_Column, IncidenceFormatter::dateTimeToString( mItem->setText(StartDateTime_Column, QLocale().toString(mItem->start, QLocale::ShortFormat));
mItem->end, e->allDay(), true, mItem->setText(EndDateTime_Column, QLocale().toString(mItem->end, QLocale::ShortFormat));
CalendarSupport::KCalPrefs::instance()->timeSpec())); }
mItem->setText(Categories_Column, e->categoriesStr()); mItem->setText(Categories_Column, e->categoriesStr());
...@@ -218,21 +213,22 @@ bool ListView::Private::ListItemVisitor::visit(const Todo::Ptr &t) ...@@ -218,21 +213,22 @@ bool ListView::Private::ListItemVisitor::visit(const Todo::Ptr &t)
{ {
mItem->setIcon(Summary_Column, QIcon::fromTheme(t->iconName())); mItem->setIcon(Summary_Column, QIcon::fromTheme(t->iconName()));
mItem->setText(Summary_Column, cleanSummary(t->summary(), KDateTime())); mItem->setText(Summary_Column, cleanSummary(t->summary(), QDateTime()));
if (t->hasStartDate()) { if (t->hasStartDate()) {
mItem->setText(StartDateTime_Column, IncidenceFormatter::dateTimeToString( if (t->allDay())
t->dtStart(), t->allDay(), true, mItem->setText(StartDateTime_Column, QLocale().toString(t->dtStart().toLocalZone().date(), QLocale::ShortFormat));
CalendarSupport::KCalPrefs::instance()->timeSpec())); else
mItem->setText(StartDateTime_Column, QLocale().toString(t->dtStart().toLocalZone().dateTime(), QLocale::ShortFormat));
} else { } else {
mItem->setText(StartDateTime_Column, QStringLiteral("---")); mItem->setText(StartDateTime_Column, QStringLiteral("---"));
} }
if (t->hasDueDate()) { if (t->hasDueDate()) {
mItem->setText(EndDateTime_Column, IncidenceFormatter::dateTimeToString( if (t->allDay())
t->dtDue(), t->allDay(), true, mItem->setText(EndDateTime_Column, QLocale().toString(t->dtDue().toLocalZone().date(), QLocale::ShortFormat));
CalendarSupport::KCalPrefs::instance()->timeSpec())); else
mItem->setText(EndDateTime_Column, QLocale().toString(t->dtDue().toLocalZone().dateTime(), QLocale::ShortFormat));
} else { } else {
mItem->setText(EndDateTime_Column, QStringLiteral("---")); mItem->setText(EndDateTime_Column, QStringLiteral("---"));
} }
...@@ -248,13 +244,14 @@ bool ListView::Private::ListItemVisitor::visit(const Journal::Ptr &j) ...@@ -248,13 +244,14 @@ bool ListView::Private::ListItemVisitor::visit(const Journal::Ptr &j)
if (j->summary().isEmpty()) { if (j->summary().isEmpty()) {
mItem->setText(Summary_Column, mItem->setText(Summary_Column,
cleanSummary(j->description().section(QLatin1Char('\n'), 0, 0), cleanSummary(j->description().section(QLatin1Char('\n'), 0, 0),
KDateTime())); QDateTime()));
} else { } else {
mItem->setText(Summary_Column, cleanSummary(j->summary(), KDateTime())); mItem->setText(Summary_Column, cleanSummary(j->summary(), QDateTime()));
} }
mItem->setText(StartDateTime_Column, IncidenceFormatter::dateTimeToString( if (j->allDay())
j->dtStart(), j->allDay(), true, mItem->setText(StartDateTime_Column, QLocale().toString(j->dtStart().toLocalZone().date(), QLocale::ShortFormat));
CalendarSupport::KCalPrefs::instance()->timeSpec())); else
mItem->setText(StartDateTime_Column, QLocale().toString(j->dtStart().toLocalZone().dateTime(), QLocale::ShortFormat));
return true; return true;
} }
...@@ -349,17 +346,8 @@ void ListView::showDates(const QDate &start, const QDate &end, const QDate &pref ...@@ -349,17 +346,8 @@ void ListView::showDates(const QDate &start, const QDate &end, const QDate &pref
d->mStartDate = start; d->mStartDate = start;
d->mEndDate = end; d->mEndDate = end;
KDateTime kStart(start); const QString startStr = QLocale().toString(start, QLocale::ShortFormat);
const QString startStr = const QString endStr = QLocale().toString(end, QLocale::ShortFormat);
QLocale::system().toString(
kStart.toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).date(),
QLocale::ShortFormat);
KDateTime kEnd(end);
const QString endStr =
QLocale::system().toString(
kEnd.toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).date(),
QLocale::ShortFormat);
d->mTreeWidget->headerItem()->setText(Summary_Column, d->mTreeWidget->headerItem()->setText(Summary_Column,
i18n("Summary [%1 - %2]", startStr, endStr)); i18n("Summary [%1 - %2]", startStr, endStr));
...@@ -425,7 +413,7 @@ void ListView::Private::addIncidence(const Akonadi::ETMCalendar::Ptr &calendar, ...@@ -425,7 +413,7 @@ void ListView::Private::addIncidence(const Akonadi::ETMCalendar::Ptr &calendar,
tinc = Incidence::Ptr(incidence->clone()); tinc = Incidence::Ptr(incidence->clone());
tinc->setReadOnly(false); tinc->setReadOnly(false);
tinc->setSummary(i18np("%2 (1 year)", "%2 (%1 years)", years, tinc->setSummary(i18np("%2 (1 year)", "%2 (%1 years)", years,
cleanSummary(incidence->summary(), KDateTime()))); cleanSummary(incidence->summary(), QDateTime())));
tinc->setReadOnly(true); tinc->setReadOnly(true);
} }
} }
...@@ -467,11 +455,9 @@ void ListView::changeIncidenceDisplay(const Akonadi::Item &aitem, int action) ...@@ -467,11 +455,9 @@ void ListView::changeIncidenceDisplay(const Akonadi::Item &aitem, int action)
QDate date; QDate date;
if (CalendarSupport::hasTodo(aitem)) { if (CalendarSupport::hasTodo(aitem)) {
date = CalendarSupport::todo(aitem)->dtDue(). date = CalendarSupport::todo(aitem)->dtDue().toLocalZone().date();
toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).date();
} else { } else {
date = incidence->dtStart(). date = incidence->dtStart().toLocalZone().date();
toTimeSpec(CalendarSupport::KCalPrefs::instance()->timeSpec()).date();
} }
switch (action) { switch (action) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment