simple_preferences.cpp 32.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
zorglub's avatar
zorglub committed
5
6
7
8
 * $Id: preferences.cpp 16348 2006-08-25 21:10:10Z zorglub $
 *
 * 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"),
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
88
    this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    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
#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 );                               \
            }

125
126
127
128
129
130
131
132
133
134
#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), \
                               p_config, label, ui.qcontrol, ui.qbutton,      \
                            false );                                          \
                    controls.append( control );                               \
                }

135
136
137
#define START_SPREFS_CAT( name , label )    \
        case SPrefs ## name:                \
        {                                   \
138
            Ui::SPrefs ## name ui;      \
139
            ui.setupUi( panel );            \
Christophe Mutricy's avatar
Christophe Mutricy committed
140
            panel_label->setText( label );
141

dionoea's avatar
dionoea committed
142
143
#define END_SPREFS_CAT      \
            break;          \
144
        }
145

146
147
    QVBoxLayout *panel_layout = new QVBoxLayout();
    QWidget *panel = new QWidget();
148
    panel_layout->setMargin( 3 );
149
150
151
152

    // Title Label
    QLabel *panel_label = new QLabel;
    QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
153
154
    labelFont.setPointSize( labelFont.pointSize() + 6 );
    labelFont.setFamily( "Verdana" );
155
156
157
158
159
160
    panel_label->setFont( labelFont );

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

162
163
164
    QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
    italicFont.setItalic( true );

dionoea's avatar
dionoea committed
165
166
    switch( number )
    {
167
168
169
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
170
        START_SPREFS_CAT( Video , qtr("General video settings") );
171
            CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
172
173
174
175
176

            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 );
177
            CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
178
179
            CONFIG_GENERIC( "vout", Module, NULL, outputModule );

180
181
#ifdef WIN32
            CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
182
            CONFIG_GENERIC( "directx-device", StringList, NULL,
183
                            dXdisplayDevice );
184
185
#else
            ui.directXBox->setVisible( false );
186
187
#endif

188
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
189
                                 snapshotsDirectory, snapshotsDirectoryBrowse );
190
191
192
193
194
            CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
            CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
                            snapshotsSequentialNumbering );
            CONFIG_GENERIC( "snapshot-format", StringList, NULL,
                            snapshotsFormat );
195
         END_SPREFS_CAT;
196

197
198
199
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
200
        START_SPREFS_CAT( Audio, qtr("General audio settings") );
201

202
203
            CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );

204
            /* hide if necessary */
205
206
207
208
209
210
211
212
213
214
215
#ifdef WIN32
            ui.OSSControl->hide();
            ui.alsaControl->hide();
#else
            ui.DirectXControl->hide();
#endif
            ui.lastfm_user_edit->hide();
            ui.lastfm_user_label->hide();
            ui.lastfm_pass_edit->hide();
            ui.lastfm_pass_label->hide();

216
            /* General Audio Options */
217
218
            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
                                     defaultVolume );
219
220
221
            CONNECT( ui.defaultVolume, valueChanged( int ),
                    this, updateAudioVolume( int ) );

222
223
            CONFIG_GENERIC( "audio-language" , String , NULL,
                            preferredAudioLanguage );
224

225
226
227
            CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
            CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
                            detectionDolby );
228

229
            CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
230

231
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
232
                                    volNormSpin );
233
234
235
            CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);

            /* Audio Output Specifics */
236
            CONFIG_GENERIC( "aout", Module, NULL, outputModule );
237

238
239
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateAudioOptions( int ) );
240

241
242
243
244
#ifdef WIN32
            CONFIG_GENERIC( "directx-audio-device", IntegerList,
                    ui.DirectXLabel, DirectXDevice );
#else
245
246
247
248
249
250
251
252
            if( module_Exists( p_intf, "alsa" ) )
            {
                CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel,
                                alsaDevice );
            }
            if( module_Exists( p_intf, "oss" ) )
            {
                CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
253
                                 OSSBrowse );
254
            }
255
#endif
256
        // File exists everywhere
257
258
            CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
                                 fileName, fileBrowseButton );
259

260
261
262
263
264
265
            optionWidgets.append( ui.alsaControl );
            optionWidgets.append( ui.OSSControl );
            optionWidgets.append( ui.DirectXControl );
            optionWidgets.append( ui.fileControl );
            optionWidgets.append( ui.outputModule );
            optionWidgets.append( ui.volNormBox );
ivoire's avatar
ivoire committed
266
            /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
ivoire's avatar
ivoire committed
267
#if HAS_QT43
ivoire's avatar
ivoire committed
268
269
            ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
#endif
270
            optionWidgets.append( ui.volumeValue );
