mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Add using IFriendSettings in AboutFriend model
This commit is contained in:
parent
e4537c04bc
commit
b53569c362
@ -3,23 +3,23 @@
|
||||
#include "src/model/friend.h"
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/ifriendsettings.h"
|
||||
|
||||
AboutFriend::AboutFriend(const Friend* f)
|
||||
AboutFriend::AboutFriend(const Friend* f, IFriendSettings* const s)
|
||||
: f{f}
|
||||
, settings{s}
|
||||
{
|
||||
Settings* s = &Settings::getInstance();
|
||||
connect(s, &Settings::contactNoteChanged, [=](const ToxPk& pk, const QString& note) {
|
||||
s->connectTo_contactNoteChanged([=](const ToxPk& pk, const QString& note) {
|
||||
emit noteChanged(note);
|
||||
});
|
||||
connect(s, &Settings::autoAcceptCallChanged,
|
||||
[=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) {
|
||||
s->connectTo_autoAcceptCallChanged(
|
||||
[=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) {
|
||||
emit autoAcceptCallChanged(flag);
|
||||
});
|
||||
connect(s, &Settings::autoAcceptDirChanged, [=](const ToxPk& pk, const QString& dir) {
|
||||
s->connectTo_autoAcceptDirChanged([=](const ToxPk& pk, const QString& dir) {
|
||||
emit autoAcceptDirChanged(dir);
|
||||
});
|
||||
connect(s, &Settings::autoGroupInviteChanged, [=](const ToxPk& pk, bool enable) {
|
||||
s->connectTo_autoGroupInviteChanged([=](const ToxPk& pk, bool enable) {
|
||||
emit autoGroupInviteChanged(enable);
|
||||
});
|
||||
}
|
||||
@ -50,53 +50,53 @@ QPixmap AboutFriend::getAvatar() const
|
||||
QString AboutFriend::getNote() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getContactNote(pk);
|
||||
return settings->getContactNote(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setNote(const QString& note)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setContactNote(pk, note);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings->setContactNote(pk, note);
|
||||
settings->saveFriendSettings(pk);
|
||||
}
|
||||
|
||||
QString AboutFriend::getAutoAcceptDir() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getAutoAcceptDir(pk);
|
||||
return settings->getAutoAcceptDir(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoAcceptDir(const QString& path)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoAcceptDir(pk, path);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings->setAutoAcceptDir(pk, path);
|
||||
settings->saveFriendSettings(pk);
|
||||
}
|
||||
|
||||
IFriendSettings::AutoAcceptCallFlags AboutFriend::getAutoAcceptCall() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getAutoAcceptCall(pk);
|
||||
return settings->getAutoAcceptCall(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoAcceptCall(pk, flag);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings->setAutoAcceptCall(pk, flag);
|
||||
settings->saveFriendSettings(pk);
|
||||
}
|
||||
|
||||
bool AboutFriend::getAutoGroupInvite() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getAutoGroupInvite(pk);
|
||||
return settings->getAutoGroupInvite(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoGroupInvite(bool enabled)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoGroupInvite(pk, enabled);
|
||||
Settings::getInstance().savePersonal();
|
||||
settings->setAutoGroupInvite(pk, enabled);
|
||||
settings->saveFriendSettings(pk);
|
||||
}
|
||||
|
||||
bool AboutFriend::clearHistory()
|
||||
|
@ -3,16 +3,19 @@
|
||||
|
||||
#include "iaboutfriend.h"
|
||||
|
||||
#include "src/persistence/ifriendsettings.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Friend;
|
||||
class IFriendSettings;
|
||||
|
||||
class AboutFriend : public IAboutFriend
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutFriend(const Friend* f);
|
||||
AboutFriend(const Friend* f, IFriendSettings* const settings);
|
||||
|
||||
QString getName() const override;
|
||||
QString getStatusMessage() const override;
|
||||
@ -47,6 +50,7 @@ public:
|
||||
|
||||
private:
|
||||
const Friend* const f;
|
||||
IFriendSettings* const settings;
|
||||
};
|
||||
|
||||
#endif // ABOUT_FRIEND_H
|
||||
|
@ -15,7 +15,7 @@ class AboutFriendForm : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutFriendForm(QPointer<IAboutFriend> about, QWidget* parent = 0);
|
||||
AboutFriendForm(QPointer<IAboutFriend> about, QWidget* parent = 0);
|
||||
~AboutFriendForm();
|
||||
|
||||
private:
|
||||
|
@ -230,7 +230,7 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||
}
|
||||
} else if (selectedItem == aboutWindow) {
|
||||
const Friend* const f = FriendList::findFriend(friendId);
|
||||
const QPointer<IAboutFriend> about = new AboutFriend(f);
|
||||
const QPointer<IAboutFriend> about = new AboutFriend(f, &Settings::getInstance());
|
||||
AboutFriendForm* aboutUser = new AboutFriendForm(about, Widget::getInstance());
|
||||
aboutUser->show();
|
||||
} else if (selectedItem == newGroupAction) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user