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