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