callwidget: remove references to CallModel

Change-Id: Iaa7f805e50d02f234c77083cd68198a00e8884c5
diff --git a/videoview.cpp b/videoview.cpp
index 969abcf..ab8b589 100644
--- a/videoview.cpp
+++ b/videoview.cpp
@@ -42,9 +42,6 @@
 {
     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 @@
 }
 
 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
@@ -183,14 +184,6 @@
 }
 
 void
-VideoView::updateCall()
-{
-    if (auto call = CallModel::instance().selectedCall()) {
-        overlay_->setName(call->formattedName());
-    }
-}
-
-void
 VideoView::mouseDoubleClickEvent(QMouseEvent* e) {
     QWidget::mouseDoubleClickEvent(e);
     toggleFullScreen();
@@ -328,6 +321,8 @@
     auto callModel = LRCInstance::getCurrentCallModel();
 
     QObject::disconnect(videoStartedConnection_);
+    QObject::disconnect(callStatusChangedConnection_);
+
     if (!callModel->hasCall(callId)) {
         return;
     }
@@ -337,6 +332,9 @@
     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);