]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
qt4: add x264 tune/preset on simple-preferences
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32
33 #include <vlc_config_cat.h>
34 #include <vlc_configuration.h>
35
36 #include <QString>
37 #include <QFont>
38 #include <QToolButton>
39 #include <QButtonGroup>
40 #include <QVBoxLayout>
41 #include <QScrollArea>
42
43 #include <QStyleFactory>
44 #include <QSettings>
45 #include <QtAlgorithms>
46
47 #define ICON_HEIGHT 64
48
49 #ifdef WIN32
50 # include <vlc_windows_interfaces.h>
51 #endif
52
53 /*********************************************************************
54  * The List of categories
55  *********************************************************************/
56 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
57                                   QWidget( _parent ), p_intf( _p_intf )
58 {
59     QVBoxLayout *layout = new QVBoxLayout();
60
61     QButtonGroup *buttonGroup = new QButtonGroup( this );
62     buttonGroup->setExclusive ( true );
63     CONNECT( buttonGroup, buttonClicked ( int ),
64             this, switchPanel( int ) );
65
66     short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
67
68 #define ADD_CATEGORY( button, label, icon, numb )                           \
69     QToolButton * button = new QToolButton( this );                         \
70     button->setIcon( QIcon( ":/prefsmenu/" #icon ) );                   \
71     button->setText( label );                                               \
72     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
73     button->setIconSize( QSize( icon_height, icon_height ) );               \
74     button->resize( icon_height + 6 , icon_height + 6 );                    \
75     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
76     button->setAutoRaise( true );                                           \
77     button->setCheckable( true );                                           \
78     buttonGroup->addButton( button, numb );                                 \
79     layout->addWidget( button );
80
81     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
82                   cone_interface_64, 0 );
83     ADD_CATEGORY( SPrefsAudio, qtr("Audio"),
84                   cone_audio_64, 1 );
85     ADD_CATEGORY( SPrefsVideo, qtr("Video"),
86                   cone_video_64, 2 );
87     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
88                   cone_subtitles_64, 3 );
89     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
90                   cone_input_64, 4 );
91     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"),
92                   cone_hotkeys_64, 5 );
93
94 #undef ADD_CATEGORY
95
96     SPrefsInterface->setChecked( true );
97     layout->setMargin( 0 );
98     layout->setSpacing( 1 );
99
100     setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
101     setLayout( layout );
102
103 }
104
105 void SPrefsCatList::switchPanel( int i )
106 {
107     emit currentItemChanged( i );
108 }
109
110 /*********************************************************************
111  * The Panels
112  *********************************************************************/
113 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
114                           int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
115 {
116     module_config_t *p_config;
117     ConfigControl *control;
118     number = _number;
119
120 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
121             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
122             if( p_config )                                                \
123             {                                                             \
124                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
125                            p_config, label, ui.qcontrol, false );         \
126                 controls.append( control );                               \
127             }                                                             \
128             else {                                                        \
129                 ui.qcontrol->setEnabled( false );                         \
130                 if( label ) label->setEnabled( false );                   \
131             }
132
133 #define CONFIG_BOOL( option, qcontrol )                           \
134             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
135             if( p_config )                                                \
136             {                                                             \
137                 control =  new BoolConfigControl( VLC_OBJECT(p_intf),     \
138                            p_config, NULL, ui.qcontrol, false );          \
139                 controls.append( control );                               \
140             }                                                             \
141             else { ui.qcontrol->setEnabled( false ); }
142
143
144 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol )             \
145             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
146             if( p_config )                                                \
147             {                                                             \
148                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
149                            p_config, label, qcontrol, false );            \
150                 controls.append( control );                               \
151             }                                                             \
152             else {                                                        \
153                 QWidget *widget = label;                                  \
154                 qcontrol->setVisible( false );                            \
155                 if( widget ) widget->setEnabled( false );                 \
156             }
157
158
159 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
160             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
161             if( p_config )                                                \
162             {                                                             \
163                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
164                            p_config, label, ui.qcontrol );                \
165                 controls.append( control );                               \
166             }
167
168 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )     \
169             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
170             if( p_config )                                                \
171             {                                                             \
172                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
173                            p_config, label, qcontrol, qbutton );          \
174                 controls.append( control );                               \
175             }
176
177 #define START_SPREFS_CAT( name , label )    \
178         case SPrefs ## name:                \
179         {                                   \
180             Ui::SPrefs ## name ui;      \
181             ui.setupUi( panel );            \
182             panel_label->setText( label );
183
184 #define END_SPREFS_CAT      \
185             break;          \
186         }
187
188     QVBoxLayout *panel_layout = new QVBoxLayout();
189     QWidget *panel = new QWidget();
190     panel_layout->setMargin( 3 );
191
192     // Title Label
193     QLabel *panel_label = new QLabel;
194     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
195     labelFont.setPointSize( labelFont.pointSize() + 6 );
196     labelFont.setFamily( "Verdana" );
197     panel_label->setFont( labelFont );
198
199     // Title <hr>
200     QFrame *title_line = new QFrame;
201     title_line->setFrameShape(QFrame::HLine);
202     title_line->setFrameShadow(QFrame::Sunken);
203
204     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
205     italicFont.setItalic( true );
206
207     switch( number )
208     {
209         /******************************
210          * VIDEO Panel Implementation *
211          ******************************/
212         START_SPREFS_CAT( Video , qtr("Video Settings") );
213             CONFIG_BOOL( "video", enableVideo );
214
215             CONFIG_BOOL( "fullscreen", fullscreen );
216             CONFIG_BOOL( "overlay", overlay );
217             CONFIG_BOOL( "video-on-top", alwaysOnTop );
218             CONFIG_BOOL( "video-deco", windowDecorations );
219             CONFIG_BOOL( "skip-frames", skipFrames );
220             CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
221
222             CONFIG_BOOL( "video-wallpaper", wallpaperMode );
223 #ifdef WIN32
224             CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
225                             dXdisplayDevice );
226             CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
227 #else
228             ui.directXBox->setVisible( false );
229             ui.hwYUVBox->setVisible( false );
230 #endif
231
232             CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
233             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
234             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
235
236             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
237                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
238             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
239             CONFIG_BOOL( "snapshot-sequential",
240                             snapshotsSequentialNumbering );
241             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
242                             snapshotsFormat );
243          END_SPREFS_CAT;
244
245         /******************************
246          * AUDIO Panel Implementation *
247          ******************************/
248         START_SPREFS_CAT( Audio, qtr("Audio Settings") );
249
250             CONFIG_BOOL( "audio", enableAudio );
251             ui.SPrefsAudio_zone->setEnabled( ui.enableAudio->isChecked() );
252             CONNECT( ui.enableAudio, toggled( bool ),
253                      ui.SPrefsAudio_zone, setEnabled( bool ) );
254
255 #define audioCommon( name ) \
256             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
257             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
258             name ## Layout->setMargin( 0 ); \
259             name ## Layout->setSpacing( 0 ); \
260             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
261             name ## Label->setMinimumSize(QSize(250, 0)); \
262             name ## Layout->addWidget( name ## Label ); \
263
264 #define audioControl( name) \
265             audioCommon( name ) \
266             QComboBox * name ## Device = new QComboBox( name ## Control ); \
267             name ## Layout->addWidget( name ## Device ); \
268             name ## Label->setBuddy( name ## Device ); \
269             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
270
271 #define audioControl2( name) \
272             audioCommon( name ) \
273             QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
274             name ## Layout->addWidget( name ## Device ); \
275             name ## Label->setBuddy( name ## Device ); \
276             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
277             name ## Layout->addWidget( name ## Browse ); \
278             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
279
280             /* Build if necessary */
281             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
282 #ifdef WIN32
283             audioControl( DirectX );
284             optionWidgets.append( DirectXControl );
285             CONFIG_GENERIC_NO_UI( "directx-audio-device-name", StringList,
286                     DirectXLabel, DirectXDevice );
287 #else
288             if( module_exists( "alsa" ) )
289             {
290                 audioControl( alsa );
291                 optionWidgets.append( alsaControl );
292
293                 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
294                                 alsaDevice );
295             }
296             else
297                 optionWidgets.append( NULL );
298             if( module_exists( "oss" ) )
299             {
300                 audioControl2( OSS );
301                 optionWidgets.append( OSSControl );
302                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
303                                  OSSBrowse );
304             }
305             else
306                 optionWidgets.append( NULL );
307 #endif
308
309 #undef audioControl2
310 #undef audioControl
311 #undef audioCommon
312
313             /* Audio Options */
314             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
315                                      defaultVolume );
316             CONNECT( ui.defaultVolume, valueChanged( int ),
317                      this, updateAudioVolume( int ) );
318
319             CONFIG_BOOL( "qt-autosave-volume", keepVolumeRadio );
320             ui.defaultVolume_zone->setEnabled( ui.resetVolumeRadio->isChecked() );
321             CONNECT( ui.resetVolumeRadio, toggled( bool ),
322                      ui.defaultVolume_zone, setEnabled( bool ) );
323
324             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
325                             preferredAudioLanguage );
326
327             CONFIG_BOOL( "spdif", spdifBox );
328             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
329                             detectionDolby );
330
331             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
332                                     volNormSpin );
333             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
334                             replayCombo );
335             CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
336                             visualisation);
337             CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
338
339             /* Audio Output Specifics */
340             CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
341
342             CONNECT( ui.outputModule, currentIndexChanged( int ),
343                      this, updateAudioOptions( int ) );
344
345             /* File output exists on all platforms */
346             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
347                                  ui.fileName, ui.fileBrowseButton );
348
349             optionWidgets.append( ui.fileControl );
350             optionWidgets.append( ui.outputModule );
351             optionWidgets.append( ui.volNormBox );
352             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
353             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
354             optionWidgets.append( ui.volumeValue );
355             optionWidgets.append( ui.headphoneEffect );
356             optionWidgets.append( ui.spdifBox );
357             updateAudioOptions( ui.outputModule->currentIndex() );
358
359             /* LastFM */
360             if( module_exists( "audioscrobbler" ) )
361             {
362                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
363                         lastfm_user_edit );
364                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
365                         lastfm_pass_edit );
366
367                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
368                     ui.lastfm->setChecked( true );
369                 else
370                     ui.lastfm->setChecked( false );
371
372                 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
373
374                 CONNECT( ui.lastfm, toggled( bool ),
375                          ui.lastfm_zone, setVisible( bool ) );
376                 CONNECT( ui.lastfm, stateChanged( int ),
377                          this, lastfm_Changed( int ) );
378             }
379             else
380             {
381                 ui.lastfm->hide();
382                 ui.lastfm_zone->hide();
383             }
384
385             /* Normalizer */
386             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
387                      setEnabled( bool ) );
388
389             char* psz = config_GetPsz( p_intf, "audio-filter" );
390             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
391             free( psz );
392
393             bool b_enabled = ( qs_filter.contains( "volnorm" ) );
394             ui.volNormBox->setChecked( b_enabled );
395             ui.volNormSpin->setEnabled( b_enabled );
396
397             b_enabled = ( qs_filter.contains( "headphone" ) );
398             ui.headphoneEffect->setChecked( b_enabled );
399
400             /* Volume Label */
401             updateAudioVolume( ui.defaultVolume->value() ); // First time init
402
403         END_SPREFS_CAT;
404
405         /* Input and Codecs Panel Implementation */
406         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
407
408             /* Disk Devices */
409             {
410                 ui.DVDDevice->setToolTip(
411                     qtr( "If this property is blank, different values\n"
412                          "for DVD, VCD, and CDDA are set.\n"
413                          "You can define a unique one or configure them \n"
414                          "individually in the advanced preferences." ) );
415                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
416                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
417                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
418                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
419                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
420                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
421                 {
422                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
423                 }
424                 free( psz_cddadiscpath );
425                 free( psz_dvddiscpath );
426                 free( psz_vcddiscpath );
427             }
428             CONFIG_GENERIC_FILE( "dvd", File, ui.DVDLabel,
429                                  ui.DVDDevice, ui.DVDBrowse );
430             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
431                                  ui.recordPath, ui.recordBrowse );
432
433             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
434                                     UDPPort );
435             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
436             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
437                                     PostProcLevel );
438             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
439
440             /* live555 module prefs */
441             CONFIG_BOOL( "rtsp-tcp",
442                                 live555TransportRTSP_TCPRadio );
443             if ( !module_exists( "live555" ) )
444             {
445                 ui.live555TransportRTSP_TCPRadio->hide();
446                 ui.live555TransportHTTPRadio->hide();
447                 ui.live555TransportLabel->hide();
448             }
449 #ifdef WIN32
450             CONFIG_BOOL( "prefer-system-codecs", systemCodecBox );
451 #else
452             ui.systemCodecBox->hide();
453 #endif
454             CONFIG_BOOL( "ffmpeg-hw", hwAccelBox );
455             optionWidgets.append( ui.DVDDevice );
456             optionWidgets.append( ui.cachingCombo );
457             CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
458             CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
459             CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
460
461             /* Caching */
462             /* Add the things to the ComboBox */
463             #define addToCachingBox( str, cachingNumber ) \
464                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
465             addToCachingBox( N_("Custom"), CachingCustom );
466             addToCachingBox( N_("Lowest latency"), CachingLowest );
467             addToCachingBox( N_("Low latency"), CachingLow );
468             addToCachingBox( N_("Normal"), CachingNormal );
469             addToCachingBox( N_("High latency"), CachingHigh );
470             addToCachingBox( N_("Higher latency"), CachingHigher );
471             #undef addToCachingBox
472
473 #define TestCaC( name ) \
474     b_cache_equal =  b_cache_equal && \
475      ( i_cache == config_GetInt( p_intf, name ) )
476
477 #define TestCaCi( name, int ) \
478     b_cache_equal = b_cache_equal &&  \
479     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
480             /* Select the accurate value of the ComboBox */
481             bool b_cache_equal = true;
482             int i_cache = config_GetInt( p_intf, "file-caching");
483
484             TestCaC( "udp-caching" );
485             if (module_exists ("dvdread"))
486                 TestCaC( "dvdread-caching" );
487             if (module_exists ("dvdnav"))
488                 TestCaC( "dvdnav-caching" );
489             TestCaC( "tcp-caching" );
490             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
491             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
492             #ifdef WIN32
493             TestCaC( "dshow-caching" );
494             #else
495             if (module_exists ("v4l"))
496                 TestCaC( "v4l-caching" );
497             if (module_exists ("access_jack"))
498                 TestCaC( "jack-input-caching" );
499             if (module_exists ("v4l2"))
500                 TestCaC( "v4l2-caching" );
501             if (module_exists ("pvr"))
502                 TestCaC( "pvr-caching" );
503             #endif
504             if (module_exists ("livedotcom"))
505                 TestCaCi( "rtsp-caching", 4 );
506             TestCaCi( "ftp-caching", 2 );
507             TestCaCi( "http-caching", 2 );
508             if (module_exists ("access_realrtsp"))
509                 TestCaCi( "realrtsp-caching", 10 );
510             TestCaCi( "mms-caching", 10 );
511             if( b_cache_equal == 1 )
512                 ui.cachingCombo->setCurrentIndex(
513                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
514 #undef TestCaCi
515 #undef TestCaC
516
517         END_SPREFS_CAT;
518         /*******************
519          * Interface Panel *
520          *******************/
521         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
522 //            ui.defaultLabel->setFont( italicFont );
523             ui.skinsLabel->setText(
524                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
525                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
526             ui.skinsLabel->setFont( italicFont );
527
528 #if defined( WIN32 )
529             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
530             BUTTONACT( ui.assoButton, assoDialog() );
531 #else
532             ui.languageBox->hide();
533             ui.assoBox->hide();
534 #endif
535             /* interface */
536             char *psz_intf = config_GetPsz( p_intf, "intf" );
537             if( psz_intf )
538             {
539                 if( strstr( psz_intf, "skin" ) )
540                     ui.skins->setChecked( true );
541             } else {
542                 /* defaults to qt */
543                 ui.qt4->setChecked( true );
544             }
545             free( psz_intf );
546
547             optionWidgets.append( ui.skins );
548             optionWidgets.append( ui.qt4 );
549 #if !defined(NDEBUG) || !defined( WIN32)
550             ui.stylesCombo->addItem( qtr("System's default") );
551             ui.stylesCombo->addItems( QStyleFactory::keys() );
552             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
553                         getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
554             ui.stylesCombo->insertSeparator( 1 );
555
556             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
557             optionWidgets.append( ui.stylesCombo );
558 #else
559             ui.stylesCombo->hide();
560             optionWidgets.append( NULL );
561 #endif
562
563             ui.skins_zone->setEnabled( ui.skins->isChecked() );
564             CONNECT( ui.skins, toggled( bool ), ui.skins_zone, setEnabled( bool ) );
565
566             ui.native_zone->setEnabled( ui.qt4->isChecked() );
567             CONNECT( ui.qt4, toggled( bool ), ui.native_zone, setEnabled( bool ) );
568
569             CONNECT( ui.minimalviewBox, toggled( bool ),
570                      ui.mainPreview, setNormalPreview( bool ) );
571             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
572             ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
573             ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
574
575             CONFIG_BOOL( "embedded-video", embedVideo );
576             CONFIG_BOOL( "qt-fs-controller", fsController );
577             CONFIG_BOOL( "qt-system-tray", systrayBox );
578             CONFIG_BOOL( "qt-notification", sysPop );
579             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
580                                  ui.fileSkin, ui.skinBrowse );
581             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
582
583             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
584                                                       artFetcher );
585
586             /* UPDATE options */
587 #ifdef UPDATE_CHECK
588             CONFIG_BOOL( "qt-updates-notif", updatesBox );
589             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
590                     updatesDays );
591             ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
592             CONNECT( ui.updatesBox, toggled( bool ),
593                      ui.updatesDays, setEnabled( bool ) );
594 #else
595             ui.updatesBox->hide();
596             ui.updatesDays->hide();
597 #endif
598             /* ONE INSTANCE options */
599 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
600             CONFIG_BOOL( "one-instance", OneInterfaceMode );
601             CONFIG_BOOL( "playlist-enqueue",
602                     EnqueueOneInterfaceMode );
603             ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
604             CONNECT( ui.OneInterfaceMode, toggled( bool ),
605                      ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
606 #else
607             ui.OneInterfaceBox->hide();
608 #endif
609             /* RECENTLY PLAYED options */
610             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
611                      ui.recentlyPlayedFilters, setEnabled( bool ) );
612             ui.recentlyPlayedFilters->setEnabled( false );
613             CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
614             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
615                     recentlyPlayedFilters );
616
617         END_SPREFS_CAT;
618
619         START_SPREFS_CAT( Subtitles,
620                             qtr("Subtitles & On Screen Display Settings") );
621             CONFIG_BOOL( "osd", OSDBox);
622             CONFIG_BOOL( "video-title-show", OSDTitleBox);
623
624
625             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
626                             encoding );
627             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
628                             preferredLanguage );
629             CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
630             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
631                             fontColor );
632             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
633                             ui.fontSizeLabel, fontSize );
634             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
635                             effect );
636             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
637
638         END_SPREFS_CAT;
639
640         case SPrefsHotkeys:
641         {
642             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
643
644             QGridLayout *gLayout = new QGridLayout;
645             panel->setLayout( gLayout );
646             int line = 0;
647
648             panel_label->setText( qtr( "Configure Hotkeys" ) );
649             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
650                                                 this, gLayout, line );
651             controls.append( control );
652
653             line++;
654
655             QFrame *sepline = new QFrame;
656             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
657             gLayout->addWidget( sepline, line, 0, 1, -1 );
658
659             line++;
660
661             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
662             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
663                     p_config, false, this, gLayout, line );
664             controls.append( control );
665
666             break;
667         }
668     }
669
670     panel_layout->addWidget( panel_label );
671     panel_layout->addWidget( title_line );
672
673     if( small )
674     {
675         QScrollArea *scroller= new QScrollArea;
676         scroller->setWidget( panel );
677         scroller->setWidgetResizable( true );
678         scroller->setFrameStyle( QFrame::NoFrame );
679         panel_layout->addWidget( scroller );
680     }
681     else
682     {
683         panel_layout->addWidget( panel );
684         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
685     }
686
687     setLayout( panel_layout );
688
689 #undef END_SPREFS_CAT
690 #undef START_SPREFS_CAT
691 #undef CONFIG_GENERIC_FILE
692 #undef CONFIG_GENERIC_NO_BOOL
693 #undef CONFIG_GENERIC_NO_UI
694 #undef CONFIG_GENERIC
695 #undef CONFIG_BOOL
696 }
697
698
699 void SPrefsPanel::updateAudioOptions( int number)
700 {
701     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
702                                             ->itemData( number ).toString();
703 #ifdef WIN32
704     optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
705 #else
706     /* optionWidgets[ossW] can be NULL */
707     if( optionWidgets[ossW] )
708         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
709     /* optionWidgets[alsaW] can be NULL */
710     if( optionWidgets[alsaW] )
711         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
712 #endif
713     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
714     optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
715                                            value == "aout_directx" || value == "waveout" ) );
716 }
717
718
719 SPrefsPanel::~SPrefsPanel()
720 {
721     qDeleteAll( controls ); controls.clear();
722 }
723
724 void SPrefsPanel::updateAudioVolume( int volume )
725 {
726     qobject_cast<QSpinBox *>(optionWidgets[volLW])
727         ->setValue( volume * 100 / 256 );
728 }
729
730
731 /* Function called from the main Preferences dialog on each SPrefs Panel */
732 void SPrefsPanel::apply()
733 {
734     /* Generic save for ever panel */
735     QList<ConfigControl *>::Iterator i;
736     for( i = controls.begin() ; i != controls.end() ; i++ )
737     {
738         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
739         c->doApply( p_intf );
740     }
741
742     switch( number )
743     {
744     case SPrefsInputAndCodecs:
745     {
746         /* Device default selection */
747         char *psz_devicepath =
748             strdup( qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() ) );
749         if( !EMPTY_STR( psz_devicepath ) )
750         {
751             config_PutPsz( p_intf, "dvd", psz_devicepath );
752             config_PutPsz( p_intf, "vcd", psz_devicepath );
753             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
754             free( psz_devicepath );
755         }
756
757 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
758 #define CaC( name ) CaCi( name, 1 )
759         /* Caching */
760         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
761         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
762         if( i_comboValue )
763         {
764             CaC( "udp-caching" );
765             if (module_exists ("dvdread" ))
766                 CaC( "dvdread-caching" );
767             if (module_exists ("dvdnav" ))
768                 CaC( "dvdnav-caching" );
769             CaC( "tcp-caching" ); CaC( "vcd-caching" );
770             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
771             CaC( "screen-caching" ); CaC( "bd-caching" );
772             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
773             CaCi( "http-caching", 2 );
774             if (module_exists ("access_realrtsp" ))
775                 CaCi( "realrtsp-caching", 10 );
776             CaCi( "mms-caching", 10 );
777             #ifdef WIN32
778             CaC( "dshow-caching" );
779             #else
780             if (module_exists ( "v4l" ))
781                 CaC( "v4l-caching" );
782             if (module_exists ( "access_jack" ))
783             CaC( "jack-input-caching" );
784             if (module_exists ( "v4l2" ))
785                 CaC( "v4l2-caching" );
786             if (module_exists ( "pvr" ))
787                 CaC( "pvr-caching" );
788             #endif
789             //CaCi( "dv-caching" ) too short...
790         }
791         break;
792 #undef CaC
793 #undef CaCi
794     }
795
796     /* Interfaces */
797     case SPrefsInterface:
798     {
799         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
800             config_PutPsz( p_intf, "intf", "skins2" );
801         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
802             config_PutPsz( p_intf, "intf", "qt" );
803         if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
804             getSettings()->setValue( "MainWindow/QtStyle",
805                 qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
806
807         break;
808     }
809
810     case SPrefsAudio:
811     {
812         bool b_checked =
813             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
814         if( b_checked && !qs_filter.contains( "volnorm" ) )
815             qs_filter.append( "volnorm" );
816         if( !b_checked && qs_filter.contains( "volnorm" ) )
817             qs_filter.removeAll( "volnorm" );
818
819         b_checked =
820             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
821
822         if( b_checked && !qs_filter.contains( "headphone" ) )
823             qs_filter.append( "headphone" );
824         if( !b_checked && qs_filter.contains( "headphone" ) )
825             qs_filter.removeAll( "headphone" );
826
827         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
828         break;
829     }
830     }
831 }
832
833 void SPrefsPanel::clean()
834 {}
835
836 void SPrefsPanel::lastfm_Changed( int i_state )
837 {
838     if( i_state == Qt::Checked )
839         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
840     else if( i_state == Qt::Unchecked )
841         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
842 }
843
844 void SPrefsPanel::changeStyle( QString s_style )
845 {
846     QApplication::setStyle( s_style );
847
848     /* force refresh on all widgets */
849     QWidgetList widgets = QApplication::allWidgets();
850     QWidgetList::iterator it = widgets.begin();
851     while( it != widgets.end() ) {
852         (*it)->update();
853         it++;
854     };
855 }
856
857 #ifdef WIN32
858 #include <QDialogButtonBox>
859 #include <QHeaderView>
860 #include "util/registry.hpp"
861 #include <string>
862
863 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
864                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
865 {
866     bool b_temp;
867     const char* psz_VLC = "VLC";
868     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
869
870     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
871     {
872         current->setCheckState( 0, Qt::Checked );
873         b_temp = false;
874     }
875     else
876     {
877         current->setCheckState( 0, Qt::Unchecked );
878         b_temp = true;
879     }
880     listAsso.append( current );
881     return b_temp;
882 }
883
884 void SPrefsPanel::assoDialog()
885 {
886     LPAPPASSOCREGUI p_appassoc;
887     CoInitialize( 0 );
888
889     if( S_OK == CoCreateInstance( &clsid_IApplication2,
890                 NULL, CLSCTX_INPROC_SERVER,
891                 &IID_IApplicationAssociationRegistrationUI,
892                 (void **)&p_appassoc) )
893     {
894         if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
895         {
896             CoUninitialize();
897             return;
898         }
899     }
900
901     CoUninitialize();
902
903     QDialog *d = new QDialog( this );
904     QGridLayout *assoLayout = new QGridLayout( d );
905
906     QTreeWidget *filetypeList = new QTreeWidget;
907     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
908     filetypeList->header()->hide();
909
910     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
911
912     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
913     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
914     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
915
916     filetypeList->addTopLevelItem( audioType );
917     filetypeList->addTopLevelItem( videoType );
918     filetypeList->addTopLevelItem( otherType );
919
920     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
921     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
922     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
923
924     QTreeWidgetItem *currentItem;
925
926     int i_temp = 0;
927 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
928 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
929 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
930
931     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
932     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
933     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
934     aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
935     audioType->setCheckState( 0, ( i_temp > 0 ) ?
936                               ( ( i_temp == audioType->childCount() ) ?
937                                Qt::Checked : Qt::PartiallyChecked )
938                             : Qt::Unchecked );
939
940     i_temp = 0;
941     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
942     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
943     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
944     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
945     aTv( ".mts" ); aTv( ".mxf" );
946     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
947     aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
948     videoType->setCheckState( 0, ( i_temp > 0 ) ?
949                               ( ( i_temp == audioType->childCount() ) ?
950                                Qt::Checked : Qt::PartiallyChecked )
951                             : Qt::Unchecked );
952
953     i_temp = 0;
954     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
955     aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
956     otherType->setCheckState( 0, ( i_temp > 0 ) ?
957                               ( ( i_temp == audioType->childCount() ) ?
958                                Qt::Checked : Qt::PartiallyChecked )
959                             : Qt::Unchecked );
960
961 #undef aTo
962 #undef aTv
963 #undef aTa
964
965     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
966     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
967     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
968     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
969     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
970
971     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
972
973     CONNECT( closeButton, clicked(), this, saveAsso() );
974     CONNECT( clearButton, clicked(), d, reject() );
975     d->resize( 300, 400 );
976     d->exec();
977     delete d;
978     delete qvReg;
979     listAsso.clear();
980 }
981
982 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
983 {
984     std::string s_path( "VLC" ); s_path += psz_ext;
985     std::string s_path2 = s_path;
986
987     /* Save a backup if already assigned */
988     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
989
990     if( psz_value && strlen( psz_value ) > 0 )
991         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
992     delete psz_value;
993
994     /* Put a "link" to VLC.EXT as default */
995     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
996
997     /* Create the needed Key if they weren't done in the installer */
998     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
999     {
1000         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1001         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
1002         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
1003
1004         /* Get the installer path */
1005         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1006         std::string str_temp; str_temp.assign(
1007             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
1008
1009         if( str_temp.size() )
1010         {
1011             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
1012                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
1013
1014             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
1015                         "", str_temp.append(",0").c_str() );
1016         }
1017         delete qvReg2;
1018     }
1019 }
1020
1021 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1022 {
1023     char psz_VLC[] = "VLC";
1024     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1025
1026     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
1027     {
1028         free( psz_value );
1029         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1030         if( psz_value )
1031             qvReg->WriteRegistryString( psz_ext, "", psz_value );
1032
1033         qvReg->DeleteKey( psz_ext, "VLC.backup" );
1034     }
1035     delete( psz_value );
1036 }
1037 void SPrefsPanel::saveAsso()
1038 {
1039     QVLCRegistry * qvReg;
1040     for( int i = 0; i < listAsso.size(); i ++ )
1041     {
1042         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
1043         if( listAsso[i]->checkState( 0 ) > 0 )
1044         {
1045             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1046         }
1047         else
1048         {
1049             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1050         }
1051     }
1052     /* Gruik ? Naaah */
1053     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1054     delete qvReg;
1055 }
1056
1057 #endif /* WIN32 */
1058