Syndication

syndicationinfo.cpp
1/*
2 This file is part of the syndication library
3 SPDX-FileCopyrightText: 2006 Frank Osterfeld <osterfeld@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "syndicationinfo.h"
9#include "property.h"
10#include "statement.h"
11#include "syndicationvocab.h"
12
13#include <tools.h>
14
15#include <QString>
16
17namespace Syndication
18{
19namespace RDF
20{
25
29
34
36{
37 QString freqStr = resource()->property(SyndicationVocab::self()->updateFrequency())->asString();
38
39 if (freqStr.isEmpty()) {
40 return 1; // 1 is default
41 }
42
43 bool ok = false;
44 int freq = freqStr.toInt(&ok);
45
46 if (ok) {
47 return freq;
48 } else {
49 return 1; // 1 is default
50 }
51}
52
54{
55 QString str = resource()->property(SyndicationVocab::self()->updateBase())->asString();
56
57 return parseDate(str, ISODate);
58}
59
61{
62 QString info;
63 if (updatePeriod() != Daily) {
64 info += QStringLiteral("syn:updatePeriod: #%1#\n").arg(periodToString(updatePeriod()));
65 }
66 info += QStringLiteral("syn:updateFrequency: #%1#\n").arg(QString::number(updateFrequency()));
67
68 const QString dbase = dateTimeToString(updateBase());
69 if (!dbase.isNull()) {
70 info += QStringLiteral("syn:updateBase: #%1#\n").arg(dbase);
71 }
72
73 return info;
74}
75
77{
78 switch (period) {
79 case Daily:
80 return QStringLiteral("daily");
81 case Hourly:
82 return QStringLiteral("hourly");
83 case Monthly:
84 return QStringLiteral("monthly");
85 case Weekly:
86 return QStringLiteral("weekly");
87 case Yearly:
88 return QStringLiteral("yearly");
89 default: // should never happen
90 return QString();
91 }
92}
93
95{
96 if (str.isEmpty()) {
97 return Daily; // default is "daily"
98 }
99
100 if (str == QLatin1String("hourly")) {
101 return Hourly;
102 }
103 if (str == QLatin1String("monthly")) {
104 return Monthly;
105 }
106 if (str == QLatin1String("weekly")) {
107 return Weekly;
108 }
109 if (str == QLatin1String("yearly")) {
110 return Yearly;
111 }
112
113 return Daily; // default is "daily"
114}
115
116} // namespace RDF
117} // namespace Syndication
A wrapper for RDF resources.
ResourcePtr resource() const
returns the wrapped resource.
SyndicationInfo()
creates a wrapper wrapping a null resource.
int updateFrequency() const
Used to describe the frequency of updates in relation to the update period.
static Period stringToPeriod(const QString &str)
parses a Period value from a string.
Period
update period enum as used by updatePeriod().
@ Yearly
the feed is updated yearly
@ Daily
the feed is updated daily
@ Hourly
the feed is updated hourly
@ Weekly
the feed is updated weekly
@ Monthly
the feed is updated monthly
static QString periodToString(Period period)
returns Period value as string.
time_t updateBase() const
Defines a base date to be used in concert with updatePeriod and updateFrequency to calculate the publ...
Period updatePeriod() const
Describes the period over which the channel format is updated.
QString debugInfo() const
description of the syndication information for debugging purposes
~SyndicationInfo() override
virtual destructor
static SyndicationVocab * self()
returns the singleton instance
QString arg(Args &&... args) const const
bool isEmpty() const const
bool isNull() const const
QString number(double n, char format, int precision)
int toInt(bool *ok, int base) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.