File indexing completed on 2024-05-05 04:51:46

0001 /*
0002     SPDX-FileCopyrightText: 1998-2009 Sebastian Trueg <trueg@k3b.org>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "k3bmovixoptionswidget.h"
0007 #include "k3bmovixdoc.h"
0008 #include "k3bmovixprogram.h"
0009 
0010 #include <KConfig>
0011 #include <KComboBox>
0012 #include <KLocalizedString>
0013 
0014 #include <QDebug>
0015 #include <QLocale>
0016 #include <QMap>
0017 #include <QStringList>
0018 #include <QCheckBox>
0019 #include <QLabel>
0020 #include <QSpinBox>
0021 
0022 
0023 class K3b::MovixOptionsWidget::LanguageSelectionHelper
0024 {
0025 public:
0026     LanguageSelectionHelper( QComboBox* box )
0027         : m_box(box) {
0028     }
0029 
0030     void insertLanguages( const QStringList& langs ) {
0031         m_box->clear();
0032         m_langMap.clear();
0033 
0034         for( QStringList::const_iterator it = langs.begin(); it != langs.end(); ++it ) {
0035             if( *it == i18n("default") )
0036                 m_box->addItem( *it );
0037             else {
0038                 m_langMap[m_box->count()] = *it;
0039                 m_indexMap[*it] = m_box->count();
0040                 m_box->addItem( QLocale( *it ).nativeLanguageName() );
0041             }
0042         }
0043     }
0044 
0045     QString selectedLanguage() const {
0046         if( m_box->currentIndex() == 0 )
0047             return i18n("default");
0048         else
0049             return m_langMap[m_box->currentIndex()];
0050     }
0051 
0052     void setLanguage( const QString& l ) {
0053         QMap<QString,int>::const_iterator it = m_indexMap.constFind(l);
0054         if( it == m_indexMap.constEnd() )
0055             m_box->setCurrentIndex( 0 );
0056         else
0057             m_box->setCurrentIndex( *it );
0058     }
0059 
0060 private:
0061     QComboBox* m_box;
0062     QMap<int,QString> m_langMap;
0063     QMap<QString,int> m_indexMap;
0064 };
0065 
0066 
0067 K3b::MovixOptionsWidget::MovixOptionsWidget( QWidget* parent )
0068     : QWidget( parent )
0069 {
0070     setupUi( this );
0071     m_keyboardLangHelper = new LanguageSelectionHelper( m_comboKeyboardLayout );
0072     m_helpLangHelper = new LanguageSelectionHelper( m_comboBootMessageLanguage );
0073 }
0074 
0075 
0076 K3b::MovixOptionsWidget::~MovixOptionsWidget()
0077 {
0078     delete m_keyboardLangHelper;
0079     delete m_helpLangHelper;
0080 }
0081 
0082 
0083 void K3b::MovixOptionsWidget::init( const K3b::MovixBin* bin )
0084 {
0085     m_labelAudioBackground->setVisible( bin->hasFeature( "newfiles" ) );
0086     m_comboAudioBackground->setVisible( bin->hasFeature( "newfiles" ) );
0087     m_labelKeyboardLayout->setVisible( bin->hasFeature( "newfiles" ) );
0088     m_comboKeyboardLayout->setVisible( bin->hasFeature( "newfiles" ) );
0089 
0090     qDebug() << bin->supportedSubtitleFonts();
0091     m_comboSubtitleFontset->addItems( bin->supportedSubtitleFonts() );
0092     m_helpLangHelper->insertLanguages( bin->supportedLanguages() );
0093     m_comboDefaultBootLabel->addItems( bin->supportedBootLabels() );
0094     m_keyboardLangHelper->insertLanguages( bin->supportedKbdLayouts() );
0095     m_comboAudioBackground->addItems( bin->supportedBackgrounds() );
0096 }
0097 
0098 
0099 void K3b::MovixOptionsWidget::readSettings( K3b::MovixDoc* doc )
0100 {
0101     if ( doc->subtitleFontset().isEmpty() )
0102         m_comboSubtitleFontset->setCurrentIndex( 0 );
0103     else
0104         m_comboSubtitleFontset->setCurrentItem( doc->subtitleFontset(), false );
0105 
0106     if ( doc->defaultBootLabel().isEmpty() )
0107         m_comboDefaultBootLabel->setCurrentIndex( 0 );
0108     else
0109         m_comboDefaultBootLabel->setCurrentItem( doc->defaultBootLabel(), false );
0110 
0111     if ( doc->audioBackground().isEmpty() )
0112         m_comboAudioBackground->setCurrentIndex( 0 );
0113     else
0114         m_comboAudioBackground->setCurrentItem( doc->audioBackground(), false );
0115 
0116     m_spinLoop->setValue( doc->loopPlaylist() );
0117     m_editAdditionalMplayerOptions->setText( doc->additionalMPlayerOptions() );
0118     m_editUnwantedMplayerOptions->setText( doc->unwantedMPlayerOptions() );
0119     m_helpLangHelper->setLanguage( doc->bootMessageLanguage() );
0120     m_keyboardLangHelper->setLanguage( doc->keyboardLayout() );
0121     m_checkShutdown->setChecked( doc->shutdown() );
0122     m_checkReboot->setChecked( doc->reboot() );
0123     m_checkEject->setChecked( doc->ejectDisk() );
0124     m_checkRandomPlay->setChecked( doc->randomPlay() );
0125     m_checkNoDma->setChecked( doc->noDma() );
0126 }
0127 
0128 
0129 void K3b::MovixOptionsWidget::saveSettings( K3b::MovixDoc* doc )
0130 {
0131     doc->setShutdown( m_checkShutdown->isChecked() );
0132     doc->setReboot( m_checkReboot->isChecked() );
0133     doc->setEjectDisk( m_checkEject->isChecked() );
0134     doc->setSubtitleFontset( m_comboSubtitleFontset->currentText() );
0135     doc->setBootMessageLanguage( m_helpLangHelper->selectedLanguage() );
0136     doc->setDefaultBootLabel( m_comboDefaultBootLabel->currentText() );
0137     doc->setKeyboardLayout( m_keyboardLangHelper->selectedLanguage() );
0138     doc->setAudioBackground( m_comboAudioBackground->currentText() );
0139     doc->setAdditionalMPlayerOptions( m_editAdditionalMplayerOptions->text() );
0140     doc->setUnwantedMPlayerOptions( m_editUnwantedMplayerOptions->text() );
0141     doc->setLoopPlaylist( m_spinLoop->value() );
0142     doc->setRandomPlay( m_checkRandomPlay->isChecked() );
0143     doc->setNoDma( m_checkNoDma->isChecked() );
0144 }
0145 
0146 
0147 void K3b::MovixOptionsWidget::loadConfig( const KConfigGroup & c )
0148 {
0149     QString s = c.readEntry("subtitle_fontset");
0150     if( !s.isEmpty() && s != "none" && m_comboSubtitleFontset->contains(s) )
0151         m_comboSubtitleFontset->setCurrentItem( s, false );
0152     else
0153         m_comboSubtitleFontset->setCurrentIndex( 0 ); // none
0154 
0155     m_spinLoop->setValue( c.readEntry("loop", 1 ) );
0156     m_editAdditionalMplayerOptions->setText( c.readEntry( "additional_mplayer_options" ) );
0157     m_editUnwantedMplayerOptions->setText( c.readEntry( "unwanted_mplayer_options" ) );
0158 
0159     s = c.readEntry("boot_message_language");
0160     m_helpLangHelper->setLanguage( s == "default" ? QString() : s );
0161 
0162     s = c.readEntry( "default_boot_label" );
0163     if( !s.isEmpty() && s != "default" && m_comboDefaultBootLabel->contains(s) )
0164         m_comboDefaultBootLabel->setCurrentItem( s, false );
0165     else
0166         m_comboDefaultBootLabel->setCurrentIndex( 0 );  // default
0167 
0168     s = c.readEntry("audio_background");
0169     if( !s.isEmpty() && s != "default" && m_comboAudioBackground->contains(s) )
0170         m_comboAudioBackground->setCurrentItem( s, false );
0171     else
0172         m_comboAudioBackground->setCurrentIndex( 0 ); // default
0173 
0174     s = c.readEntry("keyboard_layout");
0175     m_keyboardLangHelper->setLanguage( s == "default" ? QString() : s );
0176 
0177     m_checkShutdown->setChecked( c.readEntry( "shutdown", false) );
0178     m_checkReboot->setChecked( c.readEntry( "reboot", false ) );
0179     m_checkEject->setChecked( c.readEntry( "eject", false ) );
0180     m_checkRandomPlay->setChecked( c.readEntry( "random_play", false ) );
0181     m_checkNoDma->setChecked( c.readEntry( "no_dma", false ) );
0182 }
0183 
0184 
0185 void K3b::MovixOptionsWidget::saveConfig( KConfigGroup c )
0186 {
0187     if( m_comboSubtitleFontset->currentIndex() == 0 )
0188         c.writeEntry( "subtitle_fontset", "none" );
0189     else
0190         c.writeEntry( "subtitle_fontset", m_comboSubtitleFontset->currentText() );
0191 
0192     c.writeEntry( "loop", m_spinLoop->value() );
0193     c.writeEntry( "additional_mplayer_options", m_editAdditionalMplayerOptions->text() );
0194     c.writeEntry( "unwanted_mplayer_options", m_editUnwantedMplayerOptions->text() );
0195 
0196     if( m_comboBootMessageLanguage->currentIndex() == 0 )
0197         c.writeEntry( "boot_message_language", "default" );
0198     else
0199         c.writeEntry( "boot_message_language", m_helpLangHelper->selectedLanguage() );
0200 
0201     if( m_comboDefaultBootLabel->currentIndex() == 0 )
0202         c.writeEntry( "default_boot_label", "default" );
0203     else
0204         c.writeEntry( "default_boot_label", m_comboDefaultBootLabel->currentText() );
0205 
0206     if( m_comboAudioBackground->currentIndex() == 0 )
0207         c.writeEntry( "audio_background", "default" );
0208     else
0209         c.writeEntry( "audio_background", m_comboAudioBackground->currentText() );
0210 
0211     if( m_comboKeyboardLayout->currentIndex() == 0 )
0212         c.writeEntry( "keyboard_layout", "default" );
0213     else
0214         c.writeEntry( "keyboard_layout", m_keyboardLangHelper->selectedLanguage() );
0215 
0216     c.writeEntry( "shutdown", m_checkShutdown->isChecked() );
0217     c.writeEntry( "reboot", m_checkReboot->isChecked() );
0218     c.writeEntry( "eject", m_checkEject->isChecked() );
0219     c.writeEntry( "random_play", m_checkRandomPlay->isChecked() );
0220     c.writeEntry( "no_dma", m_checkNoDma->isChecked() );
0221 }
0222 
0223 #include "moc_k3bmovixoptionswidget.cpp"