示例#1
0
文件: ml_model.cpp 项目: AsamQi/vlc
bool MLModel::event( QEvent *event )
{
    if ( event->type() == MLEvent::MediaAdded_Type )
    {
        event->accept();
        MLEvent *e = static_cast<MLEvent *>(event);
        vlc_array_t* p_result = vlc_array_new();
        if ( ml_FindMedia( e->p_ml, p_result, ML_ID, e->ml_media_id ) == VLC_SUCCESS )
        {
            insertResultArray( p_result );
            ml_DestroyResultArray( p_result );
        }
        vlc_array_destroy( p_result );
        return true;
    }
    else if( event->type() == MLEvent::MediaRemoved_Type )
    {
        event->accept();
        MLEvent *e = static_cast<MLEvent *>(event);
        removeRow( getIndexByMLID( e->ml_media_id ).row() );
        return true;
    }
    else if( event->type() == MLEvent::MediaUpdated_Type )
    {
        event->accept();
        /* Never implemented... */
        return true;
    }

    return VLCModel::event( event );
}
static int mediaAdded( vlc_object_t *p_this, char const *psz_var,
                                  vlc_value_t oldval, vlc_value_t newval,
                                  void *data )
{
    VLC_UNUSED( psz_var ); VLC_UNUSED( oldval );

    int ret = VLC_SUCCESS;
    media_library_t *p_ml = ( media_library_t* )p_this;
    MLModel* p_model = ( MLModel* )data;
    vlc_array_t* p_result = vlc_array_new();
    ret = ml_FindMedia( p_ml, p_result, ML_ID, newval.i_int );
    if( ret != VLC_SUCCESS )
    {
        vlc_array_destroy( p_result );
        return VLC_EGENERIC;
    }
    p_model->insertResultArray( p_result );
    vlc_array_destroy( p_result );
    return VLC_SUCCESS;
}