]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt: simple preferences, User Experience improvements.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32
33 #include <vlc_config_cat.h>
34 #include <vlc_configuration.h>
35
36 #include <QString>
37 #include <QFont>
38 #include <QToolButton>
39 #include <QButtonGroup>
40 #include <QVBoxLayout>
41
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                     controls.append( control );                               \
144                 }
145
146 #define START_SPREFS_CAT( name , label )    \
147         case SPrefs ## name:                \
148         {                                   \
149             Ui::SPrefs ## name ui;      \
150             ui.setupUi( panel );            \
151             panel_label->setText( label );
152
153 #define END_SPREFS_CAT      \
154             break;          \
155         }
156
157     QVBoxLayout *panel_layout = new QVBoxLayout();
158     QWidget *panel = new QWidget();
159     panel_layout->setMargin( 3 );
160
161     // Title Label
162     QLabel *panel_label = new QLabel;
163     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
164     labelFont.setPointSize( labelFont.pointSize() + 6 );
165     labelFont.setFamily( "Verdana" );
166     panel_label->setFont( labelFont );
167
168     // Title <hr>
169     QFrame *title_line = new QFrame;
170     title_line->setFrameShape(QFrame::HLine);
171     title_line->setFrameShadow(QFrame::Sunken);
172
173     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
174     italicFont.setItalic( true );
175
176     switch( number )
177     {
178         /******************************
179          * VIDEO Panel Implementation *
180          ******************************/
181         START_SPREFS_CAT( Video , qtr("General Video Settings") );
182             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
183
184             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
185             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
186             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
187             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
188             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
189             CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
190
191 #ifdef WIN32
192             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
193             CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
194                             dXdisplayDevice );
195             CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
196 #else
197             ui.directXBox->setVisible( false );
198             ui.hwYUVBox->setVisible( false );
199 #endif
200
201             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterLabel, deinterlaceBox );
202             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
203
204             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
205                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
206             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
207             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
208                             snapshotsSequentialNumbering );
209             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
210                             snapshotsFormat );
211          END_SPREFS_CAT;
212
213         /******************************
214          * AUDIO Panel Implementation *
215          ******************************/
216         START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
217
218             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
219
220 #define audioCommon( name ) \
221             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
222             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
223             name ## Layout->setMargin( 0 ); \
224             name ## Layout->setSpacing( 0 ); \
225             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
226             name ## Label->setMinimumSize(QSize(100, 0)); \
227             name ## Layout->addWidget( name ## Label ); \
228
229 #define audioControl( name) \
230             audioCommon( name ) \
231             QComboBox * name ## Device = new QComboBox( name ## Control ); \
232             name ## Layout->addWidget( name ## Device ); \
233             name ## Label->setBuddy( name ## Device ); \
234             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
235
236 #define audioControl2( name) \
237             audioCommon( name ) \
238             QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
239             name ## Layout->addWidget( name ## Device ); \
240             name ## Label->setBuddy( name ## Device ); \
241             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
242             name ## Layout->addWidget( name ## Browse ); \
243             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
244
245             /* hide if necessary */
246             ui.lastfm_user_edit->hide();
247             ui.lastfm_user_label->hide();
248             ui.lastfm_pass_edit->hide();
249             ui.lastfm_pass_label->hide();
250
251             /* Build if necessary */
252             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
253 #ifdef WIN32
254             audioControl( DirectX );
255             optionWidgets.append( DirectXControl );
256             CONFIG_GENERIC2( "directx-audio-device", IntegerList,
257                     ui.DirectXLabel, DirectXDevice );
258 #else
259             if( module_exists( "alsa" ) )
260             {
261                 audioControl( alsa );
262                 optionWidgets.append( alsaControl );
263
264                 CONFIG_GENERIC2( "alsa-audio-device" , StringList, NULL,
265                                 alsaDevice );
266             }
267             else
268                 optionWidgets.append( NULL );
269             if( module_exists( "oss" ) )
270             {
271                 audioControl2( OSS );
272                 optionWidgets.append( OSSControl );
273                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
274                                  OSSBrowse );
275             }
276             else
277                 optionWidgets.append( NULL );
278 #endif
279
280             /* General Audio Options */
281             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
282                                      defaultVolume );
283             CONNECT( ui.defaultVolume, valueChanged( int ),
284                     this, updateAudioVolume( int ) );
285
286             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
287                             preferredAudioLanguage );
288
289             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
290             CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
291             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
292                             detectionDolby );
293
294             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
295                                     volNormSpin );
296             CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
297                             visualisation);
298
299             /* Audio Output Specifics */
300             CONFIG_GENERIC( "aout", Module, ui.outputLabel, 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 ),
331                          this, 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, ui.portLabel,
381                                     UDPPort );
382             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
383             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
384                                     PostProcLevel );
385             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
386             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
387 #ifdef WIN32
388             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
389 #else
390             ui.systemCodecBox->hide();
391 #endif
392             optionWidgets.append( ui.DVDDevice );
393             optionWidgets.append( ui.cachingCombo );
394
395             /* Caching */
396             /* Add the things to the ComboBox */
397             #define addToCachingBox( str, cachingNumber ) \
398                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
399             addToCachingBox( N_("Custom"), CachingCustom );
400             addToCachingBox( N_("Lowest latency"), CachingLowest );
401             addToCachingBox( N_("Low latency"), CachingLow );
402             addToCachingBox( N_("Normal"), CachingNormal );
403             addToCachingBox( N_("High latency"), CachingHigh );
404             addToCachingBox( N_("Higher latency"), CachingHigher );
405
406 #define TestCaC( name ) \
407     b_cache_equal =  b_cache_equal && \
408      ( i_cache == config_GetInt( p_intf, name ) )
409
410 #define TestCaCi( name, int ) \
411     b_cache_equal = b_cache_equal &&  \
412     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
413             /* Select the accurate value of the ComboBox */
414             bool b_cache_equal = true;
415             int i_cache = config_GetInt( p_intf, "file-caching");
416
417             TestCaC( "udp-caching" );
418             if (module_exists ("dvdread"))
419                 TestCaC( "dvdread-caching" );
420             if (module_exists ("dvdnav"))
421                 TestCaC( "dvdnav-caching" );
422             TestCaC( "tcp-caching" );
423             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
424             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
425             #ifdef WIN32
426             TestCaC( "dshow-caching" );
427             #else
428             if (module_exists ("v4l"))
429                 TestCaC( "v4l-caching" );
430             if (module_exists ("access_jack"))
431                 TestCaC( "jack-input-caching" );
432             if (module_exists ("v4l2"))
433                 TestCaC( "v4l2-caching" );
434             if (module_exists ("pvr"))
435                 TestCaC( "pvr-caching" );
436             #endif
437             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
438             TestCaCi( "http-caching", 4 );
439             if (module_exists ("access_realrtsp"))
440                 TestCaCi( "realrtsp-caching", 10 );
441             TestCaCi( "mms-caching", 19 );
442             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
443                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
444
445         END_SPREFS_CAT;
446         /*******************
447          * Interface Panel *
448          *******************/
449         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
450             ui.defaultLabel->setFont( italicFont );
451             ui.skinsLabel->setFont( italicFont );
452
453 #if defined( WIN32 )
454             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
455             BUTTONACT( ui.assoButton, assoDialog() );
456 #else
457             ui.language->hide();
458             ui.languageLabel->hide();
459             ui.assoName->hide();
460             ui.assoButton->hide();
461 #endif
462
463             /* interface */
464             char *psz_intf = config_GetPsz( p_intf, "intf" );
465             if( psz_intf )
466             {
467                 if( strstr( psz_intf, "skin" ) )
468                     ui.skins->setChecked( true );
469                 else if( strstr( psz_intf, "qt" ) )
470                     ui.qt4->setChecked( true );
471             }
472             free( psz_intf );
473
474             optionWidgets.append( ui.skins );
475             optionWidgets.append( ui.qt4 );
476
477             CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
478                             displayModeBox );
479             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
480             CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
481             CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
482             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
483                                  ui.fileSkin, ui.skinBrowse );
484
485             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
486                                                       artFetcher );
487
488             /* UPDATE options */
489 #ifdef UPDATE_CHECK
490             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
491             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
492                     updatesDays );
493             CONNECT( ui.updatesBox, toggled( bool ),
494                      ui.updatesDays, setEnabled( bool ) );
495 #else
496             ui.updatesBox->hide();
497             ui.updatesDays->hide();
498 #endif
499             /* ONE INSTANCE options */
500 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
501             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
502             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
503                     EnqueueOneInterfaceMode );
504 #else
505             ui.OneInterfaceBox->hide();
506 #endif
507             /* RECENTLY PLAYED options */
508             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
509                      ui.recentlyPlayedFilters, setEnabled( bool ) );
510             ui.recentlyPlayedFilters->setEnabled( false );
511             CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
512             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
513                     recentlyPlayedFilters );
514
515         END_SPREFS_CAT;
516
517         START_SPREFS_CAT( Subtitles,
518                             qtr("Subtitles & On Screen Display Settings") );
519             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
520             CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
521
522
523             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
524                             encoding );
525             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
526                             preferredLanguage );
527             CONFIG_GENERIC_FILE( "freetype-font", File, ui.fontLabel, ui.font,
528                             ui.fontBrowse );
529             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
530                             fontColor );
531             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
532                             ui.fontSizeLabel, fontSize );
533             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
534                             effect );
535             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
536
537         END_SPREFS_CAT;
538
539         case SPrefsHotkeys:
540         {
541             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
542
543             QGridLayout *gLayout = new QGridLayout;
544             panel->setLayout( gLayout );
545             int line = 0;
546
547             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
548                                                 this, gLayout, line );
549
550             panel_label->setText( qtr( "Configure Hotkeys" ) );
551             controls.append( control );
552
553             break;
554         }
555     }
556
557     panel_layout->addWidget( panel_label );
558     panel_layout->addWidget( title_line );
559     panel_layout->addWidget( panel );
560     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
561
562     setLayout( panel_layout );
563 }
564
565 void SPrefsPanel::updateAudioOptions( int number)
566 {
567     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
568                                             ->itemData( number ).toString();
569 #ifdef WIN32
570     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
571 #else
572     /* optionWidgets[ossW] can be NULL */
573     if( optionWidgets[ossW] )
574         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
575     /* optionWidgets[alsaW] can be NULL */
576     if( optionWidgets[alsaW] )
577         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
578 #endif
579     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
580 }
581
582
583 SPrefsPanel::~SPrefsPanel()
584 {
585     qDeleteAll( controls ); controls.clear();
586 }
587
588 void SPrefsPanel::updateAudioVolume( int volume )
589 {
590     qobject_cast<QSpinBox *>(optionWidgets[volLW])
591         ->setValue( volume * 100 / 256 );
592 }
593
594
595 /* Function called from the main Preferences dialog on each SPrefs Panel */
596 void SPrefsPanel::apply()
597 {
598     /* Generic save for ever panel */
599     QList<ConfigControl *>::Iterator i;
600     for( i = controls.begin() ; i != controls.end() ; i++ )
601     {
602         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
603         c->doApply( p_intf );
604     }
605
606     switch( number )
607     {
608     case SPrefsInputAndCodecs:
609     {
610         /* Device default selection */
611         const char *psz_devicepath =
612               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
613         if( !EMPTY_STR( psz_devicepath ) )
614         {
615             config_PutPsz( p_intf, "dvd", psz_devicepath );
616             config_PutPsz( p_intf, "vcd", psz_devicepath );
617             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
618         }
619
620 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
621 #define CaC( name ) CaCi( name, 1 )
622         /* Caching */
623         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
624         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
625         if( i_comboValue )
626         {
627             CaC( "udp-caching" );
628             if (module_exists ("dvdread" ))
629                 CaC( "dvdread-caching" );
630             if (module_exists ("dvdnav" ))
631                 CaC( "dvdnav-caching" );
632             CaC( "tcp-caching" ); CaC( "vcd-caching" );
633             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
634             CaC( "screen-caching" );
635             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
636             CaCi( "http-caching", 2 );
637             if (module_exists ("access_realrtsp" ))
638                 CaCi( "realrtsp-caching", 10 );
639             CaCi( "mms-caching", 10 );
640             #ifdef WIN32
641             CaC( "dshow-caching" );
642             #else
643             if (module_exists ( "v4l" ))
644                 CaC( "v4l-caching" );
645             if (module_exists ( "access_jack" ))
646             CaC( "jack-input-caching" );
647             if (module_exists ( "v4l2" ))
648                 CaC( "v4l2-caching" );
649             if (module_exists ( "pvr" ))
650                 CaC( "pvr-caching" );
651             #endif
652             //CaCi( "dv-caching" ) too short...
653         }
654         break;
655     }
656
657     /* Interfaces */
658     case SPrefsInterface:
659     {
660         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
661             config_PutPsz( p_intf, "intf", "skins2" );
662         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
663             config_PutPsz( p_intf, "intf", "qt" );
664         break;
665     }
666
667     case SPrefsAudio:
668     {
669         bool b_checked =
670             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
671         if( b_checked && !qs_filter.contains( "volnorm" ) )
672             qs_filter.append( "volnorm" );
673         if( !b_checked && qs_filter.contains( "volnorm" ) )
674             qs_filter.removeAll( "volnorm" );
675
676         b_checked =
677             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
678
679         if( b_checked && !qs_filter.contains( "headphone" ) )
680             qs_filter.append( "headphone" );
681         if( !b_checked && qs_filter.contains( "headphone" ) )
682             qs_filter.removeAll( "headphone" );
683
684         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
685         break;
686     }
687     }
688 }
689
690 void SPrefsPanel::clean()
691 {}
692
693 void SPrefsPanel::lastfm_Changed( int i_state )
694 {
695     if( i_state == Qt::Checked )
696         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
697     else if( i_state == Qt::Unchecked )
698         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
699 }
700
701 #ifdef WIN32
702 #include <QDialogButtonBox>
703 #include <QHeaderView>
704 #include "util/registry.hpp"
705
706 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
707                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
708 {
709     bool b_temp;
710     const char* psz_VLC = "VLC";
711     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
712
713     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
714     {
715         current->setCheckState( 0, Qt::Checked );
716         b_temp = false;
717     }
718     else
719     {
720         current->setCheckState( 0, Qt::Unchecked );
721         b_temp = true;
722     }
723     listAsso.append( current );
724     return b_temp;
725 }
726
727 void SPrefsPanel::assoDialog()
728 {
729     QDialog *d = new QDialog( this );
730     QGridLayout *assoLayout = new QGridLayout( d );
731
732     QTreeWidget *filetypeList = new QTreeWidget;
733     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
734     filetypeList->header()->hide();
735
736     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
737
738     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
739     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
740     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
741
742     filetypeList->addTopLevelItem( audioType );
743     filetypeList->addTopLevelItem( videoType );
744     filetypeList->addTopLevelItem( otherType );
745
746     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
747     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
748     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
749
750     QTreeWidgetItem *currentItem;
751
752     int i_temp = 0;
753 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
754 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
755 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
756
757     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
758     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
759     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
760     aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
761     audioType->setCheckState( 0, ( i_temp > 0 ) ?
762                               ( ( i_temp == audioType->childCount() ) ?
763                                Qt::Checked : Qt::PartiallyChecked )
764                             : Qt::Unchecked );
765
766     i_temp = 0;
767     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
768     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
769     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
770     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
771     aTv( ".mts" ); aTv( ".mxf" );
772     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
773     aTv( ".vob" ); aTv( ".wmv" );
774     videoType->setCheckState( 0, ( i_temp > 0 ) ?
775                               ( ( i_temp == audioType->childCount() ) ?
776                                Qt::Checked : Qt::PartiallyChecked )
777                             : Qt::Unchecked );
778
779     i_temp = 0;
780     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
781     aTo( ".xspf" );
782     otherType->setCheckState( 0, ( i_temp > 0 ) ?
783                               ( ( i_temp == audioType->childCount() ) ?
784                                Qt::Checked : Qt::PartiallyChecked )
785                             : Qt::Unchecked );
786
787     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
788     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
789     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
790     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
791     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
792
793     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
794
795     CONNECT( closeButton, clicked(), this, saveAsso() );
796     CONNECT( clearButton, clicked(), d, reject() );
797     d->resize( 300, 400 );
798     d->exec();
799     delete d;
800     delete qvReg;
801     listAsso.clear();
802 }
803
804 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
805 {
806     std::string s_path( "VLC" ); s_path += psz_ext;
807     std::string s_path2 = s_path;
808
809     /* Save a backup if already assigned */
810     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
811
812     if( psz_value && strlen( psz_value ) > 0 )
813         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
814     delete psz_value;
815
816     /* Put a "link" to VLC.EXT as default */
817     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
818
819     /* Create the needed Key if they weren't done in the installer */
820     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
821     {
822         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
823         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
824         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
825
826         /* Get the installer path */
827         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
828         std::string str_temp; str_temp.assign(
829             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
830
831         if( str_temp.size() )
832         {
833             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
834                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
835
836             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
837                         "", str_temp.append(",0").c_str() );
838         }
839         delete qvReg2;
840     }
841 }
842
843 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
844 {
845     char psz_VLC[] = "VLC";
846     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
847
848     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
849     {
850         free( psz_value );
851         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
852         if( psz_value )
853             qvReg->WriteRegistryString( psz_ext, "", psz_value );
854
855         qvReg->DeleteKey( psz_ext, "VLC.backup" );
856     }
857     delete( psz_value );
858 }
859 void SPrefsPanel::saveAsso()
860 {
861     QVLCRegistry * qvReg;
862     for( int i = 0; i < listAsso.size(); i ++ )
863     {
864         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
865         if( listAsso[i]->checkState( 0 ) > 0 )
866         {
867             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
868         }
869         else
870         {
871             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
872         }
873     }
874     /* Gruik ? Naaah */
875     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
876     delete qvReg;
877 }
878
879 #endif /* WIN32 */
880