1 /*****************************************************************************
2 * simple_preferences.cpp : "Simple preferences"
3 ****************************************************************************
4 * Copyright (C) 2006-2008 the VideoLAN team
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 *****************************************************************************/
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
33 #include <vlc_config_cat.h>
34 #include <vlc_configuration.h>
38 #include <QToolButton>
39 #include <QButtonGroup>
40 #include <QVBoxLayout>
41 #include <QScrollArea>
43 #include <QStyleFactory>
45 #include <QtAlgorithms>
47 #define ICON_HEIGHT 64
50 # include <vlc_windows_interfaces.h>
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 )
59 QVBoxLayout *layout = new QVBoxLayout();
61 QButtonGroup *buttonGroup = new QButtonGroup( this );
62 buttonGroup->setExclusive ( true );
63 CONNECT( buttonGroup, buttonClicked ( int ),
64 this, switchPanel( int ) );
66 short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
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 );
81 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
82 cone_interface_64, 0 );
83 ADD_CATEGORY( SPrefsAudio, qtr("Audio"),
85 ADD_CATEGORY( SPrefsVideo, qtr("Video"),
87 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
88 cone_subtitles_64, 3 );
89 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
91 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"),
96 SPrefsInterface->setChecked( true );
97 layout->setMargin( 0 );
98 layout->setSpacing( 1 );
100 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
105 void SPrefsCatList::switchPanel( int i )
107 emit currentItemChanged( i );
110 /*********************************************************************
112 *********************************************************************/
113 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
114 int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
116 module_config_t *p_config;
117 ConfigControl *control;
120 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
121 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
124 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
125 p_config, label, ui.qcontrol, false ); \
126 controls.append( control ); \
129 ui.qcontrol->setEnabled( false ); \
130 if( label ) label->setEnabled( false ); \
133 #define CONFIG_BOOL( option, qcontrol ) \
134 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
137 control = new BoolConfigControl( VLC_OBJECT(p_intf), \
138 p_config, NULL, ui.qcontrol, false ); \
139 controls.append( control ); \
141 else { ui.qcontrol->setEnabled( false ); }
144 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol ) \
145 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
148 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
149 p_config, label, qcontrol, false ); \
150 controls.append( control ); \
153 QWidget *widget = label; \
154 qcontrol->setVisible( false ); \
155 if( widget ) widget->setEnabled( false ); \
159 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
160 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
163 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
164 p_config, label, ui.qcontrol ); \
165 controls.append( control ); \
168 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
169 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
172 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
173 p_config, label, qcontrol, qbutton ); \
174 controls.append( control ); \
177 #define START_SPREFS_CAT( name , label ) \
178 case SPrefs ## name: \
180 Ui::SPrefs ## name ui; \
181 ui.setupUi( panel ); \
182 panel_label->setText( label );
184 #define END_SPREFS_CAT \
188 QVBoxLayout *panel_layout = new QVBoxLayout();
189 QWidget *panel = new QWidget();
190 panel_layout->setMargin( 3 );
193 QLabel *panel_label = new QLabel;
194 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
195 labelFont.setPointSize( labelFont.pointSize() + 6 );
196 labelFont.setFamily( "Verdana" );
197 panel_label->setFont( labelFont );
200 QFrame *title_line = new QFrame;
201 title_line->setFrameShape(QFrame::HLine);
202 title_line->setFrameShadow(QFrame::Sunken);
204 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
205 italicFont.setItalic( true );
209 /******************************
210 * VIDEO Panel Implementation *
211 ******************************/
212 START_SPREFS_CAT( Video , qtr("Video Settings") );
213 CONFIG_BOOL( "video", enableVideo );
215 CONFIG_BOOL( "fullscreen", fullscreen );
216 CONFIG_BOOL( "overlay", overlay );
217 CONFIG_BOOL( "video-on-top", alwaysOnTop );
218 CONFIG_BOOL( "video-deco", windowDecorations );
219 CONFIG_BOOL( "skip-frames", skipFrames );
220 CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
222 CONFIG_BOOL( "video-wallpaper", wallpaperMode );
224 CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
226 CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
228 ui.directXBox->setVisible( false );
229 ui.hwYUVBox->setVisible( false );
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 );
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,
245 /******************************
246 * AUDIO Panel Implementation *
247 ******************************/
248 START_SPREFS_CAT( Audio, qtr("Audio Settings") );
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 ) );
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 ); \
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 );
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 );
280 /* Build if necessary */
281 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
283 audioControl( DirectX );
284 optionWidgets.append( DirectXControl );
285 CONFIG_GENERIC_NO_UI( "directx-audio-device-name", StringList,
286 DirectXLabel, DirectXDevice );
288 if( module_exists( "alsa" ) )
290 audioControl( alsa );
291 optionWidgets.append( alsaControl );
293 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
297 optionWidgets.append( NULL );
298 if( module_exists( "oss" ) )
300 audioControl2( OSS );
301 optionWidgets.append( OSSControl );
302 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
306 optionWidgets.append( NULL );
314 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
316 CONNECT( ui.defaultVolume, valueChanged( int ),
317 this, updateAudioVolume( int ) );
319 CONFIG_BOOL( "qt-autosave-volume", keepVolumeRadio );
320 ui.defaultVolume_zone->setEnabled( ui.resetVolumeRadio->isChecked() );
321 CONNECT( ui.resetVolumeRadio, toggled( bool ),
322 ui.defaultVolume_zone, setEnabled( bool ) );
324 CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
325 preferredAudioLanguage );
327 CONFIG_BOOL( "spdif", spdifBox );
328 CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
331 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
333 CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
335 CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
337 CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
339 /* Audio Output Specifics */
340 CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
342 CONNECT( ui.outputModule, currentIndexChanged( int ),
343 this, updateAudioOptions( int ) );
345 /* File output exists on all platforms */
346 CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
347 ui.fileName, ui.fileBrowseButton );
349 optionWidgets.append( ui.fileControl );
350 optionWidgets.append( ui.outputModule );
351 optionWidgets.append( ui.volNormBox );
352 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
353 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
354 optionWidgets.append( ui.volumeValue );
355 optionWidgets.append( ui.headphoneEffect );
356 optionWidgets.append( ui.spdifBox );
357 updateAudioOptions( ui.outputModule->currentIndex() );
360 if( module_exists( "audioscrobbler" ) )
362 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
364 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
367 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
368 ui.lastfm->setChecked( true );
370 ui.lastfm->setChecked( false );
372 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
374 CONNECT( ui.lastfm, toggled( bool ),
375 ui.lastfm_zone, setVisible( bool ) );
376 CONNECT( ui.lastfm, stateChanged( int ),
377 this, lastfm_Changed( int ) );
382 ui.lastfm_zone->hide();
386 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
387 setEnabled( bool ) );
389 char* psz = config_GetPsz( p_intf, "audio-filter" );
390 qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
393 bool b_enabled = ( qs_filter.contains( "volnorm" ) );
394 ui.volNormBox->setChecked( b_enabled );
395 ui.volNormSpin->setEnabled( b_enabled );
397 b_enabled = ( qs_filter.contains( "headphone" ) );
398 ui.headphoneEffect->setChecked( b_enabled );
401 updateAudioVolume( ui.defaultVolume->value() ); // First time init
405 /* Input and Codecs Panel Implementation */
406 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
410 ui.DVDDevice->setToolTip(
411 qtr( "If this property is blank, different values\n"
412 "for DVD, VCD, and CDDA are set.\n"
413 "You can define a unique one or configure them \n"
414 "individually in the advanced preferences." ) );
415 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
416 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
417 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
418 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
419 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
420 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
422 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
424 free( psz_cddadiscpath );
425 free( psz_dvddiscpath );
426 free( psz_vcddiscpath );
428 CONFIG_GENERIC_FILE( "dvd", File, ui.DVDLabel,
429 ui.DVDDevice, ui.DVDBrowse );
430 CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
431 ui.recordPath, ui.recordBrowse );
433 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
435 CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
436 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
438 CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
440 /* live555 module prefs */
441 CONFIG_BOOL( "rtsp-tcp",
442 live555TransportRTSP_TCPRadio );
443 if ( !module_exists( "live555" ) )
445 ui.live555TransportRTSP_TCPRadio->hide();
446 ui.live555TransportHTTPRadio->hide();
447 ui.live555TransportLabel->hide();
450 CONFIG_BOOL( "prefer-system-codecs", systemCodecBox );
452 ui.systemCodecBox->hide();
454 CONFIG_BOOL( "ffmpeg-hw", hwAccelBox );
455 optionWidgets.append( ui.DVDDevice );
456 optionWidgets.append( ui.cachingCombo );
457 CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
460 /* Add the things to the ComboBox */
461 #define addToCachingBox( str, cachingNumber ) \
462 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
463 addToCachingBox( N_("Custom"), CachingCustom );
464 addToCachingBox( N_("Lowest latency"), CachingLowest );
465 addToCachingBox( N_("Low latency"), CachingLow );
466 addToCachingBox( N_("Normal"), CachingNormal );
467 addToCachingBox( N_("High latency"), CachingHigh );
468 addToCachingBox( N_("Higher latency"), CachingHigher );
469 #undef addToCachingBox
471 #define TestCaC( name ) \
472 b_cache_equal = b_cache_equal && \
473 ( i_cache == config_GetInt( p_intf, name ) )
475 #define TestCaCi( name, int ) \
476 b_cache_equal = b_cache_equal && \
477 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
478 /* Select the accurate value of the ComboBox */
479 bool b_cache_equal = true;
480 int i_cache = config_GetInt( p_intf, "file-caching");
482 TestCaC( "udp-caching" );
483 if (module_exists ("dvdread"))
484 TestCaC( "dvdread-caching" );
485 if (module_exists ("dvdnav"))
486 TestCaC( "dvdnav-caching" );
487 TestCaC( "tcp-caching" );
488 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
489 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
491 TestCaC( "dshow-caching" );
493 if (module_exists ("v4l"))
494 TestCaC( "v4l-caching" );
495 if (module_exists ("access_jack"))
496 TestCaC( "jack-input-caching" );
497 if (module_exists ("v4l2"))
498 TestCaC( "v4l2-caching" );
499 if (module_exists ("pvr"))
500 TestCaC( "pvr-caching" );
502 if (module_exists ("livedotcom"))
503 TestCaCi( "rtsp-caching", 4 );
504 TestCaCi( "ftp-caching", 2 );
505 TestCaCi( "http-caching", 2 );
506 if (module_exists ("access_realrtsp"))
507 TestCaCi( "realrtsp-caching", 10 );
508 TestCaCi( "mms-caching", 10 );
509 if( b_cache_equal == 1 )
510 ui.cachingCombo->setCurrentIndex(
511 ui.cachingCombo->findData( QVariant( i_cache ) ) );
519 START_SPREFS_CAT( Interface, qtr("Interface Settings") );
520 // ui.defaultLabel->setFont( italicFont );
521 ui.skinsLabel->setText(
522 qtr( "This is VLC's skinnable interface. You can download other skins at" )
523 + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
524 ui.skinsLabel->setFont( italicFont );
527 CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
528 BUTTONACT( ui.assoButton, assoDialog() );
530 ui.languageBox->hide();
534 char *psz_intf = config_GetPsz( p_intf, "intf" );
537 if( strstr( psz_intf, "skin" ) )
538 ui.skins->setChecked( true );
541 ui.qt4->setChecked( true );
545 optionWidgets.append( ui.skins );
546 optionWidgets.append( ui.qt4 );
547 #if !defined(NDEBUG) || !defined( WIN32)
548 ui.stylesCombo->addItem( qtr("System's default") );
549 ui.stylesCombo->addItems( QStyleFactory::keys() );
550 ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
551 getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
552 ui.stylesCombo->insertSeparator( 1 );
554 CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
555 optionWidgets.append( ui.stylesCombo );
557 ui.stylesCombo->hide();
558 optionWidgets.append( NULL );
561 ui.skins_zone->setEnabled( ui.skins->isChecked() );
562 CONNECT( ui.skins, toggled( bool ), ui.skins_zone, setEnabled( bool ) );
564 ui.native_zone->setEnabled( ui.qt4->isChecked() );
565 CONNECT( ui.qt4, toggled( bool ), ui.native_zone, setEnabled( bool ) );
567 CONNECT( ui.displayModeBox, currentIndexChanged( int ),
568 ui.mainPreview, setPreview( int ) );
569 ui.skinsPreview->setPreview( 3 ); /* skins_preview resource index */
571 CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
573 CONFIG_BOOL( "embedded-video", embedVideo );
574 CONFIG_BOOL( "qt-fs-controller", fsController );
575 CONFIG_BOOL( "qt-system-tray", systrayBox );
576 CONFIG_BOOL( "qt-notification", sysPop );
577 CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
578 ui.fileSkin, ui.skinBrowse );
579 CONFIG_BOOL( "qt-video-autoresize", resizingBox );
581 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
586 CONFIG_BOOL( "qt-updates-notif", updatesBox );
587 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
589 ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
590 CONNECT( ui.updatesBox, toggled( bool ),
591 ui.updatesDays, setEnabled( bool ) );
593 ui.updatesBox->hide();
594 ui.updatesDays->hide();
596 /* ONE INSTANCE options */
597 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
598 CONFIG_BOOL( "one-instance", OneInterfaceMode );
599 CONFIG_BOOL( "playlist-enqueue",
600 EnqueueOneInterfaceMode );
601 ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
602 CONNECT( ui.OneInterfaceMode, toggled( bool ),
603 ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
605 ui.OneInterfaceBox->hide();
607 /* RECENTLY PLAYED options */
608 CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
609 ui.recentlyPlayedFilters, setEnabled( bool ) );
610 ui.recentlyPlayedFilters->setEnabled( false );
611 CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
612 CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
613 recentlyPlayedFilters );
617 START_SPREFS_CAT( Subtitles,
618 qtr("Subtitles & On Screen Display Settings") );
619 CONFIG_BOOL( "osd", OSDBox);
620 CONFIG_BOOL( "video-title-show", OSDTitleBox);
623 CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
625 CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
627 CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
628 CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
630 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
631 ui.fontSizeLabel, fontSize );
632 CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
634 CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
640 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
642 QGridLayout *gLayout = new QGridLayout;
643 panel->setLayout( gLayout );
646 panel_label->setText( qtr( "Configure Hotkeys" ) );
647 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
648 this, gLayout, line );
649 controls.append( control );
653 QFrame *sepline = new QFrame;
654 sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
655 gLayout->addWidget( sepline, line, 0, 1, -1 );
659 p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
660 control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
661 p_config, false, this, gLayout, line );
662 controls.append( control );
668 panel_layout->addWidget( panel_label );
669 panel_layout->addWidget( title_line );
673 QScrollArea *scroller= new QScrollArea;
674 scroller->setWidget( panel );
675 scroller->setWidgetResizable( true );
676 scroller->setFrameStyle( QFrame::NoFrame );
677 panel_layout->addWidget( scroller );
681 panel_layout->addWidget( panel );
682 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
685 setLayout( panel_layout );
687 #undef END_SPREFS_CAT
688 #undef START_SPREFS_CAT
689 #undef CONFIG_GENERIC_FILE
690 #undef CONFIG_GENERIC_NO_BOOL
691 #undef CONFIG_GENERIC_NO_UI
692 #undef CONFIG_GENERIC
697 void SPrefsPanel::updateAudioOptions( int number)
699 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
700 ->itemData( number ).toString();
702 optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
704 /* optionWidgets[ossW] can be NULL */
705 if( optionWidgets[ossW] )
706 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
707 /* optionWidgets[alsaW] can be NULL */
708 if( optionWidgets[alsaW] )
709 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
711 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
712 optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
713 value == "aout_directx" || value == "waveout" ) );
717 SPrefsPanel::~SPrefsPanel()
719 qDeleteAll( controls ); controls.clear();
722 void SPrefsPanel::updateAudioVolume( int volume )
724 qobject_cast<QSpinBox *>(optionWidgets[volLW])
725 ->setValue( volume * 100 / 256 );
729 /* Function called from the main Preferences dialog on each SPrefs Panel */
730 void SPrefsPanel::apply()
732 /* Generic save for ever panel */
733 QList<ConfigControl *>::Iterator i;
734 for( i = controls.begin() ; i != controls.end() ; i++ )
736 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
737 c->doApply( p_intf );
742 case SPrefsInputAndCodecs:
744 /* Device default selection */
745 char *psz_devicepath =
746 strdup( qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() ) );
747 if( !EMPTY_STR( psz_devicepath ) )
749 config_PutPsz( p_intf, "dvd", psz_devicepath );
750 config_PutPsz( p_intf, "vcd", psz_devicepath );
751 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
752 free( psz_devicepath );
755 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
756 #define CaC( name ) CaCi( name, 1 )
758 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
759 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
762 CaC( "udp-caching" );
763 if (module_exists ("dvdread" ))
764 CaC( "dvdread-caching" );
765 if (module_exists ("dvdnav" ))
766 CaC( "dvdnav-caching" );
767 CaC( "tcp-caching" ); CaC( "vcd-caching" );
768 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
769 CaC( "screen-caching" ); CaC( "bd-caching" );
770 CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
771 CaCi( "http-caching", 2 );
772 if (module_exists ("access_realrtsp" ))
773 CaCi( "realrtsp-caching", 10 );
774 CaCi( "mms-caching", 10 );
776 CaC( "dshow-caching" );
778 if (module_exists ( "v4l" ))
779 CaC( "v4l-caching" );
780 if (module_exists ( "access_jack" ))
781 CaC( "jack-input-caching" );
782 if (module_exists ( "v4l2" ))
783 CaC( "v4l2-caching" );
784 if (module_exists ( "pvr" ))
785 CaC( "pvr-caching" );
787 //CaCi( "dv-caching" ) too short...
795 case SPrefsInterface:
797 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
798 config_PutPsz( p_intf, "intf", "skins2" );
799 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
800 config_PutPsz( p_intf, "intf", "qt" );
801 if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
802 getSettings()->setValue( "MainWindow/QtStyle",
803 qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
811 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
812 if( b_checked && !qs_filter.contains( "volnorm" ) )
813 qs_filter.append( "volnorm" );
814 if( !b_checked && qs_filter.contains( "volnorm" ) )
815 qs_filter.removeAll( "volnorm" );
818 qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
820 if( b_checked && !qs_filter.contains( "headphone" ) )
821 qs_filter.append( "headphone" );
822 if( !b_checked && qs_filter.contains( "headphone" ) )
823 qs_filter.removeAll( "headphone" );
825 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
831 void SPrefsPanel::clean()
834 void SPrefsPanel::lastfm_Changed( int i_state )
836 if( i_state == Qt::Checked )
837 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
838 else if( i_state == Qt::Unchecked )
839 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
842 void SPrefsPanel::changeStyle( QString s_style )
844 QApplication::setStyle( s_style );
846 /* force refresh on all widgets */
847 QWidgetList widgets = QApplication::allWidgets();
848 QWidgetList::iterator it = widgets.begin();
849 while( it != widgets.end() ) {
856 #include <QDialogButtonBox>
857 #include <QHeaderView>
858 #include "util/registry.hpp"
861 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
862 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
865 const char* psz_VLC = "VLC";
866 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
868 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
870 current->setCheckState( 0, Qt::Checked );
875 current->setCheckState( 0, Qt::Unchecked );
878 listAsso.append( current );
882 void SPrefsPanel::assoDialog()
884 LPAPPASSOCREGUI p_appassoc;
887 if( S_OK == CoCreateInstance( &clsid_IApplication2,
888 NULL, CLSCTX_INPROC_SERVER,
889 &IID_IApplicationAssociationRegistrationUI,
890 (void **)&p_appassoc) )
892 if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
901 QDialog *d = new QDialog( this );
902 QGridLayout *assoLayout = new QGridLayout( d );
904 QTreeWidget *filetypeList = new QTreeWidget;
905 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
906 filetypeList->header()->hide();
908 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
910 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
911 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
912 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
914 filetypeList->addTopLevelItem( audioType );
915 filetypeList->addTopLevelItem( videoType );
916 filetypeList->addTopLevelItem( otherType );
918 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
919 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
920 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
922 QTreeWidgetItem *currentItem;
925 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
926 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
927 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
929 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
930 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
931 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
932 aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
933 audioType->setCheckState( 0, ( i_temp > 0 ) ?
934 ( ( i_temp == audioType->childCount() ) ?
935 Qt::Checked : Qt::PartiallyChecked )
939 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
940 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
941 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
942 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
943 aTv( ".mts" ); aTv( ".mxf" );
944 aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".ts" );
945 aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
946 videoType->setCheckState( 0, ( i_temp > 0 ) ?
947 ( ( i_temp == audioType->childCount() ) ?
948 Qt::Checked : Qt::PartiallyChecked )
952 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
953 aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
954 otherType->setCheckState( 0, ( i_temp > 0 ) ?
955 ( ( i_temp == audioType->childCount() ) ?
956 Qt::Checked : Qt::PartiallyChecked )
963 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
964 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
965 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
966 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
967 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
969 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
971 CONNECT( closeButton, clicked(), this, saveAsso() );
972 CONNECT( clearButton, clicked(), d, reject() );
973 d->resize( 300, 400 );
980 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
982 std::string s_path( "VLC" ); s_path += psz_ext;
983 std::string s_path2 = s_path;
985 /* Save a backup if already assigned */
986 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
988 if( psz_value && strlen( psz_value ) > 0 )
989 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
992 /* Put a "link" to VLC.EXT as default */
993 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
995 /* Create the needed Key if they weren't done in the installer */
996 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
998 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
999 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
1000 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
1002 /* Get the installer path */
1003 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1004 std::string str_temp; str_temp.assign(
1005 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
1007 if( str_temp.size() )
1009 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
1010 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
1012 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
1013 "", str_temp.append(",0").c_str() );
1019 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1021 char psz_VLC[] = "VLC";
1022 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
1024 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
1027 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1029 qvReg->WriteRegistryString( psz_ext, "", psz_value );
1031 qvReg->DeleteKey( psz_ext, "VLC.backup" );
1033 delete( psz_value );
1035 void SPrefsPanel::saveAsso()
1037 QVLCRegistry * qvReg;
1038 for( int i = 0; i < listAsso.size(); i ++ )
1040 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
1041 if( listAsso[i]->checkState( 0 ) > 0 )
1043 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1047 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1051 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();