欢迎来到虫虫下载站 | 资源下载 资源专辑 关于我们
虫虫下载站

prefview.cpp

freeamp有名的媒体播放器
CPP
第 1 页 / 共 3 页
字号:
/*____________________________________________________________________________

   FreeAmp - The Free MP3 Player

   Copyright (C) 1999 EMusic
   Copyright (C) 1999 Hiromasa Kato

   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., 675 Mass Ave, Cambridge, MA 02139, USA.

   $Id: PrefView.cpp,v 1.1 2000/02/15 11:36:41 hiro Exp $
____________________________________________________________________________*/ 

#include "PrefView.h"
#include "preferences.h"
#include "ThemeManager.h"
#include "facontext.h"
#include "event.h"
#include <be/interface/TabView.h>
#include <be/interface/Button.h>
#include <be/interface/TextView.h>
#include <be/interface/Box.h>
#include <be/interface/TextControl.h>
#include <be/interface/CheckBox.h>
#include <be/interface/RadioButton.h>
#include <be/interface/ListView.h>
#include <be/interface/ScrollView.h>
#include <be/interface/Slider.h>
#include <be/storage/FilePanel.h>
#include <be/storage/Entry.h>
#include <be/storage/Path.h>
#define DEBUG 1
#include <be/support/Debug.h>
#include <string>
#include <map>

const char* FREEAMP_ABOUT_TEXT =
    "FreeAmp is an Open Source effort to build the best digital audio player "
    "available.  In the interest of supporting the free software community, "
    "while at the same time fostering the growth of the online delivery of "
    "music, EMusic.com, THE Source for Downloadable Music, is funding both "
    "the FreeAmp.org domain and the efforts of the FreeAmp team.  The FreeAmp "
    "team consists of:\n\n"
    "Mark B. Elrod, Robert Kaye, Isaac Richards, Brett Thomas, and "
    "Jason Woodward.\n\n"
    "Other people have also contributed to FreeAmp:\n\n"
    "William Bull, Alan Cutter, Gabor Fleischer, Jean-Michel HERVE, "
    "Hiromasa Kato, Michael Bruun Petersen, Sylvain Rebaud, "
    "The Snowblind Alliance, Tom Spindler, Valters Vingolds, Bill Yuan."; 

const float GRID_UNIT = 10.0;
const float BOX_INSET = 13.0;

// Message constants
const uint32 MSG_OK = 'okay';
const uint32 MSG_CANCEL = 'cncl';
const uint32 MSG_APPLY = 'aply';
const uint32 MSG_THEME_SELECTED = 'thms';
const uint32 MSG_BROWSE_DIR = 'brws';
const uint32 MSG_SET_MYMUSIC_DIR = 'mmdr';
const uint32 MSG_SET_CHECK_FOR_UPDATES = 'cfud';
const uint32 MSG_SET_RECLAIM_FILETYPES = 'rclm';
const uint32 MSG_SET_ASK_RECLAIM_FILETYPES = 'askr';
const uint32 MSG_SET_TEXT_ONLY = 'txtl';
const uint32 MSG_SET_IMAGES_ONLY = 'imgs';
const uint32 MSG_SET_TEXT_AND_IMAGES = 'txim';
const uint32 MSG_SET_SAVE_PLAYLIST_ON_EXIT = 'spoe';
const uint32 MSG_SET_PLAY_IMMEDIATELY = 'plyi';
const uint32 MSG_SET_DECODER_PRIORITY = 'dcdr';
const uint32 MSG_SET_INPUT_BUFFER_SIZE = 'inpb';
const uint32 MSG_SET_OUTPUT_BUFFER_SIZE = 'outb';
const uint32 MSG_SET_PRE_BUFFER_LENGTH = 'preb';

PrefView::PrefView( FAContext* context, ThemeManager* themeMan,
                    BRect frame, const char* name )
