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