From 82e0852f3c08287d6c6b941e478e3e28d669564e Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sat, 9 May 2020 23:33:59 +0200 Subject: [PATCH] refactor: remove Core::getInstance from grouplist --- src/grouplist.cpp | 10 ++++------ src/grouplist.h | 3 ++- src/widget/widget.cpp | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/grouplist.cpp b/src/grouplist.cpp index 9f0228242..e0c640c23 100644 --- a/src/grouplist.cpp +++ b/src/grouplist.cpp @@ -25,17 +25,15 @@ QHash GroupList::groupList; QHash GroupList::id2key; -Group* GroupList::addGroup(int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat, +Group* GroupList::addGroup(Core& core, int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat, const QString& selfName) { auto checker = groupList.find(groupId); - if (checker != groupList.end()) + if (checker != groupList.end()) { qWarning() << "addGroup: groupId already taken"; + } - // TODO: Core instance is bad but grouplist is also an instance so we can - // deal with this later - auto core = Core::getInstance(); - Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, *core, *core); + Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, core, core); groupList[groupId] = newGroup; id2key[groupNum] = groupId; return newGroup; diff --git a/src/grouplist.h b/src/grouplist.h index 8ace8d1e3..420848456 100644 --- a/src/grouplist.h +++ b/src/grouplist.h @@ -21,6 +21,7 @@ #include "src/core/groupid.h" +class Core; template class QHash; template @@ -31,7 +32,7 @@ class QString; class GroupList { public: - static Group* addGroup(int groupId, const GroupId& persistentGroupId, const QString& name, bool isAvGroupchat, const QString& selfName); + static Group* addGroup(Core& core, int groupId, const GroupId& persistentGroupId, const QString& name, bool isAvGroupchat, const QString& selfName); static Group* findGroup(const GroupId& groupId); static const GroupId& id2Key(uint32_t groupNum); static void removeGroup(const GroupId& groupId, bool fake = false); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index ae3c3ad23..eaa6bc4e1 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -2078,7 +2078,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) const auto groupName = tr("Groupchat #%1").arg(groupnumber); const bool enabled = core->getGroupAvEnabled(groupnumber); Group* newgroup = - GroupList::addGroup(groupnumber, groupId, groupName, enabled, core->getUsername()); + GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername()); auto dialogManager = ContentDialogManager::getInstance(); auto rawChatroom = new GroupChatroom(newgroup, dialogManager); std::shared_ptr chatroom(rawChatroom);