Syndication

syndicationinfo.cpp
1 /*
2  This file is part of the syndication library
3  SPDX-FileCopyrightText: 2006 Frank Osterfeld <[email protected]>
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 
17 namespace Syndication
18 {
19 namespace RDF
20 {
22  : ResourceWrapper(resource)
23 {
24 }
25 
27 {
28 }
29 
31 {
32  return stringToPeriod(resource()->property(SyndicationVocab::self()->updatePeriod())->asString());
33 }
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
bool isNull() const const
@ Yearly
the feed is updated yearly
QString number(int n, int base)
Period updatePeriod() const
Describes the period over which the channel format is updated.
static SyndicationVocab * self()
returns the singleton instance
int updateFrequency() const
Used to describe the frequency of updates in relation to the update period.
@ Weekly
the feed is updated weekly
@ Monthly
the feed is updated monthly
A wrapper for RDF resources.
static Period stringToPeriod(const QString &str)
parses a Period value from a string.
bool isEmpty() const const
static QString periodToString(Period period)
returns Period value as string.
int toInt(bool *ok, int base) const const
@ Daily
the feed is updated daily
@ Hourly
the feed is updated hourly
KCALUTILS_EXPORT QString dateTimeToString(const QDateTime &date, bool dateOnly=false, bool shortfmt=true)
~SyndicationInfo() override
virtual destructor
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
ResourcePtr resource() const
returns the wrapped resource.
QString debugInfo() const
description of the syndication information for debugging purposes
time_t updateBase() const
Defines a base date to be used in concert with updatePeriod and updateFrequency to calculate the publ...
Period
update period enum as used by updatePeriod().
SyndicationInfo()
creates a wrapper wrapping a null resource.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Jun 27 2022 04:08:15 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.