示例#1
0
void QSpotifyAlbumBrowse::processData()
{
    if (m_sp_albumbrowse) {
        if (sp_albumbrowse_error(m_sp_albumbrowse) != SP_ERROR_OK)
            return;

        m_albumTracks = new QSpotifyTrackList;
        int c = sp_albumbrowse_num_tracks(m_sp_albumbrowse);
        for (int i = 0; i < c; ++i) {
            sp_track *track = sp_albumbrowse_track(m_sp_albumbrowse, i);
            QSpotifyTrack *qtrack = new QSpotifyTrack(track, m_albumTracks);
            m_albumTracks->m_tracks.append(qtrack);
            connect(qtrack, SIGNAL(isStarredChanged()), this, SIGNAL(isStarredChanged()));
            connect(QSpotifySession::instance()->user()->starredList(), SIGNAL(tracksAdded(QVector<sp_track*>)), qtrack, SLOT(onStarredListTracksAdded(QVector<sp_track*>)));
            connect(QSpotifySession::instance()->user()->starredList(), SIGNAL(tracksRemoved(QVector<sp_track*>)), qtrack, SLOT(onStarredListTracksRemoved(QVector<sp_track*>)));
            if (qtrack->artists() != m_album->artist())
                m_hasMultipleArtists = true;
        }

        m_review = QString::fromUtf8(sp_albumbrowse_review(m_sp_albumbrowse)).split(QLatin1Char('\n'), QString::SkipEmptyParts);
        if (m_review.isEmpty())
            m_review << QLatin1String("No review available");

        m_busy = false;
        emit busyChanged();

        emit tracksChanged();
    }
}
void QSpotifySearch::populateTracks(sp_search *search)
{
    m_trackResults->clear();
    if (m_enablePreview)
        m_trackResultsPreview->clear();

    auto sourceList = QSpotifySession::instance()->playQueue()->m_sourceTrackList;
    if(sourceList == m_trackResults || sourceList == m_trackResultsPreview) {
        QSpotifySession::instance()->playQueue()->m_sourceTrackList = nullptr;
    }

    if (search) {
        int c = sp_search_num_tracks(search);
        for (int i = 0; i < c; ++i) {
            if (auto strack = sp_search_track(search, i)) {
                auto track = QSpotifyCacheManager::instance().getTrack(strack);
                if(m_enablePreview && i < m_numPreviewItems)
                    m_trackResultsPreview->appendRow(track);
                m_trackResults->appendRow(track);
                connect(QSpotifySession::instance()->user()->starredList(), SIGNAL(tracksAdded(QVector<sp_track*>)), track.get(), SLOT(onStarredListTracksAdded(QVector<sp_track*>)));
                connect(QSpotifySession::instance()->user()->starredList(), SIGNAL(tracksRemoved(QVector<sp_track*>)), track.get(), SLOT(onStarredListTracksRemoved(QVector<sp_track*>)));
            }
        }
    }
}