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

📄 preferenceswindow.cpp

📁 video linux conference
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************** * PreferencesWindow.cpp: beos interface ***************************************************************************** * Copyright (C) 1999, 2000, 2001 VideoLAN * $Id: PreferencesWindow.cpp 11291 2005-06-04 20:09:06Z titer $ * * Authors: Eric Petit <titer@m0k.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA. *****************************************************************************/#include <stdlib.h> /* atoi(), strtod() */#include <String.h>#include <vlc/vlc.h>#include <vlc/intf.h>#include <vlc_keys.h>#include <vlc_config_cat.h>#include "PreferencesWindow.h"#define TYPE_CATEGORY 0#define TYPE_SUBCATEGORY 2#define TYPE_MODULE 3/***************************************************************************** * PreferencesWindow::PreferencesWindow *****************************************************************************/PreferencesWindow::PreferencesWindow( intf_thread_t * _p_intf,                                      BRect frame, const char * name )    : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,               B_NOT_ZOOMABLE ){    p_intf   = _p_intf;    fCurrent = NULL;    BRect rect;    SetSizeLimits( PREFS_WINDOW_WIDTH, 2000, PREFS_WINDOW_HEIGHT, 2000 );    /* The "background" view */    fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );    fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );    AddChild( fPrefsView );    /* Create a scrollable outline view for the preferences tree */    rect = Bounds();    rect.InsetBy( 10, 10 );    rect.right = rect.left + 150;    fOutline = new BOutlineListView( rect, "preferences tree",                                     B_SINGLE_SELECTION_LIST,                                     B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM );    BScrollView * scrollview =        new BScrollView( "scrollview", fOutline,                         B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,                         0, false, true );    fPrefsView->AddChild( scrollview );    /* We need to be informed if the user selects an item */    fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) );    /* Create a dummy, empty view so we can correctly place the real       config views later */    rect.bottom -= 40;    rect.left = rect.right + 15 + B_V_SCROLL_BAR_WIDTH;    rect.right = Bounds().right - 15;    fDummyView = new BView( rect, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW );    fDummyView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );    fPrefsView->AddChild( fDummyView );    /* Fill the tree */    vlc_list_t * p_list;    p_list = vlc_list_find( p_intf, VLC_OBJECT_MODULE, FIND_ANYWHERE );    if( !p_list )    {        msg_Warn( p_intf, "couldn't find any module !" );        return;    }    /* Find the main module */    module_t * p_module = NULL;    module_config_t * p_item = NULL;    for( int i = 0; i < p_list->i_count; i++ )    {        p_module = (module_t*) p_list->p_values[i].p_object;        if( !strcmp( p_module->psz_object_name, "main" ) &&            ( p_item = p_module->p_config ) )            break;        else            p_module = NULL;    }    ConfigItem * catItem = NULL, * subcatItem, * otherItem;    if( p_module )    {        /* We found the main module, build the category tree */        for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )        {            switch( p_item->i_type )            {                case CONFIG_CATEGORY:                    catItem = new ConfigItem( p_intf,                        config_CategoryNameGet( p_item->i_value ),                        false,                        p_item->i_value,                        TYPE_CATEGORY,                        config_CategoryHelpGet( p_item->i_value ) );                    fOutline->AddItem( catItem );                    break;                case CONFIG_SUBCATEGORY:                    if( catItem )                    {                        subcatItem = new ConfigItem( p_intf,                            config_CategoryNameGet( p_item->i_value ),                            false,                            p_item->i_value,                            TYPE_SUBCATEGORY,                            config_CategoryHelpGet( p_item->i_value ) );                        fOutline->AddUnder( subcatItem, catItem );                    }                    else                    {                        msg_Warn( p_intf, "subcategory without a category" );                    }                    break;            }        }    }    /* Now parse all others modules */    int category, subcategory, options;    for( int i = 0; i < p_list->i_count; i++ )    {        category    = -1;        subcategory = -1;        options     = 0;        p_module = (module_t*) p_list->p_values[i].p_object;        if( !strcmp( p_module->psz_object_name, "main" ) )            continue;        if( p_module->b_submodule ||            !( p_item = p_module->p_config ) )            continue;        for( ; p_item->i_type != CONFIG_HINT_END; p_item++ )        {            switch( p_item->i_type )            {                case CONFIG_CATEGORY:                    category = p_item->i_value;                    break;                case CONFIG_SUBCATEGORY:                    subcategory = p_item->i_value;                    break;                default:                    if( p_item->i_type & CONFIG_ITEM )                        options++;            }            if( options > 0 && category >= 0 && subcategory >= 0 )            {                break;            }        }        if( options < 1 || category < 0 || subcategory < 0 )            continue;        catItem = NULL;        for( int j = 0; j < fOutline->CountItemsUnder( NULL, true ); j++ )        {            catItem = (ConfigItem*)                fOutline->ItemUnderAt( NULL, true, j );            if( catItem->ObjectId() == category )                break;            else                catItem = NULL;        }        if( !catItem )            continue;        subcatItem = NULL;        for( int j = 0; j < fOutline->CountItemsUnder( catItem, true ); j++ )        {            subcatItem = (ConfigItem*)                fOutline->ItemUnderAt( catItem, true, j );            if( subcatItem->ObjectId() == subcategory )                break;            else                subcatItem = NULL;        }        if( !subcatItem )            subcatItem = catItem;        otherItem = new ConfigItem( p_intf,            p_module->psz_shortname ?              p_module->psz_shortname : p_module->psz_object_name,            p_module->b_submodule,            p_module->b_submodule ?              ((module_t *)p_module->p_parent)->i_object_id :              p_module->i_object_id,            TYPE_MODULE,            NULL );        fOutline->AddUnder( otherItem, subcatItem );    }    vlc_list_release( p_list );    /* Collapse the whole tree */    for( int i = 0; i < fOutline->FullListCountItems(); i++ )    {        otherItem = (ConfigItem *) fOutline->FullListItemAt( i );        fOutline->Collapse( otherItem );    }    /* Set the correct values */    Apply( false );    /* Select the first item */    fOutline->Select( 0 );    /* Add the buttons */    BButton * button;    rect = Bounds();    rect.InsetBy( 10, 10 );    rect.left = rect.right - 80;    rect.top = rect.bottom - 25;    button = new BButton( rect, "", _("Apply"), new BMessage( PREFS_APPLY ),                          B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );    button->MakeDefault( true );    fPrefsView->AddChild( button );    rect.OffsetBy( -90, 0 );    button = new BButton( rect, "", _("Save"), new BMessage( PREFS_SAVE ),                          B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );    fPrefsView->AddChild( button );    rect.OffsetBy( -90, 0 );    button = new BButton( rect, "", _("Defaults"),                          new BMessage( PREFS_DEFAULTS ),                          B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );    fPrefsView->AddChild( button );    Hide();    Show();}/***************************************************************************** * PreferencesWindow::~PreferencesWindow *****************************************************************************/PreferencesWindow::~PreferencesWindow(){}/***************************************************************************** * PreferencesWindow::QuitRequested *****************************************************************************/bool PreferencesWindow::QuitRequested(){    if( !IsHidden() )    {        Hide();    }    return false;}/***************************************************************************** * PreferencesWindow::MessageReceived *****************************************************************************/void PreferencesWindow::MessageReceived( BMessage * message ){    switch( message->what )    {        case PREFS_ITEM_SELECTED:            Update();            break;        case PREFS_DEFAULTS:            config_ResetAll( p_intf );            config_SaveConfigFile( p_intf, NULL );            Apply( false );            break;        case PREFS_APPLY:            Apply( true );            break;        case PREFS_SAVE:            Apply( true );            config_SaveConfigFile( p_intf, NULL );            break;        default:            BWindow::MessageReceived( message );    }}/***************************************************************************** * PreferencesWindow::FrameResized *****************************************************************************/void PreferencesWindow::FrameResized( float width, float height ){    BWindow::FrameResized( width, height );    fCurrent->UpdateScrollBar();}/***************************************************************************** * PreferencesWindow::Update *****************************************************************************/void PreferencesWindow::Update(){    /* Get the selected item, if any */    if( fOutline->CurrentSelection() < 0 )        return;    /* Detach the old box if any */    if( fCurrent )    {        fCurrent->ResetScroll();        fDummyView->RemoveChild( fCurrent->Box() );    }    /* Add the new one... */    fCurrent = (ConfigItem *)        fOutline->ItemAt( fOutline->CurrentSelection() );    fDummyView->AddChild( fCurrent->Box() );    /* ...then resize it (we must resize it after it's attached or the       children don't get adjusted) */    fCurrent->Box()->ResizeTo( fDummyView->Bounds().Width(),                               fDummyView->Bounds().Height() );    fCurrent->UpdateScrollBar();}/***************************************************************************** * PreferencesWindow::Apply * Apply changes if doIt is true, revert them otherwise *****************************************************************************/void PreferencesWindow::Apply( bool doIt ){    ConfigItem * item;    for( int i = 0; i < fOutline->FullListCountItems(); i++ )    {        item = (ConfigItem*) fOutline->FullListItemAt( i );        item->Apply( doIt );    }}/***************************************************************************** * PreferencesWindow::ReallyQuit *****************************************************************************/void PreferencesWindow::ReallyQuit(){    Lock();    Hide();    Quit();}/*********************************************************************** * ConfigItem::ConfigItem *********************************************************************** * **********************************************************************/ConfigItem::ConfigItem( intf_thread_t * _p_intf, char * name,                        bool subModule, int objectId,                        int type, char * help )    : BStringItem( name ){    p_intf     = _p_intf;    fSubModule = subModule;    fObjectId  = objectId;    fType      = type;    fHelp      = strdup( help );    BRect r;    r = BRect( 0, 0, 100, 100 );    fBox = new BBox( r, NULL, B_FOLLOW_ALL );    fBox->SetLabel( name );    fTextView = NULL;    fScroll   = NULL;    fView     = NULL;    if( fType == TYPE_CATEGORY )    {        /* Category: we just show the help text */        r = fBox->Bounds();        r.InsetBy( 10, 10 );        r.top += 5;        fTextView = new VTextView( r, NULL, B_FOLLOW_ALL, B_WILL_DRAW);        fTextView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );        fTextView->MakeEditable( false );        fTextView->MakeSelectable( false );        fTextView->Insert( fHelp );        fBox->AddChild( fTextView );        return;

⌨️ 快捷键说明

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