void TestSqlTrack::testRemoveLabelFromTrack() { Meta::TrackPtr track = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); Meta::LabelPtr label = m_collection->registry()->getLabel( "A" ); track->addLabel( label ); QCOMPARE( track->labels().count(), 1 ); track->removeLabel( label ); QCOMPARE( track->labels().count(), 0 ); QStringList urlsLabelsCount = m_storage->query( "SELECT COUNT(*) FROM urls_labels;" ); QCOMPARE( urlsLabelsCount.first().toInt(), 0 ); }
bool LabelFilter::filterMatches( Meta::TrackPtr track ) const { foreach( const Meta::LabelPtr &label, track->labels() ) { if( m_expression.indexIn( label->name() ) != -1 ) return true; } return false; }
bool ScrobblerAdapter::isToBeSkipped( const Meta::TrackPtr &track ) const { Q_ASSERT( track ); if( !m_config->filterByLabel() ) return false; foreach( const Meta::LabelPtr &label, track->labels() ) if( label->name() == m_config->filteredLabel() ) return true; return false; }
void TestSqlTrack::testRemoveLabelFromTrackWhenNotInCache() { m_storage->query( "INSERT INTO labels(id,label) VALUES (1,'A');" ); m_storage->query( "INSERT INTO urls_labels(url,label) VALUES (1,1);" ); Meta::TrackPtr track = m_collection->registry()->getTrack( "/IDoNotExist.mp3" ); Meta::LabelPtr label = m_collection->registry()->getLabel( "A" ); track->removeLabel( label ); QCOMPARE( track->labels().count(), 0 ); QStringList urlsLabelsCount = m_storage->query( "SELECT COUNT(*) FROM urls_labels;" ); QCOMPARE( urlsLabelsCount.first().toInt(), 0 ); }
QVariant Meta::valueForField( qint64 field, Meta::TrackPtr track ) { if( !track ) return QVariant(); switch( field ) { case 0: { // that is the simple search for MetaQueryWidget QSet<QString> allInfos; allInfos += track->playableUrl().path() += track->name() += track->comment(); if( track->artist() ) allInfos += track->artist()->name(); if( track->album() ) allInfos += track->album()->name(); if( track->genre() ) allInfos += track->genre()->name(); return QVariant( allInfos.toList() ); } case Meta::valUrl: return track->playableUrl().path(); case Meta::valTitle: return track->name(); case Meta::valArtist: return track->artist() ? QVariant(track->artist()->name()) : QVariant(); case Meta::valAlbum: return track->album() ? QVariant(track->album()->name()) : QVariant(); case Meta::valGenre: return track->genre() ? QVariant(track->genre()->name()) : QVariant(); case Meta::valComposer: return track->composer() ? QVariant(track->composer()->name()) : QVariant(); case Meta::valYear: return track->year() ? QVariant(track->year()->name().toInt()) : QVariant(); case Meta::valComment: return track->comment(); case Meta::valTrackNr: return track->trackNumber(); case Meta::valDiscNr: return track->discNumber(); case Meta::valBpm: return track->bpm(); case Meta::valLength: return track->length(); case Meta::valBitrate: return track->bitrate(); case Meta::valSamplerate: return track->sampleRate(); case Meta::valFilesize: return track->filesize(); case Meta::valFormat: return int(Amarok::FileTypeSupport::fileType(track->type())); case Meta::valCreateDate: return track->createDate(); case Meta::valScore: return track->statistics()->score(); case Meta::valRating: return track->statistics()->rating(); case Meta::valFirstPlayed: return track->statistics()->firstPlayed(); case Meta::valLastPlayed: return track->statistics()->lastPlayed(); case Meta::valPlaycount: return track->statistics()->playCount(); case Meta::valUniqueId: return track->uidUrl(); // todo case Meta::valTrackGain: return "track gain"; case Meta::valTrackGainPeak: return "track gain peak"; case Meta::valAlbumGain: return "album gain"; case Meta::valAlbumGainPeak: return "album gain peak"; case Meta::valAlbumArtist: return (track->album() && track->album()->albumArtist()) ? QVariant(track->album()->albumArtist()->name()) : QVariant(); case Meta::valLabel: { Meta::LabelList labels = track->labels(); QStringList strLabels; foreach( Meta::LabelPtr label, labels ) strLabels.append( label->name() ); return QVariant( strLabels ); } case Meta::valModified: return track->modifyDate(); default: return QVariant(); } }