[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdenetwork/kget
From: Lukas Appelhans <l.appelhans () gmx ! de>
Date: 2012-08-21 10:29:47
Message-ID: 20120821102947.7BDCBAC73B () svn ! kde ! org
[Download RAW message or body]
SVN commit 1312138 by lappelhans:
Handle url redirections correctly.
BUG:180136
M +8 -0 core/datasourcefactory.cpp
M +2 -0 core/datasourcefactory.h
M +5 -0 core/transferdatasource.h
M +9 -0 transfer-plugins/multisegmentkio/multisegkiodatasource.cpp
M +2 -0 transfer-plugins/multisegmentkio/multisegkiodatasource.h
M +7 -0 transfer-plugins/multisegmentkio/segment.cpp
M +3 -0 transfer-plugins/multisegmentkio/segment.h
M +22 -0 transfer-plugins/multisegmentkio/transfermultisegkio.cpp
--- trunk/KDE/kdenetwork/kget/core/datasourcefactory.cpp #1312137:1312138
@@ -448,6 +448,7 @@
connect(source, \
SIGNAL(data(KIO::fileoffset_t,QByteArray,bool&)), this, \
SLOT(slotWriteData(KIO::fileoffset_t,QByteArray,bool&)));
connect(source, \
SIGNAL(freeSegments(TransferDataSource*,QPair<int,int>)), this, \
SLOT(slotFreeSegments(TransferDataSource*,QPair<int,int>)));
connect(source, SIGNAL(log(QString,Transfer::LogLevel)), this, \
SIGNAL(log(QString,Transfer::LogLevel))); + connect(source, \
SIGNAL(urlChanged(KUrl, KUrl)), this, SLOT(slotUrlChanged(KUrl, KUrl)));
slotUpdateCapabilities();
@@ -492,6 +493,13 @@
}
}
+void DataSourceFactory::slotUrlChanged(const KUrl &old, const KUrl &newUrl)
+{
+ TransferDataSource * ds = m_sources.take(old);
+ m_sources[newUrl] = ds;
+ emit dataSourceFactoryChange(Transfer::Tc_Source | Transfer::Tc_FileName);
+}
+
void DataSourceFactory::removeMirror(const KUrl &url)
{
kDebug(5001) << "Removing mirror: " << url;
--- trunk/KDE/kdenetwork/kget/core/datasourcefactory.h #1312137:1312138
@@ -223,6 +223,8 @@
void slotFinishedDownload(TransferDataSource *source, KIO::filesize_t size);
+ void slotUrlChanged(const KUrl &, const KUrl &);
+
private:
/**
* Add a mirror that can be used for downloading
--- trunk/KDE/kdenetwork/kget/core/transferdatasource.h #1312137:1312138
@@ -224,6 +224,11 @@
void log(const QString &message, Transfer::LogLevel logLevel);
+ /**
+ * Emitted when the filename of a url changes, e.g. when a link redirects
+ */
+ void urlChanged(const KUrl &old, const KUrl &newUrl);
+
protected:
/**
* Sets the capabilities and automatically emits capabilitiesChanged
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/multisegkiodatasource.cpp \
#1312137:1312138 @@ -80,12 +80,21 @@
connect(segment, SIGNAL(finishedSegment(Segment*,int,bool)), this, \
SLOT(slotFinishedSegment(Segment*,int,bool)));
connect(segment, SIGNAL(error(Segment*,QString,Transfer::LogLevel)), this, \
SLOT(slotError(Segment*,QString,Transfer::LogLevel)));
connect(segment, SIGNAL(finishedDownload(KIO::filesize_t)), this, \
SLOT(slotFinishedDownload(KIO::filesize_t))); + connect(segment, \
SIGNAL(urlChanged(KUrl)), this, SLOT(slotUrlChanged(KUrl)));
if (m_started) {
segment->startTransfer();
}
}
+void MultiSegKioDataSource::slotUrlChanged(const KUrl &url)
+{
+ if (m_sourceUrl != url) {
+ emit urlChanged(m_sourceUrl, url);
+ m_sourceUrl = url;
+ }
+}
+
void MultiSegKioDataSource::findFileSize(KIO::fileoffset_t segmentSize)
{
addSegments(qMakePair(segmentSize, segmentSize), qMakePair(-1, -1));
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/multisegkiodatasource.h \
#1312137:1312138 @@ -57,6 +57,8 @@
void slotFinishedDownload(KIO::filesize_t size);
+ void slotUrlChanged(const KUrl &url);
+
private:
Segment *mostUnfinishedSegments(int *unfinished = 0) const;
bool tryMerge(const QPair<KIO::fileoffset_t, KIO::fileoffset_t> \
&segmentSize, const QPair<int,int> &segmentRange);
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/segment.cpp \
#1312137:1312138 @@ -91,9 +91,16 @@
connect( m_getJob, SIGNAL(data(KIO::Job*,QByteArray)),
SLOT(slotData(KIO::Job*,QByteArray)));
connect( m_getJob, SIGNAL(result(KJob*)), SLOT(slotResult(KJob*)));
+ connect(m_getJob, SIGNAL(redirection(KIO::Job *,const KUrl &)), \
SLOT(slotRedirection(KIO::Job *, const KUrl &))); return true;
}
+void Segment::slotRedirection(KIO::Job* , const KUrl &url)
+{
+ m_url = url;
+ emit urlChanged(url);
+}
+
void Segment::slotCanResume( KIO::Job* job, KIO::filesize_t offset )
{
Q_UNUSED(job)
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/segment.h \
#1312137:1312138 @@ -121,6 +121,7 @@
void totalSize(KIO::filesize_t size, QPair<int, int> segmentRange);
void finishedDownload(KIO::filesize_t size);
void canResume();
+ void urlChanged(const KUrl &newUrl);
private Q_SLOTS:
void slotData(KIO::Job *job, const QByteArray &data);
@@ -134,6 +135,8 @@
*/
void slotWriteRest();
+ void slotRedirection(KIO::Job*, const KUrl &);
+
private:
bool writeBuffer();
void setStatus(Status stat, bool doEmit=true);
--- trunk/KDE/kdenetwork/kget/transfer-plugins/multisegmentkio/transfermultisegkio.cpp \
#1312137:1312138 @@ -163,6 +163,28 @@
void TransferMultiSegKio::slotDataSourceFactoryChange(Transfer::ChangesFlags change)
{
+ if (change & Tc_FileName) {
+ QList<KUrl> urls = m_dataSourceFactory->mirrors().keys();
+ QString filename = urls.first().fileName();
+ foreach (const KUrl url, urls) {
+ if (filename != url.fileName())
+ return;
+ }
+ KUrl path = m_dest.directory();
+ path.addPath(filename);
+ setNewDestination(path);
+ }
+ if (change & Tc_Source) {
+ m_source = KUrl();
+ QHash< KUrl, QPair<bool, int> >::const_iterator it = \
m_dataSourceFactory->mirrors().begin(); + QHash< KUrl, QPair<bool, int> \
>::const_iterator end = m_dataSourceFactory->mirrors().end(); + for (; it != \
> end; it++) {
+ if (it.value().first) {
+ m_source = it.key();
+ break;
+ }
+ }
+ }
if (change & Tc_Status) {
setStatus(m_dataSourceFactory->status());
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic