Commit 76e8ce64 authored by Volker Krause's avatar Volker Krause

Port time labels to QTimeZone.

parent 6e3b5d35
...@@ -27,11 +27,10 @@ ...@@ -27,11 +27,10 @@
#include "timelabelszone.h" #include "timelabelszone.h"
#include "timescaleconfigdialog.h" #include "timescaleconfigdialog.h"
#include <QIcon>
#include <KLocalizedString> #include <KLocalizedString>
#include <KTimeZone>
#include <QFrame> #include <QFrame>
#include <QIcon>
#include <QMenu> #include <QMenu>
#include <QPainter> #include <QPainter>
#include <QPointer> #include <QPointer>
...@@ -39,12 +38,11 @@ ...@@ -39,12 +38,11 @@
using namespace EventViews; using namespace EventViews;
TimeLabels::TimeLabels(const KDateTime::Spec &spec, int rows, TimeLabels::TimeLabels(const QTimeZone &zone, int rows, TimeLabelsZone *parent, Qt::WindowFlags f) :
TimeLabelsZone *parent, Qt::WindowFlags f) QFrame(parent, f),
: QFrame(parent, f) mTimezone(zone)
{ {
mTimeLabelsZone = parent; mTimeLabelsZone = parent;
mSpec = spec;
mRows = rows; mRows = rows;
mMiniWidth = 0; mMiniWidth = 0;
...@@ -59,8 +57,8 @@ TimeLabels::TimeLabels(const KDateTime::Spec &spec, int rows, ...@@ -59,8 +57,8 @@ TimeLabels::TimeLabels(const KDateTime::Spec &spec, int rows,
colorMousePos(); colorMousePos();
mAgenda = Q_NULLPTR; mAgenda = Q_NULLPTR;
if (mSpec.isValid()) { if (mTimezone.isValid()) {
setToolTip(i18n("Timezone:") + i18n(mSpec.timeZone().name().toUtf8())); setToolTip(i18n("Timezone:") + i18n(mTimezone.id()));
} }
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
...@@ -177,10 +175,10 @@ void TimeLabels::paintEvent(QPaintEvent *) ...@@ -177,10 +175,10 @@ void TimeLabels::paintEvent(QPaintEvent *)
const int cy = -y();// y() returns a negative value. const int cy = -y();// y() returns a negative value.
const int beginning = const int beginning =
!mSpec.isValid() ? !mTimezone.isValid() ?
0 : 0 :
(mSpec.timeZone().currentOffset() - (mTimezone.offsetFromUtc(QDateTime::currentDateTimeUtc()) -
mTimeLabelsZone->preferences()->timeSpec().timeZone().currentOffset()) / (60 * 60); mTimeLabelsZone->preferences()->timeZone().offsetFromUtc(QDateTime::currentDateTimeUtc())) / (60 * 60);
// bug: the parameters cx and cw are the areas that need to be // bug: the parameters cx and cw are the areas that need to be
// redrawn, not the area of the widget. unfortunately, this // redrawn, not the area of the widget. unfortunately, this
...@@ -296,10 +294,10 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event) ...@@ -296,10 +294,10 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event)
popup.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("&Add Timezones...")); popup.addAction(QIcon::fromTheme(QStringLiteral("document-properties")), i18n("&Add Timezones..."));
QAction *removeTimeZone = QAction *removeTimeZone =
popup.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")), popup.addAction(QIcon::fromTheme(QStringLiteral("edit-delete")),
i18n("&Remove Timezone %1", i18n(mSpec.timeZone().name().toUtf8()))); i18n("&Remove Timezone %1", i18n(mTimezone.id())));
if (!mSpec.isValid() || if (!mTimezone.isValid() ||
!mTimeLabelsZone->preferences()->timeScaleTimezones().count() || !mTimeLabelsZone->preferences()->timeScaleTimezones().count() ||
mSpec == mTimeLabelsZone->preferences()->timeSpec()) { mTimezone == mTimeLabelsZone->preferences()->timeZone()) {
removeTimeZone->setEnabled(false); removeTimeZone->setEnabled(false);
} }
...@@ -313,7 +311,7 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event) ...@@ -313,7 +311,7 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event)
delete dialog; delete dialog;
} else if (activatedAction == removeTimeZone) { } else if (activatedAction == removeTimeZone) {
QStringList list = mTimeLabelsZone->preferences()->timeScaleTimezones(); QStringList list = mTimeLabelsZone->preferences()->timeScaleTimezones();
list.removeAll(mSpec.timeZone().name()); list.removeAll(QString::fromUtf8(mTimezone.id()));
mTimeLabelsZone->preferences()->setTimeScaleTimezones(list); mTimeLabelsZone->preferences()->setTimeScaleTimezones(list);
mTimeLabelsZone->preferences()->writeConfig(); mTimeLabelsZone->preferences()->writeConfig();
mTimeLabelsZone->reset(); mTimeLabelsZone->reset();
...@@ -322,41 +320,41 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event) ...@@ -322,41 +320,41 @@ void TimeLabels::contextMenuEvent(QContextMenuEvent *event)
} }
} }
KDateTime::Spec TimeLabels::timeSpec() QTimeZone TimeLabels::timeZone() const
{ {
return mSpec; return mTimezone;
} }
QString TimeLabels::header() const QString TimeLabels::header() const
{ {
return i18n(mSpec.timeZone().name().toUtf8()); return i18n(mTimezone.id());
} }
QString TimeLabels::headerToolTip() const QString TimeLabels::headerToolTip() const
{ {
KTimeZone tz = mSpec.timeZone();
QString toolTip; QString toolTip;
toolTip += QLatin1String("<qt>"); toolTip += QLatin1String("<qt>");
toolTip += i18n("<b>%1</b>", i18n(tz.name().toUtf8())); toolTip += i18n("<b>%1</b>", i18n(mTimezone.id()));
toolTip += QLatin1String("<hr>"); toolTip += QLatin1String("<hr>");
//TODO: Once string freeze is lifted, add UTC offset here //TODO: Once string freeze is lifted, add UTC offset here
if (!tz.countryCode().isEmpty()) { if (mTimezone.country() != QLocale::AnyCountry) {
toolTip += i18n("<i>Country Code:</i> %1", tz.countryCode()); toolTip += i18n("<i>Country:</i> %1", QLocale::countryToString(mTimezone.country()));
toolTip += QLatin1String("<br/>"); toolTip += QLatin1String("<br/>");
} }
if (!tz.abbreviations().isEmpty()) {
toolTip += i18n("<i>Abbreviations:</i>") + QLatin1String("</i>"); auto abbreviations = QStringLiteral("&nbsp;");
toolTip += QLatin1String("&nbsp;"); foreach (const auto &transition, mTimezone.transitions(QDateTime::currentDateTime(), QDateTime::currentDateTime().addYears(1))) {
foreach (const QByteArray &a, tz.abbreviations()) { abbreviations += transition.abbreviation;
toolTip += QString::fromLocal8Bit(a); abbreviations += QLatin1String(",&nbsp;");
toolTip += QLatin1String(",&nbsp;");
} }
toolTip.chop(7); abbreviations.chop(7);
if (!abbreviations.isEmpty()) {
toolTip += i18n("<i>Abbreviations:</i>");
toolTip += abbreviations;
toolTip += QLatin1String("<br/>"); toolTip += QLatin1String("<br/>");
} }
if (!tz.comment().isEmpty()) { if (!mTimezone.comment().isEmpty()) {
toolTip += i18n("<i>Comment:</i> %1", tz.comment()); toolTip += i18n("<i>Comment:</i> %1", mTimezone.comment());
} }
toolTip += QLatin1String("</qt>"); toolTip += QLatin1String("</qt>");
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
#ifndef EVENTVIEWS_TIMELABELS_H #ifndef EVENTVIEWS_TIMELABELS_H
#define EVENTVIEWS_TIMELABELS_H #define EVENTVIEWS_TIMELABELS_H
#include <KDateTime> #include <QTimeZone>
#include <QFrame> #include <QFrame>
...@@ -43,8 +43,7 @@ class TimeLabels : public QFrame ...@@ -43,8 +43,7 @@ class TimeLabels : public QFrame
public: public:
typedef QList<TimeLabels *> List; typedef QList<TimeLabels *> List;
TimeLabels(const KDateTime::Spec &spec, int rows, TimeLabels(const QTimeZone &zone, int rows, TimeLabelsZone *parent = Q_NULLPTR, Qt::WindowFlags f = Q_NULLPTR);
TimeLabelsZone *parent = Q_NULLPTR, Qt::WindowFlags f = Q_NULLPTR);
/** updates widget's internal state */ /** updates widget's internal state */
void updateConfig(); void updateConfig();
...@@ -58,8 +57,8 @@ public: ...@@ -58,8 +57,8 @@ public:
/** */ /** */
void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE;
/** Returns time spec of this label */ /** Returns the time zone of this label */
KDateTime::Spec timeSpec(); QTimeZone timeZone() const;
/** /**
Return string which can be used as a header for the time label. Return string which can be used as a header for the time label.
...@@ -86,7 +85,7 @@ private Q_SLOTS: ...@@ -86,7 +85,7 @@ private Q_SLOTS:
private: private:
void colorMousePos(); void colorMousePos();
KDateTime::Spec mSpec; QTimeZone mTimezone;
int mRows; int mRows;
double mCellHeight; double mCellHeight;
int mMiniWidth; int mMiniWidth;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "prefs.h" #include "prefs.h"
#include "timelabels.h" #include "timelabels.h"
#include <KSystemTimeZone>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QScrollArea> #include <QScrollArea>
#include <QScrollBar> #include <QScrollBar>
...@@ -64,13 +62,13 @@ void TimeLabelsZone::reset() ...@@ -64,13 +62,13 @@ void TimeLabelsZone::reset()
void TimeLabelsZone::init() void TimeLabelsZone::init()
{ {
QStringList seenTimeZones(mPrefs->timeSpec().timeZone().name()); QStringList seenTimeZones(QString::fromUtf8(mPrefs->timeZone().id()));
addTimeLabels(mPrefs->timeSpec()); addTimeLabels(mPrefs->timeZone());
foreach (const QString &zoneStr, mPrefs->timeScaleTimezones()) { foreach (const QString &zoneStr, mPrefs->timeScaleTimezones()) {
if (!seenTimeZones.contains(zoneStr)) { if (!seenTimeZones.contains(zoneStr)) {
KTimeZone zone = KSystemTimeZones::zone(zoneStr); auto zone = QTimeZone(zoneStr.toUtf8());
if (zone.isValid()) { if (zone.isValid()) {
addTimeLabels(zone); addTimeLabels(zone);
seenTimeZones += zoneStr; seenTimeZones += zoneStr;
...@@ -79,10 +77,10 @@ void TimeLabelsZone::init() ...@@ -79,10 +77,10 @@ void TimeLabelsZone::init()
} }
} }
void TimeLabelsZone::addTimeLabels(const KDateTime::Spec &spec) void TimeLabelsZone::addTimeLabels(const QTimeZone &zone)
{ {
QScrollArea *area = new QScrollArea(this); QScrollArea *area = new QScrollArea(this);
TimeLabels *labels = new TimeLabels(spec, 24, this); TimeLabels *labels = new TimeLabels(zone, 24, this);
mTimeLabelsList.prepend(area); mTimeLabelsList.prepend(area);
area->setWidgetResizable(true); area->setWidgetResizable(true);
area->setWidget(labels); area->setWidget(labels);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
class QHBoxLayout; class QHBoxLayout;
class QScrollArea; class QScrollArea;
class QTimeZone;
namespace EventViews namespace EventViews
{ {
...@@ -44,10 +45,10 @@ class TimeLabelsZone : public QWidget ...@@ -44,10 +45,10 @@ class TimeLabelsZone : public QWidget
public: public:
explicit TimeLabelsZone(QWidget *parent, const PrefsPtr &preferences, Agenda *agenda = Q_NULLPTR); explicit TimeLabelsZone(QWidget *parent, const PrefsPtr &preferences, Agenda *agenda = Q_NULLPTR);
/** Add a new time label with the given spec. /** Add a new time label with the given time zone.
If spec is not valid, use the display timespec. If @p zone is not valid, use the display time zone.
*/ */
void addTimeLabels(const KDateTime::Spec &spec); void addTimeLabels(const QTimeZone &zone);
/** /**
Returns the best width for each TimeLabels widget Returns the best width for each TimeLabels widget
......
...@@ -22,11 +22,11 @@ ...@@ -22,11 +22,11 @@
#include "timescaleconfigdialog.h" #include "timescaleconfigdialog.h"
#include "prefs.h" #include "prefs.h"
#include <KSystemTimeZone>
#include <KLocalizedString> #include <KLocalizedString>
#include <QIcon> #include <QIcon>
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QPushButton> #include <QPushButton>
#include <QTimeZone>
#include <QVBoxLayout> #include <QVBoxLayout>
using namespace EventViews; using namespace EventViews;
...@@ -48,13 +48,14 @@ enum { ...@@ -48,13 +48,14 @@ enum {
TimeZoneNameRole = Qt::UserRole TimeZoneNameRole = Qt::UserRole
}; };
typedef QPair<QString, QString> TimeZoneNamePair; typedef QPair<QString, QByteArray> TimeZoneNamePair;
//TODO: move to KCalCore::Stringify //TODO: move to KCalCore::Stringify
static QString tzUTCOffsetStr(const KTimeZone &tz) static QString tzUTCOffsetStr(const QTimeZone &tz)
{ {
int utcOffsetHrs = tz.currentOffset() / 3600; // in hours auto currentOffset = tz.offsetFromUtc(QDateTime::currentDateTimeUtc());
int utcOffsetMins = (tz.currentOffset() % 3600) / 60; // in minutes int utcOffsetHrs = currentOffset / 3600; // in hours
int utcOffsetMins = (currentOffset % 3600) / 60; // in minutes
QString utcStr; QString utcStr;
if (utcOffsetMins > 0) { if (utcOffsetMins > 0) {
utcStr = utcOffsetHrs >= 0 ? utcStr = utcOffsetHrs >= 0 ?
...@@ -70,11 +71,12 @@ static QString tzUTCOffsetStr(const KTimeZone &tz) ...@@ -70,11 +71,12 @@ static QString tzUTCOffsetStr(const KTimeZone &tz)
} }
//TODO: move to KCalCore::Stringify //TODO: move to KCalCore::Stringify
static QString tzWithUTC(KTimeZones::ZoneMap::ConstIterator it) static QString tzWithUTC(const QByteArray &zoneId)
{ {
auto tz = QTimeZone(zoneId);
return return
QStringLiteral("%1 (UTC%2)"). QStringLiteral("%1 (UTC%2)").
arg(i18n(it.key().toUtf8()), tzUTCOffsetStr(it.value())); arg(i18n(zoneId), tzUTCOffsetStr(tz));
} }
TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidget *parent) TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidget *parent)
...@@ -97,18 +99,18 @@ TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidge ...@@ -97,18 +99,18 @@ TimeScaleConfigDialog::TimeScaleConfigDialog(const PrefsPtr &preferences, QWidge
mainLayout->addWidget(mainwidget); mainLayout->addWidget(mainwidget);
mainLayout->addWidget(buttonBox); mainLayout->addWidget(buttonBox);
QStringList shownTimeZones(d->mPreferences->timeSpec().timeZone().name()); QStringList shownTimeZones(QString::fromUtf8(d->mPreferences->timeZone().id()));
shownTimeZones += d->mPreferences->timeScaleTimezones(); shownTimeZones += d->mPreferences->timeScaleTimezones();
shownTimeZones.removeDuplicates(); shownTimeZones.removeDuplicates();
QList<TimeZoneNamePair> availList, selList; QList<TimeZoneNamePair> availList, selList;
const KTimeZones::ZoneMap timezones = KSystemTimeZones::zones(); const auto zoneIds = QTimeZone::availableTimeZoneIds();
for (KTimeZones::ZoneMap::ConstIterator it = timezones.begin(); it != timezones.end(); ++it) { foreach (const auto &zoneId, zoneIds) {
// do not list timezones already shown // do not list timezones already shown
if (!shownTimeZones.contains(it.key())) { if (!shownTimeZones.contains(QString::fromUtf8(zoneId))) {
availList.append(TimeZoneNamePair(tzWithUTC(it), it.key())); availList.append(TimeZoneNamePair(tzWithUTC(zoneId), zoneId));
} else { } else {
selList.append(TimeZoneNamePair(tzWithUTC(it), it.key())); selList.append(TimeZoneNamePair(tzWithUTC(zoneId), zoneId));
} }
} }
qSort(availList.begin(), availList.end()); qSort(availList.begin(), availList.end());
......
...@@ -858,6 +858,11 @@ KDateTime::Spec Prefs::timeSpec() const ...@@ -858,6 +858,11 @@ KDateTime::Spec Prefs::timeSpec() const
return KSystemTimeZones::local(); return KSystemTimeZones::local();
} }
QTimeZone Prefs::timeZone() const
{
return QTimeZone(timeSpec().timeZone().name().toUtf8());
}
void Prefs::setTimeSpec(const KDateTime::Spec &spec) void Prefs::setTimeSpec(const KDateTime::Spec &spec)
{ {
d->mBaseConfig.mTimeSpec = spec; d->mBaseConfig.mTimeSpec = spec;
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <KConfigSkeleton> #include <KConfigSkeleton>
#include <KDateTime> #include <KDateTime>
#include <QTimeZone>
namespace EventViews namespace EventViews
{ {
...@@ -155,6 +156,7 @@ public: ...@@ -155,6 +156,7 @@ public:
void setTimeSpec(const KDateTime::Spec &spec); void setTimeSpec(const KDateTime::Spec &spec);
KDateTime::Spec timeSpec() const; KDateTime::Spec timeSpec() const;
QTimeZone timeZone() const;
QStringList timeScaleTimezones() const; QStringList timeScaleTimezones() const;
void setTimeScaleTimezones(const QStringList &list); void setTimeScaleTimezones(const QStringList &list);
......
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