git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16349 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
João Mesquita 2010-01-18 02:43:48 +00:00
parent 97882a914c
commit 9952b6ef71
7 changed files with 97 additions and 6 deletions

View File

@ -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;
}

View File

@ -31,6 +31,7 @@
#include <QtCore>
#include <QString>
#include <switch.h>
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;
};

View File

@ -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<Call> FSHost::getCurrentActiveCall()
{
foreach(QSharedPointer<Call> call, _active_calls.values())
{
if (call.data()->isActive())
return call;
}
return QSharedPointer<Call>();
}
void FSHost::printEventHeaders(switch_event_t *event)
{
switch_event_header_t *hp;

View File

@ -66,6 +66,7 @@ public:
switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event);
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
QSharedPointer<Call> getCurrentActiveCall();
QString getGwStateName(int id) { return fscomm_gw_state_names[id]; }
protected:

View File

@ -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<Call> lastCall = g_FSHost.getCurrentActiveCall();
QSharedPointer<Call> 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> call = g_FSHost.getCurrentActiveCall();
if (call.isNull())
{
QMessageBox::warning(this,tr("Record call"),
tr("<p>FSComm reports that there are no active calls to be recorded."
"<p>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("<p>Could not get active call to start/stop recording."
"<p>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> call)
{
ui->textEdit->setText(QString("Calling %1 (%2)").arg(call.data()->getCidName(), call.data()->getCidNumber()));
@ -227,6 +256,7 @@ void MainWindow::newOutgoingCall(QSharedPointer<Call> 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> call)
@ -248,6 +278,7 @@ void MainWindow::ringing(QSharedPointer<Call> 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> call)
@ -301,6 +332,7 @@ void MainWindow::callFailed(QSharedPointer<Call> 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> 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);

View File

@ -73,6 +73,7 @@ private slots:
void answered(QSharedPointer<Call>);
void hungup(QSharedPointer<Call>);
void callFailed(QSharedPointer<Call>);
void recordCall(bool);
private:
Ui::MainWindow *ui;

View File

@ -39,6 +39,19 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="recoredCallBtn">
<property name="text">
<string>Record</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>