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 ); }
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 ); }
void IpodPlaylistProvider::rename( Playlists::PlaylistPtr playlist, const QString &newName ) { if( !m_playlists.contains( playlist ) ) // make following static cast safe return; KSharedPtr<IpodPlaylist> ipodPlaylist = KSharedPtr<IpodPlaylist>::staticCast( playlist ); if( ipodPlaylist->type() != IpodPlaylist::Normal ) return; // special playlists cannot be renamed playlist->setName( newName ); emit updated(); emit startWriteDatabaseTimer(); }
void SyncedPlaylist::addPlaylist( Playlists::PlaylistPtr playlist ) { if( m_playlists.contains( playlist ) ) return; //Only subscribe to the master playlist's changes if( m_playlists.isEmpty() ) subscribeTo( playlist ); else { //Deny syncing between playlists in the same provider because //there is no use case for it and it does make the code more complex if ( (*(m_playlists.begin()))->provider() == playlist->provider() ) { error() << "BUG: You cannot synchronize playlists with the same provider!!!"; return; } } m_playlists << playlist; }
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 )
// to be used with qSort. static bool lessThanPlaylistTitles( const Playlists::PlaylistPtr &lhs, const Playlists::PlaylistPtr &rhs ) { return lhs->prettyName().toLower() < rhs->prettyName().toLower(); }
m_playlists << playlist; } bool SyncedPlaylist::syncNeeded() const { DEBUG_BLOCK if( isEmpty() || m_playlists.count() == 1 ) return false; /* Use the first playlist as the base, if the others have a difference compared to it a sync is needed */ QList<Playlists::PlaylistPtr>::const_iterator i = m_playlists.begin(); Playlists::PlaylistPtr master = *i; int masterTrackCount = master->trackCount(); ++i; //From now on its only slaves on the iterator debug() << "Master Playlist: " << master->name() << " - " << master->uidUrl().url(); debug() << "Master track count: " << masterTrackCount; for( ;i != m_playlists.end(); ++i) { //Playlists::PlaylistPtr slave = i.next(); Playlists::PlaylistPtr slave = *i; debug() << "Slave Playlist: " << slave->name() << " - " << slave->uidUrl().url(); if( masterTrackCount != -1 ) { int slaveTrackCount = slave->trackCount();
Playlists::PlaylistPtr IpodPlaylistProvider::addPlaylist( Playlists::PlaylistPtr playlist ) { return save( playlist->tracks(), playlist->name() ); }
foreach( Playlists::PlaylistPtr playlist, m_playlistSubscriptions ) { playlist->unsubscribe( this ); }
bool KConfigSyncRelStore::hasToSync( Playlists::PlaylistPtr master, Playlists::PlaylistPtr slave ) const { return m_syncSlaveMap.values( slave->uidUrl() ).contains( master->uidUrl() ); }