]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCOMM-1
authorJoão Mesquita <jmesquita@freeswitch.org>
Mon, 18 Jan 2010 02:43:48 +0000 (02:43 +0000)
committerJoão Mesquita <jmesquita@freeswitch.org>
Mon, 18 Jan 2010 02:43:48 +0000 (02:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16349 d0543943-73ff-0310-b7d9-9358b9ac24b2

fscomm/call.cpp
fscomm/call.h
fscomm/fshost.cpp
fscomm/fshost.h
fscomm/mainwindow.cpp
fscomm/mainwindow.h
fscomm/mainwindow.ui

index dc7a9c481d0d50a33df7206d83b863507b7d55d4..8bcd47deeacd91f35e7b9ea263bee1d6fab58f33 100644 (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;
 }
index 11edee47f6e4922ecb3c5bb21b12d81648aef058..4e6aeb682d23af57cb85fcf4ee5d2aa68b18c0ac 100644 (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;
 };
 
index d7a776823252d6978411ea5886cf680c2d807069..a80ea27628f4664b912f2af8ca7d620b362100af 100644 (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;
index 9fbb17533d889b27dd2e1be9a0093f475e189710..cb172f324d1d40e394196f1711e2affe35d8caa5 100644 (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:
index b0df49145afc076f72081bc16fc89828afb70cd7..9d8b22545db981c4b34cad974a3935e66c8239e5 100644 (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);
index b64c55952169b6e8f4adb3aa00ac10a6762fd7db..0e9dbd69a0786dad0422ab4516d89fcfada3c6b4 100644 (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;
index 8cb83a7475b48f7465cca7b9aa0b5bddf2d70a01..427b775ca22c1e0a7261a4acbe20a8f55ed23882 100644 (file)
           </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>