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); }
void K3bMixedJob::start() { jobStarted(); m_canceled = false; m_errorOccuredAndAlreadyReported = false; d->copiesDone = 0; d->copies = m_doc->copies(); m_currentAction = PREPARING_DATA; d->maxSpeed = false; if( m_doc->dummy() ) d->copies = 1; prepareProgressInformation(); // // Check if all files exist // QValueList<K3bAudioFile*> nonExistingFiles; K3bAudioTrack* track = m_doc->audioDoc()->firstTrack(); while( track ) { K3bAudioDataSource* source = track->firstSource(); while( source ) { if( K3bAudioFile* file = dynamic_cast<K3bAudioFile*>( source ) ) { if( !QFile::exists( file->filename() ) ) nonExistingFiles.append( file ); } source = source->next(); } track = track->next(); } if( !nonExistingFiles.isEmpty() ) { if( questionYesNo( "<p>" + i18n("The following files could not be found. Do you want to remove them from the " "project and continue without adding them to the image?") + "<p>" + createNonExistingFilesString( nonExistingFiles, 10 ), i18n("Warning"), i18n("Remove missing files and continue"), i18n("Cancel and go back") ) ) { for( QValueList<K3bAudioFile*>::const_iterator it = nonExistingFiles.begin(); it != nonExistingFiles.end(); ++it ) { delete *it; } } else { m_canceled = true; emit canceled(); jobFinished(false); return; } } // // Make sure the project is not empty // if( m_doc->audioDoc()->numOfTracks() == 0 ) { emit infoMessage( i18n("Please add files to your project first."), ERROR ); jobFinished(false); return; } // set some flags that are needed m_doc->audioDoc()->setOnTheFly( m_doc->onTheFly() ); // for the toc writer m_doc->audioDoc()->setHideFirstTrack( false ); // unsupported m_doc->dataDoc()->setBurner( m_doc->burner() ); // so the isoImager can read ms data emit newTask( i18n("Preparing data") ); determineWritingMode(); // // First we make sure the data portion is valid // // we do not have msinfo yet m_currentAction = INITIALIZING_IMAGER; m_isoImager->setMultiSessionInfo( QString::null ); m_isoImager->init(); }