]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
UI: prefix/namespace resources for better maintainability
[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
227 #define audioCommon( name ) \
228             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
229             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
230             name ## Layout->setMargin( 0 ); \
231             name ## Layout->setSpacing( 0 ); \
232             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
233             name ## Label->setMinimumSize(QSize(100, 0)); \
234             name ## Layout->addWidget( name ## Label ); \
235
236 #define audioControl( name) \
237             audioCommon( name ) \
238             QComboBox * name ## Device = new QComboBox( name ## Control ); \
239             name ## Layout->addWidget( name ## Device ); \
240             name ## Label->setBuddy( name ## Device ); \
241             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
242
243 #define audioControl2( name) \
244             audioCommon( name ) \
245             QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
246             name ## Layout->addWidget( name ## Device ); \
247             name ## Label->setBuddy( name ## Device ); \
248             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
249             name ## Layout->addWidget( name ## Browse ); \
250             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
251
252             /* hide if necessary */
253             ui.lastfm_user_edit->hide();
254             ui.lastfm_user_label->hide();
255             ui.lastfm_pass_edit->hide();
256             ui.lastfm_pass_label->hide();
257
258             /* Build if necessary */
259             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
260 #ifdef WIN32
261             audioControl( DirectX );
262             optionWidgets.append( DirectXControl );
263             CONFIG_GENERIC2( "directx-audio-device", IntegerList,
264                     NULL, DirectXDevice );
265 #else
266             if( module_exists( "alsa" ) )
267             {
268                 audioControl( alsa );
269                 optionWidgets.append( alsaControl );
270
271                 CONFIG_GENERIC2( "alsa-audio-device" , StringList, NULL,
272                                 alsaDevice );
273             }
274             else
275                 optionWidgets.append( NULL );
276             if( module_exists( "oss" ) )
277             {
278                 audioControl2( OSS );
279                 optionWidgets.append( OSSControl );
280                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
281                                  OSSBrowse );
282             }
283             else
284                 optionWidgets.append( NULL );
285 #endif
286
287 #undef audioControl2
288 #undef audioControl
289 #undef audioCommon
290
291             /* Audio Options */
292             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
293                                      defaultVolume );
294             CONNECT( ui.defaultVolume, valueChanged( int ),
295                     this, updateAudioVolume( int ) );
296
297             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
298                             preferredAudioLanguage );
299
300             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
301             CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
302             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
303                             detectionDolby );
304
305             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
306                                     volNormSpin );
307             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
308                             replayCombo );
309             CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
310                             visualisation);
311
312             /* Audio Output Specifics */
313             CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
314
315             CONNECT( ui.outputModule, currentIndexChanged( int ),
316                      this, updateAudioOptions( int ) );
317
318             /* File output exists on all platforms */
319             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
320                                  ui.fileName, ui.fileBrowseButton );
321
322             optionWidgets.append( ui.fileControl );
323             optionWidgets.append( ui.outputModule );
324             optionWidgets.append( ui.volNormBox );
325             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
326             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
327             optionWidgets.append( ui.volumeValue );
328             optionWidgets.append( ui.headphoneEffect );
329             updateAudioOptions( ui.outputModule->currentIndex() );
330
331             /* LastFM */
332             if( module_exists( "audioscrobbler" ) )
333             {
334                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
335                         lastfm_user_edit );
336                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
337                         lastfm_pass_edit );
338
339                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
340                     ui.lastfm->setChecked( true );
341                 else
342                     ui.lastfm->setChecked( false );
343                 CONNECT( ui.lastfm, stateChanged( int ),
344                          this, lastfm_Changed( int ) );
345             }
346             else
347                 ui.lastfm->hide();
348
349             /* Normalizer */
350             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
351                      setEnabled( bool ) );
352
353             char* psz = config_GetPsz( p_intf, "audio-filter" );
354             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
355             free( psz );
356
357             bool b_enabled = ( qs_filter.contains( "volnorm" ) );
358             ui.volNormBox->setChecked( b_enabled );
359             ui.volNormSpin->setEnabled( b_enabled );
360
361             b_enabled = ( qs_filter.contains( "headphone" ) );
362             ui.headphoneEffect->setChecked( b_enabled );
363
364             /* Volume Label */
365             updateAudioVolume( ui.defaultVolume->value() ); // First time init
366
367         END_SPREFS_CAT;
368
369         /* Input and Codecs Panel Implementation */
370         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
371
372             /* Disk Devices */
373             {
374                 ui.DVDDevice->setToolTip(
375                     qtr( "If this property is blank, different values\n"
376                          "for DVD, VCD, and CDDA are set.\n"
377                          "You can define a unique one or configure them \n"
378                          "individually in the advanced preferences." ) );
379                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
380                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
381                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
382                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
383                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
384                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
385                 {
386                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
387                 }
388                 free( psz_cddadiscpath );
389                 free( psz_dvddiscpath );
390                 free( psz_vcddiscpath );
391             }
392             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
393                                  ui.recordPath, ui.recordBrowse );
394
395             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
396                                     UDPPort );
397             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
398             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
399                                     PostProcLevel );
400             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
401             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
402 #ifdef WIN32
403             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
404 #else
405             ui.systemCodecBox->hide();
406 #endif
407             optionWidgets.append( ui.DVDDevice );
408             optionWidgets.append( ui.cachingCombo );
409             CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
410
411             /* Caching */
412             /* Add the things to the ComboBox */
413             #define addToCachingBox( str, cachingNumber ) \
414                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
415             addToCachingBox( N_("Custom"), CachingCustom );
416             addToCachingBox( N_("Lowest latency"), CachingLowest );
417             addToCachingBox( N_("Low latency"), CachingLow );
418             addToCachingBox( N_("Normal"), CachingNormal );
419             addToCachingBox( N_("High latency"), CachingHigh );
420             addToCachingBox( N_("Higher latency"), CachingHigher );
421             #undef addToCachingBox
422
423 #define TestCaC( name ) \
424     b_cache_equal =  b_cache_equal && \
425      ( i_cache == config_GetInt( p_intf, name ) )
426
427 #define TestCaCi( name, int ) \
428     b_cache_equal = b_cache_equal &&  \
429     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
430             /* Select the accurate value of the ComboBox */
431             bool b_cache_equal = true;
432             int i_cache = config_GetInt( p_intf, "file-caching");
433
434             TestCaC( "udp-caching" );
435             if (module_exists ("dvdread"))
436                 TestCaC( "dvdread-caching" );
437             if (module_exists ("dvdnav"))
438                 TestCaC( "dvdnav-caching" );
439             TestCaC( "tcp-caching" );
440             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
441             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
442             #ifdef WIN32
443             TestCaC( "dshow-caching" );
444             #else
445             if (module_exists ("v4l"))
446                 TestCaC( "v4l-caching" );
447             if (module_exists ("access_jack"))
448                 TestCaC( "jack-input-caching" );
449             if (module_exists ("v4l2"))
450                 TestCaC( "v4l2-caching" );
451             if (module_exists ("pvr"))
452                 TestCaC( "pvr-caching" );
453             #endif
454             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
455             TestCaCi( "http-caching", 4 );
456             if (module_exists ("access_realrtsp"))
457                 TestCaCi( "realrtsp-caching", 10 );
458             TestCaCi( "mms-caching", 19 );
459             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
460                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
461 #undef TestCaCi
462 #undef TestCaC
463
464         END_SPREFS_CAT;
465         /*******************
466          * Interface Panel *
467          *******************/
468         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
469             ui.defaultLabel->setFont( italicFont );
470             ui.skinsLabel->setText(
471                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
472                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
473             ui.skinsLabel->setFont( italicFont );
474
475 #if defined( WIN32 )
476             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
477             BUTTONACT( ui.assoButton, assoDialog() );
478 #else
479             ui.languageBox->hide();
480             ui.assoBox->hide();
481 #endif
482
483             /* interface */
484             char *psz_intf = config_GetPsz( p_intf, "intf" );
485             if( psz_intf )
486             {
487                 if( strstr( psz_intf, "skin" ) )
488                     ui.skins->setChecked( true );
489             } else {
490                 /* defaults to qt */
491                 ui.qt4->setChecked( true );
492             }
493             free( psz_intf );
494
495             optionWidgets.append( ui.skins );
496             optionWidgets.append( ui.qt4 );
497
498             ui.skins_zone->setEnabled( ui.skins->isChecked() );
499             CONNECT( ui.skins, toggled( bool ), ui.skins_zone, setEnabled( bool ) );
500
501             ui.native_zone->setEnabled( ui.qt4->isChecked() );
502             CONNECT( ui.qt4, toggled( bool ), ui.native_zone, setEnabled( bool ) );
503
504             InterfacePreviewWidget *preview = new InterfacePreviewWidget( this );
505             ( (QGridLayout *) ui.LooknfeelBox->layout() )->
506                     addWidget( preview, 1, 0, 1, 2 );
507             CONNECT( ui.displayModeBox, currentIndexChanged( int ),
508                      preview, setPreview( int ) );
509             
510             CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
511                             displayModeBox );
512             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
513             CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
514             CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
515             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
516                                  ui.fileSkin, ui.skinBrowse );
517             CONFIG_GENERIC( "qt-video-autoresize", Bool, NULL, resizingBox );
518
519             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
520                                                       artFetcher );
521
522             /* UPDATE options */
523 #ifdef UPDATE_CHECK
524             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
525             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
526                     updatesDays );
527             ui.updatenotifier_zone->setEnabled( ui.updatesBox->isChecked() );
528             CONNECT( ui.updatesBox, toggled( bool ),
529                      ui.updatenotifier_zone, setEnabled( bool ) );
530 #else
531             ui.updatesBox->hide();
532             ui.updatenotifier_zone->hide();
533 #endif
534             /* ONE INSTANCE options */
535 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
536             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
537             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
538                     EnqueueOneInterfaceMode );
539             ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
540             CONNECT( ui.OneInterfaceMode, toggled( bool ),
541                      ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
542 #else
543             ui.OneInterfaceBox->hide();
544 #endif
545             /* RECENTLY PLAYED options */
546             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
547                      ui.recentlyPlayedFilters, setEnabled( bool ) );
548             ui.recentlyPlayedFilters->setEnabled( false );
549             CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
550             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
551                     recentlyPlayedFilters );
552
553         END_SPREFS_CAT;
554
555         START_SPREFS_CAT( Subtitles,
556                             qtr("Subtitles & On Screen Display Settings") );
557             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
558             CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
559
560
561             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
562                             encoding );
563             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
564                             preferredLanguage );
565             CONFIG_GENERIC_FILE( "freetype-font", File, ui.fontLabel, ui.font,
566                             ui.fontBrowse );
567             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
568                             fontColor );
569             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
570                             ui.fontSizeLabel, fontSize );
571             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
572                             effect );
573             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
574
575         END_SPREFS_CAT;
576
577         case SPrefsHotkeys:
578         {
579             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
580
581             QGridLayout *gLayout = new QGridLayout;
582             panel->setLayout( gLayout );
583             int line = 0;
584
585             panel_label->setText( qtr( "Configure Hotkeys" ) );
586             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
587                                                 this, gLayout, line );
588             controls.append( control );
589
590             line++;
591
592             QFrame *sepline = new QFrame;
593             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
594             gLayout->addWidget( sepline, line, 0, 1, -1 );
595
596             line++;
597
598             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
599             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
600                     p_config, false, this, gLayout, line );
601             controls.append( control );
602
603             break;
604         }
605     }
606
607     panel_layout->addWidget( panel_label );
608     panel_layout->addWidget( title_line );
609
610     if( small )
611     {
612         QScrollArea *scroller= new QScrollArea;
613         scroller->setWidget( panel );
614         scroller->setWidgetResizable( true );
615         scroller->setFrameStyle( QFrame::NoFrame );
616         panel_layout->addWidget( scroller );
617     }
618     else
619     {
620         panel_layout->addWidget( panel );
621         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
622     }
623
624     setLayout( panel_layout );
625
626 #undef END_SPREFS_CAT
627 #undef START_SPREFS_CAT
628 #undef CONFIG_GENERIC_FILE
629 #undef CONFIG_GENERIC_NO_BOOL
630 #undef CONFIG_GENERIC2
631 #undef CONFIG_GENERIC
632 }
633
634
635 void SPrefsPanel::updateAudioOptions( int number)
636 {
637     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
638                                             ->itemData( number ).toString();
639 #ifdef WIN32
640     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
641 #else
642     /* optionWidgets[ossW] can be NULL */
643     if( optionWidgets[ossW] )
644         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
645     /* optionWidgets[alsaW] can be NULL */
646     if( optionWidgets[alsaW] )
647         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
648 #endif
649     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
650 }
651
652
653 SPrefsPanel::~SPrefsPanel()
654 {
655     qDeleteAll( controls ); controls.clear();
656 }
657
658 void SPrefsPanel::updateAudioVolume( int volume )
659 {
660     qobject_cast<QSpinBox *>(optionWidgets[volLW])
661         ->setValue( volume * 100 / 256 );
662 }
663
664
665 /* Function called from the main Preferences dialog on each SPrefs Panel */
666 void SPrefsPanel::apply()
667 {
668     /* Generic save for ever panel */
669     QList<ConfigControl *>::Iterator i;
670     for( i = controls.begin() ; i != controls.end() ; i++ )
671     {
672         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
673         c->doApply( p_intf );
674     }
675
676     switch( number )
677     {
678     case SPrefsInputAndCodecs:
679     {
680         /* Device default selection */
681         const char *psz_devicepath =
682               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
683         if( !EMPTY_STR( psz_devicepath ) )
684         {
685             config_PutPsz( p_intf, "dvd", psz_devicepath );
686             config_PutPsz( p_intf, "vcd", psz_devicepath );
687             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
688         }
689
690 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
691 #define CaC( name ) CaCi( name, 1 )
692         /* Caching */
693         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
694         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
695         if( i_comboValue )
696         {
697             CaC( "udp-caching" );
698             if (module_exists ("dvdread" ))
699                 CaC( "dvdread-caching" );
700             if (module_exists ("dvdnav" ))
701                 CaC( "dvdnav-caching" );
702             CaC( "tcp-caching" ); CaC( "vcd-caching" );
703             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
704             CaC( "screen-caching" ); CaC( "bd-caching" );
705             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
706             CaCi( "http-caching", 2 );
707             if (module_exists ("access_realrtsp" ))
708                 CaCi( "realrtsp-caching", 10 );
709             CaCi( "mms-caching", 10 );
710             #ifdef WIN32
711             CaC( "dshow-caching" );
712             #else
713             if (module_exists ( "v4l" ))
714                 CaC( "v4l-caching" );
715             if (module_exists ( "access_jack" ))
716             CaC( "jack-input-caching" );
717             if (module_exists ( "v4l2" ))
718                 CaC( "v4l2-caching" );
719             if (module_exists ( "pvr" ))
720                 CaC( "pvr-caching" );
721             #endif
722             //CaCi( "dv-caching" ) too short...
723         }
724         break;
725 #undef CaC
726 #undef CaCi
727     }
728
729     /* Interfaces */
730     case SPrefsInterface:
731     {
732         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
733             config_PutPsz( p_intf, "intf", "skins2" );
734         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
735             config_PutPsz( p_intf, "intf", "qt" );
736         break;
737     }
738
739     case SPrefsAudio:
740     {
741         bool b_checked =
742             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
743         if( b_checked && !qs_filter.contains( "volnorm" ) )
744             qs_filter.append( "volnorm" );
745         if( !b_checked && qs_filter.contains( "volnorm" ) )
746             qs_filter.removeAll( "volnorm" );
747
748         b_checked =
749             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
750
751         if( b_checked && !qs_filter.contains( "headphone" ) )
752             qs_filter.append( "headphone" );
753         if( !b_checked && qs_filter.contains( "headphone" ) )
754             qs_filter.removeAll( "headphone" );
755
756         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
757         break;
758     }
759     }
760 }
761
762 void SPrefsPanel::clean()
763 {}
764
765 void SPrefsPanel::lastfm_Changed( int i_state )
766 {
767     if( i_state == Qt::Checked )
768         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
769     else if( i_state == Qt::Unchecked )
770         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
771 }
772
773 #ifdef WIN32
774 #include <QDialogButtonBox>
775 #include <QHeaderView>
776 #include "util/registry.hpp"
777
778 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
779                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
780 {
781     bool b_temp;
782     const char* psz_VLC = "VLC";
783     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
784
785     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
786     {
787         current->setCheckState( 0, Qt::Checked );
788         b_temp = false;
789     }
790     else
791     {
792         current->setCheckState( 0, Qt::Unchecked );
793         b_temp = true;
794     }
795     listAsso.append( current );
796     return b_temp;
797 }
798
799 void SPrefsPanel::assoDialog()
800 {
801     QDialog *d = new QDialog( this );
802     QGridLayout *assoLayout = new QGridLayout( d );
803
804     QTreeWidget *filetypeList = new QTreeWidget;
805     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
806     filetypeList->header()->hide();
807
808     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
809
810     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
811     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
812     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
813
814     filetypeList->addTopLevelItem( audioType );
815     filetypeList->addTopLevelItem( videoType );
816     filetypeList->addTopLevelItem( otherType );
817
818     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
819     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
820     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
821
822     QTreeWidgetItem *currentItem;
823
824     int i_temp = 0;
825 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
826 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
827 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
828
829     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
830     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
831     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
832     aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
833     audioType->setCheckState( 0, ( i_temp > 0 ) ?
834                               ( ( i_temp == audioType->childCount() ) ?
835                                Qt::Checked : Qt::PartiallyChecked )
836                             : Qt::Unchecked );
837
838     i_temp = 0;
839     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
840     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
841     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
842     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
843     aTv( ".mts" ); aTv( ".mxf" );
844     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
845     aTv( ".vob" ); aTv( ".wmv" );
846     videoType->setCheckState( 0, ( i_temp > 0 ) ?
847                               ( ( i_temp == audioType->childCount() ) ?
848                                Qt::Checked : Qt::PartiallyChecked )
849                             : Qt::Unchecked );
850
851     i_temp = 0;
852     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
853     aTo( ".xspf" );
854     otherType->setCheckState( 0, ( i_temp > 0 ) ?
855                               ( ( i_temp == audioType->childCount() ) ?
856                                Qt::Checked : Qt::PartiallyChecked )
857                             : Qt::Unchecked );
858
859 #undef aTo
860 #undef aTv
861 #undef aTa
862
863     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
864     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
865     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
866     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
867     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
868
869     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
870
871     CONNECT( closeButton, clicked(), this, saveAsso() );
872     CONNECT( clearButton, clicked(), d, reject() );
873     d->resize( 300, 400 );
874     d->exec();
875     delete d;
876     delete qvReg;
877     listAsso.clear();
878 }
879
880 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
881 {
882     std::string s_path( "VLC" ); s_path += psz_ext;
883     std::string s_path2 = s_path;
884
885     /* Save a backup if already assigned */
886     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
887
888     if( psz_value && strlen( psz_value ) > 0 )
889         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
890     delete psz_value;
891
892     /* Put a "link" to VLC.EXT as default */
893     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
894
895     /* Create the needed Key if they weren't done in the installer */
896     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
897     {
898         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
899         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
900         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
901
902         /* Get the installer path */
903         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
904         std::string str_temp; str_temp.assign(
905             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
906
907         if( str_temp.size() )
908         {
909             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
910                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
911
912             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
913                         "", str_temp.append(",0").c_str() );
914         }
915         delete qvReg2;
916     }
917 }
918
919 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
920 {
921     char psz_VLC[] = "VLC";
922     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
923
924     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
925     {
926         free( psz_value );
927         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
928         if( psz_value )
929             qvReg->WriteRegistryString( psz_ext, "", psz_value );
930
931         qvReg->DeleteKey( psz_ext, "VLC.backup" );
932     }
933     delete( psz_value );
934 }
935 void SPrefsPanel::saveAsso()
936 {
937     QVLCRegistry * qvReg;
938     for( int i = 0; i < listAsso.size(); i ++ )
939     {
940         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
941         if( listAsso[i]->checkState( 0 ) > 0 )
942         {
943             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
944         }
945         else
946         {
947             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
948         }
949     }
950     /* Gruik ? Naaah */
951     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
952     delete qvReg;
953 }
954
955 #endif /* WIN32 */
956