forked from Mirrors/freeswitch
Remove QObject inheritance from Account and add event for account removal.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16412 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
236db6ae69
commit
b05dfcb946
|
@ -1,6 +1,18 @@
|
|||
#include <QtGui>
|
||||
#include "account.h"
|
||||
|
||||
Account::Account(QObject *parent) :
|
||||
QObject(parent)
|
||||
Account::Account(QString name) :
|
||||
_name(name)
|
||||
{
|
||||
QSettings settings;
|
||||
settings.beginGroup("FreeSWITCH/conf/sofia.conf/profiles/profile/gateways");
|
||||
foreach(QString g, settings.childGroups())
|
||||
{
|
||||
settings.beginGroup(g);
|
||||
if(settings.value("gateway/attrs/name").toString() == name)
|
||||
{
|
||||
_uuid = g;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef ACCOUNT_H
|
||||
#define ACCOUNT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
#define FSCOMM_GW_STATE_TRYING 0
|
||||
#define FSCOMM_GW_STATE_REGISTER 1
|
||||
|
@ -26,20 +26,20 @@ static QString fscomm_gw_state_names[] = {
|
|||
QString("Not applicable")
|
||||
};
|
||||
|
||||
class Account : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
class Account {
|
||||
public:
|
||||
explicit Account(QObject *parent = 0);
|
||||
explicit Account(QString name);
|
||||
void setName(QString name) { _name = name; }
|
||||
QString getName() { return _name; }
|
||||
void setState(int state) { _state = state; }
|
||||
int getState() { return _state; }
|
||||
QString getStateName() { return fscomm_gw_state_names[_state]; }
|
||||
QString getUUID() { return _uuid; }
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
int _state;
|
||||
QString _uuid;
|
||||
};
|
||||
|
||||
#endif // ACCOUNT_H
|
||||
|
|
|
@ -326,8 +326,7 @@ void FSHost::generalEventHandler(switch_event_t *event)
|
|||
QSharedPointer<Account> acc;
|
||||
if (!_accounts.contains(gw))
|
||||
{
|
||||
Account * accPtr = new Account();
|
||||
accPtr->setName(gw);
|
||||
Account * accPtr = new Account(gw);
|
||||
acc = QSharedPointer<Account>(accPtr);
|
||||
_accounts.insert(gw, acc);
|
||||
emit newAccount(acc);
|
||||
|
@ -364,6 +363,11 @@ void FSHost::generalEventHandler(switch_event_t *event)
|
|||
emit accountStateChange(acc);
|
||||
}
|
||||
}
|
||||
else if (strcmp(event->subclass_name, "fscomm::acc_removed") == 0)
|
||||
{
|
||||
QSharedPointer<Account> acc = _accounts.take(switch_event_get_header_nil(event, "acc_name"));
|
||||
emit delAccount(acc);
|
||||
}
|
||||
else
|
||||
{
|
||||
printEventHeaders(event);
|
||||
|
@ -388,6 +392,16 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res)
|
|||
return status;
|
||||
}
|
||||
|
||||
QSharedPointer<Account> FSHost::getAccountByUUID(QString uuid)
|
||||
{
|
||||
foreach(QSharedPointer<Account> acc, _accounts.values())
|
||||
{
|
||||
if (acc.data()->getUUID() == uuid)
|
||||
return acc;
|
||||
}
|
||||
return QSharedPointer<Account>();
|
||||
}
|
||||
|
||||
QSharedPointer<Call> FSHost::getCurrentActiveCall()
|
||||
{
|
||||
foreach(QSharedPointer<Call> call, _active_calls.values())
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
|
||||
QSharedPointer<Call> getCurrentActiveCall();
|
||||
QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
|
||||
QSharedPointer<Account> getAccountByUUID(QString uuid);
|
||||
|
||||
protected:
|
||||
void run(void);
|
||||
|
@ -60,6 +61,7 @@ signals:
|
|||
void hungup(QSharedPointer<Call>);
|
||||
void accountStateChange(QSharedPointer<Account>);
|
||||
void newAccount(QSharedPointer<Account>);
|
||||
void delAccount(QSharedPointer<Account>);
|
||||
|
||||
private:
|
||||
switch_status_t processBlegEvent(switch_event_t *, QString);
|
||||
|
|
|
@ -83,6 +83,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>)));
|
||||
connect(&g_FSHost, SIGNAL(accountStateChange(QSharedPointer<Account>)), this, SLOT(accountStateChanged(QSharedPointer<Account>)));
|
||||
connect(&g_FSHost, SIGNAL(newAccount(QSharedPointer<Account>)), this, SLOT(accountAdd(QSharedPointer<Account>)));
|
||||
connect(&g_FSHost, SIGNAL(delAccount(QSharedPointer<Account>)), this, SLOT(accountDel(QSharedPointer<Account>)));
|
||||
/*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/
|
||||
|
||||
connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
|
||||
|
@ -153,6 +154,22 @@ void MainWindow::accountAdd(QSharedPointer<Account> acc)
|
|||
ui->tableAccounts->horizontalHeader()->setStretchLastSection(true);
|
||||
}
|
||||
|
||||
void MainWindow::accountDel(QSharedPointer<Account> acc)
|
||||
{
|
||||
foreach (QTableWidgetItem *i, ui->tableAccounts->findItems(acc.data()->getName(), Qt::MatchExactly))
|
||||
{
|
||||
if (i->text() == acc.data()->getName())
|
||||
{
|
||||
ui->tableAccounts->removeRow(i->row());
|
||||
ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()-1);
|
||||
ui->tableAccounts->resizeColumnsToContents();
|
||||
ui->tableAccounts->resizeRowsToContents();
|
||||
ui->tableAccounts->horizontalHeader()->setStretchLastSection(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::accountStateChanged(QSharedPointer<Account> acc)
|
||||
{
|
||||
ui->statusBar->showMessage(tr("Account %1 is %2").arg(acc.data()->getName(), acc.data()->getStateName()));
|
||||
|
|
|
@ -76,6 +76,7 @@ private slots:
|
|||
void recordCall(bool);
|
||||
void setDefaultAccount();
|
||||
void accountAdd(QSharedPointer<Account>);
|
||||
void accountDel(QSharedPointer<Account>);
|
||||
void accountStateChanged(QSharedPointer<Account>);
|
||||
|
||||
private:
|
||||
|
|
|
@ -13,6 +13,11 @@ PrefAccounts::PrefAccounts(Ui::PrefDialog *ui) :
|
|||
connect(_ui->sofiaGwEditBtn, SIGNAL(clicked()), this, SLOT(editAccountBtnClicked()));
|
||||
|
||||
_ui->accountsTable->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
if (switch_event_reserve_subclass(FSCOMM_EVENT_ACC_REMOVED) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't register subclass!\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PrefAccounts::addAccountBtnClicked()
|
||||
|
@ -86,6 +91,17 @@ void PrefAccounts::remAccountBtnClicked()
|
|||
_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())
|
||||
{
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "acc_name", acc.data()->getName().toAscii().data());
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "acc_uuid", acc.data()->getUUID().toAscii().data());
|
||||
switch_event_fire(&event);
|
||||
}
|
||||
}
|
||||
_ui->accountsTable->removeRow(row-offset);
|
||||
offset++;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <QObject>
|
||||
#include "ui_prefdialog.h"
|
||||
|
||||
#define FSCOMM_EVENT_ACC_REMOVED "fscomm::acc_removed"
|
||||
|
||||
class QSettings;
|
||||
class AccountDialog;
|
||||
|
||||
|
|
Loading…
Reference in New Issue