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