Refactor accounts and let the user select default account.
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16399 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
73f386244d
commit
a859650c39
|
@ -30,7 +30,8 @@ SOURCES += main.cpp \
|
||||||
preferences/prefportaudio.cpp \
|
preferences/prefportaudio.cpp \
|
||||||
preferences/prefsofia.cpp \
|
preferences/prefsofia.cpp \
|
||||||
preferences/accountdialog.cpp \
|
preferences/accountdialog.cpp \
|
||||||
preferences/prefaccounts.cpp
|
preferences/prefaccounts.cpp \
|
||||||
|
account.cpp
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
fshost.h \
|
fshost.h \
|
||||||
call.h \
|
call.h \
|
||||||
|
@ -39,7 +40,8 @@ HEADERS += mainwindow.h \
|
||||||
preferences/prefportaudio.h \
|
preferences/prefportaudio.h \
|
||||||
preferences/prefsofia.h \
|
preferences/prefsofia.h \
|
||||||
preferences/accountdialog.h \
|
preferences/accountdialog.h \
|
||||||
preferences/prefaccounts.h
|
preferences/prefaccounts.h \
|
||||||
|
account.h
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
preferences/prefdialog.ui \
|
preferences/prefdialog.ui \
|
||||||
preferences/accountdialog.ui
|
preferences/accountdialog.ui
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "account.h"
|
||||||
|
|
||||||
|
Account::Account(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
#ifndef ACCOUNT_H
|
||||||
|
#define ACCOUNT_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
};
|
||||||
|
|
||||||
|
class Account : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit Account(QObject *parent = 0);
|
||||||
|
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]; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString _name;
|
||||||
|
int _state;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ACCOUNT_H
|
|
@ -43,6 +43,7 @@ FSHost::FSHost(QObject *parent) :
|
||||||
switch_core_set_globals();
|
switch_core_set_globals();
|
||||||
|
|
||||||
qRegisterMetaType<QSharedPointer<Call> >("QSharedPointer<Call>");
|
qRegisterMetaType<QSharedPointer<Call> >("QSharedPointer<Call>");
|
||||||
|
qRegisterMetaType<QSharedPointer<Account> >("QSharedPointer<Account>");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,24 +323,46 @@ void FSHost::generalEventHandler(switch_event_t *event)
|
||||||
{
|
{
|
||||||
QString state = switch_event_get_header_nil(event, "State");
|
QString state = switch_event_get_header_nil(event, "State");
|
||||||
QString gw = switch_event_get_header_nil(event, "Gateway");
|
QString gw = switch_event_get_header_nil(event, "Gateway");
|
||||||
if (state == "TRYING")
|
QSharedPointer<Account> acc;
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_TRYING);
|
if (!_accounts.contains(gw))
|
||||||
else if (state == "REGISTER")
|
{
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_REGISTER);
|
Account * accPtr = new Account();
|
||||||
else if (state == "REGED")
|
accPtr->setName(gw);
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_REGED);
|
acc = QSharedPointer<Account>(accPtr);
|
||||||
else if (state == "UNREGED")
|
_accounts.insert(gw, acc);
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_UNREGED);
|
emit newAccount(acc);
|
||||||
else if (state == "UNREGISTER")
|
}
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_UNREGISTER);
|
else
|
||||||
else if (state =="FAILED")
|
acc = _accounts.value(gw);
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_FAILED);
|
|
||||||
else if (state == "FAIL_WAIT")
|
if (state == "TRYING") {
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_FAIL_WAIT);
|
acc.data()->setState(FSCOMM_GW_STATE_TRYING);
|
||||||
else if (state == "EXPIRED")
|
emit accountStateChange(acc);
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_EXPIRED);
|
} else if (state == "REGISTER") {
|
||||||
else if (state == "NOREG")
|
acc.data()->setState(FSCOMM_GW_STATE_REGISTER);
|
||||||
emit gwStateChange(gw, FSCOMM_GW_STATE_NOREG);
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "REGED") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_REGED);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "UNREGED") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_UNREGED);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "UNREGISTER") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_UNREGISTER);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state =="FAILED") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_FAILED);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "FAIL_WAIT") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_FAIL_WAIT);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "EXPIRED") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_EXPIRED);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
} else if (state == "NOREG") {
|
||||||
|
acc.data()->setState(FSCOMM_GW_STATE_NOREG);
|
||||||
|
emit accountStateChange(acc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -34,29 +34,7 @@
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include "call.h"
|
#include "call.h"
|
||||||
|
#include "account.h"
|
||||||
#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
|
|
||||||
|
|
||||||
|
|
||||||
static const char *fscomm_gw_state_names[] = {
|
|
||||||
"TRYING",
|
|
||||||
"REGISTER",
|
|
||||||
"REGED",
|
|
||||||
"UNREGED",
|
|
||||||
"UNREGISTER",
|
|
||||||
"FAILED",
|
|
||||||
"FAIL_WAIT",
|
|
||||||
"EXPIRED",
|
|
||||||
"NOREG"
|
|
||||||
};
|
|
||||||
|
|
||||||
class FSHost : public QThread
|
class FSHost : public QThread
|
||||||
{
|
{
|
||||||
|
@ -67,7 +45,7 @@ public:
|
||||||
void generalEventHandler(switch_event_t *event);
|
void generalEventHandler(switch_event_t *event);
|
||||||
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
|
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
|
||||||
QSharedPointer<Call> getCurrentActiveCall();
|
QSharedPointer<Call> getCurrentActiveCall();
|
||||||
QString getGwStateName(int id) { return fscomm_gw_state_names[id]; }
|
QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void run(void);
|
void run(void);
|
||||||
|
@ -80,7 +58,8 @@ signals:
|
||||||
void newOutgoingCall(QSharedPointer<Call>);
|
void newOutgoingCall(QSharedPointer<Call>);
|
||||||
void callFailed(QSharedPointer<Call>);
|
void callFailed(QSharedPointer<Call>);
|
||||||
void hungup(QSharedPointer<Call>);
|
void hungup(QSharedPointer<Call>);
|
||||||
void gwStateChange(QString, int);
|
void accountStateChange(QSharedPointer<Account>);
|
||||||
|
void newAccount(QSharedPointer<Account>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
switch_status_t processBlegEvent(switch_event_t *, QString);
|
switch_status_t processBlegEvent(switch_event_t *, QString);
|
||||||
|
@ -88,6 +67,7 @@ private:
|
||||||
void createFolders();
|
void createFolders();
|
||||||
void printEventHeaders(switch_event_t *event);
|
void printEventHeaders(switch_event_t *event);
|
||||||
QHash<QString, QSharedPointer<Call> > _active_calls;
|
QHash<QString, QSharedPointer<Call> > _active_calls;
|
||||||
|
QHash<QString, QSharedPointer<Account> > _accounts;
|
||||||
QHash<QString, QString> _bleg_uuids;
|
QHash<QString, QString> _bleg_uuids;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,7 @@ int main(int argc, char *argv[])
|
||||||
QObject::connect(&g_FSHost, SIGNAL(ready()), splash, SLOT(close()));
|
QObject::connect(&g_FSHost, SIGNAL(ready()), splash, SLOT(close()));
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
QObject::connect(&g_FSHost, SIGNAL(ready()), &w, SLOT(show()));
|
QObject::connect(&g_FSHost, SIGNAL(ready()), &w, SLOT(show()));
|
||||||
|
QObject::connect(&g_FSHost, SIGNAL(ready()), &w, SLOT(print()));
|
||||||
g_FSHost.start();
|
g_FSHost.start();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
connect(&g_FSHost, SIGNAL(hungup(QSharedPointer<Call>)), this, SLOT(hungup(QSharedPointer<Call>)));
|
connect(&g_FSHost, SIGNAL(hungup(QSharedPointer<Call>)), this, SLOT(hungup(QSharedPointer<Call>)));
|
||||||
connect(&g_FSHost, SIGNAL(newOutgoingCall(QSharedPointer<Call>)), this, SLOT(newOutgoingCall(QSharedPointer<Call>)));
|
connect(&g_FSHost, SIGNAL(newOutgoingCall(QSharedPointer<Call>)), this, SLOT(newOutgoingCall(QSharedPointer<Call>)));
|
||||||
connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>)));
|
connect(&g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>)));
|
||||||
connect(&g_FSHost, SIGNAL(gwStateChange(QString,int)), this, SLOT(gwStateChanged(QString,int)));
|
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(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/
|
/*connect(&g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString)));*/
|
||||||
|
|
||||||
connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
|
connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
|
||||||
|
@ -92,6 +93,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered()));
|
connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered()));
|
||||||
connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close()));
|
connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
|
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
|
||||||
|
connect(ui->actionSetDefaultAccount, SIGNAL(triggered(bool)), this, SLOT(setDefaultAccount()));
|
||||||
|
|
||||||
|
/* Set the context menus */
|
||||||
|
ui->tableAccounts->addAction(ui->actionSetDefaultAccount);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -102,6 +108,20 @@ MainWindow::~MainWindow()
|
||||||
g_FSHost.wait();
|
g_FSHost.wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::setDefaultAccount()
|
||||||
|
{
|
||||||
|
QString accName = ui->tableAccounts->item(ui->tableAccounts->selectedRanges()[0].topRow(), 0)->text();
|
||||||
|
|
||||||
|
if (accName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
settings.beginGroup("FreeSWITCH/conf/globals");
|
||||||
|
switch_core_set_variable("default_gateway", accName.toAscii().data());
|
||||||
|
settings.setValue("default_gateway", accName);
|
||||||
|
settings.endGroup();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::prefTriggered()
|
void MainWindow::prefTriggered()
|
||||||
{
|
{
|
||||||
if (!preferences)
|
if (!preferences)
|
||||||
|
@ -118,29 +138,32 @@ void MainWindow::coreLoadingError(QString err)
|
||||||
QApplication::exit(255);
|
QApplication::exit(255);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::gwStateChanged(QString gw, int state)
|
void MainWindow::accountAdd(QSharedPointer<Account> acc)
|
||||||
{
|
{
|
||||||
ui->statusBar->showMessage(tr("Account %1 is %2").arg(gw, g_FSHost.getGwStateName(state)));
|
ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()+1);
|
||||||
|
QTableWidgetItem *gwField = new QTableWidgetItem(acc.data()->getName());
|
||||||
/* TODO: This should be placed somewhere else when the config handler is here... */
|
QTableWidgetItem *stField = new QTableWidgetItem(acc.data()->getStateName());
|
||||||
QList<QTableWidgetItem *> match = ui->tableAccounts->findItems(gw, Qt::MatchExactly);
|
ui->tableAccounts->setItem(ui->tableAccounts->rowCount()-1,0,gwField);
|
||||||
if (match.isEmpty())
|
ui->tableAccounts->setItem(ui->tableAccounts->rowCount()-1,1,stField);
|
||||||
{
|
|
||||||
/* Create the damn thing */
|
|
||||||
ui->tableAccounts->setRowCount(ui->tableAccounts->rowCount()+1);
|
|
||||||
QTableWidgetItem *gwField = new QTableWidgetItem(gw);
|
|
||||||
QTableWidgetItem *stField = new QTableWidgetItem(g_FSHost.getGwStateName(state));
|
|
||||||
ui->tableAccounts->setItem(0,0,gwField);
|
|
||||||
ui->tableAccounts->setItem(0,1,stField);
|
|
||||||
ui->tableAccounts->resizeColumnsToContents();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QTableWidgetItem *gwField = match.at(0);
|
|
||||||
QTableWidgetItem *stField = ui->tableAccounts->item(gwField->row(),1);
|
|
||||||
stField->setText(g_FSHost.getGwStateName(state));
|
|
||||||
ui->tableAccounts->resizeColumnsToContents();
|
ui->tableAccounts->resizeColumnsToContents();
|
||||||
|
ui->tableAccounts->resizeRowsToContents();
|
||||||
|
ui->tableAccounts->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::accountStateChanged(QSharedPointer<Account> acc)
|
||||||
|
{
|
||||||
|
ui->statusBar->showMessage(tr("Account %1 is %2").arg(acc.data()->getName(), acc.data()->getStateName()));
|
||||||
|
foreach (QTableWidgetItem *i, ui->tableAccounts->findItems(acc.data()->getName(), Qt::MatchExactly))
|
||||||
|
{
|
||||||
|
if (i->text() == acc.data()->getName())
|
||||||
|
{
|
||||||
|
ui->tableAccounts->item(i->row(), 1)->setText(acc.data()->getStateName());
|
||||||
|
ui->tableAccounts->resizeColumnsToContents();
|
||||||
|
ui->tableAccounts->resizeRowsToContents();
|
||||||
|
ui->tableAccounts->horizontalHeader()->setStretchLastSection(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::dialDTMF(QString dtmf)
|
void MainWindow::dialDTMF(QString dtmf)
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <fshost.h>
|
#include <fshost.h>
|
||||||
#include <call.h>
|
#include <call.h>
|
||||||
|
#include <account.h>
|
||||||
#include "preferences/prefdialog.h"
|
#include "preferences/prefdialog.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
@ -60,7 +61,6 @@ private slots:
|
||||||
void showAbout();
|
void showAbout();
|
||||||
void prefTriggered();
|
void prefTriggered();
|
||||||
void coreLoadingError(QString);
|
void coreLoadingError(QString);
|
||||||
void gwStateChanged(QString, int);
|
|
||||||
void dialDTMF(QString);
|
void dialDTMF(QString);
|
||||||
void callListDoubleClick(QListWidgetItem *);
|
void callListDoubleClick(QListWidgetItem *);
|
||||||
void makeCall();
|
void makeCall();
|
||||||
|
@ -74,6 +74,9 @@ private slots:
|
||||||
void hungup(QSharedPointer<Call>);
|
void hungup(QSharedPointer<Call>);
|
||||||
void callFailed(QSharedPointer<Call>);
|
void callFailed(QSharedPointer<Call>);
|
||||||
void recordCall(bool);
|
void recordCall(bool);
|
||||||
|
void setDefaultAccount();
|
||||||
|
void accountAdd(QSharedPointer<Account>);
|
||||||
|
void accountStateChanged(QSharedPointer<Account>);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
|
|
@ -269,6 +269,9 @@
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableWidget" name="tableAccounts">
|
<widget class="QTableWidget" name="tableAccounts">
|
||||||
|
<property name="contextMenuPolicy">
|
||||||
|
<enum>Qt::ActionsContextMenu</enum>
|
||||||
|
</property>
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::NoEditTriggers</set>
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
</property>
|
</property>
|
||||||
|
@ -371,6 +374,14 @@
|
||||||
<string>About</string>
|
<string>About</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionSetDefaultAccount">
|
||||||
|
<property name="text">
|
||||||
|
<string>Set Default Account</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Set the default account for dialing out.</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in New Issue