AmarokUrl NavigationUrlGenerator::urlFromAlbum( Meta::AlbumPtr album ) { AmarokUrl url; QScopedPointer<Capabilities::BookmarkThisCapability> btc( album->create<Capabilities::BookmarkThisCapability>() ); if( btc ) { if( btc->isBookmarkable() ) { QString albumName = album->prettyName(); url.setCommand( "navigate" ); QString path = btc->browserName(); if ( !btc->collectionName().isEmpty() ) path += ( '/' + btc->collectionName() ); url.setPath( path ); QString filter; if ( btc->simpleFiltering() ) { filter = "\"" + albumName + "\""; } else { url.setArg( "levels", "album" ); QString artistName; if ( album->albumArtist() ) artistName = album->albumArtist()->prettyName(); filter = "album:\"" + albumName + "\""; if ( !artistName.isEmpty() ) filter += ( " AND artist:\"" + artistName + "\"" ); } url.setArg( "filter", filter ); if ( !btc->collectionName().isEmpty() ) url.setName( i18n( "Album \"%1\" from %2", albumName, btc->collectionName() ) ); else url.setName( i18n( "Album \"%1\"", albumName ) ); } } //debug() << "got url: " << url.url(); return url; }
void CurrentEngine::update( Meta::AlbumPtr album ) { if( !m_requested.value( QLatin1String("albums") ) ) return; DEBUG_BLOCK m_lastQueryMaker = 0; Meta::TrackPtr track = The::engineController()->currentTrack(); if( !album ) return; Meta::ArtistPtr artist = track->artist(); // Prefer track artist to album artist BUG: 266682 if( !artist ) artist = album->albumArtist(); if( artist && !artist->name().isEmpty() ) { m_albums.clear(); m_albumData.clear(); m_albumData[ QLatin1String("currentTrack") ] = qVariantFromValue( track ); m_albumData[ QLatin1String("headerText") ] = QVariant( i18n( "Albums by %1", artist->name() ) ); // -- search the collection for albums with the same artist Collections::QueryMaker *qm = CollectionManager::instance()->queryMaker(); qm->setAutoDelete( true ); qm->addFilter( Meta::valArtist, artist->name(), true, true ); qm->setAlbumQueryMode( Collections::QueryMaker::AllAlbums ); qm->setQueryType( Collections::QueryMaker::Album ); connect( qm, SIGNAL(newResultReady( Meta::AlbumList)), SLOT(resultReady( Meta::AlbumList)), Qt::QueuedConnection ); connect( qm, SIGNAL(queryDone()), SLOT(setupAlbumsData()) ); m_lastQueryMaker = qm; qm->run(); } else { removeAllData( QLatin1String("albums") ); setData( QLatin1String("albums"), QLatin1String("headerText"), i18nc( "Header text for current album applet", "Albums" ) ); } }
void ScrobblerAdapter::copyTrackMetadata( lastfm::MutableTrack &to, const Meta::TrackPtr &track ) { to.setTitle( track->name() ); QString artistOrComposer; Meta::ComposerPtr composer = track->composer(); if( m_config->scrobbleComposer() && composer ) artistOrComposer = composer->name(); Meta::ArtistPtr artist = track->artist(); if( artistOrComposer.isEmpty() && artist ) artistOrComposer = artist->name(); to.setArtist( artistOrComposer ); Meta::AlbumPtr album = track->album(); Meta::ArtistPtr albumArtist; if( album ) { to.setAlbum( album->name() ); albumArtist = album->hasAlbumArtist() ? album->albumArtist() : Meta::ArtistPtr(); } if( albumArtist ) to.setAlbumArtist( albumArtist->name() ); to.setDuration( track->length() / 1000 ); if( track->trackNumber() >= 0 ) to.setTrackNumber( track->trackNumber() ); lastfm::Track::Source source = lastfm::Track::Player; if( track->type() == "stream/lastfm" ) source = lastfm::Track::LastFmRadio; else if( track->type().startsWith( "stream" ) ) source = lastfm::Track::NonPersonalisedBroadcast; else if( track->collection() && track->collection()->collectionId() != "localCollection" ) source = lastfm::Track::MediaDevice; to.setSource( source ); }
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 ); }