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

refactor(settings): Use IGroupSettings in GroupChatForm

Move interface signals from Settings to be declared by the interface itself

Backported from e5df648e1a
This commit is contained in:
Anthony Bilinski 2022-02-14 02:16:41 -08:00
parent f5fabc2fe2
commit d0d288a9b6
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
6 changed files with 25 additions and 13 deletions

View File

@ -20,6 +20,8 @@
#ifndef IGROUP_SETTINGS_H
#define IGROUP_SETTINGS_H
#include "src/model/interface.h"
#include <QStringList>
class IGroupSettings
@ -30,6 +32,8 @@ public:
virtual void setBlackList(const QStringList& blist) = 0;
virtual bool getGroupAlwaysNotify() const = 0;
virtual void setGroupAlwaysNotify(bool newValue) = 0;
DECLARE_SIGNAL(blackListChanged, QStringList const& blist);
};
#endif /*IGROUP_SETTINGS_H*/

View File

@ -232,7 +232,6 @@ signals:
// Privacy
void typingNotificationChanged(bool enabled);
void dbSyncTypeChanged(Db::syncType type);
void blackListChanged(QStringList& blist);
public:
bool applyCommandLineOptions(const QCommandLineParser& parser);
@ -462,9 +461,12 @@ public:
// Privacy
bool getTypingNotification() const;
void setTypingNotification(bool enabled);
QStringList getBlackList() const override;
void setBlackList(const QStringList& blist) override;
SIGNAL_IMPL(Settings, blackListChanged, QStringList const& blist)
// State
QByteArray getWindowGeometry() const;
void setWindowGeometry(const QByteArray& value);

View File

@ -37,7 +37,7 @@
#include "src/widget/style.h"
#include "src/widget/tool/croppinglabel.h"
#include "src/widget/translator.h"
#include "src/persistence/settings.h"
#include "src/persistence/igroupsettings.h"
#include <QDragEnterEvent>
#include <QMimeData>
@ -82,10 +82,11 @@ QString editName(const QString& name)
* @brief Timeout = peer stopped sending audio.
*/
GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher)
GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings)
: GenericChatForm(chatGroup, chatLog, messageDispatcher)
, group(chatGroup)
, inCall(false)
, settings(_settings)
{
nusersLabel = new QLabel();
@ -129,7 +130,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispat
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);
settings.connectTo_blackListChanged(this, [this](QStringList const&) { this->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);
}
@ -415,8 +415,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::getInstance()->getSelfPublicKey();
ToxPk peerPk;
@ -457,7 +456,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
blackList << peerPk.toString();
}
s.setBlackList(blackList);
settings.setBlackList(blackList);
}
}

View File

@ -33,13 +33,14 @@ class FlowLayout;
class QTimer;
class GroupId;
class IMessageDispatcher;
class Message;
struct Message;
class IGroupSettings;
class GroupChatForm : public GenericChatForm
{
Q_OBJECT
public:
explicit GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher);
GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings);
~GroupChatForm();
void peerAudioPlaying(ToxPk peerPk);
@ -79,6 +80,7 @@ private:
QLabel* nusersLabel;
TabCompleter* tabber;
bool inCall;
IGroupSettings& settings;
};
#endif // GROUPCHATFORM_H

View File

@ -2115,7 +2115,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback);
groupAlertConnections.insert(groupId, notifyReceivedConnection);
auto form = new GroupChatForm(newgroup, *groupChatLog, *messageDispatcher);
auto form = new GroupChatForm(newgroup, *groupChatLog, *messageDispatcher, settings);
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
form->setColorizedNames(settings.getEnableGroupChatsColor());
groupMessageDispatchers[groupId] = messageDispatcher;

View File

@ -22,6 +22,8 @@
#include "src/model/groupmessagedispatcher.h"
#include "src/model/message.h"
#include "src/persistence/settings.h"
#include "src/persistence/igroupsettings.h"
#include "src/model/interface.h"
#include <QObject>
#include <QtTest/QtTest>
@ -126,8 +128,10 @@ public:
}
};
class MockGroupSettings : public IGroupSettings
class MockGroupSettings : public QObject, public IGroupSettings
{
Q_OBJECT
public:
QStringList getBlackList() const override
{
@ -145,6 +149,7 @@ public:
}
void setGroupAlwaysNotify(bool newValue) override {}
SIGNAL_IMPL(MockGroupSettings, blackListChanged, QStringList const& blist)
private:
QStringList blacklist;