1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Cleanup UI/CoreAV interface

This commit is contained in:
tux3 2015-10-07 20:11:19 +02:00
parent 73a4f40744
commit 41e0212f77
5 changed files with 42 additions and 174 deletions

View File

@ -83,6 +83,7 @@ void CoreAV::answerCall(uint32_t friendNum)
else
{
qWarning() << "Failed to answer call with error"<<err;
toxav_call_control(toxav, friendNum, TOXAV_CALL_CONTROL_CANCEL, nullptr);
calls.remove(friendNum);
emit avCallFailed(friendNum);
}
@ -90,6 +91,7 @@ void CoreAV::answerCall(uint32_t friendNum)
void CoreAV::startCall(uint32_t friendId, bool video)
{
qDebug() << QString("Starting call with %1").arg(friendId);
if(calls.contains(friendId))
{
qWarning() << QString("Can't start call with %1, we're already in this call!").arg(friendId);
@ -97,7 +99,6 @@ void CoreAV::startCall(uint32_t friendId, bool video)
return;
}
qDebug() << QString("Starting call with %1").arg(friendId);
uint32_t videoBitrate = video ? VIDEO_DEFAULT_BITRATE : 0;
if (!toxav_call(toxav, friendId, AUDIO_DEFAULT_BITRATE, videoBitrate, nullptr))
{
@ -112,8 +113,13 @@ void CoreAV::startCall(uint32_t friendId, bool video)
void CoreAV::cancelCall(uint32_t friendId)
{
qDebug() << QString("Cancelling call with %1").arg(friendId);
toxav_call_control(toxav, friendId, TOXAV_CALL_CONTROL_CANCEL, nullptr);
if (!toxav_call_control(toxav, friendId, TOXAV_CALL_CONTROL_CANCEL, nullptr))
{
qWarning() << QString("Failed to cancel call with %1").arg(friendId);
return;
}
calls.remove(friendId);
emit avCancel(friendId);
}
bool CoreAV::sendCallAudio(uint32_t callId)
@ -342,6 +348,11 @@ void CoreAV::callCallback(ToxAV* toxav, uint32_t friendNum, bool audio, bool vid
void CoreAV::stateCallback(ToxAV *, uint32_t friendNum, uint32_t state, void *_self)
{
// This callback needs to run in the CoreAV thread.
// Otherwise, there's a deadlock between the Core thread holding an internal
// toxav lock and trying to lock the CameraSource to stop it, and the
// av thread holding the Camera
CoreAV* self = static_cast<CoreAV*>(_self);
assert(self->calls.contains(friendNum));

View File

@ -94,13 +94,7 @@ signals:
void avCancel(uint32_t friendId);
void avEnd(uint32_t friendId);
void avRinging(uint32_t friendId, bool video);
void avStarting(uint32_t friendId, bool video);
void avEnding(uint32_t friendId);
void avRequestTimeout(uint32_t friendId);
void avPeerTimeout(uint32_t friendId);
void avMediaChange(uint32_t friendId, bool videoEnabled);
void avCallFailed(uint32_t friendId);
void avRejected(uint32_t friendId);
void videoFrameReceived(vpx_image* frame);

View File

@ -313,10 +313,9 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video)
if (video)
{
callButton->setObjectName("grey");
callButton->setToolTip("");
videoButton->setObjectName("red");
videoButton->setToolTip(tr("End video call"));
videoButton->style()->polish(videoButton);
connect(videoButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered()));
@ -326,14 +325,11 @@ void ChatForm::onAvStart(uint32_t FriendId, bool video)
{
callButton->setObjectName("red");
callButton->setToolTip(tr("End audio call"));
videoButton->setObjectName("grey");
videoButton->setToolTip("");
callButton->style()->polish(callButton);
connect(callButton, SIGNAL(clicked()),
this, SLOT(onHangupCallTriggered()));
hideNetcam();
}
callButton->style()->polish(callButton);
videoButton->style()->polish(videoButton);
micButton->setObjectName("green");
micButton->style()->polish(micButton);
@ -370,95 +366,6 @@ void ChatForm::onAvCancel(uint32_t FriendId)
QDateTime::currentDateTime());
}
void ChatForm::onAvRinging(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRinging";
callButton->disconnect();
videoButton->disconnect();
if (video)
{
callButton->setObjectName("grey");
callButton->style()->polish(callButton);
callButton->setToolTip("");
videoButton->setObjectName("yellow");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("Cancel video call"));
connect(videoButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
else
{
callButton->setObjectName("yellow");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("Cancel audio call"));
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
addSystemInfoMessage(tr("Calling to %1").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime());
Widget::getInstance()->updateFriendActivity(f);
}
void ChatForm::onAvStarting(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvStarting";
disableCallButtons();
if (video)
{
callButton->setObjectName("grey");
callButton->style()->polish(callButton);
callButton->setToolTip("");
videoButton->setObjectName("red");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("End video call"));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
showNetcam();
}
else
{
callButton->setObjectName("red");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("End audio call"));
videoButton->setObjectName("grey");
videoButton->style()->polish(videoButton);
videoButton->setToolTip("");
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
startCounter();
}
void ChatForm::onAvEnding(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvEnding";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
CameraSource::getInstance().unsubscribe();
hideNetcam();
}
void ChatForm::onAvEnd(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
@ -474,68 +381,36 @@ void ChatForm::onAvEnd(uint32_t FriendId)
hideNetcam();
}
void ChatForm::onAvRequestTimeout(uint32_t FriendId)
void ChatForm::onAvRinging(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRequestTimeout";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
}
void ChatForm::onAvPeerTimeout(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvPeerTimeout";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
hideNetcam();
}
void ChatForm::onAvRejected(uint32_t FriendId)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvRejected";
delete callConfirm;
callConfirm = nullptr;
enableCallButtons();
stopCounter();
insertChatMessage(ChatMessage::createChatInfoMessage(tr("Call rejected"),
ChatMessage::INFO,
QDateTime::currentDateTime()));
hideNetcam();
}
void ChatForm::onAvMediaChange(uint32_t FriendId, bool video)
{
if (FriendId != f->getFriendID())
return;
qDebug() << "onAvMediaChange";
qDebug() << "onAvRinging";
disableCallButtons();
if (video)
showNetcam();
{
videoButton->setObjectName("yellow");
videoButton->style()->polish(videoButton);
videoButton->setToolTip(tr("Cancel video call"));
connect(videoButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
else
hideNetcam();
{
callButton->setObjectName("yellow");
callButton->style()->polish(callButton);
callButton->setToolTip(tr("Cancel audio call"));
connect(callButton, SIGNAL(clicked()),
this, SLOT(onCancelCallTriggered()));
}
addSystemInfoMessage(tr("Calling %1").arg(f->getDisplayedName()),
ChatMessage::INFO,
QDateTime::currentDateTime());
Widget::getInstance()->updateFriendActivity(f);
}
void ChatForm::onAnswerCallTriggered()
@ -548,6 +423,8 @@ void ChatForm::onAnswerCallTriggered()
callConfirm = nullptr;
}
disableCallButtons();
audioInputFlag = true;
audioOutputFlag = true;
emit answerCall(f->getFriendID());
@ -593,8 +470,7 @@ void ChatForm::onCallTriggered()
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
disableCallButtons();
emit startCall(f->getFriendID(), false);
}
@ -604,8 +480,7 @@ void ChatForm::onVideoCallTriggered()
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
videoButton->disconnect();
disableCallButtons();
emit startCall(f->getFriendID(), true);
}

