Browse Source

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

One small step away from propagating singleton use
reviewable/pr6459/r1
Anthony Bilinski 3 years ago
parent
commit
18643da271
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 13
      src/widget/form/groupchatform.cpp
  2. 4
      src/widget/form/groupchatform.h
  3. 2
      src/widget/widget.cpp

13
src/widget/form/groupchatform.cpp

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

4
src/widget/form/groupchatform.h

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

2
src/widget/widget.cpp

@ -2161,7 +2161,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId) @@ -2161,7 +2161,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback);
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);
form->setColorizedNames(settings.getEnableGroupChatsColor());
groupMessageDispatchers[groupId] = messageDispatcher;

Loading…
Cancel
Save