akregator/src

tag.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 "shared.h"
00026 #include "tag.h"
00027 #include "tagset.h"
00028 
00029 #include <qstring.h>
00030 #include <qvaluelist.h>
00031 
00032 namespace Akregator {
00033 
00034 class Tag::TagPrivate : public Shared
00035 {
00036     public:
00037     QString id;
00038     QString name;
00039     QString scheme;
00040     QString icon;
00041 
00042     QValueList<TagSet*> tagSets;
00043     bool operator==(const TagPrivate& other) const
00044     {
00045         return id == other.id; // name is ignored!
00046     }
00047 };
00048 
00049 Tag::Tag() : d(new TagPrivate)
00050 {}
00051 
00052 Tag::Tag(const QString& id, const QString& name, const QString& scheme) : d(new TagPrivate)
00053 {
00054     d->id = id;
00055     d->name = name.isNull() ? id : name;
00056     d->scheme = scheme;
00057     d->icon = "rss_tag";
00058 }
00059 
00060 Tag Tag::fromCategory(const QString& term, const QString& scheme, const QString& name)
00061 {
00062     Tag tag(scheme + "/" + term, name, scheme);
00063     return tag;
00064 }
00065 
00066 
00067 Tag::Tag(const Tag& other) : d(0)
00068 {
00069     *this = other;
00070 }
00071 
00072 Tag::~Tag()
00073 {
00074     if (d->deref())
00075     {
00076         delete d;
00077         d = 0;
00078     }
00079 }
00080 
00081 Tag& Tag::operator=(const Tag& other)
00082 {
00083     if (this != &other)
00084     {
00085         other.d->ref();
00086         if (d && d->deref())
00087             delete d;
00088         d = other.d;
00089     }
00090     return *this;
00091 }
00092 
00093 
00094 bool Tag::operator==(const Tag& other) const
00095 {
00096     return *(other.d) == *d;
00097 }
00098 
00099 bool Tag::operator<(const Tag& other) const
00100 {
00101     return (name() < other.name()) || (name() == other.name() && id() < other.id());
00102 }
00103 
00104 bool Tag::isNull() const
00105 {
00106     return d->id.isNull();
00107 }
00108 
00109 QString Tag::name() const
00110 {
00111     return d->name;
00112 }
00113 
00114 QString Tag::scheme() const
00115 {
00116     return d->scheme;
00117 }
00118 
00119 QString Tag::icon() const
00120 {
00121     return d->icon;
00122 }
00123 
00124 void Tag::setIcon(const QString& icon)
00125 {
00126     if (icon != d->icon)
00127     {
00128         d->icon = icon;
00129         for (QValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
00130             (*it)->tagUpdated(*this);
00131     }
00132 }
00133 
00134 
00135 void Tag::setName(const QString& name)
00136 {
00137     if (name != d->name)
00138     {
00139         d->name = name;
00140         for (QValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
00141             (*it)->tagUpdated(*this);
00142     }
00143 }
00144 
00145 void Tag::addedToTagSet(TagSet* tagSet) const
00146 {
00147     d->tagSets.append(tagSet);
00148 }
00149 
00150 void Tag::removedFromTagSet(TagSet* tagSet) const
00151 {
00152     d->tagSets.remove(tagSet);
00153 }
00154 
00155 QString Tag::id() const
00156 {
00157     return d->id;
00158 }
00159 
00160 } // namespace Akregator
KDE Home | KDE Accessibility Home | Description of Access Keys