File indexing completed on 2024-05-19 04:52:40
0001 /* 0002 SPDX-FileCopyrightText: 2010 Michal Malek <michalm@jabster.pl> 0003 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "k3bsoxencoderconfigwidget.h" 0009 #include "k3bsoxencoderdefaults.h" 0010 0011 #include <KConfigGroup> 0012 #include <KSharedConfig> 0013 0014 K3B_EXPORT_PLUGIN_CONFIG_WIDGET( kcm_k3bsoxencoder, K3bSoxEncoderConfigWidget ) 0015 0016 K3bSoxEncoderConfigWidget::K3bSoxEncoderConfigWidget(QObject *parent, const KPluginMetaData& metaData, const QVariantList& args ) 0017 : K3b::PluginConfigWidget( parent, metaData, args ) 0018 { 0019 setupUi( widget() ); 0020 m_editSamplerate->setValidator( new QIntValidator( m_editSamplerate ) ); 0021 0022 connect( m_checkManual, SIGNAL(toggled(bool)), this, SLOT(changed()) ); 0023 connect( m_comboChannels, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()) ); 0024 connect( m_editSamplerate, SIGNAL(textChanged(QString)), this, SLOT(changed()) ); 0025 connect( m_comboSize, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()) ); 0026 connect( m_comboEncoding, SIGNAL(currentIndexChanged(int)), this, SLOT(changed()) ); 0027 } 0028 0029 0030 K3bSoxEncoderConfigWidget::~K3bSoxEncoderConfigWidget() 0031 { 0032 } 0033 0034 0035 void K3bSoxEncoderConfigWidget::load() 0036 { 0037 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0038 KConfigGroup grp( config, QStringLiteral("K3bSoxEncoderPlugin") ); 0039 0040 m_checkManual->setChecked( grp.readEntry( "manual settings", DEFAULT_MANUAL_SETTINGS ) ); 0041 setChannels( grp.readEntry( "channels", DEFAULT_CHANNELS ) ); 0042 m_editSamplerate->setText( QString::number( grp.readEntry( "samplerate", DEFAULT_SAMPLE_RATE ) ) ); 0043 setDataEncoding( grp.readEntry( "data encoding", DEFAULT_DATA_ENCODING ) ); 0044 setDataSize( grp.readEntry( "data size", DEFAULT_DATA_SIZE ) ); 0045 } 0046 0047 0048 void K3bSoxEncoderConfigWidget::save() 0049 { 0050 KSharedConfig::Ptr config = KSharedConfig::openConfig(); 0051 KConfigGroup grp( config, QStringLiteral("K3bSoxEncoderPlugin") ); 0052 0053 grp.writeEntry( "manual settings", m_checkManual->isChecked() ); 0054 grp.writeEntry( "channels", getChannels() ); 0055 grp.writeEntry( "data size", getDataSize() ); 0056 grp.writeEntry( "samplerate", m_editSamplerate->text().toInt() ); 0057 grp.writeEntry( "data encoding", getDataEncoding() ); 0058 } 0059 0060 0061 void K3bSoxEncoderConfigWidget::defaults() 0062 { 0063 m_checkManual->setChecked( DEFAULT_MANUAL_SETTINGS ); 0064 setChannels( DEFAULT_CHANNELS ); 0065 m_editSamplerate->setText( QString::number( DEFAULT_SAMPLE_RATE ) ); 0066 setDataEncoding( DEFAULT_DATA_ENCODING ); 0067 setDataSize( DEFAULT_DATA_SIZE ); 0068 setNeedsSave( true ); 0069 } 0070 0071 0072 void K3bSoxEncoderConfigWidget::setChannels( int channels ) 0073 { 0074 m_comboChannels->setCurrentIndex( channels == 4 ? 2 : channels-1 ); 0075 } 0076 0077 0078 int K3bSoxEncoderConfigWidget::getChannels() const 0079 { 0080 if( m_comboChannels->currentIndex() == 0 ) 0081 return 1; 0082 else if( m_comboChannels->currentIndex() == 2 ) 0083 return 4; 0084 else 0085 return 2; 0086 } 0087 0088 0089 void K3bSoxEncoderConfigWidget::setDataSize( int size ) 0090 { 0091 m_comboSize->setCurrentIndex( size == 8 ? 0 : ( size == 32 ? 2 : 1 ) ); 0092 } 0093 0094 0095 int K3bSoxEncoderConfigWidget::getDataSize() const 0096 { 0097 if( m_comboSize->currentIndex() == 0 ) 0098 return 8; 0099 else if( m_comboSize->currentIndex() == 2 ) 0100 return 32; 0101 else 0102 return 16; 0103 } 0104 0105 0106 void K3bSoxEncoderConfigWidget::setDataEncoding( const QString& encoding ) 0107 { 0108 if( encoding == "unsigned" ) 0109 m_comboEncoding->setCurrentIndex(1); 0110 else if( encoding == "u-law" ) 0111 m_comboEncoding->setCurrentIndex(2); 0112 else if( encoding == "A-law" ) 0113 m_comboEncoding->setCurrentIndex(3); 0114 else if( encoding == "ADPCM" ) 0115 m_comboEncoding->setCurrentIndex(4); 0116 else if( encoding == "IMA_ADPCM" ) 0117 m_comboEncoding->setCurrentIndex(5); 0118 else if( encoding == "GSM" ) 0119 m_comboEncoding->setCurrentIndex(6); 0120 else if( encoding == "Floating-point" ) 0121 m_comboEncoding->setCurrentIndex(7); 0122 else 0123 m_comboEncoding->setCurrentIndex(0); 0124 } 0125 0126 0127 QString K3bSoxEncoderConfigWidget::getDataEncoding() const 0128 { 0129 switch( m_comboEncoding->currentIndex() ) { 0130 case 1: return "unsigned"; 0131 case 2: return "u-law"; 0132 case 3: return "A-law"; 0133 case 4: return "ADPCM"; 0134 case 5: return "IMA_ADPCM"; 0135 case 6: return "GSM"; 0136 case 7: return "Floating-point"; 0137 default: return "signed"; 0138 } 0139 } 0140 0141 #include "k3bsoxencoderconfigwidget.moc" 0142 0143 #include "moc_k3bsoxencoderconfigwidget.cpp"