Commit d1c3d86e authored by Volker Krause's avatar Volker Krause

Port time combo box away from ICalTimeZone.

ICalTimeZone is still used when translating non-standard time zones
back to KDateTime::Spec, John is working on providing new API for this
in KCalCore to remove this as well.
parent a5735f2b
......@@ -22,16 +22,20 @@
#include "qtest.h"
#include <KTimeZone>
QTEST_MAIN(KTimeZoneComboBoxTest)
void KTimeZoneComboBoxTest::test_timeSpec()
{
IncidenceEditorNG::KTimeZoneComboBox combo;
KDateTime::Spec spec;
spec.setType(KDateTime::LocalZone);
combo.selectTimeSpec(spec);
QCOMPARE(combo.selectedTimeSpec().type(), KDateTime::TimeZone); // KDateTime::Spec stores it as TimeZone, not LocalTime
if (spec.timeZone().name() != "UTC")
QCOMPARE(combo.selectedTimeSpec().type(), KDateTime::TimeZone); // KDateTime::Spec stores it as TimeZone, not LocalTime
else
QCOMPARE(combo.selectedTimeSpec().type(), KDateTime::UTC);
spec = KDateTime::Spec(KDateTime::ClockTime);
combo.selectTimeSpec(spec);
......
......@@ -69,7 +69,7 @@ static bool incidenceHasDefaultTimes(const KCalCore::Incidence::Ptr &incidence)
}
IncidenceDateTime::IncidenceDateTime(Ui::EventOrTodoDesktop *ui)
: IncidenceEditor(0), mTimeZones(new KCalCore::ICalTimeZones), mUi(ui),
: IncidenceEditor(0), mUi(ui),
mTimezoneCombosWereVisibile(false)
{
setTimeZonesVisibility(false);
......@@ -104,7 +104,6 @@ IncidenceDateTime::IncidenceDateTime(Ui::EventOrTodoDesktop *ui)
IncidenceDateTime::~IncidenceDateTime()
{
delete mTimeZones;
}
bool IncidenceDateTime::eventFilter(QObject *obj, QEvent *event)
......@@ -746,16 +745,14 @@ void IncidenceDateTime::setDateTimes(const KDateTime &start, const KDateTime &en
if (startSpec.type() == KDateTime::TimeZone) {
const KTimeZone systemTz = KSystemTimeZones::zone(startSpec.timeZone().name());
if (!systemTz.isValid()) {
const KCalCore::ICalTimeZone icalTz(startSpec.timeZone());
mTimeZones->add(icalTz);
mTimeZones.push_back(startSpec.timeZone().name().toUtf8());
}
}
if (endSpec.type() == KDateTime::TimeZone) {
const KTimeZone systemTz = KSystemTimeZones::zone(endSpec.timeZone().name());
if (!systemTz.isValid()) {
const KCalCore::ICalTimeZone icalTz(endSpec.timeZone());
mTimeZones->add(icalTz);
mTimeZones.push_back(endSpec.timeZone().name().toUtf8());
}
}
......
......@@ -130,7 +130,7 @@ private:
bool timeZonesAreLocal(const KDateTime &start, const KDateTime &end);
private:
KCalCore::ICalTimeZones *mTimeZones;
QVector<QByteArray> mTimeZones;
Ui::EventOrTodoDesktop *mUi;
QDate mActiveDate;
......
......@@ -22,7 +22,10 @@
#include <KCalCore/ICalTimeZones>
#include <KLocalizedString>
#include <KSystemTimeZone>
#include <KTimeZone>
#include <KSystemTimeZones>
#include <QTimeZone>
using namespace IncidenceEditorNG;
......@@ -36,7 +39,7 @@ public:
void fillComboBox();
KTimeZoneComboBox *const mParent;
QStringList mZones;
const KCalCore::ICalTimeZones *mAdditionalZones;
QVector<QByteArray> mAdditionalZones;
};
void KTimeZoneComboBox::Private::fillComboBox()
......@@ -45,24 +48,19 @@ void KTimeZoneComboBox::Private::fillComboBox()
mZones.clear();
// Read all system time zones
const KTimeZones::ZoneMap timezones = KSystemTimeZones::zones();
for (KTimeZones::ZoneMap::ConstIterator it = timezones.begin(); it != timezones.end(); ++it) {
mZones.append(it.key().toUtf8());
foreach (const auto &id, QTimeZone::availableTimeZoneIds()) {
mZones.push_back(id);
}
mZones.sort();
// Prepend the list of additional timezones
if (mAdditionalZones) {
const KCalCore::ICalTimeZones::ZoneMap calzones = mAdditionalZones->zones();
for (KCalCore::ICalTimeZones::ZoneMap::ConstIterator it = calzones.begin();
it != calzones.end(); ++it) {
mZones.prepend(it.key().toUtf8());
}
}
foreach (const auto &id, mAdditionalZones)
mZones.prepend(id);
// Prepend Local, UTC and Floating, for convenience
mZones.prepend(QStringLiteral("UTC")); // do not use i18n here index=2
mZones.prepend(QStringLiteral("Floating")); // do not use i18n here index=1
mZones.prepend(KSystemTimeZones::local().name()); // index=0
mZones.prepend(QTimeZone::systemTimeZoneId()); // index=0
// Put translated zones into the combobox
foreach (const QString &z, mZones) {
......@@ -76,7 +74,7 @@ KTimeZoneComboBox::KTimeZoneComboBox(QWidget *parent)
d->fillComboBox();
}
void KTimeZoneComboBox::setAdditionalTimeZones(const KCalCore::ICalTimeZones *zones)
void KTimeZoneComboBox::setAdditionalTimeZones(const QVector<QByteArray> &zones)
{
d->mAdditionalZones = zones;
d->fillComboBox();
......@@ -129,8 +127,8 @@ KDateTime::Spec KTimeZoneComboBox::selectedTimeSpec() const
if (systemTz.isValid()) {
spec.setType(systemTz);
} else {
const KCalCore::ICalTimeZone additionalTz =
d->mAdditionalZones->zone(d->mZones[currentIndex()]);
KCalCore::ICalTimeZones zones;
const KCalCore::ICalTimeZone additionalTz = zones.zone(d->mZones[currentIndex()]);
spec.setType(additionalTz);
}
}
......
......@@ -28,11 +28,13 @@
#include <KComboBox>
#include <KDateTime>
#include <QVector>
namespace KCalCore
{
class ICalTimeZones;
}
class QByteArray;
namespace IncidenceEditorNG
{
......@@ -63,7 +65,7 @@ public:
Sets additional time @p zones (usually from a calendar) which should be displayed
additionally to the system time zones.
*/
void setAdditionalTimeZones(const KCalCore::ICalTimeZones *zones);
void setAdditionalTimeZones(const QVector<QByteArray> &zones);
/**
* Selects the item in the combobox corresponding to the given @p spec.
......
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