From e38d2351b83fa65c66ccde443777647ef5cb6cff Mon Sep 17 00:00:00 2001 From: tpearson Date: Mon, 1 Mar 2010 19:17:32 +0000 Subject: Added KDE3 version of Tellico git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- src/newstuff/providerloader.cpp | 102 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 src/newstuff/providerloader.cpp (limited to 'src/newstuff/providerloader.cpp') diff --git a/src/newstuff/providerloader.cpp b/src/newstuff/providerloader.cpp new file mode 100644 index 0000000..b3f95ae --- /dev/null +++ b/src/newstuff/providerloader.cpp @@ -0,0 +1,102 @@ +/*************************************************************************** + copyright : (C) 2006 by Robby Stephenson + email : robby@periapsis.org + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License as * + * published by the Free Software Foundation; * + * * + ***************************************************************************/ + +// this class is largely copied from kdelibs/knewstuff/provider.cpp +// which is Copyright (c) 2002 Cornelius Schumacher +// and licensed under GPL v2, just like Tellico + +#include "providerloader.h" +#include "../tellico_debug.h" +#include "../latin1literal.h" + +#include +#include +#include +#include +#include +#include + +#include + +using Tellico::NewStuff::ProviderLoader; + +ProviderLoader::ProviderLoader( QWidget *parentWidget ) : + mParentWidget( parentWidget ), mTryAlt(true) +{ + mProviders.setAutoDelete( true ); +} + +void ProviderLoader::load( const QString &type, const QString &providersList ) +{ + mProviders.clear(); + mJobData.truncate(0); + +// myLog() << "ProviderLoader::load(): providersList: " << providersList << endl; + + KIO::TransferJob *job = KIO::get( KURL( providersList ), false, false ); + connect( job, SIGNAL( result( KIO::Job * ) ), + SLOT( slotJobResult( KIO::Job * ) ) ); + connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ), + SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) ); + connect( job, SIGNAL( percent (KIO::Job *, unsigned long) ), + SIGNAL( percent (KIO::Job *, unsigned long) ) ); + +// job->dumpObjectInfo(); +} + +void ProviderLoader::slotJobData( KIO::Job *, const QByteArray &data ) +{ + if ( data.size() == 0 ) return; + QCString str( data, data.size() + 1 ); + mJobData.append( QString::fromUtf8( str ) ); +} + +void ProviderLoader::slotJobResult( KIO::Job *job ) +{ + if ( job->error() ) { + job->showErrorDialog( mParentWidget ); + if(mTryAlt && !mAltProvider.isEmpty()) { + mTryAlt = false; + load(QString(), mAltProvider); + } else { + emit error(); + } + return; + } + + QDomDocument doc; + if ( !doc.setContent( mJobData ) ) { + myDebug() << "ProviderLoader::slotJobResult() - error parsing providers list." << endl; + if(mTryAlt && !mAltProvider.isEmpty()) { + mTryAlt = false; + load(QString(), mAltProvider); + } else { + emit error(); + } + return; + } + + QDomElement providers = doc.documentElement(); + QDomNode n; + for ( n = providers.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement p = n.toElement(); + + if ( p.tagName() == Latin1Literal("provider") ) { + mProviders.append( new KNS::Provider( p ) ); + } + } + + emit providersLoaded( &mProviders ); +} + +#include "providerloader.moc" -- cgit v1.2.1