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"
31 #include <vlc_config_cat.h>
32 #include <vlc_configuration.h>
36 #include <QToolButton>
37 #include <QButtonGroup>
39 #include <QVBoxLayout>
41 #define ICON_HEIGHT 64
42 #define BUTTON_HEIGHT 74
44 /*********************************************************************
45 * The List of categories
46 *********************************************************************/
47 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
48 QWidget( _parent ), p_intf( _p_intf )
50 QVBoxLayout *layout = new QVBoxLayout();
52 QButtonGroup *buttonGroup = new QButtonGroup( this );
53 buttonGroup->setExclusive ( true );
54 CONNECT( buttonGroup, buttonClicked ( int ),
55 this, switchPanel( int ) );
57 #define ADD_CATEGORY( button, label, icon, numb ) \
58 QToolButton * button = new QToolButton( this ); \
59 button->setIcon( QIcon( ":/pixmaps/" #icon ) ); \
60 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
61 button->setText( label ); \
62 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
63 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
64 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
65 button->setAutoRaise( true ); \
66 button->setCheckable( true ); \
67 buttonGroup->addButton( button, numb ); \
68 layout->addWidget( button );
70 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
71 spref_cone_Interface_64.png, 0 );
72 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
73 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
74 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
75 spref_cone_Subtitles_64.png, 3 );
76 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
77 spref_cone_Input_64.png, 4 );
78 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
80 SPrefsInterface->setChecked( true );
81 layout->setMargin( 0 );
82 layout->setSpacing( 1 );
84 this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
89 void SPrefsCatList::switchPanel( int i )
91 emit currentItemChanged( i );
94 /*********************************************************************
96 *********************************************************************/
97 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
98 int _number ) : QWidget( _parent ), p_intf( _p_intf )
100 module_config_t *p_config;
101 ConfigControl *control;
104 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
105 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
108 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
109 p_config, label, ui.qcontrol, false ); \
110 controls.append( control ); \
113 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
114 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
117 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
118 p_config, label, ui.qcontrol ); \
119 controls.append( control ); \
122 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
123 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
126 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
127 p_config, label, ui.qcontrol, ui.qbutton, \
129 controls.append( control ); \
132 #define START_SPREFS_CAT( name , label ) \
133 case SPrefs ## name: \
135 Ui::SPrefs ## name ui; \
136 ui.setupUi( panel ); \
137 panel_label->setText( label );
139 #define END_SPREFS_CAT \
143 QVBoxLayout *panel_layout = new QVBoxLayout();
144 QWidget *panel = new QWidget();
145 panel_layout->setMargin( 3 );
148 QLabel *panel_label = new QLabel;
149 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
150 labelFont.setPointSize( labelFont.pointSize() + 6 );
151 labelFont.setFamily( "Verdana" );
152 panel_label->setFont( labelFont );
155 QFrame *title_line = new QFrame;
156 title_line->setFrameShape(QFrame::HLine);
157 title_line->setFrameShadow(QFrame::Sunken);
159 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
160 italicFont.setItalic( true );
164 /******************************
165 * VIDEO Panel Implementation *
166 ******************************/
167 START_SPREFS_CAT( Video , qtr("General video settings") );
168 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
170 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
171 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
172 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
173 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
174 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
175 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
176 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
179 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
180 CONFIG_GENERIC( "directx-device", StringList, NULL,
183 ui.directXBox->setVisible( false );
186 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
187 snapshotsDirectory, snapshotsDirectoryBrowse );
188 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
189 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
190 snapshotsSequentialNumbering );
191 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
195 /******************************
196 * AUDIO Panel Implementation *
197 ******************************/
198 START_SPREFS_CAT( Audio, qtr("General audio settings") );
200 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
202 /* and hide if necessary */
205 ui.OSSControl->hide();
206 ui.alsaControl->hide();
208 ui.DirectXControl->hide();
210 ui.lastfm_user_edit->hide();
211 ui.lastfm_user_label->hide();
212 ui.lastfm_pass_edit->hide();
213 ui.lastfm_pass_label->hide();
215 /* General Audio Options */
216 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
218 CONFIG_GENERIC( "audio-language" , String , NULL,
219 preferredAudioLanguage );
221 CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
222 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
225 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
227 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
229 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
231 /* Audio Output Specifics */
232 CONFIG_GENERIC( "aout", Module, NULL, outputModule );
234 CONNECT( ui.outputModule, currentIndexChanged( int ), this,
235 updateAudioOptions( int ) );
238 //TODO: use modules_Exists
240 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel, alsaDevice );
241 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
244 CONFIG_GENERIC( "directx-audio-device", IntegerList,
245 ui.DirectXLabel, DirectXDevice );
247 // File exists everywhere
248 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
249 fileName, fileBrowseButton );
251 optionWidgets.append( ui.alsaControl );
252 optionWidgets.append( ui.OSSControl );
253 optionWidgets.append( ui.DirectXControl );
254 optionWidgets.append( ui.fileControl );
255 optionWidgets.append( ui.outputModule );
256 optionWidgets.append( ui.volNormBox );
257 updateAudioOptions( ui.outputModule->currentIndex() );
260 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
262 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
265 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
266 ui.lastfm->setCheckState( Qt::Checked );
268 ui.lastfm->setCheckState( Qt::Unchecked );
269 CONNECT( ui.lastfm, stateChanged( int ), this ,
270 lastfm_Changed( int ) );
274 CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
275 setEnabled( bool ) );
276 qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
277 bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
279 ui.volNormBox->setChecked( b_normalizer );
280 ui.volNormSpin->setEnabled( b_normalizer );
285 /* Input and Codecs Panel Implementation */
286 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
290 ui.DVDDevice->setToolTip(
291 qtr( "If this propriety is blank, then you have\n"
292 "values for DVD, VCD, and CDDA.\n"
293 "You can define a unique one or set that in"
294 "the advanced preferences" ) );
295 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
296 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
297 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
298 if( ( *psz_cddadiscpath == *psz_dvddiscpath )
299 && ( *psz_dvddiscpath == *psz_vcddiscpath ) )
301 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
303 delete psz_cddadiscpath; delete psz_dvddiscpath;
304 delete psz_vcddiscpath;
307 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
308 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
309 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
310 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
311 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
313 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
315 ui.systemCodecBox->hide();
318 qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
319 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
320 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
321 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
322 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
324 optionWidgets.append( ui.recordBox );
325 optionWidgets.append( ui.dumpBox );
326 optionWidgets.append( ui.bandwidthBox );
327 optionWidgets.append( ui.timeshiftBox );
328 optionWidgets.append( ui.DVDDevice );
329 optionWidgets.append( ui.cachingCombo );
332 /* Add the things to the ComboBox */
333 #define addToCachingBox( str, cachingNumber ) \
334 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
335 addToCachingBox( "Custom", CachingCustom );
336 addToCachingBox( "Lowest latency", CachingLowest );
337 addToCachingBox( "Low latency", CachingLow );
338 addToCachingBox( "Normal", CachingNormal );
339 addToCachingBox( "High latency", CachingHigh );
340 addToCachingBox( "Higher latency", CachingHigher );
342 #define TestCaC( name ) \
343 b_cache_equal = b_cache_equal && ( i_cache == config_GetInt( p_intf, name ) );
345 #define TestCaCi( name, int ) \
346 b_cache_equal = b_cache_equal && ( ( i_cache * int ) == config_GetInt( p_intf, name ) );
347 /* Select the accurate value of the ComboBox */
348 bool b_cache_equal = true;
349 int i_cache = config_GetInt( p_intf, "file-caching");
351 TestCaC( "udp-caching" ) TestCaC( "dvdread-caching" )
352 TestCaC( "dvdnav-caching" ) TestCaC( "tcp-caching" )
353 TestCaC( "fake-caching" ) TestCaC( "cdda-caching" )
354 TestCaC( "screen-caching" ) TestCaC( "vcd-caching" )
356 TestCaC( "dshow-caching" )
358 TestCaC( "v4l-caching" ) TestCaC( "jack-input-caching" )
359 TestCaC( "v4l2-caching" ) TestCaC( "pvr-caching" )
361 TestCaCi( "rtsp-caching", 4 ) TestCaCi( "ftp-caching", 2 )
362 TestCaCi( "http-caching", 4 ) TestCaCi( "realrtsp-caching", 10 )
363 TestCaCi( "mms-caching", 19 )
365 ui.cachingCombo->setCurrentIndex( ui.cachingCombo->findData( QVariant( i_cache ) ) );
371 START_SPREFS_CAT( Interface, qtr("Interface settings") );
372 ui.defaultLabel->setFont( italicFont );
373 ui.skinsLabel->setFont( italicFont );
375 #if defined( WIN32 ) || defined (__APPLE__)
376 CONFIG_GENERIC( "language", StringList, NULL, language );
379 ui.languageLabel->hide();
383 char *psz_intf = config_GetPsz( p_intf, "intf" );
386 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
387 if( strstr( psz_intf, "skin" ) )
388 ui.skins->setChecked( true );
389 else if( strstr( psz_intf, "qt" ) )
390 ui.qt4->setChecked( true );
394 optionWidgets.append( ui.skins );
395 optionWidgets.append( ui.qt4 );
397 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
398 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
400 #if defined( WIN32 ) || defined( HAVE_DBUS_3 )
401 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
402 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
403 EnqueueOneInterfaceMode );
405 ui.OneInterfaceBox->hide();
409 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
410 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
412 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
413 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
414 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
416 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
417 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
419 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
425 p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
427 QGridLayout *gLayout = new QGridLayout;
428 panel->setLayout( gLayout );
431 KeySelectorControl *ksCtrl =
432 new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
433 this, gLayout, line );
435 panel_label->setText( qtr( "Configure Hotkeys" ) );
441 panel_layout->addWidget( panel_label );
442 panel_layout->addWidget( title_line );
443 panel_layout->addWidget( panel );
444 panel_layout->addStretch( 2 );
446 setLayout( panel_layout );
449 void SPrefsPanel::updateAudioOptions( int number)
451 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
452 ->itemData( number ).toString();
455 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
456 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
458 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
460 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
463 void SPrefsPanel::apply()
465 msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
467 /* Generic save for ever panel */
468 QList<ConfigControl *>::Iterator i;
469 for( i = controls.begin() ; i != controls.end() ; i++ )
471 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
472 c->doApply( p_intf );
476 if( number == SPrefsInputAndCodecs )
478 /* Device default selection */
479 char *psz_devicepath =
480 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
481 if( !EMPTY_STR( psz_devicepath ) )
483 config_PutPsz( p_intf, "dvd", psz_devicepath );
484 config_PutPsz( p_intf, "vcd", psz_devicepath );
485 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
489 #define saveBox( name, box ) {\
490 if( box->isChecked() ) { \
492 qs_filter.append( name ); \
495 else qs_filter.append( ":" ).append( name ); \
500 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
501 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
502 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
503 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
504 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
506 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue );
507 #define CaC( name ) CaCi( name, 1 );
509 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
510 int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
513 msg_Dbg( p_intf, "Adjusting all the cache values at level: %i", i_comboValue );
514 CaC( "udp-caching" ); CaC( "dvdread-caching" );
515 CaC( "dvdnav-caching" ); CaC( "tcp-caching" ); CaC( "vcd-caching" );
516 CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
517 CaC( "screen-caching" );
518 CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
519 CaCi( "http-caching", 4 ); CaCi( "realrtsp-caching", 10 );
520 CaCi( "mms-caching", 19 );
522 CaC( "dshow-caching" );
524 CaC( "v4l-caching" ); CaC( "jack-input-caching" ); CaC( "v4l2-caching" );
525 CaC( "pvr-caching" );
527 //CaCi( "dv-caching" ) too short...
532 if( number == SPrefsInterface )
534 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
535 config_PutPsz( p_intf, "intf", "skins2" );
536 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
537 config_PutPsz( p_intf, "intf", "qt4" );
540 if( number == SPrefsAudio )
543 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
544 if( qs_filter.isEmpty() )
546 /* the psz_filter is already empty, so we just append it needed */
547 if( b_normChecked ) qs_filter = "volnorm";
551 if( qs_filter.contains( "volnorm" ) )
553 /* The qs_filter not empty and contains "volnorm"
554 that we have to remove */
558 qs_filter.remove( "volnorm:" );
559 qs_filter.remove( ":volnorm" );
560 qs_filter.remove( "volnorm" );
563 else /* qs_filter not empty, but doesn't have volnorm inside */
564 if( b_normChecked ) qs_filter.append( ":volnorm" );
566 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
570 void SPrefsPanel::clean()
573 void SPrefsPanel::lastfm_Changed( int i_state )
575 if( i_state == Qt::Checked )
576 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
577 else if( i_state == Qt::Unchecked )
578 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );