Qt: fix build with --disable-media-library
[vlc/vlc-skelet.git] / modules / gui / qt4 / components / simple_preferences.cpp
blobfa13b1db8a51834bb478f35915cf3bff6f71ad2e
1 /*****************************************************************************
2 * simple_preferences.cpp : "Simple preferences"
3 ****************************************************************************
4 * Copyright (C) 2006-2010 the VideoLAN team
5 * $Id$
7 * Authors: Clément Stenac <zorglub@videolan.org>
8 * Antoine Cellerier <dionoea@videolan.org>
9 * Jean-Baptiste Kempf <jb@videolan.org>
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.
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.
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 *****************************************************************************/
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32 #include "dialogs/ml_configuration.hpp"
34 #include <vlc_config_cat.h>
35 #include <vlc_configuration.h>
37 #include <QString>
38 #include <QFont>
39 #include <QToolButton>
40 #include <QButtonGroup>
41 #include <QVBoxLayout>
42 #include <QScrollArea>
44 #include <QStyleFactory>
45 #include <QSettings>
46 #include <QtAlgorithms>
47 #include <QDir>
49 #define ICON_HEIGHT 64
51 #ifdef WIN32
52 # include <vlc_windows_interfaces.h>
53 #endif
54 #include <vlc_modules.h>
56 /*********************************************************************
57 * The List of categories
58 *********************************************************************/
59 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
60 QWidget( _parent ), p_intf( _p_intf )
62 QVBoxLayout *layout = new QVBoxLayout();
64 QButtonGroup *buttonGroup = new QButtonGroup( this );
65 buttonGroup->setExclusive ( true );
66 CONNECT( buttonGroup, buttonClicked ( int ),
67 this, switchPanel( int ) );
69 short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
71 #define ADD_CATEGORY( button, label, icon, numb ) \
72 QToolButton * button = new QToolButton( this ); \
73 button->setIcon( QIcon( ":/prefsmenu/" #icon ) ); \
74 button->setText( label ); \
75 button->setToolTip( label + qtr("Preferences") ); \
76 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
77 button->setIconSize( QSize( icon_height, icon_height ) ); \
78 button->resize( icon_height + 6 , icon_height + 6 ); \
79 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
80 button->setAutoRaise( true ); \
81 button->setCheckable( true ); \
82 buttonGroup->addButton( button, numb ); \
83 layout->addWidget( button );
85 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
86 cone_interface_64, 0 );
87 ADD_CATEGORY( SPrefsAudio, qtr("Audio"),
88 cone_audio_64, 1 );
89 ADD_CATEGORY( SPrefsVideo, qtr("Video"),
90 cone_video_64, 2 );
91 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
92 cone_subtitles_64, 3 );
93 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
94 cone_input_64, 4 );
95 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"),
96 cone_hotkeys_64, 5 );
98 #undef ADD_CATEGORY
100 SPrefsInterface->setChecked( true );
101 layout->setMargin( 0 );
102 layout->setSpacing( 1 );
104 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
105 setLayout( layout );
109 void SPrefsCatList::switchPanel( int i )
111 emit currentItemChanged( i );
114 /*********************************************************************
115 * The Panels
116 *********************************************************************/
117 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
118 int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
120 module_config_t *p_config;
121 ConfigControl *control;
122 number = _number;
124 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
125 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
126 if( p_config ) \
128 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
129 p_config, label, ui.qcontrol, false ); \
130 controls.append( control ); \
132 else { \
133 ui.qcontrol->setEnabled( false ); \
134 if( label ) label->setEnabled( false ); \
137 #define CONFIG_BOOL( option, qcontrol ) \
138 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
139 if( p_config ) \
141 control = new BoolConfigControl( VLC_OBJECT(p_intf), \
142 p_config, NULL, ui.qcontrol, false ); \
143 controls.append( control ); \
145 else { ui.qcontrol->setEnabled( false ); }
148 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol ) \
149 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
150 if( p_config ) \
152 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
153 p_config, label, qcontrol, false ); \
154 controls.append( control ); \
156 else { \
157 QWidget *widget = label; \
158 qcontrol->setVisible( false ); \
159 if( widget ) widget->setEnabled( false ); \
163 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
164 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
165 if( p_config ) \
167 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
168 p_config, label, ui.qcontrol ); \
169 controls.append( control ); \
172 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
173 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
174 if( p_config ) \
176 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
177 p_config, label, qcontrol, qbutton ); \
178 controls.append( control ); \
181 #define START_SPREFS_CAT( name , label ) \
182 case SPrefs ## name: \
184 Ui::SPrefs ## name ui; \
185 ui.setupUi( panel ); \
186 panel_label->setText( label );
188 #define END_SPREFS_CAT \
189 break; \
192 QVBoxLayout *panel_layout = new QVBoxLayout();
193 QWidget *panel = new QWidget();
194 panel_layout->setMargin( 3 );
196 // Title Label
197 QLabel *panel_label = new QLabel;
198 QFont labelFont = QApplication::font();
199 labelFont.setPointSize( labelFont.pointSize() + 6 );
200 panel_label->setFont( labelFont );
202 // Title <hr>
203 QFrame *title_line = new QFrame;
204 title_line->setFrameShape(QFrame::HLine);
205 title_line->setFrameShadow(QFrame::Sunken);
207 QFont italicFont = QApplication::font();
208 italicFont.setItalic( true );
210 switch( number )
212 /******************************
213 * VIDEO Panel Implementation *
214 ******************************/
215 START_SPREFS_CAT( Video , qtr("Video Settings") );
216 CONFIG_BOOL( "video", enableVideo );
218 CONFIG_BOOL( "fullscreen", fullscreen );
219 CONFIG_BOOL( "overlay", overlay );
220 CONFIG_BOOL( "video-on-top", alwaysOnTop );
221 CONFIG_BOOL( "video-deco", windowDecorations );
222 CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
224 CONFIG_BOOL( "video-wallpaper", wallpaperMode );
225 #ifdef WIN32
226 CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
227 dXdisplayDevice );
228 CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
229 #else
230 ui.directXBox->setVisible( false );
231 ui.hwYUVBox->setVisible( false );
232 #endif
234 CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
235 CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
236 CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
238 CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
239 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
240 CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
241 CONFIG_BOOL( "snapshot-sequential",
242 snapshotsSequentialNumbering );
243 CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
244 snapshotsFormat );
245 END_SPREFS_CAT;
247 /******************************
248 * AUDIO Panel Implementation *
249 ******************************/
250 START_SPREFS_CAT( Audio, qtr("Audio Settings") );
252 CONFIG_BOOL( "audio", enableAudio );
253 ui.SPrefsAudio_zone->setEnabled( ui.enableAudio->isChecked() );
254 CONNECT( ui.enableAudio, toggled( bool ),
255 ui.SPrefsAudio_zone, setEnabled( bool ) );
257 #define audioCommon( name ) \
258 QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
259 QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
260 name ## Layout->setMargin( 0 ); \
261 name ## Layout->setSpacing( 0 ); \
262 QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
263 name ## Label->setMinimumSize(QSize(250, 0)); \
264 name ## Layout->addWidget( name ## Label ); \
266 #define audioControl( name) \
267 audioCommon( name ) \
268 QComboBox * name ## Device = new QComboBox( name ## Control ); \
269 name ## Layout->addWidget( name ## Device ); \
270 name ## Label->setBuddy( name ## Device ); \
271 name ## Device->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred );\
272 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
274 #define audioControl2( name) \
275 audioCommon( name ) \
276 QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
277 name ## Layout->addWidget( name ## Device ); \
278 name ## Label->setBuddy( name ## Device ); \
279 QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
280 name ## Layout->addWidget( name ## Browse ); \
281 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
283 /* Build if necessary */
284 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
285 #ifdef WIN32
286 audioControl( DirectX );
287 optionWidgets.append( DirectXControl );
288 CONFIG_GENERIC_NO_UI( "directx-audio-device-name", StringList,
289 DirectXLabel, DirectXDevice );
290 #else
291 if( module_exists( "alsa" ) )
293 audioControl( alsa );
294 optionWidgets.append( alsaControl );
295 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
296 alsaDevice );
298 else
299 optionWidgets.append( NULL );
300 if( module_exists( "oss" ) )
302 audioControl2( OSS );
303 optionWidgets.append( OSSControl );
304 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
305 OSSBrowse );
307 else
308 optionWidgets.append( NULL );
309 #endif
311 #undef audioControl2
312 #undef audioControl
313 #undef audioCommon
315 /* Audio Options */
316 ui.volumeValue->setMaximum( QT_VOLUME_MAX / QT_VOLUME_DEFAULT * 100 );
317 CONFIG_GENERIC_NO_BOOL( "qt-startvolume" , IntegerRangeSlider, NULL,
318 defaultVolume );
319 CONNECT( ui.defaultVolume, valueChanged( int ),
320 this, updateAudioVolume( int ) );
322 CONFIG_BOOL( "qt-autosave-volume", keepVolumeRadio );
323 ui.defaultVolume_zone->setEnabled( ui.resetVolumeRadio->isChecked() );
324 CONNECT( ui.resetVolumeRadio, toggled( bool ),
325 ui.defaultVolume_zone, setEnabled( bool ) );
327 CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
328 preferredAudioLanguage );
330 CONFIG_BOOL( "spdif", spdifBox );
331 CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
332 detectionDolby );
334 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
335 volNormSpin );
336 CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
337 replayCombo );
338 CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
339 visualisation);
340 CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
342 /* Audio Output Specifics */
343 CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
345 CONNECT( ui.outputModule, currentIndexChanged( int ),
346 this, updateAudioOptions( int ) );
348 /* File output exists on all platforms */
349 CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
350 ui.fileName, ui.fileBrowseButton );
352 optionWidgets.append( ui.fileControl );
353 optionWidgets.append( ui.outputModule );
354 optionWidgets.append( ui.volNormBox );
355 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
356 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
357 optionWidgets.append( ui.volumeValue );
358 optionWidgets.append( ui.headphoneEffect );
359 optionWidgets.append( ui.spdifBox );
360 updateAudioOptions( ui.outputModule->currentIndex() );
362 /* LastFM */
363 if( module_exists( "audioscrobbler" ) )
365 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
366 lastfm_user_edit );
367 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
368 lastfm_pass_edit );
370 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
371 ui.lastfm->setChecked( true );
372 else
373 ui.lastfm->setChecked( false );
375 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
377 CONNECT( ui.lastfm, toggled( bool ),
378 ui.lastfm_zone, setVisible( bool ) );
379 CONNECT( ui.lastfm, stateChanged( int ),
380 this, lastfm_Changed( int ) );
382 else
384 ui.lastfm->hide();
385 ui.lastfm_zone->hide();
388 /* Normalizer */
389 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
390 setEnabled( bool ) );
392 char* psz = config_GetPsz( p_intf, "audio-filter" );
393 qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
394 free( psz );
396 bool b_enabled = ( qs_filter.contains( "volnorm" ) );
397 ui.volNormBox->setChecked( b_enabled );
398 ui.volNormSpin->setEnabled( b_enabled );
400 b_enabled = ( qs_filter.contains( "headphone" ) );
401 ui.headphoneEffect->setChecked( b_enabled );
403 /* Volume Label */
404 updateAudioVolume( ui.defaultVolume->value() ); // First time init
406 END_SPREFS_CAT;
408 /* Input and Codecs Panel Implementation */
409 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
411 /* Disk Devices */
413 ui.DVDDeviceComboBox->setToolTip(
414 qtr( "If this property is blank, different values\n"
415 "for DVD, VCD, and CDDA are set.\n"
416 "You can define a unique one or configure them \n"
417 "individually in the advanced preferences." ) );
418 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
419 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
420 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
421 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
422 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
423 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
425 ui.DVDDeviceComboBox->setEditText( qfu( psz_dvddiscpath ) );
427 free( psz_cddadiscpath );
428 free( psz_dvddiscpath );
429 free( psz_vcddiscpath );
431 #ifndef WIN32
432 QStringList DVDDeviceComboBoxStringList = QStringList();
433 DVDDeviceComboBoxStringList
434 << "dvd*" << "scd*" << "sr*" << "sg*" << "cd*";
435 ui.DVDDeviceComboBox->addItems( QDir( "/dev/" )
436 .entryList( DVDDeviceComboBoxStringList, QDir::System )
437 .replaceInStrings( QRegExp("^"), "/dev/" )
439 #endif
440 CONFIG_GENERIC( "dvd", String, ui.DVDLabel,
441 DVDDeviceComboBox->lineEdit() );
442 CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
443 ui.recordPath, ui.recordBrowse );
445 CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
446 CONFIG_GENERIC_NO_BOOL( "postproc-q", Integer, ui.ppLabel,
447 PostProcLevel );
448 CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
450 /* live555 module prefs */
451 CONFIG_BOOL( "rtsp-tcp",
452 live555TransportRTSP_TCPRadio );
453 if ( !module_exists( "live555" ) )
455 ui.live555TransportRTSP_TCPRadio->hide();
456 ui.live555TransportHTTPRadio->hide();
457 ui.live555TransportLabel->hide();
459 CONFIG_BOOL( "ffmpeg-hw", hwAccelBox );
460 #ifdef WIN32
461 CONFIG_BOOL( "prefer-system-codecs", systemCodecBox );
462 HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
463 if( !hdxva2_dll )
464 ui.hwAccelBox->setEnabled( false );
465 else
466 FreeLibrary( hdxva2_dll );
467 #else
468 ui.systemCodecBox->hide();
469 #endif
470 optionWidgets.append( ui.DVDDeviceComboBox );
471 optionWidgets.append( ui.cachingCombo );
472 CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
473 CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
474 CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
475 CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
476 CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
478 /* Caching */
479 /* Add the things to the ComboBox */
480 #define addToCachingBox( str, cachingNumber ) \
481 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
482 addToCachingBox( N_("Custom"), CachingCustom );
483 addToCachingBox( N_("Lowest latency"), CachingLowest );
484 addToCachingBox( N_("Low latency"), CachingLow );
485 addToCachingBox( N_("Normal"), CachingNormal );
486 addToCachingBox( N_("High latency"), CachingHigh );
487 addToCachingBox( N_("Higher latency"), CachingHigher );
488 #undef addToCachingBox
490 #define TestCaC( name ) \
491 b_cache_equal = b_cache_equal && \
492 ( i_cache == config_GetInt( p_intf, name ) )
494 #define TestCaCi( name, int ) \
495 b_cache_equal = b_cache_equal && \
496 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
497 /* Select the accurate value of the ComboBox */
498 bool b_cache_equal = true;
499 int i_cache = config_GetInt( p_intf, "file-caching");
501 TestCaC( "udp-caching" );
502 if (module_exists ("dvdread"))
503 TestCaC( "dvdread-caching" );
504 if (module_exists ("dvdnav"))
505 TestCaC( "dvdnav-caching" );
506 TestCaC( "tcp-caching" );
507 TestCaC( "cdda-caching" );
508 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
509 #ifdef WIN32
510 TestCaC( "dshow-caching" );
511 #else
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
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 );
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 #ifdef MEDIA_LIBRARY
553 BUTTONACT( ui.sqlMLbtn, configML() );
554 #endif
556 /* interface */
557 char *psz_intf = config_GetPsz( p_intf, "intf" );
558 if( psz_intf )
560 if( strstr( psz_intf, "skin" ) )
561 ui.skins->setChecked( true );
562 } else {
563 /* defaults to qt */
564 ui.qt4->setChecked( true );
566 free( psz_intf );
568 optionWidgets.append( ui.skins );
569 optionWidgets.append( ui.qt4 );
570 #if !defined(NDEBUG) || !defined( WIN32)
571 ui.stylesCombo->addItem( qtr("System's default") );
572 ui.stylesCombo->addItems( QStyleFactory::keys() );
573 ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
574 getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
575 ui.stylesCombo->insertSeparator( 1 );
577 CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
578 optionWidgets.append( ui.stylesCombo );
579 #else
580 ui.stylesCombo->hide();
581 optionWidgets.append( NULL );
582 #endif
583 radioGroup = new QButtonGroup(this);
584 radioGroup->addButton( ui.qt4, 0 );
585 radioGroup->addButton( ui.skins, 1 );
586 CONNECT( radioGroup, buttonClicked( int ),
587 ui.styleStackedWidget, setCurrentIndex( int ) );
588 ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
590 CONNECT( ui.minimalviewBox, toggled( bool ),
591 ui.mainPreview, setNormalPreview( bool ) );
592 CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
593 ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
594 ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
596 CONFIG_BOOL( "embedded-video", embedVideo );
597 CONFIG_BOOL( "qt-video-autoresize", resizingBox );
598 CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
599 ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );
601 CONFIG_BOOL( "qt-fs-controller", fsController );
602 CONFIG_BOOL( "qt-system-tray", systrayBox );
603 CONFIG_BOOL( "qt-notification", sysPop );
604 CONNECT( ui.systrayBox, toggled( bool ), ui.sysPop, setEnabled( bool ) );
605 ui.sysPop->setEnabled( ui.systrayBox->isChecked() );
607 CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
608 CONFIG_BOOL( "playlist-tree", treePlaylist );
609 CONFIG_BOOL( "play-and-pause", playPauseBox );
610 CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
611 ui.fileSkin, ui.skinBrowse );
613 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
614 artFetcher );
616 /* UPDATE options */
617 #ifdef UPDATE_CHECK
618 CONFIG_BOOL( "qt-updates-notif", updatesBox );
619 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
620 updatesDays );
621 ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
622 CONNECT( ui.updatesBox, toggled( bool ),
623 ui.updatesDays, setEnabled( bool ) );
624 #else
625 ui.updateNotifierZone->hide();
626 #endif
627 /* ONE INSTANCE options */
628 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
629 CONFIG_BOOL( "one-instance", OneInterfaceMode );
630 CONFIG_BOOL( "playlist-enqueue",
631 EnqueueOneInterfaceMode );
632 ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
633 CONNECT( ui.OneInterfaceMode, toggled( bool ),
634 ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
635 #else
636 ui.OneInterfaceBox->hide();
637 #endif
638 /* RECENTLY PLAYED options */
639 CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
640 ui.recentlyPlayedFilters, setEnabled( bool ) );
641 ui.recentlyPlayedFilters->setEnabled( false );
642 CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
643 CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
644 recentlyPlayedFilters );
646 END_SPREFS_CAT;
648 START_SPREFS_CAT( Subtitles,
649 qtr("Subtitles & On Screen Display Settings") );
650 CONFIG_BOOL( "osd", OSDBox);
651 CONFIG_BOOL( "video-title-show", OSDTitleBox);
652 CONFIG_GENERIC( "video-title-position", IntegerList,
653 ui.OSDTitlePosLabel, OSDTitlePos );
655 CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
656 encoding );
657 CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
658 preferredLanguage );
659 CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
660 CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
661 fontColor );
662 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
663 ui.fontSizeLabel, fontSize );
664 CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
665 effect );
666 CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
668 END_SPREFS_CAT;
670 case SPrefsHotkeys:
672 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
674 QGridLayout *gLayout = new QGridLayout;
675 panel->setLayout( gLayout );
676 int line = 0;
678 panel_label->setText( qtr( "Configure Hotkeys" ) );
679 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
680 this, gLayout, line );
681 controls.append( control );
683 line++;
685 QFrame *sepline = new QFrame;
686 sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
687 gLayout->addWidget( sepline, line, 0, 1, -1 );
689 line++;
691 p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
692 control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
693 p_config, this, false, gLayout, line );
694 controls.append( control );
696 #ifdef WIN32
697 line++;
699 p_config = config_FindConfig( VLC_OBJECT(p_intf), "qt-disable-volume-keys" );
700 control = new BoolConfigControl( VLC_OBJECT(p_intf), p_config, this, gLayout, line );
701 controls.append( control );
702 #endif
704 break;
708 panel_layout->addWidget( panel_label );
709 panel_layout->addWidget( title_line );
711 if( small )
713 QScrollArea *scroller= new QScrollArea;
714 scroller->setWidget( panel );
715 scroller->setWidgetResizable( true );
716 scroller->setFrameStyle( QFrame::NoFrame );
717 panel_layout->addWidget( scroller );
719 else
721 panel_layout->addWidget( panel );
722 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
725 setLayout( panel_layout );
727 #undef END_SPREFS_CAT
728 #undef START_SPREFS_CAT
729 #undef CONFIG_GENERIC_FILE
730 #undef CONFIG_GENERIC_NO_BOOL
731 #undef CONFIG_GENERIC_NO_UI
732 #undef CONFIG_GENERIC
733 #undef CONFIG_BOOL
737 void SPrefsPanel::updateAudioOptions( int number)
739 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
740 ->itemData( number ).toString();
741 #ifdef WIN32
742 optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
743 #else
744 /* optionWidgets[ossW] can be NULL */
745 if( optionWidgets[ossW] )
746 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
747 /* optionWidgets[alsaW] can be NULL */
748 if( optionWidgets[alsaW] )
749 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
750 #endif
751 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
752 optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
753 value == "aout_directx" || value == "waveout" ) );
757 SPrefsPanel::~SPrefsPanel()
759 qDeleteAll( controls ); controls.clear();
762 void SPrefsPanel::updateAudioVolume( int volume )
764 qobject_cast<QSpinBox *>(optionWidgets[volLW])
765 ->setValue( volume * 100 / QT_VOLUME_DEFAULT );
769 /* Function called from the main Preferences dialog on each SPrefs Panel */
770 void SPrefsPanel::apply()
772 /* Generic save for ever panel */
773 QList<ConfigControl *>::Iterator i;
774 for( i = controls.begin() ; i != controls.end() ; ++i )
776 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
777 c->doApply();
780 switch( number )
782 case SPrefsInputAndCodecs:
784 /* Device default selection */
785 char *psz_devicepath =
786 strdup( qtu( qobject_cast<QComboBox *>(optionWidgets[inputLE])->currentText() ) );
787 if( !EMPTY_STR( psz_devicepath ) )
789 config_PutPsz( p_intf, "dvd", psz_devicepath );
790 config_PutPsz( p_intf, "vcd", psz_devicepath );
791 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
792 free( psz_devicepath );
795 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
796 #define CaC( name ) CaCi( name, 1 )
797 /* Caching */
798 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
799 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
800 if( i_comboValue )
802 CaC( "udp-caching" );
803 if (module_exists ("dvdread" ))
804 CaC( "dvdread-caching" );
805 if (module_exists ("dvdnav" ))
806 CaC( "dvdnav-caching" );
807 CaC( "tcp-caching" ); CaC( "vcd-caching" );
808 CaC( "cdda-caching" ); CaC( "file-caching" );
809 CaC( "screen-caching" ); CaC( "bd-caching" );
810 CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
811 CaCi( "http-caching", 2 );
812 if (module_exists ("access_realrtsp" ))
813 CaCi( "realrtsp-caching", 10 );
814 CaCi( "mms-caching", 10 );
815 #ifdef WIN32
816 CaC( "dshow-caching" );
817 #else
818 if (module_exists ( "access_jack" ))
819 CaC( "jack-input-caching" );
820 if (module_exists ( "v4l2" ))
821 CaC( "v4l2-caching" );
822 if (module_exists ( "pvr" ))
823 CaC( "pvr-caching" );
824 #endif
825 //CaCi( "dv-caching" ) too short...
827 break;
828 #undef CaC
829 #undef CaCi
832 /* Interfaces */
833 case SPrefsInterface:
835 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
836 config_PutPsz( p_intf, "intf", "skins2,any" );
837 else
838 //if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
839 config_PutPsz( p_intf, "intf", "" );
840 if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
841 getSettings()->setValue( "MainWindow/QtStyle",
842 qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
844 break;
847 case SPrefsAudio:
849 bool b_checked =
850 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
851 if( b_checked && !qs_filter.contains( "volnorm" ) )
852 qs_filter.append( "volnorm" );
853 if( !b_checked && qs_filter.contains( "volnorm" ) )
854 qs_filter.removeAll( "volnorm" );
856 b_checked =
857 qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
859 if( b_checked && !qs_filter.contains( "headphone" ) )
860 qs_filter.append( "headphone" );
861 if( !b_checked && qs_filter.contains( "headphone" ) )
862 qs_filter.removeAll( "headphone" );
864 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
865 break;
870 void SPrefsPanel::clean()
873 void SPrefsPanel::lastfm_Changed( int i_state )
875 if( i_state == Qt::Checked )
876 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
877 else if( i_state == Qt::Unchecked )
878 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
881 void SPrefsPanel::changeStyle( QString s_style )
883 QApplication::setStyle( s_style );
885 /* force refresh on all widgets */
886 QWidgetList widgets = QApplication::allWidgets();
887 QWidgetList::iterator it = widgets.begin();
888 while( it != widgets.end() ) {
889 (*it)->update();
890 ++it;
894 void SPrefsPanel::configML()
896 #ifdef MEDIA_LIBRARY
897 MLConfDialog *mld = new MLConfDialog( this, p_intf );
898 mld->exec();
899 delete mld;
900 #endif
903 #ifdef WIN32
904 #include <QDialogButtonBox>
905 #include "util/registry.hpp"
906 #include <string>
908 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
909 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
911 bool b_temp;
912 const char* psz_VLC = "VLC";
913 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
915 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
917 current->setCheckState( 0, Qt::Checked );
918 b_temp = false;
920 else
922 current->setCheckState( 0, Qt::Unchecked );
923 b_temp = true;
925 listAsso.append( current );
926 return b_temp;
929 void SPrefsPanel::assoDialog()
931 LPAPPASSOCREGUI p_appassoc;
932 CoInitialize( 0 );
934 if( S_OK == CoCreateInstance( &clsid_IApplication2,
935 NULL, CLSCTX_INPROC_SERVER,
936 &IID_IApplicationAssociationRegistrationUI,
937 (void **)&p_appassoc) )
939 if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
941 CoUninitialize();
942 return;
946 CoUninitialize();
948 QDialog *d = new QDialog( this );
949 QGridLayout *assoLayout = new QGridLayout( d );
951 QTreeWidget *filetypeList = new QTreeWidget;
952 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
953 filetypeList->header()->hide();
955 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
957 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
958 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
959 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
961 filetypeList->addTopLevelItem( audioType );
962 filetypeList->addTopLevelItem( videoType );
963 filetypeList->addTopLevelItem( otherType );
965 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
966 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
967 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
969 QTreeWidgetItem *currentItem;
971 int i_temp = 0;
972 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
973 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
974 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
976 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
977 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
978 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
979 aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
980 audioType->setCheckState( 0, ( i_temp > 0 ) ?
981 ( ( i_temp == audioType->childCount() ) ?
982 Qt::Checked : Qt::PartiallyChecked )
983 : Qt::Unchecked );
985 i_temp = 0;
986 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
987 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
988 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
989 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
990 aTv( ".mts" ); aTv( ".mxf" );
991 aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".ts" );
992 aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
993 videoType->setCheckState( 0, ( i_temp > 0 ) ?
994 ( ( i_temp == audioType->childCount() ) ?
995 Qt::Checked : Qt::PartiallyChecked )
996 : Qt::Unchecked );
998 i_temp = 0;
999 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
1000 aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
1001 otherType->setCheckState( 0, ( i_temp > 0 ) ?
1002 ( ( i_temp == audioType->childCount() ) ?
1003 Qt::Checked : Qt::PartiallyChecked )
1004 : Qt::Unchecked );
1006 #undef aTo
1007 #undef aTv
1008 #undef aTa
1010 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
1011 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
1012 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
1013 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1014 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
1016 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
1018 CONNECT( closeButton, clicked(), this, saveAsso() );
1019 CONNECT( clearButton, clicked(), d, reject() );
1020 d->resize( 300, 400 );
1021 d->exec();
1022 delete d;
1023 delete qvReg;
1024 listAsso.clear();
1027 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
1029 std::string s_path( "VLC" ); s_path += psz_ext;
1030 std::string s_path2 = s_path;
1032 /* Save a backup if already assigned */
1033 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
1035 if( !EMPTY_STR(psz_value) )
1036 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
1037 delete psz_value;
1039 /* Put a "link" to VLC.EXT as default */
1040 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1042 /* Create the needed Key if they weren't done in the installer */
1043 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
1045 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
1046 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
1047 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
1049 /* Get the installer path */
1050 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1051 std::string str_temp; str_temp.assign(
1052 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
1054 if( str_temp.size() )
1056 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
1057 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
1059 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
1060 "", str_temp.append(",0").c_str() );
1062 delete qvReg2;
1066 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1068 char psz_VLC[] = "VLC";
1069 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
1071 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
1073 free( psz_value );
1074 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1075 if( psz_value )
1076 qvReg->WriteRegistryString( psz_ext, "", psz_value );
1078 qvReg->DeleteKey( psz_ext, "VLC.backup" );
1080 delete( psz_value );
1082 void SPrefsPanel::saveAsso()
1084 QVLCRegistry * qvReg;
1085 for( int i = 0; i < listAsso.size(); i ++ )
1087 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
1088 if( listAsso[i]->checkState( 0 ) > 0 )
1090 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1092 else
1094 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1097 /* Gruik ? Naaah */
1098 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1099 delete qvReg;
1102 #endif /* WIN32 */