Qt4 - Don't use html tags in strings ... This breaks all the i18n thing.
[vlc.git] / 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 76
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
86     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
87     setLayout( layout );
88 }
89
90 void SPrefsCatList::switchPanel( int i )
91 {
92     emit currentItemChanged( i );
93 }
94
95 /*********************************************************************
96  * The Panels
97  *********************************************************************/
98 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
99                           int number ) : QWidget( _parent ), p_intf( _p_intf )
100 {
101     module_config_t *p_config;
102     ConfigControl *control;
103
104 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
105             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
106             if( p_config )                                                \
107             {                                                             \
108                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
109                            p_config, label, ui.qcontrol, false );         \
110                 controls.append( control );                               \
111             }
112
113 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
114             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
115             if( p_config )                                                \
116             {                                                             \
117                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
118                            p_config, label, ui.qcontrol );                \
119                 controls.append( control );                               \
120             }
121
122 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
123                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
124                 if( p_config )                                                \
125                 {                                                             \
126                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
127                                p_config, label, ui.qcontrol, ui.qbutton,      \
128                             false );                                          \
129                     controls.append( control );                               \
130                 }
131
132 #define START_SPREFS_CAT( name , label )    \
133         case SPrefs ## name:                \
134         {                                   \
135             Ui::SPrefs ## name ui;          \
136             ui.setupUi( panel );            \
137             panel_label->setText( qtr( label ) );
138
139 #define END_SPREFS_CAT      \
140             break;          \
141         }
142
143     QVBoxLayout *panel_layout = new QVBoxLayout();
144     QWidget *panel = new QWidget();
145
146     // Title Label
147     QLabel *panel_label = new QLabel;
148     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
149     labelFont.setPointSize( labelFont.pointSize() + 6 );
150     labelFont.setFamily( "Verdana" );
151     panel_label->setFont( labelFont );
152
153     // Title <hr>
154     QFrame *title_line = new QFrame;
155     title_line->setFrameShape(QFrame::HLine);
156     title_line->setFrameShadow(QFrame::Sunken);
157
158     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
159     italicFont.setItalic( true );
160
161     switch( number )
162     {
163         /* Video Panel Implementation */
164         START_SPREFS_CAT( Video , "General video settings" );
165          #ifndef WIN32
166             ui.directXBox->setVisible( false );
167          #endif
168             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
169
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( "vout", Module, NULL, outputModule );
176
177 #ifdef WIN32
178             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
179             CONFIG_GENERIC( "directx-device", StringList, NULL, 
180                     dXdisplayDevice );
181 #endif
182
183             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
184                     snapshotsDirectory, snapshotsDirectoryBrowse );
185             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
186             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
187                             snapshotsSequentialNumbering );
188             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
189                             snapshotsFormat );
190          END_SPREFS_CAT;
191
192          /* Audio Panel Implementation */
193         START_SPREFS_CAT( Audio,  "General audio settings" );
194 #ifdef WIN32
195             ui.OSSBrowse->hide();
196             ui.OSSDevice->hide();
197             ui.OSSLabel->hide();
198             ui.alsaDevice->hide();
199             ui.alsaLabel->hide();
200 #else
201             ui.DirectXLabel->setVisible( false );
202             ui.DirectXDevice->setVisible( false );
203 #endif
204          CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
205
206          CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL, 
207                  defaultVolume );
208          CONFIG_GENERIC( "audio-language" , StringList , NULL, 
209                     preferredAudioLanguage ); //FIXME
210
211          CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
212          CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL, 
213                     detectionDolby );
214
215          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
216 #ifndef WIN32
217          CONFIG_GENERIC( "alsadev" , StringList , NULL, alsaDevice );
218          CONFIG_GENERIC_FILE( "dspdev" , File , NULL, OSSDevice, OSSBrowse );
219 #else
220          CONFIG_GENERIC( "directx-audio-device" , IntegerList, NULL, 
221                  DirectXDevice );
222 #endif
223          CONFIG_GENERIC_FILE( "audiofile-file" , File , NULL, FileName, 
224                  fileBrowseButton );
225
226          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
227 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
228          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL, 
229                  volNormalizer );
230          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
231         END_SPREFS_CAT;
232
233         /* Input and Codecs Panel Implementation */
234         START_SPREFS_CAT( InputAndCodecs, "Input & Codecs settings"  );
235           /* Disk Devices */
236 /*          CONFIG_GENERIC( );*/ //FIXME
237
238           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
239           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
240
241           /* Caching */
242 /*          CONFIG_GENERIC( );*/ //FIXME
243
244           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
245           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
246           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
247
248           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
249           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
250 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record 
251         END_SPREFS_CAT;
252
253         /* Interface Panel */
254         START_SPREFS_CAT( Interface, "Interface settings" );
255             ui.defaultLabel->setFont( italicFont );
256             ui.skinsLabel->setFont( italicFont );
257
258             CONFIG_GENERIC( "language", StringList, NULL, language );//FIXME
259 #if !defined( WIN32 ) && !defined( HAVE_DBUS_3 )
260             ui.OneInterfaceBox->hide();
261 #endif
262             /* interface */
263 /*            p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
264             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
265                     ui.qt4->setChecked( true );
266             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
267                     ui.skins->setChecked( true );*/
268 /*            CONFIG_GENERIC( "intf", Module, NULL, ??? ); */ //FIXME interface choice
269             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
270             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, 
271                     skinBrowse );
272 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
273             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
274             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, 
275                     EnqueueOneInterfaceMode );
276 #endif
277         END_SPREFS_CAT;
278
279         START_SPREFS_CAT( Subtitles, "Subtitles & OSD settings" );
280             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
281
282             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
283             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );//FIXME
284             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font, 
285                     fontBrowse ); 
286             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
287             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
288                             fontSize );
289             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
290
291         END_SPREFS_CAT;
292
293         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
294         //FIMXE
295         END_SPREFS_CAT;
296         }
297
298     panel_layout->addWidget(panel_label);
299     panel_layout->addWidget(title_line);
300     panel_layout->addWidget( panel );
301     panel_layout->addStretch( 2 );
302
303     this->setLayout(panel_layout);
304 }
305
306 void SPrefsPanel::apply()
307 {
308     QList<ConfigControl *>::Iterator i;
309     for( i = controls.begin() ; i != controls.end() ; i++ )
310     {
311         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
312         c->doApply( p_intf );
313     }
314 }
315
316 void SPrefsPanel::clean()
317 {}
318