diff --git a/videooverlay.cpp b/videooverlay.cpp index aeac7511ed6a8f2b2b33a41182f03c0941024b84..a8e1e1bfeb99b77026212f22e3db36ee06e95c00 100644 --- a/videooverlay.cpp +++ b/videooverlay.cpp @@ -20,6 +20,8 @@ #include "videooverlay.h" #include "ui_videooverlay.h" +#include <QTime> + // LRC #include "callmodel.h" #include "contactmethod.h" @@ -45,27 +47,6 @@ VideoOverlay::VideoOverlay(QWidget* parent) : ui->noMicButton->setCheckable(true); ui->onHoldLabel->setVisible(false); - - auto accountList = LRCInstance::accountModel().getAccountList(); - if (!accountList.size()) { - Utils::oneShotConnect(&LRCInstance::accountModel(), - &lrc::api::NewAccountModel::accountAdded, - [this](const std::string& accountId) { - Q_UNUSED(accountId); - connect(LRCInstance::getCurrentCallModel(), &lrc::api::NewCallModel::callStarted, - [this](const std::string& tempCallId) { - callId = tempCallId; - }); - }); - } else { - connect(LRCInstance::getCurrentCallModel(), &lrc::api::NewCallModel::callStarted, - [this](const std::string& tempCallId) { - callId = tempCallId; - }); - } - - connect(oneSecondTimer_, &QTimer::timeout, this, &VideoOverlay::setTime); - oneSecondTimer_->start(1000); } VideoOverlay::~VideoOverlay() @@ -73,6 +54,15 @@ VideoOverlay::~VideoOverlay() delete ui; } +void +VideoOverlay::callStarted(const std::string& callId) +{ + ui->timerLabel->setText("00:00"); + callId_ = callId; + connect(oneSecondTimer_, &QTimer::timeout, this, &VideoOverlay::setTime); + oneSecondTimer_->start(1000); +} + void VideoOverlay::setName(const QString& name) { @@ -82,32 +72,16 @@ VideoOverlay::setName(const QString& name) void VideoOverlay::setTime() { - if (callId.empty()) { return; } + if (callId_.empty()) { + return; + } try { - auto callInfo = LRCInstance::getCurrentCallModel()->getCall(callId); + auto callInfo = LRCInstance::getCurrentCallModel()->getCall(callId_); if (callInfo.status == lrc::api::call::Status::IN_PROGRESS) { - int numSeconds = std::chrono::duration_cast<std::chrono::seconds>( std::chrono::steady_clock::now() - callInfo.startTime).count(); - - QString labelSec; - QString labelMin; - - int numMinutes = numSeconds / 60; - int remainder = numSeconds - numMinutes * 60; - if (remainder < 10) { - labelSec = ":0" + QString::number(remainder); - } else { - labelSec = ":" + QString::number(remainder); - } - - if (numMinutes < 10) { - labelMin = "0" + QString::number(numMinutes); - } else { - labelMin = QString::number(numMinutes); - } - - ui->timerLabel->setText(labelMin + labelSec); + QTime t(0, 0, numSeconds); + ui->timerLabel->setText(t.toString(numSeconds > 3600 ? "hh:mm:ss" : "mm:ss")); } } catch (...) { } } diff --git a/videooverlay.h b/videooverlay.h index 6eb7825fd64d0638a5448b6b270945129cebf979..c44964c0a9697e5fe7aecdead7a2bfe92dcf621d 100644 --- a/videooverlay.h +++ b/videooverlay.h @@ -36,6 +36,7 @@ public: public: void setName(const QString& name); + void callStarted(const std::string & callId); inline bool isDialogVisible(){ return dialogVisible_; }; void toggleContextButtons(bool visible); void setVideoMuteVisibility(bool visible); @@ -43,11 +44,9 @@ public: void simulateShowChatview(bool checked); bool getShowChatView(); -public slots: - void setTime(); - //UI SLOTS private slots: + void setTime(); void on_hangupButton_clicked(); void on_chatButton_toggled(bool checked); void on_holdButton_clicked(); @@ -60,10 +59,9 @@ private: Ui::VideoOverlay* ui; bool dialogVisible_ = false; QTimer* oneSecondTimer_; - std::string callId; + std::string callId_; signals: void setChatVisibility(bool visible); void videoCfgBtnClicked(); }; - diff --git a/videoview.cpp b/videoview.cpp index 225ce7f00ee3af75d5a85701989e4491e3b90ea5..969abcf0c88e6704772bb0223e1b129f4e127092 100644 --- a/videoview.cpp +++ b/videoview.cpp @@ -324,21 +324,23 @@ VideoView::showContextMenu(const QPoint& pos) } void -VideoView::pushRenderer(const std::string& callUid) { +VideoView::pushRenderer(const std::string& callId) { auto callModel = LRCInstance::getCurrentCallModel(); QObject::disconnect(videoStartedConnection_); - if (!callModel->hasCall(callUid)) { + if (!callModel->hasCall(callId)) { return; } - auto call = callModel->getCall(callUid); + auto call = callModel->getCall(callId); + + this->overlay_->callStarted(callId); + this->overlay_->setVideoMuteVisibility(!LRCInstance::getCurrentCallModel()->getCall(callId).isAudioOnly); videoStartedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::remotePreviewStarted, [this](const std::string& callId, Video::Renderer* renderer) { Q_UNUSED(callId); slotVideoStarted(renderer); - this->overlay_->setVideoMuteVisibility(!LRCInstance::getCurrentCallModel()->getCall(callId).isAudioOnly); }); ui->videoWidget->setPreviewDisplay(call.type != lrc::api::call::Type::CONFERENCE); }