akregator/src/librss

testlibrss.cpp

00001 #include "testlibrss.h"
00002 
00003 #include "image.h"
00004 
00005 #include <kaboutdata.h>
00006 #include <kcmdlineargs.h>
00007 #include <kapplication.h>
00008 #include <kdebug.h>
00009 
00010 using namespace RSS;
00011 
00012 static const KCmdLineOptions options[] =
00013 {
00014   { "+url", I18N_NOOP("URL of feed"), 0 },
00015   KCmdLineLastOption
00016 };
00017 
00018 
00019 void Tester::test( const QString &url )
00020 {
00021     Loader *loader = Loader::create();
00022     connect( loader, SIGNAL( loadingComplete( Loader *, Document, Status ) ),
00023              this, SLOT( slotLoadingComplete( Loader *, Document, Status ) ) );
00024     loader->loadFrom( url, new FileRetriever );
00025 }
00026 
00027 void Tester::slotLoadingComplete( Loader *loader, Document doc, Status status )
00028 {
00029     if ( status == Success )
00030     {
00031         kdDebug() << "Successfully retrieved '" << doc.title() << "'" << endl;
00032         kdDebug() << doc.description() << endl;
00033 
00034                 if ( doc.image() ) {
00035                       kdDebug() << "Image: ";
00036                       kdDebug() << "  Title: " << doc.image()->title() << endl;
00037                       kdDebug() << "  URL: " << doc.image()->url() << endl;
00038                       kdDebug() << "  Link: " << doc.image()->link() << endl;
00039                 }
00040         
00041         kdDebug() << "Articles:" << endl;
00042 
00043         Article::List list = doc.articles();
00044         Article::List::ConstIterator it;
00045         Article::List::ConstIterator en=list.end();
00046         for (it = list.begin(); it != en; ++it)
00047         {
00048             kdDebug() << "\tTitle: " << (*it).title() << endl;
00049             kdDebug() << "\tText:  " << (*it).description() << endl;
00050         }
00051     }
00052 
00053     if ( status != Success )
00054         kdDebug() << "ERROR " << loader->errorCode() << endl;
00055 
00056     kapp->quit();
00057 }
00058 
00059 int main( int argc, char **argv )
00060 {
00061     KAboutData aboutData( "testlibrss", "testlibrss", "0.1" );
00062     KCmdLineArgs::init( argc, argv, &aboutData );
00063     KCmdLineArgs::addCmdLineOptions( options );
00064     KApplication app;
00065 
00066         KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
00067         if ( args->count() != 1 ) args->usage();
00068 
00069     Tester tester;
00070     tester.test( args->arg( 0 ) );
00071 
00072     return app.exec();
00073 }
00074 
00075 #include "testlibrss.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys