From 9952b6ef71f5332f4de197b4c9537b65d7643f54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mesquita?= Date: Mon, 18 Jan 2010 02:43:48 +0000 Subject: [PATCH] FSCOMM-1 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16349 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- fscomm/call.cpp | 25 +++++++++++++++++++++++++ fscomm/call.h | 6 ++++++ fscomm/fshost.cpp | 24 ++++++++++++++++++------ fscomm/fshost.h | 1 + fscomm/mainwindow.cpp | 33 +++++++++++++++++++++++++++++++++ fscomm/mainwindow.h | 1 + fscomm/mainwindow.ui | 13 +++++++++++++ 7 files changed, 97 insertions(+), 6 deletions(-) diff --git a/fscomm/call.cpp b/fscomm/call.cpp index dc7a9c481d..8bcd47deea 100644 --- a/fscomm/call.cpp +++ b/fscomm/call.cpp @@ -41,4 +41,29 @@ Call::Call(int call_id, QString cid_name, QString cid_number, fscomm_call_direct _direction(direction), _uuid (uuid) { + _isActive = false; +} + +switch_status_t Call::toggleRecord(bool startRecord) +{ + QDir conf_dir = QDir::home(); + QString result; + switch_status_t status; + + if (startRecord) + { + _recording_filename = QString("%1/.fscomm/recordings/%2_%3.wav").arg( + conf_dir.absolutePath(), + QDateTime::currentDateTime().toString("yyyyMMddhhmmss"), + _cid_number); + status = g_FSHost.sendCmd("uuid_record", QString("%1 start %2").arg(_uuid, _recording_filename).toAscii().data(),&result); + } + else + { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stopping call recording on call [%s]\n", + _uuid.toAscii().data()); + status = g_FSHost.sendCmd("uuid_record", QString("%1 stop %2").arg(_uuid, _recording_filename).toAscii().data(),&result); + } + + return status; } diff --git a/fscomm/call.h b/fscomm/call.h index 11edee47f6..4e6aeb682d 100644 --- a/fscomm/call.h +++ b/fscomm/call.h @@ -31,6 +31,7 @@ #include #include +#include typedef enum { FSCOMM_CALL_STATE_RINGING = 0, @@ -59,6 +60,9 @@ public: void setState(fscomm_call_state_t state) { _state = state; } void setCause(QString cause) { _cause = cause; } QString getCause() { return _cause; } + void setActive(bool isActive) { _isActive = isActive; } + bool isActive() { return _isActive == true; } + switch_status_t toggleRecord(bool); private: int _call_id; @@ -68,6 +72,8 @@ private: fscomm_call_direction_t _direction; QString _uuid; QString _buuid; + bool _isActive; + QString _recording_filename; fscomm_call_state_t _state; }; diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index d7a7768232..a80ea27628 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -51,17 +51,18 @@ void FSHost::createFolders() /* Create directory structure for softphone with default configs */ QDir conf_dir = QDir::home(); if (!conf_dir.exists(".fscomm")) - { - conf_dir.mkpath(".fscomm/conf/accounts"); + conf_dir.mkpath(".fscomm"); + if (!conf_dir.exists(".fscomm/recordings")) + conf_dir.mkpath(".fscomm/recordings"); + if (!conf_dir.exists(".fscomm/sounds")) { conf_dir.mkpath(".fscomm/sounds"); QFile::copy(":/sounds/test.wav", QString("%1/.fscomm/sounds/test.wav").arg(QDir::homePath())); + } + if(!QFile::exists(QString("%1/.fscomm/conf/freeswitch.xml").arg(conf_dir.absolutePath()))) { + conf_dir.mkdir(".fscomm/conf"); QFile rootXML(":/confs/freeswitch.xml"); QString dest = QString("%1/.fscomm/conf/freeswitch.xml").arg(conf_dir.absolutePath()); rootXML.copy(dest); - - QFile defaultAccount(":/confs/template.xml"); - dest = QString("%1/.fscomm/conf/accounts/template.xml").arg(conf_dir.absolutePath()); - defaultAccount.copy(dest); } /* Set all directories to the home user directory */ @@ -351,6 +352,7 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res) switch_status_t status = SWITCH_STATUS_FALSE; switch_stream_handle_t stream = { 0 }; SWITCH_STANDARD_STREAM(stream); + qDebug() << "Sending command: " << cmd << args << endl; status = switch_api_execute(cmd, args, NULL, &stream); *res = switch_str_nil((char *) stream.data); switch_safe_free(stream.data); @@ -358,6 +360,16 @@ switch_status_t FSHost::sendCmd(const char *cmd, const char *args, QString *res) return status; } +QSharedPointer FSHost::getCurrentActiveCall() +{ + foreach(QSharedPointer call, _active_calls.values()) + { + if (call.data()->isActive()) + return call; + } + return QSharedPointer(); +} + void FSHost::printEventHeaders(switch_event_t *event) { switch_event_header_t *hp; diff --git a/fscomm/fshost.h b/fscomm/fshost.h index 9fbb17533d..cb172f324d 100644 --- a/fscomm/fshost.h +++ b/fscomm/fshost.h @@ -66,6 +66,7 @@ public: switch_status_t sendCmd(const char *cmd, const char *args, QString *res); void generalEventHandler(switch_event_t *event); QSharedPointer getCallByUUID(QString uuid) { return _active_calls.value(uuid); } + QSharedPointer getCurrentActiveCall(); QString getGwStateName(int id) { return fscomm_gw_state_names[id]; } protected: diff --git a/fscomm/mainwindow.cpp b/fscomm/mainwindow.cpp index b0df49145a..9d8b22545d 100644 --- a/fscomm/mainwindow.cpp +++ b/fscomm/mainwindow.cpp @@ -87,6 +87,7 @@ MainWindow::MainWindow(QWidget *parent) : 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->recoredCallBtn, SIGNAL(toggled(bool)), SLOT(recordCall(bool))); connect(ui->listCalls, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(callListDoubleClick(QListWidgetItem*))); connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered())); connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); @@ -153,6 +154,7 @@ void MainWindow::dialDTMF(QString dtmf) void MainWindow::callListDoubleClick(QListWidgetItem *item) { + QSharedPointer lastCall = g_FSHost.getCurrentActiveCall(); QSharedPointer call = g_FSHost.getCallByUUID(item->data(Qt::UserRole).toString()); QString switch_str = QString("switch %1").arg(call.data()->getCallID()); QString result; @@ -161,6 +163,8 @@ void MainWindow::callListDoubleClick(QListWidgetItem *item) return; } ui->hangupBtn->setEnabled(true); + lastCall.data()->setActive(false); + call.data()->setActive(true); } void MainWindow::makeCall() @@ -220,6 +224,31 @@ void MainWindow::paHangup() ui->hangupBtn->setEnabled(false); } +void MainWindow::recordCall(bool pressed) +{ + QSharedPointer call = g_FSHost.getCurrentActiveCall(); + + if (call.isNull()) + { + QMessageBox::warning(this,tr("Record call"), + tr("

FSComm reports that there are no active calls to be recorded." + "

Please report this bug."), + QMessageBox::Ok); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not record call because there is not current active call!.\n"); + return; + } + + if (call.data()->toggleRecord(pressed) != SWITCH_STATUS_SUCCESS) + { + QMessageBox::warning(this,tr("Record call"), + tr("

Could not get active call to start/stop recording." + "

Please report this bug."), + QMessageBox::Ok); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not record call [%s].\n", call.data()->getUUID().toAscii().data()); + return; + } +} + void MainWindow::newOutgoingCall(QSharedPointer call) { ui->textEdit->setText(QString("Calling %1 (%2)").arg(call.data()->getCidName(), call.data()->getCidNumber())); @@ -227,6 +256,7 @@ void MainWindow::newOutgoingCall(QSharedPointer call) item->setData(Qt::UserRole, call.data()->getUUID()); ui->listCalls->addItem(item); ui->hangupBtn->setEnabled(true); + call.data()->setActive(true); } void MainWindow::ringing(QSharedPointer call) @@ -248,6 +278,7 @@ void MainWindow::ringing(QSharedPointer call) item->setData(Qt::UserRole, call.data()->getUUID()); ui->listCalls->addItem(item); ui->answerBtn->setEnabled(true); + call.data()->setActive(true); } void MainWindow::answered(QSharedPointer call) @@ -301,6 +332,7 @@ void MainWindow::callFailed(QSharedPointer call) ui->textEdit->setText(tr("Call with %1 (%2) failed with reason %3.").arg(call.data()->getCidName(), call.data()->getCidNumber(), call.data()->getCause())); + call.data()->setActive(false); /* TODO: Will cause problems if 2 calls are received at the same time */ ui->answerBtn->setEnabled(false); ui->hangupBtn->setEnabled(false); @@ -334,6 +366,7 @@ void MainWindow::hungup(QSharedPointer call) break; } } + call.data()->setActive(false); ui->textEdit->setText(tr("Call with %1 (%2) hungup.").arg(call.data()->getCidName(), call.data()->getCidNumber())); /* TODO: Will cause problems if 2 calls are received at the same time */ ui->answerBtn->setEnabled(false); diff --git a/fscomm/mainwindow.h b/fscomm/mainwindow.h index b64c559521..0e9dbd69a0 100644 --- a/fscomm/mainwindow.h +++ b/fscomm/mainwindow.h @@ -73,6 +73,7 @@ private slots: void answered(QSharedPointer); void hungup(QSharedPointer); void callFailed(QSharedPointer); + void recordCall(bool); private: Ui::MainWindow *ui; diff --git a/fscomm/mainwindow.ui b/fscomm/mainwindow.ui index 8cb83a7475..427b775ca2 100644 --- a/fscomm/mainwindow.ui +++ b/fscomm/mainwindow.ui @@ -39,6 +39,19 @@ + + + + Record + + + true + + + false + + +