diff --git a/fscomm/FSComm.pro b/fscomm/FSComm.pro index eff26066b0..14df1e4c1a 100644 --- a/fscomm/FSComm.pro +++ b/fscomm/FSComm.pro @@ -26,12 +26,14 @@ SOURCES += main.cpp \ fshost.cpp \ call.cpp \ mod_qsettings/mod_qsettings.cpp \ - prefdialog.cpp + prefdialog.cpp \ + prefportaudio.cpp HEADERS += mainwindow.h \ fshost.h \ call.h \ mod_qsettings/mod_qsettings.h \ - prefdialog.h + prefdialog.h \ + prefportaudio.h FORMS += mainwindow.ui \ prefdialog.ui RESOURCES += resources.qrc diff --git a/fscomm/conf/portaudio.conf.xml b/fscomm/conf/portaudio.conf.xml index 41b9f44a0d..8bffb84d6d 100644 --- a/fscomm/conf/portaudio.conf.xml +++ b/fscomm/conf/portaudio.conf.xml @@ -2,10 +2,11 @@
- + + - - + + diff --git a/fscomm/prefdialog.cpp b/fscomm/prefdialog.cpp index 3dc2ca9acd..8b537ec0b7 100644 --- a/fscomm/prefdialog.cpp +++ b/fscomm/prefdialog.cpp @@ -1,6 +1,7 @@ #include #include "prefdialog.h" #include "ui_prefdialog.h" +#include "prefportaudio.h" PrefDialog::PrefDialog(QWidget *parent) : QDialog(parent), @@ -8,8 +9,10 @@ PrefDialog::PrefDialog(QWidget *parent) : { ui->setupUi(this); _settings = new QSettings(); - connect(this, SIGNAL(accepted()), this, SLOT(configAccepted())); - getPaDevlist(); + connect(this, SIGNAL(accepted()), this, SLOT(writeConfig())); + + _mod_portaudio = new PrefPortaudio(ui, this); + readConfig(); } PrefDialog::~PrefDialog() @@ -17,127 +20,9 @@ PrefDialog::~PrefDialog() delete ui; } -void PrefDialog::configAccepted() -{ - _settings->beginGroup("FreeSWITCH/conf"); - - _settings->beginGroup("portaudio.conf"); - _settings->setValue("cid-name", ui->PaCallerIdNameEdit->text()); - _settings->setValue("cid-num", ui->PaCallerIdNumEdit->text()); - _settings->setValue("indev", ui->PaIndevCombo->currentIndex()); - _settings->setValue("outdev", ui->PaOutdevCombo->currentIndex()); - _settings->setValue("ringdev", ui->PaRingdevCombo->currentIndex()); - _settings->setValue("ring-file", ui->PaRingFileEdit->text()); - _settings->setValue("ring-interval", ui->PaRingIntervalSpin->value()); - _settings->setValue("hold-file", ui->PaHoldFileEdit->text()); - _settings->endGroup(); - - _settings->endGroup(); - -} - -void PrefDialog::getPaDevlist() -{ - QString result; - int errorLine, errorColumn; - QString errorMsg; - - if (g_FSHost.sendCmd("pa", "devlist xml", &result) != SWITCH_STATUS_SUCCESS) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error querying audio devices."), - QMessageBox::Ok); - return; - } - - if (!_xmlPaDevList.setContent(result, &errorMsg, &errorLine, &errorColumn)) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist.\n%1 (Line:%2, Col:%3).").arg(errorMsg, - errorLine, - errorColumn), - QMessageBox::Ok); - return; - } - QDomElement root = _xmlPaDevList.documentElement(); - if (root.tagName() != "xml") - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist. Root tag is not ."), - QMessageBox::Ok); - return; - } - QDomElement devices = root.firstChildElement("devices"); - if (devices.isNull()) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist. There is no tag."), - QMessageBox::Ok); - return; - } - - QDomElement child = devices.firstChildElement(); - if (child.isNull()) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist. There is no tag."), - QMessageBox::Ok); - return; - } - - while (!child.isNull()) - { - if (child.tagName() == "device") - { - QString id, name, inputs, outputs; - id = child.attribute("id","-1"); - name = child.attribute("name","Null"); - inputs = child.attribute("inputs","0"); - outputs = child.attribute("outputs","0"); - if (inputs.toInt() != 0) - ui->PaIndevCombo->addItem(name,inputs.toInt()); - if (outputs.toInt() != 0) - { - ui->PaOutdevCombo->addItem(name,inputs.toInt()); - ui->PaRingdevCombo->addItem(name,inputs.toInt()); - } - } - child = child.nextSiblingElement(); - } - - QDomElement bindings = root.firstChildElement("bindings"); - if (bindings.isNull()) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist. There is no tag."), - QMessageBox::Ok); - return; - } - - child = devices.firstChildElement(); - if (child.isNull()) - { - QMessageBox::critical(this, tr("PortAudio error" ), - tr("Error parsing output xml from pa devlist. There are no bindings."), - QMessageBox::Ok); - return; - } - - while (!child.isNull()) - { - QString id; - id = child.attribute("device","-1"); - - if (child.tagName() == "ring") - ui->PaRingdevCombo->setCurrentIndex(id.toInt()); - else if (child.tagName() == "input") - ui->PaIndevCombo->setCurrentIndex(id.toInt()); - else if (child.tagName() == "ring") - ui->PaOutdevCombo->setCurrentIndex(id.toInt()); - - child = child.nextSiblingElement(); - } - +void PrefDialog::writeConfig() +{ + _mod_portaudio->writeConfig(); } void PrefDialog::changeEvent(QEvent *e) @@ -151,3 +36,8 @@ void PrefDialog::changeEvent(QEvent *e) break; } } + +void PrefDialog::readConfig() +{ + _mod_portaudio->readConfig(); +} diff --git a/fscomm/prefdialog.h b/fscomm/prefdialog.h index 913ced9d52..d22712e3f1 100644 --- a/fscomm/prefdialog.h +++ b/fscomm/prefdialog.h @@ -6,6 +6,8 @@ #include #include +class PrefPortaudio; + namespace Ui { class PrefDialog; } @@ -20,13 +22,14 @@ protected: void changeEvent(QEvent *e); private slots: - void configAccepted(); + void writeConfig(); private: - void getPaDevlist(void); - Ui::PrefDialog *ui; - QDomDocument _xmlPaDevList; + void readConfig(); QSettings *_settings; + Ui::PrefDialog *ui; + PrefPortaudio *_mod_portaudio; }; + #endif // PREFDIALOG_H diff --git a/fscomm/prefportaudio.cpp b/fscomm/prefportaudio.cpp new file mode 100644 index 0000000000..7a4c3c4e22 --- /dev/null +++ b/fscomm/prefportaudio.cpp @@ -0,0 +1,144 @@ +#include +#include +#include "prefportaudio.h" + +PrefPortaudio::PrefPortaudio(Ui::PrefDialog *ui, QObject *parent) : + QObject(parent), + _ui(ui) +{ + _settings = new QSettings(); +} + +void PrefPortaudio::writeConfig() +{ + _settings->beginGroup("FreeSWITCH/conf"); + _settings->beginGroup("portaudio.conf"); + _settings->setValue("cid-name", _ui->PaCallerIdNameEdit->text()); + _settings->setValue("cid-num", _ui->PaCallerIdNumEdit->text()); + _settings->setValue("indev", _ui->PaIndevCombo->currentIndex()); + _settings->setValue("outdev", _ui->PaOutdevCombo->currentIndex()); + _settings->setValue("ringdev", _ui->PaRingdevCombo->currentIndex()); + _settings->setValue("ring-file", _ui->PaRingFileEdit->text()); + _settings->setValue("ring-interval", _ui->PaRingIntervalSpin->value()); + _settings->setValue("hold-file", _ui->PaHoldFileEdit->text()); + _settings->endGroup(); + _settings->endGroup(); +} + +void PrefPortaudio::readConfig() +{ + getPaDevlist(); + _settings->beginGroup("FreeSWITCH/conf"); + + _settings->beginGroup("portaudio.conf"); + _ui->PaCallerIdNameEdit->setText(_settings->value("cid-name").toString()); + _ui->PaCallerIdNumEdit->setText(_settings->value("cid-num").toString()); + _ui->PaHoldFileEdit->setText(_settings->value("hold-file").toString()); + _ui->PaRingFileEdit->setText(_settings->value("ring-file").toString()); + _ui->PaRingIntervalSpin->setValue(_settings->value("ring-interval").toInt()); + _settings->endGroup(); + + _settings->endGroup(); +} + +void PrefPortaudio::getPaDevlist() +{ + QString result; + int errorLine, errorColumn; + QString errorMsg; + + if (g_FSHost.sendCmd("pa", "devlist xml", &result) != SWITCH_STATUS_SUCCESS) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error querying audio devices."), + QMessageBox::Ok); + return; + } + + if (!_xmlPaDevList.setContent(result, &errorMsg, &errorLine, &errorColumn)) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist.\n%1 (Line:%2, Col:%3).").arg(errorMsg, + errorLine, + errorColumn), + QMessageBox::Ok); + return; + } + QDomElement root = _xmlPaDevList.documentElement(); + if (root.tagName() != "xml") + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist. Root tag is not ."), + QMessageBox::Ok); + return; + } + QDomElement devices = root.firstChildElement("devices"); + if (devices.isNull()) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist. There is no tag."), + QMessageBox::Ok); + return; + } + + QDomElement child = devices.firstChildElement(); + if (child.isNull()) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist. There is no tag."), + QMessageBox::Ok); + return; + } + + while (!child.isNull()) + { + if (child.tagName() == "device") + { + QString id, name, inputs, outputs; + id = child.attribute("id","-1"); + name = child.attribute("name","Null"); + inputs = child.attribute("inputs","0"); + outputs = child.attribute("outputs","0"); + if (inputs.toInt() != 0) + _ui->PaIndevCombo->addItem(name,inputs.toInt()); + if (outputs.toInt() != 0) + { + _ui->PaOutdevCombo->addItem(name,inputs.toInt()); + _ui->PaRingdevCombo->addItem(name,inputs.toInt()); + } + } + child = child.nextSiblingElement(); + } + + QDomElement bindings = root.firstChildElement("bindings"); + if (bindings.isNull()) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist. There is no tag."), + QMessageBox::Ok); + return; + } + + child = bindings.firstChildElement(); + if (child.isNull()) + { + QMessageBox::critical(0, tr("PortAudio error" ), + tr("Error parsing output xml from pa devlist. There are no bindings."), + QMessageBox::Ok); + return; + } + + while (!child.isNull()) + { + QString id = child.attribute("device","-1"); + if (child.tagName() == "ring") + _ui->PaRingdevCombo->setCurrentIndex(id.toInt()); + else if (child.tagName() == "input") + _ui->PaIndevCombo->setCurrentIndex(id.toInt()); + else if (child.tagName() == "output") + _ui->PaOutdevCombo->setCurrentIndex(id.toInt()); + + child = child.nextSiblingElement(); + } + +} diff --git a/fscomm/prefportaudio.h b/fscomm/prefportaudio.h new file mode 100644 index 0000000000..84b8a29079 --- /dev/null +++ b/fscomm/prefportaudio.h @@ -0,0 +1,25 @@ +#ifndef PREFPORTAUDIO_H +#define PREFPORTAUDIO_H + +#include +#include +#include "ui_prefdialog.h" + +class QSettings; + +class PrefPortaudio : public QObject +{ +Q_OBJECT +public: + explicit PrefPortaudio(Ui::PrefDialog *ui, QObject *parent = 0); + void writeConfig(); + void readConfig(); + +private: + void getPaDevlist(void); + QSettings *_settings; + Ui::PrefDialog *_ui; + QDomDocument _xmlPaDevList; +}; + +#endif // PREFPORTAUDIO_H