]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 - New Simple Preferences look'n feel. Should work without too many segfaults...
[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
31 #include "components/simple_preferences.hpp"
32 #include "components/preferences_widgets.hpp"
33 #include "qt4.hpp"
34
35 #include <vlc_config_cat.h>
36
37 #include "ui/sprefs_audio.h"
38 #include "ui/sprefs_input.h"
39 #include "ui/sprefs_video.h"
40 #include "ui/sprefs_subtitles.h"
41 #include "ui/sprefs_hotkeys.h"
42 #include "ui/sprefs_interface.h"
43
44 #define ICON_HEIGHT 64
45 #define BUTTON_HEIGHT 76
46
47 /*********************************************************************
48  * The List of categories
49  *********************************************************************/
50 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51                                   QWidget( _parent ), p_intf( _p_intf )
52 {
53     QVBoxLayout *layout = new QVBoxLayout();
54
55     QButtonGroup *buttonGroup = new QButtonGroup( this );
56     buttonGroup->setExclusive ( true );
57     CONNECT( buttonGroup, buttonClicked ( int ),
58             this, switchPanel( int ) );
59
60 #define ADD_CATEGORY( button, label, icon, numb )                           \
61     QToolButton * button = new QToolButton( this );                         \
62     button->setIcon( QIcon( ":/pixmaps/" #icon ) );                         \
63     button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
64     button->setText( label );                                               \
65     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
66     button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
67     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
68     button->setAutoRaise( true );                                           \
69     button->setCheckable( true );                                           \
70     buttonGroup->addButton( button, numb );                                 \
71     layout->addWidget( button );
72
73     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74                   spref_cone_Interface_64.png, 0 );
75     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
76     ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
78                   spref_cone_Subtitles_64.png, 3 );
79     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80                   spref_cone_Input_64.png, 4 );
81     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
82
83     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
84     setLayout( layout );
85 }
86
87 void SPrefsCatList::switchPanel( int i )
88 {
89     emit currentItemChanged( i );
90 }
91
92 /*********************************************************************
93  * The Panels
94  *********************************************************************/
95 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
96                           int number ) : QWidget( _parent ), p_intf( _p_intf )
97 {
98     module_config_t *p_config;
99     ConfigControl *control;
100
101 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
102             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
103             if( p_config )                                                \
104             {                                                             \
105                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
106                            p_config, label, ui.qcontrol, false );         \
107                 controls.append( control );                               \
108             }
109
110 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
111             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
112             if( p_config )                                                \
113             {                                                             \
114                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
115                            p_config, label, ui.qcontrol );                \
116                 controls.append( control );                               \
117             }
118
119 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
120                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
121                 if( p_config )                                                \
122                 {                                                             \
123                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
124                                p_config, label, ui.qcontrol, ui.qbutton,      \
125                             false );                                          \
126                     controls.append( control );                               \
127                 }
128
129 #define START_SPREFS_CAT( name , label )    \
130         case SPrefs ## name:                \
131         {                                   \
132             Ui::SPrefs ## name ui;          \
133             ui.setupUi( panel );            \
134             panel_label->setText( qtr( label ) );
135
136 #define END_SPREFS_CAT      \
137             break;          \
138         }
139
140     QVBoxLayout *panel_layout = new QVBoxLayout();
141     QWidget *panel = new QWidget();
142
143     // Title Label
144     QLabel *panel_label = new QLabel;
145     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
146     labelFont.setPointSize( labelFont.pointSize() + 6 );
147     labelFont.setFamily( "Verdana" );
148     panel_label->setFont( labelFont );
149
150     // Title <hr>
151     QFrame *title_line = new QFrame;
152     title_line->setFrameShape(QFrame::HLine);
153     title_line->setFrameShadow(QFrame::Sunken);
154
155     switch( number )
156     {
157         /* Video Panel Implementation */
158         START_SPREFS_CAT( Video , "General video settings" );
159          #ifndef WIN32
160             ui.directXBox->setVisible( false );
161          #endif
162             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
163
164             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
165             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
166             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
167             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
168             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames);
169             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
170
171 #ifdef WIN32
172             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
173             CONFIG_GENERIC( "directx-device", StringList, NULL, 
174                     dXdisplayDevice );
175 #endif
176
177             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
178                     snapshotsDirectory, snapshotsDirectoryBrowse );
179             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
180             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
181                             snapshotsSequentialNumbering );
182             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
183                             snapshotsFormat );
184          END_SPREFS_CAT;
185
186          /* Audio Panel Implementation */
187         START_SPREFS_CAT( Audio,  "General audio settings" );
188 #ifdef WIN32
189             ui.OSSBrowse->hide();
190             ui.OSSDevice->hide();
191             ui.OSSLabel->hide();
192             ui.alsaDevice->hide();
193             ui.alsaLabel->hide();
194 #else
195             ui.DirectXLabel->setVisible( false );
196             ui.DirectXDevice->setVisible( false );
197 #endif
198          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
199
200          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
201                  defaultVolume );
202          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
203                     preferredAudioLanguage ); //FIXME
204
205          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
206          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
207                     detectionDolby );
208
209          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
210 #ifndef WIN32
211          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
212          CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
213 #else
214          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
215                  DirectXDevice );
216 #endif
217          CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName, 
218                  fileBrowseButton );
219
220          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
221 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
222          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
223                  volNormalizer );
224          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
225         END_SPREFS_CAT;
226
227         /* Input and Codecs Panel Implementation */
228         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
229           /* Disk Devices */
230 /*          CONFIG_GENERIC( );*/ //FIXME
231
232           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
233           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
234
235           /* Caching */
236 /*          CONFIG_GENERIC( );*/ //FIXME
237
238           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
239           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
240           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
241
242           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
243           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
244 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
245         END_SPREFS_CAT;
246
247         /* Interface Panel */
248         START_SPREFS_CAT( Interface, "Interfaces settings" );
249             
250             CONFIG_GENERIC( "language", StringList, NULL, language );//FIXME
251 #if !defined( WIN32 ) && !defined( HAVE_DBUS_3 )
252             ui.OneInterfaceBox->hide();
253 #endif
254             /* interface */
255 /*            p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
256             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
257                     ui.qt4->setChecked( true );
258             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
259                     ui.skins->setChecked( true );*/
260 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
261             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
262             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, 
263                     skinBrowse );
264 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
265             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
266             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, 
267                     EnqueueOneInterfaceMode );
268 #endif
269         END_SPREFS_CAT;
270
271         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
272             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
273
274             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
275             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );//FIXME
276             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font, 
277                     fontBrowse ); 
278             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
279             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
280                             fontSize );
281             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
282
283         END_SPREFS_CAT;
284
285         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
286         //FIMXE
287         END_SPREFS_CAT;
288         }
289
290     panel_layout->addWidget(panel_label);
291     panel_layout->addWidget(title_line);
292     panel_layout->addWidget( panel );
293     panel_layout->addStretch( 2 );
294
295     this->setLayout(panel_layout);
296 }
297
298 void SPrefsPanel::apply()
299 {
300     QList<ConfigControl *>::Iterator i;
301     for( i = controls.begin() ; i != controls.end() ; i++ )
302     {
303         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
304         c->doApply( p_intf );
305     }
306 }
307
308 void SPrefsPanel::clean()
309 {}
310