1a55c6812264a4a72f4ff97680e688033592e2e4
[vlc.git] / 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-visual" , Module , ui.visuLabel,
299                             visualisation);
300
301             /* Audio Output Specifics */
302             CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
303
304             CONNECT( ui.outputModule, currentIndexChanged( int ),
305                      this, updateAudioOptions( int ) );
306
307             /* File output exists on all platforms */
308             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
309                                  ui.fileName, ui.fileBrowseButton );
310
311             optionWidgets.append( ui.fileControl );
312             optionWidgets.append( ui.outputModule );
313             optionWidgets.append( ui.volNormBox );
314             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
315             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
316             optionWidgets.append( ui.volumeValue );
317             optionWidgets.append( ui.headphoneEffect );
318             updateAudioOptions( ui.outputModule->currentIndex() );
319
320             /* LastFM */
321             if( module_exists( "audioscrobbler" ) )
322             {
323                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
324                         lastfm_user_edit );
325                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
326                         lastfm_pass_edit );
327
328                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
329                     ui.lastfm->setChecked( true );
330                 else
331                     ui.lastfm->setChecked( false );
332                 CONNECT( ui.lastfm, stateChanged( int ),
333                          this, lastfm_Changed( int ) );
334             }
335             else
336                 ui.lastfm->hide();
337
338             /* Normalizer */
339             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
340                      setEnabled( bool ) );
341
342             char* psz = config_GetPsz( p_intf, "audio-filter" );
343             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
344             free( psz );
345
346             bool b_enabled = ( qs_filter.contains( "volnorm" ) );
347             ui.volNormBox->setChecked( b_enabled );
348             ui.volNormSpin->setEnabled( b_enabled );
349
350             b_enabled = ( qs_filter.contains( "headphone" ) );
351             ui.headphoneEffect->setChecked( b_enabled );
352
353             /* Volume Label */
354             updateAudioVolume( ui.defaultVolume->value() ); // First time init
355
356         END_SPREFS_CAT;
357
358         /* Input and Codecs Panel Implementation */
359         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
360
361             /* Disk Devices */
362             {
363                 ui.DVDDevice->setToolTip(
364                     qtr( "If this property is blank, different values\n"
365                          "for DVD, VCD, and CDDA are set.\n"
366                          "You can define a unique one or configure them \n"
367                          "individually in the advanced preferences." ) );
368                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
369                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
370                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
371                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
372                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
373                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
374                 {
375                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
376                 }
377                 free( psz_cddadiscpath );
378                 free( psz_dvddiscpath );
379                 free( psz_vcddiscpath );
380             }
381
382             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
383                                     UDPPort );
384             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
385             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
386                                     PostProcLevel );
387             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
388             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
389 #ifdef WIN32
390             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
391 #else
392             ui.systemCodecBox->hide();
393 #endif
394             optionWidgets.append( ui.DVDDevice );
395             optionWidgets.append( ui.cachingCombo );
396
397             /* Caching */
398             /* Add the things to the ComboBox */
399             #define addToCachingBox( str, cachingNumber ) \
400                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
401             addToCachingBox( N_("Custom"), CachingCustom );
402             addToCachingBox( N_("Lowest latency"), CachingLowest );
403             addToCachingBox( N_("Low latency"), CachingLow );
404             addToCachingBox( N_("Normal"), CachingNormal );
405             addToCachingBox( N_("High latency"), CachingHigh );
406             addToCachingBox( N_("Higher latency"), CachingHigher );
407
408 #define TestCaC( name ) \
409     b_cache_equal =  b_cache_equal && \
410      ( i_cache == config_GetInt( p_intf, name ) )
411
412 #define TestCaCi( name, int ) \
413     b_cache_equal = b_cache_equal &&  \
414     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
415             /* Select the accurate value of the ComboBox */
416             bool b_cache_equal = true;
417             int i_cache = config_GetInt( p_intf, "file-caching");
418
419             TestCaC( "udp-caching" );
420             if (module_exists ("dvdread"))
421                 TestCaC( "dvdread-caching" );
422             if (module_exists ("dvdnav"))
423                 TestCaC( "dvdnav-caching" );
424             TestCaC( "tcp-caching" );
425             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
426             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
427             #ifdef WIN32
428             TestCaC( "dshow-caching" );
429             #else
430             if (module_exists ("v4l"))
431                 TestCaC( "v4l-caching" );
432             if (module_exists ("access_jack"))
433                 TestCaC( "jack-input-caching" );
434             if (module_exists ("v4l2"))
435                 TestCaC( "v4l2-caching" );
436             if (module_exists ("pvr"))
437                 TestCaC( "pvr-caching" );
438             #endif
439             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
440             TestCaCi( "http-caching", 4 );
441             if (module_exists ("access_realrtsp"))
442                 TestCaCi( "realrtsp-caching", 10 );
443             TestCaCi( "mms-caching", 19 );
444             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
445                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
446
447         END_SPREFS_CAT;
448         /*******************
449          * Interface Panel *
450          *******************/
451         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
452             ui.defaultLabel->setFont( italicFont );
453             ui.skinsLabel->setText(
454                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
455                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
456             ui.skinsLabel->setFont( italicFont );
457
458 #if defined( WIN32 )
459             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
460             BUTTONACT( ui.assoButton, assoDialog() );
461 #else
462             ui.language->hide();
463             ui.languageLabel->hide();
464             ui.assoName->hide();
465             ui.assoButton->hide();
466 #endif
467
468             /* interface */
469             char *psz_intf = config_GetPsz( p_intf, "intf" );
470             if( psz_intf )
471             {
472                 if( strstr( psz_intf, "skin" ) )
473                     ui.skins->setChecked( true );
474                 else if( strstr( psz_intf, "qt" ) )
475                     ui.qt4->setChecked( true );
476             }
477             free( psz_intf );
478
479             optionWidgets.append( ui.skins );
480             optionWidgets.append( ui.qt4 );
481
482             CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
483                             displayModeBox );
484             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
485             CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
486             CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
487             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
488                                  ui.fileSkin, ui.skinBrowse );
489             CONFIG_GENERIC( "qt-video-autoresize", Bool, NULL, resizingBox );
490
491             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
492                                                       artFetcher );
493
494             /* UPDATE options */
495 #ifdef UPDATE_CHECK
496             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
497             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
498                     updatesDays );
499             CONNECT( ui.updatesBox, toggled( bool ),
500                      ui.updatesDays, setEnabled( bool ) );
501 #else
502             ui.updatesBox->hide();
503             ui.updatesDays->hide();
504 #endif
505             /* ONE INSTANCE options */
506 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
507             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
508             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
509                     EnqueueOneInterfaceMode );
510 #else
511             ui.OneInterfaceBox->hide();
512 #endif
513             /* RECENTLY PLAYED options */
514             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
515                      ui.recentlyPlayedFilters, setEnabled( bool ) );
516             ui.recentlyPlayedFilters->setEnabled( false );
517             CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
518             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
519                     recentlyPlayedFilters );
520
521         END_SPREFS_CAT;
522
523         START_SPREFS_CAT( Subtitles,
524                             qtr("Subtitles & On Screen Display Settings") );
525             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
526             CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
527
528
529             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
530                             encoding );
531             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
532                             preferredLanguage );
533             CONFIG_GENERIC_FILE( "freetype-font", File, ui.fontLabel, ui.font,
534                             ui.fontBrowse );
535             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
536                             fontColor );
537             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
538                             ui.fontSizeLabel, fontSize );
539             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
540                             effect );
541             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
542
543         END_SPREFS_CAT;
544
545         case SPrefsHotkeys:
546         {
547             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
548
549             QGridLayout *gLayout = new QGridLayout;
550             panel->setLayout( gLayout );
551             int line = 0;
552
553             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
554                                                 this, gLayout, line );
555
556             panel_label->setText( qtr( "Configure Hotkeys" ) );
557             controls.append( control );
558
559             break;
560         }
561     }
562
563     panel_layout->addWidget( panel_label );
564     panel_layout->addWidget( title_line );
565
566     if( small )
567     {
568         QScrollArea *scroller= new QScrollArea;
569         scroller->setWidget( panel );
570         scroller->setWidgetResizable( true );
571         scroller->setFrameStyle( QFrame::NoFrame );
572         panel_layout->addWidget( scroller );
573     }
574     else
575     {
576         panel_layout->addWidget( panel );
577         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
578     }
579
580     setLayout( panel_layout );
581 }
582
583 void SPrefsPanel::updateAudioOptions( int number)
584 {
585     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
586                                             ->itemData( number ).toString();
587 #ifdef WIN32
588     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
589 #else
590     /* optionWidgets[ossW] can be NULL */
591     if( optionWidgets[ossW] )
592         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
593     /* optionWidgets[alsaW] can be NULL */
594     if( optionWidgets[alsaW] )
595         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
596 #endif
597     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
598 }
599
600
601 SPrefsPanel::~SPrefsPanel()
602 {
603     qDeleteAll( controls ); controls.clear();
604 }
605
606 void SPrefsPanel::updateAudioVolume( int volume )
607 {
608     qobject_cast<QSpinBox *>(optionWidgets[volLW])
609         ->setValue( volume * 100 / 256 );
610 }
611
612
613 /* Function called from the main Preferences dialog on each SPrefs Panel */
614 void SPrefsPanel::apply()
615 {
616     /* Generic save for ever panel */
617     QList<ConfigControl *>::Iterator i;
618     for( i = controls.begin() ; i != controls.end() ; i++ )
619     {
620         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
621         c->doApply( p_intf );
622     }
623
624     switch( number )
625     {
626     case SPrefsInputAndCodecs:
627     {
628         /* Device default selection */
629         const char *psz_devicepath =
630               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
631         if( !EMPTY_STR( psz_devicepath ) )
632         {
633             config_PutPsz( p_intf, "dvd", psz_devicepath );
634             config_PutPsz( p_intf, "vcd", psz_devicepath );
635             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
636         }
637
638 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
639 #define CaC( name ) CaCi( name, 1 )
640         /* Caching */
641         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
642         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
643         if( i_comboValue )
644         {
645             CaC( "udp-caching" );
646             if (module_exists ("dvdread" ))
647                 CaC( "dvdread-caching" );
648             if (module_exists ("dvdnav" ))
649                 CaC( "dvdnav-caching" );
650             CaC( "tcp-caching" ); CaC( "vcd-caching" );
651             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
652             CaC( "screen-caching" ); CaC( "bd-caching" );
653             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
654             CaCi( "http-caching", 2 );
655             if (module_exists ("access_realrtsp" ))
656                 CaCi( "realrtsp-caching", 10 );
657             CaCi( "mms-caching", 10 );
658             #ifdef WIN32
659             CaC( "dshow-caching" );
660             #else
661             if (module_exists ( "v4l" ))
662                 CaC( "v4l-caching" );
663             if (module_exists ( "access_jack" ))
664             CaC( "jack-input-caching" );
665             if (module_exists ( "v4l2" ))
666                 CaC( "v4l2-caching" );
667             if (module_exists ( "pvr" ))
668                 CaC( "pvr-caching" );
669             #endif
670             //CaCi( "dv-caching" ) too short...
671         }
672         break;
673     }
674
675     /* Interfaces */
676     case SPrefsInterface:
677     {
678         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
679             config_PutPsz( p_intf, "intf", "skins2" );
680         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
681             config_PutPsz( p_intf, "intf", "qt" );
682         break;
683     }
684
685     case SPrefsAudio:
686     {
687         bool b_checked =
688             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
689         if( b_checked && !qs_filter.contains( "volnorm" ) )
690             qs_filter.append( "volnorm" );
691         if( !b_checked && qs_filter.contains( "volnorm" ) )
692             qs_filter.removeAll( "volnorm" );
693
694         b_checked =
695             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
696
697         if( b_checked && !qs_filter.contains( "headphone" ) )
698             qs_filter.append( "headphone" );
699         if( !b_checked && qs_filter.contains( "headphone" ) )
700             qs_filter.removeAll( "headphone" );
701
702         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
703         break;
704     }
705     }
706 }
707
708 void SPrefsPanel::clean()
709 {}
710
711 void SPrefsPanel::lastfm_Changed( int i_state )
712 {
713     if( i_state == Qt::Checked )
714         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
715     else if( i_state == Qt::Unchecked )
716         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
717 }
718
719 #ifdef WIN32
720 #include <QDialogButtonBox>
721 #include <QHeaderView>
722 #include "util/registry.hpp"
723
724 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
725                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
726 {
727     bool b_temp;
728     const char* psz_VLC = "VLC";
729     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
730
731     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
732     {
733         current->setCheckState( 0, Qt::Checked );
734         b_temp = false;
735     }
736     else
737     {
738         current->setCheckState( 0, Qt::Unchecked );
739         b_temp = true;
740     }
741     listAsso.append( current );
742     return b_temp;
743 }
744
745 void SPrefsPanel::assoDialog()
746 {
747     QDialog *d = new QDialog( this );
748     QGridLayout *assoLayout = new QGridLayout( d );
749
750     QTreeWidget *filetypeList = new QTreeWidget;
751     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
752     filetypeList->header()->hide();
753
754     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
755
756     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
757     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
758     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
759
760     filetypeList->addTopLevelItem( audioType );
761     filetypeList->addTopLevelItem( videoType );
762     filetypeList->addTopLevelItem( otherType );
763
764     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
765     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
766     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
767
768     QTreeWidgetItem *currentItem;
769
770     int i_temp = 0;
771 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
772 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
773 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
774
775     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
776     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
777     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
778     aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
779     audioType->setCheckState( 0, ( i_temp > 0 ) ?
780                               ( ( i_temp == audioType->childCount() ) ?
781                                Qt::Checked : Qt::PartiallyChecked )
782                             : Qt::Unchecked );
783
784     i_temp = 0;
785     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
786     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
787     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
788     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
789     aTv( ".mts" ); aTv( ".mxf" );
790     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
791     aTv( ".vob" ); aTv( ".wmv" );
792     videoType->setCheckState( 0, ( i_temp > 0 ) ?
793                               ( ( i_temp == audioType->childCount() ) ?
794                                Qt::Checked : Qt::PartiallyChecked )
795                             : Qt::Unchecked );
796
797     i_temp = 0;
798     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
799     aTo( ".xspf" );
800     otherType->setCheckState( 0, ( i_temp > 0 ) ?
801                               ( ( i_temp == audioType->childCount() ) ?
802                                Qt::Checked : Qt::PartiallyChecked )
803                             : Qt::Unchecked );
804
805     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
806     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
807     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
808     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
809     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
810
811     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
812
813     CONNECT( closeButton, clicked(), this, saveAsso() );
814     CONNECT( clearButton, clicked(), d, reject() );
815     d->resize( 300, 400 );
816     d->exec();
817     delete d;
818     delete qvReg;
819     listAsso.clear();
820 }
821
822 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
823 {
824     std::string s_path( "VLC" ); s_path += psz_ext;
825     std::string s_path2 = s_path;
826
827     /* Save a backup if already assigned */
828     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
829
830     if( psz_value && strlen( psz_value ) > 0 )
831         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
832     delete psz_value;
833
834     /* Put a "link" to VLC.EXT as default */
835     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
836
837     /* Create the needed Key if they weren't done in the installer */
838     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
839     {
840         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
841         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
842         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
843
844         /* Get the installer path */
845         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
846         std::string str_temp; str_temp.assign(
847             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
848
849         if( str_temp.size() )
850         {
851             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
852                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
853
854             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
855                         "", str_temp.append(",0").c_str() );
856         }
857         delete qvReg2;
858     }
859 }
860
861 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
862 {
863     char psz_VLC[] = "VLC";
864     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
865
866     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
867     {
868         free( psz_value );
869         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
870         if( psz_value )
871             qvReg->WriteRegistryString( psz_ext, "", psz_value );
872
873         qvReg->DeleteKey( psz_ext, "VLC.backup" );
874     }
875     delete( psz_value );
876 }
877 void SPrefsPanel::saveAsso()
878 {
879     QVLCRegistry * qvReg;
880     for( int i = 0; i < listAsso.size(); i ++ )
881     {
882         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
883         if( listAsso[i]->checkState( 0 ) > 0 )
884         {
885             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
886         }
887         else
888         {
889             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
890         }
891     }
892     /* Gruik ? Naaah */
893     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
894     delete qvReg;
895 }
896
897 #endif /* WIN32 */
898