[Kget] branches/work/make_kget_cool/kget
Manolo Valdes
nolis71cu at gmail.com
Wed Feb 21 05:56:28 CET 2007
SVN commit 635829 by mvaldes:
start initial metalink suport. still not operational.
make the main multisegmentkio job a kjob derivated class
calculate the all segments speed using the slaveinterface.cpp funtion
CCMAIL: kget at kde.org
M +13 -0 core/kget.cpp
M +7 -0 core/kget.h
M +6 -0 mainwindow.cpp
M +1 -1 transfer-plugins/CMakeLists.txt
A transfer-plugins/metalink (directory)
A transfer-plugins/metalink/CMakeLists.txt
A transfer-plugins/metalink/kget_metalinkfactory.desktop
A transfer-plugins/metalink/metalink.cpp [License: GPL]
A transfer-plugins/metalink/metalink.h [License: GPL]
A transfer-plugins/metalink/metalinkFactory.cpp [License: GPL]
A transfer-plugins/metalink/metalinkFactory.h [License: GPL]
A transfer-plugins/metalink/metalinker.cpp [License: GPL]
A transfer-plugins/metalink/metalinker.h [License: GPL]
M +87 -36 transfer-plugins/multisegmentkio/MultiSegKio.cpp
M +22 -9 transfer-plugins/multisegmentkio/MultiSegKio.h
M +2 -2 transfer-plugins/multisegmentkio/transferMultiSegKio.cpp
--- branches/work/make_kget_cool/kget/core/kget.cpp #635828:635829
@@ -101,6 +101,19 @@
}
}
+void KGet::addMetaLink(KUrl srcUrl)
+{
+ kDebug(5001) << " addMetaLink: " << srcUrl.url() << endl;
+
+ if ( !isValidSource( srcUrl ) )
+ return;
+
+ QString destDir = destInputDialog();
+ KUrl destUrl(destDir);
+
+ createTransfer(srcUrl, destUrl, QString("MetaLinks"));
+}
+
void KGet::addTransfer( KUrl srcUrl, QString destDir,
const QString& groupName )
{
--- branches/work/make_kget_cool/kget/core/kget.h #635828:635829
@@ -95,6 +95,13 @@
static void delGroup(const QString& groupName);
/**
+ * Adds a new metalink to the KGet
+ *
+ * @param srcUrl The url to be downloaded
+ */
+ static void addMetaLink(KUrl srcUrl);
+
+ /**
* Adds a new transfer to the KGet
*
* @param srcUrl The url to be downloaded
--- branches/work/make_kget_cool/kget/mainwindow.cpp #635828:635829
@@ -268,6 +268,12 @@
return;
}
+ if(filename.endsWith(".metalink"))
+ {
+ KGet::addMetaLink( KUrl( filename ) );
+ return;
+ }
+
if(!filename.isEmpty())
KGet::addTransfer( KUrl( filename ) );
}
--- branches/work/make_kget_cool/kget/transfer-plugins/CMakeLists.txt #635828:635829
@@ -1,4 +1,4 @@
add_subdirectory(kio)
add_subdirectory(multisegmentkio)
-#add_subdirectory(metalink)
+add_subdirectory(metalink)
#add_subdirectory(bittorrent)
--- branches/work/make_kget_cool/kget/transfer-plugins/multisegmentkio/MultiSegKio.cpp #635828:635829
@@ -14,22 +14,47 @@
#include <QFile>
#include <qtimer.h>
+#include <sys/time.h>
#include <fcntl.h>
#include "MultiSegKio.h"
+static const unsigned int max_nums = 8;
+class MultiSegmentCopyJob::MultiSegmentCopyJobPrivate
+{
+public:
+ MultiSegmentCopyJobPrivate() {
+ start_time.tv_sec = 0;
+ start_time.tv_usec = 0;
+ last_time = 0;
+ nums = 0;
+ bytes = 0;
+ }
+ struct timeval start_time;
+ uint nums;
+ long times[max_nums];
+ KIO::filesize_t sizes[max_nums];
+ size_t last_time;
+ KIO::filesize_t bytes;
+
+ QTimer speed_timer;
+};
+
+
/**
* class MultiSegmentCopyJob
*/
-MultiSegmentCopyJob::MultiSegmentCopyJob( const QList<KUrl> Urls, const KUrl& dest, int permissions, bool showProgressInfo, uint segments)
- : Job(showProgressInfo), m_dest(dest),
- m_permissions(permissions),
- m_writeBlocked(false)
+MultiSegmentCopyJob::MultiSegmentCopyJob( const QList<KUrl> Urls, const KUrl& dest, int permissions, uint segments)
+ :d(new MultiSegmentCopyJobPrivate),
+ KJob(0), m_dest(dest),
+ m_permissions(permissions),
+ m_writeBlocked(false)
{
kDebug(5001) << "MultiSegmentCopyJob::MultiSegmentCopyJob()" << endl;
QList<SegData> emptySegData;
SegFactory = new SegmentFactory( segments, Urls, emptySegData );
m_putJob = 0;
+ connect(&d->speed_timer, SIGNAL(timeout()), SLOT(calcSpeed()));
QTimer::singleShot(0, this, SLOT(slotStart()));
}
@@ -37,15 +62,15 @@
const QList<KUrl> Urls,
const KUrl& dest,
int permissions,
- bool showProgressInfo,
qulonglong ProcessedSize,
KIO::filesize_t totalSize,
QList<SegData> SegmentsData,
uint segments)
- : Job(showProgressInfo), m_dest(dest),
- m_permissions(permissions),
- m_writeBlocked(false)
+ :d(new MultiSegmentCopyJobPrivate),
+ KJob(0), m_dest(dest),
+ m_permissions(permissions),
+ m_writeBlocked(false)
{
kDebug(5001) << "MultiSegmentCopyJob::MultiSegmentCopyJob()" << endl;
SegFactory = new SegmentFactory( segments, Urls, SegmentsData );
@@ -66,6 +91,7 @@
}
m_putJob = 0;
+ connect(&d->speed_timer, SIGNAL(timeout()), SLOT(calcSpeed()));
setProcessedSize(ProcessedSize);
setTotalSize(totalSize);
QTimer::singleShot(0, this, SLOT(slotStart()));
@@ -104,7 +130,6 @@
connect(m_putJob, SIGNAL(close(KIO::Job *)), SLOT(slotClose(KIO::Job *)));
connect( m_putJob, SIGNAL(written(KIO::Job * ,KIO::filesize_t )), SLOT(slotWritten( KIO::Job * ,KIO::filesize_t )));
connect( m_putJob, SIGNAL(result(KJob *)), SLOT(slotResult( KJob *)));
- addSubjob( m_putJob );
}
void MultiSegmentCopyJob::slotOpen( KIO::Job * job)
@@ -112,6 +137,14 @@
kDebug(5001) << "MultiSegmentCopyJob::slotOpen()" << endl;
if( SegFactory->startTransfer() )
{
+
+ gettimeofday(&d->start_time, 0);
+ d->last_time = 0;
+ d->sizes[0] = processedSize() - d->bytes;
+ d->times[0] = 0;
+ d->nums = 1;
+ d->speed_timer.start(1000);
+
return;
}
SegData data;
@@ -152,6 +185,39 @@
emit updateSegmentsData();
}
+// tooked from SlaveInterface.cpp
+void MultiSegmentCopyJob::calcSpeed()
+{
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+
+ long diff = ((tv.tv_sec - d->start_time.tv_sec) * 1000000 +
+ tv.tv_usec - d->start_time.tv_usec) / 1000;
+ if (diff - d->last_time >= 900) {
+ d->last_time = diff;
+ if (d->nums == max_nums) {
+ // let's hope gcc can optimize that well enough
+ // otherwise I'd try memcpy :)
+ for (unsigned int i = 1; i < max_nums; ++i) {
+ d->times[i-1] = d->times[i];
+ d->sizes[i-1] = d->sizes[i];
+ }
+ d->nums--;
+ }
+ d->times[d->nums] = diff;
+ d->sizes[d->nums++] = processedSize() - d->bytes;
+
+ KIO::filesize_t lspeed = 1000 * (d->sizes[d->nums-1] - d->sizes[0]) / (d->times[d->nums-1] - d->times[0]);
+
+ if (!lspeed) {
+ d->nums = 1;
+ d->times[0] = diff;
+ d->sizes[0] = processedSize() - d->bytes;
+ }
+ emit speed(this, lspeed);
+ }
+}
+
void MultiSegmentCopyJob::slotDataReq( Segment *seg, const QByteArray &data, bool &result)
{
// kDebug(5001) << "MultiSegmentCopyJob::slotDataReq() " << endl;
@@ -194,13 +260,8 @@
if (job == m_putJob )
{
kDebug(5001) << "MultiSegmentCopyJob: m_putJob finished " << endl;
+ kDebug(5001) << "MultiSegmentCopyJob: finished " << endl;
m_putJob = 0;
- removeSubjob(job);
- }
-
- if ( !hasSubjobs() )
- {
- kDebug(5001) << "MultiSegmentCopyJob: finished " << endl;
emitResult();
}
}
@@ -209,6 +270,14 @@
{
kDebug(5001) << "MultiSegmentCopyJob::slotTotalSize() from job: " << job << " -- " << size << endl;
setTotalSize (size);
+
+ gettimeofday(&d->start_time, 0);
+ d->last_time = 0;
+ d->sizes[0] = processedSize() - d->bytes;
+ d->times[0] = 0;
+ d->nums = 1;
+ d->speed_timer.start(1000);
+
QList<Segment *> segments = SegFactory->Segments();
Segment *seg = segments.takeFirst();
seg->setBytes(size);
@@ -235,23 +304,6 @@
void MultiSegmentCopyJob::slotSpeed( KJob* job, unsigned long bytes_per_second )
{
- if(job == m_putJob)
- return;
- kDebug(5001) << "MultiSegmentCopyJob::slotSpeed() " << job << " -- " << bytes_per_second << endl;
- speedHash.insert(job, bytes_per_second);
-
- unsigned long _speed = 0;
- QHash<KJob* , unsigned long>::iterator i = speedHash.begin();
-
- while (i != speedHash.end())
- {
- if( i.value() == 0 )
- speedHash.erase(i);
- else
- _speed += i.value();
- ++i;
- }
- emitSpeed(_speed);
}
bool MultiSegmentCopyJob::checkLocalFile()
@@ -294,22 +346,21 @@
return true;
}
-MultiSegmentCopyJob *MultiSegfile_copy( const QList<KUrl> Urls, const KUrl& dest, int permissions, bool showProgressInfo, uint segments)
+MultiSegmentCopyJob *MultiSegfile_copy( const QList<KUrl> Urls, const KUrl& dest, int permissions, uint segments)
{
- return new MultiSegmentCopyJob( Urls, dest, permissions, showProgressInfo, segments);
+ return new MultiSegmentCopyJob( Urls, dest, permissions, segments);
}
MultiSegmentCopyJob *MultiSegfile_copy(
const QList<KUrl> Urls,
const KUrl& dest,
int permissions,
- bool showProgressInfo,
qulonglong ProcessedSize,
KIO::filesize_t totalSize,
QList<SegData> SegmentsData,
uint segments)
{
- return new MultiSegmentCopyJob( Urls, dest, permissions, showProgressInfo, ProcessedSize, totalSize,SegmentsData , segments);
+ return new MultiSegmentCopyJob( Urls, dest, permissions, ProcessedSize, totalSize,SegmentsData , segments);
}
#include "MultiSegKio.moc"
--- branches/work/make_kget_cool/kget/transfer-plugins/multisegmentkio/MultiSegKio.h #635828:635829
@@ -21,7 +21,7 @@
* class MultiSegmentCopyJob
*/
- class KIO_EXPORT MultiSegmentCopyJob : public KIO::Job
+ class KIO_EXPORT MultiSegmentCopyJob : public KJob
{
Q_OBJECT
@@ -32,23 +32,21 @@
* @param src the source URL
* @param dest the destination URL
* @param permissions the permissions of the resulting resource
- * @param showProgressInfo true to show progress information to the user
* @param segments number of segments
*/
- MultiSegmentCopyJob( const QList<KUrl> Urls, const KUrl& dest, int permissions, bool showProgressInfo, uint segments);
+ MultiSegmentCopyJob( const QList<KUrl> Urls, const KUrl& dest, int permissions, uint segments);
/**
* Do not create a MultiSegmentCopyJob directly. Use MultiSegfile_copy() instead.
* @param src the source URL
* @param dest the destination URL
* @param permissions the permissions of the resulting resource
- * @param showProgressInfo true to show progress information to the user
* @param ProcessedSize
* @param totalSize
* @param segments a QList with segments data to resume a started copy
*/
MultiSegmentCopyJob( const QList<KUrl> Urls, const KUrl& dest,
- int permissions, bool showProgressInfo,
+ int permissions,
qulonglong ProcessedSize,
KIO::filesize_t totalSize,
QList<SegData> SegmentsData,
@@ -56,13 +54,28 @@
~MultiSegmentCopyJob();
QList<SegData> SegmentsData();
+ virtual void start() {};
void stop();
Q_SIGNALS:
void updateSegmentsData();
+ /**
+ * Emitted to display information about the speed of this job.
+ * @param job the job that emitted this signal
+ * @param speed the speed in bytes/s
+ */
+ void speed( KJob *job, unsigned long speed );
+
+ /**
+ * Emitted to display information about the speed of a segment.
+ * @param job the segment job that emitted this signal
+ * @param speed the speed in bytes/s
+ */
+ void segmentSpeed( KJob *job, unsigned long speed );
+
private Q_SLOTS:
-
+ void calcSpeed();
void slotDataReq( Segment *, const QByteArray &data, bool &result);
void slotStatusChanged( Segment *seg );
void slotStart();
@@ -104,19 +117,19 @@
SegmentFactory *SegFactory;
KIO::FileJob* m_putJob;
bool m_writeBlocked;
- QHash <KJob*, unsigned long>speedHash;
+ class MultiSegmentCopyJobPrivate;
+ MultiSegmentCopyJobPrivate* const d;
private:
bool checkLocalFile();
};
- MultiSegmentCopyJob *MultiSegfile_copy( const QList<KUrl> Urls, const KUrl& dest, int permissions, bool showProgressInfo, uint segments);
+ MultiSegmentCopyJob *MultiSegfile_copy( const QList<KUrl> Urls, const KUrl& dest, int permissions, uint segments);
MultiSegmentCopyJob *MultiSegfile_copy(
const QList<KUrl> Urls,
const KUrl& dest,
int permissions,
- bool showProgressInfo,
KIO::filesize_t ProcessedSize,
KIO::filesize_t totalSize,
QList<SegData> SegmentsData,
--- branches/work/make_kget_cool/kget/transfer-plugins/multisegmentkio/transferMultiSegKio.cpp #635828:635829
@@ -151,11 +151,11 @@
}
if(SegmentsData.empty())
{
- m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, MultiSegKioSettings::segments());
+ m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, MultiSegKioSettings::segments());
}
else
{
- m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, m_processedSize, m_totalSize, SegmentsData, MultiSegKioSettings::segments());
+ m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, m_processedSize, m_totalSize, SegmentsData, MultiSegKioSettings::segments());
}
connect(m_copyjob, SIGNAL(updateSegmentsData()),
SLOT(slotUpdateSegmentsData()));
More information about the Kget
mailing list