Commit 86eb025c authored by Ronan Abhamon's avatar Ronan Abhamon

feat(src/components/call/CallModel): handle auto answer

parent 1e83bd74
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <QDateTime> #include <QDateTime>
#include <QtDebug> #include <QtDebug>
#include <QTimer>
#include "../../app/App.hpp" #include "../../app/App.hpp"
#include "../../utils.hpp" #include "../../utils.hpp"
...@@ -29,11 +30,28 @@ ...@@ -29,11 +30,28 @@
#include "CallModel.hpp" #include "CallModel.hpp"
#define AUTO_ANSWER_OBJECT_NAME "auto-answer-timer"
// ============================================================================= // =============================================================================
CallModel::CallModel (shared_ptr<linphone::Call> linphone_call) { CallModel::CallModel (shared_ptr<linphone::Call> linphone_call) {
m_linphone_call = linphone_call; m_linphone_call = linphone_call;
// Deal with auto-answer.
{
SettingsModel *settings = CoreManager::getInstance()->getSettingsModel();
if (settings->getAutoAnswerStatus()) {
QTimer *timer = new QTimer(this);
timer->setInterval(settings->getAutoAnswerDelay());
timer->setSingleShot(true);
timer->setObjectName(AUTO_ANSWER_OBJECT_NAME);
QObject::connect(timer, &QTimer::timeout, this, &CallModel::accept);
timer->start();
}
}
QObject::connect( QObject::connect(
&(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::callStateChanged, &(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::callStateChanged,
this, [this](const std::shared_ptr<linphone::Call> &call, linphone::CallState state) { this, [this](const std::shared_ptr<linphone::Call> &call, linphone::CallState state) {
...@@ -41,9 +59,13 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphone_call) { ...@@ -41,9 +59,13 @@ CallModel::CallModel (shared_ptr<linphone::Call> linphone_call) {
return; return;
switch (state) { switch (state) {
case linphone::CallStateConnected:
case linphone::CallStateEnd: case linphone::CallStateEnd:
case linphone::CallStateError: case linphone::CallStateError:
stopAutoAnswerTimer();
m_paused_by_remote = false;
break;
case linphone::CallStateConnected:
case linphone::CallStateRefered: case linphone::CallStateRefered:
case linphone::CallStateReleased: case linphone::CallStateReleased:
case linphone::CallStateStreamsRunning: case linphone::CallStateStreamsRunning:
...@@ -96,6 +118,8 @@ void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &call_params) { ...@@ -96,6 +118,8 @@ void CallModel::setRecordFile (shared_ptr<linphone::CallParams> &call_params) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void CallModel::accept () { void CallModel::accept () {
stopAutoAnswerTimer();
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(m_linphone_call); shared_ptr<linphone::CallParams> params = core->createCallParams(m_linphone_call);
params->enableVideo(false); params->enableVideo(false);
...@@ -106,6 +130,8 @@ void CallModel::accept () { ...@@ -106,6 +130,8 @@ void CallModel::accept () {
} }
void CallModel::acceptWithVideo () { void CallModel::acceptWithVideo () {
stopAutoAnswerTimer();
shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore(); shared_ptr<linphone::Core> core = CoreManager::getInstance()->getCore();
shared_ptr<linphone::CallParams> params = core->createCallParams(m_linphone_call); shared_ptr<linphone::CallParams> params = core->createCallParams(m_linphone_call);
params->enableVideo(true); params->enableVideo(true);
...@@ -180,6 +206,14 @@ void CallModel::stopRecording () { ...@@ -180,6 +206,14 @@ void CallModel::stopRecording () {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void CallModel::stopAutoAnswerTimer () const {
QTimer *timer = findChild<QTimer *>(AUTO_ANSWER_OBJECT_NAME, Qt::FindDirectChildrenOnly);
if (timer) {
timer->stop();
timer->deleteLater();
}
}
QString CallModel::getSipAddress () const { QString CallModel::getSipAddress () const {
return ::Utils::linphoneStringToQString(m_linphone_call->getRemoteAddress()->asStringUriOnly()); return ::Utils::linphoneStringToQString(m_linphone_call->getRemoteAddress()->asStringUriOnly());
} }
......
...@@ -86,6 +86,8 @@ signals: ...@@ -86,6 +86,8 @@ signals:
void recordingChanged (bool status); void recordingChanged (bool status);
private: private:
void stopAutoAnswerTimer () const;
QString getSipAddress () const; QString getSipAddress () const;
CallStatus getStatus () const; CallStatus getStatus () const;
......
...@@ -111,8 +111,10 @@ Notifier::~Notifier () { ...@@ -111,8 +111,10 @@ Notifier::~Notifier () {
QObject *Notifier::createNotification (Notifier::NotificationType type) { QObject *Notifier::createNotification (Notifier::NotificationType type) {
m_mutex.lock(); m_mutex.lock();
Q_ASSERT(m_n_instances <= N_MAX_NOTIFICATIONS);
// Check existing instances. // Check existing instances.
if (m_n_instances >= N_MAX_NOTIFICATIONS) { if (m_n_instances == N_MAX_NOTIFICATIONS) {
qWarning() << "Unable to create another notification"; qWarning() << "Unable to create another notification";
m_mutex.unlock(); m_mutex.unlock();
return nullptr; return nullptr;
...@@ -148,12 +150,12 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -148,12 +150,12 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// Destroy it after timeout. // Destroy it after timeout.
QObject::connect( QObject::connect(
timer, &QTimer::timeout, this, [this, notification]() { timer, &QTimer::timeout, this, [this, notification]() {
qDebug() << "toto";
deleteNotification(QVariant::fromValue(notification)); deleteNotification(QVariant::fromValue(notification));
} }
); );
// Called explicitly (by a click on notification for example) // Called explicitly (by a click on notification for example)
// or when single shot happen and if notification is visible.
QObject::connect(notification, SIGNAL(deleteNotification(QVariant)), this, SLOT(deleteNotification(QVariant))); QObject::connect(notification, SIGNAL(deleteNotification(QVariant)), this, SLOT(deleteNotification(QVariant)));
timer->start(); timer->start();
...@@ -162,18 +164,27 @@ void Notifier::showNotification (QObject *notification, int timeout) { ...@@ -162,18 +164,27 @@ void Notifier::showNotification (QObject *notification, int timeout) {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void Notifier::deleteNotification (QVariant notification) { void Notifier::deleteNotification (QVariant notification) {
m_mutex.lock();
QObject *instance = notification.value<QObject *>(); QObject *instance = notification.value<QObject *>();
instance->property(NOTIFICATION_PROPERTY_TIMER).value<QTimer *>()->stop();
// Notification marked destroyed.
if (instance->property("__valid").isValid()) {
m_mutex.unlock();
return;
}
qDebug() << "Delete notification."; qDebug() << "Delete notification.";
m_mutex.lock(); instance->setProperty("__valid", true);
instance->property(NOTIFICATION_PROPERTY_TIMER).value<QTimer *>()->stop();
m_n_instances--; m_n_instances--;
if (m_n_instances == 0) if (m_n_instances == 0)
m_offset = 0; m_offset = 0;
Q_ASSERT(m_n_instances >= 0);
m_mutex.unlock(); m_mutex.unlock();
instance->deleteLater(); instance->deleteLater();
...@@ -217,7 +228,7 @@ void Notifier::notifyReceivedCall (const shared_ptr<linphone::Call> &call) { ...@@ -217,7 +228,7 @@ void Notifier::notifyReceivedCall (const shared_ptr<linphone::Call> &call) {
QObject::connect( QObject::connect(
model, &CallModel::statusChanged, notification, [this, notification](CallModel::CallStatus status) { model, &CallModel::statusChanged, notification, [this, notification](CallModel::CallStatus status) {
if (status == CallModel::CallStatusEnded) if (status == CallModel::CallStatusEnded || status == CallModel::CallStatusConnected)
deleteNotification(QVariant::fromValue(notification)); deleteNotification(QVariant::fromValue(notification));
} }
); );
......
...@@ -60,7 +60,7 @@ private: ...@@ -60,7 +60,7 @@ private:
QQmlComponent *m_components[MaxNbTypes]; QQmlComponent *m_components[MaxNbTypes];
int m_offset = 0; int m_offset = 0;
unsigned int m_n_instances = 0; int m_n_instances = 0;
QMutex m_mutex; QMutex m_mutex;
}; };
......
...@@ -42,8 +42,6 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { ...@@ -42,8 +42,6 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) {
// Chat & calls. // Chat & calls.
// ============================================================================= // =============================================================================
// -----------------------------------------------------------------------------
int SettingsModel::getAutoAnswerDelay () const { int SettingsModel::getAutoAnswerDelay () const {
return m_config->getInt(UI_SECTION, "auto_answer_delay", 0); return m_config->getInt(UI_SECTION, "auto_answer_delay", 0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment