1
0
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:
Diadlo 2017-08-30 09:39:54 +03:00
parent 8368f2413d
commit b0a591e0f0
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727
5 changed files with 200 additions and 0 deletions

View File

@ -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

View File

@ -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 \

View 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());
}
}

View 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

View 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