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") );
291 ui.DVDDevice->setToolTip(
292 qtr( "If this propriety is blank, then you have\n"
293 "values for DVD, VCD, and CDDA.\n"
294 "You can define a unique one or set that in"
295 "the advanced preferences" ) );
296 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
297 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
298 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
299 if( ( *psz_cddadiscpath == *psz_dvddiscpath )
300 && ( *psz_dvddiscpath == *psz_vcddiscpath ) )
302 ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
304 delete psz_cddadiscpath; delete psz_dvddiscpath;
305 delete psz_vcddiscpath;
308 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
309 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
312 #define addToCachingBox( str, cachingNumber ) \
313 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
314 addToCachingBox( "Custom", CachingCustom );
315 addToCachingBox( "Lowest latency", CachingLowest );
316 addToCachingBox( "Low latency", CachingLow );
317 addToCachingBox( "Normal", CachingNormal );
318 addToCachingBox( "High latency", CachingHigh );
319 addToCachingBox( "Higher latency", CachingHigher );
321 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
322 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
323 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
325 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
327 ui.systemCodecBox->hide();
330 qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
331 ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
332 ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
333 ui.recordBox->setChecked( qs_filter.contains( "record" ) );
334 ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
336 optionWidgets.append( ui.recordBox );
337 optionWidgets.append( ui.dumpBox );
338 optionWidgets.append( ui.bandwidthBox );
339 optionWidgets.append( ui.timeshiftBox );
340 optionWidgets.append( ui.DVDDevice );
341 optionWidgets.append( ui.cachingCombo );
347 START_SPREFS_CAT( Interface, qtr("Interface settings") );
348 ui.defaultLabel->setFont( italicFont );
349 ui.skinsLabel->setFont( italicFont );
351 #if defined( WIN32 ) || defined (__APPLE__)
352 CONFIG_GENERIC( "language", StringList, NULL, language );
355 ui.languageLabel->hide();
359 char *psz_intf = config_GetPsz( p_intf, "intf" );
362 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
363 if( strstr( psz_intf, "skin" ) )
364 ui.skins->setChecked( true );
365 else if( strstr( psz_intf, "qt" ) )
366 ui.qt4->setChecked( true );
370 optionWidgets.append( ui.skins );
371 optionWidgets.append( ui.qt4 );
373 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
374 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
376 #if defined( WIN32 ) || defined( HAVE_DBUS_3 )
377 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
378 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
379 EnqueueOneInterfaceMode );
381 ui.OneInterfaceBox->hide();
385 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
386 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
388 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
389 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
390 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
392 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
393 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
395 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
399 START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
404 panel_layout->addWidget( panel_label );
405 panel_layout->addWidget( title_line );
406 panel_layout->addWidget( panel );
407 panel_layout->addStretch( 2 );
409 setLayout( panel_layout );
412 void SPrefsPanel::updateAudioOptions( int number)
414 QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
415 ->itemData( number ).toString();
418 optionWidgets[ossW]->setVisible( ( value == "oss" ) );
419 optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
421 optionWidgets[directxW]->setVisible( ( value == "directx" ) );
423 optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
426 void SPrefsPanel::apply()
428 msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
430 /* Generic save for ever panel */
431 QList<ConfigControl *>::Iterator i;
432 for( i = controls.begin() ; i != controls.end() ; i++ )
434 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
435 c->doApply( p_intf );
439 if( number == SPrefsInputAndCodecs )
441 /* Device default selection */
442 char *psz_devicepath =
443 qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
444 if( !EMPTY_STR( psz_devicepath ) )
446 config_PutPsz( p_intf, "dvd", psz_devicepath );
447 config_PutPsz( p_intf, "vcd", psz_devicepath );
448 config_PutPsz( p_intf, "cd-audio", psz_devicepath );
452 #define saveBox( name, box ) {\
453 if( box->isChecked() ) { \
455 qs_filter.append( name ); \
458 else qs_filter.append( ":" ).append( name ); \
462 saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
463 saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
464 saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
465 saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
466 config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
468 QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
470 msg_Dbg( p_intf, "%i",
471 cachingCombo->itemData( cachingCombo->currentIndex() ).toInt() );
475 if( number == SPrefsInterface )
477 if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
478 config_PutPsz( p_intf, "intf", "skins2" );
479 if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
480 config_PutPsz( p_intf, "intf", "qt4" );
483 if( number == SPrefsAudio )
486 qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
487 if( qs_filter.isEmpty() )
489 /* the psz_filter is already empty, so we just append it needed */
490 if( b_normChecked ) qs_filter = "volnorm";
494 if( qs_filter.contains( "volnorm" ) )
496 /* The qs_filter not empty and contains "volnorm"
497 that we have to remove */
501 qs_filter.remove( "volnorm:" );
502 qs_filter.remove( ":volnorm" );
503 qs_filter.remove( "volnorm" );
506 else /* qs_filter not empty, but doesn't have volnorm inside */
507 if( b_normChecked ) qs_filter.append( ":volnorm" );
509 config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
513 void SPrefsPanel::clean()
516 void SPrefsPanel::lastfm_Changed( int i_state )
518 if( i_state == Qt::Checked )
519 config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
520 else if( i_state == Qt::Unchecked )
521 config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );