]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
qt4: fix the use of HTTP in open dialog
[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_audio.h"
30 #include "ui/sprefs_input.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_control.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         /* Video Panel Implementation */
169         START_SPREFS_CAT( Video , qtr("General video settings") );
170             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
171
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 );
179
180 #ifdef WIN32
181             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
182             CONFIG_GENERIC( "directx-device", StringList, NULL,
183                     dXdisplayDevice );
184 #else
185             ui.directXBox->setVisible( false );
186 #endif
187
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,
194                             snapshotsFormat );
195          END_SPREFS_CAT;
196
197          /* Audio Panel Implementation */
198         START_SPREFS_CAT( Audio, qtr("General audio settings") );
199
200         CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
201
202         CONFIG_GENERIC_NO_BOOL( "volume" ,  IntegerRangeSlider, NULL,
203                  defaultVolume );
204         CONFIG_GENERIC( "audio-language" , String , NULL,
205                     preferredAudioLanguage );
206
207         CONFIG_GENERIC( "spdif" , Bool , NULL, spdifBox );
208         CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
209                     detectionDolby );
210
211          CONFIG_GENERIC( "aout" , Module , NULL, outputModule );
212          CONNECT( control, Updated(), this, AudioDeviceChanged() );
213          QString aout_value = (dynamic_cast<ModuleConfigControl*>(control))->getValue();
214 #ifndef WIN32
215          CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel, alsaDevice );
216          alsa_options = control;
217          CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
218                  OSSBrowse );
219          oss_options = control;
220 #else
221          CONFIG_GENERIC( "directx-audio-device" , IntegerList, ui.DirectXLabel,
222                  DirectXDevice );
223          directx_options = control;
224 #endif
225          CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.FileLabel, FileName,
226                  fileBrowseButton );
227          file_options = control;
228
229 #ifdef WIN32
230             ui.OSSBrowse->hide();
231             ui.OSSDevice->hide();
232             ui.OSSLabel->hide();
233             ui.alsaDevice->hide();
234             ui.alsaLabel->hide();
235 #else
236             ui.DirectXLabel->setVisible( false );
237             ui.DirectXDevice->setVisible( false );
238 #endif
239
240         updateAudioOptions( aout_value );
241
242          CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
243 //         CONFIG_GENERIC( "" , Bool, NULL, ); activation of normalizer //FIXME
244          CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
245                  volNormalizer );
246          CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
247
248
249         if( control_Exists( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
250             ui.lastfm->setCheckState( Qt::Checked );
251         else
252             ui.lastfm->setCheckState( Qt::Unchecked );
253         CONNECT( ui.lastfm, stateChanged( int ), this , lastfm_Changed( int ) );
254
255          CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
256                          lastfm_user_edit );
257          CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
258                          lastfm_pass_edit );
259         END_SPREFS_CAT;
260
261         /* Input and Codecs Panel Implementation */
262         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
263           /* Disk Devices */
264 /*          CONFIG_GENERIC( );*/ //FIXME
265
266           CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
267           CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
268
269           /* Caching */
270 /*          CONFIG_GENERIC( );*/ //FIXME
271
272           CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
273           CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
274           CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
275 #ifdef WIN32
276           CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
277 #else
278           ui.systemCodecBox->hide();
279 #endif
280           CONFIG_GENERIC( "timeshift-force", Bool, NULL, timeshiftBox );
281           CONFIG_GENERIC( "dump-force", Bool, NULL, DumpBox );
282 //        CONFIG_GENERIC( "", Bool, NULL, RecordBox ); //FIXME activate record
283         END_SPREFS_CAT;
284
285         /* Interface Panel */
286         START_SPREFS_CAT( Interface, qtr("Interface settings") );
287             ui.defaultLabel->setFont( italicFont );
288             ui.skinsLabel->setFont( italicFont );
289
290 #if defined( WIN32 ) || defined (__APPLE__)
291             CONFIG_GENERIC( "language", StringList, NULL, language );
292 #else
293             ui.language->hide();
294             ui.languageLabel->hide();
295 #endif
296
297            /* interface */
298             p_config = config_FindConfig( VLC_OBJECT(p_intf), "intf" );
299             if( p_config->value.psz && strcmp( p_config->value.psz, "qt4" ))
300             {
301                 ui.qt4->setChecked( true );
302             }
303             if( p_config->value.psz && strcmp( p_config->value.psz, "skins2" ))
304             {
305                     ui.skins->setChecked( true );
306             }
307             //FIXME interface choice
308
309             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
310             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
311                     skinBrowse );
312 #if defined( WIN32 ) || defined(HAVE_DBUS_3)
313             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
314             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
315                     EnqueueOneInterfaceMode );
316 #else
317             ui.OneInterfaceBox->hide();
318 #endif
319         END_SPREFS_CAT;
320
321         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
322             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
323
324             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
325             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
326             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
327                             fontBrowse );
328             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
329             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
330                             fontSize );
331             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
332
333         END_SPREFS_CAT;
334
335         START_SPREFS_CAT( Hotkeys, "Configure Hotkeys" );
336         //FIMXE
337         END_SPREFS_CAT;
338         }
339
340     panel_layout->addWidget(panel_label);
341     panel_layout->addWidget(title_line);
342     panel_layout->addWidget( panel );
343     panel_layout->addStretch( 2 );
344
345     this->setLayout(panel_layout);
346 }
347
348 void SPrefsPanel::AudioDeviceChanged()
349 {
350     ModuleConfigControl *module_config =
351             dynamic_cast<ModuleConfigControl*>( sender() );
352     updateAudioOptions( module_config->getValue() );
353 }
354
355 void SPrefsPanel::updateAudioOptions( QString value )
356 {
357 #ifndef WIN32
358     alsa_options->hide();
359     oss_options->hide();
360 #else
361     directx_options->hide();
362 #endif
363     file_options->hide();
364
365     if( value == "aout_file" )
366         file_options->show();
367 #ifndef WIN32
368     else if( value == "alsa" )
369         alsa_options->show();
370     else if( value == "oss" )
371         oss_options->show();
372 #else
373     else if( value == "directx" )
374         directx_options->show();
375 #endif
376 }
377
378 void SPrefsPanel::apply()
379 {
380     QList<ConfigControl *>::Iterator i;
381     for( i = controls.begin() ; i != controls.end() ; i++ )
382     {
383         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
384         c->doApply( p_intf );
385     }
386 }
387
388 void SPrefsPanel::clean()
389 {}
390
391 void SPrefsPanel::lastfm_Changed( int i_state )
392 {
393     if( i_state == Qt::Checked )
394         control_Add( VLC_OBJECT( p_intf ), "audioscrobbler" );
395     else if( i_state == Qt::Unchecked )
396         control_Remove( VLC_OBJECT( p_intf ), "audioscrobbler" );
397 }