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