simple_preferences.cpp 58 KB
Newer Older
1 2 3
/*****************************************************************************
 * simple_preferences.cpp : "Simple preferences"
 ****************************************************************************
4
 * Copyright (C) 2006-2010 the VideoLAN team
Pierre's avatar
Pierre committed
5
 * $Id$
6 7 8
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *          Antoine Cellerier <dionoea@videolan.org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
10
 *
11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/
25

26 27 28
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
29 30 31

#include "components/simple_preferences.hpp"
#include "components/preferences_widgets.hpp"
32

33
#include <vlc_config_cat.h>
34
#include <vlc_configuration.h>
35 36 37 38

#include <QString>
#include <QFont>
#include <QToolButton>
39
#include <QSignalMapper>
40
#include <QVBoxLayout>
41
#include <QScrollArea>
42

43 44
#include <QStyleFactory>
#include <QSettings>
45
#include <QScreen>
46
#include <QtAlgorithms>
47
#include <QDir>
48
#include <assert.h>
49
#include <math.h>
50

51
#define ICON_HEIGHT 48
52
#define ICON_WIDTH 48
53

54
#ifdef _WIN32
55
# include <vlc_charset.h>
56
# include <shobjidl.h>
57
#endif
58
#include <vlc_modules.h>
59 60 61 62 63 64 65 66 67
#include <vlc_arrays.h>

static struct {
    const char iso[6];
    const char name[34];

} const language_map[] = {
    { "auto",  N_("Auto") },
    { "en",    "American English" },
68
    { "ar",    "عربي" },
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
    { "bn",    "বাংলা" },
    { "pt_BR", "Português Brasileiro" },
    { "en_GB", "British English" },
    { "el",    "Νέα Ελληνικά" },
    { "bg",    "български език" },
    { "ca",    "Català" },
    { "zh_TW", "正體中文" },
    { "cs",    "Čeština" },
    { "cy",    "Cymraeg" },
    { "da",    "Dansk" },
    { "nl",    "Nederlands" },
    { "fi",    "Suomi" },
    { "et",    "eesti keel" },
    { "eu",    "Euskara" },
    { "fr",    "Français" },
    { "ga",    "Gaeilge" },
    { "gd",    "Gàidhlig" },
    { "gl",    "Galego" },
    { "ka",    "ქართული" },
    { "de",    "Deutsch" },
    { "he",    "עברית" },
    { "hr",    "hrvatski" },
    { "hu",    "Magyar" },
    { "hy",    "հայերեն" },
    { "is",    "íslenska" },
    { "id",    "Bahasa Indonesia" },
    { "it",    "Italiano" },
    { "ja",    "日本語" },
    { "ko",    "한국어" },
    { "lt",    "lietuvių" },
    { "mn",    "Монгол хэл" },
    { "ms",    "Melayu" },
    { "nb",    "Bokmål" },
    { "nn",    "Nynorsk" },
    { "kk",    "Қазақ тілі" },
    { "km",    "ភាសាខ្មែរ" },
    { "ne",    "नेपाली" },
    { "oc",    "Occitan" },
107
    { "fa",    "فارسی" },
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    { "pl",    "Polski" },
    { "pt_PT", "Português" },
    { "pa",    "ਪੰਜਾਬੀ" },
    { "ro",    "Română" },
    { "ru",    "Русский" },
    { "zh_CN", "简体中文" },
    { "si",    "සිංහල" },
    { "sr",    "српски" },
    { "sk",    "Slovensky" },
    { "sl",    "slovenščina" },
    { "ckb",   "کوردیی سۆرانی" },
    { "es",    "Español" },
    { "sv",    "Svenska" },
    { "te",    "తెలుగు" },
    { "tr",    "Türkçe" },
    { "uk",    "украї́нська мо́ва" },
    { "vi",    "tiếng Việt" },
    { "wa",    "Walon" }
126 127
};

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
static int getDefaultAudioVolume(vlc_object_t *obj, const char *aout)
{
    if (!strcmp(aout, "") || !strcmp(aout, "any"))
        return -1;
    else
    /* Note: For hysterical raisins, this is sorted by decreasing priority
     * order (then alphabetical order). */
    if (!strcmp(aout, "pulse"))
        return -1;
    else
#ifdef __linux__
    if (!strcmp(aout, "alsa") && module_exists("alsa"))
        return cbrtf(config_GetFloat(obj, "alsa-gain")) * 100.f + .5f;
    else
#endif
#ifdef _WIN32
    if (!strcmp(aout, "mmdevice"))
        return -1;
    else
#endif
    if (!strcmp(aout, "sndio"))
        return -1;
    else
#ifdef __APPLE__
152
    if (!strcmp(aout, "auhal") && module_exists("auhal"))
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
        return (config_GetFloat(obj, "auhal-volume") * 100.f + .5f)
                 / AOUT_VOLUME_DEFAULT;
    else
#endif
#ifdef _WIN32
    if (!strcmp(aout, "directsound") && module_exists("directsound"))
        return config_GetFloat(obj, "directx-volume") * 100.f + .5f;
    else
#endif
    if (!strcmp(aout, "jack"))
        return cbrtf(config_GetFloat(obj, "jack-gain")) * 100.f + 0.5f;
    else
#ifdef __OS2__
    if (!strcmp(aout, "kai"))
        return cbrtf(config_GetFloat(obj, "kai-gain")) * 100.f + .5f;
    else
#endif
    if (!strcmp(aout, "oss"))
        return -1;
    else
#ifdef _WIN32
    if (!strcmp(aout, "waveout"))
        return config_GetFloat(obj, "waveout-volume") * 100.f + .5f;
    else
#endif
        return -1;
}
180

181 182 183
/*********************************************************************
 * The List of categories
 *********************************************************************/
184
SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
185
                                  QWidget( _parent ), p_intf( _p_intf )
