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