Ejemplo n.º 1
0
 foreach( Playlists::PlaylistPtr playlist, m_playlists )
 {
     int trackIndex;
     // track may be multiple times in a playlist:
     while( ( trackIndex = playlist->tracks().indexOf( track ) ) >= 0 )
         playlist->removeTrack( trackIndex );
 }
Ejemplo n.º 2
0
void TestPlaylistFileProvider::testSave()
{
    Meta::TrackList tempTrackList;
    const KUrl trackUrl = dataPath( "data/audio/Platz 01.mp3" );
    tempTrackList.append( CollectionManager::instance()->trackForUrl( trackUrl ) );
    QCOMPARE( tempTrackList.size(), 1 );

    QFETCH(QString, name);
    QFETCH(QString, result);

    Playlists::PlaylistPtr testPlaylist = m_testPlaylistFileProvider->save( tempTrackList, name );
    QVERIFY( testPlaylist );

    QVERIFY( QFile::exists( Amarok::saveLocation( "playlists" ) + result ) );
    QCOMPARE( testPlaylist->name(), QString( result ) );
    QCOMPARE( testPlaylist->tracks().size(), 1 );
    QFile::remove( Amarok::saveLocation( "playlists" ) + result );
}
Ejemplo n.º 3
0
QVariant
PlaylistBrowserModel::data( const QModelIndex &index, int role ) const
{
    int row = REMOVE_TRACK_MASK(index.internalId());
    Playlists::PlaylistPtr playlist = m_playlists.value( row );

    QString name;
    KIcon icon;
    int playlistCount = 0;
    QList<QAction *> providerActions;
    QList<Playlists::PlaylistProvider *> providers =
        The::playlistManager()->getProvidersForPlaylist( playlist );
    Playlists::PlaylistProvider *provider = providers.count() == 1 ? providers.first() : 0;
    Meta::TrackPtr track;

    switch( index.column() )
    {
        case PlaylistBrowserModel::PlaylistItemColumn: //playlist or track data
        {
            if( IS_TRACK(index) )
            {
                track = playlist->tracks()[index.row()];
                name = track->prettyName();
                icon = KIcon( "amarok_track" );
            }
            else
            {
                name = playlist->prettyName();
                icon = KIcon( "amarok_playlist" );
            }
            break;
        }
        case PlaylistBrowserModel::LabelColumn: //group
        {
            if( !playlist->groups().isEmpty() )
            {
                name = playlist->groups().first();
                icon = KIcon( "folder" );
            }
            break;
        }

        case PlaylistBrowserModel::ProviderColumn: //source
        {
            if( providers.count() > 1 )
            {
                QVariantList nameData;
                QVariantList iconData;
                QVariantList playlistCountData;
                QVariantList providerActionsData;
                foreach( Playlists::PlaylistProvider *provider, providers )
                {
                    name = provider->prettyName();
                    nameData << name;
                    icon = provider->icon();
                    iconData << QVariant( icon );
                    playlistCount = provider->playlists().count();
                    if( playlistCount >= 0 )
                        playlistCountData << i18ncp(
                                "number of playlists from one source",
                                "One Playlist", "%1 playlists",
                                playlistCount );
                    else
                        playlistCountData << i18nc(
                                "normally number of playlists, but they are still loading",
                                "Loading..." );
                    providerActions << provider->providerActions();
                    providerActionsData << QVariant::fromValue( providerActions );
                }
                switch( role )
                {
                case Qt::DisplayRole:
                case Qt::EditRole:
                case Qt::ToolTipRole:
                    return nameData;
                case Qt::DecorationRole:
                    return iconData;
                case PrettyTreeRoles::ByLineRole:
                    return playlistCountData;
                case PrettyTreeRoles::DecoratorRoleCount:
                    return providerActions.count();
                case PrettyTreeRoles::DecoratorRole:
                    return providerActionsData;
                }
            }
            else if( provider )
Ejemplo n.º 4
0
Playlists::PlaylistPtr
IpodPlaylistProvider::addPlaylist( Playlists::PlaylistPtr playlist )
{
    return save( playlist->tracks(), playlist->name() );
}