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