Error when calling Amarok::decapitateString()

Nicholas Sinlock isolatedincident at gmail.com
Thu Jan 8 16:26:03 UTC 2009


I've been working on a bug in Amarok and I've run into a fatal error, 
and I was hoping someone could help me figure out why Amarok
is crashing.    Here's the relevant code.  I apologize for the length.

QVariant
PlaylistBrowserNS::PodcastModel::data(const QModelIndex & index, int 
role) const
{

    if ( !index.isValid() ||
         ( role != Qt::DisplayRole && role != Qt::DecorationRole &&
           role != ShortDescriptionRole && role != OnDiskRole ) )
    {
        return QVariant();
    }

    Meta::PodcastMetaCommon* pmc = static_cast<Meta::PodcastMetaCommon 
*>( index.internalPointer() );

    bool isChannel = false;
    QString title, epName, chName;
    QString description;
    KIcon icon;
    bool isOnDisk = false;
    if ( pmc->podcastType() == Meta::ChannelType )
    {
        Meta::PodcastChannel *channel = static_cast<Meta::PodcastChannel 
*>(index.internalPointer());
        title = channel->title();
        description = channel->description();
        isChannel = true;
        icon = KIcon( "podcast-amarok" );
    }
    else if ( pmc->podcastType() == Meta::EpisodeType )
    {
        Meta::PodcastEpisode *episode = static_cast<Meta::PodcastEpisode 
*>( index.internalPointer() );
        Meta::PodcastChannelPtr ptr = episode->channel();
        epName = episode->titel();
        chName = ptr->title();
        if (chName.isEmpty())
            title = epName;
        else
            title = Amarok::decapitateString(epName, chName);
        description = episode->description();
        isChannel = false;
        isOnDisk = !episode->localUrl().isEmpty();
        if( isOnDisk )
            icon = KIcon( "go-down" );
        else
            icon = KIcon( "podcast-amarok" );
    }

According to the crash handler, and some testing on my part, the crash 
appears to be originating in the decapitateString function
and, if I'm reading it correctly, having something to do with the chName 
string.   But no matter what I do, even if I use a simple
quoted string, like "60 Second Science", I recieve the same error.   
Here's the decapitateString function code.

    QString decapitateString( const QString &input, const QString &ref )
    {
        QString t = ref.toUpper();
        int length = t.length();
        int commonLength = 0;
        while( length > 0 )
        {
            if ( input.toUpper().startsWith( t ) )
            {
                commonLength = t.length();
                t = ref.toUpper().left( t.length() + length/2 );
                length = length/2;
            }
            else
            {
                t = ref.toUpper().left( t.length() - length/2 );
                length = length/2;
            }
        }
        QString clean = input;
        if( t.endsWith( ' ' ) || !ref.at( t.length() 
).isLetterOrNumber() ) // common part ends with a space or complete word
            clean = input.right( input.length() - commonLength ).trimmed();
        return clean;
    }




More information about the Amarok mailing list