summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Nienhüser <[email protected]>2015-07-19 08:30:09 +0200
committerDennis Nienhüser <[email protected]>2015-07-19 08:30:09 +0200
commitf1118159fa047d9c01da44cd3d41efa471feba67 (patch)
treebe931137d09e3297fae26ecf31a8b0da5945f32d
parent53375610b50c74a6c18353ff50f437f492bdebac (diff)
Move private methods to private class
-rw-r--r--src/lib/marble/HttpDownloadManager.cpp73
-rw-r--r--src/lib/marble/HttpDownloadManager.h13
2 files changed, 45 insertions, 41 deletions
diff --git a/src/lib/marble/HttpDownloadManager.cpp b/src/lib/marble/HttpDownloadManager.cpp
index adddef7..23fe302 100644
--- a/src/lib/marble/HttpDownloadManager.cpp
+++ b/src/lib/marble/HttpDownloadManager.cpp
@@ -31,11 +31,19 @@ const quint32 requeueTime = 60000;
class HttpDownloadManager::Private
{
public:
- explicit Private( StoragePolicy *policy );
+ Private( HttpDownloadManager* parent, StoragePolicy *policy );
~Private();
+ void connectDefaultQueueSets();
+ void connectQueueSet( DownloadQueueSet * );
+ bool hasDownloadPolicy( const DownloadPolicy& policy ) const;
+ void finishJob( const QByteArray&, const QString&, const QString& id );
+ void requeue();
+ void startRetryTimer();
+
DownloadQueueSet *findQueues( const QString& hostName, const DownloadUsage usage );
+ HttpDownloadManager* m_downloadManager;
QTimer m_requeueTimer;
/**
* Contains per download policy a queue set containing of
@@ -50,8 +58,9 @@ class HttpDownloadManager::Private
};
-HttpDownloadManager::Private::Private( StoragePolicy *policy )
- : m_requeueTimer(),
+HttpDownloadManager::Private::Private(HttpDownloadManager *parent, StoragePolicy *policy )
+ : m_downloadManager( parent ),
+ m_requeueTimer(),
m_storagePolicy( policy ),
m_networkAccessManager(),
m_acceptJobs( true )
@@ -95,11 +104,11 @@ DownloadQueueSet *HttpDownloadManager::Private::findQueues( const QString& hostN
HttpDownloadManager::HttpDownloadManager( StoragePolicy *policy )
- : d( new Private( policy ) )
+ : d( new Private( this, policy ) )
{
d->m_requeueTimer.setInterval( requeueTime );
connect( &d->m_requeueTimer, SIGNAL(timeout()), this, SLOT(requeue()) );
- connectDefaultQueueSets();
+ d->connectDefaultQueueSets();
}
HttpDownloadManager::~HttpDownloadManager()
@@ -121,10 +130,10 @@ void HttpDownloadManager::setDownloadEnabled( const bool enable )
void HttpDownloadManager::addDownloadPolicy( const DownloadPolicy& policy )
{
- if ( hasDownloadPolicy( policy ))
+ if ( d->hasDownloadPolicy( policy ))
return;
DownloadQueueSet * const queueSet = new DownloadQueueSet( policy, this );
- connectQueueSet( queueSet );
+ d->connectQueueSet( queueSet );
d->m_queueSets.append( QPair<DownloadPolicyKey, DownloadQueueSet *>
( queueSet->downloadPolicy().key(), queueSet ));
}
@@ -147,65 +156,65 @@ void HttpDownloadManager::addJob( const QUrl& sourceUrl, const QString& destFile
}
}
-void HttpDownloadManager::finishJob( const QByteArray& data, const QString& destinationFileName,
+void HttpDownloadManager::Private::finishJob( const QByteArray& data, const QString& destinationFileName,
const QString& id )
{
mDebug() << "emitting downloadComplete( QByteArray, " << id << ")";
- emit downloadComplete( data, id );
- if ( d->m_storagePolicy ) {
- const bool saved = d->m_storagePolicy->updateFile( destinationFileName, data );
+ emit m_downloadManager->downloadComplete( data, id );
+ if ( m_storagePolicy ) {
+ const bool saved = m_storagePolicy->updateFile( destinationFileName, data );
if ( saved ) {
mDebug() << "emitting downloadComplete( " << destinationFileName << ", " << id << ")";
- emit downloadComplete( destinationFileName, id );
+ emit m_downloadManager->downloadComplete( destinationFileName, id );
} else {
qWarning() << "Could not save:" << destinationFileName;
}
}
}
-void HttpDownloadManager::requeue()
+void HttpDownloadManager::Private::requeue()
{
- d->m_requeueTimer.stop();
+ m_requeueTimer.stop();
- QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator pos = d->m_queueSets.begin();
- QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator const end = d->m_queueSets.end();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator pos = m_queueSets.begin();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator const end = m_queueSets.end();
for (; pos != end; ++pos ) {
(*pos).second->retryJobs();
}
}
-void HttpDownloadManager::startRetryTimer()
+void HttpDownloadManager::Private::startRetryTimer()
{
- if ( !d->m_requeueTimer.isActive() )
- d->m_requeueTimer.start();
+ if ( !m_requeueTimer.isActive() )
+ m_requeueTimer.start();
}
-void HttpDownloadManager::connectDefaultQueueSets()
+void HttpDownloadManager::Private::connectDefaultQueueSets()
{
- QMap<DownloadUsage, DownloadQueueSet *>::iterator pos = d->m_defaultQueueSets.begin();
- QMap<DownloadUsage, DownloadQueueSet *>::iterator const end = d->m_defaultQueueSets.end();
+ QMap<DownloadUsage, DownloadQueueSet *>::iterator pos = m_defaultQueueSets.begin();
+ QMap<DownloadUsage, DownloadQueueSet *>::iterator const end = m_defaultQueueSets.end();
for (; pos != end; ++pos )
connectQueueSet( pos.value() );
}
-void HttpDownloadManager::connectQueueSet( DownloadQueueSet * queueSet )
+void HttpDownloadManager::Private::connectQueueSet( DownloadQueueSet * queueSet )
{
connect( queueSet, SIGNAL(jobFinished(QByteArray,QString,QString)),
- SLOT(finishJob(QByteArray,QString,QString)));
- connect( queueSet, SIGNAL(jobRetry()), SLOT(startRetryTimer()));
+ m_downloadManager, SLOT(finishJob(QByteArray,QString,QString)));
+ connect( queueSet, SIGNAL(jobRetry()), m_downloadManager, SLOT(startRetryTimer()));
connect( queueSet, SIGNAL(jobRedirected(QUrl,QString,QString,DownloadUsage)),
- SLOT(addJob(QUrl,QString,QString,DownloadUsage)));
+ m_downloadManager, SLOT(addJob(QUrl,QString,QString,DownloadUsage)));
// relay jobAdded/jobRemoved signals (interesting for progress bar)
- connect( queueSet, SIGNAL(jobAdded()), SIGNAL(jobAdded()));
- connect( queueSet, SIGNAL(jobRemoved()), SIGNAL(jobRemoved()));
- connect( queueSet, SIGNAL(progressChanged(int,int)), SIGNAL(progressChanged(int,int)) );
+ connect( queueSet, SIGNAL(jobAdded()), m_downloadManager, SIGNAL(jobAdded()));
+ connect( queueSet, SIGNAL(jobRemoved()), m_downloadManager, SIGNAL(jobRemoved()));
+ connect( queueSet, SIGNAL(progressChanged(int,int)), m_downloadManager, SIGNAL(progressChanged(int,int)) );
}
-bool HttpDownloadManager::hasDownloadPolicy( const DownloadPolicy& policy ) const
+bool HttpDownloadManager::Private::hasDownloadPolicy( const DownloadPolicy& policy ) const
{
bool found = false;
- QList<QPair<DownloadPolicyKey, DownloadQueueSet*> >::iterator pos = d->m_queueSets.begin();
- QList<QPair<DownloadPolicyKey, DownloadQueueSet*> >::iterator const end = d->m_queueSets.end();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet*> >::const_iterator pos = m_queueSets.constBegin();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet*> >::const_iterator const end = m_queueSets.constEnd();
for (; pos != end; ++pos ) {
if ( (*pos).second->downloadPolicy() == policy ) {
found = true;
diff --git a/src/lib/marble/HttpDownloadManager.h b/src/lib/marble/HttpDownloadManager.h
index 757956f..facf1ea 100644
--- a/src/lib/marble/HttpDownloadManager.h
+++ b/src/lib/marble/HttpDownloadManager.h
@@ -103,20 +103,15 @@ class MARBLE_EXPORT HttpDownloadManager : public QObject
*/
void progressChanged( int active, int queued );
- private Q_SLOTS:
- void finishJob( const QByteArray& data, const QString& destinationFileName,
- const QString& id );
- void requeue();
- void startRetryTimer();
-
private:
Q_DISABLE_COPY( HttpDownloadManager )
- void connectDefaultQueueSets();
- void connectQueueSet( DownloadQueueSet * );
- bool hasDownloadPolicy( const DownloadPolicy& policy ) const;
class Private;
Private * const d;
+
+ Q_PRIVATE_SLOT( d, void finishJob( const QByteArray&, const QString&, const QString& id ) )
+ Q_PRIVATE_SLOT( d, void requeue() )
+ Q_PRIVATE_SLOT( d, void startRetryTimer() )
};
}