2e1a3a513457b8a4fe30dce3715f20d19e2409ee
[vlc.git] / modules / gui / beos / PreferencesWindow.cpp
1 /*****************************************************************************
2  * PreferencesWindow.cpp: beos interface
3  *****************************************************************************
4  * Copyright (C) 1999, 2000, 2001 VideoLAN
5  * $Id: PreferencesWindow.cpp,v 1.12 2003/01/29 00:02:09 titer Exp $
6  *
7  * Authors: Eric Petit <titer@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /* BeOS headers */
25 #include <InterfaceKit.h>
26
27 /* VLC headers */
28 #include <vlc/vlc.h>
29 #include <vlc/intf.h>
30
31 /* BeOS module headers */
32 #include "VlcWrapper.h"
33 #include "MsgVals.h"
34 #include "PreferencesWindow.h"
35
36
37 /*****************************************************************************
38  * Preferences::PreferencesWindow
39  *****************************************************************************/
40 PreferencesWindow::PreferencesWindow( intf_thread_t * p_intf,
41                                       BRect frame, const char * name )
42     : BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
43                B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE )
44 {
45     this->p_intf = p_intf;
46     BRect rect;
47
48     /* "background" view */
49     fPrefsView = new BView( Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
50     fPrefsView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
51     AddChild( fPrefsView );
52
53     /* add the tabs */
54     rect = Bounds();
55     rect.top += 10;
56     rect.bottom -= 65;
57     fTabView = new BTabView( rect, "preferences view" );
58     fTabView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
59     
60     fGeneralView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
61     fGeneralView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
62     fAdjustView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
63     fAdjustView->SetViewColor( ui_color( B_PANEL_BACKGROUND_COLOR ) );
64     
65     fGeneralTab = new BTab();
66     fTabView->AddTab( fGeneralView, fGeneralTab );
67     fGeneralTab->SetLabel( "General" );
68     
69     fAdjustTab = new BTab();
70     fTabView->AddTab( fAdjustView, fAdjustTab );
71     fAdjustTab->SetLabel( "Adjust" );
72     
73     /* fills the tabs */
74     /* ffmpeg tab */
75     rect = fGeneralView->Bounds();
76     rect.InsetBy( 10, 10 );
77     rect.bottom = rect.top + 10;
78     fDvdMenusCheck = new BCheckBox( rect, "dvdmenus", "Use DVD menus",
79                                   new BMessage( DVDMENUS_CHECK ) );
80     fGeneralView->AddChild( fDvdMenusCheck );
81     
82     rect.top = rect.bottom + 20;
83     rect.bottom = rect.top + 30;
84     fPpSlider = new BSlider( rect, "post-processing", "MPEG4 post-processing level",
85                                new BMessage( SLIDER_UPDATE ),
86                                0, 6, B_TRIANGLE_THUMB,
87                                B_FOLLOW_LEFT, B_WILL_DRAW ); 
88     fPpSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
89     fPpSlider->SetHashMarkCount( 7 );
90     fPpSlider->SetLimitLabels( "None", "Maximum" );
91     fPpSlider->SetValue( config_GetInt( p_intf, "ffmpeg-pp-q" ) );
92     fGeneralView->AddChild( fPpSlider );
93     
94     
95     /* adjust tab */
96     rect = fAdjustView->Bounds();
97     rect.InsetBy( 10, 10 );
98     rect.bottom = rect.top + 30;
99     fBrightnessSlider = new BSlider( rect, "brightness", "Brightness",
100                                        new BMessage( SLIDER_UPDATE ),
101                                        0, 200, B_TRIANGLE_THUMB,
102                                        B_FOLLOW_LEFT, B_WILL_DRAW );
103     fBrightnessSlider->SetValue( 100 * config_GetFloat( p_intf, "brightness" ) );
104     rect.OffsetBy( 0, 40 );
105     fContrastSlider = new BSlider( rect, "contrast", "Contrast",
106                                      new BMessage( SLIDER_UPDATE ),
107                                      0, 200, B_TRIANGLE_THUMB,
108                                      B_FOLLOW_LEFT, B_WILL_DRAW );
109     fContrastSlider->SetValue( 100 * config_GetFloat( p_intf, "contrast" ) );
110     rect.OffsetBy( 0, 40 );
111     fHueSlider = new BSlider( rect, "hue", "Hue",
112                                 new BMessage( SLIDER_UPDATE ),
113                                 0, 360, B_TRIANGLE_THUMB,
114                                 B_FOLLOW_LEFT, B_WILL_DRAW );
115     fHueSlider->SetValue( config_GetInt( p_intf, "hue" ) );
116     rect.OffsetBy( 0, 40 );
117     fSaturationSlider = new BSlider( rect, "saturation", "Saturation",
118                                        new BMessage( SLIDER_UPDATE ),
119                                        0, 200, B_TRIANGLE_THUMB,
120                                        B_FOLLOW_LEFT, B_WILL_DRAW );
121     fSaturationSlider->SetValue( 100 * config_GetFloat( p_intf, "saturation" ) );
122     fAdjustView->AddChild( fBrightnessSlider );
123     fAdjustView->AddChild( fContrastSlider );
124     fAdjustView->AddChild( fHueSlider );
125     fAdjustView->AddChild( fSaturationSlider );
126     
127     fPrefsView->AddChild( fTabView );
128
129     /* restart message */
130     rect = fPrefsView->Bounds();
131     rect.bottom -= 43;
132     rect.top = rect.bottom - 10;
133     fRestartString = new BStringView( rect, NULL,
134         "Warning: changing settings after starting playback may have no effect." );
135     fRestartString->SetAlignment( B_ALIGN_CENTER );
136     fPrefsView->AddChild( fRestartString );
137
138     /* buttons */
139     BButton *button;
140     rect = Bounds();
141     rect.InsetBy( 10, 10 );
142     rect.top = rect.bottom - 25;
143     rect.left = rect.right - 80;
144     button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
145     fPrefsView->AddChild( button );
146
147     rect.OffsetBy( -90, 0 );
148     button = new BButton( rect, NULL, "Save", new BMessage( PREFS_SAVE ) );
149     fPrefsView->AddChild( button );
150     
151     rect.OffsetBy( -90, 0 );
152     button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
153     fPrefsView->AddChild( button );
154     
155     // start window thread in hidden state
156     Hide();
157     Show();
158 }
159
160 /*****************************************************************************
161  * PreferencesWindow::~PreferencesWindow
162  *****************************************************************************/
163 PreferencesWindow::~PreferencesWindow()
164 {
165 }
166
167 /*****************************************************************************
168  * PreferencesWindow::MessageReceived
169  *****************************************************************************/
170 void PreferencesWindow::MessageReceived( BMessage * p_message )
171 {
172     switch ( p_message->what )
173     {
174         case DVDMENUS_CHECK:
175         case SLIDER_UPDATE:
176         {
177             ApplyChanges();
178             break;
179         }
180         case PREFS_DEFAULTS:
181         {
182             SetDefaults();
183             ApplyChanges();
184             break;
185         }
186         case PREFS_SAVE:
187         {
188             config_SaveConfigFile( p_intf, "main" );
189             config_SaveConfigFile( p_intf, "adjust" );
190             config_SaveConfigFile( p_intf, "ffmpeg" );
191             break;
192         }
193         case PREFS_OK:
194         {
195             Hide();
196             break;
197         }
198         default:
199             BWindow::MessageReceived( p_message );
200             break;
201     }
202 }
203
204 /*****************************************************************************
205  * PreferencesWindow::ReallyQuit
206  *****************************************************************************/
207 void PreferencesWindow::ReallyQuit()
208 {
209     Lock();
210     Hide();
211     Quit();
212 }
213
214 /*****************************************************************************
215  * PreferencesWindow::SetDefaults
216  *****************************************************************************/
217 void PreferencesWindow::SetDefaults()
218 {
219     fDvdMenusCheck->SetValue( 0 );
220     fPpSlider->SetValue( 0 );
221     fBrightnessSlider->SetValue( 100 );
222     fContrastSlider->SetValue( 100 );
223     fHueSlider->SetValue( 0 );
224     fSaturationSlider->SetValue( 100 );
225 }
226
227 /*****************************************************************************
228  * PreferencesWindow::ApplyChanges
229  *****************************************************************************/
230 void PreferencesWindow::ApplyChanges()
231 {
232     VlcWrapper * p_wrapper = p_intf->p_sys->p_wrapper;
233
234     if( fDvdMenusCheck->Value() )
235         p_intf->p_sys->b_dvdmenus = true;
236     else
237         p_intf->p_sys->b_dvdmenus = false;
238     
239     config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
240     config_PutFloat( p_intf, "brightness",
241                      (float)fBrightnessSlider->Value() / 100 );
242     config_PutFloat( p_intf, "contrast",
243                      (float)fContrastSlider->Value() / 100 );
244     config_PutInt( p_intf, "hue", fHueSlider->Value() );
245     config_PutFloat( p_intf, "saturation",
246                      (float)fSaturationSlider->Value() / 100 );
247
248     if( config_GetFloat( p_intf, "brightness" ) != 1 ||
249         config_GetFloat( p_intf, "contrast" ) != 1 ||
250         config_GetInt( p_intf, "hue" ) != 0 ||
251         config_GetFloat( p_intf, "saturation" ) != 1 )
252     {
253         if( !config_GetPsz( p_intf, "filter" ) ||
254             strcmp( config_GetPsz( p_intf, "filter" ), "adjust" ) )
255         {
256             config_PutPsz( p_intf, "filter", "adjust" );
257             p_wrapper->FilterChange();
258         }
259     }
260     else
261     {
262         if( config_GetPsz( p_intf, "filter" ) )
263         {
264             config_PutPsz( p_intf, "filter", NULL );
265             p_wrapper->FilterChange();
266         }
267     }
268 }