mainwindow.cpp \
fshost.cpp \
call.cpp \
- mod_qsettings/mod_qsettings.cpp \
preferences/prefdialog.cpp \
preferences/prefportaudio.cpp \
preferences/prefsofia.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 \
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)
#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:
</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"/>
<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"
#include <QtGui>
#include "fshost.h"
-#include "mod_qsettings/mod_qsettings.h"
/* Declare it globally */
FSHost *g_FSHost;
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);
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);
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;
}
#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
{
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(); }
private:
/* Helper methods */
void createFolders();
- void printEventHeaders(QSharedPointer<switch_event_t>event);
/*FSM State handlers*/
/** Channel Related*/
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
#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()));
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()
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);
}
StateDebugDialog * _stateDebugDialog;
QSystemTrayIcon *sysTray;
QTimer *callTimer;
+ AccountManager _accountManager;
};
#endif // MAINWINDOW_H
-#include <QSettings>
#include <QtGui>
#include "accountdialog.h"
#include "ui_accountdialog.h"
-#include "fshost.h"
-AccountDialog::AccountDialog(QString accId, QWidget *parent) :
+AccountDialog::AccountDialog(QWidget *parent) :
QDialog(parent),
- _accId(accId),
ui(new Ui::AccountDialog)
-{
+{
ui->setupUi(this);
- _settings = new QSettings;
connect(this, SIGNAL(accepted()), this, SLOT(writeConfig()));
connect(ui->sofiaExtraParamAddBtn, SIGNAL(clicked()), this, SLOT(addExtraParam()));
connect(ui->sofiaExtraParamRemBtn, SIGNAL(clicked()), this, SLOT(remExtraParam()));
ui->sofiaExtraParamTable->horizontalHeader()->setStretchLastSection(true);
}
+/* TODO: We need to figure out the callerID thing... */
void AccountDialog::readConfig()
{
- _settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
- _settings->beginGroup(_accId);
-
- _settings->beginGroup("gateway/attrs");
- ui->sofiaGwNameEdit->setText(_settings->value("name").toString());
- _settings->endGroup();
-
- _settings->beginGroup("gateway/params");
- ui->sofiaGwUsernameEdit->setText(_settings->value("username").toString());
- ui->sofiaGwRealmEdit->setText(_settings->value("realm").toString());
- ui->sofiaGwPasswordEdit->setText(_settings->value("password").toString());
- ui->sofiaGwExpireSecondsSpin->setValue(_settings->value("expire-seconds").toInt());
- ui->sofiaGwRegisterCombo->setCurrentIndex(ui->sofiaGwRegisterCombo->findText(_settings->value("register").toString(),
- Qt::MatchExactly));
- ui->sofiaGwRegisterTransportCombo->setCurrentIndex(ui->sofiaGwRegisterTransportCombo->findText(_settings->value("register-transport").toString(),
- Qt::MatchExactly));
- ui->sofiaGwRetrySecondsSpin->setValue(_settings->value("retry-seconds").toInt());
- _settings->endGroup();
-
- _settings->beginGroup("gateway/customParams");
- int row = 0;
- ui->sofiaExtraParamTable->clearContents();
- foreach(QString k, _settings->childKeys())
- {
- row++;
- ui->sofiaExtraParamTable->setRowCount(row);
- QTableWidgetItem *varName = new QTableWidgetItem(k);
- QTableWidgetItem *varVal = new QTableWidgetItem(_settings->value(k).toString());
- ui->sofiaExtraParamTable->setItem(row-1, 0,varName);
- ui->sofiaExtraParamTable->setItem(row-1, 1,varVal);
- }
- _settings->endGroup();
- _settings->endGroup();
- _settings->endGroup();
+ /* We already know the name of the gateway, so... */
+ ui->sofiaGwNameEdit->setText(_name);
+
+ ISettings settings(this);
+ QDomElement cfg = settings.getConfigNode("sofia.conf");
+
+ QDomNodeList nl = cfg.elementsByTagName("gateway");
+
+ for (int i = 0; i < nl.count(); i++) {
+ QDomElement gw = nl.at(i).toElement();
+ if (gw.attributeNode("name").value() == _name) {
+ /* Iterate the params and set the values */
+ QDomNodeList params = gw.elementsByTagName("param");
+ int row = 0; /* Used for extra params */
+ ui->sofiaExtraParamTable->clearContents();
+ for (int j = 0; j < params.count(); j++) {
+ QDomElement param = params.at(j).toElement();
+ QString var = param.attributeNode("name").value();
+ QString val = param.attributeNode("value").value();
+ if ( var == "username" ) {
+ ui->sofiaGwUsernameEdit->setText(val);
+ } else if ( var == "realm" ) {
+ ui->sofiaGwRealmEdit->setText(val);
+ } else if ( var == "password" ) {
+ ui->sofiaGwPasswordEdit->setText(val);
+ } else if ( var == "expire-seconds" ) {
+ ui->sofiaGwExpireSecondsSpin->setValue(val.toInt());
+ } else if ( var == "register" ) {
+ ui->sofiaGwRegisterCombo->setCurrentIndex(ui->sofiaGwRegisterCombo->findText(val, Qt::MatchExactly));
+ } else if ( var == "register-transport" ) {
+ ui->sofiaGwRegisterTransportCombo->setCurrentIndex(ui->sofiaGwRegisterTransportCombo->findText(val, Qt::MatchExactly));
+ } else if ( var == "retry-seconds" ) {
+ ui->sofiaGwRetrySecondsSpin->setValue(val.toInt());
+ } else {
+ /* Set custom parameters */
+ row++;
+ ui->sofiaExtraParamTable->setRowCount(row);
+ QTableWidgetItem *varName = new QTableWidgetItem(var);
+ QTableWidgetItem *varVal = new QTableWidgetItem(val);
+ ui->sofiaExtraParamTable->setItem(row-1, 0,varName);
+ ui->sofiaExtraParamTable->setItem(row-1, 1,varVal);
+ }
+ }
+ /* Stop processing the gateway list */
+ break;
+ }
+ }
ui->sofiaExtraParamTable->resizeColumnsToContents();
ui->sofiaExtraParamTable->resizeRowsToContents();
ui->sofiaExtraParamTable->horizontalHeader()->setStretchLastSection(true);
}
+/* TODO: Figure out the callerID thing... */
void AccountDialog::writeConfig()
{
- QSharedPointer<Account> acc = g_FSHost->getAccountByUUID(_accId);
- if (!acc.isNull())
+ /* TODO: This is where we need to figure out the caller ID
+ if (ui->clidSettingsCombo->currentIndex() == 0)
{
- g_FSHost->accountReloadCmd(acc);
+ settings->remove("caller_id_name");
+ settings->remove("caller_id_num");
+ } else {
+ settings->setValue("caller_id_name", ui->sofiaCallerIDName->text());
+ settings->setValue("caller_id_num", ui->sofiaCallerIDNum->text());
}
+ */
+ ISettings settings(this);
+ QDomElement cfg = settings.getConfigNode("sofia.conf");
- _settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
+ /* First check to see if we are editing */
+ if (!_name.isEmpty()) {
- _settings->beginGroup(_accId);
+ /* Find our gateway */
+ QDomElement gw;
+ QDomNodeList gws = cfg.elementsByTagName("gateway");
+ for (int i = 0; i < gws.count(); i++) {
+ if ( gws.at(i).toElement().attributeNode("name").value() == _name) {
+ gw = gws.at(i).toElement();
+ /* Set the new gateway name */
+ if ( _name != ui->sofiaGwNameEdit->text() ) {
+ _name = ui->sofiaGwNameEdit->text();
+ gws.at(i).toElement().attributeNode("name").setValue(ui->sofiaGwNameEdit->text());
+ }
+ break;
+ }
+ }
+ if ( gw.isNull() ) {
+ qDebug() << "Hey, there is no gateway!";
+ return;
+ }
- _settings->beginGroup("gateway/global_vars");
- if (ui->clidSettingsCombo->currentIndex() == 0)
- {
- _settings->remove("caller_id_name");
- _settings->remove("caller_id_num");
+ /* Found the gateway, now iterate the parameters */
+ QDomNodeList params = gw.elementsByTagName("param");
+ for (int i = 0; i < params.count(); i++) {
+ QDomElement param = params.at(i).toElement();
+ QString var = param.attributeNode("name").value();
+ QDomAttr val = param.attributeNode("value");
+ if ( var == "username" ) {
+ val.setValue(ui->sofiaGwUsernameEdit->text());
+ } else if ( var == "realm" ) {
+ val.setValue(ui->sofiaGwRealmEdit->text());
+ } else if ( var == "password" ) {
+ val.setValue(ui->sofiaGwPasswordEdit->text());
+ } else if ( var == "expire-seconds" ) {
+ val.setValue(QString::number(ui->sofiaGwExpireSecondsSpin->value()));
+ } else if ( var == "register" ) {
+ val.setValue(ui->sofiaGwRegisterCombo->currentText());
+ } else if ( var == "register-transport" ) {
+ val.setValue(ui->sofiaGwRegisterTransportCombo->currentText());
+ } else if ( var == "retry-seconds" ) {
+ val.setValue(QString::number(ui->sofiaGwRetrySecondsSpin->value()));
+ }
+ }
+ /* Set extra parameters */
+ QDomDocument d = gw.toDocument();
+ for (int i = 0; i< ui->sofiaExtraParamTable->rowCount(); i++)
+ {
+ QDomElement ePar = d.createElement("param");
+ QDomAttr var = d.createAttribute(ui->sofiaExtraParamTable->item(i, 0)->text());
+ ePar.appendChild(var);
+ QDomAttr val = d.createAttribute(ui->sofiaExtraParamTable->item(i, 1)->text());
+ ePar.appendChild(val);
+ gw.appendChild(ePar);
+ }
} else {
- _settings->setValue("caller_id_name", ui->sofiaCallerIDName->text());
- _settings->setValue("caller_id_num", ui->sofiaCallerIDNum->text());
- }
- _settings->endGroup();
-
- _settings->beginGroup("gateway/attrs");
- _settings->setValue("name", ui->sofiaGwNameEdit->text());
- _settings->endGroup();
-
-
- _settings->beginGroup("gateway/params");
- _settings->setValue("username", ui->sofiaGwUsernameEdit->text());
- _settings->setValue("realm", ui->sofiaGwRealmEdit->text());
- _settings->setValue("password", ui->sofiaGwPasswordEdit->text());
- _settings->setValue("expire-seconds", ui->sofiaGwExpireSecondsSpin->value());
- _settings->setValue("register", ui->sofiaGwRegisterCombo->currentText());
- _settings->setValue("register-transport", ui->sofiaGwRegisterTransportCombo->currentText());
- _settings->setValue("retry-seconds", ui->sofiaGwRetrySecondsSpin->value());
- _settings->endGroup();
-
- _settings->beginGroup("gateway/customParams");
- for (int i = 0; i< ui->sofiaExtraParamTable->rowCount(); i++)
- {
- _settings->setValue(ui->sofiaExtraParamTable->item(i, 0)->text(),
- ui->sofiaExtraParamTable->item(i, 1)->text());
- }
- _settings->endGroup();
+ QDomElement gws = cfg.elementsByTagName("gateways").at(0).toElement();
+ QDomDocument d = gws.toDocument();
+ QDomElement nGw = d.createElement("gateway");
+ gws.insertAfter(nGw, QDomNode());
+ nGw.setAttribute("name",ui->sofiaGwNameEdit->text());
- _settings->endGroup();
+ /* Set each one of the parameters */
+ setParam(nGw, "username", ui->sofiaGwUsernameEdit->text());
+ setParam(nGw, "password", ui->sofiaGwPasswordEdit->text());
+ setParam(nGw, "register", ui->sofiaGwRegisterCombo->currentText());
+ setParam(nGw, "realm", ui->sofiaGwRealmEdit->text());
+ setParam(nGw, "expire-seconds", QString::number(ui->sofiaGwExpireSecondsSpin->value()));
+ setParam(nGw, "register-transport", ui->sofiaGwRegisterTransportCombo->currentText());
+ setParam(nGw, "retry-seconds", QString::number(ui->sofiaGwRetrySecondsSpin->value()));
+ for (int i = 0; i< ui->sofiaExtraParamTable->rowCount(); i++)
+ {
+ setParam(nGw, ui->sofiaExtraParamTable->item(i, 0)->text(), ui->sofiaExtraParamTable->item(i, 1)->text());
+ }
+ }
- _settings->endGroup();
+ settings.setConfigNode(cfg, "sofia.conf");
+ emit gwAdded(_name);
+}
- emit gwAdded(_accId);
+void AccountDialog::setParam(QDomElement &parent, QString name, QString value) {
+ QDomDocument d = parent.toDocument();
+ QDomElement e = d.createElement("param");
+ e.setAttribute("name", name);
+ e.setAttribute("value", value);
+ parent.appendChild(e);
}
void AccountDialog::clear()
ui->sofiaGwRetrySecondsSpin->setValue(30);
}
-void AccountDialog::setAccId(QString accId)
-{
- _accId = accId;
-}
-
void AccountDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
#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);
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()));
{
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();
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();
{
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()
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();
_settings->setValue("default_gateway", default_gateway);
_settings->endGroup();
switch_core_set_variable("default_gateway", default_gateway.toAscii().data());
- }
+ }*/
}
#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 {
public:
explicit PrefAccounts(Ui::PrefDialog *ui);
void writeConfig();
+ void postWriteConfig();
public slots:
- void readConfig(bool reload=true);
+ void readConfig();
private slots:
void addAccountBtnClicked();
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
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);
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)
#include <QDialog>
#include <QDomDocument>
-#include <QSettings>
-#include <fshost.h>
+#include "fscomm.h"
class PrefPortaudio;
class PrefSofia;
class PrefAccounts;
+class QAbstractButton;
namespace Ui {
class PrefDialog;
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;
<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)));
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()
QMessageBox::Ok);
return;
}
+ _ui->PaOutdevCombo->clear();
+ _ui->PaIndevCombo->clear();
+ _ui->PaRingdevCombo->clear();
if (!_xmlPaDevList.setContent(result, &errorMsg, &errorLine, &errorColumn))
{
#include <QObject>
#include <QDomDocument>
#include "ui_prefdialog.h"
-
-class QSettings;
+#include "fscomm.h"
class PrefPortaudio : public QObject
{
public:
explicit PrefPortaudio(Ui::PrefDialog *ui, QObject *parent = 0);
void writeConfig();
+ void postWriteConfig();
void readConfig();
private slots:
private:
void getPaDevlist(void);
- QSettings *_settings;
Ui::PrefDialog *_ui;
QDomDocument _xmlPaDevList;
};
void PrefSofia::readConfig()
{
- QSettings settings;
+ ISettings *settings = new ISettings();
+ QDomElement cfg = settings->getConfigNode("sofia.conf");
+ if ( cfg.isNull() ) {
+ qDebug() << "Issue a big warning!";
+ return;
+ }
int guess_mask;
char guess_ip[80];
switch_find_local_ip(guess_ip, sizeof(guess_ip), &guess_mask, AF_INET);
_ui->sofiaRtpIpEdit->setText(QString(guess_ip));
_ui->sofiaSipIpEdit->setText(QString(guess_ip));
- settings.beginGroup("FreeSWITCH/conf");
- settings.beginGroup("sofia.conf");
-
/* General Settings */
- settings.beginGroup("global_settings/params");
- _ui->sofiaLogLevelSpin->setValue(settings.value("log-level").toInt());
- _ui->sofiaAutoRestartCombo->setCurrentIndex(_ui->sofiaAutoRestartCombo->findText(settings.value("auto-restart").toString()));
- _ui->sofiaDebugPresenceSpin->setValue(settings.value("debug-presence").toInt());
- _ui->sofiaRewriteMulticastedFsPathCombo->setCurrentIndex(_ui->sofiaRewriteMulticastedFsPathCombo->findText(settings.value("rewrite-multicasted-fs-path").toString()));
- settings.endGroup();
+ QDomNodeList l = cfg.elementsByTagName("global_settings");
+ QDomNodeList global_params = l.at(0).toElement().elementsByTagName("param");
+ for (int i = 0; i < global_params.count(); i++) {
+ QDomElement el = global_params.at(i).toElement();
+ if ( el.attribute("name") == "log-level" ) {
+ _ui->sofiaLogLevelSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "auto-restart") {
+ _ui->sofiaAutoRestartCombo->setCurrentIndex(_ui->sofiaAutoRestartCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "debug-presence") {
+ _ui->sofiaDebugPresenceSpin->setValue(el.attribute("value").toInt());
+ }
+ }
/* Profile settings */
- settings.beginGroup("profiles");
- settings.beginGroup("profile");
-
+ /* Get only the first settings, meaning one profile supported so far */
+ QDomNodeList params = cfg.elementsByTagName("settings").at(0).toElement().elementsByTagName("param");
+ for (int i = 0; i < params.count(); i++) {
+ QDomElement el = params.at(i).toElement();
+ if ( el.attribute("name") == "user-agent-string") {
+ _ui->sofiaUserAgentStringEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "debug") {
+ _ui->sofiaDebugSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "sip-trace") {
+ _ui->sofiaSipTraceCombo->setCurrentIndex(_ui->sofiaSipTraceCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "context") {
+ _ui->sofiaContextEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "rfc2833-pt") {
+ _ui->sofiaRfc2833PtEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "sip-port") {
+ _ui->sofiaSipPortSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "dialplan") {
+ _ui->sofiaDialplanEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "dtmf-duration") {
+ _ui->sofiaDtmfDurationSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "codec-prefs") {
+ _ui->sofiaProfileCodecWidget->setCodecString(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "use-rtp-timer") {
+ _ui->sofiaUseRtpTimerCombo->setCurrentIndex(_ui->sofiaUseRtpTimerCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "rtp-timer-name") {
+ _ui->sofiaRtpTimerNameEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "rtp-ip") {
+ _ui->sofiaRtpIpEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "sip-ip") {
+ _ui->sofiaSipIpEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "hold-music") {
+ _ui->sofiaHoldMusicEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "apply-nat-acl") {
+ _ui->sofiaApplyNatAclEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "manage-presence") {
+ _ui->sofiaManagePresenceCombo->setCurrentIndex(_ui->sofiaManagePresenceCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "max-proceeding") {
+ _ui->sofiaMaxProceedingEdit->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "inbound-codec-negotiation") {
+ _ui->sofiaInboundCodecNegotiationCombo->setCurrentIndex(_ui->sofiaInboundCodecNegotiationCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "nonce-ttl") {
+ _ui->sofiaNonceTtlSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "auth-calls") {
+ _ui->sofiaAuthCallsCombo->setCurrentIndex(_ui->sofiaAuthCallsCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "auth-all-packets") {
+ _ui->sofiaAuthAllPacketsCombo->setCurrentIndex(_ui->sofiaAuthAllPacketsCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "ext-sip-ip") {
+ _ui->sofiaExtSipIpEdit->setText(el.attribute("value"));
+ }
+ if ( el.attribute("name") == "rtp-timeout-sec") {
+ _ui->sofiaRtpTimeoutSecSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "rtp-hold-timeout-sec") {
+ _ui->sofiaRtpHoldTimeoutSecSpin->setValue(el.attribute("value").toInt());
+ }
+ if ( el.attribute("name") == "disable-register") {
+ _ui->sofiaDisableRegisterCombo->setCurrentIndex(_ui->sofiaDisableRegisterCombo->findText(el.attribute("value")));
+ }
+ if ( el.attribute("name") == "challenge-realm") {
+ _ui->sofiaChallengeRealmCombo->setCurrentIndex(_ui->sofiaChallengeRealmCombo->findText(el.attribute("value")));
+ }
+ }
+ delete (settings);
- settings.beginGroup("settings/params");
- _ui->sofiaUserAgentStringEdit->setText(settings.value("user-agent-string").toString());
- _ui->sofiaDebugSpin->setValue(settings.value("debug").toInt());
- _ui->sofiaSipTraceCombo->setCurrentIndex(_ui->sofiaSipTraceCombo->findText(settings.value("sip-trace").toString()));
- _ui->sofiaContextEdit->setText(settings.value("context").toString());
- _ui->sofiaRfc2833PtEdit->setText(settings.value("rfc2833-pt").toString());
- _ui->sofiaSipPortSpin->setValue(settings.value("sip-port").toInt());
- _ui->sofiaDialplanEdit->setText(settings.value("dialplan").toString());
- _ui->sofiaDtmfDurationSpin->setValue(settings.value("dtmf-duration").toInt());
- _ui->sofiaProfileCodecWidget->setCodecString(settings.value("codec-prefs").toString());
- _ui->sofiaUseRtpTimerCombo->setCurrentIndex(_ui->sofiaUseRtpTimerCombo->findText(settings.value("use-rtp-timer").toString()));
- _ui->sofiaRtpTimerNameEdit->setText(settings.value("rtp-timer-name").toString());
- _ui->sofiaRtpIpEdit->setText(settings.value("rtp-ip").toString());
- _ui->sofiaSipIpEdit->setText(settings.value("sip-ip").toString());
- _ui->sofiaHoldMusicEdit->setText(settings.value("hold-music").toString());
- _ui->sofiaApplyNatAclEdit->setText(settings.value("apply-nat-acl").toString());
- _ui->sofiaManagePresenceCombo->setCurrentIndex(_ui->sofiaManagePresenceCombo->findText(settings.value("manage-presence").toString()));
- _ui->sofiaMaxProceedingEdit->setValue(settings.value("max-proceeding").toInt());
- _ui->sofiaInboundCodecNegotiationCombo->setCurrentIndex(_ui->sofiaInboundCodecNegotiationCombo->findText(settings.value("inbound-codec-negotiation").toString()));
- _ui->sofiaNonceTtlSpin->setValue(settings.value("nonce-ttl").toInt());
- _ui->sofiaAuthCallsCombo->setCurrentIndex(_ui->sofiaAuthCallsCombo->findText(settings.value("auth-calls").toString()));
- _ui->sofiaAuthAllPacketsCombo->setCurrentIndex(_ui->sofiaAuthAllPacketsCombo->findText(settings.value("auth-all-packets").toString()));
- _ui->sofiaExtRtpIpEdit->setText(settings.value("ext-rtp-ip").toString());
- _ui->sofiaExtSipIpEdit->setText(settings.value("ext-sip-ip").toString());
- _ui->sofiaRtpTimeoutSecSpin->setValue(settings.value("rtp-timeout-sec").toInt());
- _ui->sofiaRtpHoldTimeoutSecSpin->setValue(settings.value("rtp-hold-timeout-sec").toInt());
- _ui->sofiaDisableRegisterCombo->setCurrentIndex(_ui->sofiaDisableRegisterCombo->findText(settings.value("disable-register").toString()));
- _ui->sofiaChallengeRealmCombo->setCurrentIndex(_ui->sofiaChallengeRealmCombo->findText(settings.value("challenge-realm").toString()));
- settings.endGroup();
-
- settings.endGroup();
- settings.endGroup();
- settings.endGroup();
- settings.endGroup();
+}
+void PrefSofia::postWriteConfig() {
+ /* Here, we have to know if we need to restart the profile or not */
+ return;
}
void PrefSofia::writeConfig()
{
- QSettings settings;
- settings.beginGroup("FreeSWITCH/conf");
- settings.beginGroup("sofia.conf");
+ ISettings *settings = new ISettings(this);
+
+ QDomElement e = settings->getConfigNode("sofia.conf");
+ QDomNodeList nl = e.elementsByTagName("global_settings").at(0).toElement().elementsByTagName("param");
/* General Settings */
- settings.beginGroup("global_settings/params");
- settings.setValue("log-level", _ui->sofiaLogLevelSpin->value());
- settings.setValue("auto-restart", _ui->sofiaAutoRestartCombo->currentText());
- settings.setValue("debug-presence", _ui->sofiaDebugPresenceSpin->value());
- settings.setValue("rewrite-multicasted-fs-path", _ui->sofiaRewriteMulticastedFsPathCombo->currentText());
- settings.endGroup();
+ for (int i = 0; i < nl.count(); i++) {
+ QDomElement el = nl.at(i).toElement();
+ QDomAttr val = el.attributeNode("value");
+ QDomAttr var = el.attributeNode("name");
+ if ( var.value() == "log-level" ) {
+ val.setValue(QString::number(_ui->sofiaLogLevelSpin->value()));
+ }
+ if ( var.value() == "auto-restart" ) {
+ val.setValue(_ui->sofiaAutoRestartCombo->currentText());
+ }
+ if ( var.value() == "debug-presence" ) {
+ val.setValue(QString::number(_ui->sofiaDebugPresenceSpin->value()));
+ }
+ if ( var.value() == "rewrite-multicasted-fs-path" ) {
+ val.setValue(_ui->sofiaRewriteMulticastedFsPathCombo->currentText());
+ }
+ }
/* Profile settings */
- settings.beginGroup("profiles");
- settings.beginGroup("profile");
-
- settings.beginGroup("attrs");
- settings.setValue("name", "softphone");
- settings.endGroup();
-
- settings.beginGroup("settings/params");
- settings.setValue("user-agent-string", _ui->sofiaUserAgentStringEdit->text());
- settings.setValue("debug", _ui->sofiaDebugSpin->value());
- settings.setValue("sip-trace", _ui->sofiaSipTraceCombo->currentText());
- settings.setValue("context", _ui->sofiaContextEdit->text());
- settings.setValue("rfc2833-pt", _ui->sofiaRfc2833PtEdit->text());
- settings.setValue("sip-port", _ui->sofiaSipPortSpin->value());
- settings.setValue("dialplan", _ui->sofiaDialplanEdit->text());
- settings.setValue("dtmf-duration", _ui->sofiaDtmfDurationSpin->value());
- settings.setValue("codec-prefs", _ui->sofiaProfileCodecWidget->getCodecString());
- settings.setValue("use-rtp-timer", _ui->sofiaUseRtpTimerCombo->currentText());
- settings.setValue("rtp-timer-name", _ui->sofiaRtpTimerNameEdit->text());
- settings.setValue("rtp-ip", _ui->sofiaRtpIpEdit->text());
- settings.setValue("sip-ip", _ui->sofiaSipIpEdit->text());
- settings.setValue("hold-music", _ui->sofiaHoldMusicEdit->text());
- settings.setValue("apply-nat-acl", _ui->sofiaApplyNatAclEdit->text());
- settings.setValue("manage-presence", _ui->sofiaManagePresenceCombo->currentText());
- settings.setValue("max-proceeding", _ui->sofiaMaxProceedingEdit->text());
- settings.setValue("inbound-codec-negotiation", _ui->sofiaInboundCodecNegotiationCombo->currentText());
- settings.setValue("nonce-ttl", _ui->sofiaNonceTtlSpin->value());
- settings.setValue("auth-calls", _ui->sofiaAuthCallsCombo->currentText());
- settings.setValue("auth-all-packets", _ui->sofiaAuthAllPacketsCombo->currentText());
- settings.setValue("ext-rtp-ip", _ui->sofiaExtRtpIpEdit->text());
- settings.setValue("ext-sip-ip", _ui->sofiaExtSipIpEdit->text());
- settings.setValue("rtp-timeout-sec", _ui->sofiaRtpTimeoutSecSpin->value());
- settings.setValue("rtp-hold-timeout-sec", _ui->sofiaRtpHoldTimeoutSecSpin->value());
- settings.setValue("disable-register", _ui->sofiaDisableRegisterCombo->currentText());
- settings.setValue("challenge-realm", _ui->sofiaChallengeRealmCombo->currentText());
- settings.endGroup();
+ /* Get only the first settings, meaning one profile supported so far */
+ QDomNodeList params = e.elementsByTagName("settings").at(0).toElement().elementsByTagName("param");
+ for (int i = 0; i < params.count(); i++) {
+ QDomElement el = params.at(i).toElement();
+ QDomAttr val = el.attributeNode("value");
+ if ( el.attribute("name") == "user-agent-string") {
+ val.setValue(_ui->sofiaUserAgentStringEdit->text());
+ }
+ if ( el.attribute("name") == "debug") {
+ val.setValue(QString::number(_ui->sofiaDebugSpin->value()));
+ }
+ if ( el.attribute("name") == "sip-trace") {
+ val.setValue(_ui->sofiaSipTraceCombo->currentText());
+ }
+ if ( el.attribute("name") == "context") {
+ val.setValue(_ui->sofiaContextEdit->text());
+ }
+ if ( el.attribute("name") == "rfc2833-pt") {
+ val.setValue(_ui->sofiaRfc2833PtEdit->text());
+ }
+ if ( el.attribute("name") == "sip-port") {
+ val.setValue(QString::number(_ui->sofiaSipPortSpin->value()));
+ }
+ if ( el.attribute("name") == "dialplan") {
+ val.setValue(_ui->sofiaDialplanEdit->text());
+ }
+ if ( el.attribute("name") == "dtmf-duration") {
+ val.setValue(QString::number(_ui->sofiaDtmfDurationSpin->value()));
+ }
+ if ( el.attribute("name") == "codec-prefs") {
+ val.setValue(_ui->sofiaProfileCodecWidget->getCodecString());
+ }
+ if ( el.attribute("name") == "use-rtp-timer") {
+ val.setValue(_ui->sofiaUseRtpTimerCombo->currentText());
+ }
+ if ( el.attribute("name") == "rtp-timer-name") {
+ val.setValue(_ui->sofiaRtpTimerNameEdit->text());
+ }
+ if ( el.attribute("name") == "rtp-ip") {
+ val.setValue(_ui->sofiaRtpIpEdit->text());
+ }
+ if ( el.attribute("name") == "sip-ip") {
+ val.setValue(_ui->sofiaSipIpEdit->text());
+ }
+ if ( el.attribute("name") == "hold-music") {
+ val.setValue(_ui->sofiaHoldMusicEdit->text());
+ }
+ if ( el.attribute("name") == "apply-nat-acl") {
+ val.setValue(_ui->sofiaApplyNatAclEdit->text());
+ }
+ if ( el.attribute("name") == "manage-presence") {
+ val.setValue(_ui->sofiaManagePresenceCombo->currentText());
+ }
+ if ( el.attribute("name") == "max-proceeding") {
+ val.setValue(_ui->sofiaMaxProceedingEdit->text());
+ }
+ if ( el.attribute("name") == "inbound-codec-negotiation") {
+ val.setValue(_ui->sofiaInboundCodecNegotiationCombo->currentText());
+ }
+ if ( el.attribute("name") == "nonce-ttl") {
+ val.setValue(QString::number(_ui->sofiaNonceTtlSpin->value()));
+ }
+ if ( el.attribute("name") == "auth-calls") {
+ val.setValue(_ui->sofiaAuthCallsCombo->currentText());
+ }
+ if ( el.attribute("name") == "auth-all-packets") {
+ val.setValue(_ui->sofiaAuthAllPacketsCombo->currentText());
+ }
+ if ( el.attribute("name") == "ext-rtp-ip") {
+ val.setValue(_ui->sofiaExtRtpIpEdit->text());
+ }
+ if ( el.attribute("name") == "ext-sip-ip") {
+ val.setValue(_ui->sofiaExtSipIpEdit->text());
+ }
+ if ( el.attribute("name") == "rtp-timeout-sec") {
+ val.setValue(QString::number(_ui->sofiaRtpTimeoutSecSpin->value()));
+ }
+ if ( el.attribute("name") == "rtp-hold-timeout-sec") {
+ val.setValue(QString::number(_ui->sofiaRtpHoldTimeoutSecSpin->value()));
+ }
+ if ( el.attribute("name") == "disable-register") {
+ val.setValue(_ui->sofiaDisableRegisterCombo->currentText());
+ }
+ if ( el.attribute("name") == "challenge-realm") {
+ val.setValue(_ui->sofiaChallengeRealmCombo->currentText());
+ }
+ }
- settings.endGroup();
- settings.endGroup();
- settings.endGroup();
- settings.endGroup();
+ settings->setConfigNode(e, "sofia.conf");
+ delete(settings);
}
explicit PrefSofia(Ui::PrefDialog *ui, QObject *parent = 0);
void writeConfig();
void readConfig();
+ void postWriteConfig();
private:
Ui::PrefDialog *_ui;
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)