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