]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Remove support DBus & HAL APIs
[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$
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 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "components/simple_preferences.hpp"
30 #include "components/preferences_widgets.hpp"
31
32 #include <vlc_config_cat.h>
33 #include <vlc_configuration.h>
34
35 #include <QString>
36 #include <QFont>
37 #include <QToolButton>
38 #include <QButtonGroup>
39 #include <QUrl>
40 #include <QVBoxLayout>
41
42 #include <string>
43
44 #define ICON_HEIGHT 64
45 #define BUTTON_HEIGHT 74
46
47 /*********************************************************************
48  * The List of categories
49  *********************************************************************/
50 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51                                   QWidget( _parent ), p_intf( _p_intf )
52 {
53     QVBoxLayout *layout = new QVBoxLayout();
54
55     QButtonGroup *buttonGroup = new QButtonGroup( this );
56     buttonGroup->setExclusive ( true );
57     CONNECT( buttonGroup, buttonClicked ( int ),
58             this, switchPanel( int ) );
59
60 #define ADD_CATEGORY( button, label, icon, numb )                           \
61     QToolButton * button = new QToolButton( this );                         \
62     button->setIcon( QIcon( ":/pixmaps/" #icon ) );                         \
63     button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
64     button->setText( label );                                               \
65     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
66     button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
67     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
68     button->setAutoRaise( true );                                           \
69     button->setCheckable( true );                                           \
70     buttonGroup->addButton( button, numb );                                 \
71     layout->addWidget( button );
72
73     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74                   spref_cone_Interface_64.png, 0 );
75     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
76     ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles & OSD"),
78                   spref_cone_Subtitles_64.png, 3 );
79     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80                   spref_cone_Input_64.png, 4 );
81     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
82
83     SPrefsInterface->setChecked( true );
84     layout->setMargin( 0 );
85     layout->setSpacing( 1 );
86
87     setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
88     setLayout( layout );
89
90 }
91
92 void SPrefsCatList::switchPanel( int i )
93 {
94     emit currentItemChanged( i );
95 }
96
97 /*********************************************************************
98  * The Panels
99  *********************************************************************/
100 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
101                           int _number ) : QWidget( _parent ), p_intf( _p_intf )
102 {
103     module_config_t *p_config;
104     ConfigControl *control;
105     number = _number;
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_GENERIC2( 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, qcontrol, false );         \
122                 controls.append( control );                               \
123             }
124
125
126 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
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 );                \
132                 controls.append( control );                               \
133             }
134
135 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
136                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
137                 if( p_config )                                                \
138                 {                                                             \
139                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
140                                p_config, label, qcontrol, qbutton,      \
141                             false );                                          \
142                     controls.append( control );                               \
143                 }
144
145 #define START_SPREFS_CAT( name , label )    \
146         case SPrefs ## name:                \
147         {                                   \
148             Ui::SPrefs ## name ui;      \
149             ui.setupUi( panel );            \
150             panel_label->setText( label );
151
152 #define END_SPREFS_CAT      \
153             break;          \
154         }
155
156     QVBoxLayout *panel_layout = new QVBoxLayout();
157     QWidget *panel = new QWidget();
158     panel_layout->setMargin( 3 );
159
160     // Title Label
161     QLabel *panel_label = new QLabel;
162     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
163     labelFont.setPointSize( labelFont.pointSize() + 6 );
164     labelFont.setFamily( "Verdana" );
165     panel_label->setFont( labelFont );
166
167     // Title <hr>
168     QFrame *title_line = new QFrame;
169     title_line->setFrameShape(QFrame::HLine);
170     title_line->setFrameShadow(QFrame::Sunken);
171
172     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
173     italicFont.setItalic( true );
174
175     switch( number )
176     {
177         /******************************
178          * VIDEO Panel Implementation *
179          ******************************/
180         START_SPREFS_CAT( Video , qtr("General video settings") );
181             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
182
183             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
184             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
185             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
186             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
187             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
188             CONFIG_GENERIC( "vout", Module, NULL, outputModule );
189
190 #ifdef WIN32
191             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
192             CONFIG_GENERIC( "directx-device", StringList, NULL,
193                             dXdisplayDevice );
194 #else
195             ui.directXBox->setVisible( false );
196 #endif
197
198             CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
199                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
200             CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
201             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
202                             snapshotsSequentialNumbering );
203             CONFIG_GENERIC( "snapshot-format", StringList, NULL,
204                             snapshotsFormat );
205          END_SPREFS_CAT;
206
207         /******************************
208          * AUDIO Panel Implementation *
209          ******************************/
210         START_SPREFS_CAT( Audio, qtr("General audio settings") );
211
212             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
213
214 #define audioCommon( name ) \
215             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
216             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
217             name ## Layout->setMargin( 0 ); \
218             name ## Layout->setSpacing( 0 ); \
219             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
220             name ## Label->setMinimumSize(QSize(100, 0)); \
221             name ## Layout->addWidget( name ## Label ); \
222
223 #define audioControl( name) \
224             audioCommon( name ) \
225             QComboBox * name ## Device = new QComboBox( name ## Control ); \
226             name ## Layout->addWidget( name ## Device ); \
227             name ## Label->setBuddy( name ## Device ); \
228             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
229
230 #define audioControl2( name) \
231             audioCommon( name ) \
232             QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
233             name ## Layout->addWidget( name ## Device ); \
234             name ## Label->setBuddy( name ## Device ); \
235             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
236             name ## Layout->addWidget( name ## Browse ); \
237             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
238
239             /* hide if necessary */
240             ui.lastfm_user_edit->hide();
241             ui.lastfm_user_label->hide();
242             ui.lastfm_pass_edit->hide();
243             ui.lastfm_pass_label->hide();
244
245             /* Build if necessary */
246             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
247 #ifdef WIN32
248             audioControl( DirectX );
249             optionWidgets.append( DirectXControl );
250             CONFIG_GENERIC2( "directx-audio-device", IntegerList,
251                     DirectXLabel, DirectXDevice );
252 #else
253             if( module_Exists( p_intf, "alsa" ) )
254             {
255                 audioControl( alsa );
256                 optionWidgets.append( alsaControl );
257
258                 CONFIG_GENERIC2( "alsadev" , StringList , alsaLabel,
259                                 alsaDevice );
260             }
261             else
262                 optionWidgets.append( NULL );
263             if( module_Exists( p_intf, "oss" ) )
264             {
265                 audioControl2( OSS );
266                 optionWidgets.append( OSSControl );
267                 CONFIG_GENERIC_FILE( "dspdev" , File , OSSLabel, OSSDevice,
268                                  OSSBrowse );
269             }
270             else
271                 optionWidgets.append( NULL );
272 #endif
273
274             /* General Audio Options */
275             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
276                                      defaultVolume );
277             CONNECT( ui.defaultVolume, valueChanged( int ),
278                     this, updateAudioVolume( int ) );
279
280             CONFIG_GENERIC( "audio-language" , String , NULL,
281                             preferredAudioLanguage );
282
283             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
284             CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
285             CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
286                             detectionDolby );
287
288             CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
289
290             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
291                                     volNormSpin );
292             CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);
293
294             /* Audio Output Specifics */
295             CONFIG_GENERIC( "aout", Module, NULL, outputModule );
296
297             CONNECT( ui.outputModule, currentIndexChanged( int ),
298                      this, updateAudioOptions( int ) );
299
300        // File exists everywhere
301             CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
302                                  ui.fileName, ui.fileBrowseButton );
303
304             optionWidgets.append( ui.fileControl );
305             optionWidgets.append( ui.outputModule );
306             optionWidgets.append( ui.volNormBox );
307             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
308 #if HAS_QT43
309             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
310 #endif
311             optionWidgets.append( ui.volumeValue );
312             updateAudioOptions( ui.outputModule->currentIndex() );
313
314             /* LastFM */
315             if( module_Exists( p_intf, "audioscrobbler" ) )
316             {
317                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
318                         lastfm_user_edit );
319                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
320                         lastfm_pass_edit );
321
322                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
323                     ui.lastfm->setChecked( true );
324                 else
325                     ui.lastfm->setChecked( false );
326                 CONNECT( ui.lastfm, stateChanged( int ), this ,
327                         lastfm_Changed( int ) );
328             }
329             else
330                 ui.lastfm->hide();
331
332             /* Normalizer */
333
334             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
335                      setEnabled( bool ) );
336             qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
337             bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
338             {
339                 ui.volNormBox->setChecked( b_normalizer );
340                 ui.volNormSpin->setEnabled( b_normalizer );
341             }
342
343             /* Volume Label */
344             updateAudioVolume( ui.defaultVolume->value() ); // First time init
345
346         END_SPREFS_CAT;
347
348         /* Input and Codecs Panel Implementation */
349         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
350
351             /* Disk Devices */
352             {
353                 ui.DVDDevice->setToolTip(
354                     //TODO: make this sentence understandable
355                     qtr( "If this property is blank, then you have\n"
356                          "values for DVD, VCD, and CDDA.\n"
357                          "You can define a unique one or set that in"
358                          "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             CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
487
488             /* UPDATE options */
489 #ifdef UPDATE_CHECK
490             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
491             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
492                     updatesDays );
493             CONNECT( ui.updatesBox, toggled( bool ),
494                      ui.updatesDays, setEnabled( bool ) );
495 #else
496             ui.updatesBox->hide();
497             ui.updatesDays->hide();
498 #endif
499             /* ONE INSTANCE options */
500 #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
501             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
502             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
503                     EnqueueOneInterfaceMode );
504 #else
505             ui.OneInterfaceBox->hide();
506 #endif
507         END_SPREFS_CAT;
508
509         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
510             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
511
512             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
513             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
514             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
515                             ui.fontBrowse );
516             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
517             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
518                             fontSize );
519             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
520
521         END_SPREFS_CAT;
522
523         case SPrefsHotkeys:
524         {
525             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
526
527             QGridLayout *gLayout = new QGridLayout;
528             panel->setLayout( gLayout );
529             int line = 0;
530
531             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
532                                                 this, gLayout, line );
533
534             panel_label->setText( qtr( "Configure Hotkeys" ) );
535             controls.append( control );
536
537             break;
538         }
539     }
540
541     panel_layout->addWidget( panel_label );
542     panel_layout->addWidget( title_line );
543     panel_layout->addWidget( panel );
544     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
545
546     setLayout( panel_layout );
547 }
548
549 void SPrefsPanel::updateAudioOptions( int number)
550 {
551     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
552                                             ->itemData( number ).toString();
553 #ifdef WIN32
554     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
555 #else
556     /* optionWidgets[ossW] can be NULL */
557     if( optionWidgets[ossW] )
558         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
559     /* optionWidgets[alsaW] can be NULL */
560     if( optionWidgets[alsaW] )
561         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
562 #endif
563     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
564 }
565
566 void SPrefsPanel::updateAudioVolume( int volume )
567 {
568     qobject_cast<QSpinBox *>(optionWidgets[volLW])
569         ->setValue( volume * 100 / 256 );
570 }
571
572
573 /* Function called from the main Preferences dialog on each SPrefs Panel */
574 void SPrefsPanel::apply()
575 {
576     /* Generic save for ever panel */
577     QList<ConfigControl *>::Iterator i;
578     for( i = controls.begin() ; i != controls.end() ; i++ )
579     {
580         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
581         c->doApply( p_intf );
582     }
583
584     switch( number )
585     {
586     case SPrefsInputAndCodecs:
587     {
588         /* Device default selection */
589         char *psz_devicepath =
590               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
591         if( !EMPTY_STR( psz_devicepath ) )
592         {
593             config_PutPsz( p_intf, "dvd", psz_devicepath );
594             config_PutPsz( p_intf, "vcd", psz_devicepath );
595             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
596         }
597
598         /* Access filters */
599 #define saveBox( name, box ) {\
600         if( box->isChecked() ) { \
601             if( b_first ) { \
602                 qs_filter.append( name ); \
603                 b_first = false; \
604             } \
605             else qs_filter.append( ":" ).append( name ); \
606         } }
607
608         bool b_first = true;
609         qs_filter.clear();
610         saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
611         saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
612         saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
613         saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
614         config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
615
616 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
617 #define CaC( name ) CaCi( name, 1 )
618         /* Caching */
619         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
620         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
621         if( i_comboValue )
622         {
623             CaC( "udp-caching" );
624             if (module_Exists (p_intf, "dvdread" ))
625                 CaC( "dvdread-caching" );
626             if (module_Exists (p_intf, "dvdnav" ))
627                 CaC( "dvdnav-caching" );
628             CaC( "tcp-caching" ); CaC( "vcd-caching" );
629             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
630             CaC( "screen-caching" );
631             CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
632             CaCi( "http-caching", 4 );
633             if (module_Exists (p_intf, "access_realrtsp" ))
634                 CaCi( "realrtsp-caching", 10 );
635             CaCi( "mms-caching", 19 );
636             #ifdef WIN32
637             CaC( "dshow-caching" );
638             #else
639             if (module_Exists (p_intf, "v4l" ))
640                 CaC( "v4l-caching" );
641             if (module_Exists (p_intf, "access_jack" ))
642             CaC( "jack-input-caching" );
643             if (module_Exists (p_intf, "v4l2" ))
644                 CaC( "v4l2-caching" );
645             if (module_Exists (p_intf, "pvr" ))
646                 CaC( "pvr-caching" );
647             #endif
648             //CaCi( "dv-caching" ) too short...
649         }
650         break;
651     }
652
653     /* Interfaces */
654     case SPrefsInterface:
655     {
656         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
657             config_PutPsz( p_intf, "intf", "skins2" );
658         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
659             config_PutPsz( p_intf, "intf", "qt4" );
660         break;
661     }
662
663     case SPrefsAudio:
664     {
665         bool b_normChecked =
666             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
667         if( qs_filter.isEmpty() )
668         {
669             /* the psz_filter is already empty, so we just append it needed */
670             if( b_normChecked ) qs_filter = "volnorm";
671         }
672         else /* Not Empty */
673         {
674             if( qs_filter.contains( "volnorm" ) )
675             {
676                 /* The qs_filter not empty and contains "volnorm"
677                    that we have to remove */
678                 if( !b_normChecked )
679                 {
680                     /* Ugly :D */
681                     qs_filter.remove( "volnorm:" );
682                     qs_filter.remove( ":volnorm" );
683                     qs_filter.remove( "volnorm" );
684                 }
685             }
686             else /* qs_filter not empty, but doesn't have volnorm inside */
687                 if( b_normChecked ) qs_filter.append( ":volnorm" );
688         }
689         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
690         break;
691     }
692     }
693 }
694
695 void SPrefsPanel::clean()
696 {}
697
698 void SPrefsPanel::lastfm_Changed( int i_state )
699 {
700     if( i_state == Qt::Checked )
701         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
702     else if( i_state == Qt::Unchecked )
703         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
704 }
705
706 #ifdef WIN32
707 #include <QDialogButtonBox>
708 #include <QHeaderView>
709 #include "util/registry.hpp"
710
711 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
712                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
713 {
714     bool b_temp;
715     const char* psz_VLC = "VLC";
716     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
717
718     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
719     {
720         current->setCheckState( 0, Qt::Checked );
721         b_temp = false;
722     }
723     else
724     {
725         current->setCheckState( 0, Qt::Unchecked );
726         b_temp = true;
727     }
728     listAsso.append( current );
729     return b_temp;
730 }
731
732 void SPrefsPanel::assoDialog()
733 {
734     QDialog *d = new QDialog( this );
735     QGridLayout *assoLayout = new QGridLayout( d );
736
737     QTreeWidget *filetypeList = new QTreeWidget;
738     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
739     filetypeList->header()->hide();
740
741     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
742
743     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
744     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
745     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
746
747     filetypeList->addTopLevelItem( audioType );
748     filetypeList->addTopLevelItem( videoType );
749     filetypeList->addTopLevelItem( otherType );
750
751     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
752     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
753     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
754
755     QTreeWidgetItem *currentItem;
756
757     int i_temp = 0;
758 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
759 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
760 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
761
762     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
763     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
764     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
765     aTa( ".wma" ); aTa( ".xm" );
766     audioType->setCheckState( 0, ( i_temp > 0 ) ?
767                               ( ( i_temp == audioType->childCount() ) ?
768                                Qt::Checked : Qt::PartiallyChecked )
769                             : Qt::Unchecked );
770
771     i_temp = 0;
772     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
773     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
774     aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
775     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
776     aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
777     aTv( ".vob" ); aTv( ".wmv" );
778     videoType->setCheckState( 0, ( i_temp > 0 ) ?
779                               ( ( i_temp == audioType->childCount() ) ?
780                                Qt::Checked : Qt::PartiallyChecked )
781                             : Qt::Unchecked );
782
783     i_temp = 0;
784     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
785     aTo( ".xspf" );
786     otherType->setCheckState( 0, ( i_temp > 0 ) ?
787                               ( ( i_temp == audioType->childCount() ) ?
788                                Qt::Checked : Qt::PartiallyChecked )
789                             : Qt::Unchecked );
790
791     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
792     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
793     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
794     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
795     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
796
797     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
798
799     CONNECT( closeButton, clicked(), this, saveAsso() );
800     CONNECT( clearButton, clicked(), d, reject() );
801     d->resize( 300, 400 );
802     d->exec();
803     delete d;
804     delete qvReg;
805     listAsso.clear();
806 }
807
808 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
809 {
810     std::string s_path( "VLC" ); s_path += psz_ext;
811     std::string s_path2 = s_path;
812
813     /* Save a backup if already assigned */
814     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
815
816     if( psz_value && strlen( psz_value ) > 0 )
817         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
818     delete psz_value;
819
820     /* Put a "link" to VLC.EXT as default */
821     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
822
823     /* Create the needed Key if they weren't done in the installer */
824     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
825     {
826         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
827         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
828         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
829
830         /* Get the installer path */
831         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
832         std::string str_temp; str_temp.assign(
833             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
834
835         if( str_temp.size() )
836         {
837             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
838                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
839
840             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
841                         "", str_temp.append(",0").c_str() );
842         }
843         delete qvReg2;
844     }
845 }
846
847 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
848 {
849     char psz_VLC[] = "VLC";
850     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
851
852     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
853     {
854         free( psz_value );
855         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
856         if( psz_value )
857             qvReg->WriteRegistryString( psz_ext, "", psz_value );
858
859         qvReg->DeleteKey( psz_ext, "VLC.backup" );
860     }
861     delete( psz_value );
862 }
863 void SPrefsPanel::saveAsso()
864 {
865     QVLCRegistry * qvReg;
866     for( int i = 0; i < listAsso.size(); i ++ )
867     {
868         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
869         if( listAsso[i]->checkState( 0 ) > 0 )
870         {
871             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
872         }
873         else
874         {
875             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
876         }
877     }
878     /* Gruik ? Naaah */
879     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
880     delete qvReg;
881 }
882
883 #endif /* WIN32 */
884