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
This commit is contained in:
Anthony Bilinski 2022-02-14 02:16:41 -08:00
parent 0adf4a00f3
commit e5df648e1a
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 20 additions and 8 deletions

View File

@ -19,6 +19,8 @@
#pragma once #pragma once
#include "util/interface.h"
#include <QStringList> #include <QStringList>
class IGroupSettings class IGroupSettings
@ -33,4 +35,6 @@ public:
virtual QStringList getBlackList() const = 0; virtual QStringList getBlackList() const = 0;
virtual void setBlackList(const QStringList& blist) = 0; virtual void setBlackList(const QStringList& blist) = 0;
DECLARE_SIGNAL(blackListChanged, QStringList const& blist);
}; };

View File

@ -231,7 +231,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 const& blist);
public: public:
bool applyCommandLineOptions(const QCommandLineParser& parser); bool applyCommandLineOptions(const QCommandLineParser& parser);
@ -461,9 +460,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);

View File

@ -36,7 +36,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,7 +82,7 @@ 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, Settings& _settings) GroupChatForm::GroupChatForm(Core& _core, Group* chatGroup, IChatLog& chatLog, IMessageDispatcher& messageDispatcher, IGroupSettings& _settings)
: GenericChatForm(_core, chatGroup, chatLog, messageDispatcher) : GenericChatForm(_core, chatGroup, chatLog, messageDispatcher)
, core{_core} , core{_core}
, group(chatGroup) , group(chatGroup)
@ -131,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, &Settings::blackListChanged, this, &GroupChatForm::updateUserNames); settings.connectTo_blackListChanged(this, [this](QStringList const&) { this->updateUserNames(); });
updateUserNames(); updateUserNames();
setAcceptDrops(true); setAcceptDrops(true);

View File

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

View File

@ -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 "util/interface.h"
#include "test/mock/mockcoreidhandler.h" #include "test/mock/mockcoreidhandler.h"
#include "test/mock/mockgroupquery.h" #include "test/mock/mockgroupquery.h"
@ -54,13 +56,16 @@ void MockGroupMessageSender::sendGroupMessage(int groupId, const QString& messag
numSentMessages++; numSentMessages++;
} }
class MockGroupSettings : public IGroupSettings class MockGroupSettings : public QObject, public IGroupSettings
{ {
Q_OBJECT
public: public:
QStringList getBlackList() const override; QStringList getBlackList() const override;
void setBlackList(const QStringList& blist) override; void setBlackList(const QStringList& blist) override;
SIGNAL_IMPL(MockGroupSettings, blackListChanged, QStringList const& blist)
private: private:
QStringList blacklist; QStringList blacklist;
}; };