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