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

refactor(chatform): Pass Settings to GroupChatForm instead of calling getInstance()

One small step away from propagating singleton use
This commit is contained in:
Anthony Bilinski 2022-02-14 01:45:15 -08:00
parent 939bf6a2c1
commit 18643da271
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 10 additions and 9 deletions

View File

@ -82,11 +82,12 @@ QString editName(const QString& name)
* @brief Timeout = peer stopped sending audio. * @brief Timeout = peer stopped sending audio.
*/ */
GroupChatForm::GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher) GroupChatForm::GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, Settings& _settings)
: GenericChatForm(_core, chatGroup, chatLog, messageDispatcher) : GenericChatForm(_core, chatGroup, chatLog, messageDispatcher)
, core{_core} , core{_core}
, group(chatGroup) , group(chatGroup)
, inCall(false) , inCall(false)
, settings(_settings)
{ {
nusersLabel = new QLabel(); nusersLabel = new QLabel();
@ -130,7 +131,7 @@ GroupChatForm::GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, I
connect(group, &Group::userLeft, this, &GroupChatForm::onUserLeft); connect(group, &Group::userLeft, this, &GroupChatForm::onUserLeft);
connect(group, &Group::peerNameChanged, this, &GroupChatForm::onPeerNameChanged); connect(group, &Group::peerNameChanged, this, &GroupChatForm::onPeerNameChanged);
connect(group, &Group::numPeersChanged, this, &GroupChatForm::updateUserCount); connect(group, &Group::numPeersChanged, this, &GroupChatForm::updateUserCount);
connect(&Settings::getInstance(), &Settings::blackListChanged, this, &GroupChatForm::updateUserNames); connect(&settings, &Settings::blackListChanged, this, &GroupChatForm::updateUserNames);
updateUserNames(); updateUserNames();
setAcceptDrops(true); setAcceptDrops(true);
@ -198,12 +199,11 @@ void GroupChatForm::updateUserNames()
label->setTextFormat(Qt::PlainText); label->setTextFormat(Qt::PlainText);
label->setContextMenuPolicy(Qt::CustomContextMenu); label->setContextMenuPolicy(Qt::CustomContextMenu);
const Settings& s = Settings::getInstance();
connect(label, &QLabel::customContextMenuRequested, this, &GroupChatForm::onLabelContextMenuRequested); connect(label, &QLabel::customContextMenuRequested, this, &GroupChatForm::onLabelContextMenuRequested);
if (peerPk == selfPk) { if (peerPk == selfPk) {
label->setProperty("peerType", LABEL_PEER_TYPE_OUR); label->setProperty("peerType", LABEL_PEER_TYPE_OUR);
} else if (s.getBlackList().contains(peerPk.toString())) { } else if (settings.getBlackList().contains(peerPk.toString())) {
label->setProperty("peerType", LABEL_PEER_TYPE_MUTED); label->setProperty("peerType", LABEL_PEER_TYPE_MUTED);
} }
@ -389,8 +389,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
const QPoint pos = label->mapToGlobal(localPos); const QPoint pos = label->mapToGlobal(localPos);
const QString muteString = tr("mute"); const QString muteString = tr("mute");
const QString unmuteString = tr("unmute"); const QString unmuteString = tr("unmute");
Settings& s = Settings::getInstance(); QStringList blackList = settings.getBlackList();
QStringList blackList = s.getBlackList();
QMenu* const contextMenu = new QMenu(this); QMenu* const contextMenu = new QMenu(this);
const ToxPk selfPk = core.getSelfPublicKey(); const ToxPk selfPk = core.getSelfPublicKey();
ToxPk peerPk; ToxPk peerPk;
@ -431,7 +430,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
blackList << peerPk.toString(); blackList << peerPk.toString();
} }
s.setBlackList(blackList); settings.setBlackList(blackList);
} }
} }

View File

@ -33,12 +33,13 @@ class QTimer;
class GroupId; class GroupId;
class IMessageDispatcher; class IMessageDispatcher;
struct Message; struct Message;
class Settings;
class GroupChatForm : public GenericChatForm class GroupChatForm : public GenericChatForm
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher); explicit GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, Settings& _settings);
~GroupChatForm(); ~GroupChatForm();
void peerAudioPlaying(ToxPk peerPk); void peerAudioPlaying(ToxPk peerPk);
@ -78,4 +79,5 @@ private:
QLabel* nusersLabel; QLabel* nusersLabel;
TabCompleter* tabber; TabCompleter* tabber;
bool inCall; bool inCall;
Settings& settings;
}; };

View File

@ -2161,7 +2161,7 @@ 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(*core, newgroup, *groupChatLog, *messageDispatcher); auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher, settings);
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;