Refactor configuration storage/read.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16165 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4ba291d413
commit
13c414ea25
|
@ -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
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
<section name="configuration">
|
||||
<configuration name="portaudio.conf" description="Soundcard Endpoint">
|
||||
<settings>
|
||||
<param name="indev" value="${indev}"/>
|
||||
<!-- DO NOT take the # off the devices config -->
|
||||
<param name="indev" value="#${indev}"/>
|
||||
<!-- device to use for output -->
|
||||
<param name="outdev" value="${outdev}"/>
|
||||
<!--<param name="ringdev" value="${ringdev}"/>-->
|
||||
<param name="outdev" value="#${outdev}"/>
|
||||
<param name="ringdev" value="#${ringdev}"/>
|
||||
<param name="ring-file" value="${ring-file}"/>
|
||||
<param name="ring-interval" value="${ring-interval}"/>
|
||||
<param name="hold-file" value="${hold-file}"/>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <QtGui>
|
||||
#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 <xml>."),
|
||||
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 <devices> 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 <device> 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 <bindings> 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();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <QSettings>
|
||||
#include <fshost.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
#include <QtGui>
|
||||
#include <fshost.h>
|
||||
#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 <xml>."),
|
||||
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 <devices> 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 <device> 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 <bindings> 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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
#ifndef PREFPORTAUDIO_H
|
||||
#define PREFPORTAUDIO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDomDocument>
|
||||
#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
|
Loading…
Reference in New Issue