[Marble-commits] KDE/kdeedu/marble/src/lib
Jens-Michael Hoffmann
jensmh at gmx.de
Mon Oct 12 02:22:23 CEST 2009
SVN commit 1034115 by jmhoffmann:
- Add DownloadUsage parameter for finding download policies
- Remove broken operator< for DownloadPolicyKey and use list based approach in HttpDownloadManager instead.
M +2 -13 DownloadPolicy.cpp
M +1 -4 DownloadPolicy.h
M +15 -13 HttpDownloadManager.cpp
--- trunk/KDE/kdeedu/marble/src/lib/DownloadPolicy.cpp #1034114:1034115
@@ -58,23 +58,12 @@
m_usage = usage;
}
-bool DownloadPolicyKey::matches( QString const & hostName ) const
+bool DownloadPolicyKey::matches( QString const & hostName, const DownloadUsage usage ) const
{
- return m_hostNames.contains( hostName );
+ return m_hostNames.contains( hostName ) && m_usage == usage;
}
-bool operator<( DownloadPolicyKey const & lhs, DownloadPolicyKey const & rhs )
-{
- // FIXME: implement operator< for QStringList
-// if ( lhs.m_hostNames.size() < rhs.m_hostNames.size() )
-// return true;
-// else if ( rhs.m_hostNames.size() < lhs.m_hostNames.size() )
-// return false;
-// else
- return lhs.m_usage < rhs.m_usage;
-}
-
DownloadPolicy::DownloadPolicy()
: m_key(),
m_maximumConnections( 1 )
--- trunk/KDE/kdeedu/marble/src/lib/DownloadPolicy.h #1034114:1034115
@@ -39,17 +39,14 @@
DownloadUsage usage() const;
void setUsage( DownloadUsage const usage );
- /// FIXME: take usage into account
- bool matches( QString const & hostName ) const;
+ bool matches( const QString & hostName, const DownloadUsage usage ) const;
private:
QStringList m_hostNames;
DownloadUsage m_usage;
};
-bool operator<( DownloadPolicyKey const & lhs, DownloadPolicyKey const & rhs );
-
class DownloadPolicy
{
public:
--- trunk/KDE/kdeedu/marble/src/lib/HttpDownloadManager.cpp #1034114:1034115
@@ -37,7 +37,7 @@
HttpJob *createJob( const QUrl& sourceUrl, const QString& destFileName,
const QString &id );
- DownloadQueueSet *findQueues( const QString& hostName );
+ DownloadQueueSet *findQueues( const QString& hostName, const DownloadUsage usage );
bool m_downloadEnabled;
QTimer *m_requeueTimer;
@@ -46,7 +46,7 @@
* - 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;
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet *> > m_queueSets;
int m_jobQueueLimit;
StoragePolicy *m_storagePolicy;
NetworkPlugin *m_networkPlugin;
@@ -90,21 +90,22 @@
return m_networkPlugin->createJob( sourceUrl, destFileName, id );
}
-DownloadQueueSet *HttpDownloadManager::Private::findQueues( const QString& hostName )
+DownloadQueueSet *HttpDownloadManager::Private::findQueues( const QString& hostName,
+ const DownloadUsage usage )
{
DownloadQueueSet * result = 0;
- QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator pos = m_queueSets.begin();
- QMap<DownloadPolicyKey, DownloadQueueSet*>::iterator const end = 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 ) {
- if ( pos.key().matches( hostName )) {
- result = pos.value();
+ if ( (*pos).first.matches( hostName, usage )) {
+ result = (*pos).second;
break;
}
}
// FIXME:
if ( !result ) {
Q_ASSERT( !m_queueSets.isEmpty() );
- result = m_queueSets.begin().value();
+ result = m_queueSets.first().second;
}
return result;
}
@@ -154,7 +155,8 @@
// relay jobAdded/jobRemoved signals (interesting for progress bar)
connect( queueSet, SIGNAL( jobAdded() ), SIGNAL( jobAdded() ));
connect( queueSet, SIGNAL( jobRemoved() ), SIGNAL( jobRemoved() ));
- d->m_queueSets.insert( queueSet->downloadPolicy().key(), queueSet );
+ d->m_queueSets.append( QPair<DownloadPolicyKey, DownloadQueueSet *>
+ ( queueSet->downloadPolicy().key(), queueSet ));
}
StoragePolicy* HttpDownloadManager::storagePolicy() const
@@ -168,7 +170,7 @@
if ( !d->m_downloadEnabled )
return;
- DownloadQueueSet * const queueSet = d->findQueues( sourceUrl.host() );
+ DownloadQueueSet * const queueSet = d->findQueues( sourceUrl.host(), DownloadBrowse );
if ( queueSet->canAcceptJob( sourceUrl, destFileName )) {
HttpJob * const job = d->createJob( sourceUrl, destFileName, id );
if ( job ) {
@@ -197,10 +199,10 @@
{
d->m_requeueTimer->stop();
- QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator pos = d->m_queueSets.begin();
- QMap<DownloadPolicyKey, DownloadQueueSet *>::iterator const end = d->m_queueSets.end();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator pos = d->m_queueSets.begin();
+ QList<QPair<DownloadPolicyKey, DownloadQueueSet *> >::iterator const end = d->m_queueSets.end();
for (; pos != end; ++pos ) {
- pos.value()->retryJobs();
+ (*pos).second->retryJobs();
}
}
More information about the Marble-commits
mailing list