Browse Source

Send empty calls (no sound nor video)

pull/3/head
Tux3 / Mlkj / !Lev.uXFMLA 11 years ago
parent
commit
6114cb66c6
  1. 44
      core.cpp
  2. 5
      core.h
  3. 45
      widget/form/chatform.cpp
  4. 5
      widget/form/chatform.h
  5. 5
      widget/widget.cpp

44
core.cpp

@ -34,6 +34,7 @@ @@ -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<ToxFile> Core::fileSendQueue;
@ -934,12 +935,28 @@ void Core::onAvEnd(int32_t call_index, void* core) @@ -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*>(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*>(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*>(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*>(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) @@ -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*>(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*>(core)->avRequestTimeout(friendId, call_index);
}
void Core::onAvPeerTimeout(int32_t call_index, void* core)
@ -981,3 +1006,16 @@ void Core::hangupCall(int callId) @@ -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);
}

5
core.h

@ -113,6 +113,8 @@ public slots: @@ -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: @@ -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);

45
widget/form/chatform.cpp

@ -316,6 +316,29 @@ void ChatForm::onAvEnd(int FriendId, int) @@ -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) @@ -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() @@ -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);
}

5
widget/form/chatform.h

@ -38,6 +38,7 @@ signals: @@ -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: @@ -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: @@ -55,6 +59,7 @@ private slots:
void onCallTriggered();
void onAnswerCallTriggered();
void onHangupCallTriggered();
void onCancelCallTriggered();
private:
Friend* f;

5
widget/widget.cpp

@ -231,12 +231,17 @@ void Widget::addFriend(int friendId, const QString &userId) @@ -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&)

Loading…
Cancel
Save