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);
void setInterval(int msec)
void clear()
QDomNodeList elementsByTagName(const QString &tagname) const
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
const Key key(const T &value) const
QDomNode appendChild(const QDomNode &newChild)
bool resize(qint64 sz)
QString attribute(const QString &name, const QString &defValue) const
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
void removeFirst()
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
const T & at(int i) const
void removeAt(int i)
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
bool exists() const
This Class is an interface for inter-plugins data change.
Definition: transferdatasource.h:26
int count(const Key &key) const
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
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
int size() const
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
int indexOf(const T &value, int from) const
virtual void stop()=0
QDomElement toElement() const
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
int count() const
QString number(int n, int base)
Definition: transfer.h:49
int count(const T &value) const
void append(const T &value)
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
const_iterator constEnd() const
QDomDocument ownerDocument() const
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.
QString text() const
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
bool hasAttribute(const QString &name) const
void setAttribute(const QString &name, const QString &value)
void log(const QString &message, Transfer::LogLevel logLevel)
int toInt(bool *ok, int base) const
bool isEmpty() const
iterator begin()
T & first()
Definition: transfer.h:76
int remove(const Key &key)
qulonglong toULongLong(bool *ok, int base) const
QList< Key > keys() const
virtual int changeNeeded() const
Returns the missmatch of paralellSegments() and currentSegments()
Definition: transferdatasource.cpp:83
const T value(const Key &key) const
bool contains(const T &value) const
void stop()
Definition: transfer.h:56
bool isNull() const
The job exited from its Running state successfully but wants to be restarted by the scheduler...
Definition: job.h:50
const_iterator constBegin() const
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
T take(const Key &key)
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
T takeFirst()
bool isEmpty() const
bool setNewDestination(const KUrl &newDest)
Definition: datasourcefactory.cpp:823
QDomElement firstChildElement(const QString &tagName) const
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
T * data()
void start(int msec)
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
bool contains(const Key &key) const
Definition: transfer.h:63
void capabilitiesChanged()
uint length() const
bool doDownload() const
Returns whether the datasourcefactory should download the file or not, true by default.
Definition: datasourcefactory.h:141
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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
qlonglong toLongLong(bool *ok, int base) const
void destroyed(QObject *obj)
bool mkpath(const QString &dirPath) const
virtual void setSupposedSize(KIO::filesize_t supposedSize)
Set the size the server used for downloading should report.
Definition: transferdatasource.h:88
QDomNode at(int index) const
Definition: transfer.h:51
Definition: transfer.h:36
singleShot
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-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:43 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.