]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
AssoDialog is not available on Mac.
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          Antoine Cellerier <dionoea@videolan.org>
9  *          Jean-Baptiste Kempf <jb@videolan.org>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include "components/simple_preferences.hpp"
30 #include "components/preferences_widgets.hpp"
31
32 #include <vlc_config_cat.h>
33 #include <vlc_configuration.h>
34
35 #include <QString>
36 #include <QFont>
37 #include <QToolButton>
38 #include <QButtonGroup>
39 #include <QUrl>
40 #include <QVBoxLayout>
41
42 #include <string>
43
44 #define ICON_HEIGHT 64
45 #define BUTTON_HEIGHT 74
46
47 /*********************************************************************
48  * The List of categories
49  *********************************************************************/
50 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51                                   QWidget( _parent ), p_intf( _p_intf )
52 {
53     QVBoxLayout *layout = new QVBoxLayout();
54
55     QButtonGroup *buttonGroup = new QButtonGroup( this );
56     buttonGroup->setExclusive ( true );
57     CONNECT( buttonGroup, buttonClicked ( int ),
58             this, switchPanel( int ) );
59
60 #define ADD_CATEGORY( button, label, icon, numb )                           \
61     QToolButton * button = new QToolButton( this );                         \
62     button->setIcon( QIcon( ":/pixmaps/" #icon ) );                         \
63     button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
64     button->setText( label );                                               \
65     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
66     button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
67     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
68     button->setAutoRaise( true );                                           \
69     button->setCheckable( true );                                           \
70     buttonGroup->addButton( button, numb );                                 \
71     layout->addWidget( button );
72
73     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74                   spref_cone_Interface_64.png, 0 );
75     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
76     ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles & OSD"),
78                   spref_cone_Subtitles_64.png, 3 );
79     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80                   spref_cone_Input_64.png, 4 );
81     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
82
83     SPrefsInterface->setChecked( true );
84     layout->setMargin( 0 );
85     layout->setSpacing( 1 );
86
87     setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
88     setLayout( layout );
89
90 }
91
92 void SPrefsCatList::switchPanel( int i )
93 {
94     emit currentItemChanged( i );
95 }
96
97 /*********************************************************************
98  * The Panels
99  *********************************************************************/
100 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
101                           int _number ) : QWidget( _parent ), p_intf( _p_intf )
102 {
103     module_config_t *p_config;
104     ConfigControl *control;
105     number = _number;
106
107 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
108             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
109             if( p_config )                                                \
110             {                                                             \
111                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
112                            p_config, label, ui.qcontrol, false );         \
113                 controls.append( control );                               \
114             }
115
116 #define CONFIG_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 )
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                 if( strstr( psz_intf, "skin" ) )
429                     ui.skins->setChecked( true );
430                 else if( strstr( psz_intf, "qt" ) )
431                     ui.qt4->setChecked( true );
432             }
433             delete psz_intf;
434
435             optionWidgets.append( ui.skins );
436             optionWidgets.append( ui.qt4 );
437
438             CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
439                             displayModeBox );
440             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
441             CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
442                     skinBrowse );
443
444             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
445                                                       artFetcher );
446             CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
447             CONFIG_GENERIC( "security-policy", IntegerList,
448                             ui.netPolicyLabel, netPolicyBox );
449
450             /* UPDATE options */
451 #ifdef UPDATE_CHECK
452             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
453             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
454                     updatesDays );
455             CONNECT( ui.updatesBox, toggled( bool ),
456                      ui.updatesDays, setEnabled( bool ) );
457 #else
458             ui.updatesBox->hide();
459             ui.updatesDays->hide();
460 #endif
461             /* ONE INSTANCE options */
462 #if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
463             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
464             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
465                     EnqueueOneInterfaceMode );
466 #else
467             ui.OneInterfaceBox->hide();
468 #endif
469         END_SPREFS_CAT;
470
471         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
472             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
473
474             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
475             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
476             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
477                             fontBrowse );
478             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
479             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
480                             fontSize );
481             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
482
483         END_SPREFS_CAT;
484
485         case SPrefsHotkeys:
486         {
487             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
488
489             QGridLayout *gLayout = new QGridLayout;
490             panel->setLayout( gLayout );
491             int line = 0;
492
493             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
494                                                 this, gLayout, line );
495
496             panel_label->setText( qtr( "Configure Hotkeys" ) );
497             controls.append( control );
498
499             break;
500         }
501     }
502
503     panel_layout->addWidget( panel_label );
504     panel_layout->addWidget( title_line );
505     panel_layout->addWidget( panel );
506     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
507
508     setLayout( panel_layout );
509 }
510
511 void SPrefsPanel::updateAudioOptions( int number)
512 {
513     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
514                                             ->itemData( number ).toString();
515
516 #ifdef WIN32
517     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
518 #else
519     optionWidgets[ossW]->setVisible( ( value == "oss" ) );
520     optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
521 #endif
522     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
523 }
524
525 void SPrefsPanel::updateAudioVolume( int volume )
526 {
527     qobject_cast<QSpinBox *>(optionWidgets[volLW])
528         ->setValue( volume * 100 / 256 );
529 }
530
531
532 /* Function called from the main Preferences dialog on each SPrefs Panel */
533 void SPrefsPanel::apply()
534 {
535     /* Generic save for ever panel */
536     QList<ConfigControl *>::Iterator i;
537     for( i = controls.begin() ; i != controls.end() ; i++ )
538     {
539         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
540         c->doApply( p_intf );
541     }
542
543     switch( number )
544     {
545     case SPrefsInputAndCodecs:
546     {
547         /* Device default selection */
548         char *psz_devicepath =
549               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
550         if( !EMPTY_STR( psz_devicepath ) )
551         {
552             config_PutPsz( p_intf, "dvd", psz_devicepath );
553             config_PutPsz( p_intf, "vcd", psz_devicepath );
554             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
555         }
556
557         /* Access filters */
558 #define saveBox( name, box ) {\
559         if( box->isChecked() ) { \
560             if( b_first ) { \
561                 qs_filter.append( name ); \
562                 b_first = false; \
563             } \
564             else qs_filter.append( ":" ).append( name ); \
565         } }
566
567         bool b_first = true;
568         qs_filter.clear();
569         saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
570         saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
571         saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
572         saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
573         config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
574
575 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
576 #define CaC( name ) CaCi( name, 1 )
577         /* Caching */
578         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
579         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
580         if( i_comboValue )
581         {
582             CaC( "udp-caching" );
583             if (module_Exists (p_intf, "dvdread" ))
584                 CaC( "dvdread-caching" );
585             if (module_Exists (p_intf, "dvdnav" ))
586                 CaC( "dvdnav-caching" );
587             CaC( "tcp-caching" ); CaC( "vcd-caching" );
588             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
589             CaC( "screen-caching" );
590             CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
591             CaCi( "http-caching", 4 );
592             if (module_Exists (p_intf, "access_realrtsp" ))
593                 CaCi( "realrtsp-caching", 10 );
594             CaCi( "mms-caching", 19 );
595             #ifdef WIN32
596             CaC( "dshow-caching" );
597             #else
598             if (module_Exists (p_intf, "v4l" ))
599                 CaC( "v4l-caching" );
600             if (module_Exists (p_intf, "access_jack" ))
601             CaC( "jack-input-caching" );
602             if (module_Exists (p_intf, "v4l2" ))
603                 CaC( "v4l2-caching" );
604             if (module_Exists (p_intf, "pvr" ))
605                 CaC( "pvr-caching" );
606             #endif
607             //CaCi( "dv-caching" ) too short...
608         }
609         break;
610     }
611
612     /* Interfaces */
613     case SPrefsInterface:
614     {
615         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
616             config_PutPsz( p_intf, "intf", "skins2" );
617         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
618             config_PutPsz( p_intf, "intf", "qt4" );
619         break;
620     }
621
622     case SPrefsAudio:
623     {
624         bool b_normChecked =
625             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
626         if( qs_filter.isEmpty() )
627         {
628             /* the psz_filter is already empty, so we just append it needed */
629             if( b_normChecked ) qs_filter = "volnorm";
630         }
631         else /* Not Empty */
632         {
633             if( qs_filter.contains( "volnorm" ) )
634             {
635                 /* The qs_filter not empty and contains "volnorm"
636                    that we have to remove */
637                 if( !b_normChecked )
638                 {
639                     /* Ugly :D */
640                     qs_filter.remove( "volnorm:" );
641                     qs_filter.remove( ":volnorm" );
642                     qs_filter.remove( "volnorm" );
643                 }
644             }
645             else /* qs_filter not empty, but doesn't have volnorm inside */
646                 if( b_normChecked ) qs_filter.append( ":volnorm" );
647         }
648         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
649         break;
650     }
651     }
652 }
653
654 void SPrefsPanel::clean()
655 {}
656
657 void SPrefsPanel::lastfm_Changed( int i_state )
658 {
659     if( i_state == Qt::Checked )
660         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
661     else if( i_state == Qt::Unchecked )
662         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
663 }
664
665 #ifdef WIN32
666 #include <QDialogButtonBox>
667 #include <QHeaderView>
668 #include "util/registry.hpp"
669
670 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
671                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
672 {
673     bool b_temp;
674     const char* psz_VLC = "VLC";
675     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
676
677     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
678     {
679         current->setCheckState( 0, Qt::Checked );
680         b_temp = false;
681     }
682     else
683     {
684         current->setCheckState( 0, Qt::Unchecked );
685         b_temp = true;
686     }
687     listAsso.append( current );
688     return b_temp;
689 }
690
691 void SPrefsPanel::assoDialog()
692 {
693     QDialog *d = new QDialog( this );
694     QGridLayout *assoLayout = new QGridLayout( d );
695
696     QTreeWidget *filetypeList = new QTreeWidget;
697     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
698     filetypeList->header()->hide();
699
700     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
701
702     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
703     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
704     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
705
706     filetypeList->addTopLevelItem( audioType );
707     filetypeList->addTopLevelItem( videoType );
708     filetypeList->addTopLevelItem( otherType );
709
710     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
711     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
712     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
713
714     QTreeWidgetItem *currentItem;
715
716     int i_temp = 0;
717 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
718 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
719 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
720
721     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
722     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
723     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
724     aTa( ".wma" ); aTa( ".xm" );
725     audioType->setCheckState( 0, ( i_temp > 0 ) ?
726                               ( ( i_temp == audioType->childCount() ) ?
727                                Qt::Checked : Qt::PartiallyChecked )
728                             : Qt::Unchecked );
729
730     i_temp = 0;
731     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
732     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
733     aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
734     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
735     aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
736     aTv( ".vob" ); aTv( ".wmv" );
737     videoType->setCheckState( 0, ( i_temp > 0 ) ?
738                               ( ( i_temp == audioType->childCount() ) ?
739                                Qt::Checked : Qt::PartiallyChecked )
740                             : Qt::Unchecked );
741
742     i_temp = 0;
743     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
744     aTo( ".xspf" );
745     otherType->setCheckState( 0, ( i_temp > 0 ) ?
746                               ( ( i_temp == audioType->childCount() ) ?
747                                Qt::Checked : Qt::PartiallyChecked )
748                             : Qt::Unchecked );
749
750     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
751     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
752     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
753     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
754     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
755
756     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
757
758     CONNECT( closeButton, clicked(), this, saveAsso() );
759     CONNECT( clearButton, clicked(), d, reject() );
760     d->resize( 300, 400 );
761     d->exec();
762     delete d;
763     delete qvReg;
764     listAsso.clear();
765 }
766
767 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
768 {
769     std::string s_path( "VLC" ); s_path += psz_ext;
770     std::string s_path2 = s_path;
771
772     /* Save a backup if already assigned */
773     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
774
775     if( psz_value && strlen( psz_value ) > 0 )
776         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
777     delete psz_value;
778
779     /* Put a "link" to VLC.EXT as default */
780     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
781
782     /* Create the needed Key if they weren't done in the installer */
783     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
784     {
785         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
786         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
787         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
788
789         /* Get the installer path */
790         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
791         std::string str_temp; str_temp.assign(
792             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
793
794         if( str_temp.size() )
795         {
796             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
797                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
798
799             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
800                         "", str_temp.append(",0").c_str() );
801         }
802         delete qvReg2;
803     }
804 }
805
806 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
807 {
808     char psz_VLC[] = "VLC";
809     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
810
811     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
812     {
813         free( psz_value );
814         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
815         if( psz_value )
816             qvReg->WriteRegistryString( psz_ext, "", psz_value );
817
818         qvReg->DeleteKey( psz_ext, "VLC.backup" );
819     }
820     delete( psz_value );
821 }
822 void SPrefsPanel::saveAsso()
823 {
824     QVLCRegistry * qvReg;
825     for( int i = 0; i < listAsso.size(); i ++ )
826     {
827         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
828         if( listAsso[i]->checkState( 0 ) > 0 )
829         {
830             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
831         }
832         else
833         {
834             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
835         }
836     }
837     /* Gruik ? Naaah */
838     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
839     delete qvReg;
840 }
841
842 #endif /* WIN32 */
843