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>
43 #include <QtAlgorithms>
47 #define ICON_HEIGHT 64
48 #define BUTTON_HEIGHT 74
50 /*********************************************************************
51 * The List of categories
52 *********************************************************************/
53 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
54 QWidget( _parent ), p_intf( _p_intf )
56 QVBoxLayout *layout = new QVBoxLayout();
58 QButtonGroup *buttonGroup = new QButtonGroup( this );
59 buttonGroup->setExclusive ( true );
60 CONNECT( buttonGroup, buttonClicked ( int ),
61 this, switchPanel( int ) );
63 #define ADD_CATEGORY( button, label, icon, numb ) \
64 QToolButton * button = new QToolButton( this ); \
65 button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) ); \
66 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
67 button->setText( label ); \
68 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
69 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
70 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
71 button->setAutoRaise( true ); \
72 button->setCheckable( true ); \
73 buttonGroup->addButton( button, numb ); \
74 layout->addWidget( button );
76 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
77 spref_cone_Interface_64.png, 0 );
78 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
79 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
80 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
81 spref_cone_Subtitles_64.png, 3 );
82 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
83 spref_cone_Input_64.png, 4 );
84 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
86 SPrefsInterface->setChecked( true );
87 layout->setMargin( 0 );
88 layout->setSpacing( 1 );
90 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
95 void SPrefsCatList::switchPanel( int i )
97 emit currentItemChanged( i );
100 /*********************************************************************
102 *********************************************************************/
103 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
104 int _number ) : QWidget( _parent ), p_intf( _p_intf )
106 module_config_t *p_config;
107 ConfigControl *control;
110 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
111 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
114 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
115 p_config, label, ui.qcontrol, false ); \
116 controls.append( control ); \
119 #define CONFIG_GENERIC2( option, type, label, qcontrol ) \
120 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
123 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
124 p_config, label, qcontrol, false ); \
125 controls.append( control ); \
129 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
130 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
133 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
134 p_config, label, ui.qcontrol ); \
135 controls.append( control ); \
138 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
139 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
142 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
143 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("General 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, NULL, outputModule );
194 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
195 CONFIG_GENERIC( "directx-device", StringList, NULL,
197 CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
199 ui.directXBox->setVisible( false );
200 ui.hwYUVBox->setVisible( false );
203 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
204 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
205 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
206 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
207 snapshotsSequentialNumbering );
208 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
212 /******************************
213 * AUDIO Panel Implementation *
214 ******************************/
215 START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
217 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
219 #define audioCommon( name ) \
220 QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
221 QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
222 name ## Layout->setMargin( 0 ); \
223 name ## Layout->setSpacing( 0 ); \
224 QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
225 name ## Label->setMinimumSize(QSize(100, 0)); \
226 name ## Layout->addWidget( name ## Label ); \
228 #define audioControl( name) \
229 audioCommon( name ) \
230 QComboBox * name ## Device = new QComboBox( name ## Control ); \
231 name ## Layout->addWidget( name ## Device ); \
232 name ## Label->setBuddy( name ## Device ); \
233 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
235 #define audioControl2( name) \
236 audioCommon( name ) \
237 QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
238 name ## Layout->addWidget( name ## Device ); \
239 name ## Label->setBuddy( name ## Device ); \
240 QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
241 name ## Layout->addWidget( name ## Browse ); \
242 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
244 /* hide if necessary */
245 ui.lastfm_user_edit->hide();
246 ui.lastfm_user_label->hide();
247 ui.lastfm_pass_edit->hide();
248 ui.lastfm_pass_label->hide();
250 /* Build if necessary */
251 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
253 audioControl( DirectX );
254 optionWidgets.append( DirectXControl );
255 CONFIG_GENERIC2( "directx-audio-device", IntegerList,
256 DirectXLabel, DirectXDevice );
258 if( module_exists( "alsa" ) )
260 audioControl( alsa );
261 optionWidgets.append( alsaControl );
263 CONFIG_GENERIC2( "alsa-audio-device" , StringList , alsaLabel,
267 optionWidgets.append( NULL );
268 if( module_exists( "oss" ) )
270 audioControl2( OSS );
271 optionWidgets.append( OSSControl );
272 CONFIG_GENERIC_FILE( "oss-audio-device" , File , OSSLabel, OSSDevice,
276 optionWidgets.append( NULL );
279 /* General Audio Options */
280 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
282 CONNECT( ui.defaultVolume, valueChanged( int ),
283 this, updateAudioVolume( int ) );
285 CONFIG_GENERIC( "audio-language" , String , NULL,
286 preferredAudioLanguage );
288 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
289 CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
290 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
293 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
295 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
297 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
299 /* Audio Output Specifics */
300 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
302 CONNECT( ui.outputModule, currentIndexChanged( int ),
303 this, updateAudioOptions( int ) );
305 /* File output exists on all platforms */
306 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
307 ui.fileName, ui.fileBrowseButton );
309 optionWidgets.append( ui.fileControl );
310 optionWidgets.append( ui.outputModule );
311 optionWidgets.append( ui.volNormBox );
312 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
314 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
316 optionWidgets.append( ui.volumeValue );
317 updateAudioOptions( ui.outputModule->currentIndex() );
320 if( module_exists( "audioscrobbler" ) )
322 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
324 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
327 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
328 ui.lastfm->setChecked( true );
330 ui.lastfm->setChecked( false );
331 CONNECT( ui.lastfm, stateChanged( int ), this ,
332 lastfm_Changed( int ) );
339 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
340 setEnabled( bool ) );
341 char* psz = config_GetPsz( p_intf, "audio-filter" );
342 qs_filter = qfu( psz );
344 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
346 ui.volNormBox->setChecked( b_normalizer );
347 ui.volNormSpin->setEnabled( b_normalizer );
351 updateAudioVolume( ui.defaultVolume->value() ); // First time init
355 /* Input and Codecs Panel Implementation */
356 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
360 ui.DVDDevice->setToolTip(
361 qtr( "If this property is blank, different values\n"
362 "for DVD, VCD, and CDDA are set.\n"
363 "You can define a unique one or configure them \n"
364 "individually in the advanced preferences." ) );
365 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
366 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
367 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
368 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
369 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
370 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
372 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
374 free( psz_cddadiscpath );
375 free( psz_dvddiscpath );
376 free( psz_vcddiscpath );
379 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
380 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
381 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
382 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
383 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
385 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
387 ui.systemCodecBox->hide();
390 char* psz = config_GetPsz( p_intf, "access-filter" );
391 qs_filter = qfu( psz );
393 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
394 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
395 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
397 optionWidgets.append( ui.dumpBox );
398 optionWidgets.append( ui.bandwidthBox );
399 optionWidgets.append( ui.timeshiftBox );
400 optionWidgets.append( ui.DVDDevice );
401 optionWidgets.append( ui.cachingCombo );
404 /* Add the things to the ComboBox */
405 #define addToCachingBox( str, cachingNumber ) \
406 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
407 addToCachingBox( N_("Custom"), CachingCustom );
408 addToCachingBox( N_("Lowest latency"), CachingLowest );
409 addToCachingBox( N_("Low latency"), CachingLow );
410 addToCachingBox( N_("Normal"), CachingNormal );
411 addToCachingBox( N_("High latency"), CachingHigh );
412 addToCachingBox( N_("Higher latency"), CachingHigher );
414 #define TestCaC( name ) \
415 b_cache_equal = b_cache_equal && \
416 ( i_cache == config_GetInt( p_intf, name ) )
418 #define TestCaCi( name, int ) \
419 b_cache_equal = b_cache_equal && \
420 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
421 /* Select the accurate value of the ComboBox */
422 bool b_cache_equal = true;
423 int i_cache = config_GetInt( p_intf, "file-caching");
425 TestCaC( "udp-caching" );
426 if (module_exists ("dvdread"))
427 TestCaC( "dvdread-caching" );
428 if (module_exists ("dvdnav"))
429 TestCaC( "dvdnav-caching" );
430 TestCaC( "tcp-caching" );
431 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
432 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
434 TestCaC( "dshow-caching" );
436 if (module_exists ("v4l"))
437 TestCaC( "v4l-caching" );
438 if (module_exists ("access_jack"))
439 TestCaC( "jack-input-caching" );
440 if (module_exists ("v4l2"))
441 TestCaC( "v4l2-caching" );
442 if (module_exists ("pvr"))
443 TestCaC( "pvr-caching" );
445 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
446 TestCaCi( "http-caching", 4 );
447 if (module_exists ("access_realrtsp"))
448 TestCaCi( "realrtsp-caching", 10 );
449 TestCaCi( "mms-caching", 19 );
450 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
451 ui.cachingCombo->findData( QVariant( i_cache ) ) );
457 START_SPREFS_CAT( Interface, qtr("Interface Settings") );
458 ui.defaultLabel->setFont( italicFont );
459 ui.skinsLabel->setFont( italicFont );
462 CONFIG_GENERIC( "language", StringList, NULL, language );
463 BUTTONACT( ui.assoButton, assoDialog() );
466 ui.languageLabel->hide();
468 ui.assoButton->hide();
472 char *psz_intf = config_GetPsz( p_intf, "intf" );
475 if( strstr( psz_intf, "skin" ) )
476 ui.skins->setChecked( true );
477 else if( strstr( psz_intf, "qt" ) )
478 ui.qt4->setChecked( true );
482 optionWidgets.append( ui.skins );
483 optionWidgets.append( ui.qt4 );
485 CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
487 CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
488 CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
489 CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
490 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
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, NULL,
521 recentlyPlayedFilters );
525 START_SPREFS_CAT( Subtitles, qtr("Subtitles & On Screen Display Settings") );
526 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
527 CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
530 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
531 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
532 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
534 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
535 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
537 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
538 CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, NULL, subsPosition );
544 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
546 QGridLayout *gLayout = new QGridLayout;
547 panel->setLayout( gLayout );
550 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
551 this, gLayout, line );
553 panel_label->setText( qtr( "Configure Hotkeys" ) );
554 controls.append( control );
560 panel_layout->addWidget( panel_label );
561 panel_layout->addWidget( title_line );
562 panel_layout->addWidget( panel );
563 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
565 setLayout( panel_layout );
568 void SPrefsPanel::updateAudioOptions( int number)
570 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
571 ->itemData( number ).toString();
573 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
575 /* optionWidgets[ossW] can be NULL */
576 if( optionWidgets[ossW] )
577 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
578 /* optionWidgets[alsaW] can be NULL */
579 if( optionWidgets[alsaW] )
580 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
582 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
586 SPrefsPanel::~SPrefsPanel()
588 qDeleteAll( controls ); controls.clear();
591 void SPrefsPanel::updateAudioVolume( int volume )
593 qobject_cast<QSpinBox *>(optionWidgets[volLW])
594 ->setValue( volume * 100 / 256 );
598 /* Function called from the main Preferences dialog on each SPrefs Panel */
599 void SPrefsPanel::apply()
601 /* Generic save for ever panel */
602 QList<ConfigControl *>::Iterator i;
603 for( i = controls.begin() ; i != controls.end() ; i++ )
605 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
606 c->doApply( p_intf );
611 case SPrefsInputAndCodecs:
613 /* Device default selection */
614 char *psz_devicepath =
615 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
616 if( !EMPTY_STR( psz_devicepath ) )
618 config_PutPsz( p_intf, "dvd", psz_devicepath );
619 config_PutPsz( p_intf, "vcd", psz_devicepath );
620 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
624 #define saveBox( name, box ) {\
625 if( box->isChecked() ) { \
627 qs_filter.append( name ); \
630 else qs_filter.append( ":" ).append( name ); \
635 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
636 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
637 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
638 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
640 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
641 #define CaC( name ) CaCi( name, 1 )
643 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
644 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
647 CaC( "udp-caching" );
648 if (module_exists ("dvdread" ))
649 CaC( "dvdread-caching" );
650 if (module_exists ("dvdnav" ))
651 CaC( "dvdnav-caching" );
652 CaC( "tcp-caching" ); CaC( "vcd-caching" );
653 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
654 CaC( "screen-caching" );
655 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
656 CaCi( "http-caching", 4 );
657 if (module_exists ("access_realrtsp" ))
658 CaCi( "realrtsp-caching", 10 );
659 CaCi( "mms-caching", 19 );
661 CaC( "dshow-caching" );
663 if (module_exists ( "v4l" ))
664 CaC( "v4l-caching" );
665 if (module_exists ( "access_jack" ))
666 CaC( "jack-input-caching" );
667 if (module_exists ( "v4l2" ))
668 CaC( "v4l2-caching" );
669 if (module_exists ( "pvr" ))
670 CaC( "pvr-caching" );
672 //CaCi( "dv-caching" ) too short...
678 case SPrefsInterface:
680 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
681 config_PutPsz( p_intf, "intf", "skins2" );
682 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
683 config_PutPsz( p_intf, "intf", "qt4" );
690 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
691 if( qs_filter.isEmpty() )
693 /* the psz_filter is already empty, so we just append it needed */
694 if( b_normChecked ) qs_filter = "volnorm";
698 if( qs_filter.contains( "volnorm" ) )
700 /* The qs_filter not empty and contains "volnorm"
701 that we have to remove */
705 qs_filter.remove( "volnorm:" );
706 qs_filter.remove( ":volnorm" );
707 qs_filter.remove( "volnorm" );
710 else /* qs_filter not empty, but doesn't have volnorm inside */
711 if( b_normChecked ) qs_filter.append( ":volnorm" );
713 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
719 void SPrefsPanel::clean()
722 void SPrefsPanel::lastfm_Changed( int i_state )
724 if( i_state == Qt::Checked )
725 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
726 else if( i_state == Qt::Unchecked )
727 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
731 #include <QDialogButtonBox>
732 #include <QHeaderView>
733 #include "util/registry.hpp"
735 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
736 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
739 const char* psz_VLC = "VLC";
740 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
742 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
744 current->setCheckState( 0, Qt::Checked );
749 current->setCheckState( 0, Qt::Unchecked );
752 listAsso.append( current );
756 void SPrefsPanel::assoDialog()
758 QDialog *d = new QDialog( this );
759 QGridLayout *assoLayout = new QGridLayout( d );
761 QTreeWidget *filetypeList = new QTreeWidget;
762 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
763 filetypeList->header()->hide();
765 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
767 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
768 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
769 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
771 filetypeList->addTopLevelItem( audioType );
772 filetypeList->addTopLevelItem( videoType );
773 filetypeList->addTopLevelItem( otherType );
775 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
776 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
777 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
779 QTreeWidgetItem *currentItem;
782 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
783 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
784 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
786 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
787 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
788 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
789 aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
790 audioType->setCheckState( 0, ( i_temp > 0 ) ?
791 ( ( i_temp == audioType->childCount() ) ?
792 Qt::Checked : Qt::PartiallyChecked )
796 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
797 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
798 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
799 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
800 aTv( ".mts" ); aTv( ".mxf" );
801 aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".ts" );
802 aTv( ".vob" ); aTv( ".wmv" );
803 videoType->setCheckState( 0, ( i_temp > 0 ) ?
804 ( ( i_temp == audioType->childCount() ) ?
805 Qt::Checked : Qt::PartiallyChecked )
809 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
811 otherType->setCheckState( 0, ( i_temp > 0 ) ?
812 ( ( i_temp == audioType->childCount() ) ?
813 Qt::Checked : Qt::PartiallyChecked )
816 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
817 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
818 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
819 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
820 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
822 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
824 CONNECT( closeButton, clicked(), this, saveAsso() );
825 CONNECT( clearButton, clicked(), d, reject() );
826 d->resize( 300, 400 );
833 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
835 std::string s_path( "VLC" ); s_path += psz_ext;
836 std::string s_path2 = s_path;
838 /* Save a backup if already assigned */
839 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
841 if( psz_value && strlen( psz_value ) > 0 )
842 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
845 /* Put a "link" to VLC.EXT as default */
846 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
848 /* Create the needed Key if they weren't done in the installer */
849 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
851 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
852 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
853 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
855 /* Get the installer path */
856 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
857 std::string str_temp; str_temp.assign(
858 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
860 if( str_temp.size() )
862 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
863 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
865 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
866 "", str_temp.append(",0").c_str() );
872 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
874 char psz_VLC[] = "VLC";
875 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
877 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
880 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
882 qvReg->WriteRegistryString( psz_ext, "", psz_value );
884 qvReg->DeleteKey( psz_ext, "VLC.backup" );
888 void SPrefsPanel::saveAsso()
890 QVLCRegistry * qvReg;
891 for( int i = 0; i < listAsso.size(); i ++ )
893 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
894 if( listAsso[i]->checkState( 0 ) > 0 )
896 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
900 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
904 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();