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

Initial work to support multiple lines. Took away the dial for a minute. Sorry about that.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@16111 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 71db7fd1
......@@ -25,9 +25,9 @@ LIBS = -L../../../.libs \
SOURCES += main.cpp \
mainwindow.cpp \
fshost.cpp
#call.cpp
fshost.cpp \
call.cpp
HEADERS += mainwindow.h \
fshost.h
#call.h
fshost.h \
call.h
FORMS += mainwindow.ui
#include "call.h"
Call::Call(int call_id, QString cid_name, QString cid_number) :
Call::Call()
{
}
Call::Call(int call_id, QString cid_name, QString cid_number, fsphone_call_direction_t direction, QString uuid) :
_call_id(call_id),
_cid_name(cid_name),
_cid_number(cid_number)
_cid_number(cid_number),
_direction(direction),
_uuid (uuid)
{
}
#ifndef CALL_H
#define CALL_H
#include <QtCore>
#include <QString>
#include <fshost.h>
......@@ -12,13 +13,21 @@ typedef enum {
class Call
{
public:
Call(int call_id, QString cid_name, QString cid_number);
Call(void);
Call(int call_id, QString cid_name, QString cid_number, fsphone_call_direction_t direction, QString uuid);
QString getCidName(void) { return _cid_name; }
QString getCidNumber(void) { return _cid_number; }
int getCallID(void) { return _call_id; }
QString getUUID(void) { return _uuid; }
private:
int _call_id;
QString _cid_name;
QString _cid_number;
fsphone_call_direction_t _direction;
QString _uuid;
};
Q_DECLARE_METATYPE(Call)
#endif // CALL_H
#include <QtGui>
#include "fshost.h"
#include "call.h"
/* Declare it globally */
FSHost g_FSHost;
......@@ -10,6 +12,9 @@ FSHost::FSHost(QObject *parent) :
printf("Initializing globals...\n");
switch_core_setrlimits();
switch_core_set_globals();
qRegisterMetaType<Call>("Call");
}
void FSHost::run(void)
......@@ -58,7 +63,12 @@ void FSHost::generalEventHandler(switch_event_t *event)
{
if (strcmp(event->subclass_name, "portaudio::ringing") == 0)
{
emit ringing(switch_event_get_header_nil(event, "call_id"), switch_event_get_header_nil(event, "Caller-Caller-ID-Number"), switch_event_get_header_nil(event, "Caller-Caller-ID-Name"));
Call *call = new Call(atoi(switch_event_get_header_nil(event, "call_id")),
switch_event_get_header_nil(event, "Caller-Caller-ID-Name"),
switch_event_get_header_nil(event, "Caller-Caller-ID-Number"),
FSPHONE_CALL_DIRECTION_INBOUND,
switch_event_get_header_nil(event, "Unique-ID"));
emit ringing(call);
}
else
{
......
......@@ -4,6 +4,8 @@
#include <QThread>
#include <switch.h>
class Call;
class FSHost : public QThread
{
Q_OBJECT
......@@ -17,7 +19,7 @@ protected:
signals:
void ready(void);
void ringing(QString uuid, QString caller_id_name, QString caller_id_name);
void ringing(Call *call);
};
......
......@@ -8,11 +8,9 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
connect(&g_FSHost, SIGNAL(ringing(QString,QString,QString)), this, SLOT(ringing(QString,QString,QString)));
connect(&g_FSHost, SIGNAL(ringing(Call *)), this, SLOT(ringing(Call *)));
connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer()));
connect(ui->callBtn, SIGNAL(clicked()), this, SLOT(paCall()));
connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup()));
connect(ui->paDevlistBtn, SIGNAL(clicked()), this, SLOT(paDevlist()));
g_FSHost.start();
}
......@@ -28,20 +26,8 @@ MainWindow::~MainWindow()
void MainWindow::fshostReady()
{
ui->statusBar->showMessage("Ready", 0);
ui->paDevlistBtn->setEnabled(true);
ui->textEdit->setEnabled(true);
ui->callBtn->setEnabled(true);
ui->textEdit->setText("Click to dial number...");
}
void MainWindow::paDevlist()
{
QString result;
if (g_FSHost.sendCmd("pa", "devlist as xml", &result) == SWITCH_STATUS_FALSE) {
ui->textEdit->setText("Error sending that command");
}
ui->textEdit->setText(result);
ui->textEdit->setText("Click on line to dial number...");
}
void MainWindow::paAnswer()
......@@ -51,11 +37,9 @@ void MainWindow::paAnswer()
ui->textEdit->setText("Error sending that command");
}
ui->textEdit->setReadOnly(true);
ui->textEdit->setText("Talking...");
ui->hangupBtn->setEnabled(true);
ui->answerBtn->setEnabled(false);
ui->callBtn->setEnabled(false);
}
void MainWindow::paCall()
......@@ -81,13 +65,18 @@ void MainWindow::paHangup()
ui->textEdit->setText("Click to dial number...");
ui->statusBar->showMessage("Call hungup", 10);
ui->hangupBtn->setEnabled(false);
ui->textEdit->setReadOnly(false);
ui->callBtn->setEnabled(true);
}
void MainWindow::ringing(QString uuid, QString caller_id_number, QString caller_id_name)
void MainWindow::ringing(Call *call)
{
ui->textEdit->setText(QString("Number: %1\nName: %3").arg(caller_id_number, caller_id_name));
if (_lines.contains(call->getUUID()))
{
delete call;
}
else
{
ui->textEdit->setText(QString("Number: %1\nName: %3").arg(call->getCidNumber(), call->getCidName()));
}
ui->answerBtn->setEnabled(true);
}
......
......@@ -34,8 +34,10 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include <QPushButton>
#include <switch.h>
#include <fshost.h>
#include <call.h>
namespace Ui {
class MainWindow;
......@@ -52,14 +54,14 @@ protected:
private slots:
void fshostReady();
void paDevlist();
void paAnswer();
void paCall();
void paHangup();
void ringing(QString, QString, QString);
void ringing(Call *);
private:
Ui::MainWindow *ui;
QHash<QString, Call *> _lines;
};
#endif // MAINWINDOW_H
......@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>287</width>
<height>471</height>
<height>438</height>
</rect>
</property>
<property name="windowTitle">
......@@ -21,23 +21,13 @@
<bool>false</bool>
</property>
<property name="readOnly">
<bool>false</bool>
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="callBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Call</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QPushButton" name="answerBtn">
<property name="enabled">
<bool>false</bool>
......@@ -47,17 +37,7 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="paDevlistBtn">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>pa devlist</string>
</property>
</widget>
</item>
<item>
<item row="0" column="1">
<widget class="QPushButton" name="hangupBtn">
<property name="enabled">
<bool>false</bool>
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论