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