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

#include "components/simple_preferences.hpp"
#include "components/preferences_widgets.hpp"
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 41

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

42 43
#include <QtAlgorithms>

44 45
#include <string>

46
#define ICON_HEIGHT 64
47
#define BUTTON_HEIGHT 74
48

Clément Stenac's avatar
Clément Stenac committed
49 50 51 52
/*********************************************************************
 * The List of categories
 *********************************************************************/
SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
53
                                  QWidget( _parent ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
54
{
55 56 57 58 59 60 61 62 63
    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 );                         \
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
64
    button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) );                   \
65 66 67 68 69 70 71 72 73
    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 );
74

75
    ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
76 77 78
                  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 );
79
    ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
80
                  spref_cone_Subtitles_64.png, 3 );
81
    ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
82 83
                  spref_cone_Input_64.png, 4 );
    ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
84

85
    SPrefsInterface->setChecked( true );
86 87
    layout->setMargin( 0 );
    layout->setSpacing( 1 );
88

89
    setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
90
    setLayout( layout );
91

92 93 94 95 96
}

void SPrefsCatList::switchPanel( int i )
{
    emit currentItemChanged( i );
Clément Stenac's avatar
Clément Stenac committed
97 98 99 100 101 102
}

/*********************************************************************
 * The Panels
 *********************************************************************/
SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
103
                          int _number ) : QWidget( _parent ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
104
{
Antoine Cellerier's avatar
Antoine Cellerier committed
105 106
    module_config_t *p_config;
    ConfigControl *control;
107
    number = _number;
Antoine Cellerier's avatar
Antoine Cellerier committed
108 109 110 111 112 113 114 115 116 117

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

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


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

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

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

Antoine Cellerier's avatar
Antoine Cellerier committed
154 155
#define END_SPREFS_CAT      \
            break;          \
156
        }
157

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

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

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

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

Antoine Cellerier's avatar
Antoine Cellerier committed
177 178
    switch( number )
    {
179 180 181
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
182
        START_SPREFS_CAT( Video , qtr("General Video Settings") );
183
            CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
184 185 186 187 188

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

192 193
#ifdef WIN32
            CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
194
            CONFIG_GENERIC( "directx-device", StringList, NULL,
195
                            dXdisplayDevice );
196
            CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
197 198
#else
            ui.directXBox->setVisible( false );
199
            ui.hwYUVBox->setVisible( false );
200 201
#endif

202
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
203
                                 ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
204 205 206 207 208
            CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
            CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
                            snapshotsSequentialNumbering );
            CONFIG_GENERIC( "snapshot-format", StringList, NULL,
                            snapshotsFormat );
209
         END_SPREFS_CAT;
210

211 212 213
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
214
        START_SPREFS_CAT( Audio, qtr("General Audio Settings") );
215

216 217
            CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );

218 219 220 221 222 223 224 225 226 227 228 229 230 231
#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 ); \
232
            outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
233 234 235 236 237 238 239 240

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

243
            /* hide if necessary */
244 245 246 247 248
            ui.lastfm_user_edit->hide();
            ui.lastfm_user_label->hide();
            ui.lastfm_pass_edit->hide();
            ui.lastfm_pass_label->hide();

249
            /* Build if necessary */
250
            QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
251 252 253
#ifdef WIN32
            audioControl( DirectX );
            optionWidgets.append( DirectXControl );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
254 255
            CONFIG_GENERIC2( "directx-audio-device", IntegerList,
                    DirectXLabel, DirectXDevice );
256
#else
257
            if( module_exists( "alsa" ) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
258 259 260 261
            {
                audioControl( alsa );
                optionWidgets.append( alsaControl );

262
                CONFIG_GENERIC2( "alsa-audio-device" , StringList , alsaLabel,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
263 264 265 266
                                alsaDevice );
            }
            else
                optionWidgets.append( NULL );
267
            if( module_exists( "oss" ) )
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
268 269 270
            {
                audioControl2( OSS );
                optionWidgets.append( OSSControl );
271
                CONFIG_GENERIC_FILE( "oss-audio-device" , File , OSSLabel, OSSDevice,
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
272 273 274 275
                                 OSSBrowse );
            }
            else
                optionWidgets.append( NULL );
276 277
#endif

278
            /* General Audio Options */
279 280
            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
                                     defaultVolume );
281 282 283
            CONNECT( ui.defaultVolume, valueChanged( int ),
                    this, updateAudioVolume( int ) );

284 285
            CONFIG_GENERIC( "audio-language" , String , NULL,
                            preferredAudioLanguage );
286

287
            CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
288
            CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
289
            CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
290
                            detectionDolby );
291

292
            CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
293

294
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
295
                                    volNormSpin );
296 297 298
            CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);

            /* Audio Output Specifics */
299
            CONFIG_GENERIC( "aout", Module, NULL, outputModule );