271
            updateAudioOptions( ui.outputModule->currentIndex() );
272

273
            /* LastFM */
274
            if( module_Exists( p_intf, "audioscrobbler" ) )
275
276
277
278
279
280
281
            {
                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" ) )
282
                    ui.lastfm->setChecked( true );
283
                else
284
                    ui.lastfm->setChecked( false );
285
286
287
                CONNECT( ui.lastfm, stateChanged( int ), this ,
                        lastfm_Changed( int ) );
            }
288
289
            else
                ui.lastfm->hide();
290

291
            /* Normalizer */
292

293
294
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
295
296
297
298
299
300
301
            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 );
            }

302
303
304
            /* Volume Label */
            updateAudioVolume( ui.defaultVolume->value() ); // First time init

dionoea's avatar
dionoea committed
305
        END_SPREFS_CAT;
306

307
        /* Input and Codecs Panel Implementation */
Christophe Mutricy's avatar
Christophe Mutricy committed
308
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
309
310

            /* Disk Devices */
311
            {
312
                ui.DVDDevice->setToolTip(
313
                    //TODO: make this sentence understandable
Christophe Mutricy's avatar
Typo    
Christophe Mutricy committed
314
                    qtr( "If this property is blank, then you have\n"
315
316
317
                         "values for DVD, VCD, and CDDA.\n"
                         "You can define a unique one or set that in"
                         "the advanced preferences" ) );
318
319
320
                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
321
                if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
322
                if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
323
                    !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
324
325
326
                {
                    ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
                }
327
328
                delete psz_cddadiscpath; delete psz_dvddiscpath;
                delete psz_vcddiscpath;
329
            }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
330

331
332
333
334
335
            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 );
336
#ifdef WIN32
337
            CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
338
#else
339
            ui.systemCodecBox->hide();
340
#endif
341
342
343
344
345
346
            /* 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" ) );
347

348
349
350
351
352
353
            optionWidgets.append( ui.recordBox );
            optionWidgets.append( ui.dumpBox );
            optionWidgets.append( ui.bandwidthBox );
            optionWidgets.append( ui.timeshiftBox );
            optionWidgets.append( ui.DVDDevice );
            optionWidgets.append( ui.cachingCombo );
354

355
356
357
358
359
360
361
362
363
364
365
366
            /* 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 ) \
367
368
    b_cache_equal =  b_cache_equal && \
     ( i_cache == config_GetInt( p_intf, name ) )
369
370

#define TestCaCi( name, int ) \
371
    b_cache_equal = b_cache_equal &&  \
372
    ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
373
374
375
376
            /* Select the accurate value of the ComboBox */
            bool b_cache_equal = true;
            int i_cache = config_GetInt( p_intf, "file-caching");

377
378
379
380
381
382
383
384
            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" );
385
            #ifdef WIN32
386
            TestCaC( "dshow-caching" );
387
            #else
388
389
390
391
392
393
394
395
            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" );
396
            #endif
397
398
399
400
401
            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 );
402
403
            if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
                ui.cachingCombo->findData( QVariant( i_cache ) ) );
404
405

        END_SPREFS_CAT;
406
407
408
        /*******************
         * Interface Panel *
         *******************/
Christophe Mutricy's avatar
Christophe Mutricy committed
409
        START_SPREFS_CAT( Interface, qtr("Interface settings") );
410
411
412
            ui.defaultLabel->setFont( italicFont );
            ui.skinsLabel->setFont( italicFont );

413
#if defined( WIN32 ) || defined (__APPLE__)
414
            CONFIG_GENERIC( "language", StringList, NULL, language );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
415
            BUTTONACT( ui.assoButton, assoDialog() );
416
417
418
#else
            ui.language->hide();
            ui.languageLabel->hide();
419
420
            ui.assoName->hide();
            ui.assoButton->hide();
421
#endif
422

423
            /* interface */
424
425
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
426
            {
427
428
429
430
431
                msg_Dbg( p_intf, "Interface in config file: %s", psz_intf );
                if( strstr( psz_intf, "skin" ) )
                    ui.skins->setChecked( true );
                else if( strstr( psz_intf, "qt" ) )
                    ui.qt4->setChecked( true );
432
            }
433
            delete psz_intf;
434

435
436
437
            optionWidgets.append( ui.skins );
            optionWidgets.append( ui.qt4 );

438
439
            CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
                                                      artFetcher );
440
            CONFIG_GENERIC( "fetch-meta", Bool, NULL, metaFetcher );
441
442
            CONFIG_GENERIC( "security-policy", IntegerList,
                            ui.netPolicyLabel, netPolicyBox );
443
#ifdef UPDATE_CHECK
444
445
446
447
448
449
            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
