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