simple_preferences.cpp 34.8 KB
Newer Older
zorglub's avatar
zorglub committed
1
2
3
/*****************************************************************************
 * simple_preferences.cpp : "Simple preferences"
 ****************************************************************************
4
 * Copyright (C) 2006-2007 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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
zorglub's avatar
zorglub committed
28
29
30

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

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

#include <QString>
#include <QFont>
#include <QToolButton>
#include <QButtonGroup>
#include <QUrl>
#include <QVBoxLayout>

42
43
#include <string>

44
#define ICON_HEIGHT 64
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
45
#define BUTTON_HEIGHT 74
46

zorglub's avatar
zorglub committed
47
48
49
50
/*********************************************************************
 * The List of categories
 *********************************************************************/
SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
51
                                  QWidget( _parent ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
52
{
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    QVBoxLayout *layout = new QVBoxLayout();

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

#define ADD_CATEGORY( button, label, icon, numb )                           \
    QToolButton * button = new QToolButton( this );                         \
    button->setIcon( QIcon( ":/pixmaps/" #icon ) );                         \
    button->setIconSize( QSize( ICON_HEIGHT , ICON_HEIGHT ) );              \
    button->setText( label );                                               \
    button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              \
    button->resize( BUTTON_HEIGHT , BUTTON_HEIGHT);                         \
    button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  \
    button->setAutoRaise( true );                                           \
    button->setCheckable( true );                                           \
    buttonGroup->addButton( button, numb );                                 \
    layout->addWidget( button );
72

73
    ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
74
75
76
                  spref_cone_Interface_64.png, 0 );
    ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
    ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
77
    ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles & OSD"),
78
                  spref_cone_Subtitles_64.png, 3 );
79
    ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
80
81
                  spref_cone_Input_64.png, 4 );
    ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
dionoea's avatar
dionoea committed
82

83
    SPrefsInterface->setChecked( true );
84
85
    layout->setMargin( 0 );
    layout->setSpacing( 1 );
86

87
    setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
88
    setLayout( layout );
89

90
91
92
93
94
}

void SPrefsCatList::switchPanel( int i )
{
    emit currentItemChanged( i );
zorglub's avatar
zorglub committed
95
96
97
98
99
100
}

/*********************************************************************
 * The Panels
 *********************************************************************/
SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
101
                          int _number ) : QWidget( _parent ), p_intf( _p_intf )
zorglub's avatar
zorglub committed
102
{
dionoea's avatar
dionoea committed
103
104
    module_config_t *p_config;
    ConfigControl *control;
105
    number = _number;
dionoea's avatar
dionoea committed
106
107
108
109
110
111
112
113
114
115

#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 );                               \
            }

116
117
118
119
120
121
122
123
124
125
#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 );                               \
            }


126
127
128
129
130
131
132
133
134
#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 );                               \
            }

135
136
137
138
139
#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), \
140
                               p_config, label, qcontrol, qbutton,      \
141
142
143
144
                            false );                                          \
                    controls.append( control );                               \
                }

145
146
147
#define START_SPREFS_CAT( name , label )    \
        case SPrefs ## name:                \
        {                                   \
148
            Ui::SPrefs ## name ui;      \
149
            ui.setupUi( panel );            \
Christophe Mutricy's avatar
Christophe Mutricy committed
150
            panel_label->setText( label );
151

dionoea's avatar
dionoea committed
152
153
#define END_SPREFS_CAT      \
            break;          \
154
        }
155

156
157
    QVBoxLayout *panel_layout = new QVBoxLayout();
    QWidget *panel = new QWidget();
158
    panel_layout->setMargin( 3 );
159
160
161
162

    // Title Label
    QLabel *panel_label = new QLabel;
    QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
163
164
    labelFont.setPointSize( labelFont.pointSize() + 6 );
    labelFont.setFamily( "Verdana" );
165
166
167
168
169
170
    panel_label->setFont( labelFont );

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

172
173
174
    QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
    italicFont.setItalic( true );

