[Marble-commits] KDE/kdeedu/marble/src/lib
Jens-Michael Hoffmann
jensmh at gmx.de
Thu Oct 1 12:52:58 CEST 2009
SVN commit 1029990 by jmhoffmann:
HttpDownloadManager d-pointerfied.
M +72 -36 HttpDownloadManager.cpp
M +4 -24 HttpDownloadManager.h
--- trunk/KDE/kdeedu/marble/src/lib/HttpDownloadManager.cpp #1029989:1029990
@@ -13,8 +13,12 @@
#include "HttpDownloadManager.h"
#include <QtCore/QDebug>
+#include <QtCore/QList>
+#include <QtCore/QMap>
#include <QtCore/QTimer>
+#include "DownloadPolicy.h"
+#include "DownloadQueueSet.h"
#include "HttpJob.h"
#include "StoragePolicy.h"
#include "NetworkPlugin.h"
@@ -25,18 +29,51 @@
// Time before a failed download job is requeued in ms
const quint32 requeueTime = 60000;
-HttpDownloadManager::HttpDownloadManager( const QUrl& serverUrl,
- StoragePolicy *policy )
+class HttpDownloadManager::Private
+{
+ public:
+ Private( const QUrl& serverUrl, StoragePolicy *policy );
+ ~Private();
+
+ bool m_downloadEnabled;
+ QTimer *m_requeueTimer;
+ /**
+ * Contains per download policy a queue set containing of
+ * - a queue where jobs are waiting for being activated (=dowloaded)
+ * - a queue containing currently being dowloaded
+ * - a queue for retries of failed downloads */
+ QMap<DownloadPolicyKey, DownloadQueueSet *> m_queueSets;
+ int m_jobQueueLimit;
+ QUrl m_serverUrl;
+ StoragePolicy *m_storagePolicy;
+ NetworkPlugin *m_networkPlugin;
+};
+
+HttpDownloadManager::Private::Private( const QUrl& serverUrl, StoragePolicy *policy )
: m_downloadEnabled( true ), //enabled for now
+ m_requeueTimer( 0 ),
m_jobQueueLimit( 1000 ),
m_serverUrl( serverUrl ),
m_storagePolicy( policy ),
m_networkPlugin( 0 )
{
- m_requeueTimer = new QTimer( this );
- m_requeueTimer->setInterval( requeueTime );
- connect( m_requeueTimer, SIGNAL( timeout() ), this, SLOT( requeue() ) );
+}
+HttpDownloadManager::Private::~Private()
+{
+ delete m_storagePolicy;
+ delete m_networkPlugin;
+}
+
+
+HttpDownloadManager::HttpDownloadManager( const QUrl& serverUrl,
+ StoragePolicy *policy )
+ : d( new Private( serverUrl, policy ))
+{
+ d->m_requeueTimer = new QTimer( this );
+ d->m_requeueTimer->setInterval( requeueTime );
+ connect( d->m_requeueTimer, SIGNAL( timeout() ), this, SLOT( requeue() ) );
+
// default download policy
DownloadPolicy defaultDownloadPolicy;
defaultDownloadPolicy.setMaximumConnections( 20 );
@@ -46,19 +83,18 @@
HttpDownloadManager::~HttpDownloadManager()
{
- m_downloadEnabled = false;
- delete m_storagePolicy;
- delete m_networkPlugin;
+ d->m_downloadEnabled = false;
+ delete d;
}
void HttpDownloadManager::setServerUrl( const QUrl& serverUrl )
{
- m_serverUrl = serverUrl;
+ d->m_serverUrl = serverUrl;
}
void HttpDownloadManager::setJobQueueLimit( int jobQueueLimit )
{
- m_jobQueueLimit = jobQueueLimit;
+ d->m_jobQueueLimit = jobQueueLimit;
}
// FIXME: remove this method
@@ -68,7 +104,7 @@
void HttpDownloadManager::setDownloadEnabled( const bool enable )
{
- m_downloadEnabled = enable;
+ d->m_downloadEnabled = enable;
}
void HttpDownloadManager::addDownloadPolicy( const DownloadPolicy& policy )
@@ -82,17 +118,17 @@
// relay jobAdded/jobRemoved signals (interesting for progress bar)
connect( queueSet, SIGNAL( jobAdded() ), SIGNAL( jobAdded() ));
connect( queueSet, SIGNAL( jobRemoved() ), SIGNAL( jobRemoved() ));
- m_queueSets.insert( queueSet->downloadPolicy().key(), queueSet );
+ d->m_queueSets.insert( queueSet->downloadPolicy().key(), queueSet );
}
StoragePolicy* HttpDownloadManager::storagePolicy() const
{
- return m_storagePolicy;
+ return d->m_storagePolicy;
}
void HttpDownloadManager::addJob( const QString& relativeUrlString, const QString &id )
{
- QUrl sourceUrl( m_serverUrl );
+ QUrl sourceUrl( d->m_serverUrl );
QString path = sourceUrl.path();
sourceUrl.setPath( path + relativeUrlString );
addJob( sourceUrl, relativeUrlString, id );
@@ -101,7 +137,7 @@
void HttpDownloadManager::addJob( const QUrl& sourceUrl, const QString& destFileName,
const QString &id )
{
- if ( !m_downloadEnabled )
+ if ( !d->m_downloadEnabled )
return;
DownloadQueueSet * const queueSet = findQueues( sourceUrl.host() );
@@ -118,8 +154,8 @@
{
qDebug() << "emitting downloadComplete( QByteArray, " << id << ")";
emit downloadComplete( data, id );
- if ( m_storagePolicy ) {
- const bool saved = m_storagePolicy->updateFile( destinationFileName, data );
+ if ( d->m_storagePolicy ) {
+ const bool saved = d->m_storagePolicy->updateFile( destinationFileName, data );
if ( saved ) {
qDebug() << "emitting downloadComplete( " << destinationFileName << ", " << id << ")";
emit downloadComplete( destinationFileName, id );
@@ -131,10 +167,10 @@
void HttpDownloadManager::requeue()
{
- m_requeueTimer->stop();
+ d->m_requeueTimer->stop();
- QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator pos = m_queueSets.begin();
- QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator const end = m_queueSets.end();
+ QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator pos = d->m_queueSets.begin();
+ QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator const end = d->m_queueSets.end();
for (; pos != end; ++pos ) {
pos.value()->retryJobs();
}
@@ -142,37 +178,37 @@
void HttpDownloadManager::startRetryTimer()
{
- if ( !m_requeueTimer->isActive() )
- m_requeueTimer->start();
+ if ( !d->m_requeueTimer->isActive() )
+ d->m_requeueTimer->start();
}
HttpJob *HttpDownloadManager::createJob( const QUrl& sourceUrl, const QString& destFileName,
const QString &id )
{
- if ( !m_networkPlugin ) {
+ if ( !d->m_networkPlugin ) {
PluginManager pluginManager;
QList<NetworkPlugin *> networkPlugins = pluginManager.createNetworkPlugins();
if ( !networkPlugins.isEmpty() ) {
// FIXME: not just take the first plugin, but use some configuration setting
// take the first plugin and delete the rest
- m_networkPlugin = networkPlugins.takeFirst();
+ d->m_networkPlugin = networkPlugins.takeFirst();
qDeleteAll( networkPlugins );
- m_networkPlugin->setParent( this );
+ d->m_networkPlugin->setParent( this );
}
else {
- m_downloadEnabled = false;
+ d->m_downloadEnabled = false;
return 0;
}
}
- Q_ASSERT( m_networkPlugin );
- return m_networkPlugin->createJob( sourceUrl, destFileName, id );
+ Q_ASSERT( d->m_networkPlugin );
+ return d->m_networkPlugin->createJob( sourceUrl, destFileName, id );
}
DownloadQueueSet const * HttpDownloadManager::findQueues( const QString& hostName ) const
{
DownloadQueueSet const * result = 0;
- QMap<DownloadPolicyKey, DownloadQueueSet*>::const_iterator pos = m_queueSets.constBegin();
- QMap<DownloadPolicyKey, DownloadQueueSet*>::const_iterator const end = m_queueSets.constEnd();
+ QMap<DownloadPolicyKey, DownloadQueueSet*>::const_iterator pos = d->m_queueSets.constBegin();
+ QMap<DownloadPolicyKey, DownloadQueueSet*>::const_iterator const end = d->m_queueSets.constEnd();
for (; pos != end; ++pos ) {
if ( pos.key().matches( hostName )) {
result = pos.value();
@@ -181,8 +217,8 @@
}
// FIXME:
if ( !result ) {
- Q_ASSERT( !m_queueSets.isEmpty() );
- result = m_queueSets.constBegin().value();
+ Q_ASSERT( !d->m_queueSets.isEmpty() );
+ result = d->m_queueSets.constBegin().value();
}
return result;
}
@@ -190,8 +226,8 @@
DownloadQueueSet *HttpDownloadManager::findQueues( const QString& hostName )
{
DownloadQueueSet * result = 0;
- QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator pos = m_queueSets.begin();
- QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator const end = m_queueSets.end();
+ QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator pos = d->m_queueSets.begin();
+ QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator const end = d->m_queueSets.end();
for (; pos != end; ++pos ) {
if ( pos.key().matches( hostName )) {
result = pos.value();
@@ -200,8 +236,8 @@
}
// FIXME:
if ( !result ) {
- Q_ASSERT( !m_queueSets.isEmpty() );
- result = m_queueSets.begin().value();
+ Q_ASSERT( !d->m_queueSets.isEmpty() );
+ result = d->m_queueSets.begin().value();
}
return result;
}
--- trunk/KDE/kdeedu/marble/src/lib/HttpDownloadManager.h #1029989:1029990
@@ -19,13 +19,8 @@
#define MARBLE_HTTPDOWNLOADMANAGER_H
-#include <QtCore/QMap>
#include <QtCore/QString>
#include <QtCore/QUrl>
-#include <QtCore/QList>
-#include <QtCore/QSet>
-#include <QtCore/QStack>
-#include <QtCore/QQueue>
#include "DownloadPolicy.h"
#include "DownloadQueueSet.h"
@@ -37,9 +32,10 @@
namespace Marble
{
+class DownloadPolicy;
+class DownloadQueueSet;
class HttpJob;
class StoragePolicy;
-class NetworkPlugin;
/**
* @Short This class manages scheduled downloads.
@@ -140,24 +136,8 @@
DownloadQueueSet *findQueues( const QString& hostName );
DownloadQueueSet const *findQueues( const QString& hostName ) const;
- bool m_downloadEnabled;
-
- QTimer *m_requeueTimer;
-
- /**
- * Contains per download policy a queue set containing of
- * - a queue where jobs are waiting for being activated (=downloaded)
- * - a queue containing currently being downloaded
- * - a queue for retries of failed downloads
- */
- QMap<DownloadPolicyKey, DownloadQueueSet *> m_queueSets;
-
- int m_jobQueueLimit;
-
- QUrl m_serverUrl;
- StoragePolicy *m_storagePolicy;
-
- NetworkPlugin *m_networkPlugin;
+ class Private;
+ Private * const d;
};
}
More information about the Marble-commits
mailing list