From 8a3001e61171c5975dcad49319fc7d4e46fb9f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Mesquita?= Date: Thu, 28 Jan 2010 01:12:34 +0000 Subject: [PATCH] Do the time properly. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16528 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- fscomm/call.cpp | 6 ++++++ fscomm/call.h | 3 +++ fscomm/fshost.cpp | 4 ++++ fscomm/mainwindow.cpp | 5 +++-- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fscomm/call.cpp b/fscomm/call.cpp index f177bc3278..32bdaf894a 100644 --- a/fscomm/call.cpp +++ b/fscomm/call.cpp @@ -78,3 +78,9 @@ void Call::sendDTMF(QString digit) QMessageBox::critical(0, QWidget::tr("DTMF Error"), QWidget::tr("There was an error sending DTMF, please report this bug."), QMessageBox::Ok); } } + +QTime Call::getCurrentStateTime() +{ + int now = QDateTime::fromTime_t(_answered_epoch).secsTo(QDateTime::currentDateTime()); + return QTime::fromString(QString::number(now), "s"); +} diff --git a/fscomm/call.h b/fscomm/call.h index 6ec45d2076..4973c0484d 100644 --- a/fscomm/call.h +++ b/fscomm/call.h @@ -63,6 +63,8 @@ public: bool isActive() { return _isActive == true; } switch_status_t toggleRecord(bool); void sendDTMF(QString digit); + void setAnsweredEpoch(qulonglong time) { _answered_epoch = time/1000000; } + QTime getCurrentStateTime(); private: int _call_id; @@ -75,6 +77,7 @@ private: bool _isActive; QString _recording_filename; fscomm_call_state_t _state; + qulonglong _answered_epoch; }; Q_DECLARE_METATYPE(Call) diff --git a/fscomm/fshost.cpp b/fscomm/fshost.cpp index 69e732cc7a..641d46e086 100644 --- a/fscomm/fshost.cpp +++ b/fscomm/fshost.cpp @@ -177,6 +177,8 @@ switch_status_t FSHost::processAlegEvent(switch_event_t * event, QString uuid) switch(event->event_id) { case SWITCH_EVENT_CHANNEL_ANSWER: { + QString answeredEpoch = switch_event_get_header_nil(event, "Caller-Channel-Answered-Time"); + call.data()->setAnsweredEpoch(answeredEpoch.toLong()); call.data()->setbUUID(switch_event_get_header_nil(event, "Other-Leg-Unique-ID")); _bleg_uuids.insert(switch_event_get_header_nil(event, "Other-Leg-Unique-ID"), uuid); call.data()->setState(FSCOMM_CALL_STATE_ANSWERED); @@ -257,6 +259,8 @@ switch_status_t FSHost::processBlegEvent(switch_event_t * event, QString buuid) case SWITCH_EVENT_CHANNEL_ANSWER: { /* When do we get here? */ + QString answeredEpoch = switch_event_get_header_nil(event, "Caller-Channel-Answered-Time"); + call.data()->setAnsweredEpoch(answeredEpoch.toULongLong()); emit answered(call); break; } diff --git a/fscomm/mainwindow.cpp b/fscomm/mainwindow.cpp index 10544f2686..b44570bf0c 100644 --- a/fscomm/mainwindow.cpp +++ b/fscomm/mainwindow.cpp @@ -130,9 +130,10 @@ void MainWindow::updateCallTimers() for(int row=0; rowtableCalls->rowCount(); row++) { QTableWidgetItem* item = ui->tableCalls->item(row, 2); - QTime time = QTime::fromString(item->text(),"hh:mm:ss"); - time = time.addSecs(1); + QSharedPointer call = g_FSHost.getCallByUUID(item->data(Qt::UserRole).toString()); + QTime time = call.data()->getCurrentStateTime(); item->setText(time.toString("hh:mm:ss")); + item->setTextAlignment(Qt::AlignRight); } }