Exemplo n.º 1
0
void
ScrobblesListWidget::read()
{
    qDebug() << m_path;

    clear();

    // always have a now playing item in the list
    m_trackItem = new ScrobblesListWidgetItem( this );
    TrackWidget* trackWidget = new TrackWidget( m_track, this );
    trackWidget->setObjectName( "nowPlaying" );
    setItemWidget( m_trackItem, trackWidget );
    m_trackItem->setSizeHint( trackWidget->sizeHint() );
    m_trackItem->setHidden( true );
    m_trackItem->setNowPlaying( true );

    connect( trackWidget, SIGNAL(clicked(TrackWidget&)), SLOT(onItemClicked(TrackWidget&)) );

    // always have the refresh button in the list
    m_refreshItem = new ScrobblesListWidgetItem( this );
    RefreshButton* refreshButton = new RefreshButton( this );
    refreshButton->setObjectName( "refresh" );
    setItemWidget( m_refreshItem, refreshButton );
    m_refreshItem->setSizeHint( refreshButton->sizeHint() );

    connect( refreshButton, SIGNAL(clicked()), SLOT(refresh()) );

    onRefreshing( false );

    // always have a view more item in the list
    m_moreItem = new ScrobblesListWidgetItem( this );
    QPushButton* moreButton = new QPushButton( tr( "More Scrobbles at Last.fm" ), this );
    moreButton->setObjectName( "more" );
    setItemWidget( m_moreItem, moreButton );
    m_moreItem->setSizeHint( moreButton->sizeHint() );

    connect( moreButton, SIGNAL(clicked()), SLOT(onMoreClicked()) );

    QFile file( m_path );
    file.open( QFile::Text | QFile::ReadOnly );
    QTextStream stream( &file );
    stream.setCodec( "UTF-8" );

    QDomDocument xml;
    xml.setContent( stream.readAll() );

    QList<Track> tracks;

    for (QDomNode n = xml.documentElement().lastChild(); !n.isNull(); n = n.previousSibling())
        tracks << Track( n.toElement() );

    addTracks( tracks );
    fetchTrackInfo( tracks );

    limit( kScrobbleLimit );
}
Exemplo n.º 2
0
void
ScrobblesWidget::onTrackClicked( TrackWidget& trackWidget )
{
    MetadataWidget* w;
    ui->layout->addWidget( w = new MetadataWidget( trackWidget.track() ));
    w->fetchTrackInfo();
    w->setBackButtonVisible( true );

    trackWidget.startSpinner();
    connect( ui->layout, SIGNAL( moveFinished(QLayoutItem*)), &trackWidget, SLOT(clearSpinner()) );

    connect( w, SIGNAL(finished()), SLOT(onMetadataWidgetFinished()));
    connect( w, SIGNAL(backClicked()), SLOT(onBackClicked()));
}
void
ScrobblesListWidget::showEvent(QShowEvent *)
{
    QList<lastfm::Track> tracks;

    for ( int i = 0 ; i < count() ; ++i )
    {
        TrackWidget* trackWidget = qobject_cast<TrackWidget*>( itemWidget( item( i ) ) );

        if ( trackWidget && !item( i )->isHidden() )
            tracks << trackWidget->track();
    }

    fetchTrackInfo( tracks );
}