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"
30 #include "ui/sprefs_audio.h"
31 #include "ui/sprefs_input.h"
32 #include "ui/sprefs_video.h"
33 #include "ui/sprefs_subtitles.h"
34 #include "ui/sprefs_hotkeys.h"
35 #include "ui/sprefs_interface.h"
37 #include <vlc_config_cat.h>
41 #include <QToolButton>
42 #include <QButtonGroup>
44 #include <QVBoxLayout>
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/" #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"),
80 spref_cone_Subtitles_64.png, 3 );
81 ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and 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 this->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;
108 #define CONFIG_GENERIC( option, type, label, qcontrol ) \
109 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
112 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
113 p_config, label, ui.qcontrol, false ); \
114 controls.append( control ); \
117 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol ) \
118 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
121 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
122 p_config, label, ui.qcontrol ); \
123 controls.append( control ); \
126 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton ) \
127 p_config = config_FindConfig( VLC_OBJECT(p_intf), option ); \
130 control = new type ## ConfigControl( VLC_OBJECT(p_intf), \
131 p_config, label, ui.qcontrol, ui.qbutton, \
133 controls.append( control ); \
136 #define START_SPREFS_CAT( name , label ) \
137 case SPrefs ## name: \
139 Ui::SPrefs ## name ui; \
140 ui.setupUi( panel ); \
141 panel_label->setText( qtr( label ) );
143 #define END_SPREFS_CAT \
147 QVBoxLayout *panel_layout = new QVBoxLayout();
148 QWidget *panel = new QWidget();
149 panel_layout->setMargin( 3 );
152 QLabel *panel_label = new QLabel;
153 QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
154 labelFont.setPointSize( labelFont.pointSize() + 6 );
155 labelFont.setFamily( "Verdana" );
156 panel_label->setFont( labelFont );
159 QFrame *title_line = new QFrame;
160 title_line->setFrameShape(QFrame::HLine);
161 title_line->setFrameShadow(QFrame::Sunken);
163 QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
164 italicFont.setItalic( true );
168 /* Video Panel Implementation */
169 START_SPREFS_CAT( Video , "General video settings" );
170 CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
172 CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
173 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
174 CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
175 CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
176 CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
177 CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
178 CONFIG_GENERIC( "vout", Module, NULL, outputModule );
181 CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
182 CONFIG_GENERIC( "directx-device", StringList, NULL,
185 ui.directXBox->setVisible( false );
188 CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
189 snapshotsDirectory, snapshotsDirectoryBrowse );
190 CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
191 CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
192 snapshotsSequentialNumbering );
193 CONFIG_GENERIC( "snapshot-format", StringList, NULL,
197 /* Audio Panel Implementation */
198 START_SPREFS_CAT( Audio, "General audio settings" );
200 ui.OSSBrowse->hide();
201 ui.OSSDevice->hide();
203 ui.alsaDevice->hide();
204 ui.alsaLabel->hide();
206 ui.DirectXLabel->setVisible( false );
207 ui.DirectXDevice->setVisible( false );
209 CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
211 CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
213 CONFIG_GENERIC( "audio-language" , String , NULL,
214 preferredAudioLanguage );
216 CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
217 CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
220 CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
222 CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
223 CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
225 CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL,
228 CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName,
231 CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
232 // CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
233 CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
235 CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
238 /* Input and Codecs Panel Implementation */
239 START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings" );
241 /* CONFIG_GENERIC( );*/ //FIXME
243 CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
244 CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
247 /* CONFIG_GENERIC( );*/ //FIXME
249 CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
250 CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
251 CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
253 CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
255 ui.systemCodecBox->hide();
257 CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
258 CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
259 // CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record
262 /* Interface Panel */
263 START_SPREFS_CAT( Interface, "Interface settings" );
264 ui.defaultLabel->setFont( italicFont );
265 ui.skinsLabel->setFont( italicFont );
267 #if defined( WIN32 ) || defined (__APPLE__)
268 CONFIG_GENERIC( "language", StringList, NULL, language );
271 ui.languageLabel->hide();
275 p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
276 if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
278 ui.qt4->setChecked( true );
280 if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
282 ui.skins->setChecked( true );
284 //FIXME interface choice
286 CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
287 CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
289 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
290 CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
291 CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
292 EnqueueOneInterfaceMode );
294 ui.OneInterfaceBox->hide();
298 START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
299 CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
301 CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
302 CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
303 CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
305 CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
306 CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
308 CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
312 START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
317 panel_layout->addWidget(panel_label);
318 panel_layout->addWidget(title_line);
319 panel_layout->addWidget( panel );
320 panel_layout->addStretch( 2 );
322 this->setLayout(panel_layout);
325 void SPrefsPanel::apply()
327 QList<ConfigControl *>::Iterator i;
328 for( i = controls.begin() ; i != controls.end() ; i++ )
330 ConfigControl *c = qobject_cast<ConfigControl *>(*i);
331 c->doApply( p_intf );
335 void SPrefsPanel::clean()