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 <QtAlgorithms>
47 #define ICON_HEIGHT 64
49 /*********************************************************************
50 * The List of categories
51 *********************************************************************/
52 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
53 QWidget( _parent ), p_intf( _p_intf )
55 QVBoxLayout *layout = new QVBoxLayout();
57 QButtonGroup *buttonGroup = new QButtonGroup( this );
58 buttonGroup->setExclusive ( true );
59 CONNECT( buttonGroup, buttonClicked ( int ),
60 this, switchPanel( int ) );
62 short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
64 #define ADD_CATEGORY( button, label, icon, numb ) \
65 QToolButton * button = new QToolButton( this ); \
66 button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) ); \
67 button->setText( label ); \
68 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
69 button->setIconSize( QSize( icon_height, icon_height ) ); \
70 button->resize( icon_height + 6 , icon_height + 6 ); \
71 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
72 button->setAutoRaise( true ); \
73 button->setCheckable( true ); \
74 buttonGroup->addButton( button, numb ); \
75 layout->addWidget( button );
77 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
78 spref_cone_Interface_64.png, 0 );
79 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
80 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
81 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
82 spref_cone_Subtitles_64.png, 3 );
83 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
84 spref_cone_Input_64.png, 4 );
85 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
87 SPrefsInterface->setChecked( true );
88 layout->setMargin( 0 );
89 layout->setSpacing( 1 );
91 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
96 void SPrefsCatList::switchPanel( int i )
98 emit currentItemChanged( i );
101 /*********************************************************************
103 *********************************************************************/
104 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
105 int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
107 module_config_t *p_config;
108 ConfigControl *control;
111 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
112 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
115 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
116 p_config, label, ui.qcontrol, false ); \
117 controls.append( control ); \
120 #define CONFIG_GENERIC2( 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, qcontrol, false ); \
126 controls.append( control ); \
130 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
131 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
134 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
135 p_config, label, ui.qcontrol ); \
136 controls.append( control ); \
139 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
140 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
143 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
144 p_config, label, qcontrol, qbutton ); \
145 controls.append( control ); \
148 #define START_SPREFS_CAT( name , label ) \
149 case SPrefs ## name: \
151 Ui::SPrefs ## name ui; \
152 ui.setupUi( panel ); \
153 panel_label->setText( label );
155 #define END_SPREFS_CAT \
159 QVBoxLayout *panel_layout = new QVBoxLayout();
160 QWidget *panel = new QWidget();
161 panel_layout->setMargin( 3 );
164 QLabel *panel_label = new QLabel;
165 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
166 labelFont.setPointSize( labelFont.pointSize() + 6 );
167 labelFont.setFamily( "Verdana" );
168 panel_label->setFont( labelFont );
171 QFrame *title_line = new QFrame;
172 title_line->setFrameShape(QFrame::HLine);
173 title_line->setFrameShadow(QFrame::Sunken);
175 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
176 italicFont.setItalic( true );
180 /******************************
181 * VIDEO Panel Implementation *
182 ******************************/
183 START_SPREFS_CAT( Video , qtr("Video Settings") );
184 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
186 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
187 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
188 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
189 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
190 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
191 CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
194 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
195 CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
197 CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
199 ui.directXBox->setVisible( false );
200 ui.hwYUVBox->setVisible( false );
203 CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterLabel, deinterlaceBox );
204 CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
206 CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
207 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
208 CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
209 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
210 snapshotsSequentialNumbering );
211 CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
215 /******************************
216 * AUDIO Panel Implementation *
217 ******************************/
218 START_SPREFS_CAT( Audio, qtr("Audio Settings") );
220 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
222 #define audioCommon( name ) \
223 QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
224 QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
225 name ## Layout->setMargin( 0 ); \
226 name ## Layout->setSpacing( 0 ); \
227 QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
228 name ## Label->setMinimumSize(QSize(100, 0)); \
229 name ## Layout->addWidget( name ## Label ); \
231 #define audioControl( name) \
232 audioCommon( name ) \
233 QComboBox * name ## Device = new QComboBox( name ## Control ); \
234 name ## Layout->addWidget( name ## Device ); \
235 name ## Label->setBuddy( name ## Device ); \
236 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
238 #define audioControl2( name) \
239 audioCommon( name ) \
240 QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
241 name ## Layout->addWidget( name ## Device ); \
242 name ## Label->setBuddy( name ## Device ); \
243 QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
244 name ## Layout->addWidget( name ## Browse ); \
245 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
247 /* hide if necessary */
248 ui.lastfm_user_edit->hide();
249 ui.lastfm_user_label->hide();
250 ui.lastfm_pass_edit->hide();
251 ui.lastfm_pass_label->hide();
253 /* Build if necessary */
254 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
256 audioControl( DirectX );
257 optionWidgets.append( DirectXControl );
258 CONFIG_GENERIC2( "directx-audio-device", IntegerList,
259 NULL, DirectXDevice );
261 if( module_exists( "alsa" ) )
263 audioControl( alsa );
264 optionWidgets.append( alsaControl );
266 CONFIG_GENERIC2( "alsa-audio-device" , StringList, NULL,
270 optionWidgets.append( NULL );
271 if( module_exists( "oss" ) )
273 audioControl2( OSS );
274 optionWidgets.append( OSSControl );
275 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
279 optionWidgets.append( NULL );
283 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
285 CONNECT( ui.defaultVolume, valueChanged( int ),
286 this, updateAudioVolume( int ) );
288 CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
289 preferredAudioLanguage );
291 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
292 CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
293 CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
296 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
298 CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
300 CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
303 /* Audio Output Specifics */
304 CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
306 CONNECT( ui.outputModule, currentIndexChanged( int ),
307 this, updateAudioOptions( int ) );
309 /* File output exists on all platforms */
310 CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
311 ui.fileName, ui.fileBrowseButton );
313 optionWidgets.append( ui.fileControl );
314 optionWidgets.append( ui.outputModule );
315 optionWidgets.append( ui.volNormBox );
316 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
317 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
318 optionWidgets.append( ui.volumeValue );
319 optionWidgets.append( ui.headphoneEffect );
320 updateAudioOptions( ui.outputModule->currentIndex() );
323 if( module_exists( "audioscrobbler" ) )
325 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
327 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
330 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
331 ui.lastfm->setChecked( true );
333 ui.lastfm->setChecked( false );
334 CONNECT( ui.lastfm, stateChanged( int ),
335 this, lastfm_Changed( int ) );
341 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
342 setEnabled( bool ) );
344 char* psz = config_GetPsz( p_intf, "audio-filter" );
345 qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
348 bool b_enabled = ( qs_filter.contains( "volnorm" ) );
349 ui.volNormBox->setChecked( b_enabled );
350 ui.volNormSpin->setEnabled( b_enabled );
352 b_enabled = ( qs_filter.contains( "headphone" ) );
353 ui.headphoneEffect->setChecked( b_enabled );
356 updateAudioVolume( ui.defaultVolume->value() ); // First time init
360 /* Input and Codecs Panel Implementation */
361 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
365 ui.DVDDevice->setToolTip(
366 qtr( "If this property is blank, different values\n"
367 "for DVD, VCD, and CDDA are set.\n"
368 "You can define a unique one or configure them \n"
369 "individually in the advanced preferences." ) );
370 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
371 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
372 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
373 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
374 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
375 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
377 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
379 free( psz_cddadiscpath );
380 free( psz_dvddiscpath );
381 free( psz_vcddiscpath );
384 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
386 CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
387 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
389 CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
390 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
392 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
394 ui.systemCodecBox->hide();
396 optionWidgets.append( ui.DVDDevice );
397 optionWidgets.append( ui.cachingCombo );
400 /* Add the things to the ComboBox */
401 #define addToCachingBox( str, cachingNumber ) \
402 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
403 addToCachingBox( N_("Custom"), CachingCustom );
404 addToCachingBox( N_("Lowest latency"), CachingLowest );
405 addToCachingBox( N_("Low latency"), CachingLow );
406 addToCachingBox( N_("Normal"), CachingNormal );
407 addToCachingBox( N_("High latency"), CachingHigh );
408 addToCachingBox( N_("Higher latency"), CachingHigher );
410 #define TestCaC( name ) \
411 b_cache_equal = b_cache_equal && \
412 ( i_cache == config_GetInt( p_intf, name ) )
414 #define TestCaCi( name, int ) \
415 b_cache_equal = b_cache_equal && \
416 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
417 /* Select the accurate value of the ComboBox */
418 bool b_cache_equal = true;
419 int i_cache = config_GetInt( p_intf, "file-caching");
421 TestCaC( "udp-caching" );
422 if (module_exists ("dvdread"))
423 TestCaC( "dvdread-caching" );
424 if (module_exists ("dvdnav"))
425 TestCaC( "dvdnav-caching" );
426 TestCaC( "tcp-caching" );
427 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
428 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
430 TestCaC( "dshow-caching" );
432 if (module_exists ("v4l"))
433 TestCaC( "v4l-caching" );
434 if (module_exists ("access_jack"))
435 TestCaC( "jack-input-caching" );
436 if (module_exists ("v4l2"))
437 TestCaC( "v4l2-caching" );
438 if (module_exists ("pvr"))
439 TestCaC( "pvr-caching" );
441 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
442 TestCaCi( "http-caching", 4 );
443 if (module_exists ("access_realrtsp"))
444 TestCaCi( "realrtsp-caching", 10 );
445 TestCaCi( "mms-caching", 19 );
446 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
447 ui.cachingCombo->findData( QVariant( i_cache ) ) );
453 START_SPREFS_CAT( Interface, qtr("Interface Settings") );
454 ui.defaultLabel->setFont( italicFont );
455 ui.skinsLabel->setText(
456 qtr( "This is VLC's skinnable interface. You can download other skins at" )
457 + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
458 ui.skinsLabel->setFont( italicFont );
461 CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
462 BUTTONACT( ui.assoButton, assoDialog() );
465 ui.languageLabel->hide();
467 ui.assoButton->hide();
471 char *psz_intf = config_GetPsz( p_intf, "intf" );
474 if( strstr( psz_intf, "skin" ) )
475 ui.skins->setChecked( true );
476 else if( strstr( psz_intf, "qt" ) )
477 ui.qt4->setChecked( true );
481 optionWidgets.append( ui.skins );
482 optionWidgets.append( ui.qt4 );
484 CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
486 CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
487 CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
488 CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
489 CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
490 ui.fileSkin, ui.skinBrowse );
491 CONFIG_GENERIC( "qt-video-autoresize", Bool, NULL, resizingBox );
493 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
498 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
499 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
501 CONNECT( ui.updatesBox, toggled( bool ),
502 ui.updatesDays, setEnabled( bool ) );
504 ui.updatesBox->hide();
505 ui.updatesDays->hide();
507 /* ONE INSTANCE options */
508 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
509 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
510 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
511 EnqueueOneInterfaceMode );
513 ui.OneInterfaceBox->hide();
515 /* RECENTLY PLAYED options */
516 CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
517 ui.recentlyPlayedFilters, setEnabled( bool ) );
518 ui.recentlyPlayedFilters->setEnabled( false );
519 CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
520 CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
521 recentlyPlayedFilters );
525 START_SPREFS_CAT( Subtitles,
526 qtr("Subtitles & On Screen Display Settings") );
527 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
528 CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
531 CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
533 CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
535 CONFIG_GENERIC_FILE( "freetype-font", File, ui.fontLabel, ui.font,
537 CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
539 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
540 ui.fontSizeLabel, fontSize );
541 CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
543 CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
549 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
551 QGridLayout *gLayout = new QGridLayout;
552 panel->setLayout( gLayout );
555 panel_label->setText( qtr( "Configure Hotkeys" ) );
556 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
557 this, gLayout, line );
558 controls.append( control );
561 p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
562 control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
563 p_config, false, this, gLayout, line );
564 controls.append( control );
570 panel_layout->addWidget( panel_label );
571 panel_layout->addWidget( title_line );
575 QScrollArea *scroller= new QScrollArea;
576 scroller->setWidget( panel );
577 scroller->setWidgetResizable( true );
578 scroller->setFrameStyle( QFrame::NoFrame );
579 panel_layout->addWidget( scroller );
583 panel_layout->addWidget( panel );
584 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
587 setLayout( panel_layout );
590 void SPrefsPanel::updateAudioOptions( int number)
592 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
593 ->itemData( number ).toString();
595 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
597 /* optionWidgets[ossW] can be NULL */
598 if( optionWidgets[ossW] )
599 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
600 /* optionWidgets[alsaW] can be NULL */
601 if( optionWidgets[alsaW] )
602 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
604 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
608 SPrefsPanel::~SPrefsPanel()
610 qDeleteAll( controls ); controls.clear();
613 void SPrefsPanel::updateAudioVolume( int volume )
615 qobject_cast<QSpinBox *>(optionWidgets[volLW])
616 ->setValue( volume * 100 / 256 );
620 /* Function called from the main Preferences dialog on each SPrefs Panel */
621 void SPrefsPanel::apply()
623 /* Generic save for ever panel */
624 QList<ConfigControl *>::Iterator i;
625 for( i = controls.begin() ; i != controls.end() ; i++ )
627 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
628 c->doApply( p_intf );
633 case SPrefsInputAndCodecs:
635 /* Device default selection */
636 const char *psz_devicepath =
637 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
638 if( !EMPTY_STR( psz_devicepath ) )
640 config_PutPsz( p_intf, "dvd", psz_devicepath );
641 config_PutPsz( p_intf, "vcd", psz_devicepath );
642 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
645 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
646 #define CaC( name ) CaCi( name, 1 )
648 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
649 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
652 CaC( "udp-caching" );
653 if (module_exists ("dvdread" ))
654 CaC( "dvdread-caching" );
655 if (module_exists ("dvdnav" ))
656 CaC( "dvdnav-caching" );
657 CaC( "tcp-caching" ); CaC( "vcd-caching" );
658 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
659 CaC( "screen-caching" ); CaC( "bd-caching" );
660 CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
661 CaCi( "http-caching", 2 );
662 if (module_exists ("access_realrtsp" ))
663 CaCi( "realrtsp-caching", 10 );
664 CaCi( "mms-caching", 10 );
666 CaC( "dshow-caching" );
668 if (module_exists ( "v4l" ))
669 CaC( "v4l-caching" );
670 if (module_exists ( "access_jack" ))
671 CaC( "jack-input-caching" );
672 if (module_exists ( "v4l2" ))
673 CaC( "v4l2-caching" );
674 if (module_exists ( "pvr" ))
675 CaC( "pvr-caching" );
677 //CaCi( "dv-caching" ) too short...
683 case SPrefsInterface:
685 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
686 config_PutPsz( p_intf, "intf", "skins2" );
687 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
688 config_PutPsz( p_intf, "intf", "qt" );
695 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
696 if( b_checked && !qs_filter.contains( "volnorm" ) )
697 qs_filter.append( "volnorm" );
698 if( !b_checked && qs_filter.contains( "volnorm" ) )
699 qs_filter.removeAll( "volnorm" );
702 qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
704 if( b_checked && !qs_filter.contains( "headphone" ) )
705 qs_filter.append( "headphone" );
706 if( !b_checked && qs_filter.contains( "headphone" ) )
707 qs_filter.removeAll( "headphone" );
709 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
715 void SPrefsPanel::clean()
718 void SPrefsPanel::lastfm_Changed( int i_state )
720 if( i_state == Qt::Checked )
721 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
722 else if( i_state == Qt::Unchecked )
723 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
727 #include <QDialogButtonBox>
728 #include <QHeaderView>
729 #include "util/registry.hpp"
731 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
732 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
735 const char* psz_VLC = "VLC";
736 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
738 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
740 current->setCheckState( 0, Qt::Checked );
745 current->setCheckState( 0, Qt::Unchecked );
748 listAsso.append( current );
752 void SPrefsPanel::assoDialog()
754 QDialog *d = new QDialog( this );
755 QGridLayout *assoLayout = new QGridLayout( d );
757 QTreeWidget *filetypeList = new QTreeWidget;
758 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
759 filetypeList->header()->hide();
761 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
763 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
764 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
765 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
767 filetypeList->addTopLevelItem( audioType );
768 filetypeList->addTopLevelItem( videoType );
769 filetypeList->addTopLevelItem( otherType );
771 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
772 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
773 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
775 QTreeWidgetItem *currentItem;
778 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
779 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
780 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
782 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
783 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
784 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
785 aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
786 audioType->setCheckState( 0, ( i_temp > 0 ) ?
787 ( ( i_temp == audioType->childCount() ) ?
788 Qt::Checked : Qt::PartiallyChecked )
792 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
793 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
794 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
795 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
796 aTv( ".mts" ); aTv( ".mxf" );
797 aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".ts" );
798 aTv( ".vob" ); aTv( ".wmv" );
799 videoType->setCheckState( 0, ( i_temp > 0 ) ?
800 ( ( i_temp == audioType->childCount() ) ?
801 Qt::Checked : Qt::PartiallyChecked )
805 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
807 otherType->setCheckState( 0, ( i_temp > 0 ) ?
808 ( ( i_temp == audioType->childCount() ) ?
809 Qt::Checked : Qt::PartiallyChecked )
812 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
813 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
814 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
815 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
816 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
818 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
820 CONNECT( closeButton, clicked(), this, saveAsso() );
821 CONNECT( clearButton, clicked(), d, reject() );
822 d->resize( 300, 400 );
829 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
831 std::string s_path( "VLC" ); s_path += psz_ext;
832 std::string s_path2 = s_path;
834 /* Save a backup if already assigned */
835 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
837 if( psz_value && strlen( psz_value ) > 0 )
838 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
841 /* Put a "link" to VLC.EXT as default */
842 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
844 /* Create the needed Key if they weren't done in the installer */
845 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
847 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
848 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
849 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
851 /* Get the installer path */
852 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
853 std::string str_temp; str_temp.assign(
854 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
856 if( str_temp.size() )
858 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
859 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
861 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
862 "", str_temp.append(",0").c_str() );
868 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
870 char psz_VLC[] = "VLC";
871 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
873 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
876 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
878 qvReg->WriteRegistryString( psz_ext, "", psz_value );
880 qvReg->DeleteKey( psz_ext, "VLC.backup" );
884 void SPrefsPanel::saveAsso()
886 QVLCRegistry * qvReg;
887 for( int i = 0; i < listAsso.size(); i ++ )
889 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
890 if( listAsso[i]->checkState( 0 ) > 0 )
892 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
896 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
900 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();