Revision
16349
Author
jmesquita
Date
2010-01-17 20:43:48 -0600 (Sun, 17 Jan 2010)

Log Message

FSCOMM-1

Modified Paths

Diff

Modified: freeswitch/trunk/fscomm/call.cpp (16348 => 16349)


--- freeswitch/trunk/fscomm/call.cpp	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/call.cpp	2010-01-18 02:43:48 UTC (rev 16349)
@@ -41,4 +41,29 @@
         _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;
+}

Modified: freeswitch/trunk/fscomm/call.h (16348 => 16349)


--- freeswitch/trunk/fscomm/call.h	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/call.h	2010-01-18 02:43:48 UTC (rev 16349)
@@ -31,6 +31,7 @@
 
 #include <QtCore>
 #include <QString>
+#include <switch.h>
 
 typedef enum {
     FSCOMM_CALL_STATE_RINGING = 0,
@@ -59,6 +60,9 @@
     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 @@
     fscomm_call_direction_t _direction;
     QString _uuid;
     QString _buuid;
+    bool _isActive;
+    QString _recording_filename;
     fscomm_call_state_t _state;
 };
 

Modified: freeswitch/trunk/fscomm/fshost.cpp (16348 => 16349)


--- freeswitch/trunk/fscomm/fshost.cpp	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/fshost.cpp	2010-01-18 02:43:48 UTC (rev 16349)
@@ -51,17 +51,18 @@
     /* 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 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 @@
     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;

Modified: freeswitch/trunk/fscomm/fshost.h (16348 => 16349)


--- freeswitch/trunk/fscomm/fshost.h	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/fshost.h	2010-01-18 02:43:48 UTC (rev 16349)
@@ -66,6 +66,7 @@
     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:

Modified: freeswitch/trunk/fscomm/mainwindow.cpp (16348 => 16349)


--- freeswitch/trunk/fscomm/mainwindow.cpp	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/mainwindow.cpp	2010-01-18 02:43:48 UTC (rev 16349)
@@ -87,6 +87,7 @@
     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::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 @@
         return;
     }
     ui->hangupBtn->setEnabled(true);
+    lastCall.data()->setActive(false);
+    call.data()->setActive(true);
 }
 
 void MainWindow::makeCall()
@@ -220,6 +224,31 @@
     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 @@
     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 @@
     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 @@
     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 @@
             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);

Modified: freeswitch/trunk/fscomm/mainwindow.h (16348 => 16349)


--- freeswitch/trunk/fscomm/mainwindow.h	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/mainwindow.h	2010-01-18 02:43:48 UTC (rev 16349)
@@ -73,6 +73,7 @@
     void answered(QSharedPointer<Call>);
     void hungup(QSharedPointer<Call>);
     void callFailed(QSharedPointer<Call>);
+    void recordCall(bool);
 
 private:
     Ui::MainWindow *ui;

Modified: freeswitch/trunk/fscomm/mainwindow.ui (16348 => 16349)


--- freeswitch/trunk/fscomm/mainwindow.ui	2010-01-18 00:29:03 UTC (rev 16348)
+++ freeswitch/trunk/fscomm/mainwindow.ui	2010-01-18 02:43:48 UTC (rev 16349)
@@ -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>