提交 f0fed269 authored 作者: Joao Mesquita's avatar Joao Mesquita

Fix the mess I've made on the last commit. Now we really don't depend on…

Fix the mess I've made on the last commit. Now we really don't depend on QSettings or mod_qsettings.
上级 1cbf30ac
......@@ -25,7 +25,6 @@ SOURCES += main.cpp \
mainwindow.cpp \
fshost.cpp \
call.cpp \
mod_qsettings/mod_qsettings.cpp \
preferences/prefdialog.cpp \
preferences/prefportaudio.cpp \
preferences/prefsofia.cpp \
......@@ -36,11 +35,12 @@ SOURCES += main.cpp \
channel.cpp \
debugtools/consolewindow.cpp \
debugtools/sortfilterproxymodel.cpp \
debugtools/statedebugdialog.cpp
debugtools/statedebugdialog.cpp \
isettings.cpp \
accountmanager.cpp
HEADERS += mainwindow.h \
fshost.h \
call.h \
mod_qsettings/mod_qsettings.h \
preferences/prefdialog.h \
preferences/prefportaudio.h \
preferences/prefsofia.h \
......@@ -51,7 +51,10 @@ HEADERS += mainwindow.h \
channel.h \
debugtools/consolewindow.h \
debugtools/sortfilterproxymodel.h \
debugtools/statedebugdialog.h
debugtools/statedebugdialog.h \
isettings.h \
fscomm.h \
accountmanager.h
FORMS += mainwindow.ui \
preferences/prefdialog.ui \
preferences/accountdialog.ui \
......
#include <QtGui>
#include "account.h"
#include "fscomm.h"
Account::Account(QString name) :
_name(name)
......
......@@ -2,31 +2,7 @@
#define ACCOUNT_H
#include <QString>
#define FSCOMM_GW_STATE_TRYING 0
#define FSCOMM_GW_STATE_REGISTER 1
#define FSCOMM_GW_STATE_REGED 2
#define FSCOMM_GW_STATE_UNREGED 3
#define FSCOMM_GW_STATE_UNREGISTER 4
#define FSCOMM_GW_STATE_FAILED 5
#define FSCOMM_GW_STATE_FAIL_WAIT 6
#define FSCOMM_GW_STATE_EXPIRED 7
#define FSCOMM_GW_STATE_NOREG 8
#define FSCOMM_GW_STATE_NOAVAIL 9
static QString fscomm_gw_state_names[] = {
QString("Trying"),
QString("Registering"),
QString("Registered"),
QString("Un-Registered"),
QString("Un-Registering"),
QString("Failed"),
QString("Failed"),
QString("Expired"),
QString("Not applicable"),
QString("Not available")
};
//#include "fscomm.h" Why does this break AccountManager?
class Account {
public:
......
......@@ -45,10 +45,6 @@
</routes>
</configuration>
<configuration name="qsettings.conf" description="configures our mod_qsettings">
<bindings value="configuration" />
</configuration>
<configuration name="local_stream.conf" description="stream files from local dir">
<directory name="moh/48000" path="$${base_dir}/sounds/music/48000">
<param name="rate" value="48000"/>
......@@ -85,7 +81,7 @@
<load module="mod_commands"/>
<load module="mod_dptools"/>
<load module="mod_dialplan_xml"/>
<load module="mod_voipcodecs"/>
<load module="mod_spandsp"/>
<load module="mod_ilbc"/>
<load module="mod_speex"/>
<load module="mod_celt"/>
......
#ifndef FSCOMM_H
#define FSCOMM_H
#include "account.h"
#include "isettings.h"
#include "fshost.h"
#include "accountmanager.h"
......
......@@ -29,7 +29,6 @@
#include <QtGui>
#include "fshost.h"
#include "mod_qsettings/mod_qsettings.h"
/* Declare it globally */
FSHost *g_FSHost;
......@@ -146,12 +145,6 @@ void FSHost::run(void)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
}
/* Load our QSettings module */
if (mod_qsettings_load() != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't load mod_qsettings\n");
}
emit loadingModules("Loading modules...", Qt::AlignRight|Qt::AlignBottom, Qt::blue);
if (switch_core_init_and_modload(flags, console, &err) != SWITCH_STATUS_SUCCESS) {
fprintf(stderr, "Failed to initialize FreeSWITCH's core: %s\n", err);
......@@ -501,7 +494,7 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res)
switch_status_t status = SWITCH_STATUS_FALSE;
switch_stream_handle_t stream = { 0 };
SWITCH_STANDARD_STREAM(stream);
qDebug() << "Sending command: " << cmd << args << endl;
//qDebug() << "Sending command: " << cmd << args << endl;
status = switch_api_execute(cmd, args, NULL, &stream);
*res = switch_str_nil((char *) stream.data);
switch_safe_free(stream.data);
......@@ -551,9 +544,34 @@ QSharedPointer<Account> FSHost::getAccountByName(QString accStr)
QSharedPointer<Account> FSHost::getCurrentDefaultAccount()
{
QSettings settings;
settings.beginGroup("FreeSWITCH/conf/globals");
QString accString = settings.value("default_gateway").toString();
settings.endGroup();
return getAccountByName(accString);
ISettings *settings = new ISettings();
//settings->beginGroup("FreeSWITCH/conf/globals");
//QString accString = settings->value("default_gateway").toString();
//settings->endGroup();
delete (settings);
return getAccountByName("Other"); /* Pay attention to this! */
}
/*
Used to match callback from fs core. We dup the event and call the class
method callback to make use of the signal/slot infrastructure.
*/
static void eventHandlerCallback(switch_event_t *event)
{
switch_event_t *clone = NULL;
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
QSharedPointer<switch_event_t> e(clone);
g_FSHost->generalEventHandler(e);
}
}
/*
Used to propagate logs on the application
*/
static switch_status_t loggerHandler(const switch_log_node_t *node, switch_log_level_t level)
{
switch_log_node_t *clone = switch_log_node_dup(node);
QSharedPointer<switch_log_node_t> l(clone);
g_FSHost->generalLoggerHandler(l, level);
return SWITCH_STATUS_SUCCESS;
}
......@@ -37,6 +37,11 @@
#include "call.h"
#include "channel.h"
#include "account.h"
#include "fscomm.h"
static void eventHandlerCallback(switch_event_t *);
static switch_status_t loggerHandler(const switch_log_node_t *, switch_log_level_t);
class FSHost : public QThread
{
......@@ -46,6 +51,7 @@ public:
switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(QSharedPointer<switch_event_t>event);
void generalLoggerHandler(QSharedPointer<switch_log_node_t>node, switch_log_level_t level);
void printEventHeaders(QSharedPointer<switch_event_t>event);
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
QSharedPointer<Call> getCurrentActiveCall();
QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
......@@ -90,7 +96,6 @@ private slots:
private:
/* Helper methods */
void createFolders();
void printEventHeaders(QSharedPointer<switch_event_t>event);
/*FSM State handlers*/
/** Channel Related*/
......@@ -124,28 +129,4 @@ private:
extern FSHost *g_FSHost;
/*
Used to match callback from fs core. We dup the event and call the class
method callback to make use of the signal/slot infrastructure.
*/
static void eventHandlerCallback(switch_event_t *event)
{
switch_event_t *clone = NULL;
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
QSharedPointer<switch_event_t> e(clone);
g_FSHost->generalEventHandler(e);
}
}
/*
Used to propagate logs on the application
*/
static switch_status_t loggerHandler(const switch_log_node_t *node, switch_log_level_t level)
{
switch_log_node_t *clone = switch_log_node_dup(node);
QSharedPointer<switch_log_node_t> l(clone);
g_FSHost->generalLoggerHandler(l, level);
return SWITCH_STATUS_SUCCESS;
}
#endif // FSHOST_H
......@@ -30,23 +30,20 @@
#include <QtGui/QApplication>
#include <QSplashScreen>
#include "mainwindow.h"
#include "isettings.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCoreApplication::setOrganizationName("FreeSWITCH");
QCoreApplication::setOrganizationDomain("freeswitch.org");
QCoreApplication::setApplicationName("FSComm");
QApplication::setOrganizationDomain("freeswitch.org");
QPixmap image(":/images/splash.png");
QSplashScreen *splash = new QSplashScreen(image);
splash->show();
splash->showMessage("Loading core, please wait...", Qt::AlignRight|Qt::AlignBottom, Qt::blue);
g_FSHost = new FSHost();
g_FSHost = new FSHost();
QObject::connect(g_FSHost, SIGNAL(loadingModules(QString,int,QColor)), splash, SLOT(showMessage(QString,int,QColor)));
QObject::connect(g_FSHost, SIGNAL(ready()), splash, SLOT(close()));
MainWindow w;
QObject::connect(g_FSHost, SIGNAL(ready()), &w, SLOT(show()));
......
......@@ -151,11 +151,12 @@ void MainWindow::setDefaultAccount()
if (accName.isEmpty())
return;
QSettings settings;
settings.beginGroup("FreeSWITCH/conf/globals");
ISettings *settings = new ISettings();
//settings->beginGroup("FreeSWITCH/conf/globals");
switch_core_set_variable("default_gateway", accName.toAscii().data());
settings.setValue("default_gateway", accName);
settings.endGroup();
//settings->setValue("default_gateway", accName);
//settings->endGroup();
delete (settings);
}
void MainWindow::debugEventsTriggered()
......@@ -287,30 +288,31 @@ void MainWindow::makeCall()
QSharedPointer<Account> acc = g_FSHost->getCurrentDefaultAccount();
if (!acc.isNull()) {
QSettings settings;
settings.beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways/");
settings.beginGroup(acc.data()->getUUID());
settings.beginGroup("gateway/global_vars");
QString cidName = settings.value("caller_id_name").toString();
QString cidNum = settings.value("caller_id_num").toString();
settings.endGroup();
settings.endGroup();
settings.endGroup();
/*QSettings *settings = fscommSettings();
settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways/");
settings->beginGroup(acc.data()->getUUID());
settings->beginGroup("gateway/global_vars");
QString cidName = settings->value("caller_id_name").toString();
QString cidNum = settings->value("caller_id_num").toString();
settings->endGroup();
settings->endGroup();
settings->endGroup();
if (cidName.isEmpty()) {
settings.beginGroup("FreeSWITCH/conf/portaudio.conf/settings/params");
cidName = settings.value("cid-name").toString();
settings.endGroup();
settings->beginGroup("FreeSWITCH/conf/portaudio.conf/settings/params");
cidName = settings->value("cid-name").toString();
settings->endGroup();
}
if (cidNum.isEmpty()) {
settings.beginGroup("FreeSWITCH/conf/portaudio.conf/settings/params");
cidNum = settings.value("cid-num").toString();
settings.endGroup();
}
settings->beginGroup("FreeSWITCH/conf/portaudio.conf/settings/params");
cidNum = settings->value("cid-num").toString();
settings->endGroup();
}*/
/* Set the vars for this call */
switch_core_set_variable("fscomm_caller_id_name", cidName.toAscii().data());
switch_core_set_variable("fscomm_caller_id_num", cidNum.toAscii().data());
//switch_core_set_variable("fscomm_caller_id_name", cidName.toAscii().data());
//switch_core_set_variable("fscomm_caller_id_num", cidNum.toAscii().data());
//delete (settings);
}
......
......@@ -96,6 +96,7 @@ private:
StateDebugDialog * _stateDebugDialog;
QSystemTrayIcon *sysTray;
QTimer *callTimer;
AccountManager _accountManager;
};
#endif // MAINWINDOW_H
......@@ -2,21 +2,20 @@
#define ACCOUNTDIALOG_H
#include <QDialog>
#include "fscomm.h"
namespace Ui {
class AccountDialog;
}
class QSettings;
class AccountDialog : public QDialog {
Q_OBJECT
public:
AccountDialog(QString accId, QWidget *parent = 0);
AccountDialog(QWidget *parent = 0);
~AccountDialog();
void clear();
void setAccId(QString);
void readConfig();
void setName(QString name) { _name = name; }
signals:
void gwAdded(QString);
......@@ -32,9 +31,10 @@ protected:
void changeEvent(QEvent *e);
private:
QString _accId;
void setParam(QDomElement &parent, QString name, QString value);
/* Might need the profile as well someday */
QString _name; /* Needs to be empty when not editing */
Ui::AccountDialog *ui;
QSettings *_settings;
};
#endif // ACCOUNTDIALOG_H
#include <QtGui>
#include "prefaccounts.h"
#include "accountdialog.h"
#include "fshost.h"
PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) :
_ui(ui)
{
_settings = new QSettings();
_accDlg = NULL;
connect(_ui->sofiaGwAddBtn, SIGNAL(clicked()), this, SLOT(addAccountBtnClicked()));
connect(_ui->sofiaGwRemBtn, SIGNAL(clicked()), this, SLOT(remAccountBtnClicked()));
......@@ -19,27 +17,15 @@ void PrefAccounts::addAccountBtnClicked()
{
if (!_accDlg)
{
QString uuid;
if (g_FSHost->sendCmd("create_uuid", "", &uuid) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create UUID for account. Reason: %s\n", uuid.toAscii().constData());
return;
}
_accDlg = new AccountDialog(uuid);
_accDlg = new AccountDialog();
connect(_accDlg, SIGNAL(gwAdded(QString)), this, SLOT(readConfig()));
}
else
{
QString uuid;
if (g_FSHost->sendCmd("create_uuid", "", &uuid) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not create UUID for account. Reason: %s\n", uuid.toAscii().constData());
return;
}
_accDlg->setAccId(uuid);
/* Needs to be set to empty because we are not editing */
_accDlg->setName(QString());
_accDlg->clear();
}
_accDlg->show();
_accDlg->raise();
_accDlg->activateWindow();
......@@ -53,18 +39,18 @@ void PrefAccounts::editAccountBtnClicked()
return;
QTableWidgetSelectionRange range = selList[0];
QString uuid = _ui->accountsTable->item(range.topRow(),0)->data(Qt::UserRole).toString();
/* Get the selected item */
QString gwName = _ui->accountsTable->item(range.topRow(),0)->text();
if (!_accDlg)
{
_accDlg = new AccountDialog(uuid);
/* TODO: We need a way to read this sucker... Might as well just already pass the profile name */
_accDlg = new AccountDialog();
connect(_accDlg, SIGNAL(gwAdded(QString)), this, SLOT(readConfig()));
}
else
{
_accDlg->setAccId(uuid);
}
/* TODO: Should pass the profile name someday */
_accDlg->setName(gwName);
_accDlg->readConfig();
_accDlg->show();
......@@ -83,32 +69,28 @@ void PrefAccounts::remAccountBtnClicked()
{
QTableWidgetItem *item = _ui->accountsTable->item(row-offset,0);
_settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
_settings->remove(item->data(Qt::UserRole).toString());
_settings->endGroup();
/* Fire event to remove account */
switch_event_t *event;
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FSCOMM_EVENT_ACC_REMOVED) == SWITCH_STATUS_SUCCESS) {
QSharedPointer<Account> acc = g_FSHost->getAccountByUUID(item->data(Qt::UserRole).toString());
if (!acc.isNull())
{
QString res;
QString arg = QString("profile softphone killgw %1").arg(acc.data()->getName());
if (g_FSHost->sendCmd("sofia", arg.toAscii().data() , &res) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not killgw %s from profile softphone.\n",
acc.data()->getName().toAscii().data());
}
ISettings settings(this);
QDomElement cfg = settings.getConfigNode("sofia.conf");
QDomNodeList gws = cfg.elementsByTagName("gateway");
for (int i = 0; i < gws.count(); i++) {
QDomElement gw = gws.at(i).toElement();
if ( gw.attributeNode("name").value() == item->text()) {
cfg.elementsByTagName("gateways").at(0).removeChild(gw);
break;
}
}
settings.setConfigNode(cfg, "sofia.conf");
/* Mark the account to be deleted */
_toDelete.append(item->text());
_ui->accountsTable->removeRow(row-offset);
offset++;
}
}
if (offset > 0)
readConfig(false);
if (offset)
readConfig();
}
void PrefAccounts::writeConfig()
......@@ -116,46 +98,68 @@ void PrefAccounts::writeConfig()
return;
}
void PrefAccounts::readConfig(bool reload)
void PrefAccounts::postWriteConfig() {
QString res;
if (g_FSHost->sendCmd("sofia", "profile softphone rescan", &res) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not rescan the softphone profile.\n");
}
foreach (QString gw, _toDelete) {
if (g_FSHost->sendCmd("sofia", QString("profile softphone killgw %1").arg(gw).toAscii().constData(), &res) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not remove gateway from profile [%s].\n", gw.toAscii().constData());
}
}
}
void PrefAccounts::readConfig()
{
_ui->accountsTable->clearContents();
_ui->accountsTable->setRowCount(0);
_settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
foreach(QString accId, _settings->childGroups())
{
_settings->beginGroup(accId);
_settings->beginGroup("gateway/attrs");
QTableWidgetItem *item0 = new QTableWidgetItem(_settings->value("name").toString());
item0->setData(Qt::UserRole, accId);
_settings->endGroup();
_settings->beginGroup("gateway/params");
QTableWidgetItem *item1 = new QTableWidgetItem(_settings->value("username").toString());
item1->setData(Qt::UserRole, accId);
_settings->endGroup();
_settings->endGroup();
ISettings settings(this);
QDomElement cfg = settings.getConfigNode("sofia.conf");
if ( cfg.elementsByTagName("gateways").count() == 0 ) {
QDomElement profile = cfg.elementsByTagName("profile").at(0).toElement();
QDomDocument d = profile.toDocument();
QDomElement gws = d.createElement("gateways");
profile.insertBefore(gws, QDomNode()); /* To make it look nicer */
settings.setConfigNode(cfg, "sofia.conf");
return;
}
QDomNodeList l = cfg.elementsByTagName("gateway");
for (int i = 0; i < l.count(); i++) {
QDomElement gw = l.at(i).toElement();
QTableWidgetItem *item0 = new QTableWidgetItem(gw.attribute("name"));
QTableWidgetItem *item1 = NULL;
/* Iterate until we find what we need */
QDomNodeList params = gw.elementsByTagName("param");
for(int j = 0; i < params.count(); j++) {
QDomElement e = params.at(j).toElement();
QString var = e.attributeNode("name").value();
if (var == "username" ) {
item1 = new QTableWidgetItem(e.attributeNode("value").value());
break; /* We found, so stop looping */
}
}
_ui->accountsTable->setRowCount(_ui->accountsTable->rowCount()+1);
_ui->accountsTable->setItem(_ui->accountsTable->rowCount()-1, 0, item0);
_ui->accountsTable->setItem(_ui->accountsTable->rowCount()-1, 1, item1);
}
_ui->accountsTable->resizeRowsToContents();
_ui->accountsTable->resizeColumnsToContents();
_ui->accountsTable->horizontalHeader()->setStretchLastSection(true);
_settings->endGroup();
if (reload)
{
QString res;
if (g_FSHost->sendCmd("sofia", "profile softphone rescan", &res) != SWITCH_STATUS_SUCCESS)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not rescan the softphone profile.\n");
return;
}
}
/*
TODO: We have to figure out what to do with the default account stuff!
if (_ui->accountsTable->rowCount() == 1)
{
QString default_gateway = _settings->value(QString("/FreeSWITCH/conf/sofia.conf/profiles/profile/gateways/%1/gateway/attrs/name").arg(_ui->accountsTable->item(0,0)->data(Qt::UserRole).toString())).toString();
......@@ -163,6 +167,6 @@ void PrefAccounts::readConfig(bool reload)
_settings->setValue("default_gateway", default_gateway);
_settings->endGroup();
switch_core_set_variable("default_gateway", default_gateway.toAscii().data());
}
}*/
}
......@@ -3,10 +3,8 @@
#include <QObject>
#include "ui_prefdialog.h"
#include "fscomm.h"
#define FSCOMM_EVENT_ACC_REMOVED "fscomm::acc_removed"
class QSettings;
class AccountDialog;
class PrefAccounts : public QObject {
......@@ -14,9 +12,10 @@ class PrefAccounts : public QObject {
public:
explicit PrefAccounts(Ui::PrefDialog *ui);
void writeConfig();
void postWriteConfig();
public slots:
void readConfig(bool reload=true);
void readConfig();
private slots:
void addAccountBtnClicked();
......@@ -24,9 +23,10 @@ private slots:
void remAccountBtnClicked();
private:
void markAccountToDelete(QString gwName); /* TODO: Might be interesting to pass the account instead */
Ui::PrefDialog *_ui;
AccountDialog *_accDlg;
QSettings *_settings;
QList<QString> _toDelete;
};
#endif // PREFACCOUNTS_H
......@@ -10,8 +10,8 @@ PrefDialog::PrefDialog(QWidget *parent) :
ui(new Ui::PrefDialog)
{
ui->setupUi(this);
_settings = new QSettings();
connect(this, SIGNAL(accepted()), this, SLOT(writeConfig()));
connect(ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
_pref_accounts = new PrefAccounts(ui);
_mod_portaudio = new PrefPortaudio(ui, this);
......@@ -25,11 +25,44 @@ PrefDialog::~PrefDialog()
delete ui;
}
void PrefDialog::clicked(QAbstractButton *b) {
if (ui->buttonBox->buttonRole(b) == QDialogButtonBox::ApplyRole) {
writeConfig();
readConfig();
}
if ( ui->buttonBox->buttonRole(b) == QDialogButtonBox::RejectRole) {
/* This doesn't really work because we need to reset the DOM as well to discard changes... */
readConfig();
}
}
void PrefDialog::writeConfig()
{
/* Ask modules to write their configs. */
_mod_portaudio->writeConfig();
_mod_sofia->writeConfig();
_pref_accounts->writeConfig();
/* Write it to file */
ISettings settings(this);
settings.saveToFile();
/* Re-read the configuration to memory */
const char *err;
switch_xml_t xml_root;
if ((xml_root = switch_xml_open_root(1, &err))) {
switch_xml_free(xml_root);
} else {
QMessageBox::critical(0, tr("Unable to save settings"),
tr("There was an error saving your settings.\nPlease report this bug.\n%1").arg(err),
QMessageBox::Ok);
return;
}
/* Tell modules new config is in memory so they get a chance */
_mod_portaudio->postWriteConfig();
_pref_accounts->postWriteConfig();
}
void PrefDialog::changeEvent(QEvent *e)
......
......@@ -3,12 +3,12 @@
#include <QDialog>
#include <QDomDocument>
#include <QSettings>
#include <fshost.h>
#include "fscomm.h"
class PrefPortaudio;
class PrefSofia;
class PrefAccounts;
class QAbstractButton;
namespace Ui {
class PrefDialog;
......@@ -25,13 +25,13 @@ protected:
private slots:
void writeConfig();
void clicked(QAbstractButton*);
signals:
void preprocessorsApplied(QStringList);
private:
void readConfig();
QSettings *_settings;
PrefAccounts *_pref_accounts;
Ui::PrefDialog *ui;
PrefPortaudio *_mod_portaudio;
......
......@@ -1170,7 +1170,7 @@
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
......
#include <QtGui>
#include <fshost.h>
#include "prefportaudio.h"
PrefPortaudio::PrefPortaudio(Ui::PrefDialog *ui, QObject *parent) :
QObject(parent),
_ui(ui)
{
_settings = new QSettings();
connect(_ui->PaRingFileBtn, SIGNAL(clicked()), this, SLOT(ringFileChoose()));
connect(_ui->PaHoldFileBtn, SIGNAL(clicked()), this, SLOT(holdFileChoose()));
connect(_ui->PaIndevCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(indevChangeDev(int)));
......@@ -139,111 +137,111 @@ void PrefPortaudio::ringFileChoose()
void PrefPortaudio::writeConfig()
{
_settings->beginGroup("FreeSWITCH/conf");
_settings->beginGroup("portaudio.conf/settings/params");
QString cid_name = _settings->value("cid-name").toString();
QString ncid_name = _ui->PaCallerIdNameEdit->text();
QString cid_num = _settings->value("cid-num").toString();
QString ncid_num = _ui->PaCallerIdNumEdit->text();
QString hold_file = _settings->value("hold-file").toString();
QString nhold_file = _ui->PaHoldFileEdit->text();
QString ring_file = _settings->value("ring-file").toString();
QString nring_file = _ui->PaRingFileEdit->text();
int ring_interval = _settings->value("ring-interval").toInt();
int nring_interval = _ui->PaRingIntervalSpin->value();
QString sample_rate = _settings->value("sample-rate").toString();
QString nsample_rate = _ui->PaSampleRateEdit->text();
QString codec_ms = _settings->value("codec-ms").toString();
QString ncodec_ms = _ui->PaCodecMSEdit->text();
QString result;
if (cid_name != ncid_name ||
cid_num != ncid_num ||
hold_file != nhold_file ||
ring_file != nring_file ||
ring_interval != nring_interval ||
sample_rate != nsample_rate||
codec_ms != ncodec_ms)
{
if (g_FSHost->sendCmd("reload", "mod_portaudio", &result) == SWITCH_STATUS_SUCCESS)
{
_settings->setValue("cid-name", ncid_name);
_settings->setValue("cid-num", ncid_num);
_settings->setValue("ring-file", nring_file);
_settings->setValue("ring-interval", nring_interval);
_settings->setValue("hold-file", nhold_file);
_settings->setValue("sample-rate", nsample_rate);
_settings->setValue("codec-ms", ncodec_ms);
/* We can do better error control here, can't we? */
ISettings *_settings = new ISettings();
QDomElement cfg = _settings->getConfigNode("portaudio.conf");
QDomNodeList nl = cfg.elementsByTagName("param");
for (int i = 0; i < nl.count(); i++) {
QDomAttr var = nl.at(i).toElement().attributeNode("name");
QDomAttr val = nl.at(i).toElement().attributeNode("value");
if (var.value() == "indev") {
val.setValue(QString::number(_ui->PaIndevCombo->itemData(_ui->PaIndevCombo->currentIndex(), Qt::UserRole).toInt()));
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error while issuing reload command to mod_portaudio!\n");
QMessageBox::critical(0, tr("Unable to save settings"),
tr("There was an error saving your settings.\nPlease report this bug."),
QMessageBox::Ok);
if (var.value() == "outdev") {
val.setValue(QString::number(_ui->PaOutdevCombo->itemData(_ui->PaOutdevCombo->currentIndex(), Qt::UserRole).toInt()));
}
}
int nindev = _ui->PaIndevCombo->itemData(_ui->PaIndevCombo->currentIndex(), Qt::UserRole).toInt();
int indev = _settings->value("indev").toInt();
int noutdev = _ui->PaOutdevCombo->itemData(_ui->PaOutdevCombo->currentIndex(), Qt::UserRole).toInt();
int outdev = _settings->value("outdev").toInt();
int nringdev = _ui->PaRingdevCombo->itemData(_ui->PaRingdevCombo->currentIndex(), Qt::UserRole).toInt();
int ringdev = _settings->value("ringdev").toInt();
if (nindev != indev)
{
if (g_FSHost->sendCmd("pa", QString("indev #%1").arg(nindev).toAscii().constData(), &result) == SWITCH_STATUS_SUCCESS)
{
_settings->setValue("indev", nindev);
if (var.value() == "ringdev") {
val.setValue(QString::number(_ui->PaRingdevCombo->itemData(_ui->PaRingdevCombo->currentIndex(), Qt::UserRole).toInt()));
}
else
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error setting indev from #%d to #%d on mod_portaudio!\n",
indev, nindev);
QMessageBox::critical(0, tr("Unable to save settings"),
tr("There was an error changing the indev.\nPlease report this bug."),
QMessageBox::Ok);
if (var.value() == "ring-file") {
val.setValue(_ui->PaRingFileEdit->text());
}
if (var.value() == "ring-interval") {
val.setValue(QString::number(_ui->PaRingIntervalSpin->value()));
}
if (var.value() == "hold-file") {
val.setValue(_ui->PaHoldFileEdit->text());
}
if (var.value() == "cid-name") {
val.setValue(_ui->PaCallerIdNameEdit->text());
}
if (var.value() == "cid-num") {
val.setValue(_ui->PaCallerIdNumEdit->text());
}
if (var.value() == "sample-rate") {
val.setValue(_ui->PaSampleRateEdit->text());
}
if (var.value() == "codec-ms") {
val.setValue(_ui->PaCodecMSEdit->text());
}
/* Not used currently
if (var.value() == "dialplan") {
val.setValue();
}
if (var.value() == "timer-name") {
val.setValue();
}*/
}
/* Save the config to the file */
_settings->setConfigNode(cfg, "portaudio.conf");
}
if (noutdev!= outdev)
{
_settings->setValue("outdev", noutdev);
}
if (nringdev != ringdev)
void PrefPortaudio::postWriteConfig() {
QString result;
if (g_FSHost->sendCmd("reload", "mod_portaudio", &result) != SWITCH_STATUS_SUCCESS)
{
_settings->setValue("ringdev", nringdev);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error while issuing reload command to mod_portaudio!\n");
QMessageBox::critical(0, tr("Unable to save settings"),
tr("There was an error saving your settings.\nPlease report this bug."),
QMessageBox::Ok);
}
_settings->endGroup();
_settings->endGroup();
}
void PrefPortaudio::readConfig()
{
getPaDevlist();
_settings->beginGroup("FreeSWITCH/conf");
_settings->beginGroup("portaudio.conf/settings/params");
_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());
_ui->PaSampleRateEdit->setText(_settings->value("sample-rate").toString());
_ui->PaCodecMSEdit->setText(_settings->value("codec-ms").toString());
_settings->endGroup();
_settings->endGroup();
getPaDevlist(); /* To populate the combo */
ISettings *_settings = new ISettings();
QDomElement cfg = _settings->getConfigNode("portaudio.conf");
QDomNodeList nl = cfg.elementsByTagName("param");
for (int i = 0; i < nl.count(); i++) {
QDomAttr var = nl.at(i).toElement().attributeNode("name");
QDomAttr val = nl.at(i).toElement().attributeNode("value");
/* Set when getting the device list */
if (var.value() == "indev") {
}
if (var.value() == "outdev") {
}
if (var.value() == "ringdev") {
}
if (var.value() == "ring-file") {
_ui->PaRingFileEdit->setText(val.value());
}
if (var.value() == "ring-interval") {
_ui->PaRingIntervalSpin->setValue(val.value().toInt());
}
if (var.value() == "hold-file") {
_ui->PaHoldFileEdit->setText(val.value());
}
/* Not yet used.
if (var.value() == "dialplan") {
}
if (var.value() == "timer-name") {
}
*/
if (var.value() == "cid-name") {
_ui->PaCallerIdNameEdit->setText(val.value());
}
if (var.value() == "cid-num") {
_ui->PaCallerIdNumEdit->setText(val.value());
}
if (var.value() == "sample-rate") {
_ui->PaSampleRateEdit->setText(val.value());
}
if (var.value() == "codec-ms") {
_ui->PaCodecMSEdit->setText(val.value());
}
}
}
void PrefPortaudio::getPaDevlist()
......@@ -259,6 +257,9 @@ void PrefPortaudio::getPaDevlist()
QMessageBox::Ok);
return;
}
_ui->PaOutdevCombo->clear();
_ui->PaIndevCombo->clear();
_ui->PaRingdevCombo->clear();
if (!_xmlPaDevList.setContent(result, &errorMsg, &errorLine, &errorColumn))
{
......
......@@ -4,8 +4,7 @@
#include <QObject>
#include <QDomDocument>
#include "ui_prefdialog.h"
class QSettings;
#include "fscomm.h"
class PrefPortaudio : public QObject
{
......@@ -13,6 +12,7 @@ Q_OBJECT
public:
explicit PrefPortaudio(Ui::PrefDialog *ui, QObject *parent = 0);
void writeConfig();
void postWriteConfig();
void readConfig();
private slots:
......@@ -31,7 +31,6 @@ signals:
private:
void getPaDevlist(void);
QSettings *_settings;
Ui::PrefDialog *_ui;
QDomDocument _xmlPaDevList;
};
......
......@@ -11,6 +11,7 @@ public:
explicit PrefSofia(Ui::PrefDialog *ui, QObject *parent = 0);
void writeConfig();
void readConfig();
void postWriteConfig();
private:
Ui::PrefDialog *_ui;
......
......@@ -126,6 +126,17 @@ QString CodecWidget::getCodecString()
void CodecWidget::setCodecString(QString codecList)
{
/* Mostly for backwards compatibility. */
if ( codecList.startsWith("$")) {
QStringList parsed = codecList.split("{");
QString var = parsed.at(1);
var = var.split("}").at(0);
var = switch_core_get_variable(var.toAscii().data());
if ( ! var.isEmpty() ) {
codecList = var;
}
}
QStringList rawEnCodecs;
QStringList split = codecList.split(",");
foreach(QString s, split)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论