2 /***************************************************************************
3 document.cpp - A DCOP Service to provide RSS data
5 begin : Saturday 15 February 2003
6 copyright : (C) 2003 by Ian Reinhart Geiser
7 email : geiseri@kde.org
8 ***************************************************************************/
10 /***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 ***************************************************************************/
19 #include <qdatetime.h>
25 RSSDocument::RSSDocument(const QString
& url
) :
26 QObject(), DCOPObject(), m_Url(url
)
33 m_Timeout
= QDateTime::currentDateTime();
37 RSSDocument::~RSSDocument()
41 kDebug() << "Document going away..." << endl
;
46 void RSSDocument::loadingComplete(Loader
*ldr
, Document doc
, Status stat
)
56 if (stat
!= RSS::Success
)
58 kDebug() << "Document error! Loader:" << ldr
->errorCode() << " Parser:" << stat
<< endl
;
62 if( stat
== RSS::ParseError
)
63 documentUpdateError(DCOPRef(this), 1);
64 else if( stat
== RSS::RetrieveError
)
65 documentUpdateError(DCOPRef(this), 2);
67 documentUpdateError(DCOPRef(this), 3);
71 kDebug() << "New Document is done..." << endl
;
72 m_Doc
= new Document(doc
);
74 Article::List list
= doc
.articles();
75 for(Article::List::ConstIterator it
= list
.begin(); it
!= list
.end(); ++it
)
77 int state
= m_state
[(*it
).title()];
78 if( state
== 0 ) m_state
[(*it
).title()] = 1; // new
79 else if( state
== 1 ) m_state
[(*it
).title()] = 2; // old message now
80 m_list
.append( new RSSArticle( new Article(*it
)));
82 Image
*img
= m_Doc
->image();
85 connect(img
, SIGNAL(gotPixmap(const QPixmap
&)),
86 SLOT(pixmapLoaded(const QPixmap
&)));
88 pixmapUpdating(DCOPRef(this));
91 documentUpdated(DCOPRef(this));
93 kDebug() << "Old Mod time " << m_Timeout
.toString() << endl
;
94 m_Timeout
= m_Timeout
.addSecs(m_maxAge
* 60 );
95 kDebug() << "New Mod time " << m_Timeout
.toString() << endl
;
100 void RSSDocument::pixmapLoaded(const QPixmap
&pix
)
103 pixmapUpdated(DCOPRef(this));
106 QString
RSSDocument::webMaster()
109 return m_Doc
->webMaster();
114 QString
RSSDocument::managingEditor()
117 return m_Doc
->managingEditor();
122 QString
RSSDocument::rating()
125 return m_Doc
->rating();
130 QDateTime
RSSDocument::lastBuildDate()
133 return m_Doc
->lastBuildDate();
135 return QDateTime::currentDateTime();
138 QDateTime
RSSDocument::pubDate()
141 return m_Doc
->pubDate();
143 return QDateTime::currentDateTime();
146 QString
RSSDocument::copyright()
149 return m_Doc
->copyright();
154 QStringList
RSSDocument::articles()
158 kDebug() << "Document giving articles..." << endl
;
159 Article::List list
= m_Doc
->articles();
160 QStringList stringList
;
162 for(Article::List::ConstIterator it
= list
.begin(); it
!= list
.end(); ++it
)
163 stringList
.append((*it
).title());
167 return QStringList();
170 DCOPRef
RSSDocument::article(int idx
)
173 return DCOPRef(m_list
.at(idx
));
178 int RSSDocument::count()
181 return m_Doc
->articles().count();
185 QString
RSSDocument::link()
188 return m_Doc
->link().prettyUrl();
193 QString
RSSDocument::description()
196 return m_Doc
->description();
201 QString
RSSDocument::title()
204 return m_Doc
->title();
209 QString
RSSDocument::verbVersion()
212 return m_Doc
->verbVersion();
217 QString
RSSDocument::pixmapURL()
221 return m_Doc
->image()->url().prettyUrl();
228 QPixmap
RSSDocument::pixmap()
233 bool RSSDocument::documentValid()
241 bool RSSDocument::pixmapValid()
243 return !m_pix
.isNull();
246 void RSSDocument::refresh()
248 kDebug() << "Mod time " << m_Timeout
.toString() << endl
;
249 kDebug() << "Current time " << QDateTime::currentDateTime().toString() << endl
;
251 if(!m_isLoading
&& (QDateTime::currentDateTime() >= m_Timeout
))
253 kDebug() << "Document going to refresh" << endl
;
255 Loader
*loader
= Loader::create(this,
256 SLOT(loadingComplete(Loader
*, Document
, Status
)));
257 loader
->loadFrom(KUrl( m_Url
), new FileRetriever());
258 documentUpdating(DCOPRef(this));
262 documentUpdated(DCOPRef(this));
264 pixmapUpdated(DCOPRef(this));
269 Image *img = m_Doc->image();
272 connect(img, SIGNAL(gotPixmap(const QPixmap &)),
273 SLOT(pixmapLoaded(const QPixmap &)));
275 pixmapUpdating(DCOPRef(this));
283 int RSSDocument::maxAge()
288 void RSSDocument::setMaxAge(int _min
)
290 m_Timeout
.addSecs(-m_maxAge
);
292 m_Timeout
.addSecs(m_maxAge
);
295 int RSSDocument::state( const QString
&title
) const
297 return m_state
[title
];
300 void RSSDocument::setState( const QString
&title
, int s
)
305 void RSSDocument::read( const QString
&title
)
310 #include "service.moc"