]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/simple_preferences.cpp
2ae81a03b061c84e67e6aa898caa7906f58dd524
[vlc] / modules / gui / qt4 / components / simple_preferences.cpp
1 /*****************************************************************************
2  * simple_preferences.cpp : "Simple preferences"
3  ****************************************************************************
4  * Copyright (C) 2006-2010 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 <QSignalMapper>
40 #include <QVBoxLayout>
41 #include <QScrollArea>
42
43 #include <QStyleFactory>
44 #include <QSettings>
45 #include <QtAlgorithms>
46 #include <QDir>
47 #include <math.h>
48
49 #define ICON_HEIGHT 64
50
51 #ifdef _WIN32
52 # include <vlc_windows_interfaces.h>
53 # include <vlc_charset.h>
54 #endif
55 #include <vlc_modules.h>
56
57 static const char *const ppsz_language[] =
58 {
59     "auto",
60     "en",
61     "ar",
62     "bn",
63     "pt_BR",
64     "en_GB",
65     "el",
66     "bg",
67     "ca",
68     "zh_TW",
69     "cs",
70     "cy",
71     "da",
72     "nl",
73     "fi",
74     "et",
75     "eu",
76     "fr",
77     "ga",
78     "gd",
79     "gl",
80     "ka",
81     "de",
82     "he",
83     "hr",
84     "hu",
85     "hy",
86     "is",
87     "id",
88     "it",
89     "ja",
90     "ko",
91     "lt",
92     "mn",
93     "ms",
94     "nb",
95     "nn",
96     "kk",
97     "km",
98     "ne",
99     "oc",
100     "fa",
101     "pl",
102     "pt_PT",
103     "pa",
104     "ro",
105     "ru",
106     "zh_CN",
107     "si",
108     "sr",
109     "sk",
110     "sl",
111     "ckb",
112     "es",
113     "sv",
114     "te",
115     "tr",
116     "uk",
117     "vi",
118     "wa",
119     NULL,
120 };
121
122 static const char *const ppsz_language_text[] =
123 {
124     N_("Auto"),
125     "American English",
126     "ﻉﺮﺒﻳ",
127     "বাংলা",
128     "Português Brasileiro",
129     "British English",
130     "Νέα Ελληνικά",
131     "български език",
132     "Català",
133     "正體中文",
134     "Čeština",
135     "Cymraeg",
136     "Dansk",
137     "Nederlands",
138     "Suomi",
139     "eesti keel",
140     "Euskara",
141     "Français",
142     "Gaeilge",
143     "Gàidhlig",
144     "Galego",
145     "ქართული",
146     "Deutsch",
147     "עברית",
148     "hrvatski",
149     "Magyar",
150     "հայերեն",
151     "íslenska",
152     "Bahasa Indonesia",
153     "Italiano",
154     "日本語",
155     "한국어",
156     "lietuvių",
157     "Монгол хэл",
158     "Melayu",
159     "Bokmål",
160     "Nynorsk",
161     "Қазақ тілі",
162     "ភាសាខ្មែរ",
163     "नेपाली",
164     "Occitan",
165     "ﻑﺍﺮﺳی",
166     "Polski",
167     "Português",
168     "ਪੰਜਾਬੀ",
169     "Română",
170     "Русский",
171     "简体中文",
172     "සිංහල",
173     "српски",
174     "Slovensky",
175     "slovenščina",
176     "کوردیی سۆرانی",
177     "Español",
178     "Svenska",
179     "తెలుగు",
180     "Türkçe",
181     "украї́нська мо́ва",
182     "tiếng Việt",
183     "Walon",
184 };
185
186 static int getDefaultAudioVolume(vlc_object_t *obj, const char *aout)
187 {
188     if (!strcmp(aout, "") || !strcmp(aout, "any"))
189         return -1;
190     else
191     /* Note: For hysterical raisins, this is sorted by decreasing priority
192      * order (then alphabetical order). */
193     if (!strcmp(aout, "pulse"))
194         return -1;
195     else
196 #ifdef __linux__
197     if (!strcmp(aout, "alsa") && module_exists("alsa"))
198         return cbrtf(config_GetFloat(obj, "alsa-gain")) * 100.f + .5f;
199     else
200 #endif
201 #ifdef _WIN32
202     if (!strcmp(aout, "mmdevice"))
203         return -1;
204     else
205 #endif
206     if (!strcmp(aout, "sndio"))
207         return -1;
208     else
209 #ifdef __APPLE__
210     if (!strcmp("auhal") && module_exists("auhal"))
211         return (config_GetFloat(obj, "auhal-volume") * 100.f + .5f)
212                  / AOUT_VOLUME_DEFAULT;
213     else
214 #endif
215 #ifdef _WIN32
216     if (!strcmp(aout, "directsound") && module_exists("directsound"))
217         return config_GetFloat(obj, "directx-volume") * 100.f + .5f;
218     else
219 #endif
220     if (!strcmp(aout, "jack"))
221         return cbrtf(config_GetFloat(obj, "jack-gain")) * 100.f + 0.5f;
222     else
223 #ifdef __OS2__
224     if (!strcmp(aout, "kai"))
225         return cbrtf(config_GetFloat(obj, "kai-gain")) * 100.f + .5f;
226     else
227 #endif
228     if (!strcmp(aout, "oss"))
229         return -1;
230     else
231 #ifdef _WIN32
232     if (!strcmp(aout, "waveout"))
233         return config_GetFloat(obj, "waveout-volume") * 100.f + .5f;
234     else
235 #endif
236         return -1;
237 }
238
239 /*********************************************************************
240  * The List of categories
241  *********************************************************************/
242 SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
243                                   QWidget( _parent ), p_intf( _p_intf )
244 {
245     QVBoxLayout *layout = new QVBoxLayout();
246
247     /* Use autoExclusive buttons and a mapper as QButtonGroup can't
248        set focus (keys) when it manages the buttons's exclusivity.
249        See QT bugs 131 & 816 and QAbstractButton's source code. */
250     QSignalMapper *mapper = new QSignalMapper( layout );
251     CONNECT( mapper, mapped(int), this, switchPanel(int) );
252
253     short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
254
255 #define ADD_CATEGORY( button, label, ltooltip, icon, numb )                 \
256     QToolButton * button = new QToolButton( this );                         \
257     button->setIcon( QIcon( ":/prefsmenu/" #icon ) );                       \
258     button->setText( label );                                               \
259     button->setToolTip( ltooltip );                                         \
260     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
261     button->setIconSize( QSize( icon_height, icon_height ) );               \
262     button->resize( icon_height + 6 , icon_height + 6 );                    \
263     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
264     button->setAutoRaise( true );                                           \
265     button->setCheckable( true );                                           \
266     button->setAutoExclusive( true );                                       \
267     CONNECT( button, clicked(), mapper, map() );                            \
268     mapper->setMapping( button, numb );                                     \
269     layout->addWidget( button );
270
271     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), qtr("Interface Settings"),
272                   cone_interface_64, 0 );
273     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), qtr("Audio Settings"),
274                   cone_audio_64, 1 );
275     ADD_CATEGORY( SPrefsVideo, qtr("Video"), qtr("Video Settings"),
276                   cone_video_64, 2 );
277     ADD_CATEGORY( SPrefsSubtitles, qtr(SUBPIC_TITLE), qtr("Subtitle & On Screen Display Settings"),
278                   cone_subtitles_64, 3 );
279     ADD_CATEGORY( SPrefsInputAndCodecs, qtr(INPUT_TITLE), qtr("Input & Codecs Settings"),
280                   cone_input_64, 4 );
281     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), qtr("Configure Hotkeys"),
282                   cone_hotkeys_64, 5 );
283
284 #undef ADD_CATEGORY
285
286     SPrefsInterface->setChecked( true );
287     layout->setMargin( 0 );
288     layout->setSpacing( 1 );
289
290     setMinimumWidth( 140 );
291     setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
292     setLayout( layout );
293
294 }
295
296 void SPrefsCatList::switchPanel( int i )
297 {
298     emit currentItemChanged( i );
299 }
300
301 /*********************************************************************
302  * The Panels
303  *********************************************************************/
304 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
305                           int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
306 {
307     module_config_t *p_config;
308     ConfigControl *control;
309     number = _number;
310     lang = NULL;
311
312 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
313             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
314             if( p_config )                                                \
315             {                                                             \
316                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
317                            p_config, label, ui.qcontrol, false );         \
318                 controls.append( control );                               \
319             }                                                             \
320             else {                                                        \
321                 ui.qcontrol->setEnabled( false );                         \
322                 if( label ) label->setEnabled( false );                   \
323             }
324
325 #define CONFIG_BOOL( option, qcontrol )                           \
326             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
327             if( p_config )                                                \
328             {                                                             \
329                 control =  new BoolConfigControl( VLC_OBJECT(p_intf),     \
330                            p_config, NULL, ui.qcontrol );          \
331                 controls.append( control );                               \
332             }                                                             \
333             else { ui.qcontrol->setEnabled( false ); }
334
335
336 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol )             \
337             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
338             if( p_config )                                                \
339             {                                                             \
340                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
341                            p_config, label, qcontrol, false );            \
342                 controls.append( control );                               \
343             }                                                             \
344             else {                                                        \
345                 QWidget *widget = label;                                  \
346                 qcontrol->setVisible( false );                            \
347                 if( widget ) widget->setEnabled( false );                 \
348             }
349
350
351 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
352             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
353             if( p_config )                                                \
354             {                                                             \
355                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
356                            p_config, label, ui.qcontrol );                \
357                 controls.append( control );                               \
358             }
359
360 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )     \
361             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
362             if( p_config )                                                \
363             {                                                             \
364                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
365                            p_config, label, qcontrol, qbutton );          \
366                 controls.append( control );                               \
367             }
368
369 #define START_SPREFS_CAT( name , label )    \
370         case SPrefs ## name:                \
371         {                                   \
372             Ui::SPrefs ## name ui;      \
373             ui.setupUi( panel );            \
374             panel_label->setText( label );
375
376 #define END_SPREFS_CAT      \
377             break;          \
378         }
379
380     QVBoxLayout *panel_layout = new QVBoxLayout();
381     QWidget *panel = new QWidget();
382     panel_layout->setMargin( 3 );
383
384     // Title Label
385     QLabel *panel_label = new QLabel;
386     QFont labelFont = QApplication::font();
387     labelFont.setPointSize( labelFont.pointSize() + 6 );
388     panel_label->setFont( labelFont );
389
390     // Title <hr>
391     QFrame *title_line = new QFrame;
392     title_line->setFrameShape(QFrame::HLine);
393     title_line->setFrameShadow(QFrame::Sunken);
394
395     QFont italicFont = QApplication::font();
396     italicFont.setItalic( true );
397
398     switch( number )
399     {
400         /******************************
401          * VIDEO Panel Implementation *
402          ******************************/
403         START_SPREFS_CAT( Video , qtr("Video Settings") );
404             CONFIG_BOOL( "video", enableVideo );
405             ui.videoZone->setEnabled( ui.enableVideo->isChecked() );
406             CONNECT( ui.enableVideo, toggled( bool ),
407                      ui.videoZone, setEnabled( bool ) );
408
409             CONFIG_BOOL( "fullscreen", fullscreen );
410             CONFIG_BOOL( "overlay", overlay );
411             CONFIG_BOOL( "video-on-top", alwaysOnTop );
412             CONFIG_BOOL( "video-deco", windowDecorations );
413             CONFIG_GENERIC( "vout", StringList, ui.voutLabel, outputModule );
414
415 #ifdef _WIN32
416             CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
417                             dXdisplayDevice );
418             CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
419             CONNECT( ui.overlay, toggled( bool ), ui.hwYUVBox, setEnabled( bool ) );
420 #else
421             ui.directXBox->setVisible( false );
422             ui.hwYUVBox->setVisible( false );
423 #endif
424
425 #ifdef __OS2__
426             CONFIG_BOOL( "kva-fixt23", kvaFixT23 );
427             CONFIG_GENERIC( "kva-video-mode", StringList, ui.kvaVideoModeLabel,
428                             kvaVideoMode );
429 #else
430             ui.kvaBox->setVisible( false );
431 #endif
432
433             CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
434             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
435             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
436
437             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
438                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
439             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
440             CONFIG_BOOL( "snapshot-sequential",
441                             snapshotsSequentialNumbering );
442             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
443                             snapshotsFormat );
444          END_SPREFS_CAT;
445
446         /******************************
447          * AUDIO Panel Implementation *
448          ******************************/
449         START_SPREFS_CAT( Audio, qtr("Audio Settings") );
450
451             CONFIG_BOOL( "audio", enableAudio );
452             ui.audioZone->setEnabled( ui.enableAudio->isChecked() );
453             CONNECT( ui.enableAudio, toggled( bool ),
454                      ui.audioZone, setEnabled( bool ) );
455
456 #define audioCommon( name ) \
457             QLabel * name ## Label = new QLabel( qtr( "Device:" ) ); \
458             name ## Label->setMinimumSize(QSize(250, 0)); \
459             outputAudioLayout->addWidget( name ## Label, outputAudioLayout->rowCount(), 0, 1, 1 ); \
460
461 #define audioControl( name) \
462             audioCommon( name ) \
463             QComboBox * name ## Device = new QComboBox; \
464             name ## Label->setBuddy( name ## Device ); \
465             name ## Device->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred  );\
466             outputAudioLayout->addWidget( name ## Device, outputAudioLayout->rowCount() - 1, 1, 1, -1 );
467
468 #define audioControl2( name) \
469             audioCommon( name ) \
470             QLineEdit * name ## Device = new QLineEdit; \
471             name ## Label->setBuddy( name ## Device ); \
472             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ) ); \
473             outputAudioLayout->addWidget( name ## Device, outputAudioLayout->rowCount() - 1, 0, 1, -1, Qt::AlignLeft );
474
475             /* Build if necessary */
476             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
477 #ifdef _WIN32
478             audioControl( DirectX );
479             optionWidgets["directxL" ] = DirectXLabel;
480             optionWidgets["directxW" ] = DirectXDevice;
481             CONFIG_GENERIC_NO_UI( "directx-audio-device", StringList,
482                     DirectXLabel, DirectXDevice );
483
484             audioControl( Waveout );
485             optionWidgets["waveoutL" ] = WaveoutLabel;
486             optionWidgets["waveoutW" ] = WaveoutDevice;
487             CONFIG_GENERIC_NO_UI( "waveout-audio-device", StringList,
488                     WaveoutLabel, WaveoutDevice );
489
490 #elif defined( __OS2__ )
491             audioControl( kai );
492             optionWidgets["kaiL"] = kaiLabel;
493             optionWidgets["kaiW"] = kaiDevice;
494             CONFIG_GENERIC_NO_UI( "kai-audio-device", StringList, kaiLabel,
495                     kaiDevice );
496 #else
497             if( module_exists( "alsa" ) )
498             {
499                 audioControl( alsa );
500                 optionWidgets["alsaL"] = alsaLabel;
501                 optionWidgets["alsaW"] = alsaDevice;
502                 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
503                                 alsaDevice );
504             }
505             if( module_exists( "oss" ) )
506             {
507                 audioControl2( OSS );
508                 optionWidgets["ossL"] = OSSLabel;
509                 optionWidgets["ossW"] = OSSDevice;
510                 optionWidgets["ossB"] = OSSBrowse;
511                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
512                                  OSSBrowse );
513             }
514 #endif
515
516 #undef audioControl2
517 #undef audioControl
518 #undef audioCommon
519
520             int i_max_volume = config_GetInt( p_intf, "qt-max-volume" );
521
522             /* Audio Options */
523             ui.volumeValue->setMaximum( i_max_volume );
524             ui.defaultVolume->setMaximum( i_max_volume );
525
526             CONNECT( ui.defaultVolume, valueChanged( int ),
527                      this, updateAudioVolume( int ) );
528
529             ui.defaultVolume_zone->setEnabled( ui.resetVolumeCheckbox->isChecked() );
530             CONNECT( ui.resetVolumeCheckbox, toggled( bool ),
531                      ui.defaultVolume_zone, setEnabled( bool ) );
532
533             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
534                             preferredAudioLanguage );
535
536             CONFIG_BOOL( "spdif", spdifBox );
537             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
538                             detectionDolby );
539
540             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
541                                     volNormSpin );
542             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
543                             replayCombo );
544             CONFIG_GENERIC( "audio-visual" , StringList, ui.visuLabel,
545                             visualisation);
546             CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
547
548             /* Audio Output Specifics */
549             CONFIG_GENERIC( "aout", StringList, ui.outputLabel, outputModule );
550
551             CONNECT( ui.outputModule, currentIndexChanged( int ),
552                      this, updateAudioOptions( int ) );
553
554             /* File output exists on all platforms */
555             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
556                                  ui.fileName, ui.fileBrowseButton );
557
558             optionWidgets["fileW"] = ui.fileControl;
559             optionWidgets["audioOutCoB"] = ui.outputModule;
560             optionWidgets["normalizerChB"] = ui.volNormBox;
561             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
562             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
563             optionWidgets["volLW"] = ui.volumeValue;
564             optionWidgets["headphoneB"] = ui.headphoneEffect;
565             optionWidgets["spdifChB"] = ui.spdifBox;
566             optionWidgets["defaultVolume"] = ui.defaultVolume;
567             optionWidgets["resetVolumeCheckbox"] = ui.resetVolumeCheckbox;
568             updateAudioOptions( ui.outputModule->currentIndex() );
569
570             /* LastFM */
571             if( module_exists( "audioscrobbler" ) )
572             {
573                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
574                         lastfm_user_edit );
575                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
576                         lastfm_pass_edit );
577
578                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
579                     ui.lastfm->setChecked( true );
580                 else
581                     ui.lastfm->setChecked( false );
582
583                 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
584
585                 CONNECT( ui.lastfm, toggled( bool ),
586                          ui.lastfm_zone, setVisible( bool ) );
587                 CONNECT( ui.lastfm, stateChanged( int ),
588                          this, lastfm_Changed( int ) );
589             }
590             else
591             {
592                 ui.lastfm->hide();
593                 ui.lastfm_zone->hide();
594             }
595
596             /* Normalizer */
597             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
598                      setEnabled( bool ) );
599
600             char* psz = config_GetPsz( p_intf, "audio-filter" );
601             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
602             free( psz );
603
604             bool b_enabled = ( qs_filter.contains( "normvol" ) );
605             ui.volNormBox->setChecked( b_enabled );
606             ui.volNormSpin->setEnabled( b_enabled );
607
608             b_enabled = ( qs_filter.contains( "headphone" ) );
609             ui.headphoneEffect->setChecked( b_enabled );
610
611             /* Volume Label */
612             updateAudioVolume( ui.defaultVolume->value() ); // First time init
613
614         END_SPREFS_CAT;
615
616         /* Input and Codecs Panel Implementation */
617         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
618
619             /* Disk Devices */
620             {
621                 ui.DVDDeviceComboBox->setToolTip(
622                     qtr( "If this property is blank, different values\n"
623                          "for DVD, VCD, and CDDA are set.\n"
624                          "You can define a unique one or configure them \n"
625                          "individually in the advanced preferences." ) );
626                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
627                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
628                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
629                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
630                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
631                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
632                 {
633                     ui.DVDDeviceComboBox->setEditText( qfu( psz_dvddiscpath ) );
634                 }
635                 free( psz_cddadiscpath );
636                 free( psz_dvddiscpath );
637                 free( psz_vcddiscpath );
638             }
639 #ifndef _WIN32
640             QStringList DVDDeviceComboBoxStringList = QStringList();
641             DVDDeviceComboBoxStringList
642                     << "dvd*" << "scd*" << "sr*" << "sg*" << "cd*";
643             ui.DVDDeviceComboBox->addItems( QDir( "/dev/" )
644                     .entryList( DVDDeviceComboBoxStringList, QDir::System )
645                     .replaceInStrings( QRegExp("^"), "/dev/" )
646             );
647 #endif
648             CONFIG_GENERIC( "dvd", String, ui.DVDLabel,
649                             DVDDeviceComboBox->lineEdit() );
650             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
651                                  ui.recordPath, ui.recordBrowse );
652
653             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
654             CONFIG_GENERIC_NO_BOOL( "postproc-q", Integer, ui.ppLabel,
655                                     PostProcLevel );
656             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
657
658             /* live555 module prefs */
659             CONFIG_BOOL( "rtsp-tcp",
660                                 live555TransportRTSP_TCPRadio );
661             if ( !module_exists( "live555" ) )
662             {
663                 ui.live555TransportRTSP_TCPRadio->hide();
664                 ui.live555TransportHTTPRadio->hide();
665                 ui.live555TransportLabel->hide();
666             }
667             CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel, hwAccelModule );
668 #ifdef _WIN32
669             HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
670             if( !hdxva2_dll )
671                 ui.hwAccelModule->setEnabled( false );
672             else
673                 FreeLibrary( hdxva2_dll );
674 #endif
675             optionWidgets["inputLE"] = ui.DVDDeviceComboBox;
676             optionWidgets["cachingCoB"] = ui.cachingCombo;
677             CONFIG_GENERIC( "avcodec-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
678             CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
679             CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
680             CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
681             CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
682             CONFIG_BOOL( "mkv-preload-local-dir", mkvPreloadBox );
683
684             /* Caching */
685             /* Add the things to the ComboBox */
686             #define addToCachingBox( str, cachingNumber ) \
687                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
688             addToCachingBox( N_("Custom"), CachingCustom );
689             addToCachingBox( N_("Lowest latency"), CachingLowest );
690             addToCachingBox( N_("Low latency"), CachingLow );
691             addToCachingBox( N_("Normal"), CachingNormal );
692             addToCachingBox( N_("High latency"), CachingHigh );
693             addToCachingBox( N_("Higher latency"), CachingHigher );
694             #undef addToCachingBox
695
696 #define TestCaC( name, factor ) \
697     b_cache_equal =  b_cache_equal && \
698      ( i_cache * factor == config_GetInt( p_intf, name ) );
699             /* Select the accurate value of the ComboBox */
700             bool b_cache_equal = true;
701             int i_cache = config_GetInt( p_intf, "file-caching" );
702
703             TestCaC( "network-caching", 10/3 );
704             TestCaC( "disc-caching", 1);
705             TestCaC( "live-caching", 1 );
706             if( b_cache_equal == 1 )
707                 ui.cachingCombo->setCurrentIndex(
708                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
709 #undef TestCaC
710
711         END_SPREFS_CAT;
712         /*******************
713          * Interface Panel *
714          *******************/
715         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
716
717 #ifndef _WIN32
718             ui.langBox->hide();
719 #else
720             for( int i = 0; ppsz_language[i] != NULL; i++)
721                 ui.langCombo->addItem( qfu(ppsz_language_text[i]), ppsz_language[i]);
722             CONNECT( ui.langCombo, currentIndexChanged( int ), this, langChanged( int ) );
723
724             HKEY h_key;
725             char *langReg = NULL;
726             if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
727                     == ERROR_SUCCESS )
728             {
729                 TCHAR szData[256];
730                 DWORD len = 256;
731                 if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) {
732                     langReg = FromWide( szData );
733                     ui.langCombo->setCurrentIndex( ui.langCombo->findData(langReg) );
734                 }
735             }
736             free( langReg);
737 #endif
738
739 //            ui.defaultLabel->setFont( italicFont );
740             ui.skinsLabel->setText(
741                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
742                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">" )
743                     + qtr( "VLC skins website" )+ QString( "</a>." ) );
744             ui.skinsLabel->setFont( italicFont );
745
746 #ifdef _WIN32
747             BUTTONACT( ui.assoButton, assoDialog() );
748 #else
749             ui.osGroupBox->hide();
750 #endif
751
752             /* interface */
753             char *psz_intf = config_GetPsz( p_intf, "intf" );
754             if( psz_intf )
755             {
756                 if( strstr( psz_intf, "skin" ) )
757                     ui.skins->setChecked( true );
758             } else {
759                 /* defaults to qt */
760                 ui.qt->setChecked( true );
761             }
762             free( psz_intf );
763
764             optionWidgets["skinRB"] = ui.skins;
765             optionWidgets["qtRB"] = ui.qt;
766 #if !defined( _WIN32)
767             ui.stylesCombo->addItem( qtr("System's default") );
768             ui.stylesCombo->addItems( QStyleFactory::keys() );
769             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
770                         getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
771             ui.stylesCombo->insertSeparator( 1 );
772             if ( ui.stylesCombo->currentIndex() < 0 )
773                 ui.stylesCombo->setCurrentIndex( 0 ); /* default */
774
775             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
776             optionWidgets["styleCB"] = ui.stylesCombo;
777 #else
778             ui.stylesCombo->hide();
779             ui.stylesLabel->hide();
780 #endif
781             radioGroup = new QButtonGroup(this);
782             radioGroup->addButton( ui.qt, 0 );
783             radioGroup->addButton( ui.skins, 1 );
784             CONNECT( radioGroup, buttonClicked( int ),
785                      ui.styleStackedWidget, setCurrentIndex( int ) );
786             ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
787
788             CONNECT( ui.minimalviewBox, toggled( bool ),
789                      ui.mainPreview, setNormalPreview( bool ) );
790             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
791             ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
792             ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
793
794             CONFIG_BOOL( "embedded-video", embedVideo );
795             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
796             CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
797             ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );
798
799             CONFIG_BOOL( "qt-fs-controller", fsController );
800             CONFIG_BOOL( "qt-system-tray", systrayBox );
801             CONFIG_GENERIC( "qt-notification", IntegerList, ui.notificationComboLabel,
802                                                       notificationCombo );
803             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationCombo, setEnabled( bool ) );
804             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationComboLabel, setEnabled( bool ) );
805             ui.notificationCombo->setEnabled( ui.systrayBox->isChecked() );
806
807             CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
808             CONFIG_BOOL( "playlist-tree", treePlaylist );
809             CONFIG_BOOL( "play-and-pause", playPauseBox );
810             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
811                                  ui.fileSkin, ui.skinBrowse );
812
813             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
814                                                       artFetcher );
815
816             /* UPDATE options */
817 #ifdef UPDATE_CHECK
818             CONFIG_BOOL( "qt-updates-notif", updatesBox );
819             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
820                     updatesDays );
821             ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
822             CONNECT( ui.updatesBox, toggled( bool ),
823                      ui.updatesDays, setEnabled( bool ) );
824 #else
825             ui.updatesBox->hide();
826             ui.updatesDays->hide();
827 #endif
828             /* ONE INSTANCE options */
829 #if !defined( _WIN32 ) && !defined(__APPLE__) && !defined(__OS2__)
830             if( !module_exists( "dbus" ) )
831                 ui.OneInterfaceBox->hide();
832             else
833 #endif
834             {
835                 CONFIG_BOOL( "one-instance", OneInterfaceMode );
836                 CONFIG_BOOL( "playlist-enqueue", EnqueueOneInterfaceMode );
837                 ui.EnqueueOneInterfaceMode->setEnabled(
838                                                        ui.OneInterfaceMode->isChecked() );
839                 CONNECT( ui.OneInterfaceMode, toggled( bool ),
840                          ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
841                 CONFIG_BOOL( "one-instance-when-started-from-file", oneInstanceFromFile );
842             }
843
844             /* RECENTLY PLAYED options */
845             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
846                      ui.recentlyPlayedFilters, setEnabled( bool ) );
847             ui.recentlyPlayedFilters->setEnabled( false );
848             CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
849             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
850                     recentlyPlayedFilters );
851
852         END_SPREFS_CAT;
853
854         START_SPREFS_CAT( Subtitles,
855                             qtr("Subtitle & On Screen Display Settings") );
856             CONFIG_BOOL( "osd", OSDBox);
857             CONFIG_BOOL( "video-title-show", OSDTitleBox);
858             CONFIG_GENERIC( "video-title-position", IntegerList,
859                             ui.OSDTitlePosLabel, OSDTitlePos );
860
861             CONFIG_BOOL( "spu", spuActiveBox);
862             ui.spuZone->setEnabled( ui.spuActiveBox->isChecked() );
863             CONNECT( ui.spuActiveBox, toggled( bool ),
864                      ui.spuZone, setEnabled( bool ) );
865
866             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
867                             encoding );
868             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
869                             preferredLanguage );
870
871             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
872                             ui.fontSizeLabel, fontSize );
873
874             CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
875             CONFIG_GENERIC_NO_BOOL( "freetype-color", Color, ui.fontColorLabel,
876                             fontColor );
877             CONFIG_GENERIC( "freetype-outline-thickness", IntegerList,
878                             ui.fontEffectLabel, effect );
879             CONFIG_GENERIC_NO_BOOL( "freetype-outline-color", Color, ui.outlineColorLabel,
880                             outlineColor );
881
882             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
883
884             ui.shadowCheck->setChecked( config_GetInt( p_intf, "freetype-shadow-opacity" ) > 0 );
885             ui.backgroundCheck->setChecked( config_GetInt( p_intf, "freetype-background-opacity" ) > 0 );
886             optionWidgets["shadowCB"] = ui.shadowCheck;
887             optionWidgets["backgroundCB"] = ui.backgroundCheck;
888
889         END_SPREFS_CAT;
890
891         case SPrefsHotkeys:
892         {
893             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-play" );
894
895             QGridLayout *gLayout = new QGridLayout;
896             panel->setLayout( gLayout );
897             int line = 0;
898
899             panel_label->setText( qtr( "Configure Hotkeys" ) );
900             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config, this );
901             control->insertIntoExistingGrid( gLayout, line );
902             controls.append( control );
903
904             line++;
905
906             QFrame *sepline = new QFrame;
907             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
908             gLayout->addWidget( sepline, line, 0, 1, -1 );
909
910             line++;
911
912             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
913             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
914                     p_config, this, false );
915             control->insertIntoExistingGrid( gLayout, line );
916             controls.append( control );
917
918 #ifdef _WIN32
919             line++;
920
921             p_config = config_FindConfig( VLC_OBJECT(p_intf), "qt-disable-volume-keys" );
922             control = new BoolConfigControl( VLC_OBJECT(p_intf), p_config, this );
923             control->insertIntoExistingGrid( gLayout, line );
924             controls.append( control );
925 #endif
926
927             break;
928         }
929     }
930
931     panel_layout->addWidget( panel_label );
932     panel_layout->addWidget( title_line );
933
934     if( small )
935     {
936         QScrollArea *scroller= new QScrollArea;
937         scroller->setWidget( panel );
938         scroller->setWidgetResizable( true );
939         scroller->setFrameStyle( QFrame::NoFrame );
940         panel_layout->addWidget( scroller );
941     }
942     else
943     {
944         panel_layout->addWidget( panel );
945         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
946     }
947
948     setLayout( panel_layout );
949
950 #undef END_SPREFS_CAT
951 #undef START_SPREFS_CAT
952 #undef CONFIG_GENERIC_FILE
953 #undef CONFIG_GENERIC_NO_BOOL
954 #undef CONFIG_GENERIC_NO_UI
955 #undef CONFIG_GENERIC
956 #undef CONFIG_BOOL
957 }
958
959
960 void SPrefsPanel::updateAudioOptions( int number)
961 {
962     QString value = qobject_cast<QComboBox *>(optionWidgets["audioOutCoB"])
963                                             ->itemData( number ).toString();
964 #ifdef _WIN32
965     optionWidgets["directxW"]->setVisible( ( value == "directsound" ) );
966     optionWidgets["directxL"]->setVisible( ( value == "directsound" ) );
967     optionWidgets["waveoutW"]->setVisible( ( value == "waveout" ) );
968     optionWidgets["waveoutL"]->setVisible( ( value == "waveout" ) );
969 #elif defined( __OS2__ )
970     optionWidgets["kaiL"]->setVisible( ( value == "kai" ) );
971     optionWidgets["kaiW"]->setVisible( ( value == "kai" ) );
972 #else
973     /* optionWidgets["ossW] can be NULL */
974     if( optionWidgets["ossW"] ) {
975         optionWidgets["ossW"]->setVisible( ( value == "oss" ) );
976         optionWidgets["ossL"]->setVisible( ( value == "oss" ) );
977         optionWidgets["ossB"]->setVisible( ( value == "oss" ) );
978     }
979     /* optionWidgets["alsaW] can be NULL */
980     if( optionWidgets["alsaW"] ) {
981         optionWidgets["alsaW"]->setVisible( ( value == "alsa" ) );
982         optionWidgets["alsaL"]->setVisible( ( value == "alsa" ) );
983     }
984 #endif
985     optionWidgets["fileW"]->setVisible( ( value == "afile" ) );
986     optionWidgets["spdifChB"]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
987                                            value == "directsound" || value == "waveout" ) );
988
989     int volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), qtu(value));
990     bool save = true;
991
992     if (volume >= 0)
993         save = config_GetInt(VLC_OBJECT(p_intf), "volume-save");
994
995     QCheckBox *resetVolumeCheckBox =
996         qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"]);
997     resetVolumeCheckBox->setChecked(!save);
998     resetVolumeCheckBox->setEnabled(volume >= 0);
999
1000     QSlider *defaultVolume =
1001         qobject_cast<QSlider *>(optionWidgets["defaultVolume"]);
1002     defaultVolume->setValue((volume >= 0) ? volume : 100);
1003     defaultVolume->setEnabled(volume >= 0);
1004 }
1005
1006
1007 SPrefsPanel::~SPrefsPanel()
1008 {
1009     qDeleteAll( controls ); controls.clear();
1010 }
1011
1012 void SPrefsPanel::updateAudioVolume( int volume )
1013 {
1014     qobject_cast<QSpinBox *>(optionWidgets["volLW"])
1015         ->setValue( volume );
1016 }
1017
1018
1019 /* Function called from the main Preferences dialog on each SPrefs Panel */
1020 void SPrefsPanel::apply()
1021 {
1022     /* Generic save for ever panel */
1023     QList<ConfigControl *>::const_iterator i;
1024     for( i = controls.begin() ; i != controls.end() ; ++i )
1025     {
1026         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
1027         c->doApply();
1028     }
1029
1030     switch( number )
1031     {
1032     case SPrefsInputAndCodecs:
1033     {
1034         /* Device default selection */
1035         QByteArray devicepath =
1036             qobject_cast<QComboBox *>(optionWidgets["inputLE"])->currentText().toUtf8();
1037         if( devicepath.size() > 0 )
1038         {
1039             config_PutPsz( p_intf, "dvd", devicepath );
1040             config_PutPsz( p_intf, "vcd", devicepath );
1041             config_PutPsz( p_intf, "cd-audio", devicepath );
1042         }
1043
1044 #define CaC( name, factor ) config_PutInt( p_intf, name, i_comboValue * factor )
1045         /* Caching */
1046         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets["cachingCoB"]);
1047         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
1048         if( i_comboValue )
1049         {
1050             CaC( "file-caching", 1 );
1051             CaC( "network-caching", 10/3 );
1052             CaC( "disc-caching", 1 );
1053             CaC( "live-caching", 1 );
1054         }
1055         break;
1056 #undef CaC
1057     }
1058
1059     /* Interfaces */
1060     case SPrefsInterface:
1061     {
1062         if( qobject_cast<QRadioButton *>(optionWidgets["skinRB"])->isChecked() )
1063             config_PutPsz( p_intf, "intf", "skins2,any" );
1064         else
1065         //if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
1066             config_PutPsz( p_intf, "intf", "" );
1067         if( qobject_cast<QComboBox *>(optionWidgets["styleCB"]) )
1068             getSettings()->setValue( "MainWindow/QtStyle",
1069                 qobject_cast<QComboBox *>(optionWidgets["styleCB"])->currentText() );
1070 #ifdef _WIN32
1071     saveLang();
1072 #endif
1073         break;
1074     }
1075
1076     case SPrefsAudio:
1077     {
1078         bool b_checked =
1079             qobject_cast<QCheckBox *>(optionWidgets["normalizerChB"])->isChecked();
1080         if( b_checked && !qs_filter.contains( "normvol" ) )
1081             qs_filter.append( "normvol" );
1082         if( !b_checked && qs_filter.contains( "normvol" ) )
1083             qs_filter.removeAll( "normvol" );
1084
1085         b_checked =
1086             qobject_cast<QCheckBox *>(optionWidgets["headphoneB"])->isChecked();
1087
1088         if( b_checked && !qs_filter.contains( "headphone" ) )
1089             qs_filter.append( "headphone" );
1090         if( !b_checked && qs_filter.contains( "headphone" ) )
1091             qs_filter.removeAll( "headphone" );
1092
1093         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
1094
1095         /* Default volume */
1096         int i_volume =
1097             qobject_cast<QSlider *>(optionWidgets["defaultVolume"])->value();
1098         bool b_reset_volume =
1099             qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"])->isChecked();
1100         module_config_t *p_config = config_FindConfig( VLC_OBJECT(p_intf), "aout" );
1101         char *psz_aout = p_config->value.psz;
1102
1103
1104         float f_gain = powf( i_volume / 100.f, 3 );
1105
1106 #define save_vol_aout( name ) \
1107             module_exists( name ) && ( !psz_aout || !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
1108
1109         //FIXME this is moot
1110 #if defined( _WIN32 )
1111         VLC_UNUSED( f_gain );
1112         if( save_vol_aout( "directsound" ) )
1113             config_PutFloat( p_intf, "directx-volume", i_volume / 100.f );
1114         if( save_vol_aout( "waveout" ) )
1115             config_PutFloat( p_intf, "waveout-volume", i_volume / 100.f );
1116 #elif defined( Q_OS_MAC )
1117         VLC_UNUSED( f_gain );
1118         if( save_vol_aout( "auhal" ) )
1119             config_PutFloat( p_intf, "auhal-volume", i_volume / 100.f
1120                     * AOUT_VOLUME_DEFAULT );
1121 #elif defined( __OS2__ )
1122         if( save_vol_aout( "kai" ) )
1123             config_PutFloat( p_intf, "kai-gain",  f_gain );
1124 #else
1125         if( save_vol_aout( "alsa" ) )
1126             config_PutFloat( p_intf, "alsa-gain", f_gain );
1127         if( save_vol_aout( "jack" ) )
1128             config_PutFloat( p_intf, "jack-gain", f_gain );
1129 #endif
1130 #undef save_vol_aout
1131
1132         config_PutInt( p_intf, "volume-save", !b_reset_volume );
1133
1134         break;
1135     }
1136     case SPrefsSubtitles:
1137     {
1138         bool b_checked = qobject_cast<QCheckBox *>(optionWidgets["shadowCB"])->isChecked();
1139         if( b_checked && config_GetInt( p_intf, "freetype-shadow-opacity" ) == 0 ) {
1140             config_PutInt( p_intf, "freetype-shadow-opacity", 128 );
1141         }
1142         else if (!b_checked ) {
1143             config_PutInt( p_intf, "freetype-shadow-opacity", 0 );
1144         }
1145
1146         b_checked = qobject_cast<QCheckBox *>(optionWidgets["backgroundCB"])->isChecked();
1147         if( b_checked && config_GetInt( p_intf, "freetype-background-opacity" ) == 0 ) {
1148             config_PutInt( p_intf, "freetype-background-opacity", 128 );
1149         }
1150         else if (!b_checked ) {
1151             config_PutInt( p_intf, "freetype-background-opacity", 0 );
1152         }
1153
1154     }
1155     }
1156 }
1157
1158 void SPrefsPanel::clean()
1159 {}
1160
1161 void SPrefsPanel::lastfm_Changed( int i_state )
1162 {
1163     if( i_state == Qt::Checked )
1164         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1165     else if( i_state == Qt::Unchecked )
1166         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1167 }
1168
1169 void SPrefsPanel::changeStyle( QString s_style )
1170 {
1171     QApplication::setStyle( s_style );
1172
1173     /* force refresh on all widgets */
1174     QWidgetList widgets = QApplication::allWidgets();
1175     QWidgetList::iterator it = widgets.begin();
1176     while( it != widgets.end() ) {
1177         (*it)->update();
1178         ++it;
1179     };
1180 }
1181
1182 void SPrefsPanel::langChanged( int i )
1183 {
1184     lang = strdup( ppsz_language[i] );
1185 }
1186
1187 void SPrefsPanel::configML()
1188 {
1189 #ifdef SQL_MEDIA_LIBRARY
1190     MLConfDialog *mld = new MLConfDialog( this, p_intf );
1191     mld->exec();
1192     delete mld;
1193 #endif
1194 }
1195
1196 #ifdef _WIN32
1197 #include <QDialogButtonBox>
1198 #include "util/registry.hpp"
1199
1200 void SPrefsPanel::cleanLang() {
1201     QVLCRegistry *qvReg = new QVLCRegistry( HKEY_CURRENT_USER );
1202     qvReg->DeleteValue( "Software\\VideoLAN\\VLC\\", "Lang" );
1203     qvReg->DeleteKey( "Software\\VideoLAN\\", "VLC" );
1204     qvReg->DeleteKey( "Software\\", "VideoLAN" );
1205     delete qvReg;
1206 }
1207
1208 void SPrefsPanel::saveLang() {
1209     if( !lang ) return;
1210
1211     if( !strncmp( lang, "auto", 4 ) ) {
1212         cleanLang();
1213     }
1214     else
1215     {
1216         QVLCRegistry *qvReg = new QVLCRegistry( HKEY_CURRENT_USER );
1217         qvReg->WriteRegistryString( "Software\\VideoLAN\\VLC\\", "Lang", lang );
1218     }
1219 }
1220
1221 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
1222                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
1223 {
1224     bool b_temp;
1225     const char* psz_VLC = "VLC";
1226     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
1227
1228     if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
1229     {
1230         current->setCheckState( 0, Qt::Checked );
1231         b_temp = false;
1232     }
1233     else
1234     {
1235         current->setCheckState( 0, Qt::Unchecked );
1236         b_temp = true;
1237     }
1238     listAsso.append( current );
1239     return b_temp;
1240 }
1241
1242 void SPrefsPanel::assoDialog()
1243 {
1244 #if !defined(__IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__)
1245 #define __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__
1246     const GUID IID_IApplicationAssociationRegistrationUI = {0x1f76a169,0xf994,0x40ac, {0x8f,0xc8,0x09,0x59,0xe8,0x87,0x47,0x10}};
1247     const GUID CLSID_ApplicationAssociationRegistrationUI = { 0x1968106d,0xf3b5,0x44cf,{0x89,0x0e,0x11,0x6f,0xcb,0x9e,0xce,0xf1}};
1248 #ifdef __cplusplus
1249     interface IApplicationAssociationRegistrationUI : public IUnknown
1250     {
1251         virtual HRESULT STDMETHODCALLTYPE LaunchAdvancedAssociationUI(
1252                 LPCWSTR pszAppRegName) = 0;
1253     };
1254 #endif /* __cplusplus */
1255 #endif /* __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__ */
1256
1257     IApplicationAssociationRegistrationUI *p_appassoc;
1258     CoInitializeEx( NULL, COINIT_MULTITHREADED );
1259
1260     if( S_OK == CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
1261                 NULL, CLSCTX_INPROC_SERVER,
1262                 IID_IApplicationAssociationRegistrationUI,
1263                 (void **)&p_appassoc) )
1264     {
1265         if(S_OK == p_appassoc->LaunchAdvancedAssociationUI(L"VLC" ) )
1266         {
1267             CoUninitialize();
1268             return;
1269         }
1270     }
1271
1272     CoUninitialize();
1273
1274     QDialog *d = new QDialog( this );
1275     d->setWindowTitle( qtr( "File associations" ) );
1276     QGridLayout *assoLayout = new QGridLayout( d );
1277
1278     QTreeWidget *filetypeList = new QTreeWidget;
1279     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
1280     filetypeList->header()->hide();
1281
1282     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
1283
1284     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
1285     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
1286     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
1287
1288     filetypeList->addTopLevelItem( audioType );
1289     filetypeList->addTopLevelItem( videoType );
1290     filetypeList->addTopLevelItem( otherType );
1291
1292     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
1293     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
1294     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
1295
1296     QTreeWidgetItem *currentItem = NULL;
1297
1298     int i_temp = 0;
1299 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
1300 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
1301 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
1302
1303     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
1304     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
1305     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".opus" );
1306     aTa( ".spx" ); aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
1307     audioType->setCheckState( 0, ( i_temp > 0 ) ?
1308                               ( ( i_temp == audioType->childCount() ) ?
1309                                Qt::Checked : Qt::PartiallyChecked )
1310                             : Qt::Unchecked );
1311
1312     i_temp = 0;
1313     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
1314     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
1315     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
1316     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
1317     aTv( ".mts" ); aTv( ".mtv" ); aTv( ".mxf" );
1318     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
1319     aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
1320     videoType->setCheckState( 0, ( i_temp > 0 ) ?
1321                               ( ( i_temp == audioType->childCount() ) ?
1322                                Qt::Checked : Qt::PartiallyChecked )
1323                             : Qt::Unchecked );
1324
1325     i_temp = 0;
1326     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
1327     aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
1328     otherType->setCheckState( 0, ( i_temp > 0 ) ?
1329                               ( ( i_temp == audioType->childCount() ) ?
1330                                Qt::Checked : Qt::PartiallyChecked )
1331                             : Qt::Unchecked );
1332
1333 #undef aTo
1334 #undef aTv
1335 #undef aTa
1336
1337     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
1338     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
1339     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
1340     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1341     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
1342
1343     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
1344
1345     CONNECT( closeButton, clicked(), this, saveAsso() );
1346     CONNECT( clearButton, clicked(), d, reject() );
1347     d->resize( 300, 400 );
1348     d->exec();
1349     delete qvReg;
1350     listAsso.clear();
1351 }
1352
1353 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
1354 {
1355     QString s_path( "VLC" ); s_path += psz_ext;
1356     QString s_path2 = s_path;
1357
1358     /* Save a backup if already assigned */
1359     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1360
1361     if( !EMPTY_STR(psz_value) )
1362         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
1363     free( psz_value );
1364
1365     /* Put a "link" to VLC.EXT as default */
1366     qvReg->WriteRegistryString( psz_ext, "", qtu( s_path ) );
1367
1368     /* Create the needed Key if they weren't done in the installer */
1369     if( !qvReg->RegistryKeyExists( qtu( s_path ) ) )
1370     {
1371         qvReg->WriteRegistryString( psz_ext, "", qtu( s_path ) );
1372         qvReg->WriteRegistryString( qtu( s_path ), "", "Media file" );
1373         qvReg->WriteRegistryString( qtu( s_path.append( "\\shell" ) ), "", "Play" );
1374
1375         /* Get the installer path */
1376         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1377         QString str_temp = qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" );
1378
1379         if( str_temp.size() )
1380         {
1381             qvReg->WriteRegistryString( qtu( s_path.append( "\\Play\\command" ) ),
1382                 "", qtu( str_temp.append(" --started-from-file \"%1\"" ) ) );
1383
1384             qvReg->WriteRegistryString( qtu( s_path2.append( "\\DefaultIcon" ) ),
1385                         "", qtu( str_temp.append(",0") ) );
1386         }
1387         delete qvReg2;
1388     }
1389 }
1390
1391 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1392 {
1393     QString s_path( "VLC"); s_path += psz_ext;
1394     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
1395
1396     if( psz_value && !strcmp( qtu(s_path), psz_value ) )
1397     {
1398         free( psz_value );
1399         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1400         if( psz_value )
1401             qvReg->WriteRegistryString( psz_ext, "", psz_value );
1402
1403         qvReg->DeleteKey( psz_ext, "VLC.backup" );
1404     }
1405     free( psz_value );
1406 }
1407
1408 void SPrefsPanel::saveAsso()
1409 {
1410     QVLCRegistry * qvReg = NULL;
1411     for( int i = 0; i < listAsso.size(); i ++ )
1412     {
1413         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
1414         if( listAsso[i]->checkState( 0 ) > 0 )
1415         {
1416             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1417         }
1418         else
1419         {
1420             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1421         }
1422     }
1423     /* Gruik ? Naaah */
1424     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1425     delete qvReg;
1426 }
1427
1428 #endif /* _WIN32 */
1429