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,
196 CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
198 ui.directXBox->setVisible( false );
199 ui.hwYUVBox->setVisible( false );
202 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
203 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
204 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
205 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
206 snapshotsSequentialNumbering );
207 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
211 /******************************
212 * AUDIO Panel Implementation *
213 ******************************/
214 START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
216 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
218 #define audioCommon( name ) \
219 QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
220 QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
221 name ## Layout->setMargin( 0 ); \
222 name ## Layout->setSpacing( 0 ); \
223 QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
224 name ## Label->setMinimumSize(QSize(100, 0)); \
225 name ## Layout->addWidget( name ## Label ); \
227 #define audioControl( name) \
228 audioCommon( name ) \
229 QComboBox * name ## Device = new QComboBox( name ## Control ); \
230 name ## Layout->addWidget( name ## Device ); \
231 name ## Label->setBuddy( name ## Device ); \
232 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
234 #define audioControl2( name) \
235 audioCommon( name ) \
236 QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
237 name ## Layout->addWidget( name ## Device ); \
238 name ## Label->setBuddy( name ## Device ); \
239 QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
240 name ## Layout->addWidget( name ## Browse ); \
241 outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
243 /* hide if necessary */
244 ui.lastfm_user_edit->hide();
245 ui.lastfm_user_label->hide();
246 ui.lastfm_pass_edit->hide();
247 ui.lastfm_pass_label->hide();
249 /* Build if necessary */
250 QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
252 audioControl( DirectX );
253 optionWidgets.append( DirectXControl );
254 CONFIG_GENERIC2( "directx-audio-device", IntegerList,
255 DirectXLabel, DirectXDevice );
257 if( module_exists( "alsa" ) )
259 audioControl( alsa );
260 optionWidgets.append( alsaControl );
262 CONFIG_GENERIC2( "alsa-audio-device" , StringList , alsaLabel,
266 optionWidgets.append( NULL );
267 if( module_exists( "oss" ) )
269 audioControl2( OSS );
270 optionWidgets.append( OSSControl );
271 CONFIG_GENERIC_FILE( "oss-audio-device" , File , OSSLabel, OSSDevice,
275 optionWidgets.append( NULL );
278 /* General Audio Options */
279 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
281 CONNECT( ui.defaultVolume, valueChanged( int ),
282 this, updateAudioVolume( int ) );
284 CONFIG_GENERIC( "audio-language" , String , NULL,
285 preferredAudioLanguage );
287 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
288 CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
289 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
292 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
294 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
296 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
298 /* Audio Output Specifics */
299 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
301 CONNECT( ui.outputModule, currentIndexChanged( int ),
302 this, updateAudioOptions( int ) );
304 /* File output exists on all platforms */
305 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
306 ui.fileName, ui.fileBrowseButton );
308 optionWidgets.append( ui.fileControl );
309 optionWidgets.append( ui.outputModule );
310 optionWidgets.append( ui.volNormBox );
311 /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
312 ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
313 optionWidgets.append( ui.volumeValue );
314 updateAudioOptions( ui.outputModule->currentIndex() );
317 if( module_exists( "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.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
394 optionWidgets.append( ui.dumpBox );
395 optionWidgets.append( ui.bandwidthBox );
396 optionWidgets.append( ui.timeshiftBox );
397 optionWidgets.append( ui.DVDDevice );
398 optionWidgets.append( ui.cachingCombo );
401 /* Add the things to the ComboBox */
402 #define addToCachingBox( str, cachingNumber ) \
403 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
404 addToCachingBox( N_("Custom"), CachingCustom );
405 addToCachingBox( N_("Lowest latency"), CachingLowest );
406 addToCachingBox( N_("Low latency"), CachingLow );
407 addToCachingBox( N_("Normal"), CachingNormal );
408 addToCachingBox( N_("High latency"), CachingHigh );
409 addToCachingBox( N_("Higher latency"), CachingHigher );
411 #define TestCaC( name ) \
412 b_cache_equal = b_cache_equal && \
413 ( i_cache == config_GetInt( p_intf, name ) )
415 #define TestCaCi( name, int ) \
416 b_cache_equal = b_cache_equal && \
417 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
418 /* Select the accurate value of the ComboBox */
419 bool b_cache_equal = true;
420 int i_cache = config_GetInt( p_intf, "file-caching");
422 TestCaC( "udp-caching" );
423 if (module_exists ("dvdread"))
424 TestCaC( "dvdread-caching" );
425 if (module_exists ("dvdnav"))
426 TestCaC( "dvdnav-caching" );
427 TestCaC( "tcp-caching" );
428 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
429 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
431 TestCaC( "dshow-caching" );
433 if (module_exists ("v4l"))
434 TestCaC( "v4l-caching" );
435 if (module_exists ("access_jack"))
436 TestCaC( "jack-input-caching" );
437 if (module_exists ("v4l2"))
438 TestCaC( "v4l2-caching" );
439 if (module_exists ("pvr"))
440 TestCaC( "pvr-caching" );
442 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
443 TestCaCi( "http-caching", 4 );
444 if (module_exists ("access_realrtsp"))
445 TestCaCi( "realrtsp-caching", 10 );
446 TestCaCi( "mms-caching", 19 );
447 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
448 ui.cachingCombo->findData( QVariant( i_cache ) ) );
454 START_SPREFS_CAT( Interface, qtr("Interface Settings") );
455 ui.defaultLabel->setFont( italicFont );
456 ui.skinsLabel->setFont( italicFont );
459 CONFIG_GENERIC( "language", StringList, NULL, language );
460 BUTTONACT( ui.assoButton, assoDialog() );
463 ui.languageLabel->hide();
465 ui.assoButton->hide();
469 char *psz_intf = config_GetPsz( p_intf, "intf" );
472 if( strstr( psz_intf, "skin" ) )
473 ui.skins->setChecked( true );
474 else if( strstr( psz_intf, "qt" ) )
475 ui.qt4->setChecked( true );
479 optionWidgets.append( ui.skins );
480 optionWidgets.append( ui.qt4 );
482 CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
484 CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
485 CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
486 CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
487 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
490 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
495 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
496 CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
498 CONNECT( ui.updatesBox, toggled( bool ),
499 ui.updatesDays, setEnabled( bool ) );
501 ui.updatesBox->hide();
502 ui.updatesDays->hide();
504 /* ONE INSTANCE options */
505 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
506 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
507 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
508 EnqueueOneInterfaceMode );
510 ui.OneInterfaceBox->hide();
512 /* RECENTLY PLAYED options */
513 CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
514 ui.recentlyPlayedFilters, setEnabled( bool ) );
515 ui.recentlyPlayedFilters->setEnabled( false );
516 CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
517 CONFIG_GENERIC( "qt-recentplay-filter", String, NULL,
518 recentlyPlayedFilters );
522 START_SPREFS_CAT( Subtitles, qtr("Subtitles & On Screen Display Settings") );
523 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
524 CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
527 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
528 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
529 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
531 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
532 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
534 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
535 CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, NULL, subsPosition );
541 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
543 QGridLayout *gLayout = new QGridLayout;
544 panel->setLayout( gLayout );
547 control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
548 this, gLayout, line );
550 panel_label->setText( qtr( "Configure Hotkeys" ) );
551 controls.append( control );
557 panel_layout->addWidget( panel_label );
558 panel_layout->addWidget( title_line );
559 panel_layout->addWidget( panel );
560 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
562 setLayout( panel_layout );
565 void SPrefsPanel::updateAudioOptions( int number)
567 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
568 ->itemData( number ).toString();
570 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
572 /* optionWidgets[ossW] can be NULL */
573 if( optionWidgets[ossW] )
574 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
575 /* optionWidgets[alsaW] can be NULL */
576 if( optionWidgets[alsaW] )
577 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
579 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
583 SPrefsPanel::~SPrefsPanel()
585 qDeleteAll( controls ); controls.clear();
588 void SPrefsPanel::updateAudioVolume( int volume )
590 qobject_cast<QSpinBox *>(optionWidgets[volLW])
591 ->setValue( volume * 100 / 256 );
595 /* Function called from the main Preferences dialog on each SPrefs Panel */
596 void SPrefsPanel::apply()
598 /* Generic save for ever panel */
599 QList<ConfigControl *>::Iterator i;
600 for( i = controls.begin() ; i != controls.end() ; i++ )
602 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
603 c->doApply( p_intf );
608 case SPrefsInputAndCodecs:
610 /* Device default selection */
611 char *psz_devicepath =
612 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
613 if( !EMPTY_STR( psz_devicepath ) )
615 config_PutPsz( p_intf, "dvd", psz_devicepath );
616 config_PutPsz( p_intf, "vcd", psz_devicepath );
617 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
621 #define saveBox( name, box ) {\
622 if( box->isChecked() ) { \
624 qs_filter.append( name ); \
627 else qs_filter.append( ":" ).append( name ); \
632 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
633 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
634 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
635 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
637 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
638 #define CaC( name ) CaCi( name, 1 )
640 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
641 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
644 CaC( "udp-caching" );
645 if (module_exists ("dvdread" ))
646 CaC( "dvdread-caching" );
647 if (module_exists ("dvdnav" ))
648 CaC( "dvdnav-caching" );
649 CaC( "tcp-caching" ); CaC( "vcd-caching" );
650 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
651 CaC( "screen-caching" );
652 CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
653 CaCi( "http-caching", 2 );
654 if (module_exists ("access_realrtsp" ))
655 CaCi( "realrtsp-caching", 10 );
656 CaCi( "mms-caching", 10 );
658 CaC( "dshow-caching" );
660 if (module_exists ( "v4l" ))
661 CaC( "v4l-caching" );
662 if (module_exists ( "access_jack" ))
663 CaC( "jack-input-caching" );
664 if (module_exists ( "v4l2" ))
665 CaC( "v4l2-caching" );
666 if (module_exists ( "pvr" ))
667 CaC( "pvr-caching" );
669 //CaCi( "dv-caching" ) too short...
675 case SPrefsInterface:
677 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
678 config_PutPsz( p_intf, "intf", "skins2" );
679 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
680 config_PutPsz( p_intf, "intf", "qt4" );
687 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
688 if( qs_filter.isEmpty() )
690 /* the psz_filter is already empty, so we just append it needed */
691 if( b_normChecked ) qs_filter = "volnorm";
695 if( qs_filter.contains( "volnorm" ) )
697 /* The qs_filter not empty and contains "volnorm"
698 that we have to remove */
702 qs_filter.remove( "volnorm:" );
703 qs_filter.remove( ":volnorm" );
704 qs_filter.remove( "volnorm" );
707 else /* qs_filter not empty, but doesn't have volnorm inside */
708 if( b_normChecked ) qs_filter.append( ":volnorm" );
710 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
716 void SPrefsPanel::clean()
719 void SPrefsPanel::lastfm_Changed( int i_state )
721 if( i_state == Qt::Checked )
722 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
723 else if( i_state == Qt::Unchecked )
724 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
728 #include <QDialogButtonBox>
729 #include <QHeaderView>
730 #include "util/registry.hpp"
732 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
733 QTreeWidgetItem* parent, QVLCRegistry *qvReg )
736 const char* psz_VLC = "VLC";
737 current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
739 if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
741 current->setCheckState( 0, Qt::Checked );
746 current->setCheckState( 0, Qt::Unchecked );
749 listAsso.append( current );
753 void SPrefsPanel::assoDialog()
755 QDialog *d = new QDialog( this );
756 QGridLayout *assoLayout = new QGridLayout( d );
758 QTreeWidget *filetypeList = new QTreeWidget;
759 assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
760 filetypeList->header()->hide();
762 QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
764 QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
765 QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
766 QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
768 filetypeList->addTopLevelItem( audioType );
769 filetypeList->addTopLevelItem( videoType );
770 filetypeList->addTopLevelItem( otherType );
772 audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
773 videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
774 otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
776 QTreeWidgetItem *currentItem;
779 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
780 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
781 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
783 aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
784 aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
785 aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
786 aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
787 audioType->setCheckState( 0, ( i_temp > 0 ) ?
788 ( ( i_temp == audioType->childCount() ) ?
789 Qt::Checked : Qt::PartiallyChecked )
793 aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
794 aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
795 aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
796 aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
797 aTv( ".mts" ); aTv( ".mxf" );
798 aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" ); aTv( ".ts" );
799 aTv( ".vob" ); aTv( ".wmv" );
800 videoType->setCheckState( 0, ( i_temp > 0 ) ?
801 ( ( i_temp == audioType->childCount() ) ?
802 Qt::Checked : Qt::PartiallyChecked )
806 aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
808 otherType->setCheckState( 0, ( i_temp > 0 ) ?
809 ( ( i_temp == audioType->childCount() ) ?
810 Qt::Checked : Qt::PartiallyChecked )
813 QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
814 QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
815 QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
816 buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
817 buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
819 assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
821 CONNECT( closeButton, clicked(), this, saveAsso() );
822 CONNECT( clearButton, clicked(), d, reject() );
823 d->resize( 300, 400 );
830 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
832 std::string s_path( "VLC" ); s_path += psz_ext;
833 std::string s_path2 = s_path;
835 /* Save a backup if already assigned */
836 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
838 if( psz_value && strlen( psz_value ) > 0 )
839 qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
842 /* Put a "link" to VLC.EXT as default */
843 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
845 /* Create the needed Key if they weren't done in the installer */
846 if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
848 qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
849 qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
850 qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
852 /* Get the installer path */
853 QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
854 std::string str_temp; str_temp.assign(
855 qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
857 if( str_temp.size() )
859 qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
860 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
862 qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
863 "", str_temp.append(",0").c_str() );
869 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
871 char psz_VLC[] = "VLC";
872 char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
874 if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
877 psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
879 qvReg->WriteRegistryString( psz_ext, "", psz_value );
881 qvReg->DeleteKey( psz_ext, "VLC.backup" );
885 void SPrefsPanel::saveAsso()
887 QVLCRegistry * qvReg;
888 for( int i = 0; i < listAsso.size(); i ++ )
890 qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
891 if( listAsso[i]->checkState( 0 ) > 0 )
893 addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
897 delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
901 qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();