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