示例#1
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 )
示例#2
0
// to be used with qSort.
static bool
lessThanPlaylistTitles( const Playlists::PlaylistPtr &lhs, const Playlists::PlaylistPtr &rhs )
{
    return lhs->prettyName().toLower() < rhs->prettyName().toLower();
}