]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 - Cosmetic changes.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 #include <QString>
27 #include <QFont>
28 #include <QToolButton>
29 #include <QButtonGroup>
30 #include <QUrl>
31
32 #include "components/simple_preferences.hpp"
33 #include "components/preferences_widgets.hpp"
34 #include "qt4.hpp"
35
36 #include <vlc_config_cat.h>
37
38 #include "ui/sprefs_audio.h"
39 #include "ui/sprefs_input.h"
40 #include "ui/sprefs_video.h"
41 #include "ui/sprefs_subtitles.h"
42 #include "ui/sprefs_hotkeys.h"
43 #include "ui/sprefs_interface.h"
44
45 #define ICON_HEIGHT 64
46 #define BUTTON_HEIGHT 74
47
48 /*********************************************************************
49  * The List of categories
50  *********************************************************************/
51 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
52                                   QWidget( _parent ), p_intf( _p_intf )
53 {
54     QVBoxLayout *layout = new QVBoxLayout();
55
56     QButtonGroup *buttonGroup = new QButtonGroup( this );
57     buttonGroup->setExclusive ( true );
58     CONNECT( buttonGroup, buttonClicked ( int ),
59             this, switchPanel( int ) );
60
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 );
73
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 );
83
84     SPrefsInterface->setChecked( true );
85     layout->setMargin( 0 );
86     layout->setSpacing( 1 );
87
88     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
89     setLayout( layout );
90
91 }
92
93 void SPrefsCatList::switchPanel( int i )
94 {
95     emit currentItemChanged( i );
96 }
97
98 /*********************************************************************
99  * The Panels
100  *********************************************************************/
101 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
102                           int number ) : QWidget( _parent ), p_intf( _p_intf )
103 {
104     module_config_t *p_config;
105     ConfigControl *control;
106
107 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
108             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
109             if( p_config )                                                \
110             {                                                             \
111                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
112                            p_config, label, ui.qcontrol, false );         \
113                 controls.append( control );                               \
114             }
115
116 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
117             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
118             if( p_config )                                                \
119             {                                                             \
120                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
121                            p_config, label, ui.qcontrol );                \
122                 controls.append( control );                               \
123             }
124
125 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
126                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
127                 if( p_config )                                                \
128                 {                                                             \
129                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
130                                p_config, label, ui.qcontrol, ui.qbutton,      \
131                             false );                                          \
132                     controls.append( control );                               \
133                 }
134
135 #define START_SPREFS_CAT( name , label )    \
136         case SPrefs ## name:                \
137         {                                   \
138             Ui::SPrefs ## name ui;          \
139             ui.setupUi( panel );            \
140             panel_label->setText( qtr( label ) );
141
142 #define END_SPREFS_CAT      \
143             break;          \
144         }
145
146     QVBoxLayout *panel_layout = new QVBoxLayout();
147     QWidget *panel = new QWidget();
148     panel_layout->setMargin( 3 );
149
150     // Title Label
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 );
156
157     // Title <hr>
158     QFrame *title_line = new QFrame;
159     title_line->setFrameShape(QFrame::HLine);
160     title_line->setFrameShadow(QFrame::Sunken);
161
162     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
163     italicFont.setItalic( true );
164
165     switch( number )
166     {
167         /* Video Panel Implementation */
168         START_SPREFS_CAT( Video , "General video settings" );
169          #ifndef WIN32
170             ui.directXBox->setVisible( false );
171          #endif
172             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
173
174             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
175             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
176             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
177             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
178             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames);
179             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
180
181 #ifdef WIN32
182             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
183             CONFIG_GENERIC( "directx-device", StringList, NULL, 
184                     dXdisplayDevice );
185 #endif
186
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,
193                             snapshotsFormat );
194          END_SPREFS_CAT;
195
196          /* Audio Panel Implementation */
197         START_SPREFS_CAT( Audio,  "General audio settings" );
198 #ifdef WIN32
199             ui.OSSBrowse->hide();
200             ui.OSSDevice->hide();
201             ui.OSSLabel->hide();
202             ui.alsaDevice->hide();
203             ui.alsaLabel->hide();
204 #else
205             ui.DirectXLabel->setVisible( false );
206             ui.DirectXDevice->setVisible( false );
207 #endif
208          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
209
210          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
211                  defaultVolume );
212          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
213                     preferredAudioLanguage ); //FIXME
214
215          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
216          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
217                     detectionDolby );
218
219          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
220 #ifndef WIN32
221          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
222          CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
223 #else
224          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
225                  DirectXDevice );
226 #endif
227          CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName, 
228                  fileBrowseButton );
229
230          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
231 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
232          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
233                  volNormalizer );
234          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
235         END_SPREFS_CAT;
236
237         /* Input and Codecs Panel Implementation */
238         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
239           /* Disk Devices */
240 /*          CONFIG_GENERIC( );*/ //FIXME
241
242           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
243           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
244
245           /* Caching */
246 /*          CONFIG_GENERIC( );*/ //FIXME
247
248           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
249           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
250           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
251
252           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
253           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
254 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
255         END_SPREFS_CAT;
256
257         /* Interface Panel */
258         START_SPREFS_CAT( Interface, "Interface settings" );
259             ui.defaultLabel->setFont( italicFont );
260             ui.skinsLabel->setFont( italicFont );
261
262             CONFIG_GENERIC( "language", StringList, NULL, language );//FIXME
263 #if !defined( WIN32 ) && !defined( HAVE_DBUS_3 )
264             ui.OneInterfaceBox->hide();
265 #endif
266             /* interface */
267 /*            p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
268             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
269                     ui.qt4->setChecked( true );
270             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
271                     ui.skins->setChecked( true );*/
272 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
273             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
274             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, 
275                     skinBrowse );
276 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
277             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
278             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, 
279                     EnqueueOneInterfaceMode );
280 #endif
281         END_SPREFS_CAT;
282
283         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
284             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
285
286             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
287             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );//FIXME
288             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font, 
289                     fontBrowse ); 
290             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
291             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
292                             fontSize );
293             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
294
295         END_SPREFS_CAT;
296
297         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
298         //FIMXE
299         END_SPREFS_CAT;
300         }
301
302     panel_layout->addWidget(panel_label);
303     panel_layout->addWidget(title_line);
304     panel_layout->addWidget( panel );
305     panel_layout->addStretch( 2 );
306
307     this->setLayout(panel_layout);
308 }
309
310 void SPrefsPanel::apply()
311 {
312     QList<ConfigControl *>::Iterator i;
313     for( i = controls.begin() ; i != controls.end() ; i++ )
314     {
315         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
316         c->doApply( p_intf );
317     }
318 }
319
320 void SPrefsPanel::clean()
321 {}
322