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