300

301 302
            CONNECT( ui.outputModule, currentIndexChanged( int ),
                     this, updateAudioOptions( int ) );
303

304
            /* File output exists on all platforms */
305
            CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
306
                                 ui.fileName, ui.fileBrowseButton );
307

308 309 310
            optionWidgets.append( ui.fileControl );
            optionWidgets.append( ui.outputModule );
            optionWidgets.append( ui.volNormBox );
Rémi Duraffort's avatar
Rémi Duraffort committed
311 312
            /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
            ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
313
            optionWidgets.append( ui.volumeValue );
314
            updateAudioOptions( ui.outputModule->currentIndex() );
315

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

334
            /* Normalizer */
335

336 337
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
338 339 340
            char* psz = config_GetPsz( p_intf, "audio-filter" );
            qs_filter = qfu( psz );
            free( psz );
341 342 343 344 345 346
            bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
            {
                ui.volNormBox->setChecked( b_normalizer );
                ui.volNormSpin->setEnabled( b_normalizer );
            }

347 348 349
            /* Volume Label */
            updateAudioVolume( ui.defaultVolume->value() ); // First time init

Antoine Cellerier's avatar
Antoine Cellerier committed
350
        END_SPREFS_CAT;
351

352
        /* Input and Codecs Panel Implementation */
353
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
354 355

            /* Disk Devices */
356
            {
357
                ui.DVDDevice->setToolTip(
358 359 360 361
                    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." ) );
362 363 364
                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
365
                if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
366
                if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
367
                    !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
368 369 370
                {
                    ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
                }
371 372 373
                free( psz_cddadiscpath );
                free( psz_dvddiscpath );
                free( psz_vcddiscpath );
374
            }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
375

376 377 378 379 380
            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 );
381
#ifdef WIN32
382
            CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
383
#else
384
            ui.systemCodecBox->hide();
385
#endif
386
            /* Access Filters */
387 388 389
            char* psz = config_GetPsz( p_intf, "access-filter" );
            qs_filter = qfu( psz );
            free( psz );
390 391 392
            ui.timeshiftBox->setChecked( qs_filter.contains( "timeshift" ) );
            ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
            ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
393

394 395 396 397 398
            optionWidgets.append( ui.dumpBox );
            optionWidgets.append( ui.bandwidthBox );
            optionWidgets.append( ui.timeshiftBox );
            optionWidgets.append( ui.DVDDevice );
            optionWidgets.append( ui.cachingCombo );
399

400 401 402
            /* Caching */
            /* Add the things to the ComboBox */
            #define addToCachingBox( str, cachingNumber ) \
403 404 405 406 407 408 409
                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 );
410 411

#define TestCaC( name ) \
412 413
    b_cache_equal =  b_cache_equal && \
     ( i_cache == config_GetInt( p_intf, name ) )
414 415

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

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

        END_SPREFS_CAT;
451 452 453
        /*******************
         * Interface Panel *
         *******************/
454
        START_SPREFS_CAT( Interface, qtr("Interface Settings") );
455 456 457
            ui.defaultLabel->setFont( italicFont );
            ui.skinsLabel->setFont( italicFont );

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

468
            /* interface */
469 470
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
471
            {
472 473 474 475
                if( strstr( psz_intf, "skin" ) )
                    ui.skins->setChecked( true );
                else if( strstr( psz_intf, "qt" ) )
                    ui.qt4->setChecked( true );
476
            }
477
            free( psz_intf );
478

479 480 481
            optionWidgets.append( ui.skins );
            optionWidgets.append( ui.qt4 );

482 483 484
            CONFIG_GENERIC( "qt-display-mode", IntegerList, NULL,
                            displayModeBox );
            CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
485
            CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
486
            CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
487 488
            CONFIG_GENERIC_FILE( "skins2-last", File, NULL, ui.fileSkin,
                    ui.skinBrowse );
489

490 491
            CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
                                                      artFetcher );
492 493

            /* UPDATE options */
494
#ifdef UPDATE_CHECK
495 496 497 498 499 500
            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
501
            ui.updatesBox->hide();
Felix Paul Kühne's avatar
Felix Paul Kühne committed
502
            ui.updatesDays->hide();
503
#endif
504
            /* ONE INSTANCE options */
505
#if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
506
            CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
507
            CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
508
                    EnqueueOneInterfaceMode );
509 510
#else
            ui.OneInterfaceBox->hide();
511
#endif
Ludovic Fauvet's avatar
Ludovic Fauvet committed
512 513 514 515 516 517 518 519
            /* RECENTLY PLAYED options */
            CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
                     ui.recentlyPlayedFilters, setEnabled( bool ) );
            ui.recentlyPlayedFilters->setEnabled( false );
            CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
            CONFIG_GENERIC( "qt-recentplay-filter", String, NULL,
                    recentlyPlayedFilters );

520
        END_SPREFS_CAT;
Antoine Cellerier's avatar
Antoine Cellerier committed
521

522
        START_SPREFS_CAT( Subtitles, qtr("Subtitles & On Screen Display Settings") );
523
            CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
524 525
            CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);

Antoine Cellerier's avatar
Antoine Cellerier committed
526 527

            CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
528
            CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
529 530
            CONFIG_GENERIC_FILE( "freetype-font", File, NULL, ui.font,
                            ui.fontBrowse );
Antoine Cellerier's avatar
Antoine Cellerier committed
531 532 533
            CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
                            fontSize );
534
            CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
535
            CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, NULL, subsPosition );
Antoine Cellerier's avatar
Antoine Cellerier committed
536 537 538

        END_SPREFS_CAT;

539 540 541 542 543 544 545 546
        case SPrefsHotkeys:
        {
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );

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

547
            control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
548 549 550
                                                this, gLayout, line );

            panel_label->setText( qtr( "Configure Hotkeys" ) );
551
            controls.append( control );
552 553

            break;
554
        }
555
    }
556

557 558
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
559
    panel_layout->addWidget( panel );
560
    if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
561

562
    setLayout( panel_layout );
Clément Stenac's avatar
Clément Stenac committed
563 564
}

565
void SPrefsPanel::updateAudioOptions( int number)
566
{
567 568
    QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
                                            ->itemData( number ).toString();
569 570 571
#ifdef WIN32
    optionWidgets[directxW]->setVisible( ( value == "directx" ) );
#else
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
572 573 574 575 576 577
    /* 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" ) );
578
#endif
579
    optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
580 581
}

582 583 584

SPrefsPanel::~SPrefsPanel()
{
585
    qDeleteAll( controls ); controls.clear();
586 587
}

588 589 590 591 592 593 594
void SPrefsPanel::updateAudioVolume( int volume )
{
    qobject_cast<QSpinBox *>(optionWidgets[volLW])
        ->setValue( volume * 100 / 256 );
}


595
/* Function called from the main Preferences dialog on each SPrefs Panel */
596
void SPrefsPanel::apply()
Clément Stenac's avatar
Clément Stenac committed
597
{
598
    /* Generic save for ever panel */
Clément Stenac's avatar
Clément Stenac committed
599 600 601
    QList<ConfigControl *>::Iterator i;
    for( i = controls.begin() ; i != controls.end() ; i++ )
    {
602 603
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
        c->doApply( p_intf );
Clément Stenac's avatar
Clément Stenac committed
604
    }
605

606 607 608
    switch( number )
    {
    case SPrefsInputAndCodecs:
609
    {
610
        /* Device default selection */
611
        char *psz_devicepath =
612
              qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
613 614 615 616 617 618
        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 );
        }
619

620
        /* Access filters */
621 622 623 624 625 626 627
#define saveBox( name, box ) {\
        if( box->isChecked() ) { \
            if( b_first ) { \
                qs_filter.append( name ); \
                b_first = false; \
            } \
            else qs_filter.append( ":" ).append( name ); \
628
        } }
629

630 631
        bool b_first = true;
        qs_filter.clear();
632 633 634
        saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
        saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
        saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
635
        config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
636

637 638
#define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
#define CaC( name ) CaCi( name, 1 )
639
        /* Caching */
640 641 642 643
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
644
            CaC( "udp-caching" );
645
            if (module_exists ("dvdread" ))
646
                CaC( "dvdread-caching" );
647
            if (module_exists ("dvdnav" ))
648 649
                CaC( "dvdnav-caching" );
            CaC( "tcp-caching" ); CaC( "vcd-caching" );
650 651
            CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
            CaC( "screen-caching" );
652 653
            CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
            CaCi( "http-caching", 2 );
654
            if (module_exists ("access_realrtsp" ))
655
                CaCi( "realrtsp-caching", 10 );
656
            CaCi( "mms-caching", 10 );
657 658 659
            #ifdef WIN32
            CaC( "dshow-caching" );
            #else
660
            if (module_exists ( "v4l" ))
661
                CaC( "v4l-caching" );
662
            if (module_exists ( "access_jack" ))
663
            CaC( "jack-input-caching" );
664
            if (module_exists ( "v4l2" ))
665
                CaC( "v4l2-caching" );
666
            if (module_exists ( "pvr" ))
667
                CaC( "pvr-caching" );
668 669 670
            #endif
            //CaCi( "dv-caching" ) too short...
        }
671
        break;
672 673
    }

674
    /* Interfaces */
675
    case SPrefsInterface:
676
    {
677
        if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
678
            config_PutPsz( p_intf, "intf", "skins2" );
679
        if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
680
            config_PutPsz( p_intf, "intf", "qt4" );
681
        break;
682
    }
683