dionoea's avatar
dionoea committed
175
176
    switch( number )
    {
177
178
179
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
180
        START_SPREFS_CAT( Video , qtr("General video settings") );
181
            CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
182
183
184
185
186

            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 );
187
            CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
188
189
            CONFIG_GENERIC( "vout", Module, NULL, outputModule );

190
191
#ifdef WIN32
            CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
192
            CONFIG_GENERIC( "directx-device", StringList, NULL,
193
                            dXdisplayDevice );
194
195
#else
            ui.directXBox->setVisible( false );
196
197
#endif

198
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
199
                                 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
200
201
202
203
204
            CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
            CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
                            snapshotsSequentialNumbering );
            CONFIG_GENERIC( "snapshot-format", StringList, NULL,
                            snapshotsFormat );
205
         END_SPREFS_CAT;
206

207
208
209
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
210
        START_SPREFS_CAT( Audio, qtr("General audio settings") );
211

212
213
            CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );

214
215
216
217
218
219
220
221
222
223
224
225
226
227
#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 ); \
            name ## Label->setMinimumSize(QSize(100, 0)); \
            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 ); \
228
            outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
229
230
231
232
233
234
235
236

#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 ); \
237
            outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
238

239
            /* hide if necessary */
240
241
242
243
244
            ui.lastfm_user_edit->hide();
            ui.lastfm_user_label->hide();
            ui.lastfm_pass_edit->hide();
            ui.lastfm_pass_label->hide();

245
            /* Build if necessary */
246
            QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
247
248
249
#ifdef WIN32
            audioControl( DirectX );
            optionWidgets.append( DirectXControl );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
250
251
            CONFIG_GENERIC2( "directx-audio-device", IntegerList,
                    DirectXLabel, DirectXDevice );
252
#else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
            if( module_Exists( p_intf, "alsa" ) )
            {
                audioControl( alsa );
                optionWidgets.append( alsaControl );

                CONFIG_GENERIC2( "alsadev" , StringList , alsaLabel,
                                alsaDevice );
            }
            else
                optionWidgets.append( NULL );
            if( module_Exists( p_intf, "oss" ) )
            {
                audioControl2( OSS );
                optionWidgets.append( OSSControl );
                CONFIG_GENERIC_FILE( "dspdev" , File , OSSLabel, OSSDevice,
                                 OSSBrowse );
            }
            else
                optionWidgets.append( NULL );
272
273
#endif

274
            /* General Audio Options */
275
276
            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
                                     defaultVolume );
277
278
279
            CONNECT( ui.defaultVolume, valueChanged( int ),
                    this, updateAudioVolume( int ) );

280
281
            CONFIG_GENERIC( "audio-language" , String , NULL,
                            preferredAudioLanguage );
282

283
            CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
284
            CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
285
286
            CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
                            detectionDolby );
287

288
            CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
289

290
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
291
                                    volNormSpin );
292
293
294
            CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);

            /* Audio Output Specifics */
295
            CONFIG_GENERIC( "aout", Module, NULL, outputModule );
296

297
298
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateAudioOptions( int ) );
299

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
300
       // File exists everywhere
301
            CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
302
                                 ui.fileName, ui.fileBrowseButton );
303

304
305
306
            optionWidgets.append( ui.fileControl );
            optionWidgets.append( ui.outputModule );
            optionWidgets.append( ui.volNormBox );
ivoire's avatar
ivoire committed
307
            /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
ivoire's avatar
ivoire committed
308
#if HAS_QT43
ivoire's avatar
ivoire committed
309
310
            ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
#endif
311
            optionWidgets.append( ui.volumeValue );
312
            updateAudioOptions( ui.outputModule->currentIndex() );
313

314
            /* LastFM */
315
            if( module_Exists( p_intf, "audioscrobbler" ) )
316
317
318
319
320
321
322
            {
                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" ) )
323
                    ui.lastfm->setChecked( true );
324
                else
325
                    ui.lastfm->setChecked( false );
326
327
328
                CONNECT( ui.lastfm, stateChanged( int ), this ,
                        lastfm_Changed( int ) );
            }
329
330
            else
                ui.lastfm->hide();
331

332
            /* Normalizer */
333

334
335
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
336
337
338
339
340
341
342
            qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
            bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
            {
                ui.volNormBox->setChecked( b_normalizer );
                ui.volNormSpin->setEnabled( b_normalizer );
            }

343
344
345
            /* Volume Label */
            updateAudioVolume( ui.defaultVolume->value() ); // First time init

dionoea's avatar
dionoea committed
346
        END_SPREFS_CAT;
347

348
        /* Input and Codecs Panel Implementation */
Christophe Mutricy's avatar
Christophe Mutricy committed
349
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
350
351

            /* Disk Devices */
352
            {
353
                ui.DVDDevice->setToolTip(
354
                    //TODO: make this sentence understandable
Christophe Mutricy's avatar
Typo    
Christophe Mutricy committed
355
                    qtr( "If this property is blank, then you have\n"
356
357
358
                         "values for DVD, VCD, and CDDA.\n"
                         "You can define a unique one or set that in"
                         "the advanced preferences" ) );
359
360
361
                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
362
                if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
363
                if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
364
                    !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
365
366
367
                {
                    ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
                }
368
369
                delete psz_cddadiscpath; delete psz_dvddiscpath;
                delete psz_vcddiscpath;
370
            }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
371

372
373
374
375
376
            CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
            CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
            CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
            CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
            CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
377
#ifdef WIN32
378
            CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
379
#else
380
            ui.systemCodecBox->hide();
381
#endif
382
383
384
385
386
387
            /* Access Filters */
            qs_filter = qfu( config_GetPsz( p_intf, "access-filter" ) );
            ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
            ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
            ui.recordBox->setChecked( qs_filter.contains( "record" ) );
            ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
388

389
390
391
392
393
394
            optionWidgets.append( ui.recordBox );
            optionWidgets.append( ui.dumpBox );
            optionWidgets.append( ui.bandwidthBox );
            optionWidgets.append( ui.timeshiftBox );
            optionWidgets.append( ui.DVDDevice );
            optionWidgets.append( ui.cachingCombo );
395

396
397
398
399
400
401
402
403
404
405
406
407
            /* Caching */
            /* Add the things to the ComboBox */
            #define addToCachingBox( str, cachingNumber ) \
                ui.cachingCombo->addItem( str, QVariant( cachingNumber ) );
            addToCachingBox( "Custom", CachingCustom );
            addToCachingBox( "Lowest latency", CachingLowest );
            addToCachingBox( "Low latency", CachingLow );
            addToCachingBox( "Normal", CachingNormal );
            addToCachingBox( "High latency", CachingHigh );
            addToCachingBox( "Higher latency", CachingHigher );

#define TestCaC( name ) \
408
409
    b_cache_equal =  b_cache_equal && \
     ( i_cache == config_GetInt( p_intf, name ) )
410
411

#define TestCaCi( name, int ) \
412
    b_cache_equal = b_cache_equal &&  \
413
    ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
414
415
416
417
            /* Select the accurate value of the ComboBox */
            bool b_cache_equal = true;
            int i_cache = config_GetInt( p_intf, "file-caching");

418
419
420
421
422
423
424
425
            TestCaC( "udp-caching" );
            if (module_Exists (p_intf, "dvdread"))
                TestCaC( "dvdread-caching" );
            if (module_Exists (p_intf, "dvdnav"))
                TestCaC( "dvdnav-caching" );
            TestCaC( "tcp-caching" );
            TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
            TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
426
            #ifdef WIN32
427
            TestCaC( "dshow-caching" );
428
            #else
429
430
431
432
433
434
435
436
            if (module_Exists (p_intf, "v4l"))
                TestCaC( "v4l-caching" );
            if (module_Exists (p_intf, "access_jack"))
                TestCaC( "jack-input-caching" );
            if (module_Exists (p_intf, "v4l2"))
                TestCaC( "v4l2-caching" );
            if (module_Exists (p_intf, "pvr"))
                TestCaC( "pvr-caching" );
437
            #endif
