simple_preferences.cpp 23.5 KB
Newer Older
Clément Stenac's avatar
Clément Stenac committed
1 2 3
/*****************************************************************************
 * simple_preferences.cpp : "Simple preferences"
 ****************************************************************************
4
 * Copyright (C) 2006-2007 the VideoLAN team
Clément Stenac's avatar
Clément Stenac 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
 *
Clément Stenac's avatar
Clément Stenac committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 * 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.
 *****************************************************************************/

#include "components/simple_preferences.hpp"
#include "components/preferences_widgets.hpp"
Clément Stenac's avatar
Clément Stenac committed
28

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
29
#include <vlc_config_cat.h>
30
#include <vlc_configuration.h>
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
31 32 33 34 35 36 37 38

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

39
#define ICON_HEIGHT 64
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
40
#define BUTTON_HEIGHT 74
41

Clément Stenac's avatar
Clément Stenac committed
42 43 44 45
/*********************************************************************
 * The List of categories
 *********************************************************************/
SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent ) :
46
                                  QWidget( _parent ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
47
{
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    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 );
67

68
    ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
69 70 71
                  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 );
72
    ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles"),
73
                  spref_cone_Subtitles_64.png, 3 );
74
    ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input and Codecs"),
75 76
                  spref_cone_Input_64.png, 4 );
    ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
77

78
    SPrefsInterface->setChecked( true );
79 80
    layout->setMargin( 0 );
    layout->setSpacing( 1 );
81

82 83
    this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
    setLayout( layout );
84

85 86 87 88 89
}

void SPrefsCatList::switchPanel( int i )
{
    emit currentItemChanged( i );
Clément Stenac's avatar
Clément Stenac committed
90 91 92 93 94 95
}

/*********************************************************************
 * The Panels
 *********************************************************************/
SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
96
                          int _number ) : QWidget( _parent ), p_intf( _p_intf )
Clément Stenac's avatar
Clément Stenac committed
97
{
Antoine Cellerier's avatar
Antoine Cellerier committed
98 99
    module_config_t *p_config;
    ConfigControl *control;
100
    number = _number;
Antoine Cellerier's avatar
Antoine Cellerier committed
101 102 103 104 105 106 107 108 109 110

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

111 112 113 114 115 116 117 118 119
#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 );                               \
            }

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

130 131 132
#define START_SPREFS_CAT( name , label )    \
        case SPrefs ## name:                \
        {                                   \
133
            Ui::SPrefs ## name ui;      \
134
            ui.setupUi( panel );            \
Christophe Mutricy's avatar
Christophe Mutricy committed
135
            panel_label->setText( label );
136

Antoine Cellerier's avatar
Antoine Cellerier committed
137 138
#define END_SPREFS_CAT      \
            break;          \
139
        }
140

141 142
    QVBoxLayout *panel_layout = new QVBoxLayout();
    QWidget *panel = new QWidget();
143
    panel_layout->setMargin( 3 );
144 145 146 147

    // Title Label
    QLabel *panel_label = new QLabel;
    QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
148 149
    labelFont.setPointSize( labelFont.pointSize() + 6 );
    labelFont.setFamily( "Verdana" );
150 151 152 153 154 155
    panel_label->setFont( labelFont );

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

157 158 159
    QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
    italicFont.setItalic( true );

Antoine Cellerier's avatar
Antoine Cellerier committed
160 161
    switch( number )
    {
162 163 164
        /******************************
         * VIDEO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
165
        START_SPREFS_CAT( Video , qtr("General video settings") );
166
            CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
167 168 169 170 171

            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 );
172 173
            CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
            CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
174 175
            CONFIG_GENERIC( "vout", Module, NULL, outputModule );

176 177
#ifdef WIN32
            CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
178
            CONFIG_GENERIC( "directx-device", StringList, NULL,
179
                            dXdisplayDevice );
180 181
#else
            ui.directXBox->setVisible( false );
182 183
#endif

184 185
            CONFIG_GENERIC_FILE( "snapshot-path", Directory, NULL,
                    snapshotsDirectory, snapshotsDirectoryBrowse );
186 187 188 189 190
            CONFIG_GENERIC( "snapshot-prefix", String, NULL, snapshotsPrefix );
            CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
                            snapshotsSequentialNumbering );
            CONFIG_GENERIC( "snapshot-format", StringList, NULL,
                            snapshotsFormat );
191
         END_SPREFS_CAT;
192

193 194 195
        /******************************
         * AUDIO Panel Implementation *
         ******************************/
Christophe Mutricy's avatar
Christophe Mutricy committed
196
        START_SPREFS_CAT( Audio, qtr("General audio settings") );
197

198 199
            CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );

