diff --git a/linphone-desktop/src/components/call/CallModel.cpp b/linphone-desktop/src/components/call/CallModel.cpp index 71eb14dee..ff0d9208e 100644 --- a/linphone-desktop/src/components/call/CallModel.cpp +++ b/linphone-desktop/src/components/call/CallModel.cpp @@ -22,6 +22,7 @@ #include #include +#include #include "../../app/App.hpp" #include "../../utils.hpp" @@ -29,11 +30,28 @@ #include "CallModel.hpp" +#define AUTO_ANSWER_OBJECT_NAME "auto-answer-timer" + // ============================================================================= CallModel::CallModel (shared_ptr 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( &(*CoreManager::getInstance()->getHandlers()), &CoreHandlers::callStateChanged, this, [this](const std::shared_ptr &call, linphone::CallState state) { @@ -41,9 +59,13 @@ CallModel::CallModel (shared_ptr linphone_call) { return; switch (state) { - case linphone::CallStateConnected: case linphone::CallStateEnd: case linphone::CallStateError: + stopAutoAnswerTimer(); + m_paused_by_remote = false; + break; + + case linphone::CallStateConnected: case linphone::CallStateRefered: case linphone::CallStateReleased: case linphone::CallStateStreamsRunning: @@ -96,6 +118,8 @@ void CallModel::setRecordFile (shared_ptr &call_params) { // ----------------------------------------------------------------------------- void CallModel::accept () { + stopAutoAnswerTimer(); + shared_ptr core = CoreManager::getInstance()->getCore(); shared_ptr params = core->createCallParams(m_linphone_call); params->enableVideo(false); @@ -106,6 +130,8 @@ void CallModel::accept () { } void CallModel::acceptWithVideo () { + stopAutoAnswerTimer(); + shared_ptr core = CoreManager::getInstance()->getCore(); shared_ptr params = core->createCallParams(m_linphone_call); params->enableVideo(true); @@ -180,6 +206,14 @@ void CallModel::stopRecording () { // ----------------------------------------------------------------------------- +void CallModel::stopAutoAnswerTimer () const { + QTimer *timer = findChild(AUTO_ANSWER_OBJECT_NAME, Qt::FindDirectChildrenOnly); + if (timer) { + timer->stop(); + timer->deleteLater(); + } +} + QString CallModel::getSipAddress () const { return ::Utils::linphoneStringToQString(m_linphone_call->getRemoteAddress()->asStringUriOnly()); } diff --git a/linphone-desktop/src/components/call/CallModel.hpp b/linphone-desktop/src/components/call/CallModel.hpp index 13dc5b417..850081638 100644 --- a/linphone-desktop/src/components/call/CallModel.hpp +++ b/linphone-desktop/src/components/call/CallModel.hpp @@ -86,6 +86,8 @@ signals: void recordingChanged (bool status); private: + void stopAutoAnswerTimer () const; + QString getSipAddress () const; CallStatus getStatus () const; diff --git a/linphone-desktop/src/components/notifier/Notifier.cpp b/linphone-desktop/src/components/notifier/Notifier.cpp index a9dc2fd7e..1043fdcfa 100644 --- a/linphone-desktop/src/components/notifier/Notifier.cpp +++ b/linphone-desktop/src/components/notifier/Notifier.cpp @@ -111,8 +111,10 @@ Notifier::~Notifier () { QObject *Notifier::createNotification (Notifier::NotificationType type) { m_mutex.lock(); + Q_ASSERT(m_n_instances <= N_MAX_NOTIFICATIONS); + // Check existing instances. - if (m_n_instances >= N_MAX_NOTIFICATIONS) { + if (m_n_instances == N_MAX_NOTIFICATIONS) { qWarning() << "Unable to create another notification"; m_mutex.unlock(); return nullptr; @@ -148,12 +150,12 @@ void Notifier::showNotification (QObject *notification, int timeout) { // Destroy it after timeout. QObject::connect( timer, &QTimer::timeout, this, [this, notification]() { + qDebug() << "toto"; deleteNotification(QVariant::fromValue(notification)); } ); // 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))); timer->start(); @@ -162,18 +164,27 @@ void Notifier::showNotification (QObject *notification, int timeout) { // ----------------------------------------------------------------------------- void Notifier::deleteNotification (QVariant notification) { + m_mutex.lock(); + QObject *instance = notification.value(); - instance->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); + + // Notification marked destroyed. + if (instance->property("__valid").isValid()) { + m_mutex.unlock(); + return; + } qDebug() << "Delete notification."; - m_mutex.lock(); + instance->setProperty("__valid", true); + instance->property(NOTIFICATION_PROPERTY_TIMER).value()->stop(); m_n_instances--; - if (m_n_instances == 0) m_offset = 0; + Q_ASSERT(m_n_instances >= 0); + m_mutex.unlock(); instance->deleteLater(); @@ -217,7 +228,7 @@ void Notifier::notifyReceivedCall (const shared_ptr &call) { QObject::connect( model, &CallModel::statusChanged, notification, [this, notification](CallModel::CallStatus status) { - if (status == CallModel::CallStatusEnded) + if (status == CallModel::CallStatusEnded || status == CallModel::CallStatusConnected) deleteNotification(QVariant::fromValue(notification)); } ); diff --git a/linphone-desktop/src/components/notifier/Notifier.hpp b/linphone-desktop/src/components/notifier/Notifier.hpp index 55f7ac704..5a6f80021 100644 --- a/linphone-desktop/src/components/notifier/Notifier.hpp +++ b/linphone-desktop/src/components/notifier/Notifier.hpp @@ -60,7 +60,7 @@ private: QQmlComponent *m_components[MaxNbTypes]; int m_offset = 0; - unsigned int m_n_instances = 0; + int m_n_instances = 0; QMutex m_mutex; }; diff --git a/linphone-desktop/src/components/settings/SettingsModel.cpp b/linphone-desktop/src/components/settings/SettingsModel.cpp index 96d62ce55..87e970f0c 100644 --- a/linphone-desktop/src/components/settings/SettingsModel.cpp +++ b/linphone-desktop/src/components/settings/SettingsModel.cpp @@ -42,8 +42,6 @@ SettingsModel::SettingsModel (QObject *parent) : QObject(parent) { // Chat & calls. // ============================================================================= -// ----------------------------------------------------------------------------- - int SettingsModel::getAutoAnswerDelay () const { return m_config->getInt(UI_SECTION, "auto_answer_delay", 0); }