450
            ui.updatesBox->hide();
Felix Paul Kühne's avatar
Felix Paul Kühne committed
451
            ui.updatesDays->hide();
452
#endif
453
            CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
454
            CONFIG_GENERIC( "embeded-video", Bool, NULL, embedVideo );
455
            CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
456
                    skinBrowse );
457
#if defined( WIN32 ) || defined( HAVE_DBUS_3 ) || defined(__APPLE__)
458
            CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
459
            CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
460
                    EnqueueOneInterfaceMode );
461
462
#else
            ui.OneInterfaceBox->hide();
463
#endif
dionoea's avatar
dionoea committed
464
        END_SPREFS_CAT;
dionoea's avatar
dionoea committed
465

Christophe Mutricy's avatar
Christophe Mutricy committed
466
        START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
467
            CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
dionoea's avatar
dionoea committed
468
469

            CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
470
471
472
            CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
            CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
                            fontBrowse );
dionoea's avatar
dionoea committed
473
474
475
            CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
                            fontSize );
476
            CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
dionoea's avatar
dionoea committed
477
478
479

        END_SPREFS_CAT;

480
481
482
483
484
485
486
487
        case SPrefsHotkeys:
        {
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );

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

488
            control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
489
490
491
                                                this, gLayout, line );

            panel_label->setText( qtr( "Configure Hotkeys" ) );
492
            controls.append( control );
493
494

            break;
495
        }
496
    }
497

498
499
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
500
    panel_layout->addWidget( panel );
501
    if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
502

503
    setLayout( panel_layout );
zorglub's avatar
zorglub committed
504
505
}

506
void SPrefsPanel::updateAudioOptions( int number)
507
{
508
509
    QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
                                            ->itemData( number ).toString();
510

511
512
513
#ifdef WIN32
    optionWidgets[directxW]->setVisible( ( value == "directx" ) );
#else
514
515
    optionWidgets[ossW]->setVisible( ( value == "oss" ) );
    optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
516
#endif
517
    optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
518
519
}

520
521
522
523
524
525
526
void SPrefsPanel::updateAudioVolume( int volume )
{
    qobject_cast<QSpinBox *>(optionWidgets[volLW])
        ->setValue( volume * 100 / 256 );
}


527
/* Function called from the main Preferences dialog on each SPrefs Panel */
zorglub's avatar
zorglub committed
528
void SPrefsPanel::apply()
zorglub's avatar
zorglub committed
529
{
530
    msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
531

532
    /* Generic save for ever panel */
zorglub's avatar
zorglub committed
533
534
535
    QList<ConfigControl *>::Iterator i;
    for( i = controls.begin() ; i != controls.end() ; i++ )
    {
zorglub's avatar
zorglub committed
536
537
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
        c->doApply( p_intf );
zorglub's avatar
zorglub committed
538
    }
539

540
541
542
    switch( number )
    {
    case SPrefsInputAndCodecs:
543
    {
544
        /* Device default selection */
545
        char *psz_devicepath =
546
              qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
547
548
549
550
551
552
        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 );
        }
553

554
        /* Access filters */
555
556
557
558
559
560
561
#define saveBox( name, box ) {\
        if( box->isChecked() ) { \
            if( b_first ) { \
                qs_filter.append( name ); \
                b_first = false; \
            } \
            else qs_filter.append( ":" ).append( name ); \
562
        } }
563

564
565
        bool b_first = true;
        qs_filter.clear();
566
567
568
569
        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] ) );
570
        config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
571

572
573
#define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
#define CaC( name ) CaCi( name, 1 )
574
        /* Caching */
575
576
577
578
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
579
            msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
580
            CaC( "udp-caching" );
581
            if (module_Exists (p_intf, "dvdread" ))
582
                CaC( "dvdread-caching" );
583
            if (module_Exists (p_intf, "dvdnav" ))
584
585
                CaC( "dvdnav-caching" );
            CaC( "tcp-caching" ); CaC( "vcd-caching" );
586
587
588
            CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
            CaC( "screen-caching" );
            CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
589
            CaCi( "http-caching", 4 );
590
            if (module_Exists (p_intf, "access_realrtsp" ))
591
                CaCi( "realrtsp-caching", 10 );
592
593
594
595
            CaCi( "mms-caching", 19 );
            #ifdef WIN32
            CaC( "dshow-caching" );
            #else
596
            if (module_Exists (p_intf, "v4l" ))
597
                CaC( "v4l-caching" );
598
            if (module_Exists (p_intf, "access_jack" ))
599
            CaC( "jack-input-caching" );
600
            if (module_Exists (p_intf, "v4l2" ))
