mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(aboutfriend): Add AboutFriend model and interface
This commit is contained in:
parent
8368f2413d
commit
b0a591e0f0
|
@ -251,6 +251,9 @@ set(${PROJECT_NAME}_SOURCES
|
|||
src/grouplist.h
|
||||
src/ipc.cpp
|
||||
src/ipc.h
|
||||
src/model/about/aboutfriend.cpp
|
||||
src/model/about/aboutfriend.h
|
||||
src/model/about/iaboutfriend.h
|
||||
src/model/contact.cpp
|
||||
src/model/contact.h
|
||||
src/model/friend.cpp
|
||||
|
|
3
qtox.pro
3
qtox.pro
|
@ -369,6 +369,8 @@ HEADERS += \
|
|||
src/groupinvite.h \
|
||||
src/grouplist.h \
|
||||
src/ipc.h \
|
||||
src/model/about/aboutfriend.h \
|
||||
src/model/about/iaboutfriend.h \
|
||||
src/model/contact.h \
|
||||
src/model/friend.h \
|
||||
src/model/group.h \
|
||||
|
@ -492,6 +494,7 @@ SOURCES += \
|
|||
src/grouplist.cpp \
|
||||
src/ipc.cpp \
|
||||
src/main.cpp \
|
||||
src/model/about/aboutfriend.cpp \
|
||||
src/model/contact.cpp \
|
||||
src/model/friend.cpp \
|
||||
src/model/group.cpp \
|
||||
|
|
101
src/model/about/aboutfriend.cpp
Normal file
101
src/model/about/aboutfriend.cpp
Normal file
|
@ -0,0 +1,101 @@
|
|||
#include "aboutfriend.h"
|
||||
|
||||
#include "src/nexus.h"
|
||||
#include "src/persistence/profile.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
||||
AboutFriend::AboutFriend(const Friend* f)
|
||||
: f{f}
|
||||
{
|
||||
}
|
||||
|
||||
QString AboutFriend::getName() const
|
||||
{
|
||||
return f->getDisplayedName();
|
||||
}
|
||||
|
||||
QString AboutFriend::getStatusMessage() const
|
||||
{
|
||||
return f->getStatusMessage();
|
||||
}
|
||||
|
||||
QString AboutFriend::getPublicKey() const
|
||||
{
|
||||
return f->getPublicKey().toString();
|
||||
}
|
||||
|
||||
QPixmap AboutFriend::getAvatar() const
|
||||
{
|
||||
const QString pk = f->getPublicKey().toString();
|
||||
const QPixmap avatar = Nexus::getProfile()->loadAvatar(pk);
|
||||
return avatar.isNull() ? QPixmap(QStringLiteral(":/img/contact_dark.svg"))
|
||||
: avatar;
|
||||
}
|
||||
|
||||
QString AboutFriend::getNote() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getContactNote(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setNote(const QString& note)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setContactNote(pk, note);
|
||||
Settings::getInstance().savePersonal();
|
||||
emit noteChanged(note);
|
||||
}
|
||||
|
||||
QString AboutFriend::getAutoAcceptDir() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getAutoAcceptDir(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoAcceptDir(const QString& path)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoAcceptDir(pk, path);
|
||||
Settings::getInstance().savePersonal();
|
||||
emit autoAcceptDirChanged(path);
|
||||
}
|
||||
|
||||
IAboutFriend::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);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoAcceptCall(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().savePersonal();
|
||||
emit autoAcceptCallChanged(flag);
|
||||
}
|
||||
|
||||
bool AboutFriend::getAutoGroupInvite() const
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
return Settings::getInstance().getAutoGroupInvite(pk);
|
||||
}
|
||||
|
||||
void AboutFriend::setAutoGroupInvite(bool enabled)
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
Settings::getInstance().setAutoGroupInvite(pk, enabled);
|
||||
Settings::getInstance().savePersonal();
|
||||
emit autoGroupInviteChaged(enabled);
|
||||
}
|
||||
|
||||
bool AboutFriend::clearHistory()
|
||||
{
|
||||
const ToxPk pk = f->getPublicKey();
|
||||
History* const history = Nexus::getProfile()->getHistory();
|
||||
if (history) {
|
||||
history->removeFriendHistory(pk.toString());
|
||||
}
|
||||
}
|
40
src/model/about/aboutfriend.h
Normal file
40
src/model/about/aboutfriend.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef ABOUT_FRIEND_H
|
||||
#define ABOUT_FRIEND_H
|
||||
|
||||
#include "iaboutfriend.h"
|
||||
#include "src/model/friend.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class AboutFriend : public IAboutFriend
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AboutFriend(const Friend* f);
|
||||
|
||||
QString getName() const override;
|
||||
QString getStatusMessage() const override;
|
||||
QString getPublicKey() const override;
|
||||
|
||||
QPixmap getAvatar() const override;
|
||||
|
||||
QString getNote() const override;
|
||||
void setNote(const QString& note) override;
|
||||
|
||||
QString getAutoAcceptDir() const override;
|
||||
void setAutoAcceptDir(const QString& path) override;
|
||||
|
||||
AutoAcceptCallFlags getAutoAcceptCall() const override;
|
||||
void setAutoAcceptCall(AutoAcceptCallFlags flag) override;
|
||||
|
||||
bool getAutoGroupInvite() const override;
|
||||
void setAutoGroupInvite(bool enabled) override;
|
||||
|
||||
bool clearHistory() override;
|
||||
|
||||
private:
|
||||
const Friend* const f;
|
||||
};
|
||||
|
||||
#endif // ABOUT_FRIEND_H
|
53
src/model/about/iaboutfriend.h
Normal file
53
src/model/about/iaboutfriend.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
#ifndef I_ABOUT_FRIEND_H
|
||||
#define I_ABOUT_FRIEND_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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;
|
||||
|
||||
virtual QPixmap getAvatar() const = 0;
|
||||
|
||||
virtual QString getNote() const = 0;
|
||||
virtual void setNote(const QString& note) = 0;
|
||||
|
||||
virtual QString getAutoAcceptDir() const = 0;
|
||||
virtual void setAutoAcceptDir(const QString& path) = 0;
|
||||
|
||||
virtual AutoAcceptCallFlags getAutoAcceptCall() const = 0;
|
||||
virtual void setAutoAcceptCall(AutoAcceptCallFlags flag) = 0;
|
||||
|
||||
virtual bool getAutoGroupInvite() const = 0;
|
||||
virtual void setAutoGroupInvite(bool enabled) = 0;
|
||||
|
||||
virtual bool clearHistory() = 0;
|
||||
|
||||
signals:
|
||||
void nameChanged(const QString& name) const;
|
||||
void statusChanged(const QString& status) const;
|
||||
void publicKeyChanged(const QString& pk) const;
|
||||
|
||||
void avatarChanged(const QPixmap& avatar) const;
|
||||
void noteChanged(const QString& note) const;
|
||||
|
||||
void autoAcceptDirChanged(const QString& dir);
|
||||
void autoAcceptCallChanged(AutoAcceptCall flag);
|
||||
void autoGroupInviteChaged(bool enabled);
|
||||
};
|
||||
|
||||
#endif // I_ABOUT_FRIEND_H
|
Loading…
Reference in New Issue
Block a user