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