logo       

branches/KDE/4.3/kdelibs/kdecore/date [POSSIBLY UNSAFE]: msg#12947

kde-commits

Subject: branches/KDE/4.3/kdelibs/kdecore/date [POSSIBLY UNSAFE]

SVN commit 1005236 by winterz:

Backport r1004456 by tilladam from trunk to the 4.3 branch:

Implementation of a timezone backend for Windows. It queries the registry for
all available and the current timezone and allows setting the system timezone
as well. Reviewed by David Jarvie.



M +51 -4 ksystemtimezone.cpp
M +2 -7 ktimezone.cpp
A ktimezone_win.cpp
trunk/KDE/kdelibs/kdecore/date/ktimezone_win.cpp#1004456 [License: LGPL (v2+)]
A ktimezone_win.h
trunk/KDE/kdelibs/kdecore/date/ktimezone_win.h#1004456 [POSSIBLY UNSAFE:
system] [License: LGPL (v2+)]


--- branches/KDE/4.3/kdelibs/kdecore/date/ksystemtimezone.cpp #1005235:1005236
@@ -54,8 +54,10 @@
#include <kdebug.h>
#include <kconfiggroup.h>
#include "ktzfiletimezone.h"
+#ifdef Q_OS_WIN
+#include "ktimezone_win.h"
+#endif

-
#define KTIMEZONED_DBUS_IFACE "org.kde.KTimeZoned"


@@ -116,7 +118,12 @@
static void setLocalZone();
static void cleanup();
static void readConfig(bool init);
-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+ static void updateTimezoneInformation()
+ {
+ instance()->updateTimezoneInformation(true);
+ }
+#else
static void updateZonetab() { instance()->readZoneTab(true); }
#endif

@@ -128,7 +135,9 @@

private:
KSystemTimeZonesPrivate() {}
-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+ void updateTimezoneInformation(bool update);
+#else
void readZoneTab(bool update);
static float convertCoordinate(const QString &coordinate);
#endif
@@ -287,6 +296,7 @@
#ifdef Q_OS_WIN
// On Windows, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\Time Zones
// is the place to look. The TZI binary value is the
TIME_ZONE_INFORMATION structure.
+ m_instance->updateTimezoneInformation(false);
#else
// For Unix, read zone.tab.
if (!m_zonetab.isEmpty())
@@ -344,7 +354,43 @@
delete m_tzfileSource;
}

-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+
+void KSystemTimeZonesPrivate::updateTimezoneInformation(bool update)
+{
+ if (!m_source)
+ m_source = new KSystemTimeZoneSourceWindows;
+ QStringList newZones;
+ Q_FOREACH( const QString & tz, KSystemTimeZoneWindows::listTimeZones() ) {
+ // const std::wstring wstr = tz.toStdWString();
+ // const KTimeZone info = make_time_zone( wstr.c_str() );
+ KSystemTimeZoneWindows stz(m_source, tz);
+ if (update)
+ {
+ // Update the existing collection with the new zone definition
+ newZones += stz.name();
+ KTimeZone oldTz = zone(stz.name());
+ if (oldTz.isValid())
+ oldTz.updateBase(stz); // the zone previously existed, so
update its definition
+ else
+ add(stz); // the zone didn't previously exist, so add it
+ }
+ else
+ add(stz);
+ }
+ if (update)
+ {
+ // Remove any zones from the collection which no longer exist
+ const ZoneMap oldZones = zones();
+ for (ZoneMap::const_iterator it = oldZones.begin(); it !=
oldZones.end(); ++it)
+ {
+ if (newZones.indexOf(it.key()) < 0)
+ remove(it.value());
+ }
+ }
+}
+
+#else
/*
* Find the location of the zoneinfo files and store in mZoneinfoDir.
* Parse zone.tab and for each time zone, create a KSystemTimeZone instance.
@@ -800,3 +846,4 @@
{
return QList<int>();
}
+
--- branches/KDE/4.3/kdelibs/kdecore/date/ktimezone.cpp #1005235:1005236
@@ -118,10 +118,6 @@

KTimeZone KTimeZones::zone(const QString &name) const
{
-#ifdef Q_WS_WIN
- // return always the utc for now
- return KTimeZone::utc();
-#else
if (!name.isEmpty())
{
ZoneMap::ConstIterator it = d->zones.constFind(name);
@@ -131,7 +127,6 @@
return KTimeZone::utc();
}
return KTimeZone(); // error
-#endif
}


@@ -249,7 +244,7 @@
{
}

-KTimeZone::Transition::Transition(const QDateTime &t, const KTimeZone::Phase
&p)
+KTimeZone::Transition::Transition(const QDateTime &t, const KTimeZone::Phase
&p)
: d(new KTimeZoneTransitionPrivate)
{
d->time = t;
@@ -419,7 +414,7 @@
{
++d->refCount;
}
-
+
KTimeZoneBackend::~KTimeZoneBackend()
{
if (d && --d->refCount == 0)

<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | Mail Home | sitemap | FAQ | advertise