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