akregator/src

frame.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2004 Sashmit Bhaduri <smt@vfemail.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 <tqregexp.h>
26#include <tqstylesheet.h>
27
28#include <tdeactioncollection.h>
29#include <kdebug.h>
30#include <tdelocale.h>
31#include <tdeparts/browserextension.h>
32#include <tdeparts/part.h>
33
34#include <libtdepim/progressmanager.h>
35
36#include "frame.h"
37
38namespace Akregator {
39
40Frame::Frame(TQObject * parent, KParts::ReadOnlyPart *p, TQWidget *visWidget, const TQString& tit, bool watchSignals)
41 :TQObject(parent, "aKregatorFrame")
42{
43 m_autoDeletePart = false;
44 m_part=p;
45 m_widget=visWidget;
46 m_title=tit;
47 m_state=Idle;
48 m_progress=-1;
49 m_progressItem=0;
50
51 if (watchSignals) // e.g, articles tab has no part
52 {
53 connect(m_part, TQ_SIGNAL(setWindowCaption (const TQString &)), this, TQ_SLOT(setCaption (const TQString &)));
54 connect(m_part, TQ_SIGNAL(setStatusBarText (const TQString &)), this, TQ_SLOT(setStatusText (const TQString &)));
55
56 KParts::BrowserExtension *ext=KParts::BrowserExtension::childObject( p );
57 if (ext)
58 connect( ext, TQ_SIGNAL(loadingProgress(int)), this, TQ_SLOT(setProgress(int)) );
59
60 connect(p, TQ_SIGNAL(started(TDEIO::Job*)), this, TQ_SLOT(setStarted()));
61 connect(p, TQ_SIGNAL(completed()), this, TQ_SLOT(setCompleted()));
62 connect(p, TQ_SIGNAL(canceled(const TQString &)), this, TQ_SLOT(setCanceled(const TQString&)));
63 connect(p, TQ_SIGNAL(completed(bool)), this, TQ_SLOT(setCompleted()));
64
65/* TDEActionCollection *coll=p->actionCollection();
66 if (coll)
67 {
68 connect( coll, TQ_SIGNAL( actionStatusText( const TQString & ) ),
69 this, TQ_SLOT( slotActionStatusText( const TQString & ) ) );
70 connect( coll, TQ_SIGNAL( clearStatusText() ),
71 this, TQ_SLOT( slotClearStatusText() ) );
72 }
73*/
74 }
75}
76
77void Frame::setAutoDeletePart(bool autoDelete)
78{
79 m_autoDeletePart = autoDelete;
80}
81
82Frame::~Frame()
83{
84 if(m_progressItem)
85 {
86 m_progressItem->setComplete();
87 }
88 if (m_autoDeletePart)
89 m_part->deleteLater();
90}
91
92int Frame::state() const
93{
94 return m_state;
95}
96
97KParts::ReadOnlyPart *Frame::part() const
98{
99 return m_part;
100}
101
102TQWidget *Frame::widget() const
103{
104 return m_widget;
105}
106
107void Frame::setTitle(const TQString &s)
108{
109 if (m_title != s)
110 {
111 m_title = s;
112 emit titleChanged(this, s);
113 }
114}
115
116void Frame::setCaption(const TQString &s)
117{
118 if(m_progressItem) m_progressItem->setLabel(s);
119 m_caption=s;
120 emit captionChanged(s);
121}
122
123void Frame::setStatusText(const TQString &s)
124{
125 m_statusText=s;
126 m_statusText.replace(TQRegExp("<[^>]*>"), "");
127 emit statusText(m_statusText);
128}
129
130void Frame::setProgress(int a)
131{
132 if(m_progressItem) {
133 m_progressItem->setProgress((int)a);
134 }
135 m_progress=a;
136 emit loadingProgress(a);
137}
138
139void Frame::setState(int a)
140{
141 m_state=a;
142
143 switch (m_state)
144 {
145 case Frame::Started:
146 emit started();
147 break;
148 case Frame::Canceled:
149 emit canceled(TQString());
150 break;
151 case Frame::Idle:
152 case Frame::Completed:
153 default:
154 emit completed();
155 }}
156
157
158
159const TQString& Frame::title() const
160{
161 return m_title;
162}
163
164const TQString& Frame::caption() const
165{
166 return m_caption;
167}
168
169const TQString& Frame::statusText() const
170{
171 return m_statusText;
172}
173
174void Frame::setStarted()
175{
176 if(m_progressId.isNull() || m_progressId.isEmpty()) m_progressId = KPIM::ProgressManager::getUniqueID();
177 m_progressItem = KPIM::ProgressManager::createProgressItem(m_progressId, TQStyleSheet::escape( title() ), TQString(), false);
178 m_progressItem->setStatus(i18n("Loading..."));
179 //connect(m_progressItem, TQ_SIGNAL(progressItemCanceled(KPIM::ProgressItem*)), TQ_SLOT(slotAbortFetch()));
180 m_state=Started;
181 emit started();
182}
183
184void Frame::setCanceled(const TQString &s)
185{
186 if(m_progressItem) {
187 m_progressItem->setStatus(i18n("Loading canceled"));
188 m_progressItem->setComplete();
189 m_progressItem = 0;
190 }
191 m_state=Canceled;
192 emit canceled(s);
193}
194
195void Frame::setCompleted()
196{
197 if(m_progressItem) {
198 m_progressItem->setStatus(i18n("Loading completed"));
199 m_progressItem->setComplete();
200 m_progressItem = 0;
201 }
202 m_state=Completed;
203 emit completed();
204}
205
206int Frame::progress() const
207{
208 return m_progress;
209}
210
211} // namespace Akregator
212
213#include "frame.moc"