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