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