Qt: fix OSS simple prefs
[vlc.git] / 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 48
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 ) :
243                                   QWidget( _parent ), p_intf( _p_intf )
244 {
245     QHBoxLayout *layout = new QHBoxLayout();
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 = 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 + 40 , icon_height ) );         \
262     button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred        ); \
263     button->setAutoRaise( true );                                           \
264     button->setCheckable( true );                                           \
265     button->setAutoExclusive( true );                                       \
266     CONNECT( button, clicked(), mapper, map() );                            \
267     mapper->setMapping( button, numb );                                     \
268     layout->addWidget( button );
269
270     ADD_CATEGORY( SPrefsInterface, qtr("Interface"), qtr("Interface Settings"),
271                   cone_interface_64, 0 );
272     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), qtr("Audio Settings"),
273                   cone_audio_64, 1 );
274     ADD_CATEGORY( SPrefsVideo, qtr("Video"), qtr("Video Settings"),
275                   cone_video_64, 2 );
276     ADD_CATEGORY( SPrefsSubtitles, qtr(SUBPIC_TITLE), qtr("Subtitle & On Screen Display Settings"),
277                   cone_subtitles_64, 3 );
278     ADD_CATEGORY( SPrefsInputAndCodecs, qtr(INPUT_TITLE), qtr("Input & Codecs Settings"),
279                   cone_input_64, 4 );
280     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), qtr("Configure Hotkeys"),
281                   cone_hotkeys_64, 5 );
282
283 #undef ADD_CATEGORY
284
285     SPrefsInterface->setChecked( true );
286     layout->setMargin( 0 );
287     layout->setSpacing( 1 );
288
289     setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
290     setMinimumWidth( ICON_HEIGHT * 6 + 10 );
291     setLayout( layout );
292 }
293
294 void SPrefsCatList::switchPanel( int i )
295 {
296     emit currentItemChanged( i );
297 }
298
299 /*********************************************************************
300  * The Panels
301  *********************************************************************/
302 SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
303                           int _number ) : QWidget( _parent ), p_intf( _p_intf )
304 {
305     module_config_t *p_config;
306     ConfigControl *control;
307     number = _number;
308     lang = NULL;
309
310 #define CONFIG_GENERIC( option, type, label, qcontrol )                   \
311             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
312             if( p_config )                                                \
313             {                                                             \
314                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
315                            p_config, label, ui.qcontrol, false );         \
316                 controls.append( control );                               \
317             }                                                             \
318             else {                                                        \
319                 ui.qcontrol->setEnabled( false );                         \
320                 if( label ) label->setEnabled( false );                   \
321             }
322
323 #define CONFIG_BOOL( option, qcontrol )                           \
324             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
325             if( p_config )                                                \
326             {                                                             \
327                 control =  new BoolConfigControl( VLC_OBJECT(p_intf),     \
328                            p_config, NULL, ui.qcontrol );          \
329                 controls.append( control );                               \
330             }                                                             \
331             else { ui.qcontrol->setEnabled( false ); }
332
333
334 #define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol )             \
335             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
336             if( p_config )                                                \
337             {                                                             \
338                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
339                            p_config, label, qcontrol, false );            \
340                 controls.append( control );                               \
341             }                                                             \
342             else {                                                        \
343                 QWidget *widget = label;                                  \
344                 qcontrol->setVisible( false );                            \
345                 if( widget ) widget->setEnabled( false );                 \
346             }
347
348
349 #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
350             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
351             if( p_config )                                                \
352             {                                                             \
353                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
354                            p_config, label, ui.qcontrol );                \
355                 controls.append( control );                               \
356             }
357
358 #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )     \
359             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
360             if( p_config )                                                \
361             {                                                             \
362                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
363                            p_config, label, qcontrol, qbutton );          \
364                 controls.append( control );                               \
365             }
366
367 #define START_SPREFS_CAT( name , label )    \
368         case SPrefs ## name:                \
369         {                                   \
370             Ui::SPrefs ## name ui;      \
371             ui.setupUi( panel );            \
372             panel_label->setText( label );
373
374 #define END_SPREFS_CAT      \
375             break;          \
376         }
377
378     QVBoxLayout *panel_layout = new QVBoxLayout();
379     QWidget *panel = new QWidget();
380     panel_layout->setMargin( 3 );
381
382     // Title Label
383     QLabel *panel_label = new QLabel;
384     QFont labelFont = QApplication::font();
385     labelFont.setPointSize( labelFont.pointSize() + 6 );
386     panel_label->setFont( labelFont );
387
388     // Title <hr>
389     QFrame *title_line = new QFrame;
390     title_line->setFrameShape(QFrame::HLine);
391     title_line->setFrameShadow(QFrame::Sunken);
392
393     QFont italicFont = QApplication::font();
394     italicFont.setItalic( true );
395
396     switch( number )
397     {
398         /******************************
399          * VIDEO Panel Implementation *
400          ******************************/
401         START_SPREFS_CAT( Video , qtr("Video Settings") );
402             CONFIG_BOOL( "video", enableVideo );
403             ui.videoZone->setEnabled( ui.enableVideo->isChecked() );
404             CONNECT( ui.enableVideo, toggled( bool ),
405                      ui.videoZone, setEnabled( bool ) );
406
407             CONFIG_BOOL( "fullscreen", fullscreen );
408             CONFIG_BOOL( "overlay", overlay );
409             CONFIG_BOOL( "video-on-top", alwaysOnTop );
410             CONFIG_BOOL( "video-deco", windowDecorations );
411             CONFIG_GENERIC( "vout", StringList, ui.voutLabel, outputModule );
412
413 #ifdef _WIN32
414             CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
415                             dXdisplayDevice );
416             CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
417             CONNECT( ui.overlay, toggled( bool ), ui.hwYUVBox, setEnabled( bool ) );
418 #else
419             ui.directXBox->setVisible( false );
420             ui.hwYUVBox->setVisible( false );
421 #endif
422
423 #ifdef __OS2__
424             CONFIG_BOOL( "kva-fixt23", kvaFixT23 );
425             CONFIG_GENERIC( "kva-video-mode", StringList, ui.kvaVideoModeLabel,
426                             kvaVideoMode );
427 #else
428             ui.kvaBox->setVisible( false );
429 #endif
430
431             CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
432             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
433             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
434
435             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
436                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
437             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
438             CONFIG_BOOL( "snapshot-sequential",
439                             snapshotsSequentialNumbering );
440             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
441                             snapshotsFormat );
442          END_SPREFS_CAT;
443
444         /******************************
445          * AUDIO Panel Implementation *
446          ******************************/
447         START_SPREFS_CAT( Audio, qtr("Audio Settings") );
448
449             CONFIG_BOOL( "audio", enableAudio );
450             ui.audioZone->setEnabled( ui.enableAudio->isChecked() );
451             CONNECT( ui.enableAudio, toggled( bool ),
452                      ui.audioZone, setEnabled( bool ) );
453
454 #define audioCommon( name ) \
455             QLabel * name ## Label = new QLabel( qtr( "Device:" ) ); \
456             name ## Label->setMinimumSize(QSize(250, 0)); \
457             outputAudioLayout->addWidget( name ## Label, outputAudioLayout->rowCount(), 0, 1, 1 ); \
458
459 #define audioControl( name) \
460             audioCommon( name ) \
461             QComboBox * name ## Device = new QComboBox; \
462             name ## Label->setBuddy( name ## Device ); \
463             name ## Device->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred  );\
464             outputAudioLayout->addWidget( name ## Device, outputAudioLayout->rowCount() - 1, 1, 1, -1 );
465
466 #define audioControl2( name) \
467             audioCommon( name ) \
468             QHBoxLayout * name ## hboxLayout = new QHBoxLayout; \
469             QLineEdit * name ## Device = new QLineEdit; \
470             name ## Label->setBuddy( name ## Device ); \
471             name ## hboxLayout->addWidget( name ## Device ); \
472             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ) ); \
473             name ## hboxLayout->addWidget( name ## Browse ); \
474             outputAudioLayout->addLayout( name ## hboxLayout, outputAudioLayout->rowCount() - 1, 1, 1, 1, Qt::AlignLeft );
475
476             /* Build if necessary */
477             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
478 #ifdef _WIN32
479             audioControl( DirectX );
480             optionWidgets["directxL" ] = DirectXLabel;
481             optionWidgets["directxW" ] = DirectXDevice;
482             CONFIG_GENERIC_NO_UI( "directx-audio-device", StringList,
483                     DirectXLabel, DirectXDevice );
484
485             audioControl( Waveout );
486             optionWidgets["waveoutL" ] = WaveoutLabel;
487             optionWidgets["waveoutW" ] = WaveoutDevice;
488             CONFIG_GENERIC_NO_UI( "waveout-audio-device", StringList,
489                     WaveoutLabel, WaveoutDevice );
490
491 #elif defined( __OS2__ )
492             audioControl( kai );
493             optionWidgets["kaiL"] = kaiLabel;
494             optionWidgets["kaiW"] = kaiDevice;
495             CONFIG_GENERIC_NO_UI( "kai-audio-device", StringList, kaiLabel,
496                     kaiDevice );
497 #else
498             if( module_exists( "alsa" ) )
499             {
500                 audioControl( alsa );
501                 optionWidgets["alsaL"] = alsaLabel;
502                 optionWidgets["alsaW"] = alsaDevice;
503                 CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
504                                 alsaDevice );
505             }
506             if( module_exists( "oss" ) )
507             {
508                 audioControl2( OSS );
509                 optionWidgets["ossL"] = OSSLabel;
510                 optionWidgets["ossW"] = OSSDevice;
511                 optionWidgets["ossB"] = OSSBrowse;
512                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, OSSLabel, OSSDevice,
513                                  OSSBrowse );
514             }
515 #endif
516
517 #undef audioControl2
518 #undef audioControl
519 #undef audioCommon
520
521             int i_max_volume = config_GetInt( p_intf, "qt-max-volume" );
522
523             /* Audio Options */
524             ui.volumeValue->setMaximum( i_max_volume );
525             ui.defaultVolume->setMaximum( i_max_volume );
526
527             CONNECT( ui.defaultVolume, valueChanged( int ),
528                      this, updateAudioVolume( int ) );
529
530             ui.defaultVolume_zone->setEnabled( ui.resetVolumeCheckbox->isChecked() );
531             CONNECT( ui.resetVolumeCheckbox, toggled( bool ),
532                      ui.defaultVolume_zone, setEnabled( bool ) );
533
534             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
535                             preferredAudioLanguage );
536
537             CONFIG_BOOL( "spdif", spdifBox );
538             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
539                             detectionDolby );
540
541             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
542                                     volNormSpin );
543             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
544                             replayCombo );
545             CONFIG_GENERIC( "audio-visual" , StringList, ui.visuLabel,
546                             visualisation);
547             CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
548
549             /* Audio Output Specifics */
550             CONFIG_GENERIC( "aout", StringList, ui.outputLabel, outputModule );
551
552             CONNECT( ui.outputModule, currentIndexChanged( int ),
553                      this, updateAudioOptions( int ) );
554
555             /* File output exists on all platforms */
556             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
557                                  ui.fileName, ui.fileBrowseButton );
558
559             optionWidgets["fileW"] = ui.fileControl;
560             optionWidgets["audioOutCoB"] = ui.outputModule;
561             optionWidgets["normalizerChB"] = ui.volNormBox;
562             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
563             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
564             optionWidgets["volLW"] = ui.volumeValue;
565             optionWidgets["headphoneB"] = ui.headphoneEffect;
566             optionWidgets["spdifChB"] = ui.spdifBox;
567             optionWidgets["defaultVolume"] = ui.defaultVolume;
568             optionWidgets["resetVolumeCheckbox"] = ui.resetVolumeCheckbox;
569             updateAudioOptions( ui.outputModule->currentIndex() );
570
571             /* LastFM */
572             if( module_exists( "audioscrobbler" ) )
573             {
574                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
575                         lastfm_user_edit );
576                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
577                         lastfm_pass_edit );
578
579                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
580                     ui.lastfm->setChecked( true );
581                 else
582                     ui.lastfm->setChecked( false );
583
584                 ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
585
586                 CONNECT( ui.lastfm, toggled( bool ),
587                          ui.lastfm_zone, setVisible( bool ) );
588                 CONNECT( ui.lastfm, stateChanged( int ),
589                          this, lastfm_Changed( int ) );
590             }
591             else
592             {
593                 ui.lastfm->hide();
594                 ui.lastfm_zone->hide();
595             }
596
597             /* Normalizer */
598             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
599                      setEnabled( bool ) );
600
601             char* psz = config_GetPsz( p_intf, "audio-filter" );
602             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
603             free( psz );
604
605             bool b_enabled = ( qs_filter.contains( "normvol" ) );
606             ui.volNormBox->setChecked( b_enabled );
607             ui.volNormSpin->setEnabled( b_enabled );
608
609             b_enabled = ( qs_filter.contains( "headphone" ) );
610             ui.headphoneEffect->setChecked( b_enabled );
611
612             /* Volume Label */
613             updateAudioVolume( ui.defaultVolume->value() ); // First time init
614
615         END_SPREFS_CAT;
616
617         /* Input and Codecs Panel Implementation */
618         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
619
620             /* Disk Devices */
621             {
622                 ui.DVDDeviceComboBox->setToolTip(
623                     qtr( "If this property is blank, different values\n"
624                          "for DVD, VCD, and CDDA are set.\n"
625                          "You can define a unique one or configure them \n"
626                          "individually in the advanced preferences." ) );
627                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
628                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
629                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
630                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
631                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
632                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
633                 {
634                     ui.DVDDeviceComboBox->setEditText( qfu( psz_dvddiscpath ) );
635                 }
636                 free( psz_cddadiscpath );
637                 free( psz_dvddiscpath );
638                 free( psz_vcddiscpath );
639             }
640 #ifndef _WIN32
641             QStringList DVDDeviceComboBoxStringList = QStringList();
642             DVDDeviceComboBoxStringList
643                     << "dvd*" << "scd*" << "sr*" << "sg*" << "cd*";
644             ui.DVDDeviceComboBox->addItems( QDir( "/dev/" )
645                     .entryList( DVDDeviceComboBoxStringList, QDir::System )
646                     .replaceInStrings( QRegExp("^"), "/dev/" )
647             );
648 #endif
649             CONFIG_GENERIC( "dvd", String, ui.DVDLabel,
650                             DVDDeviceComboBox->lineEdit() );
651             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
652                                  ui.recordPath, ui.recordBrowse );
653
654             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
655             CONFIG_GENERIC_NO_BOOL( "postproc-q", Integer, ui.ppLabel,
656                                     PostProcLevel );
657             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
658
659             /* live555 module prefs */
660             CONFIG_BOOL( "rtsp-tcp",
661                                 live555TransportRTSP_TCPRadio );
662             if ( !module_exists( "live555" ) )
663             {
664                 ui.live555TransportRTSP_TCPRadio->hide();
665                 ui.live555TransportHTTPRadio->hide();
666                 ui.live555TransportLabel->hide();
667             }
668             CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel, hwAccelModule );
669 #ifdef _WIN32
670             HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
671             if( !hdxva2_dll )
672                 ui.hwAccelModule->setEnabled( false );
673             else
674                 FreeLibrary( hdxva2_dll );
675 #endif
676             optionWidgets["inputLE"] = ui.DVDDeviceComboBox;
677             optionWidgets["cachingCoB"] = ui.cachingCombo;
678             CONFIG_GENERIC( "avcodec-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
679             CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
680             CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
681             CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
682             CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
683             CONFIG_BOOL( "mkv-preload-local-dir", mkvPreloadBox );
684
685             /* Caching */
686             /* Add the things to the ComboBox */
687             #define addToCachingBox( str, cachingNumber ) \
688                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
689             addToCachingBox( N_("Custom"), CachingCustom );
690             addToCachingBox( N_("Lowest latency"), CachingLowest );
691             addToCachingBox( N_("Low latency"), CachingLow );
692             addToCachingBox( N_("Normal"), CachingNormal );
693             addToCachingBox( N_("High latency"), CachingHigh );
694             addToCachingBox( N_("Higher latency"), CachingHigher );
695             #undef addToCachingBox
696
697 #define TestCaC( name, factor ) \
698     b_cache_equal =  b_cache_equal && \
699      ( i_cache * factor == config_GetInt( p_intf, name ) );
700             /* Select the accurate value of the ComboBox */
701             bool b_cache_equal = true;
702             int i_cache = config_GetInt( p_intf, "file-caching" );
703
704             TestCaC( "network-caching", 10/3 );
705             TestCaC( "disc-caching", 1);
706             TestCaC( "live-caching", 1 );
707             if( b_cache_equal == 1 )
708                 ui.cachingCombo->setCurrentIndex(
709                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
710 #undef TestCaC
711
712         END_SPREFS_CAT;
713         /*******************
714          * Interface Panel *
715          *******************/
716         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
717
718 #ifndef _WIN32
719             ui.langBox->hide();
720 #else
721             for( int i = 0; ppsz_language[i] != NULL; i++)
722                 ui.langCombo->addItem( qfu(ppsz_language_text[i]), ppsz_language[i]);
723             CONNECT( ui.langCombo, currentIndexChanged( int ), this, langChanged( int ) );
724
725             HKEY h_key;
726             char *langReg = NULL;
727             if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
728                     == ERROR_SUCCESS )
729             {
730                 TCHAR szData[256];
731                 DWORD len = 256;
732                 if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) {
733                     langReg = FromWide( szData );
734                     ui.langCombo->setCurrentIndex( ui.langCombo->findData(langReg) );
735                 }
736             }
737             free( langReg);
738 #endif
739
740 //            ui.defaultLabel->setFont( italicFont );
741             ui.skinsLabel->setText(
742                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
743                     + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">" )
744                     + qtr( "VLC skins website" )+ QString( "</a>." ) );
745             ui.skinsLabel->setFont( italicFont );
746
747 #ifdef _WIN32
748             BUTTONACT( ui.assoButton, assoDialog() );
749 #else
750             ui.osGroupBox->hide();
751 #endif
752
753             /* interface */
754             char *psz_intf = config_GetPsz( p_intf, "intf" );
755             if( psz_intf )
756             {
757                 if( strstr( psz_intf, "skin" ) )
758                     ui.skins->setChecked( true );
759             } else {
760                 /* defaults to qt */
761                 ui.qt->setChecked( true );
762             }
763             free( psz_intf );
764
765             optionWidgets["skinRB"] = ui.skins;
766             optionWidgets["qtRB"] = ui.qt;
767 #if !defined( _WIN32)
768             ui.stylesCombo->addItem( qtr("System's default") );
769             ui.stylesCombo->addItems( QStyleFactory::keys() );
770             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
771                         getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
772             ui.stylesCombo->insertSeparator( 1 );
773             if ( ui.stylesCombo->currentIndex() < 0 )
774                 ui.stylesCombo->setCurrentIndex( 0 ); /* default */
775
776             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
777             optionWidgets["styleCB"] = ui.stylesCombo;
778 #else
779             ui.stylesCombo->hide();
780             ui.stylesLabel->hide();
781 #endif
782             radioGroup = new QButtonGroup(this);
783             radioGroup->addButton( ui.qt, 0 );
784             radioGroup->addButton( ui.skins, 1 );
785             CONNECT( radioGroup, buttonClicked( int ),
786                      ui.styleStackedWidget, setCurrentIndex( int ) );
787             ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
788
789             CONNECT( ui.minimalviewBox, toggled( bool ),
790                      ui.mainPreview, setNormalPreview( bool ) );
791             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
792             ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
793             ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
794
795             CONFIG_BOOL( "embedded-video", embedVideo );
796             CONFIG_BOOL( "qt-video-autoresize", resizingBox );
797             CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
798             ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );
799
800             CONFIG_BOOL( "qt-fs-controller", fsController );
801             CONFIG_BOOL( "qt-system-tray", systrayBox );
802             CONFIG_GENERIC( "qt-notification", IntegerList, ui.notificationComboLabel,
803                                                       notificationCombo );
804             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationCombo, setEnabled( bool ) );
805             CONNECT( ui.systrayBox, toggled( bool ), ui.notificationComboLabel, setEnabled( bool ) );
806             ui.notificationCombo->setEnabled( ui.systrayBox->isChecked() );
807
808             CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
809             CONFIG_BOOL( "playlist-tree", treePlaylist );
810             CONFIG_BOOL( "play-and-pause", playPauseBox );
811             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
812                                  ui.fileSkin, ui.skinBrowse );
813
814             CONFIG_BOOL( "metadata-network-access", MetadataNetworkAccessMode );
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     QScrollArea *scroller= new QScrollArea;
935     scroller->setWidget( panel );
936     scroller->setWidgetResizable( true );
937     scroller->setFrameStyle( QFrame::NoFrame );
938     panel_layout->addWidget( scroller );
939
940     setLayout( panel_layout );
941
942 #undef END_SPREFS_CAT
943 #undef START_SPREFS_CAT
944 #undef CONFIG_GENERIC_FILE
945 #undef CONFIG_GENERIC_NO_BOOL
946 #undef CONFIG_GENERIC_NO_UI
947 #undef CONFIG_GENERIC
948 #undef CONFIG_BOOL
949 }
950
951
952 void SPrefsPanel::updateAudioOptions( int number)
953 {
954     QString value = qobject_cast<QComboBox *>(optionWidgets["audioOutCoB"])
955                                             ->itemData( number ).toString();
956 #ifdef _WIN32
957     optionWidgets["directxW"]->setVisible( ( value == "directsound" ) );
958     optionWidgets["directxL"]->setVisible( ( value == "directsound" ) );
959     optionWidgets["waveoutW"]->setVisible( ( value == "waveout" ) );
960     optionWidgets["waveoutL"]->setVisible( ( value == "waveout" ) );
961 #elif defined( __OS2__ )
962     optionWidgets["kaiL"]->setVisible( ( value == "kai" ) );
963     optionWidgets["kaiW"]->setVisible( ( value == "kai" ) );
964 #else
965     /* optionWidgets["ossW] can be NULL */
966     if( optionWidgets["ossW"] ) {
967         optionWidgets["ossW"]->setVisible( ( value == "oss" ) );
968         optionWidgets["ossL"]->setVisible( ( value == "oss" ) );
969         optionWidgets["ossB"]->setVisible( ( value == "oss" ) );
970     }
971     /* optionWidgets["alsaW] can be NULL */
972     if( optionWidgets["alsaW"] ) {
973         optionWidgets["alsaW"]->setVisible( ( value == "alsa" ) );
974         optionWidgets["alsaL"]->setVisible( ( value == "alsa" ) );
975     }
976 #endif
977     optionWidgets["fileW"]->setVisible( ( value == "afile" ) );
978     optionWidgets["spdifChB"]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
979                                            value == "directsound" || value == "waveout" ) );
980
981     int volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), qtu(value));
982     bool save = true;
983
984     if (volume >= 0)
985         save = config_GetInt(VLC_OBJECT(p_intf), "volume-save");
986
987     QCheckBox *resetVolumeCheckBox =
988         qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"]);
989     resetVolumeCheckBox->setChecked(!save);
990     resetVolumeCheckBox->setEnabled(volume >= 0);
991
992     QSlider *defaultVolume =
993         qobject_cast<QSlider *>(optionWidgets["defaultVolume"]);
994     defaultVolume->setValue((volume >= 0) ? volume : 100);
995     defaultVolume->setEnabled(volume >= 0);
996 }
997
998
999 SPrefsPanel::~SPrefsPanel()
1000 {
1001     qDeleteAll( controls ); controls.clear();
1002 }
1003
1004 void SPrefsPanel::updateAudioVolume( int volume )
1005 {
1006     qobject_cast<QSpinBox *>(optionWidgets["volLW"])
1007         ->setValue( volume );
1008 }
1009
1010
1011 /* Function called from the main Preferences dialog on each SPrefs Panel */
1012 void SPrefsPanel::apply()
1013 {
1014     /* Generic save for ever panel */
1015     QList<ConfigControl *>::const_iterator i;
1016     for( i = controls.begin() ; i != controls.end() ; ++i )
1017     {
1018         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
1019         c->doApply();
1020     }
1021
1022     switch( number )
1023     {
1024     case SPrefsInputAndCodecs:
1025     {
1026         /* Device default selection */
1027         QByteArray devicepath =
1028             qobject_cast<QComboBox *>(optionWidgets["inputLE"])->currentText().toUtf8();
1029         if( devicepath.size() > 0 )
1030         {
1031             config_PutPsz( p_intf, "dvd", devicepath );
1032             config_PutPsz( p_intf, "vcd", devicepath );
1033             config_PutPsz( p_intf, "cd-audio", devicepath );
1034         }
1035
1036 #define CaC( name, factor ) config_PutInt( p_intf, name, i_comboValue * factor )
1037         /* Caching */
1038         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets["cachingCoB"]);
1039         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
1040         if( i_comboValue )
1041         {
1042             CaC( "file-caching", 1 );
1043             CaC( "network-caching", 10/3 );
1044             CaC( "disc-caching", 1 );
1045             CaC( "live-caching", 1 );
1046         }
1047         break;
1048 #undef CaC
1049     }
1050
1051     /* Interfaces */
1052     case SPrefsInterface:
1053     {
1054         if( qobject_cast<QRadioButton *>(optionWidgets["skinRB"])->isChecked() )
1055             config_PutPsz( p_intf, "intf", "skins2,any" );
1056         else
1057         //if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
1058             config_PutPsz( p_intf, "intf", "" );
1059         if( qobject_cast<QComboBox *>(optionWidgets["styleCB"]) )
1060             getSettings()->setValue( "MainWindow/QtStyle",
1061                 qobject_cast<QComboBox *>(optionWidgets["styleCB"])->currentText() );
1062 #ifdef _WIN32
1063     saveLang();
1064 #endif
1065         break;
1066     }
1067
1068     case SPrefsAudio:
1069     {
1070         bool b_checked =
1071             qobject_cast<QCheckBox *>(optionWidgets["normalizerChB"])->isChecked();
1072         if( b_checked && !qs_filter.contains( "normvol" ) )
1073             qs_filter.append( "normvol" );
1074         if( !b_checked && qs_filter.contains( "normvol" ) )
1075             qs_filter.removeAll( "normvol" );
1076
1077         b_checked =
1078             qobject_cast<QCheckBox *>(optionWidgets["headphoneB"])->isChecked();
1079
1080         if( b_checked && !qs_filter.contains( "headphone" ) )
1081             qs_filter.append( "headphone" );
1082         if( !b_checked && qs_filter.contains( "headphone" ) )
1083             qs_filter.removeAll( "headphone" );
1084
1085         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
1086
1087         /* Default volume */
1088         int i_volume =
1089             qobject_cast<QSlider *>(optionWidgets["defaultVolume"])->value();
1090         bool b_reset_volume =
1091             qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"])->isChecked();
1092         module_config_t *p_config = config_FindConfig( VLC_OBJECT(p_intf), "aout" );
1093         char *psz_aout = p_config->value.psz;
1094
1095
1096         float f_gain = powf( i_volume / 100.f, 3 );
1097
1098 #define save_vol_aout( name ) \
1099             module_exists( name ) && ( !psz_aout || !strcmp( psz_aout, name ) || !strcmp( psz_aout, "any" ) )
1100
1101         //FIXME this is moot
1102 #if defined( _WIN32 )
1103         VLC_UNUSED( f_gain );
1104         if( save_vol_aout( "directsound" ) )
1105             config_PutFloat( p_intf, "directx-volume", i_volume / 100.f );
1106         if( save_vol_aout( "waveout" ) )
1107             config_PutFloat( p_intf, "waveout-volume", i_volume / 100.f );
1108 #elif defined( Q_OS_MAC )
1109         VLC_UNUSED( f_gain );
1110         if( save_vol_aout( "auhal" ) )
1111             config_PutFloat( p_intf, "auhal-volume", i_volume / 100.f
1112                     * AOUT_VOLUME_DEFAULT );
1113 #elif defined( __OS2__ )
1114         if( save_vol_aout( "kai" ) )
1115             config_PutFloat( p_intf, "kai-gain",  f_gain );
1116 #else
1117         if( save_vol_aout( "alsa" ) )
1118             config_PutFloat( p_intf, "alsa-gain", f_gain );
1119         if( save_vol_aout( "jack" ) )
1120             config_PutFloat( p_intf, "jack-gain", f_gain );
1121 #endif
1122 #undef save_vol_aout
1123
1124         config_PutInt( p_intf, "volume-save", !b_reset_volume );
1125
1126         break;
1127     }
1128     case SPrefsSubtitles:
1129     {
1130         bool b_checked = qobject_cast<QCheckBox *>(optionWidgets["shadowCB"])->isChecked();
1131         if( b_checked && config_GetInt( p_intf, "freetype-shadow-opacity" ) == 0 ) {
1132             config_PutInt( p_intf, "freetype-shadow-opacity", 128 );
1133         }
1134         else if (!b_checked ) {
1135             config_PutInt( p_intf, "freetype-shadow-opacity", 0 );
1136         }
1137
1138         b_checked = qobject_cast<QCheckBox *>(optionWidgets["backgroundCB"])->isChecked();
1139         if( b_checked && config_GetInt( p_intf, "freetype-background-opacity" ) == 0 ) {
1140             config_PutInt( p_intf, "freetype-background-opacity", 128 );
1141         }
1142         else if (!b_checked ) {
1143             config_PutInt( p_intf, "freetype-background-opacity", 0 );
1144         }
1145
1146     }
1147     }
1148 }
1149
1150 void SPrefsPanel::clean()
1151 {}
1152
1153 void SPrefsPanel::lastfm_Changed( int i_state )
1154 {
1155     if( i_state == Qt::Checked )
1156         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1157     else if( i_state == Qt::Unchecked )
1158         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
1159 }
1160
1161 void SPrefsPanel::changeStyle( QString s_style )
1162 {
1163     QApplication::setStyle( s_style );
1164
1165     /* force refresh on all widgets */
1166     QWidgetList widgets = QApplication::allWidgets();
1167     QWidgetList::iterator it = widgets.begin();
1168     while( it != widgets.end() ) {
1169         (*it)->update();
1170         ++it;
1171     };
1172 }
1173
1174 void SPrefsPanel::langChanged( int i )
1175 {
1176     lang = strdup( ppsz_language[i] );
1177 }
1178
1179 void SPrefsPanel::configML()
1180 {
1181 #ifdef SQL_MEDIA_LIBRARY
1182     MLConfDialog *mld = new MLConfDialog( this, p_intf );
1183     mld->exec();
1184     delete mld;
1185 #endif
1186 }
1187
1188 #ifdef _WIN32
1189 #include <QDialogButtonBox>
1190 #include "util/registry.hpp"
1191
1192 void SPrefsPanel::cleanLang() {
1193     QVLCRegistry *qvReg = new QVLCRegistry( HKEY_CURRENT_USER );
1194     qvReg->DeleteValue( "Software\\VideoLAN\\VLC\\", "Lang" );
1195     qvReg->DeleteKey( "Software\\VideoLAN\\", "VLC" );
1196     qvReg->DeleteKey( "Software\\", "VideoLAN" );
1197     delete qvReg;
1198 }
1199
1200 void SPrefsPanel::saveLang() {
1201     if( !lang ) return;
1202
1203     if( !strncmp( lang, "auto", 4 ) ) {
1204         cleanLang();
1205     }
1206     else
1207     {
1208         QVLCRegistry *qvReg = new QVLCRegistry( HKEY_CURRENT_USER );
1209         qvReg->WriteRegistryString( "Software\\VideoLAN\\VLC\\", "Lang", lang );
1210     }
1211 }
1212
1213 bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
1214                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
1215 {
1216     bool b_temp;
1217     const char* psz_VLC = "VLC";
1218     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
1219
1220     if( strstr( qvReg->ReadRegistryString( psz_ext, "", "" ), psz_VLC ) )
1221     {
1222         current->setCheckState( 0, Qt::Checked );
1223         b_temp = false;
1224     }
1225     else
1226     {
1227         current->setCheckState( 0, Qt::Unchecked );
1228         b_temp = true;
1229     }
1230     listAsso.append( current );
1231     return b_temp;
1232 }
1233
1234 void SPrefsPanel::assoDialog()
1235 {
1236 #if !defined(__IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__)
1237 #define __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__
1238     const GUID IID_IApplicationAssociationRegistrationUI = {0x1f76a169,0xf994,0x40ac, {0x8f,0xc8,0x09,0x59,0xe8,0x87,0x47,0x10}};
1239     const GUID CLSID_ApplicationAssociationRegistrationUI = { 0x1968106d,0xf3b5,0x44cf,{0x89,0x0e,0x11,0x6f,0xcb,0x9e,0xce,0xf1}};
1240 #ifdef __cplusplus
1241     interface IApplicationAssociationRegistrationUI : public IUnknown
1242     {
1243         virtual HRESULT STDMETHODCALLTYPE LaunchAdvancedAssociationUI(
1244                 LPCWSTR pszAppRegName) = 0;
1245     };
1246 #endif /* __cplusplus */
1247 #endif /* __IApplicationAssociationRegistrationUI_INTERFACE_DEFINED__ */
1248
1249     IApplicationAssociationRegistrationUI *p_appassoc;
1250     CoInitializeEx( NULL, COINIT_MULTITHREADED );
1251
1252     if( S_OK == CoCreateInstance(CLSID_ApplicationAssociationRegistrationUI,
1253                 NULL, CLSCTX_INPROC_SERVER,
1254                 IID_IApplicationAssociationRegistrationUI,
1255                 (void **)&p_appassoc) )
1256     {
1257         if(S_OK == p_appassoc->LaunchAdvancedAssociationUI(L"VLC" ) )
1258         {
1259             CoUninitialize();
1260             return;
1261         }
1262     }
1263
1264     CoUninitialize();
1265
1266     QDialog *d = new QDialog( this );
1267     d->setWindowTitle( qtr( "File associations" ) );
1268     QGridLayout *assoLayout = new QGridLayout( d );
1269
1270     QTreeWidget *filetypeList = new QTreeWidget;
1271     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
1272     filetypeList->header()->hide();
1273
1274     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
1275
1276     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
1277     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
1278     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
1279
1280     filetypeList->addTopLevelItem( audioType );
1281     filetypeList->addTopLevelItem( videoType );
1282     filetypeList->addTopLevelItem( otherType );
1283
1284     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
1285     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
1286     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
1287
1288     QTreeWidgetItem *currentItem = NULL;
1289
1290     int i_temp = 0;
1291 #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
1292 #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
1293 #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
1294
1295     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
1296     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
1297     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".opus" );
1298     aTa( ".spx" ); aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
1299     audioType->setCheckState( 0, ( i_temp > 0 ) ?
1300                               ( ( i_temp == audioType->childCount() ) ?
1301                                Qt::Checked : Qt::PartiallyChecked )
1302                             : Qt::Unchecked );
1303
1304     i_temp = 0;
1305     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
1306     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
1307     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
1308     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
1309     aTv( ".mts" ); aTv( ".mtv" ); aTv( ".mxf" );
1310     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
1311     aTv( ".vob" ); aTv( ".vro" ); aTv( ".wmv" );
1312     videoType->setCheckState( 0, ( i_temp > 0 ) ?
1313                               ( ( i_temp == audioType->childCount() ) ?
1314                                Qt::Checked : Qt::PartiallyChecked )
1315                             : Qt::Unchecked );
1316
1317     i_temp = 0;
1318     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" );
1319     aTo( ".sdp" ); aTo( ".vlc" ); aTo( ".xspf" );
1320     otherType->setCheckState( 0, ( i_temp > 0 ) ?
1321                               ( ( i_temp == audioType->childCount() ) ?
1322                                Qt::Checked : Qt::PartiallyChecked )
1323                             : Qt::Unchecked );
1324
1325 #undef aTo
1326 #undef aTv
1327 #undef aTa
1328
1329     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
1330     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
1331     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
1332     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
1333     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
1334
1335     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
1336
1337     CONNECT( closeButton, clicked(), this, saveAsso() );
1338     CONNECT( clearButton, clicked(), d, reject() );
1339     d->resize( 300, 400 );
1340     d->exec();
1341     delete qvReg;
1342     listAsso.clear();
1343 }
1344
1345 void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
1346 {
1347     QString s_path( "VLC" ); s_path += psz_ext;
1348     QString s_path2 = s_path;
1349
1350     /* Save a backup if already assigned */
1351     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
1352
1353     if( !EMPTY_STR(psz_value) )
1354         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
1355     free( psz_value );
1356
1357     /* Put a "link" to VLC.EXT as default */
1358     qvReg->WriteRegistryString( psz_ext, "", qtu( s_path ) );
1359
1360     /* Create the needed Key if they weren't done in the installer */
1361     if( !qvReg->RegistryKeyExists( qtu( s_path ) ) )
1362     {
1363         qvReg->WriteRegistryString( psz_ext, "", qtu( s_path ) );
1364         qvReg->WriteRegistryString( qtu( s_path ), "", "Media file" );
1365         qvReg->WriteRegistryString( qtu( s_path.append( "\\shell" ) ), "", "Play" );
1366
1367         /* Get the installer path */
1368         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
1369         QString str_temp = qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" );
1370
1371         if( str_temp.size() )
1372         {
1373             qvReg->WriteRegistryString( qtu( s_path.append( "\\Play\\command" ) ),
1374                 "", qtu( str_temp.append(" --started-from-file \"%1\"" ) ) );
1375
1376             qvReg->WriteRegistryString( qtu( s_path2.append( "\\DefaultIcon" ) ),
1377                         "", qtu( str_temp.append(",0") ) );
1378         }
1379         delete qvReg2;
1380     }
1381 }
1382
1383 void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
1384 {
1385     QString s_path( "VLC"); s_path += psz_ext;
1386     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", "" );
1387
1388     if( psz_value && !strcmp( qtu(s_path), psz_value ) )
1389     {
1390         free( psz_value );
1391         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
1392         if( psz_value )
1393             qvReg->WriteRegistryString( psz_ext, "", psz_value );
1394
1395         qvReg->DeleteKey( psz_ext, "VLC.backup" );
1396     }
1397     free( psz_value );
1398 }
1399
1400 void SPrefsPanel::saveAsso()
1401 {
1402     QVLCRegistry * qvReg = NULL;
1403     for( int i = 0; i < listAsso.size(); i ++ )
1404     {
1405         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
1406         if( listAsso[i]->checkState( 0 ) > 0 )
1407         {
1408             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1409         }
1410         else
1411         {
1412             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
1413         }
1414     }
1415     /* Gruik ? Naaah */
1416     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
1417     delete qvReg;
1418 }
1419
1420 #endif /* _WIN32 */
1421