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