magnatunebrowser.cpp

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

CPP
521
字号
    MagnatuneListViewAlbumItem *selectedAlbum = dynamic_cast<MagnatuneListViewAlbumItem *>( m_listView->selectedItem() );    if (selectedAlbum)        m_purchaseHandler->purchaseAlbum( *selectedAlbum );}void MagnatuneBrowser::purchaseAlbumContainingSelectedTrack( ){    if ( !m_purchaseHandler )    {        m_purchaseHandler = new MagnatunePurchaseHandler();        m_purchaseHandler->setParent( this );        connect( m_purchaseHandler, SIGNAL( purchaseCompleted( bool ) ), this, SLOT( purchaseCompleted( bool ) ) );    }    MagnatuneListViewTrackItem *selectedTrack = dynamic_cast<MagnatuneListViewTrackItem *>( m_listView->selectedItem() );    if (!selectedTrack) {	debug() << "dynamic_cast to selected track failed!" << endl;	return;    }    MagnatuneAlbum album( MagnatuneDatabaseHandler::instance() ->getAlbumById( selectedTrack->getAlbumId() ) );    m_purchaseHandler->purchaseAlbum( album );}void MagnatuneBrowser::initTopPanel( ){    m_topPanel = new QHBox( this, "topPanel", 0 );    m_topPanel->setMaximumHeight( 24 );    m_topPanel->setSpacing( 2 );    m_topPanel->setMargin( 2 );    new QLabel ( i18n( "Genre: " ), m_topPanel, "genreLabel", 0 );    m_genreComboBox = new QComboBox( false, m_topPanel, "genreComboBox" );    updateGenreBox();    m_advancedFeaturesButton = new QPushButton( i18n( "Redownload" ), m_topPanel, "advancedButton" );    connect( m_advancedFeaturesButton, SIGNAL( clicked() ), this, SLOT( processRedownload() ) );    connect( m_genreComboBox, SIGNAL( activated ( int ) ), this, SLOT( genreChanged() ) );}void MagnatuneBrowser::initBottomPanel(){    m_bottomPanel = new QVBox( this, "bottomPanel", 0 );    m_bottomPanel->setMaximumHeight( 54 );    m_bottomPanel->setSpacing( 2 );    m_bottomPanel->setMargin( 2 );    QHBox *hBox = new QHBox( m_bottomPanel, "bottomHBox", 0 );    hBox->setMaximumHeight( 24 );    hBox->setSpacing( 2 );    //hBox->setMargin( 2 );    m_purchaseAlbumButton = new QPushButton( i18n( "Purchase Album" ), m_bottomPanel, "purchaseButton" );    m_purchaseAlbumButton->setIconSet( SmallIconSet( Amarok::icon( "download" ) ) );    m_purchaseAlbumButton->setEnabled( false );    m_purchaseAlbumButton->setMaximumHeight( 24 );    m_updateListButton = new QPushButton( i18n( "Update" ), hBox, "updateButton" );    m_updateListButton->setIconSet( SmallIconSet( Amarok::icon( "rescan" ) ) );    m_showInfoToggleButton = new QPushButton( i18n( "Show Info" ) , hBox, "showInfoCheckbox" );    m_showInfoToggleButton->setToggleButton( true );    m_showInfoToggleButton->setIconSet( SmallIconSet( Amarok::icon( "info" ) ) );    m_showInfoToggleButton->setOn( true );    m_isInfoShown = true;    connect( m_showInfoToggleButton, SIGNAL( toggled( bool ) ), this, SLOT( showInfo( bool ) ) );    connect( m_updateListButton, SIGNAL( clicked() ), this, SLOT( updateButtonClicked() ) );    connect( m_purchaseAlbumButton, SIGNAL( clicked() ) , this, SLOT( purchaseButtonClicked() ) );}void MagnatuneBrowser::updateButtonClicked(){    m_updateListButton->setEnabled( false );    updateMagnatuneList();}bool MagnatuneBrowser::updateMagnatuneList(){    //download new list from magnatune    m_listDownloadJob = KIO::storedGet( KURL( "http://magnatune.com/info/album_info.xml" ), false, false );    Amarok::StatusBar::instance() ->newProgressOperation( m_listDownloadJob )    .setDescription( i18n( "Downloading Magnatune.com Database" ) )    .setAbortSlot( this, SLOT( listDownloadCancelled() ) );    connect( m_listDownloadJob, SIGNAL( result( KIO::Job* ) ), SLOT( listDownloadComplete( KIO::Job* ) ) );    return true;}void MagnatuneBrowser::listDownloadComplete( KIO::Job * downLoadJob ){    if ( downLoadJob != m_listDownloadJob )        return ; //not the right job, so let's ignore it    m_updateListButton->setEnabled( true );    if ( !downLoadJob->error() == 0 )    {        //TODO: error handling here        return ;    }    KIO::StoredTransferJob* const storedJob = static_cast<KIO::StoredTransferJob*>( downLoadJob );    QString list = QString( storedJob->data() );    QFile file( "/tmp/album_info.xml" );    if ( file.exists() )        file.remove();    if ( file.open( IO_WriteOnly ) )    {        QTextStream stream( &file );        stream << list;        file.close();    }    MagnatuneXmlParser * parser = new MagnatuneXmlParser( "/tmp/album_info.xml" );    connect( parser, SIGNAL( doneParsing() ), SLOT( doneParsing() ) );    ThreadManager::instance() ->queueJob( parser );}void MagnatuneBrowser::listDownloadCancelled( ){    Amarok::StatusBar::instance() ->endProgressOperation( m_listDownloadJob );    m_listDownloadJob->kill( true );    delete m_listDownloadJob;    m_listDownloadJob = 0;    debug() << "Aborted xml download" << endl;    m_updateListButton->setEnabled( true );}void MagnatuneBrowser::showInfo( bool show ){    if ( show )    {        m_isInfoShown = true;        m_artistInfobox->widget() ->setMaximumHeight( 2000 );    }    else    {        m_artistInfobox->widget() ->setMaximumHeight( 0 );        m_isInfoShown = false;    }}void MagnatuneBrowser::updateList(){    DEBUG_BLOCK    const QString genre = m_genreComboBox->currentText();    MagnatuneArtistList artists;    artists = MagnatuneDatabaseHandler::instance() ->getArtistsByGenre( genre );    m_listView->clear();    MagnatuneArtistList::iterator it;    for ( it = artists.begin(); it != artists.end(); ++it )        new MagnatuneListViewArtistItem( ( *it ), m_listView );    m_listView->repaintContents();}void MagnatuneBrowser::genreChanged(){    debug() << "Genre changed..." << endl;    updateList( );}void MagnatuneBrowser::doneParsing(){    updateList();    updateGenreBox( );    updateList(); // stupid stupid hack....}void MagnatuneBrowser::updateGenreBox(){    const QStringList genres = MagnatuneDatabaseHandler::instance() ->getAlbumGenres();    m_genreComboBox->clear();    m_genreComboBox->insertItem ( "All" , 0 ); // should not be i18n'ed as it is    //used as a trigger in the code in the database handler.    foreach( genres )    m_genreComboBox->insertItem( ( *it ), -1 );}void MagnatuneBrowser::processRedownload( ){    if ( m_redownloadHandler == 0 )    {        m_redownloadHandler = new MagnatuneRedownloadHandler( this );    }    m_redownloadHandler->showRedownloadDialog();}void MagnatuneBrowser::purchaseCompleted( bool /*success*/ ){    if ( m_purchaseHandler != 0 )    {        delete m_purchaseHandler;        m_purchaseHandler = 0;    }    m_purchaseAlbumButton->setEnabled( true );    m_purchaseInProgress = false;    debug() << "Purchase operation complete" << endl;    //TODO: display some kind of success dialog here?}void MagnatuneBrowser::polish( ){    DEBUG_BLOCK;    if (!m_polished) {        m_polished = true;        updateList( );        m_artistInfobox->begin( KURL( locate( "data", "amarok/data/" ) ) );        m_artistInfobox->write( "<table align='center' border='0'><tbody align='center' valign='top'>"          "<tr align='center'><td><div align='center'>"          "<IMG src='magnatune_logo.png' width='200' height='36' align='center' border='0'>"          "</div></td></tr><tr><td><BR>"        + i18n( "Welcome to Amarok's integrated Magnatune.com store. If this is the "                "first time you run it, you must update the database by pressing the "                "'Update' button below." )        + "</td></tr></tbody></table>" );        m_artistInfobox->end();    }}#include "magnatunebrowser.moc"

⌨️ 快捷键说明

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