200 201 202 203 204 205 206 207 208 209 210 211 212
            /* and hide if necessary */

#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();

213
            /* General Audio Options */
214 215 216 217
            CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
                                     defaultVolume );
            CONFIG_GENERIC( "audio-language" , String , NULL,
                            preferredAudioLanguage );
218

219 220 221
            CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
            CONFIG_GENERIC( "force-dolby-surround" , IntegerList , NULL,
                            detectionDolby );
222

223
            CONFIG_GENERIC( "headphone-dolby" , Bool , NULL, headphoneEffect );
224

225
            CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float , NULL,
226
                                    volNormSpin );
227 228 229
            CONFIG_GENERIC( "audio-visual" , Module , NULL, visualisation);

            /* Audio Output Specifics */
230
            CONFIG_GENERIC( "aout", Module, NULL, outputModule );
231

232 233
            CONNECT( ui.outputModule, currentIndexChanged( int ), this,
                             updateAudioOptions( int ) );
234

235

236
        //TODO: use modules_Exists
237
#ifndef WIN32
238 239 240
            CONFIG_GENERIC( "alsadev" , StringList , ui.alsaLabel, alsaDevice );
            CONFIG_GENERIC_FILE( "dspdev" , File , ui.OSSLabel, OSSDevice,
                                 OSSBrowse );
241
#else
242 243
            CONFIG_GENERIC( "directx-audio-device", IntegerList,
                    ui.DirectXLabel, DirectXDevice );
244
#endif
245
        // File exists everywhere
246 247
            CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
                                 fileName, fileBrowseButton );
248

249 250 251 252 253 254 255
            optionWidgets.append( ui.alsaControl );
            optionWidgets.append( ui.OSSControl );
            optionWidgets.append( ui.DirectXControl );
            optionWidgets.append( ui.fileControl );
            optionWidgets.append( ui.outputModule );
            optionWidgets.append( ui.volNormBox );
            updateAudioOptions( ui.outputModule->currentIndex() );
256

257 258
            /* LastFM */
            CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
259
                         lastfm_user_edit );
260
            CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
261
                         lastfm_pass_edit );
262 263 264 265 266 267 268

            if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
                ui.lastfm->setCheckState( Qt::Checked );
            else
                ui.lastfm->setCheckState( Qt::Unchecked );
            CONNECT( ui.lastfm, stateChanged( int ), this ,
                    lastfm_Changed( int ) );
269

270
            /* Normalizer */
271

272 273
            CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
                     setEnabled( bool ) );
274 275 276 277 278 279 280
            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 );
            }

Antoine Cellerier's avatar
Antoine Cellerier committed
281
        END_SPREFS_CAT;
282

283
        /* Input and Codecs Panel Implementation */
Christophe Mutricy's avatar
Christophe Mutricy committed
284
        START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
285 286

            /* Disk Devices */
287
            {
288 289 290 291 292
                ui.DVDDevice->setToolTip(
                    qtr( "If this propriety is blank, then you have\n"
                         "values for DVD, VCD, and CDDA.\n"
                         "You can define a unique one or set that in"
                         "the advanced preferences" ) );
293 294 295 296 297 298 299 300
                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" );
                if( ( *psz_cddadiscpath == *psz_dvddiscpath )
                   && ( *psz_dvddiscpath == *psz_vcddiscpath ) )
                {
                    ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
                }
301 302
                delete psz_cddadiscpath; delete psz_dvddiscpath;
                delete psz_vcddiscpath;
303
            }
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
304

305 306 307 308 309
            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 );
310
#ifdef WIN32
311
            CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
312
#else
313
            ui.systemCodecBox->hide();