186
{
187
    QHBoxLayout *layout = new QHBoxLayout();
188

189 190 191 192 193
    /* Use autoExclusive buttons and a mapper as QButtonGroup can't
       set focus (keys) when it manages the buttons's exclusivity.
       See QT bugs 131 & 816 and QAbstractButton's source code. */
    QSignalMapper *mapper = new QSignalMapper( layout );
    CONNECT( mapper, mapped(int), this, switchPanel(int) );
194

195
    QPixmap scaled;
196 197 198 199 200
#if HAS_QT56
    qreal dpr = devicePixelRatioF();
#else
    qreal dpr = devicePixelRatio();
#endif
201

202
#define ADD_CATEGORY( button, label, ltooltip, icon, numb )                 \
203
    QToolButton * button = new QToolButton( this );                         \
204 205 206
    /* Scale icon to non native size outside of toolbutton to avoid widget size */\
    /* computation using native size */\
    scaled = QPixmap( ":/prefsmenu/" #icon ".png" )\
207 208
             .scaledToHeight( ICON_HEIGHT * dpr, Qt::SmoothTransformation );\
    scaled.setDevicePixelRatio( dpr ); \
209
    button->setIcon( scaled );                \
210
    button->setText( label );                                               \
211
    button->setToolTip( ltooltip );                                         \
212
    button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
213 214
    button->setIconSize( QSize( ICON_WIDTH, ICON_HEIGHT ) );          \
    button->setMinimumWidth( 40 + ICON_WIDTH );\
215
    button->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); \
216 217
    button->setAutoRaise( true );                                           \
    button->setCheckable( true );                                           \
218 219 220
    button->setAutoExclusive( true );                                       \
    CONNECT( button, clicked(), mapper, map() );                            \
    mapper->setMapping( button, numb );                                     \
221
    layout->addWidget( button );
222

223
    ADD_CATEGORY( SPrefsInterface, qtr("Interface"), qtr("Interface Settings"),
224
                  cone_interface_64, 0 );
225
    ADD_CATEGORY( SPrefsAudio, qtr("Audio"), qtr("Audio Settings"),
226
                  cone_audio_64, 1 );
227
    ADD_CATEGORY( SPrefsVideo, qtr("Video"), qtr("Video Settings"),
228
                  cone_video_64, 2 );
229
    ADD_CATEGORY( SPrefsSubtitles, qtr(SUBPIC_TITLE), qtr("Subtitle & On Screen Display Settings"),
230
                  cone_subtitles_64, 3 );
231
    ADD_CATEGORY( SPrefsInputAndCodecs, qtr(INPUT_TITLE), qtr("Input & Codecs Settings"),
232
                  cone_input_64, 4 );
233
    ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), qtr("Configure Hotkeys"),
234
                  cone_hotkeys_64, 5 );
235

Rémi Duraffort's avatar
Rémi Duraffort committed
236 237
#undef ADD_CATEGORY

238
    SPrefsInterface->setChecked( true );
239 240
    layout->setMargin( 0 );
    layout->setSpacing( 1 );
241

242 243
    setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::Preferred);
    setMinimumWidth( ICON_HEIGHT * 6 + 10 );
244 245 246 247 248 249
    setLayout( layout );
}

void SPrefsCatList::switchPanel( int i )
{
    emit currentItemChanged( i );
250 251 252 253 254 255
}

/*********************************************************************
 * The Panels
 *********************************************************************/
SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
256
                          int _number ) : QWidget( _parent ), p_intf( _p_intf )
257
{
Antoine Cellerier's avatar
Antoine Cellerier committed
258 259
    module_config_t *p_config;
    ConfigControl *control;
260
    number = _number;
261
    lang = NULL;
262
    radioGroup = NULL;
Antoine Cellerier's avatar
Antoine Cellerier committed
263 264

#define CONFIG_GENERIC( option, type, label, qcontrol )                   \
265
            p_config =  config_FindConfig( option );                      \
Antoine Cellerier's avatar
Antoine Cellerier committed
266 267 268 269 270
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, ui.qcontrol, false );         \
                controls.append( control );                               \
271 272 273 274
            }                                                             \
            else {                                                        \
                ui.qcontrol->setEnabled( false );                         \
                if( label ) label->setEnabled( false );                   \
Antoine Cellerier's avatar
Antoine Cellerier committed
275 276
            }

277
#define CONFIG_BOOL( option, qcontrol )                           \
278
            p_config =  config_FindConfig( option );                      \
279 280 281
            if( p_config )                                                \
            {                                                             \
                control =  new BoolConfigControl( VLC_OBJECT(p_intf),     \
282
                           p_config, NULL, ui.qcontrol );          \
283 284 285 286 287 288
                controls.append( control );                               \
            }                                                             \
            else { ui.qcontrol->setEnabled( false ); }


#define CONFIG_GENERIC_NO_UI( option, type, label, qcontrol )             \
289
            p_config =  config_FindConfig( option );                      \
290 291 292
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
293
                           p_config, label, qcontrol, false );            \
294
                controls.append( control );                               \
295 296
            }                                                             \
            else {                                                        \
Jakob Leben's avatar
Jakob Leben committed
297
                QWidget *widget = label;                                  \
298
                qcontrol->setVisible( false );                            \
Jakob Leben's avatar
Jakob Leben committed
299
                if( widget ) widget->setEnabled( false );                 \
300 301 302
            }


303
#define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
304
            p_config =  config_FindConfig( option );                      \
305 306 307 308 309 310 311
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, ui.qcontrol );                \
                controls.append( control );                               \
            }

312
#define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )     \
313
            p_config =  config_FindConfig( option );                      \
314 315 316 317 318 319
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, qcontrol, qbutton );          \
                controls.append( control );                               \
            }
320

321 322 323
#define START_SPREFS_CAT( name , label )    \
        case SPrefs ## name:                \
        {                                   \
324
            Ui::SPrefs ## name ui;      \
325
            ui.setupUi( panel );            \
Christophe Mutricy's avatar
Christophe Mutricy committed
326
            panel_label->setText( label );
327

Antoine Cellerier's avatar
Antoine Cellerier committed
328 329
#define END_SPREFS_CAT      \
            break;          \
330
        }
331

332 333
    QVBoxLayout *panel_layout = new QVBoxLayout();
    QWidget *panel = new QWidget();
334
    panel_layout->setMargin( 3 );
335 336 337

    // Title Label
    QLabel *panel_label = new QLabel;
338
    QFont labelFont = QApplication::font();
339
    labelFont.setPointSize( labelFont.pointSize() + 6 );
340 341 342 343 344 345
    panel_label->setFont( labelFont );

    // Title <hr>
    QFrame *title_line = new QFrame;
    title_line->setFrameShape(QFrame::HLine);
    title_line->setFrameShadow(QFrame::Sunken);
346

347
    QFont italicFont = QApplication::font();
348 349
    italicFont.setItalic( true );

Antoine Cellerier's avatar
Antoine Cellerier committed
350 351
    switch( number )
    {
352 353 354
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
355
        START_SPREFS_CAT( Video , qtr("Video Settings") );
356
            CONFIG_BOOL( "video", enableVideo );
357 358 359
            ui.videoZone->setEnabled( ui.enableVideo->isChecked() );
            CONNECT( ui.enableVideo, toggled( bool ),
                     ui.videoZone, setEnabled( bool ) );
360

361 362
            CONFIG_BOOL( "fullscreen", fullscreen );
            CONFIG_BOOL( "video-deco", windowDecorations );
363
            CONFIG_GENERIC( "vout", StringList, ui.voutLabel, outputModule );
364

365 366 367 368
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateVideoOptions( int ) );
            optionWidgets["videoOutCoB"] = ui.outputModule;

369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
            optionWidgets["fullscreenScreenB"] = ui.fullscreenScreenBox;
            ui.fullscreenScreenBox->addItem( qtr("Automatic"), -1 );
            int i_screenCount = 0;
            foreach( QScreen* screen, QGuiApplication::screens() )
            {
                ui.fullscreenScreenBox->addItem( screen->name(), i_screenCount );
                i_screenCount++;
            }
            p_config =  config_FindConfig( "qt-fullscreen-screennumber" );
            if( p_config )
            {
                int i_defaultScreen = p_config->value.i + 1;
                if ( i_defaultScreen < 0 || i_defaultScreen > ( ui.fullscreenScreenBox->count() - 1 ) )
                    ui.fullscreenScreenBox->setCurrentIndex( 0 );
                else
                    ui.fullscreenScreenBox->setCurrentIndex(p_config->value.i + 1);
            }

387
#ifdef _WIN32
388
            CONFIG_BOOL( "directx-overlay", overlay );
389
            CONFIG_BOOL( "directx-hw-yuv", hwYUVBox );
390
            CONNECT( ui.overlay, toggled( bool ), ui.hwYUVBox, setEnabled( bool ) );
391
            optionWidgets["directxVideoB"] = ui.directXBox;
392 393
#else
            ui.directXBox->setVisible( false );
394 395
#endif

KO Myung-Hun's avatar
KO Myung-Hun committed
396 397 398 399 400 401 402
#ifdef __OS2__
            CONFIG_BOOL( "kva-fixt23", kvaFixT23 );
            CONFIG_GENERIC( "kva-video-mode", StringList, ui.kvaVideoModeLabel,
                            kvaVideoMode );
#else
            ui.kvaBox->setVisible( false );
#endif
403

404 405
            CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
            CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
406
            CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
407

408
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
409
                                 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
410
            CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
411
            CONFIG_BOOL( "snapshot-sequential",
412
                            snapshotsSequentialNumbering );
413
            CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
414
                            snapshotsFormat );
415 416

            updateVideoOptions( ui.outputModule->currentIndex() );
417
         END_SPREFS_CAT;
418

419 420 421
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
422
        START_SPREFS_CAT( Audio, qtr("Audio Settings") );
423

424
            CONFIG_BOOL( "audio", enableAudio );
425
            ui.audioZone->setEnabled( ui.enableAudio->isChecked() );
426
            CONNECT( ui.enableAudio, toggled( bool ),
427
                     ui.audioZone, setEnabled( bool ) );
428

429
#define audioCommon( name ) \
430
            QLabel * name ## Label = new QLabel( qtr( "Device:" ) ); \
431
            name ## Label->setMinimumSize(QSize(250, 0)); \
432
            outputAudioLayout->addWidget( name ## Label, outputAudioLayout->rowCount(), 0, 1, 1 ); \
433 434 435

#define audioControl( name) \
            audioCommon( name ) \
436
            QComboBox * name ## Device = new QComboBox; \
437
            name ## Label->setBuddy( name ## Device ); \
438
            name ## Device->setSizePolicy( QSizePolicy::Ignored, QSizePolicy::Preferred  );\
439
            outputAudioLayout->addWidget( name ## Device, outputAudioLayout->rowCount() - 1, 1, 1, -1 );
440 441 442

#define audioControl2( name) \
            audioCommon( name ) \
443
            QHBoxLayout * name ## hboxLayout = new QHBoxLayout; \
444
            QLineEdit * name ## Device = new QLineEdit; \
445
            name ## Label->setBuddy( name ## Device ); \
446
            name ## hboxLayout->addWidget( name ## Device ); \
447
            QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ) ); \
448 449
            name ## hboxLayout->addWidget( name ## Browse ); \
            outputAudioLayout->addLayout( name ## hboxLayout, outputAudioLayout->rowCount() - 1, 1, 1, 1, Qt::AlignLeft );
450 451

            /* Build if necessary */
452
            QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
453
#ifdef _WIN32
454
            audioControl( DirectX );
455 456
            optionWidgets["directxL" ] = DirectXLabel;
            optionWidgets["directxW" ] = DirectXDevice;
457
            CONFIG_GENERIC_NO_UI( "directx-audio-device", StringList,
458
                    DirectXLabel, DirectXDevice );
459 460 461 462 463 464 465

            audioControl( Waveout );
            optionWidgets["waveoutL" ] = WaveoutLabel;
            optionWidgets["waveoutW" ] = WaveoutDevice;
            CONFIG_GENERIC_NO_UI( "waveout-audio-device", StringList,
                    WaveoutLabel, WaveoutDevice );

KO Myung-Hun's avatar
KO Myung-Hun committed
466 467
#elif defined( __OS2__ )
            audioControl( kai );
468 469
            optionWidgets["kaiL"] = kaiLabel;
            optionWidgets["kaiW"] = kaiDevice;
KO Myung-Hun's avatar
KO Myung-Hun committed
470 471
            CONFIG_GENERIC_NO_UI( "kai-audio-device", StringList, kaiLabel,
                    kaiDevice );
472
#else
473
            if( module_exists( "alsa" ) )
474 475
            {
                audioControl( alsa );
476 477
                optionWidgets["alsaL"] = alsaLabel;
                optionWidgets["alsaW"] = alsaDevice;
478
                CONFIG_GENERIC_NO_UI( "alsa-audio-device" , StringList, alsaLabel,
479 480
                                alsaDevice );
            }
481
            if( module_exists( "oss" ) )
482 483
            {
                audioControl2( OSS );
484 485 486
                optionWidgets["ossL"] = OSSLabel;
                optionWidgets["ossW"] = OSSDevice;
                optionWidgets["ossB"] = OSSBrowse;
487
                CONFIG_GENERIC_FILE( "oss-audio-device" , File, OSSLabel, OSSDevice,
488 489
                                 OSSBrowse );
            }
490 491
#endif

492
#ifdef _WIN32
493 494 495 496 497 498
            audioControl( MMDevice );
            optionWidgets["mmdeviceL" ] = MMDeviceLabel;
            optionWidgets["mmdeviceW" ] = MMDeviceDevice;
            CONFIG_GENERIC_NO_UI( "mmdevice-audio-device", StringList,
                                  MMDeviceLabel, MMDeviceDevice );

499 500 501 502 503 504 505 506 507 508
            CONFIG_GENERIC( "mmdevice-passthrough", IntegerList,
                            ui.mmdevicePassthroughLabel, mmdevicePassthroughBox );
            optionWidgets["mmdevicePassthroughL"] = ui.mmdevicePassthroughLabel;
            optionWidgets["mmdevicePassthroughB"] = ui.mmdevicePassthroughBox;
#else
            ui.mmdevicePassthroughLabel->setVisible( false );
            ui.mmdevicePassthroughBox->setVisible( false );
#endif


Rémi Duraffort's avatar
Rémi Duraffort committed
509 510 511 512
#undef audioControl2
#undef audioControl
#undef audioCommon

513 514
            int i_max_volume = config_GetInt( p_intf, "qt-max-volume" );

515
            /* Audio Options */
516 517 518
            ui.volumeValue->setMaximum( i_max_volume );
            ui.defaultVolume->setMaximum( i_max_volume );

519
            CONNECT( ui.defaultVolume, valueChanged( int ),
520 521
                     this, updateAudioVolume( int ) );

522 523
            ui.defaultVolume_zone->setEnabled( ui.resetVolumeCheckbox->isChecked() );
            CONNECT( ui.resetVolumeCheckbox, toggled( bool ),
524
                     ui.defaultVolume_zone, setEnabled( bool ) );
525

526
            CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
527
                            preferredAudioLanguage );
528

529
            CONFIG_BOOL( "spdif", spdifBox );
530

531
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
532
                                    volNormSpin );
533 534
            CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
                            replayCombo );
535
            CONFIG_GENERIC( "audio-visual" , StringList, ui.visuLabel,
536
                            visualisation);
537
            CONFIG_BOOL( "audio-time-stretch", autoscaleBox );
538 539

            /* Audio Output Specifics */
540
            CONFIG_GENERIC( "aout", StringList, ui.outputLabel, outputModule );
541

542 543
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateAudioOptions( int ) );
544

545
            /* File output exists on all platforms */
546
            CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
547
                                 ui.fileName, ui.fileBrowseButton );
548

549 550 551
            optionWidgets["fileW"] = ui.fileControl;
            optionWidgets["audioOutCoB"] = ui.outputModule;
            optionWidgets["normalizerChB"] = ui.volNormBox;
552 553
            /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
            ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
554
            optionWidgets["volLW"] = ui.volumeValue;
555
            optionWidgets["spdifChB"] = ui.spdifBox;
556 557
            optionWidgets["defaultVolume"] = ui.defaultVolume;
            optionWidgets["resetVolumeCheckbox"] = ui.resetVolumeCheckbox;
558
            updateAudioOptions( ui.outputModule->currentIndex() );
559

560
            /* LastFM */
561
            if( module_exists( "audioscrobbler" ) )
562 563 564 565 566 567 568
            {
                CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
                        lastfm_user_edit );
                CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
                        lastfm_pass_edit );

                if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
569
                    ui.lastfm->setChecked( true );
570
                else
571
                    ui.lastfm->setChecked( false );
572

573
                ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
574 575

                CONNECT( ui.lastfm, toggled( bool ),
576
                         ui.lastfm_zone, setVisible( bool ) );
577 578
                CONNECT( ui.lastfm, stateChanged( int ),
                         this, lastfm_Changed( int ) );
579
            }
580
            else
581
            {
582
                ui.lastfm->hide();
583 584
                ui.lastfm_zone->hide();
            }
585

586
            /* Normalizer */
587 588
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
589

590
            char* psz = config_GetPsz( p_intf, "audio-filter" );
591
            qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
592
            free( psz );
593

594
            bool b_enabled = ( qs_filter.contains( "normvol" ) );
595 596 597
            ui.volNormBox->setChecked( b_enabled );
            ui.volNormSpin->setEnabled( b_enabled );

598 599 600
            /* Volume Label */
            updateAudioVolume( ui.defaultVolume->value() ); // First time init

Antoine Cellerier's avatar
Antoine Cellerier committed
601
        END_SPREFS_CAT;
602

603
        /* Input and Codecs Panel Implementation */
604
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
605 606

            /* Disk Devices */
607
            {
608
                ui.DVDDeviceComboBox->setToolTip(
609 610 611 612
                    qtr( "If this property is blank, different values\n"
                         "for DVD, VCD, and CDDA are set.\n"
                         "You can define a unique one or configure them \n"
                         "individually in the advanced preferences." ) );
613 614 615
                char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
                char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
                char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
616
                if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
617
                if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
618
                    !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
619
                {
620
                    ui.DVDDeviceComboBox->setEditText( qfu( psz_dvddiscpath ) );
621
                }
622 623 624
                free( psz_cddadiscpath );
                free( psz_dvddiscpath );
                free( psz_vcddiscpath );
625
            }
626
#ifndef _WIN32
627 628 629 630 631 632 633 634 635 636
            QStringList DVDDeviceComboBoxStringList = QStringList();
            DVDDeviceComboBoxStringList
                    << "dvd*" << "scd*" << "sr*" << "sg*" << "cd*";
            ui.DVDDeviceComboBox->addItems( QDir( "/dev/" )
                    .entryList( DVDDeviceComboBoxStringList, QDir::System )
                    .replaceInStrings( QRegExp("^"), "/dev/" )
            );
#endif
            CONFIG_GENERIC( "dvd", String, ui.DVDLabel,
                            DVDDeviceComboBox->lineEdit() );
637 638
            CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
                                 ui.recordPath, ui.recordBrowse );
639

640
            CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
641
            CONFIG_GENERIC_NO_BOOL( "postproc-q", Integer, ui.ppLabel,
642 643
                                    PostProcLevel );
            CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
644 645

            /* live555 module prefs */
646
            CONFIG_BOOL( "rtsp-tcp",
647 648 649 650 651 652 653
                                live555TransportRTSP_TCPRadio );
            if ( !module_exists( "live555" ) )
            {
                ui.live555TransportRTSP_TCPRadio->hide();
                ui.live555TransportHTTPRadio->hide();
                ui.live555TransportLabel->hide();
            }
654
            CONFIG_GENERIC( "avcodec-hw", StringList, ui.hwAccelLabel, hwAccelModule );
655
#ifdef _WIN32
656 657
            HINSTANCE hdxva2_dll = LoadLibrary(TEXT("DXVA2.DLL") );
            if( !hdxva2_dll )
658
                ui.hwAccelModule->setEnabled( false );
659 660
            else
                FreeLibrary( hdxva2_dll );
661
#endif
662
            CONFIG_BOOL( "input-fast-seek", fastSeekBox );
663 664
            optionWidgets["inputLE"] = ui.DVDDeviceComboBox;
            optionWidgets["cachingCoB"] = ui.cachingCombo;
