enclosure.cpp
00001 /* 00002 This file is part of Akregator. 00003 00004 Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program 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 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of TQt, and distribute the resulting executable, 00022 without including the source code for TQt in the source distribution. 00023 */ 00024 00025 #include "enclosure.h" 00026 #include "tools_p.h" 00027 00028 #include <tqdom.h> 00029 #include <tqstring.h> 00030 00031 #include <kdebug.h> 00032 00033 namespace RSS 00034 { 00035 00036 00037 class Enclosure::EnclosurePrivate : public Shared 00038 { 00039 public: 00040 00041 bool isNull; 00042 TQString url; 00043 int length; 00044 TQString type; 00045 00046 bool operator==(const EnclosurePrivate &other) const 00047 { 00048 return ( isNull == other.isNull || (url == other.url && 00049 length == other.length && 00050 type == other.type)); 00051 } 00052 }; 00053 00054 00055 Enclosure Enclosure::fromXML(const TQDomElement& e) 00056 { 00057 TQString url, type; 00058 int length = -1; 00059 00060 if (e.hasAttribute(TQString::fromLatin1("url"))) 00061 url = e.attribute(TQString::fromLatin1("url")); 00062 00063 if (e.hasAttribute(TQString::fromLatin1("length"))) 00064 { 00065 bool ok; 00066 int c = e.attribute(TQString::fromLatin1("length")).toInt(&ok); 00067 length = ok ? c : -1; 00068 } 00069 if (e.hasAttribute(TQString::fromLatin1("type"))) 00070 type = e.attribute(TQString::fromLatin1("type")); 00071 00072 return Enclosure(url, length, type); 00073 } 00074 00075 TQDomElement Enclosure::toXML(TQDomDocument document) const 00076 { 00077 TQDomElement e = document.createElement(TQString::fromLatin1("enclosure")); 00078 if (!d->url.isNull()) 00079 e.setAttribute(TQString::fromLatin1("url"), d->url); 00080 if (d->length != -1) 00081 e.setAttribute(TQString::fromLatin1("length"), TQString::number(d->length)); 00082 if (!d->type.isNull()) 00083 e.setAttribute(TQString::fromLatin1("type"), d->type); 00084 00085 return e; 00086 } 00087 00088 Enclosure::Enclosure() : d(new EnclosurePrivate) 00089 { 00090 d->isNull = true; 00091 d->length = -1; 00092 } 00093 00094 Enclosure::Enclosure(const Enclosure& other) : d(0) 00095 { 00096 *this = other; 00097 } 00098 00099 Enclosure::Enclosure(const TQString& url, int length, const TQString& type) : d(new EnclosurePrivate) 00100 { 00101 d->isNull = false; 00102 d->url = url; 00103 d->length = length; 00104 d->type = type; 00105 } 00106 00107 Enclosure::~Enclosure() 00108 { 00109 if (d->deref()) 00110 { 00111 delete d; 00112 d = 0; 00113 } 00114 } 00115 00116 Enclosure& Enclosure::operator=(const Enclosure& other) 00117 { 00118 if (d != other.d) 00119 { 00120 other.d->ref(); 00121 if (d && d->deref()) 00122 delete d; 00123 d = other.d; 00124 } 00125 return *this; 00126 } 00127 00128 bool Enclosure::operator==(const Enclosure &other) const 00129 { 00130 return *d == *other.d; 00131 } 00132 00133 bool Enclosure::isNull() const 00134 { 00135 return d->isNull; 00136 } 00137 00138 TQString Enclosure::url() const 00139 { 00140 return d->url; 00141 } 00142 00143 int Enclosure::length() const 00144 { 00145 return d->length; 00146 } 00147 00148 TQString Enclosure::type() const 00149 { 00150 return d->type; 00151 } 00152 00153 00154 } // namespace RSS