提交 f5dee82f authored 作者: João Mesquita's avatar João Mesquita

Display account information

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@16117 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 4bbdae72
...@@ -112,6 +112,29 @@ void FSHost::generalEventHandler(switch_event_t *event) ...@@ -112,6 +112,29 @@ void FSHost::generalEventHandler(switch_event_t *event)
_active_calls.insert(uuid, call); _active_calls.insert(uuid, call);
emit newOutgoingCall(uuid); emit newOutgoingCall(uuid);
} }
else if (strcmp(event->subclass_name, "sofia::gateway_state") == 0)
{
QString state = switch_event_get_header_nil(event, "State");
QString gw = switch_event_get_header_nil(event, "Gateway");
if (state == "TRYING")
emit gwStateChange(gw, FSPHONE_GW_STATE_TRYING);
else if (state == "REGISTER")
emit gwStateChange(gw, FSPHONE_GW_STATE_REGISTER);
else if (state == "REGED")
emit gwStateChange(gw, FSPHONE_GW_STATE_REGED);
else if (state == "UNREGED")
emit gwStateChange(gw, FSPHONE_GW_STATE_UNREGED);
else if (state == "UNREGISTER")
emit gwStateChange(gw, FSPHONE_GW_STATE_UNREGISTER);
else if (state =="FAILED")
emit gwStateChange(gw, FSPHONE_GW_STATE_FAILED);
else if (state == "FAIL_WAIT")
emit gwStateChange(gw, FSPHONE_GW_STATE_FAIL_WAIT);
else if (state == "EXPIRED")
emit gwStateChange(gw, FSPHONE_GW_STATE_EXPIRED);
else if (state == "NOREG")
emit gwStateChange(gw, FSPHONE_GW_STATE_NOREG);
}
else else
{ {
printf("We got a not treated custom event: %s\n", (!zstr(event->subclass_name) ? event->subclass_name : "NULL")); printf("We got a not treated custom event: %s\n", (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
......
...@@ -7,6 +7,28 @@ ...@@ -7,6 +7,28 @@
class Call; class Call;
#define FSPHONE_GW_STATE_TRYING 0
#define FSPHONE_GW_STATE_REGISTER 1
#define FSPHONE_GW_STATE_REGED 2
#define FSPHONE_GW_STATE_UNREGED 3
#define FSPHONE_GW_STATE_UNREGISTER 4
#define FSPHONE_GW_STATE_FAILED 5
#define FSPHONE_GW_STATE_FAIL_WAIT 6
#define FSPHONE_GW_STATE_EXPIRED 7
#define FSPHONE_GW_STATE_NOREG 8
static const char *fsphone_gw_state_names[] = {
"TRYING",
"REGISTER",
"REGED",
"UNREGED",
"UNREGISTER",
"FAILED",
"FAIL_WAIT",
"EXPIRED",
"NOREG"
};
class FSHost : public QThread class FSHost : public QThread
{ {
Q_OBJECT Q_OBJECT
...@@ -15,6 +37,7 @@ public: ...@@ -15,6 +37,7 @@ public:
switch_status_t sendCmd(const char *cmd, const char *args, QString *res); switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event); void generalEventHandler(switch_event_t *event);
Call * getCallByUUID(QString uuid) { return _active_calls.value(uuid, NULL); } Call * getCallByUUID(QString uuid) { return _active_calls.value(uuid, NULL); }
QString getGwStateName(int id) { return fsphone_gw_state_names[id]; }
protected: protected:
void run(void); void run(void);
...@@ -25,6 +48,7 @@ signals: ...@@ -25,6 +48,7 @@ signals:
void answered(QString); void answered(QString);
void newOutgoingCall(QString); void newOutgoingCall(QString);
void hungup(QString); void hungup(QString);
void gwStateChange(QString, int);
private: private:
QHash<QString, Call*> _active_calls; QHash<QString, Call*> _active_calls;
......
...@@ -40,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -40,6 +40,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(&g_FSHost, SIGNAL(answered(QString)), this, SLOT(answered(QString))); connect(&g_FSHost, SIGNAL(answered(QString)), this, SLOT(answered(QString)));
connect(&g_FSHost, SIGNAL(hungup(QString)), this, SLOT(hungup(QString))); connect(&g_FSHost, SIGNAL(hungup(QString)), this, SLOT(hungup(QString)));
connect(&g_FSHost, SIGNAL(newOutgoingCall(QString)), this, SLOT(newOutgoingCall(QString))); connect(&g_FSHost, SIGNAL(newOutgoingCall(QString)), this, SLOT(newOutgoingCall(QString)));
connect(&g_FSHost, SIGNAL(gwStateChange(QString,int)), this, SLOT(gwStateChanged(QString,int)));
connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall())); connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer())); connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer()));
...@@ -57,6 +58,31 @@ MainWindow::~MainWindow() ...@@ -57,6 +58,31 @@ MainWindow::~MainWindow()
g_FSHost.wait(); g_FSHost.wait();
} }
void MainWindow::gwStateChanged(QString gw, int state)
{
ui->statusBar->showMessage(tr("Account %1 is %2").arg(gw, g_FSHost.getGwStateName(state)));
/* TODO: This should be placed somewhere else when the config handler is here... */
QList<QTableWidgetItem *> match = ui->tableAccounts->findItems(gw, Qt::MatchExactly);
if (match.isEmpty())
{
/* 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();
}
void MainWindow::dialDTMF(QString dtmf) void MainWindow::dialDTMF(QString dtmf)
{ {
QString result; QString result;
...@@ -92,7 +118,7 @@ void MainWindow::makeCall() ...@@ -92,7 +118,7 @@ void MainWindow::makeCall()
void MainWindow::fshostReady() void MainWindow::fshostReady()
{ {
ui->statusBar->showMessage("Ready", 0); ui->statusBar->showMessage("Ready");
ui->newCallBtn->setEnabled(true); ui->newCallBtn->setEnabled(true);
ui->textEdit->setEnabled(true); ui->textEdit->setEnabled(true);
ui->textEdit->setText("Ready to dial and receive calls!"); ui->textEdit->setText("Ready to dial and receive calls!");
...@@ -131,7 +157,7 @@ void MainWindow::paHangup() ...@@ -131,7 +157,7 @@ void MainWindow::paHangup()
} }
ui->textEdit->setText("Click to dial number..."); ui->textEdit->setText("Click to dial number...");
ui->statusBar->showMessage("Call hungup", 10); ui->statusBar->showMessage("Call hungup");
ui->hangupBtn->setEnabled(false); ui->hangupBtn->setEnabled(false);
} }
......
...@@ -57,6 +57,7 @@ signals: ...@@ -57,6 +57,7 @@ signals:
void dtmfDialed(QString); void dtmfDialed(QString);
private slots: private slots:
void gwStateChanged(QString, int);
void dialDTMF(QString); void dialDTMF(QString);
void callListDoubleClick(QListWidgetItem *); void callListDoubleClick(QListWidgetItem *);
void makeCall(); void makeCall();
......
...@@ -6,15 +6,15 @@ ...@@ -6,15 +6,15 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>805</width> <width>579</width>
<height>500</height> <height>541</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>FSPhone - A FreeSWITCH softphone</string> <string>FSPhone - A FreeSWITCH softphone</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_4">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
...@@ -198,13 +198,78 @@ ...@@ -198,13 +198,78 @@
<property name="title"> <property name="title">
<string>Active Calls</string> <string>Active Calls</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<widget class="QListWidget" name="listCalls"/> <widget class="QListWidget" name="listCalls"/>
</item> </item>
</layout> </layout>
</widget> </widget>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Active Accounts</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QTableWidget" name="tableAccounts">
<property name="alternatingRowColors">
<bool>false</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="cornerButtonEnabled">
<bool>true</bool>
</property>
<property name="rowCount">
<number>0</number>
</property>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
</attribute>
<attribute name="horizontalHeaderVisible">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderHighlightSections">
<bool>false</bool>
</attribute>
<column>
<property name="text">
<string>Account</string>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>
...@@ -214,7 +279,7 @@ ...@@ -214,7 +279,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>805</width> <width>579</width>
<height>24</height> <height>24</height>
</rect> </rect>
</property> </property>
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论