438
439
440
441
442
            TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
            TestCaCi( "http-caching", 4 );
            if (module_Exists (p_intf, "access_realrtsp"))
                TestCaCi( "realrtsp-caching", 10 );
            TestCaCi( "mms-caching", 19 );
443
444
            if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
                ui.cachingCombo->findData( QVariant( i_cache ) ) );
445
446

        END_SPREFS_CAT;
447
448
449
        /*******************
         * Interface Panel *
         *******************/
Christophe Mutricy's avatar
Christophe Mutricy committed
450
        START_SPREFS_CAT( Interface, qtr("Interface settings") );
451
452
453
            ui.defaultLabel->setFont( italicFont );
            ui.skinsLabel->setFont( italicFont );

454
#if defined( WIN32 )
455
            CONFIG_GENERIC( "language", StringList, NULL, language );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
456
            BUTTONACT( ui.assoButton, assoDialog() );
457
458
459
#else
            ui.language->hide();
            ui.languageLabel->hide();
460
461
            ui.assoName->hide();
            ui.assoButton->hide();
462
#endif
463

464
            /* interface */
465
466
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
467
            {
468
469
470
471
                if( strstr( psz_intf, "skin" ) )
                    ui.skins->setChecked( true );
                else if( strstr( psz_intf, "qt" ) )
                    ui.qt4->setChecked( true );
472
            }
473
            delete psz_intf;
474

475
476
477
            optionWidgets.append( ui.skins );
            optionWidgets.append( ui.qt4 );

478
479
480
            CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
                            displayModeBox );
            CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
481
482
            CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
                    ui.skinBrowse );
483

484
485
            CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
                                                      artFetcher );
486
            CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
487
488

            /* UPDATE options */
489
#ifdef UPDATE_CHECK
490
491
492
493
494
495
            CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
            CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
                    updatesDays );
            CONNECT( ui.updatesBox, toggled( bool ),
                     ui.updatesDays, setEnabled( bool ) );
#else
Felix Paul Kühne's avatar
Felix Paul Kühne committed
496
            ui.updatesBox->hide();
Felix Paul Kühne's avatar
Felix Paul Kühne committed
497
            ui.updatesDays->hide();
498
#endif
499
            /* ONE INSTANCE options */
500
#if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
501
            CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
502
            CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
503
                    EnqueueOneInterfaceMode );
504
505
#else
            ui.OneInterfaceBox->hide();
506
#endif
dionoea's avatar
dionoea committed
507
        END_SPREFS_CAT;
dionoea's avatar
dionoea committed
508

Christophe Mutricy's avatar
Christophe Mutricy committed
509
        START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
510
            CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
dionoea's avatar
dionoea committed
511
512

            CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
513
            CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
514
515
            CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
                            ui.fontBrowse );
dionoea's avatar
dionoea committed
516
517
518
            CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
                            fontSize );
519
            CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
dionoea's avatar
dionoea committed
520
521
522

        END_SPREFS_CAT;

523
524
525
526
527
528
529
530
        case SPrefsHotkeys:
        {
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );

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

531
            control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
532
533
534
                                                this, gLayout, line );

            panel_label->setText( qtr( "Configure Hotkeys" ) );
535
            controls.append( control );
536
537

            break;
538
        }
539
    }
540

541
542
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
543
    panel_layout->addWidget( panel );
544
    if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
545

546
    setLayout( panel_layout );
zorglub's avatar
zorglub committed
547
548
}

