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

refactor: remove Core::getInstance from grouplist

This commit is contained in:
sudden6 2020-05-09 23:33:59 +02:00
parent 365a452fb8
commit 82e0852f3c
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
3 changed files with 7 additions and 8 deletions

View File

@ -25,17 +25,15 @@
QHash<const GroupId, Group*> GroupList::groupList; QHash<const GroupId, Group*> GroupList::groupList;
QHash<uint32_t, GroupId> GroupList::id2key; QHash<uint32_t, GroupId> 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) const QString& selfName)
{ {
auto checker = groupList.find(groupId); auto checker = groupList.find(groupId);
if (checker != groupList.end()) if (checker != groupList.end()) {
qWarning() << "addGroup: groupId already taken"; qWarning() << "addGroup: groupId already taken";
}
// TODO: Core instance is bad but grouplist is also an instance so we can Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, core, core);
// deal with this later
auto core = Core::getInstance();
Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, *core, *core);
groupList[groupId] = newGroup; groupList[groupId] = newGroup;
id2key[groupNum] = groupId; id2key[groupNum] = groupId;
return newGroup; return newGroup;

View File

@ -21,6 +21,7 @@
#include "src/core/groupid.h" #include "src/core/groupid.h"
class Core;
template <class A, class B> template <class A, class B>
class QHash; class QHash;
template <class T> template <class T>
@ -31,7 +32,7 @@ class QString;
class GroupList class GroupList
{ {
public: 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 Group* findGroup(const GroupId& groupId);
static const GroupId& id2Key(uint32_t groupNum); static const GroupId& id2Key(uint32_t groupNum);
static void removeGroup(const GroupId& groupId, bool fake = false); static void removeGroup(const GroupId& groupId, bool fake = false);

View File

@ -2078,7 +2078,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
const auto groupName = tr("Groupchat #%1").arg(groupnumber); const auto groupName = tr("Groupchat #%1").arg(groupnumber);
const bool enabled = core->getGroupAvEnabled(groupnumber); const bool enabled = core->getGroupAvEnabled(groupnumber);
Group* newgroup = Group* newgroup =
GroupList::addGroup(groupnumber, groupId, groupName, enabled, core->getUsername()); GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername());
auto dialogManager = ContentDialogManager::getInstance(); auto dialogManager = ContentDialogManager::getInstance();
auto rawChatroom = new GroupChatroom(newgroup, dialogManager); auto rawChatroom = new GroupChatroom(newgroup, dialogManager);
std::shared_ptr<GroupChatroom> chatroom(rawChatroom); std::shared_ptr<GroupChatroom> chatroom(rawChatroom);