diff --git a/CMakeLists.txt b/CMakeLists.txt index ebea37d61..fa054d0ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/qtox.pro b/qtox.pro index 1bc3826e7..f8f3ca857 100644 --- a/qtox.pro +++ b/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 \ diff --git a/src/model/about/aboutfriend.cpp b/src/model/about/aboutfriend.cpp new file mode 100644 index 000000000..52cb92bf3 --- /dev/null +++ b/src/model/about/aboutfriend.cpp @@ -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(Settings::getInstance().getAutoAcceptCall(pk)); + return static_cast(value); +} + +void AboutFriend::setAutoAcceptCall(AutoAcceptCallFlags flag) +{ + const ToxPk pk = f->getPublicKey(); + const int value = static_cast(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()); + } +} diff --git a/src/model/about/aboutfriend.h b/src/model/about/aboutfriend.h new file mode 100644 index 000000000..474290834 --- /dev/null +++ b/src/model/about/aboutfriend.h @@ -0,0 +1,40 @@ +#ifndef ABOUT_FRIEND_H +#define ABOUT_FRIEND_H + +#include "iaboutfriend.h" +#include "src/model/friend.h" + +#include + +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 diff --git a/src/model/about/iaboutfriend.h b/src/model/about/iaboutfriend.h new file mode 100644 index 000000000..48d302b45 --- /dev/null +++ b/src/model/about/iaboutfriend.h @@ -0,0 +1,53 @@ +#ifndef I_ABOUT_FRIEND_H +#define I_ABOUT_FRIEND_H + +#include + +class IAboutFriend : public QObject +{ + Q_OBJECT + +public: + enum class AutoAcceptCall + { + None = 0x00, + Audio = 0x01, + Video = 0x02, + AV = Audio | Video + }; + using AutoAcceptCallFlags = QFlags; + + 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