]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Qt4 - whitespaces cleaning, code line size, code beautification ;)
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
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 $
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 "components/simple_preferences.hpp"
27 #include "components/preferences_widgets.hpp"
28
29 #include "ui/sprefs_input.h"
30 #include "ui/sprefs_audio.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"
35
36 #include <vlc_config_cat.h>
37 #include <vlc_configuration.h>
38
39 #include <QString>
40 #include <QFont>
41 #include <QToolButton>
42 #include <QButtonGroup>
43 #include <QUrl>
44 #include <QVBoxLayout>
45
46 #define ICON_HEIGHT 64
47 #define BUTTON_HEIGHT 74
48
49 /*********************************************************************
50  * The List of categories
51  *********************************************************************/
52 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
53                                   QWidget( _parent ), p_intf( _p_intf )
54 {
55     QVBoxLayout *layout = new QVBoxLayout();
56
57     QButtonGroup *buttonGroup = new QButtonGroup( this );
58     buttonGroup->setExclusive ( true );
59     CONNECT( buttonGroup, buttonClicked ( int ),
60             this, switchPanel( int ) );
61
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 );
74
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 );
84
85     SPrefsInterface->setChecked( true );
86     layout->setMargin( 0 );
87     layout->setSpacing( 1 );
88
89     this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
90     setLayout( layout );
91
92 }
93
94 void SPrefsCatList::switchPanel( int i )
95 {
96     emit currentItemChanged( i );
97 }
98
99 /*********************************************************************
100  * The Panels
101  *********************************************************************/
102 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
103                           int number ) : QWidget( _parent ), p_intf( _p_intf )
104 {
105     module_config_t *p_config;
106     ConfigControl *control;
107
108 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
109             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
110             if( p_config )                                                \
111             {                                                             \
112                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
113                            p_config, label, ui.qcontrol, false );         \
114                 controls.append( control );                               \
115             }
116
117 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
118             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
119             if( p_config )                                                \
120             {                                                             \
121                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
122                            p_config, label, ui.qcontrol );                \
123                 controls.append( control );                               \
124             }
125
126 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
127                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
128                 if( p_config )                                                \
129                 {                                                             \
130                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
131                                p_config, label, ui.qcontrol, ui.qbutton,      \
132                             false );                                          \
133                     controls.append( control );                               \
134                 }
135
136 #define START_SPREFS_CAT( name , label )    \
137         case SPrefs ## name:                \
138         {                                   \
139             Ui::SPrefs ## name ui;          \
140             ui.setupUi( panel );            \
141             panel_label->setText( label );
142
143 #define END_SPREFS_CAT      \
144             break;          \
145         }
146
147     QVBoxLayout *panel_layout = new QVBoxLayout();
148     QWidget *panel = new QWidget();
149     panel_layout->setMargin( 3 );
150
151     // Title Label
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 );
157
158     // Title <hr>
159     QFrame *title_line = new QFrame;
160     title_line->setFrameShape(QFrame::HLine);
161     title_line->setFrameShadow(QFrame::Sunken);
162
163     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
164     italicFont.setItalic( true );
165
166     switch( number )
167     {
168         /******************************
169          * VIDEO Panel Implementation *
170          ******************************/
171         START_SPREFS_CAT( Video , qtr("General video settings") );
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( "overlay", Bool, NULL, overlay );
180             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
181
182 #ifdef WIN32
183             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
184             CONFIG_GENERIC( "directx-device", StringList, NULL,
185                     dXdisplayDevice );
186 #else
187             ui.directXBox->setVisible( false );
188 #endif
189
190             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
191                     snapshotsDirectory, snapshotsDirectoryBrowse );
192             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
193             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
194                             snapshotsSequentialNumbering );
195             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
196                             snapshotsFormat );
197          END_SPREFS_CAT;
198
199         /******************************
200          * AUDIO Panel Implementation *
201          ******************************/
202         START_SPREFS_CAT( Audio, qtr("General audio settings") );
203
204             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
205
206             /* General Audio Options */
207             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
208                                      defaultVolume );
209             CONFIG_GENERIC( "audio-language" , String , NULL,
210                             preferredAudioLanguage );
211
212             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
213             CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
214                             detectionDolby );
215
216             CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
217 //          CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
218             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
219                                     volNormalizer );
220             CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
221
222             /* Audio Output Specifics */
223             CONFIG_GENERIC( "aout", Module, NULL, outputModule );
224
225             CONNECT( ui.outputModule, currentIndexChanged( int ), this,
226                              updateAudioOptions( int ) );
227             audioOutput = ui.outputModule;
228
229         //FIXME: use modules_Exists
230 #ifndef WIN32
231             CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel, alsaDevice );
232             CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
233                                  OSSBrowse );
234 #else
235             CONFIG_GENERIC( "directx-audio-device", IntegerList,
236                     ui.DirectXLabel, DirectXDevice );
237 #endif
238         // File exists everywhere
239             CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
240                                  fileName, fileBrowseButton );
241             alsa_options = ui.alsaControl;
242             oss_options = ui.OSSControl;
243             directx_options = ui.DirectXControl;
244             file_options = ui.fileControl;
245
246         /* and hide if necessary */
247 #ifdef WIN32
248             oss_options->hide();
249             alsa_options->hide();
250 #else
251             directx_options->hide();
252 #endif
253
254             updateAudioOptions( audioOutput->currentIndex() );
255
256             /* LastFM */
257             CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
258                          lastfm_user_edit );
259             CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
260                          lastfm_pass_edit );
261             ui.lastfm_user_edit->hide();
262             ui.lastfm_user_label->hide();
263             ui.lastfm_pass_edit->hide();
264             ui.lastfm_pass_label->hide();
265
266             if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
267                 ui.lastfm->setCheckState( Qt::Checked );
268             else
269                 ui.lastfm->setCheckState( Qt::Unchecked );
270             CONNECT( ui.lastfm, stateChanged( int ), this ,
271                     lastfm_Changed( int ) );
272
273         END_SPREFS_CAT;
274
275         /* Input and Codecs Panel Implementation */
276         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
277             inputDevice = ui.DVDDevice;
278           /* Disk Devices */
279             {
280                 ui.DVDDevice->setToolTip(
281                     qtr( "If this propriety is blank, then you have\n"
282                          "values for DVD, VCD, and CDDA.\n"
283                          "You can define a unique one or set that in"
284                          "the advanced preferences" ) );
285                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
286                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
287                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
288                 if( ( *psz_cddadiscpath == *psz_dvddiscpath )
289                    && ( *psz_dvddiscpath == *psz_vcddiscpath ) )
290                 {
291                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
292                 }
293                 delete psz_cddadiscpath; delete psz_dvddiscpath;
294                 delete psz_vcddiscpath;
295             }
296
297           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
298           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
299
300           /* Caching */
301 /*          CONFIG_GENERIC( );*/ //FIXME
302
303           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
304           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
305           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
306 #ifdef WIN32
307           CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
308 #else
309           ui.systemCodecBox->hide();
310 #endif
311           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
312           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
313 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record
314         END_SPREFS_CAT;
315
316         /* Interface Panel */
317         START_SPREFS_CAT( Interface, qtr("Interface settings") );
318             ui.defaultLabel->setFont( italicFont );
319             ui.skinsLabel->setFont( italicFont );
320
321 #if defined( WIN32 ) || defined (__APPLE__)
322             CONFIG_GENERIC( "language", StringList, NULL, language );
323 #else
324             ui.language->hide();
325             ui.languageLabel->hide();
326 #endif
327
328            /* interface */
329             p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
330             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
331             {
332                 ui.qt4->setChecked( true );
333             }
334             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
335             {
336                 ui.skins->setChecked( true );
337             }
338             skinInterfaceButton = ui.skins;
339             qtInterfaceButton = ui.qt4;
340
341             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
342             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
343                     skinBrowse );
344 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
345             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
346             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
347                     EnqueueOneInterfaceMode );
348 #else
349             ui.OneInterfaceBox->hide();
350 #endif
351         END_SPREFS_CAT;
352
353         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
354             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
355
356             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
357             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
358             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
359                             fontBrowse );
360             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
361             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
362                             fontSize );
363             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
364
365         END_SPREFS_CAT;
366
367         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
368         //FIMXE
369         END_SPREFS_CAT;
370         }
371
372     panel_layout->addWidget(panel_label);
373     panel_layout->addWidget(title_line);
374     panel_layout->addWidget( panel );
375     panel_layout->addStretch( 2 );
376
377     this->setLayout(panel_layout);
378 }
379
380 void SPrefsPanel::updateAudioOptions( int number)
381 {
382     QString value = audioOutput->itemData( number ).toString();
383     msg_Dbg( p_intf, "I was here, waiting for funman, %s", qtu( value ) );
384
385 #ifndef WIN32
386     oss_options->hide();
387     alsa_options->hide();
388 #else
389     directx_options->hide();
390 #endif
391     file_options->hide();
392
393    if( value == "aout_file" )
394          file_options->show();
395 #ifndef WIN32
396     else if( value == "alsa" )
397         alsa_options->show();
398     else if( value == "oss" )
399         oss_options->show();
400 #else
401     else if( value == "directx" )
402         directx_options->show();
403 #endif
404 }
405
406 void SPrefsPanel::apply()
407 {
408     QList<ConfigControl *>::Iterator i;
409     for( i = controls.begin() ; i != controls.end() ; i++ )
410     {
411         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
412         c->doApply( p_intf );
413     }
414
415     /* Devices */
416     //FIXME is it qta or qtu ????
417     char *psz_devicepath = qtu( inputDevice->text() );
418     if( !EMPTY_STR( psz_devicepath ) )
419     {
420         config_PutPsz( p_intf, "dvd", psz_devicepath );
421         config_PutPsz( p_intf, "vcd", psz_devicepath );
422         config_PutPsz( p_intf, "cd-audio", psz_devicepath );
423     }
424
425     /* Interfaces */
426     if( skinInterfaceButton->isChecked() )
427        config_PutPsz( p_intf, "intf", "skins2" );
428     if( qtInterfaceButton->isChecked() )
429         config_PutPsz( p_intf, "intf", "qt4" );
430 }
431
432 void SPrefsPanel::clean()
433 {}
434
435 void SPrefsPanel::lastfm_Changed( int i_state )
436 {
437     if( i_state == Qt::Checked )
438         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
439     else if( i_state == Qt::Unchecked )
440         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
441 }