* PreferencesWindow.cpp: beos interface
*****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN
- * $Id: PreferencesWindow.cpp,v 1.14 2003/04/22 16:36:16 titer Exp $
+ * $Id: PreferencesWindow.cpp,v 1.15 2003/05/03 13:37:21 titer Exp $
*
* Authors: Eric Petit <titer@videolan.org>
*
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
-/* system headers */
-#include <malloc.h>
-#include <string.h>
+#include <stdlib.h> /* atoi(), strtod() */
-/* BeOS headers */
#include <InterfaceKit.h>
-#include <Entry.h>
-#include <Path.h>
-#include <TranslatorRoster.h>
+#include <SupportKit.h>
-/* VLC headers */
#include <vlc/vlc.h>
#include <vlc/intf.h>
-/* BeOS module headers */
-#include "VlcWrapper.h"
-#include "MsgVals.h"
#include "PreferencesWindow.h"
-static const char* kTranslatorField = "be:translator";
-static const char* kTypeField = "be:type";
-static const char* kDefaultScreenShotPath = "/boot/home/vlc screenshot";
-static const uint32 kDefaultScreenShotFormat = 'PNG ';
-
-// add_translator_items
-status_t
-add_translator_items( BMenu* intoMenu, uint32 fromType, uint32 command )
-{
- BTranslatorRoster* roster = BTranslatorRoster::Default();
- translator_id* ids = NULL;
- int32 count = 0;
-
- status_t err = B_NO_INIT;
- if ( roster )
- err = roster->GetAllTranslators( &ids, &count );
- if ( err < B_OK )
- return err;
- for ( int32 tix = 0; tix < count; tix++ )
- {
- const translation_format* formats = NULL;
- int32 num_formats = 0;
- bool checkOutFormats = false;
- err = roster->GetInputFormats( ids[tix], &formats, &num_formats );
- if ( err == B_OK )
- {
- for ( int iix = 0; iix < num_formats; iix++ )
- {
- if ( formats[iix].type == fromType )
- {
- checkOutFormats = true;
- break;
- }
- }
- }
- if ( !checkOutFormats )
- continue;
- err = roster->GetOutputFormats(ids[tix], &formats, &num_formats);
- if ( err == B_OK )
- {
- for ( int32 oix = 0; oix < num_formats; oix++ )
- {
- if ( formats[oix].type != fromType )
- {
- BMessage* message = new BMessage( command );
- message->AddInt32( kTranslatorField, ids[tix] );
- message->AddInt32( kTypeField, formats[oix].type );
- intoMenu->AddItem( new BMenuItem( formats[oix].name, message ) );
- }
- }
- }
- }
- delete[] ids;
- return B_OK;
-}
-
-// get_config_string
-char*
-get_config_string( intf_thread_t* intf, const char* field, const char* defaultString )
-{
- char* string = config_GetPsz( intf, field );
- if ( !string )
- {
- string = strdup( defaultString );
- config_PutPsz( intf, field, string );
- }
- return string;
-}
-
-// get_config_int
-int32
-get_config_int( intf_thread_t* intf, const char* field, int32 defaultValue )
-{
- int32 value = config_GetInt( intf, field );
- if ( value < 0 )
- {
- value = defaultValue;
- config_PutInt( intf, field, value );
- }
- return value;
-}
-
-// get_config_float
-float
-get_config_float( intf_thread_t* intf, const char* field, float defaultValue )
-{
- float value = config_GetFloat( intf, field );
- if ( value < 0 )
- {
- value = defaultValue;
- config_PutFloat( intf, field, value );
- }
- return value;
-}
-
-
/*****************************************************************************
- * DirectoryTextControl class
+ * StringItemWithView::StringItemWithView
*****************************************************************************/
-class DirectoryTextControl : public BTextControl
-{
- public:
- DirectoryTextControl( BRect frame, const char* name,
- const char* label, const char* text,
- BMessage* message,
- uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
- uint32 flags = B_WILL_DRAW | B_NAVIGABLE );
- virtual ~DirectoryTextControl();
-
- virtual void MessageReceived(BMessage *msg);
-};
-
-DirectoryTextControl::DirectoryTextControl( BRect frame, const char* name,
- const char* label, const char* text,
- BMessage* message,
- uint32 resizingMode, uint32 flags)
- : BTextControl( frame, name, label, text, message, resizingMode, flags )
-{
-}
-
-DirectoryTextControl::~DirectoryTextControl()
+StringItemWithView::StringItemWithView( const char * text )
+ : BStringItem( text )
{
+ /* We use the default constructor */
}
/*****************************************************************************
- * DirectoryTextControl::MessageReceived
+ * ConfigView::ConfigView
*****************************************************************************/
-void
-DirectoryTextControl::MessageReceived( BMessage* message )
+ConfigView::ConfigView( BRect frame, const char * name,
+ uint32 resizingMode, uint32 flags )
+ : BView( frame, name, resizingMode, flags )
{
- switch ( message->what )
- {
- case B_SIMPLE_DATA:
- {
- entry_ref ref;
- if ( message->FindRef( "refs", &ref ) == B_OK ) {
- BString directory;
- BEntry entry;
- BPath path;
- if ( entry.SetTo( &ref, true ) == B_OK
- && entry.IsDirectory()
- && path.SetTo( &entry ) == B_OK )
- {
- SetText( path.Path() );
- }
- }
- break;
- }
- default:
- BTextControl::MessageReceived( message );
- break;
- }
+ /* We use the default constructor */
}
-
-
/*****************************************************************************
- * Preferences::PreferencesWindow
+ * PreferencesWindow::PreferencesWindow
*****************************************************************************/
PreferencesWindow::PreferencesWindow( intf_thread_t * p_interface,
BRect frame, const char * name )
: BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
- B_NOT_ZOOMABLE | B_NOT_RESIZABLE ),
- fDVDMenusBackup( false ),
- fPostProcessingBackup( 0 ),
- fBrightnessBackup( 100.0 ),
- fContrastBackup( 100.0 ),
- fHueBackup( 0 ),
- fSaturationBackup( 100.0 ),
- fScreenShotPathBackup( kDefaultScreenShotPath ),
- fScreenShotFormatBackup( kDefaultScreenShotFormat ),
- p_intf( p_interface )
+ B_NOT_ZOOMABLE ),
+ fConfigScroll( NULL ),
+ p_intf( p_interface )
{
BRect rect;
- /* "background" view */
+ /* The "background" view */
rgb_color background = ui_color( B_PANEL_BACKGROUND_COLOR );
fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
fPrefsView->SetViewColor( background );
AddChild( fPrefsView );
-
- /* add the tabs */
- rect = Bounds();
- rect.top += 10.0;
- rect.bottom -= 45.0;
- fTabView = new BTabView( rect, "preferences view" );
- fTabView->SetViewColor( background );
- fGeneralView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
- fGeneralView->SetViewColor( background );
- fAdjustView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
- fAdjustView->SetViewColor( background );
+ /* Create 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 );
+
+ rect.right += B_V_SCROLL_BAR_WIDTH;
+ BScrollView * scrollview = new BScrollView( "scrollview", fOutline,
+ B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM,
+ 0, false, true );
+ fPrefsView->AddChild( scrollview );
- fGeneralTab = new BTab();
- fTabView->AddTab( fGeneralView, fGeneralTab );
- fGeneralTab->SetLabel( _("General") );
+ /* We need to be informed if the user selects an item */
+ fOutline->SetSelectionMessage( new BMessage( PREFS_ITEM_SELECTED ) );
+
+ /* Create a dummy view so we can correctly place the real config views later */
+ rect.bottom -= 40;
+ rect.left = rect.right + 15;
+ rect.right = Bounds().right - 15;
+ fDummyView = new BView( rect, "", B_FOLLOW_ALL_SIDES, B_WILL_DRAW );
+ fPrefsView->AddChild( fDummyView );
+
+ /* Fill the tree */
+ /* TODO:
+ - manage CONFIG_HINT_SUBCATEGORY
+ - use a pop-up for CONFIG_HINT_MODULE
+ - use BSliders for integer_with_range and float_with_range
+ - add a tab for BeOS specific configution (screenshot path, etc)
+ - add the needed LockLooper()s
+ - fix window resizing
+ - make this intuitive ! */
+ 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;
+ }
+
+ module_t * p_module;
+ for( int i = 0; i < p_list->i_count; i++ )
+ {
+ p_module = (module_t*) p_list->p_values[i].p_object;
+
+ /* If the module has no config option, ignore it */
+ module_config_t * p_item;
+ p_item = p_module->p_config;
+ if( !p_item )
+ continue;
+ do
+ {
+ if( p_item->i_type & CONFIG_ITEM )
+ break;
+ } while( p_item->i_type != CONFIG_HINT_END && p_item++ );
+ if( p_item->i_type == CONFIG_HINT_END )
+ continue;
+
+ /* Build the config view for this module */
+ rect = fDummyView->Bounds();
+ rect.right -= B_V_SCROLL_BAR_WIDTH;
+ ConfigView * configView;
+ configView = new ConfigView( rect, "config view",
+ B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW );
+ configView->SetViewColor( background );
+
+ rect = configView->Bounds();
+ rect.InsetBy( 10, 10 );
+ rect.bottom = rect.top + TEXT_HEIGHT;
+ BTextControl * textControl;
+ BCheckBox * checkBox;
+
+ /* FIXME: we use the BControl name to store the VLC variable name.
+ To know what variable type it is, I add one character at the beginning
+ of the name (see ApplyChanges()); it's not pretty, but it works. To
+ be cleaned later. */
+ char name[128];
+ p_item = p_module->p_config;
+ bool firstItem = true;
+ do
+ {
+ switch( p_item->i_type )
+ {
+ case CONFIG_ITEM_STRING:
+ case CONFIG_ITEM_FILE:
+ case CONFIG_ITEM_MODULE:
+ case CONFIG_ITEM_DIRECTORY:
+ if( !firstItem )
+ rect.OffsetBy( 0, 25 );
+ else
+ firstItem = false;
+
+ memset( name, 0, 128 );
+ sprintf( name, "s%s", p_item->psz_name );
+ textControl = new BTextControl( rect, name, p_item->psz_text,
+ "", new BMessage(),
+ B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
+ configView->AddChild( textControl );
+ break;
+
+ case CONFIG_ITEM_INTEGER:
+ if( !firstItem )
+ rect.OffsetBy( 0, 25 );
+ else
+ firstItem = false;
+
+ memset( name, 0, 128 );
+ sprintf( name, "i%s", p_item->psz_name );
+ textControl = new BTextControl( rect, name, p_item->psz_text,
+ "", new BMessage(),
+ B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
+ configView->AddChild( textControl );
+ break;
+
+ case CONFIG_ITEM_FLOAT:
+ if( !firstItem )
+ rect.OffsetBy( 0, 25 );
+ else
+ firstItem = false;
+
+ memset( name, 0, 128 );
+ sprintf( name, "f%s", p_item->psz_name );
+ textControl = new BTextControl( rect, name, p_item->psz_text,
+ "", new BMessage(),
+ B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
+ configView->AddChild( textControl );
+ break;
+
+ case CONFIG_ITEM_BOOL:
+ if( !firstItem )
+ rect.OffsetBy( 0,25 );
+ else
+ firstItem = false;
+
+ memset( name, 0, 128 );
+ sprintf( name, "b%s", p_item->psz_name );
+ checkBox = new BCheckBox( rect, name, p_item->psz_text,
+ new BMessage(), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP );
+ configView->AddChild( checkBox );
+ break;
+ }
+
+ } while( p_item->i_type != CONFIG_HINT_END && p_item++ );
- fAdjustTab = new BTab();
- fTabView->AddTab( fAdjustView, fAdjustTab );
- fAdjustTab->SetLabel( _("Picture") );
+ /* Adjust the configView size */
+ rect.bottom += 10;
+ configView->fRealBounds = BRect( 0, 0, configView->Bounds().Width(), rect.bottom );
+ configView->ResizeTo( configView->Bounds().Width(), configView->Bounds().Height() );
+
+ /* Add the item to the tree */
+ StringItemWithView * stringItem;
+ stringItem = new StringItemWithView( p_module->psz_object_name );
+ stringItem->fConfigView = configView;
+ fOutline->AddItem( stringItem );
+ }
- /* fills the tabs */
- /* general tab */
- rect = fGeneralView->Bounds();
- rect.InsetBy( 10, 10 );
- rect.bottom = rect.top + 10;
- fDvdMenusCheck = new BCheckBox( rect, "dvdmenus", _("Use DVD menus"),
- new BMessage( DVDMENUS_CHECK ) );
- fGeneralView->AddChild( fDvdMenusCheck );
+ vlc_list_release( p_list );
- rect.top = rect.bottom + 20;
- rect.bottom = rect.top + 30;
- fPpSlider = new BSlider( rect, "post-processing", _("MPEG4 post-processing level"),
- new BMessage( FFMPEG_UPDATE ),
- 0, 6, B_TRIANGLE_THUMB,
- B_FOLLOW_LEFT, B_WILL_DRAW );
- fPpSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
- fPpSlider->SetHashMarkCount( 7 );
- fPpSlider->SetLimitLabels( _("None"), _("Maximum") );
- fGeneralView->AddChild( fPpSlider );
-
-
- rect.top = fPpSlider->Frame().bottom + 5.0;
- rect.bottom = rect.top + 15.0;
- fScreenShotPathTC = new DirectoryTextControl( rect, "screenshot path",
- _("Screenshot Path:"),
- fScreenShotPathBackup.String(),
- new BMessage( SET_FOLDER ) );
-// fScreenShotPathTC->ResizeToPreferred();
-
- rect.top = fScreenShotPathTC->Frame().bottom + 5.0;
- rect.bottom = rect.top + 15.0; // TODO: this will be so tricky to get right!
- BMenu* translatorMenu = new BMenu( "translators" );
- add_translator_items( translatorMenu, B_TRANSLATOR_BITMAP, SET_TRANSLATOR );
- fScreenShotFormatMF = new BMenuField( rect, "translators field",
- _("Screenshot Format:"), translatorMenu );
- fScreenShotFormatMF->Menu()->SetRadioMode( true );
- fScreenShotFormatMF->Menu()->SetLabelFromMarked( true );
- // this will most likely not work for BMenuFields
-// fScreenShotFormatMF->ResizeToPreferred();
-
- fGeneralView->AddChild( fScreenShotPathTC );
- fGeneralView->AddChild( fScreenShotFormatMF );
-
- // make sure the controls labels are aligned nicely
- float labelWidthM = fScreenShotFormatMF->StringWidth( fScreenShotFormatMF->Label() ) + 5.0;
- float labelWidthP = fScreenShotPathTC->StringWidth( fScreenShotPathTC->Label() ) + 5.0;
- if ( labelWidthM > labelWidthP )
- {
- fScreenShotPathTC->SetDivider( labelWidthM );
- fScreenShotFormatMF->SetDivider( labelWidthM );
- }
- else
- {
- fScreenShotPathTC->SetDivider( labelWidthP );
- fScreenShotFormatMF->SetDivider( labelWidthP );
- }
-
- /* restart message */
- rect = fGeneralView->Bounds();
- rect.bottom -= 40.0;
- font_height fh;
- be_plain_font->GetHeight( &fh );
- rect.top = rect.bottom - ceilf( fh.ascent + fh.descent ) - 2.0;
- fRestartString = new BStringView( rect, NULL,
- _("DVD-menu and MPEG4 settings take effect after playback is restarted.") );
- fRestartString->SetAlignment( B_ALIGN_CENTER );
- fGeneralView->AddChild( fRestartString );
-
+ /* Set the correct values */
+ ApplyChanges( false );
- /* adjust tab */
- rect = fAdjustView->Bounds();
- rect.InsetBy( 10, 10 );
- rect.bottom = rect.top + 30;
- fBrightnessSlider = new BSlider( rect, "brightness", _("Brightness"),
- new BMessage( ADJUST_UPDATE ),
- 0, 200, B_TRIANGLE_THUMB,
- B_FOLLOW_LEFT, B_WILL_DRAW );
- rect.OffsetBy( 0, 40 );
- fContrastSlider = new BSlider( rect, "contrast", _("Contrast"),
- new BMessage( ADJUST_UPDATE ),
- 0, 200, B_TRIANGLE_THUMB,
- B_FOLLOW_LEFT, B_WILL_DRAW );
- rect.OffsetBy( 0, 40 );
- fHueSlider = new BSlider( rect, "hue", _("Hue"),
- new BMessage( ADJUST_UPDATE ),
- 0, 360, B_TRIANGLE_THUMB,
- B_FOLLOW_LEFT, B_WILL_DRAW );
- rect.OffsetBy( 0, 40 );
- fSaturationSlider = new BSlider( rect, "saturation", _("Saturation"),
- new BMessage( ADJUST_UPDATE ),
- 0, 200, B_TRIANGLE_THUMB,
- B_FOLLOW_LEFT, B_WILL_DRAW );
- fAdjustView->AddChild( fBrightnessSlider );
- fAdjustView->AddChild( fContrastSlider );
- fAdjustView->AddChild( fHueSlider );
- fAdjustView->AddChild( fSaturationSlider );
+ /* Select the first item */
+ fOutline->Select( 0 );
- fPrefsView->AddChild( fTabView );
-
- /* buttons */
- BButton *button;
+ /* Add the buttons */
+ BButton * button;
rect = Bounds();
rect.InsetBy( 10, 10 );
- rect.top = rect.bottom - 25;
rect.left = rect.right - 80;
- button = new BButton( rect, NULL, _("OK"), new BMessage( PREFS_OK ) );
+ rect.top = rect.bottom - 25;
+ button = new BButton( rect, "", _("OK"), new BMessage( PREFS_OK ),
+ B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
fPrefsView->AddChild( button );
-
- SetDefaultButton( button );
-
rect.OffsetBy( -90, 0 );
- button = new BButton( rect, NULL, _("Cancel"), new BMessage( PREFS_CANCEL ) );
+ button = new BButton( rect, "", _("Revert"), new BMessage( PREFS_REVERT ),
+ B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
fPrefsView->AddChild( button );
-
rect.OffsetBy( -90, 0 );
- button = new BButton( rect, NULL, _("Revert"), new BMessage( PREFS_REVERT ) );
- fPrefsView->AddChild( button );
-
- rect.left = Bounds().left + 10.0;
- rect.right = rect.left + 80.0;
- button = new BButton( rect, NULL, _("Defaults"), new BMessage( PREFS_DEFAULTS ) );
+ button = new BButton( rect, "", _("Apply"), new BMessage( PREFS_APPLY ),
+ B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM );
fPrefsView->AddChild( button );
-
-
- // sync GUI to VLC
- _SetToSettings();
-
- // start window thread in hidden state
+
Hide();
Show();
}
/*****************************************************************************
* PreferencesWindow::QuitRequested
*****************************************************************************/
-bool
-PreferencesWindow::QuitRequested()
+bool PreferencesWindow::QuitRequested()
{
- // work arround problem when window is closed or Ok pressed though
- // the text control has focus (it will not have commited changes)
- config_PutPsz( p_intf, "beos-screenshot-path", fScreenShotPathTC->Text() );
- if ( !IsHidden() )
- Hide();
+ if( !IsHidden() )
+ Hide();
return false;
}
/*****************************************************************************
* PreferencesWindow::MessageReceived
*****************************************************************************/
-void PreferencesWindow::MessageReceived( BMessage * p_message )
+void PreferencesWindow::MessageReceived( BMessage * message )
{
- switch ( p_message->what )
+ switch( message->what )
{
- case SET_TRANSLATOR:
- case SET_FOLDER:
- _ApplyScreenShotSettings();
- break;
- case DVDMENUS_CHECK:
- _ApplyDVDSettings();
- break;
- case ADJUST_UPDATE:
- _ApplyPictureSettings();
- break;
- case FFMPEG_UPDATE:
- _ApplyFFmpegSettings();
+ case PREFS_ITEM_SELECTED:
+ Update();
break;
- case PREFS_REVERT:
- _RevertChanges();
- break;
- case PREFS_DEFAULTS:
- _SetDefaults();
- _ApplyChanges();
- break;
- case PREFS_CANCEL:
- _RevertChanges();
- // fall through
+
case PREFS_OK:
+ ApplyChanges( true );
PostMessage( B_QUIT_REQUESTED );
break;
- default:
- BWindow::MessageReceived( p_message );
+
+ case PREFS_REVERT:
+ ApplyChanges( false );
+ break;
+
+ case PREFS_APPLY:
+ ApplyChanges( true );
break;
- }
-}
-
-/*****************************************************************************
- * PreferencesWindow::Show
- *****************************************************************************/
-void
-PreferencesWindow::Show()
-{
- // collect settings for backup
- fDVDMenusBackup = fDvdMenusCheck->Value() == B_CONTROL_ON;
- fPostProcessingBackup = fPpSlider->Value();
- fBrightnessBackup = fBrightnessSlider->Value();
- fContrastBackup = fContrastSlider->Value();
- fHueBackup = fHueSlider->Value();
- fSaturationBackup = fSaturationSlider->Value();
- fScreenShotPathBackup.SetTo( fScreenShotPathTC->Text() );
- if ( BMenuItem* item = fScreenShotFormatMF->Menu()->FindMarked() )
- {
- BMessage* message = item->Message();
- if ( message && message->FindInt32( kTypeField,
- (int32*)&fScreenShotFormatBackup ) != B_OK )
- fScreenShotFormatBackup = kDefaultScreenShotFormat;
- }
- else
- fScreenShotFormatBackup = kDefaultScreenShotFormat;
-
- BWindow::Show();
-}
-
-/*****************************************************************************
- * PreferencesWindow::ReallyQuit
- *****************************************************************************/
-void PreferencesWindow::ReallyQuit()
-{
- Lock();
- Hide();
- Quit();
-}
-
-void
-PreferencesWindow::_SetGUI( bool dvdMenus, int32 postProcessing,
- float brightness, float contrast,
- int32 hue, float saturation,
- const char* screenShotPath,
- uint32 screenShotTranslator)
-{
- fDvdMenusCheck->SetValue( dvdMenus );
- fPpSlider->SetValue( postProcessing );
- fBrightnessSlider->SetValue( brightness );
- fContrastSlider->SetValue( contrast );
- fHueSlider->SetValue( hue );
- fSaturationSlider->SetValue( saturation );
- // mark appropriate translator item
- bool found = false;
- for ( int32 i = 0; BMenuItem* item = fScreenShotFormatMF->Menu()->ItemAt( i ); i++ )
- {
- if ( BMessage* message = item->Message() )
- {
- uint32 format;
- if ( message->FindInt32( kTypeField, (int32*)&format ) == B_OK
- && format == screenShotTranslator )
- {
- item->SetMarked( true );
- found = true;
- break;
- }
- }
- }
- if ( !found )
- {
- if ( BMenuItem* item = fScreenShotFormatMF->Menu()->ItemAt( 0 ) )
- item->SetMarked( true );
- }
- fScreenShotPathTC->SetText( screenShotPath );
-}
-
-/*****************************************************************************
- * PreferencesWindow::_SetDefaults
- *****************************************************************************/
-void PreferencesWindow::_SetDefaults()
-{
- _SetGUI( false, 0, 100.0, 100.0, 0, 100.0,
- kDefaultScreenShotPath, kDefaultScreenShotFormat );
+ default:
+ BWindow::MessageReceived( message );
+ }
}
/*****************************************************************************
- * PreferencesWindow::_SetToSettings
+ * PreferencesWindow::FrameResized
*****************************************************************************/
-void PreferencesWindow::_SetToSettings()
+void PreferencesWindow::FrameResized( float width, float height )
{
- char* path = get_config_string( p_intf, "beos-screenshot-path", kDefaultScreenShotPath );
-
- p_intf->p_sys->b_dvdmenus = get_config_int( p_intf, "beos-use-dvd-menus", false );
-
- _SetGUI( p_intf->p_sys->b_dvdmenus,
- get_config_int( p_intf, "ffmpeg-pp-q", 0 ),
- 100 * get_config_float( p_intf, "brightness", 1.0 ),
- 100 * get_config_float( p_intf, "contrast", 1.0 ),
- get_config_int( p_intf, "hue", 0 ),
- 100 * get_config_float( p_intf, "saturation", 1.0 ),
- path,
- get_config_int( p_intf, "beos-screenshot-format",
- kDefaultScreenShotFormat ) );
- free( path );
+ BWindow::FrameResized( width, height );
+ UpdateScrollBar();
}
/*****************************************************************************
- * PreferencesWindow::_RevertChanges
+ * PreferencesWindow::Update
*****************************************************************************/
-void
-PreferencesWindow::_RevertChanges()
+void PreferencesWindow::Update()
{
- _SetGUI( fDVDMenusBackup,
- fPostProcessingBackup,
- fBrightnessBackup,
- fContrastBackup,
- fHueBackup,
- fSaturationBackup,
- fScreenShotPathBackup.String(),
- fScreenShotFormatBackup );
+ /* Get the selected item */
+ if( fOutline->CurrentSelection() < 0 )
+ return;
+ StringItemWithView * selectedItem =
+ (StringItemWithView*) fOutline->ItemAt( fOutline->CurrentSelection() );
- _ApplyChanges();
+ if( fConfigScroll )
+ {
+ /* If we don't do this, the ConfigView will remember a wrong position */
+ BScrollBar * scrollBar = fConfigScroll->ScrollBar( B_VERTICAL );
+ scrollBar->SetValue( 0 );
+
+ /* Detach the current ConfigView, remove the BScrollView */
+ BView * view;
+ while( ( view = fConfigScroll->ChildAt( 0 ) ) )
+ fConfigScroll->RemoveChild( view );
+ fDummyView->RemoveChild( fConfigScroll );
+ delete fConfigScroll;
+ }
+
+ /* Create a BScrollView with the new ConfigView in it */
+ fConfigScroll = new BScrollView( "", selectedItem->fConfigView, B_FOLLOW_ALL_SIDES,
+ 0, false, true, B_NO_BORDER );
+ fDummyView->AddChild( fConfigScroll );
+ UpdateScrollBar();
}
-/*****************************************************************************
- * PreferencesWindow::_ApplyChanges
- *****************************************************************************/
-void PreferencesWindow::_ApplyChanges()
-{
- _ApplyScreenShotSettings();
- _ApplyPictureSettings();
- _ApplyFFmpegSettings();
- _ApplyDVDSettings();
-}
/*****************************************************************************
- * PreferencesWindow::_ApplyScreenShotSettings
+ * PreferencesWindow::UpdateScrollBar
*****************************************************************************/
-void
-PreferencesWindow::_ApplyScreenShotSettings()
+void PreferencesWindow::UpdateScrollBar()
{
- // screen shot settings
- uint32 translator = kDefaultScreenShotFormat;
- if ( BMenuItem* item = fScreenShotFormatMF->Menu()->FindMarked() )
- {
- BMessage* message = item->Message();
- if ( message && message->FindInt32( kTypeField, (int32*)&translator ) != B_OK )
- translator = kDefaultScreenShotFormat;
- }
- config_PutInt( p_intf, "beos-screenshot-format", translator );
- config_PutPsz( p_intf, "beos-screenshot-path", fScreenShotPathTC->Text() );
+ /* We have to fix the scrollbar manually because it doesn't handle
+ correctly simple BViews */
+
+ /* Get the current config view */
+ if( fOutline->CurrentSelection() < 0 )
+ return;
+ StringItemWithView * selectedItem =
+ (StringItemWithView*) fOutline->ItemAt( fOutline->CurrentSelection() );
+
+ /* Fix the scrollbar */
+ BRect visible = fConfigScroll->Bounds() & selectedItem->fConfigView->fRealBounds;
+ BRect total = fConfigScroll->Bounds() | selectedItem->fConfigView->fRealBounds;
+ BScrollBar * scrollBar = fConfigScroll->ScrollBar( B_VERTICAL );
+ long max = (long)( selectedItem->fConfigView->fRealBounds.Height() -
+ fConfigScroll->Bounds().Height() );
+ if( max < 0 ) max = 0;
+ scrollBar->SetRange( 0, max );
+ scrollBar->SetProportion( visible.Height() / total.Height() );
}
/*****************************************************************************
- * PreferencesWindow::_ApplyPictureSettings
+ * PreferencesWindow::ApplyChanges
+ * Apply changes if doIt is true, revert them otherwise
*****************************************************************************/
-void
-PreferencesWindow::_ApplyPictureSettings()
+void PreferencesWindow::ApplyChanges( bool doIt )
{
- VlcWrapper* p_wrapper = p_intf->p_sys->p_wrapper;
-
- // picture adjustment settings
- config_PutFloat( p_intf, "brightness",
- (float)fBrightnessSlider->Value() / 100 );
- config_PutFloat( p_intf, "contrast",
- (float)fContrastSlider->Value() / 100 );
- config_PutInt( p_intf, "hue", fHueSlider->Value() );
- config_PutFloat( p_intf, "saturation",
- (float)fSaturationSlider->Value() / 100 );
-
- // take care of changing "filters on the fly"
- if( config_GetFloat( p_intf, "brightness" ) != 1 ||
- config_GetFloat( p_intf, "contrast" ) != 1 ||
- config_GetInt( p_intf, "hue" ) != 0 ||
- config_GetFloat( p_intf, "saturation" ) != 1 )
- {
- char* string = config_GetPsz( p_intf, "filter" );
- if( !string || strcmp( string, "adjust" ) )
- {
- config_PutPsz( p_intf, "filter", "adjust" );
- p_wrapper->FilterChange();
- }
- if ( string )
- free( string );
- }
- else
+ StringItemWithView * item;
+ ConfigView * view;
+ BView * child;
+ const char * name;
+ BString string;
+ for( int i = 0; i < fOutline->CountItems(); i++ )
{
- char* string = config_GetPsz( p_intf, "filter" );
- if ( string )
+ item = (StringItemWithView*) fOutline->ItemAt( i );
+ view = item->fConfigView;
+
+ for( int j = 0; j < view->CountChildren(); j++ )
{
- config_PutPsz( p_intf, "filter", NULL );
- p_wrapper->FilterChange();
- free( string );
+ child = view->ChildAt( j );
+ name = child->Name();
+ switch( *name )
+ {
+ case 's': /* BTextControl, string variable */
+ if( doIt )
+ config_PutPsz( p_intf, name + 1, ((BTextControl*)child)->Text() );
+ else
+ ((BTextControl*)child)->SetText( config_GetPsz( p_intf, name + 1 ) );
+ break;
+ case 'i': /* BTextControl, int variable */
+ if( doIt )
+ config_PutInt( p_intf, name + 1, atoi( ((BTextControl*)child)->Text() ) );
+ else
+ {
+ string = "";
+ string << config_GetInt( p_intf, name + 1 );
+ ((BTextControl*)child)->SetText( string.String() );
+ }
+ break;
+ case 'f': /* BTextControl, float variable */
+ if( doIt )
+ config_PutFloat( p_intf, name + 1,
+ strtod( ((BTextControl*)child)->Text(), NULL ) );
+ else
+ {
+ string = "";
+ string << config_GetFloat( p_intf, name + 1 );
+ ((BTextControl*)child)->SetText( string.String() );
+ }
+ break;
+ case 'b': /* BCheckBox, bool variable */
+ if( doIt )
+ config_PutInt( p_intf, name + 1, ((BCheckBox*)child)->Value() );
+ else
+ ((BCheckBox*)child)->SetValue( config_GetInt( p_intf, name + 1 ) );
+ break;
+ }
}
}
}
/*****************************************************************************
- * PreferencesWindow::_ApplyFFmpegSettings
- *****************************************************************************/
-void
-PreferencesWindow::_ApplyFFmpegSettings()
-{
- // ffmpeg post processing
- config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
-}
-
-/*****************************************************************************
- * PreferencesWindow::_ApplyDVDSettings
+ * PreferencesWindow::ReallyQuit
*****************************************************************************/
-void
-PreferencesWindow::_ApplyDVDSettings()
+void PreferencesWindow::ReallyQuit()
{
- // dvd menus
- bool dvdMenus = fDvdMenusCheck->Value() == B_CONTROL_ON;
- p_intf->p_sys->b_dvdmenus = dvdMenus;
- config_PutInt( p_intf, "beos-use-dvd-menus", dvdMenus );
+ Lock();
+ Hide();
+ Quit();
}
-