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