]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
C++: use postfix operator for interators (that's supposedly faster and a good practice).
[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             CONFIG_BOOL( "playlist-tree", treePlaylist );
597             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
598                                  ui.fileSkin, ui.skinBrowse );
599             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
600
601             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
602                                                       artFetcher );
603
604             /* UPDATE options */
605 #ifdef UPDATE_CHECK
606             CONFIG_BOOL( "qt-updates-notif", updatesBox );
607             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
608                     updatesDays );
609             ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
610             CONNECT( ui.updatesBox, toggled( bool ),
611                      ui.updatesDays, setEnabled( bool ) );
612 #else
613             ui.updateNotifierZone->hide();
614 #endif
615             /* ONE INSTANCE options */
616 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
617             CONFIG_BOOL( "one-instance", OneInterfaceMode );
618             CONFIG_BOOL( "playlist-enqueue",
619                     EnqueueOneInterfaceMode );
620             ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
621             CONNECT( ui.OneInterfaceMode, toggled( bool ),
622                      ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
623 #else
624             ui.OneInterfaceBox->hide();
625 #endif
626             /* RECENTLY PLAYED options */
627             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
628                      ui.recentlyPlayedFilters, setEnabled( bool ) );
629             ui.recentlyPlayedFilters->setEnabled( false );
630             CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
631             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
632                     recentlyPlayedFilters );
633
634         END_SPREFS_CAT;
635
636         START_SPREFS_CAT( Subtitles,
637                             qtr("Subtitles & On Screen Display Settings") );
638             CONFIG_BOOL( "osd", OSDBox);
639             CONFIG_BOOL( "video-title-show", OSDTitleBox);
640
641
642             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
643                             encoding );
644             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
645                             preferredLanguage );
646             CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
647             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
648                             fontColor );
649             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
650                             ui.fontSizeLabel, fontSize );
651             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
652                             effect );
653             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
654
655         END_SPREFS_CAT;
656
657         case SPrefsHotkeys:
658         {
659             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
660
661             QGridLayout *gLayout = new QGridLayout;
662             panel->setLayout( gLayout );
663             int line = 0;
664
665             panel_label->setText( qtr( "Configure Hotkeys" ) );
666             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
667                                                 this, gLayout, line );
668             controls.append( control );
669
670             line++;
671
672             QFrame *sepline = new QFrame;
673             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
674             gLayout->addWidget( sepline, line, 0, 1, -1 );
675
676             line++;
677
678             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
679             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
680                     p_config, this, false, gLayout, line );
681             controls.append( control );
682
683             break;
684         }
685     }
686
687     panel_layout->addWidget( panel_label );
688     panel_layout->addWidget( title_line );
689
690     if( small )
691     {
692         QScrollArea *scroller= new QScrollArea;
693         scroller->setWidget( panel );
694         scroller->setWidgetResizable( true );
695         scroller->setFrameStyle( QFrame::NoFrame );
696         panel_layout->addWidget( scroller );
697     }
698     else
699     {
700         panel_layout->addWidget( panel );
701         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
702     }
703
704     setLayout( panel_layout );
705
706 #undef END_SPREFS_CAT
707 #undef START_SPREFS_CAT
708 #undef CONFIG_GENERIC_FILE
709 #undef CONFIG_GENERIC_NO_BOOL
710 #undef CONFIG_GENERIC_NO_UI
711 #undef CONFIG_GENERIC
712 #undef CONFIG_BOOL
713 }
714
715
716 void SPrefsPanel::updateAudioOptions( int number)
717 {
718     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
719                                             ->itemData( number ).toString();
720 #ifdef WIN32
721     optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
722 #else
723     /* optionWidgets[ossW] can be NULL */
724     if( optionWidgets[ossW] )
725         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
726     /* optionWidgets[alsaW] can be NULL */
727     if( optionWidgets[alsaW] )
728         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
729 #endif
730     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
731     optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
732                                            value == "aout_directx" || value == "waveout" ) );
733 }
734
735
736 SPrefsPanel::~SPrefsPanel()
737 {
738     qDeleteAll( controls ); controls.clear();
739 }
740
741 void SPrefsPanel::updateAudioVolume( int volume )
742 {
743     qobject_cast<QSpinBox *>(optionWidgets[volLW])
744         ->setValue( volume * 100 / QT_VOLUME_DEFAULT );
745 }
746
747
748 /* Function called from the main Preferences dialog on each SPrefs Panel */
749 void SPrefsPanel::apply()
750 {
751     /* Generic save for ever panel */
752     QList<ConfigControl *>::Iterator i;
753     for( i = controls.begin() ; i != controls.end() ; ++i )
754     {
755         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
756         c->doApply( p_intf );
757     }
758
759     switch( number )
760     {
761     case SPrefsInputAndCodecs:
762     {
763         /* Device default selection */
764         char *psz_devicepath =
765             strdup( qtu( qobject_cast<QComboBox *>(optionWidgets[inputLE])->currentText() ) );
766         if( !EMPTY_STR( psz_devicepath ) )
767         {
768             config_PutPsz( p_intf, "dvd", psz_devicepath );
769             config_PutPsz( p_intf, "vcd", psz_devicepath );
770             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
771             free( psz_devicepath );
772         }
773
774 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
775 #define CaC( name ) CaCi( name, 1 )
776         /* Caching */
777         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
778         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
779         if( i_comboValue )
780         {
781             CaC( "udp-caching" );
782             if (module_exists ("dvdread" ))
783                 CaC( "dvdread-caching" );
784             if (module_exists ("dvdnav" ))
785                 CaC( "dvdnav-caching" );
786             CaC( "tcp-caching" ); CaC( "vcd-caching" );
787             CaC( "cdda-caching" ); CaC( "file-caching" );
788             CaC( "screen-caching" ); CaC( "bd-caching" );
789             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
790             CaCi( "http-caching", 2 );
791             if (module_exists ("access_realrtsp" ))
792                 CaCi( "realrtsp-caching", 10 );
793             CaCi( "mms-caching", 10 );
794             #ifdef WIN32
795             CaC( "dshow-caching" );
796             #else
797             if (module_exists ( "v4l" ))
798                 CaC( "v4l-caching" );
799             if (module_exists ( "access_jack" ))
800             CaC( "jack-input-caching" );
801             if (module_exists ( "v4l2" ))
802                 CaC( "v4l2-caching" );
803             if (module_exists ( "pvr" ))
804                 CaC( "pvr-caching" );
805             #endif
806             //CaCi( "dv-caching" ) too short...
807         }
808         break;
809 #undef CaC
810 #undef CaCi
811     }
812
813     /* Interfaces */
814     case SPrefsInterface:
815     {
816         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
817             config_PutPsz( p_intf, "intf", "skins2" );
818         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
819             config_PutPsz( p_intf, "intf", "qt" );
820         if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
821             getSettings()->setValue( "MainWindow/QtStyle",
822                 qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
823
824         break;
825     }
826
827     case SPrefsAudio:
828     {
829         bool b_checked =
830             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
831         if( b_checked && !qs_filter.contains( "volnorm" ) )
832             qs_filter.append( "volnorm" );
833         if( !b_checked && qs_filter.contains( "volnorm" ) )
834             qs_filter.removeAll( "volnorm" );
835
836         b_checked =
837             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
838
839         if( b_checked && !qs_filter.contains( "headphone" ) )
840             qs_filter.append( "headphone" );
841         if( !b_checked && qs_filter.contains( "headphone" ) )
842             qs_filter.removeAll( "headphone" );
843
844         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
845         break;
846     }
847     }
848 }
849
850 void SPrefsPanel::clean()
851 {}
852
853 void SPrefsPanel::lastfm_Changed( int i_state )
854 {
855     if( i_state == Qt::Checked )
856         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
857     else if( i_state == Qt::Unchecked )
858         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
859 }
860
861 void SPrefsPanel::changeStyle( QString s_style )
862 {
863     QApplication::setStyle( s_style );
864
865     /* force refresh on all widgets */
866     QWidgetList widgets = QApplication::allWidgets();
867     QWidgetList::iterator it = widgets.begin();
868     while( it != widgets.end() ) {
869         (*it)->update();
870         ++it;
871     };
872 }
873
874 #ifdef WIN32
875 #include <QDialogButtonBox>
876 #include <QHeaderView>
877 #include "util/registry.hpp"
878 #include <string>
879
880 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
881                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
882 {
883     bool b_temp;
884     const char* psz_VLC = "VLC";
885     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
886
887     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
888     {
889         current->setCheckState( 0, Qt::Checked );
890         b_temp = false;
891     }
892     else
893     {
894         current->setCheckState( 0, Qt::Unchecked );
895         b_temp = true;
896     }
897     listAsso.append( current );
898     return b_temp;
899 }
900
901 void SPrefsPanel::assoDialog()
902 {
903     LPAPPASSOCREGUI p_appassoc;
904     CoInitialize( 0 );
905
906     if( S_OK == CoCreateInstance( &clsid_IApplication2,
907                 NULL, CLSCTX_INPROC_SERVER,
908                 &IID_IApplicationAssociationRegistrationUI,
909                 (void **)&p_appassoc) )
910     {
911         if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
912         {
913             CoUninitialize();
914             return;
915         }
916     }
917
918     CoUninitialize();
919
920     QDialog *d = new QDialog( this );
921     QGridLayout *assoLayout = new QGridLayout( d );
922
923     QTreeWidget *filetypeList = new QTreeWidget;
924     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
925     filetypeList->header()->hide();
926
927     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
928
929     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
930     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
931     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
932
933     filetypeList->addTopLevelItem( audioType );
934     filetypeList->addTopLevelItem( videoType );
935     filetypeList->addTopLevelItem( otherType );
936
937     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
938     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
939     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
940
941     QTreeWidgetItem *currentItem;
942
943     int i_temp = 0;
944 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
945 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
946 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
947
948     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
949     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
950     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
951     aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
952     audioType->setCheckState( 0, ( i_temp > 0 ) ?
953                               ( ( i_temp == audioType->childCount() ) ?
954                                Qt::Checked : Qt::PartiallyChecked )
955                             : Qt::Unchecked );
956
957     i_temp = 0;
958     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
959     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
960     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
961     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
962     aTv( ".mts" ); aTv( ".mxf" );
963     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
964     aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
965     videoType->setCheckState( 0, ( i_temp > 0 ) ?
966                               ( ( i_temp == audioType->childCount() ) ?
967                                Qt::Checked : Qt::PartiallyChecked )
968                             : Qt::Unchecked );
969
970     i_temp = 0;
971     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
972     aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
973     otherType->setCheckState( 0, ( i_temp > 0 ) ?
974                               ( ( i_temp == audioType->childCount() ) ?
975                                Qt::Checked : Qt::PartiallyChecked )
976                             : Qt::Unchecked );
977
978 #undef aTo
979 #undef aTv
980 #undef aTa
981
982     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
983     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
984     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
985     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
986     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
987
988     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
989
990     CONNECT( closeButton, clicked(), this, saveAsso() );
991     CONNECT( clearButton, clicked(), d, reject() );
992     d->resize( 300, 400 );
993     d->exec();
994     delete d;
995     delete qvReg;
996     listAsso.clear();
997 }
998
999 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
1000 {
1001     std::string s_path( "VLC" ); s_path += psz_ext;
1002     std::string s_path2 = s_path;
1003
1004     /* Save a backup if already assigned */
1005     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1006
1007     if( !EMPTY_STR(psz_value) )
1008         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
1009     delete psz_value;
1010
1011     /* Put a "link" to VLC.EXT as default */
1012     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1013
1014     /* Create the needed Key if they weren't done in the installer */
1015     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
1016     {
1017         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1018         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
1019         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
1020
1021         /* Get the installer path */
1022         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1023         std::string str_temp; str_temp.assign(
1024             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
1025
1026         if( str_temp.size() )
1027         {
1028             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
1029                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
1030
1031             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
1032                         "", str_temp.append(",0").c_str() );
1033         }
1034         delete qvReg2;
1035     }
1036 }
1037
1038 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1039 {
1040     char psz_VLC[] = "VLC";
1041     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1042
1043     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
1044     {
1045         free( psz_value );
1046         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1047         if( psz_value )
1048             qvReg->WriteRegistryString( psz_ext, "", psz_value );
1049
1050         qvReg->DeleteKey( psz_ext, "VLC.backup" );
1051     }
1052     delete( psz_value );
1053 }
1054 void SPrefsPanel::saveAsso()
1055 {
1056     QVLCRegistry * qvReg;
1057     for( int i = 0; i < listAsso.size(); i ++ )
1058     {
1059         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
1060         if( listAsso[i]->checkState( 0 ) > 0 )
1061         {
1062             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1063         }
1064         else
1065         {
1066             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1067         }
1068     }
1069     /* Gruik ? Naaah */
1070     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1071     delete qvReg;
1072 }
1073
1074 #endif /* WIN32 */
1075