syndication/rdf
syndicationinfo.cpp
00001 /* 00002 * This file is part of the syndication library 00003 * 00004 * Copyright (C) 2006 Frank Osterfeld <osterfeld@kde.org> 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Library General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Library General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Library General Public License 00017 * along with this library; see the file COPYING.LIB. If not, write to 00018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 * 00021 */ 00022 00023 #include "syndicationinfo.h" 00024 #include "property.h" 00025 #include "statement.h" 00026 #include "syndicationvocab.h" 00027 00028 #include <tools.h> 00029 00030 #include <QtCore/QString> 00031 00032 namespace Syndication { 00033 namespace RDF { 00034 00035 SyndicationInfo::SyndicationInfo(ResourcePtr resource) : ResourceWrapper(resource) 00036 { 00037 } 00038 00039 SyndicationInfo::~SyndicationInfo() 00040 { 00041 } 00042 00043 SyndicationInfo::Period SyndicationInfo::updatePeriod() const 00044 { 00045 return stringToPeriod(resource()->property(SyndicationVocab::self()->updatePeriod())->asString()); 00046 } 00047 00048 int SyndicationInfo::updateFrequency() const 00049 { 00050 QString freqStr = resource()->property(SyndicationVocab::self()->updateFrequency())->asString(); 00051 00052 if (freqStr.isEmpty()) 00053 return 1; // 1 is default 00054 00055 bool ok = false; 00056 int freq = freqStr.toInt(&ok); 00057 00058 if (ok) 00059 return freq; 00060 else 00061 return 1; // 1 is default 00062 } 00063 00064 time_t SyndicationInfo::updateBase() const 00065 { 00066 QString str = resource()->property(SyndicationVocab::self()->updateBase())->asString(); 00067 00068 return parseDate(str, ISODate); 00069 } 00070 00071 QString SyndicationInfo::debugInfo() const 00072 { 00073 QString info; 00074 if (updatePeriod() != Daily) 00075 info += QString::fromLatin1("syn:updatePeriod: #%1#\n").arg(periodToString(updatePeriod())); 00076 info += QString::fromLatin1("syn:updateFrequency: #%1#\n").arg(QString::number(updateFrequency())); 00077 00078 QString dbase = dateTimeToString(updateBase()); 00079 if (!dbase.isNull()) 00080 info += QString::fromLatin1("syn:updateBase: #%1#\n").arg(dbase); 00081 00082 return info; 00083 } 00084 00085 QString SyndicationInfo::periodToString(Period period) 00086 { 00087 switch (period) 00088 { 00089 case Daily: 00090 return QLatin1String("daily"); 00091 case Hourly: 00092 return QLatin1String("hourly"); 00093 case Monthly: 00094 return QLatin1String("monthly"); 00095 case Weekly: 00096 return QLatin1String("weekly"); 00097 case Yearly: 00098 return QLatin1String("yearly"); 00099 default: // should never happen 00100 return QString(); 00101 } 00102 } 00103 00104 SyndicationInfo::Period SyndicationInfo::stringToPeriod(const QString& str) 00105 { 00106 if (str.isEmpty()) 00107 return Daily; // default is "daily" 00108 00109 if (str == QLatin1String("hourly")) 00110 return Hourly; 00111 if (str == QLatin1String("monthly")) 00112 return Monthly; 00113 if (str == QLatin1String("weekly")) 00114 return Weekly; 00115 if (str == QLatin1String("yearly")) 00116 return Yearly; 00117 00118 return Daily; // default is "daily" 00119 } 00120 00121 } // namespace RDF 00122 } // namespace Syndication
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:47:16 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon May 14 2012 04:47:16 by doxygen 1.7.5 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.