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