simple_preferences.cpp
上传用户:kjfoods
上传日期:2020-07-06
资源大小:29949k
文件大小:37k
源码类别:

midi

开发平台:

Unix_Linux

  1. /*****************************************************************************
  2.  * simple_preferences.cpp : "Simple preferences"
  3.  ****************************************************************************
  4.  * Copyright (C) 2006-2008 the VideoLAN team
  5.  * $Id: 1a861f0c3db772693a09e8919e3600a6e2a3db89 $
  6.  *
  7.  * Authors: Clément Stenac <zorglub@videolan.org>
  8.  *          Antoine Cellerier <dionoea@videolan.org>
  9.  *          Jean-Baptiste Kempf <jb@videolan.org>
  10.  *
  11.  * This program is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * This program is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  24.  *****************************************************************************/
  25. #ifdef HAVE_CONFIG_H
  26. # include "config.h"
  27. #endif
  28. #include "components/simple_preferences.hpp"
  29. #include "components/preferences_widgets.hpp"
  30. #include <vlc_config_cat.h>
  31. #include <vlc_configuration.h>
  32. #include <QString>
  33. #include <QFont>
  34. #include <QToolButton>
  35. #include <QButtonGroup>
  36. #include <QVBoxLayout>
  37. #include <QScrollArea>
  38. #include <QtAlgorithms>
  39. #include <string>
  40. #define ICON_HEIGHT 64
  41. /*********************************************************************
  42.  * The List of categories
  43.  *********************************************************************/
  44. SPrefsCatList::SPrefsCatList( intf_thread_t *_p_intf, QWidget *_parent, bool small ) :
  45.                                   QWidget( _parent ), p_intf( _p_intf )
  46. {
  47.     QVBoxLayout *layout = new QVBoxLayout();
  48.     QButtonGroup *buttonGroup = new QButtonGroup( this );
  49.     buttonGroup->setExclusive ( true );
  50.     CONNECT( buttonGroup, buttonClicked ( int ),
  51.             this, switchPanel( int ) );
  52.     short icon_height = small ? ICON_HEIGHT /2 : ICON_HEIGHT;
  53. #define ADD_CATEGORY( button, label, icon, numb )                           
  54.     QToolButton * button = new QToolButton( this );                         
  55.     button->setIcon( QIcon( ":/pixmaps/prefs/" #icon ) );                   
  56.     button->setText( label );                                               
  57.     button->setToolButtonStyle( Qt::ToolButtonTextUnderIcon );              
  58.     button->setIconSize( QSize( icon_height, icon_height ) );               
  59.     button->resize( icon_height + 6 , icon_height + 6 );                    
  60.     button->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding) ;  
  61.     button->setAutoRaise( true );                                           
  62.     button->setCheckable( true );                                           
  63.     buttonGroup->addButton( button, numb );                                 
  64.     layout->addWidget( button );
  65.     ADD_CATEGORY( SPrefsInterface, qtr("Interface"),
  66.                   spref_cone_Interface_64.png, 0 );
  67.     ADD_CATEGORY( SPrefsAudio, qtr("Audio"), spref_cone_Audio_64.png, 1 );
  68.     ADD_CATEGORY( SPrefsVideo, qtr("Video"), spref_cone_Video_64.png, 2 );
  69.     ADD_CATEGORY( SPrefsSubtitles, qtr("Subtitles && OSD"),
  70.                   spref_cone_Subtitles_64.png, 3 );
  71.     ADD_CATEGORY( SPrefsInputAndCodecs, qtr("Input && Codecs"),
  72.                   spref_cone_Input_64.png, 4 );
  73.     ADD_CATEGORY( SPrefsHotkeys, qtr("Hotkeys"), spref_cone_Hotkeys_64.png, 5 );
  74. #undef ADD_CATEGORY
  75.     SPrefsInterface->setChecked( true );
  76.     layout->setMargin( 0 );
  77.     layout->setSpacing( 1 );
  78.     setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
  79.     setLayout( layout );
  80. }
  81. void SPrefsCatList::switchPanel( int i )
  82. {
  83.     emit currentItemChanged( i );
  84. }
  85. /*********************************************************************
  86.  * The Panels
  87.  *********************************************************************/
  88. SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
  89.                           int _number, bool small ) : QWidget( _parent ), p_intf( _p_intf )
  90. {
  91.     module_config_t *p_config;
  92.     ConfigControl *control;
  93.     number = _number;
  94. #define CONFIG_GENERIC( option, type, label, qcontrol )                   
  95.             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  
  96.             if( p_config )                                                
  97.             {                                                             
  98.                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), 
  99.                            p_config, label, ui.qcontrol, false );         
  100.                 controls.append( control );                               
  101.             }
  102. #define CONFIG_GENERIC2( option, type, label, qcontrol )                   
  103.             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  
  104.             if( p_config )                                                
  105.             {                                                             
  106.                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), 
  107.                            p_config, label, qcontrol, false );         
  108.                 controls.append( control );                               
  109.             }
  110. #define CONFIG_GENERIC_NO_BOOL( option, type, label, qcontrol )           
  111.             p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  
  112.             if( p_config )                                                
  113.             {                                                             
  114.                 control =  new type ## ConfigControl( VLC_OBJECT(p_intf), 
  115.                            p_config, label, ui.qcontrol );                
  116.                 controls.append( control );                               
  117.             }
  118. #define CONFIG_GENERIC_FILE( option, type, label, qcontrol, qbutton )         
  119.                 p_config =  config_FindConfig( VLC_OBJECT(p_intf), option );  
  120.                 if( p_config )                                                
  121.                 {                                                             
  122.                     control =  new type ## ConfigControl( VLC_OBJECT(p_intf), 
  123.                                p_config, label, qcontrol, qbutton ); 
  124.                     controls.append( control );                               
  125.                 }
  126. #define START_SPREFS_CAT( name , label )    
  127.         case SPrefs ## name:                
  128.         {                                   
  129.             Ui::SPrefs ## name ui;      
  130.             ui.setupUi( panel );            
  131.             panel_label->setText( label );
  132. #define END_SPREFS_CAT      
  133.             break;          
  134.         }
  135.     QVBoxLayout *panel_layout = new QVBoxLayout();
  136.     QWidget *panel = new QWidget();
  137.     panel_layout->setMargin( 3 );
  138.     // Title Label
  139.     QLabel *panel_label = new QLabel;
  140.     QFont labelFont = QApplication::font( static_cast<QWidget*>(0) );
  141.     labelFont.setPointSize( labelFont.pointSize() + 6 );
  142.     labelFont.setFamily( "Verdana" );
  143.     panel_label->setFont( labelFont );
  144.     // Title <hr>
  145.     QFrame *title_line = new QFrame;
  146.     title_line->setFrameShape(QFrame::HLine);
  147.     title_line->setFrameShadow(QFrame::Sunken);
  148.     QFont italicFont = QApplication::font( static_cast<QWidget*>(0) );
  149.     italicFont.setItalic( true );
  150.     switch( number )
  151.     {
  152.         /******************************
  153.          * VIDEO Panel Implementation *
  154.          ******************************/
  155.         START_SPREFS_CAT( Video , qtr("Video Settings") );
  156.             CONFIG_GENERIC( "video", Bool, NULL, enableVideo );
  157.             CONFIG_GENERIC( "fullscreen", Bool, NULL, fullscreen );
  158.             CONFIG_GENERIC( "overlay", Bool, NULL, overlay );
  159.             CONFIG_GENERIC( "video-on-top", Bool, NULL, alwaysOnTop );
  160.             CONFIG_GENERIC( "video-deco", Bool, NULL, windowDecorations );
  161.             CONFIG_GENERIC( "skip-frames" , Bool, NULL, skipFrames );
  162.             CONFIG_GENERIC( "vout", Module, ui.voutLabel, outputModule );
  163. #ifdef WIN32
  164.             CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
  165.             CONFIG_GENERIC( "directx-device", StringList, ui.dxDeviceLabel,
  166.                             dXdisplayDevice );
  167.             CONFIG_GENERIC( "directx-hw-yuv", Bool, NULL, hwYUVBox );
  168. #else
  169.             ui.directXBox->setVisible( false );
  170.             ui.hwYUVBox->setVisible( false );
  171. #endif
  172.             CONFIG_GENERIC( "deinterlace-mode", StringList, ui.deinterLabel, deinterlaceBox );
  173.             CONFIG_GENERIC( "aspect-ratio", String, ui.arLabel, arLine );
  174.             CONFIG_GENERIC_FILE( "snapshot-path", Directory, ui.dirLabel,
  175.                                  ui.snapshotsDirectory, ui.snapshotsDirectoryBrowse );
  176.             CONFIG_GENERIC( "snapshot-prefix", String, ui.prefixLabel, snapshotsPrefix );
  177.             CONFIG_GENERIC( "snapshot-sequential", Bool, NULL,
  178.                             snapshotsSequentialNumbering );
  179.             CONFIG_GENERIC( "snapshot-format", StringList, ui.arLabel,
  180.                             snapshotsFormat );
  181.          END_SPREFS_CAT;
  182.         /******************************
  183.          * AUDIO Panel Implementation *
  184.          ******************************/
  185.         START_SPREFS_CAT( Audio, qtr("Audio Settings") );
  186.             CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
  187. #define audioCommon( name ) 
  188.             QWidget * name ## Control = new QWidget( ui.outputAudioBox ); 
  189.             QHBoxLayout * name ## Layout = new QHBoxLayout( name ## Control); 
  190.             name ## Layout->setMargin( 0 ); 
  191.             name ## Layout->setSpacing( 0 ); 
  192.             QLabel * name ## Label = new QLabel( qtr( "Device:" ), name ## Control ); 
  193.             name ## Label->setMinimumSize(QSize(100, 0)); 
  194.             name ## Layout->addWidget( name ## Label ); 
  195. #define audioControl( name) 
  196.             audioCommon( name ) 
  197.             QComboBox * name ## Device = new QComboBox( name ## Control ); 
  198.             name ## Layout->addWidget( name ## Device ); 
  199.             name ## Label->setBuddy( name ## Device ); 
  200.             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
  201. #define audioControl2( name) 
  202.             audioCommon( name ) 
  203.             QLineEdit * name ## Device = new QLineEdit( name ## Control ); 
  204.             name ## Layout->addWidget( name ## Device ); 
  205.             name ## Label->setBuddy( name ## Device ); 
  206.             QPushButton * name ## Browse = new QPushButton( qtr( "Browse..." ), name ## Control); 
  207.             name ## Layout->addWidget( name ## Browse ); 
  208.             outputAudioLayout->addWidget( name ## Control, outputAudioLayout->rowCount(), 0, 1, -1 );
  209.             /* hide if necessary */
  210.             ui.lastfm_user_edit->hide();
  211.             ui.lastfm_user_label->hide();
  212.             ui.lastfm_pass_edit->hide();
  213.             ui.lastfm_pass_label->hide();
  214.             /* Build if necessary */
  215.             QGridLayout * outputAudioLayout = qobject_cast<QGridLayout *>(ui.outputAudioBox->layout());
  216. #ifdef WIN32
  217.             audioControl( DirectX );
  218.             optionWidgets.append( DirectXControl );
  219.             CONFIG_GENERIC2( "directx-audio-device", IntegerList,
  220.                     NULL, DirectXDevice );
  221. #else
  222.             if( module_exists( "alsa" ) )
  223.             {
  224.                 audioControl( alsa );
  225.                 optionWidgets.append( alsaControl );
  226.                 CONFIG_GENERIC2( "alsa-audio-device" , StringList, NULL,
  227.                                 alsaDevice );
  228.             }
  229.             else
  230.                 optionWidgets.append( NULL );
  231.             if( module_exists( "oss" ) )
  232.             {
  233.                 audioControl2( OSS );
  234.                 optionWidgets.append( OSSControl );
  235.                 CONFIG_GENERIC_FILE( "oss-audio-device" , File, NULL, OSSDevice,
  236.                                  OSSBrowse );
  237.             }
  238.             else
  239.                 optionWidgets.append( NULL );
  240. #endif
  241. #undef audioControl2
  242. #undef audioControl
  243. #undef audioCommon
  244.             /* Audio Options */
  245.             CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
  246.                                      defaultVolume );
  247.             CONNECT( ui.defaultVolume, valueChanged( int ),
  248.                     this, updateAudioVolume( int ) );
  249.             CONFIG_GENERIC( "audio-language" , String , ui.langLabel,
  250.                             preferredAudioLanguage );
  251.             CONFIG_GENERIC( "spdif", Bool, NULL, spdifBox );
  252.             CONFIG_GENERIC( "qt-autosave-volume", Bool, NULL, saveVolBox );
  253.             CONFIG_GENERIC( "force-dolby-surround", IntegerList, ui.dolbyLabel,
  254.                             detectionDolby );
  255.             CONFIG_GENERIC_NO_BOOL( "norm-max-level" , Float, NULL,
  256.                                     volNormSpin );
  257.             CONFIG_GENERIC( "audio-replay-gain-mode", StringList, ui.replayLabel,
  258.                             replayCombo );
  259.             CONFIG_GENERIC( "audio-visual" , Module , ui.visuLabel,
  260.                             visualisation);
  261.             /* Audio Output Specifics */
  262.             CONFIG_GENERIC( "aout", Module, ui.outputLabel, outputModule );
  263.             CONNECT( ui.outputModule, currentIndexChanged( int ),
  264.                      this, updateAudioOptions( int ) );
  265.             /* File output exists on all platforms */
  266.             CONFIG_GENERIC_FILE( "audiofile-file", File, ui.fileLabel,
  267.                                  ui.fileName, ui.fileBrowseButton );
  268.             optionWidgets.append( ui.fileControl );
  269.             optionWidgets.append( ui.outputModule );
  270.             optionWidgets.append( ui.volNormBox );
  271.             /*Little mofification of ui.volumeValue to compile with Qt < 4.3 */
  272.             ui.volumeValue->setButtonSymbols(QAbstractSpinBox::NoButtons);
  273.             optionWidgets.append( ui.volumeValue );
  274.             optionWidgets.append( ui.headphoneEffect );
  275.             updateAudioOptions( ui.outputModule->currentIndex() );
  276.             /* LastFM */
  277.             if( module_exists( "audioscrobbler" ) )
  278.             {
  279.                 CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
  280.                         lastfm_user_edit );
  281.                 CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
  282.                         lastfm_pass_edit );
  283.                 if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
  284.                     ui.lastfm->setChecked( true );
  285.                 else
  286.                     ui.lastfm->setChecked( false );
  287.                 CONNECT( ui.lastfm, stateChanged( int ),
  288.                          this, lastfm_Changed( int ) );
  289.             }
  290.             else
  291.                 ui.lastfm->hide();
  292.             /* Normalizer */
  293.             CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
  294.                      setEnabled( bool ) );
  295.             char* psz = config_GetPsz( p_intf, "audio-filter" );
  296.             qs_filter = qfu( psz ).split( ':', QString::SkipEmptyParts );
  297.             free( psz );
  298.             bool b_enabled = ( qs_filter.contains( "volnorm" ) );
  299.             ui.volNormBox->setChecked( b_enabled );
  300.             ui.volNormSpin->setEnabled( b_enabled );
  301.             b_enabled = ( qs_filter.contains( "headphone" ) );
  302.             ui.headphoneEffect->setChecked( b_enabled );
  303.             /* Volume Label */
  304.             updateAudioVolume( ui.defaultVolume->value() ); // First time init
  305.         END_SPREFS_CAT;
  306.         /* Input and Codecs Panel Implementation */
  307.         START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs Settings") );
  308.             /* Disk Devices */
  309.             {
  310.                 ui.DVDDevice->setToolTip(
  311.                     qtr( "If this property is blank, different valuesn"
  312.                          "for DVD, VCD, and CDDA are set.n"
  313.                          "You can define a unique one or configure them n"
  314.                          "individually in the advanced preferences." ) );
  315.                 char *psz_dvddiscpath = config_GetPsz( p_intf, "dvd" );
  316.                 char *psz_vcddiscpath = config_GetPsz( p_intf, "vcd" );
  317.                 char *psz_cddadiscpath = config_GetPsz( p_intf, "cd-audio" );
  318.                 if( psz_dvddiscpath && psz_vcddiscpath && psz_cddadiscpath )
  319.                 if( !strcmp( psz_cddadiscpath, psz_dvddiscpath ) &&
  320.                     !strcmp( psz_dvddiscpath, psz_vcddiscpath ) )
  321.                 {
  322.                     ui.DVDDevice->setText( qfu( psz_dvddiscpath ) );
  323.                 }
  324.                 free( psz_cddadiscpath );
  325.                 free( psz_dvddiscpath );
  326.                 free( psz_vcddiscpath );
  327.             }
  328.             CONFIG_GENERIC_FILE( "input-record-path", Directory, ui.recordLabel,
  329.                                  ui.recordPath, ui.recordBrowse );
  330.             CONFIG_GENERIC_NO_BOOL( "server-port", Integer, ui.portLabel,
  331.                                     UDPPort );
  332.             CONFIG_GENERIC( "http-proxy", String , ui.httpProxyLabel, proxy );
  333.             CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, ui.ppLabel,
  334.                                     PostProcLevel );
  335.             CONFIG_GENERIC( "avi-index", IntegerList, ui.aviLabel, AviRepair );
  336.             CONFIG_GENERIC( "rtsp-tcp", Bool, NULL, RTSP_TCPBox );
  337. #ifdef WIN32
  338.             CONFIG_GENERIC( "prefer-system-codecs", Bool, NULL, systemCodecBox );
  339. #else
  340.             ui.systemCodecBox->hide();
  341. #endif
  342.             optionWidgets.append( ui.DVDDevice );
  343.             optionWidgets.append( ui.cachingCombo );
  344.             CONFIG_GENERIC( "ffmpeg-skiploopfilter", IntegerList, ui.filterLabel, loopFilterBox );
  345.             /* Caching */
  346.             /* Add the things to the ComboBox */
  347.             #define addToCachingBox( str, cachingNumber ) 
  348.                 ui.cachingCombo->addItem( qtr(str), QVariant( cachingNumber ) );
  349.             addToCachingBox( N_("Custom"), CachingCustom );
  350.             addToCachingBox( N_("Lowest latency"), CachingLowest );
  351.             addToCachingBox( N_("Low latency"), CachingLow );
  352.             addToCachingBox( N_("Normal"), CachingNormal );
  353.             addToCachingBox( N_("High latency"), CachingHigh );
  354.             addToCachingBox( N_("Higher latency"), CachingHigher );
  355.             #undef addToCachingBox
  356. #define TestCaC( name ) 
  357.     b_cache_equal =  b_cache_equal && 
  358.      ( i_cache == config_GetInt( p_intf, name ) )
  359. #define TestCaCi( name, int ) 
  360.     b_cache_equal = b_cache_equal &&  
  361.     ( ( i_cache * int ) == config_GetInt( p_intf, name ) )
  362.             /* Select the accurate value of the ComboBox */
  363.             bool b_cache_equal = true;
  364.             int i_cache = config_GetInt( p_intf, "file-caching");
  365.             TestCaC( "udp-caching" );
  366.             if (module_exists ("dvdread"))
  367.                 TestCaC( "dvdread-caching" );
  368.             if (module_exists ("dvdnav"))
  369.                 TestCaC( "dvdnav-caching" );
  370.             TestCaC( "tcp-caching" );
  371.             TestCaC( "fake-caching" ); TestCaC( "cdda-caching" );
  372.             TestCaC( "screen-caching" ); TestCaC( "vcd-caching" );
  373.             #ifdef WIN32
  374.             TestCaC( "dshow-caching" );
  375.             #else
  376.             if (module_exists ("v4l"))
  377.                 TestCaC( "v4l-caching" );
  378.             if (module_exists ("access_jack"))
  379.                 TestCaC( "jack-input-caching" );
  380.             if (module_exists ("v4l2"))
  381.                 TestCaC( "v4l2-caching" );
  382.             if (module_exists ("pvr"))
  383.                 TestCaC( "pvr-caching" );
  384.             #endif
  385.             TestCaCi( "rtsp-caching", 4 ); TestCaCi( "ftp-caching", 2 );
  386.             TestCaCi( "http-caching", 4 );
  387.             if (module_exists ("access_realrtsp"))
  388.                 TestCaCi( "realrtsp-caching", 10 );
  389.             TestCaCi( "mms-caching", 19 );
  390.             if( b_cache_equal ) ui.cachingCombo->setCurrentIndex(
  391.                 ui.cachingCombo->findData( QVariant( i_cache ) ) );
  392. #undef TestCaCi
  393. #undef TestCaC
  394.         END_SPREFS_CAT;
  395.         /*******************
  396.          * Interface Panel *
  397.          *******************/
  398.         START_SPREFS_CAT( Interface, qtr("Interface Settings") );
  399.             ui.defaultLabel->setFont( italicFont );
  400.             ui.skinsLabel->setText(
  401.                     qtr( "This is VLC's skinnable interface. You can download other skins at" )
  402.                     + QString( " <a href="http://www.videolan.org/vlc/skins.php">VLC skins website</a>." ) );
  403.             ui.skinsLabel->setFont( italicFont );
  404. #if defined( WIN32 )
  405.             CONFIG_GENERIC( "language", StringList, ui.languageLabel, language );
  406.             BUTTONACT( ui.assoButton, assoDialog() );
  407. #else
  408.             ui.language->hide();
  409.             ui.languageLabel->hide();
  410.             ui.assoName->hide();
  411.             ui.assoButton->hide();
  412. #endif
  413.             /* interface */
  414.             char *psz_intf = config_GetPsz( p_intf, "intf" );
  415.             if( psz_intf )
  416.             {
  417.                 if( strstr( psz_intf, "skin" ) )
  418.                     ui.skins->setChecked( true );
  419.                 else if( strstr( psz_intf, "qt" ) )
  420.                     ui.qt4->setChecked( true );
  421.             }
  422.             free( psz_intf );
  423.             optionWidgets.append( ui.skins );
  424.             optionWidgets.append( ui.qt4 );
  425.             CONFIG_GENERIC( "qt-display-mode", IntegerList, ui.displayLabel,
  426.                             displayModeBox );
  427.             CONFIG_GENERIC( "embedded-video", Bool, NULL, embedVideo );
  428.             CONFIG_GENERIC( "qt-fs-controller", Bool, NULL, fsController );
  429.             CONFIG_GENERIC( "qt-system-tray", Bool, NULL, systrayBox );
  430.             CONFIG_GENERIC_FILE( "skins2-last", File, ui.skinFileLabel,
  431.                                  ui.fileSkin, ui.skinBrowse );
  432.             CONFIG_GENERIC( "qt-video-autoresize", Bool, NULL, resizingBox );
  433.             CONFIG_GENERIC( "album-art", IntegerList, ui.artFetchLabel,
  434.                                                       artFetcher );
  435.             /* UPDATE options */
  436. #ifdef UPDATE_CHECK
  437.             CONFIG_GENERIC( "qt-updates-notif", Bool, NULL, updatesBox );
  438.             CONFIG_GENERIC_NO_BOOL( "qt-updates-days", Integer, NULL,
  439.                     updatesDays );
  440.             CONNECT( ui.updatesBox, toggled( bool ),
  441.                      ui.updatesDays, setEnabled( bool ) );
  442. #else
  443.             ui.updatesBox->hide();
  444.             ui.updatesDays->hide();
  445. #endif
  446.             /* ONE INSTANCE options */
  447. #if defined( WIN32 ) || defined( HAVE_DBUS ) || defined(__APPLE__)
  448.             CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
  449. #if 0
  450.             CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
  451.                     EnqueueOneInterfaceMode );
  452. #endif
  453. #else
  454.             ui.OneInterfaceBox->hide();
  455. #endif
  456.             /* RECENTLY PLAYED options */
  457.             CONNECT( ui.saveRecentlyPlayed, toggled( bool ),
  458.                      ui.recentlyPlayedFilters, setEnabled( bool ) );
  459.             ui.recentlyPlayedFilters->setEnabled( false );
  460.             CONFIG_GENERIC( "qt-recentplay", Bool, NULL, saveRecentlyPlayed );
  461.             CONFIG_GENERIC( "qt-recentplay-filter", String, ui.filterLabel,
  462.                     recentlyPlayedFilters );
  463.         END_SPREFS_CAT;
  464.         START_SPREFS_CAT( Subtitles,
  465.                             qtr("Subtitles & On Screen Display Settings") );
  466.             CONFIG_GENERIC( "osd", Bool, NULL, OSDBox);
  467.             CONFIG_GENERIC( "video-title-show", Bool, NULL, OSDTitleBox);
  468.             CONFIG_GENERIC( "subsdec-encoding", StringList, ui.encodLabel,
  469.                             encoding );
  470.             CONFIG_GENERIC( "sub-language", String, ui.subLangLabel,
  471.                             preferredLanguage );
  472.             CONFIG_GENERIC_FILE( "freetype-font", File, ui.fontLabel, ui.font,
  473.                             ui.fontBrowse );
  474.             CONFIG_GENERIC( "freetype-color", IntegerList, ui.fontColorLabel,
  475.                             fontColor );
  476.             CONFIG_GENERIC( "freetype-rel-fontsize", IntegerList,
  477.                             ui.fontSizeLabel, fontSize );
  478.             CONFIG_GENERIC( "freetype-effect", IntegerList, ui.fontEffectLabel,
  479.                             effect );
  480.             CONFIG_GENERIC_NO_BOOL( "sub-margin", Integer, ui.subsPosLabel, subsPosition );
  481.         END_SPREFS_CAT;
  482.         case SPrefsHotkeys:
  483.         {
  484.             p_config = config_FindConfig( VLC_OBJECT(p_intf), "key-fullscreen" );
  485.             QGridLayout *gLayout = new QGridLayout;
  486.             panel->setLayout( gLayout );
  487.             int line = 0;
  488.             panel_label->setText( qtr( "Configure Hotkeys" ) );
  489.             control = new KeySelectorControl( VLC_OBJECT(p_intf), p_config ,
  490.                                                 this, gLayout, line );
  491.             controls.append( control );
  492.             line++;
  493.             QFrame *sepline = new QFrame;
  494.             sepline->setFrameStyle(QFrame::HLine | QFrame::Sunken);
  495.             gLayout->addWidget( sepline, line, 0, 1, -1 );
  496.             line++;
  497.             p_config = config_FindConfig( VLC_OBJECT(p_intf), "hotkeys-mousewheel-mode" );
  498.             control = new IntegerListConfigControl( VLC_OBJECT(p_intf),
  499.                     p_config, false, this, gLayout, line );
  500.             controls.append( control );
  501.             break;
  502.         }
  503.     }
  504.     panel_layout->addWidget( panel_label );
  505.     panel_layout->addWidget( title_line );
  506.     if( small )
  507.     {
  508.         QScrollArea *scroller= new QScrollArea;
  509.         scroller->setWidget( panel );
  510.         scroller->setWidgetResizable( true );
  511.         scroller->setFrameStyle( QFrame::NoFrame );
  512.         panel_layout->addWidget( scroller );
  513.     }
  514.     else
  515.     {
  516.         panel_layout->addWidget( panel );
  517.         if( number != SPrefsHotkeys ) panel_layout->addStretch( 2 );
  518.     }
  519.     setLayout( panel_layout );
  520. #undef END_SPREFS_CAT
  521. #undef START_SPREFS_CAT
  522. #undef CONFIG_GENERIC_FILE
  523. #undef CONFIG_GENERIC_NO_BOOL
  524. #undef CONFIG_GENERIC2
  525. #undef CONFIG_GENERIC
  526. }
  527. void SPrefsPanel::updateAudioOptions( int number)
  528. {
  529.     QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
  530.                                             ->itemData( number ).toString();
  531. #ifdef WIN32
  532.     optionWidgets[directxW]->setVisible( ( value == "aout_directx" ) );
  533. #else
  534.     /* optionWidgets[ossW] can be NULL */
  535.     if( optionWidgets[ossW] )
  536.         optionWidgets[ossW]->setVisible( ( value == "oss" ) );
  537.     /* optionWidgets[alsaW] can be NULL */
  538.     if( optionWidgets[alsaW] )
  539.         optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
  540. #endif
  541.     optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
  542. }
  543. SPrefsPanel::~SPrefsPanel()
  544. {
  545.     qDeleteAll( controls ); controls.clear();
  546. }
  547. void SPrefsPanel::updateAudioVolume( int volume )
  548. {
  549.     qobject_cast<QSpinBox *>(optionWidgets[volLW])
  550.         ->setValue( volume * 100 / 256 );
  551. }
  552. /* Function called from the main Preferences dialog on each SPrefs Panel */
  553. void SPrefsPanel::apply()
  554. {
  555.     /* Generic save for ever panel */
  556.     QList<ConfigControl *>::Iterator i;
  557.     for( i = controls.begin() ; i != controls.end() ; i++ )
  558.     {
  559.         ConfigControl *c = qobject_cast<ConfigControl *>(*i);
  560.         c->doApply( p_intf );
  561.     }
  562.     switch( number )
  563.     {
  564.     case SPrefsInputAndCodecs:
  565.     {
  566.         /* Device default selection */
  567.         const char *psz_devicepath =
  568.               qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
  569.         if( !EMPTY_STR( psz_devicepath ) )
  570.         {
  571.             config_PutPsz( p_intf, "dvd", psz_devicepath );
  572.             config_PutPsz( p_intf, "vcd", psz_devicepath );
  573.             config_PutPsz( p_intf, "cd-audio", psz_devicepath );
  574.         }
  575. #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
  576. #define CaC( name ) CaCi( name, 1 )
  577.         /* Caching */
  578.         QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
  579.         int i_comboValue = cachingCombo->itemData( cachingCombo->currentIndex() ).toInt();
  580.         if( i_comboValue )
  581.         {
  582.             CaC( "udp-caching" );
  583.             if (module_exists ("dvdread" ))
  584.                 CaC( "dvdread-caching" );
  585.             if (module_exists ("dvdnav" ))
  586.                 CaC( "dvdnav-caching" );
  587.             CaC( "tcp-caching" ); CaC( "vcd-caching" );
  588.             CaC( "fake-caching" ); CaC( "cdda-caching" ); CaC( "file-caching" );
  589.             CaC( "screen-caching" ); CaC( "bd-caching" );
  590.             CaCi( "rtsp-caching", 2 ); CaCi( "ftp-caching", 2 );
  591.             CaCi( "http-caching", 2 );
  592.             if (module_exists ("access_realrtsp" ))
  593.                 CaCi( "realrtsp-caching", 10 );
  594.             CaCi( "mms-caching", 10 );
  595.             #ifdef WIN32
  596.             CaC( "dshow-caching" );
  597.             #else
  598.             if (module_exists ( "v4l" ))
  599.                 CaC( "v4l-caching" );
  600.             if (module_exists ( "access_jack" ))
  601.             CaC( "jack-input-caching" );
  602.             if (module_exists ( "v4l2" ))
  603.                 CaC( "v4l2-caching" );
  604.             if (module_exists ( "pvr" ))
  605.                 CaC( "pvr-caching" );
  606.             #endif
  607.             //CaCi( "dv-caching" ) too short...
  608.         }
  609.         break;
  610. #undef CaC
  611. #undef CaCi
  612.     }
  613.     /* Interfaces */
  614.     case SPrefsInterface:
  615.     {
  616.         if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
  617.             config_PutPsz( p_intf, "intf", "skins2" );
  618.         if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
  619.             config_PutPsz( p_intf, "intf", "qt" );
  620.         break;
  621.     }
  622.     case SPrefsAudio:
  623.     {
  624.         bool b_checked =
  625.             qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
  626.         if( b_checked && !qs_filter.contains( "volnorm" ) )
  627.             qs_filter.append( "volnorm" );
  628.         if( !b_checked && qs_filter.contains( "volnorm" ) )
  629.             qs_filter.removeAll( "volnorm" );
  630.         b_checked =
  631.             qobject_cast<QCheckBox *>(optionWidgets[headphoneB])->isChecked();
  632.         if( b_checked && !qs_filter.contains( "headphone" ) )
  633.             qs_filter.append( "headphone" );
  634.         if( !b_checked && qs_filter.contains( "headphone" ) )
  635.             qs_filter.removeAll( "headphone" );
  636.         config_PutPsz( p_intf, "audio-filter", qtu( qs_filter.join( ":" ) ) );
  637.         break;
  638.     }
  639.     }
  640. }
  641. void SPrefsPanel::clean()
  642. {}
  643. void SPrefsPanel::lastfm_Changed( int i_state )
  644. {
  645.     if( i_state == Qt::Checked )
  646.         config_AddIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
  647.     else if( i_state == Qt::Unchecked )
  648.         config_RemoveIntf( VLC_OBJECT( p_intf ), "audioscrobbler" );
  649. }
  650. #ifdef WIN32
  651. #include <QDialogButtonBox>
  652. #include <QHeaderView>
  653. #include "util/registry.hpp"
  654. bool SPrefsPanel::addType( const char * psz_ext, QTreeWidgetItem* current,
  655.                            QTreeWidgetItem* parent, QVLCRegistry *qvReg )
  656. {
  657.     bool b_temp;
  658.     const char* psz_VLC = "VLC";
  659.     current = new QTreeWidgetItem( parent, QStringList( psz_ext ) );
  660.     if( strstr( qvReg->ReadRegistryString( psz_ext, "", ""  ), psz_VLC ) )
  661.     {
  662.         current->setCheckState( 0, Qt::Checked );
  663.         b_temp = false;
  664.     }
  665.     else
  666.     {
  667.         current->setCheckState( 0, Qt::Unchecked );
  668.         b_temp = true;
  669.     }
  670.     listAsso.append( current );
  671.     return b_temp;
  672. }
  673. void SPrefsPanel::assoDialog()
  674. {
  675.     QDialog *d = new QDialog( this );
  676.     QGridLayout *assoLayout = new QGridLayout( d );
  677.     QTreeWidget *filetypeList = new QTreeWidget;
  678.     assoLayout->addWidget( filetypeList, 0, 0, 1, 4 );
  679.     filetypeList->header()->hide();
  680.     QVLCRegistry * qvReg = new QVLCRegistry( HKEY_CLASSES_ROOT );
  681.     QTreeWidgetItem *audioType = new QTreeWidgetItem( QStringList( qtr( "Audio Files" ) ) );
  682.     QTreeWidgetItem *videoType = new QTreeWidgetItem( QStringList( qtr( "Video Files" ) ) );
  683.     QTreeWidgetItem *otherType = new QTreeWidgetItem( QStringList( qtr( "Playlist Files" ) ) );
  684.     filetypeList->addTopLevelItem( audioType );
  685.     filetypeList->addTopLevelItem( videoType );
  686.     filetypeList->addTopLevelItem( otherType );
  687.     audioType->setExpanded( true ); audioType->setCheckState( 0, Qt::Unchecked );
  688.     videoType->setExpanded( true ); videoType->setCheckState( 0, Qt::Unchecked );
  689.     otherType->setExpanded( true ); otherType->setCheckState( 0, Qt::Unchecked );
  690.     QTreeWidgetItem *currentItem;
  691.     int i_temp = 0;
  692. #define aTa( name ) i_temp += addType( name, currentItem, audioType, qvReg )
  693. #define aTv( name ) i_temp += addType( name, currentItem, videoType, qvReg )
  694. #define aTo( name ) i_temp += addType( name, currentItem, otherType, qvReg )
  695.     aTa( ".a52" ); aTa( ".aac" ); aTa( ".ac3" ); aTa( ".dts" ); aTa( ".flac" );
  696.     aTa( ".m4a" ); aTa( ".m4p" ); aTa( ".mka" ); aTa( ".mod" ); aTa( ".mp1" );
  697.     aTa( ".mp2" ); aTa( ".mp3" ); aTa( ".oma" ); aTa( ".oga" ); aTa( ".spx" );
  698.     aTa( ".tta" ); aTa( ".wav" ); aTa( ".wma" ); aTa( ".xm" );
  699.     audioType->setCheckState( 0, ( i_temp > 0 ) ?
  700.                               ( ( i_temp == audioType->childCount() ) ?
  701.                                Qt::Checked : Qt::PartiallyChecked )
  702.                             : Qt::Unchecked );
  703.     i_temp = 0;
  704.     aTv( ".asf" ); aTv( ".avi" ); aTv( ".divx" ); aTv( ".dv" ); aTv( ".flv" );
  705.     aTv( ".gxf" ); aTv( ".m1v" ); aTv( ".m2v" ); aTv( ".m2ts" ); aTv( ".m4v" );
  706.     aTv( ".mkv" ); aTv( ".mov" ); aTv( ".mp2" ); aTv( ".mp4" ); aTv( ".mpeg" );
  707.     aTv( ".mpeg1" ); aTv( ".mpeg2" ); aTv( ".mpeg4" ); aTv( ".mpg" );
  708.     aTv( ".mts" ); aTv( ".mxf" );
  709.     aTv( ".ogg" ); aTv( ".ogm" ); aTv( ".ogx" ); aTv( ".ogv" );  aTv( ".ts" );
  710.     aTv( ".vob" ); aTv( ".wmv" );
  711.     videoType->setCheckState( 0, ( i_temp > 0 ) ?
  712.                               ( ( i_temp == audioType->childCount() ) ?
  713.                                Qt::Checked : Qt::PartiallyChecked )
  714.                             : Qt::Unchecked );
  715.     i_temp = 0;
  716.     aTo( ".asx" ); aTo( ".b4s" ); aTo( ".ifo" ); aTo( ".m3u" ); aTo( ".pls" ); aTo( ".vlc" );
  717.     aTo( ".xspf" );
  718.     otherType->setCheckState( 0, ( i_temp > 0 ) ?
  719.                               ( ( i_temp == audioType->childCount() ) ?
  720.                                Qt::Checked : Qt::PartiallyChecked )
  721.                             : Qt::Unchecked );
  722. #undef aTo
  723. #undef aTv
  724. #undef aTa
  725.     QDialogButtonBox *buttonBox = new QDialogButtonBox( d );
  726.     QPushButton *closeButton = new QPushButton( qtr( "&Apply" ) );
  727.     QPushButton *clearButton = new QPushButton( qtr( "&Cancel" ) );
  728.     buttonBox->addButton( closeButton, QDialogButtonBox::AcceptRole );
  729.     buttonBox->addButton( clearButton, QDialogButtonBox::ActionRole );
  730.     assoLayout->addWidget( buttonBox, 1, 2, 1, 2 );
  731.     CONNECT( closeButton, clicked(), this, saveAsso() );
  732.     CONNECT( clearButton, clicked(), d, reject() );
  733.     d->resize( 300, 400 );
  734.     d->exec();
  735.     delete d;
  736.     delete qvReg;
  737.     listAsso.clear();
  738. }
  739. void addAsso( QVLCRegistry *qvReg, const char *psz_ext )
  740. {
  741.     std::string s_path( "VLC" ); s_path += psz_ext;
  742.     std::string s_path2 = s_path;
  743.     /* Save a backup if already assigned */
  744.     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
  745.     if( psz_value && strlen( psz_value ) > 0 )
  746.         qvReg->WriteRegistryString( psz_ext, "VLC.backup", psz_value );
  747.     delete psz_value;
  748.     /* Put a "link" to VLC.EXT as default */
  749.     qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
  750.     /* Create the needed Key if they weren't done in the installer */
  751.     if( !qvReg->RegistryKeyExists( s_path.c_str() ) )
  752.     {
  753.         qvReg->WriteRegistryString( psz_ext, "", s_path.c_str() );
  754.         qvReg->WriteRegistryString( s_path.c_str(), "", "Media file" );
  755.         qvReg->WriteRegistryString( s_path.append( "\shell" ).c_str() , "", "Play" );
  756.         /* Get the installer path */
  757.         QVLCRegistry *qvReg2 = new QVLCRegistry( HKEY_LOCAL_MACHINE );
  758.         std::string str_temp; str_temp.assign(
  759.             qvReg2->ReadRegistryString( "Software\VideoLAN\VLC", "", "" ) );
  760.         if( str_temp.size() )
  761.         {
  762.             qvReg->WriteRegistryString( s_path.append( "\Play\command" ).c_str(),
  763.                 "", str_temp.append(" --started-from-file "%1"" ).c_str() );
  764.             qvReg->WriteRegistryString( s_path2.append( "\DefaultIcon" ).c_str(),
  765.                         "", str_temp.append(",0").c_str() );
  766.         }
  767.         delete qvReg2;
  768.     }
  769. }
  770. void delAsso( QVLCRegistry *qvReg, const char *psz_ext )
  771. {
  772.     char psz_VLC[] = "VLC";
  773.     char *psz_value = qvReg->ReadRegistryString( psz_ext, "", ""  );
  774.     if( psz_value && !strcmp( strcat( psz_VLC, psz_ext ), psz_value ) )
  775.     {
  776.         free( psz_value );
  777.         psz_value = qvReg->ReadRegistryString( psz_ext, "VLC.backup", "" );
  778.         if( psz_value )
  779.             qvReg->WriteRegistryString( psz_ext, "", psz_value );
  780.         qvReg->DeleteKey( psz_ext, "VLC.backup" );
  781.     }
  782.     delete( psz_value );
  783. }
  784. void SPrefsPanel::saveAsso()
  785. {
  786.     QVLCRegistry * qvReg;
  787.     for( int i = 0; i < listAsso.size(); i ++ )
  788.     {
  789.         qvReg  = new QVLCRegistry( HKEY_CLASSES_ROOT );
  790.         if( listAsso[i]->checkState( 0 ) > 0 )
  791.         {
  792.             addAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
  793.         }
  794.         else
  795.         {
  796.             delAsso( qvReg, qtu( listAsso[i]->text( 0 ) ) );
  797.         }
  798.     }
  799.     /* Gruik ? Naaah */
  800.     qobject_cast<QDialog *>(listAsso[0]->treeWidget()->parent())->accept();
  801.     delete qvReg;
  802. }
  803. #endif /* WIN32 */