| 1 | #include "soundconf.h" |
| 2 | #include "qtermconfig.h" |
| 3 | #include "qtermsound.h" |
| 4 | #include "qtermglobal.h" |
| 5 | #include "qterm.h" |
| 6 | |
| 7 | #include <QMessageBox> |
| 8 | #include <QFileDialog> |
| 9 | namespace QTerm |
| 10 | { |
| 11 | //extern QString getOpenFileName(const QString&, QWidget*); |
| 12 | |
| 13 | /* |
| 14 | * Constructs a fSoundConf which is a child of 'parent', with the |
| 15 | * name 'name' and widget flags set to 'f' |
| 16 | * |
| 17 | * The dialog will by default be modeless, unless you set 'modal' to |
| 18 | * TRUE to construct a modal dialog. |
| 19 | */ |
| 20 | soundConf::soundConf( QWidget* parent, Qt::WindowFlags fl ) |
| 21 | : QDialog( parent, fl ),bgMethod(this) |
| 22 | { |
| 23 | ui.setupUi(this); |
| 24 | bgMethod.addButton(ui.radioButton1,0); |
| 25 | bgMethod.addButton(ui.radioButton2,1); |
| 26 | bgMethod.addButton(ui.radioButton3,2); |
| 27 | bgMethod.addButton(ui.radioButton4,3); |
| 28 | m_pSound = NULL; |
| 29 | loadSetting(); |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * Destroys the object and frees any allocated resources |
| 34 | */ |
| 35 | soundConf::~soundConf() |
| 36 | { |
| 37 | // no need to delete child widgets, Qt does it all for us |
| 38 | delete m_pSound; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * public slot |
| 43 | */ |
| 44 | void soundConf::onSelectFile() |
| 45 | { |
| 46 | QString soundfile = QFileDialog::getOpenFileName( this, "Choose a file", QDir::currentPath(), "*" ); |
| 47 | if ( !soundfile.isNull() ) { |
| 48 | ui.leFile->setText(soundfile); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * public slot |
| 54 | */ |
| 55 | void soundConf::onSelectProg() |
| 56 | { |
| 57 | QString progfile = QFileDialog::getOpenFileName( this, "Choose a program", QDir::currentPath(), "*" ); |
| 58 | if ( !progfile.isEmpty() ) { |
| 59 | ui.leFile->setText(progfile); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * public slot |
| 65 | */ |
| 66 | void soundConf::onPlayMethod( int id ) |
| 67 | { |
| 68 | #ifdef _NO_ARTS_COMPILED |
| 69 | if (id == 1){ |
| 70 | QMessageBox::critical(this, tr("No such output driver"), |
| 71 | tr("ARTS is not supported by this instance of QTerm,\nCheck whether your ARTS support is enabled in compile time."), |
| 72 | tr("&OK")); |
| 73 | bgMethod.button(3)->setChecked(true); |
| 74 | // QRadioButton * tmp = static_cast<QRadioButton *>(bgMethod->find(3)); |
| 75 | // tmp->setChecked(true); |
| 76 | } |
| 77 | #endif |
| 78 | #ifdef _NO_ESD_COMPILED |
| 79 | if (id == 2){ |
| 80 | QMessageBox::critical(this, tr("No such output driver"), |
| 81 | tr("ESD is not supported by this instance of QTerm,\nCheck whether your ESD support is enabled in compile time"), |
| 82 | tr("&OK")); |
| 83 | // QRadioButton * tmp = static_cast<QRadioButton *>(bgMethod->find(3)); |
| 84 | // tmp->setChecked(true); |
| 85 | bgMethod.button(3)->setChecked(true); |
| 86 | } |
| 87 | #endif |
| 88 | if(id == 3 || bgMethod.checkedId() == 3) |
| 89 | { |
| 90 | ui.leProg->setEnabled(true); |
| 91 | ui.bpSelect->setEnabled(true); |
| 92 | } |
| 93 | else if(id==0 || id==1 || id==2) |
| 94 | { |
| 95 | ui.leProg->setEnabled(false); |
| 96 | ui.bpSelect->setEnabled(false); |
| 97 | } |
| 98 | } |
| 99 | void soundConf::onTestPlay() |
| 100 | { |
| 101 | if (ui.leFile->text().isEmpty()) |
| 102 | QMessageBox::critical(this, tr("No sound file"), |
| 103 | tr("You have to select a file to test the sound"), |
| 104 | tr("&Ok")); |
| 105 | |
| 106 | switch (bgMethod.checkedId()) { |
| 107 | case 0: |
| 108 | m_pSound = new InternalSound(ui.leFile->text()); |
| 109 | break; |
| 110 | case 1: |
| 111 | /* |
| 112 | #ifndef _NO_ARTS_COMPILED |
| 113 | m_pSound = new QTermArtsSound(leFile->text()); |
| 114 | #endif |
| 115 | break; |
| 116 | case 2: |
| 117 | #ifndef _NO_ESD_COMPILED |
| 118 | m_pSound = new QTermEsdSound(leFile->text()); |
| 119 | #endif*/ |
| 120 | break; |
| 121 | case 3: |
| 122 | if (ui.leProg->text().isEmpty()) |
| 123 | QMessageBox::critical(this, tr("No player"), |
| 124 | tr("You have to specify an external player"), |
| 125 | tr("&Ok")); |
| 126 | else |
| 127 | m_pSound = new ExternalSound(ui.leProg->text(), ui.leFile->text()); |
| 128 | break; |
| 129 | default: |
| 130 | m_pSound = NULL; |
| 131 | } |
| 132 | if (m_pSound) |
| 133 | m_pSound->play(); |
| 134 | delete m_pSound; |
| 135 | m_pSound = NULL; |
| 136 | } |
| 137 | |
| 138 | void soundConf::loadSetting() |
| 139 | { |
| 140 | QString strTmp; |
| 141 | |
| 142 | strTmp = Global::instance()->fileCfg()->getItemValue("preference", "wavefile"); |
| 143 | if (!strTmp.isEmpty()) |
| 144 | ui.leFile->setText( strTmp ); |
| 145 | |
| 146 | strTmp = Global::instance()->fileCfg()->getItemValue("preference", "playmethod"); |
| 147 | if (!strTmp.isEmpty()){ |
| 148 | bgMethod.button(strTmp.toInt())->setChecked(true); |
| 149 | if (strTmp.toInt() != 3) { |
| 150 | ui.leProg->setEnabled(false); |
| 151 | ui.bpSelect->setEnabled(false); |
| 152 | } |
| 153 | else { |
| 154 | strTmp = Global::instance()->fileCfg()->getItemValue("preference", "externalplayer"); |
| 155 | if (!strTmp.isEmpty()) |
| 156 | ui.leProg->setText( strTmp ); |
| 157 | } |
| 158 | } |
| 159 | else { |
| 160 | ui.leProg->setEnabled(false); |
| 161 | ui.bpSelect->setEnabled(false); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | void soundConf::saveSetting() |
| 166 | { |
| 167 | QString strTmp; |
| 168 | |
| 169 | Global::instance()->fileCfg()->setItemValue("preference", "beep", "2"); |
| 170 | |
| 171 | Global::instance()->fileCfg()->setItemValue("preference", "wavefile", ui.leFile->text()); |
| 172 | |
| 173 | strTmp.setNum(bgMethod.checkedId()); |
| 174 | Global::instance()->fileCfg()->setItemValue("preference", "playmethod", strTmp); |
| 175 | |
| 176 | if (strTmp == "3") |
| 177 | Global::instance()->fileCfg()->setItemValue("preference", "externalplayer", ui.leProg->text()); |
| 178 | |
| 179 | Global::instance()->fileCfg()->save(); |
| 180 | } |
| 181 | |
| 182 | void soundConf::accept() |
| 183 | { |
| 184 | saveSetting(); |
| 185 | QDialog::accept(); |
| 186 | } |
| 187 | |
| 188 | } // namespace QTerm |
| 189 | |
| 190 | #include <moc_soundconf.cpp> |