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