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

refactor: remove Core::getInstance() from ChatForm classes

This commit is contained in:
sudden6 2020-05-02 22:55:49 +02:00
parent ea46c0caf2
commit 9306e946f8
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
11 changed files with 89 additions and 83 deletions

View File

@ -184,7 +184,7 @@ void Nexus::bootstrapWithProfile(Profile* p)
if (profile) { if (profile) {
audioControl = std::unique_ptr<IAudioControl>(Audio::makeAudio(*settings)); audioControl = std::unique_ptr<IAudioControl>(Audio::makeAudio(*settings));
assert(audioControl != nullptr); assert(audioControl != nullptr);
profile->getCore()->getAv()->setAudio(*audioControl); profile->getCore().getAv()->setAudio(*audioControl);
start(); start();
} }
} }
@ -224,7 +224,7 @@ void Nexus::showMainGUI()
assert(profile); assert(profile);
// Create GUI // Create GUI
widget = new Widget(*audioControl); widget = new Widget(*profile, *audioControl);
// Start GUI // Start GUI
widget->init(); widget->init();
@ -278,7 +278,7 @@ Core* Nexus::getCore()
if (!nexus.profile) if (!nexus.profile)
return nullptr; return nullptr;
return nexus.profile->getCore(); return &nexus.profile->getCore();
} }
/** /**

View File

@ -404,10 +404,11 @@ const QStringList Profile::getAllProfileNames()
return profiles; return profiles;
} }
Core* Profile::getCore() Core& Profile::getCore() const
{ {
// TODO(sudden6): this is evil Core* c = core.get();
return core.get(); assert(c != nullptr);
return *c;
} }
QString Profile::getName() const QString Profile::getName() const

View File

@ -48,7 +48,7 @@ public:
const QCommandLineParser* parser); const QCommandLineParser* parser);
~Profile(); ~Profile();
Core* getCore(); Core& getCore() const;
QString getName() const; QString getName() const;
void startCore(); void startCore();

View File

@ -104,8 +104,9 @@ QString secondsToDHMS(quint32 duration)
} }
} // namespace } // namespace
ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher) ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher)
: GenericChatForm(chatFriend, chatLog, messageDispatcher) : GenericChatForm(profile.getCore(), chatFriend, chatLog, messageDispatcher)
, core{profile.getCore()}
, f(chatFriend) , f(chatFriend)
, isTyping{false} , isTyping{false}
, lastCallIsVideo{false} , lastCallIsVideo{false}
@ -136,17 +137,15 @@ ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& me
copyStatusAction = statusMessageMenu.addAction(QString(), this, SLOT(onCopyStatusMessage())); copyStatusAction = statusMessageMenu.addAction(QString(), this, SLOT(onCopyStatusMessage()));
const Core* core = Core::getInstance(); const CoreFile* coreFile = core.getCoreFile();
const Profile* profile = Nexus::getProfile(); connect(&profile, &Profile::friendAvatarChanged, this, &ChatForm::onAvatarChanged);
const CoreFile* coreFile = core->getCoreFile();
connect(profile, &Profile::friendAvatarChanged, this, &ChatForm::onAvatarChanged);
connect(coreFile, &CoreFile::fileReceiveRequested, this, &ChatForm::updateFriendActivityForFile); connect(coreFile, &CoreFile::fileReceiveRequested, this, &ChatForm::updateFriendActivityForFile);
connect(coreFile, &CoreFile::fileSendStarted, this, &ChatForm::updateFriendActivityForFile); connect(coreFile, &CoreFile::fileSendStarted, this, &ChatForm::updateFriendActivityForFile);
connect(core, &Core::friendTypingChanged, this, &ChatForm::onFriendTypingChanged); connect(&core, &Core::friendTypingChanged, this, &ChatForm::onFriendTypingChanged);
connect(core, &Core::friendStatusChanged, this, &ChatForm::onFriendStatusChanged); connect(&core, &Core::friendStatusChanged, this, &ChatForm::onFriendStatusChanged);
connect(coreFile, &CoreFile::fileNameChanged, this, &ChatForm::onFileNameChanged); connect(coreFile, &CoreFile::fileNameChanged, this, &ChatForm::onFileNameChanged);
const CoreAV* av = core->getAv(); const CoreAV* av = core.getAv();
connect(av, &CoreAV::avInvite, this, &ChatForm::onAvInvite); connect(av, &CoreAV::avInvite, this, &ChatForm::onAvInvite);
connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart); connect(av, &CoreAV::avStart, this, &ChatForm::onAvStart);
connect(av, &CoreAV::avEnd, this, &ChatForm::onAvEnd); connect(av, &CoreAV::avEnd, this, &ChatForm::onAvEnd);
@ -167,8 +166,8 @@ ChatForm::ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& me
} }
}); });
connect(&typingTimer, &QTimer::timeout, this, [=] { connect(&typingTimer, &QTimer::timeout, this, [&] {
Core::getInstance()->sendTyping(f->getId(), false); core.sendTyping(f->getId(), false);
isTyping = false; isTyping = false;
}); });
@ -229,14 +228,14 @@ void ChatForm::onTextEditChanged()
if (!Settings::getInstance().getTypingNotification()) { if (!Settings::getInstance().getTypingNotification()) {
if (isTyping) { if (isTyping) {
isTyping = false; isTyping = false;
Core::getInstance()->sendTyping(f->getId(), false); core.sendTyping(f->getId(), false);
} }
return; return;
} }
bool isTypingNow = !msgEdit->toPlainText().isEmpty(); bool isTypingNow = !msgEdit->toPlainText().isEmpty();
if (isTyping != isTypingNow) { if (isTyping != isTypingNow) {
Core::getInstance()->sendTyping(f->getId(), isTypingNow); core.sendTyping(f->getId(), isTypingNow);
if (isTypingNow) { if (isTypingNow) {
typingTimer.start(TYPING_NOTIFICATION_DURATION); typingTimer.start(TYPING_NOTIFICATION_DURATION);
} }
@ -254,7 +253,6 @@ void ChatForm::onAttachClicked()
return; return;
} }
Core* core = Core::getInstance();
for (QString path : paths) { for (QString path : paths) {
QFile file(path); QFile file(path);
QString fileName = QFileInfo(path).fileName(); QString fileName = QFileInfo(path).fileName();
@ -273,7 +271,7 @@ void ChatForm::onAttachClicked()
} }
qint64 filesize = file.size(); qint64 filesize = file.size();
core->getCoreFile()->sendFile(f->getId(), fileName, path, filesize); core.getCoreFile()->sendFile(f->getId(), fileName, path, filesize);
} }
} }
@ -293,7 +291,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
if (Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(testedFlag)) { if (Settings::getInstance().getAutoAcceptCall(f->getPublicKey()).testFlag(testedFlag)) {
uint32_t friendId = f->getId(); uint32_t friendId = f->getId();
qDebug() << "automatic call answer"; qDebug() << "automatic call answer";
CoreAV* coreav = Core::getInstance()->getAv(); CoreAV* coreav = core.getAv();
QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection, QMetaObject::invokeMethod(coreav, "answerCall", Qt::QueuedConnection,
Q_ARG(uint32_t, friendId), Q_ARG(bool, video)); Q_ARG(uint32_t, friendId), Q_ARG(bool, video));
onAvStart(friendId, video); onAvStart(friendId, video);
@ -358,7 +356,7 @@ void ChatForm::onAnswerCallTriggered(bool video)
emit acceptCall(friendId); emit acceptCall(friendId);
updateCallButtons(); updateCallButtons();
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
if (!av->answerCall(friendId, video)) { if (!av->answerCall(friendId, video)) {
updateCallButtons(); updateCallButtons();
stopCounter(); stopCounter();
@ -377,7 +375,7 @@ void ChatForm::onRejectCallTriggered()
void ChatForm::onCallTriggered() void ChatForm::onCallTriggered()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
uint32_t friendId = f->getId(); uint32_t friendId = f->getId();
if (av->isCallStarted(f)) { if (av->isCallStarted(f)) {
av->cancelCall(friendId); av->cancelCall(friendId);
@ -388,7 +386,7 @@ void ChatForm::onCallTriggered()
void ChatForm::onVideoCallTriggered() void ChatForm::onVideoCallTriggered()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
uint32_t friendId = f->getId(); uint32_t friendId = f->getId();
if (av->isCallStarted(f)) { if (av->isCallStarted(f)) {
// TODO: We want to activate video on the active call. // TODO: We want to activate video on the active call.
@ -402,7 +400,7 @@ void ChatForm::onVideoCallTriggered()
void ChatForm::updateCallButtons() void ChatForm::updateCallButtons()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
const bool audio = av->isCallActive(f); const bool audio = av->isCallActive(f);
const bool video = av->isCallVideoEnabled(f); const bool video = av->isCallVideoEnabled(f);
const bool online = Status::isOnline(f->getStatus()); const bool online = Status::isOnline(f->getStatus());
@ -413,14 +411,14 @@ void ChatForm::updateCallButtons()
void ChatForm::onMicMuteToggle() void ChatForm::onMicMuteToggle()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
av->toggleMuteCallInput(f); av->toggleMuteCallInput(f);
updateMuteMicButton(); updateMuteMicButton();
} }
void ChatForm::onVolMuteToggle() void ChatForm::onVolMuteToggle()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
av->toggleMuteCallOutput(f); av->toggleMuteCallOutput(f);
updateMuteVolButton(); updateMuteVolButton();
} }
@ -483,7 +481,7 @@ std::unique_ptr<NetCamView> ChatForm::createNetcam()
qDebug() << "creating netcam"; qDebug() << "creating netcam";
uint32_t friendId = f->getId(); uint32_t friendId = f->getId();
std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(new NetCamView(f->getPublicKey(), this)); std::unique_ptr<NetCamView> view = std::unique_ptr<NetCamView>(new NetCamView(f->getPublicKey(), this));
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
VideoSource* source = av->getVideoSourceFromCall(friendId); VideoSource* source = av->getVideoSourceFromCall(friendId);
view->show(source, f->getDisplayedName()); view->show(source, f->getDisplayedName());
connect(view.get(), &NetCamView::videoCallEnd, this, &ChatForm::onVideoCallTriggered); connect(view.get(), &NetCamView::videoCallEnd, this, &ChatForm::onVideoCallTriggered);
@ -505,7 +503,6 @@ void ChatForm::dropEvent(QDropEvent* ev)
return; return;
} }
Core* core = Core::getInstance();
for (const QUrl& url : ev->mimeData()->urls()) { for (const QUrl& url : ev->mimeData()->urls()) {
QFileInfo info(url.path()); QFileInfo info(url.path());
QFile file(info.absoluteFilePath()); QFile file(info.absoluteFilePath());
@ -538,7 +535,7 @@ void ChatForm::dropEvent(QDropEvent* ev)
} }
if (info.exists()) { if (info.exists()) {
core->getCoreFile()->sendFile(f->getId(), fileName, info.absoluteFilePath(), info.size()); core.getCoreFile()->sendFile(f->getId(), fileName, info.absoluteFilePath(), info.size());
} }
} }
} }
@ -582,7 +579,7 @@ void ChatForm::sendImage(const QPixmap& pixmap)
qint64 filesize = file.size(); qint64 filesize = file.size();
file.close(); file.close();
QFileInfo fi(file); QFileInfo fi(file);
CoreFile* coreFile = Core::getInstance()->getCoreFile(); CoreFile* coreFile = core.getCoreFile();
coreFile->sendFile(f->getId(), fi.fileName(), fi.filePath(), filesize); coreFile->sendFile(f->getId(), fi.fileName(), fi.filePath(), filesize);
} else { } else {
QMessageBox::warning(this, QMessageBox::warning(this,
@ -611,7 +608,7 @@ void ChatForm::onCopyStatusMessage()
void ChatForm::updateMuteMicButton() void ChatForm::updateMuteMicButton()
{ {
const CoreAV* av = Core::getInstance()->getAv(); const CoreAV* av = core.getAv();
bool active = av->isCallActive(f); bool active = av->isCallActive(f);
bool inputMuted = av->isCallInputMuted(f); bool inputMuted = av->isCallInputMuted(f);
headWidget->updateMuteMicButton(active, inputMuted); headWidget->updateMuteMicButton(active, inputMuted);
@ -622,7 +619,7 @@ void ChatForm::updateMuteMicButton()
void ChatForm::updateMuteVolButton() void ChatForm::updateMuteVolButton()
{ {
const CoreAV* av = Core::getInstance()->getAv(); const CoreAV* av = core.getAv();
bool active = av->isCallActive(f); bool active = av->isCallActive(f);
bool outputMuted = av->isCallOutputMuted(f); bool outputMuted = av->isCallOutputMuted(f);
headWidget->updateMuteVolButton(active, outputMuted); headWidget->updateMuteVolButton(active, outputMuted);

View File

@ -47,8 +47,8 @@ class ChatForm : public GenericChatForm
{ {
Q_OBJECT Q_OBJECT
public: public:
ChatForm(Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher); ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog, IMessageDispatcher& messageDispatcher);
~ChatForm(); ~ChatForm() override;
void setStatusMessage(const QString& newMessage); void setStatusMessage(const QString& newMessage);
void setFriendTyping(bool isTyping); void setFriendTyping(bool isTyping);
@ -122,6 +122,7 @@ protected:
void showEvent(QShowEvent* event) final; void showEvent(QShowEvent* event) final;
private: private:
Core& core;
Friend* f; Friend* f;
CroppingLabel* statusMessageLabel; CroppingLabel* statusMessageLabel;
QMenu statusMessageMenu; QMenu statusMessageMenu;

View File

@ -182,7 +182,7 @@ ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool col
isSelf, chatLogMessage.state, timestamp, colorizeNames); isSelf, chatLogMessage.state, timestamp, colorizeNames);
} }
void renderMessage(const QString& displayName, bool isSelf, bool colorizeNames, void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
const ChatLogMessage& chatLogMessage, ChatMessage::Ptr& chatMessage) const ChatLogMessage& chatLogMessage, ChatMessage::Ptr& chatMessage)
{ {
@ -208,33 +208,6 @@ void renderFile(QString displayName, ToxFile file, bool isSelf, QDateTime timest
} }
} }
void renderItem(const ChatLogItem& item, bool hideName, bool colorizeNames, ChatMessage::Ptr& chatMessage)
{
const auto& sender = item.getSender();
const Core* core = Core::getInstance();
bool isSelf = sender == core->getSelfId().getPublicKey();
switch (item.getContentType()) {
case ChatLogItem::ContentType::message: {
const auto& chatLogMessage = item.getContentAsMessage();
renderMessage(item.getDisplayName(), isSelf, colorizeNames, chatLogMessage, chatMessage);
break;
}
case ChatLogItem::ContentType::fileTransfer: {
const auto& file = item.getContentAsFile();
renderFile(item.getDisplayName(), file.file, isSelf, item.getTimestamp(), chatMessage);
break;
}
}
if (hideName) {
chatMessage->hideSender();
}
}
ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog) ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog)
{ {
auto idxs = chatLog.getDateIdxs(date, 1); auto idxs = chatLog.getDateIdxs(date, 1);
@ -246,9 +219,10 @@ ChatLogIdx firstItemAfterDate(QDate date, const IChatLog& chatLog)
} }
} // namespace } // namespace
GenericChatForm::GenericChatForm(const Contact* contact, IChatLog& chatLog, GenericChatForm::GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog,
IMessageDispatcher& messageDispatcher, QWidget* parent) IMessageDispatcher& messageDispatcher, QWidget* parent)
: QWidget(parent, Qt::Window) : QWidget(parent, Qt::Window)
, core{_core}
, audioInputFlag(false) , audioInputFlag(false)
, audioOutputFlag(false) , audioOutputFlag(false)
, chatLog(chatLog) , chatLog(chatLog)
@ -1076,6 +1050,32 @@ void GenericChatForm::handleSearchResult(SearchResult result, SearchDirection di
renderMessages(endRenderedIdx, firstRenderedIdx, [this]{enableSearchText();}); renderMessages(endRenderedIdx, firstRenderedIdx, [this]{enableSearchText();});
} }
void GenericChatForm::renderItem(const ChatLogItem& item, bool hideName, bool colorizeNames, ChatMessage::Ptr& chatMessage)
{
const auto& sender = item.getSender();
bool isSelf = sender == core.getSelfId().getPublicKey();
switch (item.getContentType()) {
case ChatLogItem::ContentType::message: {
const auto& chatLogMessage = item.getContentAsMessage();
renderMessageRaw(item.getDisplayName(), isSelf, colorizeNames, chatLogMessage, chatMessage);
break;
}
case ChatLogItem::ContentType::fileTransfer: {
const auto& file = item.getContentAsFile();
renderFile(item.getDisplayName(), file.file, isSelf, item.getTimestamp(), chatMessage);
break;
}
}
if (hideName) {
chatMessage->hideSender();
}
}
void GenericChatForm::renderMessage(ChatLogIdx idx) void GenericChatForm::renderMessage(ChatLogIdx idx)
{ {
renderMessages(idx, idx + 1); renderMessages(idx, idx + 1);

View File

@ -70,7 +70,7 @@ class GenericChatForm : public QWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
GenericChatForm(const Contact* contact, IChatLog& chatLog, GenericChatForm(const Core& _core, const Contact* contact, IChatLog& chatLog,
IMessageDispatcher& messageDispatcher, QWidget* parent = nullptr); IMessageDispatcher& messageDispatcher, QWidget* parent = nullptr);
~GenericChatForm() override; ~GenericChatForm() override;
@ -136,6 +136,7 @@ private:
void removeFirstsMessages(const int num); void removeFirstsMessages(const int num);
void removeLastsMessages(const int num); void removeLastsMessages(const int num);
void renderItem(const ChatLogItem &item, bool hideName, bool colorizeNames, ChatMessage::Ptr &chatMessage);
protected: protected:
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message, ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
const QDateTime& datetime, bool isAction, bool isSent, bool colorizeName = false); const QDateTime& datetime, bool isAction, bool isSent, bool colorizeName = false);
@ -153,6 +154,7 @@ protected:
std::pair<int, int> indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction); std::pair<int, int> indexForSearchInLine(const QString& txt, const QString& phrase, const ParameterSearch& parameter, SearchDirection direction);
protected: protected:
const Core& core;
bool audioInputFlag; bool audioInputFlag;
bool audioOutputFlag; bool audioOutputFlag;
int curRow; int curRow;

View File

@ -82,8 +82,9 @@ QString editName(const QString& name)
* @brief Timeout = peer stopped sending audio. * @brief Timeout = peer stopped sending audio.
*/ */
GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher) GroupChatForm::GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher)
: GenericChatForm(chatGroup, chatLog, messageDispatcher) : GenericChatForm(_core, chatGroup, chatLog, messageDispatcher)
, core{_core}
, group(chatGroup) , group(chatGroup)
, inCall(false) , inCall(false)
{ {
@ -185,7 +186,7 @@ void GroupChatForm::updateUserNames()
/* we store the peer labels by their ToxPk, but the namelist layout /* we store the peer labels by their ToxPk, but the namelist layout
* needs it in alphabetical order, so we first create and store the labels * needs it in alphabetical order, so we first create and store the labels
* and then sort them by their text and add them to the layout in that order */ * and then sort them by their text and add them to the layout in that order */
const auto selfPk = Core::getInstance()->getSelfPublicKey(); const auto selfPk = core.getSelfPublicKey();
for (const auto& peerPk : peers.keys()) { for (const auto& peerPk : peers.keys()) {
const QString peerName = peers.value(peerPk); const QString peerName = peers.value(peerPk);
const QString editedName = editName(peerName); const QString editedName = editName(peerName);
@ -296,14 +297,14 @@ void GroupChatForm::dropEvent(QDropEvent* ev)
int friendId = frnd->getId(); int friendId = frnd->getId();
int groupId = group->getId(); int groupId = group->getId();
if (Status::isOnline(frnd->getStatus())) { if (Status::isOnline(frnd->getStatus())) {
Core::getInstance()->groupInviteFriend(friendId, groupId); core.groupInviteFriend(friendId, groupId);
} }
} }
void GroupChatForm::onMicMuteToggle() void GroupChatForm::onMicMuteToggle()
{ {
if (audioInputFlag) { if (audioInputFlag) {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
const bool oldMuteState = av->isGroupCallInputMuted(group); const bool oldMuteState = av->isGroupCallInputMuted(group);
const bool newMute = !oldMuteState; const bool newMute = !oldMuteState;
av->muteCallInput(group, newMute); av->muteCallInput(group, newMute);
@ -314,7 +315,7 @@ void GroupChatForm::onMicMuteToggle()
void GroupChatForm::onVolMuteToggle() void GroupChatForm::onVolMuteToggle()
{ {
if (audioOutputFlag) { if (audioOutputFlag) {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
const bool oldMuteState = av->isGroupCallOutputMuted(group); const bool oldMuteState = av->isGroupCallOutputMuted(group);
const bool newMute = !oldMuteState; const bool newMute = !oldMuteState;
av->muteCallOutput(group, newMute); av->muteCallOutput(group, newMute);
@ -324,7 +325,7 @@ void GroupChatForm::onVolMuteToggle()
void GroupChatForm::onCallClicked() void GroupChatForm::onCallClicked()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
if (!inCall) { if (!inCall) {
joinGroupCall(); joinGroupCall();
@ -391,7 +392,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
Settings& s = Settings::getInstance(); Settings& s = Settings::getInstance();
QStringList blackList = s.getBlackList(); QStringList blackList = s.getBlackList();
QMenu* const contextMenu = new QMenu(this); QMenu* const contextMenu = new QMenu(this);
const ToxPk selfPk = Core::getInstance()->getSelfPublicKey(); const ToxPk selfPk = core.getSelfPublicKey();
ToxPk peerPk; ToxPk peerPk;
// delete menu after it stops being used // delete menu after it stops being used
@ -436,7 +437,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
void GroupChatForm::joinGroupCall() void GroupChatForm::joinGroupCall()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
av->joinGroupCall(*group); av->joinGroupCall(*group);
audioInputFlag = true; audioInputFlag = true;
audioOutputFlag = true; audioOutputFlag = true;
@ -445,7 +446,7 @@ void GroupChatForm::joinGroupCall()
void GroupChatForm::leaveGroupCall() void GroupChatForm::leaveGroupCall()
{ {
CoreAV* av = Core::getInstance()->getAv(); CoreAV* av = core.getAv();
av->leaveGroupCall(group->getId()); av->leaveGroupCall(group->getId());
audioInputFlag = false; audioInputFlag = false;
audioOutputFlag = false; audioOutputFlag = false;

View File

@ -39,7 +39,7 @@ class GroupChatForm : public GenericChatForm
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher); explicit GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher);
~GroupChatForm(); ~GroupChatForm();
void peerAudioPlaying(ToxPk peerPk); void peerAudioPlaying(ToxPk peerPk);
@ -71,6 +71,7 @@ private:
void leaveGroupCall(); void leaveGroupCall();
private: private:
Core& core;
Group* group; Group* group;
QMap<ToxPk, QLabel*> peerLabels; QMap<ToxPk, QLabel*> peerLabels;
QMap<ToxPk, QTimer*> peerAudioTimers; QMap<ToxPk, QTimer*> peerAudioTimers;

View File

@ -137,8 +137,9 @@ void Widget::acceptFileTransfer(const ToxFile& file, const QString& path)
Widget* Widget::instance{nullptr}; Widget* Widget::instance{nullptr};
Widget::Widget(IAudioControl& audio, QWidget* parent) Widget::Widget(Profile &_profile, IAudioControl& audio, QWidget* parent)
: QMainWindow(parent) : QMainWindow(parent)
, profile{_profile}
, trayMenu{nullptr} , trayMenu{nullptr}
, ui(new Ui::MainWindow) , ui(new Ui::MainWindow)
, activeChatroomWidget{nullptr} , activeChatroomWidget{nullptr}
@ -277,7 +278,7 @@ void Widget::init()
addFriendForm = new AddFriendForm; addFriendForm = new AddFriendForm;
groupInviteForm = new GroupInviteForm; groupInviteForm = new GroupInviteForm;
core = Nexus::getCore(); core = &profile.getCore();
#if UPDATE_CHECK_ENABLED #if UPDATE_CHECK_ENABLED
updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings)); updateCheck = std::unique_ptr<UpdateCheck>(new UpdateCheck(settings));
@ -1146,7 +1147,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
auto chatHistory = auto chatHistory =
std::make_shared<ChatHistory>(*newfriend, history, *core, Settings::getInstance(), std::make_shared<ChatHistory>(*newfriend, history, *core, Settings::getInstance(),
*friendMessageDispatcher); *friendMessageDispatcher);
auto friendForm = new ChatForm(newfriend, *chatHistory, *friendMessageDispatcher); auto friendForm = new ChatForm(profile, newfriend, *chatHistory, *friendMessageDispatcher);
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity); connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
friendMessageDispatchers[friendPk] = friendMessageDispatcher; friendMessageDispatchers[friendPk] = friendMessageDispatcher;
@ -2110,7 +2111,8 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback); connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback);
groupAlertConnections.insert(groupId, notifyReceivedConnection); groupAlertConnections.insert(groupId, notifyReceivedConnection);
auto form = new GroupChatForm(newgroup, *groupChatLog, *messageDispatcher); assert(core != nullptr);
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher);
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames); connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
form->setColorizedNames(settings.getEnableGroupChatsColor()); form->setColorizedNames(settings.getEnableGroupChatsColor());
groupMessageDispatchers[groupId] = messageDispatcher; groupMessageDispatchers[groupId] = messageDispatcher;

View File

@ -117,7 +117,7 @@ private:
}; };
public: public:
explicit Widget(IAudioControl& audio, QWidget* parent = nullptr); explicit Widget(Profile& _profile, IAudioControl& audio, QWidget* parent = nullptr);
~Widget() override; ~Widget() override;
void init(); void init();
void setCentralWidget(QWidget* widget, const QString& widgetName); void setCentralWidget(QWidget* widget, const QString& widgetName);
@ -278,6 +278,7 @@ private:
void acceptFileTransfer(const ToxFile &file, const QString &path); void acceptFileTransfer(const ToxFile &file, const QString &path);
private: private:
Profile& profile;
std::unique_ptr<QSystemTrayIcon> icon; std::unique_ptr<QSystemTrayIcon> icon;
QMenu* trayMenu; QMenu* trayMenu;
QAction* statusOnline; QAction* statusOnline;