akregator/src

progressmanager.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 <tqmap.h>
26#include <tqstylesheet.h>
27
28#include <tdelocale.h>
29#include <kstaticdeleter.h>
30
31#include <libtdepim/progressmanager.h>
32
33#include "feedlist.h"
34#include "feed.h"
35#include "treenode.h"
36
37#include "progressmanager.h"
38
39//#include <kdebug.h>
40
41namespace Akregator {
42
43class ProgressManager::ProgressManagerPrivate
44{
45 public:
46 FeedList* feedList;
47 TQMap<Feed*, ProgressItemHandler*> handlers;
48
49};
50
51static KStaticDeleter<ProgressManager> progressmanagersd;
52ProgressManager* ProgressManager::m_self = 0;
53
54ProgressManager* ProgressManager::self()
55{
56 if (!m_self)
57 m_self = progressmanagersd.setObject(m_self, new ProgressManager);
58 return m_self;
59}
60
61ProgressManager::ProgressManager() : d(new ProgressManagerPrivate)
62{
63 d->feedList = 0;
64}
65
66ProgressManager::~ProgressManager()
67{
68 delete d;
69 d = 0;
70}
71
72void ProgressManager::setFeedList(FeedList* feedList)
73{
74 if (feedList == d->feedList)
75 return;
76
77 if (d->feedList != 0)
78 {
79 for (TQMap<Feed*, ProgressItemHandler*>::ConstIterator it = d->handlers.begin(); it != d->handlers.end(); ++it)
80 delete *it;
81 d->handlers.clear();
82
83 disconnect(d->feedList, TQ_SIGNAL(signalNodeAdded(TreeNode*)), this, TQ_SLOT(slotNodeAdded(TreeNode*)));
84 disconnect(d->feedList, TQ_SIGNAL(signalNodeRemoved(TreeNode*)), this, TQ_SLOT(slotNodeRemoved(TreeNode*)));
85 }
86
87 d->feedList = feedList;
88
89 if (feedList != 0)
90 {
91 TQValueList<TreeNode*> list = feedList->asFlatList();
92
93 for (TQValueList<TreeNode*>::ConstIterator it = list.begin(); it != list.end(); ++it)
94 slotNodeAdded(*it);
95 connect(feedList, TQ_SIGNAL(signalNodeAdded(TreeNode*)), this, TQ_SLOT(slotNodeAdded(TreeNode*)));
96 connect(feedList, TQ_SIGNAL(signalNodeRemoved(TreeNode*)), this, TQ_SLOT(slotNodeRemoved(TreeNode*)));
97 }
98}
99
100void ProgressManager::slotNodeAdded(TreeNode* node)
101{
102 Feed* feed = dynamic_cast<Feed*>(node);
103 if (feed)
104 {
105 if (!d->handlers.contains(feed))
106 d->handlers[feed] = new ProgressItemHandler(feed);
107 connect(feed, TQ_SIGNAL(signalDestroyed(TreeNode*)), this, TQ_SLOT(slotNodeDestroyed(TreeNode*)));
108 }
109}
110
111void ProgressManager::slotNodeRemoved(TreeNode* node)
112{
113 Feed* feed = dynamic_cast<Feed*>(node);
114 if (feed)
115 {
116 disconnect(feed, TQ_SIGNAL(signalDestroyed(TreeNode*)), this, TQ_SLOT(slotNodeDestroyed(TreeNode*)));
117 delete d->handlers[feed];
118 d->handlers.remove(feed);
119 }
120}
121
122void ProgressManager::slotNodeDestroyed(TreeNode* node)
123{
124 Feed* feed = dynamic_cast<Feed*>(node);
125 if (feed)
126 {
127 delete d->handlers[feed];
128 d->handlers.remove(feed);
129 }
130}
131
132class ProgressItemHandler::ProgressItemHandlerPrivate
133{
134 public:
135
136 Feed* feed;
137 KPIM::ProgressItem* progressItem;
138};
139
140ProgressItemHandler::ProgressItemHandler(Feed* feed) : d(new ProgressItemHandlerPrivate)
141{
142 d->feed = feed;
143 d->progressItem = 0;
144
145 connect(feed, TQ_SIGNAL(fetchStarted(Feed*)), this, TQ_SLOT(slotFetchStarted()));
146 connect(feed, TQ_SIGNAL(fetched(Feed*)), this, TQ_SLOT(slotFetchCompleted()));
147 connect(feed, TQ_SIGNAL(fetchError(Feed*)), this, TQ_SLOT(slotFetchError()));
148 connect(feed, TQ_SIGNAL(fetchAborted(Feed*)), this, TQ_SLOT(slotFetchAborted()));
149}
150
151ProgressItemHandler::~ProgressItemHandler()
152{
153 if (d->progressItem)
154 {
155 d->progressItem->setComplete();
156 d->progressItem = 0;
157 }
158
159 delete d;
160 d = 0;
161}
162
163void ProgressItemHandler::slotFetchStarted()
164{
165 if (d->progressItem)
166 {
167 d->progressItem->setComplete();
168 d->progressItem = 0;
169 }
170
171 d->progressItem = KPIM::ProgressManager::createProgressItem(KPIM::ProgressManager::getUniqueID(), TQStyleSheet::escape( d->feed->title() ), TQString(), true);
172
173 connect(d->progressItem, TQ_SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), d->feed, TQ_SLOT(slotAbortFetch()));
174}
175
176
177void ProgressItemHandler::slotFetchCompleted()
178{
179 if (d->progressItem)
180 {
181 d->progressItem->setStatus(i18n("Fetch completed"));
182 d->progressItem->setComplete();
183 d->progressItem = 0;
184 }
185}
186
187void ProgressItemHandler::slotFetchError()
188{
189 if (d->progressItem)
190 {
191 d->progressItem->setStatus(i18n("Fetch error"));
192 d->progressItem->setComplete();
193 d->progressItem = 0;
194 }
195}
196
197void ProgressItemHandler::slotFetchAborted()
198{
199 if (d->progressItem)
200 {
201 d->progressItem->setStatus(i18n("Fetch aborted"));
202 d->progressItem->setComplete();
203 d->progressItem = 0;
204 }
205}
206
207} // namespace Akregator
208
209#include "progressmanager.moc"
The model of a feed tree, represents an OPML document.
Definition: feedlist.h:45
represents a feed
Definition: feed.h:63
this class handles the creation and deletion of progress items for one feed.
Abstract base class for all kind of elements in the feed tree, like feeds and feed groups (and search...
Definition: treenode.h:52