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