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