akregator/src/librss

category.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 Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "category.h"
00026 #include "tools_p.h"
00027 
00028 #include <qdom.h>
00029 #include <qstring.h>
00030 
00031 class QString;
00032 
00033 namespace RSS
00034 {
00035 
00036 class Category::CategoryPrivate : public Shared
00037 {
00038     public:
00039     bool isNull;
00040     QString category;
00041     QString domain;
00042 
00043     bool operator==(const CategoryPrivate &other) const
00044     {
00045         return (isNull && other.isNull) || (category == other.category && domain == other.domain);
00046     }
00047 
00048     static CategoryPrivate* copyOnWrite(CategoryPrivate* ep)
00049     {
00050         if (ep->count > 1)
00051         {
00052             ep->deref();
00053             ep = new CategoryPrivate(*ep);
00054         }
00055         return ep;
00056     }
00057 };
00058 
00059 bool Category::isNull() const
00060 {
00061     return d == 0;
00062 }
00063 
00064 Category Category::fromXML(const QDomElement& e)
00065 {
00066     Category obj;
00067     if (e.hasAttribute(QString::fromLatin1("domain")))
00068         obj.d->domain = e.attribute(QString::fromLatin1("domain"));
00069     obj.d->category = e.text();
00070     obj.d->isNull = false;
00071     return obj;
00072 }
00073 
00074 Category::Category() : d(new CategoryPrivate)
00075 {
00076     d->isNull = true;
00077 }
00078 
00079 Category::Category(const Category& other) : d(0)
00080 {
00081      *this = other;
00082 }
00083 
00084 Category::Category(const QString& category, const QString& domain) : d(new CategoryPrivate)
00085 {
00086     d->isNull = false;
00087     d->category = category;
00088     d->domain = domain;
00089 }
00090 
00091 Category::~Category()
00092 {
00093     if (d->deref())
00094     {
00095         delete d;
00096         d = 0;
00097     }
00098 }
00099 
00100 Category& Category::operator=(const Category& other)
00101 {
00102     if (d != other.d)
00103     {
00104         other.d->ref();
00105         if (d && d->deref())
00106             delete d;
00107         d = other.d;
00108     }
00109     return *this;
00110 }
00111 
00112 bool Category::operator==(const Category &other) const
00113 {
00114     return *d == *other.d;
00115 }
00116 
00117 QString Category::category() const
00118 {
00119     return !d->isNull ? d->category : QString::null;
00120 }
00121 
00122 QString Category::domain() const
00123 {
00124     return !d->isNull ? d->domain : QString::null;
00125 }
00126 
00127 } // namespace RSS
00128 
00129 
KDE Home | KDE Accessibility Home | Description of Access Keys