684
    case SPrefsAudio:
685
    {
686
        bool b_normChecked =
687
            qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
688 689 690 691 692 693 694 695 696
        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" ) )
            {
697
                /* The qs_filter not empty and contains "volnorm"
698
                   that we have to remove */
699 700 701 702 703 704 705 706
                if( !b_normChecked )
                {
                    /* Ugly :D */
                    qs_filter.remove( "volnorm:" );
                    qs_filter.remove( ":volnorm" );
                    qs_filter.remove( "volnorm" );
                }
            }
707
            else /* qs_filter not empty, but doesn't have volnorm inside */
708 709 710
                if( b_normChecked ) qs_filter.append( ":volnorm" );
        }
        config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
711 712
        break;
    }
713
    }
Clément Stenac's avatar
Clément Stenac committed
714 715
}

716
void SPrefsPanel::clean()
Clément Stenac's avatar
Clément Stenac committed
717
{}
718

719 720 721
void SPrefsPanel::lastfm_Changed( int i_state )
{
    if( i_state == Qt::Checked )
722
        config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
723
    else if( i_state == Qt::Unchecked )
724
        config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
725
}
726

727 728
#ifdef WIN32
#include <QDialogButtonBox>
729
#include <QHeaderView>
730 731
#include "util/registry.hpp"

732 733
bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
                           QTreeWidgetItem* parent, QVLCRegistry *qvReg )
734
{
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
    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;
}
752

753 754
void SPrefsPanel::assoDialog()
{
755 756 757
    QDialog *d = new QDialog( this );
    QGridLayout *assoLayout = new QGridLayout( d );

758
    QTreeWidget *filetypeList = new QTreeWidget;
759
    assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784
    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" );
785
    aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
786
    aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
787
    audioType->setCheckState( 0, ( i_temp > 0 ) ?
788 789 790 791 792 793
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );

    i_temp = 0;
    aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
794 795
    aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
    aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
796
    aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
797 798
    aTv( ".mts" ); aTv( ".mxf" );
    aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
799
    aTv( ".vob" ); aTv( ".wmv" );
800
    videoType->setCheckState( 0, ( i_temp > 0 ) ?
801 802 803 804 805 806 807
                              ( ( 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" );
808
    otherType->setCheckState( 0, ( i_temp > 0 ) ?
809 810 811
                              ( ( i_temp == audioType->childCount() ) ?
                               Qt::Checked : Qt::PartiallyChecked )
                            : Qt::Unchecked );
812 813 814 815 816 817 818 819 820 821 822

    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() );
823
    d->resize( 300, 400 );
824 825
    d->exec();
    delete d;
826
    delete qvReg;
827
    listAsso.clear();
828 829
}

830
void addAsso( QVLCRegistry *qvReg, char *psz_ext )
831
{
832 833
    std::string s_path( "VLC" ); s_path += psz_ext;
    std::string s_path2 = s_path;
834

835
    /* Save a backup if already assigned */
836
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
837

838
    if( psz_value && strlen( psz_value ) > 0 )
839
        qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
840
    delete psz_value;
841

842 843
    /* Put a "link" to VLC.EXT as default */
    qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
844

845 846 847 848 849 850 851 852 853
    /* 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 );
854
        std::string str_temp; str_temp.assign(
855
            qvReg2->ReadRegistryString( "Software\\VideoLAN\\VLC", "", "" ) );
856

857 858 859 860
        if( str_temp.size() )
        {
            qvReg->WriteRegistryString( s_path.append( "\\Play\\command" ).c_str(),
                "", str_temp.append(" --started-from-file \"%1\"" ).c_str() );
861

862
            qvReg->WriteRegistryString( s_path2.append( "\\DefaultIcon" ).c_str(),
863 864 865 866
                        "", str_temp.append(",0").c_str() );
        }
        delete qvReg2;
    }
867
}
868

869
void delAsso( QVLCRegistry *qvReg, char *psz_ext )
870
{
871 872
    char psz_VLC[] = "VLC";
    char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
873

874
    if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
875
    {
876 877 878 879 880
        free( psz_value );
        psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
        if( psz_value )
            qvReg->WriteRegistryString( psz_ext, "", psz_value );

881
        qvReg->DeleteKey( psz_ext, "VLC.backup" );
882
    }
883
    delete( psz_value );
884 885 886
}
void SPrefsPanel::saveAsso()
{
887
    QVLCRegistry * qvReg;
888 889
    for( int i = 0; i < listAsso.size(); i ++ )
    {
890 891
        qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
        if( listAsso[i]->checkState( 0 ) > 0 )
892
        {
893
            addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
894 895 896
        }
        else
        {
897
            delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
898 899 900
        }
    }
    /* Gruik ? Naaah */
901 902
    qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
    delete qvReg;
903 904 905 906
}

#endif /* WIN32 */