]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Various strings change and capitalisation changes to match the guidelines.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
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 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include "components/simple_preferences.hpp"
31 #include "components/preferences_widgets.hpp"
32
33 #include <vlc_config_cat.h>
34 #include <vlc_configuration.h>
35
36 #include <QString>
37 #include <QFont>
38 #include <QToolButton>
39 #include <QButtonGroup>
40 #include <QUrl>
41 #include <QVBoxLayout>
42
43 #include <string>
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 & OSD"),
79                   spref_cone_Subtitles_64.png, 3 );
80     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input & 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     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     number = _number;
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_GENERIC2( 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, qcontrol, false );         \
123                 controls.append( control );                               \
124             }
125
126
127 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
128             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
129             if( p_config )                                                \
130             {                                                             \
131                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
132                            p_config, label, ui.qcontrol );                \
133                 controls.append( control );                               \
134             }
135
136 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
137                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
138                 if( p_config )                                                \
139                 {                                                             \
140                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
141                                p_config, label, qcontrol, qbutton,      \
142                             false );                                          \
143                     controls.append( control );                               \
144                 }
145
146 #define START_SPREFS_CAT( name , label )    \
147         case SPrefs ## name:                \
148         {                                   \
149             Ui::SPrefs ## name ui;      \
150             ui.setupUi( panel );            \
151             panel_label->setText( label );
152
153 #define END_SPREFS_CAT      \
154             break;          \
155         }
156
157     QVBoxLayout *panel_layout = new QVBoxLayout();
158     QWidget *panel = new QWidget();
159     panel_layout->setMargin( 3 );
160
161     // Title Label
162     QLabel *panel_label = new QLabel;
163     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
164     labelFont.setPointSize( labelFont.pointSize() + 6 );
165     labelFont.setFamily( "Verdana" );
166     panel_label->setFont( labelFont );
167
168     // Title <hr>
169     QFrame *title_line = new QFrame;
170     title_line->setFrameShape(QFrame::HLine);
171     title_line->setFrameShadow(QFrame::Sunken);
172
173     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
174     italicFont.setItalic( true );
175
176     switch( number )
177     {
178         /******************************
179          * VIDEO Panel Implementation *
180          ******************************/
181         START_SPREFS_CAT( Video , qtr("General Video Settings") );
182             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
183
184             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
185             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
186             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
187             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
188             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
189             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
190
191 #ifdef WIN32
192             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
193             CONFIG_GENERIC( "directx-device", StringList, NULL,
194                             dXdisplayDevice );
195 #else
196             ui.directXBox->setVisible( false );
197 #endif
198
199             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
200                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
201             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
202             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
203                             snapshotsSequentialNumbering );
204             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
205                             snapshotsFormat );
206          END_SPREFS_CAT;
207
208         /******************************
209          * AUDIO Panel Implementation *
210          ******************************/
211         START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
212
213             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
214
215 #define audioCommon( name ) \
216             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
217             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
218             name ## Layout->setMargin( 0 ); \
219             name ## Layout->setSpacing( 0 ); \
220             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
221             name ## Label->setMinimumSize(QSize(100, 0)); \
222             name ## Layout->addWidget( name ## Label ); \
223
224 #define audioControl( name) \
225             audioCommon( name ) \
226             QComboBox * name ## Device = new QComboBox( name ## Control ); \
227             name ## Layout->addWidget( name ## Device ); \
228             name ## Label->setBuddy( name ## Device ); \
229             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
230
231 #define audioControl2( name) \
232             audioCommon( name ) \
233             QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
234             name ## Layout->addWidget( name ## Device ); \
235             name ## Label->setBuddy( name ## Device ); \
236             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
237             name ## Layout->addWidget( name ## Browse ); \
238             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
239
240             /* hide if necessary */
241             ui.lastfm_user_edit->hide();
242             ui.lastfm_user_label->hide();
243             ui.lastfm_pass_edit->hide();
244             ui.lastfm_pass_label->hide();
245
246             /* Build if necessary */
247             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
248 #ifdef WIN32
249             audioControl( DirectX );
250             optionWidgets.append( DirectXControl );
251             CONFIG_GENERIC2( "directx-audio-device", IntegerList,
252                     DirectXLabel, DirectXDevice );
253 #else
254             if( module_Exists( p_intf, "alsa" ) )
255             {
256                 audioControl( alsa );
257                 optionWidgets.append( alsaControl );
258
259                 CONFIG_GENERIC2( "alsadev" , StringList , alsaLabel,
260                                 alsaDevice );
261             }
262             else
263                 optionWidgets.append( NULL );
264             if( module_Exists( p_intf, "oss" ) )
265             {
266                 audioControl2( OSS );
267                 optionWidgets.append( OSSControl );
268                 CONFIG_GENERIC_FILE( "dspdev" , File , OSSLabel, OSSDevice,
269                                  OSSBrowse );
270             }
271             else
272                 optionWidgets.append( NULL );
273 #endif
274
275             /* General Audio Options */
276             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
277                                      defaultVolume );
278             CONNECT( ui.defaultVolume, valueChanged( int ),
279                     this, updateAudioVolume( int ) );
280
281             CONFIG_GENERIC( "audio-language" , String , NULL,
282                             preferredAudioLanguage );
283
284             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
285             CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
286             CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
287                             detectionDolby );
288
289             CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
290
291             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
292                                     volNormSpin );
293             CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
294
295             /* Audio Output Specifics */
296             CONFIG_GENERIC( "aout", Module, NULL, outputModule );
297
298             CONNECT( ui.outputModule, currentIndexChanged( int ),
299                      this, updateAudioOptions( int ) );
300
301             /* File output exists on all platforms */
302             CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
303                                  ui.fileName, ui.fileBrowseButton );
304
305             optionWidgets.append( ui.fileControl );
306             optionWidgets.append( ui.outputModule );
307             optionWidgets.append( ui.volNormBox );
308             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
309 #if HAS_QT43
310             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
311 #endif
312             optionWidgets.append( ui.volumeValue );
313             updateAudioOptions( ui.outputModule->currentIndex() );
314
315             /* LastFM */
316             if( module_Exists( p_intf, "audioscrobbler" ) )
317             {
318                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
319                         lastfm_user_edit );
320                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
321                         lastfm_pass_edit );
322
323                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
324                     ui.lastfm->setChecked( true );
325                 else
326                     ui.lastfm->setChecked( false );
327                 CONNECT( ui.lastfm, stateChanged( int ), this ,
328                         lastfm_Changed( int ) );
329             }
330             else
331                 ui.lastfm->hide();
332
333             /* Normalizer */
334
335             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
336                      setEnabled( bool ) );
337             qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
338             bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
339             {
340                 ui.volNormBox->setChecked( b_normalizer );
341                 ui.volNormSpin->setEnabled( b_normalizer );
342             }
343
344             /* Volume Label */
345             updateAudioVolume( ui.defaultVolume->value() ); // First time init
346
347         END_SPREFS_CAT;
348
349         /* Input and Codecs Panel Implementation */
350         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
351
352             /* Disk Devices */
353             {
354                 ui.DVDDevice->setToolTip(
355                     qtr( "If this property is blank, different values\n"
356                          "for DVD, VCD, and CDDA are set.\n"
357                          "You can define a unique one or configure them \n"
358                          "individually in the advanced preferences." ) );
359                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
360                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
361                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
362                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
363                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
364                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
365                 {
366                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
367                 }
368                 delete psz_cddadiscpath; delete psz_dvddiscpath;
369                 delete psz_vcddiscpath;
370             }
371
372             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
373             CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
374             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
375             CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
376             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
377 #ifdef WIN32
378             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
379 #else
380             ui.systemCodecBox->hide();
381 #endif
382             /* Access Filters */
383             qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
384             ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
385             ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
386             ui.recordBox->setChecked( qs_filter.contains( "record" ) );
387             ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
388
389             optionWidgets.append( ui.recordBox );
390             optionWidgets.append( ui.dumpBox );
391             optionWidgets.append( ui.bandwidthBox );
392             optionWidgets.append( ui.timeshiftBox );
393             optionWidgets.append( ui.DVDDevice );
394             optionWidgets.append( ui.cachingCombo );
395
396             /* Caching */
397             /* Add the things to the ComboBox */
398             #define addToCachingBox( str, cachingNumber ) \
399                 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
400             addToCachingBox( "Custom", CachingCustom );
401             addToCachingBox( "Lowest latency", CachingLowest );
402             addToCachingBox( "Low latency", CachingLow );
403             addToCachingBox( "Normal", CachingNormal );
404             addToCachingBox( "High latency", CachingHigh );
405             addToCachingBox( "Higher latency", CachingHigher );
406
407 #define TestCaC( name ) \
408     b_cache_equal =  b_cache_equal && \
409      ( i_cache == config_GetInt( p_intf, name ) )
410
411 #define TestCaCi( name, int ) \
412     b_cache_equal = b_cache_equal &&  \
413     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
414             /* Select the accurate value of the ComboBox */
415             bool b_cache_equal = true;
416             int i_cache = config_GetInt( p_intf, "file-caching");
417
418             TestCaC( "udp-caching" );
419             if (module_Exists (p_intf, "dvdread"))
420                 TestCaC( "dvdread-caching" );
421             if (module_Exists (p_intf, "dvdnav"))
422                 TestCaC( "dvdnav-caching" );
423             TestCaC( "tcp-caching" );
424             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
425             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
426             #ifdef WIN32
427             TestCaC( "dshow-caching" );
428             #else
429             if (module_Exists (p_intf, "v4l"))
430                 TestCaC( "v4l-caching" );
431             if (module_Exists (p_intf, "access_jack"))
432                 TestCaC( "jack-input-caching" );
433             if (module_Exists (p_intf, "v4l2"))
434                 TestCaC( "v4l2-caching" );
435             if (module_Exists (p_intf, "pvr"))
436                 TestCaC( "pvr-caching" );
437             #endif
438             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
439             TestCaCi( "http-caching", 4 );
440             if (module_Exists (p_intf, "access_realrtsp"))
441                 TestCaCi( "realrtsp-caching", 10 );
442             TestCaCi( "mms-caching", 19 );
443             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
444                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
445
446         END_SPREFS_CAT;
447         /*******************
448          * Interface Panel *
449          *******************/
450         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
451             ui.defaultLabel->setFont( italicFont );
452             ui.skinsLabel->setFont( italicFont );
453
454 #if defined( WIN32 )
455             CONFIG_GENERIC( "language", StringList, NULL, language );
456             BUTTONACT( ui.assoButton, assoDialog() );
457 #else
458             ui.language->hide();
459             ui.languageLabel->hide();
460             ui.assoName->hide();
461             ui.assoButton->hide();
462 #endif
463
464             /* interface */
465             char *psz_intf = config_GetPsz( p_intf, "intf" );
466             if( psz_intf )
467             {
468                 if( strstr( psz_intf, "skin" ) )
469                     ui.skins->setChecked( true );
470                 else if( strstr( psz_intf, "qt" ) )
471                     ui.qt4->setChecked( true );
472             }
473             delete psz_intf;
474
475             optionWidgets.append( ui.skins );
476             optionWidgets.append( ui.qt4 );
477
478             CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
479                             displayModeBox );
480             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
481             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
482                     ui.skinBrowse );
483
484             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
485                                                       artFetcher );
486
487             /* UPDATE options */
488 #ifdef UPDATE_CHECK
489             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
490             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
491                     updatesDays );
492             CONNECT( ui.updatesBox, toggled( bool ),
493                      ui.updatesDays, setEnabled( bool ) );
494 #else
495             ui.updatesBox->hide();
496             ui.updatesDays->hide();
497 #endif
498             /* ONE INSTANCE options */
499 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
500             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
501             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
502                     EnqueueOneInterfaceMode );
503 #else
504             ui.OneInterfaceBox->hide();
505 #endif
506         END_SPREFS_CAT;
507
508         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD Settings") );
509             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
510
511             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
512             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
513             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
514                             ui.fontBrowse );
515             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
516             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
517                             fontSize );
518             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
519
520         END_SPREFS_CAT;
521
522         case SPrefsHotkeys:
523         {
524             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
525
526             QGridLayout *gLayout = new QGridLayout;
527             panel->setLayout( gLayout );
528             int line = 0;
529
530             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
531                                                 this, gLayout, line );
532
533             panel_label->setText( qtr( "Configure Hotkeys" ) );
534             controls.append( control );
535
536             break;
537         }
538     }
539
540     panel_layout->addWidget( panel_label );
541     panel_layout->addWidget( title_line );
542     panel_layout->addWidget( panel );
543     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
544
545     setLayout( panel_layout );
546 }
547
548 void SPrefsPanel::updateAudioOptions( int number)
549 {
550     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
551                                             ->itemData( number ).toString();
552 #ifdef WIN32
553     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
554 #else
555     /* optionWidgets[ossW] can be NULL */
556     if( optionWidgets[ossW] )
557         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
558     /* optionWidgets[alsaW] can be NULL */
559     if( optionWidgets[alsaW] )
560         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
561 #endif
562     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
563 }
564
565 void SPrefsPanel::updateAudioVolume( int volume )
566 {
567     qobject_cast<QSpinBox *>(optionWidgets[volLW])
568         ->setValue( volume * 100 / 256 );
569 }
570
571
572 /* Function called from the main Preferences dialog on each SPrefs Panel */
573 void SPrefsPanel::apply()
574 {
575     /* Generic save for ever panel */
576     QList<ConfigControl *>::Iterator i;
577     for( i = controls.begin() ; i != controls.end() ; i++ )
578     {
579         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
580         c->doApply( p_intf );
581     }
582
583     switch( number )
584     {
585     case SPrefsInputAndCodecs:
586     {
587         /* Device default selection */
588         char *psz_devicepath =
589               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
590         if( !EMPTY_STR( psz_devicepath ) )
591         {
592             config_PutPsz( p_intf, "dvd", psz_devicepath );
593             config_PutPsz( p_intf, "vcd", psz_devicepath );
594             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
595         }
596
597         /* Access filters */
598 #define saveBox( name, box ) {\
599         if( box->isChecked() ) { \
600             if( b_first ) { \
601                 qs_filter.append( name ); \
602                 b_first = false; \
603             } \
604             else qs_filter.append( ":" ).append( name ); \
605         } }
606
607         bool b_first = true;
608         qs_filter.clear();
609         saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
610         saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
611         saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
612         saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
613         config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
614
615 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
616 #define CaC( name ) CaCi( name, 1 )
617         /* Caching */
618         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
619         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
620         if( i_comboValue )
621         {
622             CaC( "udp-caching" );
623             if (module_Exists (p_intf, "dvdread" ))
624                 CaC( "dvdread-caching" );
625             if (module_Exists (p_intf, "dvdnav" ))
626                 CaC( "dvdnav-caching" );
627             CaC( "tcp-caching" ); CaC( "vcd-caching" );
628             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
629             CaC( "screen-caching" );
630             CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
631             CaCi( "http-caching", 4 );
632             if (module_Exists (p_intf, "access_realrtsp" ))
633                 CaCi( "realrtsp-caching", 10 );
634             CaCi( "mms-caching", 19 );
635             #ifdef WIN32
636             CaC( "dshow-caching" );
637             #else
638             if (module_Exists (p_intf, "v4l" ))
639                 CaC( "v4l-caching" );
640             if (module_Exists (p_intf, "access_jack" ))
641             CaC( "jack-input-caching" );
642             if (module_Exists (p_intf, "v4l2" ))
643                 CaC( "v4l2-caching" );
644             if (module_Exists (p_intf, "pvr" ))
645                 CaC( "pvr-caching" );
646             #endif
647             //CaCi( "dv-caching" ) too short...
648         }
649         break;
650     }
651
652     /* Interfaces */
653     case SPrefsInterface:
654     {
655         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
656             config_PutPsz( p_intf, "intf", "skins2" );
657         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
658             config_PutPsz( p_intf, "intf", "qt4" );
659         break;
660     }
661
662     case SPrefsAudio:
663     {
664         bool b_normChecked =
665             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
666         if( qs_filter.isEmpty() )
667         {
668             /* the psz_filter is already empty, so we just append it needed */
669             if( b_normChecked ) qs_filter = "volnorm";
670         }
671         else /* Not Empty */
672         {
673             if( qs_filter.contains( "volnorm" ) )
674             {
675                 /* The qs_filter not empty and contains "volnorm"
676                    that we have to remove */
677                 if( !b_normChecked )
678                 {
679                     /* Ugly :D */
680                     qs_filter.remove( "volnorm:" );
681                     qs_filter.remove( ":volnorm" );
682                     qs_filter.remove( "volnorm" );
683                 }
684             }
685             else /* qs_filter not empty, but doesn't have volnorm inside */
686                 if( b_normChecked ) qs_filter.append( ":volnorm" );
687         }
688         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
689         break;
690     }
691     }
692 }
693
694 void SPrefsPanel::clean()
695 {}
696
697 void SPrefsPanel::lastfm_Changed( int i_state )
698 {
699     if( i_state == Qt::Checked )
700         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
701     else if( i_state == Qt::Unchecked )
702         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
703 }
704
705 #ifdef WIN32
706 #include <QDialogButtonBox>
707 #include <QHeaderView>
708 #include "util/registry.hpp"
709
710 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
711                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
712 {
713     bool b_temp;
714     const char* psz_VLC = "VLC";
715     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
716
717     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
718     {
719         current->setCheckState( 0, Qt::Checked );
720         b_temp = false;
721     }
722     else
723     {
724         current->setCheckState( 0, Qt::Unchecked );
725         b_temp = true;
726     }
727     listAsso.append( current );
728     return b_temp;
729 }
730
731 void SPrefsPanel::assoDialog()
732 {
733     QDialog *d = new QDialog( this );
734     QGridLayout *assoLayout = new QGridLayout( d );
735
736     QTreeWidget *filetypeList = new QTreeWidget;
737     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
738     filetypeList->header()->hide();
739
740     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
741
742     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
743     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
744     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
745
746     filetypeList->addTopLevelItem( audioType );
747     filetypeList->addTopLevelItem( videoType );
748     filetypeList->addTopLevelItem( otherType );
749
750     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
751     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
752     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
753
754     QTreeWidgetItem *currentItem;
755
756     int i_temp = 0;
757 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
758 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
759 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
760
761     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
762     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
763     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
764     aTa( ".wma" ); aTa( ".xm" );
765     audioType->setCheckState( 0, ( i_temp > 0 ) ?
766                               ( ( i_temp == audioType->childCount() ) ?
767                                Qt::Checked : Qt::PartiallyChecked )
768                             : Qt::Unchecked );
769
770     i_temp = 0;
771     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
772     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
773     aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
774     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
775     aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
776     aTv( ".vob" ); aTv( ".wmv" );
777     videoType->setCheckState( 0, ( i_temp > 0 ) ?
778                               ( ( i_temp == audioType->childCount() ) ?
779                                Qt::Checked : Qt::PartiallyChecked )
780                             : Qt::Unchecked );
781
782     i_temp = 0;
783     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
784     aTo( ".xspf" );
785     otherType->setCheckState( 0, ( i_temp > 0 ) ?
786                               ( ( i_temp == audioType->childCount() ) ?
787                                Qt::Checked : Qt::PartiallyChecked )
788                             : Qt::Unchecked );
789
790     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
791     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
792     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
793     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
794     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
795
796     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
797
798     CONNECT( closeButton, clicked(), this, saveAsso() );
799     CONNECT( clearButton, clicked(), d, reject() );
800     d->resize( 300, 400 );
801     d->exec();
802     delete d;
803     delete qvReg;
804     listAsso.clear();
805 }
806
807 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
808 {
809     std::string s_path( "VLC" ); s_path += psz_ext;
810     std::string s_path2 = s_path;
811
812     /* Save a backup if already assigned */
813     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
814
815     if( psz_value && strlen( psz_value ) > 0 )
816         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
817     delete psz_value;
818
819     /* Put a "link" to VLC.EXT as default */
820     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
821
822     /* Create the needed Key if they weren't done in the installer */
823     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
824     {
825         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
826         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
827         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
828
829         /* Get the installer path */
830         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
831         std::string str_temp; str_temp.assign(
832             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
833
834         if( str_temp.size() )
835         {
836             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
837                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
838
839             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
840                         "", str_temp.append(",0").c_str() );
841         }
842         delete qvReg2;
843     }
844 }
845
846 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
847 {
848     char psz_VLC[] = "VLC";
849     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
850
851     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
852     {
853         free( psz_value );
854         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
855         if( psz_value )
856             qvReg->WriteRegistryString( psz_ext, "", psz_value );
857
858         qvReg->DeleteKey( psz_ext, "VLC.backup" );
859     }
860     delete( psz_value );
861 }
862 void SPrefsPanel::saveAsso()
863 {
864     QVLCRegistry * qvReg;
865     for( int i = 0; i < listAsso.size(); i ++ )
866     {
867         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
868         if( listAsso[i]->checkState( 0 ) > 0 )
869         {
870             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
871         }
872         else
873         {
874             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
875         }
876     }
877     /* Gruik ? Naaah */
878     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
879     delete qvReg;
880 }
881
882 #endif /* WIN32 */
883