diff --git a/src/api/behaviorcontroller.h b/src/api/behaviorcontroller.h index 34492efeacb3b00695df572dd9ee65b0e42978a0..8d47dde4fd05ff4ac0fe8e2a5cbb0e082d999096 100644 --- a/src/api/behaviorcontroller.h +++ b/src/api/behaviorcontroller.h @@ -102,6 +102,11 @@ Q_SIGNALS: * Emitted audioMeter */ void audioMeter(const QString& id, float level); + + /** + * Emitted callStatusChanged + */ + void callStatusChanged(const QString& accountId, const QString& callId) const; }; } // namespace api } // namespace lrc diff --git a/src/api/newcallmodel.h b/src/api/newcallmodel.h index 5eb7ce511a73308de724c3859ee45da7c9fe5acb..d3f37c19a9cf40901efb6686ed143eef0d0290b0 100644 --- a/src/api/newcallmodel.h +++ b/src/api/newcallmodel.h @@ -18,6 +18,7 @@ ***************************************************************************/ #pragma once +#include "api/behaviorcontroller.h" #include "api/call.h" #include "api/account.h" #include "typedefs.h" @@ -60,7 +61,9 @@ public: enum class Media { NONE, AUDIO, VIDEO }; - NewCallModel(const account::Info& owner, const CallbacksHandler& callbacksHandler); + NewCallModel(const account::Info& owner, + const CallbacksHandler& callbacksHandler, + const BehaviorController& behaviorController); ~NewCallModel(); /** @@ -187,9 +190,7 @@ public: * @param audioOnly If the call is audio only * @return id for a new call */ - QString callAndAddParticipant(const QString uri, - const QString& callId, - bool audioOnly); + QString callAndAddParticipant(const QString uri, const QString& callId, bool audioOnly); /** * Not implemented yet @@ -295,14 +296,16 @@ Q_SIGNALS: int oldCount, int urgentCount) const; - /** + /** * Listen from CallbacksHandler when the peer start recording * @param callId * @param contactId * @param peerName * @param state the new state */ - void remoteRecordingChanged(const QString& callId, const QSet<QString>& peerRec, bool state) const; + void remoteRecordingChanged(const QString& callId, + const QSet<QString>& peerRec, + bool state) const; private: std::unique_ptr<NewCallModelPimpl> pimpl_; diff --git a/src/newaccountmodel.cpp b/src/newaccountmodel.cpp index 5aadcaa67c5d6a287419c7f3e2389120fae3343b..9a011a904177cb08cfb816dd2d84475e07789dd0 100644 --- a/src/newaccountmodel.cpp +++ b/src/newaccountmodel.cpp @@ -735,7 +735,7 @@ NewAccountModelPimpl::addToAccounts(const QString& accountId, std::shared_ptr<Da // Init models for this account newAccInfo.accountModel = &linked; - newAccInfo.callModel = std::make_unique<NewCallModel>(newAccInfo, callbacksHandler); + newAccInfo.callModel = std::make_unique<NewCallModel>(newAccInfo, callbacksHandler, behaviorController); newAccInfo.contactModel = std::make_unique<ContactModel>(newAccInfo, *db, callbacksHandler, diff --git a/src/newcallmodel.cpp b/src/newcallmodel.cpp index 1583eeea107ba8211c08fad303b56fb5dfd9fdf5..560006e662e84d8b3ed1268f59fe150978d751ed 100644 --- a/src/newcallmodel.cpp +++ b/src/newcallmodel.cpp @@ -19,13 +19,9 @@ #include "api/newcallmodel.h" -// std -#include <chrono> -#include <random> -#include <map> - // Lrc #include "callbackshandler.h" +#include "api/behaviorcontroller.h" #include "api/conversationmodel.h" #include "api/contact.h" #include "api/contactmodel.h" @@ -47,6 +43,11 @@ #include <QObject> #include <QString> +// std +#include <chrono> +#include <random> +#include <map> + static std::uniform_int_distribution<int> dis {0, std::numeric_limits<int>::max()}; static const std::map<short, QString> sip_call_status_code_map {{0, QObject::tr("Null")}, @@ -113,7 +114,9 @@ using namespace api; class NewCallModelPimpl : public QObject { public: - NewCallModelPimpl(const NewCallModel& linked, const CallbacksHandler& callbacksHandler); + NewCallModelPimpl(const NewCallModel& linked, + const CallbacksHandler& callbacksHandler, + const BehaviorController& behaviorController); ~NewCallModelPimpl(); /** @@ -125,6 +128,7 @@ public: NewCallModel::CallInfoMap calls; const CallbacksHandler& callbacksHandler; const NewCallModel& linked; + const BehaviorController& behaviorController; /** * key = peer's uri @@ -205,10 +209,12 @@ public Q_SLOTS: void remoteRecordingChanged(const QString& callId, const QString& peerNumber, bool state); }; -NewCallModel::NewCallModel(const account::Info& owner, const CallbacksHandler& callbacksHandler) +NewCallModel::NewCallModel(const account::Info& owner, + const CallbacksHandler& callbacksHandler, + const BehaviorController& behaviorController) : QObject(nullptr) , owner(owner) - , pimpl_(std::make_unique<NewCallModelPimpl>(*this, callbacksHandler)) + , pimpl_(std::make_unique<NewCallModelPimpl>(*this, callbacksHandler, behaviorController)) {} NewCallModel::~NewCallModel() {} @@ -537,9 +543,11 @@ NewCallModel::getSIPCallStatusString(const short& statusCode) } NewCallModelPimpl::NewCallModelPimpl(const NewCallModel& linked, - const CallbacksHandler& callbacksHandler) + const CallbacksHandler& callbacksHandler, + const BehaviorController& behaviorController) : linked(linked) , callbacksHandler(callbacksHandler) + , behaviorController(behaviorController) { connect(&callbacksHandler, &CallbacksHandler::incomingCall, @@ -840,6 +848,7 @@ NewCallModelPimpl::slotCallStateChanged(const QString& callId, const QString& st if (status == call::Status::ENDED && !call::isTerminating(call->status)) { call->status = call::Status::TERMINATING; emit linked.callStatusChanged(callId, code); + emit behaviorController.callStatusChanged(linked.owner.id, callId); } // proper state transition @@ -858,6 +867,7 @@ NewCallModelPimpl::slotCallStateChanged(const QString& callId, const QString& st // NOTE: signal emission order matters, always emit CallStatusChanged before CallEnded emit linked.callStatusChanged(callId, code); + emit behaviorController.callStatusChanged(linked.owner.id, callId); if (call->status == call::Status::ENDED) { emit linked.callEnded(callId); @@ -1028,7 +1038,9 @@ NewCallModelPimpl::sendProfile(const QString& callId) } void -NewCallModelPimpl::remoteRecordingChanged(const QString& callId, const QString& peerNumber, bool state) +NewCallModelPimpl::remoteRecordingChanged(const QString& callId, + const QString& peerNumber, + bool state) { auto it = calls.find(callId); if (it == calls.end() or not it->second)