⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menus.cpp

📁 VLC Player Source Code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                if( p_object )                {                    objects.push_back( p_object->i_object_id );                    varnames.push_back( "intf-skins" );                    Populate( p_intf, submenu, varnames, objects );                    vlc_object_release( p_object );                }                else                {                    msg_Dbg( p_intf, "could not find parent interface" );                }            }            menu->addMenu( submenu );        }        PopupMenuStaticEntries( p_intf, menu );        p_intf->p_sys->p_popup_menu = menu;        p_intf->p_sys->p_popup_menu->popup( QCursor::pos() );    }    else    {        // destroy popup if there is one        delete p_intf->p_sys->p_popup_menu;        p_intf->p_sys->p_popup_menu = NULL;    }}#undef ACT_ADD/************************************************************************ * Systray Menu                                                         * ************************************************************************/void QVLCMenu::updateSystrayMenu( MainInterface *mi,                                  intf_thread_t *p_intf,                                  bool b_force_visible ){    POPUP_BOILERPLATE;    /* Get the systray menu and clean it */    QMenu *sysMenu = mi->getSysTrayMenu();    sysMenu->clear();    /* Hide / Show VLC and cone */    if( mi->isVisible() || b_force_visible )    {        sysMenu->addAction( QIcon( ":/vlc16.png" ),                            qtr( "Hide VLC media player in taskbar" ), mi,                            SLOT( toggleUpdateSystrayMenu() ) );    }    else    {        sysMenu->addAction( QIcon( ":/vlc16.png" ),                            qtr( "Show VLC media player" ), mi,                            SLOT( toggleUpdateSystrayMenu() ) );    }    sysMenu->addSeparator();    PopupMenuControlEntries( sysMenu, p_intf, p_input );    sysMenu->addSeparator();    addDPStaticEntry( sysMenu, qtr( "&Open Media" ), "",            ":/file-wide", SLOT( openFileDialog() ), "" );    addDPStaticEntry( sysMenu, qtr( "&Quit" ) , "",            ":/quit", SLOT( quit() ), "" );    /* Set the menu */    mi->getSysTray()->setContextMenu( sysMenu );}#undef PUSH_VAR#undef PUSH_SEPARATOR/************************************************************************* * Builders for automenus *************************************************************************/QMenu * QVLCMenu::Populate( intf_thread_t *p_intf,                            QMenu *current,                            vector< const char *> & varnames,                            vector<int> & objects,                            bool append ){    QMenu *menu = current;    if( !menu ) menu = new QMenu();    /* Disable all non static entries */    QAction *p_action;    foreach( p_action, menu->actions() )    {        if( p_action->data().toString() != "_static_" )            p_action->setEnabled( false );    }    currentGroup = NULL;    vlc_object_t *p_object;    int i;    for( i = 0; i < ( int )objects.size() ; i++ )    {        if( !varnames[i] || !*varnames[i] )        {            menu->addSeparator();            continue;        }        if( objects[i] == 0 )        {            p_object = NULL;        }        else        {            p_object = ( vlc_object_t * )vlc_object_get( objects[i] );            if( !p_object )            {                msg_Warn( p_intf, "object %d not found !", objects[i] );                continue;            }        }        UpdateItem( p_intf, menu, varnames[i], p_object, true );        if( p_object )            vlc_object_release( p_object );    }    return menu;}/***************************************************************************** * Private methods. *****************************************************************************/static bool IsMenuEmpty( const char *psz_var,                         vlc_object_t *p_object,                         bool b_root = true ){    vlc_value_t val, val_list;    int i_type, i_result, i;    /* Check the type of the object variable */    i_type = var_Type( p_object, psz_var );    /* Check if we want to display the variable */    if( !( i_type & VLC_VAR_HASCHOICE ) ) return false;    var_Change( p_object, psz_var, VLC_VAR_CHOICESCOUNT, &val, NULL );    if( val.i_int == 0 ) return true;    if( ( i_type & VLC_VAR_TYPE ) != VLC_VAR_VARIABLE )    {        if( val.i_int == 1 && b_root ) return true;        else return false;    }    /* Check children variables in case of VLC_VAR_VARIABLE */    if( var_Change( p_object, psz_var, VLC_VAR_GETLIST, &val_list, NULL ) < 0 )    {        return true;    }    for( i = 0, i_result = true; i < val_list.p_list->i_count; i++ )    {        if( !IsMenuEmpty( val_list.p_list->p_values[i].psz_string,                    p_object, false ) )        {            i_result = false;            break;        }    }    /* clean up everything */    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, NULL );    return i_result;}#define TEXT_OR_VAR qfu ( text.psz_string ? text.psz_string : psz_var )void QVLCMenu::UpdateItem( intf_thread_t *p_intf, QMenu *menu,        const char *psz_var, vlc_object_t *p_object, bool b_submenu ){    vlc_value_t val, text;    int i_type;    QAction *action = FindActionWithVar( menu, psz_var );    if( action )        DeleteNonStaticEntries( action->menu() );    if( !p_object )        return;    /* Check the type of the object variable */    if( !strcmp( psz_var, "audio-es" )     || !strcmp( psz_var, "video-es" ) )        i_type = VLC_VAR_INTEGER | VLC_VAR_HASCHOICE;    else        i_type = var_Type( p_object, psz_var );    switch( i_type & VLC_VAR_TYPE )    {        case VLC_VAR_VOID:        case VLC_VAR_BOOL:        case VLC_VAR_VARIABLE:        case VLC_VAR_STRING:        case VLC_VAR_INTEGER:        case VLC_VAR_FLOAT:            break;        default:            /* Variable doesn't exist or isn't handled */            return;    }    /* Make sure we want to display the variable */    if( menu->isEmpty() && IsMenuEmpty( psz_var, p_object ) )        return;    /* Get the descriptive name of the variable */    int i_ret = var_Change( p_object, psz_var, VLC_VAR_GETTEXT, &text, NULL );    if( i_ret != VLC_SUCCESS )    {        text.psz_string = NULL;    }    if( !action )    {        action = new QAction( TEXT_OR_VAR, menu );        menu->addAction( action );        action->setData( psz_var );    }    /* Some specific stuff */    bool forceDisabled = false;    if( !strcmp( psz_var, "spu-es" ) )    {        vlc_object_t *p_vout = ( vlc_object_t* )( vlc_object_find( p_intf,                                    VLC_OBJECT_VOUT, FIND_ANYWHERE ) );        forceDisabled = ( p_vout == NULL );        if( p_vout )            vlc_object_release( p_vout );    }    if( i_type & VLC_VAR_HASCHOICE )    {        /* Append choices menu */        if( b_submenu )        {            QMenu *submenu;            submenu = action->menu();            if( !submenu )            {                submenu = new QMenu( menu );                action->setMenu( submenu );            }            action->setEnabled(               CreateChoicesMenu( submenu, psz_var, p_object, true ) == 0 );            if( forceDisabled )                action->setEnabled( false );        }        else            CreateChoicesMenu( menu, psz_var, p_object, true );        FREENULL( text.psz_string );        return;    }    switch( i_type & VLC_VAR_TYPE )    {        case VLC_VAR_VOID:            var_Get( p_object, psz_var, &val );            CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_NORMAL,                    p_object->i_object_id, val, i_type );            break;        case VLC_VAR_BOOL:            var_Get( p_object, psz_var, &val );            val.b_bool = !val.b_bool;            CreateAndConnect( menu, psz_var, TEXT_OR_VAR, "", ITEM_CHECK,                    p_object->i_object_id, val, i_type, !val.b_bool );            break;    }    FREENULL( text.psz_string );}int QVLCMenu::CreateChoicesMenu( QMenu *submenu, const char *psz_var,        vlc_object_t *p_object, bool b_root ){    vlc_value_t val, val_list, text_list;    int i_type, i;    /* Check the type of the object variable */    i_type = var_Type( p_object, psz_var );    /* Make sure we want to display the variable */    if( submenu->isEmpty() && IsMenuEmpty( psz_var, p_object, b_root ) )        return VLC_EGENERIC;    switch( i_type & VLC_VAR_TYPE )    {        case VLC_VAR_VOID:        case VLC_VAR_BOOL:        case VLC_VAR_VARIABLE:        case VLC_VAR_STRING:        case VLC_VAR_INTEGER:        case VLC_VAR_FLOAT:            break;        default:            /* Variable doesn't exist or isn't handled */            return VLC_EGENERIC;    }    if( var_Change( p_object, psz_var, VLC_VAR_GETLIST,                    &val_list, &text_list ) < 0 )    {        return VLC_EGENERIC;    }#define NORMAL_OR_RADIO i_type & VLC_VAR_ISCOMMAND ? ITEM_NORMAL: ITEM_RADIO#define NOTCOMMAND !( i_type & VLC_VAR_ISCOMMAND )#define CURVAL val_list.p_list->p_values[i]#define CURTEXT text_list.p_list->p_values[i].psz_string    for( i = 0; i < val_list.p_list->i_count; i++ )    {        vlc_value_t another_val;        QString menutext;        QMenu *subsubmenu = new QMenu( submenu );        switch( i_type & VLC_VAR_TYPE )        {            case VLC_VAR_VARIABLE:                CreateChoicesMenu( subsubmenu, CURVAL.psz_string, p_object, false );                subsubmenu->setTitle( qfu( CURTEXT ? CURTEXT :CURVAL.psz_string ) );                submenu->addMenu( subsubmenu );                break;            case VLC_VAR_STRING:                var_Get( p_object, psz_var, &val );                another_val.psz_string = strdup( CURVAL.psz_string );                menutext = qfu( CURTEXT ? CURTEXT : another_val.psz_string );                CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,                        p_object->i_object_id, another_val, i_type,                        NOTCOMMAND && val.psz_string &&                        !strcmp( val.psz_string, CURVAL.psz_string ) );                free( val.psz_string );                break;            case VLC_VAR_INTEGER:                var_Get( p_object, psz_var, &val );                if( CURTEXT ) menutext = qfu( CURTEXT );                else menutext.sprintf( "%d", CURVAL.i_int );                CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,                        p_object->i_object_id, CURVAL, i_type,                        NOTCOMMAND && CURVAL.i_int == val.i_int );                break;            case VLC_VAR_FLOAT:                var_Get( p_object, psz_var, &val );                if( CURTEXT ) menutext = qfu( CURTEXT );                else menutext.sprintf( "%.2f", CURVAL.f_float );                CreateAndConnect( submenu, psz_var, menutext, "", NORMAL_OR_RADIO,                        p_object->i_object_id, CURVAL, i_type,                        NOTCOMMAND && CURVAL.f_float == val.f_float );                break;            default:                break;        }    }    currentGroup = NULL;    /* clean up everything */    var_Change( p_object, psz_var, VLC_VAR_FREELIST, &val_list, &text_list );#undef NORMAL_OR_RADIO#undef NOTCOMMAND#undef CURVAL#undef CURTEXT    return VLC_SUCCESS;}void QVLCMenu::CreateAndConnect( QMenu *menu, const char *psz_var,        QString text, QString help,        int i_item_type, int i_object_id,        vlc_value_t val, int i_val_type,        bool checked ){    QAction *action = FindActionWithVar( menu, psz_var );    if( !action )    {        action = new QAction( text, menu );        menu->addAction( action );    }    action->setToolTip( help );    action->setEnabled( i_object_id != 0 );    if( i_item_type == ITEM_CHECK )    {        action->setCheckable( true );    }    else if( i_item_type == ITEM_RADIO )    {        action->setCheckable( true );        if( !currentGroup )            currentGroup = new QActionGroup( menu );        currentGroup->addAction( action );    }    action->setChecked( checked );    MenuItemData *itemData = new MenuItemData( THEDP->menusMapper, i_object_id, i_val_type,            val, psz_var );    CONNECT( action, triggered(), THEDP->menusMapper, map() );    THEDP->menusMapper->setMapping( action, itemData );    menu->addAction( action );}void QVLCMenu::DoAction( intf_thread_t *p_intf, QObject *data ){    MenuItemData *itemData = qobject_cast<MenuItemData *>( data );    vlc_object_t *p_object = ( vlc_object_t * )vlc_object_get( itemData->i_object_id );    if( p_object == NULL ) return;    var_Set( p_object, itemData->psz_var, itemData->val );    vlc_object_release( p_object );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -