simple_preferences.cpp 40.7 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * simple_preferences.cpp : "Simple preferences"
 ****************************************************************************
4
 * Copyright (C) 2006-2008 the VideoLAN team
Pierre's avatar
Pierre committed
5
 * $Id$
zorglub's avatar
zorglub committed
6
7
8
 *
 * Authors: Clément Stenac <zorglub@videolan.org>
 *          Antoine Cellerier <dionoea@videolan.org>
9
 *          Jean-Baptiste Kempf <jb@videolan.org>
10
 *
zorglub's avatar
zorglub committed
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
zorglub's avatar
zorglub committed
29
30
31

#include "components/simple_preferences.hpp"
#include "components/preferences_widgets.hpp"
zorglub's avatar
zorglub committed
32

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
33
#include <vlc_config_cat.h>
34
#include <vlc_configuration.h>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
35
36
37
38
39
40

#include <QString>
#include <QFont>
#include <QToolButton>
#include <QButtonGroup>
#include <QVBoxLayout>
41
#include <QScrollArea>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
42

43
44
#include <QStyleFactory>
#include <QSettings>
45
46
#include <QtAlgorithms>

47
#define ICON_HEIGHT 64
48

49
#ifdef WIN32
50
# include <vlc_windows_interfaces.h>
51
52
#endif

zorglub's avatar
zorglub committed
53
54
55
/*********************************************************************
 * The List of categories
 *********************************************************************/
56
SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
57
                                  QWidget( _parent ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
58
{
59
60
61
62
63
64
65
    QVBoxLayout *layout = new QVBoxLayout();

    QButtonGroup *buttonGroup = new QButtonGroup( this );
    buttonGroup->setExclusive ( true );
    CONNECT( buttonGroup, buttonClicked ( int ),
            this, switchPanel( int ) );

66
67
    short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;

68
69
#define ADD_CATEGORY( button, label, icon, numb )                           \
    QToolButton * button = new QToolButton( this );                         \
70
    button->setIcon( QIcon( ":/prefsmenu/" #icon ) );                   \
71
72
    button->setText( label );                                               \
    button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
73
74
    button->setIconSize( QSize( icon_height, icon_height ) );               \
    button->resize( icon_height + 6 , icon_height + 6 );                    \
75
76
77
78
79
    button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
    button->setAutoRaise( true );                                           \
    button->setCheckable( true );                                           \
    buttonGroup->addButton( button, numb );                                 \
    layout->addWidget( button );
80

81
    ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
82
83
84
85
86
                  cone_interface_64, 0 );
    ADD_CATEGORY( SPrefsAudio, qtr("Audio"),
                  cone_audio_64, 1 );
    ADD_CATEGORY( SPrefsVideo, qtr("Video"),
                  cone_video_64, 2 );
87
    ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
88
                  cone_subtitles_64, 3 );
89
    ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
90
91
92
                  cone_input_64, 4 );
    ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"),
                  cone_hotkeys_64, 5 );
dionoea's avatar
dionoea committed
93

ivoire's avatar
ivoire committed
94
95
#undef ADD_CATEGORY

96
    SPrefsInterface->setChecked( true );
97
98
    layout->setMargin( 0 );
    layout->setSpacing( 1 );
99

100
    setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
101
    setLayout( layout );
102

103
104
105
106
107
}

void SPrefsCatList::switchPanel( int i )
{
    emit currentItemChanged( i );
zorglub's avatar
zorglub committed
108
109
110
111
112
113
}

/*********************************************************************
 * The Panels
 *********************************************************************/
SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
114
                          int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
115
{
dionoea's avatar
dionoea committed
116
117
    module_config_t *p_config;
    ConfigControl *control;
118
    number = _number;
dionoea's avatar
dionoea committed
119
120
121
122
123
124
125
126
127
128

#define CONFIG_GENERIC( option, type, label, qcontrol )                   \
            p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, ui.qcontrol, false );         \
                controls.append( control );                               \
            }

129
130
131
132
133
134
135
136
137
138
#define CONFIG_GENERIC2( option, type, label, qcontrol )                   \
            p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, qcontrol, false );         \
                controls.append( control );                               \
            }


139
140
141
142
143
144
145
146
147
#define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           \
            p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
            if( p_config )                                                \
            {                                                             \
                control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
                           p_config, label, ui.qcontrol );                \
                controls.append( control );                               \
            }

148
149
150
151
152
#define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         \
                p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  \
                if( p_config )                                                \
                {                                                             \
                    control =  new type ## ConfigControl( VLC_OBJECT(p_intf), \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
153
                               p_config, label, qcontrol, qbutton ); \
154
155
156
                    controls.append( control );                               \
                }

157
158
159
#define START_SPREFS_CAT( name , label )    \
        case SPrefs ## name:                \
        {                                   \
160
            Ui::SPrefs ## name ui;      \
161
            ui.setupUi( panel );            \
Christophe Mutricy's avatar
Christophe Mutricy committed
162
            panel_label->setText( label );
163

dionoea's avatar
dionoea committed
164
165
#define END_SPREFS_CAT      \
            break;          \
166
        }
167

168
169
    QVBoxLayout *panel_layout = new QVBoxLayout();
    QWidget *panel = new QWidget();
170
    panel_layout->setMargin( 3 );
171
172
173
174

    // Title Label
    QLabel *panel_label = new QLabel;
    QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
175
176
    labelFont.setPointSize( labelFont.pointSize() + 6 );
    labelFont.setFamily( "Verdana" );
177
178
179
180
181
182
    panel_label->setFont( labelFont );

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

184
185
186
    QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
    italicFont.setItalic( true );

dionoea's avatar
dionoea committed
187
188
    switch( number )
    {
189
190
191
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
192
        START_SPREFS_CAT( Video , qtr("Video Settings") );
193
            CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
194
195
196
197
198

            CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
            CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
            CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
            CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
199
            CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
200
            CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
201

202
            CONFIG_GENERIC( "video-wallpaper" , Bool , NULL, wallpaperMode );
203
#ifdef WIN32
204
            CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
205
                            dXdisplayDevice );
206
            CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
207
208
#else
            ui.directXBox->setVisible( false );
209
            ui.hwYUVBox->setVisible( false );
210
211
#endif

212
213
            CONFIG_GENERIC( "deinterlace", IntegerList, ui.deinterLabel, deinterlaceBox );
            CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterModeLabel, deinterlaceModeBox );
214
            CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
215

216
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
217
                                 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
218
            CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
219
220
            CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
                            snapshotsSequentialNumbering );
221
            CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
222
                            snapshotsFormat );
223
         END_SPREFS_CAT;
224

225
226
227
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
228
        START_SPREFS_CAT( Audio, qtr("Audio Settings") );
229

230
            CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
231
232
233
            ui.SPrefsAudio_zone->setEnabled( ui.enableAudio->isChecked() );
            CONNECT( ui.enableAudio, toggled( bool ),
                     ui.SPrefsAudio_zone, setEnabled( bool ) );
234

235
236
237
238
239
240
#define audioCommon( name ) \
            QWidget * name ## Control = new QWidget( ui.outputAudioBox ); \
            QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); \
            name ## Layout->setMargin( 0 ); \
            name ## Layout->setSpacing( 0 ); \
            QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); \
241
            name ## Label->setMinimumSize(QSize(250, 0)); \
242
243
244
245
246
247
248
            name ## Layout->addWidget( name ## Label ); \

#define audioControl( name) \
            audioCommon( name ) \
            QComboBox * name ## Device = new QComboBox( name ## Control ); \
            name ## Layout->addWidget( name ## Device ); \
            name ## Label->setBuddy( name ## Device ); \
249
            outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
250
251
252
253
254
255
256
257

#define audioControl2( name) \
            audioCommon( name ) \
            QLineEdit * name ## Device = new QLineEdit( name ## Control ); \
            name ## Layout->addWidget( name ## Device ); \
            name ## Label->setBuddy( name ## Device ); \
            QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); \
            name ## Layout->addWidget( name ## Browse ); \
258
            outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
259
260

            /* Build if necessary */
261
            QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
262
263
264
#ifdef WIN32
            audioControl( DirectX );
            optionWidgets.append( DirectXControl );
265
            CONFIG_GENERIC2( "directx-audio-device-name", StringList,
266
                    NULL, DirectXDevice );
267
#else
268
            if( module_exists( "alsa" ) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
269
270
271
272
            {
                audioControl( alsa );
                optionWidgets.append( alsaControl );

273
                CONFIG_GENERIC2( "alsa-audio-device" , StringList, NULL,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
274
275
276
277
                                alsaDevice );
            }
            else
                optionWidgets.append( NULL );
278
            if( module_exists( "oss" ) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
279
280
281
            {
                audioControl2( OSS );
                optionWidgets.append( OSSControl );
282
                CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
283
284
285
286
                                 OSSBrowse );
            }
            else
                optionWidgets.append( NULL );
287
288
#endif

ivoire's avatar
ivoire committed
289
290
291
292
#undef audioControl2
#undef audioControl
#undef audioCommon

293
            /* Audio Options */
294
295
            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
                                     defaultVolume );
296
            CONNECT( ui.defaultVolume, valueChanged( int ),
297
298
299
300
301
302
                     this, updateAudioVolume( int ) );

            CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, keepVolumeRadio );
            ui.defaultVolume_zone->setEnabled( ui.resetVolumeRadio->isChecked() );
            CONNECT( ui.resetVolumeRadio, toggled( bool ),
                     ui.defaultVolume_zone, setEnabled( bool ) );
303

304
            CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
305
                            preferredAudioLanguage );
306

307
            CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
308
            CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
309
                            detectionDolby );
310

311
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
312
                                    volNormSpin );
313
314
            CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
                            replayCombo );
315
316
            CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
                            visualisation);
317
318

            /* Audio Output Specifics */
319
            CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
320

321
322
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateAudioOptions( int ) );
323

324
            /* File output exists on all platforms */
325
            CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
326
                                 ui.fileName, ui.fileBrowseButton );
327

328
329
330
            optionWidgets.append( ui.fileControl );
            optionWidgets.append( ui.outputModule );
            optionWidgets.append( ui.volNormBox );
ivoire's avatar
ivoire committed
331
332
            /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
            ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
333
            optionWidgets.append( ui.volumeValue );
334
            optionWidgets.append( ui.headphoneEffect );
335
            optionWidgets.append( ui.spdifBox );
336
            updateAudioOptions( ui.outputModule->currentIndex() );
337

338
            /* LastFM */
339
            if( module_exists( "audioscrobbler" ) )
340
341
342
343
344
345
346
            {
                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" ) )
347
                    ui.lastfm->setChecked( true );
348
                else
349
                    ui.lastfm->setChecked( false );
350

351
                ui.lastfm_zone->setVisible( ui.lastfm->isChecked() );
352
353

                CONNECT( ui.lastfm, toggled( bool ),
354
                         ui.lastfm_zone, setVisible( bool ) );
355
356
                CONNECT( ui.lastfm, stateChanged( int ),
                         this, lastfm_Changed( int ) );
357
            }
358
            else
359
            {
360
                ui.lastfm->hide();
361
362
                ui.lastfm_zone->hide();
            }
363

364
            /* Normalizer */
365
366
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
367

ivoire's avatar
ivoire committed
368
            char* psz = config_GetPsz( p_intf, "audio-filter" );
369
            qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
ivoire's avatar
ivoire committed
370
            free( psz );
371
372
373
374
375
376
377

            bool b_enabled = ( qs_filter.contains( "volnorm" ) );
            ui.volNormBox->setChecked( b_enabled );
            ui.volNormSpin->setEnabled( b_enabled );

            b_enabled = ( qs_filter.contains( "headphone" ) );
            ui.headphoneEffect->setChecked( b_enabled );
378

379
380
381
            /* Volume Label */
            updateAudioVolume( ui.defaultVolume->value() ); // First time init

dionoea's avatar
dionoea committed
382
        END_SPREFS_CAT;
383

384
        /* Input and Codecs Panel Implementation */
385
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
386
387

            /* Disk Devices */
388
            {
389
                ui.DVDDevice->setToolTip(
390
391
392
393
                    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." ) );
394
395
396
                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" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
397
                if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
398
                if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
399
                    !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
400
401
402
                {
                    ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
                }
ivoire's avatar
ivoire committed
403
404
405
                free( psz_cddadiscpath );
                free( psz_dvddiscpath );
                free( psz_vcddiscpath );
406
            }
407
408
            CONFIG_GENERIC_FILE( "dvd", File, ui.DVDLabel,
                                 ui.DVDDevice, ui.DVDBrowse );
409
410
            CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
                                 ui.recordPath, ui.recordBrowse );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
411

412
413
414
415
416
417
            CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
                                    UDPPort );
            CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
            CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
                                    PostProcLevel );
            CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
418
419
420
421
422
423
424
425
426
427

            /* live555 module prefs */
            CONFIG_GENERIC( "rtsp-tcp", Bool, NULL,
                                live555TransportRTSP_TCPRadio );
            if ( !module_exists( "live555" ) )
            {
                ui.live555TransportRTSP_TCPRadio->hide();
                ui.live555TransportHTTPRadio->hide();
                ui.live555TransportLabel->hide();
            }
428
#ifdef WIN32
429
            CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
430
#else
431
            ui.systemCodecBox->hide();
432
#endif
433
            CONFIG_GENERIC( "ffmpeg-hw", Bool, NULL, hwAccelBox );
434
435
            optionWidgets.append( ui.DVDDevice );
            optionWidgets.append( ui.cachingCombo );
436
            CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
437

438
439
440
            /* Caching */
            /* Add the things to the ComboBox */
            #define addToCachingBox( str, cachingNumber ) \
441
442
443
444
445
446
447
                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 );
ivoire's avatar
ivoire committed
448
            #undef addToCachingBox
449
450

#define TestCaC( name ) \
451
452
    b_cache_equal =  b_cache_equal && \
     ( i_cache == config_GetInt( p_intf, name ) )
453
454

#define TestCaCi( name, int ) \
455
    b_cache_equal = b_cache_equal &&  \
456
    ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
457
458
459
460
            /* Select the accurate value of the ComboBox */
            bool b_cache_equal = true;
            int i_cache = config_GetInt( p_intf, "file-caching");

461
            TestCaC( "udp-caching" );
462
            if (module_exists ("dvdread"))
463
                TestCaC( "dvdread-caching" );
464
            if (module_exists ("dvdnav"))
465
466
467
468
                TestCaC( "dvdnav-caching" );
            TestCaC( "tcp-caching" );
            TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
            TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
469
            #ifdef WIN32
470
            TestCaC( "dshow-caching" );
471
            #else
472
            if (module_exists ("v4l"))
473
                TestCaC( "v4l-caching" );
474
            if (module_exists ("access_jack"))
475
                TestCaC( "jack-input-caching" );
476
            if (module_exists ("v4l2"))
477
                TestCaC( "v4l2-caching" );
478
            if (module_exists ("pvr"))
479
                TestCaC( "pvr-caching" );
480
            #endif
481
482
483
            if (module_exists ("livedotcom"))
                TestCaCi( "rtsp-caching", 4 );
            TestCaCi( "ftp-caching", 2 );
484
            TestCaCi( "http-caching", 2 );
485
            if (module_exists ("access_realrtsp"))
486
                TestCaCi( "realrtsp-caching", 10 );
487
488
489
            TestCaCi( "mms-caching", 10 );
            if( b_cache_equal == 1 )
                ui.cachingCombo->setCurrentIndex(
490
                ui.cachingCombo->findData( QVariant( i_cache ) ) );
ivoire's avatar
ivoire committed
491
492
#undef TestCaCi
#undef TestCaC
493
494

        END_SPREFS_CAT;
495
496
497
        /*******************
         * Interface Panel *
         *******************/
498
        START_SPREFS_CAT( Interface, qtr("Interface Settings") );
499
//            ui.defaultLabel->setFont( italicFont );
500
501
502
            ui.skinsLabel->setText(
                    qtr( "This is VLC's skinnable interface. You can download other skins at" )
                    + QString( " <a href=\"http://www.videolan.org/vlc/skins.php\">VLC skins website</a>." ) );
503
504
            ui.skinsLabel->setFont( italicFont );

505
#if defined( WIN32 )
506
            CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
507
            BUTTONACT( ui.assoButton, assoDialog() );
508
#else
509
510
            ui.languageBox->hide();
            ui.assoBox->hide();
511
#endif
512
            /* interface */
513
514
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
515
            {
516
517
                if( strstr( psz_intf, "skin" ) )
                    ui.skins->setChecked( true );
518
519
520
            } else {
                /* defaults to qt */
                ui.qt4->setChecked( true );
521
            }
ivoire's avatar
ivoire committed
522
            free( psz_intf );
523

524
525
            optionWidgets.append( ui.skins );
            optionWidgets.append( ui.qt4 );
526
#if !defined(NDEBUG) || !defined( WIN32)
527
            ui.stylesCombo->addItem( qtr("System's default") );
528
529
530
531
532
533
            ui.stylesCombo->addItems( QStyleFactory::keys() );
            ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
                        getSettings()->value( "MainWindow/QtStyle", "" ).toString() ) );
            ui.stylesCombo->insertSeparator( 1 );

            CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
534
            optionWidgets.append( ui.stylesCombo );
535
#else
Pierre Ynard's avatar
Pierre Ynard committed
536
            ui.stylesCombo->hide();
537
            optionWidgets.append( NULL );
538
#endif
539

540
541
542
543
544
545
546
            ui.skins_zone->setEnabled( ui.skins->isChecked() );
            CONNECT( ui.skins, toggled( bool ), ui.skins_zone, setEnabled( bool ) );

            ui.native_zone->setEnabled( ui.qt4->isChecked() );
            CONNECT( ui.qt4, toggled( bool ), ui.native_zone, setEnabled( bool ) );

            CONNECT( ui.displayModeBox, currentIndexChanged( int ),
547
548
                     ui.mainPreview, setPreview( int ) );
            ui.skinsPreview->setPreview( 3 ); /* skins_preview resource index */
549

550
            CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
551
552
                            displayModeBox );
            CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
553
            CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
554
            CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
555
556
            CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
                                 ui.fileSkin, ui.skinBrowse );
557
            CONFIG_GENERIC( "qt-video-autoresize", Bool, NULL, resizingBox );
558

559
560
            CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
                                                      artFetcher );
561
562

            /* UPDATE options */
563
#ifdef UPDATE_CHECK
564
565
566
            CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
            CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
                    updatesDays );
567
            ui.updatesDays->setEnabled( ui.updatesBox->isChecked() );
568
            CONNECT( ui.updatesBox, toggled( bool ),
569
                     ui.updatesDays, setEnabled( bool ) );
570
#else
Felix Paul Kühne's avatar
Felix Paul Kühne committed
571
            ui.updatesBox->hide();
572
            ui.updatesDays->hide();
573
#endif
574
            /* ONE INSTANCE options */
575
#if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
576
            CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
577
            CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
578
                    EnqueueOneInterfaceMode );
579
580
581
            ui.EnqueueOneInterfaceMode->setEnabled( ui.OneInterfaceMode->isChecked() );
            CONNECT( ui.OneInterfaceMode, toggled( bool ),
                     ui.EnqueueOneInterfaceMode, setEnabled( bool ) );
582
583
#else
            ui.OneInterfaceBox->hide();
584
#endif
Ludovic Fauvet's avatar
Ludovic Fauvet committed
585
586
587
588
589
            /* RECENTLY PLAYED options */
            CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
                     ui.recentlyPlayedFilters, setEnabled( bool ) );
            ui.recentlyPlayedFilters->setEnabled( false );
            CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
590
            CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
Ludovic Fauvet's avatar
Ludovic Fauvet committed
591
592
                    recentlyPlayedFilters );

dionoea's avatar
dionoea committed
593
        END_SPREFS_CAT;
dionoea's avatar
dionoea committed
594

595
596
        START_SPREFS_CAT( Subtitles,
                            qtr("Subtitles & On Screen Display Settings") );
597
            CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
598
599
            CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);

dionoea's avatar
dionoea committed
600

601
602
603
604
            CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
                            encoding );
            CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
                            preferredLanguage );
605
            CONFIG_GENERIC_NO_BOOL( "freetype-font", Font, ui.fontLabel, font );
606
607
608
609
610
611
612
            CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
                            fontColor );
            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
                            ui.fontSizeLabel, fontSize );
            CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
                            effect );
            CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
dionoea's avatar
dionoea committed
613
614
615

        END_SPREFS_CAT;

616
617
618
619
620
621
622
623
        case SPrefsHotkeys:
        {
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );

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

624
            panel_label->setText( qtr( "Configure Hotkeys" ) );
625
            control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
626
                                                this, gLayout, line );
627
            controls.append( control );
628

629
            line++;
630
631
632
633
634
635
636

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

            line++;

637
638
639
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
            control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
                    p_config, false, this, gLayout, line );
640
            controls.append( control );
641
642

            break;
643
        }
644
    }
645

646
647
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
648
649
650
651
652
653
654
655
656
657
658
659
660
661

    if( small )
    {
        QScrollArea *scroller= new QScrollArea;
        scroller->setWidget( panel );
        scroller->setWidgetResizable( true );
        scroller->setFrameStyle( QFrame::NoFrame );
        panel_layout->addWidget( scroller );
    }
    else
    {
        panel_layout->addWidget( panel );
        if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
    }
662

663
    setLayout( panel_layout );
ivoire's avatar
ivoire committed
664
665
666
667
668
669
670

#undef END_SPREFS_CAT
#undef START_SPREFS_CAT
#undef CONFIG_GENERIC_FILE
#undef CONFIG_GENERIC_NO_BOOL
#undef CONFIG_GENERIC2
#undef CONFIG_GENERIC
zorglub's avatar
zorglub committed
671
672
}

673

674
void SPrefsPanel::updateAudioOptions( int number)
675
{
676
677
    QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
                                            ->itemData( number ).toString();
678
#ifdef WIN32
679
    optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
680
#else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
681
682
683
684
685
686
    /* optionWidgets[ossW] can be NULL */
    if( optionWidgets[ossW] )
        optionWidgets[ossW]->setVisible( ( value == "oss" ) );
    /* optionWidgets[alsaW] can be NULL */
    if( optionWidgets[alsaW] )
        optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
687
#endif
688
    optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
689
690
    optionWidgets[spdifChB]->setVisible( ( value == "alsa" || value == "oss" || value == "auhal" ||
                                           value == "aout_directx" || value == "waveout" ) );
691
692
}

693
694
695

SPrefsPanel::~SPrefsPanel()
{
696
    qDeleteAll( controls ); controls.clear();
697
698
}

699
700
701
702
703
704
705
void SPrefsPanel::updateAudioVolume( int volume )
{
    qobject_cast<QSpinBox *>(optionWidgets[volLW])
        ->setValue( volume * 100 / 256 );
}


706
/* Function called from the main Preferences dialog on each SPrefs Panel */
zorglub's avatar
zorglub committed
707
void SPrefsPanel::apply()
zorglub's avatar
zorglub committed
708
{
709
    /* Generic save for ever panel */
zorglub's avatar
zorglub committed
710
711
712
    QList<ConfigControl *>::Iterator i;
    for( i = controls.begin() ; i != controls.end() ; i++ )
    {
zorglub's avatar
zorglub committed
713
714
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
        c->doApply( p_intf );
zorglub's avatar
zorglub committed
715
    }
716

717
718
719
    switch( number )
    {
    case SPrefsInputAndCodecs:
720
    {
721
        /* Device default selection */
722
723
        char *psz_devicepath =
            strdup( qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() ) );
724
725
726
727
728
        if( !EMPTY_STR( psz_devicepath ) )
        {
            config_PutPsz( p_intf, "dvd", psz_devicepath );
            config_PutPsz( p_intf, "vcd", psz_devicepath );
            config_PutPsz( p_intf, "cd-audio", psz_devicepath );
729
            free( psz_devicepath );
730
        }
731

732
733
#define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
#define CaC( name ) CaCi( name, 1 )
734
        /* Caching */
735
736
737
738
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
739
            CaC( "udp-caching" );
740
            if (module_exists ("dvdread" ))
741
                CaC( "dvdread-caching" );
742
            if (module_exists ("dvdnav" ))
743
744
                CaC( "dvdnav-caching" );
            CaC( "tcp-caching" ); CaC( "vcd-caching" );
745
            CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
746
            CaC( "screen-caching" ); CaC( "bd-caching" );
747
748
            CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
            CaCi( "http-caching", 2 );
749
            if (module_exists ("access_realrtsp" ))
750
                CaCi( "realrtsp-caching", 10 );
751
            CaCi( "mms-caching", 10 );
752
753
754
            #ifdef WIN32
            CaC( "dshow-caching" );
            #else
755
            if (module_exists ( "v4l" ))
756
                CaC( "v4l-caching" );
757
            if (module_exists ( "access_jack" ))
758
            CaC( "jack-input-caching" );
759
            if (module_exists ( "v4l2" ))
760
                CaC( "v4l2-caching" );
761
            if (module_exists ( "pvr" ))
762
                CaC( "pvr-caching" );
763
764
765
            #endif
            //CaCi( "dv-caching" ) too short...
        }
766
        break;
ivoire's avatar
ivoire committed
767
768
#undef CaC
#undef CaCi
769
770
    }

771
    /* Interfaces */
772
    case SPrefsInterface:
773
    {
774
        if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
775
            config_PutPsz( p_intf, "intf", "skins2" );
776
        if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
777
            config_PutPsz( p_intf, "intf", "qt" );
778
779
780
        if( qobject_cast<QComboBox *>(optionWidgets[styleCB]) )
            getSettings()->setValue( "MainWindow/QtStyle",
                qobject_cast<QComboBox *>(optionWidgets[styleCB])->currentText() );
781

782
        break;
783
    }
784

785
    case SPrefsAudio:
786
    {
787
        bool b_checked =
788
            qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
789
790
791
792
793
794
795
796
797
798
799
800
801
802
        if( b_checked && !qs_filter.contains( "volnorm" ) )
            qs_filter.append( "volnorm" );
        if( !b_checked && qs_filter.contains( "volnorm" ) )
            qs_filter.removeAll( "volnorm" );

        b_checked =
            qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();

        if( b_checked && !qs_filter.contains( "headphone" ) )
            qs_filter.append( "headphone" );
        if( !b_checked && qs_filter.contains( "headphone" ) )
            qs_filter.removeAll( "headphone" );

        config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
803
804
        break;
    }
805
    }
zorglub's avatar
zorglub committed
806
807
}

zorglub's avatar
zorglub committed
808
void SPrefsPanel::clean()
zorglub's avatar
zorglub committed
809
{}
810

811
812
813
void SPrefsPanel::lastfm_Changed( int i_state )
{
    if( i_state == Qt::Checked )
814
        config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
815
    else if( i_state == Qt::Unchecked )
816
        config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
817
}
818

819
820
821
822
823
824
825
826
827
828
829
830
831
void SPrefsPanel::changeStyle( QString s_style )
{
    QApplication::setStyle( s_style );

    /* force refresh on all widgets */
    QWidgetList widgets = QApplication::allWidgets();
    QWidgetList::iterator it = widgets.begin();
    while( it != widgets.end() ) {
        (*it)->update();
        it++;
    };
}

832
833
#ifdef WIN32
#include <QDialogButtonBox>
834
#include <QHeaderView>
835
#include "util/registry.hpp"
836
#include <string>
837

838
839
bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
                           QTreeWidgetItem* parent, QVLCRegistry *qvReg )
840
{
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
    bool b_temp;
    const char* psz_VLC = "VLC";
    current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );

    if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
    {
        current->setCheckState( 0, Qt::Checked );
        b_temp = false;
    }
    else
    {
        current->setCheckState( 0, Qt::Unchecked );
        b_temp = true;
    }
    listAsso.append( current );
    return b_temp;
}
858

859
860
void SPrefsPanel::assoDialog()
{
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
    OSVERSIONINFO winVer;
    winVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    //Vista specific file associations
    if( GetVersionEx(&winVer) && winVer.dwMajorVersion > 5 )
    {
            LPAPPASSOCREGUI p_appassoc;
            CoInitialize( 0 );

            if( S_OK == CoCreateInstance( &clsid_IApplication2,
                        NULL, CLSCTX_INPROC_SERVER,
                        &IID_IApplicationAssociationRegistrationUI,
                        (void **)&p_appassoc) )
            {
                if(S_OK == p_appassoc->vt->LaunchAdvancedAssociationUI(p_appassoc, L"VLC" ) )
                {
                    CoUninitialize();
                    return;
                }
            }

            CoUninitialize();
    }
883
884
885
    QDialog *d = new QDialog( this );
    QGridLayout *assoLayout = new QGridLayout( d );

886
    QTreeWidget *filetypeList = new QTreeWidget;
887
    assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
    filetypeList->header()->hide();

    QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );

    QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
    QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
    QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );

    filetypeList->addTopLevelItem( audioType );
    filetypeList->addTopLevelItem( videoType );
    filetypeList->addTopLevelItem( otherType );

    audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
    videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
    otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );

    QTreeWidgetItem *currentItem;

    int i_temp = 0;
#define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
#define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
#define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )

    aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
    aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
913
    aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
914
    aTA( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
915
    audioType->setCheckState( 0, ( i_temp > 0 ) ?
916
917
918
919
920
921
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );

    i_temp = 0;
    aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
922
923
    aTv( ".gxf" ); aTv( ".m1v"