1 /*****************************************************************************
2 * simple_preferences.cpp : "Simple preferences"
3 ****************************************************************************
4 * Copyright (C) 2006-2007 the VideoLAN team
5 * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
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 *****************************************************************************/
26 #include "components/simple_preferences.hpp"
27 #include "components/preferences_widgets.hpp"
29 #include <vlc_config_cat.h>
30 #include <vlc_configuration.h>
34 #include <QToolButton>
35 #include <QButtonGroup>
37 #include <QVBoxLayout>
39 #define ICON_HEIGHT 64
40 #define BUTTON_HEIGHT 74
42 /*********************************************************************
43 * The List of categories
44 *********************************************************************/
45 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
46 QWidget( _parent ), p_intf( _p_intf )
48 QVBoxLayout *layout = new QVBoxLayout();
50 QButtonGroup *buttonGroup = new QButtonGroup( this );
51 buttonGroup->setExclusive ( true );
52 CONNECT( buttonGroup, buttonClicked ( int ),
53 this, switchPanel( int ) );
55 #define ADD_CATEGORY( button, label, icon, numb ) \
56 QToolButton * button = new QToolButton( this ); \
57 button->setIcon( QIcon( ":/pixmaps/" #icon ) ); \
58 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
59 button->setText( label ); \
60 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
61 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
62 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
63 button->setAutoRaise( true ); \
64 button->setCheckable( true ); \
65 buttonGroup->addButton( button, numb ); \
66 layout->addWidget( button );
68 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
69 spref_cone_Interface_64.png, 0 );
70 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
71 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
72 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
73 spref_cone_Subtitles_64.png, 3 );
74 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
75 spref_cone_Input_64.png, 4 );
76 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
78 SPrefsInterface->setChecked( true );
79 layout->setMargin( 0 );
80 layout->setSpacing( 1 );
82 this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
87 void SPrefsCatList::switchPanel( int i )
89 emit currentItemChanged( i );
92 /*********************************************************************
94 *********************************************************************/
95 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
96 int _number ) : QWidget( _parent ), p_intf( _p_intf )
98 module_config_t *p_config;
99 ConfigControl *control;
102 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
103 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
106 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
107 p_config, label, ui.qcontrol, false ); \
108 controls.append( control ); \
111 #define CONFIG_GENERIC_NO_BOOL( 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 ); \
117 controls.append( control ); \
120 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
121 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
124 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
125 p_config, label, ui.qcontrol, ui.qbutton, \
127 controls.append( control ); \
130 #define START_SPREFS_CAT( name , label ) \
131 case SPrefs ## name: \
133 Ui::SPrefs ## name ui; \
134 ui.setupUi( panel ); \
135 panel_label->setText( label );
137 #define END_SPREFS_CAT \
141 QVBoxLayout *panel_layout = new QVBoxLayout();
142 QWidget *panel = new QWidget();
143 panel_layout->setMargin( 3 );
146 QLabel *panel_label = new QLabel;
147 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
148 labelFont.setPointSize( labelFont.pointSize() + 6 );
149 labelFont.setFamily( "Verdana" );
150 panel_label->setFont( labelFont );
153 QFrame *title_line = new QFrame;
154 title_line->setFrameShape(QFrame::HLine);
155 title_line->setFrameShadow(QFrame::Sunken);
157 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
158 italicFont.setItalic( true );
162 /******************************
163 * VIDEO Panel Implementation *
164 ******************************/
165 START_SPREFS_CAT( Video , qtr("General video settings") );
166 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
168 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
169 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
170 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
171 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
172 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
173 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
176 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
177 CONFIG_GENERIC( "directx-device", StringList, NULL,
180 ui.directXBox->setVisible( false );
183 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
184 snapshotsDirectory, snapshotsDirectoryBrowse );
185 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
186 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
187 snapshotsSequentialNumbering );
188 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
192 /******************************
193 * AUDIO Panel Implementation *
194 ******************************/
195 START_SPREFS_CAT( Audio, qtr("General audio settings") );
197 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
199 /* hide if necessary */
201 ui.OSSControl->hide();
202 ui.alsaControl->hide();
204 ui.DirectXControl->hide();
206 ui.lastfm_user_edit->hide();
207 ui.lastfm_user_label->hide();
208 ui.lastfm_pass_edit->hide();
209 ui.lastfm_pass_label->hide();
211 /* General Audio Options */
212 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
214 CONFIG_GENERIC( "audio-language" , String , NULL,
215 preferredAudioLanguage );
217 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
218 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
221 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
223 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
225 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
227 /* Audio Output Specifics */
228 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
230 CONNECT( ui.outputModule, currentIndexChanged( int ),
231 this, updateAudioOptions( int ) );
234 if( module_Exists( p_intf, "alsa" ) )
236 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel,
239 if( module_Exists( p_intf, "oss" ) )
241 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
245 CONFIG_GENERIC( "directx-audio-device", IntegerList,
246 ui.DirectXLabel, DirectXDevice );
248 // File exists everywhere
249 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
250 fileName, fileBrowseButton );
252 optionWidgets.append( ui.alsaControl );
253 optionWidgets.append( ui.OSSControl );
254 optionWidgets.append( ui.DirectXControl );
255 optionWidgets.append( ui.fileControl );
256 optionWidgets.append( ui.outputModule );
257 optionWidgets.append( ui.volNormBox );
258 updateAudioOptions( ui.outputModule->currentIndex() );
261 if( module_Exists( p_intf, "audioscrobbler" ) )
263 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
265 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
268 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
269 ui.lastfm->setChecked( true );
271 ui.lastfm->setChecked( false );
272 CONNECT( ui.lastfm, stateChanged( int ), this ,
273 lastfm_Changed( int ) );
280 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
281 setEnabled( bool ) );
282 qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
283 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
285 ui.volNormBox->setChecked( b_normalizer );
286 ui.volNormSpin->setEnabled( b_normalizer );
291 /* Input and Codecs Panel Implementation */
292 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
296 ui.DVDDevice->setToolTip(
297 //BUG: make this sentence understandable
298 qtr( "If this property is blank, then you have\n"
299 "values for DVD, VCD, and CDDA.\n"
300 "You can define a unique one or set that in"
301 "the advanced preferences" ) );
302 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
303 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
304 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
305 if( ( *psz_cddadiscpath == *psz_dvddiscpath )
306 && ( *psz_dvddiscpath == *psz_vcddiscpath ) )
308 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
310 delete psz_cddadiscpath; delete psz_dvddiscpath;
311 delete psz_vcddiscpath;
314 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
315 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
316 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
317 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
318 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
320 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
322 ui.systemCodecBox->hide();
325 qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
326 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
327 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
328 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
329 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
331 optionWidgets.append( ui.recordBox );
332 optionWidgets.append( ui.dumpBox );
333 optionWidgets.append( ui.bandwidthBox );
334 optionWidgets.append( ui.timeshiftBox );
335 optionWidgets.append( ui.DVDDevice );
336 optionWidgets.append( ui.cachingCombo );
339 /* Add the things to the ComboBox */
340 #define addToCachingBox( str, cachingNumber ) \
341 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
342 addToCachingBox( "Custom", CachingCustom );
343 addToCachingBox( "Lowest latency", CachingLowest );
344 addToCachingBox( "Low latency", CachingLow );
345 addToCachingBox( "Normal", CachingNormal );
346 addToCachingBox( "High latency", CachingHigh );
347 addToCachingBox( "Higher latency", CachingHigher );
349 #define TestCaC( name ) \
350 b_cache_equal = b_cache_equal && \
351 ( i_cache == config_GetInt( p_intf, name ) )
353 #define TestCaCi( name, int ) \
354 b_cache_equal = b_cache_equal && \
355 ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
356 /* Select the accurate value of the ComboBox */
357 bool b_cache_equal = true;
358 int i_cache = config_GetInt( p_intf, "file-caching");
360 TestCaC( "udp-caching" );
361 if (module_Exists (p_intf, "dvdread"))
362 TestCaC( "dvdread-caching" );
363 if (module_Exists (p_intf, "dvdnav"))
364 TestCaC( "dvdnav-caching" );
365 TestCaC( "tcp-caching" );
366 TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
367 TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
369 TestCaC( "dshow-caching" );
371 if (module_Exists (p_intf, "v4l"))
372 TestCaC( "v4l-caching" );
373 if (module_Exists (p_intf, "access_jack"))
374 TestCaC( "jack-input-caching" );
375 if (module_Exists (p_intf, "v4l2"))
376 TestCaC( "v4l2-caching" );
377 if (module_Exists (p_intf, "pvr"))
378 TestCaC( "pvr-caching" );
380 TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
381 TestCaCi( "http-caching", 4 );
382 if (module_Exists (p_intf, "access_realrtsp"))
383 TestCaCi( "realrtsp-caching", 10 );
384 TestCaCi( "mms-caching", 19 );
385 if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
386 ui.cachingCombo->findData( QVariant( i_cache ) ) );
392 START_SPREFS_CAT( Interface, qtr("Interface settings") );
393 ui.defaultLabel->setFont( italicFont );
394 ui.skinsLabel->setFont( italicFont );
396 #if defined( WIN32 ) || defined (__APPLE__)
397 CONFIG_GENERIC( "language", StringList, NULL, language );
400 ui.languageLabel->hide();
404 char *psz_intf = config_GetPsz( p_intf, "intf" );
407 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
408 if( strstr( psz_intf, "skin" ) )
409 ui.skins->setChecked( true );
410 else if( strstr( psz_intf, "qt" ) )
411 ui.qt4->setChecked( true );
415 optionWidgets.append( ui.skins );
416 optionWidgets.append( ui.qt4 );
418 CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel, artFetcher );
419 CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
420 CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, qtUpdates );
421 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
422 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
424 #if defined( WIN32 ) || defined( HAVE_DBUS_3 )
425 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
426 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
427 EnqueueOneInterfaceMode );
429 ui.OneInterfaceBox->hide();
433 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
434 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
436 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
437 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
438 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
440 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
441 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
443 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
449 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
451 QGridLayout *gLayout = new QGridLayout;
452 panel->setLayout( gLayout );
455 KeySelectorControl *ksCtrl =
456 new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
457 this, gLayout, line );
459 panel_label->setText( qtr( "Configure Hotkeys" ) );
465 panel_layout->addWidget( panel_label );
466 panel_layout->addWidget( title_line );
467 panel_layout->addWidget( panel );
468 if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
470 setLayout( panel_layout );
473 void SPrefsPanel::updateAudioOptions( int number)
475 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
476 ->itemData( number ).toString();
479 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
480 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
482 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
484 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
487 /* Function called from the main Preferences dialog on each SPrefs Panel */
488 void SPrefsPanel::apply()
490 msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
492 /* Generic save for ever panel */
493 QList<ConfigControl *>::Iterator i;
494 for( i = controls.begin() ; i != controls.end() ; i++ )
496 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
497 c->doApply( p_intf );
502 case SPrefsInputAndCodecs:
504 /* Device default selection */
505 char *psz_devicepath =
506 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
507 if( !EMPTY_STR( psz_devicepath ) )
509 config_PutPsz( p_intf, "dvd", psz_devicepath );
510 config_PutPsz( p_intf, "vcd", psz_devicepath );
511 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
515 #define saveBox( name, box ) {\
516 if( box->isChecked() ) { \
518 qs_filter.append( name ); \
521 else qs_filter.append( ":" ).append( name ); \
526 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
527 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
528 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
529 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
530 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
532 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
533 #define CaC( name ) CaCi( name, 1 )
535 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
536 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
539 msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
540 CaC( "udp-caching" );
541 if (module_Exists (p_intf, "dvdread"))
542 CaC( "dvdread-caching" );
543 if (module_Exists (p_intf, "dvdnav"))
544 CaC( "dvdnav-caching" );
545 CaC( "tcp-caching" ); CaC( "vcd-caching" );
546 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
547 CaC( "screen-caching" );
548 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
549 CaCi( "http-caching", 4 );
550 if (module_Exists (p_intf, "access_realrtsp"))
551 CaCi( "realrtsp-caching", 10 );
552 CaCi( "mms-caching", 19 );
554 CaC( "dshow-caching" );
556 if (module_Exists (p_intf, "v4l"))
557 CaC( "v4l-caching" );
558 if (module_Exists (p_intf, "access_jack"))
559 CaC( "jack-input-caching" );
560 if (module_Exists (p_intf, "v4l2"))
561 CaC( "v4l2-caching" );
562 if (module_Exists (p_intf, "pvr"))
563 CaC( "pvr-caching" );
565 //CaCi( "dv-caching" ) too short...
571 case SPrefsInterface:
573 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
574 config_PutPsz( p_intf, "intf", "skins2" );
575 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
576 config_PutPsz( p_intf, "intf", "qt4" );
583 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
584 if( qs_filter.isEmpty() )
586 /* the psz_filter is already empty, so we just append it needed */
587 if( b_normChecked ) qs_filter = "volnorm";
591 if( qs_filter.contains( "volnorm" ) )
593 /* The qs_filter not empty and contains "volnorm"
594 that we have to remove */
598 qs_filter.remove( "volnorm:" );
599 qs_filter.remove( ":volnorm" );
600 qs_filter.remove( "volnorm" );
603 else /* qs_filter not empty, but doesn't have volnorm inside */
604 if( b_normChecked ) qs_filter.append( ":volnorm" );
606 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
612 void SPrefsPanel::clean()
615 void SPrefsPanel::lastfm_Changed( int i_state )
617 if( i_state == Qt::Checked )
618 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
619 else if( i_state == Qt::Unchecked )
620 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );