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