549
void SPrefsPanel::updateAudioOptions( int number)
550
{
551
552
    QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
                                            ->itemData( number ).toString();
553
554
555
#ifdef WIN32
    optionWidgets[directxW]->setVisible( ( value == "directx" ) );
#else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
556
557
558
559
560
561
    /* 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" ) );
562
#endif
563
    optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
564
565
}

566
567
568
569
570
571
572
void SPrefsPanel::updateAudioVolume( int volume )
{
    qobject_cast<QSpinBox *>(optionWidgets[volLW])
        ->setValue( volume * 100 / 256 );
}


573
/* Function called from the main Preferences dialog on each SPrefs Panel */
zorglub's avatar
zorglub committed
574
void SPrefsPanel::apply()
zorglub's avatar
zorglub committed
575
{
576
    /* Generic save for ever panel */
zorglub's avatar
zorglub committed
577
578
579
    QList<ConfigControl *>::Iterator i;
    for( i = controls.begin() ; i != controls.end() ; i++ )
    {
zorglub's avatar
zorglub committed
580
581
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
        c->doApply( p_intf );
zorglub's avatar
zorglub committed
582
    }
583

584
585
586
    switch( number )
    {
    case SPrefsInputAndCodecs:
587
    {
588
        /* Device default selection */
589
        char *psz_devicepath =
590
              qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
591
592
593
594
595
596
        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 );
        }
597

598
        /* Access filters */
599
600
601
602
603
604
605
#define saveBox( name, box ) {\
        if( box->isChecked() ) { \
            if( b_first ) { \
                qs_filter.append( name ); \
                b_first = false; \
            } \
            else qs_filter.append( ":" ).append( name ); \
606
        } }
607

608
609
        bool b_first = true;
        qs_filter.clear();
610
611
612
613
        saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
        saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
        saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
        saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
614
        config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
615

616
617
#define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
#define CaC( name ) CaCi( name, 1 )
618
        /* Caching */
619
620
621
622
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
623
            CaC( "udp-caching" );
624
            if (module_Exists (p_intf, "dvdread" ))
625
                CaC( "dvdread-caching" );
626
            if (module_Exists (p_intf, "dvdnav" ))
627
628
                CaC( "dvdnav-caching" );
            CaC( "tcp-caching" ); CaC( "vcd-caching" );
629
630
631
            CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
            CaC( "screen-caching" );
            CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
632
            CaCi( "http-caching", 4 );
633
            if (module_Exists (p_intf, "access_realrtsp" ))
634
                CaCi( "realrtsp-caching", 10 );
635
636
637
638
            CaCi( "mms-caching", 19 );
            #ifdef WIN32
            CaC( "dshow-caching" );
            #else
639
            if (module_Exists (p_intf, "v4l" ))
640
                CaC( "v4l-caching" );
641
            if (module_Exists (p_intf, "access_jack" ))
642
            CaC( "jack-input-caching" );
643
            if (module_Exists (p_intf, "v4l2" ))
644
                CaC( "v4l2-caching" );
645
            if (module_Exists (p_intf, "pvr" ))
646
                CaC( "pvr-caching" );
647
648
649
            #endif
            //CaCi( "dv-caching" ) too short...
        }
650
        break;
651
652
    }

653
    /* Interfaces */
654
    case SPrefsInterface:
655
    {
656
        if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
657
            config_PutPsz( p_intf, "intf", "skins2" );
658
        if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
659
            config_PutPsz( p_intf, "intf", "qt4" );
660
        break;
661
    }
662

663
    case SPrefsAudio:
664
    {
665
        bool b_normChecked =
666
            qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
667
668
669
670
671
672
673
674
675
        if( qs_filter.isEmpty() )
        {
            /* the psz_filter is already empty, so we just append it needed */
            if( b_normChecked ) qs_filter = "volnorm";
        }
        else /* Not Empty */
        {
            if( qs_filter.contains( "volnorm" ) )
            {
676
                /* The qs_filter not empty and contains "volnorm"
677
                   that we have to remove */
678
679
680
681
682
683
684
685
                if( !b_normChecked )
                {
                    /* Ugly :D */
                    qs_filter.remove( "volnorm:" );
                    qs_filter.remove( ":volnorm" );
                    qs_filter.remove( "volnorm" );
                }
            }
686
            else /* qs_filter not empty, but doesn't have volnorm inside */
687
688
689
                if( b_normChecked ) qs_filter.append( ":volnorm" );
        }
        config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
690
691
        break;
    }
692
    }
zorglub's avatar
zorglub committed
693
694
}

zorglub's avatar
zorglub committed
695
void SPrefsPanel::clean()
zorglub's avatar
zorglub committed
696
{}
697

