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