File indexing completed on 2024-04-21 04:01:03

0001 /*
0002     This file is part of the syndication library
0003     SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef SYNDICATION_RDF_SYNDICATIONINFO_H
0009 #define SYNDICATION_RDF_SYNDICATIONINFO_H
0010 
0011 #include <syndication/rdf/resourcewrapper.h>
0012 
0013 #include <ctime>
0014 
0015 class QString;
0016 
0017 namespace Syndication
0018 {
0019 namespace RDF
0020 {
0021 /**
0022  * Wrapper to access syndication information for a feed.
0023  * The RSS 1.0 syndication module provides syndication hints to
0024  * aggregators regarding how often it is updated.
0025  *
0026  * The specification can be found at
0027  * http://web.resource.org/rss/1.0/modules/syndication/
0028  *
0029  * @author Frank Osterfeld
0030  */
0031 class SyndicationInfo : public ResourceWrapper
0032 {
0033 public:
0034     /**
0035      * update period enum as used by updatePeriod().
0036      */
0037     enum Period {
0038         Hourly, /**< the feed is updated hourly */
0039         Daily, /**< the feed is updated daily */
0040         Weekly, /**< the feed is updated weekly */
0041         Monthly, /**< the feed is updated monthly */
0042         Yearly, /**< the feed is updated yearly */
0043     };
0044 
0045     /**
0046      * creates a wrapper wrapping a null resource.
0047      * isNull() will be true.
0048      */
0049     SyndicationInfo();
0050 
0051     /**
0052      * creates a wrapper from a resource
0053      * @param resource the feed resource to read syndication
0054      * information from
0055      */
0056     explicit SyndicationInfo(ResourcePtr resource);
0057 
0058     /**
0059      * virtual destructor
0060      */
0061     ~SyndicationInfo() override;
0062 
0063     /**
0064      * Describes the period over which the channel format is updated.
0065      * Acceptable values are: hourly, daily, weekly, monthly, yearly.
0066      * If omitted, daily is assumed.
0067      *
0068      * @return update period, daily is default
0069      */
0070     Period updatePeriod() const;
0071 
0072     /** Used to describe the frequency of updates in relation to the
0073      * update period. A positive integer indicates how many times in
0074      * that period the channel is updated. For example, an
0075      * updatePeriod of daily, and an updateFrequency of 2 indicates
0076      * the channel format is updated twice daily. If omitted a value
0077      * of 1 is assumed.
0078      *
0079      * @return update frequency, default is 1
0080      */
0081     int updateFrequency() const;
0082 
0083     /**
0084      * Defines a base date to be used in concert with updatePeriod
0085      * and updateFrequency to calculate the publishing schedule.
0086      *
0087      * @return the base date in seconds since epoch. Default value is
0088      * 0 (epoch).
0089      */
0090     time_t updateBase() const;
0091 
0092     /**
0093      * description of the syndication information
0094      * for debugging purposes
0095      *
0096      * @return debug string
0097      */
0098     QString debugInfo() const;
0099 
0100 protected:
0101     /**
0102      * returns Period value as string.
0103      * @param period period enum to convert to a string
0104      * @return the enum name in lower case, "daily", "hourly", etc.
0105      */
0106     static QString periodToString(Period period);
0107 
0108     /**
0109      * parses a Period value from a string.
0110      *
0111      * @param str a period string as defined in the syndication module
0112      * @return the parsed period, Daily (the default) if the parsed
0113      * string is empty or invalid
0114      */
0115     static Period stringToPeriod(const QString &str);
0116 };
0117 
0118 } // namespace RDF
0119 } // namespace Syndication
0120 
0121 #endif // SYNDICATION_RDF_SYNDICATIONINFO_H