summaryrefslogtreecommitdiffstats
path: root/plugins/rssfeed/rss/testlibrss.cpp
blob: bef989c68c16bb39c121f4aaf6299ac9e8737f2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "testlibrss.h"

#include "image.h"

#include <tdeaboutdata.h>
#include <tdecmdlineargs.h>
#include <tdeapplication.h>
#include <kdebug.h>

using namespace RSS;

static const TDECmdLineOptions options[] =
{
  { "+url", I18N_NOOP("URL of feed"), 0 },
  TDECmdLineLastOption
};


void Tester::test( const TQString &url )
{
	Loader *loader = Loader::create();
	connect( loader, TQT_SIGNAL( loadingComplete( Loader *, Document, Status ) ),
	         this, TQT_SLOT( slotLoadingComplete( Loader *, Document, Status ) ) );
	loader->loadFrom( url, new FileRetriever );
}

void Tester::slotLoadingComplete( Loader *loader, Document doc, Status status )
{
	if ( status == Success )
	{
		kdDebug() << "Successfully retrieved '" << doc.title() << "'" << endl;
		kdDebug() << doc.description() << endl;

                if ( doc.image() ) {
                      kdDebug() << "Image: ";
                      kdDebug() << "  Title: " << doc.image()->title() << endl;
                      kdDebug() << "  URL: " << doc.image()->url() << endl;
                      kdDebug() << "  Link: " << doc.image()->link() << endl;
                }
		
		kdDebug() << "Articles:" << endl;

		Article::List list = doc.articles();
		Article::List::ConstIterator it;
		Article::List::ConstIterator en=list.end();
		for (it = list.begin(); it != en; ++it)
		{
		    kdDebug() << "\tTitle: " << (*it).title() << endl;
		    kdDebug() << "\tText:  " << (*it).description() << endl;
		}
	}

	if ( status != Success )
		kdDebug() << "ERROR " << loader->errorCode() << endl;

	kapp->quit();
}

int main( int argc, char **argv )
{
	TDEAboutData aboutData( "testlibrss", "testlibrss", "0.1" );
	TDECmdLineArgs::init( argc, argv, &aboutData );
    TDECmdLineArgs::addCmdLineOptions( options );
	TDEApplication app;

        TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
        if ( args->count() != 1 ) args->usage();

	Tester tester;
	tester.test( args->arg( 0 ) );

	return app.exec();
}

#include "testlibrss.moc"