mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Add IFriendSettings
This commit is contained in:
parent
63bd3831ce
commit
e4537c04bc
|
@ -286,6 +286,7 @@ set(${PROJECT_NAME}_SOURCES
|
|||
src/persistence/db/rawdatabase.h
|
||||
src/persistence/history.cpp
|
||||
src/persistence/history.h
|
||||
src/persistence/ifriendsettings.h
|
||||
src/persistence/offlinemsgengine.cpp
|
||||
src/persistence/offlinemsgengine.h
|
||||
src/persistence/profile.cpp
|
||||
|
|
|
@ -12,10 +12,9 @@ AboutFriend::AboutFriend(const Friend* f)
|
|||
connect(s, &Settings::contactNoteChanged, [=](const ToxPk& pk, const QString& note) {
|
||||
emit noteChanged(note);
|
||||
});
|
||||
connect(s, &Settings::autoAcceptCallChanged, [=](const ToxPk& pk, Settings::AutoAcceptCallFlags flag) {
|
||||
const int value = static_cast<int>(Settings::getInstance().getAutoAcceptCall(pk));
|
||||
const AutoAcceptCallFlags sFlag = static_cast<IAboutFriend::AutoAcceptCall>(value);
|
||||
emit autoAcceptCallChanged(sFlag);
|
||||
connect(s, &Settings::autoAcceptCallChanged,
|
||||
[=](const ToxPk& pk, IFriendSettings::AutoAcceptCallFlags flag) {
|
||||
emit autoAcceptCallChanged(flag);
|
||||
});
|
||||
connect(s, &Settings::autoAcceptDirChanged, [=](const ToxPk& pk, const QString& dir) {
|
||||
emit autoAcceptDirChanged(dir);
|
||||
|
@ -74,19 +73,16 @@ void AboutFriend::setAutoAcceptDir(const QString& path)
|
|||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
|
||||
IAboutFriend::AutoAcceptCallFlags AboutFriend::getAutoAcceptCall() const
|
||||
IFriendSettings::AutoAcceptCallFlags AboutFriend::getAutoAcceptCall() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
const int value = static_cast<int>(Settings::getInstance().getAutoAcceptCall(pk));
|
||||
return static_cast<IAboutFriend::AutoAcceptCallFlags>(value);
|
||||
return Settings::getInstance().getAutoAcceptCall(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoAcceptCall(AutoAcceptCallFlags flag)
|
||||
void AboutFriend::setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
const int value = static_cast<int>(flag);
|
||||
const Settings::AutoAcceptCallFlags sFlag(value);
|
||||
Settings::getInstance().setAutoAcceptCall(pk, sFlag);
|
||||
Settings::getInstance().setAutoAcceptCall(pk, flag);
|
||||
Settings::getInstance().savePersonal();
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ public:
|
|||
QString getAutoAcceptDir() const override;
|
||||
void setAutoAcceptDir(const QString& path) override;
|
||||
|
||||
AutoAcceptCallFlags getAutoAcceptCall() const override;
|
||||
void setAutoAcceptCall(AutoAcceptCallFlags flag) override;
|
||||
IFriendSettings::AutoAcceptCallFlags getAutoAcceptCall() const override;
|
||||
void setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag) override;
|
||||
|
||||
bool getAutoGroupInvite() const override;
|
||||
void setAutoGroupInvite(bool enabled) override;
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
SIGNAL_IMPL(AboutFriend, noteChanged, const QString&)
|
||||
|
||||
SIGNAL_IMPL(AboutFriend, autoAcceptDirChanged, const QString&)
|
||||
SIGNAL_IMPL(AboutFriend, autoAcceptCallChanged, AutoAcceptCallFlags)
|
||||
SIGNAL_IMPL(AboutFriend, autoAcceptCallChanged, IFriendSettings::AutoAcceptCallFlags)
|
||||
SIGNAL_IMPL(AboutFriend, autoGroupInviteChanged, bool)
|
||||
|
||||
private:
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define I_ABOUT_FRIEND_H
|
||||
|
||||
#include "src/model/interface.h"
|
||||
#include "src/persistence/ifriendsettings.h"
|
||||
#include <QObject>
|
||||
|
||||
class IAboutFriend : public QObject
|
||||
|
@ -9,15 +10,6 @@ class IAboutFriend : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class AutoAcceptCall
|
||||
{
|
||||
None = 0x00,
|
||||
Audio = 0x01,
|
||||
Video = 0x02,
|
||||
AV = Audio | Video
|
||||
};
|
||||
using AutoAcceptCallFlags = QFlags<AutoAcceptCall>;
|
||||
|
||||
virtual QString getName() const = 0;
|
||||
virtual QString getStatusMessage() const = 0;
|
||||
virtual QString getPublicKey() const = 0;
|
||||
|
@ -30,8 +22,8 @@ public:
|
|||
virtual QString getAutoAcceptDir() const = 0;
|
||||
virtual void setAutoAcceptDir(const QString& path) = 0;
|
||||
|
||||
virtual AutoAcceptCallFlags getAutoAcceptCall() const = 0;
|
||||
virtual void setAutoAcceptCall(AutoAcceptCallFlags flag) = 0;
|
||||
virtual IFriendSettings::AutoAcceptCallFlags getAutoAcceptCall() const = 0;
|
||||
virtual void setAutoAcceptCall(IFriendSettings::AutoAcceptCallFlags flag) = 0;
|
||||
|
||||
virtual bool getAutoGroupInvite() const = 0;
|
||||
virtual void setAutoGroupInvite(bool enabled) = 0;
|
||||
|
|
55
src/persistence/ifriendsettings.h
Normal file
55
src/persistence/ifriendsettings.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
#ifndef I_FRIEND_SETTINGS_H
|
||||
#define I_FRIEND_SETTINGS_H
|
||||
|
||||
#include "src/model/interface.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QFlag>
|
||||
|
||||
class ToxPk;
|
||||
|
||||
class IFriendSettings
|
||||
{
|
||||
public:
|
||||
enum class AutoAcceptCall
|
||||
{
|
||||
None = 0x00,
|
||||
Audio = 0x01,
|
||||
Video = 0x02,
|
||||
AV = Audio | Video
|
||||
};
|
||||
Q_DECLARE_FLAGS(AutoAcceptCallFlags, AutoAcceptCall)
|
||||
|
||||
virtual QString getContactNote(const ToxPk& pk) const = 0;
|
||||
virtual void setContactNote(const ToxPk& pk, const QString& note) = 0;
|
||||
|
||||
virtual QString getAutoAcceptDir(const ToxPk& pk) const = 0;
|
||||
virtual void setAutoAcceptDir(const ToxPk& pk, const QString& dir) = 0;
|
||||
|
||||
virtual AutoAcceptCallFlags getAutoAcceptCall(const ToxPk& pk) const = 0;
|
||||
virtual void setAutoAcceptCall(const ToxPk& pk, AutoAcceptCallFlags accept) = 0;
|
||||
|
||||
virtual bool getAutoGroupInvite(const ToxPk& pk) const = 0;
|
||||
virtual void setAutoGroupInvite(const ToxPk& pk, bool accept) = 0;
|
||||
|
||||
virtual QString getFriendAlias(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendAlias(const ToxPk& pk, const QString& alias) = 0;
|
||||
|
||||
virtual int getFriendCircleID(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendCircleID(const ToxPk& pk, int circleID) = 0;
|
||||
|
||||
virtual QDate getFriendActivity(const ToxPk& pk) const = 0;
|
||||
virtual void setFriendActivity(const ToxPk& pk, const QDate& date) = 0;
|
||||
|
||||
virtual void saveFriendSettings(const ToxPk& pk) = 0;
|
||||
virtual void removeFriendSettings(const ToxPk& pk) = 0;
|
||||
|
||||
signals:
|
||||
DECLARE_SIGNAL(autoAcceptCallChanged, const ToxPk& pk, AutoAcceptCallFlags accept);
|
||||
DECLARE_SIGNAL(autoGroupInviteChanged, const ToxPk& pk, bool accept);
|
||||
DECLARE_SIGNAL(autoAcceptDirChanged, const ToxPk& pk, const QString& dir);
|
||||
DECLARE_SIGNAL(contactNoteChanged, const ToxPk& pk, const QString& note);
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(IFriendSettings::AutoAcceptCallFlags)
|
||||
#endif // I_FRIEND_SETTINGS_H
|
|
@ -2107,6 +2107,12 @@ void Settings::setFriendActivity(const ToxPk& id, const QDate& activity)
|
|||
}
|
||||
}
|
||||
|
||||
void Settings::saveFriendSettings(const ToxPk& id)
|
||||
{
|
||||
Q_UNUSED(id);
|
||||
savePersonal();
|
||||
}
|
||||
|
||||
void Settings::removeFriendSettings(const ToxPk& id)
|
||||
{
|
||||
QMutexLocker locker{&bigLock};
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "src/core/icoresettings.h"
|
||||
#include "src/core/toxencrypt.h"
|
||||
#include "src/core/toxfile.h"
|
||||
#include "src/persistence/ifriendsettings.h"
|
||||
#include "src/video/ivideosettings.h"
|
||||
|
||||
#include <QDate>
|
||||
|
@ -36,14 +37,14 @@
|
|||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
|
||||
class ToxPk;
|
||||
class Profile;
|
||||
|
||||
namespace Db {
|
||||
enum class syncType;
|
||||
}
|
||||
|
||||
class Settings : public QObject, public ICoreSettings, public IAudioSettings, public IVideoSettings
|
||||
class Settings : public QObject, public ICoreSettings, public IFriendSettings,
|
||||
public IAudioSettings, public IVideoSettings
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -126,14 +127,6 @@ public:
|
|||
WITH_CHARS = 1,
|
||||
WITHOUT_CHARS = 2
|
||||
};
|
||||
enum class AutoAcceptCall
|
||||
{
|
||||
None = 0x00,
|
||||
Audio = 0x01,
|
||||
Video = 0x02,
|
||||
AV = Audio | Video
|
||||
};
|
||||
Q_DECLARE_FLAGS(AutoAcceptCallFlags, AutoAcceptCall)
|
||||
|
||||
public:
|
||||
static Settings& getInstance();
|
||||
|
@ -191,12 +184,6 @@ signals:
|
|||
void checkUpdatesChanged(bool enabled);
|
||||
void widgetDataChanged(const QString& key);
|
||||
|
||||
// Friend
|
||||
void autoAcceptCallChanged(const ToxPk& id, AutoAcceptCallFlags accept);
|
||||
void autoGroupInviteChanged(const ToxPk& id, bool accept);
|
||||
void autoAcceptDirChanged(const ToxPk& id, const QString& dir);
|
||||
void contactNoteChanged(const ToxPk& id, const QString& note);
|
||||
|
||||
// GUI
|
||||
void autoLoginChanged(bool enabled);
|
||||
void separateWindowChanged(bool enabled);
|
||||
|
@ -421,20 +408,20 @@ public:
|
|||
int getEmojiFontPointSize() const;
|
||||
void setEmojiFontPointSize(int value);
|
||||
|
||||
QString getContactNote(const ToxPk& id) const;
|
||||
void setContactNote(const ToxPk& id, const QString& note);
|
||||
QString getContactNote(const ToxPk& id) const override;
|
||||
void setContactNote(const ToxPk& id, const QString& note) override;
|
||||
|
||||
QString getAutoAcceptDir(const ToxPk& id) const;
|
||||
void setAutoAcceptDir(const ToxPk& id, const QString& dir);
|
||||
QString getAutoAcceptDir(const ToxPk& id) const override;
|
||||
void setAutoAcceptDir(const ToxPk& id, const QString& dir) override;
|
||||
|
||||
AutoAcceptCallFlags getAutoAcceptCall(const ToxPk& id) const;
|
||||
void setAutoAcceptCall(const ToxPk& id, AutoAcceptCallFlags accept);
|
||||
AutoAcceptCallFlags getAutoAcceptCall(const ToxPk& id) const override;
|
||||
void setAutoAcceptCall(const ToxPk& id, AutoAcceptCallFlags accept) override;
|
||||
|
||||
QString getGlobalAutoAcceptDir() const;
|
||||
void setGlobalAutoAcceptDir(const QString& dir);
|
||||
|
||||
bool getAutoGroupInvite(const ToxPk& id) const;
|
||||
void setAutoGroupInvite(const ToxPk& id, bool accept);
|
||||
bool getAutoGroupInvite(const ToxPk& id) const override;
|
||||
void setAutoGroupInvite(const ToxPk& id, bool accept) override;
|
||||
|
||||
// ChatView
|
||||
const QFont& getChatMessageFont() const;
|
||||
|
@ -480,16 +467,23 @@ public:
|
|||
QString getFriendAddress(const QString& publicKey) const;
|
||||
void updateFriendAddress(const QString& newAddr);
|
||||
|
||||
QString getFriendAlias(const ToxPk& id) const;
|
||||
void setFriendAlias(const ToxPk& id, const QString& alias);
|
||||
QString getFriendAlias(const ToxPk& id) const override;
|
||||
void setFriendAlias(const ToxPk& id, const QString& alias) override;
|
||||
|
||||
int getFriendCircleID(const ToxPk& id) const;
|
||||
void setFriendCircleID(const ToxPk& id, int circleID);
|
||||
int getFriendCircleID(const ToxPk& id) const override;
|
||||
void setFriendCircleID(const ToxPk& id, int circleID) override;
|
||||
|
||||
QDate getFriendActivity(const ToxPk& id) const;
|
||||
void setFriendActivity(const ToxPk& id, const QDate& date);
|
||||
QDate getFriendActivity(const ToxPk& id) const override;
|
||||
void setFriendActivity(const ToxPk& id, const QDate& date) override;
|
||||
|
||||
void removeFriendSettings(const ToxPk& id);
|
||||
void saveFriendSettings(const ToxPk& id) override;
|
||||
void removeFriendSettings(const ToxPk& id) override;
|
||||
|
||||
SIGNAL_IMPL(Settings, autoAcceptCallChanged,
|
||||
const ToxPk& id, IFriendSettings::AutoAcceptCallFlags accept)
|
||||
SIGNAL_IMPL(Settings, autoGroupInviteChanged, const ToxPk& id, bool accept)
|
||||
SIGNAL_IMPL(Settings, autoAcceptDirChanged, const ToxPk& id, const QString& dir)
|
||||
SIGNAL_IMPL(Settings, contactNoteChanged, const ToxPk& id, const QString& note)
|
||||
|
||||
bool getFauxOfflineMessaging() const;
|
||||
void setFauxOfflineMessaging(bool value);
|
||||
|
@ -690,5 +684,4 @@ private:
|
|||
static QThread* settingsThread;
|
||||
};
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(Settings::AutoAcceptCallFlags)
|
||||
#endif // SETTINGS_HPP
|
||||
|
|
|
@ -19,7 +19,7 @@ AboutFriendForm::AboutFriendForm(QPointer<IAboutFriend> about, QWidget* parent)
|
|||
connect(ui->autogroupinvite, &QCheckBox::clicked, this, &AboutFriendForm::onAutoGroupInvite);
|
||||
connect(ui->selectSaveDir, &QPushButton::clicked, this, &AboutFriendForm::onSelectDirClicked);
|
||||
connect(ui->removeHistory, &QPushButton::clicked, this, &AboutFriendForm::onRemoveHistoryClicked);
|
||||
connect(about.data(), &IAboutFriend::autoAcceptDirChanged, this, &AboutFriendForm::onAutoAcceptDirChanged);
|
||||
about.data()->connectTo_autoAcceptDirChanged([=](const QString& dir){ onAutoAcceptDirChanged(dir); });
|
||||
|
||||
const QString dir = about->getAutoAcceptDir();
|
||||
ui->autoacceptfile->setChecked(!dir.isEmpty());
|
||||
|
@ -76,7 +76,7 @@ void AboutFriendForm::onAutoAcceptDirChanged(const QString& path)
|
|||
void AboutFriendForm::onAutoAcceptCallClicked()
|
||||
{
|
||||
const int index = ui->autoacceptcall->currentIndex();
|
||||
const IAboutFriend::AutoAcceptCall flag = static_cast<IAboutFriend::AutoAcceptCall>(index);
|
||||
const IFriendSettings::AutoAcceptCallFlags flag{index};
|
||||
about->setAutoAcceptCall(flag);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user