diff --git a/callwidget.cpp b/callwidget.cpp index d591796f80d645e6ccb7c462ade456c0b53a21db..cae7dda72e5d0c670694aaf53d52b5470ca6f7a8 100644 --- a/callwidget.cpp +++ b/callwidget.cpp @@ -545,22 +545,6 @@ CallWidget::smartListSelectionChanged(const QItemSelection &selected, const QIt selectConversation(selectedIndex); } -void -CallWidget::placeCall() -{ - if (ui->ringContactLineEdit->text().isEmpty()) - return; - Call* c = CallModel::instance().dialingCall(PhoneDirectoryModel::instance().getNumber(ui->ringContactLineEdit->text())); - c->performAction(Call::Action::ACCEPT); - ui->ringContactLineEdit->clear(); - auto photoRect = ui->callingPhoto->frameGeometry(); - ui->callingPhoto->setPixmap( - QPixmap::fromImage( - GlobalInstances::pixmapManipulator() - .callPhoto(c, QSize(photoRect.width(), photoRect.height())) - .value<QImage>())); -} - void CallWidget::conversationsButtonClicked() { diff --git a/callwidget.h b/callwidget.h index 54365b97382e1b18c36a694f11aed3b3ba62ed8d..1c006745a3ab5b2634225283e25533bc7f0e6a4c 100644 --- a/callwidget.h +++ b/callwidget.h @@ -33,7 +33,6 @@ #include "smartlistmodel.h" // old LRC -#include "callmodel.h" #include "video/renderer.h" #include "video/previewmanager.h" #include "accountmodel.h" diff --git a/utils.cpp b/utils.cpp index 381fc32f9ed7e4888595ba44e988e38b07dfcbb7..e6e90287e7313fecc535a764e3d881ef28a21d5e 100644 --- a/utils.cpp +++ b/utils.cpp @@ -430,18 +430,23 @@ Utils::generateTintedPixmap(const QString& filename, QColor color) return QPixmap::fromImage(tmpImage); } -std::string -Utils::getConversationFromCallId(const std::string& callId) +lrc::api::conversation::Info +Utils::getConversationFromCallId(const std::string & callId) { auto convModel = LRCInstance::getCurrentConversationModel(); - auto conversations = convModel->allFilteredConversations(); - std::string convUid; - for (auto conversation : conversations) { - if (conversation.callId == callId) { - return conversation.uid; + using namespace lrc::api::profile; + for (int i = toUnderlyingValue(Type::RING); i <= toUnderlyingValue(Type::TEMPORARY); ++i) { + auto filter = toEnum<lrc::api::profile::Type>(i); + auto conversations = convModel->getFilteredConversations(filter); + auto conv = std::find_if(conversations.begin(), conversations.end(), + [&](const lrc::api::conversation::Info& conv) { + return callId == conv.callId; + }); + if (conv != conversations.end()) { + return *conv; } } - return ""; + return lrc::api::conversation::Info(); } lrc::api::conversation::Info diff --git a/utils.h b/utils.h index c2d79c9744bb9b0fee621f335a704077b7068458..6d981c60962aaa925f295708d4267989bfc288ec 100644 --- a/utils.h +++ b/utils.h @@ -78,7 +78,7 @@ namespace Utils QImage conversationPhoto(const std::string& convUid, const lrc::api::account::Info& accountInfo); QByteArray QByteArrayFromFile(const QString& filename); QPixmap generateTintedPixmap(const QString& filename, QColor color); - std::string getConversationFromCallId(const std::string& callId); + lrc::api::conversation::Info getConversationFromCallId(const std::string& callId); lrc::api::conversation::Info getSelectedConversation(); lrc::api::conversation::Info getConversationFromUid(const std::string & convUid, bool filtered = true); diff --git a/videoview.cpp b/videoview.cpp index 969abcf0c88e6704772bb0223e1b129f4e127092..ab8b589f34380abb441fc4a9794be1b41dc205eb 100644 --- a/videoview.cpp +++ b/videoview.cpp @@ -42,9 +42,6 @@ VideoView::VideoView(QWidget* parent) : { ui->setupUi(this); - connect(&CallModel::instance(), SIGNAL(callStateChanged(Call*, Call::State)), - this, SLOT(callStateChanged(Call*, Call::State))); - overlay_ = new VideoOverlay(this); auto effect = new QGraphicsOpacityEffect(overlay_); effect->setOpacity(maxOverlayOpacity_); @@ -150,23 +147,27 @@ VideoView::fadeOverlayOut() } void -VideoView::callStateChanged(Call* call, Call::State previousState) +VideoView::slotCallStatusChanged(const std::string& callId) { - Q_UNUSED(previousState) - - if (call->state() == Call::State::CURRENT) { + using namespace lrc::api::call; + auto call = LRCInstance::getCurrentCallModel()->getCall(callId); + switch (call.status) { + case Status::IN_PROGRESS: + { ui->videoWidget->show(); - timerConnection_ = connect(call, SIGNAL(changed()), this, SLOT(updateCall())); - } else { - QObject::disconnect(timerConnection_); - try { - if (call) { - emit closing(call->historyId().toStdString()); - } - } catch (...) { - qWarning() << "VideoView::callStateChanged except"; + auto convInfo = Utils::getConversationFromCallId(call.id); + if (!convInfo.uid.empty()) { + auto contactInfo = LRCInstance::getCurrentAccountInfo().contactModel->getContact(convInfo.participants[0]); + auto contactName = Utils::bestNameForContact(contactInfo); + overlay_->setName(QString::fromStdString(contactName)); } + return; + } + default: + emit closing(call.id); + break; } + QObject::disconnect(timerConnection_); } void @@ -182,14 +183,6 @@ VideoView::simulateShowChatview(bool checked) overlay_->simulateShowChatview(true); } -void -VideoView::updateCall() -{ - if (auto call = CallModel::instance().selectedCall()) { - overlay_->setName(call->formattedName()); - } -} - void VideoView::mouseDoubleClickEvent(QMouseEvent* e) { QWidget::mouseDoubleClickEvent(e); @@ -328,6 +321,8 @@ VideoView::pushRenderer(const std::string& callId) { auto callModel = LRCInstance::getCurrentCallModel(); QObject::disconnect(videoStartedConnection_); + QObject::disconnect(callStatusChangedConnection_); + if (!callModel->hasCall(callId)) { return; } @@ -337,6 +332,9 @@ VideoView::pushRenderer(const std::string& callId) { this->overlay_->callStarted(callId); this->overlay_->setVideoMuteVisibility(!LRCInstance::getCurrentCallModel()->getCall(callId).isAudioOnly); + callStatusChangedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::callStatusChanged, + this, &VideoView::slotCallStatusChanged); + videoStartedConnection_ = QObject::connect(callModel, &lrc::api::NewCallModel::remotePreviewStarted, [this](const std::string& callId, Video::Renderer* renderer) { Q_UNUSED(callId); diff --git a/videoview.h b/videoview.h index f2f388cf984f0549cfe9cf1304b388dd790ae94c..2782d9068abd667af3212c2c946cf28650936710 100644 --- a/videoview.h +++ b/videoview.h @@ -57,8 +57,7 @@ protected: void mouseMoveEvent(QMouseEvent* event); private slots: - void callStateChanged(Call* call, Call::State previousState); - void updateCall(); + void slotCallStatusChanged(const std::string& callId); void showContextMenu(const QPoint& pos); void slotVideoStarted(Video::Renderer* renderer); void fadeOverlayOut(); @@ -73,6 +72,7 @@ private: QSize oldSize_; QMetaObject::Connection timerConnection_; QMetaObject::Connection videoStartedConnection_; + QMetaObject::Connection callStatusChangedConnection_; QPoint origin_; QPoint originMouseDisplacement_; bool draggingPreview_ = false; @@ -102,4 +102,3 @@ signals: void toggleFullScreenClicked(); void closing(const std::string& callid); }; -