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-13 22:25:27 -05:00
|
|
|
#include "fshost.h"
|
2010-01-10 23:40:39 -05:00
|
|
|
|
|
|
|
PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) :
|
|
|
|
_ui(ui)
|
|
|
|
{
|
|
|
|
_settings = new QSettings();
|
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-13 21:32:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrefAccounts::addAccountBtnClicked()
|
|
|
|
{
|
|
|
|
if (!_accDlg)
|
|
|
|
{
|
2010-01-13 22:25:27 -05:00
|
|
|
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);
|
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
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
_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];
|
|
|
|
|
|
|
|
QString uuid = _ui->accountsTable->item(range.topRow(),0)->data(Qt::UserRole).toString();
|
|
|
|
|
|
|
|
if (!_accDlg)
|
|
|
|
{
|
|
|
|
_accDlg = new AccountDialog(uuid);
|
2010-01-17 18:10:57 -05:00
|
|
|
connect(_accDlg, SIGNAL(gwAdded(QString)), this, SLOT(readConfig()));
|
2010-01-13 23:54:03 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_accDlg->setAccId(uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
|
|
|
_settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
|
|
|
|
_settings->remove(item->data(Qt::UserRole).toString());
|
|
|
|
_settings->endGroup();
|
|
|
|
_ui->accountsTable->removeRow(row-offset);
|
|
|
|
offset++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
{
|
|
|
|
QString res;
|
2010-01-17 23:21:46 -05:00
|
|
|
_settings->sync();
|
2010-01-13 22:25:27 -05:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
readConfig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-10 23:40:39 -05:00
|
|
|
void PrefAccounts::writeConfig()
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrefAccounts::readConfig()
|
|
|
|
{
|
2010-01-13 21:32:20 -05:00
|
|
|
|
|
|
|
_ui->accountsTable->clearContents();
|
|
|
|
_ui->accountsTable->setRowCount(0);
|
|
|
|
|
|
|
|
_settings->beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
|
|
|
|
|
|
|
|
foreach(QString accId, _settings->childGroups())
|
2010-01-10 23:40:39 -05:00
|
|
|
{
|
2010-01-13 21:32:20 -05:00
|
|
|
_settings->beginGroup(accId);
|
|
|
|
_settings->beginGroup("gateway/attrs");
|
|
|
|
QTableWidgetItem *item0 = new QTableWidgetItem(_settings->value("name").toString());
|
2010-01-13 22:25:27 -05:00
|
|
|
item0->setData(Qt::UserRole, accId);
|
2010-01-13 21:32:20 -05:00
|
|
|
_settings->endGroup();
|
|
|
|
_settings->beginGroup("gateway/params");
|
2010-01-10 23:40:39 -05:00
|
|
|
QTableWidgetItem *item1 = new QTableWidgetItem(_settings->value("username").toString());
|
2010-01-13 22:25:27 -05:00
|
|
|
item1->setData(Qt::UserRole, accId);
|
2010-01-10 23:40:39 -05:00
|
|
|
_settings->endGroup();
|
2010-01-13 21:32:20 -05:00
|
|
|
_settings->endGroup();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
_settings->endGroup();
|
2010-01-17 23:21:46 -05:00
|
|
|
|
|
|
|
QString res;
|
|
|
|
_settings->sync();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-01-10 23:40:39 -05:00
|
|
|
}
|