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;
    }
示例#2
0
void
TrackItem::metadataChanged( Meta::TrackPtr track )
{
    int trackNumber = track->trackNumber();
    QString trackName = track->prettyName();

    QString text;

    if( trackNumber > 0 )
        text = QString( "%1\t%2" ).arg( QString::number( trackNumber ), trackName );
    else
        text = QString( "\t%1" ).arg( trackName );

    setText( text );
}
示例#3
0
/**
 * called whenever metadata of the current track has changed
 */
void
TabsEngine::update()
{
    DEBUG_BLOCK

    // get the current track
    Meta::TrackPtr track = The::engineController()->currentTrack();
    if( !track )
    {
        debug() << "no track";
        m_titleName.clear();
        m_artistName.clear();
        removeAllData( "tabs" );
        setData( "tabs", "state", "Stopped" );
        return;
    }
    m_currentTrack = track;
    Meta::ArtistPtr artistPtr = track->artist();
    QString newArtist;
    if( artistPtr )
    {
        if( ( track->playableUrl().protocol() == "lastfm" ) ||
            ( track->playableUrl().protocol() == "daap" ) ||
            !The::engineController()->isStream() )
            newArtist = artistPtr->name();
        else
            newArtist = artistPtr->prettyName();
    }

    QString newTitle = track->name();
    if( newTitle.isEmpty() )
        newTitle = track->prettyName();

    // check if something changed
    if( newTitle == m_titleName && newArtist == m_artistName )
    {
        debug() << "nothing changed";
        return;
    }

    // stop fetching for unknown artists or titles
    if( newTitle.isEmpty() || newArtist.isEmpty() )
    {
        setData("tabs", "state", "noTabs" );
        return;
    }
    requestTab( newArtist, newTitle );
}
示例#4
0
文件: Osd.cpp 项目: ErrAza/amarok
void
Amarok::OSD::show( Meta::TrackPtr track ) //slot
{
    setAlignment( static_cast<OSDWidget::Alignment>( AmarokConfig::osdAlignment() ) );
    setOffset( AmarokConfig::osdYOffset() );

    QString text;
    if( !track || track->playableUrl().isEmpty() )
    {
        text = i18n( "No track playing" );
        setRating( 0 ); // otherwise stars from last rating change are visible
    }
    else
    {
        setRating( track->rating() );
        text = track->prettyName();
        if( track->artist() && !track->artist()->prettyName().isEmpty() )
            text = track->artist()->prettyName() + " - " + text;
        if( track->album() && !track->album()->prettyName().isEmpty() )
            text += "\n (" + track->album()->prettyName() + ") ";
        else
            text += '\n';
        if( track->length() > 0 )
            text += Meta::msToPrettyTime( track->length() );
    }

    if( text.isEmpty() )
        text =  track->playableUrl().fileName();

    if( text.startsWith( "- " ) ) //When we only have a title tag, _something_ prepends a f*****g hyphen. Remove that.
        text = text.mid( 2 );

    if( text.isEmpty() ) //still
        text = i18n("No information available for this track");

    QImage image;
    if( track && track->album() )
        image = The::svgHandler()->imageWithBorder( track->album(), 100, 5 ).toImage();

    OSDWidget::show( text, image );
}
示例#5
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 )
void WikipediaEngine::update()
{
    DEBUG_BLOCK

    m_triedRefinedSearch = false;
    
    QString tmpWikiStr;

    unsubscribeFrom( m_currentTrack );
    Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
    m_currentTrack = currentTrack;
    subscribeTo( currentTrack );

    if ( !currentTrack )
        return;
    
    DataEngine::Data data;

    if( selection() == "artist" ) // default, or applet told us to fetch artist
    {
        data["wikipedia"] = "label, artist";
        if( currentTrack->artist() )
        {
            data["wikipedia"] = "title", currentTrack->artist()->prettyName();

            if ( ( currentTrack->playableUrl().protocol() == "lastfm" ) ||
                ( currentTrack->playableUrl().protocol() == "daap" ) ||
                !The::engineController()->isStream() )
            {
                tmpWikiStr = currentTrack->artist()->name();
                tmpWikiStr += wikiArtistPostfix(); //makes wikipedia bail out

                debug() << "tmpWikiStr: " << tmpWikiStr;
            }
            else
            {
                tmpWikiStr = currentTrack->artist()->prettyName();
                tmpWikiStr += wikiArtistPostfix(); //makes wikipedia bail out
            }
        }
    }
    else if( selection() == "title" )
    {
        tmpWikiStr = currentTrack->prettyName();
        data["wikipedia"] = QString( "label" ), QString( "Title" );
        data["wikipedia"] = "title", currentTrack->prettyName();
    }
    else if( selection() == "album" )
    {
        if( currentTrack->album() )
        {
            data["wikipedia"] = QString( "label" ), QString( "Album" );
            data["wikipedia"] = "title", currentTrack->album()->prettyName();
            if ( ( currentTrack->playableUrl().protocol() == "lastfm" ) ||
                ( currentTrack->playableUrl().protocol() == "daap" ) ||
                !The::engineController()->isStream() )
            {
                tmpWikiStr = currentTrack->album()->name();
                tmpWikiStr += wikiAlbumPostfix();
            }
        }
    }

    //Hack to make wiki searches work with magnatune preview tracks

    if ( tmpWikiStr.contains( "PREVIEW: buy it at www.magnatune.com" ) )
    {
        tmpWikiStr = tmpWikiStr.remove(" (PREVIEW: buy it at www.magnatune.com)" );

        int index = tmpWikiStr.indexOf( '-' );
        if ( index != -1 )
            tmpWikiStr = tmpWikiStr.left (index - 1);
    }

    if( m_wikiCurrentEntry == tmpWikiStr )
    {
        debug() << "Same entry requested again. Ignoring.";
        return;
    }

    removeAllData( "wikipedia" );

    foreach( const QString &key, data.keys() )
        setData( key, data[key] );

    m_wikiCurrentEntry = tmpWikiStr;
    m_wikiCurrentUrl = wikiUrl( tmpWikiStr );

    debug() << "wiki url: " << m_wikiCurrentUrl;

    setData( "wikipedia", "message", i18n( "Fetching content.." ) );
    m_wikiJob = KIO::storedGet( m_wikiCurrentUrl, KIO::NoReload, KIO::HideProgressInfo );
    connect( m_wikiJob, SIGNAL( result( KJob* ) ), SLOT( wikiResult( KJob* ) ) );
}
void LyricsEngine::update()
{
    if( m_isUpdateInProgress )
        return;

    m_isUpdateInProgress = true;

    // -- get current title and artist
    Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
    if( !currentTrack )
    {
        debug() << "no current track";
        m_prevLyrics.clear();
        removeAllData( "lyrics" );
        setData( "lyrics", "stopped", "stopped" );
        m_isUpdateInProgress = false;
        return;
    }

    QString title = currentTrack->name();
    QString artist = currentTrack->artist() ? currentTrack->artist()->name() : QString();

    // -- clean up title
    const QString magnatunePreviewString = QLatin1String( "PREVIEW: buy it at www.magnatune.com" );
    if( title.contains(magnatunePreviewString, Qt::CaseSensitive) )
        title = title.remove( " (" + magnatunePreviewString + ")" );
    if( artist.contains(magnatunePreviewString, Qt::CaseSensitive) )
        artist = artist.remove( " (" + magnatunePreviewString + ")" );

    if( title.isEmpty() && currentTrack )
    {
        /* If title is empty, try to use pretty title.
           The fact that it often (but not always) has "artist name" together, can be bad,
           but at least the user will hopefully get nice suggestions. */
        QString prettyTitle = currentTrack->prettyName();
        int h = prettyTitle.indexOf( QLatin1Char('-') );
        if ( h != -1 )
        {
            title = prettyTitle.mid( h + 1 ).trimmed();
            if( title.contains(magnatunePreviewString, Qt::CaseSensitive) )
                title = title.remove( " (" + magnatunePreviewString + ")" );

            if( artist.isEmpty() )
            {
                artist = prettyTitle.mid( 0, h ).trimmed();
                if( artist.contains(magnatunePreviewString, Qt::CaseSensitive) )
                    artist = artist.remove( " (" + magnatunePreviewString + ")" );
            }
        }
    }

    LyricsData lyrics = { currentTrack->cachedLyrics(), title, artist, KUrl() };

    // Check if the title, the artist and the lyrics are still the same.
    if( !lyrics.text.isEmpty() && (lyrics.text == m_prevLyrics.text) )
    {
        debug() << "nothing changed:" << lyrics.title;
        newLyrics( lyrics );
        m_isUpdateInProgress = false;
        return;
    }

    // don't rely on caching for streams
    const bool cached = !LyricsManager::self()->isEmpty( lyrics.text )
        && !The::engineController()->isStream();

    if( cached )
    {
        newLyrics( lyrics );
    }
    else
    {
        // no lyrics, and no lyrics script!
        if( !ScriptManager::instance()->lyricsScriptRunning() )
        {
            debug() << "no lyrics script running";
            removeAllData( "lyrics" );
            setData( "lyrics", "noscriptrunning", "noscriptrunning" );
            disconnect( ScriptManager::instance(), SIGNAL(lyricsScriptStarted()), this, 0 );
            connect( ScriptManager::instance(), SIGNAL(lyricsScriptStarted()), SLOT(update()) );
            m_isUpdateInProgress = false;
            return;
        }

        // fetch by lyrics script
        removeAllData( "lyrics" );
        setData( "lyrics", "fetching", "fetching" );
        ScriptManager::instance()->notifyFetchLyrics( lyrics.artist, lyrics.title );
    }
    m_isUpdateInProgress = false;
}
void
ScrobblerAdapter::banTrack( const Meta::TrackPtr &track ) // slot
{
    if( !track )
        return;

    lastfm::MutableTrack trackInfo;
    copyTrackMetadata( trackInfo, track );
    trackInfo.ban();
    Amarok::Components::logger()->shortMessage( i18nc( "As in Last.fm", "Banned Track: %1", track->prettyName() ) );
}