]> git.sesse.net Git - vlc/blob - modules/gui/beos/PreferencesWindow.cpp
Now you can save preferences.
[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.6 2003/01/14 16:00:49 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     fFfmpegView = new BView( fTabView->Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW );
61     fFfmpegView->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     fFfmpegTab = new BTab();
66     fTabView->AddTab( fFfmpegView, fFfmpegTab );
67     fFfmpegTab->SetLabel( "Ffmpeg" );
68     
69     fAdjustTab = new BTab();
70     fTabView->AddTab( fAdjustView, fAdjustTab );
71     fAdjustTab->SetLabel( "Adjust" );
72     
73     /* fills the tabs */
74     /* ffmpeg tab */
75     rect = fFfmpegView->Bounds();
76     rect.InsetBy( 10, 10 );
77     rect.bottom = rect.top + 30;
78     fPpSlider = new BSlider( rect, "post-processing", "MPEG4 post-processing level",
79                                new BMessage( SLIDER_UPDATE ),
80                                0, 6, B_TRIANGLE_THUMB,
81                                B_FOLLOW_LEFT, B_WILL_DRAW ); 
82     fPpSlider->SetHashMarks(B_HASH_MARKS_BOTTOM);
83     fPpSlider->SetHashMarkCount( 7 );
84     fPpSlider->SetLimitLabels( "None", "Maximum" );
85     fPpSlider->SetValue( config_GetInt( p_intf, "ffmpeg-pp-q" ) );
86     fFfmpegView->AddChild( fPpSlider );
87     
88     
89     /* adjust tab */
90     rect = fAdjustView->Bounds();
91     rect.InsetBy( 10, 10 );
92     rect.bottom = rect.top + 30;
93     fBrightnessSlider = new BSlider( rect, "brightness", "Brightness",
94                                        new BMessage( SLIDER_UPDATE ),
95                                        0, 200, B_TRIANGLE_THUMB,
96                                        B_FOLLOW_LEFT, B_WILL_DRAW );
97     fBrightnessSlider->SetValue( 100 * config_GetFloat( p_intf, "brightness" ) );
98     rect.OffsetBy( 0, 40 );
99     fContrastSlider = new BSlider( rect, "contrast", "Contrast",
100                                      new BMessage( SLIDER_UPDATE ),
101                                      0, 200, B_TRIANGLE_THUMB,
102                                      B_FOLLOW_LEFT, B_WILL_DRAW );
103     fContrastSlider->SetValue( 100 * config_GetFloat( p_intf, "contrast" ) );
104     rect.OffsetBy( 0, 40 );
105     fHueSlider = new BSlider( rect, "hue", "Hue",
106                                 new BMessage( SLIDER_UPDATE ),
107                                 0, 360, B_TRIANGLE_THUMB,
108                                 B_FOLLOW_LEFT, B_WILL_DRAW );
109     fHueSlider->SetValue( config_GetInt( p_intf, "hue" ) );
110     rect.OffsetBy( 0, 40 );
111     fSaturationSlider = new BSlider( rect, "saturation", "Saturation",
112                                        new BMessage( SLIDER_UPDATE ),
113                                        0, 200, B_TRIANGLE_THUMB,
114                                        B_FOLLOW_LEFT, B_WILL_DRAW );
115     fSaturationSlider->SetValue( 100 * config_GetFloat( p_intf, "saturation" ) );
116     fAdjustView->AddChild( fBrightnessSlider );
117     fAdjustView->AddChild( fContrastSlider );
118     fAdjustView->AddChild( fHueSlider );
119     fAdjustView->AddChild( fSaturationSlider );
120     
121     fPrefsView->AddChild( fTabView );
122
123     /* restart message */
124     rect = fPrefsView->Bounds();
125     rect.bottom -= 43;
126     rect.top = rect.bottom - 10;
127     fRestartString = new BStringView( rect, NULL,
128         "Warning: changing settings after starting playback may have no effect." );
129     /*rgb_color redColor = {255, 0, 0, 255};
130     fRestartString->SetHighColor(redColor);*/
131     fRestartString->SetAlignment( B_ALIGN_CENTER );
132     fPrefsView->AddChild( fRestartString );
133
134     /* buttons */
135     BButton *button;
136     rect = Bounds();
137     rect.InsetBy( 10, 10 );
138     rect.top = rect.bottom - 25;
139     rect.left = rect.right - 80;
140     button = new BButton( rect, NULL, "OK", new BMessage( PREFS_OK ) );
141     fPrefsView->AddChild( button );
142
143     rect.OffsetBy( -90, 0 );
144     button = new BButton( rect, NULL, "Save", new BMessage( PREFS_SAVE ) );
145     fPrefsView->AddChild( button );
146     
147     rect.OffsetBy( -90, 0 );
148     button = new BButton( rect, NULL, "Defaults", new BMessage( PREFS_DEFAULTS ) );
149     fPrefsView->AddChild( button );
150     
151         // start window thread in hidden state
152         Hide();
153         Show();
154 }
155
156 /*****************************************************************************
157  * PreferencesWindow::~PreferencesWindow
158  *****************************************************************************/
159 PreferencesWindow::~PreferencesWindow()
160 {
161 }
162
163 /*****************************************************************************
164  * PreferencesWindow::MessageReceived
165  *****************************************************************************/
166 void PreferencesWindow::MessageReceived( BMessage * p_message )
167 {
168         switch ( p_message->what )
169         {
170             case SLIDER_UPDATE:
171             {
172                 ApplyChanges();
173                 break;
174             }
175             case PREFS_DEFAULTS:
176             {
177                 SetDefaults();
178             ApplyChanges();
179                 break;
180             }
181             case PREFS_SAVE:
182             {
183                 config_SaveConfigFile( p_intf, "main" );
184                 config_SaveConfigFile( p_intf, "adjust" );
185                 config_SaveConfigFile( p_intf, "ffmpeg" );
186                 break;
187             }
188             case PREFS_OK:
189             {
190             Hide();
191             break;
192             }
193                 default:
194                         BWindow::MessageReceived( p_message );
195                         break;
196         }
197 }
198
199 /*****************************************************************************
200  * PreferencesWindow::ReallyQuit
201  *****************************************************************************/
202 void PreferencesWindow::ReallyQuit()
203 {
204     Hide();
205     Quit();
206 }
207
208 /*****************************************************************************
209  * PreferencesWindow::SetDefaults
210  *****************************************************************************/
211 void PreferencesWindow::SetDefaults()
212 {
213     fPpSlider->SetValue( 0 );
214     fBrightnessSlider->SetValue( 100 );
215     fContrastSlider->SetValue( 100 );
216     fHueSlider->SetValue( 0 );
217     fSaturationSlider->SetValue( 100 );
218 }
219
220 /*****************************************************************************
221  * PreferencesWindow::ApplyChanges
222  *****************************************************************************/
223 void PreferencesWindow::ApplyChanges()
224 {
225     config_PutInt( p_intf, "ffmpeg-pp-q", fPpSlider->Value() );
226     config_PutFloat( p_intf, "brightness",
227                      (float)fBrightnessSlider->Value() / 100 );
228     config_PutFloat( p_intf, "contrast",
229                      (float)fContrastSlider->Value() / 100 );
230     config_PutInt( p_intf, "hue", fHueSlider->Value() );
231     config_PutFloat( p_intf, "saturation",
232                      (float)fSaturationSlider->Value() / 100 );
233
234     if( config_GetFloat( p_intf, "brightness" ) != 1 ||
235         config_GetFloat( p_intf, "contrast" ) != 1 ||
236         config_GetInt( p_intf, "hue" ) != 0 ||
237         config_GetFloat( p_intf, "saturation" ) != 1 )
238     {
239         config_PutPsz( p_intf, "filter", "adjust" );
240     }
241     else
242     {
243         config_PutPsz( p_intf, "filter", NULL );
244     }
245 }