diff --git a/Linphone/model/cli/CliModel.cpp b/Linphone/model/cli/CliModel.cpp index 2554b0da4..c39d5a91b 100644 --- a/Linphone/model/cli/CliModel.cpp +++ b/Linphone/model/cli/CliModel.cpp @@ -39,6 +39,9 @@ QMap CliModel::mCommands{ createCommand("show", QT_TR_NOOP("showFunctionDescription"), &CliModel::cliShow, {}, true), createCommand("fetch-config", QT_TR_NOOP("fetchConfigFunctionDescription"), &CliModel::cliFetchConfig, {}, true), createCommand("call", QT_TR_NOOP("callFunctionDescription"), &CliModel::cliCall, {{"sip-address", {}}}, true), + createCommand("bye", QT_TR_NOOP("byeFunctionDescription"), &CliModel::cliBye, {}, true), + createCommand("accept", QT_TR_NOOP("acceptFunctionDescription"), &CliModel::cliAccept, {}, true), + createCommand("decline", QT_TR_NOOP("declineFunctionDescription"), &CliModel::cliDecline, {}, true), /* createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), cliInitiateConference, { { "sip-address", {} }, { "conference-id", {} } @@ -48,11 +51,8 @@ QMap CliModel::mCommands{ }), createCommand("join-conference-as", QT_TR_NOOP("joinConferenceAsFunctionDescription"), cliJoinConferenceAs, { { "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} } - }), - createCommand("bye", QT_TR_NOOP("byeFunctionDescription"), cliBye, QHash(), true), - createCommand("accept", QT_TR_NOOP("acceptFunctionDescription"), cliAccept, QHash(), true), - createCommand("decline", QT_TR_NOOP("declineFunctionDescription"), cliDecline, QHash(), true), - */ + }),*/ + }; std::pair CliModel::createCommand(const QString &functionName, @@ -147,6 +147,69 @@ void CliModel::cliCall(QHash args) { } } +void CliModel::cliBye(QHash args) { + if (!CoreModel::getInstance()->getCore() || + CoreModel::getInstance()->getCore()->getGlobalState() != linphone::GlobalState::On) { + connect( + CoreModel::getInstance().get(), &CoreModel::globalStateChanged, this, [this, args]() { cliBye(args); }, + Qt::SingleShotConnection); + return; + } + + if (args["sip-address"] == "*") // Call with options + CoreModel::getInstance()->getCore()->terminateAllCalls(); + else if (args.size() == 0 || args["sip-address"] == "") { + auto currentCall = CoreModel::getInstance()->getCore()->getCurrentCall(); + if (currentCall) currentCall->terminate(); + else lWarning() << log().arg("Cannot find a call to bye."); + } else { + auto address = ToolModel::interpretUrl(args["sip-address"]); + auto currentCall = CoreModel::getInstance()->getCore()->getCallByRemoteAddress2(address); + if (currentCall) currentCall->terminate(); + else lWarning() << log().arg("Cannot find a call to bye."); + } +} + +void CliModel::cliAccept(QHash args) { + if (!CoreModel::getInstance()->getCore() || + CoreModel::getInstance()->getCore()->getGlobalState() != linphone::GlobalState::On) { + connect( + CoreModel::getInstance().get(), &CoreModel::globalStateChanged, this, [this, args]() { cliBye(args); }, + Qt::SingleShotConnection); + return; + } + if (args.size() == 0 || args["sip-address"] == "" || args["sip-address"] == "*") { + auto currentCall = CoreModel::getInstance()->getCore()->getCurrentCall(); + if (currentCall) currentCall->accept(); + else lWarning() << log().arg("Cannot find a call to accept."); + } else { + auto address = ToolModel::interpretUrl(args["sip-address"]); + auto currentCall = CoreModel::getInstance()->getCore()->getCallByRemoteAddress2(address); + if (currentCall) currentCall->accept(); + else lWarning() << log().arg("Cannot find a call to accept."); + } +} + +void CliModel::cliDecline(QHash args) { + if (!CoreModel::getInstance()->getCore() || + CoreModel::getInstance()->getCore()->getGlobalState() != linphone::GlobalState::On) { + connect( + CoreModel::getInstance().get(), &CoreModel::globalStateChanged, this, [this, args]() { cliBye(args); }, + Qt::SingleShotConnection); + return; + } + if (args.size() == 0 || args["sip-address"] == "" || args["sip-address"] == "*") { + auto currentCall = CoreModel::getInstance()->getCore()->getCurrentCall(); + if (currentCall) currentCall->decline(linphone::Reason::Declined); + else lWarning() << log().arg("Cannot find a call to decline."); + } else { + auto address = ToolModel::interpretUrl(args["sip-address"]); + auto currentCall = CoreModel::getInstance()->getCore()->getCallByRemoteAddress2(address); + if (currentCall) currentCall->decline(linphone::Reason::Declined); + else lWarning() << log().arg("Cannot find a call to decline."); + } +} + /* QString CoreModel::getFetchConfig(QCommandLineParser *parser) { QString filePath = parser->value("fetch-config"); diff --git a/Linphone/model/cli/CliModel.hpp b/Linphone/model/cli/CliModel.hpp index a8ef2d2ae..0c7a48d4a 100644 --- a/Linphone/model/cli/CliModel.hpp +++ b/Linphone/model/cli/CliModel.hpp @@ -46,6 +46,9 @@ public: void cliShow(QHash args); void cliFetchConfig(QHash args); void cliCall(QHash args); + void cliBye(QHash args); + void cliAccept(QHash args); + void cliDecline(QHash args); static QRegularExpression mRegExpArgs; static QRegularExpression mRegExpFunctionName;