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

call duration

This commit is contained in:
agilob 2014-11-03 01:51:56 +00:00
parent 2ac1a33cb5
commit b386e4f08f
No known key found for this signature in database
GPG Key ID: 34568050DBCCB997
2 changed files with 110 additions and 5 deletions

View File

@ -59,6 +59,9 @@ ChatForm::ChatForm(Friend* chatFriend)
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 +207,7 @@ void ChatForm::onFileRecvRequest(ToxFile file)
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
{
qDebug() << "onAvInvite";
if (FriendId != f->friendId)
return;
@ -239,6 +243,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 +252,7 @@ void ChatForm::onAvStart(int FriendId, int CallId, bool video)
callId = CallId;
callButton->disconnect();
videoButton->disconnect();
if (video)
{
callButton->setObjectName("grey");
@ -265,10 +271,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 +298,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 +324,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 +357,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 +382,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 +410,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 +444,8 @@ void ChatForm::onAvRequestTimeout(int FriendId, int)
void ChatForm::onAvPeerTimeout(int FriendId, int)
{
qDebug() << "onAvPeerTimeout";
if (FriendId != f->friendId)
return;
@ -446,6 +471,8 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
void ChatForm::onAvRejected(int FriendId, int)
{
qDebug() << "onAvRejected";
if (FriendId != f->friendId)
return;
@ -473,6 +500,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 +517,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 +539,8 @@ void ChatForm::onHangupCallTriggered()
void ChatForm::onCallTriggered()
{
qDebug() << "onCallTriggered";
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
@ -515,6 +550,8 @@ void ChatForm::onCallTriggered()
void ChatForm::onVideoCallTriggered()
{
qDebug() << "onVideoCallTriggered";
audioInputFlag = true;
audioOutputFlag = true;
callButton->disconnect();
@ -524,6 +561,8 @@ void ChatForm::onVideoCallTriggered()
void ChatForm::onAvCallFailed(int FriendId)
{
qDebug() << "onAvCallFailed";
if (FriendId != f->friendId)
return;
@ -537,6 +576,8 @@ void ChatForm::onAvCallFailed(int FriendId)
void ChatForm::onCancelCallTriggered()
{
qDebug() << "onCancelCallTriggered";
audioInputFlag = false;
audioOutputFlag = false;
micButton->setObjectName("green");
@ -555,7 +596,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 +730,57 @@ void ChatForm::onLoadHistory()
chatWidget->verticalScrollBar()->setValue(savedSliderPos);
}
}
void ChatForm::startCounter()
{
if(timer)
{
qDebug() << "timer nie istnieje";
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();
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