2010-01-10 23:40:39 -05:00
|
|
|
#include <QtGui>
|
|
|
|
#include "prefaccounts.h"
|
2010-01-13 21:32:20 -05:00
|
|
|
#include "accountdialog.h"
|
2010-01-10 23:40:39 -05:00
|
|
|
|
|
|
|
PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) :
|
|
|
|
_ui(ui)
|
|
|
|
{
|
2010-01-13 21:32:20 -05:00
|
|
|
_accDlg = NULL;
|
|
|
|
connect(_ui->sofiaGwAddBtn, SIGNAL(clicked()), this, SLOT(addAccountBtnClicked()));
|
2010-01-13 22:25:27 -05:00
|
|
|
connect(_ui->sofiaGwRemBtn, SIGNAL(clicked()), this, SLOT(remAccountBtnClicked()));
|
2010-01-13 23:54:03 -05:00
|
|
|
connect(_ui->sofiaGwEditBtn, SIGNAL(clicked()), this, SLOT(editAccountBtnClicked()));
|
2010-01-19 18:54:32 -05:00
|
|
|
|
|
|
|
_ui->accountsTable->horizontalHeader()->setStretchLastSection(true);
|
2010-01-13 21:32:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrefAccounts::addAccountBtnClicked()
|
|
|
|
{
|
|
|
|
if (!_accDlg)
|
|
|
|
{
|
2010-07-03 12:37:32 -04:00
|
|
|
_accDlg = new AccountDialog();
|
2010-01-17 18:10:57 -05:00
|
|
|
connect(_accDlg, SIGNAL(gwAdded(QString)), this, SLOT(readConfig()));
|
2010-01-13 21:32:20 -05:00
|
|
|
}
|
2010-01-13 22:25:27 -05:00
|
|
|
else
|
|
|
|
{
|
2010-07-03 12:37:32 -04:00
|
|
|
/* Needs to be set to empty because we are not editing */
|
|
|
|
_accDlg->setName(QString());
|
2010-01-13 22:25:27 -05:00
|
|
|
_accDlg->clear();
|
|
|
|
}
|
2010-01-13 21:32:20 -05:00
|
|
|
_accDlg->show();
|
|
|
|
_accDlg->raise();
|
|
|
|
_accDlg->activateWindow();
|
2010-01-10 23:40:39 -05:00
|
|
|
}
|
|
|
|
|
2010-01-13 23:54:03 -05:00
|
|
|
void PrefAccounts::editAccountBtnClicked()
|
|
|
|
{
|
|
|
|
QList<QTableWidgetSelectionRange> selList = _ui->accountsTable->selectedRanges();
|
|
|
|
|
|
|
|
if (selList.isEmpty())
|
|
|
|
return;
|
|
|
|
QTableWidgetSelectionRange range = selList[0];
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
/* Get the selected item */
|
|
|
|
QString gwName = _ui->accountsTable->item(range.topRow(),0)->text();
|
2010-01-13 23:54:03 -05:00
|
|
|
|
|
|
|
if (!_accDlg)
|
|
|
|
{
|
2010-07-03 12:37:32 -04:00
|
|
|
/* TODO: We need a way to read this sucker... Might as well just already pass the profile name */
|
|
|
|
_accDlg = new AccountDialog();
|
2010-01-17 18:10:57 -05:00
|
|
|
connect(_accDlg, SIGNAL(gwAdded(QString)), this, SLOT(readConfig()));
|
2010-01-13 23:54:03 -05:00
|
|
|
}
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
/* TODO: Should pass the profile name someday */
|
|
|
|
_accDlg->setName(gwName);
|
2010-01-13 23:54:03 -05:00
|
|
|
_accDlg->readConfig();
|
|
|
|
|
|
|
|
_accDlg->show();
|
|
|
|
_accDlg->raise();
|
|
|
|
_accDlg->activateWindow();
|
|
|
|
}
|
|
|
|
|
2010-01-13 22:25:27 -05:00
|
|
|
void PrefAccounts::remAccountBtnClicked()
|
|
|
|
{
|
|
|
|
QList<QTableWidgetSelectionRange> sel = _ui->accountsTable->selectedRanges();
|
|
|
|
int offset =0;
|
|
|
|
|
|
|
|
foreach(QTableWidgetSelectionRange range, sel)
|
|
|
|
{
|
|
|
|
for(int row = range.topRow(); row<=range.bottomRow(); row++)
|
|
|
|
{
|
|
|
|
QTableWidgetItem *item = _ui->accountsTable->item(row-offset,0);
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
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;
|
2010-01-20 00:11:40 -05:00
|
|
|
}
|
|
|
|
}
|
2010-07-03 12:37:32 -04:00
|
|
|
settings.setConfigNode(cfg, "sofia.conf");
|
|
|
|
|
|
|
|
/* Mark the account to be deleted */
|
|
|
|
_toDelete.append(item->text());
|
|
|
|
|
2010-01-13 22:25:27 -05:00
|
|
|
_ui->accountsTable->removeRow(row-offset);
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
if (offset)
|
|
|
|
readConfig();
|
2010-01-13 22:25:27 -05:00
|
|
|
}
|
|
|
|
|
2010-01-10 23:40:39 -05:00
|
|
|
void PrefAccounts::writeConfig()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
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()
|
2010-01-10 23:40:39 -05:00
|
|
|
{
|
2010-01-13 21:32:20 -05:00
|
|
|
|
|
|
|
_ui->accountsTable->clearContents();
|
|
|
|
_ui->accountsTable->setRowCount(0);
|
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
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 */
|
|
|
|
}
|
|
|
|
}
|
2010-01-10 23:40:39 -05:00
|
|
|
_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);
|
|
|
|
}
|
2010-07-03 12:37:32 -04:00
|
|
|
|
2010-01-19 18:54:32 -05:00
|
|
|
_ui->accountsTable->resizeRowsToContents();
|
|
|
|
_ui->accountsTable->resizeColumnsToContents();
|
|
|
|
_ui->accountsTable->horizontalHeader()->setStretchLastSection(true);
|
2010-01-10 23:40:39 -05:00
|
|
|
|
2010-07-03 12:37:32 -04:00
|
|
|
/*
|
|
|
|
TODO: We have to figure out what to do with the default account stuff!
|
2010-01-17 23:21:46 -05:00
|
|
|
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->beginGroup("FreeSWITCH/conf/globals");
|
|
|
|
_settings->setValue("default_gateway", default_gateway);
|
|
|
|
_settings->endGroup();
|
|
|
|
switch_core_set_variable("default_gateway", default_gateway.toAscii().data());
|
2010-07-03 12:37:32 -04:00
|
|
|
}*/
|
2010-01-17 23:21:46 -05:00
|
|
|
|
2010-01-10 23:40:39 -05:00
|
|
|
}
|