// 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++] = processedAmount(Bytes) - 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] = processedAmount(Bytes) - d->bytes; } emit speed(this, lspeed); } }
void KrPreviewJob::slotGotPreview(const KFileItem & item, const QPixmap & preview) { KrViewItem *vi = _hash[item]; ASSERT(vi); _scheduled.removeOne(vi); const vfile *file = vi->getVfile(); _parent->addPreview(file, preview); vi->redraw(); setProcessedAmount(KJob::Files, processedAmount(KJob::Files) + 1); emitPercent(processedAmount(KJob::Files), totalAmount(KJob::Files)); }
void KonqMultiRestoreJob::slotStart() { if (m_urlsIterator == m_urls.begin()) // first time: emit total setTotalAmount(KJob::Files, m_urls.count()); if (m_urlsIterator != m_urls.end()) { const QUrl &url = *m_urlsIterator; QUrl new_url = url; if (new_url.scheme() == QStringLiteral("system") && new_url.path().startsWith(QLatin1String("/trash"))) { QString path = new_url.path(); path.remove(0, 6); new_url.setScheme(QStringLiteral("trash")); new_url.setPath(path); } Q_ASSERT(new_url.scheme() == QStringLiteral("trash")); QByteArray packedArgs; QDataStream stream(&packedArgs, QIODevice::WriteOnly); stream << (int)3 << new_url; KIO::Job* job = KIO::special(new_url, packedArgs, KIO::HideProgressInfo); addSubjob(job); setProcessedAmount(KJob::Files, processedAmount(KJob::Files) + 1); } else { // done! emitResult(); } }
void MultiSegmentCopyJob::slotOpen( KIO::Job * job) { Q_UNUSED(job); kDebug(5001); if( SegFactory->startTransfer() ) { gettimeofday(&d->start_time, 0); d->last_time = 0; d->sizes[0] = processedAmount(Bytes) - d->bytes; d->times[0] = 0; d->nums = 1; d->speed_timer.start(1000); return; } SegData data; m_firstSeg = SegFactory->createSegment(data, SegFactory->nextUrl() ); connect( m_firstSeg->job(), SIGNAL(totalSize( KJob *, qulonglong )), SLOT(slotTotalSize( KJob *, qulonglong ))); m_firstSeg->startTransfer(); if( MultiSegKioSettings::useSearchEngines() && !(SegFactory->Urls().size() > 1) ) { kDebug(5001) << "waiting 30 seg for the mirror search result..."; QTimer::singleShot(30000, this, SLOT(slotSplitSegment())); } }
void Kopete::Transfer::slotProcessed( unsigned int bytes ) { if ( !d->transferRateTimer ) d->transferRateTimer = startTimer( TransferRateTimerDelay ); d->transferRate[0] += (bytes - processedAmount(KJob::Bytes)); setProcessedAmount( KJob::Bytes, bytes ); emitPercent( bytes, d->info.size() ); }
void MultiSegmentCopyJob::slotClose( KIO::Job * ) { kDebug(5001) << " putjob"; if( processedAmount(Bytes) == totalAmount(Bytes) ) { kDebug(5001) << "Renaming local file."; QString dest_orig = m_dest.path(); QString dest_part = m_dest_part.path(); if ( QFile::exists (dest_orig) ) { QFile::remove (dest_orig); } QFile::rename ( dest_part, dest_orig ); } emit updateSegmentsData(); }
void KJob::setProcessedAmount(Unit unit, qulonglong amount) { Q_D(KJob); bool should_emit = (d->processedAmount[unit] != amount); d->processedAmount[unit] = amount; if ( should_emit ) { emit processedAmount(this, unit, amount); if (unit==d->progressUnit) { emit processedSize(this, amount); emitPercent(d->processedAmount[unit], d->totalAmount[unit]); } } }
void MultiSegmentCopyJob::slotTotalSize( KJob *job, qulonglong size ) { kDebug(5001) << " from job: " << job << " -- " << size; setTotalAmount (Bytes, size); Q_ASSERT( m_firstSeg ); m_firstSeg->setBytes( size - m_firstSeg->BytesWritten() ); gettimeofday(&d->start_time, 0); d->last_time = 0; d->sizes[0] = processedAmount(Bytes) - d->bytes; d->times[0] = 0; d->nums = 1; d->speed_timer.start(1000); if(!MultiSegKioSettings::useSearchEngines() || (SegFactory->Urls().size() > 1)) { kDebug(5001) << "slotSplitSegment() now"; slotSplitSegment(); } }
void MultiSegmentCopyJob::slotDataReq( Segment *seg, const QByteArray &data, bool &result) { // kDebug(5001) << "MultiSegmentCopyJob::slotDataReq() "; if ( m_writeBlocked ) { result = false; return; } m_writeBlocked = true; m_putJob->seek(seg->offset()); m_putJob->write(data); result = true; m_chunkSize += data.size(); if( m_chunkSize > (uint)MultiSegKioSettings::saveSegSize() * 1024) { emit updateSegmentsData(); m_chunkSize = 0; } setProcessedAmount(Bytes, processedAmount(Bytes)+data.size()); }
void Kopete::Transfer::slotNextFile( const QString &sourceFile, const QString &destinationFile ) { KUrl src; KUrl dest; kDebug() << "source: " << sourceFile << " destination: " << destinationFile; if( d->info.direction() == Kopete::FileTransferInfo::Incoming ) { KUrl url( sourceFile ); src = displayURL( d->info.contact(), url.fileName() ); dest.setPath( destinationFile ); } else { src.setPath( sourceFile ); KUrl url( destinationFile ); dest = displayURL( d->info.contact(), url.fileName() ); } setProcessedAmount( KJob::Files, processedAmount(KJob::Files) + 1 ); emit description(this, i18n("Copying"), qMakePair(i18n("Source"), src.prettyUrl()), qMakePair(i18n("Destination"), dest.prettyUrl())); }
void MultiSegmentCopyJob::slotWritten( KIO::Job * ,KIO::filesize_t bytesWritten) { if( processedAmount(Bytes) == totalAmount(Bytes) ) m_putJob->close(); m_writeBlocked = false; }