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