]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
Remove security-policy UI
[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
448             /* UPDATE options */
449 #ifdef UPDATE_CHECK
450             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
451             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
452                     updatesDays );
453             CONNECT( ui.updatesBox, toggled( bool ),
454                      ui.updatesDays, setEnabled( bool ) );
455 #else
456             ui.updatesBox->hide();
457             ui.updatesDays->hide();
458 #endif
459             /* ONE INSTANCE options */
460 #if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
461             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
462             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
463                     EnqueueOneInterfaceMode );
464 #else
465             ui.OneInterfaceBox->hide();
466 #endif
467         END_SPREFS_CAT;
468
469         START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
470             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
471
472             CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
473             CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
474             CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
475                             fontBrowse );
476             CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
477             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
478                             fontSize );
479             CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
480
481         END_SPREFS_CAT;
482
483         case SPrefsHotkeys:
484         {
485             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
486
487             QGridLayout *gLayout = new QGridLayout;
488             panel->setLayout( gLayout );
489             int line = 0;
490
491             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
492                                                 this, gLayout, line );
493
494             panel_label->setText( qtr( "Configure Hotkeys" ) );
495             controls.append( control );
496
497             break;
498         }
499     }
500
501     panel_layout->addWidget( panel_label );
502     panel_layout->addWidget( title_line );
503     panel_layout->addWidget( panel );
504     if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
505
506     setLayout( panel_layout );
507 }
508
509 void SPrefsPanel::updateAudioOptions( int number)
510 {
511     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
512                                             ->itemData( number ).toString();
513
514 #ifdef WIN32
515     optionWidgets[directxW]->setVisible( ( value == "directx" ) );
516 #else
517     optionWidgets[ossW]->setVisible( ( value == "oss" ) );
518     optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
519 #endif
520     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
521 }
522
523 void SPrefsPanel::updateAudioVolume( int volume )
524 {
525     qobject_cast<QSpinBox *>(optionWidgets[volLW])
526         ->setValue( volume * 100 / 256 );
527 }
528
529
530 /* Function called from the main Preferences dialog on each SPrefs Panel */
531 void SPrefsPanel::apply()
532 {
533     /* Generic save for ever panel */
534     QList<ConfigControl *>::Iterator i;
535     for( i = controls.begin() ; i != controls.end() ; i++ )
536     {
537         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
538         c->doApply( p_intf );
539     }
540
541     switch( number )
542     {
543     case SPrefsInputAndCodecs:
544     {
545         /* Device default selection */
546         char *psz_devicepath =
547               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
548         if( !EMPTY_STR( psz_devicepath ) )
549         {
550             config_PutPsz( p_intf, "dvd", psz_devicepath );
551             config_PutPsz( p_intf, "vcd", psz_devicepath );
552             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
553         }
554
555         /* Access filters */
556 #define saveBox( name, box ) {\
557         if( box->isChecked() ) { \
558             if( b_first ) { \
559                 qs_filter.append( name ); \
560                 b_first = false; \
561             } \
562             else qs_filter.append( ":" ).append( name ); \
563         } }
564
565         bool b_first = true;
566         qs_filter.clear();
567         saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
568         saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
569         saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
570         saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
571         config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
572
573 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
574 #define CaC( name ) CaCi( name, 1 )
575         /* Caching */
576         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
577         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
578         if( i_comboValue )
579         {
580             CaC( "udp-caching" );
581             if (module_Exists (p_intf, "dvdread" ))
582                 CaC( "dvdread-caching" );
583             if (module_Exists (p_intf, "dvdnav" ))
584                 CaC( "dvdnav-caching" );
585             CaC( "tcp-caching" ); CaC( "vcd-caching" );
586             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
587             CaC( "screen-caching" );
588             CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
589             CaCi( "http-caching", 4 );
590             if (module_Exists (p_intf, "access_realrtsp" ))
591                 CaCi( "realrtsp-caching", 10 );
592             CaCi( "mms-caching", 19 );
593             #ifdef WIN32
594             CaC( "dshow-caching" );
595             #else
596             if (module_Exists (p_intf, "v4l" ))
597                 CaC( "v4l-caching" );
598             if (module_Exists (p_intf, "access_jack" ))
599             CaC( "jack-input-caching" );
600             if (module_Exists (p_intf, "v4l2" ))
601                 CaC( "v4l2-caching" );
602             if (module_Exists (p_intf, "pvr" ))
603                 CaC( "pvr-caching" );
604             #endif
605             //CaCi( "dv-caching" ) too short...
606         }
607         break;
608     }
609
610     /* Interfaces */
611     case SPrefsInterface:
612     {
613         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
614             config_PutPsz( p_intf, "intf", "skins2" );
615         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
616             config_PutPsz( p_intf, "intf", "qt4" );
617         break;
618     }
619
620     case SPrefsAudio:
621     {
622         bool b_normChecked =
623             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
624         if( qs_filter.isEmpty() )
625         {
626             /* the psz_filter is already empty, so we just append it needed */
627             if( b_normChecked ) qs_filter = "volnorm";
628         }
629         else /* Not Empty */
630         {
631             if( qs_filter.contains( "volnorm" ) )
632             {
633                 /* The qs_filter not empty and contains "volnorm"
634                    that we have to remove */
635                 if( !b_normChecked )
636                 {
637                     /* Ugly :D */
638                     qs_filter.remove( "volnorm:" );
639                     qs_filter.remove( ":volnorm" );
640                     qs_filter.remove( "volnorm" );
641                 }
642             }
643             else /* qs_filter not empty, but doesn't have volnorm inside */
644                 if( b_normChecked ) qs_filter.append( ":volnorm" );
645         }
646         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
647         break;
648     }
649     }
650 }
651
652 void SPrefsPanel::clean()
653 {}
654
655 void SPrefsPanel::lastfm_Changed( int i_state )
656 {
657     if( i_state == Qt::Checked )
658         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
659     else if( i_state == Qt::Unchecked )
660         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
661 }
662
663 #ifdef WIN32
664 #include <QDialogButtonBox>
665 #include <QHeaderView>
666 #include "util/registry.hpp"
667
668 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
669                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
670 {
671     bool b_temp;
672     const char* psz_VLC = "VLC";
673     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
674
675     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
676     {
677         current->setCheckState( 0, Qt::Checked );
678         b_temp = false;
679     }
680     else
681     {
682         current->setCheckState( 0, Qt::Unchecked );
683         b_temp = true;
684     }
685     listAsso.append( current );
686     return b_temp;
687 }
688
689 void SPrefsPanel::assoDialog()
690 {
691     QDialog *d = new QDialog( this );
692     QGridLayout *assoLayout = new QGridLayout( d );
693
694     QTreeWidget *filetypeList = new QTreeWidget;
695     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
696     filetypeList->header()->hide();
697
698     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
699
700     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
701     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
702     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
703
704     filetypeList->addTopLevelItem( audioType );
705     filetypeList->addTopLevelItem( videoType );
706     filetypeList->addTopLevelItem( otherType );
707
708     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
709     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
710     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
711
712     QTreeWidgetItem *currentItem;
713
714     int i_temp = 0;
715 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
716 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
717 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
718
719     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
720     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
721     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
722     aTa( ".wma" ); aTa( ".xm" );
723     audioType->setCheckState( 0, ( i_temp > 0 ) ?
724                               ( ( i_temp == audioType->childCount() ) ?
725                                Qt::Checked : Qt::PartiallyChecked )
726                             : Qt::Unchecked );
727
728     i_temp = 0;
729     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
730     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
731     aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
732     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
733     aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
734     aTv( ".vob" ); aTv( ".wmv" );
735     videoType->setCheckState( 0, ( i_temp > 0 ) ?
736                               ( ( i_temp == audioType->childCount() ) ?
737                                Qt::Checked : Qt::PartiallyChecked )
738                             : Qt::Unchecked );
739
740     i_temp = 0;
741     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
742     aTo( ".xspf" );
743     otherType->setCheckState( 0, ( i_temp > 0 ) ?
744                               ( ( i_temp == audioType->childCount() ) ?
745                                Qt::Checked : Qt::PartiallyChecked )
746                             : Qt::Unchecked );
747
748     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
749     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
750     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
751     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
752     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
753
754     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
755
756     CONNECT( closeButton, clicked(), this, saveAsso() );
757     CONNECT( clearButton, clicked(), d, reject() );
758     d->resize( 300, 400 );
759     d->exec();
760     delete d;
761     delete qvReg;
762     listAsso.clear();
763 }
764
765 void addAsso( QVLCRegistry *qvReg, char *psz_ext )
766 {
767     std::string s_path( "VLC" ); s_path += psz_ext;
768     std::string s_path2 = s_path;
769
770     /* Save a backup if already assigned */
771     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
772
773     if( psz_value && strlen( psz_value ) > 0 )
774         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
775     delete psz_value;
776
777     /* Put a "link" to VLC.EXT as default */
778     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
779
780     /* Create the needed Key if they weren't done in the installer */
781     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
782     {
783         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
784         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
785         qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );
786
787         /* Get the installer path */
788         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
789         std::string str_temp; str_temp.assign(
790             qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
791
792         if( str_temp.size() )
793         {
794             qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
795                 "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
796
797             qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
798                         "", str_temp.append(",0").c_str() );
799         }
800         delete qvReg2;
801     }
802 }
803
804 void delAsso( QVLCRegistry *qvReg, char *psz_ext )
805 {
806     char psz_VLC[] = "VLC";
807     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
808
809     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
810     {
811         free( psz_value );
812         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
813         if( psz_value )
814             qvReg->WriteRegistryString( psz_ext, "", psz_value );
815
816         qvReg->DeleteKey( psz_ext, "VLC.backup" );
817     }
818     delete( psz_value );
819 }
820 void SPrefsPanel::saveAsso()
821 {
822     QVLCRegistry * qvReg;
823     for( int i = 0; i < listAsso.size(); i ++ )
824     {
825         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
826         if( listAsso[i]->checkState( 0 ) > 0 )
827         {
828             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
829         }
830         else
831         {
832             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
833         }
834     }
835     /* Gruik ? Naaah */
836     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
837     delete qvReg;
838 }
839
840 #endif /* WIN32 */
841