kget
datasourcefactory.cpp
Go to the documentation of this file.
39 DataSourceFactory::DataSourceFactory(QObject *parent, const KUrl &dest, KIO::filesize_t size, KIO::fileoffset_t segSize)
70 kDebug(5001) << "Initialize DataSourceFactory: Dest: " + m_dest.url() + "Size: " + QString::number(m_size) + "SegSize: " + QString::number(m_segSize);
125 connect(source, SIGNAL(foundFileSize(TransferDataSource*,KIO::filesize_t,QPair<int,int>)), this, SLOT(slotFoundFileSize(TransferDataSource*,KIO::filesize_t,QPair<int,int>)));
126 connect(source, SIGNAL(finishedDownload(TransferDataSource*,KIO::filesize_t)), this, SLOT(slotFinishedDownload(TransferDataSource*,KIO::filesize_t)));
138 void DataSourceFactory::slotFoundFileSize(TransferDataSource *source, KIO::filesize_t fileSize, const QPair<int, int> &segmentRange)
141 kDebug(5001) << source << "found size" << m_size << "and is assigned segments" << segmentRange << this;
279 KMessageBox::error(0, i18n("Filesize is larger than maximum file size supported by VFAT."), i18n("Error"));
317 connect(m_putJob, SIGNAL(position(KIO::Job*,KIO::filesize_t)), this, SLOT(slotOffset(KIO::Job*,KIO::filesize_t)));
318 connect(m_putJob, SIGNAL(written(KIO::Job*,KIO::filesize_t)), this, SLOT(slotDataWritten(KIO::Job*,KIO::filesize_t)));
383 void DataSourceFactory::addMirror(const KUrl &url, bool used, int numParalellConnections, bool usedDefined)
445 connect(source, SIGNAL(brokenSegments(TransferDataSource*,QPair<int,int>)), this, SLOT(brokenSegments(TransferDataSource*,QPair<int,int>)));
446 connect(source, SIGNAL(broken(TransferDataSource*,TransferDataSource::Error)), this, SLOT(broken(TransferDataSource*,TransferDataSource::Error)));
447 connect(source, SIGNAL(finishedSegment(TransferDataSource*,int,bool)), this, SLOT(finishedSegment(TransferDataSource*,int,bool)));
448 connect(source, SIGNAL(data(KIO::fileoffset_t,QByteArray,bool&)), this, SLOT(slotWriteData(KIO::fileoffset_t,QByteArray,bool&)));
449 connect(source, SIGNAL(freeSegments(TransferDataSource*,QPair<int,int>)), this, SLOT(slotFreeSegments(TransferDataSource*,QPair<int,int>)));
450 connect(source, SIGNAL(log(QString,Transfer::LogLevel)), this, SIGNAL(log(QString,Transfer::LogLevel)));
597 void DataSourceFactory::brokenSegments(TransferDataSource *source, const QPair<int, int> &segmentRange)
600 if (!source || !m_startedChunks || !m_finishedChunks || (segmentRange.first < 0) || (segmentRange.second < 0) || (static_cast<quint32>(segmentRange.second) > m_finishedChunks->getNumBits()))
624 KMessageBox::error(0, i18nc("A mirror is removed when the file has the wrong download size", "%1 removed as it did report a wrong file size.", url), i18n("Error"));
628 void DataSourceFactory::slotFreeSegments(TransferDataSource *source, QPair<int, int> segmentRange)
642 void DataSourceFactory::finishedSegment(TransferDataSource *source, int segmentNumber, bool connectionFinished)
644 if (!source || (segmentNumber < 0) || (static_cast<quint32>(segmentNumber) > m_finishedChunks->getNumBits()))
722 //the lastSegsize is rest, but only if there is a rest and it is the last segment of the download
723 const KIO::fileoffset_t lastSegSize = ((static_cast<uint>(newEnd + 1) == m_startedChunks->getNumBits() && rest) ? rest : m_segSize);
725 kDebug(5001) << "Segments assigned:" << newStart << "-" << newEnd << "segment-size:" << m_segSize << "rest:" << rest;
735 //TODO implement checks if the correct offsets etc. are used + error recovering e.g. when something else
737 void DataSourceFactory::slotWriteData(KIO::fileoffset_t offset, const QByteArray &data, bool &worked)
791 m_speed = (m_downloadedSize - m_prevDownloadedSizes.first()) / (SPEEDTIMER * m_prevDownloadedSizes.size() / 1000);//downloaded in 1 second
801 Transfer::ChangesFlags change = (percentChanged ? (Transfer::Tc_DownloadSpeed | Transfer::Tc_Percent) : Transfer::Tc_DownloadSpeed);
898 connect(verifier(), SIGNAL(brokenPieces(QList<KIO::fileoffset_t>,KIO::filesize_t)), this, SLOT(slotRepair(QList<KIO::fileoffset_t>,KIO::filesize_t)));
903 void DataSourceFactory::slotRepair(const QList<KIO::fileoffset_t> &offsets, KIO::filesize_t length)
905 disconnect(verifier(), SIGNAL(brokenPieces(QList<KIO::fileoffset_t>,KIO::filesize_t)), this, SLOT(slotRepair(QList<KIO::fileoffset_t>,KIO::filesize_t)));
932 const QList<KUrl> mirrors = m_sources.keys();//FIXME only remove the mirrors of the broken segments?! --> for that m_assignedChunks would need to be saved was well
1155 //the lastSegsize is rest, but only if there is a rest and it is the last segment of the download
1160 factory.setAttribute("processedSize", m_segSize * (m_finishedChunks->numOnBits() - lastOn) + lastOn * lastSegSize);
Definition: transfer.h:52
The job is stopped, but this also indicates that it stopped because an error occurred.
Definition: job.h:47
void setMirrors(const QHash< KUrl, QPair< bool, int > > &mirrors)
Sets the mirrors that should be used/not used for downloading.
Definition: datasourcefactory.cpp:538
void setRange(quint32 start, quint32 end, bool value)
Sets the value of a range of bits.
Definition: bitset.h:170
void verify(const QModelIndex &index=QModelIndex())
Call this method if you want to verify() in its own thread, then signals with the result are emitted...
Definition: verifier.cpp:364
virtual void start()=0
Definition: transfer.h:75
void getContinuousRange(qint32 *start, qint32 *end, bool on)
Finds a continous rang of bits that on/off.
Definition: bitset.cpp:80
Definition: transfer.h:74
This class manages multiple DataSources and saves the received data to the file.
Definition: datasourcefactory.h:38
QHash< KUrl, QPair< bool, int > > mirrors() const
Return all mirrors, where bool defines if the mirror is used, while in defines the number of paralell...
Definition: datasourcefactory.cpp:565
Definition: transfer.h:77
void dataSourceFactoryChange(Transfer::ChangesFlags change)
virtual void findFileSize(KIO::fileoffset_t segmentSize)
Tries to find the filesize if this capability is supported, if successfull it emits foundFileSize(Tra...
Definition: transferdatasource.cpp:43
static bool checksumAutomaticVerification()
Get ChecksumAutomaticVerification.
Definition: settings.h:1019
This Class is an interface for inter-plugins data change.
Definition: transferdatasource.h:26
void repair()
Tries to repair a broken download, via completely redownloading it or only the borken parts...
Definition: datasourcefactory.cpp:889
Definition: mirrors.h:17
Transfer::Capabilities capabilities() const
The capabilities the DataSourceFactory supports.
Definition: datasourcefactory.h:55
static KJob * deleteFile(const KUrl &dest, QObject *receiver=0, const char *method=0)
Starts the deletion of dest and emits KJob::finished once done.
Definition: filedeleter.cpp:73
virtual void stop()=0
Definition: transfer.h:53
virtual QList< QPair< int, int > > assignedSegments() const
Returns the assignedSegments to this TransferDataSource Each connection is represented by a QPair...
Definition: transferdatasource.cpp:53
DataSourceFactory(QObject *parent, const KUrl &dest=KUrl(), KIO::filesize_t size=0, KIO::fileoffset_t segSize=512000)
In general use this constructor, if the size is 0, the datasourcefactory will try to find the filesiz...
Definition: datasourcefactory.cpp:39
Definition: transfer.h:49
Definition: job.h:43
void addMirror(const KUrl &url, bool used, int numParalellConnections=1)
Add a mirror that can be used for downloading.
Definition: datasourcefactory.cpp:378
virtual void addSegments(const QPair< KIO::fileoffset_t, KIO::fileoffset_t > &segmentSize, const QPair< int, int > &segmentRange)=0
Adds multiple continuous segments that should be downloaded by this TransferDataSource.
Definition: transfer.h:73
void setDoDownload(bool doDownload)
Set if the datasourcefactory should download the file or not, if set to false the download will be st...
Definition: datasourcefactory.cpp:350
void log(const QString &message, Transfer::LogLevel logLevel)
Definition: transfer.h:76
virtual int changeNeeded() const
Returns the missmatch of paralellSegments() and currentSegments()
Definition: transferdatasource.cpp:83
Definition: transfer.h:56
The job exited from its Running state successfully but wants to be restarted by the scheduler...
Definition: job.h:50
static bool signatureAutomaticVerification()
Get SignatureAutomaticVerification.
Definition: settings.h:1057
Definition: verifier.h:68
void removeMirror(const KUrl &url)
Does not use the specified mirror for downloading the file.
Definition: datasourcefactory.cpp:503
static TransferDataSource * createTransferDataSource(const KUrl &src, const QDomElement &type=QDomElement(), QObject *parent=0)
Scans for all the available plugins and creates the proper transfer DataSource object for transfers C...
Definition: kget.cpp:931
virtual int countUnfinishedSegments() const
Returns the number of unfinished Segments of the connection with the most unfinished segments Each Tr...
Definition: transferdatasource.cpp:58
virtual QPair< int, int > split()
If a connection of this TransferDataSource is assigned multiple (continuous) segments, then this method will split them (the unfinished ones) in half, it returns the beginning and the end of the now unassigned segments; (-1, -1) if there are none.
Definition: transferdatasource.cpp:63
bool setNewDestination(const KUrl &newDest)
Definition: datasourcefactory.cpp:823
virtual void setParalellSegments(int paralellSegments)
Sets the number of paralell segments this DataSource is allowed to use.
Definition: transferdatasource.cpp:73
Transfer::Capabilities capabilities() const
Returns the capabilities this TransferDataSource supports.
Definition: transferdatasource.cpp:32
Definition: transfer.h:54
Definition: transfer.h:55
virtual QPair< int, int > removeConnection()
Removes one connection, useful when setMaximumParalellDownloads was called with a lower number...
Definition: transferdatasource.cpp:48
Definition: transfer.h:63
void capabilitiesChanged()
bool doDownload() const
Returns whether the datasourcefactory should download the file or not, true by default.
Definition: datasourcefactory.h:141
void deinit()
Deletes the created (downloadInitialized() is true) file if the download was not finished Does not de...
Definition: datasourcefactory.cpp:112
Definition: verifier.h:79
virtual int paralellSegments() const
Definition: transferdatasource.cpp:68
virtual void setSupposedSize(KIO::filesize_t supposedSize)
Set the size the server used for downloading should report.
Definition: transferdatasource.h:88
Definition: transfer.h:51
Definition: transfer.h:36
void brokenPieces() const
Call this method after calling verify() with a negative result, it will emit a list of the broken pie...
Definition: verifier.cpp:386
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:17 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.