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

refactor(chatform): move netcam ownership to ChatForm from GenericChatForm

Since now only ChatForm uses the NetCamView.
This commit is contained in:
Anthony Bilinski 2020-01-25 23:00:32 -08:00
parent 8d8e75b800
commit 600993b43a
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
4 changed files with 11 additions and 16 deletions

View File

@ -191,8 +191,6 @@ ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& me
ChatForm::~ChatForm()
{
Translator::unregister(this);
delete netcam;
netcam = nullptr;
}
void ChatForm::setStatusMessage(const QString& newMessage)
@ -480,18 +478,18 @@ void ChatForm::onAvatarChanged(const ToxPk& friendPk, const QPixmap& pic)
headWidget->setAvatar(pic);
}
GenericNetCamView* ChatForm::createNetcam()
std::unique_ptr<GenericNetCamView> ChatForm::createNetcam()
{
qDebug() << "creating netcam";
uint32_t friendId = f->getId();
NetCamView* view = new NetCamView(f->getPublicKey(), this);
std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(new NetCamView(f->getPublicKey(), this));
CoreAV* av = Core::getInstance()->getAv();
VideoSource* source = av->getVideoSourceFromCall(friendId);
view->show(source, f->getDisplayedName());
connect(view, &GenericNetCamView::videoCallEnd, this, &ChatForm::onVideoCallTriggered);
connect(view, &GenericNetCamView::volMuteToggle, this, &ChatForm::onVolMuteToggle);
connect(view, &GenericNetCamView::micMuteToggle, this, &ChatForm::onMicMuteToggle);
connect(view, &GenericNetCamView::videoPreviewToggle, view, &NetCamView::toggleVideoPreview);
connect(view.get(), &GenericNetCamView::videoCallEnd, this, &ChatForm::onVideoCallTriggered);
connect(view.get(), &GenericNetCamView::volMuteToggle, this, &ChatForm::onVolMuteToggle);
connect(view.get(), &GenericNetCamView::micMuteToggle, this, &ChatForm::onMicMuteToggle);
connect(view.get(), &GenericNetCamView::videoPreviewToggle, view.get(), &NetCamView::toggleVideoPreview);
return view;
}
@ -718,10 +716,10 @@ void ChatForm::showNetcam()
netcam = createNetcam();
}
connect(netcam, &GenericNetCamView::showMessageClicked, this,
connect(netcam.get(), &GenericNetCamView::showMessageClicked, this,
&ChatForm::onShowMessagesClicked);
bodySplitter->insertWidget(0, netcam);
bodySplitter->insertWidget(0, netcam.get());
bodySplitter->setCollapsible(0, false);
QSize minSize = netcam->getSurfaceMinSize();
@ -744,8 +742,7 @@ void ChatForm::hideNetcam()
netcam->close();
netcam->hide();
delete netcam;
netcam = nullptr;
netcam.reset();
}
void ChatForm::onSplitterMoved(int, int)

View File

@ -113,7 +113,7 @@ private:
void hideNetcam();
protected:
GenericNetCamView* createNetcam();
std::unique_ptr<GenericNetCamView> createNetcam();
void insertChatMessage(ChatMessage::Ptr msg) final;
void dragEnterEvent(QDragEnterEvent* ev) final;
void dropEvent(QDropEvent* ev) final;
@ -131,6 +131,7 @@ private:
QAction* copyStatusAction;
bool isTyping;
bool lastCallIsVideo;
std::unique_ptr<GenericNetCamView> netcam;
};
#endif // CHATFORM_H

View File

@ -390,8 +390,6 @@ GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog,
auto firstChatLogIdx = (chatLogIdxRange < DEF_NUM_MSG_TO_LOAD) ? chatLog.getFirstIdx() : chatLog.getNextIdx() - DEF_NUM_MSG_TO_LOAD;
renderMessages(firstChatLogIdx, chatLog.getNextIdx());
netcam = nullptr;
}
GenericChatForm::~GenericChatForm()

View File

@ -186,7 +186,6 @@ protected:
Sonnet::SpellCheckDecorator* decorator{nullptr};
#endif
FlyoutOverlayWidget* fileFlyout;
GenericNetCamView* netcam;
Widget* parent;
IChatLog& chatLog;