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:
parent
939bf6a2c1
commit
18643da271
|
@ -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
|
|||
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()
|
|||
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)
|
|||
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)
|
|||
blackList << peerPk.toString();
|
||||
}
|
||||
|
||||
s.setBlackList(blackList);
|
||||
settings.setBlackList(blackList);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
|||
QLabel* nusersLabel;
|
||||
TabCompleter* tabber;
|
||||
bool inCall;
|
||||
Settings& settings;
|
||||
};
|
||||
|
|
|
@ -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…
Reference in New Issue
Block a user