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:
parent
f5fabc2fe2
commit
d0d288a9b6
|
@ -20,6 +20,8 @@
|
||||||
#ifndef IGROUP_SETTINGS_H
|
#ifndef IGROUP_SETTINGS_H
|
||||||
#define IGROUP_SETTINGS_H
|
#define IGROUP_SETTINGS_H
|
||||||
|
|
||||||
|
#include "src/model/interface.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
|
||||||
class IGroupSettings
|
class IGroupSettings
|
||||||
|
@ -30,6 +32,8 @@ public:
|
||||||
virtual void setBlackList(const QStringList& blist) = 0;
|
virtual void setBlackList(const QStringList& blist) = 0;
|
||||||
virtual bool getGroupAlwaysNotify() const = 0;
|
virtual bool getGroupAlwaysNotify() const = 0;
|
||||||
virtual void setGroupAlwaysNotify(bool newValue) = 0;
|
virtual void setGroupAlwaysNotify(bool newValue) = 0;
|
||||||
|
|
||||||
|
DECLARE_SIGNAL(blackListChanged, QStringList const& blist);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*IGROUP_SETTINGS_H*/
|
#endif /*IGROUP_SETTINGS_H*/
|
||||||
|
|
|
@ -232,7 +232,6 @@ signals:
|
||||||
// Privacy
|
// Privacy
|
||||||
void typingNotificationChanged(bool enabled);
|
void typingNotificationChanged(bool enabled);
|
||||||
void dbSyncTypeChanged(Db::syncType type);
|
void dbSyncTypeChanged(Db::syncType type);
|
||||||
void blackListChanged(QStringList& blist);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool applyCommandLineOptions(const QCommandLineParser& parser);
|
bool applyCommandLineOptions(const QCommandLineParser& parser);
|
||||||
|
@ -462,9 +461,12 @@ public:
|
||||||
// Privacy
|
// Privacy
|
||||||
bool getTypingNotification() const;
|
bool getTypingNotification() const;
|
||||||
void setTypingNotification(bool enabled);
|
void setTypingNotification(bool enabled);
|
||||||
|
|
||||||
QStringList getBlackList() const override;
|
QStringList getBlackList() const override;
|
||||||
void setBlackList(const QStringList& blist) override;
|
void setBlackList(const QStringList& blist) override;
|
||||||
|
|
||||||
|
SIGNAL_IMPL(Settings, blackListChanged, QStringList const& blist)
|
||||||
|
|
||||||
// State
|
// State
|
||||||
QByteArray getWindowGeometry() const;
|
QByteArray getWindowGeometry() const;
|
||||||
void setWindowGeometry(const QByteArray& value);
|
void setWindowGeometry(const QByteArray& value);
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
#include "src/widget/tool/croppinglabel.h"
|
#include "src/widget/tool/croppinglabel.h"
|
||||||
#include "src/widget/translator.h"
|
#include "src/widget/translator.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/igroupsettings.h"
|
||||||
|
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
@ -82,10 +82,11 @@ QString editName(const QString& name)
|
||||||
* @brief Timeout = peer stopped sending audio.
|
* @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)
|
: GenericChatForm(chatGroup, chatLog, messageDispatcher)
|
||||||
, group(chatGroup)
|
, group(chatGroup)
|
||||||
, inCall(false)
|
, inCall(false)
|
||||||
|
, settings(_settings)
|
||||||
{
|
{
|
||||||
nusersLabel = new QLabel();
|
nusersLabel = new QLabel();
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispat
|
||||||
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);
|
settings.connectTo_blackListChanged(this, [this](QStringList const&) { this->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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,8 +415,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::getInstance()->getSelfPublicKey();
|
const ToxPk selfPk = Core::getInstance()->getSelfPublicKey();
|
||||||
ToxPk peerPk;
|
ToxPk peerPk;
|
||||||
|
@ -457,7 +456,7 @@ void GroupChatForm::onLabelContextMenuRequested(const QPoint& localPos)
|
||||||
blackList << peerPk.toString();
|
blackList << peerPk.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
s.setBlackList(blackList);
|
settings.setBlackList(blackList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,13 +33,14 @@ class FlowLayout;
|
||||||
class QTimer;
|
class QTimer;
|
||||||
class GroupId;
|
class GroupId;
|
||||||
class IMessageDispatcher;
|
class IMessageDispatcher;
|
||||||
class Message;
|
struct Message;
|
||||||
|
class IGroupSettings;
|
||||||
|
|
||||||
class GroupChatForm : public GenericChatForm
|
class GroupChatForm : public GenericChatForm
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher);
|
GroupChatForm(Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings);
|
||||||
~GroupChatForm();
|
~GroupChatForm();
|
||||||
|
|
||||||
void peerAudioPlaying(ToxPk peerPk);
|
void peerAudioPlaying(ToxPk peerPk);
|
||||||
|
@ -79,6 +80,7 @@ private:
|
||||||
QLabel* nusersLabel;
|
QLabel* nusersLabel;
|
||||||
TabCompleter* tabber;
|
TabCompleter* tabber;
|
||||||
bool inCall;
|
bool inCall;
|
||||||
|
IGroupSettings& settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GROUPCHATFORM_H
|
#endif // GROUPCHATFORM_H
|
||||||
|
|
|
@ -2115,7 +2115,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(newgroup, *groupChatLog, *messageDispatcher);
|
auto form = new GroupChatForm(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;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "src/model/groupmessagedispatcher.h"
|
#include "src/model/groupmessagedispatcher.h"
|
||||||
#include "src/model/message.h"
|
#include "src/model/message.h"
|
||||||
#include "src/persistence/settings.h"
|
#include "src/persistence/settings.h"
|
||||||
|
#include "src/persistence/igroupsettings.h"
|
||||||
|
#include "src/model/interface.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
|
@ -126,8 +128,10 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MockGroupSettings : public IGroupSettings
|
class MockGroupSettings : public QObject, public IGroupSettings
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QStringList getBlackList() const override
|
QStringList getBlackList() const override
|
||||||
{
|
{
|
||||||
|
@ -145,6 +149,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGroupAlwaysNotify(bool newValue) override {}
|
void setGroupAlwaysNotify(bool newValue) override {}
|
||||||
|
SIGNAL_IMPL(MockGroupSettings, blackListChanged, QStringList const& blist)
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QStringList blacklist;
|
QStringList blacklist;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user