]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
* InterfaceWindow.cpp : fixed DVD drag & drop
[vlc] / 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.7 2003/01/16 15:26:23 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( BRect frame, const char* name,
41                                                                 intf_thread_t *p_interface )
42         :       BWindow( frame, name, B_FLOATING_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
43                                  B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE )
44 {
45         p_intf = p_interface;
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     fOldDvdCheck = new BCheckBox( rect, "olddvd", "Do not use DVD menus",
79                                   new BMessage( OLDDVD_CHECK ) );
80     fGeneralView->AddChild( fOldDvdCheck );
81     fprintf( stderr, "%s\n", config_GetPsz( p_intf, "access" ) );
82     if( config_GetPsz( p_intf, "access" ) &&
83         !strncmp( config_GetPsz( p_intf, "access" ), "dvdold,any", 10 ) )
84         fOldDvdCheck->SetValue( 1 );
85     
86     rect.top = rect.bottom + 20;
87     rect.bottom = rect.top + 30;
88     fPpSlider = new BSlider( rect, "post-processing", "MPEG4 post-processing level",
89                                new BMessage( SLIDER_UPDATE ),
90                                0, 6, B_TRIANGLE_THUMB,
91                                B_FOLLOW_LEFT, B_WILL_DRAW ); 
92     fPpSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
93     fPpSlider->SetHashMarkCount( 7 );
94     fPpSlider->SetLimitLabels( "None", "Maximum" );
95     fPpSlider->SetValue( config_GetInt( p_intf, "ffmpeg-pp-q" ) );
96     fGeneralView->AddChild( fPpSlider );
97     
98     
99     /* adjust tab */
100     rect = fAdjustView->Bounds();
101     rect.InsetBy( 10, 10 );
102     rect.bottom = rect.top + 30;
103     fBrightnessSlider = new BSlider( rect, "brightness", "Brightness",
104                                        new BMessage( SLIDER_UPDATE ),
105                                        0, 200, B_TRIANGLE_THUMB,
106                                        B_FOLLOW_LEFT, B_WILL_DRAW );
107     fBrightnessSlider->SetValue( 100 * config_GetFloat( p_intf, "brightness" ) );
108     rect.OffsetBy( 0, 40 );
109     fContrastSlider = new BSlider( rect, "contrast", "Contrast",
110                                      new BMessage( SLIDER_UPDATE ),
111                                      0, 200, B_TRIANGLE_THUMB,
112                                      B_FOLLOW_LEFT, B_WILL_DRAW );
113     fContrastSlider->SetValue( 100 * config_GetFloat( p_intf, "contrast" ) );
114     rect.OffsetBy( 0, 40 );
115     fHueSlider = new BSlider( rect, "hue", "Hue",
116                                 new BMessage( SLIDER_UPDATE ),
117                                 0, 360, B_TRIANGLE_THUMB,
118                                 B_FOLLOW_LEFT, B_WILL_DRAW );
119     fHueSlider->SetValue( config_GetInt( p_intf, "hue" ) );
120     rect.OffsetBy( 0, 40 );
121     fSaturationSlider = new BSlider( rect, "saturation", "Saturation",
122                                        new BMessage( SLIDER_UPDATE ),
123                                        0, 200, B_TRIANGLE_THUMB,
124                                        B_FOLLOW_LEFT, B_WILL_DRAW );
125     fSaturationSlider->SetValue( 100 * config_GetFloat( p_intf, "saturation" ) );
126     fAdjustView->AddChild( fBrightnessSlider );
127     fAdjustView->AddChild( fContrastSlider );
128     fAdjustView->AddChild( fHueSlider );
129     fAdjustView->AddChild( fSaturationSlider );
130     
131     fPrefsView->AddChild( fTabView );
132
133     /* restart message */
134     rect = fPrefsView->Bounds();
135     rect.bottom -= 43;
136     rect.top = rect.bottom - 10;
137     fRestartString = new BStringView( rect, NULL,
138         "Warning: changing settings after starting playback may have no effect." );
139     /*rgb_color redColor = {255, 0, 0, 255};
140     fRestartString->SetHighColor(redColor);*/
141     fRestartString->SetAlignment( B_ALIGN_CENTER );
142     fPrefsView->AddChild( fRestartString );
143
144     /* buttons */
145     BButton *button;
146     rect = Bounds();
147     rect.InsetBy( 10, 10 );
148     rect.top = rect.bottom - 25;
149     rect.left = rect.right - 80;
150     button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
151     fPrefsView->AddChild( button );
152
153     rect.OffsetBy( -90, 0 );
154     button = new BButton( rect, NULL, "Save", new BMessage( PREFS_SAVE ) );
155     fPrefsView->AddChild( button );
156     
157     rect.OffsetBy( -90, 0 );
158     button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
159     fPrefsView->AddChild( button );
160     
161         // start window thread in hidden state
162         Hide();
163         Show();
164 }
165
166 /*****************************************************************************
167  * PreferencesWindow::~PreferencesWindow
168  *****************************************************************************/
169 PreferencesWindow::~PreferencesWindow()
170 {
171 }
172
173 /*****************************************************************************
174  * PreferencesWindow::MessageReceived
175  *****************************************************************************/
176 void PreferencesWindow::MessageReceived( BMessage * p_message )
177 {
178         switch ( p_message->what )
179         {
180             case OLDDVD_CHECK:
181             case SLIDER_UPDATE:
182             {
183                 ApplyChanges();
184                 break;
185             }
186             case PREFS_DEFAULTS:
187             {
188                 SetDefaults();
189             ApplyChanges();
190                 break;
191             }
192             case PREFS_SAVE:
193             {
194                 config_SaveConfigFile( p_intf, "main" );
195                 config_SaveConfigFile( p_intf, "adjust" );
196                 config_SaveConfigFile( p_intf, "ffmpeg" );
197                 break;
198             }
199             case PREFS_OK:
200             {
201             Hide();
202             break;
203             }
204                 default:
205                         BWindow::MessageReceived( p_message );
206                         break;
207         }
208 }
209
210 /*****************************************************************************
211  * PreferencesWindow::ReallyQuit
212  *****************************************************************************/
213 void PreferencesWindow::ReallyQuit()
214 {
215     Hide();
216     Quit();
217 }
218
219 /*****************************************************************************
220  * PreferencesWindow::SetDefaults
221  *****************************************************************************/
222 void PreferencesWindow::SetDefaults()
223 {
224     fOldDvdCheck->SetValue( 0 );
225     fPpSlider->SetValue( 0 );
226     fBrightnessSlider->SetValue( 100 );
227     fContrastSlider->SetValue( 100 );
228     fHueSlider->SetValue( 0 );
229     fSaturationSlider->SetValue( 100 );
230 }
231
232 /*****************************************************************************
233  * PreferencesWindow::ApplyChanges
234  *****************************************************************************/
235 void PreferencesWindow::ApplyChanges()
236 {
237     if( fOldDvdCheck->Value() )
238         config_PutPsz( p_intf, "access", "dvdold,any" );
239     else
240         config_PutPsz( p_intf, "access", NULL );
241     
242     config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
243     config_PutFloat( p_intf, "brightness",
244                      (float)fBrightnessSlider->Value() / 100 );
245     config_PutFloat( p_intf, "contrast",
246                      (float)fContrastSlider->Value() / 100 );
247     config_PutInt( p_intf, "hue", fHueSlider->Value() );
248     config_PutFloat( p_intf, "saturation",
249                      (float)fSaturationSlider->Value() / 100 );
250
251     if( config_GetFloat( p_intf, "brightness" ) != 1 ||
252         config_GetFloat( p_intf, "contrast" ) != 1 ||
253         config_GetInt( p_intf, "hue" ) != 0 ||
254         config_GetFloat( p_intf, "saturation" ) != 1 )
255     {
256         config_PutPsz( p_intf, "filter", "adjust" );
257     }
258     else
259     {
260         config_PutPsz( p_intf, "filter", NULL );
261     }
262 }