]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 - SPrefsInterface Button is clicked by default.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #include <QString>
27 #include <QFont>
28 #include <QToolButton>
29 #include <QButtonGroup>
30
31 #include "components/simple_preferences.hpp"
32 #include "components/preferences_widgets.hpp"
33 #include "qt4.hpp"
34
35 #include <vlc_config_cat.h>
36
37 #include "ui/sprefs_audio.h"
38 #include "ui/sprefs_input.h"
39 #include "ui/sprefs_video.h"
40 #include "ui/sprefs_subtitles.h"
41 #include "ui/sprefs_hotkeys.h"
42 #include "ui/sprefs_interface.h"
43
44 #define ICON_HEIGHT 64
45 #define BUTTON_HEIGHT 76
46
47 /*********************************************************************
48  * The List of categories
49  *********************************************************************/
50 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51                                   QWidget( _parent ), p_intf( _p_intf )
52 {
53     QVBoxLayout *layout = new QVBoxLayout();
54
55     QButtonGroup *buttonGroup = new QButtonGroup( this );
56     buttonGroup->setExclusive ( true );
57     CONNECT( buttonGroup, buttonClicked ( int ),
58             this, switchPanel( int ) );
59
60 #define ADD_CATEGORY( button, label, icon, numb )                           \
61     QToolButton * button = new QToolButton( this );                         \
62     button->setIcon( QIcon( ":/pixmaps/" #icon ) );                         \
63     button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
64     button->setText( label );                                               \
65     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
66     button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
67     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
68     button->setAutoRaise( true );                                           \
69     button->setCheckable( true );                                           \
70     buttonGroup->addButton( button, numb );                                 \
71     layout->addWidget( button );
72
73     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74                   spref_cone_Interface_64.png, 0 );
75     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
76     ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
78                   spref_cone_Subtitles_64.png, 3 );
79     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80                   spref_cone_Input_64.png, 4 );
81     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
82
83     SPrefsInterface->setChecked( true );
84
85     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
86     setLayout( layout );
87 }
88
89 void SPrefsCatList::switchPanel( int i )
90 {
91     emit currentItemChanged( i );
92 }
93
94 /*********************************************************************
95  * The Panels
96  *********************************************************************/
97 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
98                           int number ) : QWidget( _parent ), p_intf( _p_intf )
99 {
100     module_config_t *p_config;
101     ConfigControl *control;
102
103 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
104             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
105             if( p_config )                                                \
106             {                                                             \
107                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
108                            p_config, label, ui.qcontrol, false );         \
109                 controls.append( control );                               \
110             }
111
112 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
113             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
114             if( p_config )                                                \
115             {                                                             \
116                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
117                            p_config, label, ui.qcontrol );                \
118                 controls.append( control );                               \
119             }
120
121 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
122                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
123                 if( p_config )                                                \
124                 {                                                             \
125                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
126                                p_config, label, ui.qcontrol, ui.qbutton,      \
127                             false );                                          \
128                     controls.append( control );                               \
129                 }
130
131 #define START_SPREFS_CAT( name , label )    \
132         case SPrefs ## name:                \
133         {                                   \
134             Ui::SPrefs ## name ui;          \
135             ui.setupUi( panel );            \
136             panel_label->setText( qtr( label ) );
137
138 #define END_SPREFS_CAT      \
139             break;          \
140         }
141
142     QVBoxLayout *panel_layout = new QVBoxLayout();
143     QWidget *panel = new QWidget();
144
145     // Title Label
146     QLabel *panel_label = new QLabel;
147     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
148     labelFont.setPointSize( labelFont.pointSize() + 6 );
149     labelFont.setFamily( "Verdana" );
150     panel_label->setFont( labelFont );
151
152     // Title <hr>
153     QFrame *title_line = new QFrame;
154     title_line->setFrameShape(QFrame::HLine);
155     title_line->setFrameShadow(QFrame::Sunken);
156
157     switch( number )
158     {
159         /* Video Panel Implementation */
160         START_SPREFS_CAT( Video , "General video settings" );
161          #ifndef WIN32
162             ui.directXBox->setVisible( false );
163          #endif
164             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
165
166             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
167             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
168             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
169             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
170             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames);
171             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
172
173 #ifdef WIN32
174             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
175             CONFIG_GENERIC( "directx-device", StringList, NULL, 
176                     dXdisplayDevice );
177 #endif
178
179             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
180                     snapshotsDirectory, snapshotsDirectoryBrowse );
181             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
182             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
183                             snapshotsSequentialNumbering );
184             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
185                             snapshotsFormat );
186          END_SPREFS_CAT;
187
188          /* Audio Panel Implementation */
189         START_SPREFS_CAT( Audio,  "General audio settings" );
190 #ifdef WIN32
191             ui.OSSBrowse->hide();
192             ui.OSSDevice->hide();
193             ui.OSSLabel->hide();
194             ui.alsaDevice->hide();
195             ui.alsaLabel->hide();
196 #else
197             ui.DirectXLabel->setVisible( false );
198             ui.DirectXDevice->setVisible( false );
199 #endif
200          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
201
202          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
203                  defaultVolume );
204          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
205                     preferredAudioLanguage ); //FIXME
206
207          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
208          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
209                     detectionDolby );
210
211          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
212 #ifndef WIN32
213          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
214          CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
215 #else
216          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
217                  DirectXDevice );
218 #endif
219          CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName, 
220                  fileBrowseButton );
221
222          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
223 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
224          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
225                  volNormalizer );
226          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
227         END_SPREFS_CAT;
228
229         /* Input and Codecs Panel Implementation */
230         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
231           /* Disk Devices */
232 /*          CONFIG_GENERIC( );*/ //FIXME
233
234           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
235           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
236
237           /* Caching */
238 /*          CONFIG_GENERIC( );*/ //FIXME
239
240           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
241           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
242           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
243
244           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
245           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
246 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
247         END_SPREFS_CAT;
248
249         /* Interface Panel */
250         START_SPREFS_CAT( Interface, "Interfaces settings" );
251             
252             CONFIG_GENERIC( "language", StringList, NULL, language );//FIXME
253 #if !defined( WIN32 ) && !defined( HAVE_DBUS_3 )
254             ui.OneInterfaceBox->hide();
255 #endif
256             /* interface */
257 /*            p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
258             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
259                     ui.qt4->setChecked( true );
260             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
261                     ui.skins->setChecked( true );*/
262 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
263             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
264             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, 
265                     skinBrowse );
266 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
267             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
268             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, 
269                     EnqueueOneInterfaceMode );
270 #endif
271         END_SPREFS_CAT;
272
273         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
274             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
275
276             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
277             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );//FIXME
278             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font, 
279                     fontBrowse ); 
280             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
281             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
282                             fontSize );
283             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
284
285         END_SPREFS_CAT;
286
287         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
288         //FIMXE
289         END_SPREFS_CAT;
290         }
291
292     panel_layout->addWidget(panel_label);
293     panel_layout->addWidget(title_line);
294     panel_layout->addWidget( panel );
295     panel_layout->addStretch( 2 );
296
297     this->setLayout(panel_layout);
298 }
299
300 void SPrefsPanel::apply()
301 {
302     QList<ConfigControl *>::Iterator i;
303     for( i = controls.begin() ; i != controls.end() ; i++ )
304     {
305         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
306         c->doApply( p_intf );
307     }
308 }
309
310 void SPrefsPanel::clean()
311 {}
312