665
            CONFIG_GENERIC( "avcodec-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
666 667
            CONFIG_GENERIC( "sout-x264-tune", StringList, ui.x264Label, tuneBox );
            CONFIG_GENERIC( "sout-x264-preset", StringList, ui.x264Label, presetBox );
668 669
            CONFIG_GENERIC( "sout-x264-profile", StringList, ui.x264profileLabel, profileBox );
            CONFIG_GENERIC( "sout-x264-level", String, ui.x264profileLabel, levelBox );
670
            CONFIG_BOOL( "mkv-preload-local-dir", mkvPreloadBox );
671

672 673 674
            /* Caching */
            /* Add the things to the ComboBox */
            #define addToCachingBox( str, cachingNumber ) \
675 676 677 678 679 680 681
                ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
            addToCachingBox( N_("Custom"), CachingCustom );
            addToCachingBox( N_("Lowest latency"), CachingLowest );
            addToCachingBox( N_("Low latency"), CachingLow );
            addToCachingBox( N_("Normal"), CachingNormal );
            addToCachingBox( N_("High latency"), CachingHigh );
            addToCachingBox( N_("Higher latency"), CachingHigher );
Rémi Duraffort's avatar
Rémi Duraffort committed
682
            #undef addToCachingBox
683

684
#define TestCaC( name, factor ) \
685
    b_cache_equal =  b_cache_equal && \
686
     ( i_cache * factor == config_GetInt( p_intf, name ) );
687 688
            /* Select the accurate value of the ComboBox */
            bool b_cache_equal = true;
689
            int i_cache = config_GetInt( p_intf, "file-caching" );
690

691 692 693
            TestCaC( "network-caching", 10/3 );
            TestCaC( "disc-caching", 1);
            TestCaC( "live-caching", 1 );
694 695
            if( b_cache_equal == 1 )
                ui.cachingCombo->setCurrentIndex(
696
                ui.cachingCombo->findData( QVariant( i_cache ) ) );
Rémi Duraffort's avatar
Rémi Duraffort committed
697
#undef TestCaC
698 699

        END_SPREFS_CAT;
700 701 702
        /*******************
         * Interface Panel *
         *******************/
703
        START_SPREFS_CAT( Interface, qtr("Interface Settings") );
704 705 706 707

#ifndef _WIN32
            ui.langBox->hide();
#else
708 709
            for( int i = 0; i < ARRAY_SIZE( language_map ); i++)
                ui.langCombo->addItem( qfu( language_map[i].name ), language_map[i].iso );
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726
            CONNECT( ui.langCombo, currentIndexChanged( int ), this, langChanged( int ) );

            HKEY h_key;
            char *langReg = NULL;
            if( RegOpenKeyEx( HKEY_CURRENT_USER, TEXT("Software\\VideoLAN\\VLC\\"), 0, KEY_READ, &h_key )
                    == ERROR_SUCCESS )
            {
                TCHAR szData[256];
                DWORD len = 256;
                if( RegQueryValueEx( h_key, TEXT("Lang"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) {
                    langReg = FromWide( szData );
                    ui.langCombo->setCurrentIndex( ui.langCombo->findData(langReg) );
                }
            }
            free( langReg);
#endif

727
//            ui.defaultLabel->setFont( italicFont );
728 729
            ui.skinsLabel->setText(
                    qtr( "This is VLC's skinnable interface. You can download other skins at" )
Christophe Mutricy's avatar
Christophe Mutricy committed
730 731
                    + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">" )
                    + qtr( "VLC skins website" )+ QString( "</a>." ) );
732 733
            ui.skinsLabel->setFont( italicFont );

734
#ifdef _WIN32
735
            BUTTONACT( ui.assoButton, assoDialog() );
736
#else
737
            ui.osGroupBox->hide();
738
#endif
739

740
            /* interface */
741 742
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
743
            {
744 745
                if( strstr( psz_intf, "skin" ) )
                    ui.skins->setChecked( true );
746 747
            } else {
                /* defaults to qt */
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
748
                ui.qt->setChecked( true );
749
            }
750
            free( psz_intf );
751

752 753
            optionWidgets["skinRB"] = ui.skins;
            optionWidgets["qtRB"] = ui.qt;
754
#if !defined( _WIN32)
755
            ui.stylesCombo->addItem( qtr("System's default") );
756 757 758 759
            ui.stylesCombo->addItems( QStyleFactory::keys() );
            ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
                        getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
            ui.stylesCombo->insertSeparator( 1 );
760 761
            if ( ui.stylesCombo->currentIndex() < 0 )
                ui.stylesCombo->setCurrentIndex( 0 ); /* default */
762 763

            CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
764
            optionWidgets["styleCB"] = ui.stylesCombo;
765
#else
Pierre Ynard's avatar
Pierre Ynard committed
766
            ui.stylesCombo->hide();
767
            ui.stylesLabel->hide();
768
#endif
769
            radioGroup = new QButtonGroup(this);
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
770
            radioGroup->addButton( ui.qt, 0 );
771 772 773 774
            radioGroup->addButton( ui.skins, 1 );
            CONNECT( radioGroup, buttonClicked( int ),
                     ui.styleStackedWidget, setCurrentIndex( int ) );
            ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
775

776 777 778 779 780
            CONNECT( ui.minimalviewBox, toggled( bool ),
                     ui.mainPreview, setNormalPreview( bool ) );
            CONFIG_BOOL( "qt-minimal-view", minimalviewBox );
            ui.mainPreview->setNormalPreview( ui.minimalviewBox->isChecked() );
            ui.skinsPreview->setPreview( InterfacePreviewWidget::SKINS );
781

782
            CONFIG_BOOL( "embedded-video", embedVideo );
783 784 785 786
            CONFIG_BOOL( "qt-video-autoresize", resizingBox );
            CONNECT( ui.embedVideo, toggled( bool ), ui.resizingBox, setEnabled( bool ) );
            ui.resizingBox->setEnabled( ui.embedVideo->isChecked() );

787 788
            CONFIG_BOOL( "qt-fs-controller", fsController );
            CONFIG_BOOL( "qt-system-tray", systrayBox );
789 790 791
            CONFIG_GENERIC( "qt-notification", IntegerList, ui.notificationComboLabel,
                                                      notificationCombo );
            CONNECT( ui.systrayBox, toggled( bool ), ui.notificationCombo, setEnabled( bool ) );
792
            CONNECT( ui.systrayBox, toggled( bool ), ui.notificationComboLabel, setEnabled( bool ) );
793
            ui.notificationCombo->setEnabled( ui.systrayBox->isChecked() );
794

795
            CONFIG_BOOL( "qt-pause-minimized", pauseMinimizedBox );
796
            CONFIG_BOOL( "playlist-tree", treePlaylist );
797
            CONFIG_BOOL( "play-and-pause", playPauseBox );
798 799
            CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
                                 ui.fileSkin, ui.skinBrowse );
800

801
            CONFIG_BOOL( "metadata-network-access", MetadataNetworkAccessMode );
802 803

            /* UPDATE options */
804
#ifdef UPDATE_CHECK
805
            CONFIG_BOOL( "qt-updates-notif", updatesBox );
806 807
            CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
                    updatesDays );
808
            ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
809
            CONNECT( ui.updatesBox, toggled( bool ),
810
                     ui.updatesDays, setEnabled( bool ) );
811
#else
812 813
            ui.updatesBox->hide();
            ui.updatesDays->hide();
814
#endif
815
            /* ONE INSTANCE options */
816
#if !defined( _WIN32 ) && !defined(__APPLE__) && !defined(__OS2__)
817 818 819
            if( !module_exists( "dbus" ) )
                ui.OneInterfaceBox->hide();
            else
820
#endif
821 822 823 824 825 826 827
            {
                CONFIG_BOOL( "one-instance", OneInterfaceMode );
                CONFIG_BOOL( "playlist-enqueue", EnqueueOneInterfaceMode );
                ui.EnqueueOneInterfaceMode->setEnabled(
                                                       ui.OneInterfaceMode->isChecked() );
                CONNECT( ui.OneInterfaceMode, toggled( bool ),
                         ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
828
                CONFIG_BOOL( "one-instance-when-started-from-file", oneInstanceFromFile );
829 830
            }

831 832 833 834
            /* RECENTLY PLAYED options */
            CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
                     ui.recentlyPlayedFilters, setEnabled( bool ) );
            ui.recentlyPlayedFilters->setEnabled( false );
