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