26 #include "articlefilter.h"
27 #include "fetchqueue.h"
32 #include "treenodevisitor.h"
36 #include <tqvaluelist.h>
40 class TagNode::TagNodePrivate
43 Filters::TagMatcher filter;
48 TQValueList<Article> articles;
49 TQValueList<Article> addedArticlesNotify;
50 TQValueList<Article> removedArticlesNotify;
51 TQValueList<Article> updatedArticlesNotify;
54 TagNode::TagNode(
const Tag& tag, TreeNode* observed) : d(new TagNodePrivate)
58 d->filter = Filters::TagMatcher(tag.id());
60 d->observed = observed;
63 connect(observed, TQ_SIGNAL(signalDestroyed(TreeNode*)),
this, TQ_SLOT(slotObservedDestroyed(TreeNode*)));
64 connect(observed, TQ_SIGNAL(signalArticlesAdded(TreeNode*,
const TQValueList<Article>&)),
this, TQ_SLOT(slotArticlesAdded(TreeNode*,
const TQValueList<Article>&)) );
65 connect(observed, TQ_SIGNAL(signalArticlesUpdated(TreeNode*,
const TQValueList<Article>&)),
this, TQ_SLOT(slotArticlesUpdated(TreeNode*,
const TQValueList<Article>&)) );
66 connect(observed, TQ_SIGNAL(signalArticlesRemoved(TreeNode*,
const TQValueList<Article>&)),
this, TQ_SLOT(slotArticlesRemoved(TreeNode*,
const TQValueList<Article>&)) );
68 d->articles = observed->articles(tag.id());
72 TQString TagNode::icon()
const
77 Tag TagNode::tag()
const
84 emitSignalDestroyed();
89 bool TagNode::accept(TreeNodeVisitor* visitor)
91 if (visitor->visitTagNode(
this))
94 return visitor->visitTreeNode(
this);
97 void TagNode::calcUnread()
100 TQValueList<Article>::Iterator en = d->articles.end();
101 for (TQValueList<Article>::Iterator it = d->articles.begin(); it != en; ++it)
102 if ((*it).status() != Article::Read)
104 if (d->unread != unread)
111 int TagNode::unread()
const
117 int TagNode::totalCount()
const
119 return d->articles.count();
123 TQValueList<Article> TagNode::articles(
const TQString& tag)
128 TQStringList TagNode::tags()
const
131 return TQStringList();
134 TQDomElement TagNode::toOPML( TQDomElement parent, TQDomDocument document )
const
136 return TQDomElement();
139 TreeNode* TagNode::next()
142 return nextSibling();
144 Folder* p = parent();
147 if ( p->nextSibling() )
148 return p->nextSibling();
155 void TagNode::slotDeleteExpiredArticles()
160 void TagNode::slotMarkAllArticlesAsRead()
162 setNotificationMode(
false);
163 TQValueList<Article>::Iterator en = d->articles.end();
164 for (TQValueList<Article>::Iterator it = d->articles.begin(); it != en; ++it)
165 (*it).setStatus(Article::Read);
166 setNotificationMode(
true);
169 void TagNode::slotAddToFetchQueue(FetchQueue* ,
bool )
174 void TagNode::doArticleNotification()
176 if (!d->addedArticlesNotify.isEmpty())
178 emit signalArticlesAdded(
this, d->addedArticlesNotify);
179 d->addedArticlesNotify.clear();
181 if (!d->updatedArticlesNotify.isEmpty())
183 emit signalArticlesUpdated(
this, d->updatedArticlesNotify);
184 d->updatedArticlesNotify.clear();
186 if (!d->removedArticlesNotify.isEmpty())
188 emit signalArticlesRemoved(
this, d->removedArticlesNotify);
189 d->removedArticlesNotify.clear();
191 TreeNode::doArticleNotification();
194 void TagNode::slotArticlesAdded(TreeNode* node,
const TQValueList<Article>& list)
197 for (TQValueList<Article>::ConstIterator it = list.begin(); it != list.end(); ++it)
199 if (!d->articles.contains(*it) && d->filter.matches(*it))
201 d->articles.append(*it);
202 d->addedArticlesNotify.append(*it);
214 void TagNode::slotArticlesUpdated(TreeNode* node,
const TQValueList<Article>& list)
216 bool updated =
false;
217 for (TQValueList<Article>::ConstIterator it = list.begin(); it != list.end(); ++it)
219 if (d->articles.contains(*it))
221 if (!d->filter.matches(*it))
223 d->articles.remove(*it);
224 d->removedArticlesNotify.append(*it);
229 d->updatedArticlesNotify.append(*it);
235 if (d->filter.matches(*it))
237 d->articles.append(*it);
238 d->addedArticlesNotify.append(*it);
250 void TagNode::slotArticlesRemoved(TreeNode* node,
const TQValueList<Article>& list)
252 bool removed =
false;
253 for (TQValueList<Article>::ConstIterator it = list.begin(); it != list.end(); ++it)
255 if (d->articles.contains(*it))
257 d->articles.remove(*it);
258 d->removedArticlesNotify.append(*it);
269 void TagNode::setTitle(
const TQString& title)
271 if (d->tag.name() != title)
272 d->tag.setName(title);
273 TreeNode::setTitle(title);
276 void TagNode::slotObservedDestroyed(TreeNode* )
278 d->removedArticlesNotify = d->articles;
283 void TagNode::tagChanged()
285 bool changed =
false;
286 if (title() != d->tag.name())
288 setTitle(d->tag.name());
292 if (d->icon != d->tag.icon())
294 d->icon = d->tag.icon();
304 #include "tagnode.moc"