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