]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Compilation fix for Qt4.2
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25 #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 #ifdef WIN32
240             CONFIG_GENERIC( "directx-audio-device", IntegerList,
241                     ui.DirectXLabel, DirectXDevice );
242 #else
243             if( module_Exists( p_intf, "alsa" ) )
244             {
245                 CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel,
246                                 alsaDevice );
247             }
248             if( module_Exists( p_intf, "oss" ) )
249             {
250                 CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
251                                  OSSBrowse );
252             }
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             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
265 #ifdef QT43
266             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
267 #endif
268             optionWidgets.append( ui.volumeValue );
269             updateAudioOptions( ui.outputModule->currentIndex() );
270
271             /* LastFM */
272             if( module_Exists( p_intf, "audioscrobbler" ) )
273             {
274                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
275                         lastfm_user_edit );
276                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
277                         lastfm_pass_edit );
278
279                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
280                     ui.lastfm->setChecked( true );
281                 else
282                     ui.lastfm->setChecked( false );
283                 CONNECT( ui.lastfm, stateChanged( int ), this ,
284                         lastfm_Changed( int ) );
285             }
286             else
287                 ui.lastfm->hide();
288
289             /* Normalizer */
290
291             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
292                      setEnabled( bool ) );
293             qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
294             bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
295             {
296                 ui.volNormBox->setChecked( b_normalizer );
297                 ui.volNormSpin->setEnabled( b_normalizer );
298             }
299
300             /* Volume Label */
301             updateAudioVolume( ui.defaultVolume->value() ); // First time init
302
303         END_SPREFS_CAT;
304
305         /* Input and Codecs Panel Implementation */
306         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
307
308             /* Disk Devices */
309             {
310                 ui.DVDDevice->setToolTip(
311                     //TODO: make this sentence understandable
312                     qtr( "If this property is blank, then you have\n"
313                          "values for DVD, VCD, and CDDA.\n"
314                          "You can define a unique one or set that in"
315                          "the advanced preferences" ) );
316                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
317                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
318                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
319                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
320                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
321                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
322                 {
323                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
324                 }
325                 delete psz_cddadiscpath; delete psz_dvddiscpath;
326                 delete psz_vcddiscpath;
327             }
328
329             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
330             CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
331             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
332             CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
333             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
334 #ifdef WIN32
335             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
336 #else
337             ui.systemCodecBox->hide();
338 #endif
339             /* Access Filters */
340             qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
341             ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
342             ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
343             ui.recordBox->setChecked( qs_filter.contains( "record" ) );
344             ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
345
346             optionWidgets.append( ui.recordBox );
347             optionWidgets.append( ui.dumpBox );
348             optionWidgets.append( ui.bandwidthBox );
349             optionWidgets.append( ui.timeshiftBox );
350             optionWidgets.append( ui.DVDDevice );
351             optionWidgets.append( ui.cachingCombo );
352
353             /* Caching */
354             /* Add the things to the ComboBox */
355             #define addToCachingBox( str, cachingNumber ) \
356                 ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
357             addToCachingBox( "Custom", CachingCustom );
358             addToCachingBox( "Lowest latency", CachingLowest );
359             addToCachingBox( "Low latency", CachingLow );
360             addToCachingBox( "Normal", CachingNormal );
361             addToCachingBox( "High latency", CachingHigh );
362             addToCachingBox( "Higher latency", CachingHigher );
363
364 #define TestCaC( name ) \
365     b_cache_equal =  b_cache_equal && \
366      ( i_cache == config_GetInt( p_intf, name ) )
367
368 #define TestCaCi( name, int ) \
369     b_cache_equal = b_cache_equal &&  \
370     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
371             /* Select the accurate value of the ComboBox */
372             bool b_cache_equal = true;
373             int i_cache = config_GetInt( p_intf, "file-caching");
374
375             TestCaC( "udp-caching" );
376             if (module_Exists (p_intf, "dvdread"))
377                 TestCaC( "dvdread-caching" );
378             if (module_Exists (p_intf, "dvdnav"))
379                 TestCaC( "dvdnav-caching" );
380             TestCaC( "tcp-caching" );
381             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
382             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
383             #ifdef WIN32
384             TestCaC( "dshow-caching" );
385             #else
386             if (module_Exists (p_intf, "v4l"))
387                 TestCaC( "v4l-caching" );
388             if (module_Exists (p_intf, "access_jack"))
389                 TestCaC( "jack-input-caching" );
390             if (module_Exists (p_intf, "v4l2"))
391                 TestCaC( "v4l2-caching" );
392             if (module_Exists (p_intf, "pvr"))
393                 TestCaC( "pvr-caching" );
394             #endif
395             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
396             TestCaCi( "http-caching", 4 );
397             if (module_Exists (p_intf, "access_realrtsp"))
398                 TestCaCi( "realrtsp-caching", 10 );
399             TestCaCi( "mms-caching", 19 );
400             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
401                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
402
403         END_SPREFS_CAT;
404         /*******************
405          * Interface Panel *
406          *******************/
407         START_SPREFS_CAT( Interface, qtr("Interface settings") );
408             ui.defaultLabel->setFont( italicFont );
409             ui.skinsLabel->setFont( italicFont );
410
411 #if defined( WIN32 ) || defined (__APPLE__)
412             CONFIG_GENERIC( "language", StringList, NULL, language );
413             BUTTONACT( ui.assoButton, assoDialog() );
414 #else
415             ui.language->hide();
416             ui.languageLabel->hide();
417             ui.assoName->hide();
418             ui.assoButton->hide();
419 #endif
420
421             /* interface */
422             char *psz_intf = config_GetPsz( p_intf, "intf" );
423             if( psz_intf )
424             {
425                 msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
426                 if( strstr( psz_intf, "skin" ) )
427                     ui.skins->setChecked( true );
428                 else if( strstr( psz_intf, "qt" ) )
429                     ui.qt4->setChecked( true );
430             }
431             delete psz_intf;
432
433             optionWidgets.append( ui.skins );
434             optionWidgets.append( ui.qt4 );
435
436             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel, artFetcher );
437             CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
438 #ifdef UPDATE_CHECK
439             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
440             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
441                     updatesDays );
442             CONNECT( ui.updatesBox, toggled( bool ),
443                      ui.updatesDays, setEnabled( bool ) );
444 #else
445             ui.updatesBox->hide();
446             ui.updatesDays->hide();
447 #endif
448             CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
449             CONFIG_GENERIC( "embeded-video", Bool, NULL, embedVideo );
450             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
451                     skinBrowse );
452 #if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
453             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
454             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
455                     EnqueueOneInterfaceMode );
456 #else
457             ui.OneInterfaceBox->hide();
458 #endif
459         END_SPREFS_CAT;
460
461         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
462             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
463
464             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
465             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
466             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
467                             fontBrowse );
468             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
469             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
470                             fontSize );
471             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
472
473         END_SPREFS_CAT;
474
475         case SPrefsHotkeys:
476         {
477             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
478
479             QGridLayout *gLayout = new QGridLayout;
480             panel->setLayout( gLayout );
481             int line = 0;
482
483             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
484                                                 this, gLayout, line );
485
486             panel_label->setText( qtr( "Configure Hotkeys" ) );
487             controls.append( control );
488
489             break;
490         }
491     }
492
493     panel_layout->addWidget( panel_label );
494     panel_layout->addWidget( title_line );
495     panel_layout->addWidget( panel );
496     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
497
498     setLayout( panel_layout );
499 }
500
501 void SPrefsPanel::updateAudioOptions( int number)
502 {
503     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
504                                             ->itemData( number ).toString();
505
506 #ifdef WIN32
507     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
508 #else
509     optionWidgets[ossW]->setVisible( ( value == "oss" ) );
510     optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
511 #endif
512     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
513 }
514
515 void SPrefsPanel::updateAudioVolume( int volume )
516 {
517     qobject_cast<QSpinBox *>(optionWidgets[volLW])
518         ->setValue( volume * 100 / 256 );
519 }
520
521
522 /* Function called from the main Preferences dialog on each SPrefs Panel */
523 void SPrefsPanel::apply()
524 {
525     msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
526
527     /* Generic save for ever panel */
528     QList<ConfigControl *>::Iterator i;
529     for( i = controls.begin() ; i != controls.end() ; i++ )
530     {
531         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
532         c->doApply( p_intf );
533     }
534
535     switch( number )
536     {
537     case SPrefsInputAndCodecs:
538     {
539         /* Device default selection */
540         char *psz_devicepath =
541               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
542         if( !EMPTY_STR( psz_devicepath ) )
543         {
544             config_PutPsz( p_intf, "dvd", psz_devicepath );
545             config_PutPsz( p_intf, "vcd", psz_devicepath );
546             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
547         }
548
549         /* Access filters */
550 #define saveBox( name, box ) {\
551         if( box->isChecked() ) { \
552             if( b_first ) { \
553                 qs_filter.append( name ); \
554                 b_first = false; \
555             } \
556             else qs_filter.append( ":" ).append( name ); \
557         } }
558
559         bool b_first = true;
560         qs_filter.clear();
561         saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
562         saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
563         saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
564         saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
565         config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
566
567 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
568 #define CaC( name ) CaCi( name, 1 )
569         /* Caching */
570         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
571         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
572         if( i_comboValue )
573         {
574             msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
575             CaC( "udp-caching" );
576             if (module_Exists (p_intf, "dvdread" ))
577                 CaC( "dvdread-caching" );
578             if (module_Exists (p_intf, "dvdnav" ))
579                 CaC( "dvdnav-caching" );
580             CaC( "tcp-caching" ); CaC( "vcd-caching" );
581             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
582             CaC( "screen-caching" );
583             CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
584             CaCi( "http-caching", 4 );
585             if (module_Exists (p_intf, "access_realrtsp" ))
586                 CaCi( "realrtsp-caching", 10 );
587             CaCi( "mms-caching", 19 );
588             #ifdef WIN32
589             CaC( "dshow-caching" );
590             #else
591             if (module_Exists (p_intf, "v4l" ))
592                 CaC( "v4l-caching" );
593             if (module_Exists (p_intf, "access_jack" ))
594             CaC( "jack-input-caching" );
595             if (module_Exists (p_intf, "v4l2" ))
596                 CaC( "v4l2-caching" );
597             if (module_Exists (p_intf, "pvr" ))
598                 CaC( "pvr-caching" );
599             #endif
600             //CaCi( "dv-caching" ) too short...
601         }
602         break;
603     }
604
605     /* Interfaces */
606     case SPrefsInterface:
607     {
608         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
609             config_PutPsz( p_intf, "intf", "skins2" );
610         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
611             config_PutPsz( p_intf, "intf", "qt4" );
612         break;
613     }
614
615     case SPrefsAudio:
616     {
617         bool b_normChecked =
618             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
619         if( qs_filter.isEmpty() )
620         {
621             /* the psz_filter is already empty, so we just append it needed */
622             if( b_normChecked ) qs_filter = "volnorm";
623         }
624         else /* Not Empty */
625         {
626             if( qs_filter.contains( "volnorm" ) )
627             {
628                 /* The qs_filter not empty and contains "volnorm"
629                    that we have to remove */
630                 if( !b_normChecked )
631                 {
632                     /* Ugly :D */
633                     qs_filter.remove( "volnorm:" );
634                     qs_filter.remove( ":volnorm" );
635                     qs_filter.remove( "volnorm" );
636                 }
637             }
638             else /* qs_filter not empty, but doesn't have volnorm inside */
639                 if( b_normChecked ) qs_filter.append( ":volnorm" );
640         }
641         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
642         break;
643     }
644     }
645 }
646
647 void SPrefsPanel::clean()
648 {}
649
650 void SPrefsPanel::lastfm_Changed( int i_state )
651 {
652     if( i_state == Qt::Checked )
653         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
654     else if( i_state == Qt::Unchecked )
655         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
656 }
657
658 #ifdef WIN32
659 #include <QDialogButtonBox>
660 #include <QHeaderView>
661 #include "util/registry.hpp"
662
663 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
664                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
665 {
666     bool b_temp;
667     const char* psz_VLC = "VLC";
668     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
669
670     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
671     {
672         current->setCheckState( 0, Qt::Checked );
673         b_temp = false;
674     }
675     else
676     {
677         current->setCheckState( 0, Qt::Unchecked );
678         b_temp = true;
679     }
680     listAsso.append( current );
681     return b_temp;
682 }
683
684 void SPrefsPanel::assoDialog()
685 {
686     QDialog *d = new QDialog( this );
687     QGridLayout *assoLayout = new QGridLayout( d );
688
689     QTreeWidget *filetypeList = new QTreeWidget;
690     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
691     filetypeList->header()->hide();
692
693     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
694
695     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
696     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
697     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
698
699     filetypeList->addTopLevelItem( audioType );
700     filetypeList->addTopLevelItem( videoType );
701     filetypeList->addTopLevelItem( otherType );
702
703     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
704     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
705     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
706
707     QTreeWidgetItem *currentItem;
708
709     int i_temp = 0;
710 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
711 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
712 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
713
714     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
715     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
716     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
717     aTa( ".wma" ); aTa( ".xm" );
718     audioType->setCheckState( 0, ( i_temp > 0 ) ?
719                               ( ( i_temp == audioType->childCount() ) ?
720                                Qt::Checked : Qt::PartiallyChecked )
721                             : Qt::Unchecked );
722
723     i_temp = 0;
724     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
725     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
726     aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
727     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
728     aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
729     aTv( ".vob" ); aTv( ".wmv" );
730     videoType->setCheckState( 0, ( i_temp > 0 ) ?
731                               ( ( i_temp == audioType->childCount() ) ?
732                                Qt::Checked : Qt::PartiallyChecked )
733                             : Qt::Unchecked );
734
735     i_temp = 0;
736     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
737     aTo( ".xspf" );
738     otherType->setCheckState( 0, ( i_temp > 0 ) ?
739                               ( ( i_temp == audioType->childCount() ) ?
740                                Qt::Checked : Qt::PartiallyChecked )
741                             : Qt::Unchecked );
742
743     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
744     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
745     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
746     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
747     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
748
749     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
750
751     CONNECT( closeButton, clicked(), this, saveAsso() );
752     CONNECT( clearButton, clicked(), d, reject() );
753     d->resize( 300, 400 );
754     d->exec();
755     delete d;
756     delete qvReg;
757     listAsso.clear();
758 }
759
760 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
761 {
762     std::string s_path( "VLC" ); s_path += psz_ext;
763     std::string s_path2 = s_path;
764
765     /* Save a backup if already assigned */
766     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
767
768     if( psz_value && strlen( psz_value ) > 0 )
769         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
770     delete psz_value;
771
772     /* Put a "link" to VLC.EXT as default */
773     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
774
775     /* Create the needed Key if they weren't done in the installer */
776     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
777     {
778         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
779         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
780         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
781
782         /* Get the installer path */
783         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
784         std::string str_temp; str_temp.assign(
785             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
786
787         if( str_temp.size() )
788         {
789             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
790                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
791
792             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
793                         "", str_temp.append(",0").c_str() );
794         }
795         delete qvReg2;
796     }
797 }
798
799 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
800 {
801     char psz_VLC[] = "VLC";
802     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
803
804     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
805     {
806         free( psz_value );
807         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
808         if( psz_value )
809             qvReg->WriteRegistryString( psz_ext, "", psz_value );
810
811         qvReg->DeleteKey( psz_ext, "VLC.backup" );
812     }
813     delete( psz_value );
814 }
815 void SPrefsPanel::saveAsso()
816 {
817     QVLCRegistry * qvReg;
818     for( int i = 0; i < listAsso.size(); i ++ )
819     {
820         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
821         if( listAsso[i]->checkState( 0 ) > 0 )
822         {
823             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
824         }
825         else
826         {
827             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
828         }
829     }
830     /* Gruik ? Naaah */
831     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
832     delete qvReg;
833 }
834
835 #endif /* WIN32 */
836