601
                CaC( "v4l2-caching" );
602
            if (module_Exists (p_intf, "pvr" ))
603
                CaC( "pvr-caching" );
604
605
606
            #endif
            //CaCi( "dv-caching" ) too short...
        }
607
        break;
608
609
    }

610
    /* Interfaces */
611
    case SPrefsInterface:
612
    {
613
        if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
614
            config_PutPsz( p_intf, "intf", "skins2" );
615
        if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
616
            config_PutPsz( p_intf, "intf", "qt4" );
617
        break;
618
    }
619

620
    case SPrefsAudio:
621
    {
622
        bool b_normChecked =
623
            qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
624
625
626
627
628
629
630
631
632
        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" ) )
            {
633
                /* The qs_filter not empty and contains "volnorm"
634
                   that we have to remove */
635
636
637
638
639
640
641
642
                if( !b_normChecked )
                {
                    /* Ugly :D */
                    qs_filter.remove( "volnorm:" );
                    qs_filter.remove( ":volnorm" );
                    qs_filter.remove( "volnorm" );
                }
            }
643
            else /* qs_filter not empty, but doesn't have volnorm inside */
644
645
646
                if( b_normChecked ) qs_filter.append( ":volnorm" );
        }
        config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
647
648
        break;
    }
649
    }
zorglub's avatar
zorglub committed
650
651
}

zorglub's avatar
zorglub committed
652
void SPrefsPanel::clean()
zorglub's avatar
zorglub committed
653
{}
654

655
656
657
void SPrefsPanel::lastfm_Changed( int i_state )
{
    if( i_state == Qt::Checked )
658
        config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
659
    else if( i_state == Qt::Unchecked )
660
        config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
661
}
662

663
664
#ifdef WIN32
#include <QDialogButtonBox>
665
#include <QHeaderView>
666
667
#include "util/registry.hpp"

668
669
bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
                           QTreeWidgetItem* parent, QVLCRegistry *qvReg )
670
{
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    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;
}
688

689
690
void SPrefsPanel::assoDialog()
{
691
692
693
    QDialog *d = new QDialog( this );
    QGridLayout *assoLayout = new QGridLayout( d );

694
    QTreeWidget *filetypeList = new QTreeWidget;
695
    assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
    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" );
723
    audioType->setCheckState( 0, ( i_temp > 0 ) ?
724
725
726
727
728
729
730
731
732
733
734
                              ( ( 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" );
735
    videoType->setCheckState( 0, ( i_temp > 0 ) ?
736
737
738
739
740
741
742
                              ( ( 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" );
743
    otherType->setCheckState( 0, ( i_temp > 0 ) ?
744
745
746
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );
747
748
749
750
751
752
753
754
755
756
757

    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() );
758
    d->resize( 300, 400 );
759
760
    d->exec();
    delete d;
761
    delete qvReg;
762
    listAsso.clear();
763
764
}

765
void addAsso( QVLCRegistry *qvReg, char *psz_ext )
766
{
767
768
    std::string s_path( "VLC" ); s_path += psz_ext;
    std::string s_path2 = s_path;
769

770
    /* Save a backup if already assigned */
771
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
772

773
    if( psz_value && strlen( psz_value ) > 0 )
774
        qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
775
    delete psz_value;
776

777
778
    /* Put a "link" to VLC.EXT as default */
    qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
779

780
781
782
783
784
785
786
787
788
    /* 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 );
789
        std::string str_temp; str_temp.assign(
790
            qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
791

792
793
794
795
        if( str_temp.size() )
        {
            qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
                "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
796

797
            qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
798
799
800
801
                        "", str_temp.append(",0").c_str() );
        }
        delete qvReg2;
    }
802
}
803

804
void delAsso( QVLCRegistry *qvReg, char *psz_ext )
805
{
806
807
    char psz_VLC[] = "VLC";
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
808

809
    if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
810
    {
811
812
813
814
815
        free( psz_value );
        psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
        if( psz_value )
            qvReg->WriteRegistryString( psz_ext, "", psz_value );

816
        qvReg->DeleteKey( psz_ext, "VLC.backup" );
817
    }
818
    delete( psz_value );
819
820
821
}
void SPrefsPanel::saveAsso()
{
822
    QVLCRegistry * qvReg;
823
824
    for( int i = 0; i < listAsso.size(); i ++ )
    {
825
826
        qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
        if( listAsso[i]->checkState( 0 ) > 0 )
827
        {
828
            addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
829
830
831
        }
        else
        {
832
            delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
833
834
835
        }
    }
    /* Gruik ? Naaah */
836
837
    qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
    delete qvReg;
838
839
840
841
}

#endif /* WIN32 */