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

Merge branch 'pr612'

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-03 23:21:11 +01:00
commit 36017a124f
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 111 additions and 5 deletions

View File

@ -56,9 +56,13 @@ ChatForm::ChatForm(Friend* chatFriend)
statusMessageLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
netcam = new NetCamView();
timer = nullptr;
headTextLayout->addWidget(statusMessageLabel);
headTextLayout->addStretch();
callDuration = new QLabel();
headTextLayout->addWidget(callDuration, 1, Qt::AlignCenter);
callDuration->hide();
menu.addAction(tr("Load History..."), this, SLOT(onLoadHistory()));
@ -204,6 +208,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
{
qDebug() << "onAvInvite";
if (FriendId != f->friendId)
return;
@ -239,6 +244,7 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
void ChatForm::onAvStart(int FriendId, int CallId, bool video)
{
qDebug() << "onAvStart";
if (FriendId != f->friendId)
return;
@ -247,6 +253,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
callId = CallId;
callButton->disconnect();
videoButton->disconnect();
if (video)
{
callButton->setObjectName("grey");
@ -265,10 +272,14 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
startCounter();
}
void ChatForm::onAvCancel(int FriendId, int)
{
qDebug() << "onAvCancel";
if (FriendId != f->friendId)
return;
@ -288,10 +299,13 @@ void ChatForm::onAvCancel(int FriendId, int)
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
}
void ChatForm::onAvEnd(int FriendId, int)
{
qDebug() << "onAvEnd";
if (FriendId != f->friendId)
return;
@ -311,10 +325,12 @@ void ChatForm::onAvEnd(int FriendId, int)
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
stopCounter();
}
void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
{
{
if (FriendId != f->friendId)
return;
@ -342,6 +358,8 @@ void ChatForm::onAvRinging(int FriendId, int CallId, bool video)
void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
{
qDebug() << "onAvStarting";
if (FriendId != f->friendId)
return;
@ -365,10 +383,14 @@ void ChatForm::onAvStarting(int FriendId, int CallId, bool video)
videoButton->style()->polish(videoButton);
connect(callButton, SIGNAL(clicked()), this, SLOT(onHangupCallTriggered()));
}
startCounter();
}
void ChatForm::onAvEnding(int FriendId, int)
{
qDebug() << "onAvEnding";
if (FriendId != f->friendId)
return;
@ -389,13 +411,15 @@ void ChatForm::onAvEnding(int FriendId, int)
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
addSystemInfoMessage(tr("Call with %1 ended").arg(f->getName()), "white", QDateTime::currentDateTime());
netcam->hide();
stopCounter();
}
void ChatForm::onAvRequestTimeout(int FriendId, int)
{
qDebug() << "onAvRequestTimeout";
if (FriendId != f->friendId)
return;
@ -421,6 +445,8 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
void ChatForm::onAvPeerTimeout(int FriendId, int)
{
qDebug() << "onAvPeerTimeout";
if (FriendId != f->friendId)
return;
@ -446,6 +472,8 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
void ChatForm::onAvRejected(int FriendId, int)
{
qDebug() << "onAvRejected";
if (FriendId != f->friendId)
return;
@ -473,6 +501,8 @@ void ChatForm::onAvRejected(int FriendId, int)
void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
{
qDebug() << "onAvMediaChange";
if (FriendId != f->friendId || CallId != callId)
return;
@ -488,13 +518,17 @@ void ChatForm::onAvMediaChange(int FriendId, int CallId, bool video)
void ChatForm::onAnswerCallTriggered()
{
qDebug() << "onAnswerCallTriggered";
audioInputFlag = true;
audioOutputFlag = true;
emit answerCall(callId);
}
void ChatForm::onHangupCallTriggered()
{
{
qDebug() << "onHangupCallTriggered";
audioInputFlag = false;
audioOutputFlag = false;
emit hangupCall(callId);
@ -506,6 +540,8 @@ void ChatForm::onHangupCallTriggered()
void ChatForm::onCallTriggered()
{
qDebug() << "onCallTriggered";
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
@ -515,6 +551,8 @@ void ChatForm::onCallTriggered()
void ChatForm::onVideoCallTriggered()
{
qDebug() << "onVideoCallTriggered";
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
@ -524,6 +562,8 @@ void ChatForm::onVideoCallTriggered()
void ChatForm::onAvCallFailed(int FriendId)
{
qDebug() << "onAvCallFailed";
if (FriendId != f->friendId)
return;
@ -537,6 +577,8 @@ void ChatForm::onAvCallFailed(int FriendId)
void ChatForm::onCancelCallTriggered()
{
qDebug() << "onCancelCallTriggered";
audioInputFlag = false;
audioOutputFlag = false;
micButton->setObjectName("green");
@ -555,7 +597,7 @@ void ChatForm::onCancelCallTriggered()
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
netcam->hide();
emit cancelCall(callId, f->friendId);
emit cancelCall(callId, f->friendId);
}
void ChatForm::onMicMuteToggle()
@ -689,3 +731,57 @@ void ChatForm::onLoadHistory()
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}
}
void ChatForm::startCounter()
{
if(!timer)
{
timer = new QTimer();
connect(timer, SIGNAL(timeout()), this, SLOT(updateTime()));
timer->start(1000);
timeElapsed.start();
callDuration->show();
}
}
void ChatForm::stopCounter()
{
if(timer)
{
addSystemInfoMessage(tr("Call with %1 ended. %2").arg(f->getName(), secondsToDHMS(timeElapsed.elapsed()/1000)),
"white", QDateTime::currentDateTime());
timer->stop();
callDuration->hide();
timer = nullptr;
delete timer;
}
}
void ChatForm::updateTime()
{
callDuration->setText(secondsToDHMS(timeElapsed.elapsed()/1000));
}
QString ChatForm::secondsToDHMS(quint32 duration)
{
QString res;
QString cD = tr("Call duration: ");
int seconds = (int) (duration % 60);
duration /= 60;
int minutes = (int) (duration % 60);
duration /= 60;
int hours = (int) (duration % 24);
int days = (int) (duration / 24);
if(minutes == 0)
return cD + res.sprintf("%02ds", seconds);
if(hours == 0 && days == 0)
return cD + res.sprintf("%02dm %02ds", minutes, seconds);
if (days == 0)
return cD + res.sprintf("%02dh %02dm %02ds", hours, minutes, seconds);
//I assume no one will ever have call longer than ~30days
return cD + res.sprintf("%dd%02dh %02dm %02ds", days, hours, minutes, seconds);
}

View File

@ -19,6 +19,9 @@
#include "genericchatform.h"
#include "src/corestructs.h"
#include <QLabel>
#include <QTimer>
#include <QElapsedTimer>
struct Friend;
class FileTransferInstance;
@ -74,6 +77,7 @@ private slots:
void onFileTansBtnClicked(QString widgetName, QString buttonName);
void onFileSendFailed(int FriendId, const QString &fname);
void onLoadHistory();
void updateTime();
protected:
// drag & drop
@ -87,8 +91,14 @@ private:
bool audioInputFlag;
bool audioOutputFlag;
int callId;
QLabel *callDuration;
QTimer *timer;
QElapsedTimer timeElapsed;
QHash<uint, FileTransferInstance*> ftransWidgets;
void startCounter();
void stopCounter();
QString secondsToDHMS(quint32 duration);
};
#endif // CHATFORM_H