akregator/src/librss

testlibrss.cpp
1#include "testlibrss.h"
2
3#include "image.h"
4
5#include <tdeaboutdata.h>
6#include <tdecmdlineargs.h>
7#include <tdeapplication.h>
8#include <kdebug.h>
9
10using namespace RSS;
11
12static const TDECmdLineOptions options[] =
13{
14 { "+url", I18N_NOOP("URL of feed"), 0 },
15 TDECmdLineLastOption
16};
17
18
19void Tester::test( const TQString &url )
20{
21 Loader *loader = Loader::create();
22 connect( loader, TQ_SIGNAL( loadingComplete( Loader *, Document, Status ) ),
23 this, TQ_SLOT( slotLoadingComplete( Loader *, Document, Status ) ) );
24 loader->loadFrom( url, new FileRetriever );
25}
26
27void Tester::slotLoadingComplete( Loader *loader, Document doc, Status status )
28{
29 if ( status == Success )
30 {
31 kdDebug() << "Successfully retrieved '" << doc.title() << "'" << endl;
32 kdDebug() << doc.description() << endl;
33
34 if ( doc.image() ) {
35 kdDebug() << "Image: ";
36 kdDebug() << " Title: " << doc.image()->title() << endl;
37 kdDebug() << " URL: " << doc.image()->url() << endl;
38 kdDebug() << " Link: " << doc.image()->link() << endl;
39 }
40
41 kdDebug() << "Articles:" << endl;
42
43 Article::List list = doc.articles();
44 Article::List::ConstIterator it;
45 Article::List::ConstIterator en=list.end();
46 for (it = list.begin(); it != en; ++it)
47 {
48 kdDebug() << "\tTitle: " << (*it).title() << endl;
49 kdDebug() << "\tText: " << (*it).description() << endl;
50 }
51 }
52
53 if ( status != Success )
54 kdDebug() << "ERROR " << loader->errorCode() << endl;
55
56 tdeApp->quit();
57}
58
59int main( int argc, char **argv )
60{
61 TDEAboutData aboutData( "testlibrss", "testlibrss", "0.1" );
62 TDECmdLineArgs::init( argc, argv, &aboutData );
63 TDECmdLineArgs::addCmdLineOptions( options );
64 TDEApplication app;
65
66 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
67 if ( args->count() != 1 ) args->usage();
68
69 Tester tester;
70 tester.test( args->arg( 0 ) );
71
72 return app.exec();
73}
74
75#include "testlibrss.moc"
TQValueList< Article > List
A list of articles.
Definition: article.h:43
Represents a RSS document and provides all the features and properties as stored in it.
Definition: document.h:32
Image * image()
RSS 0.90 and upwards.
Definition: document.cpp:562
TQString description() const
RSS 0.90 and upwards.
Definition: document.cpp:552
TQString title() const
RSS 0.90 and upwards.
Definition: document.cpp:547
const Article::List & articles() const
RSS 0.90 and upwards.
Definition: document.cpp:582
Implements a file retriever, to be used with Loader::loadFrom().
Definition: loader.h:91
TQString title() const
RSS 0.90 and upwards.
Definition: image.cpp:75
const KURL & link() const
RSS 0.90 and upwards.
Definition: image.cpp:85
const KURL & url() const
RSS 0.90 and upwards.
Definition: image.cpp:80
This class is the preferred way of loading RSS files.
Definition: loader.h:258
int errorCode() const
Retrieves the error code of the last loading process (if any), as reported by the employed data retre...
Definition: loader.cpp:299
void loadFrom(const KURL &url, DataRetriever *retriever)
Loads the RSS file referenced by the given URL using the specified retrieval algorithm.
Definition: loader.cpp:285