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>
42 #include <QtAlgorithms>
46 #define ICON_HEIGHT 64
47 #define BUTTON_HEIGHT 74
49 /*********************************************************************
50 * The List of categories
51 *********************************************************************/
52 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
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 #define ADD_CATEGORY( button, label, icon, numb ) \
63 QToolButton * button = new QToolButton( this ); \
64 button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) ); \
65 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
66 button->setText( label ); \
67 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
68 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
69 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
70 button->setAutoRaise( true ); \
71 button->setCheckable( true ); \
72 buttonGroup->addButton( button, numb ); \
73 layout->addWidget( button );
75 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
76 spref_cone_Interface_64.png, 0 );
77 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
78 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
79 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
80 spref_cone_Subtitles_64.png, 3 );
81 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
82 spref_cone_Input_64.png, 4 );
83 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
85 SPrefsInterface->setChecked( true );
86 layout->setMargin( 0 );
87 layout->setSpacing( 1 );
89 setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
94 void SPrefsCatList::switchPanel( int i )
96 emit currentItemChanged( i );
99 /*********************************************************************
101 *********************************************************************/
102 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
103 int _number ) : QWidget( _parent ), p_intf( _p_intf )
105 module_config_t *p_config;
106 ConfigControl *control;
109 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
110 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
113 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
114 p_config, label, ui.qcontrol, false ); \
115 controls.append( control ); \
118 #define CONFIG_GENERIC2( option, type, label, qcontrol ) \
119 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
122 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
123 p_config, label, qcontrol, false ); \
124 controls.append( control ); \
128 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
129 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
132 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
133 p_config, label, ui.qcontrol ); \
134 controls.append( control ); \
137 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
138 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
141 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
142 p_config, label, qcontrol, qbutton, \
144 controls.append( control ); \
147 #define START_SPREFS_CAT( name , label ) \
148 case SPrefs ## name: \
150 Ui::SPrefs ## name ui; \
151 ui.setupUi( panel ); \
152 panel_label->setText( label );
154 #define END_SPREFS_CAT \
158 QVBoxLayout *panel_layout = new QVBoxLayout();
159 QWidget *panel = new QWidget();
160 panel_layout->setMargin( 3 );
163 QLabel *panel_label = new QLabel;
164 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
165 labelFont.setPointSize( labelFont.pointSize() + 6 );
166 labelFont.setFamily( "Verdana" );
167 panel_label->setFont( labelFont );
170 QFrame *title_line = new QFrame;
171 title_line->setFrameShape(QFrame::HLine);
172 title_line->setFrameShadow(QFrame::Sunken);
174 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
175 italicFont.setItalic( true );
179 /******************************
180 * VIDEO Panel Implementation *
181 ******************************/
182 START_SPREFS_CAT( Video , qtr("General Video Settings") );
183 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
185 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
186 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
187 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
188 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
189 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
190 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
193 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
194 CONFIG_GENERIC( "directx-device", StringList, NULL,
197 ui.directXBox->setVisible( false );
200 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
201 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
202 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
203 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
204 snapshotsSequentialNumbering );
205 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
209 /******************************
210 * AUDIO Panel Implementation *
211 ******************************/
212 START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
214 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
216 #define audioCommon( name ) \
217 QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
218 QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
219 name ## Layout->setMargin( 0 ); \
220 name ## Layout->setSpacing( 0 ); \
221 QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
222 name ## Label->setMinimumSize(QSize(100, 0)); \
223 name ## Layout->addWidget( name ## Label ); \
225 #define audioControl( name) \
226 audioCommon( name ) \
227 QComboBox * name ## Device = new QComboBox( name ## Control ); \
228 name ## Layout->addWidget( name ## Device ); \
229 name ## Label->setBuddy( name ## Device ); \
230 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
232 #define audioControl2( name) \
233 audioCommon( name ) \
234 QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
235 name ## Layout->addWidget( name ## Device ); \
236 name ## Label->setBuddy( name ## Device ); \
237 QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
238 name ## Layout->addWidget( name ## Browse ); \
239 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
241 /* hide if necessary */
242 ui.lastfm_user_edit->hide();
243 ui.lastfm_user_label->hide();
244 ui.lastfm_pass_edit->hide();
245 ui.lastfm_pass_label->hide();
247 /* Build if necessary */
248 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
250 audioControl( DirectX );
251 optionWidgets.append( DirectXControl );
252 CONFIG_GENERIC2( "directx-audio-device", IntegerList,
253 DirectXLabel, DirectXDevice );
255 if( module_Exists( p_intf, "alsa" ) )
257 audioControl( alsa );
258 optionWidgets.append( alsaControl );
260 CONFIG_GENERIC2( "alsadev" , StringList , alsaLabel,
264 optionWidgets.append( NULL );
265 if( module_Exists( p_intf, "oss" ) )
267 audioControl2( OSS );
268 optionWidgets.append( OSSControl );
269 CONFIG_GENERIC_FILE( "dspdev" , File , OSSLabel, OSSDevice,
273 optionWidgets.append( NULL );
276 /* General Audio Options */
277 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
279 CONNECT( ui.defaultVolume, valueChanged( int ),
280 this, updateAudioVolume( int ) );
282 CONFIG_GENERIC( "audio-language" , String , NULL,
283 preferredAudioLanguage );
285 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
286 CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
287 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
290 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
292 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
294 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
296 /* Audio Output Specifics */
297 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
299 CONNECT( ui.outputModule, currentIndexChanged( int ),
300 this, updateAudioOptions( int ) );
302 /* File output exists on all platforms */
303 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
304 ui.fileName, ui.fileBrowseButton );
306 optionWidgets.append( ui.fileControl );
307 optionWidgets.append( ui.outputModule );
308 optionWidgets.append( ui.volNormBox );
309 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
311 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
313 optionWidgets.append( ui.volumeValue );
314 updateAudioOptions( ui.outputModule->currentIndex() );
317 if( module_Exists( p_intf, "audioscrobbler" ) )
319 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
321 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
324 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
325 ui.lastfm->setChecked( true );
327 ui.lastfm->setChecked( false );
328 CONNECT( ui.lastfm, stateChanged( int ), this ,
329 lastfm_Changed( int ) );
336 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
337 setEnabled( bool ) );
338 char* psz = config_GetPsz( p_intf, "audio-filter" );
339 qs_filter = qfu( psz );
341 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
343 ui.volNormBox->setChecked( b_normalizer );
344 ui.volNormSpin->setEnabled( b_normalizer );
348 updateAudioVolume( ui.defaultVolume->value() ); // First time init
352 /* Input and Codecs Panel Implementation */
353 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
357 ui.DVDDevice->setToolTip(
358 qtr( "If this property is blank, different values\n"
359 "for DVD, VCD, and CDDA are set.\n"
360 "You can define a unique one or configure them \n"
361 "individually in the advanced preferences." ) );
362 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
363 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
364 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
365 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
366 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
367 !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
369 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
371 free( psz_cddadiscpath );
372 free( psz_dvddiscpath );
373 free( psz_vcddiscpath );
376 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
377 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
378 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
379 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
380 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
382 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
384 ui.systemCodecBox->hide();
387 char* psz = config_GetPsz( p_intf, "access-filter" );
388 qs_filter = qfu( psz );
390 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
391 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
392 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
393 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
395 optionWidgets.append( ui.recordBox );
396 optionWidgets.append( ui.dumpBox );
397 optionWidgets.append( ui.bandwidthBox );
398 optionWidgets.append( ui.timeshiftBox );
399 optionWidgets.append( ui.DVDDevice );
400 optionWidgets.append( ui.cachingCombo );
403 /* Add the things to the ComboBox */
404 #define addToCachingBox( str, cachingNumber ) \
405 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
406 addToCachingBox( "Custom", CachingCustom );
407 addToCachingBox( "Lowest latency", CachingLowest );
408 addToCachingBox( "Low latency", CachingLow );
409 addToCachingBox( "Normal", CachingNormal );
410 addToCachingBox( "High latency", CachingHigh );
411 addToCachingBox( "Higher latency", CachingHigher );
413 #define TestCaC( name ) \
414 b_cache_equal = b_cache_equal && \
415 ( i_cache == config_GetInt( p_intf, name ) )
417 #define TestCaCi( name, int ) \
418 b_cache_equal = b_cache_equal && \
419 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
420 /* Select the accurate value of the ComboBox */
421 bool b_cache_equal = true;
422 int i_cache = config_GetInt( p_intf, "file-caching");
424 TestCaC( "udp-caching" );
425 if (module_Exists (p_intf, "dvdread"))
426 TestCaC( "dvdread-caching" );
427 if (module_Exists (p_intf, "dvdnav"))
428 TestCaC( "dvdnav-caching" );
429 TestCaC( "tcp-caching" );
430 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
431 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
433 TestCaC( "dshow-caching" );
435 if (module_Exists (p_intf, "v4l"))
436 TestCaC( "v4l-caching" );
437 if (module_Exists (p_intf, "access_jack"))
438 TestCaC( "jack-input-caching" );
439 if (module_Exists (p_intf, "v4l2"))
440 TestCaC( "v4l2-caching" );
441 if (module_Exists (p_intf, "pvr"))
442 TestCaC( "pvr-caching" );
444 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
445 TestCaCi( "http-caching", 4 );
446 if (module_Exists (p_intf, "access_realrtsp"))
447 TestCaCi( "realrtsp-caching", 10 );
448 TestCaCi( "mms-caching", 19 );
449 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
450 ui.cachingCombo->findData( QVariant( i_cache ) ) );
456 START_SPREFS_CAT( Interface, qtr("Interface Settings") );
457 ui.defaultLabel->setFont( italicFont );
458 ui.skinsLabel->setFont( italicFont );
461 CONFIG_GENERIC( "language", StringList, NULL, 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, NULL,
486 CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
487 CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
488 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
491 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
496 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
497 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
499 CONNECT( ui.updatesBox, toggled( bool ),
500 ui.updatesDays, setEnabled( bool ) );
502 ui.updatesBox->hide();
503 ui.updatesDays->hide();
505 /* ONE INSTANCE options */
506 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
507 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
508 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
509 EnqueueOneInterfaceMode );
511 ui.OneInterfaceBox->hide();
515 START_SPREFS_CAT( Subtitles, qtr("Subtitles & On Screen Display Settings") );
516 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
518 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
519 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
520 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
522 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
523 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
525 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
531 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
533 QGridLayout *gLayout = new QGridLayout;
534 panel->setLayout( gLayout );
537 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
538 this, gLayout, line );
540 panel_label->setText( qtr( "Configure Hotkeys" ) );
541 controls.append( control );
547 panel_layout->addWidget( panel_label );
548 panel_layout->addWidget( title_line );
549 panel_layout->addWidget( panel );
550 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
552 setLayout( panel_layout );
555 void SPrefsPanel::updateAudioOptions( int number)
557 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
558 ->itemData( number ).toString();
560 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
562 /* optionWidgets[ossW] can be NULL */
563 if( optionWidgets[ossW] )
564 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
565 /* optionWidgets[alsaW] can be NULL */
566 if( optionWidgets[alsaW] )
567 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
569 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
573 SPrefsPanel::~SPrefsPanel()
575 qDeleteAll( controls ); controls.clear();
578 void SPrefsPanel::updateAudioVolume( int volume )
580 qobject_cast<QSpinBox *>(optionWidgets[volLW])
581 ->setValue( volume * 100 / 256 );
585 /* Function called from the main Preferences dialog on each SPrefs Panel */
586 void SPrefsPanel::apply()
588 /* Generic save for ever panel */
589 QList<ConfigControl *>::Iterator i;
590 for( i = controls.begin() ; i != controls.end() ; i++ )
592 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
593 c->doApply( p_intf );
598 case SPrefsInputAndCodecs:
600 /* Device default selection */
601 char *psz_devicepath =
602 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
603 if( !EMPTY_STR( psz_devicepath ) )
605 config_PutPsz( p_intf, "dvd", psz_devicepath );
606 config_PutPsz( p_intf, "vcd", psz_devicepath );
607 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
611 #define saveBox( name, box ) {\
612 if( box->isChecked() ) { \
614 qs_filter.append( name ); \
617 else qs_filter.append( ":" ).append( name ); \
622 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
623 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
624 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
625 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
626 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
628 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
629 #define CaC( name ) CaCi( name, 1 )
631 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
632 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
635 CaC( "udp-caching" );
636 if (module_Exists (p_intf, "dvdread" ))
637 CaC( "dvdread-caching" );
638 if (module_Exists (p_intf, "dvdnav" ))
639 CaC( "dvdnav-caching" );
640 CaC( "tcp-caching" ); CaC( "vcd-caching" );
641 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
642 CaC( "screen-caching" );
643 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
644 CaCi( "http-caching", 4 );
645 if (module_Exists (p_intf, "access_realrtsp" ))
646 CaCi( "realrtsp-caching", 10 );
647 CaCi( "mms-caching", 19 );
649 CaC( "dshow-caching" );
651 if (module_Exists (p_intf, "v4l" ))
652 CaC( "v4l-caching" );
653 if (module_Exists (p_intf, "access_jack" ))
654 CaC( "jack-input-caching" );
655 if (module_Exists (p_intf, "v4l2" ))
656 CaC( "v4l2-caching" );
657 if (module_Exists (p_intf, "pvr" ))
658 CaC( "pvr-caching" );
660 //CaCi( "dv-caching" ) too short...
666 case SPrefsInterface:
668 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
669 config_PutPsz( p_intf, "intf", "skins2" );
670 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
671 config_PutPsz( p_intf, "intf", "qt4" );
678 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
679 if( qs_filter.isEmpty() )
681 /* the psz_filter is already empty, so we just append it needed */
682 if( b_normChecked ) qs_filter = "volnorm";
686 if( qs_filter.contains( "volnorm" ) )
688 /* The qs_filter not empty and contains "volnorm"
689 that we have to remove */
693 qs_filter.remove( "volnorm:" );
694 qs_filter.remove( ":volnorm" );
695 qs_filter.remove( "volnorm" );
698 else /* qs_filter not empty, but doesn't have volnorm inside */
699 if( b_normChecked ) qs_filter.append( ":volnorm" );
701 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
707 void SPrefsPanel::clean()
710 void SPrefsPanel::lastfm_Changed( int i_state )
712 if( i_state == Qt::Checked )
713 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
714 else if( i_state == Qt::Unchecked )
715 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
719 #include <QDialogButtonBox>
720 #include <QHeaderView>
721 #include "util/registry.hpp"
723 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
724 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
727 const char* psz_VLC = "VLC";
728 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
730 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
732 current->setCheckState( 0, Qt::Checked );
737 current->setCheckState( 0, Qt::Unchecked );
740 listAsso.append( current );
744 void SPrefsPanel::assoDialog()
746 QDialog *d = new QDialog( this );
747 QGridLayout *assoLayout = new QGridLayout( d );
749 QTreeWidget *filetypeList = new QTreeWidget;
750 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
751 filetypeList->header()->hide();
753 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
755 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
756 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
757 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
759 filetypeList->addTopLevelItem( audioType );
760 filetypeList->addTopLevelItem( videoType );
761 filetypeList->addTopLevelItem( otherType );
763 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
764 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
765 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
767 QTreeWidgetItem *currentItem;
770 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
771 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
772 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
774 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
775 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
776 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".ogg" ); aTa( ".spx" );
777 aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
778 audioType->setCheckState( 0, ( i_temp > 0 ) ?
779 ( ( i_temp == audioType->childCount() ) ?
780 Qt::Checked : Qt::PartiallyChecked )
784 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
785 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
786 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
787 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
788 aTv( ".mts" ); aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ts" );
789 aTv( ".vob" ); aTv( ".wmv" );
790 videoType->setCheckState( 0, ( i_temp > 0 ) ?
791 ( ( i_temp == audioType->childCount() ) ?
792 Qt::Checked : Qt::PartiallyChecked )
796 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
798 otherType->setCheckState( 0, ( i_temp > 0 ) ?
799 ( ( i_temp == audioType->childCount() ) ?
800 Qt::Checked : Qt::PartiallyChecked )
803 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
804 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
805 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
806 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
807 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
809 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
811 CONNECT( closeButton, clicked(), this, saveAsso() );
812 CONNECT( clearButton, clicked(), d, reject() );
813 d->resize( 300, 400 );
820 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
822 std::string s_path( "VLC" ); s_path += psz_ext;
823 std::string s_path2 = s_path;
825 /* Save a backup if already assigned */
826 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
828 if( psz_value && strlen( psz_value ) > 0 )
829 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
832 /* Put a "link" to VLC.EXT as default */
833 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
835 /* Create the needed Key if they weren't done in the installer */
836 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
838 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
839 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
840 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
842 /* Get the installer path */
843 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
844 std::string str_temp; str_temp.assign(
845 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
847 if( str_temp.size() )
849 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
850 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
852 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
853 "", str_temp.append(",0").c_str() );
859 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
861 char psz_VLC[] = "VLC";
862 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
864 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
867 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
869 qvReg->WriteRegistryString( psz_ext, "", psz_value );
871 qvReg->DeleteKey( psz_ext, "VLC.backup" );
875 void SPrefsPanel::saveAsso()
877 QVLCRegistry * qvReg;
878 for( int i = 0; i < listAsso.size(); i ++ )
880 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
881 if( listAsso[i]->checkState( 0 ) > 0 )
883 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
887 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
891 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();