Commit 72a25f19 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - SPrefs, doing funny things with qobject_cast to improve a bit the code...

parent b8836621
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include <QGroupBox> #include <QGroupBox>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QSignalMapper> #include <QSignalMapper>
QString formatTooltip(const QString & tooltip) QString formatTooltip(const QString & tooltip)
{ {
QString formatted = QString formatted =
......
...@@ -26,12 +26,7 @@ ...@@ -26,12 +26,7 @@
#include "components/simple_preferences.hpp" #include "components/simple_preferences.hpp"
#include "components/preferences_widgets.hpp" #include "components/preferences_widgets.hpp"
#include "ui/sprefs_input.h"
#include "ui/sprefs_audio.h"
#include "ui/sprefs_video.h"
#include "ui/sprefs_subtitles.h"
#include "ui/sprefs_hotkeys.h"
#include "ui/sprefs_interface.h"
#include <vlc_config_cat.h> #include <vlc_config_cat.h>
#include <vlc_configuration.h> #include <vlc_configuration.h>
...@@ -137,7 +132,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -137,7 +132,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
#define START_SPREFS_CAT( name , label ) \ #define START_SPREFS_CAT( name , label ) \
case SPrefs ## name: \ case SPrefs ## name: \
{ \ { \
Ui::SPrefs ## name ui; \ Ui::SPrefs ## name ui; \
ui.setupUi( panel ); \ ui.setupUi( panel ); \
panel_label->setText( label ); panel_label->setText( label );
...@@ -183,7 +178,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -183,7 +178,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
#ifdef WIN32 #ifdef WIN32
CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode ); CONFIG_GENERIC( "directx-wallpaper" , Bool , NULL, wallpaperMode );
CONFIG_GENERIC( "directx-device", StringList, NULL, CONFIG_GENERIC( "directx-device", StringList, NULL,
dXdisplayDevice ); dXdisplayDevice );
#else #else
ui.directXBox->setVisible( false ); ui.directXBox->setVisible( false );
#endif #endif
...@@ -204,6 +199,19 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -204,6 +199,19 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
CONFIG_GENERIC( "audio", Bool, NULL, enableAudio ); CONFIG_GENERIC( "audio", Bool, NULL, enableAudio );
/* 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();
/* General Audio Options */ /* General Audio Options */
CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL, CONFIG_GENERIC_NO_BOOL( "volume" , IntegerRangeSlider, NULL,
defaultVolume ); defaultVolume );
...@@ -225,7 +233,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -225,7 +233,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
CONNECT( ui.outputModule, currentIndexChanged( int ), this, CONNECT( ui.outputModule, currentIndexChanged( int ), this,
updateAudioOptions( int ) ); updateAudioOptions( int ) );
audioOutput = ui.outputModule;
//TODO: use modules_Exists //TODO: use modules_Exists
#ifndef WIN32 #ifndef WIN32
...@@ -239,30 +247,20 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -239,30 +247,20 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
// File exists everywhere // File exists everywhere
CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel, CONFIG_GENERIC_FILE( "audiofile-file" , File , ui.fileLabel,
fileName, fileBrowseButton ); fileName, fileBrowseButton );
alsa_options = ui.alsaControl;
oss_options = ui.OSSControl;
directx_options = ui.DirectXControl;
file_options = ui.fileControl;
/* and hide if necessary */
#ifdef WIN32
oss_options->hide();
alsa_options->hide();
#else
directx_options->hide();
#endif
updateAudioOptions( audioOutput->currentIndex() ); 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() );
/* LastFM */ /* LastFM */
CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label, CONFIG_GENERIC( "lastfm-username", String, ui.lastfm_user_label,
lastfm_user_edit ); lastfm_user_edit );
CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label, CONFIG_GENERIC( "lastfm-password", String, ui.lastfm_pass_label,
lastfm_pass_edit ); lastfm_pass_edit );
ui.lastfm_user_edit->hide();
ui.lastfm_user_label->hide();
ui.lastfm_pass_edit->hide();
ui.lastfm_pass_label->hide();
if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) ) if( config_ExistIntf( VLC_OBJECT( p_intf ), "audioscrobbler" ) )
ui.lastfm->setCheckState( Qt::Checked ); ui.lastfm->setCheckState( Qt::Checked );
...@@ -272,8 +270,9 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -272,8 +270,9 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
lastfm_Changed( int ) ); lastfm_Changed( int ) );
/* Normalizer */ /* Normalizer */
normalizerBox = ui.volNormBox;
CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin, setEnabled( bool ) ); CONNECT( ui.volNormBox, toggled( bool ), ui.volNormSpin,
setEnabled( bool ) );
qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) ); qs_filter = qfu( config_GetPsz( p_intf, "audio-filter" ) );
bool b_normalizer = ( qs_filter.contains( "volnorm" ) ); bool b_normalizer = ( qs_filter.contains( "volnorm" ) );
{ {
...@@ -285,8 +284,9 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -285,8 +284,9 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
/* Input and Codecs Panel Implementation */ /* Input and Codecs Panel Implementation */
START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") ); START_SPREFS_CAT( InputAndCodecs, qtr("Input & Codecs settings") );
inputDevice = ui.DVDDevice;
/* Disk Devices */
/* Disk Devices */
{ {
ui.DVDDevice->setToolTip( ui.DVDDevice->setToolTip(
qtr( "If this propriety is blank, then you have\n" qtr( "If this propriety is blank, then you have\n"
...@@ -308,8 +308,15 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -308,8 +308,15 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort ); CONFIG_GENERIC_NO_BOOL( "server-port", Integer, NULL, UDPPort );
CONFIG_GENERIC( "http-proxy", String , NULL, proxy ); CONFIG_GENERIC( "http-proxy", String , NULL, proxy );
/* Caching */ /* Caching */
/* CONFIG_GENERIC( );*/ //FIXME #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 );
CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel ); CONFIG_GENERIC_NO_BOOL( "ffmpeg-pp-q", Integer, NULL, PostProcLevel );
CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair ); CONFIG_GENERIC( "avi-index", IntegerList, NULL, AviRepair );
...@@ -325,13 +332,18 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -325,13 +332,18 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
ui.dumpBox->setChecked( qs_filter.contains( "dump" ) ); ui.dumpBox->setChecked( qs_filter.contains( "dump" ) );
ui.recordBox->setChecked( qs_filter.contains( "record" ) ); ui.recordBox->setChecked( qs_filter.contains( "record" ) );
ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) ); ui.bandwidthBox->setChecked( qs_filter.contains( "bandwidth" ) );
timeshiftBox = ui.timeshiftBox;
recordBox = ui.recordBox; optionWidgets.append( ui.recordBox );
dumpBox = ui.dumpBox; optionWidgets.append( ui.dumpBox );
bandwidthBox = ui.bandwidthBox; optionWidgets.append( ui.bandwidthBox );
optionWidgets.append( ui.timeshiftBox );
optionWidgets.append( ui.DVDDevice );
optionWidgets.append( ui.cachingCombo );
END_SPREFS_CAT; END_SPREFS_CAT;
/* Interface Panel */ /*******************
* Interface Panel *
*******************/
START_SPREFS_CAT( Interface, qtr("Interface settings") ); START_SPREFS_CAT( Interface, qtr("Interface settings") );
ui.defaultLabel->setFont( italicFont ); ui.defaultLabel->setFont( italicFont );
ui.skinsLabel->setFont( italicFont ); ui.skinsLabel->setFont( italicFont );
...@@ -343,7 +355,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -343,7 +355,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
ui.languageLabel->hide(); ui.languageLabel->hide();
#endif #endif
/* interface */ /* interface */
char *psz_intf = config_GetPsz( p_intf, "intf" ); char *psz_intf = config_GetPsz( p_intf, "intf" );
if( psz_intf ) if( psz_intf )
{ {
...@@ -353,14 +365,15 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -353,14 +365,15 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
else if( strstr( psz_intf, "qt" ) ) else if( strstr( psz_intf, "qt" ) )
ui.qt4->setChecked( true ); ui.qt4->setChecked( true );
} }
skinInterfaceButton = ui.skins;
qtInterfaceButton = ui.qt4;
delete psz_intf; delete psz_intf;
optionWidgets.append( ui.skins );
optionWidgets.append( ui.qt4 );
CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo ); CONFIG_GENERIC( "qt-always-video", Bool, NULL, qtAlwaysVideo );
CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin, CONFIG_GENERIC_FILE( "skins2-last", File, NULL, fileSkin,
skinBrowse ); skinBrowse );
#if defined( WIN32 ) || defined(HAVE_DBUS_3) #if defined( WIN32 ) || defined( HAVE_DBUS_3 )
CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode ); CONFIG_GENERIC( "one-instance", Bool, NULL, OneInterfaceMode );
CONFIG_GENERIC( "playlist-enqueue", Bool, NULL, CONFIG_GENERIC( "playlist-enqueue", Bool, NULL,
EnqueueOneInterfaceMode ); EnqueueOneInterfaceMode );
...@@ -388,37 +401,26 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent, ...@@ -388,37 +401,26 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
END_SPREFS_CAT; END_SPREFS_CAT;
} }
panel_layout->addWidget(panel_label); panel_layout->addWidget( panel_label );
panel_layout->addWidget(title_line); panel_layout->addWidget( title_line );
panel_layout->addWidget( panel ); panel_layout->addWidget( panel );
panel_layout->addStretch( 2 ); panel_layout->addStretch( 2 );
this->setLayout(panel_layout); setLayout( panel_layout );
} }
void SPrefsPanel::updateAudioOptions( int number) void SPrefsPanel::updateAudioOptions( int number)
{ {
QString value = audioOutput->itemData( number ).toString(); QString value = qobject_cast<QComboBox *>(optionWidgets[audioOutCoB])
->itemData( number ).toString();
#ifndef WIN32 #ifndef WIN32
oss_options->hide(); optionWidgets[ossW]->setVisible( ( value == "oss" ) );
alsa_options->hide(); optionWidgets[alsaW]->setVisible( ( value == "alsa" ) );
#else #else
directx_options->hide(); optionWidgets[directxW]->setVisible( ( value == "directx" ) );
#endif
file_options->hide();
if( value == "aout_file" )
file_options->show();
#ifndef WIN32
else if( value == "alsa" )
alsa_options->show();
else if( value == "oss" )
oss_options->show();
#else
else if( value == "directx" )
directx_options->show();
#endif #endif
optionWidgets[fileW]->setVisible( ( value == "aout_file" ) );
} }
void SPrefsPanel::apply() void SPrefsPanel::apply()
...@@ -436,7 +438,9 @@ void SPrefsPanel::apply() ...@@ -436,7 +438,9 @@ void SPrefsPanel::apply()
/* Devices */ /* Devices */
if( number == SPrefsInputAndCodecs ) if( number == SPrefsInputAndCodecs )
{ {
char *psz_devicepath = qtu( inputDevice->text() ); /* Device default selection */
char *psz_devicepath =
qtu( qobject_cast<QLineEdit *>(optionWidgets[inputLE] )->text() );
if( !EMPTY_STR( psz_devicepath ) ) if( !EMPTY_STR( psz_devicepath ) )
{ {
config_PutPsz( p_intf, "dvd", psz_devicepath ); config_PutPsz( p_intf, "dvd", psz_devicepath );
...@@ -444,7 +448,7 @@ void SPrefsPanel::apply() ...@@ -444,7 +448,7 @@ void SPrefsPanel::apply()
config_PutPsz( p_intf, "cd-audio", psz_devicepath ); config_PutPsz( p_intf, "cd-audio", psz_devicepath );
} }
bool b_first = true; /* Access filters */
#define saveBox( name, box ) {\ #define saveBox( name, box ) {\
if( box->isChecked() ) { \ if( box->isChecked() ) { \
if( b_first ) { \ if( b_first ) { \
...@@ -453,26 +457,33 @@ void SPrefsPanel::apply() ...@@ -453,26 +457,33 @@ void SPrefsPanel::apply()
} \ } \
else qs_filter.append( ":" ).append( name ); \ else qs_filter.append( ":" ).append( name ); \
} } } }
saveBox( "record", recordBox ); bool b_first = true;
saveBox( "dump", dumpBox ); saveBox( "record", qobject_cast<QCheckBox *>(optionWidgets[recordChB]) );
saveBox( "timeshift", timeshiftBox ); saveBox( "dump", qobject_cast<QCheckBox *>(optionWidgets[dumpChB]) );
saveBox( "bandwidth", bandwidthBox ); saveBox( "timeshift", qobject_cast<QCheckBox *>(optionWidgets[timeshiftChB]) );
saveBox( "bandwidth", qobject_cast<QCheckBox *>(optionWidgets[bandwidthChB] ) );
config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) ); config_PutPsz( p_intf, "access-filter", qtu( qs_filter ) );
QComboBox *cachingCombo = qobject_cast<QComboBox *>(optionWidgets[cachingCoB]);
/* Caching */
msg_Dbg( p_intf, "%i",
cachingCombo->itemData( cachingCombo->currentIndex() ).toInt() );
} }
/* Interfaces */ /* Interfaces */
if( number == SPrefsInterface ) if( number == SPrefsInterface )
{ {
if( skinInterfaceButton->isChecked() ) if( qobject_cast<QRadioButton *>(optionWidgets[skinRB])->isChecked() )
config_PutPsz( p_intf, "intf", "skins2" ); config_PutPsz( p_intf, "intf", "skins2" );
if( qtInterfaceButton->isChecked() ) if( qobject_cast<QRadioButton *>(optionWidgets[qtRB])->isChecked() )
config_PutPsz( p_intf, "intf", "qt4" ); config_PutPsz( p_intf, "intf", "qt4" );
} }
if( number == SPrefsAudio ) if( number == SPrefsAudio )
{ {
bool b_normChecked = normalizerBox->isChecked(); bool b_normChecked =
qobject_cast<QCheckBox *>(optionWidgets[normalizerChB])->isChecked();
if( qs_filter.isEmpty() ) if( qs_filter.isEmpty() )
{ {
/* the psz_filter is already empty, so we just append it needed */ /* the psz_filter is already empty, so we just append it needed */
......
...@@ -28,6 +28,13 @@ ...@@ -28,6 +28,13 @@
#include <vlc_interface.h> #include <vlc_interface.h>
#include <QWidget> #include <QWidget>
#include "ui/sprefs_input.h"
#include "ui/sprefs_audio.h"
#include "ui/sprefs_video.h"
#include "ui/sprefs_subtitles.h"
#include "ui/sprefs_hotkeys.h"
#include "ui/sprefs_interface.h"
enum { enum {
SPrefsInterface = 0, SPrefsInterface = 0,
SPrefsAudio, SPrefsAudio,
...@@ -39,6 +46,19 @@ enum { ...@@ -39,6 +46,19 @@ enum {
}; };
#define SPrefsDefaultCat SPrefsInterface #define SPrefsDefaultCat SPrefsInterface
enum {
CachingCustom = 0,
CachingLowest = 100,
CachingLow = 200,
CachingNormal = 300,
CachingHigh = 400,
CachingHigher = 500
};
enum { alsaW = 0, ossW, directxW, fileW, audioOutCoB, normalizerChB };
enum { recordChB, dumpChB, bandwidthChB, timeshiftChB, inputLE, cachingCoB };
enum { skinRB, qtRB };
class ConfigControl; class ConfigControl;
class QComboBox; class QComboBox;
class QLineEdit; class QLineEdit;
...@@ -74,18 +94,8 @@ private: ...@@ -74,18 +94,8 @@ private:
int number; int number;
/* this is ugly and bad until I found a new solution */ QList<QWidget *> optionWidgets;
QWidget *alsa_options;
QWidget *oss_options;
QWidget *directx_options;
QWidget *file_options;
QComboBox *audioOutput;
QLineEdit *inputDevice;
QRadioButton *skinInterfaceButton;
QRadioButton *qtInterfaceButton;
QString qs_filter; QString qs_filter;
QCheckBox *normalizerBox;
QCheckBox *recordBox, *dumpBox, *bandwidthBox, *timeshiftBox;
/* Display only the options for the selected audio output */ /* Display only the options for the selected audio output */
private slots: private slots:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment