[Kget] branches/work/make_kget_cool/kget/transfers/multisegmentkio
Manolo Valdes
nolis71cu at gmail.com
Tue Dec 19 06:30:35 CET 2006
SVN commit 614835 by mvaldes:
Add search capability (still buggy)
Add a setting widget and a local setting file
still under development...
CCMAIL: kget at kde.org
M +6 -0 CMakeLists.txt
M +30 -2 MultiSegKio.cpp
M +1 -1 MultiSegKio.h
A MultiSegKioSettings.kcfgc
A dlgmultisegkio.ui
A kget_MultiSegKiofactory.kcfg
A mirrors.cpp [License: GPL]
A mirrors.h [License: GPL]
M +73 -17 segmentfactory.cpp
M +6 -0 segmentfactory.h
M +9 -5 transferMultiSegKio.cpp
M +25 -14 transferMultiSegKioFactory.cpp
M +12 -10 transferMultiSegKioFactory.h
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/CMakeLists.txt #614834:614835
@@ -12,10 +12,15 @@
set(kget_MultiSegKiofactory_PART_SRCS
segmentfactory.cpp
MultiSegKio.cpp
+ mirrors.cpp
transferMultiSegKio.cpp
transferMultiSegKioFactory.cpp
)
+kde4_add_ui_files(kget_MultiSegKiofactory_PART_SRCS dlgmultisegkio.ui)
+
+kde4_add_kcfg_files(kget_MultiSegKiofactory_PART_SRCS MultiSegKioSettings.kcfgc)
+
kde4_automoc(${kget_MultiSegKiofactory_PART_SRCS})
kde4_add_plugin(kget_MultiSegKiofactory WITH_PREFIX ${kget_MultiSegKiofactory_PART_SRCS})
@@ -27,4 +32,5 @@
########### install files ###############
install(FILES kget_MultiSegKiofactory.desktop DESTINATION ${SERVICES_INSTALL_DIR})
+install(FILES kget_MultiSegKiofactory.kcfg DESTINATION ${KCFG_INSTALL_DIR})
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/MultiSegKio.cpp #614834:614835
@@ -49,6 +49,20 @@
{
kDebug(5001) << "MultiSegmentCopyJob::MultiSegmentCopyJob()" << endl;
SegFactory = new SegmentFactory( segments, Urls, SegmentsData );
+ QList<Segment *> Segments = SegFactory->Segments();
+ QList<Segment *>::iterator it = Segments.begin();
+ QList<Segment *>::iterator itEnd = Segments.end();
+ for ( ; it!=itEnd ; ++it )
+ {
+ kDebug(5001) << "MultiSegmentCopyJob::MultiSegmentCopyJob() conecting job Signals" << endl;
+ connect( (*it), SIGNAL(data( Segment*, const QByteArray&, bool &)),
+ SLOT(slotDataReq( Segment *, const QByteArray&, bool &)));
+ connect( (*it)->job(), SIGNAL(speed( KIO::Job*, unsigned long )),
+ SLOT(slotSpeed( KIO::Job*, unsigned long )));
+ connect( (*it), SIGNAL(updateSegmentData()),
+ SIGNAL(updateSegmentsData()));
+ }
+
m_putJob = 0;
setProcessedSize(ProcessedSize);
setTotalSize(totalSize);
@@ -57,9 +71,18 @@
QList<SegData> MultiSegmentCopyJob::SegmentsData()
{
+ kDebug(5001) << "MultiSegmentCopyJob::SegmentsData()" << endl;
return SegFactory->SegmentsData();
}
+void MultiSegmentCopyJob::stop()
+{
+ kDebug(5001) << "MultiSegmentCopyJob::stop()" << endl;
+ if (SegFactory)
+ SegFactory->stopTransfer();
+ doKill();
+}
+
void MultiSegmentCopyJob::slotStart()
{
kDebug(5001) << "MultiSegmentCopyJob::slotStart()" << endl;
@@ -78,7 +101,10 @@
void MultiSegmentCopyJob::slotOpen( KIO::Job * job)
{
kDebug(5001) << "MultiSegmentCopyJob::slotOpen()" << endl;
-
+ if( SegFactory->startTransfer() )
+ {
+ return;
+ }
SegData data;
Segment *seg = SegFactory->createSegment(data, SegFactory->nextUrl() );
@@ -86,6 +112,8 @@
SLOT(slotDataReq( Segment *, const QByteArray&, bool &)));
connect( seg, SIGNAL(updateSegmentData()),
SIGNAL(updateSegmentsData()));
+ connect( seg->job(), SIGNAL(speed( KIO::Job*, unsigned long )),
+ SLOT(slotSpeed( KIO::Job*, unsigned long )));
connect( seg->job(), SIGNAL(totalSize( KJob *, qulonglong )),
SLOT(slotTotalSize( KJob *, qulonglong )));
seg->startTransfer();
@@ -197,7 +225,7 @@
while (i.hasNext())
{
i.next();
- _speed += i.value();
+ _speed += i.value();
}
emit speed( this, _speed );
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/MultiSegKio.h #614834:614835
@@ -55,6 +55,7 @@
uint segments);
QList<SegData> SegmentsData();
+ void stop();
Q_SIGNALS:
void updateSegmentsData();
@@ -97,7 +98,6 @@
void slotSpeed( KIO::Job*, unsigned long bytes_per_second );
private:
- KUrl m_src;
KUrl m_dest;
KUrl m_dest_part;
int m_permissions;
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/segmentfactory.cpp #614834:614835
@@ -8,6 +8,7 @@
of the License.
*/
+#include<QtCore/QTimer>
#include "segmentfactory.h"
@@ -27,12 +28,11 @@
bool Segment::createTransfer ( KUrl src )
{
- kDebug(5001) << "Segment::startTransfer()" << endl;
+ kDebug(5001) << "Segment::createTransfer() -- " << src << endl;
if ( m_getJob )
return false;
m_getJob = KIO::get(src, false, false);
m_getJob->internalSuspend();
-// m_getJob->url(); // to know the url
if ( m_segData.offset )
{
m_getJob->addMetaData( "resume", KIO::number(m_segData.offset) );
@@ -44,23 +44,39 @@
return true;
}
-bool Segment::startTransfer ( )
+bool Segment::startTransfer ()
{
- m_stoped = false;
+ kDebug(5001) << "Segment::startTransfer()"<< endl;
if( m_getJob )
+ {
+ m_stoped = false;
m_getJob->internalResume();
+ return true;
+ }
+ return false;
}
-bool Segment::stopTransfer ( )
+bool Segment::stopTransfer ()
{
- m_stoped = true;
+ kDebug(5001) << "Segment::stopTransfer()"<< endl;
if( m_getJob )
- m_getJob->internalSuspend();
+ {
+ m_stoped = true;
+ m_getJob->kill( KJob::EmitResult );
+ return true;
+ }
+ return false;
}
void Segment::slotResult( KJob *job )
{
+ kDebug(5001) << "Segment::slotResult() job: " << job << endl;
m_getJob = 0;
+ if ( !m_buffer.isEmpty() )
+ {
+ kDebug(5001) << "Looping until write the buffer ..." << endl;
+ while(writeBuffer());
+ }
if( m_stoped || !m_segData.bytes )
{
emit updateSegmentData();
@@ -68,6 +84,7 @@
}
else
{
+// restart tranfer
}
}
@@ -77,13 +94,18 @@
m_buffer.append(_data);
if ( m_buffer.size() > m_segData.bytes )
{
+ kDebug(5001) << "Segment::slotData() buffer full. stoping transfer..." << endl;
m_buffer.truncate( m_segData.bytes );
- m_getJob->internalSuspend();
+ m_getJob->kill( KJob::EmitResult );
}
- kDebug(5001) << "Segment::slotData() sending: " << m_buffer.size() << " from job: "<< m_getJob << endl;
+ writeBuffer();
+}
+
+bool Segment::writeBuffer()
+{
+ kDebug(5001) << "Segment::writeBuffer() sending: " << m_buffer.size() << " from job: "<< m_getJob << endl;
bool rest;
emit data( this, m_buffer, rest);
- kDebug(5001) << "Segment::slotData() the writer return: " << rest << endl;
if ( rest )
{
m_segData.bytes -= m_buffer.size();
@@ -91,19 +113,27 @@
m_bytesWritten += m_buffer.size();
m_chunkSize += m_buffer.size();
m_buffer = QByteArray();
- kDebug(5001) << "Segment::slotData() updating segment record of job: " << m_getJob << " -- " << m_segData.bytes <<" bytes left"<< endl;
+ kDebug(5001) << "Segment::writeBuffer() updating segment record of job: " << m_getJob << " -- " << m_segData.bytes <<" bytes left"<< endl;
if( m_chunkSize > 50*1024)
{
emit updateSegmentData();
m_chunkSize =0;
}
- if (!m_segData.bytes)
- {
- kDebug(5001) << "Segment::slotData() closing transfer ..." << endl;
+ }
+/* else
+ {
+ kDebug(5001) << "Segment::writeBuffer() " << m_buffer.size() <<" bytes still left in buffer"<< endl;
+ if( !m_getJob )
+ QTimer::singleShot (1000, this, SLOT( writeBuffer()));
+ return rest;
+ }*/
+ if (!m_segData.bytes)
+ {
+ kDebug(5001) << "Segment::writeBuffer() closing transfer ..." << endl;
+ if( m_getJob )
m_getJob->kill( KJob::EmitResult );
- return;
- }
}
+ return rest;
}
SegmentFactory::SegmentFactory(uint n, const QList<KUrl> Urls, QList<SegData> SegmentsData)
@@ -117,11 +147,37 @@
QList<SegData>::const_iterator itEnd = SegmentsData.end();
for ( ; it!=itEnd ; ++it )
{
- m_Segments << createSegment( (*it), nextUrl() );
+ createSegment( (*it), nextUrl() );
}
}
}
+bool SegmentFactory::startTransfer ( )
+{
+ kDebug(5001) << "SegmentFactory::startTransfer()" << endl;
+ bool rest = false;
+ QList<Segment *>::iterator it = m_Segments.begin();
+ QList<Segment *>::iterator itEnd = m_Segments.end();
+ for ( ; it!=itEnd ; ++it )
+ {
+ rest |= (*it)->startTransfer();
+ }
+ return rest;
+}
+
+bool SegmentFactory::stopTransfer ( )
+{
+ kDebug(5001) << "SegmentFactory::stopTransfer()" << endl;
+ bool rest = false;
+ QList<Segment *>::iterator it = m_Segments.begin();
+ QList<Segment *>::iterator itEnd = m_Segments.end();
+ for ( ; it!=itEnd ; ++it )
+ {
+ rest |= (*it)->stopTransfer();
+ }
+ return rest;
+}
+
QList<SegData> SegmentFactory::SegmentsData()
{
kDebug(5001) << "SegmentFactory::getSegmentsData" << endl;
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/segmentfactory.h #614834:614835
@@ -117,6 +117,10 @@
private:
+ bool writeBuffer();
+
+private:
+
bool m_stoped;
SegData m_segData;
KIO::filesize_t m_bytesWritten;
@@ -131,6 +135,8 @@
public:
// SegmentFactory(uint n, QList<KUrl> Urls);
SegmentFactory( uint n, const QList<KUrl> Urls, QList<SegData> SegmentsData );
+ bool startTransfer ( );
+ bool stopTransfer ( );
QList<SegData> SegmentsData();
QList<KUrl> Urls() {return m_Urls;};
QList<Segment *> Segments() {return m_Segments;};
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/transferMultiSegKio.cpp #614834:614835
@@ -15,7 +15,9 @@
#include <klocale.h>
#include <kdebug.h>
+#include "MultiSegKioSettings.h"
#include "transferMultiSegKio.h"
+#include "mirrors.h"
transferMultiSegKio::transferMultiSegKio(TransferGroup * parent, TransferFactory * factory,
Scheduler * scheduler, const KUrl & source, const KUrl & dest,
@@ -46,7 +48,7 @@
if(m_copyjob)
{
- m_copyjob->doKill();
+ m_copyjob->stop();
// m_copyjob=0;
}
@@ -140,16 +142,18 @@
{
if(m_Urls.empty())
{
- // Call a search funtion to fill the Urls list. to be coded :)
- m_Urls << m_source;
+ if(MultiSegKioSettings::useSearchEngines())
+ m_Urls = MirrorSearch (m_source);
+ else
+ m_Urls << m_source;
}
if(SegmentsData.empty())
{
- m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, 5);
+ m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, MultiSegKioSettings::segments());
}
else
{
- m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, m_processedSize, m_totalSize, SegmentsData, 5);
+ m_copyjob = MultiSegfile_copy( m_Urls, m_dest, -1, false, m_processedSize, m_totalSize, SegmentsData, MultiSegKioSettings::segments());
}
connect(m_copyjob, SIGNAL(updateSegmentsData()),
SLOT(slotUpdateSegmentsData()));
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/transferMultiSegKioFactory.cpp #614834:614835
@@ -13,6 +13,8 @@
#include "core/scheduler.h"
#include "core/transfergroup.h"
+#include "MultiSegKioSettings.h"
+#include "ui_dlgmultisegkio.h"
#include "transfers/multisegmentkio/transferMultiSegKioFactory.h"
#include "transfers/multisegmentkio/transferMultiSegKio.h"
@@ -31,31 +33,40 @@
Scheduler * scheduler,
const QDomElement * e )
{
- kDebug(5001) << "TransferMultiSegKioFactory::createTransfer" << endl;
+ kDebug(5001) << "TransferMultiSegKioFactory::createTransfer" << endl;
- QString prot = srcUrl.protocol();
- kDebug(5001) << "Protocol = " << prot << endl;
- if( prot == "http" || prot == "https"
- || prot == "ftp" || prot == "sftp"
- )
- {
- return new transferMultiSegKio(parent, this, scheduler, srcUrl, destUrl, e);
- }
- return 0;
+ QString prot = srcUrl.protocol();
+ kDebug(5001) << "Protocol = " << prot << endl;
+ if( prot == "http" || prot == "https" ||
+ prot == "ftp" || prot == "sftp" &&
+ MultiSegKioSettings::segments() > 1
+ )
+ {
+ return new transferMultiSegKio(parent, this, scheduler, srcUrl, destUrl, e);
+ }
+ return 0;
}
TransferHandler * TransferMultiSegKioFactory::createTransferHandler(Transfer * transfer, Scheduler * scheduler)
{
- return new TransferHandler(transfer, scheduler);
+ return new TransferHandler(transfer, scheduler);
}
+QWidget * TransferMultiSegKioFactory::dlgSettings()
+{
+ QWidget *dlg = new QWidget();
+ Ui::DlgMultiSeg DlgMultiSeg;
+ DlgMultiSeg.setupUi(dlg);
+ return dlg;
+}
+
QWidget * TransferMultiSegKioFactory::createDetailsWidget( TransferHandler * transfer )
{
- Q_UNUSED(transfer);
- return new QWidget(); //Temporary!!
+ Q_UNUSED(transfer);
+ return new QWidget(); //Temporary!!
}
const QList<KAction *> TransferMultiSegKioFactory::actions()
{
- return QList<KAction *>();
+ return QList<KAction *>();
}
--- branches/work/make_kget_cool/kget/transfers/multisegmentkio/transferMultiSegKioFactory.h #614834:614835
@@ -19,20 +19,22 @@
class TransferMultiSegKioFactory : public TransferFactory
{
- public:
- TransferMultiSegKioFactory();
- ~TransferMultiSegKioFactory();
+ public:
+ TransferMultiSegKioFactory();
+ ~TransferMultiSegKioFactory();
- Transfer * createTransfer( KUrl srcUrl, KUrl destUrl,
- TransferGroup * parent, Scheduler * scheduler,
- const QDomElement * e = 0 );
+ Transfer * createTransfer( KUrl srcUrl, KUrl destUrl,
+ TransferGroup * parent, Scheduler * scheduler,
+ const QDomElement * e = 0 );
- TransferHandler * createTransferHandler(Transfer * transfer,
- Scheduler * scheduler);
+ TransferHandler * createTransferHandler(Transfer * transfer,
+ Scheduler * scheduler);
- QWidget * createDetailsWidget( TransferHandler * transfer );
+ QWidget * TransferMultiSegKioFactory::dlgSettings();
- const QList<KAction *> actions();
+ QWidget * createDetailsWidget( TransferHandler * transfer );
+
+ const QList<KAction *> actions();
};
#endif
More information about the Kget
mailing list