scancontroller.cpp

来自「Amarok是一款在LINUX或其他类UNIX操作系统中运行的音频播放器软件。 」· C++ 代码 · 共 554 行 · 第 1/2 页

CPP
554
字号
    }    if( !isAborted() ) {        if( m_scanner->normalExit() && !m_scanner->signalled() ) {            CollectionDB::instance()->sanitizeCompilations();            if ( m_incremental ) {                m_foldersToRemove += m_folders;                foreach( m_foldersToRemove ) {                    m_fileMapsMutex.lock();                    CollectionDB::instance()->removeSongsInDir( *it, &m_filesDeleted );                    m_fileMapsMutex.unlock();                    CollectionDB::instance()->removeDirFromCollection( *it );                }                CollectionDB::instance()->removeOrphanedEmbeddedImages();            }            else                CollectionDB::instance()->clearTables( false ); // empty permanent tables            CollectionDB::instance()->copyTempTables(); // copy temp into permanent tables            //Clean up unused entries in the main tables (eg artist, composer)            CollectionDB::instance()->deleteAllRedundant( "artist" );            CollectionDB::instance()->deleteAllRedundant( "composer" );            CollectionDB::instance()->deleteAllRedundant( "year" );            CollectionDB::instance()->deleteAllRedundant( "genre" );            CollectionDB::instance()->deleteAllRedundant( "album" );            //Remove free space and fragmentation in the DB. Used to run on shutdown, but            //that took too long, sometimes causing Amarok to be killed.            CollectionDB::instance()->vacuum();        }        else {            if( m_crashedFiles.size() <= MAX_RESTARTS ||                    m_crashedFiles.size() <= (m_scanCount * MAX_FAILURE_PERCENTAGE) / 100 ) {                kapp->postEvent( this, new RestartEvent() );                sleep( 3 );            }            else                m_aborted = true;            goto main_loop;        }    }    if( CollectionDB::instance()->isConnected() )    {        m_tablesCreated = false;        CollectionDB::instance()->dropTables( true ); // drop temp tables    }    setProgress100Percent();    return !isAborted();}voidScanController::slotReadReady(){    QString line;    m_dataMutex.lock();    while( m_scanner->readln( line, true, 0 ) != -1 ) {        if( !line.startsWith( "exepath=" ) ) // skip binary location info from scanner            m_xmlData += line;    }    m_dataMutex.unlock();}boolScanController::requestPause(){    DEBUG_BLOCK    debug() << "Attempting to pause the collection scanner..." << endl;    DCOPRef dcopRef( "amarokcollectionscanner", "scanner" );    m_lastCommandPaused = true;    return dcopRef.send( "pause" );}boolScanController::requestUnpause(){    DEBUG_BLOCK    debug() << "Attempting to unpause the collection scanner..." << endl;    DCOPRef dcopRef( "amarokcollectionscanner", "scanner" );    m_lastCommandPaused = false;    return dcopRef.send( "unpause" );}voidScanController::requestAcknowledged(){    DEBUG_BLOCK    if( m_waitingBundle )        m_waitingBundle->scannerAcknowledged();    if( m_lastCommandPaused )        m_isPaused = true;    else        m_isPaused = false;}voidScanController::slotFileMoved( const QString &/*src*/, const QString &/*dest*/){    //why is this needed?  QBob, take a look at this    /*    if( m_incremental ) // pedantry      {        m_fileMapsMutex.lock();        m_filesFound[ src ] = true;        m_fileMapsMutex.unlock();      }    */}voidScanController::notifyThisBundle( MetaBundle* bundle ){    DEBUG_BLOCK    m_waitingBundle = bundle;    debug() << "will notify " << m_waitingBundle << endl;}boolScanController::startElement( const QString&, const QString& localName, const QString&, const QXmlAttributes& attrs ){    // List of entity names:    //    // itemcount     Number of files overall    // folder        Folder which is being processed    // dud           Invalid audio file    // tags          Valid audio file with metadata    // playlist      Playlist file    // image         Cover image    // compilation   Folder to check for compilation    // filesize      Size of the track in bytes    if( localName == "dud" || localName == "tags" || localName == "playlist" ) {        incrementProgress();    }    if( localName == "itemcount") {        const int totalSteps = attrs.value( "count" ).toInt();        debug() << "itemcount event: " << totalSteps << endl;        setProgressTotalSteps( totalSteps );    }    else if( localName == "tags") {        MetaBundle bundle;        bundle.setPath      ( attrs.value( "path" ) );        bundle.setTitle     ( attrs.value( "title" ) );        bundle.setArtist    ( attrs.value( "artist" ) );        bundle.setComposer  ( attrs.value( "composer" ) );        bundle.setAlbum     ( attrs.value( "album" ) );        bundle.setComment   ( attrs.value( "comment" ) );        bundle.setGenre     ( attrs.value( "genre" ) );        bundle.setYear      ( attrs.value( "year" ).toInt() );        bundle.setTrack     ( attrs.value( "track" ).toInt() );        bundle.setDiscNumber( attrs.value( "discnumber" ).toInt() );        bundle.setBpm       ( attrs.value( "bpm" ).toFloat() );        bundle.setFileType( attrs.value( "filetype" ).toInt() );        bundle.setUniqueId( attrs.value( "uniqueid" ) );        bundle.setCompilation( attrs.value( "compilation" ).toInt() );        if( attrs.value( "audioproperties" ) == "true" ) {            bundle.setBitrate   ( attrs.value( "bitrate" ).toInt() );            bundle.setLength    ( attrs.value( "length" ).toInt() );            bundle.setSampleRate( attrs.value( "samplerate" ).toInt() );        }        if( !attrs.value( "filesize" ).isNull()                && !attrs.value( "filesize" ).isEmpty() )        {            bundle.setFilesize( attrs.value( "filesize" ).toInt() );        }        CollectionDB::instance()->addSong( &bundle, m_incremental );        if( !bundle.uniqueId().isEmpty() )        {            m_fileMapsMutex.lock();            m_filesAdded[bundle.uniqueId()] = bundle.url().path();            m_fileMapsMutex.unlock();        }        m_scanCount++;    }    else if( localName == "folder" ) {        const QString folder = attrs.value( "path" );        const QFileInfo info( folder );        // Update dir statistics for rescanning purposes        if( info.exists() )            CollectionDB::instance()->updateDirStats( folder, info.lastModified().toTime_t(), true);        if( m_incremental ) {            m_foldersToRemove += folder;        }    }    else if( localName == "playlist" )        QApplication::postEvent( PlaylistBrowser::instance(), new PlaylistFoundEvent( attrs.value( "path" ) ) );    else if( localName == "compilation" )        CollectionDB::instance()->checkCompilations( attrs.value( "path" ), !m_incremental);    else if( localName == "image" ) {        // Deserialize CoverBundle list        QStringList list = QStringList::split( "AMAROK_MAGIC", attrs.value( "list" ), true );        QValueList< QPair<QString, QString> > covers;        for( uint i = 0; i < list.count(); ) {            covers += qMakePair( list[i], list[i + 1] );            i += 2;        }        CollectionDB::instance()->addImageToAlbum( attrs.value( "path" ), covers, CollectionDB::instance()->isConnected() );    }    else if( localName == "embed" ) {        CollectionDB::instance()->addEmbeddedImage( attrs.value( "path" ), attrs.value( "hash" ), attrs.value( "description" ) );    }    return true;}voidScanController::customEvent( QCustomEvent* e ){    if( e->type() == RestartEventType )    {        debug() << "RestartEvent received." << endl;        QFile log( Amarok::saveLocation( QString::null ) + "collection_scan.log" );        if ( !log.open( IO_ReadOnly ) )        ::warning() << "Failed opening log file " << log.name() << endl;        else {            QCString path = QCString(log.readAll());            m_crashedFiles << QString::fromUtf8( path, path.length() );        }        m_dataMutex.lock();        m_xmlData = QString::null;        delete m_source;        m_source = new QXmlInputSource();        m_dataMutex.unlock();        delete m_reader;        m_reader = new QXmlSimpleReader();        m_reader->setContentHandler( this );        m_reader->parse( m_source, true );        delete m_scanner; // Reusing doesn't work, so we have to destroy and reinstantiate        m_scanner = new Amarok::ProcIO();        connect( m_scanner, SIGNAL( readReady( KProcIO* ) ), SLOT( slotReadReady() ) );        *m_scanner << "amarokcollectionscanner";        *m_scanner << "--nocrashhandler"; // We want to be able to catch SIGSEGV        if( m_incremental )            *m_scanner << "-i";        *m_scanner << "-p";        *m_scanner << "-s";        m_scanner->start();    }    else        ThreadManager::Job::customEvent( e );}#include "scancontroller.moc"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?