示例#1
0
void
IpodCopyTracksJob::slotDuplicateTrackSearchNewResult( const Meta::TrackList &tracks )
{
    if( !tracks.isEmpty() )
        // we don't really know which one, but be sure to allow multiple results
        m_duplicateTrack = tracks.last();
}
示例#2
0
void
AlbumItem::update()
{
    if( !m_album )
        return;

    Meta::TrackList tracks = m_album->tracks();
    if( !tracks.isEmpty() )
    {
        Meta::TrackPtr first = tracks.first();
        Meta::YearPtr year = first->year();
        if( year )
            setData( year->year(), AlbumYearRole );
    }

    QString albumName = m_album->name();
    albumName = albumName.isEmpty() ? i18n("Unknown") : albumName;
    QString name = ( m_showArtist && m_album->hasAlbumArtist() )
                 ? QString( "%1 - %2" ).arg( m_album->albumArtist()->name(), albumName )
                 : albumName;
    setData( name, NameRole );

    qint64 totalTime = 0;
    foreach( Meta::TrackPtr item, tracks )
        totalTime += item->length();

    QString trackCount = i18np( "%1 track", "%1 tracks", tracks.size() );
    QString lengthText = QString( "%1, %2" ).arg( trackCount, Meta::msToPrettyTime( totalTime ) );
    setData( lengthText, AlbumLengthRole );

    QPixmap cover = The::svgHandler()->imageWithBorder( m_album, m_iconSize, 3 );
    setIcon( QIcon( cover ) );
}
示例#3
0
void
AlbumsView::slotEditSelected()
{
    Meta::TrackList selected = getSelectedTracks();
    if( !selected.isEmpty() )
    {
        TagDialog *dialog = new TagDialog( selected );
        dialog->show();
    }
}
示例#4
0
Dynamic::TrackSet
Dynamic::AlbumPlayBias::matchingTracks( const Meta::TrackList& playlist,
                                        int contextCount, int finalCount,
                                        Dynamic::TrackCollectionPtr universe ) const
{
    Q_UNUSED( contextCount );
    Q_UNUSED( finalCount );

    if( playlist.isEmpty() ) // no track means we can't find any tracks in the same album
        return Dynamic::TrackSet( universe, false );

    Meta::TrackPtr track = playlist.last();
    Meta::AlbumPtr album = track->album();

    if( !album ) // no album means we can't find any tracks in the same album
        return Dynamic::TrackSet( universe, false );

    Meta::TrackList albumTracks = album->tracks();

    if( ( albumTracks.count() <= 1 ) || // the album has only one track (or even less) so there can't be any other tracks in the same album
        ( m_follow != DontCare && sameTrack( track, albumTracks.last() ) ) ) // track is the last one and we want to find a later one.
        return Dynamic::TrackSet( universe, false );

    // we assume that the album tracks are sorted by cd and track number which
    // is at least true for the SqlCollection
    TrackSet result( universe, false );
    if( m_follow == DirectlyFollow )
    {
        for( int i = 1; i < albumTracks.count(); i++ )
            if( sameTrack( albumTracks[i-1], track ) )
                result.unite( albumTracks[i] );
    }
    else if( m_follow == Follow )
    {
        bool found = false;
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( found )
                result.unite( albumTracks[i] );
            if( sameTrack( albumTracks[i], track ) )
                found = true;
        }
    }
    else if( m_follow == DontCare )
    {
        for( int i = 0; i < albumTracks.count(); i++ )
        {
            if( !sameTrack( albumTracks[i], track ) )
                result.unite( albumTracks[i] );
        }
    }

    return result;
}
QMimeData *
ScriptableServiceCollectionTreeModel::mimeData( const QList<CollectionTreeItem *> &items ) const
{
    // this is basically a copy of superclass method with a couple of changes:
    // 1. we don't reuse tracks already in the model
    // 2. we tell the querymaker to masquerade special tracks

    using namespace Collections;
    Meta::TrackList tracks;
    QList<QueryMaker *> queries;
    foreach( CollectionTreeItem *item, items )
    {
        if( item->isTrackItem() )
        {
            using namespace Meta;
            const ScriptableServiceTrack *serviceTrack =
                    dynamic_cast<const ScriptableServiceTrack *>( item->data().data() );
            if( !serviceTrack )
            {
                error() << "failed to convert generic track" << item->data() << "to ScriptableServiceTrack";
                continue;
            }
            tracks << serviceTrack->playableTrack();
            continue;
        }

        ScriptableServiceQueryMaker *qm = qobject_cast<ScriptableServiceQueryMaker *>( item->queryMaker() );
        if( !qm )
        {
            error() << "failed to convert generic QueryMaker to ScriptableService one";
            continue;
        }
        qm->setConvertToMultiTracks( true );
        for( CollectionTreeItem *tmp = item; tmp; tmp = tmp->parent() )
            tmp->addMatch( qm, levelCategory( tmp->level() - 1 ) );
        Collections::addTextualFilter( qm, m_currentFilter );
        queries.append( qm );
    }

    if( queries.isEmpty() && tracks.isEmpty() )
        return 0;

    AmarokMimeData *mimeData = new AmarokMimeData();
    mimeData->setTracks( tracks );
    mimeData->setQueryMakers( queries );
    mimeData->startQueries();
    return mimeData;
}
示例#6
0
Dynamic::TrackSet
Dynamic::LastFmBias::matchingTracks( const Meta::TrackList& playlist,
                                     int contextCount, int finalCount,
                                     Dynamic::TrackCollectionPtr universe ) const
{
    Q_UNUSED( contextCount );
    Q_UNUSED( finalCount );

    if( playlist.isEmpty() )
        return Dynamic::TrackSet( universe, true );

    // determine the last track and artist
    Meta::TrackPtr lastTrack = playlist.last();
    Meta::ArtistPtr lastArtist = lastTrack->artist();

    m_currentTrack = lastTrack->name();
    m_currentArtist = lastArtist ? lastArtist->name() : QString();

    {
        QMutexLocker locker( &m_mutex );

        if( m_match == SimilarArtist )
        {
            if( m_currentArtist.isEmpty() )
                return Dynamic::TrackSet( universe, true );
            if( m_tracksMap.contains( m_currentArtist ) )
                return m_tracksMap.value( m_currentArtist );
        }
        else if( m_match == SimilarTrack )
        {
            if( m_currentTrack.isEmpty() )
                return Dynamic::TrackSet( universe, true );
            QString key = m_currentTrack + '|' + m_currentArtist;
            if( m_tracksMap.contains( key ) )
                return m_tracksMap.value( key );
        }
    }

    m_tracks = Dynamic::TrackSet( universe, false );
    QTimer::singleShot(0,
                       const_cast<LastFmBias*>(this),
                       SLOT(newQuery())); // create the new query from my parent thread

    return Dynamic::TrackSet();
}
示例#7
0
void Albums::dataUpdated( const QString &name, const Plasma::DataEngine::Data &data )
{
    if( name != QLatin1String("albums") )
        return;

    Meta::AlbumList albums = data[ "albums" ].value<Meta::AlbumList>();
    Meta::TrackPtr track = data[ "currentTrack" ].value<Meta::TrackPtr>();
    QString headerText = data[ "headerText" ].toString();
    setHeaderText( headerText.isEmpty() ? i18n("Albums") : headerText );

    //Don't keep showing the albums for the artist of the last track that had album in the collection
    if( (m_currentTrack == track) && (m_albums == albums) )
        return;

    if( albums.isEmpty() )
    {
        debug() << "received albums is empty";
        setCollapseOn();
        m_albums.clear();
        m_albumsView->clear();
        return;
    }

    setCollapseOff();

    m_albums = albums;
    m_currentTrack = track;
    m_albumsView->clear();
    m_albumsView->setMode( track ? AlbumsProxyModel::SortByYear : AlbumsProxyModel::SortByCreateDate );
    QStandardItem *currentItem( 0 );

    foreach( Meta::AlbumPtr albumPtr, albums )
    {
        // do not show all tracks without an album from the collection, this takes ages
        // TODO: show all tracks from this artist that are not part of an album
        if( albumPtr->name().isEmpty() )
            continue;

        Meta::TrackList tracks = albumPtr->tracks();
        if( tracks.isEmpty() )
            continue;

        AlbumItem *albumItem = new AlbumItem();
        albumItem->setIconSize( 50 );
        albumItem->setAlbum( albumPtr );
        albumItem->setShowArtist( !m_currentTrack );

        int numberOfDiscs = 0;
        int childRow = 0;

        qStableSort( tracks.begin(), tracks.end(), Meta::Track::lessThan );

        QMultiHash< int, TrackItem* > trackItems; // hash of tracks items for each disc
        foreach( Meta::TrackPtr trackPtr, tracks )
        {
            if( numberOfDiscs < trackPtr->discNumber() )
                numberOfDiscs = trackPtr->discNumber();

            TrackItem *trackItem = new TrackItem();
            trackItem->setTrack( trackPtr );

            // bold the current track to make it more visible
            if( m_currentTrack && *m_currentTrack == *trackPtr )
            {
                currentItem = trackItem;
                trackItem->bold();
            }

            // If compilation and same artist, then highlight, but only if there's a current track
            if( m_currentTrack
                && m_currentTrack->artist() && trackPtr->artist()
                && (*m_currentTrack->artist() == *trackPtr->artist())
                && albumPtr->isCompilation() )
            {
                trackItem->italicise();
            }
            trackItems.insert( trackPtr->discNumber(), trackItem );
        }

        for( int i = 0; i <= numberOfDiscs; ++i )
        {
            QList<TrackItem*> items = trackItems.values( i );
            if( !items.isEmpty() )
            {
                const TrackItem *item = items.first();
                QStandardItem *discItem( 0 );
                if( numberOfDiscs > 1 )
                {
                    discItem = new QStandardItem( i18n("Disc %1", item->track()->discNumber()) );
                    albumItem->setChild( childRow++, discItem );
                    int discChildRow = 0;
                    foreach( TrackItem *trackItem, items )
                        discItem->setChild( discChildRow++, trackItem );
                }
                else
                {
                    foreach( TrackItem *trackItem, items )
                        albumItem->setChild( childRow++, trackItem );
                }
            }
        }
        m_albumsView->appendAlbum( albumItem );
    }

    m_albumsView->sort();
    if( currentItem )
    {
        m_albumsView->setRecursiveExpanded( currentItem, true );
        m_albumsView->scrollTo( currentItem );
    }

    updateConstraints();
}