Commit ee8b1377 authored by Bernhard Beschow's avatar Bernhard Beschow
Browse files

remove network plugin infrastructure -> always use QNetworkAccessManager

The network plugin infrastructure represents a network abstraction layer.
However, Marble uses QNetworkAccessManager in a number of places directly, e.g. in the GHNS dialogs and in all the runners.
Given that QNetworkAccessManager also represents a network abstraction layer, Marble's own network plugin infrastructure shouldn't be neccessary.

REVIEW: 107919
parent 5d45030c
......@@ -139,11 +139,6 @@ void AbstractDataPlugin::setModel( AbstractDataPluginModel* model )
emit favoritesModelChanged();
}
const PluginManager* AbstractDataPlugin::pluginManager() const
{
return marbleModel()->pluginManager();
}
quint32 AbstractDataPlugin::numberOfItems() const
{
return d->m_numberOfItems;
......
......@@ -26,7 +26,6 @@ class GeoSceneLayer;
class AbstractDataPluginItem;
class AbstractDataPluginModel;
class AbstractDataPluginPrivate;
class PluginManager;
/**
* @short An abstract class for plugins that show data that has a geo coordinate
......@@ -85,8 +84,6 @@ class MARBLE_EXPORT AbstractDataPlugin : public RenderPlugin
* Set the model of the plugin.
*/
void setModel( AbstractDataPluginModel* model );
const PluginManager *pluginManager() const;
/**
* Set the number of items to be shown at the same time.
......
......@@ -56,7 +56,6 @@ class AbstractDataPluginModelPrivate
{
public:
AbstractDataPluginModelPrivate( const QString& name,
const PluginManager *pluginManager,
AbstractDataPluginModel * parent );
~AbstractDataPluginModelPrivate();
......@@ -103,7 +102,6 @@ public:
};
AbstractDataPluginModelPrivate::AbstractDataPluginModelPrivate( const QString& name,
const PluginManager *pluginManager,
AbstractDataPluginModel * parent )
: m_parent( parent ),
m_name( name ),
......@@ -117,7 +115,7 @@ AbstractDataPluginModelPrivate::AbstractDataPluginModelPrivate( const QString& n
m_itemSettings(),
m_favoriteItemsOnly( false ),
m_storagePolicy( MarbleDirs::localPath() + "/cache/" + m_name + '/' ),
m_downloadManager( &m_storagePolicy, pluginManager ),
m_downloadManager( &m_storagePolicy ),
m_favoritesModel( 0 ),
m_hasMetaObject( false ),
m_needsSorting( false )
......@@ -225,11 +223,9 @@ void FavoritesModel::reset()
QAbstractListModel::reset();
}
AbstractDataPluginModel::AbstractDataPluginModel( const QString& name,
const PluginManager *pluginManager,
QObject *parent )
AbstractDataPluginModel::AbstractDataPluginModel( const QString& name, QObject *parent )
: QObject( parent ),
d( new AbstractDataPluginModelPrivate( name, pluginManager, this ) )
d( new AbstractDataPluginModelPrivate( name, this ) )
{
// Initializing file and download System
connect( &d->m_downloadManager, SIGNAL( downloadComplete( QString, QString ) ),
......
......@@ -30,7 +30,6 @@ class AbstractDataPluginModelPrivate;
class AbstractDataPluginItem;
class GeoDataLatLonAltBox;
class MarbleModel;
class PluginManager;
class ViewportParams;
/**
......@@ -51,9 +50,7 @@ class MARBLE_EXPORT AbstractDataPluginModel : public QObject
Q_PROPERTY( QObject* favoritesModel READ favoritesModel CONSTANT )
public:
explicit AbstractDataPluginModel( const QString& name,
const PluginManager *pluginManager,
QObject *parent = 0 );
explicit AbstractDataPluginModel( const QString& name, QObject *parent = 0 );
virtual ~AbstractDataPluginModel();
/**
......
......@@ -97,7 +97,6 @@ set(marblewidget_SRCS
GeoPolygon.cpp
HttpDownloadManager.cpp
HttpJob.cpp
NetworkPlugin.cpp
LayerManager.cpp
PluginManager.cpp
MarbleCacheSettingsWidget.cpp
......@@ -158,7 +157,6 @@ set(marblewidget_SRCS
AbstractWorkerThread.cpp
PluginInterface.cpp
NetworkPluginInterface.cpp
DialogConfigurationInterface.cpp
LayerInterface.cpp
RenderPlugin.cpp
......
......@@ -15,14 +15,13 @@
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QTimer>
#include <QtNetwork/QNetworkAccessManager>
#include "DownloadPolicy.h"
#include "DownloadQueueSet.h"
#include "HttpJob.h"
#include "MarbleDebug.h"
#include "StoragePolicy.h"
#include "NetworkPlugin.h"
#include "PluginManager.h"
using namespace Marble;
......@@ -32,8 +31,7 @@ const quint32 requeueTime = 60000;
class HttpDownloadManager::Private
{
public:
explicit Private( StoragePolicy *policy,
const PluginManager *pluginManager );
explicit Private( StoragePolicy *policy );
~Private();
HttpJob *createJob( const QUrl& sourceUrl, const QString& destFileName,
......@@ -50,18 +48,15 @@ class HttpDownloadManager::Private
QList<QPair<DownloadPolicyKey, DownloadQueueSet *> > m_queueSets;
QMap<DownloadUsage, DownloadQueueSet *> m_defaultQueueSets;
StoragePolicy *const m_storagePolicy;
const PluginManager *const m_pluginManager;
NetworkPlugin *m_networkPlugin;
QNetworkAccessManager m_networkAccessManager;
};
HttpDownloadManager::Private::Private( StoragePolicy *policy,
const PluginManager *pluginManager )
HttpDownloadManager::Private::Private( StoragePolicy *policy )
: m_downloadEnabled( true ), //enabled for now
m_requeueTimer( 0 ),
m_storagePolicy( policy ),
m_pluginManager( pluginManager ),
m_networkPlugin( 0 )
m_networkAccessManager()
{
// setup default download policy and associated queue set
DownloadPolicy defaultBrowsePolicy;
......@@ -78,27 +73,15 @@ HttpDownloadManager::Private::~Private()
QMap<DownloadUsage, DownloadQueueSet *>::iterator const end = m_defaultQueueSets.end();
for (; pos != end; ++pos )
delete pos.value();
delete m_networkPlugin;
}
HttpJob *HttpDownloadManager::Private::createJob( const QUrl& sourceUrl,
const QString& destFileName,
const QString &id )
{
if ( !m_networkPlugin ) {
QList<const NetworkPlugin *> networkPlugins = m_pluginManager->networkPlugins();
if ( !networkPlugins.isEmpty() ) {
// FIXME: not just take the first plugin, but use some configuration setting
// take the first plugin
m_networkPlugin = networkPlugins.first()->newInstance();
}
else {
m_downloadEnabled = false;
return 0;
}
}
Q_ASSERT( m_networkPlugin );
return m_networkPlugin->createJob( sourceUrl, destFileName, id );
HttpJob * const job = new HttpJob( sourceUrl, destFileName, id, &m_networkAccessManager );
job->setUserAgentPluginId( "QNamNetworkPlugin" );
return job;
}
DownloadQueueSet *HttpDownloadManager::Private::findQueues( const QString& hostName,
......@@ -122,9 +105,8 @@ DownloadQueueSet *HttpDownloadManager::Private::findQueues( const QString& hostN
}
HttpDownloadManager::HttpDownloadManager( StoragePolicy *policy,
const PluginManager *pluginManager )
: d( new Private( policy, pluginManager ))
HttpDownloadManager::HttpDownloadManager( StoragePolicy *policy )
: d( new Private( policy ) )
{
d->m_requeueTimer = new QTimer( this );
d->m_requeueTimer->setInterval( requeueTime );
......
......@@ -29,7 +29,6 @@ namespace Marble
class DownloadPolicy;
class DownloadQueueSet;
class PluginManager;
class StoragePolicy;
/**
......@@ -54,8 +53,7 @@ class MARBLE_EXPORT HttpDownloadManager : public QObject
*
* @param policy The storage policy for this manager.
*/
explicit HttpDownloadManager( StoragePolicy *policy,
const PluginManager *pluginManager );
explicit HttpDownloadManager( StoragePolicy *policy );
/**
* Destroys the http download manager.
......
......@@ -12,16 +12,20 @@
//
#include "HttpJob.h"
#include "MarbleDebug.h"
#include "TinyWebBrowser.h"
#include <QtCore/QDebug>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
using namespace Marble;
class Marble::HttpJobPrivate
{
public:
HttpJobPrivate( const QUrl & sourceUrl, const QString & destFileName, const QString &id );
HttpJobPrivate( const QUrl & sourceUrl, const QString & destFileName,
const QString &id, QNetworkAccessManager *networkAccessManager );
QUrl m_sourceUrl;
QString m_destinationFileName;
......@@ -29,10 +33,12 @@ class Marble::HttpJobPrivate
int m_trialsLeft;
DownloadUsage m_downloadUsage;
QString m_pluginId;
QNetworkAccessManager *const m_networkAccessManager;
QNetworkReply *m_networkReply;
};
HttpJobPrivate::HttpJobPrivate( const QUrl & sourceUrl, const QString & destFileName,
const QString &id )
const QString &id, QNetworkAccessManager *networkAccessManager )
: m_sourceUrl( sourceUrl ),
m_destinationFileName( destFileName ),
m_initiatorId( id ),
......@@ -40,13 +46,15 @@ HttpJobPrivate::HttpJobPrivate( const QUrl & sourceUrl, const QString & destFile
m_downloadUsage( DownloadBrowse ),
// FIXME: remove initialization depending on if empty pluginId
// results in valid user agent string
m_pluginId( "unknown" )
m_pluginId( "unknown" ),
m_networkAccessManager( networkAccessManager ),
m_networkReply( 0 )
{
}
HttpJob::HttpJob( const QUrl & sourceUrl, const QString & destFileName, const QString &id )
: d( new HttpJobPrivate( sourceUrl, destFileName, id ))
HttpJob::HttpJob( const QUrl & sourceUrl, const QString & destFileName, const QString &id, QNetworkAccessManager *networkAccessManager )
: d( new HttpJobPrivate( sourceUrl, destFileName, id, networkAccessManager ) )
{
}
......@@ -126,4 +134,68 @@ QByteArray HttpJob::userAgent() const
}
}
void HttpJob::execute()
{
QNetworkRequest request( d->m_sourceUrl );
request.setAttribute( QNetworkRequest::HttpPipeliningAllowedAttribute, true );
request.setRawHeader( "User-Agent", userAgent() );
d->m_networkReply = d->m_networkAccessManager->get( request );
connect( d->m_networkReply, SIGNAL( downloadProgress( qint64, qint64 )),
SLOT( downloadProgress( qint64, qint64 )));
connect( d->m_networkReply, SIGNAL( error( QNetworkReply::NetworkError )),
SLOT( error( QNetworkReply::NetworkError )));
connect( d->m_networkReply, SIGNAL( finished()),
SLOT( finished()));
}
void HttpJob::downloadProgress( qint64 bytesReceived, qint64 bytesTotal )
{
Q_UNUSED(bytesReceived);
Q_UNUSED(bytesTotal);
// mDebug() << "downloadProgress" << destinationFileName()
// << bytesReceived << '/' << bytesTotal;
}
void HttpJob::error( QNetworkReply::NetworkError code )
{
mDebug() << "error" << destinationFileName() << code;
}
void HttpJob::finished()
{
QNetworkReply::NetworkError const error = d->m_networkReply->error();
// mDebug() << "finished" << destinationFileName()
// << "error" << error;
const QVariant httpPipeliningWasUsed =
d->m_networkReply->attribute( QNetworkRequest::HttpPipeliningWasUsedAttribute );
if ( !httpPipeliningWasUsed.isNull() )
mDebug() << "http pipelining used:" << httpPipeliningWasUsed.toBool();
switch ( error ) {
case QNetworkReply::NoError: {
// check if we are redirected
const QVariant redirectionAttribute =
d->m_networkReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( !redirectionAttribute.isNull() ) {
emit redirected( this, redirectionAttribute.toUrl() );
}
else {
// no redirection occurred
const QByteArray data = d->m_networkReply->readAll();
emit dataReceived( this, data );
}
}
break;
default:
emit jobDone( this, 1 );
}
d->m_networkReply->disconnect( this );
// No delete. This method is called by a signal QNetworkReply::finished.
d->m_networkReply->deleteLater();
d->m_networkReply = 0;
}
#include "HttpJob.moc"
......@@ -18,11 +18,14 @@
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QtNetwork/QNetworkReply>
#include "MarbleGlobal.h"
#include "marble_export.h"
class QNetworkAccessManager;
namespace Marble
{
class HttpJobPrivate;
......@@ -32,7 +35,7 @@ class MARBLE_EXPORT HttpJob: public QObject
Q_OBJECT
public:
HttpJob( const QUrl & sourceUrl, const QString & destFileName, const QString &id );
HttpJob( const QUrl & sourceUrl, const QString & destFileName, const QString &id, QNetworkAccessManager *networkAccessManager );
~HttpJob();
QUrl sourceUrl() const;
......@@ -67,7 +70,12 @@ class MARBLE_EXPORT HttpJob: public QObject
void dataReceived( HttpJob * job, QByteArray data );
public Q_SLOTS:
virtual void execute() = 0;
void execute();
private Q_SLOTS:
void downloadProgress( qint64 bytesReceived, qint64 bytesTotal );
void error( QNetworkReply::NetworkError code );
void finished();
private:
Q_DISABLE_COPY( HttpJob )
......
......@@ -85,7 +85,7 @@ class MarbleModelPrivate
m_homeZoom( 1050 ),
m_mapTheme( 0 ),
m_storagePolicy( MarbleDirs::localPath() ),
m_downloadManager( &m_storagePolicy, &m_pluginManager ),
m_downloadManager( &m_storagePolicy ),
m_storageWatcher( MarbleDirs::localPath() ),
m_fileManager( 0 ),
m_treemodel(),
......
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2008 Pino Toscano <pino@kde.org>
// Copyright 2008 Jens-Michael Hoffmann <jensmh@gmx.de>
//
#include "NetworkPlugin.h"
namespace Marble
{
class NetworkPluginPrivate
{
public:
NetworkPluginPrivate()
{
}
~NetworkPluginPrivate()
{
}
};
// Do not create the NetworkPluginPrivate, because it holds
// no data at the moment (may change in the future).
NetworkPlugin::NetworkPlugin()
: d( 0 )
{
}
NetworkPlugin::~NetworkPlugin()
{
//delete d; //for the future :)
}
}
#include "NetworkPlugin.moc"
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2008 Pino Toscano <pino@kde.org>
// Copyright 2009 Jens-Michael Hoffmann <jensmh@gmx.de>
//
#ifndef MARBLE_NETWORKPLUGIN_H
#define MARBLE_NETWORKPLUGIN_H
#include "NetworkPluginInterface.h"
#include "marble_export.h"
namespace Marble
{
class NetworkPluginPrivate;
/**
* @short The abstract class that handles network operations.
*
*/
class MARBLE_EXPORT NetworkPlugin : public QObject, public NetworkPluginInterface
{
Q_OBJECT
public:
virtual ~NetworkPlugin();
/**
* Create a new Network Plugin and return it.
* Has to be defined in concrete network plugin classes.
*/
virtual NetworkPlugin * newInstance() const = 0;
protected:
NetworkPlugin();
private:
Q_DISABLE_COPY( NetworkPlugin )
NetworkPluginPrivate * const d;
};
}
#endif
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2009 Jens-Michael Hoffmann <jensmh@gmx.de>
//
#include "NetworkPluginInterface.h"
namespace Marble
{
NetworkPluginInterface::~NetworkPluginInterface()
{
}
}
//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2008 Pino Toscano <pino@kde.org>
//
#ifndef MARBLE_NETWORKPLUGININTERFACE_H
#define MARBLE_NETWORKPLUGININTERFACE_H
#include <QtCore/QObject>
#include <QtCore/QString>
#include "PluginInterface.h"
class QUrl;
namespace Marble
{
class HttpJob;
/**
* @short The interface for network operation plugins.
*
*/
class NetworkPluginInterface: public PluginInterface
{
public:
virtual ~NetworkPluginInterface();
/**
* @brief Creates a new HTTP download job.
* @return the new HTTP job
*/
virtual HttpJob *createJob( const QUrl &source, const QString &destination, const QString &id ) = 0;
};
}
Q_DECLARE_INTERFACE( Marble::NetworkPluginInterface, "org.kde.Marble.NetworkPluginInterface/1.01" )
#endif
......@@ -22,7 +22,6 @@
#include "MarbleDirs.h"
#include "MarbleDebug.h"
#include "RenderPlugin.h"
#include "NetworkPlugin.h"
#include "PositionProviderPlugin.h"
#include "AbstractFloatItem.h"
#include "ParseRunnerPlugin.h"
......@@ -47,7 +46,6 @@ class PluginManagerPrivate
bool m_pluginsLoaded;
QList<const RenderPlugin *> m_renderPluginTemplates;
QList<const NetworkPlugin *> m_networkPluginTemplates;
QList<const PositionProviderPlugin *> m_positionProviderPluginTemplates;
QList<const SearchRunnerPlugin *> m_searchRunnerPlugins;
QList<const ReverseGeocodingRunnerPlugin *> m_reverseGeocodingRunnerPlugins;
......@@ -83,19 +81,6 @@ void PluginManager::addRenderPlugin( RenderPlugin *plugin )
emit renderPluginsChanged();
}
QList<const NetworkPlugin *> PluginManager::networkPlugins() const
{
d->loadPlugins();
return d->m_networkPluginTemplates;
}
void PluginManager::addNetworkPlugin( NetworkPlugin *plugin )
{
d->loadPlugins();
d->m_networkPluginTemplates << plugin;
emit networkPluginsChanged();
}
QList<const PositionProviderPlugin *> PluginManager::positionProviderPlugins() const
{
d->loadPlugins();
......@@ -211,7 +196,6 @@ void PluginManagerPrivate::loadPlugins()
MarbleDirs::debug();
Q_ASSERT( m_renderPluginTemplates.isEmpty() );
Q_ASSERT( m_networkPluginTemplates.isEmpty() );
Q_ASSERT( m_positionProviderPluginTemplates.isEmpty() );
Q_ASSERT( m_searchRunnerPlugins.isEmpty() );
Q_ASSERT( m_reverseGeocodingRunnerPlugins.isEmpty() );
......@@ -228,8 +212,6 @@ void PluginManagerPrivate::loadPlugins()
if ( obj ) {
bool isPlugin = appendPlugin<RenderPlugin, RenderPluginInterface>
( obj, loader, m_renderPluginTemplates );
isPlugin = isPlugin || appendPlugin<NetworkPlugin, NetworkPluginInterface>
( obj, loader, m_networkPluginTemplates );
isPlugin = isPlugin || appendPlugin<PositionProviderPlugin, PositionProviderPluginInterface>
( obj, loader, m_positionProviderPluginTemplates );
isPlugin = isPlugin || appendPlugin<SearchRunnerPlugin, SearchRunnerPlugin>
......
......@@ -21,7 +21,6 @@ namespace Marble
{
class RenderPlugin;
class NetworkPlugin;
class PositionProviderPlugin;
class AbstractFloatItem;
class PluginManagerPrivate;
......@@ -68,22 +67,6 @@ class MARBLE_EXPORT PluginManager : public QObject
*/
void addRenderPlugin( RenderPlugin * plugin );
/**
* @brief Returns all available NetworkPlugins.
*
* Ownership of the items remains in PluginManager.
* In order to use the NetworkPlugins, first create new instances using