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