835
            CONFIG_BOOL( "qt-recentplay", saveRecentlyPlayed );
836
            CONFIG_GENERIC( "qt-continue", IntegerList, ui.continuePlaybackLabel, continuePlaybackComboBox );
837
            CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
838
                    recentlyPlayedFilters );
839
            CONFIG_GENERIC( "qt-auto-raise", IntegerList, ui.autoRaiseLabel, autoRaiseComboBox );
840

841
        END_SPREFS_CAT;
Antoine Cellerier's avatar
Antoine Cellerier committed
842

843
        START_SPREFS_CAT( Subtitles,
844
                            qtr("Subtitle & On Screen Display Settings") );
845 846
            CONFIG_BOOL( "osd", OSDBox);
            CONFIG_BOOL( "video-title-show", OSDTitleBox);
847 848
            CONFIG_GENERIC( "video-title-position", IntegerList,
                            ui.OSDTitlePosLabel, OSDTitlePos );
Antoine Cellerier's avatar
Antoine Cellerier committed
849

850
            CONFIG_BOOL( "spu", spuActiveBox);
851 852 853
            ui.spuZone->setEnabled( ui.spuActiveBox->isChecked() );
            CONNECT( ui.spuActiveBox, toggled( bool ),
                     ui.spuZone, setEnabled( bool ) );
854

855 856 857 858
            CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
                            encoding );
            CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
                            preferredLanguage );
859 860 861 862

            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
                            ui.fontSizeLabel, fontSize );

863
            CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
864
            CONFIG_GENERIC_NO_BOOL( "freetype-color", Color, ui.fontColorLabel,
865
                            fontColor );
866 867
            CONFIG_GENERIC( "freetype-outline-thickness", IntegerList,
                            ui.fontEffectLabel, effect );
868 869 870
            CONFIG_GENERIC_NO_BOOL( "freetype-outline-color", Color, ui.outlineColorLabel,
                            outlineColor );

871
            CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
Antoine Cellerier's avatar
Antoine Cellerier committed
872

873 874
            ui.shadowCheck->setChecked( config_GetInt( p_intf, "freetype-shadow-opacity" ) > 0 );
            ui.backgroundCheck->setChecked( config_GetInt( p_intf, "freetype-background-opacity" ) > 0 );
875 876
            optionWidgets["shadowCB"] = ui.shadowCheck;
            optionWidgets["backgroundCB"] = ui.backgroundCheck;
877

Antoine Cellerier's avatar
Antoine Cellerier committed
878 879
        END_SPREFS_CAT;

880 881
        case SPrefsHotkeys:
        {
882
            p_config = config_FindConfig( "key-play" );
883 884 885 886 887

            QGridLayout *gLayout = new QGridLayout;
            panel->setLayout( gLayout );
            int line = 0;

888
            panel_label->setText( qtr( "Configure Hotkeys" ) );
889 890
            control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config, this );
            control->insertIntoExistingGrid( gLayout, line );
891
            controls.append( control );
892

893
            line++;
894 895 896 897 898 899 900

            QFrame *sepline = new QFrame;
            sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
            gLayout->addWidget( sepline, line, 0, 1, -1 );

            line++;

901
            p_config = config_FindConfig( "hotkeys-y-wheel-mode" );
902 903 904 905 906 907 908
            control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
                    p_config, this, false );
            control->insertIntoExistingGrid( gLayout, line );
            controls.append( control );

            line++;

909
            p_config = config_FindConfig( "hotkeys-x-wheel-mode" );
910
            control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
911 912
                    p_config, this, false );
            control->insertIntoExistingGrid( gLayout, line );
913
            controls.append( control );
914

915
#ifdef _WIN32
916 917
            line++;

918
            p_config = config_FindConfig( "qt-disable-volume-keys" );
919 920
            control = new BoolConfigControl( VLC_OBJECT(p_intf), p_config, this );
            control->insertIntoExistingGrid( gLayout, line );
921 922 923
            controls.append( control );
#endif

924
            break;
925
        }
926
    }
927

928 929
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
930

931 932 933 934 935
    QScrollArea *scroller= new QScrollArea;
    scroller->setWidget( panel );
    scroller->setWidgetResizable( true );
    scroller->setFrameStyle( QFrame::NoFrame );
    panel_layout->addWidget( scroller );
936

937
    setLayout( panel_layout );
Rémi Duraffort's avatar
Rémi Duraffort committed
938 939 940 941 942

#undef END_SPREFS_CAT
#undef START_SPREFS_CAT
#undef CONFIG_GENERIC_FILE
#undef CONFIG_GENERIC_NO_BOOL
943
#undef CONFIG_GENERIC_NO_UI
Rémi Duraffort's avatar
Rémi Duraffort committed
944
#undef CONFIG_GENERIC
945
#undef CONFIG_BOOL
946 947
}

948 949 950 951 952 953 954 955 956 957 958
void SPrefsPanel::updateVideoOptions( int number )
{
    QString value = qobject_cast<QComboBox *>(optionWidgets["videoOutCoB"])
                                            ->itemData( number ).toString();
#ifdef _WIN32
    if( optionWidgets["directxVideoB"] ) {
        optionWidgets["directxVideoB"]->setVisible( ( value == "directdraw" ) );
    }
#endif
}

959

