26 #include <tqvaluelist.h>
28 #include "akregatorconfig.h"
29 #include "fetchqueue.h"
36 class FetchQueue::FetchQueuePrivate
40 TQValueList<Feed*> queuedFeeds;
41 TQValueList<Feed*> fetchingFeeds;
45 FetchQueue::FetchQueue(TQObject* parent,
const char* name): TQObject(parent, name), d(new FetchQueuePrivate) {}
48 FetchQueue::~FetchQueue()
55 void FetchQueue::slotAbort()
57 for (TQValueList<Feed*>::Iterator it = d->fetchingFeeds.begin(); it != d->fetchingFeeds.end(); ++it)
59 disconnectFromFeed(*it);
60 (*it)->slotAbortFetch();
62 d->fetchingFeeds.clear();
64 for (TQValueList<Feed*>::Iterator it = d->queuedFeeds.begin(); it != d->queuedFeeds.end(); ++it)
66 disconnectFromFeed(*it);
68 d->queuedFeeds.clear();
73 void FetchQueue::addFeed(Feed *f)
75 if (!d->queuedFeeds.contains(f) && !d->fetchingFeeds.contains(f))
78 d->queuedFeeds.append(f);
83 void FetchQueue::fetchNextFeed()
85 if (!d->queuedFeeds.isEmpty() && d->fetchingFeeds.count() < Settings::concurrentFetches())
87 if (d->fetchingFeeds.isEmpty() && d->queuedFeeds.count() == 1)
89 Feed* f = *(d->queuedFeeds.begin());
90 d->queuedFeeds.pop_front();
91 d->fetchingFeeds.append(f);
97 void FetchQueue::slotFeedFetched(Feed *f)
103 void FetchQueue::slotFetchError(Feed *f)
109 void FetchQueue::slotFetchAborted(Feed *f)
115 bool FetchQueue::isEmpty()
const
117 return d->queuedFeeds.isEmpty() && d->fetchingFeeds.isEmpty();
120 void FetchQueue::feedDone(Feed *f)
122 disconnectFromFeed(f);
123 d->fetchingFeeds.remove(f);
125 emit signalStopped();
130 void FetchQueue::connectToFeed(Feed* feed)
132 connect (feed, TQ_SIGNAL(fetched(Feed*)),
this, TQ_SLOT(slotFeedFetched(Feed*)));
133 connect (feed, TQ_SIGNAL(fetchError(Feed*)),
this, TQ_SLOT(slotFetchError(Feed*)));
134 connect (feed, TQ_SIGNAL(fetchAborted(Feed*)),
this, TQ_SLOT(slotFetchAborted(Feed*)));
135 connect (feed, TQ_SIGNAL(signalDestroyed(TreeNode*)),
this, TQ_SLOT(slotNodeDestroyed(TreeNode*)));
138 void FetchQueue::disconnectFromFeed(Feed* feed)
140 disconnect (feed, TQ_SIGNAL(fetched(Feed*)),
this, TQ_SLOT(slotFeedFetched(Feed*)));
141 disconnect (feed, TQ_SIGNAL(fetchError(Feed*)),
this, TQ_SLOT(slotFetchError(Feed*)));
142 disconnect (feed, TQ_SIGNAL(fetchAborted(Feed*)),
this, TQ_SLOT(slotFetchAborted(Feed*)));
143 disconnect (feed, TQ_SIGNAL(signalDestroyed(TreeNode*)),
this, TQ_SLOT(slotNodeDestroyed(TreeNode*)));
147 void FetchQueue::slotNodeDestroyed(TreeNode* node)
149 Feed* feed =
dynamic_cast<Feed*
> (node);
153 d->fetchingFeeds.remove(feed);
154 d->queuedFeeds.remove(feed);
160 #include "fetchqueue.moc"