bool ProxyBase::rowMatch( int sourceModelRow, const QString &searchTerms, int searchFields ) const { if ( !m_belowModel ) return false; Meta::TrackPtr track = m_belowModel->trackAt( sourceModelRow ); QStringList searchList = searchTerms.split(" ", QString::SkipEmptyParts); foreach( const QString& searchTerm, searchList ) { bool match = false; if ( searchFields & MatchTrack && track->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if ( searchFields & MatchArtist && track->artist() && track->artist()->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if ( searchFields & MatchAlbum && track->album() && track->album()->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if ( searchFields & MatchGenre && track->genre() && track->genre()->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if ( searchFields & MatchComposer && track->composer() && track->composer()->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if ( searchFields & MatchYear && track->year() && track->year()->prettyName().contains( searchTerm, Qt::CaseInsensitive ) ) match = true; if( searchFields & MatchRating ) { bool ok; int rating = QString( searchTerm ).remove( "rating:" ).toInt( &ok ); if( ok && ( track->statistics()->rating() == rating ) ) match = true; } if( !match ) return false; }
void IpodCopyTracksJob::slotStartDuplicateTrackSearch( const Meta::TrackPtr &track ) { Collections::QueryMaker *qm = m_coll.data()->queryMaker(); qm->setQueryType( Collections::QueryMaker::Track ); // we cannot qm->addMatch( track ) - it matches by uidUrl() qm->addFilter( Meta::valTitle, track->name(), true, true ); qm->addMatch( track->album() ); qm->setArtistQueryMode( Collections::QueryMaker::TrackArtists ); qm->addMatch( track->artist() ); qm->addMatch( track->composer() ); qm->addMatch( track->genre() ); qm->addMatch( track->year() ); qm->addNumberFilter( Meta::valTrackNr, track->trackNumber(), Collections::QueryMaker::Equals ); qm->addNumberFilter( Meta::valDiscNr, track->discNumber(), Collections::QueryMaker::Equals ); // we don't want to match by filesize, track length, filetype etc - these change during // transcoding. We don't match album artist because handling of it is inconsistent connect( qm, SIGNAL(newResultReady(Meta::TrackList)), SLOT(slotDuplicateTrackSearchNewResult(Meta::TrackList)) ); connect( qm, SIGNAL(queryDone()), SLOT(slotDuplicateTrackSearchQueryDone()) ); qm->setAutoDelete( true ); m_duplicateTrack = Meta::TrackPtr(); // reset duplicate track from previous query qm->run(); }
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 ) ); }
QString TrackOrganizer::buildDestination(const QString& format, const Meta::TrackPtr& track) const { // get hold of the shared pointers Meta::AlbumPtr album = track->album(); Meta::ArtistPtr artist = track->artist(); Meta::ComposerPtr composer = track->composer(); Meta::ArtistPtr albumArtist = album ? album->albumArtist() : Meta::ArtistPtr(); Meta::GenrePtr genre = track->genre(); Meta::YearPtr year = track->year(); bool isCompilation = album && album->isCompilation(); QMap<QString, QString> args; QString strArtist = artist ? artist->name() : QString(); QString strAlbumArtist = isCompilation ? i18n( "Various Artists" ) : ( albumArtist ? albumArtist->name() : strArtist ); args["theartist"] = strArtist; args["thealbumartist"] = strAlbumArtist; if( m_postfixThe ) { Amarok::manipulateThe( strArtist, true ); Amarok::manipulateThe( strAlbumArtist, true ); } if ( track->trackNumber() ) { QString trackNum = QString("%1").arg( track->trackNumber(), 2, 10, QChar('0') ); args["track"] = trackNum; } args["title"] = track->name(); args["artist"] = strArtist; args["composer"] = composer ? composer->name() : QString(); // if year == 0 then we don't want include it QString strYear = year ? year->name() : QString(); args["year"] = strYear.localeAwareCompare( "0" ) == 0 ? QString() : strYear; args["album"] = track->album() ? track->album()->name() : QString(); args["albumartist"] = strAlbumArtist; args["comment"] = track->comment(); args["genre"] = genre ? genre->name() : QString(); if( m_targetFileExtension.isEmpty() ) args["filetype"] = track->type(); else args["filetype"] = m_targetFileExtension; QString strFolder = QFileInfo( track->playableUrl().toLocalFile() ).path(); strFolder = strFolder.mid( commonPrefixLength( m_folderPrefix, strFolder ) ); args["folder"] = strFolder; args["initial"] = strAlbumArtist.mid( 0, 1 ).toUpper(); //artists starting with The are already handled above if( track->discNumber() ) args["discnumber"] = QString::number( track->discNumber() ); args["collectionroot"] = m_folderPrefix; // some additional properties not supported by organize dialog. args["rating"] = track->statistics()->rating(); args["filesize"] = track->filesize(); args["length"] = track->length() / 1000; // Fill up default empty values for StringX formater // TODO make this values changeable by user args["default_album"] = i18n( "Unknown album" ); args["default_albumartist"] = i18n( "Unknown artist" ); args["default_artist"] = args["albumartist"]; args["default_thealbumartist"] = args["albumartist"]; args["default_theartist"] = args["albumartist"]; args["default_comment"] = i18n( "No comments" ); args["default_composer"] = i18n( "Unknown composer" ); args["default_discnumber"] = i18n( "Unknown disc number" ); args["default_genre"] = i18n( "Unknown genre" ); args["default_title"] = i18n( "Unknown title" ); args["default_year"] = i18n( "Unknown year" ); foreach( const QString &key, args.keys() ) if( key != "collectionroot" && key != "folder" ) args[key] = args[key].replace( '/', '-' ); Amarok::QStringx formatx( format ); QString result = formatx.namedOptArgs( args ); return cleanPath( result ); }
void CurrentTrack::setupLayoutActions( Meta::TrackPtr track ) { if( !track ) return; PERF_LOG( "Begin actions layout setup" ); //first, add any global CurrentTrackActions (iow, actions that are shown for all tracks) QList<QAction *> actions = The::globalCurrentTrackActions()->actions(); using namespace Capabilities; QScopedPointer<ActionsCapability> ac( track->create<ActionsCapability>() ); if( ac ) { QList<QAction*> trackActions = ac->actions(); // ensure that the actions get deleted afterwards foreach( QAction* action, trackActions ) { if( !action->parent() ) action->setParent( this ); actions << action; } } QScopedPointer<BookmarkThisCapability> btc( track->create<BookmarkThisCapability>() ); if( btc && btc->bookmarkAction() ) { actions << btc->bookmarkAction(); } if( m_showEditTrackDetailsAction && track->editor() ) { QAction *editAction = new QAction( KIcon("media-track-edit-amarok"), i18n("Edit Track Details"), this ); connect( editAction, SIGNAL(triggered()), SLOT(editTrack()) ); m_customActions << editAction; } if( track->has<FindInSourceCapability>() ) { if( !m_findInSourceSignalMapper ) { m_findInSourceSignalMapper = new QSignalMapper( this ); connect( m_findInSourceSignalMapper, SIGNAL(mapped(QString)), SLOT(findInSource(QString)) ); } Meta::AlbumPtr album = track->album(); Meta::ArtistPtr artist = track->artist(); Meta::ComposerPtr composer = track->composer(); Meta::GenrePtr genre = track->genre(); Meta::YearPtr year = track->year(); QAction *act( 0 ); if( album && !album->name().isEmpty() ) { act = new QAction( KIcon("current-track-amarok"), i18n("Show Album in Media Sources"), this ); connect( act, SIGNAL(triggered()), m_findInSourceSignalMapper, SLOT(map()) ); m_findInSourceSignalMapper->setMapping( act, QLatin1String("album") ); m_customActions << act; } if( artist && !artist->name().isEmpty() ) { act = new QAction( KIcon("filename-artist-amarok"), i18n("Show Artist in Media Sources"), this ); connect( act, SIGNAL(triggered()), m_findInSourceSignalMapper, SLOT(map()) ); m_findInSourceSignalMapper->setMapping( act, QLatin1String("artist") ); m_customActions << act; KPluginInfo::List services = The::pluginManager()->plugins( QLatin1String("Service") ); foreach( const KPluginInfo &service, services ) { if( service.pluginName() == QLatin1String("amarok_service_amazonstore") ) { if( service.isPluginEnabled() ) { act = new QAction( KIcon("view-services-amazon-amarok"), i18n("Search for Artist in the MP3 Music Store"), this ); connect( act, SIGNAL(triggered()), this, SLOT(findInStore()) ); m_customActions << act; } break; } } } if( composer && !composer->name().isEmpty() && (composer->name() != i18n("Unknown Composer")) ) { act = new QAction( KIcon("filename-composer-amarok"), i18n("Show Composer in Media Sources"), this ); connect( act, SIGNAL(triggered()), m_findInSourceSignalMapper, SLOT(map()) ); m_findInSourceSignalMapper->setMapping( act, QLatin1String("composer") ); m_customActions << act; } if( genre && !genre->name().isEmpty() ) { act = new QAction( KIcon("filename-genre-amarok"), i18n("Show Genre in Media Sources"), this ); connect( act, SIGNAL(triggered()), m_findInSourceSignalMapper, SLOT(map()) ); m_findInSourceSignalMapper->setMapping( act, QLatin1String("genre") ); m_customActions << act; } if( year && !year->name().isEmpty() ) { act = new QAction( KIcon("filename-year-amarok"), i18n("Show Year in Media Sources"), this ); connect( act, SIGNAL(triggered()), m_findInSourceSignalMapper, SLOT(map()) ); m_findInSourceSignalMapper->setMapping( act, QLatin1String("year") ); m_customActions << act; } }
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(); } }