314
#endif
315 316 317 318 319 320
            /* 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" ) );
321

322 323 324 325 326 327
            optionWidgets.append( ui.recordBox );
            optionWidgets.append( ui.dumpBox );
            optionWidgets.append( ui.bandwidthBox );
            optionWidgets.append( ui.timeshiftBox );
            optionWidgets.append( ui.DVDDevice );
            optionWidgets.append( ui.cachingCombo );
328

329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
            /* 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 ) \
    b_cache_equal =  b_cache_equal && ( i_cache == config_GetInt( p_intf, name ) );

#define TestCaCi( name, int ) \
344 345
    b_cache_equal = b_cache_equal &&  \
    ( ( i_cache * int ) == config_GetInt( p_intf, name ) );
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
            /* Select the accurate value of the ComboBox */
            bool b_cache_equal = true;
            int i_cache = config_GetInt( p_intf, "file-caching");

            TestCaC( "udp-caching" ) TestCaC( "dvdread-caching" )
            TestCaC( "dvdnav-caching" ) TestCaC( "tcp-caching" )
            TestCaC( "fake-caching" ) TestCaC( "cdda-caching" )
            TestCaC( "screen-caching" ) TestCaC( "vcd-caching" )
            #ifdef WIN32
            TestCaC( "dshow-caching" )
            #else
            TestCaC( "v4l-caching" ) TestCaC( "jack-input-caching" )
            TestCaC( "v4l2-caching" ) TestCaC( "pvr-caching" )
            #endif
            TestCaCi( "rtsp-caching", 4 ) TestCaCi( "ftp-caching", 2 )
            TestCaCi( "http-caching", 4 ) TestCaCi( "realrtsp-caching", 10 )
            TestCaCi( "mms-caching", 19 )
363 364
            if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
                ui.cachingCombo->findData( QVariant( i_cache ) ) );
365 366

        END_SPREFS_CAT;
367 368 369
        /*******************
         * Interface Panel *
         *******************/
Christophe Mutricy's avatar
Christophe Mutricy committed
370
        START_SPREFS_CAT( Interface, qtr("Interface settings") );
371 372 373
            ui.defaultLabel->setFont( italicFont );
            ui.skinsLabel->setFont( italicFont );

374
#if defined( WIN32 ) || defined (__APPLE__)
375
            CONFIG_GENERIC( "language", StringList, NULL, language );
376 377 378
#else
            ui.language->hide();
            ui.languageLabel->hide();
379
#endif
380

381
            /* interface */
382 383
            char *psz_intf = config_GetPsz( p_intf, "intf" );
            if( psz_intf )
384
            {
385 386 387 388 389
                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 );
390
            }
391
            delete psz_intf;
392

393 394 395
            optionWidgets.append( ui.skins );
            optionWidgets.append( ui.qt4 );

396
            CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
397
            CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
398
                    skinBrowse );
399
#if defined( WIN32 ) || defined( HAVE_DBUS_3 )
400
            CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
401
            CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
402
                    EnqueueOneInterfaceMode );
403 404
#else
            ui.OneInterfaceBox->hide();
405
#endif
406
        END_SPREFS_CAT;
Antoine Cellerier's avatar
Antoine Cellerier committed
407

Christophe Mutricy's avatar
Christophe Mutricy committed
408
        START_SPREFS_CAT( Subtitles, qtr("Subtitles & OSD settings") );
409
            CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
Antoine Cellerier's avatar
Antoine Cellerier committed
410 411

            CONFIG_GENERIC( "subsdec-encoding", StringList, NULL, encoding );
412 413 414
            CONFIG_GENERIC( "sub-language", String, NULL, preferredLanguage );
            CONFIG_GENERIC_FILE( "freetype-font", File, NULL, font,
                            fontBrowse );
Antoine Cellerier's avatar
Antoine Cellerier committed
415 416 417
            CONFIG_GENERIC( "freetype-color", IntegerList, NULL, fontColor );
            CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList, NULL,
                            fontSize );
418
            CONFIG_GENERIC( "freetype-effect", IntegerList, NULL, effect );
Antoine Cellerier's avatar
Antoine Cellerier committed
419 420 421

        END_SPREFS_CAT;

422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
        case SPrefsHotkeys:
        {
            p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );

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

            KeySelectorControl *ksCtrl =
                        new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
                                                this, gLayout, line );

            panel_label->setText( qtr( "Configure Hotkeys" ) );

            break;
437
        }
438
    }
439

440 441
    panel_layout->addWidget( panel_label );
    panel_layout->addWidget( title_line );
442
    panel_layout->addWidget( panel );
443
    if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
444

445
    setLayout( panel_layout );
Clément Stenac's avatar
Clément Stenac committed
446 447
}

