File indexing completed on 2024-04-21 14:55:43

0001 /*
0002    This file is part of the KDE libraries
0003    Copyright (c) 2005-2008 David Jarvie <djarvie@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 
0021 /** @file
0022  * TZFILE time zone functions
0023  * @author David Jarvie <djarvie@kde.org>.
0024  */
0025 
0026 #ifndef _KTZFILETIMEZONE_H
0027 #define _KTZFILETIMEZONE_H
0028 
0029 #include <kdelibs4support_export.h>
0030 #include <ktimezone.h>
0031 
0032 #include <QString>
0033 
0034 class KTzfileTimeZoneSource;
0035 class KTzfileTimeZonePrivate;
0036 class KTzfileTimeZoneDataPrivate;
0037 class KTzfileTimeZoneSourcePrivate;
0038 
0039 /**
0040  * The KTzfileTimeZone class represents a time zone defined in tzfile(5) format.
0041  *
0042  * It works in partnership with the KTzfileTimeZoneSource class which reads and parses the
0043  * time zone definition files.
0044  *
0045  * @short Represents a time zone defined in tzfile(5) format
0046  * @see KTzfileTimeZoneBackend, KTzfileTimeZoneSource, KTzfileTimeZoneData
0047  * @ingroup timezones
0048  * @author David Jarvie <djarvie@kde.org>.
0049  */
0050 class KDELIBS4SUPPORT_EXPORT KTzfileTimeZone : public KTimeZone  //krazy:exclude=dpointer (no d-pointer for KTimeZone derived classes)
0051 {
0052 public:
0053     /**
0054      * Creates a time zone.
0055      *
0056      * @param source      tzfile reader and parser
0057      * @param name        time zone's unique name, which must be the tzfile path relative
0058      *                    to the location specified for @p source
0059      * @param countryCode ISO 3166 2-character country code, empty if unknown
0060      * @param latitude    in degrees (between -90 and +90), UNKNOWN if not known
0061      * @param longitude   in degrees (between -180 and +180), UNKNOWN if not known
0062      * @param comment     description of the time zone, if any
0063      */
0064     KTzfileTimeZone(KTzfileTimeZoneSource *source, const QString &name,
0065                     const QString &countryCode = QString(), float latitude = UNKNOWN, float longitude = UNKNOWN,
0066                     const QString &comment = QString());
0067 
0068     ~KTzfileTimeZone() override;
0069 
0070 private:
0071     // d-pointer is in KTzfileTimeZoneBackend.
0072     // This is a requirement for classes inherited from KTimeZone.
0073 };
0074 
0075 /**
0076  * Backend class for KTzfileTimeZone class.
0077  *
0078  * This class implements KTzfileTimeZone's constructors and virtual methods. A
0079  * backend class is required for all classes inherited from KTimeZone to
0080  * allow KTimeZone virtual methods to work together with reference counting of
0081  * private data.
0082  *
0083  * @short Backend class for KTzfileTimeZone class
0084  * @see KTimeZoneBackend, KTzfileTimeZone, KTimeZone
0085  * @ingroup timezones
0086  * @author David Jarvie <djarvie@kde.org>.
0087  */
0088 class KDELIBS4SUPPORT_EXPORT KTzfileTimeZoneBackend : public KTimeZoneBackend  //krazy:exclude=dpointer (non-const d-pointer for KTimeZoneBackend-derived classes)
0089 {
0090 public:
0091     /** Implements KTzfileTimeZone::KTzfileTimeZone(). */
0092     KTzfileTimeZoneBackend(KTzfileTimeZoneSource *source, const QString &name,
0093                            const QString &countryCode, float latitude, float longitude, const QString &comment);
0094 
0095     ~KTzfileTimeZoneBackend() override;
0096 
0097     /**
0098      * Creates a copy of this instance.
0099      *
0100      * @return new copy
0101      */
0102     KTimeZoneBackend *clone() const override;
0103 
0104     /**
0105      * Returns the class name of the data represented by this instance.
0106      *
0107      * @return "KTzfileTimeZone"
0108      */
0109     QByteArray type() const override;
0110 
0111     /**
0112      * Implements KTzfileTimeZone::hasTransitions().
0113      *
0114      * Returns whether daylight saving transitions are available for the time zone.
0115      *
0116      * @param caller calling KTzfileTimeZone object
0117      * @return @c true
0118      */
0119     bool hasTransitions(const KTimeZone *caller) const override;
0120 
0121 private:
0122     KTzfileTimeZonePrivate *d;   // non-const
0123 };
0124 
0125 /**
0126  * A class to read and parse tzfile time zone definition files.
0127  *
0128  * tzfile is the format used by zoneinfo files in the system time zone database.
0129  * The format is documented in the tzfile(5) manpage.
0130  *
0131  * @short Reads and parses tzfile(5) time zone definition files
0132  * @see KTzfileTimeZone, KTzfileTimeZoneData
0133  * @ingroup timezones
0134  * @author David Jarvie <djarvie@kde.org>.
0135  */
0136 class KDELIBS4SUPPORT_EXPORT KTzfileTimeZoneSource : public KTimeZoneSource
0137 {
0138 public:
0139     /**
0140      * Constructs a time zone source.
0141      *
0142      * The directory containing the time zone definition files is given by the
0143      * @p location parameter, which will usually be the zoneinfo directory. For
0144      * tzfile files in other locations, bear in mind that the name generated
0145      * for each KTzfileTimeZone is its file path relative to @p location.
0146      *
0147      * @param location the local directory containing the time zone definition files
0148      */
0149     KDELIBS4SUPPORT_DEPRECATED explicit KTzfileTimeZoneSource(const QString &location);
0150     ~KTzfileTimeZoneSource() override;
0151 
0152     /**
0153      * Returns the local directory containing the time zone definition files.
0154      *
0155      * @return path to time zone definition files
0156      */
0157     QString location() const;
0158 
0159     /**
0160      * Parses a tzfile file to extract detailed information for one time zone.
0161      *
0162      * @param zone the time zone for which data is to be extracted
0163      * @return a KTzfileTimeZoneData instance containing the parsed data.
0164      *         The caller is responsible for deleting the KTimeZoneData instance.
0165      *         Null is returned on error.
0166      */
0167     KTimeZoneData *parse(const KTimeZone &zone) const override;
0168 
0169 private:
0170     KTzfileTimeZoneSourcePrivate *const d;
0171 };
0172 
0173 /**
0174  * @internal
0175  * The parsed data returned by KTzfileTimeZoneSource.
0176  *
0177  * @short Parsed data from tzfile(5) time zone definition files
0178  * @see KTzfileTimeZoneSource, KTzfileTimeZone
0179  * @ingroup timezones
0180  * @author David Jarvie <djarvie@kde.org>.
0181  */
0182 class KTzfileTimeZoneData : public KTimeZoneData
0183 {
0184     friend class KTzfileTimeZoneSource;
0185 
0186 public:
0187     KTzfileTimeZoneData();
0188     KTzfileTimeZoneData(const KTzfileTimeZoneData &);
0189     ~KTzfileTimeZoneData() override;
0190 
0191     KTzfileTimeZoneData &operator=(const KTzfileTimeZoneData &);
0192 
0193     /**
0194      * Creates a new copy of this object.
0195      * The caller is responsible for deleting the copy.
0196      * Derived classes must reimplement this method to return a copy of the
0197      * calling instance
0198      *
0199      * @return copy of this instance. This is a KTzfileTimeZoneData pointer.
0200      */
0201     KTimeZoneData *clone() const override;
0202 
0203     /**
0204      * Return whether daylight saving transitions are available for the time zone.
0205      *
0206      * @return @c true
0207      */
0208     bool hasTransitions() const override;
0209 
0210 private:
0211     // Enable this if you add KDELIBS4SUPPORT_EXPORT to this class
0212     //KTzfileTimeZoneDataPrivate * const d;
0213 };
0214 
0215 #endif