:   BView( frame, name, B_FOLLOW_ALL, B_WILL_DRAW ),
    m_prefs( context->prefs ),
    m_context( context ),
    m_themeMan( themeMan )
{
    GetPrefsValues( m_prefs, &m_originalValues );
    m_proposedValues = m_currentValues = m_originalValues;

    SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );

    // Buttons
    float buttonWidth, buttonHeight;
    BRect buttonRect( 0, 0, 100, 50 );

    BButton* okButton = new BButton( buttonRect, "OKButton", "OK",
                                     new BMessage( MSG_OK ),
                                     B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
    BButton* cancelButton = new BButton( buttonRect, "CancelButton", "Cancel",
                                         new BMessage( MSG_CANCEL ),
                                         B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
    BButton* applyButton = new BButton( buttonRect, "ApplyButton", "Apply",
                                        new BMessage( MSG_APPLY ),
                                        B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
    okButton->ResizeToPreferred();
    cancelButton->ResizeToPreferred();
    applyButton->ResizeToPreferred();
    cancelButton->GetPreferredSize( &buttonWidth, &buttonHeight );
    okButton->MoveTo( Bounds().right - buttonWidth - 2 * GRID_UNIT,
                      Bounds().bottom - buttonHeight - GRID_UNIT );
    applyButton->MoveTo( okButton->Frame().left - buttonWidth - GRID_UNIT,
                         okButton->Frame().top );
    cancelButton->MoveTo( applyButton->Frame().left - buttonWidth - GRID_UNIT,
                          applyButton->Frame().top );
    okButton->MakeDefault( true );
    AddChild( okButton );
    AddChild( applyButton );
    AddChild( cancelButton );
    m_controls.push_back( okButton );
    m_controls.push_back( applyButton );
    m_controls.push_back( cancelButton );

    // Tab container
    BRect r( Bounds() );
    r.bottom -= buttonHeight + 2 * GRID_UNIT;
    PrefTabView* tabView = new PrefTabView( r, "TabView" );

    // Tabbed panes
    r.InsetBy( 5, 5 );
    r.bottom -= tabView->TabHeight();

    m_general = new PrefPane( r, "General" );
    tabView->AddTab( m_general );
    m_themes = new PrefPane( r, "Themes" );
    tabView->AddTab( m_themes );
    m_advanced = new PrefPane( r, "Advanced" );
    tabView->AddTab( m_advanced );
    m_about = new PrefPane( r, "About" );
    tabView->AddTab(m_about);

    CreateGeneralPane();
    CreateThemesPane();
    CreateAdvancedPane();
    CreateAboutPane();

    AddChild( tabView );
}

PrefView::~PrefView()
{
}

void
PrefView::AttachedToWindow( void )
{
    BView::AttachedToWindow();
    m_about->FindView( "AboutText" )
           ->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
    ((BListView*)m_themes->FindView( "ThemeList" ))->SetTarget( this );

    vector<BControl*>::iterator i;
    for ( i = m_controls.begin(); i != m_controls.end(); i++ )
    {
        printf( "setting up the target for %s\n", (*i)->Name() );
        (*i)->SetTarget( this );
    }
}

void
PrefView::MessageReceived( BMessage* message )
{
    switch ( message->what )
    {
    case MSG_OK:
        Apply();
        Window()->PostMessage( B_QUIT_REQUESTED );
        break;
    case MSG_APPLY:
        Apply();
        break;
    case MSG_CANCEL:
        Window()->PostMessage( B_QUIT_REQUESTED );
        break;
    case MSG_BROWSE_DIR:
        {
            if ( !m_filePanel )
            {
                PRINT(( "constructing BFilePanel\n" ));
                BMessage reply( MSG_SET_MYMUSIC_DIR );
                m_filePanel = new BFilePanel(
                                B_OPEN_PANEL,
                                new BMessenger( this ),
                                NULL,
                                B_DIRECTORY_NODE, // node_flavors,
                                false,            // allow_multiple_selection
                                &reply            // message is set below
                                );
            }
            m_filePanel->Show();
        }
        break;
    case MSG_SET_MYMUSIC_DIR:
        {
            entry_ref ref;
            if ( message->FindRef( "refs", &ref ) < B_NO_ERROR ) break;
            BEntry entry( &ref );
            BPath path;
            entry.GetPath( &path );
            SetSaveMusicDirectory( path.Path() );

            // need to delete file panel myself.
            delete m_filePanel;
            m_filePanel = NULL;
        }
        break;
    case MSG_SET_CHECK_FOR_UPDATES:
        message->PrintToStream();
        SetCheckForUpdates( (message->FindInt32( "be:value" ) == B_CONTROL_ON) );
        break;
    case MSG_SET_RECLAIM_FILETYPES:
        m_proposedValues.reclaimFiletypes =
            ( message->FindInt32( "be:value" ) == B_CONTROL_ON );
        break;
    case MSG_SET_ASK_RECLAIM_FILETYPES:
        m_proposedValues.askReclaimFiletypes =
            ( message->FindInt32( "be:value" ) == B_CONTROL_ON );
        printf( "val = %d\n", m_proposedValues.askReclaimFiletypes );
        break;
    case MSG_SET_TEXT_ONLY:
        m_proposedValues.useTextLabels = true;
        m_proposedValues.useImages = false;
        break;
    case MSG_SET_IMAGES_ONLY:
        m_proposedValues.useTextLabels = false;
        m_proposedValues.useImages = true;
        break;
    case MSG_SET_TEXT_AND_IMAGES:
        m_proposedValues.useTextLabels = true;
        m_proposedValues.useImages = true;
        break;
    case MSG_SET_SAVE_PLAYLIST_ON_EXIT:
        m_proposedValues.savePlaylistOnExit =
            ( message->FindInt32( "be:value" ) == B_CONTROL_ON );
        break;
    case MSG_SET_PLAY_IMMEDIATELY:
        m_proposedValues.playImmediately =
            ( message->FindInt32( "be:value" ) == B_CONTROL_ON );
        break;
    case MSG_THEME_SELECTED:
        {
            BListView* list;
            if ( message->FindPointer( "source", (void**)&list ) == B_OK )
            {
                BStringItem* item =
                    (BStringItem*)list->ItemAt( list->CurrentSelection() );
                m_proposedValues.currentTheme = item->Text();
            }
        }
        break;
    case MSG_SET_INPUT_BUFFER_SIZE:
        {
            BTextControl* ctrl;
            int32 size = m_originalValues.inputBufferSize;;
            if ( message->FindPointer( "source", (void**)&ctrl ) < B_OK ) break;
            sscanf( ctrl->Text(), "%ld", &size );
            m_proposedValues.inputBufferSize = size;
        }
        break;
    case MSG_SET_OUTPUT_BUFFER_SIZE:
        {
            BTextControl* ctrl;
            int32 size = m_originalValues.outputBufferSize;;
            if ( message->FindPointer( "source", (void**)&ctrl ) < B_OK ) break;
            sscanf( ctrl->Text(), "%ld", &size );
            m_proposedValues.outputBufferSize = size;
        }
        break;
    case MSG_SET_DECODER_PRIORITY:
        SetDecoderThreadPriority( message->FindInt32( "be:value" ) );
        break;
    default:
        BView::MessageReceived( message );
        break;
    }
}

void
PrefView::Apply( void )
{
    if ( m_proposedValues != m_currentValues )
    {
       SavePrefsValues( m_prefs, &m_proposedValues );
    }
}

⌨️ 快捷键说明

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