View File

@ -69,13 +69,7 @@ public slots:
void onAvCancel(uint32_t FriendId);
void onAvEnd(uint32_t FriendId);
void onAvRinging(uint32_t FriendId, bool video);
void onAvStarting(uint32_t FriendId, bool video);
void onAvEnding(uint32_t FriendId);
void onAvRequestTimeout(uint32_t FriendId);
void onAvPeerTimeout(uint32_t FriendId);
void onAvMediaChange(uint32_t FriendId, bool video);
void onAvCallFailed(uint32_t FriendId);
void onAvRejected(uint32_t FriendId);
void onMicMuteToggle();
void onVolMuteToggle();
void onAvatarChange(uint32_t FriendId, const QPixmap& pic);

View File

@ -906,13 +906,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(coreav, &CoreAV::avCancel, newfriend->getChatForm(), &ChatForm::onAvCancel);
connect(coreav, &CoreAV::avEnd, newfriend->getChatForm(), &ChatForm::onAvEnd);
connect(coreav, &CoreAV::avRinging, newfriend->getChatForm(), &ChatForm::onAvRinging);
connect(coreav, &CoreAV::avStarting, newfriend->getChatForm(), &ChatForm::onAvStarting);
connect(coreav, &CoreAV::avEnding, newfriend->getChatForm(), &ChatForm::onAvEnding);
connect(coreav, &CoreAV::avRequestTimeout, newfriend->getChatForm(), &ChatForm::onAvRequestTimeout);
connect(coreav, &CoreAV::avPeerTimeout, newfriend->getChatForm(), &ChatForm::onAvPeerTimeout);
connect(coreav, &CoreAV::avMediaChange, newfriend->getChatForm(), &ChatForm::onAvMediaChange);
connect(coreav, &CoreAV::avCallFailed, newfriend->getChatForm(), &ChatForm::onAvCallFailed);
connect(coreav, &CoreAV::avRejected, newfriend->getChatForm(), &ChatForm::onAvRejected);
connect(core, &Core::friendAvatarChanged, newfriend->getChatForm(), &ChatForm::onAvatarChange);
connect(core, &Core::friendAvatarChanged, newfriend->getFriendWidget(), &FriendWidget::onAvatarChange);
connect(core, &Core::friendAvatarRemoved, newfriend->getChatForm(), &ChatForm::onAvatarRemoved);