KDECore
ktimezones.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _KTIMEZONES_H
00021 #define _KTIMEZONES_H
00022
00023 #include "kdelibs_export.h"
00024 #include <qdatetime.h>
00025 #include <qnamespace.h>
00026 #include <qmap.h>
00027 #include <qstring.h>
00028 #include <ksharedptr.h>
00029
00030 class KTimezoneDetails;
00031 class KTimezoneDetailsPrivate;
00032 class KTimezonePrivate;
00033 class KTimezonesPrivate;
00034
00051 class KDECORE_EXPORT KTimezoneSource :
00052 public KShared
00053 {
00054 public:
00055 KTimezoneSource(const QString &db);
00056 virtual ~KTimezoneSource();
00057
00062 virtual QString db();
00063
00069 virtual bool parse(const QString &zone, KTimezoneDetails &dataReceiver) const;
00070
00071 private:
00072 QString m_db;
00073 };
00074
00085 class KDECORE_EXPORT KTimezone
00086 {
00087 public:
00092 static const float UNKNOWN;
00093
00098 static bool isValidLatitude(float latitude);
00099
00104 static bool isValidLongitude(float longitude);
00105
00116 KTimezone(
00117 KSharedPtr<KTimezoneSource> db, const QString &name,
00118 const QString &countryCode = QString(), float latitude = UNKNOWN, float longitude = UNKNOWN,
00119 const QString &comment = QString());
00120 ~KTimezone();
00121
00127 QString name() const;
00128
00134 QString countryCode() const;
00135
00141 float latitude() const;
00142
00148 float longitude() const;
00149
00159 int offset(Qt::TimeSpec basisSpec = Qt::UTC) const;
00160
00167 int offset(const QDateTime &dateTime) const;
00168
00175 QDateTime convert(const KTimezone *newZone, const QDateTime &dateTime) const;
00176
00182 QString comment() const;
00183
00188 bool parse(KTimezoneDetails &dataReceiver) const;
00189
00190 private:
00191 KTimezone(const KTimezone&);
00192 KTimezone& operator=(const KTimezone&);
00193
00194 KSharedPtr<KTimezoneSource> m_db;
00195 QString m_name;
00196 QString m_countryCode;
00197 float m_latitude;
00198 float m_longitude;
00199 QString m_comment;
00200 KTimezonePrivate *d;
00201 };
00202
00225 class KDECORE_EXPORT KTimezoneDetails
00226 {
00227 public:
00228 KTimezoneDetails();
00229 virtual ~KTimezoneDetails();
00230
00234 virtual void parseEnded();
00235
00239 virtual void parseStarted();
00240
00244 virtual void gotHeader(
00245 unsigned ttIsGmtCnt, unsigned ttIsStdCnt, unsigned leapCnt,
00246 unsigned timeCnt, unsigned typeCnt, unsigned charCnt);
00247
00251 virtual void gotTransitionTime(int index, unsigned transitionTime);
00252
00256 virtual void gotLocalTimeIndex(int index, unsigned localTimeIndex);
00257
00261 virtual void gotLocalTime(int index, int gmtOff, bool isDst, unsigned abbrIndex);
00262
00268 virtual void gotAbbreviation(int index, const QString &abbr);
00269
00273 virtual void gotLeapAdjustment(int index, unsigned leapTime, unsigned leapSeconds);
00274
00278 virtual void gotIsStandard(int index, bool isStandard);
00279
00283 virtual void gotIsUTC(int index, bool isUTC);
00284
00285 private:
00286 KTimezoneDetailsPrivate *d;
00287 };
00288
00296 class KDECORE_EXPORT KTimezones
00297 {
00298 public:
00299 KTimezones();
00300 ~KTimezones();
00301
00316 const KTimezone *local();
00317
00324 const KTimezone *zone(const QString &name);
00325
00326 typedef QMap<QString, KTimezone *> ZoneMap;
00327
00332 const ZoneMap allZones();
00333
00337 void add(KTimezone *zone);
00338
00339 private:
00340 KTimezones(const KTimezones&);
00341 KTimezones& operator=(const KTimezones&);
00342
00343 float convertCoordinate(const QString &coordinate);
00344
00345 QString m_zoneinfoDir;
00346 ZoneMap *m_zones;
00347 KTimezone *m_UTC;
00348 KTimezonesPrivate *d;
00349 };
00350
00351 #endif