Ejemplo n.º 1
0
void K3b::MusicBrainzJob::slotMbJobFinished( bool success )
{
    if( hasBeenCanceled() ) {
        emit canceled();
        jobFinished(false);
    }
    else {
        K3b::AudioTrack* currentTrack = d->tracks.at( d->currentTrackIndex );

        if( success ) {
            // found entries
            QStringList resultStrings, resultStringsUnique;
            for( int i = 0; i < d->mbTrackLookupJob->results(); ++i )
                resultStrings.append( d->mbTrackLookupJob->artist(i) + " - " + d->mbTrackLookupJob->title(i) );

            // since we are only using the title and the artist a lot of entries are alike to us
            // so to not let the user have to choose between two equal entries we trim the list down
            for( QStringList::const_iterator it = resultStrings.constBegin();
                 it != resultStrings.constEnd(); ++it )
                if( !resultStringsUnique.contains( *it ) )
                    resultStringsUnique.append( *it );

            QString s;
            bool ok = true;
            if( resultStringsUnique.count() > 1 )
                s = KInputDialog::getItem( i18n("MusicBrainz Query"),
                                           i18n("Found multiple matches for track %1 (%2). Please select one.",
                                                currentTrack->trackNumber(),
                                                currentTrack->firstSource()->sourceComment()),
                                           resultStringsUnique,
                                           0,
                                           false,
                                           &ok,
                                           dynamic_cast<QWidget*>(parent()) );
            else
                s = resultStringsUnique.first();

            if( ok ) {
                int i = resultStrings.lastIndexOf( s );
                currentTrack->setTitle( d->mbTrackLookupJob->title(i) );
                currentTrack->setArtist( d->mbTrackLookupJob->artist(i) );
            }
        }

        emit trackFinished( currentTrack, success );

        // query next track
        ++d->currentTrackIndex;
        if( d->currentTrackIndex < d->tracks.count() ) {
            d->mbTrackLookupJob->setAudioTrack( d->tracks.at( d->currentTrackIndex ) );
            d->mbTrackLookupJob->start();
        }
        else {
            jobFinished( true );
        }
    }
}
Ejemplo n.º 2
0
void K3b::AudioCueFileWritingJob::importCueInProject()
{
    // cleanup the project (this wil also delete the decoder)
    // we do not use newDocument as that would overwrite the settings already made
    while( d->audioDoc->firstTrack() )
        delete d->audioDoc->firstTrack()->take();

    d->decoder = 0;

    K3b::CueFileParser parser( d->cueFile );
    if( parser.isValid() && parser.toc().contentType() == K3b::Device::AUDIO ) {

        kDebug() << "(K3b::AudioCueFileWritingJob::importCueFile) parsed with image: " << parser.imageFilename();

        // global cd-text
        d->audioDoc->setTitle( parser.cdText().title() );
        d->audioDoc->setPerformer( parser.cdText().performer() );
        d->audioDoc->writeCdText( !parser.cdText().title().isEmpty() );

        d->decoder = K3b::AudioDecoderFactory::createDecoder( parser.imageFilename() );
        if( d->decoder ) {
            d->decoder->setFilename( parser.imageFilename() );

            K3b::AudioTrack* after = 0;
            K3b::AudioFile* newFile = 0;
            unsigned int i = 0;
            for( K3b::Device::Toc::const_iterator it = parser.toc().constBegin();
                 it != parser.toc().constEnd(); ++it ) {
                const K3b::Device::Track& track = *it;

                newFile = new K3b::AudioFile( d->decoder, d->audioDoc );
                newFile->setStartOffset( track.firstSector() );
                newFile->setEndOffset( track.lastSector()+1 );

                K3b::AudioTrack* newTrack = new K3b::AudioTrack( d->audioDoc );
                newTrack->addSource( newFile );
                newTrack->moveAfter( after );

                // cd-text
                newTrack->setTitle( parser.cdText()[i].title() );
                newTrack->setPerformer( parser.cdText()[i].performer() );

                // add the next track after this one
                after = newTrack;
                ++i;
            }

            // let the last source use the data up to the end of the file
            if( newFile )
                newFile->setEndOffset(0);

            // now analyze the source
            emit newTask( i18n("Analysing the audio file") );
            emit newSubTask( i18n("Analysing %1", parser.imageFilename() ) );

            // start the analyser job
            d->analyserJob->setDecoder( d->decoder );
            d->analyserJob->start();
        }
        else {
            emit infoMessage( i18n("Unable to handle '%1' due to an unsupported format.", d->cueFile ), MessageError );
            jobFinished(false);
        }
    }
    else {
        emit infoMessage( i18n("No valid audio cue file: '%1'", d->cueFile ), MessageError );
        jobFinished(false);
    }
}