Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp (16113 => 16114)
--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp 2010-01-01 20:00:18 UTC (rev 16113)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.cpp 2010-01-02 02:29:00 UTC (rev 16114)
@@ -58,6 +58,38 @@
void FSHost::generalEventHandler(switch_event_t *event)
{
+ QString uuid = switch_event_get_header_nil(event, "Unique-ID");
+
+ if (_active_calls.contains(uuid))
+ {
+ switch(event->event_id) {
+ case SWITCH_EVENT_CHANNEL_ANSWER:
+ case SWITCH_EVENT_CHANNEL_BRIDGE:
+ {
+ emit answered(uuid);
+ break;
+ }
+ case SWITCH_EVENT_CHANNEL_HANGUP_COMPLETE:
+ {
+ emit hungup(uuid);
+ break;
+ }
+ case SWITCH_EVENT_CUSTOM:
+ {
+ /* We dont want to treat this anymore */
+ if (strcmp(event->subclass_name, "portaudio::ringing") == 0)
+ {
+ return;
+ }
+ }
+ default:
+ {
+ printf("Untreated event from an UUID we have: %s -> %s | %s\n", switch_event_name(event->event_id), (!zstr(event->subclass_name) ? event->subclass_name : "NULL"), uuid.toAscii().constData());
+ }
+ }
+ }
+
+ /* This is how we identify new calls, inbound and outbound */
switch(event->event_id) {
case SWITCH_EVENT_CUSTOM:
{
@@ -67,19 +99,25 @@
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);
+ uuid);
+ _active_calls.insert(uuid, call);
+ emit ringing(uuid);
}
+ else if (strcmp(event->subclass_name, "portaudio::makecall") == 0)
+ {
+ Call *call = new Call(atoi(switch_event_get_header_nil(event, "call_id")),NULL,
+ switch_event_get_header_nil(event, "Caller-Destination-Number"),
+ FSPHONE_CALL_DIRECTION_INBOUND,
+ uuid);
+ _active_calls.insert(uuid, call);
+ emit newOutgoingCall(uuid);
+ }
else
{
printf("We got a not treated custom event: %s\n", (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
}
break;
}
- default:
- {
- printf("Untreated event: %s -> %s\n", switch_event_name(event->event_id), (!zstr(event->subclass_name) ? event->subclass_name : "NULL"));
- }
}
}
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h (16113 => 16114)
--- freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h 2010-01-01 20:00:18 UTC (rev 16113)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/fshost.h 2010-01-02 02:29:00 UTC (rev 16114)
@@ -2,6 +2,7 @@
#define FSHOST_H
#include <QThread>
+#include <QHash>
#include <switch.h>
class Call;
@@ -13,14 +14,20 @@
explicit FSHost(QObject *parent = 0);
switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event);
+ Call * getCallByUUID(QString uuid) { return _active_calls.value(uuid, NULL); }
protected:
void run(void);
signals:
void ready(void);
- void ringing(Call *call);
+ void ringing(QString);
+ void answered(QString);
+ void newOutgoingCall(QString);
+ void hungup(QString);
+private:
+ QHash<QString, Call*> _active_calls;
};
extern FSHost g_FSHost;
@@ -35,7 +42,7 @@
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
g_FSHost.generalEventHandler(clone);
}
- /*switch_safe_free(event);*/
+ switch_safe_free(clone);
}
#endif // FSHOST_H
Modified: freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp (16113 => 16114)
--- freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp 2010-01-01 20:00:18 UTC (rev 16113)
+++ freeswitch/trunk/contrib/jmesquita/FSPhone/mainwindow.cpp 2010-01-02 02:29:00 UTC (rev 16114)
@@ -1,3 +1,4 @@
+#include <QInputDialog>
#include "mainwindow.h"
#include "ui_mainwindow.h"
@@ -8,7 +9,12 @@
ui->setupUi(this);
connect(&g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady()));
- connect(&g_FSHost, SIGNAL(ringing(Call *)), this, SLOT(ringing(Call *)));
+ connect(&g_FSHost, SIGNAL(ringing(QString)), this, SLOT(ringing(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(newOutgoingCall(QString)), this, SLOT(newOutgoingCall(QString)));
+
+ connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall()));
connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer()));
connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup()));
connect(ui->listCalls, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(callListDoubleClick(QListWidgetItem*)));
@@ -26,7 +32,7 @@
void MainWindow::callListDoubleClick(QListWidgetItem *item)
{
- Call *call = _lines.value(item->data(Qt::UserRole).toString());
+ Call *call = g_FSHost.getCallByUUID(item->data(Qt::UserRole).toString());
QString switch_str = QString("switch %1").arg(call->getCallID());
QString result;
if (g_FSHost.sendCmd("pa", switch_str.toAscii(), &result) == SWITCH_STATUS_FALSE) {
@@ -36,9 +42,22 @@
ui->hangupBtn->setEnabled(true);
}
+void MainWindow::makeCall()
+{
+ bool ok;
+ QString dialstring = QInputDialog::getText(this, tr("Make new call"),
+ tr("Number to dial:"), QLineEdit::Normal, NULL,&ok);
+
+ if (ok && !dialstring.isEmpty())
+ {
+ paCall(dialstring);
+ }
+}
+
void MainWindow::fshostReady()
{
ui->statusBar->showMessage("Ready", 0);
+ ui->newCallBtn->setEnabled(true);
ui->textEdit->setEnabled(true);
ui->textEdit->setText("Click on line to dial number...");
}
@@ -55,11 +74,11 @@
ui->answerBtn->setEnabled(false);
}
-void MainWindow::paCall()
+void MainWindow::paCall(QString dialstring)
{
QString result;
- QString callstring = QString("call %1").arg(ui->textEdit->toPlainText());
+ QString callstring = QString("call %1").arg(dialstring);
if (g_FSHost.sendCmd("pa", callstring.toAscii(), &result) == SWITCH_STATUS_FALSE) {
ui->textEdit->setText("Error sending that command");
@@ -80,20 +99,57 @@
ui->hangupBtn->setEnabled(false);
}
-void MainWindow::ringing(Call *call)
+void MainWindow::newOutgoingCall(QString uuid)
{
- if (_lines.contains(call->getUUID()))
+ Call *call = g_FSHost.getCallByUUID(uuid);
+ ui->textEdit->setText(QString("Calling %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
+ QListWidgetItem *item = new QListWidgetItem(tr("%1 (%2) - Calling").arg(call->getCidName(), call->getCidNumber()));
+ item->setData(Qt::UserRole, uuid);
+ ui->listCalls->addItem(item);
+ ui->hangupBtn->setEnabled(true);
+}
+
+void MainWindow::ringing(QString uuid)
+{
+
+ Call *call = g_FSHost.getCallByUUID(uuid);
+ ui->textEdit->setText(QString("Call from %1 (%2)").arg(call->getCidName(), call->getCidNumber()));
+ QListWidgetItem *item = new QListWidgetItem(tr("%1 (%2) - Ringing").arg(call->getCidName(), call->getCidNumber()));
+ item->setData(Qt::UserRole, uuid);
+ ui->listCalls->addItem(item);
+ ui->answerBtn->setEnabled(true);
+}
+
+void MainWindow::answered(QString uuid)
+{
+ Call *call = g_FSHost.getCallByUUID(uuid);
+ for (int i=0; i<ui->listCalls->count(); i++)
{
- delete call;
+ QListWidgetItem *item = ui->listCalls->item(i);
+ if (item->data(Qt::UserRole).toString() == uuid)
+ {
+ item->setText(tr("%1 (%2) - Active").arg(call->getCidName(), call->getCidNumber()));
+ break;
+ }
}
- else
+}
+
+void MainWindow::hungup(QString uuid)
+{
+ Call *call = g_FSHost.getCallByUUID(uuid);
+ for (int i=0; i<ui->listCalls->count(); i++)
{
- _lines.insert(call->getUUID(), call);
- ui->textEdit->setText(QString("Number: %1\nName: %3").arg(call->getCidNumber(), call->getCidName()));
- QListWidgetItem *item = new QListWidgetItem(tr("%1 - %2 (Ringing)").arg(call->getCidName(), call->getCidNumber()), ui->listCalls);
- item->setData(Qt::UserRole, call->getUUID());
+ QListWidgetItem *item = ui->listCalls->item(i);
+ if (item->data(Qt::UserRole).toString() == uuid)
+ {
+ delete ui->listCalls->takeItem(i);
+ break;
+ }
}
- ui->answerBtn->setEnabled(true);
+ ui->textEdit->setText(tr("Call with %1 (%2) hungup.").arg(call->getCidName(), call->getCidNumber()));
+ /* TODO: Will cause problems if 2 calls are received at the same time */
+ ui->answerBtn->setEnabled(false);
+ ui->hangupBtn->setEnabled(false);
}
void MainWindow::changeEvent(QEvent *e)