]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt: sprefs, simplification
[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_BOOL( "skip-frames", skipFrames );
462             CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
463             CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
464             CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
465             CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
466
467             /* Caching */
468             /* Add the things to the ComboBox */
469             #define addToCachingBox( str, cachingNumber ) \
470                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
471             addToCachingBox( N_("Custom"), CachingCustom );
472             addToCachingBox( N_("Lowest latency"), CachingLowest );
473             addToCachingBox( N_("Low latency"), CachingLow );
474             addToCachingBox( N_("Normal"), CachingNormal );
475             addToCachingBox( N_("High latency"), CachingHigh );
476             addToCachingBox( N_("Higher latency"), CachingHigher );
477             #undef addToCachingBox
478
479 #define TestCaC( name ) \
480     b_cache_equal =  b_cache_equal && \
481      ( i_cache == config_GetInt( p_intf, name ) )
482
483 #define TestCaCi( name, int ) \
484     b_cache_equal = b_cache_equal &&  \
485     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
486             /* Select the accurate value of the ComboBox */
487             bool b_cache_equal = true;
488             int i_cache = config_GetInt( p_intf, "file-caching");
489
490             TestCaC( "udp-caching" );
491             if (module_exists ("dvdread"))
492                 TestCaC( "dvdread-caching" );
493             if (module_exists ("dvdnav"))
494                 TestCaC( "dvdnav-caching" );
495             TestCaC( "tcp-caching" );
496             TestCaC( "cdda-caching" );
497             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
498             #ifdef WIN32
499             TestCaC( "dshow-caching" );
500             #else
501             if (module_exists ("v4l"))
502                 TestCaC( "v4l-caching" );
503             if (module_exists ("access_jack"))
504                 TestCaC( "jack-input-caching" );
505             if (module_exists ("v4l2"))
506                 TestCaC( "v4l2-caching" );
507             if (module_exists ("pvr"))
508                 TestCaC( "pvr-caching" );
509             #endif
510             if (module_exists ("livedotcom"))
511                 TestCaCi( "rtsp-caching", 4 );
512             TestCaCi( "ftp-caching", 2 );
513             TestCaCi( "http-caching", 2 );
514             if (module_exists ("access_realrtsp"))
515                 TestCaCi( "realrtsp-caching", 10 );
516             TestCaCi( "mms-caching", 10 );
517             if( b_cache_equal == 1 )
518                 ui.cachingCombo->setCurrentIndex(
519                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
520 #undef TestCaCi
521 #undef TestCaC
522
523         END_SPREFS_CAT;
524         /*******************
525          * Interface Panel *
526          *******************/
527         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
528 //            ui.defaultLabel->setFont( italicFont );
529             ui.skinsLabel->setText(
530                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
531                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">" )
532                     + qtr( "VLC skins website" )+ QString( "</a>." ) );
533             ui.skinsLabel->setFont( italicFont );
534
535 #if defined( WIN32 )
536             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
537             BUTTONACT( ui.assoButton, assoDialog() );
538 #else
539             ui.languageBox->hide();
540             ui.assoButton->hide();
541             ui.assocLabel->hide();
542 #endif
543             /* interface */
544             char *psz_intf = config_GetPsz( p_intf, "intf" );
545             if( psz_intf )
546             {
547                 if( strstr( psz_intf, "skin" ) )
548                     ui.skins->setChecked( true );
549             } else {
550                 /* defaults to qt */
551                 ui.qt4->setChecked( true );
552             }
553             free( psz_intf );
554
555             optionWidgets.append( ui.skins );
556             optionWidgets.append( ui.qt4 );
557 #if !defined(NDEBUG) || !defined( WIN32)
558             ui.stylesCombo->addItem( qtr("System's default") );
559             ui.stylesCombo->addItems( QStyleFactory::keys() );
560             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
561                         getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
562             ui.stylesCombo->insertSeparator( 1 );
563
564             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
565             optionWidgets.append( ui.stylesCombo );
566 #else
567             ui.stylesCombo->hide();
568             optionWidgets.append( NULL );
569 #endif
570             radioGroup = new QButtonGroup(this);
571             radioGroup->addButton( ui.qt4, 0 );
572             radioGroup->addButton( ui.skins, 1 );
573             CONNECT( radioGroup, buttonClicked( int ),
574                      ui.styleStackedWidget, setCurrentIndex( int ) );
575             ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
576
577             CONNECT( ui.minimalviewBox, toggled( bool ),
578                      ui.mainPreview, setNormalPreview( bool ) );
579             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
580             ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
581             ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
582
583             CONFIG_BOOL( "embedded-video", embedVideo );
584             CONFIG_BOOL( "qt-fs-controller", fsController );
585             CONFIG_BOOL( "qt-system-tray", systrayBox );
586             CONFIG_BOOL( "qt-notification", sysPop );
587             CONFIG_BOOL( "playlist-tree", treePlaylist );
588             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
589                                  ui.fileSkin, ui.skinBrowse );
590             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
591
592             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
593                                                       artFetcher );
594
595             /* UPDATE options */
596 #ifdef UPDATE_CHECK
597             CONFIG_BOOL( "qt-updates-notif", updatesBox );
598             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
599                     updatesDays );
600             ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
601             CONNECT( ui.updatesBox, toggled( bool ),
602                      ui.updatesDays, setEnabled( bool ) );
603 #else
604             ui.updateNotifierZone->hide();
605 #endif
606             /* ONE INSTANCE options */
607 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
608             CONFIG_BOOL( "one-instance", OneInterfaceMode );
609             CONFIG_BOOL( "playlist-enqueue",
610                     EnqueueOneInterfaceMode );
611             ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
612             CONNECT( ui.OneInterfaceMode, toggled( bool ),
613                      ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
614 #else
615             ui.OneInterfaceBox->hide();
616 #endif
617             /* RECENTLY PLAYED options */
618             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
619                      ui.recentlyPlayedFilters, setEnabled( bool ) );
620             ui.recentlyPlayedFilters->setEnabled( false );
621             CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
622             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
623                     recentlyPlayedFilters );
624
625         END_SPREFS_CAT;
626
627         START_SPREFS_CAT( Subtitles,
628                             qtr("Subtitles & On Screen Display Settings") );
629             CONFIG_BOOL( "osd", OSDBox);
630             CONFIG_BOOL( "video-title-show", OSDTitleBox);
631
632
633             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
634                             encoding );
635             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
636                             preferredLanguage );
637             CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
638             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
639                             fontColor );
640             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
641                             ui.fontSizeLabel, fontSize );
642             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
643                             effect );
644             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
645
646         END_SPREFS_CAT;
647
648         case SPrefsHotkeys:
649         {
650             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
651
652             QGridLayout *gLayout = new QGridLayout;
653             panel->setLayout( gLayout );
654             int line = 0;
655
656             panel_label->setText( qtr( "Configure Hotkeys" ) );
657             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
658                                                 this, gLayout, line );
659             controls.append( control );
660
661             line++;
662
663             QFrame *sepline = new QFrame;
664             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
665             gLayout->addWidget( sepline, line, 0, 1, -1 );
666
667             line++;
668
669             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
670             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
671                     p_config, this, false, gLayout, line );
672             controls.append( control );
673
674             break;
675         }
676     }
677
678     panel_layout->addWidget( panel_label );
679     panel_layout->addWidget( title_line );
680
681     if( small )
682     {
683         QScrollArea *scroller= new QScrollArea;
684         scroller->setWidget( panel );
685         scroller->setWidgetResizable( true );
686         scroller->setFrameStyle( QFrame::NoFrame );
687         panel_layout->addWidget( scroller );
688     }
689     else
690     {
691         panel_layout->addWidget( panel );
692         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
693     }
694
695     setLayout( panel_layout );
696
697 #undef END_SPREFS_CAT
698 #undef START_SPREFS_CAT
699 #undef CONFIG_GENERIC_FILE
700 #undef CONFIG_GENERIC_NO_BOOL
701 #undef CONFIG_GENERIC_NO_UI
702 #undef CONFIG_GENERIC
703 #undef CONFIG_BOOL
704 }
705
706
707 void SPrefsPanel::updateAudioOptions( int number)
708 {
709     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
710                                             ->itemData( number ).toString();
711 #ifdef WIN32
712     optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
713 #else
714     /* optionWidgets[ossW] can be NULL */
715     if( optionWidgets[ossW] )
716         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
717     /* optionWidgets[alsaW] can be NULL */
718     if( optionWidgets[alsaW] )
719         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
720 #endif
721     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
722     optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
723                                            value == "aout_directx" || value == "waveout" ) );
724 }
725
726
727 SPrefsPanel::~SPrefsPanel()
728 {
729     qDeleteAll( controls ); controls.clear();
730 }
731
732 void SPrefsPanel::updateAudioVolume( int volume )
733 {
734     qobject_cast<QSpinBox *>(optionWidgets[volLW])
735         ->setValue( volume * 100 / QT_VOLUME_DEFAULT );
736 }
737
738
739 /* Function called from the main Preferences dialog on each SPrefs Panel */
740 void SPrefsPanel::apply()
741 {
742     /* Generic save for ever panel */
743     QList<ConfigControl *>::Iterator i;
744     for( i = controls.begin() ; i != controls.end() ; i++ )
745     {
746         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
747         c->doApply( p_intf );
748     }
749
750     switch( number )
751     {
752     case SPrefsInputAndCodecs:
753     {
754         /* Device default selection */
755         char *psz_devicepath =
756             strdup( qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() ) );
757         if( !EMPTY_STR( psz_devicepath ) )
758         {
759             config_PutPsz( p_intf, "dvd", psz_devicepath );
760             config_PutPsz( p_intf, "vcd", psz_devicepath );
761             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
762             free( psz_devicepath );
763         }
764
765 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
766 #define CaC( name ) CaCi( name, 1 )
767         /* Caching */
768         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
769         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
770         if( i_comboValue )
771         {
772             CaC( "udp-caching" );
773             if (module_exists ("dvdread" ))
774                 CaC( "dvdread-caching" );
775             if (module_exists ("dvdnav" ))
776                 CaC( "dvdnav-caching" );
777             CaC( "tcp-caching" ); CaC( "vcd-caching" );
778             CaC( "cdda-caching" ); CaC( "file-caching" );
779             CaC( "screen-caching" ); CaC( "bd-caching" );
780             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
781             CaCi( "http-caching", 2 );
782             if (module_exists ("access_realrtsp" ))
783                 CaCi( "realrtsp-caching", 10 );
784             CaCi( "mms-caching", 10 );
785             #ifdef WIN32
786             CaC( "dshow-caching" );
787             #else
788             if (module_exists ( "v4l" ))
789                 CaC( "v4l-caching" );
790             if (module_exists ( "access_jack" ))
791             CaC( "jack-input-caching" );
792             if (module_exists ( "v4l2" ))
793                 CaC( "v4l2-caching" );
794             if (module_exists ( "pvr" ))
795                 CaC( "pvr-caching" );
796             #endif
797             //CaCi( "dv-caching" ) too short...
798         }
799         break;
800 #undef CaC
801 #undef CaCi
802     }
803
804     /* Interfaces */
805     case SPrefsInterface:
806     {
807         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
808             config_PutPsz( p_intf, "intf", "skins2" );
809         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
810             config_PutPsz( p_intf, "intf", "qt" );
811         if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
812             getSettings()->setValue( "MainWindow/QtStyle",
813                 qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
814
815         break;
816     }
817
818     case SPrefsAudio:
819     {
820         bool b_checked =
821             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
822         if( b_checked && !qs_filter.contains( "volnorm" ) )
823             qs_filter.append( "volnorm" );
824         if( !b_checked && qs_filter.contains( "volnorm" ) )
825             qs_filter.removeAll( "volnorm" );
826
827         b_checked =
828             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
829
830         if( b_checked && !qs_filter.contains( "headphone" ) )
831             qs_filter.append( "headphone" );
832         if( !b_checked && qs_filter.contains( "headphone" ) )
833             qs_filter.removeAll( "headphone" );
834
835         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
836         break;
837     }
838     }
839 }
840
841 void SPrefsPanel::clean()
842 {}
843
844 void SPrefsPanel::lastfm_Changed( int i_state )
845 {
846     if( i_state == Qt::Checked )
847         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
848     else if( i_state == Qt::Unchecked )
849         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
850 }
851
852 void SPrefsPanel::changeStyle( QString s_style )
853 {
854     QApplication::setStyle( s_style );
855
856     /* force refresh on all widgets */
857     QWidgetList widgets = QApplication::allWidgets();
858     QWidgetList::iterator it = widgets.begin();
859     while( it != widgets.end() ) {
860         (*it)->update();
861         it++;
862     };
863 }
864
865 #ifdef WIN32
866 #include <QDialogButtonBox>
867 #include <QHeaderView>
868 #include "util/registry.hpp"
869 #include <string>
870
871 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
872                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
873 {
874     bool b_temp;
875     const char* psz_VLC = "VLC";
876     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
877
878     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
879     {
880         current->setCheckState( 0, Qt::Checked );
881         b_temp = false;
882     }
883     else
884     {
885         current->setCheckState( 0, Qt::Unchecked );
886         b_temp = true;
887     }
888     listAsso.append( current );
889     return b_temp;
890 }
891
892 void SPrefsPanel::assoDialog()
893 {
894     LPAPPASSOCREGUI p_appassoc;
895     CoInitialize( 0 );
896
897     if( S_OK == CoCreateInstance( &clsid_IApplication2,
898                 NULL, CLSCTX_INPROC_SERVER,
899                 &IID_IApplicationAssociationRegistrationUI,
900                 (void **)&p_appassoc) )
901     {
902         if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
903         {
904             CoUninitialize();
905             return;
906         }
907     }
908
909     CoUninitialize();
910
911     QDialog *d = new QDialog( this );
912     QGridLayout *assoLayout = new QGridLayout( d );
913
914     QTreeWidget *filetypeList = new QTreeWidget;
915     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
916     filetypeList->header()->hide();
917
918     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
919
920     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
921     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
922     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
923
924     filetypeList->addTopLevelItem( audioType );
925     filetypeList->addTopLevelItem( videoType );
926     filetypeList->addTopLevelItem( otherType );
927
928     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
929     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
930     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
931
932     QTreeWidgetItem *currentItem;
933
934     int i_temp = 0;
935 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
936 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
937 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
938
939     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
940     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
941     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
942     aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
943     audioType->setCheckState( 0, ( i_temp > 0 ) ?
944                               ( ( i_temp == audioType->childCount() ) ?
945                                Qt::Checked : Qt::PartiallyChecked )
946                             : Qt::Unchecked );
947
948     i_temp = 0;
949     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
950     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
951     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
952     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
953     aTv( ".mts" ); aTv( ".mxf" );
954     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
955     aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
956     videoType->setCheckState( 0, ( i_temp > 0 ) ?
957                               ( ( i_temp == audioType->childCount() ) ?
958                                Qt::Checked : Qt::PartiallyChecked )
959                             : Qt::Unchecked );
960
961     i_temp = 0;
962     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
963     aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
964     otherType->setCheckState( 0, ( i_temp > 0 ) ?
965                               ( ( i_temp == audioType->childCount() ) ?
966                                Qt::Checked : Qt::PartiallyChecked )
967                             : Qt::Unchecked );
968
969 #undef aTo
970 #undef aTv
971 #undef aTa
972
973     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
974     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
975     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
976     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
977     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
978
979     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
980
981     CONNECT( closeButton, clicked(), this, saveAsso() );
982     CONNECT( clearButton, clicked(), d, reject() );
983     d->resize( 300, 400 );
984     d->exec();
985     delete d;
986     delete qvReg;
987     listAsso.clear();
988 }
989
990 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
991 {
992     std::string s_path( "VLC" ); s_path += psz_ext;
993     std::string s_path2 = s_path;
994
995     /* Save a backup if already assigned */
996     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
997
998     if( psz_value && strlen( psz_value ) > 0 )
999         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
1000     delete psz_value;
1001
1002     /* Put a "link" to VLC.EXT as default */
1003     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1004
1005     /* Create the needed Key if they weren't done in the installer */
1006     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
1007     {
1008         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1009         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
1010         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
1011
1012         /* Get the installer path */
1013         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1014         std::string str_temp; str_temp.assign(
1015             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
1016
1017         if( str_temp.size() )
1018         {
1019             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
1020                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
1021
1022             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
1023                         "", str_temp.append(",0").c_str() );
1024         }
1025         delete qvReg2;
1026     }
1027 }
1028
1029 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1030 {
1031     char psz_VLC[] = "VLC";
1032     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1033
1034     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
1035     {
1036         free( psz_value );
1037         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1038         if( psz_value )
1039             qvReg->WriteRegistryString( psz_ext, "", psz_value );
1040
1041         qvReg->DeleteKey( psz_ext, "VLC.backup" );
1042     }
1043     delete( psz_value );
1044 }
1045 void SPrefsPanel::saveAsso()
1046 {
1047     QVLCRegistry * qvReg;
1048     for( int i = 0; i < listAsso.size(); i ++ )
1049     {
1050         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
1051         if( listAsso[i]->checkState( 0 ) > 0 )
1052         {
1053             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1054         }
1055         else
1056         {
1057             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1058         }
1059     }
1060     /* Gruik ? Naaah */
1061     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1062     delete qvReg;
1063 }
1064
1065 #endif /* WIN32 */
1066