Example #1
0
void ResourceTask::itemRetrieved(const Akonadi::Item &item)
{
    if (!mCancelled) {
        m_resource->itemRetrieved(item);
        emitPercent(100);
    }
    deleteLater();
}
void BackupRestorationJob::doWork()
{
    kDebug() << "RESTORING!!!";
    connect( m_storageService, SIGNAL(resetRepositoryDone(QString, QString)), this, SLOT(slotRestRepo(QString, QString)) );
    QTimer::singleShot(0, m_storageService, SLOT(resetRepository()) );

    // Gives the users a sense that something is happening
    emitPercent( 3, 100 );
}
Example #3
0
void K3bAudioMaxSpeedJob::WorkThread::run()
{
  kdDebug() << k_funcinfo << endl;
  m_canceled = false;

  emitStarted();

  K3bAudioDataSourceIterator it( m_doc );

  // count sources for minimal progress info
  int numSources = 0;
  int sourcesDone = 0;
  while( it.current() ) {
    ++numSources;
    it.next();
  }

  bool success = true;
  maxSpeed = 175*1000;
  it.first();

  while( it.current() && !m_canceled ) {
    if( !it.current()->seek(0) ) {
      kdDebug() << "(K3bAudioMaxSpeedJob) seek failed." << endl;
      success = false;
      break;
    }
      
    // read some data
    int speed = speedTest( it.current() );

    ++sourcesDone;
    emitPercent( 100*numSources/sourcesDone );

    if( speed < 0 ) {
      success = false;
      break;
    }
    else if( speed > 0 ) {
      // update the max speed
      maxSpeed = QMIN( maxSpeed, speed );
    }
      
    it.next();
  }

  if( m_canceled ) {
    emitCanceled();
    success = false;
  }

  if( success )
    kdDebug() << "(K3bAudioMaxSpeedJob) max speed: " << maxSpeed << endl;

  emitFinished( success );
}
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() );
}
Example #5
0
void KonqMultiRestoreJob::slotResult(KJob *job)
{
    if (job->error()) {
        KIO::Job::slotResult(job);   // will set the error and emit result(this)
        return;
    }
    removeSubjob(job);
    // Move on to next one
    ++m_urlsIterator;
    ++m_progress;
    //emit processedSize( this, m_progress );
    emitPercent(m_progress, m_urls.count());
    slotStart();
}
Example #6
0
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));
}
Example #7
0
void KJob::setTotalAmount(Unit unit, qulonglong amount)
{
    Q_D(KJob);
    bool should_emit = (d->totalAmount[unit] != amount);

    d->totalAmount[unit] = amount;

    if ( should_emit )
    {
        emit totalAmount(this, unit, amount);
        if (unit==d->progressUnit) {
            emit totalSize(this, amount);
            emitPercent(d->processedAmount[unit], d->totalAmount[unit]);
        }
    }
}
void BackupRestorationJob::slotRestRepo(const QString&, const QString& newPath)
{
    m_oldRepoPath = newPath;

    BackupFile bf = BackupFile::fromUrl( m_url );
    Soprano::StatementIterator it = bf.iterator();

    kDebug() << "Restore Statements:" << bf.numStatements();
    int numStatements = 0;
    while( it.next() ) {
        Soprano::Statement st = it.current();
        if( st.predicate() == NIE::url() ) {
            QUrl url = st.object().uri();
            if( url.scheme() == QLatin1String("file") ) {
                //
                // Check if the file exists
                //
                if( !QFile::exists( url.toLocalFile() ) ) {
                    url = translateHomeUri( url );

                    // REMOVING THIS CHANGE TO nepomuk-backup because one can have removablemedia
                    // files which are currently not mounted. This change sucks but the restore
                    // utility will have to manually check each file
                    // if( !QFile::exists( url.toLocalFile() ) ) {
                    //    url.setScheme("nepomuk-backup");
                    // }
                    if( QFile::exists( url.toLocalFile() ) )
                        st.setObject( url );
                }
            }
        }

        Soprano::Error::ErrorCode err = m_model->addStatement( st );
        if( err ) {
            kWarning() << m_model->lastError();
            setErrorText( m_model->lastError().message() );
            emitResult();
            return;
        }

        numStatements++;
        emitPercent( numStatements, bf.numStatements() );
    }

    QTimer::singleShot(0, m_storageService, SLOT(openPublicInterfaces()) );
    emitResult();
}
Example #9
0
void FileCopyJob::copyFile()
{
    // Open the source file for reading
    QFile sourceFile(m_source);
    if (!sourceFile.open(QFile::ReadOnly)) {
        setError(CopySourceError);
        setErrorText(sourceFile.errorString());
        emitResult();
        return;
    }

    // Open destination file for writing
    QFile destinationFile(m_destination);
    if (!destinationFile.open(QFile::WriteOnly)) {
        setError(CopyDestinationError);
        setErrorText(destinationFile.errorString());
        emitResult();
        return;
    }

    qint64 total = sourceFile.size();
    qint64 bytesCopied = 0;

    while (!sourceFile.atEnd()) {
        // Read 8KB from the source file at once
        QByteArray data = sourceFile.read(8192);
        bytesCopied += data.size();

        // Write to the destination
        destinationFile.write(data);

        // Emit the percentage
        emitPercent(bytesCopied, total);
    }

    if (m_isMove) {
        // Remove the source file
        if (!sourceFile.remove()) {
            // The source file could not be removed hence we remove the destination
            // file and trigger an error
            destinationFile.remove();
            setError(MoveSourceError);
            setErrorText(sourceFile.errorString());
            return;
        }
    }
}
Example #10
0
void K3bAudioImager::WorkThread::run()
{
  m_canceled = false;

  emitStarted();

  lastError = K3bAudioImager::ERROR_UNKNOWN;

  //
  // 
  //
  QStringList::iterator imageFileIt = m_imageNames.begin();
  K3bWaveFileWriter waveFileWriter;

  K3bAudioTrack* track = m_doc->firstTrack();
  int trackNumber = 1;
  unsigned long long totalSize = m_doc->length().audioBytes();
  unsigned long long totalRead = 0;
  char buffer[2352 * 10];

  while( track ) {

    emitNextTrack( trackNumber, m_doc->numOfTracks() );

    //
    // Seek to the beginning of the track
    //
    if( !track->seek(0) ) {
      emitInfoMessage( i18n("Unable to seek in track %1.").arg(trackNumber), K3bJob::ERROR );
      emitFinished(false);
      return;
    }

    //
    // Initialize the reading
    //
    int read = 0;
    unsigned long long trackRead = 0;

    //
    // Create the image file
    //
    if( m_fd == -1 ) {
      if( !waveFileWriter.open( *imageFileIt ) ) {
	emitInfoMessage( i18n("Could not open %1 for writing").arg(*imageFileIt), K3bJob::ERROR );
	emitFinished(false);
	return;
      }
    }

    //
    // Read data from the track
    //
    while( (read = track->read( buffer, sizeof(buffer) )) > 0 ) {
      if( m_fd == -1 ) {
	waveFileWriter.write( buffer, read, K3bWaveFileWriter::BigEndian );
      }
      else {
	if( ::write( m_fd, reinterpret_cast<void*>(buffer), read ) != read ) {
	  kdDebug() << "(K3bAudioImager::WorkThread) writing to fd " << m_fd << " failed." << endl;
	  lastError = K3bAudioImager::ERROR_FD_WRITE;
	  emitFinished(false);
	  return;
	}
      }

      if( m_canceled ) {
	emitCanceled();
	emitFinished(false);
	return;
      }

      //
      // Emit progress
      //
      totalRead += read;
      trackRead += read;
	
      emitSubPercent( 100*trackRead/track->length().audioBytes() );
      emitPercent( 100*totalRead/totalSize );
      emitProcessedSubSize( trackRead/1024/1024, track->length().audioBytes()/1024/1024 );
      emitProcessedSize( totalRead/1024/1024, totalSize/1024/1024 );
    }

    if( read < 0 ) {
      emitInfoMessage( i18n("Error while decoding track %1.").arg(trackNumber), K3bJob::ERROR );
      kdDebug() << "(K3bAudioImager::WorkThread) read error on track " << trackNumber
		<< " at pos " << K3b::Msf(trackRead/2352) << endl;
      lastError = K3bAudioImager::ERROR_DECODING_TRACK;
      emitFinished(false);
      return;
    }

    track = track->next();
    trackNumber++;
    imageFileIt++;
  }

  emitFinished(true);
}