960
void SPrefsPanel::updateAudioOptions( int number)
961
{
962
    QString value = qobject_cast<QComboBox *>(optionWidgets["audioOutCoB"])
963
                                            ->itemData( number ).toString();
964
#ifdef _WIN32
965 966 967 968 969
    /* Since MMDevice is most likely to be used by default, we show MMDevice
     * options by default */
    const bool mmDeviceEnabled = value == "mmdevice" || value == "any";
    optionWidgets["mmdevicePassthroughL"]->setVisible( mmDeviceEnabled );
    optionWidgets["mmdevicePassthroughB"]->setVisible( mmDeviceEnabled );
970 971
    optionWidgets["mmdeviceW"]->setVisible( mmDeviceEnabled );
    optionWidgets["mmdeviceL"]->setVisible( mmDeviceEnabled );
972

973
    optionWidgets["directxW"]->setVisible( ( value == "directsound" ) );
974
    optionWidgets["directxL"]->setVisible( ( value == "directsound" ) );
975 976
    optionWidgets["waveoutW"]->setVisible( ( value == "waveout" ) );
    optionWidgets["waveoutL"]->setVisible( ( value == "waveout" ) );
KO Myung-Hun's avatar
KO Myung-Hun committed
977
#elif defined( __OS2__ )
978
    optionWidgets["kaiL"]->setVisible( ( value == "kai" ) );
979
    optionWidgets["kaiW"]->setVisible( ( value == "kai" ) );
980
#else
981
    /* optionWidgets["ossW] can be NULL */
982
    if( optionWidgets["ossW"] ) {
983
        optionWidgets["ossW"]->setVisible( ( value == "oss" ) );
984 985 986
        optionWidgets["ossL"]->setVisible( ( value == "oss" ) );
        optionWidgets["ossB"]->setVisible( ( value == "oss" ) );
    }
987
    /* optionWidgets["alsaW] can be NULL */
988
    if( optionWidgets["alsaW"] ) {
989
        optionWidgets["alsaW"]->setVisible( ( value == "alsa" ) );
990 991
        optionWidgets["alsaL"]->setVisible( ( value == "alsa" ) );
    }
992
#endif
993
    optionWidgets["fileW"]->setVisible( ( value == "afile" ) );
994 995
    optionWidgets["spdifChB"]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
                                           value == "directsound" || value == "waveout" ) );
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011

    int volume = getDefaultAudioVolume(VLC_OBJECT(p_intf), qtu(value));
    bool save = true;

    if (volume >= 0)
        save = config_GetInt(VLC_OBJECT(p_intf), "volume-save");

    QCheckBox *resetVolumeCheckBox =
        qobject_cast<QCheckBox *>(optionWidgets["resetVolumeCheckbox"]);
    resetVolumeCheckBox->setChecked(!save);
    resetVolumeCheckBox->setEnabled(volume >= 0);

    QSlider *defaultVolume =
        qobject_cast<QSlider *>(optionWidgets["defaultVolume"]);
    defaultVolume->setValue((volume >= 0) ? volume : 100);
    defaultVolume->setEnabled(volume >= 0);
1012 1013
}

1014 1015 1016

SPrefsPanel::~SPrefsPanel()
{
1017
    qDeleteAll( controls ); controls.clear();
Hannes Domani's avatar
Hannes Domani committed
1018
    free( lang );
1019 1020
}

1021 1022
void SPrefsPanel::updateAudioVolume( int volume )
{
1023
    qobject_cast<QSpinBox *>(optionWidgets["volLW"])
1024
        ->setValue( volume );
1025 1026 1027
}


1028
/* Function called from the main Preferences dialog on each SPrefs Panel */
1029
void SPrefsPanel::apply()
1030
{
1031
    /* Generic save for ever panel */
1032
    QList<ConfigControl *>::const_iterator i;
1033
    for( i = controls.begin() ; i != controls.end() ; ++i )
1034
    {
1035
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
1036
        c->doApply();
1037
    }
1038

1039 1040 1041
    switch( number )
    {
    case SPrefsInputAndCodecs:
1042
    {
1043
        /* Device default selection */
1044
        QByteArray devicepath =
1045
            qobject_cast<QComboBox *>(optionWidgets["inputLE"])->currentText().toUtf8();
1046
        if( devicepath.size() > 0 )
1047
        {
1048 1049 1050
            config_PutPsz( p_intf, "dvd", devicepath );
            config_PutPsz( p_intf, "vcd", devicepath );
            config_PutPsz( p_intf, "cd-audio", devicepath );
1051
        }
1052

1053
#define CaC( name, factor ) config_PutInt( p_intf, name, i_comboValue * factor )
1054
        /* Caching */
1055
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets["cachingCoB"]);
1056 1057 1058
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
1059 1060 1061 1062
            CaC( "file-caching", 1 );
            CaC( "network-caching", 10/3 );
            CaC( "disc-caching", 1 );
            CaC( "live-caching", 1 );
1063
        }
1064
        break;
Rémi Duraffort's avatar
Rémi Duraffort committed
1065
#undef CaC
1066 1067
    }

1068
    /* Interfaces */
1069
    case SPrefsInterface:
1070
    {
1071
        if( qobject_cast<QRadioButton *>(optionWidgets["skinRB"])->isChecked() )
1072 1073 1074 1075
            config_PutPsz( p_intf, "intf", "skins2,any" );
        else
        //if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
            config_PutPsz( p_intf, "intf", "" );
1076
        if( qobject_cast<QComboBox *>(optionWidgets["styleCB"]) )
1077
            getSettings()->setValue( "MainWindow/QtStyle",
1078
                qobject_cast<QComboBox *>(optionWidgets["styleCB"])->currentText() );
1079 1080 1081
#ifdef _WIN32
    saveLang();
#endif
1082
        break;
1083
    }
1084

1085 1086 1087 1088 1089 1090 1091
    case SPrefsVideo:
    {
        int i_fullscreenScreen =  qobject_cast<QComboBox *>(optionWidgets["fullscreenScreenB"])->currentData().toInt();
        config_PutInt( p_intf, "qt-fullscreen-screennumber", i_fullscreenScreen );
        break;
    }

1092
    case SPrefsAudio:
1093
    {
1094
        bool b_checked =