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 "ui/sprefs_audio.h"
30 #include "ui/sprefs_input.h"
31 #include "ui/sprefs_video.h"
32 #include "ui/sprefs_subtitles.h"
33 #include "ui/sprefs_hotkeys.h"
34 #include "ui/sprefs_interface.h"
36 #include <vlc_config_cat.h>
40 #include <QToolButton>
41 #include <QButtonGroup>
43 #include <QVBoxLayout>
45 #define ICON_HEIGHT 64
46 #define BUTTON_HEIGHT 74
48 /*********************************************************************
49 * The List of categories
50 *********************************************************************/
51 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
52 QWidget( _parent ), p_intf( _p_intf )
54 QVBoxLayout *layout = new QVBoxLayout();
56 QButtonGroup *buttonGroup = new QButtonGroup( this );
57 buttonGroup->setExclusive ( true );
58 CONNECT( buttonGroup, buttonClicked ( int ),
59 this, switchPanel( int ) );
61 #define ADD_CATEGORY( button, label, icon, numb ) \
62 QToolButton * button = new QToolButton( this ); \
63 button->setIcon( QIcon( ":/pixmaps/" #icon ) ); \
64 button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) ); \
65 button->setText( label ); \
66 button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); \
67 button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT); \
68 button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ; \
69 button->setAutoRaise( true ); \
70 button->setCheckable( true ); \
71 buttonGroup->addButton( button, numb ); \
72 layout->addWidget( button );
74 ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
75 spref_cone_Interface_64.png, 0 );
76 ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
77 ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
78 ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
79 spref_cone_Subtitles_64.png, 3 );
80 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
81 spref_cone_Input_64.png, 4 );
82 ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
84 SPrefsInterface->setChecked( true );
85 layout->setMargin( 0 );
86 layout->setSpacing( 1 );
88 this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
93 void SPrefsCatList::switchPanel( int i )
95 emit currentItemChanged( i );
98 /*********************************************************************
100 *********************************************************************/
101 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
102 int number ) : QWidget( _parent ), p_intf( _p_intf )
104 module_config_t *p_config;
105 ConfigControl *control;
107 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
108 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
111 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
112 p_config, label, ui.qcontrol, false ); \
113 controls.append( control ); \
116 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
117 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
120 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
121 p_config, label, ui.qcontrol ); \
122 controls.append( control ); \
125 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
126 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
129 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
130 p_config, label, ui.qcontrol, ui.qbutton, \
132 controls.append( control ); \
135 #define START_SPREFS_CAT( name , label ) \
136 case SPrefs ## name: \
138 Ui::SPrefs ## name ui; \
139 ui.setupUi( panel ); \
140 panel_label->setText( label );
142 #define END_SPREFS_CAT \
146 QVBoxLayout *panel_layout = new QVBoxLayout();
147 QWidget *panel = new QWidget();
148 panel_layout->setMargin( 3 );
151 QLabel *panel_label = new QLabel;
152 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
153 labelFont.setPointSize( labelFont.pointSize() + 6 );
154 labelFont.setFamily( "Verdana" );
155 panel_label->setFont( labelFont );
158 QFrame *title_line = new QFrame;
159 title_line->setFrameShape(QFrame::HLine);
160 title_line->setFrameShadow(QFrame::Sunken);
162 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
163 italicFont.setItalic( true );
167 /* Video Panel Implementation */
168 START_SPREFS_CAT( Video , qtr("General video settings") );
169 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
171 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
172 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
173 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
174 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
175 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
176 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
177 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
180 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
181 CONFIG_GENERIC( "directx-device", StringList, NULL,
184 ui.directXBox->setVisible( false );
187 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
188 snapshotsDirectory, snapshotsDirectoryBrowse );
189 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
190 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
191 snapshotsSequentialNumbering );
192 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
196 /* Audio Panel Implementation */
197 START_SPREFS_CAT( Audio, qtr("General audio settings") );
199 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
201 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
203 CONFIG_GENERIC( "audio-language" , String , NULL,
204 preferredAudioLanguage );
206 CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
207 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
210 CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
211 CONNECT( control, Updated(), this, AudioDeviceChanged() );
212 QString aout_value = (dynamic_cast<ModuleConfigControl*>(control))->getValue();
214 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel, alsaDevice );
215 alsa_options = control;
216 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
218 oss_options = control;
220 CONFIG_GENERIC( "directx-audio-device" , IntegerList, ui.DirectXLabel,
222 directx_options = control;
224 CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.FileLabel, FileName,
226 file_options = control;
229 ui.OSSBrowse->hide();
230 ui.OSSDevice->hide();
232 ui.alsaDevice->hide();
233 ui.alsaLabel->hide();
235 ui.DirectXLabel->setVisible( false );
236 ui.DirectXDevice->setVisible( false );
239 updateAudioOptions( aout_value );
241 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
242 // CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
243 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
245 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
248 if( control_Exists( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
249 ui.lastfm->setCheckState( Qt::Checked );
251 ui.lastfm->setCheckState( Qt::Unchecked );
252 CONNECT( ui.lastfm, stateChanged( int ), this , lastfm_Changed( int ) );
254 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
256 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
260 /* Input and Codecs Panel Implementation */
261 START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
263 /* CONFIG_GENERIC( );*/ //FIXME
265 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
266 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
269 /* CONFIG_GENERIC( );*/ //FIXME
271 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
272 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
273 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
275 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
277 ui.systemCodecBox->hide();
279 CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
280 CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
281 // CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record
284 /* Interface Panel */
285 START_SPREFS_CAT( Interface, qtr("Interface settings") );
286 ui.defaultLabel->setFont( italicFont );
287 ui.skinsLabel->setFont( italicFont );
289 #if defined( WIN32 ) || defined (__APPLE__)
290 CONFIG_GENERIC( "language", StringList, NULL, language );
293 ui.languageLabel->hide();
297 p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
298 if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
300 ui.qt4->setChecked( true );
302 if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
304 ui.skins->setChecked( true );
306 //FIXME interface choice
308 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
309 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
311 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
312 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
313 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
314 EnqueueOneInterfaceMode );
316 ui.OneInterfaceBox->hide();
320 START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
321 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
323 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
324 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
325 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
327 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
328 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
330 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
334 START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
339 panel_layout->addWidget(panel_label);
340 panel_layout->addWidget(title_line);
341 panel_layout->addWidget( panel );
342 panel_layout->addStretch( 2 );
344 this->setLayout(panel_layout);
347 void SPrefsPanel::AudioDeviceChanged()
349 ModuleConfigControl *module_config =
350 dynamic_cast<ModuleConfigControl*>( sender() );
351 updateAudioOptions( module_config->getValue() );
354 void SPrefsPanel::updateAudioOptions( QString value )
357 alsa_options->hide();
360 directx_options->hide();
362 file_options->hide();
364 if( value == "aout_file" )
365 file_options->show();
367 else if( value == "alsa" )
368 alsa_options->show();
369 else if( value == "oss" )
372 else if( value == "directx" )
373 directx_options->show();
377 void SPrefsPanel::apply()
379 QList<ConfigControl *>::Iterator i;
380 for( i = controls.begin() ; i != controls.end() ; i++ )
382 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
383 c->doApply( p_intf );
387 void SPrefsPanel::clean()
390 void SPrefsPanel::lastfm_Changed( int i_state )
393 if( i_state == Qt::Checked )
394 control_Add( VLC_OBJECT( p_intf ), "audioscrobbler" );
395 else if( i_state == Qt::Unchecked )
396 control_Remove( VLC_OBJECT( p_intf ), "audioscrobbler" );