diff --git a/core.cpp b/core.cpp index 7aa841a52..acfa0b150 100644 --- a/core.cpp +++ b/core.cpp @@ -34,6 +34,7 @@ #define TOX_FILE_INTERVAL 20 #define TOX_BOOTSTRAP_INTERVAL 10*1000 #define TOXAV_MAX_CALLS 32 +#define TOXAV_RINGING_TIME 15 const QString Core::CONFIG_FILE_NAME = "tox_save"; QList Core::fileSendQueue; @@ -934,12 +935,28 @@ void Core::onAvEnd(int32_t call_index, void* core) void Core::onAvRinging(int32_t call_index, void* core) { - qDebug() << "Core: AV ringing"; + int friendId = toxav_get_peer_id(static_cast(core)->toxav, call_index, 0); + if (friendId < 0) + { + qWarning() << "Core: Received invalid AV ringing"; + return; + } + qDebug() << QString("Core: AV ringing with %1").arg(friendId); + + emit static_cast(core)->avRinging(friendId, call_index); } void Core::onAvStarting(int32_t call_index, void* core) { - qDebug() << "Core: AV starting"; + int friendId = toxav_get_peer_id(static_cast(core)->toxav, call_index, 0); + if (friendId < 0) + { + qWarning() << "Core: Received invalid AV starting"; + return; + } + qDebug() << QString("Core: AV starting %1").arg(friendId); + + emit static_cast(core)->avStarting(friendId, call_index); } void Core::onAvEnding(int32_t call_index, void* core) @@ -962,7 +979,15 @@ void Core::onAvError(int32_t call_index, void* core) void Core::onAvRequestTimeout(int32_t call_index, void* core) { - qDebug() << "Core: AV request timeout"; + int friendId = toxav_get_peer_id(static_cast(core)->toxav, call_index, 0); + if (friendId < 0) + { + qWarning() << "Core: Received invalid AV request timeout"; + return; + } + qDebug() << QString("Core: AV request timeout with %1").arg(friendId); + + emit static_cast(core)->avRequestTimeout(friendId, call_index); } void Core::onAvPeerTimeout(int32_t call_index, void* core) @@ -981,3 +1006,16 @@ void Core::hangupCall(int callId) qDebug() << QString("Core: hanging up call %1").arg(callId); toxav_hangup(toxav, callId); } + +void Core::startCall(int friendId) +{ + qDebug() << QString("Core: Starting call with %1").arg(friendId); + int callId; + toxav_call(toxav, &callId, friendId, TypeAudio, TOXAV_RINGING_TIME); +} + +void Core::cancelCall(int callId, int friendId) +{ + qDebug() << QString("Core: Cancelling call with %1").arg(friendId); + toxav_cancel(toxav, callId, friendId, 0); +} diff --git a/core.h b/core.h index 3c7b55f14..7ea1fe1aa 100644 --- a/core.h +++ b/core.h @@ -113,6 +113,8 @@ public slots: void answerCall(int callId); void hangupCall(int callId); + void startCall(int friendId); + void cancelCall(int callId, int friendId); signals: void connected(); @@ -171,7 +173,10 @@ signals: void avStart(int friendId, int callIndex); void avCancel(int friendId, int callIndex); void avEnd(int friendId, int callIndex); + void avRinging(int friendId, int callIndex); + void avStarting(int friendId, int callIndex); void avEnding(int friendId, int callIndex); + void avRequestTimeout(int friendId, int callIndex); private: static void onFriendRequest(Tox* tox, const uint8_t* cUserId, const uint8_t* cMessage, uint16_t cMessageSize, void* core); diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 83138a030..3801f7017 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -316,6 +316,29 @@ void ChatForm::onAvEnd(int FriendId, int) connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered())); } +void ChatForm::onAvRinging(int FriendId, int CallId) +{ + if (FriendId != f->friendId) + return; + callId = CallId; + QPalette pal; + pal.setColor(QPalette::Button, Qt::gray); // Call ringing grey + callButton->setPalette(pal); + callButton->disconnect(); + connect(callButton, SIGNAL(clicked()), this, SLOT(onCancelCallTriggered())); +} + +void ChatForm::onAvStarting(int FriendId, int) +{ + if (FriendId != f->friendId) + return; + QPalette toxred; + toxred.setColor(QPalette::Button, QColor(200,78,78)); // Tox Red + callButton->setPalette(toxred); + callButton->disconnect(); + connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered())); +} + void ChatForm::onAvEnding(int FriendId, int) { if (FriendId != f->friendId) @@ -327,6 +350,17 @@ void ChatForm::onAvEnding(int FriendId, int) connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered())); } +void ChatForm::onAvRequestTimeout(int FriendId, int) +{ + if (FriendId != f->friendId) + return; + QPalette toxgreen; + toxgreen.setColor(QPalette::Button, QColor(107,194,96)); // Tox Green + callButton->setPalette(toxgreen); + callButton->disconnect(); + connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered())); +} + void ChatForm::onAnswerCallTriggered() { emit answerCall(callId); @@ -339,5 +373,16 @@ void ChatForm::onHangupCallTriggered() void ChatForm::onCallTriggered() { - + callButton->disconnect(); + emit startCall(f->friendId); +} + +void ChatForm::onCancelCallTriggered() +{ + QPalette toxgreen; + toxgreen.setColor(QPalette::Button, QColor(107,194,96)); // Tox Green + callButton->setPalette(toxgreen); + callButton->disconnect(); + connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered())); + emit cancelCall(callId, f->friendId); } diff --git a/widget/form/chatform.h b/widget/form/chatform.h index bb50a705d..38268c810 100644 --- a/widget/form/chatform.h +++ b/widget/form/chatform.h @@ -38,6 +38,7 @@ signals: void startCall(int friendId); void answerCall(int callId); void hangupCall(int callId); + void cancelCall(int callId, int friendId); public slots: void startFileSend(ToxFile file); @@ -46,7 +47,10 @@ public slots: void onAvStart(int FriendId, int CallId); void onAvCancel(int FriendId, int CallId); void onAvEnd(int FriendId, int CallId); + void onAvRinging(int FriendId, int CallId); + void onAvStarting(int FriendId, int CallId); void onAvEnding(int FriendId, int CallId); + void onAvRequestTimeout(int FriendId, int CallId); private slots: void onSendTriggered(); @@ -55,6 +59,7 @@ private slots: void onCallTriggered(); void onAnswerCallTriggered(); void onHangupCallTriggered(); + void onCancelCallTriggered(); private: Friend* f; diff --git a/widget/widget.cpp b/widget/widget.cpp index 764fbe322..809b29287 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -231,12 +231,17 @@ void Widget::addFriend(int friendId, const QString &userId) connect(newfriend->chatForm, SIGNAL(sendFile(int32_t,QString,QByteArray)), core, SLOT(sendFile(int32_t,QString,QByteArray))); connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int))); connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int))); + connect(newfriend->chatForm, SIGNAL(startCall(int)), core, SLOT(startCall(int))); + connect(newfriend->chatForm, SIGNAL(cancelCall(int,int)), core, SLOT(cancelCall(int,int))); connect(core, &Core::fileReceiveRequested, newfriend->chatForm, &ChatForm::onFileRecvRequest); connect(core, &Core::avInvite, newfriend->chatForm, &ChatForm::onAvInvite); connect(core, &Core::avStart, newfriend->chatForm, &ChatForm::onAvStart); connect(core, &Core::avCancel, newfriend->chatForm, &ChatForm::onAvCancel); connect(core, &Core::avEnd, newfriend->chatForm, &ChatForm::onAvEnd); + connect(core, &Core::avRinging, newfriend->chatForm, &ChatForm::onAvRinging); + connect(core, &Core::avStarting, newfriend->chatForm, &ChatForm::onAvStarting); connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding); + connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout); } void Widget::addFriendFailed(const QString&)