/*
 * Reads and updates the playlist's duration as [xx:xx] after the label in the tree
 * item - the treeview item to get the duration for
 * prefix - the string to use before the time (should be the category name)
 */
void PLSelector::updateTotalDuration( PLSelItem* item, const char* prefix )
{
    /* Getting  the playlist */
    QVariant playlistVariant = item->treeItem()->data( 0, PL_ITEM_ROLE );
    playlist_item_t* node = playlistVariant.value<playlist_item_t*>();

    /* Get the duration of the playlist item */
    playlist_Lock( THEPL );
    mtime_t mt_duration = playlist_GetNodeDuration( node );
    playlist_Unlock( THEPL );

    /* Formatting time */
    QString qs_timeLabel( prefix );

    int i_seconds = mt_duration / 1000000;
    int i_minutes = i_seconds / 60;
    i_seconds = i_seconds % 60;
    if( i_minutes >= 60 )
    {
        int i_hours = i_minutes / 60;
        i_minutes = i_minutes % 60;
        qs_timeLabel += QString(" [%1:%2:%3]").arg( i_hours ).arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );
    }
    else
        qs_timeLabel += QString( " [%1:%2]").arg( i_minutes, 2, 10, QChar('0') ).arg( i_seconds, 2, 10, QChar('0') );

    item->setText( qs_timeLabel );
}
Ejemplo n.º 2
0
Archivo: item.c Proyecto: BossKing/vlc
/**
 * Get the duration of all items in a node.
 */
mtime_t playlist_GetNodeDuration( playlist_item_t* node )
{
    /* For the assert */
    playlist_t *p_playlist = node->p_playlist;
    PL_ASSERT_LOCKED;

    mtime_t mt_duration = 0;

    if( node->i_children != -1 )
        for( int i = 0; i < node->i_children; i++ )
        {
            input_item_t* p_input = node->pp_children[i]->p_input;
            if ( p_input->i_type == ITEM_TYPE_NODE )
                mt_duration += playlist_GetNodeDuration( node->pp_children[i] );
            else
                mt_duration += input_item_GetDuration( p_input );
        }

    return mt_duration;
}