448
void SPrefsPanel::updateAudioOptions( int number)
449
{
450 451
    QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
                                            ->itemData( number ).toString();
452 453

#ifndef WIN32
454 455
    optionWidgets[ossW]->setVisible( ( value == "oss" ) );
    optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
456
#else
457
    optionWidgets[directxW]->setVisible( ( value == "directx" ) );
458
#endif
459
    optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
460 461
}

462
/* Function called from the main Preferences dialog on each SPrefs Panel */
Clément Stenac's avatar
Clément Stenac committed
463
void SPrefsPanel::apply()
Clément Stenac's avatar
Clément Stenac committed
464
{
465
    msg_Dbg( p_intf, "Trying to save the %i simple panel", number );
466

467
    /* Generic save for ever panel */
Clément Stenac's avatar
Clément Stenac committed
468 469 470
    QList<ConfigControl *>::Iterator i;
    for( i = controls.begin() ; i != controls.end() ; i++ )
    {
Clément Stenac's avatar
Clément Stenac committed
471 472
        ConfigControl *c = qobject_cast<ConfigControl *>(*i);
        c->doApply( p_intf );
Clément Stenac's avatar
Clément Stenac committed
473
    }
474

475 476 477
    switch( number )
    {
    case SPrefsInputAndCodecs:
478
    {
479
        /* Device default selection */
480
        char *psz_devicepath =
481
              qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
482 483 484 485 486 487
        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 );
        }
488

489
        /* Access filters */
490 491 492 493 494 495 496
#define saveBox( name, box ) {\
        if( box->isChecked() ) { \
            if( b_first ) { \
                qs_filter.append( name ); \
                b_first = false; \
            } \
            else qs_filter.append( ":" ).append( name ); \
497
        } }
498

499 500
        bool b_first = true;
        qs_filter.clear();
501 502 503 504
        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] ) );
505
        config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
506

507 508
#define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue );
#define CaC( name ) CaCi( name, 1 );
509
        /* Caching */
510 511 512 513
        QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
        int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
        if( i_comboValue )
        {
514
            msg_Dbg( p_intf, "Adjusting all cache values at: %i", i_comboValue );
515 516 517 518 519 520 521 522 523 524
            CaC( "udp-caching" ); CaC( "dvdread-caching" );
            CaC( "dvdnav-caching" ); CaC( "tcp-caching" ); CaC( "vcd-caching" );
            CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
            CaC( "screen-caching" );
            CaCi( "rtsp-caching", 4 ); CaCi( "ftp-caching", 2 );
            CaCi( "http-caching", 4 ); CaCi( "realrtsp-caching", 10 );
            CaCi( "mms-caching", 19 );
            #ifdef WIN32
            CaC( "dshow-caching" );
            #else
525 526
            CaC( "v4l-caching" ); CaC( "jack-input-caching" );
            CaC( "v4l2-caching" ); CaC( "pvr-caching" );
527 528 529
            #endif
            //CaCi( "dv-caching" ) too short...
        }
530
        break;
531 532
    }

533
    /* Interfaces */
534
    case SPrefsInterface:
535
    {
536
        if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
537
            config_PutPsz( p_intf, "intf", "skins2" );
538
        if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
539
            config_PutPsz( p_intf, "intf", "qt4" );
540
        break;
541
    }
542

543
    case SPrefsAudio:
544
    {
545
        bool b_normChecked =
546
            qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
547 548 549 550 551 552 553 554 555
        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" ) )
            {
556
                /* The qs_filter not empty and contains "volnorm"
557
                   that we have to remove */
558 559 560 561 562 563 564 565
                if( !b_normChecked )
                {
                    /* Ugly :D */
                    qs_filter.remove( "volnorm:" );
                    qs_filter.remove( ":volnorm" );
                    qs_filter.remove( "volnorm" );
                }
            }
566
            else /* qs_filter not empty, but doesn't have volnorm inside */
567 568 569
                if( b_normChecked ) qs_filter.append( ":volnorm" );
        }
        config_PutPsz( p_intf, "audio-filter", qtu( qs_filter ) );
570 571
        break;
    }
572
    }
Clément Stenac's avatar
Clément Stenac committed
573 574
}

Clément Stenac's avatar
Clément Stenac committed
575
void SPrefsPanel::clean()
Clément Stenac's avatar
Clément Stenac committed
576
{}
577

578 579 580
void SPrefsPanel::lastfm_Changed( int i_state )
{
    if( i_state == Qt::Checked )
581
        config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
582
    else if( i_state == Qt::Unchecked )
583
        config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
584
}