akregator/src

tag.cpp
1 /*
2  This file is part of Akregator.
3 
4  Copyright (C) 2005 Frank Osterfeld <frank.osterfeld at kdemail.net>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include "shared.h"
26 #include "tag.h"
27 #include "tagset.h"
28 
29 #include <tqstring.h>
30 #include <tqvaluelist.h>
31 
32 namespace Akregator {
33 
34 class Tag::TagPrivate : public Shared
35 {
36  public:
37  TQString id;
38  TQString name;
39  TQString scheme;
40  TQString icon;
41 
42  TQValueList<TagSet*> tagSets;
43  bool operator==(const TagPrivate& other) const
44  {
45  return id == other.id; // name is ignored!
46  }
47 };
48 
49 Tag::Tag() : d(new TagPrivate)
50 {}
51 
52 Tag::Tag(const TQString& id, const TQString& name, const TQString& scheme) : d(new TagPrivate)
53 {
54  d->id = id;
55  d->name = name.isNull() ? id : name;
56  d->scheme = scheme;
57  d->icon = "rss_tag";
58 }
59 
60 Tag Tag::fromCategory(const TQString& term, const TQString& scheme, const TQString& name)
61 {
62  Tag tag(scheme + "/" + term, name, scheme);
63  return tag;
64 }
65 
66 
67 Tag::Tag(const Tag& other) : d(0)
68 {
69  *this = other;
70 }
71 
72 Tag::~Tag()
73 {
74  if (d->deref())
75  {
76  delete d;
77  d = 0;
78  }
79 }
80 
81 Tag& Tag::operator=(const Tag& other)
82 {
83  if (this != &other)
84  {
85  other.d->ref();
86  if (d && d->deref())
87  delete d;
88  d = other.d;
89  }
90  return *this;
91 }
92 
93 
94 bool Tag::operator==(const Tag& other) const
95 {
96  return *(other.d) == *d;
97 }
98 
99 bool Tag::operator<(const Tag& other) const
100 {
101  return (name() < other.name()) || (name() == other.name() && id() < other.id());
102 }
103 
104 bool Tag::isNull() const
105 {
106  return d->id.isNull();
107 }
108 
109 TQString Tag::name() const
110 {
111  return d->name;
112 }
113 
114 TQString Tag::scheme() const
115 {
116  return d->scheme;
117 }
118 
119 TQString Tag::icon() const
120 {
121  return d->icon;
122 }
123 
124 void Tag::setIcon(const TQString& icon)
125 {
126  if (icon != d->icon)
127  {
128  d->icon = icon;
129  for (TQValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
130  (*it)->tagUpdated(*this);
131  }
132 }
133 
134 
135 void Tag::setName(const TQString& name)
136 {
137  if (name != d->name)
138  {
139  d->name = name;
140  for (TQValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
141  (*it)->tagUpdated(*this);
142  }
143 }
144 
145 void Tag::addedToTagSet(TagSet* tagSet) const
146 {
147  d->tagSets.append(tagSet);
148 }
149 
150 void Tag::removedFromTagSet(TagSet* tagSet) const
151 {
152  d->tagSets.remove(tagSet);
153 }
154 
155 TQString Tag::id() const
156 {
157  return d->id;
158 }
159 
160 } // namespace Akregator