698
699
700
void SPrefsPanel::lastfm_Changed( int i_state )
{
    if( i_state == Qt::Checked )
701
        config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
702
    else if( i_state == Qt::Unchecked )
703
        config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
704
}
705

706
707
#ifdef WIN32
#include <QDialogButtonBox>
708
#include <QHeaderView>
709
710
#include "util/registry.hpp"

711
712
bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
                           QTreeWidgetItem* parent, QVLCRegistry *qvReg )
713
{
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
    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;
}
731

732
733
void SPrefsPanel::assoDialog()
{
734
735
736
    QDialog *d = new QDialog( this );
    QGridLayout *assoLayout = new QGridLayout( d );

737
    QTreeWidget *filetypeList = new QTreeWidget;
738
    assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
    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" );
    aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".ogg" ); aTa( ".spx" ); aTa( ".wav" );
    aTa( ".wma" ); aTa( ".xm" );
766
    audioType->setCheckState( 0, ( i_temp > 0 ) ?
767
768
769
770
771
772
773
774
775
776
777
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );

    i_temp = 0;
    aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
    aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m4v" ); aTv( ".mkv" );
    aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
    aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
    aTv( ".mxf" ); aTv( ".ogm" ); aTv( ".ps" ); aTv( ".ts" );
    aTv( ".vob" ); aTv( ".wmv" );
778
    videoType->setCheckState( 0, ( i_temp > 0 ) ?
779
780
781
782
783
784
785
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );

    i_temp = 0;
    aTo( ".asx" ); aTo( ".b4s" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
    aTo( ".xspf" );
786
    otherType->setCheckState( 0, ( i_temp > 0 ) ?
787
788
789
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );
790
791
792
793
794
795
796
797
798
799
800

    QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
    QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
    QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
    buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
    buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );

    assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );

    CONNECT( closeButton, clicked(), this, saveAsso() );
    CONNECT( clearButton, clicked(), d, reject() );
801
    d->resize( 300, 400 );
802
803
    d->exec();
    delete d;
804
    delete qvReg;
805
    listAsso.clear();
806
807
}

808
void addAsso( QVLCRegistry *qvReg, char *psz_ext )
809
{
810
811
    std::string s_path( "VLC" ); s_path += psz_ext;
    std::string s_path2 = s_path;
812

813
    /* Save a backup if already assigned */
814
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
815

816
    if( psz_value && strlen( psz_value ) > 0 )
817
        qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
818
    delete psz_value;
819

820
821
    /* Put a "link" to VLC.EXT as default */
    qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
822

823
824
825
826
827
828
829
830
831
    /* Create the needed Key if they weren't done in the installer */
    if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
    {
        qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
        qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
        qvReg->WriteRegistryString( s_path.append( "\\shell" ).c_str() , "", "Play" );

        /* Get the installer path */
        QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
832
        std::string str_temp; str_temp.assign(
833
            qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
834

835
836
837
838
        if( str_temp.size() )
        {
            qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
                "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
839

840
            qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
841
842
843
844
                        "", str_temp.append(",0").c_str() );
        }
        delete qvReg2;
    }
845
}
846

847
void delAsso( QVLCRegistry *qvReg, char *psz_ext )
848
{
849
850
    char psz_VLC[] = "VLC";
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
851

852
    if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
853
    {
854
855
856
857
858
        free( psz_value );
        psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
        if( psz_value )
            qvReg->WriteRegistryString( psz_ext, "", psz_value );

859
        qvReg->DeleteKey( psz_ext, "VLC.backup" );
860
    }
861
    delete( psz_value );
862
863
864
}
void SPrefsPanel::saveAsso()
{
865
    QVLCRegistry * qvReg;
866
867
    for( int i = 0; i < listAsso.size(); i ++ )
    {
868
869
        qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
        if( listAsso[i]->checkState( 0 ) > 0 )
870
        {
871
            addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
872
873
874
        }
        else
        {
875
            delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
876
877
878
        }
    }
    /* Gruik ? Naaah */
879
880
    qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
    delete qvReg;
881
882
883
884
}

#endif /* WIN32 */