From 7e3ad7ba873615f4b7a65071d678ac936f7504e7 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Thu, 4 May 2017 22:42:39 +0300 Subject: [PATCH] refactor(chatform): Remove Audio dependencies from ChatForm --- src/widget/form/chatform.cpp | 10 ++++------ src/widget/form/chatform.h | 2 ++ src/widget/widget.cpp | 22 ++++++++++++++++++++++ src/widget/widget.h | 3 +++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index bad36feed..7b4531160 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -386,7 +386,6 @@ void ChatForm::onAvEnd(uint32_t friendId) netcam->showNormal(); } - Audio::getInstance().stopLoop(); updateCallButtons(); stopCounter(); hideNetcam(); @@ -406,10 +405,11 @@ void ChatForm::showOutgoingCall(bool video) void ChatForm::onAnswerCallTriggered() { delete callConfirm; - Audio::getInstance().stopLoop(); + uint32_t friendId = f->getFriendId(); + emit acceptCall(friendId); + updateCallButtons(); CoreAV* av = Core::getInstance()->getAv(); - uint32_t friendId = f->getFriendId(); if (!av->answerCall(friendId)) { updateCallButtons(); stopCounter(); @@ -423,9 +423,7 @@ void ChatForm::onAnswerCallTriggered() void ChatForm::onRejectCallTriggered() { delete callConfirm; - Audio::getInstance().stopLoop(); - CoreAV* av = Core::getInstance()->getAv(); - av->cancelCall(f->getFriendId()); + emit rejectCall(f->getFriendId()); } void ChatForm::onCallTriggered() diff --git a/src/widget/form/chatform.h b/src/widget/form/chatform.h index 75efa84b2..ee366be14 100644 --- a/src/widget/form/chatform.h +++ b/src/widget/form/chatform.h @@ -58,6 +58,8 @@ public: signals: void aliasChanged(const QString& alias); void incomingNotification(uint32_t friendId); + void rejectCall(uint32_t friendId); + void acceptCall(uint32_t friendId); public slots: void startFileSend(ToxFile file); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 347e47011..8cd989fe9 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -234,6 +234,9 @@ void Widget::init() const Settings& s = Settings::getInstance(); Core* core = Nexus::getCore(); + CoreAV* av = core->getAv(); + connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd); + connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete); connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete); connect(core, &Core::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded); @@ -928,6 +931,23 @@ void Widget::incomingNotification(uint32_t friendId) audio.playMono16Sound(Audio::getSound(Audio::Sound::IncomingCall)); } +void Widget::onRejectCall(uint32_t friendId) +{ + Audio::getInstance().stopLoop(); + CoreAV* av = Core::getInstance()->getAv(); + av->cancelCall(friendId); +} + +void Widget::onAcceptCall(uint32_t friendId) +{ + Audio::getInstance().stopLoop(); +} + +void Widget::onCallEnd(uint32_t friendId) +{ + Audio::getInstance().stopLoop(); +} + void Widget::addFriend(int friendId, const ToxPk& friendPk) { Friend* newfriend = FriendList::addFriend(friendId, friendPk); @@ -954,6 +974,8 @@ void Widget::addFriend(int friendId, const ToxPk& friendPk) connect(newfriend, &Friend::nameChanged, this, &Widget::onFriendAliasChanged); connect(friendForm, &ChatForm::incomingNotification, this, &Widget::incomingNotification); + connect(friendForm, &ChatForm::rejectCall, this, &Widget::onRejectCall); + connect(friendForm, &ChatForm::acceptCall, this, &Widget::onAcceptCall); connect(widget, &FriendWidget::chatroomWidgetClicked, this, &Widget::onChatroomWidgetClicked); connect(widget, &FriendWidget::chatroomWidgetClicked, friendForm, &ChatForm::focusInput); diff --git a/src/widget/widget.h b/src/widget/widget.h index 0aa9dcbd0..49d4e8cd0 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -218,6 +218,9 @@ private slots: void groupInvitesClear(); void onDialogShown(GenericChatroomWidget* widget); void incomingNotification(uint32_t friendId); + void onRejectCall(uint32_t friendId); + void onAcceptCall(uint32_t friendId); + void onCallEnd(uint32_t friendId); private: bool newMessageAlert(QWidget* currentWindow, bool isActive, bool sound = true, bool notify = true);